Transfer locking final balance
Your task
Simulate money transfers between accounts under per-account locking with deadlock avoidance. You start with balances (balances[i] is account i's balance). You are given a list of transfers, each [src, dst, amount]. To transfer, BOTH accounts must be lockable; locks are acquired in ascending account-id order (lower id first) to avoid deadlock. A transfer is applied (atomically) only if (a) src != dst and (b) the source has at least amount available. If applied, it subtracts amount from src and adds it to dst. Transfers that violate a rule are skipped. Locks are released immediately after each transfer (no held locks across transfers), so the ordering rule never blocks anything here, but you must still reject self-transfers and insufficient-funds transfers. Process transfers in order and return the final balances list.
Examples
apply_transfers(balances: list[int], transfers: list[list[int]]) -> list[int]apply_transfers([100, 50], [[0, 1, 30], [1, 0, 200]])[70, 80]