A pricing tool lists price adjustments in deltas: negative numbers are discounts and positive numbers are surcharges. An auditor wants every set of three adjustments that cancel out exactly.
Write zeroSumTriples(deltas) that returns every distinct triple of values [x, y, z], taken from three different positions, with x + y + z === 0. Write each triple in ascending order, list the triples in ascending order (compare first values, then second), and list each distinct triple once.
Input: deltas = [-3,1,2,-1,-1,4] Output: [[-3,-1,4],[-3,1,2],[-1,-1,2]]
Both -1s are used in [-1, -1, 2]; [-3, -1, 4] uses either -1, but it's listed once.
Input: deltas = [1,2,-2,-1] Output: []
No three values add up to zero.
0 <= deltas.length <= 3000-10^5 <= deltas[i] <= 10^5Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #115 Zero-Sum Discount Triples. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.