FunctionRacerProblemsRace

Transfers Between Accounts

MediumHash mapsPython, JavaScript, TypeScript, Java, C++

ops is a list of bank operations, applied in order. Every account starts at balance 0 and exists from the first operation that mentions it, even if that operation is rejected. The operations are:

Return a dictionary mapping every account that was mentioned to its final balance (zero balances included). No operations gives an empty dictionary.

Example 1

ops ["deposit ann 50","withdraw ann 20","transfer ann bob 25","withdraw bob 30"]
returns {"ann":5,"bob":25}

ann gets 50, loses 20, then sends 25 to bob and is left with 5. bob has 25, so his withdrawal of 30 is rejected.

Example 2

ops ["transfer ann bob 10"]
returns {"ann":0,"bob":0}

ann has nothing, so the transfer is rejected, but both accounts now exist with balance 0.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Hash maps problems