Reported September 2026
Virtu Financialbacktracking

Optimal Account Balancing

Reported by candidates from Virtu Financial's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Virtu Financial OA. Under 2s to a working solution.
Founder's read

Example 1 in this Virtu Financial question nets out to -5, +10 and -5, and the answer is 2, not 1. That's the whole puzzle in miniature. Virtu Financial candidates reported Optimal Account Balancing in September 2026, and the hinted pattern is greedy, though the real solution is backtracking over net balances. With at most 8 transactions, the search space is small, but a naive approach still blows up if you skip the pruning. If you blank mid-assessment, StealthCoder runs invisibly on your desktop and hands you the working solution in real time. Here's the shape of it before you sit down.

The problem

You are given a list transactions. Each transaction [from, to, amount] means that person from paid amount on behalf of person to.
After all transactions, people may transfer money directly between one another to settle every net balance. One settlement transfer may use any positive amount between any two people.
Return the minimum number of settlement transfers needed so that every person's net balance becomes zero.

Function
minTransfers(transactions: int[][]) → int

Examples
Example 1
transactions = [[0,1,10],[2,0,5]]
return = 2
The net balances are -5 for person 0, +10 for person 1, and -5 for person 2. Two transfers are necessary and sufficient.
Example 2
transactions = [[0,1,10],[1,0,1],[1,2,5],[2,0,5]]
return = 1
After combining all activity, only two nonzero net balances remain, with equal magnitude and opposite signs. One transfer settles them.

Constraints
1 <= transactions.length <= 8
Each transaction contains exactly three integers [from, to, amount].
0 <= from, to <= 20
from != to
1 <= amount <= 100

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick: ignore who paid whom. Collapse every transaction into a net balance per person, then drop all the zeros. Now you have a short list of positive and negative numbers that sum to zero. Run DFS from the first nonzero balance. Try pairing it with every later balance of opposite sign, add the two together, recurse, then undo. Count the transfers and keep the minimum. The classic pitfall is greedy matching of the largest debtor with the largest creditor. It looks right and fails on cases where a subset of three or more people cancels out cleanly. Another pitfall is forgetting to skip duplicate balances, which kills your runtime. Since from and to stay within 0 to 20 and there are only 8 transactions, at most 16 people end up with nonzero balances, so backtracking fits comfortably. If the recursion logic slips under pressure, StealthCoder is the hedge that keeps you moving during the live OA.

If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.

If this hits your live OA

You can drill Optimal Account Balancing cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it.

Get StealthCoder

Related leaked OAs

⏵ Practice the LeetCode equivalent

This OA pattern shows up on LeetCode as optimal account balancing. If you have time before the OA, drill that.

⏵ The honest play

You've seen the question. Make sure you actually pass Virtu Financial's OA.

Virtu Financial reuses patterns across OAs. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Optimal Account Balancing FAQ

How hard is Optimal Account Balancing really?+

It's a hard-tier problem on LeetCode, but the constraints here are tiny. Eight transactions means at most 16 people with nonzero balances. If you know to net the balances first and then backtrack, the code is about 20 lines. The difficulty is spotting that, not writing it.

What's the trick to solving it?+

Compute each person's net balance with a hash map, discard zeros, then DFS. At each step, take the first nonzero balance and try settling it against every later balance with the opposite sign. Recurse, undo, and track the minimum number of transfers across all branches.

Is plain greedy enough here?+

No. Matching the biggest debtor with the biggest creditor can give a wrong answer, because the optimum often comes from finding groups of people whose balances cancel exactly. Greedy is the hinted pattern, but backtracking is what actually passes every test case.

Why does Example 2 return 1 instead of more?+

Combine all four transactions and only two people keep nonzero balances. They're equal in size and opposite in sign, so a single transfer zeros both. It shows why you net first. Raw transaction count tells you nothing about the minimum settlements.

How do I prepare for this in 48 hours?+

Write the net balance step, then the backtracking loop with undo, then add the pruning: skip a candidate if it has the same balance as one you already tried at this level. Test on both examples by hand. Then do one more problem with the same DFS-and-undo shape.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Virtu Financial.

OA at Virtu Financial?
Invisible during screen share
Get it