Seat Reservation Manager Problem

Seat Reservation Manager Problem — ExecCode Medium DSA Practice

Solve the Seat Reservation Manager problem on ExecCode. Free online medium DSA practice in Heap. Write and run code in Java, C++, Python — no signup required to run.

Problem description

Description Design a system that manages the reservation state of n seats that are numbered from 1 to n. Implement the SeatManager class: SeatManager(int n) Initializes a SeatManager object that will manage n seats numbered from 1 to n. All seats are initially available. int reserve() Fetches the smallest-numbered unreserved seat, reserves it, and returns its number. void unreserve(int seatNumber) Unreserves the seat with the given seatNumber. Constraints 1 <= n <= 10^5 1 <= seatNumber <= n For each call to reserve, it is guaranteed that there will be at least one unreserved seat. For each call to unreserve, it is guaranteed that seatNumber will be reserved. At most 10^5 calls in total will be made to reserve and unreserve.

Examples

Input {"data": "3\nreserve\nreserve\nreserve"}; Output 1 2 Input {"data": "5\nreserve\nunreserve 1\nreserve"}; Output 1 Input {"data": "SeatManager(5); reserve(); reserve(); unreserve(2); reserve()"}; Output 1 2 2

Constraints

1 <= n <= 10^5 1 <= seatNumber <= n For each call to reserve, it is guaranteed that there will be at least one unreserved seat. For each call to unreserve, it is guaranteed that seatNumber will be reserved. At most 10^5 calls in total will be made to reserve and unreserve.

Practice Seat Reservation Manager free on ExecCode. Browse DSA problems, topic map, and placement guides.