Katkat

Compute transfers to balance account debts

RemitlySoftware Engineer · Technical Screen

Last updated

This question evaluates a candidate's ability to convert per-account net balances into a set of transfers, testing algorithmic problem solving, data-structure manipulation, and correctness under conservation invariants in transactional systems.

Problem: Balance accounts by generating transfers

You are given a dictionary/map balances from accountId -> netBalance.

  • A positive balance means the account should receive money (is owed money).
  • A negative balance means the account should pay money (owes money).
  • The sum of all balances is guaranteed to be 0.

Produce a list of transfers that will settle all accounts to net 0.

Output format

Return a list of transfers like:

  • (fromAccount, toAccount, amount) where amount > 0

After applying all transfers:

  • Every account’s balance becomes exactly 0.

Example

Input:

{ A: -5, B: 2, C: 3 }

One valid output:

[(A, B, 2), (A, C, 3)]

Notes / constraints

  • You may return any valid set of transfers.
  • Prefer fewer transfers if possible, but correctness is the priority.