Fewest Rooms Needed for a Day of Sessions

Implement fewestRooms

A conference has a list of sessions, each with a start and an end time. A session occupies its room from its start up to (not including) its end, so a room can host a session that begins at the moment the previous one finishes. Find the smallest number of rooms that lets every session run at its scheduled time.

Scanning a list of rooms for a free one works, but a min-heap of end times always hands over the room that frees up first in O(log n).

Example 1:

Input: sessions = [[9,12],[1,4],[3,8],[4,6],[7,10],[11,15]]

Output: 2

Example 2:

Input: sessions = [[1,4],[4,6]]

Output: 1

Example 3:

Input: sessions = [[2,5],[2,5],[2,5],[2,5]]

Output: 4

+ 9 hidden test cases run on Submit.

Constraints:

  • ●1 ≤ sessions.length ≤ 12; each session is [start, end] with 0 ≤ start < end ≤ 40
  • ●A session occupies its room from start up to (not including) end, so a room can host a session that starts exactly when the previous one ends
  • ●Sessions may be assigned to any room. Return the fewest rooms that let every session run at its scheduled time

sessions =

[[9,12], [1,4], [3,8], [4,6], [7,10], [11,15]]