Expand a Run-Length Iterator
Updated
Problem statement
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 and0 <= 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