Three Sum

Given an integer array nums, return every distinct triplet of values whose sum is zero. Use distinct input indices for each tuple. Equal values are allowed if…

Given an integer array nums, return every distinct triplet of values whose sum is zero. Use distinct input indices for each tuple. Equal values are allowed if enough separate occurrences exist. Return an empty list when no tuple exists. Inner and outer order do not matter, but return each value tuple only once. The function may reorder nums.

1 <= nums.length <= 3000 -10000 <= nums[i] <= 10000 Return every distinct tuple of exactly 3 strict integers; all tuple indices are distinct. Coding accepts the full bounds; the preset visualizer uses at most 12 values.

Example 1: input nums = [2, -2, 0, 3, -3, 5]; output [[-3, -2, 5], [-3, 0, 3], [-2, 0, 2]]. Each listed tuple uses distinct positions. Reordering the values or the tuple list is also valid; duplicate tuples must not be returned.

Example 2: input nums = [2, -1, -1, 3, -1]; output [[-1, -1, 2]]. Each listed tuple uses distinct positions. Reordering the values or the tuple list is also valid; duplicate tuples must not be returned.

Category: Two Pointers. Topic: two-pointers. Difficulty: Medium. Patterns: two-pointers, hashing.