Parking Garage Allocator
Problem statement
Manage spaceCount parking spaces. Each operation is "PARK size" or "LEAVE start size". A park request occupies the leftmost available run of the requested size and contributes its starting index, or -1 when no run fits. A leave operation frees the stated valid occupied range and contributes no output.
Sizes are 1, 2, or 3.
Function
processParking(spaceCount: int, operations: String[]) → int[]Examples
Example 1
spaceCount = 6operations = ["PARK 2","PARK 3","LEAVE 0 2","PARK 1"]return = [0,2,0]The final request reuses the leftmost freed space.
Example 2
spaceCount = 2operations = ["PARK 3","PARK 2"]return = [-1,0]The oversized request fails without changing state.
Constraints
1 <= spaceCount, operations.length <= 100000.- Every leave operation refers to a currently occupied range.
Source note: Author-written prompt excerpt retained for source fidelity.