Optimal Dasher to Order Assignment With Bitmask DP
Last updated: November 29, 2026
Quick Overview
Given a matrix cost[o][d] of travel distance for Dasher d to take order o, with at most about 16 Dashers and no more orders than Dashers, assign each order a distinct Dasher to minimize total distance and return the assignment.
DoorDash
November 29, 20260
0
0 solved
Given a matrix cost[o][d] of travel distance for Dasher d to take order o, with at most about 16 Dashers and no more orders than Dashers, assign each order a distinct Dasher to minimize total distance and return the assignment.
Dispatch at DoorDash is fundamentally an assignment problem. For a small batch in one zone, interviewers like this bitmask DP because it forces you to encode which Dashers are used as bits, reason about 2^n states, and contrast it with the Hungarian algorithm used at scale.
What the Interviewer Expects
- Explain why greedy nearest Dasher can be suboptimal
- Encode used Dashers as a bitmask and infer the next order from its popcount
- Write the transition and its O(2^n * n) cost
- Reconstruct the assignment from stored choices
- Name the Hungarian algorithm or min-cost flow for larger inputs
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you allow an order to stay unassigned at a penalty cost?
- How would you handle 500 Dashers and 300 orders in a real market?
- How would you add a constraint that a Dasher cannot take an order more than 5 miles away?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
costisk x nwithk <= n <= ~16.- Each order gets exactly one Dasher; each Dasher takes at most one order.
- Output:
(min_total, assignment)whereassignment[o]is the Dasher for order o...
High-Level Design
State dp[mask] = minimum cost to give the first popcount(mask) orders the Dashers in mask. Processing orders in a fixed order removes the need to store which order each bit took. From a reachabl...