Skip to content

Latest commit

 

History

History
29 lines (24 loc) · 1002 Bytes

Meeting Rooms II.md

File metadata and controls

29 lines (24 loc) · 1002 Bytes

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

Screen Shot 2021-09-14 at 4 45 53 PM

Screen Shot 2021-09-14 at 5 07 44 PM

/**
 * @param {number[][]} intervals
 * @return {number}
 */
var minMeetingRooms = function(intervals) {
    if(!intervals.length) return 0;
    let rooms = 0;
    let end = 0;
    let starts = intervals.map(a => a[0]).sort((a, b) => a - b);
    let ends = intervals.map(a => a[1]).sort((a, b) => a - b);
    
    for(let i = 0; i < intervals.length; i++) {
        if(starts[i] < ends[end]) {
            rooms++;
        } else {
            end++;
        }
    }
    return rooms;
};