Minimise Transfers to Settle Balances Between Platform Accounts
Last updated: November 29, 2026
Quick Overview
Given the net balance of each balance account after a day of marketplace activity (positive means owed money, negative means owes money, all summing to zero), return the minimum number of transfers that settles every account.
Adyen
November 29, 20260
0
0 solved
Given the net balance of each balance account after a day of marketplace activity (positive means owed money, negative means owes money, all summing to zero), return the minimum number of transfers that settles every account.
On a platform with many sub-merchants, internal movements between balance accounts can be netted before money actually moves, and every transfer has an operational cost. The interviewer wants the candidate to see that the answer is n minus the maximum number of disjoint zero-sum groups, and to implement an exact bitmask DP for small n while discussing heuristics at scale.
What the Interviewer Expects
- Reduce the problem to net balances and drop settled accounts
- Prove that a zero-sum group of size k needs exactly k minus 1 transfers
- Formulate a bitmask DP that maximises disjoint zero-sum groups
- State the exponential complexity and the n limit where it is practical
- Suggest a greedy fallback for large n and what it loses
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 also produce the actual list of transfers, not just the count?
- Transfers between different currencies need FX. How does that change the model?
- With 10,000 accounts, what heuristic would you ship and how would you measure how far it is from optimal?
- Some account pairs are not allowed to transfer directly. Is the problem still solvable with this DP?
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: map of account to integer net balance in minor units, summing to zero. Output: the minimum number of transfers, each moving any positive amount from a debtor to a creditor, such that every bala...
High-Level Design
Key fact: any set of k accounts whose balances sum to zero can be settled with k minus 1 transfers (chain them: each passes its running total to the next), and no fewer, because each transfer can zero...