FastPrepRunning Interval Union Length
Problems/Running Interval Union Length

Running Interval Union Length

Google logoGoogle● MediumINTERNONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The interview report begins with merging intervals. It then asks for an online structure that takes one interval at a time and returns the current length of the union. It also calls out containment, neighbors that merge, and clarifying how endpoints count. Our version uses half-open intervals and returns results as a batch, while keeping the reported online behavior.

Intervals arrive one at a time in uploads. Each row [left, right] represents the half-open interval [left, right).

After every upload, return the total length covered by all intervals seen so far. Count overlapping portions only once. Overlapping or touching intervals may be stored as one merged interval. An interval that is already fully covered does not change the total.

Function

runningIntervalUnionLengths(uploads: long[][]) → long[]

Examples

Example 1

uploads = [[1,5],[7,10],[3,8],[8,9]]return = [4,7,9,9]

The first two intervals cover lengths 4 and 3. Uploading [3,8) joins them into [1,10), whose length is 9. The final interval is already covered.

Example 2

uploads = [[-2,0],[0,3],[1,2]]return = [2,5,5]

The first two half-open intervals touch and together cover [-2,3). The final upload lies inside that union.

Constraints

  • 1 <= uploads.length <= 200000.
  • Every row contains exactly two integers [left, right].
  • -10^12 <= left < right <= 10^12.
  • Every prefix union length fits in a signed 64-bit integer.

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

  • My Calendar IUber · ONSITE INTERVIEWUber interview questions
  • Run-Length Integer Map: Get and SetAdobe · OAAdobe interview questions
  • Random Dasher Set OperationsDoorDash · ONSITE INTERVIEWDoorDash interview questions
  • Merge IntervalsApple · OA · PHONE SCREEN · ONSITE INTERVIEWApple interview questions
  • Merge Overlapping IntervalsAtlassian · PHONE SCREEN · ONSITE INTERVIEWAtlassian interview questions
  • Round-Robin Iterator over IteratorsBridge · ONSITE INTERVIEWBridge interview questions
  • Design Hit CounterNutanix · ONSITE INTERVIEWNutanix interview questions
  • Maximum Intervals Overlapping a Fixed-Length WindowBooking.com · ONSITE INTERVIEW
  • Design Browser HistoryBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
  • Meeting Rooms IISalesforce · ONSITE INTERVIEWSalesforce interview questions

Google interview experiences

  • Google interviews · November 2026
  • Google Software Engineer Onsite Questions: 10 Experiences
  • Google OA: What It Tests (2026)
  • Google L4 SWE Phone Screen: 1 Experience
  • Google ML Engineering Manager Onsite: 1 Experience
  • Google Experienced SWE First Round and Onsite: 1 Experience
All Google interview questionsSee Google hiring insights
Saved
class Solution {
    public long[] runningIntervalUnionLengths(long[][] uploads) {
        // Write your code here.
    }
}
Checking account…