Rider Idle Time Between Consecutive Deliveries per Shift

Last updated: November 29, 2026

Quick Overview

From a deliveries table with rider, assignment and delivery timestamps, compute each rider's average idle minutes per day between finishing one delivery and being assigned the next, excluding long breaks and handling batched orders.

Zomato
Data Manipulation (SQL/Python)
Data Engineer
Zomato
November 29, 2026
Data Engineer
Technical Screen
Data Manipulation (SQL/Python)
Medium

0

0

0 solved


From a deliveries table with rider, assignment and delivery timestamps, compute each rider's average idle minutes per day between finishing one delivery and being assigned the next, excluding long breaks and handling batched orders.

Idle time between orders is a core supply efficiency metric for Zomato's delivery fleet and feeds decisions on rider onboarding per zone. The screen checks LEAD window functions plus judgement about overlapping and gap edge cases.

What the Interviewer Expects
  • Use LEAD partitioned by rider and day ordered by assignment time
  • Compute gaps from delivered time to next assigned time
  • Treat negative gaps (batched orders) as zero idle
  • Exclude gaps over a threshold as breaks and report them separately
  • Explain why the partition is by day and its limits
Key Topics to Cover
LEAD and LAG
Gaps and islands
Time arithmetic
Data quality
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 use actual login sessions instead of a 60 minute threshold?
  • Shifts cross midnight for late-night riders. How does the partition change?
  • How would you build this incrementally in a daily pipeline over billions of rows?
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

deliveries(rider_id, order_id, assigned_at, delivered_at). A rider can carry two batched orders, so a second assignment can happen before the first delivery finishes. Gaps above 60 minutes are proba...

Approach

Order each rider's deliveries in a day by assigned_at, pair each row with the next assignment via LEAD, and compute the gap from this delivery to the next assignment. Clamp negatives to zero becau...


Submit Your Answer
Markdown supported

Related Questions