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. ...
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. ...
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. ...
LeetCode - Blind 75 - Insert Interval
The problem You are given an array of non-overlapping intervals intervals where intervals[i] = [starti, endi] represents the start and the end of the ith interval, and intervals is sorted in ascending order by starti. You are also given an interval newInterval = [start, end] that represents the start and end of another interval. Insert newInterval into intervals such that intervals is still sorted in ascending order by starti and intervals still does not have any overlapping intervals (merge overlapping intervals if necessary). ...
LeetCode - Blind 75 - Jump Game
The problem You are given an integer array nums. You are initially positioned at the array’s first index, and each element in the array represents your maximum jump length at that position. Return true if you can reach the last index, or false otherwise. Examples Input: nums = [2,3,1,1,4] Output: true Explanation: Jump 1 step from index 0 to 1, then 3 steps to the last index. Input: nums = [3,2,1,0,4] Output: false Explanation: You will always arrive at index 3 no matter what. Its maximum jump length is 0, which makes it impossible to reach the last index. Constraints 1 <= nums.length <= 10⁴ 0 <= nums[i] <= 10⁵ Explanation From the description of the problem, we learn that we start from the start index, and for every element in the array, the number at the position represents the max jump length that we can perform at every single position. Basically, this means for input with nums = [2,3,1,1,4] ...