← Questions

Transfers to bring every account up to a minimum balance

0
StripeCodingLast asked Nov 2023

You hold money in several bank accounts, and every account must end with at least a minimum balance. Given each account's balance, return a list of transfers (from, to, amount) that achieves it, moving money from accounts above the minimum to accounts below it without pushing any donor under the minimum. Any working list is fine at first.

Follow-up: return the smallest possible number of transfers. Explain why greedy matching is not always optimal and how you would search for the minimum on a small number of accounts.

Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding