Problem
Ask
Submissions

Problem: 4Sum

Medium
30 min
Explore how to identify all unique quadruplets in an integer array that sum to a given target, and implement an optimal O(n^3) time solution. Understand the logic behind the problem and practice coding in a hands-on environment to enhance your algorithm skills.

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 200\leq 200

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

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

Problem
Ask
Submissions

Problem: 4Sum

Medium
30 min
Explore how to identify all unique quadruplets in an integer array that sum to a given target, and implement an optimal O(n^3) time solution. Understand the logic behind the problem and practice coding in a hands-on environment to enhance your algorithm skills.

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 200\leq 200

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

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