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


 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:


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.