Meeting Rooms II in Java: Explanation & Practice
Minimum number of conference rooms required
Problem summary
Given an array of meeting time intervals, find the minimum number of conference rooms required. Use min-heap to track end times.
Starter code
public class Main {
public static void main(String[] args) {
int[][] intervals = {{0,30},{5,10},{15,20}};
// Sort by start time
// Min-heap tracks earliest ending meeting
// If new meeting starts after earliest end, reuse room
// Print: Rooms: 2
}
}Expected output and test cases
- [[0,30],[5,10],[15,20]]
Rooms: 2
- [[7,10],[2,4]] → no overlap
Rooms: 1
- All overlap → 3 rooms
Rooms: 3
Hints
- Sort meetings by start time
- Min-heap tracks end times of ongoing meetings
- If new meeting starts after heap top, reuse room (poll and add new end)
- Otherwise, need new room (just add new end)
Related Data Structures & Algorithms exercises
Practice all Data Structures & Algorithms exercises · Run this idea in the Java compiler