Minimum Pix Transfers to Settle a Shared Trip Expense

Last updated: November 29, 2026

Quick Overview

Friends record who paid for whom during a trip as (debtor, creditor, amount) entries; return the minimum number of Pix transfers that settles every balance to zero.

Nubank
Coding & Algorithms
Software Engineer
Nubank
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Hard

0

0

0 solved


Friends record who paid for whom during a trip as (debtor, creditor, amount) entries; return the minimum number of Pix transfers that settles every balance to zero.

Splitting bills over Pix is everyday behavior for Nubank customers, and a settle-up feature is a plausible product idea. The problem looks greedy but is not, so the interviewer checks whether you reduce it to net balances and find the zero-sum subset structure that makes the answer exact.

What the Interviewer Expects
  • Reduces the input to net balances per person and drops zeros
  • Explains why greedy matching of largest debtor and creditor is not optimal
  • Shows that the answer is k minus the maximum number of disjoint zero-sum groups
  • Implements bitmask DP over subsets
  • States complexity and the practical limit on k
Key Topics to Cover
bitmask dynamic programming
graph reduction
net balances
NP-hard optimization
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
  • Prove that a zero-sum group of size s needs exactly s minus 1 transfers.
  • How would you return the actual transfers, not just the count?
  • With 60 people the DP is infeasible. What heuristic would you ship?
  • How would you avoid suggesting a transfer between two people who do not know each other?
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 list of debts in cents. Output a single integer, the fewest transfers so all nets are zero. People with zero net need no transfers....

High-Level Design

Only net positions matter. With k nonzero balances, any settlement partitions people into groups that each sum to zero, and a group of size s can always be settled with s-1 transfers (chain them) but ...


Submit Your Answer
Markdown supported

Related Questions