Total Online Hours per Driver From Status Log Lines

Last updated: November 29, 2026

Quick Overview

Each log line looks like `08:15:00 d42 ONLINE` or `09:00:30 d42 OFFLINE`, sorted by time within a day. Return each driver's total online seconds, ignoring repeated ONLINE events while already online and closing any open session at midnight (86400).

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

0

0

0 solved


Each log line looks like `08:15:00 d42 ONLINE` or `09:00:30 d42 OFFLINE`, sorted by time within a day. Return each driver's total online seconds, ignoring repeated ONLINE events while already online and closing any open session at midnight (86400).

A practical Uber phone screen question close to how driver hours are computed for safety limits. It checks clean parsing, a per-driver state map, and explicit rules for messy events.

What the Interviewer Expects
  • Parses the timestamp into seconds since midnight
  • Tracks the open session start per driver in a dict
  • Ignores duplicate ONLINE and stray OFFLINE events as specified
  • Closes open sessions at end of day
  • Skips or reports malformed lines instead of crashing
Key Topics to Cover
string parsing
hash map
state tracking
log processing
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
  • What if logs from several days arrive out of order?
  • How would you enforce a 12-hour online limit in real time?
  • How would you handle sessions that cross midnight into the next day?
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: list of lines HH:MM:SS driver STATUS, time-sorted.
  • Output: dict of driver to online seconds.
  • Duplicate ONLINE while online is ignored; OFFLINE while offline is ignored; open sessions en...
High-Level Design

Keep start[driver] for drivers currently online and total[driver] for accumulated seconds. For each line, split into three fields and convert the time. ONLINE sets start only if the driver is no...


Submit Your Answer
Markdown supported