819. Remove Interval

Given a sorted list of non-overlapping intervals, where intervals[i] = [starti, endi] represent the start and end of the i-th interval. You are also given an interval toBeRemoved = [startr, endr].

Remove all portions of intervals that overlap with toBeRemoved, and return the result as a new list of non-overlapping intervals.

Example 1:

Input: intervals = [[0,2],[3,4],[5,7]], toBeRemoved = [1,6]

Output: [[0,1],[6,7]]

Explanation:

[0,2] → [0,1] (because [1,2] is removed)

[3,4] → completely removed

[5,7] → [6,7] (because [5,6] is removed)

Example 2:

Input: intervals = [[0,5]], toBeRemoved = [2,3]

Output: [[0,2],[3,5]]

Explanation:

[0,5] → Split into [0,2] and [3,5] (removing [2,3])

Now Your Turn!

Pick the correct output for the given input

Input: intervals = [[5, 10], [15, 20]] and toBeRemoved = [7, 18]

Still unsure what the problem is asking ?

Let’s go through a few more examples, step by step, to make it clearer.

Constraints:

  • 1 <= intervals.length <= 104
  • -109 <= ai < bi <= 109

Hints

Frequently Occurring Doubts

Interview Follow-up Questions

Fun Facts

0
class Solution {
public:
vector<vector<int>> removeInterval(vector<vector<int>>& intervals, vector<int>& toBeRemoved) {
//Your Code Goes Here
}
};
Test Case

Input:

Intervals
To Be Removed