You are given a list of meeting time intervals.
Each interval is provided as a string in the format "start,end", where start is the meeting start time and end is the meeting end time. You need to split each interval string and extract the integer values start and end.
Each interval is half-open, represented as [start, end). This means a meeting ending at time x does not overlap with another meeting starting at time x. For example, [1, 3) does not overlap with [3, 5).
Your task is to determine the minimum number of meeting rooms required so that no two overlapping meetings are placed in the same meeting room.
Method Signature
Find Minimum Rooms
int minRooms(List<String> intervals)
intervals is a list of strings, where each string is formatted as "start,end".
- Each string contains exactly two integer values separated by a comma with no spaces.
- The method should return the minimum number of meeting rooms required to schedule all meetings.
- No parameter value will be
null.
Interval Rules
- Each interval is treated as a half-open interval
[start, end).
- If one meeting ends at time
t and another meeting starts at time t, they do not overlap.
- Intervals may be given in any order.
- Multiple meetings may start or end at the same time.
Constraints
1 ≤ intervals.size() ≤ 12000
0 ≤ start < end ≤ 100000
- Each interval string is formatted as
"start,end".
- Intervals may overlap in any order.
- No value inside
intervals will be null.
Examples
Example 1
minRooms(intervals = List.of("1,4", "2,5", "3,6"))
Output: 3
Explanation: All three meetings overlap during the time range [3, 4), so three meeting rooms are required.
Example 2
minRooms(intervals = List.of("1,3", "3,6", "6,9"))
Output: 1
Explanation: Since the intervals are half-open, [1, 3) does not overlap with [3, 6), and [3, 6) does not overlap with [6, 9). One meeting room is enough.
Example 3
minRooms(intervals = List.of("10,20", "1,5", "6,9", "4,8"))
Output: 2
Explanation: The intervals [1, 5) and [4, 8) overlap, so at least two meeting rooms are needed. The other intervals can reuse available meeting rooms.
Example 4
minRooms(intervals = List.of("0,100", "10,20", "20,30", "30,40"))
Output: 2
Explanation: The long meeting [0, 100) overlaps with each shorter meeting. However, the shorter meetings do not overlap with each other because each one starts when the previous one ends.