Debounced Geofence Enter and Exit Events for a Vehicle

Last updated: November 29, 2026

Quick Overview

Given a time-sorted stream of vehicle positions and a polygon geofence, emit enter and exit events, but only after the vehicle has stayed on the new side for a configurable number of consecutive pings, using the first ping of that run as the event time.

Motive
Coding & Algorithms
Software Engineer
Motive
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Medium

0

0

0 solved


Given a time-sorted stream of vehicle positions and a polygon geofence, emit enter and exit events, but only after the vehicle has stayed on the new side for a configurable number of consecutive pings, using the first ping of that run as the event time.

Fleet managers on Motive set geofences around yards, customer sites and job sites to get arrival and departure alerts and detention time. GPS noise near a fence edge creates flapping, so this round tests point-in-polygon plus a small state machine that suppresses flicker without losing the true event time.

What the Interviewer Expects
  • Implement ray casting point-in-polygon correctly, including the half-open edge rule
  • Separate the confirmed state from the candidate state
  • Reset the candidate when the vehicle returns to the confirmed side
  • Backdate the event to the first ping of the confirmed run
  • Discuss using a bounding box check first at scale
Key Topics to Cover
point in polygon
debouncing
state machine
geofencing
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 evaluate 50,000 geofences against every ping efficiently?
  • How would you handle polygons that cross the antimeridian or use lat and lon directly?
  • Should debounce be by ping count or by elapsed time, and why?
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

Positions are (t, x, y) sorted by time and the fence is a simple polygon. The first ping sets the initial side with no event. A side change becomes an event only after confirm consecutive pings on...

High-Level Design

Point in polygon uses ray casting: count edges a horizontal ray from the point crosses; odd means inside. The condition (y1 > y) != (y2 > y) treats edges as half-open, so a ray passing exactly throu...


Submit Your Answer
Markdown supported

Related Questions