Two Couriers Collecting the Most Orders on One Grid Sweep
Last updated: November 29, 2026
Quick Overview
Two couriers start at the top-left of a grid and each moves only right or down to the bottom-right; cells hold a number of ready orders (or -1 if blocked), and an order cell's orders are collected once even if both couriers pass it. Return the maximum total collected, or 0 if no route exists.
Uber
November 29, 20260
0
0 solved
Two couriers start at the top-left of a grid and each moves only right or down to the bottom-right; cells hold a number of ready orders (or -1 if blocked), and an order cell's orders are collected once even if both couriers pass it. Return the maximum total collected, or 0 if no route exists.
Coordinating two couriers through a dense district so they do not double-serve the same pickups is a natural Uber Eats framing of a known hard grid DP. The onsite interviewer checks that you see why running a single-courier DP twice is wrong and that you synchronize both couriers by step count.
What the Interviewer Expects
- Explain why two greedy single-path DPs fail
- Move both couriers in lockstep with step k = r + c
- Use state (k, r1, r2) and derive columns
- Count a shared cell once
- Use -inf for unreachable states and analyze O(n^3)
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 extend this to three couriers?
- Return the two routes, not just the total
- What if couriers may start at different corners?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
- Input: n x n grid, values
>= 0or-1for blocked. - Both couriers go from
(0,0)to(n-1,n-1)moving right or down. - Output: maximum total; 0 if either courier cannot reach the goal....
High-Level Design
Taking the best single path and then the best path on the leftover grid can be suboptimal, since the first path may grab cells that the two couriers could have split more profitably. Instead move both...