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