Sum of Three Values

Try to solve the 3Sum problem.

Statement

Given an array of integers, nums, and an integer value, target, determine if there are any three integers in nums whose sum is equal to the target, that is, nums[i] + nums[j] + nums[k] == target. Return TRUE if three such integers exist in the array. Otherwise, return FALSE.

Note: A valid triplet consists of elements with distinct indexes. This means, for the triplet nums[i], nums[j], and nums[k], i \not = j, i \not = k and j \not = k.

Constraints:

  • 33 \leq nums.length \leq 500500
  • 103-10^3 \leq nums[i] \leq 10310^3
  • 103-10^3 \leq target \leq 10310^3

Examples

1 of 3

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:

Sum of Three Values

1

What should be the output if the following set of inputs is provided?

nums = [2, 3, 1]

target = 6

A)

True

B)

False

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.

Drag and drop the cards to rearrange them in the correct sequence.

Try it yourself

Implement your solution in main.py in the following coding playground. The supporting code template provided in two_pointers.py is meant to assist in developing your solution to the problem.

Press + to interact
Python
usercode > main.py
def find_sum_of_three(nums, target):
# Replace this placeholder return statement with your code
return False
3Sum