3Sum - Leetcode 15 - Python

preview_player
Показать описание


0:00 - Conceptual
7:50 - Coding Solution

Leetcode 15
#Coding #Programming #CodingInterview #leetcode #neetcode

Disclosure: Some of the links above may be affiliate links, from which I may earn a small commission.
Рекомендации по теме
Комментарии
Автор

Your last comment that it's a pretty hard problem and showing that you struggled was encouraging. I did both the Two Sum and Two Sum II problems but still was struggling in figuring out the solution. Thanks a lot for such a nice explanation and honest feedback! Appreciate it!

ishtiaquehussain
Автор

more than anything else i love how patient you are with us as the viewer, never skipping a step, sayng something is obvious, and offering encouragement by showing us all the times you screwed up too. it really helps. invaluable resource!!

Miniay
Автор

Man, you do explanations exceptionally clean. Please don't stop.

niko-l-
Автор

I can see this channel blowing up. just keep making vids man, these are great explanations! ty

rostm
Автор

As a guy who is struggling with the easiest of LC questions, the final part of this video is really motivating.

sujithkumar
Автор

rather than just solving the question, you helped us understand the question and how to go about solving it, and THAT is what many channels lack! Thank you so much

Cloud-
Автор

I will literally pay for leetcode premium if intuitive video explanations like these were supplied with it

mohammadusman
Автор

Thanks a lot. You must have helped thousand, if not millions of people!

MichaelButlerC
Автор

additionally
when tthreeSum==0:
along with increment i, j can be decremented too, if nums[j]==nums[j+1], because that combination is already considered
hence the code from line 17 to 21 becomes
```
else:
res.append([a, nums[l], nums[r]])
l+=1; r-=1
while nums[l]==nums[l-1] and l<r: l+=1
while nums[r]==nums[r+1] and l<r: r-=1
```

rasi
Автор

I have to say, there are few channels I will like + subscribe + hit notification bell, and you are one of them! Currently looking at practicing for interviews and this is incredibly helpful! Thank you for doing what you do!

cristianbedoya
Автор

At the beginning I was hesitant of watching this video because I'm not really proficient in Python, but the explanation of the problem was super clear and the code is so easy to understand. Good job!

valentinmorales
Автор

Just wanted to drop an appreciation comment that your explanations and videos are better than services that charge hundreds of dollars. I used to not enjoy Leetcoding because I'd get frustrated when I try to read the solutions and don't understand them, but now I do thanks to Neetcode!

htoomyatnaing
Автор

after sorting, you could check to see if the first element is greater than 0. if it is, then you can just return before looping. there's no possible triplet if the first number is greater than 0 (after sorting). if you want to add this optimization, you have to check to make sure it's not empty before trying to access first element

eecs
Автор

As someone already said, Please dont stop. Keep up the good work. This is another gem of explanation and clean solution of yours. Hats off. Loved the way how you showed all your previous failed attempts.

srinadhp
Автор

not just he explained and solved the question, He also motivated not to gets demotivated.
appreciated

deepvoyager
Автор

thanks for directing me to 2sum part 2. I was indeed able to immediately solve 3sum after i solved that one with two converging pointers.

OM-eloy
Автор

Thanks bro, I was frustrated because I was not able to solve it, so I got high, and I was high and frustrated, but now with your video I understand the solution, so now I'm high and happy, thanks a lot :)

Dexter-lwxv
Автор

Thanks Neetcode for step-by-step explanations. For people like me, who still find it difficult even after seeing Two Sum 2, do these 2 problems.

1. Two Sum 2 - Return Pairs (Assume Two Sum 2 has more than 1 unique correct pair. How do you approach?)
2. Two Sum 2 - With duplicates (Assume Two Sum 2 has duplicate numbers. How do you approach?)

Once you think along these 2 lines, 3 Sum is a cake walk.

Happy learning ! May the Vitamin M be with you !

HemprasanthTech
Автор

This is genius, I had solved the problem too but had a lot more to code to eliminate dups and was updating both ptrs after appending to the result. I love how your code only updates the left ptr and lets the existing loop update the right pointer. Also nice optimization on the GitHub version of the solution to break when encountering a positive value for the first number. Brilliant!

syafzal
Автор

The way you explained to readjust the left and right variable in case when a triplet is correctly found to find another triplet but not like the previous one proved to be very helpful for me .. Thanks

PankajKumar-fwgu
join shbcf.ru