Loading
Loading
A ledger holds signed adjustments. An auditor wants the number of distinct triples of values that cancel out exactly — that is, sum to zero.
Two triples are the same if they consist of the same three values, regardless of which positions they came from. Return the count of distinct value-triples.
adjustments = [-1, 0, 1, 2, -1, -4]sorted[-4, -1, -1, 0, 1, 2]fix -1find 0 and 1 → (-1, 0, 1)fix -1 againsame values, skipped as duplicatefix -1, pair(-1, -1, 2)2Sign in to keep a note here. It is free, and nobody else can see it.
Sign inExample 1
Sign in to open hints.
Struggling is where the learning happens. Open this once you have genuinely tried, or once the hints have run out.
O(n²) time · O(n) space
Input. Run your code to watch it work on this input, one line at a time.
Running code is turned off on this deployment. You can still read the problem, write code, use hints and the visualizer.
Tab moves focus out of the editor. Press Ctrl+M to let Tab indent instead.
No results yet
Run your code against the sample tests, or submit to run the full suite.
(-1,0,1) and (-1,-1,2).
Example 2
Only the triple (0,0,0), counted once.
Example 3