Tap here to switch tabs
Problem
Submissions

Problem: 4Sum

med
30 min
Explore the 4Sum problem where you identify all unique quadruplets in an integer array that sum to a given target. Learn to implement an optimized solution running in cubic time and understand the process of ensuring quadruplet uniqueness and distinct indices.

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

Unlock AI-Powered LearningUpgrade to smarter learning with instant explanations of Ask Agent, Personalized Interview Prep, Real-World Projects, 3 AI Mock Interviews per month, and Personalized Paths
Tap here to switch tabs
Problem
Submissions

Problem: 4Sum

med
30 min
Explore the 4Sum problem where you identify all unique quadruplets in an integer array that sum to a given target. Learn to implement an optimized solution running in cubic time and understand the process of ensuring quadruplet uniqueness and distinct indices.

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

Unlock AI-Powered LearningUpgrade to smarter learning with instant explanations of Ask Agent, Personalized Interview Prep, Real-World Projects, 3 AI Mock Interviews per month, and Personalized Paths