1845. Seat Reservation Manager
1845. Seat Reservation Manager
Description
Difficulty: Medium
Related Topics: Design, Heap (Priority Queue)
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 aSeatManager
object that will managen
seats numbered from1
ton
. 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 givenseatNumber
.
Example 1:
1 | Input |
Constraints:
- 1 <= n <= 105
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 thatseatNumber
will be reserved. - At most 105 calls in total will be made to
reserve
andunreserve
.
Hints/Notes
- priority queue
Solution
Language: C++
1 | class SeatManager { |