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
November 29, 20260
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
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 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 ProblemsSample 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...