Katkat

Design Algorithm to Minimize Payments in Expense-Sharing App

PinterestData Scientist · Onsite

Last 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.