Minimize Transfers to Settle Shared Team Offsite Expenses
Last updated: November 29, 2026
Quick Overview
During a team offsite, different employees paid for shared items, each split evenly among some participants. Compute the minimum number of person-to-person transfers needed to settle every balance.
Ramp
November 29, 20260
0
0 solved
During a team offsite, different employees paid for shared items, each split evenly among some participants. Compute the minimum number of person-to-person transfers needed to settle every balance.
Ramp's reimbursement and card products often deal with who fronted what, and settling a messy offsite tab is a compact way to test net-balance reasoning plus backtracking with real pruning. The interviewer expects you to reduce the problem to nonzero balances, explain why greedy matching is not optimal, and prune the search.
What the Interviewer Expects
- Reduces expenses to net balances in integer cents, distributing remainder cents deterministically
- Explains why greedy largest-creditor-to-largest-debtor is not always minimal
- Relates the answer to n minus the maximum number of zero-sum subgroups
- Implements backtracking that settles one balance per step with pruning
- Validates against a bitmask DP on small cases
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
- Give the bitmask DP that solves it in O(2^n times n).
- With 200 people this is too slow. What practical heuristic would you ship?
- How would you also return the actual transfers, not just the count?
- How would you handle multiple currencies?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Each expense is (payer, amount_cents, participants) split evenly, with leftover cents assigned to the first participants so totals stay exact. Return the minimum number of transfers after which ever...
High-Level Design
Only net balances matter, so collapse expenses into a map and drop zeros. A transfer can always zero at least one person, giving an upper bound of n - 1. More precisely, if the balances can be split i...