Four Sum - aloalgo

Four Sum

Hard

You are given an array nums of n integers, find all unique quadruplets [a, b, c, d] in nums such that a + b + c + d equals a given target integer.

The solution set must not contain duplicate quadruplets. You may return the answer in any order.

Example 1

Inputs
nums = [1, 0, -1, 0, -2, 2]
target = 0
Output
[
  [-2, -1, 1, 2],
  [-2, 0, 0, 2],
  [-1, 0, 0, 1]
]
Explanation:

The quadruplets (-2, -1, 1, 2), (-2, 0, 0, 2), and (-1, 0, 0, 1) each sum up to 0.

Example 2

Inputs
nums = [2, 2, 2, 2, 2]
target = 8
Output
[
  [2, 2, 2, 2]
]
Explanation:

The only unique quadruplet that sums to 8 is (2, 2, 2, 2).

Example 3

Inputs
nums = [0, 0, 0, 0]
target = 0
Output
[
  [0, 0, 0, 0]
]
Explanation:

The only unique quadruplet is (0,0,0,0) which sums to 0.

Loading...
Inputs
nums = [1, 0, -1, 0, -2, 2]
target = 0
Output
[
  [-2, -1, 1, 2],
  [-2, 0, 0, 2],
  [-1, 0, 0, 1]
]

Hello! I am your ✨ AI assistant. I can provide you hints, explanations, give feedback on your code, and more. Just ask me anything related to the problem you're working on!