Peekable Iterator That Collapses Repeated GPS Pings

Last updated: November 29, 2026

Quick Overview

Driver phones send GPS pings as (timestamp, lat, lng). Wrap a ping iterator in a class with peek(), next() and has_next() that skips any ping whose rounded position equals the previous emitted ping's position, so consumers only see real movement.

Uber
Coding & Algorithms
Software Engineer
Uber
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

0

0

0 solved


Driver phones send GPS pings as (timestamp, lat, lng). Wrap a ping iterator in a class with peek(), next() and has_next() that skips any ping whose rounded position equals the previous emitted ping's position, so consumers only see real movement.

A streaming iterator question in the style of Uber's technical screens, based on location ingestion where stationary drivers flood the pipeline with identical pings. The interviewer checks a one-element lookahead buffer and correct interplay between peek and next.

What the Interviewer Expects
  • Keeps a single buffered lookahead element
  • Makes peek idempotent (calling it twice returns the same ping)
  • Compares against the last emitted position, not the last seen
  • Rounds coordinates to a configurable precision
  • Raises StopIteration correctly at the end
Key Topics to Cover
Iterators
Lookahead buffer
Streaming
Deduplication
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • How would you collapse pings that move less than 10 meters instead of exact equality?
  • How would you keep the latest timestamp of a stationary run instead of the first?
  • How would this run inside a Flink or Kafka Streams job?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Input: an iterable of (ts, lat, lng) and a decimal precision. API: peek(), next(), has_next(). A ping is dropped if its rounded (lat, lng) equals that of the last ping returned (or peeked an...

High-Level Design

Hold a buffer slot for the next ping that will be emitted, plus last_pos of the most recently emitted ping. A private _fill() pulls from the source until it finds a ping whose rounded position d...


Submit Your Answer
Markdown supported