Design Projects: Classic Systems · Debugging task
Debug: Parking Lot - Two Cars, One Spot
A free debugging task from the Design a Parking Lot skill. Read it here, then solve it in the app in Java or Python.
- Easy
- Debugging task
- Free
- Java and Python
The problem
Your task
Operations filed a bug report - it's README.md in the project, with the gate logs: one evening the
lot sent a car to a spot that already had a car in it. The code that shipped is the project's
ParkingLot.java, and Main.java replays that evening (in Python: parking_lot.py and main.py).
Find the root cause, fix it, and explain the root cause in the Root cause box under the editor - Submit needs it. Only the hidden tests decide whether the fix is accepted; your explanation is saved with the submission.
How the lot is supposed to work
parkVehicle(vehicle)puts the vehicle in a free spot of its size - MOTORCYCLE in SMALL, CAR in MEDIUM, BUS in LARGE - and returns a new ticket, ornull(None) if no spot of that size is free. In Python the methods arepark_vehicle,unpark_vehicleandavailable_spots.unparkVehicle(ticket)frees the spot that ticket holds and returnstrue; a ticket it doesn't recognize returnsfalseand changes nothing. A ticket is good for one exit.availableSpots(size)is the number of free spots of that size.
A good fix
- Is as small as the bug and keeps every constructor and public method signature.
- Fixes the cause, not just the evening in the report - the hidden suite checks the report's scenario, and everything the lot already did right, with other values.
- Comes with a root cause that says what in the code goes wrong and why, not just what you changed.
Constraints
- Do not change the signatures of
ParkingLot's constructor and public methods, or the classes inparkinglot/model/- the hidden tests call them exactly as given. - Assume single-threaded access.
How it's graded
- The shipped code passes the team's existing tests - that's how the bug shipped. Fix it, then Submit runs a hidden suite that checks the reported scenario and everything else, and asks you to write the root cause in a sentence or two.
- Stuck? Hints come in four steps, from a nudge to a code skeleton, each costing part of the points.
More problems in Design a Parking Lot
Solve it Debug: Parking Lot - Two Cars, One Spot free
No card needed. Lessons, practice questions and easy problems are free forever.
Free plan, no card · 7-day Pro trial · Cancel anytime