#K78187. Three Sum Closest

    ID: 35031 Type: Default 1000ms 256MiB

Three Sum Closest

Three Sum Closest

Given an array of integers \(nums\) and an integer \(target\), your task is to find three integers in \(nums\) such that the sum is closest to \(target\). Return the sum of the three integers.

You may assume that each input would have exactly one solution.

Example:

Input: nums = [-1, 2, 1, -4], target = 1
Output: 2
Explanation: The sum that is closest to the target is 2 (-1 + 2 + 1 = 2).

Note: The absolute difference is defined as \(|a - b|\) for any two numbers \(a\) and \(b\).

inputFormat

The first line of the input contains an integer \(n\) representing the number of elements in the array.

The second line contains \(n\) integers separated by spaces.

The third line contains the integer \(target\).

outputFormat

Output a single integer, which is the sum of the three integers that is closest to the target.

## sample
4
-1 2 1 -4
1
2