FastPrepIntersect Two Interval Lists
Problems/Intersect Two Interval Lists

Intersect Two Interval Lists

Superhuman logoSuperhuman● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The source company label is Grammarly while the thread title says Superhuman. This item is placed under Superhuman for now and can be moved without changing either company record or the source history. The source described only a variant of the well-known Interval List Intersections problem, so the rules below are our reading: closed intervals, sorted, and no two in the same list overlap. Our version is about 70% the same as the reported question.

You are given two lists of closed integer intervals, firstList and secondList. Within each list, intervals are sorted by start value and are pairwise disjoint.

Return every nonempty intersection between an interval in firstList and an interval in secondList, ordered by increasing position.

For two closed intervals [a, b] and [c, d], their intersection is nonempty when max(a, c) <= min(b, d), including intersections consisting of one endpoint.

Function

intervalIntersections(firstList: int[][], secondList: int[][]) → int[][]

Examples

Example 1

firstList = [[0,2],[5,10],[13,23],[24,25]]secondList = [[1,5],[8,12],[15,24],[25,26]]return = [[1,2],[5,5],[8,10],[15,23],[24,24],[25,25]]

Each output interval is the overlap of the current pair. Endpoint-only overlaps such as [5,5] are included because the intervals are closed.

Example 2

firstList = [[1,3],[5,9]]secondList = []return = []

There can be no intersections when one list is empty.

Example 3

firstList = [[-3,0],[4,7]]secondList = [[0,4],[8,10]]return = [[0,0],[4,4]]

The first two pairs touch at 0 and 4. The final intervals do not overlap.

Constraints

  • 0 <= firstList.length, secondList.length <= 10^5.
  • Every interval has exactly two signed 32-bit integer endpoints [start, end] with start <= end.
  • Within each list, intervals are sorted by start and pairwise disjoint.
  • Return intersections in ascending order.
  • Your traversal should run in O(n + m) time apart from output storage.

More Superhuman interview questions

  • Email Funnel: Opened Within a Day, Replied Within a WeekPHONE SCREEN · Seen Nov 2026
  • Find the First Target IndexPHONE SCREEN · Seen Jul 2026
  • Deep Copy a Random-Pointer ListPHONE SCREEN
  • Deep Copy a Singly Linked ListPHONE SCREEN
  • Recover a Tree from Preorder Depth EncodingPHONE SCREEN
  • Reverse a Singly Linked ListPHONE SCREEN
  • Longest Distinct StringOA · Seen Sep 2026
  • Minimum Time on Two ProcessorsOA · Seen Sep 2026
  • Top Mutual-Friend RecommendationsOA · Seen Sep 2026
  • Lost MessagesOA · Seen Apr 2026

Similar questions at other companies

  • Meeting Rooms IIUber · PHONE SCREENUber interview questions
  • Meeting Rooms IIAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • Common Camera Motion IntervalsVerkada · PHONE SCREENVerkada interview questions
  • Intersect Two Sorted Interval ListsByteDance · PHONE SCREENByteDance interview questions
  • Meeting Rooms IIWalmart · PHONE SCREENWalmart interview questions
  • Find Shared Camera Activity PeriodsServal · PHONE SCREEN
  • Earliest Common Meeting SlotAdobe · PHONE SCREENAdobe interview questions
  • Intersections of Two Interval ListsDatadog · PHONE SCREENDatadog interview questions
  • Interval List IntersectionsGoogle · ONSITE INTERVIEWGoogle interview questions
  • Minimum Machines for TasksExpedia · OAExpedia interview questions
All Superhuman interview questionsSee Superhuman hiring insights
Saved
class Solution {
    public int[][] intervalIntersections(int[][] firstList, int[][] secondList) {
      // write your code here
    }
}
Checking account…