← Uber Interview Insights

Uber·Software Engineer·Onsite - Coding / Algorithms·Intermediate

IntermediatePrefer not to say
Jun 2026

Summary

Uber coding round with a tricky seat assignment problem I hadn't seen before. Couldn't crack it and I'm still not sure there's a clean LeetCode equivalent for it.

Questions Asked (1)

Q1

Design a class that assigns seats to employees one at a time, where each new assignment maximizes the minimum distance from all previously occupied seats. The class takes a total seat count and exposes a single assign method.

Algorithms & Data StructuresSystem Design
Author's notes

Didn't solve it.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify the problem constraints and then propose an efficient solution using a max-heap to track the largest available gaps between occupied seats. For each assignment, pop the largest gap, place the employee at its midpoint, and push the two new sub-gaps back into the heap. Discuss time and space complexity, and consider edge cases like the first assignment and when seats are exhausted.

Pro tip: Mention that this is essentially the 'Exam Room' problem and that using a priority queue with a custom comparator (to break ties by smaller index) ensures deterministic and optimal placement. Also, note that the first assignment should always be seat 0 to maximize distance for subsequent placements.

1. Clarify Requirements and Constraints

Ask about the range of N, whether seats are 0-indexed, and if multiple assignments can happen concurrently. Confirm that the goal is to maximize the minimum distance to any occupied seat at each step.

2. Choose Data Structures

Use a max-heap (priority queue) to store available intervals between occupied seats, prioritized by the maximum possible distance to the nearest neighbor. For each interval, store its start and end indices.

3. Define Interval Distance and Midpoint

For an interval (left, right), the best seat is at mid = (left + right) / 2, and the distance to the nearest occupied seat is min(mid - left, right - mid). Handle edge cases: if left == -1 (before first seat), distance = right; if right == N (after last seat), distance = N - 1 - left.

4. Implement assign Method

On each call, pop the interval with the largest distance (break ties by smaller index). Place the employee at the computed seat, then push the two new intervals (left, seat) and (seat, right) back into the heap. Return the assigned seat.

5. Analyze Complexity and Edge Cases

Time complexity: O(log N) per assignment due to heap operations. Space: O(N) for the heap. Discuss handling of first assignment (seat 0), last seat, and when no seats are left.

Key Points to Mention

  • Use a max-heap to efficiently retrieve the largest available gap.
  • Define distance for edge intervals (before first and after last occupied seat).
  • Tie-breaking rule: when distances are equal, choose the smaller seat index.
  • First assignment should be seat 0 to maximize future distances.
  • Time complexity: O(log N) per assignment, space O(N).
  • Consider concurrency if multiple threads might call assign simultaneously.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.