Practice Seat Reservation Manager
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
SeatManager(n) initially has seats 1 through n available. reserve() occupies and returns the smallest unreserved seat. unreserve(seatNumber) releases a reserved seat. Each reserve has an available seat, and each released seat is currently reserved. Practice approach: Use a min-heap of released seats plus a pointer to the smallest never-reserved seat. Prefer the heap when it is nonempty. This avoids initially inserting all n seats and gives O(log n) release/reuse operations. Test reusing a low-numbered seat before allocating a new one.
Source: Seat Reservation Manager on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
["SeatManager","reserve","reserve","unreserve","reserve","reserve"] [[3],[],[],[1],[],[]]
[null,1,2,null,1,3]
Seat 1 becomes the smallest available seat again after release.
Constraints
Related LeetCode Problems
Practice more problems similar to Seat Reservation Manager.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.