LeetCode - Blind 75 - Meeting Rooms II

The problem Given an array of meeting time intervals intervals where intervals[i] = [starti, endi], return the minimum number of conference rooms required. Examples Input: intervals = [[0,30],[5,10],[15,20]] Output: 2 Input: intervals = [[7,10],[2,4]] Output: 1 Constraints 1 <= intervals.length <= 10^4 0 <= starti < endi <= 10^6 Explanation Before jumping to the code, we are going to sort the input because it’s not sorted by default. Sorting Solution func minMeetingRooms(_ intervals: [[Int]]) -> Int { let start = intervals.map({ $0[0] }).sorted() let end = intervals.map({ $0[1] }).sorted() var res = 0 var count = 0 var s = 0 var e = 0 let n = intervals.count while s < n { if start[s] < end[e] { s += 1 count += 1 } else { e += 1 count -= 1 } res = max(res, count) } return res } Explanation We can visualize input with intervals = [[0,30],[5,10],[15,20]] like this: ...

April 25, 2025 · 4 min · Dmytro Chumakov