Optimal Account Balancing

Try to solve the Optimal Account Balancing problem.

Statement

Given a list of transactions, where each transaction is represented as transactions[i]=[fromi, toi, amounti]transactions[i] = [from_i,~ to_i,~amount_i], indicating that the person fromifrom_i gave amountiamount_i to the person toito_i. Return the minimum number of transactions needed to settle all debts.

Constraints:

  • 11\leq transactions.length 10\leq10

  • transactions[i].length ==3==3

  • 00 \leq fromi, toi 10\leq10

  • 11\leq amounti 100\leq100

  • fromi \neq toi

Examples

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.