Trains the technique from
LeetCode 1942The Number of the Smallest Unoccupied ChairThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A waiting room has an endless run of seats numbered 0, 1, 2 and onwards. visits[i] = [arrives, leaves] says when guest i comes in and when they go.
A guest coming in takes the free seat with the smallest number. A seat falls free the moment its guest goes, so a guest arriving exactly then may take it.
No two guests arrive at the same moment. Return the number of the seat taken by guest watched.
Example 1
Each guest goes exactly as the next comes in, so seat 0 is free every time and everyone sits there.
Example 2
Both guests stay until the same moment, so the second has to take the next seat up.
Example 3
By the time the last guest arrives, seats 1 and 2 have both fallen free, and the smaller number wins even though seat 2 fell free first.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def smallest_chair(visits: list[list[int]], watched: int) -> int:public int smallestChair(int[][] visits, int watched)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.