SarthakKeshari / CPP-Questions-and-Solutions

This repository aims to solve and create new problems from different spheres of coding. A path to help students to get access to solutions and discuss their doubts.
MIT License
47 stars 132 forks source link

3 sum closest #539

Open rahulgoyal8312 opened 2 years ago

rahulgoyal8312 commented 2 years ago

Choose your form and fill it -

1. Form 1(C++ Solution contributors)


1) Form 1

Issue Id you have worked upon -

Given a target element, need to find the sum of exactly three numbers from an array which should be around or equal to that target element.

Briefly explain your program logic -

Sort the array provided, then using two pointer approach need to calculate the sum of (currentIndex) + (currentIndex+1) + (RightIndex) and find the absolute difference and keep track of a variable "closest" which will be updated if the resultant value is lower than existing closest value.

Screenshots(Attach 2 screenshots of your own input and output) -

Screenshot 2021-10-31 at 2 14 11 AM Screenshot 2021-10-31 at 2 14 37 AM


Checklist:

Eg - If your code follow the below guidelines. Kindly change [] to [x]

All the conditions should be fulfilled for considering your code for merging -

SarthakKeshari commented 2 years ago

@rahulgoyal8312, Kindly create an issue first and then PR. And follow the PR template and contribution guidelines. I am not closing this PR since this was your first time. You may refer CONTRIBUTING.md(present in the repository) and create an issue(iff program has not been done in repositories probable folders).

If above given lines follow, then kindly create an issue now and claim it. I will assign it to you.

rahulgoyal8312 commented 2 years ago

@SarthakKeshari Do take a look at this PR for the 3 Sum Closest issue that you've assigned.