Compute Trip Mileage From Noisy GPS Breadcrumbs
Last updated: November 29, 2026
Quick Overview
Given possibly unsorted and duplicated GPS fixes (timestamp, latitude, longitude) for one trip, compute total distance in miles using haversine, discarding fixes that imply an impossible speed and ignoring jitter while parked.
Motive
November 29, 20260
0
0 solved
Given possibly unsorted and duplicated GPS fixes (timestamp, latitude, longitude) for one trip, compute total distance in miles using haversine, discarding fixes that imply an impossible speed and ignoring jitter while parked.
Mileage drives IFTA fuel tax reports, utilization, and per-mile safety rates in Motive's platform, so distance has to be robust to multipath glitches and parked drift. The interviewer is looking for correct geometry plus sensible filtering, and for the insight that a rejected point must not move the anchor.
What the Interviewer Expects
- Use haversine rather than Euclidean distance on degrees
- Sort and dedupe the input first
- Reject fixes by implied speed relative to the last accepted fix, not the previous raw fix
- Suppress tiny movements while stationary so parked drift does not add miles
- Discuss when engine odometer data should win over GPS
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 split the trip into miles per state for IFTA?
- What if a long cellular outage leaves a 40-minute gap between fixes?
- How would you combine GPS distance with the engine ECU odometer?
- How would a Kalman filter improve on this?
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 fixes (t, lat, lon) may arrive out of order (buffered uploads) and may repeat. Output total miles. Filters: drop any fix whose speed from the last accepted fix exceeds max_mph (a teleport), ...
High-Level Design
Sort and dedupe, then walk the fixes keeping an anchor, the last accepted fix. For each new fix compute haversine distance from the anchor and the implied speed. If the speed is impossible, skip the f...