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
Coding & Algorithms
Software Engineer
Meta
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Medium

0

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
ordered set
binary search
gap tracking
heap with lazy deletion
object design
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. 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 Problems
Sample 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:

  1. Seat 0, if empty, with distance equal to the first occupied seat.
  2. Midpoint of each interior gap (a, b): seat `(a + b) ...

Submit Your Answer
Markdown supported