Sum of Three Values
Try to solve the Sum of Three Values problem.
We'll cover the following
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], andnums[k],ij,ikandjk.
Constraints:
-
nums.length -
nums[i] -
target
Examples#
1 of 3
2 of 3
3 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
What should be the output if the following set of inputs is provided?
nums = [2, 3, 1]
target = 6
True
False
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 main.py in the following coding playground. We have provided a useful code template in the other file that you can use to solve this problem.
Solution: Sort Colors
Solution: Sum of Three Values