Intersect Two Sorted Lists of Disjoint Closed Intervals
Company: Meta
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Other
### Problem
Each input list contains sorted, pairwise disjoint closed intervals. Return all nonempty intersections between the two lists, in their natural left-to-right order. Closed endpoints count as included, so an intersection may be a single point `[x,x]` even though each input interval has positive length.
```cpp
class Solution {
public:
vector<vector<int>> intervalIntersection(vector<vector<int>>& firstList, vector<vector<int>>& secondList);
};
```
### Examples
**Example 1:**
```text
Input: firstList = [[0,3],[6,9]], secondList = [[3,7]]
Output: [[3,3],[6,7]]
Explanation: The first contact is the shared endpoint3; the second overlap runs from6 through7.
```
**Example 2:**
```text
Input: firstList = [], secondList = [[2,4]]
Output: []
Explanation: An empty list contributes no overlap.
```
### Constraints
- `0 <= firstList.length,secondList.length <= 1000`.
- Their combined length is at least1.
- Every input interval has `0 <= start < end <= 10^9`.
- Within each list, every end is strictly less than the next start.
### Contract considerations
Within each input list, the end of an interval is strictly less than the next start.
```hint Read the boundary condition
After comparing two intervals, the one that ends first cannot help with any future interval in the other list.
```
### Boundary reminders
Within each input list, the end of an interval is strictly less than the next start.
Overview: Intersect Two Sorted Lists of Disjoint Closed Intervals. Each input list contains sorted, pairwise disjoint closed intervals.
Intersect Two Sorted Lists of Disjoint Closed Intervals
Meta
Aug 30, 2026
mediumSoftware EngineerOtherCoding & Algorithms
0
0
Problem
Each input list contains sorted, pairwise disjoint closed intervals. Return all nonempty intersections between the two lists, in their natural left-to-right order. Closed endpoints count as included, so an intersection may be a single point [x,x] even though each input interval has positive length.
class Solution {
public:
vector<vector<int>> intervalIntersection(vector<vector<int>>& firstList, vector<vector<int>>& secondList);
};
Examples
Example 1:
Input: firstList = [[0,3],[6,9]], secondList = [[3,7]]
Output: [[3,3],[6,7]]
Explanation: The first contact is the shared endpoint3; the second overlap runs from6 through7.
Example 2:
Input: firstList = [], secondList = [[2,4]]
Output: []
Explanation: An empty list contributes no overlap.
Constraints
0 <= firstList.length,secondList.length <= 1000
.
Their combined length is at least1.
Every input interval has
0 <= start < end <= 10^9
.
Within each list, every end is strictly less than the next start.
Contract considerations
Within each input list, the end of an interval is strictly less than the next start.
Boundary reminders
Within each input list, the end of an interval is strictly less than the next start.