A debt tracking app records transactions showing who paid whom and how much. Each transaction includes a borrower, a lender, and an amount.
Given a list of transactions, determine the minimum number of transactions required to settle all debts.
Suppose the number of people (n) = 3, the number of transactions (m) = 4, and transactions = [[0, 1, 20], [1, 0, 10], [1, 2, 10], [0, 10, 10]].
Each transaction is represented as [from, to, amount], meaning:
After simplification, only one transaction is needed: Person 0 pays $15 to person 1. Therefore, the minimum number of transactions required is 1.
Hard