A parking lot has three kinds of spaces, big, medium and small, with a fixed number of each. Cars arrive one at a time, and each car has a type: 1 for big, 2 for medium and 3 for small. A car can park only in a space of its own kind. If such a space is free, the car parks and the space stays occupied for the rest of the sequence; otherwise the car is turned away and nothing changes.
Given the number of spaces of each kind and the sequence of arriving car types, return whether each car was able to park.
The report describes this only as an easy parking-lot design problem. It is usually posed as a class whose constructor takes the three capacities and whose method is called once per arriving car; this console tests the same behavior through a single function that replays the arrivals in order.
Function Signature
def park_cars(big: int, medium: int, small: int, car_types: list[int]) -> list[bool]:
Rules
-
big
,
medium
and
small
are the numbers of free spaces of each kind before the first car arrives.
-
Process
car_types
from first to last. For a car of type
t
, if at least one space of kind
t
is free, the car parks, one space of that kind becomes occupied, and the answer for that car is
True
; otherwise the answer is
False
and no space changes.
-
A car never uses a space of a different kind, larger or smaller, and parked cars never leave.
-
Return a list with exactly one boolean per car, in arrival order.
Constraints
-
0 <= big, medium, small <= 1000
-
1 <= len(car_types) <= 10^4
-
Every element of
car_types
is
1
,
2
or
3
.
Examples
Example 1
Input: big = 2, medium = 0, small = 1, car_types = [3, 1, 2, 3, 1, 1]
Output: [True, True, False, False, True, False]
The first small car takes the only small space, so the second small car is turned away. The lot has no medium spaces, so the medium car is turned away. The first two big cars take the two big spaces, and the third big car is turned away.
Example 2
Input: big = 1, medium = 0, small = 0, car_types = [3, 2, 1]
Output: [False, False, True]
The small and medium cars are turned away even though a big space is free, because a car parks only in a space of its own kind. The big car then takes the big space.