Two Sum | LeetCode 1 | JavaScript | Easy

preview_player
Показать описание
In painstaking detail, I go through my entire thought process for solving Two Sum from first principles. We'll start with the essential insights that lead us to the brute-force solution. From there, we'll optimize to get various performant O(n) time approaches. Finally, we'll discuss the pros/cons of our performant approaches.

0:00 Two sum problem statement
0:21 Initial thought process
1:14 Brute-force implementation & analysis
3:03 Optimizing our initial approach
7:28 Implementing a faster algorithm
7:50 What about the one-pass approach?
8:20 Coming up with the one-pass
9:55 Why the one-pass is so awkward
12:03 The most important part
Рекомендации по теме
Комментарии
Автор

The best breakdown I have ever came across! EVER. Thank you for the intense amount of work that went into this video.

willbdev
Автор

I am a visual learner and have been a software engineer for over 10 years. This is by far the most clear (and beautiful) explanation of any algorithm I've ever seen. I will be anticipating with excitement your next videos. Please keep this format!

germain
Автор

Very underrated channel. Very creative way to teach! You're going to go big in future for sure!

shantanu
Автор

To teach this way requires not only meticulous technique, but also a high dose empathy. Great work as always

jim.....
Автор

Wow! I love how you explain how the one pass solution is actually not great (for clarity and mental overhead). Excellent video!

janelledement
Автор

Dude, I love this kind of stuff. And I love teaching people. I’ve been toying with the idea of making a channel to teach CS concepts. Every time I feel ready to pull the trigger and get started I take a look at existing channels. Your content is outstanding. It’s very well thought out. It’s showing the thought process and diagram in addition to multiple solution paths and breaking down time and space complexity in an easy to understand format … and this channel has very few views and very few subs.

I think you’re awesome. I really wish there was more of an audience for your work.

zero
Автор

this channel is so underrated, today i discovered Two Sum problem and decided to know more about it, thanks for this video

existentialism_
Автор

This was really excellent. The animation for the brute force solution was such a useful and concrete way of holding the solution in my head. It made it much easier to follow each of your questions, and the systematic way you approached improving on your initial solution, all while being assured of correctness.

The take-aways for me:
- look for insights to solve the problem by diagramming
- use prompts to improve your solution e.g. perfect information
- don't code until you're certain of your approach
- use simple examples to test out ideas

ranga
Автор

This is the most clear explanation of an algorithm I have ever seen. Awesome, subscribing now. Hoping to see more. Thank you for this beautiful explanation it helps a lot.

Fidohn
Автор

Love your video mate, wish you luck with your future videos

gyrozepelix
Автор

Amazing video! I love that you begin with the simplest brute force approach and improve on it incrementally. The questions you ask yourself during the problem solving process are really useful. They give me a clue on how I could come up with the solutions on my own.

Other Two Sum videos I watched skipped straight from brute force to the one pass approach. I like that you provided the two pass solution and also explained that it's arguably the better approach in comparison to the one pass.

anthonyxie
Автор

Dude, this is very good. I hope your channel grows

Mahfyw
Автор

Thank you so much for the detailed analysis. I just started LeetCode and struggled with it, but now I think I can make it! Thank you for your guidance❤

grace.newlife
Автор

Incredible !
I need to get my algorithmic logic together in order to pass interview tests. It's my main weakness. I very good with html and css but not abstract thinking. And you are right when you say that if you observe and focus on the questions/hints, it takes you to the solution.

AllanRolle
Автор

I loved this... subscribed and liked!!!!

antonionelson
Автор

Great job! Thank you so much! Love the mindset and the realization of the video. Subscribed right away :)

Timeus
Автор

Wonder if they make sense;

1) numberToIndex[num[i]] = i has to go last:
Avoid returning the same index when num[i] is exactly half the target.

2) numberToIndex[numberNeeded] !== i is not needed anymore:
When numberToIndex[num[i]] = i goes last, the current index i will not be in the map YET. So in the case of two elements(different indexes) having the same value(exactly half the target), index i and the index stored at numberToIndex[numberNeeded] will always be different and correct.

Production value is great Gordon! Love the simple yet very functional animations in terms of visualizing the thought process.

KennyChowPD
Автор

great explanation! i have seen nobody that explains this deeply, with detail. if background music was lower, it would be great

oliver
Автор

Holy crap! Best visuals for thinking about algorithms wrt ds+a, really helps me visualize the solution. I don’t know how I didn’t find your channel sooner but please continue putting out bangers like this!

Funny pat is I had already solved this problem before and I actually solved it using the last solution because that was the first thing I thought of. I never thought of the one pass solution but the part I think I need to practice and learned the most from was the questions you asked to come up to the solutions. I never thought or the idea of “perfect information”, was that something you came up with yourself or a concept formalized somewhere where I can learn more?

babyboie
Автор

I solved this problem but it still showed error 1 hour of figuring out what was wrong in the logic at the end my mistake was i was using
console.log(' ') instead of return haha

raghabpandit
welcome to shbcf.ru