Solution: 4Sum

Let’s solve the 4Sum problem using the Two Pointers pattern.

Statement

Given an array nums of nn integers, return an array of all the unique quadruplets, [nums[a], nums[b], nums[c], nums[d]] such that:

  • 00 \leq a, b, c, d <n< n

  • a, b, c, and d are distinct.

  • nums[a] + nums[b] + nums[c] + nums[d] == target

You may return the answer in any order.

Constraints:

  • 11 \leq nums.length ...