Four Sum

Given an integer array nums and an integer target, return every distinct quadruplet of values whose sum is target. Use distinct input indices for each tuple.…

Given an integer array nums and an integer target, return every distinct quadruplet of values whose sum is target. 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 <= 200 -10000 <= nums[i] <= 10000 -10000 <= target <= 10000 Return every distinct tuple of exactly 4 strict integers; all tuple indices are distinct. Coding accepts the full bounds; the preset visualizer uses at most 8 values.

Example 1: input nums = [1, -2, 3, 5, 7, 9], target = 7; output [[-2, 1, 3, 5]]. 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 = [7, -7, 1, 2, 14, 3], target = 9; output []. 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.