🇮🇳
🇮🇳
Republic Day Special Offer!Get 20% OFF on all courses
Enroll Now
P
Prakalpana
📚Learn
Code Your Future
System Design⏱️ 18 min read📅 Jan 2

LLD Interview: 7 Machine Coding Rounds You Must Practice (With Solutions)

AT
Amit TandonEngineering Manager at Uber
📑 Contents (24 sections)

📌What is LLD Interview?

Low Level Design (Machine Coding) rounds test your ability to:

  • Write clean, extensible code
  • Apply SOLID principles
  • Use design patterns correctly
  • Handle edge cases
  • 📌Problem 1: Parking Lot System

    Requirements

  • Multiple floors, various spot sizes
  • Entry/exit points
  • Ticket generation
  • Payment calculation
  • Key Classes

    class ParkingLot {
    List<ParkingFloor> floors;
    List<EntryPoint> entries;
    List<ExitPoint> exits;
    }
    class ParkingFloor {
    int floorNumber;
    Map<SpotType, List<ParkingSpot>> spots;
    }
    class ParkingSpot {
    SpotType type;
    Vehicle vehicle;
    boolean isOccupied;
    }
    class Ticket {
    String id;
    ParkingSpot spot;
    LocalDateTime entryTime;
    }

    Design Patterns Used

  • Strategy Pattern: Different pricing strategies
  • Factory Pattern: Creating different spot types
  • Singleton: ParkingLot instance
  • 📌Problem 2: BookMyShow

    Requirements

  • Browse movies by city
  • Select shows and seats
  • Book and pay
  • Handle concurrent bookings
  • Key Design Decisions

  • Optimistic locking for seat booking
  • Event-driven for notifications
  • Cache for movie/show data
  • 📌Problem 3: Splitwise

    Requirements

  • Add expenses with splits
  • Calculate balances
  • Settle debts optimally
  • Support different split types (equal, exact, percentage)
  • Core Logic

    interface SplitStrategy {
    Map<User, Double> split(double amount, List<User> users);
    }
    class EqualSplit implements SplitStrategy {
    public Map<User, Double> split(double amount, List<User> users) {
    double each = amount / users.size();
    return users.stream()
    .collect(toMap(u -> u, u -> each));
    }
    }

    📌Problem 4: Elevator System

    Requirements

  • Multiple elevators
  • Optimal elevator selection
  • Handle up/down requests
  • Emergency stop
  • Algorithm: SCAN (Elevator Algorithm)

  • Move in one direction
  • Service all requests in that direction
  • Reverse when no more requests
  • 📌Problem 5: Snake and Ladder

    Requirements

  • Multiple players
  • Snakes take down, ladders take up
  • Dice rolling
  • Winner detection
  • Key Classes

    class Board {
    Map<Integer, Integer> snakes; // start -> end
    Map<Integer, Integer> ladders; // start -> end
    int size;
    }
    class Game {
    Board board;
    Queue<Player> players;
    Dice dice;
    void play() {
    while (!isGameOver()) {
    Player current = players.poll();
    int roll = dice.roll();
    movePlayer(current, roll);
    if (!hasWon(current)) {
    players.add(current);
    }
    }
    }
    }

    📌Problem 6: LRU Cache

    Requirements

  • Get and Put in O(1)
  • Evict least recently used
  • Thread-safe version
  • Implementation

    class LRUCache<K, V> {
    private final int capacity;
    private final Map<K, Node<K, V>> map;
    private final DoublyLinkedList<K, V> list;
    public V get(K key) {
    if (!map.containsKey(key)) return null;
    Node<K, V> node = map.get(key);
    list.moveToFront(node);
    return node.value;
    }
    public void put(K key, V value) {
    if (map.containsKey(key)) {
    Node<K, V> node = map.get(key);
    node.value = value;
    list.moveToFront(node);
    } else {
    if (map.size() >= capacity) {
    Node<K, V> removed = list.removeLast();
    map.remove(removed.key);
    }
    Node<K, V> newNode = new Node<>(key, value);
    list.addFirst(newNode);
    map.put(key, newNode);
    }
    }
    }

    📌Problem 7: Chess Game

    Requirements

  • 8x8 board
  • Different piece movements
  • Check/checkmate detection
  • Turn management
  • Design Highlights

  • Strategy Pattern: Each piece has move strategy
  • Command Pattern: Undo/redo moves
  • State Pattern: Game states (playing, check, checkmate)
  • 📌Interview Tips

  • 1Clarify requirements first (5-10 mins)
  • 2Start with entities and relationships
  • 3Apply SOLID principles
  • 4Use appropriate design patterns
  • 5Write clean, testable code
  • 6Handle edge cases
  • Our LLD course includes practice sessions for all 7 problems with expert feedback.

    AT

    Written by

    Amit Tandon

    Engineering Manager at Uber

    🚀 Master System Design

    Join 500+ developers

    Explore Courses →
    Chat on WhatsApp