Snap Noisy GPS Pings to Road Segments With Viterbi

Last updated: November 29, 2026

Quick Overview

Given, for each GPS ping, candidate road segments with the distance from the ping to each segment, plus a routing function between segments, return the most likely sequence of segments using a hidden Markov model and the Viterbi algorithm, restarting cleanly when no connected path exists.

Samsara
Coding & Algorithms
Software Engineer
Samsara
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Hard

0

0

0 solved


Given, for each GPS ping, candidate road segments with the distance from the ping to each segment, plus a routing function between segments, return the most likely sequence of segments using a hidden Markov model and the Viterbi algorithm, restarting cleanly when no connected path exists.

Accurate trip replays, speeding detection against posted limits, and mileage by state for fuel tax all depend on snapping noisy GPS to the right road. An onsite interviewer at Samsara uses this to see whether you can model a real problem as dynamic programming and handle broken chains.

What the Interviewer Expects
  • Model segments as hidden states and pings as observations
  • Emission score from distance to segment (Gaussian in log space)
  • Transition score that penalizes route distance differing from straight-line distance
  • Viterbi with backpointers in log space
  • Handle HMM breaks where no candidate is reachable
  • State complexity in pings and candidates
Key Topics to Cover
Hidden Markov model
Viterbi
Dynamic programming
Map matching
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 pick candidates per ping efficiently over a national road graph?
  • Route distance queries are expensive; how would you bound or cache them?
  • How would you do this online with low latency instead of over a whole trip?
  • How would you tune sigma and beta from data?
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: candidates[i] is a list of (segment_id, d) for ping i; straight[i] is the straight-line distance from ping i to i+1; route_dist(a, b) is driving distance between segments, inf if unre...

High-Level Design

Classic Newson and Krumm style HMM. Log emission: −12(d/σ)2-\frac{1}{2}(d/\sigma)^2. Log transition: −∣route−straight∣/β-|route - straight| / \beta. Viterbi keeps the best score per candidate of the current ping and a backpo...


Submit Your Answer
Markdown supported

Related Questions