Minimum Transfers to Settle a Shared Group Bill
Last updated: November 29, 2026
Quick Overview
Friends record who paid for whom during a trip as a list of (payer, beneficiary, amount) entries. Compute the minimum number of person-to-person UPI transfers needed to settle every balance to zero.
PhonePe
November 29, 20260
0
0 solved
Friends record who paid for whom during a trip as a list of (payer, beneficiary, amount) entries. Compute the minimum number of person-to-person UPI transfers needed to settle every balance to zero.
Splitting bills and settling up with friends maps directly onto PhonePe's peer-to-peer payments, where fewer transfers mean fewer UPI requests and less friction. The interviewer wants to see that you reduce the problem to net balances, recognize that greedy matching is not optimal, and find the subset structure behind the exact answer.
What the Interviewer Expects
- Reduce the raw ledger to one net balance per person
- Explain why greedy largest-creditor-to-largest-debtor matching can be suboptimal
- Show that the answer is (people with nonzero balance) minus (max number of zero-sum groups)
- Implement a bitmask DP that computes the max number of zero-sum groups
- State the exponential complexity honestly and when it is acceptable
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
- Prove that a zero-sum group of k people can always be settled with k-1 transfers and never fewer.
- Group sizes are 20+ people. What would you ship in the app instead of the exact algorithm?
- How would you present the settlement plan so users trust it?
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 (payer, payee, amount) where payer covered amount for payee, so payee owes payer. Output: the minimum number of transfers. Amounts are integers (paise). Group size is small,...
High-Level Design
Only net balances matter: positive means the person should receive, negative means they should pay, and they sum to zero. Any set of people whose balances sum to zero can settle among themselves with ...