KatInterview

Busiest Conference Room Tracker

Heaps, Sorting & SearchAuto-graded · 22 test cases
MediumAuto-gradedHeaps, Sorting & Searchheapsimulationgreedy

Last updated

Tests the ability to simulate event scheduling with delayed assignments using two priority queues to track which resource handles the most requests.

Problem Statement

A building has num_rooms conference rooms, numbered 0 through num_rooms - 1. You are given a list of bookings, where bookings[i] = [start_i, end_i] describes a session that was originally requested to run from time start_i up to (but not including) time end_i.

The building's scheduling system assigns sessions to rooms using the following policy:

  1. Sessions are processed in ascending order of their requested start times. No two sessions share the same requested start time.
  2. A session is placed in the lowest-numbered room that is free at or before the session's requested start time.
  3. If every room is still occupied when a session's turn comes up, that session is postponed until the earliest moment a room opens. The session keeps its original length (end_i - start_i) even though it starts late.
  4. When two or more rooms open at the same moment, the waiting session goes to the one with the lowest number.
  5. If multiple sessions are waiting, they are assigned in the order of their original requested start times.

Return the number of the room that hosted the greatest number of sessions overall. If two or more rooms are tied for the most sessions, return the one with the smallest number.

Constraints

  • 1 <= num_rooms <= 100
  • 1 <= len(bookings) <= 10^5
  • bookings[i].length == 2
  • 0 <= start_i < end_i <= 10^9
  • All start_i values are distinct.

Examples

Example 1

Input: busiest_conference_room(2, [[0, 10], [1, 5], [2, 7], [3, 4]])

Output: 0

Example 2

Input: busiest_conference_room(3, [[1, 20], [2, 10], [3, 5], [4, 9], [6, 8]])

Output: 1

Hints

Hint 1

Sort the bookings by start time first. Then think about what ordering you need when picking a free room versus when picking among occupied rooms — are those the same ordering?

Hint 2

A min-heap of free room indices gives you the lowest-numbered available room in O(log n). A separate min-heap of (finish_time, room_index) tuples gives you the room that opens soonest, with ties broken by index automatically.

Hint 3

When a session must be delayed, the new finish time is earliest_release + (end - start), not just `end`. Also remember to release rooms whose finish time is <= the current session's start time before deciding whether any room is free.