Problem · Heap

Farthest Seat Assignment

MediumUberFULLTIMEONSITE INTERVIEW
See Uber hiring insights

Design the assignment behavior for a row of n seats numbered from 0 to n - 1. Each call assigns one unoccupied seat to a new employee. The chosen seat must maximize the distance to the nearest occupied seat. If multiple seats have the same best distance, choose the smallest seat index.

Return the first count assigned seats. If count is larger than n, return only the n actual assignments.

Examples
01 · Example 1
n = 10
count = 5
return = [0,9,4,2,6]

The first two assignments take the ends. The third assignment chooses seat 4, which is one of the middle seats farthest from 0 and 9; ties use the smaller index.

02 · Example 2
n = 3
count = 4
return = [0,2,1]

Only three seats exist, so only three assignments are returned.

Constraints

When no seats are occupied yet, assign seat 0.

More Uber problems
drafts saved locally
public int[] assignSeats(int n, int count) {
    // write your code here
}
n10
count5
expected[0,9,4,2,6]
sign in to submit