Rebalance Bank Accounts to a Minimum Balance
Reported by candidates from Remitly's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The Remitly OA reported in September 2026 looks like a simple money-moving problem, but one edge case breaks the naive version. You get rows like "AU,80", a threshold, and you must output transfers that lift every underfunded account to the minimum. It's a two-pointer greedy over two ordered lists, and the output format is strict. If you blank on the pointer logic, StealthCoder runs invisibly during the live OA as a safety net. Know the shape before you sit down.
The problem
Stripe tracks money across bank accounts and sometimes moves funds so that every account stays at or above a required minimum balance. Each input row is accountName,balance. Return a working sequence of transfers in the form from,to,amount that leaves every account with at least threshold. An optimal number of transfers is not required. For deterministic output, process underfunded accounts in input order and take funds from overfunded accounts in input order. Move as much as possible in each transfer without taking a donor below the threshold or raising the current receiver above it. Function rebalanceAccounts(accounts: String[], threshold: long) → String[] Examples Example 1 accounts = ["AU,80","US,140","MX,110","SG,120","FR,70"] threshold = 100 return = ["US,AU,20","US,FR,20","MX,FR,10"] US first fills AU, then contributes its remaining surplus to FR. MX supplies FR's final ten. Example 2 accounts = ["a,50","b,50","c,200"] threshold = 100 return = ["c,a,50","c,b,50"] The only donor funds both receivers in their input order. Constraints 1 <= accounts.length <= 500. Account names are unique and contain no commas. 0 <= balance, threshold <= 10^12. The total balance is at least accounts.length * threshold. All arithmetic fits in signed 64-bit integers.
Reported by candidates. Source: FastPrep
Pattern and pitfall
Split the input into receivers (balance below threshold) and donors (balance above threshold), each kept in input order. Walk both lists with two pointers. For each transfer, amount is min(receiver's remaining deficit, donor's remaining surplus). Emit from,to,amount, then update both and advance whichever one hit zero. The pitfall is the edge case: accounts exactly at the threshold are neither donors nor receivers, and a donor must never drop below the threshold. Also skip zero-amount transfers, and parse balances as 64-bit longs because values reach 10^12. Don't re-sort anything, since determinism depends on input order. The total-balance guarantee means the donors always cover the deficits, so the loop ends cleanly. Complexity is O(n). StealthCoder is the hedge if the pointer advancement slips under pressure in the live OA.
Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.
You can drill Rebalance Bank Accounts to a Minimum Balance 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. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.
Get StealthCoderYou've seen the question.
Make sure you actually pass Remitly's OA.
Remitly reuses patterns across OAs. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Rebalance Bank Accounts to a Minimum Balance FAQ
What's the trick in the Remitly rebalance accounts problem?+
Two pointers over two lists. One list holds underfunded accounts in input order, the other holds overfunded accounts in input order. Each transfer moves min(deficit, surplus), then you advance whichever side is exhausted. No sorting, no heaps, no optimization of transfer count.
What edge case breaks a naive solution?+
Accounts exactly at the threshold, and zero-amount transfers. Treat balance equal to threshold as neither donor nor receiver. Never emit a transfer of 0. Also use 64-bit integers, since balances go up to 10^12 and int overflows.
Do I need to minimize the number of transfers?+
No. The problem says an optimal count isn't required. It only needs a valid sequence, and the output must match the deterministic rule: underfunded in input order, donors in input order, maximum amount per transfer. Follow that rule exactly or the output won't match.
How hard is this one really?+
Easy to medium. The algorithm is a simple greedy, but the output format and ordering rules cause most failures. Parsing the strings, tracking remaining surplus per donor, and advancing pointers correctly is where people lose points, not the idea itself.
How do I prepare in 48 hours?+
Write this one from scratch twice. Parse the CSV-style strings, build the two lists, run the pointer loop, and check both examples by hand. Then practice a couple of other two-pointer greedy problems with strict output formats so the bookkeeping feels automatic.