Sort the array. For each element nums[i], use two pointers to search for a pair where nums[i] + nums[left] + nums[right] is closest to target.
If the current sum equals the target, return immediately. Otherwise, if the sum is less than target, move left pointer right to increase the sum. If greater, move right pointer left to decrease it.
Track the closest sum seen so far. Update it whenever you find a sum with smaller absolute difference from target.
With nums = [-4, -1, 1, 2] (sorted) and target = 1: fix -4, then use two pointers on [-1, 1, 2]. Try different combinations, tracking which gets closest to 1.