3 Sum - InterviewBit Solution
Problem: 3 Sum
Problem Description:
Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers.
Assume that there will only be one solution
Example:
given array S = {-1 2 1 -4},
and target = 1.The sum that is closest to the target is 2. (-1 + 2 + 1 = 2)
Solution Approach:
Solution:
Code in C++
If you have any questions or queries, feel free to drop a comment in the comments section below.
Note: Help us improve this blog
If you have a better solution, and you think you can help your peers to understand this problem better, then please drop your solution and approach in the comments section below.
We will upload your approach and solution here by giving you the proper credit so that you can showcase it among your peers.



https://casinosvensklicensfri.com actually made me think about how much this problem resembles the two-pointer variant I struggled with last week, since the closest-sum twist forces you to track the minimum difference rather than an exact match. Keeping a running best sum instead of returning early is the part I always forget under pressure. I ended up writing a brute force version first just to sanity-check my output against the sample.