1845. Seat Reservation Manager
https://leetcode.com/problems/seat-reservation-manager
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 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:
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 toreserve
andunreserve
.
ac
Last updated