FastPrepExpand a Run-Length Iterator
Problems/Expand a Run-Length Iterator

Expand a Run-Length Iterator

Google logoGoogle● EasyNEW GRADONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report describes value and count pairs, and an iterator with hasNext and next. It notes that counts can be zero. Here the function returns the whole finite sequence the iterator would give. Our version is about 95% the same as the reported question.

A run-length encoding is an array of pairs [value,count]. The iterator would return value exactly count times before advancing to the next pair.

Return the complete finite iterator output. Pairs with count zero contribute nothing. Preserve pair order and repeated values in different pairs.

Function

expandRuns(runs: int[][]) → int[]

Examples

Example 1

runs = [[1,2],[4,3]]return = [1,1,4,4,4]

Value 1 appears twice and value 4 appears three times.

Example 2

runs = [[5,0],[2,1]]return = [2]

The zero-count run is skipped.

Example 3

runs = []return = []

An empty iterator has no output.

Constraints

  • 0 <= runs.length <= 100000.
  • Each row is [value,count] with signed integer value and 0 <= count.
  • The total output length is at most 200000.

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

  • Ring Buffer OperationsAmazon · ONSITE INTERVIEW
  • Count Distinct Underwriting PII ValuesAffirm · PHONE SCREEN · ONSITE INTERVIEWAffirm interview questions
  • Bounded Word Guess SolverAtlassian · ONSITE INTERVIEWAtlassian interview questions
  • Apply Overridden Integer TransformsOptimus Information · ONSITE INTERVIEWOptimus Information interview questions
  • Copy File Bytes with Partial WritesMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Policy Violation Set ChecksPinterest · ONSITE INTERVIEWPinterest interview questions
  • Retry with an Attempt LimitOracle · ONSITE INTERVIEWOracle interview questions
  • Extract Error Log ContextFlexTrade · ONSITE INTERVIEWFlexTrade interview questions
  • Moving Cost by Volume and CategoryWayfair · ONSITE INTERVIEWWayfair interview questions
  • Alternate Positive and Negative ValuesTesla · ONSITE INTERVIEWTesla 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 int[] expandRuns(int[][] runs) {
        // Write your code here.
    }
}
Checking account…