The Optimal Account Balancing problem gives you a list of transactions between people. Find the minimum number of transactions needed to settle all debts so that everyone's net balance is zero. This hard coding problem reduces to matching creditors with debtors and counting the minimum number of settlements needed.
Uber, Goldman Sachs, Stripe, Amazon, Google, and many others ask this because it models real-world financial reconciliation. The bitmask DP or backtracking approach finds the minimum settlements by grouping people into zero-sum subsets. The array, bitmask, backtracking, bit manipulation, and dynamic programming interview pattern is the core.
Debt balancing + backtracking/bitmask DP. Compute each person's net balance (positive = owed, negative = owes). Collect non-zero balances. Use backtracking: try to settle the first unsettled person with each later unsettled person (transferring debt). Count minimum transactions. Or use bitmask DP: dp[mask] = minimum transactions to zero out the subset mask. Transition: for each subset of mask summing to 0, dp[mask] = min(dp[subset] + dp[mask^subset]). Return dp[all_nonzero].
Balances: [+4,-2,-2]. Person 0 owed 4, persons 1,2 owe 2 each.
Debt settlement problems reduce to "minimum number of zero-sum partitions of the balance array." For small n (≤10 people), bitmask DP over subsets summing to 0 works. For backtracking, always eliminate zero-balance people first. Practice similar "group settlement" problems in financial technology contexts — this exact problem appears in expense-splitting apps like Splitwise and is common in fintech interviews.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Find Minimum Time to Finish All Jobs | Hard | Solve | |
| Matchsticks to Square | Medium | Solve | |
| Beautiful Arrangement | Medium | Solve | |
| Fair Distribution of Cookies | Medium | Solve | |
| Campus Bikes II | Medium | Solve |