🚀
End of Year Sale: Use Coupon Code
END2025
to Get Extra
25% Off
.
12
DAYS
:
01
HOURS
:
32
MINUTES
:
19
SECONDS
Claim Now
✕
Leetcode Problem 855. Exam Room
855. Exam Room
AI Mock Interview
Leetcode Solutions
Priority Queue Approach
Solution Idea
Algorithm Steps
Code Implementation
Complexity Analysis
Initialize a priority queue that orders gaps by their size and starting position.
When seating a student, pop the largest gap from the queue.
Place the student in the middle of the gap (or at the start/end if the gap includes the first/last seat).
Push the new gaps created by seating the student back into the queue.
When a student leaves, remove the corresponding seat and merge adjacent gaps if necessary before pushing them back into the queue.
Ordered List Approach
Ask Question
Programming Language
Purpose:
General Question
Debug My Code
image/screenshot of info
(optional)
[+]
Full Screen
Loading...
Get Answer
Suggested Answer
Answer
Full Screen
Copy Answer Code
Loading...