Problem of The Day: 08/07/2023 | Find Triplets with Zero Sum | Abhinav Awasthi

preview_player
Показать описание
Welcome to our daily problem-solving session where Abhinav will be tackling the Problem of The Day. We will be discussing the entire problem step-by-step and work towards developing an optimized solution. This will not only help you brush up on your concepts of Data Structures and Algorithms but will also help you build up problem-solving skills.

So come along and solve the POD of 08th July 2023 with us!


Daily solutions will be streamed live exclusively on our channel! So start solving today and subscribe to our channel for free coding lessons.

-----------------------------------------------------------------------------------------

🎊 Geek-O-Lympics 2023 🎊

👨‍💻👩‍💻 Build a habit of daily coding with GFG’s Problem of the Day. Participate in POTD from 1st-31st July and explain your insightful approach in the comment section.

✔ We will be selecting 1 winning comment each day for 31 days which will be selected as the “Comment Of The Day”.
✔ Each day’s winner will get a Gold Medal in Geek Olympics Medal Tally along with an Amazon Voucher worth Rs. 500.
✔ Disclaimer: You are only eligible to win the rewards if you have registered for the Geek Olympics.


-----------------------------------------------------------------------------------------

Follow us and stay updated on everything happening in the world of geeks:


#GFGPractice #GeeksforGeeks #ProblemofTheDay #CodingQuestions #POTD
Рекомендации по теме
Комментарии
Автор

In this question we have to solve the problem in O(N^2) complexity, so I used this logic. if a+b+c=0, the a+b =-c.
We first sort the array. Then, we will find a+b such that it equals -c where -c is negative of a value in array. So, I run a loop from 0 to n-1; then, val= - arr[i];
Then, we traverse on the array. we have two pointer one front and another end. Now, we find the sum= arr[front] and arr[end];
here, front is i+1, and end=n-1. Since array is sorted, sum will be modified likewise. if target < sum: front++;

else if(target>sum) end--;
else{
return sum;
}
So, basically I used sorting, a little mathematics and then pointer to solve this question in given time and space constraints.

TusharSharmaBMT