Back to DSA
Meeting Rooms II
mediumGiven a list of meeting time intervals [start, end], determine the fewest meeting rooms needed so that no two overlapping meetings share a room.
Examples
Example 1:
Input:
intervals = [[0,25],[5,15],[10,20]]Output:
2 Example 2:
Input:
intervals = [[3,8],[9,14]]Output:
1Hints
import java.util.*;
class Solution {
public int minMeetingRooms(int[][] intervals) {
Arrays.sort(intervals, (a, b) -> a[0] - b[0]);
PriorityQueue<Integer> pq = new PriorityQueue<>();
for (int[] i : intervals) {
if (!pq.isEmpty() && pq.peek() <= i[0]) pq.poll();
pq.offer(i[1]);
}
return pq.size();
}
}Time complexity
O(n log n)Space complexity
O(n)