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
Coding & Algorithms
Software Engineer
Uber
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Hard

0

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
interval dynamic programming
prefix sums
Knuth optimization
Huffman comparison
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. 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 Problems
Sample 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...


Submit Your Answer
Markdown supported