Seat Viewers in a Watch Party Room to Maximize Their Distance
Last updated: November 29, 2026
Quick Overview
A watch party row has n seats. seat() places a viewer in the seat that maximizes the distance to the nearest occupied seat (lowest index on ties) and returns it; leave(p) frees seat p.
Meta
November 29, 20260
0
0 solved
A watch party row has n seats. seat() places a viewer in the seat that maximizes the distance to the nearest occupied seat (lowest index on ties) and returns it; leave(p) frees seat p.
Inspired by spacing participants in Messenger Rooms and watch parties, this Meta onsite question tests ordered-set reasoning about gaps. Interviewers accept an O(k) scan over a sorted list of occupied seats and then ask how to get O(log k) with a gap heap.
What the Interviewer Expects
- Keep occupied seats in sorted order
- Consider the left wall, interior gaps, and the right wall separately
- Pick the midpoint of the best interior gap with lowest-index ties
- Handle leave by removing from the sorted structure
- Discuss an O(log n) design with a heap of gaps and lazy deletion
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- Make seat() O(log n).
- Support a minimum distance rule that refuses to seat anyone too close.
- Extend to a 2D grid of seats.
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
- Seats 0 to n - 1, empty at start.
seat(): choose the seat maximizing the minimum distance to occupied seats; ties go to the lowest index. Return it.leave(p): seat p is occupied; free it....
High-Level Design
Keep occupied seats in a sorted list. Candidates for the best seat:
- Seat 0, if empty, with distance equal to the first occupied seat.
- Midpoint of each interior gap (a, b): seat `(a + b) ...