Loading...
Loading...
Loading...
A ledger holds n entries, positive and negative. Count the different triples of values (as sets of numbers, not positions) that add up to 0. The same triple of values is counted once.
Example 1
Input
6 -1 0 1 2 -1 -4
Output
2
(-1, -1, 2) and (-1, 0, 1).
Example 2
Input
3 1 2 3
Output
0
Try the problem first. Open one hint at a time.
Sort the values. Fix the first value, then use two pointers on the rest.
Skip equal neighbours so the same triple is counted only once.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor