Interval List Intersections
Updated
Problem statement
firstList and secondList are lists of intervals that include both endpoints. Within each list, intervals do not overlap and are sorted by start.
Return every nonempty intersection between an interval from the first list and an interval from the second list, in sorted order. If two intervals share only an endpoint, include that point as an interval.
Function
intervalListIntersections(firstList: int[][], secondList: int[][]) → int[][]Examples
Example 1
firstList = [[0,2],[5,10]]secondList = [[1,5],[8,12]]return = [[1,2],[5,5],[8,10]]The intervals overlap at [1,2], the shared endpoint 5, and [8,10].
Example 2
firstList = []secondList = [[1,3]]return = []An empty list has no intersections.
Example 3
firstList = [[1,7]]secondList = [[2,3],[5,6]]return = [[2,3],[5,6]]Both second-list intervals lie inside [1,7].
Constraints
0 <= firstList.length, secondList.length <= 100000.-1000000000 <= start <= end <= 1000000000.- Each list is sorted by start and internally pairwise disjoint.
More Google Onsite Interview questions
- Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Distinct Subset SumsONSITE INTERVIEW · Seen Nov 2026
- Playlist With No Same Artist in a RowONSITE INTERVIEW · Seen Nov 2026
- Delete Nodes and Return Forest RootsONSITE INTERVIEW · Seen Nov 2026
- Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- First and Last Target Position in a Mountain ArrayONSITE INTERVIEW · Seen Nov 2026
- Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- 0/1 Knapsack with Weight and Volume LimitsONSITE INTERVIEW · Seen Nov 2026
- Batched Subsequence Word MatchesONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Meeting Rooms IIAmazon · PHONE SCREEN · ONSITE INTERVIEW
- Meeting Rooms IIUber · PHONE SCREENUber interview questions
- Common Camera Motion IntervalsVerkada · PHONE SCREENVerkada interview questions
- Intersect Two Sorted Interval ListsByteDance · PHONE SCREENByteDance interview questions
- Meeting Rooms IIWalmart · PHONE SCREENWalmart interview questions
- Intersect Two Interval ListsSuperhuman · PHONE SCREENSuperhuman interview questions
- Find Shared Camera Activity PeriodsServal · PHONE SCREEN
- Most Employees Working at OnceCitadel · OACitadel interview questions
- Minimum Machines for TasksExpedia · OAExpedia interview questions
- Earliest Common Meeting SlotAdobe · PHONE SCREENAdobe interview questions