Rank Carriers by On-Time Arrival Within Each Trade Lane

Last updated: November 29, 2026

Quick Overview

Using a shipments table with carrier, origin port, destination port, scheduled arrival and actual arrival, compute each carrier's monthly on-time arrival rate per trade lane (on time meaning within one day of schedule) and rank carriers within each lane and month.

Flexport
Data Manipulation (SQL/Python)
Data Scientist
Flexport
November 29, 2026
Data Scientist
Technical Screen
Data Manipulation (SQL/Python)
Medium

0

0

0 solved


Using a shipments table with carrier, origin port, destination port, scheduled arrival and actual arrival, compute each carrier's monthly on-time arrival rate per trade lane (on time meaning within one day of schedule) and rank carriers within each lane and month.

Schedule reliability is a key input when Flexport recommends a carrier to a shipper on a lane. The interviewer checks careful definitions (what counts as on time, what to do with shipments still at sea), aggregation by the right grain, window functions, and awareness of small-sample noise.

What the Interviewer Expects
  • Define on time and the month a shipment belongs to before writing SQL
  • Exclude or separately count shipments that have not arrived
  • Aggregate at lane, month and carrier grain
  • Use a window function for ranking within lane and month
  • Apply a minimum volume threshold and discuss why
Key Topics to Cover
Window Functions
Aggregation
CASE Expressions
Metric Definition
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 adjust the ranking so a carrier with 3 of 3 on time does not beat one with 95 of 100?
  • Should the month be based on scheduled or actual arrival, and does it change the answer?
  • How would you measure early arrivals, which also cause problems at the terminal?
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

shipments(shipment_id, carrier, origin_port, dest_port, scheduled_arrival, actual_arrival). Questions I would confirm: is scheduled_arrival the original schedule at booking or the latest carrier e...

Approach
  1. Filter to arrived shipments and compute an on_time 0/1 flag.
  2. Group by lane, month and carrier; AVG(on_time) is the rate.
  3. Drop thin groups with a HAVING threshold.
  4. RANK() partitione...

Submit Your Answer
Markdown supported

Related Questions