{}DSA Atlas

The LLD Interview Method

A step-by-step process for LLD and machine-coding rounds (requirements → entities → relationships → APIs → patterns → code → concurrency → extensions), how to manage time, thread-safety techniques for in-memory designs, testing your design live, and the mistakes that sink candidates.

Intermediate4 interview questions

The 8-step method

1. Requirementsuse cases, scope 2. Entitiesnouns → classes 3. Relationshipsclass diagram 4. APIs & flowssignatures, sequences 5. Patternsonly where variation is 6. Codecore flow first 7. Concurrency+ edge cases 8. Extensions+ tests narrate trade-offs at every step — the interviewer grades your reasoning, not just the code
A repeatable path through any LLD question.

1. Requirements

Ask about:

  • Actors (customer, admin, driver) and use cases for each.
  • Scope: in-memory only? persistence? UI/CLI? payments mocked?
  • Rules: pricing, limits, cancellation policy, priorities.
  • Concurrency: multiple entry points/users at once?
  • Extensibility expectations ("we'll add EV charging spots later").

Write a short numbered list and confirm it.

2. Entities and responsibilities

Underline nouns in the requirements → candidate classes; verbs → methods. Decide:

  • Entities (identity): ParkingLot, Spot, Ticket.
  • Value objects: Money, TimeRange, Location.
  • Enums: VehicleType, SpotType, TicketStatus.
  • Services for workflows that span entities: ParkingService, PaymentService.
  • Repositories (interfaces) for storage, in-memory implementations.

3. Relationships

Composition vs aggregation vs association, multiplicities, inheritance only for genuine is-a.

4. APIs and flows

Java
public interface ParkingService {
    Ticket park(Vehicle vehicle, EntryGateId gate);           // throws NoSpotAvailable
    Receipt exit(TicketId ticket, PaymentMethod method);      // throws InvalidTicket
    Map<SpotType, Integer> availability(FloorId floor);
}

Walk through each flow aloud ("a car arrives at gate 2…") — it often reveals missing pieces.

5. Patterns where they earn their keep

Point to the axis of change: "pricing differs by vehicle type and time → Strategy"; "spot assignment policy may change (nearest to entrance vs fill floors bottom-up) → Strategy"; "order lifecycle → State"; "display boards update on changes → Observer".

6. Code

  • Enums, interfaces and models first, then services, then a main/test driving the flows.
  • Validate inputs; throw domain-specific exceptions.
  • Keep I/O (printing, parsing commands) out of the domain.

7. Concurrency and edge cases

Shared resourceRaceFix
parking spotstwo gates assign the same spotlock per spot / atomic tryOccupy() / concurrent free-spot queues
seats in a showdouble bookingper-show lock, seat hold with expiry, CAS on seat status
elevator requestslost/duplicate requeststhread-safe queues, single scheduler thread
account balancesdouble spendper-account lock, atomic update
counters/IDsduplicate IDsAtomicLong, UUIDs
Java
// lock-free spot claim: only one thread can flip FREE → OCCUPIED
final class Spot {
    private final AtomicReference<Vehicle> occupant = new AtomicReference<>();
    boolean tryOccupy(Vehicle v) { return occupant.compareAndSet(null, v); }
    void release() { occupant.set(null); }
}

8. Extensions and testing

Show how a new requirement lands: a new VehicleType → enum value + pricing strategy entry; a new split type → new SplitStrategy class. Mention unit tests for strategies/state transitions and a concurrency test (many threads parking simultaneously, assert no spot is double-assigned).

Package structure for machine-coding rounds

Text
src/
  model/        Vehicle, Spot, Ticket, enums, value objects
  service/      ParkingService, PricingStrategy implementations
  repository/   interfaces + InMemory implementations
  exception/    domain exceptions
  Main.java     wires everything, runs sample flows / reads commands
test/
  ParkingServiceTest.java

Common mistakes

MistakeBetter
God class doing everythingsplit responsibilities (SRP), services per use case
Inheritance for every variation (RedCar, BlueCar)fields/enums; strategies for behaviour
Strings for types/statesenums
Patterns without a reasonname the change each pattern absorbs
Ignoring concurrencyidentify shared state; lock per entity
Printing inside domain logicreturn values; I/O at the edges
No runnable flow at the endbuild vertical slices early
Public mutable fieldsencapsulation, immutable value objects
Not validating input / statesfail fast with clear exceptions

Interview questions

0 / 4 marked confident

Answer out loud first, then open the model answer. Mark a question confident only when you could explain it to an interviewer without notes.