“Machine Coding interview problems test the holistic synthesis of SOLID principles and GoF patterns. Designing a Smart Parking Lot requires modeling Spot hierarchies (Compact, Large, Handicapped), dynamic fee calculation strategies (Hourly, Flat, Peak pricing via Strategy pattern), entry/exit gate state machines, and concurrency-safe spot allocation locks.”
End-to-end Low-Level Design of a multi-floor Parking Lot and Elevator scheduling system using Clean Architecture and Design Patterns.
// LLD Parking Lot Domain Implementation
export enum VehicleType { MOTORCYCLE, COMPACT, TRUCK }
export enum SpotType { TWO_WHEELER, COMPACT, LARGE }
export abstract class Vehicle {
constructor(public readonly license: string, public readonly type: VehicleType) {}
}
export class ParkingSpot {
private occupiedVehicle: Vehicle | null = null;
constructor(public readonly id: string, public readonly type: SpotType) {}
isFree(): boolean { return this.occupiedVehicle === null; }
park(v: Vehicle) { this.occupiedVehicle = v; }
unpark() { this.occupiedVehicle = null; }
}
export interface IParkingStrategy {
findSpot(spots: ParkingSpot[], v: Vehicle): ParkingSpot | null;
}
export class NearestFirstStrategy implements IParkingStrategy {
findSpot(spots: ParkingSpot[], v: Vehicle): ParkingSpot | null {
return spots.find(s => s.isFree()) || null;
}
}Clarify functional and non-functional requirements (Capacity, spot types, payment methods, concurrency)
Identify core domain entities (ParkingLot, Floor, ParkingSpot, Vehicle, Ticket, Payment)
Apply Factory pattern for Vehicle & Ticket instantiation
Apply Strategy pattern for parking spot allocation algorithms (Nearest-to-entrance, Best-fit)
Apply Observer pattern to update real-time LED display boards across all floors upon parking/unparking
Using concurrent read-write locks per Floor rather than locking the entire Parking Lot allows thousands of cars to park simultaneously across multiple levels.