Skip to content

Practice 3Sum Closest

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#16
LeetCode Problem

3Sum Closest

Problem Statement

Given nums and target, choose three distinct array indices whose values have a sum closest to target. Return that sum. Each input has exactly one solution.

Source: 3Sum Closest on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
nums = [-1,2,1,-4], target = 1
Output
2

# Example 2

Input
nums = [0,0,0], target = 1
Output
0

Constraints

3 <= nums.length <= 500
-1000 <= nums[i] <= 1000
-10^4 <= target <= 10^4

Related LeetCode Problems

Practice more problems similar to 3Sum Closest.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.