Emit Debounced Geofence Entry and Exit Events
Last updated: November 29, 2026
Quick Overview
Given a polygon geofence and a time-ordered list of GPS pings for one vehicle, emit ENTER and EXIT events, accepting a state change only after a configurable number of consecutive pings agree.
Samsara
November 29, 20260
0
0 solved
Given a polygon geofence and a time-ordered list of GPS pings for one vehicle, emit ENTER and EXIT events, accepting a state change only after a configurable number of consecutive pings agree.
Geofence alerts (arrived at job site, left the yard) are among the most used Samsara workflow triggers, and GPS jitter near a boundary causes flapping alerts. The interviewer checks a correct point-in-polygon test, a small state machine, and thinking about false alerts that annoy dispatchers.
What the Interviewer Expects
- Implement ray casting correctly, including the half-open edge rule
- Model the vehicle state as inside or outside with a pending run
- Require k consecutive agreeing pings before switching
- Stamp the event with the first ping of the confirming run
- Discuss complexity per ping and for many geofences
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 check one ping against 100,000 customer geofences efficiently?
- What about circular geofences defined in latitude and longitude?
- Should the debounce be by ping count or by elapsed time? Why?
- How do you handle a vehicle that powers on already inside a geofence?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Pings are (t, x, y) in a projected plane (fine for city-sized fences; for large ones project lat/lon first). The fence is a simple polygon. The vehicle starts in a known state. A change is confirmed...
High-Level Design
point_in_polygonwith ray casting: count edges a horizontal ray to the right crosses. Using(y1 > y) != (y2 > y)makes each edge half-open, so a ray through a vertex is counted once.- A state...