Problem · Heap
Farthest Seat Assignment
Learn this problemProblem statement
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.
Function
assignSeats(n: int, count: int) → int[]Examples
Example 1
n = 10count = 5return = [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.
Example 2
n = 3count = 4return = [0,2,1]Only three seats exist, so only three assignments are returned.
Constraints
When no seats are occupied yet, assign seat 0.