Bus Station Seat Allotment
Updated
Problem statement
A bus has infinitely many seats numbered with positive integers. There are n people in a queue. Person i initially requests seat desiredSeats[i].
Repeatedly process the person at the front of the queue:
- If their currently requested seat is empty, assign that seat to the person and remove them from the queue.
- If the seat is occupied, increase their requested seat number by
1and move them to the back of the queue.
Return an array assigned in the original queue order, where assigned[i] is the final seat assigned to person i.
Function
allotSeats(desiredSeats: int[]) → int[]Examples
Example 1
desiredSeats = [1,1,2]return = [1,3,2]The first person takes seat 1. The second person finds it occupied and moves behind the third person with a request for seat 2. The third person takes seat 2, so the second person eventually takes seat 3.
Example 2
desiredSeats = [3,1,3,2]return = [3,1,4,2]The first, second, and fourth people take seats 3, 1, and 2 on their first turns. The third person first finds seat 3 occupied, then takes seat 4.
Constraints
1 <= desiredSeats.length <= 10^51 <= desiredSeats[i] <= desiredSeats.length
More InMobi Phone Screen questions
- House Robber IPHONE SCREEN · Seen Aug 2026
- Word Break IIPHONE SCREEN · Seen Aug 2026
- Find Missing and Duplicate IntegerPHONE SCREEN · Seen Mar 2026
- Frequency Equals Card ValuePHONE SCREEN · Seen Mar 2026
- Frog Position After T SecondsPHONE SCREEN · Seen Mar 2026
- IPOPHONE SCREEN · Seen Mar 2026
- Evaluate DivisionPHONE SCREEN · Seen Dec 2025
- Compare Version NumbersPHONE SCREEN · Seen Feb 2022
- Count Array DerangementsPHONE SCREEN · Seen Feb 2022
- Maximum Frequency StackPHONE SCREEN · Seen Feb 2022
Similar questions at other companies
- Determine the Winner of Three-Card HandsOpenAI · PHONE SCREENOpenAI interview questions
- Constant-Time Weighted Pick with an Alias TableEtched · PHONE SCREEN
- Pins Violation Log QueriesPinterest · PHONE SCREENPinterest interview questions
- Resource Reconciler: Plan and Apply CreatesPerplexity AI · PHONE SCREENPerplexity AI interview questions
- Deterministic Secret Santa AssignmentShopify · PHONE SCREENShopify interview questions
- Shortest-Job-First Process SchedulingByteDance · PHONE SCREENByteDance interview questions
- High-Card Pot GameAffirm · PHONE SCREENAffirm interview questions
- Stateful Paginated Fetch NLyft · PHONE SCREENLyft interview questions
- Music Player Operation SequenceAtlassian · PHONE SCREENAtlassian interview questions
- Dynamic Longest-Waiting Unique Task QueriesAmazon · PHONE SCREEN