Notice Period

Triple Zero Sum

medium

An accounting tool flags suspicious ledgers by finding three transactions that cancel out — three entries summing to exactly zero. Auditors want every distinct combination, not the same trio reported twice with its numbers shuffled.

Given a list of integers ledger, return all unique triplets [a, b, c] of values (taken from three different positions) with a + b + c == 0. No duplicate triplets: [-1, 0, 1] and [0, 1, -1] are the same finding. Triplet order and within-triplet order don't matter to the grader.

Example 1
in ledger = [-1, 0, 1, 2, -1, -4]
out [[-1, -1, 2], [-1, 0, 1]]
Two distinct trios cancel out. The second -1 doesn't create a new finding — same values, same trio.
Example 2
in ledger = [0, 1, 1]
out []
No three entries cancel.
Example 3
in ledger = [0, 0, 0]
out [[0, 0, 0]]
Constraints
  • · 3 <= len(ledger) <= 3000
  • · -10^5 <= ledger[i] <= 10^5
similar problem on LeetCode ↗
solution.pyloading python…
test results
Hit ▶ Run to test your code against the visible cases.