Skip to content

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.

Medium#1845
LeetCode Problem

Seat Reservation Manager

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

Input
["SeatManager","reserve","reserve","unreserve","reserve","reserve"]
[[3],[],[],[1],[],[]]
Output
[null,1,2,null,1,3]
Explanation

Seat 1 becomes the smallest available seat again after release.

Constraints

1 <= n <= 10^5
1 <= seatNumber <= n
Reserve and unreserve calls satisfy the stated availability guarantees.
At most 10^5 total calls.

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.