Design Parking System
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
A parking lot has three kinds of slots: big, medium and small, with a fixed number of each. Implement ParkingSystem:
- ParkingSystem(big, medium, small) creates a lot with that many slots of each size.
- addCar(carType) tries to park a car of type 1 (big), 2 (medium) or 3 (small). A car may only use a slot of its own size. If a free slot of that size exists, the car takes it and the method returns true; otherwise it returns false and nothing changes.
Cars never leave once parked. Each call should run in O(1).
Examples
Constraints
- 0 <= big, medium, small <= 1000
- `carType` is 1, 2 or 3.
- At most 1000 calls are made to `addCar`.
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.