
Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
You need a data structure that maintains the states of the seats. This data structure should also allow you to get the first available seat and flip the state of a seat in a reasonable time.
You can let the data structure contain the available seats. Then you want to be able to get the lowest element and erase an element, in a reasonable time.
Ordered sets support these operations.