Apply Wallet Transfers
This models a simple transfer system where money is taken from one user and added to another. Given a dictionary balances with user balances and a list transfers, where each transfer contains from, to, and amount, apply the transfers in order. Run a transfer only if the sender has enough money; otherwise, skip it. Return the final balances dictionary.
Примеры
Ввод
{"a": 100, "b": 0}, [["a", "b", 30]]Вывод
{"a": 70, "b": 30}Ввод
{"a": 10, "b": 0}, [["a", "b", 50]]Вывод
{"a": 10, "b": 0}Ввод
{"a": 100, "b": 0, "c": 0}, [["a", "b", 40], ["b", "c", 40], ["a", "c", 60]]Вывод
{"a": 0, "b": 0, "c": 100}Нужно реализовать
def apply_transfers(balances: dict, transfers: list) -> dict:
Теги
dicthashmap
Logáil isteach chun stair na n-aighneachtaí a fheiceáil
Logáil isteachLogáil isteach chun an Meantóir IS a úsáid
Logáil isteachVisible tests
1
Input
{"a":100,"b":0}, [["a","b",30]]Expected
{"a":70,"b":30}2
Input
{"a":10,"b":0}, [["a","b",50]]Expected
{"a":10,"b":0}3
Input
{"a":100,"b":0,"c":0}, [["a","b",40],["b","c",40],["a","c",60]]Expected
{"a":0,"b":0,"c":100}4
Input
{"a":50,"b":50}, [["a","b",50],["b","a",100]]Expected
{"a":100,"b":0}5
Input
{"a":5}, [["a","z",1]]Expected
{"a":5}6
Input
{"a":100,"b":0,"c":0}, [["a","b",40]]Expected
{"a":60,"b":40,"c":0}Focus radio
Paused · SomaFM · Fluid