FastPrepInterval List Intersections
Problems/Interval List Intersections

Interval List Intersections

Grammarly logoGrammarly● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The interview report names an interval-intersection variant, but leaves out the variant's rule and the interval conventions. We use the usual closed-interval base task. Our version is about 82% 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 and pairwise disjoint.

Return every nonempty intersection between an interval in firstList and an interval in secondList, ordered by increasing start. Because the input lists are internally disjoint, the returned intersections are also pairwise disjoint.

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 returned interval is the closed overlap of one interval from each list. Endpoint-only overlaps such as [5,5] are nonempty.

Example 2

firstList = [[1,3],[6,8]]secondList = [[4,5],[9,10]]return = []

No interval from one list overlaps an interval from the other.

Example 3

firstList = []secondList = [[2,7]]return = []

An empty list has no intersections.

Constraints

  • 0 <= firstList.length, secondList.length <= 100000.
  • Every interval has exactly two integers [start, end] with start <= end.
  • Within each list, intervals are sorted by start and satisfy intervals[i][1] < intervals[i + 1][0].
  • Every endpoint is a signed 32-bit integer.

More Grammarly interview questions

  • Recover a Tree From Preorder TraversalPHONE SCREEN · Seen Nov 2026
  • First Target IndexPHONE SCREEN · Seen Jul 2026
  • Transactional Key-Value StoreONSITE INTERVIEW · Seen Aug 2026

Similar questions at other companies

  • Merge Sorted Squares of Two ArraysWhatNot · PHONE SCREEN · ONSITE INTERVIEWWhatNot interview questions
  • Run-Length Encoded Vector Dot ProductMeta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions
  • Subarray Product Less Than KApple · PHONE SCREENApple interview questions
  • 3SumAmazon · PHONE SCREEN
  • Subarray Product Less Than KAngel One · PHONE SCREEN
  • Subarray Product Less Than KThe D.E. Shaw Group · PHONE SCREENThe D.E. Shaw Group interview questions
  • Trapping Rain WaterGoldman Sachs · PHONE SCREENGoldman Sachs interview questions
  • Sort Ones, Twos, and Threes In PlaceAgoda · PHONE SCREEN · ONSITE INTERVIEWAgoda interview questions
  • Candy Crush Grid Matching and GravityRoblox · PHONE SCREEN · ONSITE INTERVIEWRoblox interview questions
  • Find All Pythagorean TripletsDell Technologies · PHONE SCREENDell Technologies interview questions

Interview reports that mention this question

  • Grammarly SWE Phone Screen Questions: 1 Experience
See Grammarly hiring insights
Saved
class Solution {
    public int[][] intervalIntersections(int[][] firstList, int[][] secondList) {
      // Write your code here.
    }
}
Checking account…