3Sum | LeetCode 15 | C++, Java, Python
HTML-код
- Опубликовано: 19 окт 2024
- LeetCode Solutions: • LeetCode Solutions | L...
Data Structures and Algorithms playlist: • Data Structures and Al...
Github Link: github.com/Kno...
*** Best Books For Data Structures & Algorithms for Interviews:*********
1. Cracking the Coding Interview: amzn.to/2WeO3eO
2. Cracking the Coding Interview Paperback: amzn.to/3aSSe3Q
3. Coding Interview Questions - Narasimha Karumanchi: amzn.to/3cYqjkV
4. Data Structures and Algorithms Made Easy - N. Karumanchi: amzn.to/2U8FrDt
5. Data Structures & Algorithms made Easy in Java - N. Karumanchi: amzn.to/2U0qZgY
6. Introduction to Algorithms - CLR - Cormen, Leiserson, Rivest: amzn.to/2Wdp8rZ
*****************************************************************************
July LeetCoding Challenge | Problem 8 | 3Sum | 8 July,
Facebook Coding Interview question,
google coding interview question,
leetcode,
3Sum,
3Sum c++,
3Sum Java,
3Sum python,
3Sum solution,
15. 3Sum,
#CodingInterview #LeetCode #JulyLeetCodingChallenge #Google #Amazon #3Sum
Clear explanation, Thanks
Glad you liked it
I always look for your explanation it is crisp and clear !!
Thanks.
One word for this... beautiful
Thanks.
Amazing !! Loved this Time order and code together thank you
Thank you!
air your explanation is the best
Thanks a lot 😊
Hi
Won' t the logic you explained for 2-SUM change the indices post sorting? In order to use the left-right logic, we need to sort the array. Once sorted, the indices will get updated. So the i and j will reflect indices of sorted array not the original array.
Can you please clarify?
Thanks a lot! helps me figur out how to code it.
Glad to hear.
2 pointer approach is awesome. But sir can we do it with DP...? I spent 3 hours in it....I even took 4D DP array but but didn't get correct solution. It was easily done with the help of (coin change) recursion.
Thankyou for the effort. You explained it really well.
Thanks.
Thanks
No problem
Great explanation!!!
Thanks.
very well explained.
Glad it was helpful!
Awesome video sir!!!
Keep posting them
Thank you
@@KnowledgeCenter Your Welcome sir!!!
Hope your channel reaches to 100K soon!
Thank you so much for a simpler solution!!!
Just one doubt: In python code - Line 17 - i had written 'if' instead of 'elif' and one tc was failing. What diff it will make?
because all 3 conditions are different right i.e summ == 0, summ < 0 and summ > 0 so anyway only either of these should execute. (btw we've to use summ not sum as var name - bcoz sum is keyword in python)
Thanks, This is the strategy I used as well, though I couldn't do better than 43% on the time. Maybe because I did the 2sum part as a separate function and in JS.
Anyhoo, here's a possible optimization (right after line 9 in the C++ code):
if(nums[i] > 0) break;
ehilr
just awesome
Thanks.
Thank you well explained👍 and we'll coded too I didn't knew the use of this -> {} operator in vector but now I do. Thanks to you👌
Great 👍
Keep up the good work!
Thanks, will do!
Brilliant!
Thanks.
Gajab search for one element in sorted array takes logn time
while(j < k && nums[j] == nums[j+1]) j++;
while(j < k && nums[k] == nums[k-1]) k--;
Can someone explain me what is the use these 2 while loops?
It's just like mentioned in the solution. He made the two while loops to avoid duplicate solutions for the fixed first number. So , he incremented the (j) pointer if the next element in the sorted array is equal to the the current one (which will lead to the same current solution) and the same goes for the (k) pointer but with decrementing.
2 while condition we are checking for sum==0.... We could check these conditions for sum>0 and sum
If(sum == 0) means nums[j] + nums[k] = 0. So here we have to make sure that one of these or both numbers do not repeat, as we will get duplicate answer in that, but........other if conditions do not require these while conditions as it's working the same without them.
Nice explanation sir.......
Thanks for liking
@@KnowledgeCenter Please keep on making videos on leetcode problems this is really helpful sir....
Thanks for the explanation. Always i skip the problem..Now always i have to attain... :)
thanks alot
Most welcome
How could i reach u, either give yours Instagram handle or linkedin profile
www.linkedin.com/in/iitdelhi/