Problem: Meeting Rooms II

Posted by Marcy on February 18, 2015

Question

Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] (si < ei), find the minimum number of conference rooms required.

For example, Given [[0, 30],[5, 10],[15, 20]], return 2.

Solution

TODO

Code

class Solution {
    public int minMeetingRooms(Interval[] intervals) {
        Arrays.sort(intervals, (i1, i2) -> i1.start - i2.start);
        PriorityQueue<Integer> pq = new PriorityQueue<Integer>();
        for(Interval i:intervals) {
            if(!pq.isEmpty() && pq.peek() <= i.start) {
                pq.poll();
            }
            pq.offer(i.end);
        }
        
        return pq.size();
    }
}

Performance

TODO