top of page

Looking to master object-oriented and system design for tech interviews or career growth?

  • Improve your system design and machine coding skills.

  • Study with our helpful resources.

  • Prepare for technical interviews and advance your career.

**We're in beta mode and would love to hear your feedback.

Writer's pictureilluminati

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.

Comments


bottom of page