Minimize Transfers to Settle Net Balances Across Entities

Last updated: November 29, 2026

Quick Overview

Given a list of intercompany payments between entities in a single currency, return the minimum number of transfers needed so every entity's net balance becomes zero.

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

0

0

0 solved


Given a list of intercompany payments between entities in a single currency, return the minimum number of transfers needed so every entity's net balance becomes zero.

Relevant to Airwallex treasury operations, where many internal movements between regional entities and banking partners can be netted before real money moves over SWIFT or local rails. The interviewer is checking whether you reduce to net balances, see that greedy matching is not optimal, and find the subset-sum structure.

What the Interviewer Expects
  • Collapses the transaction list into per-entity net balances and drops zeros
  • Shows why greedily pairing largest debtor and creditor can be suboptimal
  • Identifies that a zero-sum group of size m needs m minus 1 transfers
  • Implements a bitmask DP maximizing the number of zero-sum groups
  • States exponential complexity honestly and when it is acceptable
Key Topics to Cover
Netting
Bitmask DP
Subset sums
Greedy counterexamples
Treasury
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
  • Give a counterexample where greedy matching uses more transfers than optimal.
  • How would you scale this to 500 entities in practice?
  • How do you extend to multiple currencies with FX costs?
  • Which constraint matters more to treasury: transfer count or total fees?
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: (payer, payee, amount_minor) tuples, one currency. Output: minimum number of new transfers that zero every net balance. Amounts are integers....

High-Level Design
  1. Compute net balance per entity; drop zeros, leaving n nonzero balances that sum to 0.
  2. Key fact: any group of entities whose balances sum to zero can be settled with (group size minus 1) transfer...

Submit Your Answer
Markdown supported

Related Questions