FastPrepQueued Seats

Queued Seats

IMC Trading logoIMC Trading● MediumNEW GRADOA
Learn

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 1 and 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^5
  • 1 <= arr[i] <= arr.length

More IMC Trading problems

See IMC Trading hiring insights
public int[] getSeatsAllocation(int[] arr) {
    // Write your solution here.
}
arr[1,2,3,2,4]
expected[1,2,3,5,4]
Checking account…