4Sum

Try to solve the 4Sum problem.

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:

  • 0≤0 \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:

  • 1≤1 \leq nums.length ≤200\leq 200

  • −109≤-10^9 \leq nums[i] ≤109\leq 10^9

  • −109≤-10^9 \leq target ≤109\leq 10^9

Examples

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.