Young Devs Bin
๐Ÿ“ Today I Learned

Meeting Rooms III: Two Heaps, One Delayed Start

ยท2 min readยท#today-i-learned#algorithm#heap#sweep-line#leetcode#python

Closed out the interval family with Meeting Rooms III โ€” same sweep, but now the answer needs a specific room number, not just a count.

  • Two heaps instead of one: available (min-heap of empty room ids, so "lowest free room" is a peek away) and busy (min-heap of (end_time, room_id), same pairing trick as the Meeting Rooms II room-assignment follow-up)
  • Releasing finished rooms into available needs a while loop, not an if โ€” same reasoning as yesterday's Car Pooling: more than one room can finish in the gap between two meetings' start times
  • The trap: when no room is free, the meeting waits for whichever room frees up soonest, but keeps its ORIGINAL duration โ€” freeAt + duration, not freeAt + end and not the original end. Easy to grab the wrong variable here
  • count[roomId] += 1 works safely right after the if/else because both branches set roomId before that line runs โ€” whichever branch fired, the count always matches the room actually picked
  • Folded this into the existing Interval Family post instead of a standalone one โ€” it's the same sweep-line family as Merge Intervals through Car Pooling, just with a second heap added for identity