Iterator Over Run-Length Encoded Vehicle Telemetry
Last updated: November 29, 2026
Quick Overview
Vehicle telemetry is compressed with run-length encoding as a flat list [count1, value1, count2, value2, ...]. Implement next(n), which consumes the next n readings and returns the last one consumed, or -1 if fewer than n readings remain.
Uber
November 29, 20260
0
0 solved
Vehicle telemetry is compressed with run-length encoding as a flat list [count1, value1, count2, value2, ...]. Implement next(n), which consumes the next n readings and returns the last one consumed, or -1 if fewer than n readings remain.
An iterator question in the style of Uber's technical screens, based on compressed telemetry from vehicles and scooters. The interviewer checks that you never expand the encoding and that partial consumption of a run is tracked correctly.
What the Interviewer Expects
- Does not decompress the runs into memory
- Tracks the current run index and how much of it is used
- Skips zero-count runs
- Returns -1 and exhausts the iterator when n exceeds what remains
- Analyzes amortized cost per call
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you support a peek that does not consume?
- How would you support seeking to an absolute reading index in O(log runs)?
- How would you append new runs while the iterator is active?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input: an even-length list of non-negative counts and values. API: next(n) with n >= 1. Counts can be huge (for example identical speed readings while parked), so expansion is not an option...
High-Level Design
Keep i, the index of the current count in the flat list, and used, how many readings of that run are consumed. On next(n), while runs remain: let left = counts[i] - used. If n <= left, consu...