Detect Harsh Braking Events From Irregular Speed Samples

Last updated: November 29, 2026

Quick Overview

Given (timestamp, speed in m/s) samples at irregular intervals, find harsh braking events where deceleration is at least a threshold, merging consecutive flagged intervals into one event with its start, end and peak deceleration.

Samsara
Coding & Algorithms
Software Engineer
Samsara
November 29, 2026
Software Engineer
Online Assessment
Coding & Algorithms
Easy

0

0

0 solved


Given (timestamp, speed in m/s) samples at irregular intervals, find harsh braking events where deceleration is at least a threshold, merging consecutive flagged intervals into one event with its start, end and peak deceleration.

Harsh event detection feeds Samsara safety scores and dash cam coaching clips, so it fits an online assessment for backend or firmware roles. The interviewer wants correct rate computation on uneven sampling, merging of adjacent hits, and defensive handling of bad timestamps.

What the Interviewer Expects
  • Compute deceleration per adjacent pair as dv/dt
  • Skip pairs with non-positive dt or gaps too long to trust
  • Merge consecutive flagged pairs into a single event
  • Track peak deceleration per event
  • Linear time and constant extra state
Key Topics to Cover
Sliding pairs
Rate of change
Event merging
Sensor noise
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
  • GPS speed is noisy; how would you use accelerometer data instead or in addition?
  • How would you avoid one bump on the road triggering an event?
  • How would thresholds differ for a loaded semi truck vs a light van?
  • How would you run this on-device with limited memory?
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: (t, v) sorted by time, speeds in m/s, timestamps possibly irregular. A pair is harsh if (v1 - v2) / (t2 - t1) >= threshold (3 m/s^2 is a common starting point, about 0.3 g). Pairs with `dt ...

High-Level Design

One pass over adjacent pairs with an open event. On a harsh pair, start or extend the event and update the peak. On a non-harsh or untrusted pair, close the event. Close any event left open at the end...


Submit Your Answer
Markdown supported

Related Questions