Leetcode 253 Meeting Rooms II

Gary Chiang
1 min readNov 1, 2021

--

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

[Java]

  1. use array sort to sort the meeting start time
  2. create a priorityqueue as min heap, peek interval would be the earliest ending time
  3. offer the first interval, and loop for the rest of intervals
  4. poll from the priorityqueue(which is the earliest ending time), if the next interval start after the this interval, merge it into the the current one.
  5. or if the current interval and next interval had overlap time, will need to add another room, add it into the queue
  6. return the pq.size

--

--

Gary Chiang
Gary Chiang

Written by Gary Chiang

CS new grad, 6 years experience related to supply chain management. Located in Bay area

No responses yet