Nested Ranges Check

You are given a 2D array ranges where ranges[i] = [x, y] represents an inclusive interval from x to y.

A range A = [a, b] contains another range B = [c, d] if a <= c and d <= b.

Your task is to determine two things for every range in the exact order they were given:

  • Does it contain at least one other range?
  • Is it contained by at least one other range?

Return a 2D integer array of size 2 x ranges.length. The first row should contain 1s and 0s representing the answer to the first question for each range. The second row should represent the answers to the second question.

Example 1:

Input: ranges = [[1, 6], [2, 4], [4, 8], [3, 6]]

Output: [[1, 0, 0, 0], [0, 1, 0, 1]]

Explanation:

[1, 6] contains [2, 4] and [3, 6]. [4, 8] doesn't interact with the others.

Example 2:

Input: ranges = [[1, 2], [3, 4]]

Output: [[0, 0], [0, 0]]

Explanation:

No ranges overlap at all.

Now Your Turn!

Pick the correct output for the given input

Input: ranges = [[2, 5], [2, 8]]

Still unsure what the problem is asking ?

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

Constraints:

  • 1 <= ranges.length <= 200,000
  • ranges[i].length == 2
  • 1 <= ranges[i][0] < ranges[i][1] <= 109
  • All provided ranges are strictly unique.

Hints

Frequently Occurring Doubts

Interview Follow-up Questions

Fun Facts

0
class Solution {
public:
vector<vector<int>> checkRanges(vector<vector<int>>& ranges) {
}
};
Test Case

Input:

Ranges