Description

Design an exam room where students sit to maximize distance from closest person. Implement seat() and leave().

Examples

Input:n=10, ["seat","seat","seat","seat"]
Output:[0,9,4,2]
Explanation:

Maximize distances.

Input:n=5, ["seat","seat","leave",0,"seat"]
Output:[0,4,null,2]
Explanation:

First seat goes to position 0. Second seat goes to position 4 (maximum distance). Leave position 0. Next seat goes to position 2 (middle of now-empty range 0-4, maximizing distance from person at 4).

Input:n=3, ["seat","seat","seat"]
Output:[0,2,1]
Explanation:

In a small room with only 3 seats: first person sits at position 0, second at position 2 (maximum distance), third must sit at position 1 (the only remaining seat between them).

Constraints

  • 1 ≤ n ≤ 10⁹

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!