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
Coding & Algorithms
Software Engineer
PayPal
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Easy

0

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
hash maps
integer money
sorting with tie-breaks
ledger invariants
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. 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 Problems
Sample 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...


Submit Your Answer
Markdown supported

Related Questions