Design Algorithm to Minimize Payments in Expense-Sharing App
PinterestData Scientist · OnsiteLast updated
This question evaluates algorithm design and optimization skills, focusing on modeling multi-party transactions and minimizing the number of settlement operations.
Scenario
Expense-sharing app needs to settle debts among friends after a trip.
Question
Given a list of transactions (payer, payee, amount), design an algorithm that produces the minimum set of payments required to settle every person’s balance.
Hints
Compute each person’s net balance, then greedily match positives with negatives using a heap or two-pointer sweep.
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.