Split a Day's Ready Orders Into Courier Batches at Minimum Cost
Last updated: November 29, 2026
Quick Overview
Orders become ready at sorted times t[0..n-1]; they must be dispatched in consecutive batches of at most cap orders. Each batch costs a fixed dispatch fee F plus w times the total wait, where every order in the batch waits until the batch's last order is ready. Return the minimum total cost.
Uber
November 29, 20260
0
0 solved
Orders become ready at sorted times t[0..n-1]; they must be dispatched in consecutive batches of at most cap orders. Each batch costs a fixed dispatch fee F plus w times the total wait, where every order in the batch waits until the batch's last order is ready. Return the minimum total cost.
Uber Eats batching trades fewer courier trips against food waiting longer. The onsite interviewer is checking whether you can turn the trade-off into a partition DP, compute batch costs in O(1) with prefix sums, and discuss optimizations when the cap is large.
What the Interviewer Expects
- Argue that optimal batches are contiguous in ready-time order
- Define dp[i] as the min cost to dispatch the first i orders
- Compute batch wait cost in O(1) with prefix sums
- Respect the cap with a bounded inner loop
- Mention convex hull trick or monotone queue for large caps
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 speed this up when cap equals n?
- What if each order has a promised delivery time that must not be exceeded?
- How would you handle orders that become ready online, one at a time?
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: sorted
t, integerscap >= 1,F >= 0,w >= 0. - A batch
j..i-1waits untilt[i-1]; its cost isF + w x sum(t[i-1] - t[k]). - Output: minimum total cost over all partitions into c...
High-Level Design
With sorted ready times, an exchange argument shows some optimal solution uses contiguous batches: if an earlier order sits in a later-dispatched batch while a later order sits in an earlier-dispatche...