Practice Design Parking System
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
ParkingSystem(big, medium, small) tracks remaining spaces of three types. addCar(carType) uses one matching space and returns true if available, otherwise false. Types 1, 2, and 3 mean big, medium, and small. A car can only use its exact type; a larger empty space is not a substitute. Practice approach: Keep three counters. Reject a request whose counter is zero, otherwise decrement that counter. Each operation uses O(1) time and the object uses O(1) space. A rejected request must not consume another type's capacity. Test zero initial capacity and repeated arrivals of the same type.
Source: Design Parking System on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
["ParkingSystem","addCar","addCar","addCar","addCar"] [[1,0,2],[2],[1],[1],[3]]
[null,false,true,false,true]
A medium car fails despite spare big and small slots. The second big car fails after the single big slot is used.
Constraints
Related LeetCode Problems
Practice more problems similar to Design Parking System.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.