Computing Driver Online Hours and Utilization From Status Logs
Last updated: November 29, 2026
Quick Overview
Given a log of driver status changes (online, on_trip, offline), compute each driver's online hours, on-trip hours and utilization per calendar day in pandas, correctly splitting intervals that cross midnight.
Uber
November 29, 20260
0
0 solved
Given a log of driver status changes (online, on_trip, offline), compute each driver's online hours, on-trip hours and utilization per calendar day in pandas, correctly splitting intervals that cross midnight.
Driver utilization (time on trip divided by time online) is one of Uber's key supply metrics, and turning event logs into intervals is a classic take-home or onsite pandas task. The interviewer checks interval construction, midnight splitting and messy-log handling.
What the Interviewer Expects
- Sort by driver and time, and build intervals with a shifted end time
- Handle duplicate timestamps and repeated statuses
- Close the final open interval with a report end time
- Split intervals across day boundaries
- Aggregate to driver-day with utilization
Key Topics to Cover
How to Approach This
- Clarify the schema and expected output format before writing queries.
- Use CTEs (WITH clauses) to break complex queries into readable steps.
- Consider window functions (ROW_NUMBER, RANK, LAG, LEAD) for ranking and sequential analysis.
- Watch for NULLs, duplicates, and edge cases in JOINs and GROUP BY.
- For pandas, prefer vectorized operations over row-by-row iteration.
Possible Follow-up Questions
- How would you vectorize the midnight split for 100M rows?
- What if logs are missing an offline event because the app crashed?
- How would you compute this in each city's local time zone?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice SQL ProblemsSample Answer
Clarify the Data
Columns: driver_id, ts, status. Each row starts a state that lasts until the driver's next row. on_trip counts as online. Assumptions to confirm: timestamps are already in local time, duplicat...
Approach
- Parse, stable sort, and drop same-timestamp duplicates.
- Remove consecutive repeated statuses so each row is a real state change.
- End of each interval is the next row's
tsper driver, else `...