Queued Seats
Updated
Problem statement
There are infinitely many seats numbered from 1. The people in arr initially stand in input order; person i wants seat arr[i].
- Process the person at the front of the queue.
- If their desired seat is unoccupied, assign it and remove that person from the queue.
- Otherwise, increase their desired seat by
1and move them to the end of the queue.
Return each person's final seat number in original input order.
Function
getSeatsAllocation(arr: int[]) → int[]Examples
Example 1
arr = [1,2,3,2,4]return = [1,2,3,5,4]Assignments are returned by original person index; occupied choices increase by one before requeueing.
Example 2
arr = [1,3,3,2,2]return = [1,3,4,2,5]Assignments are returned by original person index; occupied choices increase by one before requeueing.
Example 3
arr = [2,2,1]return = [2,3,1]Assignments are returned by original person index; occupied choices increase by one before requeueing.
Constraints
1 <= arr.length <= 10^51 <= arr[i] <= arr.length
More IMC Trading Online Assessment questions
- Earliest Meeting Start on a 24-Hour ClockOA · Seen Nov 2026
- Grid Paths with Override PassesOA · Seen Oct 2026
- Weighted LFU CacheOA · Seen Sep 2026
- Rock JumpingOA · Seen Aug 2026
- Stack Batch RemovalOA · Seen Aug 2026
- Chain of CommandOA · Seen Aug 2026
- Choose ContainersOA · Seen Aug 2026
- Sub-matrix SumsOA · Seen Jul 2026
- Sub-matrix SumsOA · Seen Jul 2026
- Can Every Package Fit in a BoxOA · Seen Jul 2026
Similar questions at other companies
- Compress Editor Actions into Operational Transform OperationsReplit · OA · PHONE SCREEN · ONSITE INTERVIEW
- Sum of Subarray MinimumsNVIDIA · OANVIDIA interview questions
- Realized PnL with Oldest Inventory FirstBelvedere Trading · OA
- Shopkeeper Final Price SummaryMicrosoft · OAMicrosoft interview questions
- Nested Recipe Blocks (Game Adaptation)Roblox · OARoblox interview questions
- Buffet Day GainsUpstart · OAUpstart interview questions
- Minimum of Fixed-Window MaximaJuspay · OA
- Maximum of Subarray MinimumsJP Morgan Chase · OAJP Morgan Chase interview questions
- Profit AnalysisVirtu Financial · OAVirtu Financial interview questions
- Maximum Capped Histogram Area After One RemovalMyntra · OAMyntra interview questions