Given an integer array `nums` of length `n` and an integer `target`, 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 1
Input: nums = [-1,2,1,-4], target = 1
Output: 2
Explanation: The possible sums are -1+2+1 = 2, -1+2-4 = -3, -1+1-4 = -4 and 2+1-4 = -1. The sum 2 is only 1 away from the target 1, which is the closest.
Example 2
Input: nums = [0,0,0], target = 1
Output: 0
Explanation: There is only one way to pick three numbers: 0 + 0 + 0 = 0, so 0 is the closest sum to 1.
Example 3
Input: nums = [1,1,1,0], target = -100
Output: 2
Explanation: Every sum is far above -100, so the best choice is the smallest possible sum: 0 + 1 + 1 = 2.
Sort the array, then fix each element and sweep the remaining range with two pointers. Because the array is sorted, moving the pointer inward changes the sum predictably: if the current triple is below target move the left pointer right, otherwise move the right pointer left. Track the closest sum seen.
Run checks all cases above. Submit evaluates all test cases.