Parking lot manager in React
I was asked this
No reports yet. Sign in to say where you were asked it.
A coding interview question asked in Uber's technical phone screen, last asked May 2026. It tests react, frontend and state management.
Build a small React app that manages a parking lot. The screen shows every spot and whether it is free, lets an attendant park an arriving vehicle and check one out, and charges a fee when a vehicle leaves. Use function components and hooks. The round is about how you model vehicles and spots, how you split components, where state lives, and how easily new rules fit in.
Interface
Unless you agree on a different interface with the interviewer, assume:
-
<ParkingLot spots={Spot[]} rates={Record<SpotType, number>} />, whereSpot = { id: number, type: "motorcycle" | "compact" | "large" }andratesis the price per started hour for each spot type. - Vehicles are
{ plate: string, type: "motorcycle" | "car" | "truck" }. A motorcycle fits any spot, a car fits a compact or large spot, a truck fits only a large spot. -
Park assigns the smallest spot type that fits, and among those the lowest
id. If nothing fits, show a message and change nothing. A plate already parked is rejected. - Leave frees the spot and shows the fee: started hours × the spot's rate.
Example
spots = [{id: 1, type: "motorcycle"}, {id: 2, type: "compact"}, {id: 3, type: "large"}]
rates = {motorcycle: 1, compact: 3, large: 5}
park {plate: "ABC", type: "car"} -> spot 2
park {plate: "TRK", type: "truck"} -> spot 3
park {plate: "XYZ", type: "car"} -> "No spot for a car" # compact and large are taken
leave "ABC" after 90 minutes -> fee $6 # 2 started hours × $3
Constraints
- A few hundred spots; everything runs in the browser, no backend.
- Inject the clock so the fee can be tested.
Clarifying questions
- How is the spot chosen: smallest fitting, nearest the entrance, or picked by the attendant?
- How is the fee computed: per started hour, per minute, with a daily cap?
- Can a car take a large spot when no compact one is free?
- Should the state survive a page reload?
- What else is on screen: occupancy counts, a list of parked vehicles, history?
What a strong answer covers
- A data model kept apart from the UI: spots, vehicles, an assignment map, and pure functions for
findSpotandcomputeFeethat can be unit-tested without React. - State in one place (a
useReducerat the top, or a context), with components for the lot grid, a spot, the park form and the checkout result. - Derived values (free counts) computed, not stored twice.
- Validation and clear messages for full lots, duplicate plates and unknown plates.
- Extensibility: new vehicle or spot types and new pricing rules added as data or small strategy functions, not edits all over the components.
Follow-ups
- Add electric-vehicle spots that only electric cars may use, plus a charging fee.
- Add a daily maximum and a free first 15 minutes.
- The lot has several floors. Show them and assign the lowest floor first.
- Persist the state and sync it across two browser tabs.
Where it's asked
- Uber · Technical phone screen · Last asked May 202660 min · One medium problem with a follow-up, or two short ones; sometimes object-oriented design
What it tests
react · frontend · state management
No official answer yet. Write yours on the right and run it.
Nothing published yet.
Sign in to submit your code; every attempt is kept here.
