At a party, n friends, numbered from 0 to n−1, arrive and leave at different times. There are infinitely many chairs, numbered 0 onwards. Each arriving friend sits on the smallest available chair at that moment.
For example, if chairs 0, 1, and 5 are occupied when a friend arrives, they will sit on chair number 2.
When a friend leaves, their chair becomes immediately available. If another friend arrives simultaneously, they can take that chair.
You are given a 0-indexed 2D list ...