Skip to main content
LeetCode 465, Hard. Topics: Bit Manipulation, Array, Dynamic Programming, Backtracking, Bitmask. View on LeetCode. Generate this problem as a practice environment: tested reference solution, 12 parametrized pytest cases, and a playground notebook:

Problem

You are given an array of transactions transactions where transactions[i] = [from_i, to_i, amount_i] indicates that the person with ID = from_i gave amount_i $ to the person with ID = to_i. Return the minimum number of transactions required to settle the debt.

Examples

Constraints

  • 1 <= transactions.length <= 8
  • transactions[i].length == 3
  • 0 <= from_i, to_i < 12
  • from_i != to_i
  • 1 <= amount_i <= 100

Solution

Reference implementation from solution.py on GitHub, full suite in test_solution.py:

Complexity

Tags

NeetCode All.
Last modified on September 7, 2026