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
Data Manipulation (SQL/Python)
Data Scientist
Uber
November 29, 2026
Data Scientist
Take-home Project
Data Manipulation (SQL/Python)
Hard

0

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
pandas
interval construction
groupby shift
time series
data cleaning
How to Approach This
  1. Clarify the schema and expected output format before writing queries.
  2. Use CTEs (WITH clauses) to break complex queries into readable steps.
  3. Consider window functions (ROW_NUMBER, RANK, LAG, LEAD) for ranking and sequential analysis.
  4. Watch for NULLs, duplicates, and edge cases in JOINs and GROUP BY.
  5. 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 Problems
Sample 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
  1. Parse, stable sort, and drop same-timestamp duplicates.
  2. Remove consecutive repeated statuses so each row is a real state change.
  3. End of each interval is the next row's ts per driver, else `...

Submit Your Answer
Markdown supported