Courier On Time Delivery Rate From Raw Scan Events
Last updated: November 29, 2026
Quick Overview
Given raw courier scan events (out for delivery, delivered, failed attempt) with duplicates and reassignments, plus the promised delivery time per package, compute each courier's on-time delivery rate as of a given time, attributing undelivered overdue packages to the last courier who took them out.
Coupang
November 29, 20260
0
0 solved
Given raw courier scan events (out for delivery, delivered, failed attempt) with duplicates and reassignments, plus the promised delivery time per package, compute each courier's on-time delivery rate as of a given time, attributing undelivered overdue packages to the last courier who took them out.
Rocket Delivery is judged on keeping its promise, and camp managers look at courier-level on-time rates daily. Scan data is noisy (double scans, packages moved between routes), so the interviewer looks for explicit attribution rules and correct handling of unresolved packages.
What the Interviewer Expects
- Deduplicate repeated scans before aggregating
- Use the first delivered scan per package and credit the courier who scanned it
- Attribute overdue, undelivered packages to the last out for delivery courier
- Exclude packages whose outcome is not yet known (promise in the future, not delivered)
- Count distinct packages, not scan rows
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 make this an incremental daily job instead of a full recompute?
- Should a failed attempt because the customer was absent count against the courier?
- How would you compare couriers fairly across easy apartment routes and rural routes?
- How would you write the same logic in SQL with window functions?
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
scans(package_id, courier_id, event, ts) and promises(package_id, promised_by). Questions I would ask: can a package have two delivered scans (yes, double taps), can it be reassigned (yes, the rou...
Approach
- Drop exact duplicate scans. 2) First delivered scan per package gives delivery time and the credited courier. 3) Last out for delivery scan gives the fallback owner for packages never delivered. 4)...