253. Meeting Rooms II

SValakatte
1 min readMay 31, 2022

--

Given an array of meeting time intervals intervals where intervals[i] = [starti, endi], return the minimum number of conference rooms required.

Example 1:

Input: intervals = [[0,30],[5,10],[15,20]]
Output: 2

Example 2:

Input: intervals = [[7,10],[2,4]]
Output: 1

Constraints:

  • 1 <= intervals.length <= 104
  • 0 <= starti < endi <= 106

Intuition

We need to be able to find out efficiently if a room is available or not for the current meeting and assign a new room only if none of the assigned rooms is currently free.

[ (1,10), (2,7), (3,19), (8,12), (10,20)]

start timings : 1, 2, 3, 8, 10

end timings : 7, 10, 12, 19, 20

start_pointer on 1st element of start timings and end_pointer on 1st element of end timings.

1 > 7 => No , so assign a new room
2 > 7 => No, so assign a new room
3 > 7 => No, so assign a new room
8 > 7 => Yes, no need to assign new room, just increment end_pointer

--

--

SValakatte
SValakatte

Written by SValakatte

Passionate about problem solving; #VoraciousReader #MBTIEnthusiast #LovePsychology

No responses yet