Try to solve the 4Sum problem.


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 we get the following:

  • 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.


  • 11 \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


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