Intuition
- This is one of those too good to be true problems. Super easy. Literally just COUNT.
Complexity
Runtime
, where N is big + medium + small
Space
, since you only track 3 variables at a time
Code
class ParkingSystem:
def __init__(self, big: int, medium: int, small: int):
self.parkinglot = [big, medium, small]
def addCar(self, carType: int) -> bool:
if self.parkinglot[carType - 1]:
self.parkinglot[carType - 1] -= 1
return True
return False