Interval List Intersection Problem
You are provided with two sorted lists of closed intervals, INTERVAL1
and INTERVAL2
. A closed interval [x, y] (x < y) signifies the set of real numbers z such that x <= z <= y.
Your task is to find the intersections of these two interval lists.
The intersection of two closed intervals is a set of real numbers represented as a closed interval or an empty set. For instance, the intersection of [0, 2] and [1, 3] is [1, 2].
Input:
The first line contains an integer 'T', which represents the number of test cases. Each test case consists of:
- First line with two integers 'N1' and 'N2', indicating the sizes of 'INTERVAL1' and 'INTERVAL2'.
- Second line with '2 * N1' integers representing the intervals in 'INTERVAL1'.
- Third line with '2 * N2' integers representing the intervals in 'INTERVAL2'.
Output:
For each test case, output a list or array containing the intervals of intersections of 'INTERVAL1' and 'INTERVAL2'.
Output each test case result on a new line.
Example:
Input:
INTERVAL1 = [[0, 5], [7, 9], [10, 11]]
INTERVAL2 = [[0, 2], [3, 7], [12, 15]]
Output:
[[0, 2], [3, 5], [7, 7]]
Constraints:
- 1 <= T <= 100
- 0 <= N1 <= 5000
- 0 <= N2 <= 5000
- 0 <= INTERVAL1[i][0] <= 105
- INTERVAL1[i][0] < INTERVAL1[i][1] <= 105
- 0 <= INTERVAL2[i][0] <= 105
- INTERVAL2[i][0] < INTERVAL2[i][1] <= 105
Note:
Your implementation should not print anything. Just implement the function to return the result.

AnswerBot
10d

Find the intersections of two sorted lists of closed intervals.
Iterate through both interval lists to find intersections
Compare the intervals and find the common range
Handle cases where there is no in...read more

Help your peers!
Add answer anonymously...
Top American Express Software Developer Intern interview questions & answers
Popular interview questions of Software Developer Intern
>
American Express Software Developer Intern Interview Questions
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app