Solution: Sum of Three Values

Let's solve the 3Sum problem using the Two Pointers pattern.

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