253. Meeting Rooms II

T: O(nlogn)

S: O(n)

class Solution {
    private static final int START = 1;
    private static final int END = -1;
    public int minMeetingRooms(int[][] intervals) {
        
        TreeMap<Integer, Integer> map = new TreeMap<>();
        for (int[] interval : intervals) {
            map.put(interval[0], map.getOrDefault(interval[0], 0) + START);
            map.put(interval[1], map.getOrDefault(interval[1], 0) + END);
        }
        
        int max = 0;
        int num = 0;
        for (int value : map.values()) {
            num += value;
            max = Math.max(max, num);
        }
        return max;
    }
}

Last updated