Assign Meetings to the Minimum Number of Rooms

Quick Overview

Assign meetings to the minimum number of rooms while returning a deterministic room ID for every original interval. Use priority queues to release all eligible rooms, reuse the smallest free ID, and preserve half-open interval semantics.

Assign Meetings to the Minimum Number of Rooms

Company: Uber

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

Implement `assign_meeting_rooms(intervals)`. Each interval is `[start, end)`, so a room used by a meeting ending at time `t` is available to another meeting starting at `t`. Return one flat integer list `[room_count, room_for_meeting_0, room_for_meeting_1, ...]`. The first value is the minimum number of rooms required, and each following value is the nonnegative room ID assigned to the interval at that original input index. The output must be deterministic: - Process meetings by increasing start time, then increasing end time, then original index. - Reuse the smallest room ID that is free at the meeting's start. - If no room is free, allocate the next unused room ID. Every interval has `start < end`. ```hint Track two priorities One priority queue can identify which occupied room becomes free next, while a second can return the smallest currently available room ID. ``` ```hint Free all eligible rooms Before assigning a meeting, release every room whose previous meeting has already ended, not only the earliest one. ``` ### Discussion Extensions - If only the minimum room count were required, how would a sweep line solve the problem? - What changes if intervals arrive as a stream and cannot first be globally sorted?

Quick Answer: Assign meetings to the minimum number of rooms while returning a deterministic room ID for every original interval. Use priority queues to release all eligible rooms, reuse the smallest free ID, and preserve half-open interval semantics.

|Home/Coding & Algorithms/Uber
Uber logo
Uber
Aug 16, 2026, 12:00 AM
mediumSoftware EngineerOnsiteCoding & Algorithms
0
0

Implement assign_meeting_rooms(intervals). Each interval is [start, end), so a room used by a meeting ending at time t is available to another meeting starting at t.

Return one flat integer list [room_count, room_for_meeting_0, room_for_meeting_1, ...]. The first value is the minimum number of rooms required, and each following value is the nonnegative room ID assigned to the interval at that original input index.

The output must be deterministic:

  • Process meetings by increasing start time, then increasing end time, then original index.
  • Reuse the smallest room ID that is free at the meeting's start.
  • If no room is free, allocate the next unused room ID.

Every interval has start < end.

Discussion Extensions

  • If only the minimum room count were required, how would a sweep line solve the problem?
  • What changes if intervals arrive as a stream and cannot first be globally sorted?

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...