986. Interval List Intersections
mediumAsked at MetaGiven two sorted lists of disjoint intervals, return the intersection. Meta asks this to test whether you reach for the two-pointer pattern and articulate why it's O(m+n) instead of O(m*n).
By Alex Chen, Founder, InterviewChamp.AI · Last verified
Source citations
Public interview reports confirming this problem appears in Meta loops.
- Glassdoor (2026-Q1)— Meta E3/E4 onsite reports cite this as a recurring intervals problem.
- Blind (2025-12)— Recurring Meta interview question.
Problem
You are given two lists of closed intervals, firstList and secondList, where firstList[i] = [start_i, end_i] and secondList[j] = [start_j, end_j]. Each list of intervals is pairwise disjoint and in sorted order. Return the intersection of these two interval lists.
Constraints
0 <= firstList.length, secondList.length <= 1000firstList.length + secondList.length >= 10 <= start_i < end_i <= 10^9end_i < start_(i+1)0 <= start_j < end_j <= 10^9end_j < start_(j+1)
Examples
Example 1
firstList = [[0,2],[5,10],[13,23],[24,25]], secondList = [[1,5],[8,12],[15,24],[25,26]][[1,2],[5,5],[8,10],[15,23],[24,24],[25,25]]Example 2
firstList = [[1,3],[5,9]], secondList = [][]Approaches
1. Two-pointer sweep (optimal)
Two pointers i and j into the lists. At each step, compute the overlap of firstList[i] and secondList[j] (if any). Advance whichever interval ends first.
- Time
- O(m + n)
- Space
- O(m + n) for output
function intervalIntersection(firstList, secondList) {
const result = [];
let i = 0, j = 0;
while (i < firstList.length && j < secondList.length) {
const lo = Math.max(firstList[i][0], secondList[j][0]);
const hi = Math.min(firstList[i][1], secondList[j][1]);
if (lo <= hi) result.push([lo, hi]);
if (firstList[i][1] < secondList[j][1]) i++;
else j++;
}
return result;
}Tradeoff: Linear in the total length. Advancing whichever interval ends first is correct because once an interval is exhausted, it can't intersect any further intervals in the other list.
Meta-specific tips
Meta interviewers grade this on whether you articulate why the two-pointer approach is correct. State out loud: 'I advance the interval that ENDS first because it can't possibly intersect anything later — the other list's intervals are sorted by start.' Without that articulation, the algorithm looks like magic.
Common mistakes
- Computing the overlap as (lo, hi) without checking lo <= hi — produces invalid intervals when there's no overlap.
- Advancing both pointers (i++; j++;) on every iteration — skips valid intersections.
- Using strict inequality (<) instead of <= for the endpoint match — misses single-point intersections like [5,5].
Follow-up questions
An interviewer at Meta may pivot to one of these next:
- What if the lists weren't sorted?
- Merge Intervals (LC 56) — different problem class, also intervals.
- Meeting Rooms II (LC 253) — interval scheduling.
Solve it now
Free. No sign-up. Python and JavaScript run instantly in your browser.
FAQ
Why advance the one that ends first?
If interval A ends before interval B, A cannot overlap with any future interval in the other list (they're all later). So we move past A.
What if intervals were half-open instead of closed?
Replace <= with <. Closed intervals require <= because [5,5] is a valid one-point intersection.
Practice these live with InterviewChamp.AI
Drill Interval List Intersections and other Meta interview questions under real-loop conditions with instant feedback on your reasoning, complexity claims, and code.
Practice these live with InterviewChamp.AI →