The Triple Seeker
HardAcc. 68.5%
+50 XP 25
Combinatorial Balance
Given an array, find all unique triplets $[a, b, c]$ such that $a + b + c = 0$.
The Assignment
Your function receives nums.
- First, sort the array.
- Iterate through with index
i. Skip duplicates. - For each
i, use Two Pointers (left = i+1,right = end) to find sums that equal-nums[i]. - Print each triplet on a new line (format:
a b c).
01EXAMPLE 1
Input
[-1, 0, 1, 2, -1, -4]Output
-1 -1 2
-1 0 1Explanation: Unique triplets.
Constraints
- Avoid duplicate triplets.
- O(n^2) time complexity.
ArraysTwo Pointers
JavaScriptSystem handles I/O — write your function only
Loading...
1 Hidden
Input Arguments
nums[-1,0,1,2,-1,-4]
Expected Output
-1 -1 2 -1 0 1
Click RUN to test your solution