Courier Speed

ASKED IN INTERVIEW
4pts
Door Dash

Problem Statement

DoorDash logistics team wants to identify high-performing couriers. A courier is considered high-performing if their average delivery speed is at least 20% faster than the average delivery speed of all couriers in the same city.

Write an SQL query to find these couriers.

Rules:

  • Speed is defined as distance divided by time (distance / duration).
  • Distance is in kilometers and duration is in minutes.
  • A courier is faster if their speed value is higher.
  • 20% faster means the courier speed must be >= 1.2 * City Average Speed.
  • Output columns: courier_id, city_id, courier_avg_speed, city_avg_speed.
  • Round all speed values to 2 decimal places.
  • Results should be ordered by courier_id in ascending order.

Table Schema:

  • Couriers: Information about the delivery partners.
  • Deliveries: Records of individual completed deliveries including distance and time.
Tests your understanding of
Window Functions, Aggregation, Mathematical Operations and Joins

Input Tables

Couriers
courier_id(INTEGER)city_id(INTEGER)
1501
2501
3501
4502
5502
6502
Deliveries
delivery_id(INTEGER)courier_id(INTEGER)distance(DECIMAL)duration(INTEGER)
101510
111612
122315
133420
1441015
155520
166210

Expected Output

courier_id(INTEGER)city_id(INTEGER)courier_avg_speed(DECIMAL)city_avg_speed(DECIMAL)
15010.50.3
45020.670.37

Tags

MediumASKED IN INTERVIEWWindow FunctionsAggregationMathematical OperationsJoins
20-25 min
51%

Hints