Compute Net Balances From a Peer-to-Peer Transfer Log
Last updated: November 29, 2026
Quick Overview
Given a list of transfers (payer, payee, amount in cents), compute each account's net balance and return the non-zero balances sorted from largest creditor to largest debtor.
PayPal
November 29, 20260
0
0 solved
Given a list of transfers (payer, payee, amount in cents), compute each account's net balance and return the non-zero balances sorted from largest creditor to largest debtor.
A warm-up in the style of PayPal's phone screens, framed around Venmo-style transfers between friends. The interviewer checks that you reach for a hash map immediately, keep money in integer cents, and think about ties and self-transfers without being prompted.
What the Interviewer Expects
- Use a single pass with a hash map from account to net cents
- Represent money as integers, never floats
- Handle self-transfers and invalid amounts explicitly
- Produce a deterministic ordering, including tie-breaks
- State O(n + a log a) complexity where a is the number of accounts
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
- How would you then produce the minimum list of settle-up payments between friends?
- What changes if transfers come in multiple currencies?
- How would you compute this over billions of rows in a batch job?
- How do you verify the result (what invariant must always hold)?
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 is a list of (payer, payee, cents) tuples. Output is a list of (account, net) pairs where net is money received minus money sent, dropping accounts that net to zero. Sort by net descending, ...
High-Level Design
Each transfer moves the same amount out of one account and into another, so one pass over the log with a dictionary is enough: subtract from the payer, add to the payee. Because every transfer is bala...