Complete the code to sort the input array before processing.
nums.[1]();Sorting the array helps to use two pointers efficiently and avoid duplicates.
Complete the code to skip duplicate elements for the first pointer i.
if (i > 0 && nums[i] === nums[i - 1]) [1];
Using 'continue' skips the current loop iteration to avoid processing duplicates.
Fix the error in the while loop condition to move the left pointer correctly.
while (left < right && nums[left] === nums[left - 1]) [1]++;
We move the left pointer forward to skip duplicates after finding a valid triplet.
Fill both blanks to correctly move pointers when sum is less or greater than zero.
if (sum < 0) [1]++; else [2]--;
When sum is less than zero, move left pointer right to increase sum; else move right pointer left to decrease sum.
Fill all three blanks to add the triplet and skip duplicates after finding a valid triplet.
result.push([nums[i], nums[left], nums[right]]); while (left < right && nums[left] === nums[left + [1]]) [2]++; while (left < right && nums[right] === nums[right - [1]]) [3]--;
After adding a triplet, we skip duplicates by moving left pointer forward and right pointer backward by 1 step.
