Parking Garage Allocator
Updated
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.
More Amazon Phone Screen questions
- Course SchedulePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Search in a Rotated Sorted ArrayPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Top K Frequent ElementsOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- LRU Cache for Query ResultsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Course Schedule IIPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Minimum Time to Spread Through a GridPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Consistent-Hash Packet RouterPHONE SCREEN · Seen Nov 2026
- Count Connected ComponentsPHONE SCREEN · Seen Nov 2026
- Second Largest Distinct ElementPHONE SCREEN · Seen Nov 2026
- Task SchedulerOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Query Log MatchDatadog · PHONE SCREEN · ONSITE INTERVIEWDatadog interview questions
- Elevator Scheduling SimulationOpenAI · PHONE SCREENOpenAI interview questions
- Compress Editor Actions into Operational Transform OperationsReplit · OA · PHONE SCREEN · ONSITE INTERVIEW
- Load/Store Arithmetic InterpreterJane Street · PHONE SCREENJane Street interview questions
- Variadic Function Library MatchesIBM · PHONE SCREENIBM interview questions
- Project and Filter Structured RecordsStripe · PHONE SCREENStripe interview questions
- Ordered IP FirewallDatabricks · PHONE SCREENDatabricks interview questions
- Add Signed Character ArraysByteDance · PHONE SCREENByteDance interview questions
- Is This Tic-Tac-Toe Board ReachableAdobe · PHONE SCREENAdobe interview questions
- Wordle Guess LoopRetool · PHONE SCREENRetool interview questions
Amazon interview experiences
- Amazon Experienced SDE Onsite Questions: 1 Experience
- Amazon SDE Onsite Interview Questions: 9 Experiences
- Amazon SDE II and L5 FDE Interview Questions: 4 Experiences
- Amazon Full-Time OA Problems, Earlier Reports (Part 5 of 5)
- Amazon Full-Time OA Problems, Recent Reports (Part 4 of 5)
- Amazon New Grad OA Problems: Every Task We Have (Part 3 of 5)