Compute Remaining Driving Time Under Hours of Service Rules

Last updated: November 29, 2026

Quick Overview

Given a driver's duty status log (OFF, ON duty not driving, D for driving) with start minutes and the current time, return how many minutes the driver may still drive under simplified rules: 11 hours of driving and a 14 hour on-duty window after 10 consecutive hours off, plus a 30 minute break required after 8 cumulative hours of driving.

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

0

0

0 solved


Given a driver's duty status log (OFF, ON duty not driving, D for driving) with start minutes and the current time, return how many minutes the driver may still drive under simplified rules: 11 hours of driving and a 14 hour on-duty window after 10 consecutive hours off, plus a 30 minute break required after 8 cumulative hours of driving.

Samsara's ELD product must show drivers an accurate Hours of Service clock, and a wrong number is a compliance violation for the customer. This onsite question checks whether you can turn regulatory rules into precise state tracking and test the boundaries.

What the Interviewer Expects
  • Convert the log into closed segments ending at now
  • Track driving since reset, driving since last qualifying break, and window start
  • Reset all clocks after 10 consecutive hours off duty
  • Let any 30 minutes of consecutive non-driving time satisfy the break
  • Return the minimum of the three limits, never negative
  • Write boundary tests at exactly 8, 11 and 14 hours
Key Topics to Cover
Simulation
State tracking
Compliance logic
Boundary testing
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 add the 60 hour / 7 day or 70 hour / 8 day cycle limit?
  • How would you support the sleeper berth split (7/3 or 8/2) provision?
  • Logs can be edited later by the driver or carrier; how does recomputation work?
  • How would you test this against regulatory examples?
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

Log entries (start_minute, status) sorted, each lasting until the next or until now. Rules (simplified FMCSA property-carrying): after 10 consecutive hours off, the driver gets 11 hours of driving...

High-Level Design

Replay segments and keep: driven, since_break, window_start, off_run (consecutive off minutes), non_drive_run (consecutive non-driving minutes). Off time short of 10 hours does not pause the...


Submit Your Answer
Markdown supported

Related Questions