3Sum Closest - aloalgo

3Sum Closest

Hard

You are given an array nums of n integers and an integer target, find three integers in nums such that their sum is closest to target. Return the sum of the three integers. You may assume that each input would have exactly one solution.

Example 1

Inputs
nums = [-1, 2, 1, -4]
target = 1
Output
2
Explanation:

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

Example 2

Inputs
nums = [0, 0, 0]
target = 1
Output
0
Explanation:

The only possible sum is 0 (0 + 0 + 0 = 0), which is closest to 1.

Example 3

Inputs
nums = [1, 1, -1, -1, 3]
target = -1
Output
-1
Explanation:

The sum -1 + -1 + 1 = -1 is the closest to the target -1.

Loading...
Inputs
nums = [-1, 2, 1, -4]
target = 1
Output
2

Hello! I am your ✨ AI assistant. I can provide you hints, explanations, give feedback on your code, and more. Just ask me anything related to the problem you're working on!