Sum of Three Values
Try to solve the 3Sum problem.
Statement
Given an integer array, nums
, find and return all unique triplets [nums[i], nums[j], nums[k]]
, such that i
j
, i
k
, and j
k
and nums[i] + nums[j] + nums[k]
Note: The order of the triplets in the output does not matter.
Constraints:
nums.length
nums[i]
Examples
Press + to interact
1 / 4
Understand the problem
Let’s take a moment to make sure you’ve correctly understood the problem. The quiz below helps you check if you’re solving the correct problem:
3Sum
1
Which triplet is a valid solution for the array nums
that sums to zero?
A)
B)
C)
D)
Question 1 of 40 attempted
Figure it out!
We have a game for you to play. Rearrange the logical building blocks to develop a clearer understanding of how to solve this problem.
Try it yourself
Implement your solution in the following coding playground.
Press + to interact
Python
usercode > Solution.py
def three_sum(nums):# Replace this placeholder return statement with your codereturn [[]]
Click "Run" to evaluate your code.
3Sum