Your question is Apply Multiple Array Transactions. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
In an Addepar portfolio model, each transaction transfers cash between two accounts. Given the starting balance of every account and exactly three ordered transactions, compute the final balance of each account after applying the transactions in order.
Each transaction is represented as [from_account, to_account, amount]. Deduct amount from the source account and add it to the destination account. Account balances must be updated immediately, because later transactions may depend on earlier transfers.
Implement apply_transactions(balances, transactions), where balances is a list of nonnegative integers and transactions is a list containing exactly three transaction arrays. Return a new list containing the final balance for every account. Account IDs are zero-based indices into balances.
You may assume every transaction references valid accounts, the source and destination are different, and the source account has sufficient funds when its transaction is applied.
def apply_transactions(balances, transactions):