Exam Room
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
An exam room has n seats in a single row, numbered 0 to n - 1. Students enter one at a time, and each picks the empty seat that **maximizes the distance to the closest occupied seat**. If several seats achieve that maximum distance, the student takes the **lowest-numbered** one. If the room is empty, the student sits in seat 0.
- ExamRoom(n) creates an empty room.
- seat() seats a new student using the rule above and returns the seat number.
- leave(p) makes the student in seat p leave. Seat p is guaranteed to be occupied.
seat is only called when at least one seat is empty. The room can be huge, so avoid work proportional to n per call.
Examples
Constraints
- `1 <= n <= 10^9`
- `leave(p)` is only called for an occupied seat `p`.
- `seat` is only called when the room has an empty seat.
- At most 10^4 calls in total.
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.