3 Sum

Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target.
Return the sum of the three integers.

Assume that there will only be one solution

Example:
given array S = {-1 2 1 -4},
and target = 1.

The sum that is closest to the target is 2. (-1 + 2 + 1 = 2)

Interview Code Editor
Hints
  • Hint 1
  • Solution Approach
  • Complete Solution
5758 successful submissions.
Asked In:
  • Facebook
  • Amazon
  • Microsoft
Click here to jump start your coding interview preparation