n guests, numbered 0 to n - 1, come in. Every guest who walks in takes the free stool with the smallest number.
You get an array visits where visits[i] = [arrive, leave] gives the arrival and departure times of guest i. A guest's stool becomes free exactly at time leave; anyone arriving at that same moment can already take it. All arrival times are distinct.
Return the number of the stool that guest guest sits on.visits=[[3, 8], [1, 4], [6, 9], [4, 7]], guest=3 → 0
At time 1 guest 1 takes stool 0, at time 3 guest 0 takes stool 1. At time 4 guest 1 leaves, and guest 3, arriving at that very moment, takes the freed stool 0.
visits=[[2, 5], [1, 10], [3, 6]], guest=2 → 2
Guests 1, 0 and 2 arrive at times 1, 2 and 3, and nobody has left by the time guest 2 comes: stools 0 and 1 are taken, so they get stool 2.
visits=[[3, 8], [1, 4], [6, 9], [4, 7]], guest=3
0
Run checks the first 3 tests in your browser. Submit checks all 94 tests on the server, hidden ones included.