This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import collections | |
# input: list of transactions in form (a, b, amount) corresponding to "a owes b amount" | |
def min_transactions(transactions): | |
# build map of users to change in wealth | |
wealth = collections.defaultdict(int) | |
for lendee, lender, amount in transactions: | |
wealth[lendee] -= amount | |
wealth[lender] += amount |