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
Coding & Algorithms
Software Engineer
Samsara
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

0

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
Point in polygon
State machine
Debouncing
Spatial indexing
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 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 Problems
Sample 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
  1. point_in_polygon with 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.
  2. A state...

Submit Your Answer
Markdown supported

Related Questions