Minimum Cost to Merge Adjacent Payout Batches Into One Transfer
Last updated: November 29, 2026
Quick Overview
Driver payouts sit in a row of pending batches with amounts a[0..n-1]; merging two adjacent batches costs the sum of their amounts (bank fees scale with volume) and creates one batch. Return the minimum total cost to merge everything into a single transfer.
Uber
November 29, 20260
0
0 solved
Driver payouts sit in a row of pending batches with amounts a[0..n-1]; merging two adjacent batches costs the sum of their amounts (bank fees scale with volume) and creates one batch. Return the minimum total cost to merge everything into a single transfer.
Uber's payments platform consolidates payouts, and an interviewer may wrap a known interval DP in that framing. The onsite checks that you notice adjacency rules out the Huffman greedy, define dp over subarrays, and use prefix sums for merge cost.
What the Interviewer Expects
- Explain why the Huffman-style greedy is wrong when only adjacent merges are allowed
- Define dp[i][j] as min cost to merge a[i..j] into one batch
- Recurrence over the split point with prefix sum cost
- Fill by increasing interval length
- Mention Knuth optimization to reach O(n^2)
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
- What if any two batches (not just adjacent) can merge? What algorithm then?
- What if exactly K adjacent batches must be merged at a time?
- How would Knuth's optimization apply here?
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: list of positive integers
a. - Merge cost = sum of the two merged batches' amounts.
- Output: minimum total cost to end with one batch; 0 for 0 or 1 batches....
High-Level Design
Any final merge splits the row into a left part a[i..k] and a right part a[k+1..j], each merged independently into one batch first. The last merge costs the whole range sum, regardless of the spli...