3Sum Closest

Medium
ArrayTwo PointersSortingAmazonMeta
Given an integer array and target, choose three distinct indices whose values have the sum closest to the target. Print that sum. Input format: - First line: n target - Second line: n integers If two sums are equally close to the target, print the smaller sum.

Constraints

3 <= n <= 3000
-10^5 <= nums[i], target <= 10^5

Sample tests

Sample 1

Sample 2

Sign in to submit