Assign dashers to orders to minimize total delivery time

Quick Overview

Assign each delivery order to a different dasher so the sum of delivery times is as small as possible, where each delivery time depends on travel distance, dasher availability and food prep time. Tests whether you can spot why greedy choices fail and solve the problem as an exact minimum-cost assignment.

Assign dashers to orders to minimize total delivery time

Company: DoorDash

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: hard

Interview Round: Other

You are given a list of orders and a list of dashers, all placed on a number line. Each order is `[location, prep_time]`, where `location` is the pickup point and `prep_time` is the time the food is ready. Each dasher is `[location, availability_time]`, where `location` is the dasher's current position and `availability_time` is the earliest time the dasher can start traveling. If order `i` is assigned to dasher `j`, its delivery time is `max(availability_time_j + abs(location_i - location_j), prep_time_i)`. The dasher leaves at their availability time and covers one unit of distance per unit of time, and the order can be picked up only once the dasher has arrived and the food is ready. Assign every order to exactly one dasher, with each dasher taking at most one order, so that the sum of delivery times over all orders is as small as possible. Return that minimum total. ### Function Signature ```python def assign_dashers(orders: list[list[int]], dashers: list[list[int]]) -> int: ``` ### Rules - `orders[i] = [location, prep_time]` and `dashers[j] = [location, availability_time]`. - Every order must be assigned. A dasher may be left without an order. - Return only the minimum total delivery time. Several assignments can reach the same total, but the total itself is unique. - If there are fewer dashers than orders, return `-1`. ### Constraints - `1 <= orders.length <= 100` - `orders.length <= dashers.length <= 200` - `0 <= orders[i][0], dashers[j][0] <= 1000` - `0 <= orders[i][1], dashers[j][1] <= 1000` ### Examples ```text Input: orders = [[10, 5], [20, 8]], dashers = [[0, 0], [15, 2], [25, 1]] Output: 15 ``` Dasher 1 takes order 0 with delivery time `max(2 + 5, 5) = 7`, and dasher 2 takes order 1 with `max(1 + 5, 8) = 8`, for a total of 15. The next best pairing costs 18 (dasher 0 on order 0 at 10, plus 8 for order 1). ```text Input: orders = [[5, 10]], dashers = [[3, 0], [100, 0]] Output: 10 ``` Dasher 0 arrives at time 2, but the food is ready only at time 10, so the delivery time is 10. Dasher 1 would need until time 95. ```text Input: orders = [[4, 0], [6, 0]], dashers = [[5, 0], [0, 0]] Output: 5 ``` Dasher 0 is closest to both orders. Giving it order 0 leaves order 1 to dasher 1, for `1 + 6 = 7`. Giving it order 1 and sending dasher 1 to order 0 costs `1 + 4 = 5`.

Overview: Assign each delivery order to a different dasher so the sum of delivery times is as small as possible, where each delivery time depends on travel distance, dasher availability and food prep time. Tests whether you can spot why greedy choices fail and solve the problem as an exact minimum-cost assignment.

DoorDash logo
DoorDash
Nov 24, 2026
hardSoftware EngineerOtherCoding & Algorithms
0
0

You are given a list of orders and a list of dashers, all placed on a number line. Each order is [location, prep_time], where location is the pickup point and prep_time is the time the food is ready. Each dasher is [location, availability_time], where location is the dasher's current position and availability_time is the earliest time the dasher can start traveling.

If order i is assigned to dasher j, its delivery time is max(availability_time_j + abs(location_i - location_j), prep_time_i). The dasher leaves at their availability time and covers one unit of distance per unit of time, and the order can be picked up only once the dasher has arrived and the food is ready.

Assign every order to exactly one dasher, with each dasher taking at most one order, so that the sum of delivery times over all orders is as small as possible. Return that minimum total.

Function Signature

def assign_dashers(orders: list[list[int]], dashers: list[list[int]]) -> int:

Rules

  • orders[i] = [location, prep_time] and dashers[j] = [location, availability_time] .
  • Every order must be assigned. A dasher may be left without an order.
  • Return only the minimum total delivery time. Several assignments can reach the same total, but the total itself is unique.
  • If there are fewer dashers than orders, return -1 .

Constraints

  • 1 <= orders.length <= 100
  • orders.length <= dashers.length <= 200
  • 0 <= orders[i][0], dashers[j][0] <= 1000
  • 0 <= orders[i][1], dashers[j][1] <= 1000

Examples

Input: orders = [[10, 5], [20, 8]], dashers = [[0, 0], [15, 2], [25, 1]]
Output: 15

Dasher 1 takes order 0 with delivery time max(2 + 5, 5) = 7, and dasher 2 takes order 1 with max(1 + 5, 8) = 8, for a total of 15. The next best pairing costs 18 (dasher 0 on order 0 at 10, plus 8 for order 1).

Input: orders = [[5, 10]], dashers = [[3, 0], [100, 0]]
Output: 10

Dasher 0 arrives at time 2, but the food is ready only at time 10, so the delivery time is 10. Dasher 1 would need until time 95.

Input: orders = [[4, 0], [6, 0]], dashers = [[5, 0], [0, 0]]
Output: 5

Dasher 0 is closest to both orders. Giving it order 0 leaves order 1 to dasher 1, for 1 + 6 = 7. Giving it order 1 and sending dasher 1 to order 0 costs 1 + 4 = 5.