Sum Engine Idle Time From Vehicle Gateway Samples

Last updated: November 29, 2026

Quick Overview

Given time-ordered telemetry samples of (timestamp, engine_on, speed) from a vehicle gateway, return the total idle time and the list of idle periods lasting at least two minutes. Do not count time across gaps in the data longer than five minutes.

Samsara
Coding & Algorithms
Software Engineer
Samsara
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Easy

0

0

0 solved


Given time-ordered telemetry samples of (timestamp, engine_on, speed) from a vehicle gateway, return the total idle time and the list of idle periods lasting at least two minutes. Do not count time across gaps in the data longer than five minutes.

Idling reports are a core fuel-waste feature for fleet customers, so this is a natural warm-up in a Samsara phone screen. The interviewer checks clean interval reasoning over a stream and whether you notice that cellular data gaps should not be billed as idling.

What the Interviewer Expects
  • Clarify that each sample's state holds until the next sample
  • Treat a pair of samples as idle only when the engine is on and speed is near zero
  • Refuse to bridge gaps longer than the max gap
  • Close the final open period after the loop
  • Single pass, O(n) time, O(1) extra space besides output
Key Topics to Cover
Interval merging
Stream processing
Telemetry gaps
Edge cases
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 make this work incrementally as samples stream in per vehicle?
  • Power take-off trucks idle on purpose; how would you exclude PTO time?
  • How would you report idle fuel burned if you also had fuel rate samples?
  • What changes if samples can arrive out of order?
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: samples (t, engine_on, speed_mph) sorted by t. A sample's state applies until the next sample. Output: total idle seconds and idle periods (start, end) of at least min_idle seconds. Idl...

High-Level Design

Walk consecutive pairs. Each pair is either an idle span or not. Keep an open period (start, end): extend it while pairs stay idle; when a non-idle pair appears, close it and keep it only if it is l...


Submit Your Answer
Markdown supported

Related Questions