FastPrepSum Two Piecewise-Constant Time Series
Problems/Sum Two Piecewise-Constant Time Series

Sum Two Piecewise-Constant Time Series

Google logoGoogle● MediumNEW GRADONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report gives the piecewise-constant format and a full example of the summed series. We made the rules explicit for empty input and for output at the same timestamp. Our version is about 95% the same as the reported question.

Each time series is a sorted array of pairs [time, value]. A pair changes the series to value at time, and that value remains active until the next pair. Before its first event, a series has value 0.

Add the two series by summing their active values at each time. Return the sum in the same format. Emit the earliest time from either input, then emit a pair only when the summed value changes. If both inputs change at the same time, apply both changes before emitting that time.

Both inputs use strictly increasing integer times. Either input may be empty.

Function

sumTimeSeries(first: int[][], second: int[][]) → int[][]

Examples

Example 1

first = [[0,0],[2,1],[8,0]]second = [[0,0],[1,3],[5,2]]return = [[0,0],[1,3],[2,4],[5,3],[8,2]]

The union of change times is 0,1,2,5,8; summing the active values gives the shown series.

Example 2

first = [[1,2],[8,10],[15,0]]second = [[3,5],[10,4],[12,0]]return = [[1,2],[3,7],[8,15],[10,14],[12,10],[15,0]]

Each output event occurs when either input changes.

Example 3

first = []second = [[4,7]]return = [[4,7]]

An empty series contributes zero everywhere.

Constraints

  • 0 <= first.length, second.length <= 100000.
  • Each row contains exactly two integers [time,value].
  • Times are strictly increasing within each input and lie in [-10^9,10^9].
  • Values lie in [-10^9,10^9]; every sum fits a signed 32-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

  • Candy Crush Grid Matching and GravityRoblox · PHONE SCREEN · ONSITE INTERVIEWRoblox interview questions
  • Alternate Positive and Negative ValuesTesla · ONSITE INTERVIEWTesla interview questions
  • Add Signed Character ArraysByteDance · PHONE SCREENByteDance interview questions
  • Nested List Iterator with RemoveAirbnb · PHONE SCREENAirbnb interview questions
  • Match OutcomesAdobe · OAAdobe interview questions
  • Rotate the Box and Drop the StonesZipRecruiter · OAZipRecruiter interview questions
  • DMA Stream DistributionEtched · PHONE SCREEN
  • Catch Fish with Reusable BaitsSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
  • Collect Branches for a Bird NestVisa · OAVisa interview questions
  • Score Difference When Even Picks Reverse the ListMicrosoft · OAMicrosoft interview questions

Interview reports that mention this question

  • Google New Grad SWE Interview Questions Guide (Part 1 of 2)
  • Google PhD New Grad Five-Round Loop: 1 Experience

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
All Google interview questionsSee Google hiring insights
Saved
class Solution {
    public int[][] sumTimeSeries(int[][] first, int[][] second) {
        // Write your code here.
    }
}
Checking account…