Design Parking System

Easy Design Counting

Problem

A parking lot has a fixed number of big, medium and small slots. addCar(carType) parks a car of that type, where 1 is big, 2 is medium and 3 is small, and returns whether a slot was available. A car can only use a slot of its own size.

Original: LeetCode 1603: Design Parking System.

Examples

Example 1

Input`ParkingSystem: ParkingSystem(1, 1, 0), addCar(1), addCar(2), addCar(3), addCar(1)`
Output`[null, true, true, false, false]`

There is no small slot, and the one big slot is already taken by the last call.

Constraints

  • 0 <= big, medium, small <= 1000
  • carType is 1, 2, or 3
  • At most 1000 calls will be made to addCar

Hints

Solution

Tried it yourself? The approach, complexity, and code stay hidden until you choose.

Sources (1)
  1. LeetCode 1603: Design Parking Systemleetcode.com