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
- Total Palindrome Substring CostOA · Seen Jun 2026
- Earliest Time All Users Are ConnectedPHONE SCREEN · Seen May 2026
- Tournament Rounds by RankPHONE SCREEN · Seen May 2026
- Convex Function MinimizationPHONE SCREEN · Seen May 2026
- Maximal Square AreaONSITE INTERVIEW · Seen May 2026
- First Unique IP Hitting the ServerPHONE SCREEN · Seen May 2026
- Jump Game with Prime-Step RuleOA · Seen May 2026
- Pipeline Throughput Maximization Under BudgetOA · Seen May 2026
public int[] assignSeats(int n, int count) {
// write your code here
}
n10
count5
expected[0,9,4,2,6]
sign in to submit