Design a parking lot
medium 90 minModel a car park with several levels as classes: vehicles, spaces of different sizes, tickets and a replaceable price rule.
Watch lesson4:48
Remember it
The few things worth knowing cold, and how to make them stick.
Memory hook
The disc on the hook: whoever holds it owns the space. Taking is the check.
A car park by the sea with one hook of numbered discs. A clerk does not look out of the window. They reach for a disc. An empty hook is a clear no.

Cheat sheet
- Verbs
- enter, leave
- Owner of free spaces
- SpotPool, a queue by size
- Fit
- spot.size >= vehicle.min_size, upwards
- Enter, under the lock
- plate, claim, store
- Leave
- pop, price, charge, release, open
- Started hours
- max(1, (s + 3599) // 3600)
- Lock load
- 1.7 claims/s x 5 microseconds = 0.00085%
- Nearest
- heap by size, about 9 steps for 500
- Five in a row
- run counter O(n), or bits
- Invariant
- free + active = total
Spot it when you see
- Typed things in limited number and several askers: allocator.
- "Several ways to calculate": Strategy.
- "Tell several others": Observer.
- "N of them, and wait": Semaphore.
Tricks that stick
- PARK: Participants, Actions, Relationships, Key risks.
- C.I.M.P.L.: Container, Item, Manager, Policy, Lifecycle. A net, not a list of classes.
- A level is a number until it owns something.
- Pop before pay, release after pay.
Do not forget
- isFull() before enter.
- A lock held while a card is charged.
- toHours() rounds down.
- Subtracting local times.
- Singleton by habit.
- A total across levels treated as exact.