LeetCode - Blind 75 - Rotate Image

The problem You are given an n x n 2D matrix representing an image, rotate the image by 90 degrees (clockwise). You have to rotate the image in-place, which means you have to modify the input 2D matrix directly. DO NOT allocate another 2D matrix and do the rotation. Examples Input: matrix = [[1,2,3],[4,5,6],[7,8,9]] Output: [[7,4,1],[8,5,2],[9,6,3]] Input: matrix = [[5,1,9,11],[2,4,8,10],[13,3,6,7],[15,14,12,16]] Output: [[15,13,2,5],[14,3,4,1],[12,6,8,9],[16,7,10,11]] Constraints n == matrix.length == matrix[i].length 1 <= n <= 20 -1000 <= matrix[i][j] <= 1000 Explanation Before we jump to the solution, let’s look at how rotation was done to the matrix = [[1,2,3],[4,5,6],[7,8,9]]. ...

April 28, 2025 · 3 min · Dmytro Chumakov

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

LeetCode - Blind 75 - Meeting Rooms

The problem Given an array of meeting time intervals where intervals[i] = [starti, endi], determine if a person could attend all meetings. Examples Input: intervals = [[0,30],[5,10],[15,20]] Output: false Input: intervals = [[7,10],[2,4]] Output: true Constraints 0 <= intervals.length <= 10^4 intervals[i].length == 2 0 <= starti < endi <= 10^6 Explanation Before we dive into coding, let’s look at base cases in which intervals are not overlapping. ...

April 22, 2025 · 3 min · Dmytro Chumakov

LeetCode - Blind 75 - Non-overlapping Intervals

The problem Given an array of intervals where intervals[i] = [starti, endi], return the minimum number of intervals you need to remove to make the rest of the intervals non-overlapping. Note that intervals which only touch at a point are non-overlapping. For example, [1, 2] and [2, 3] are non-overlapping. Examples Input: intervals = [[1,2],[2,3],[3,4],[1,3]] Output: 1 Explanation: [1,3] can be removed and the rest of the intervals are non-overlapping. Input: intervals = [[1,2],[1,2],[1,2]] Output: 2 Explanation: You need to remove two [1,2] to make the rest of the intervals non-overlapping. Input: intervals = [[1,2],[2,3]] Output: 0 Explanation: You don't need to remove any of the intervals since they're already non-overlapping. Constraints 1 <= intervals.length <= 10^5 intervals[i].length == 2 -5 * 10^4 <= starti < endi <= 5 * 10^4 Explanation Before we dive into coding, let’s figure out the definition of overlapping intervals for this problem. ...

April 20, 2025 · 4 min · Dmytro Chumakov

LeetCode - Blind 75 - Merge Intervals

The problem Given an array of intervals where intervals[i] = [starti, endi], merge all overlapping intervals, and return an array of the non-overlapping intervals that cover all the intervals in the input. Examples Input: intervals = [[1,3],[2,6],[8,10],[15,18]] Output: [[1,6],[8,10],[15,18]] Explanation: Since intervals [1,3] and [2,6] overlap, merge them into [1,6]. Input: intervals = [[1,4],[4,5]] Output: [[1,5]] Explanation: Intervals [1,4] and [4,5] are considered overlapping. Constraints 1 <= intervals.length <= 10^4 intervals[i].length == 2 0 <= starti <= endi <= 10^4 Explanation Let’s look at examples and figure out our base cases for intervals that are considered overlapping. ...

April 18, 2025 · 2 min · Dmytro Chumakov