Two Sum - Leetcode 1 - HashMap - Python

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


0:00 - Brute Force (Conceptual)
1:50 - One Pass (Conceptual)
6:54 - Coding one pass solution

leetcode 1
#python #hashmap #CodingInterview

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

Interview tip:
If the interviewer asks something and you don't know the answer, just answer "a hash map should do the trick". 90% success rate 70% of the time.

BirinderSingh
Автор

Thank you NeetCode for the incredible explanation videos, and the BLIND-75 playlist particularly!! I can confidently say that your videos were an integral part of me being able to get an exciting new position with a global tech company. I'll definitely be supporting your channel through Patreon, and looking forward to your future content!

timkim
Автор

I can't thank you enough. I've never seen anyone making the explaination this simple/easy/concrete

shanekim
Автор

It makes sense, there are 2 values needed for a sum. One of the values has to appear after another. Cool work around.

IhsanMujdeci
Автор

God, Im a SWE but suck so bad at these leetcode questions

jixster
Автор

Nice, I only got it through the comparison with hashmap way. Your one way pass was really good and informative :) had to watch and compare codes for some time to better understand. Hopefully, I get used to recognizing these patterns or techniques to do things and use it next time.

HarimaKentaro
Автор

Thank you so much. I've had no idea except brute force but your solution is so easy!

vonmansfeld
Автор

something else that's worth mentioning is that there exists a O(n log n) solution. this obviously is inferior to the average case O(n) performance of a one-pass hash table, but it's worth mentioning. this is from the CLRS algorithms textbook, exercise 2.3-7.

basically, the procedure is to first perform a merge sort on the array, followed by a binary search of the complement of each element. the merge sort takes O(n lg n) time, and performing a binary search (log n time) on n elements takes O(n lg n) time. thus, the entire algorithm takes O(n lg n) time.

ujewfmr
Автор

I know how to solve a lot of leetcode problems but I don’t know how to explain in detail what I’m doing during interviews. Essentially idk how to sound more technical and I gotta say these videos have been a big help.. I also started helping friends(forcing them to do leetcode session) so I can improve lol

bigazTV
Автор

I stored all the pairs of indies and values and sorted the array and used the two pointers that starts at the each edge of the array. More comlicated and inefficient. This solution is really nice. Your ability to figure what you have to do to solve a question is really amazing. I've learned a lot today too! Thanks a lot!

licokr
Автор

Well that was a success. As i got understood how hash table works. Thanks 😊

hridyepuneetsingh
Автор

video is helpful. one advice: -don't put the next video link/thumbnail at the end of the video. it covers the code part. if you want to put then add a 10-sec blank screen at the end and put there.

lalitmali
Автор

Thanks for the breakdown of this solution, very helpful.

ChaosArtist
Автор

As someone who is new to python, the most confusing part was people calling it hasmap and not dictionary. It only clicked for me when I realised that it is just a dictionary.

rain-er
Автор

class TwoSum:
def summation(self, nums, target):
prevMap = {}

for i, n in enumerate(nums):
diff = target - n
if diff in prevMap:
return [prevMap[diff], i]
prevMap[n] = i
return

kvelez
Автор

Your channel is so underrated!! Thank you so much it was veryyyy helpful!!!❤️❤️❤️❤️

mitalikambli
Автор

you sir, is god sent! I used your idea and beat 97% python submissions! I started with a timeout!

izzyr
Автор

out here loving the tutorial and then you open python and I go blind from the white background😂 love the video tho!

justinskaggs
Автор

thanks man ! i came looking for u only

Shanky_
Автор

Thanks for the explanations..Helped me a lot Sir!!

rishikeshv.m