LLD Problem Solving Framework (Phase-wise with Examples)


Phase 1: Understand the Problem (Time: 5 minutes)

Goal: Get absolute clarity on the problem statement.

Questions to ask:

  • What are the inputs/outputs?

  • What real-world entities exist?

  • What is out of scope?

Examples:

ProblemClarifying Questions
Parking LotMulti-level? Handicapped spots? Reservations?
ElevatorHow many elevators? Multiple floors? Prioritization logic?
Expression EvaluatorSupported operators? Data types? What happens if field missing in input?

Phase 2: Identify Core Responsibilities (Time: 5–10 minutes)

Goal: Break the problem into distinct functional components.

Examples:

ProblemCore Responsibilities
Parking LotSpot allocation, availability tracking, entry/exit flow
ElevatorRequest handling, scheduling, movement control
Expression EvaluatorParsing condition rules, comparing fields, applying operators

Phase 3: Define Key Entities & Interfaces (Time: 10 minutes)

Goal: Design key classes, enums, and interfaces that model the system.

Examples:

ProblemKey Classes & Interfaces
Parking LotParkingLot, Spot, Vehicle, Ticket, SpotAllocator
ElevatorElevator, Request, Scheduler, Direction, ElevatorState
Expression EvaluatorCondition, Operator, ExpressionEvaluator, OperatorRegistry

Design Tip: Follow OOP principles — Identify areas for abstraction (via interfaces), encapsulation, and extensibility.

--- 

Phase 4: Strategy Pattern or Plug-in Logic (Time: 10–15 minutes)

Goal: Make the system flexible and extensible using patterns like Strategy, Factory, or Registry.

Examples:

ProblemPlug-in Logic
Parking LotUse SpotAllocator interface with implementations for Nearest, Reserved, etc.
ElevatorUse Scheduler interface with FCFS, Optimized, or PriorityBased strategies
Expression EvaluatorUse Operator interface and plug different comparisons via strategy pattern

Phase 5: Build Orchestrator / Engine (Time: 10–15 minutes)

Goal: Assemble all components into a working system that can be tested and extended.

Examples:

ProblemCore Engine Logic
Parking LotEntry/exit controller calling allocator and updating map of spots
ElevatorScheduler assigns elevators, moves elevator state machine
Expression EvaluatorIterate conditions → get operator → compare values → return result

Phase 6: Validate & Extend (Time: 5 minutes)

Goal: Handle edge cases, support future extensions, and demonstrate understanding.

Examples:

ProblemAdditions & Validations
Parking LotSupport for electric vehicles, pricing strategies
ElevatorFire alarm interrupt, maintenance mode, weight handling
Expression EvaluatorSupport nested expressions (AND/OR), add new data types

Total Time: 45–50 minutes

PhaseTimeDeliverable
Understand5 minsClarified scope and constraints
Define Roles5–10Core responsibilities
Model Entities10Classes, enums, interfaces
Plug-in Logic10–15Strategy/Factory/Registry
Engine Design10–15Integrate the system
Extend/Test5Edge cases + extensibility plan

Summary Table Across All 3 Examples:

PhaseParking LotElevatorExpression Evaluator
EntitiesSpot, Vehicle, TicketElevator, Request, SchedulerCondition, Operator, Evaluator
Core FunctionsAssign/release spot, track capacitySchedule requests, move elevatorsCompare fields with rules
Patterns UsedStrategy (Allocator)Strategy (Scheduler), FSM for movementStrategy (Operator), Registry
Extensibility PointsNew spot types, pricingScheduler strategies, smart movementNew operators, nested expressions
Common MistakesNo spot tracking per level/floorNo prioritization logicHardcoded logic instead of extensible