FastPrepThree Sum Closest
Problems/Three Sum Closest

Three Sum Closest

Amazon logoAmazon● MediumFULLTIMEPHONE SCREEN
QuestionFunctionExamplesConstraints

Problem statement

Source note: The source names the conventional 3Sum Closest exercise but omits its interface, examples, bounds, and tie behavior. The judged version chooses the smaller sum on an equal-distance tie, so the core task match is about 93%.

Given an integer array nums and an integer target, choose three distinct indices and return the sum of their values that is closest to target.

If two obtainable sums are equally close, return the smaller sum.

Function

threeSumClosest(nums: int[], target: int) → int

Examples

Example 1

nums = [-1,2,1,-4]target = 1return = 2

The closest sum is -1 + 2 + 1 = 2.

Example 2

nums = [0,0,0]target = 1return = 0

The only possible sum is 0.

Example 3

nums = [-2,0,2,4]target = 1return = 0

Sums 0 and 2 are both one away, so the smaller sum 0 is returned.

Constraints

  • 3 <= nums.length <= 1000.
  • -10^4 <= nums[i], target <= 10^4.
  • The answer fits in a signed 32-bit integer.

More Amazon problems

  • Count Adjacent Symbol Pairs for BPEONSITE INTERVIEW · Seen Nov 2026
  • First Non-Repeating CharacterOA · ONSITE INTERVIEW · Seen Nov 2026
  • Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
See Amazon hiring insights
Saved
class Solution {
    public int threeSumClosest(int[] nums, int target) {
      // write your code here
    }
}
Checking account…