🚀

End of Year Sale: Use Coupon Code END2025 to Get Extra 25% Off.

12DAYS
:
03HOURS
:
19MINUTES
:
29SECONDS

Leetcode Problem 855. Exam Room

855. Exam Room

Leetcode Solutions

Priority Queue Approach

  1. Initialize a priority queue that orders gaps by their size and starting position.
  2. When seating a student, pop the largest gap from the queue.
  3. Place the student in the middle of the gap (or at the start/end if the gap includes the first/last seat).
  4. Push the new gaps created by seating the student back into the queue.
  5. When a student leaves, remove the corresponding seat and merge adjacent gaps if necessary before pushing them back into the queue.
UML Thumbnail

Ordered List Approach

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...