Тёмный

Leetcode Two Sum Solution | Coding Interview Question 

techsith
Подписаться 148 тыс.
Просмотров 33 тыс.
50% 1

Two Sum Leetcode JavaScript solution O(n) | number one interview coding interview question | conmanly asked algorithm question
#algorithms #leetcode #interviewQuestions
*Code
codepen.io/techsithcode/pen/E...
*My Courses
www.learn.heapskills.com/cour...
www.learn.heapskills.com/cour...
Follow me
* / techsith
* / algoanddsinjavascript
* / techsith
* / techsith1
* / 13677140
* / patelhemil
Help me translate this video.
* ru-vid.com_cs_...
Note: use translate.google.com/ to translate this video to your language. Let me know once you do that so i can give you credit. Thank you in advance.

Наука

Опубликовано:

 

18 авг 2020

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 65   
@midnightrun5
@midnightrun5 3 года назад
You always provide exceptional tutorials. Thank you for taking the time to put this together.
@themynamesb
@themynamesb 3 года назад
liked this video.. good work.
@patrickchan2503
@patrickchan2503 3 года назад
I have watched other RU-vidrs' videos of the same question, yours is brilliant, thank you very much.
@PG1131
@PG1131 3 года назад
This is by far the CLEAREST explanation of this LeetCode problem. Thank you 👍👍👍
@Techsithtube
@Techsithtube 3 года назад
Glad it helped!
@sajjadkazi1806
@sajjadkazi1806 3 года назад
Thank You for the very Detailed Explanation
@suri5023
@suri5023 3 года назад
I LOVE YOU! thank you so much, man. I could not understand this because I am new to algorithms. thanks for the video
@pratikkumar939
@pratikkumar939 3 года назад
I always watch ur videos for interview prep. I ll tell u this ds n algo series that u r doing is going to be the most valuable one
@Ali-mc4le
@Ali-mc4le 3 года назад
learn Algorithms and Data Structures: www.udemy.com/course/coding-interview-crash-course-for-web-developer-2020/?couponCode=ADA6B72288D49A1CAE25
@malikasultanova9950
@malikasultanova9950 3 года назад
Thank you, best explanation.
@abdella4
@abdella4 2 года назад
Thanks for the video. I'm just confused by one part that I hope you can help me with. In the conditional statement, if the first cycle of the for loop is i=0, that would be equal to the first item in the array which is 2. The key value of 2 in comp is 1. So wouldn't it be [1,0] for the answer?
@AshishGupta-be2yz
@AshishGupta-be2yz Год назад
Wow! thanks man you have explained soo damn easily. Good job brother.
@techbhupi9398
@techbhupi9398 3 года назад
Wao thanks for starting this series...will be very helpful for all students .Thanx a ton sir❤️
@Techsithtube
@Techsithtube 3 года назад
It's my pleasure. Thanks for watching!
@krishnanspace
@krishnanspace 3 года назад
Hey, Techsith. Loved this video. Please do more on these Leetcode questions
@Techsithtube
@Techsithtube 3 года назад
Just released a new video . Please do check it out. !
@Ali-mc4le
@Ali-mc4le 3 года назад
learn Algorithms and Data Structures: www.udemy.com/course/coding-interview-crash-course-for-web-developer-2020/?couponCode=ADA6B72288D49A1CAE25
@chirag2005
@chirag2005 3 года назад
More leetcode problems, please 👍🏽
@Techsithtube
@Techsithtube 3 года назад
More to come! I am planning to make release leet code videos on regular basis. Thanks for watching!
@sadiksaroar7053
@sadiksaroar7053 Год назад
Thank
@rishiraj2548
@rishiraj2548 Год назад
🙏👍💯
@yatchan
@yatchan 3 года назад
Good explanation. You can also use the forEach and for ... of loops. In that way, you can get rid of the array length and "i", but have to use indexOf instead. I don't know, which is better performance-wise. Also, isn't using the set() and get() methods the "more proper" way of setting and accessing values in a Map object? function twoSum(nums, target) { const comp = new Map() nums.forEach(num => { comp.set(target - num, nums.indexOf(num)) }) for (let num of nums) { if (comp.has(num)) { return[nums.indexOf(num), comp.get(num)] } } }
@Techsithtube
@Techsithtube 3 года назад
Yatchan , set is the right way of using maps. However the second forloop is not needed. you can simply use comp.has in the first loop.
@yatchan
@yatchan 3 года назад
@@Techsithtube You're right, that's much simpler! However, from what I'm aware, you can't just return a value from inside of forEach loop and exit it. Instead you can push the pair to some other variable and return it after the loop ends. That way it would work even when there is more than one pair of numbers satisfying the equation. There's also an option to use reduce(): const comp = new Map() return(nums.reduce((_acc, num) => { comp.set(target - num, nums.indexOf(num)) if (comp.has(num)) { return _acc.concat([[nums.indexOf(num), comp.get(num)]]) } else return [] }, [])) I would also be happy to see the leetcode video series. Keep up the good job!
@romikonlinepotapenko3475
@romikonlinepotapenko3475 3 года назад
I didn't even know that it is possible to use bracket notation with maps. It seems that when you add a property using bracket notation it just becomes a generic property of that map object, but it is not iterable (it won't be revealed in a for/of loop). When you add properties to a map object using set(), those properties will be iterable.
@jeyraj3075
@jeyraj3075 3 года назад
Nice video...We need more tutorials like this...
@Techsithtube
@Techsithtube 3 года назад
More to come! I am planning to make release leet code videos on regular basis. Thanks for watching!
@jeyraj3075
@jeyraj3075 3 года назад
@@Techsithtube Thank you so much...
@caesarbala
@caesarbala 3 года назад
when i decided to learn angular you posted video about angular series i got job in service based company. When i decided to learn DS and algorithm you are posting videos on same topic :) thanks a lot guru ji :)
@Techsithtube
@Techsithtube 3 года назад
Great to hear! keep up the good work!
@NCJHE
@NCJHE 2 года назад
Could we also do it another way by adding the current value into the hash table rather than the difference? for example we do i = 0, there's nothing in the hash table so we add it in there, then when i = 1, we find the compliment of that in the hash table so we return those 2 indices? I have seen it done both ways.
@hectorkaizenf.v.7224
@hectorkaizenf.v.7224 3 года назад
why " const com = new Map(); " have a value in " if " statement? why "complement[nums[i]]" have value? I never see that you assing key / value to that Map() can you explain please?
@arunkaiser
@arunkaiser 3 года назад
Love ❤ u dear 💕
@Imgahlot
@Imgahlot 3 года назад
I started giving interview after 2-3 years, most of the companies are asking algo and DS. Although didn't realise it is really important for frontend. But knowledge always helps us to become better and better. Thanks for coming up with these topics, it more like you heard from my inner soul that I really need DS / Algo enhancements . Thanks always like the way you explain stuffs. 👍
@Techsithtube
@Techsithtube 3 года назад
Yes mohit, most companies ask for DS and Algo, and its not that hard if you practice for atleast a month. I will keep making more such videos . keep on practicing . Good Luck with the interviews.
@deepat1189
@deepat1189 3 года назад
Please make vedios on angular 2+
@satyadeeproat2012
@satyadeeproat2012 3 года назад
@techsith. Start playlist for leetcode type questions. Even frontend developers are asked these questions. Also can you make Videos on Design questions for senior engineers.
@Techsithtube
@Techsithtube 3 года назад
Satyadeep, I will keep making more such videos and create a play list from easy to hard. I am also planning to do design question on ui side and some architecture level.
@ankitalal114
@ankitalal114 3 года назад
@@Techsithtube please make videos for design questions on ui.
@srinivasaprabus1686
@srinivasaprabus1686 3 года назад
Hi, can you make some detailed video on Event loop in Javascript. Eagerly expecting
@Techsithtube
@Techsithtube 3 года назад
srinivasa, Sure I will add that to the queue. Thanks for the suggestion.
@nativeKar
@nativeKar 3 года назад
Sir, can you please elaborate on the condition within the if block? I'm not quite sure how that works since most of times, the value of comp[nums[i]] would return undefine.
@Techsithtube
@Techsithtube 3 года назад
comp[nums[i]] if returns undefined than we know we have not found the value . putting it in if statement converts it to a boolean. if returns something than true else false.
@nativeKar
@nativeKar 3 года назад
Got it! Thanks for clearing that up.
@dilshadazam880
@dilshadazam880 3 года назад
Thank you so much. I started learning java script a month ago because of you.How can I appear in one of your interviews.
@Techsithtube
@Techsithtube 3 года назад
Send me an email and we can set it up. you can find my email on the channel page.
@himanshubansal6425
@himanshubansal6425 3 года назад
More leet code problem please
@Techsithtube
@Techsithtube 3 года назад
More to come! I am planning to make release leetcode videos on regular basis. Thanks for watching!
@michaelrooze278
@michaelrooze278 3 года назад
why do you use len for array?
@oskariloytynoja4366
@oskariloytynoja4366 3 года назад
Isn't the time complexity still O(n^2) since Javascript maps aren't hashmaps but just linked lists?
@Techsithtube
@Techsithtube 3 года назад
JavaScript is bit weird, arrays are also linkedlists. However, the purpose of using specific data structure in an interview is to assume that you know about the data-structure and your knowledge of data structure is clear. underlying implementation of that data-structure doesn't matter.
@dipeshranavlogs
@dipeshranavlogs 3 года назад
Will it work if the array is like [3,5,4,1,0]... How your code is working without 2 for loops ? Is it due to this map thing
@Techsithtube
@Techsithtube 3 года назад
this would work for any array with numbers. yes map has quick lookup which means I dont have go through all the elements to find the value so you avoid one more for loop
@GarrettBSettles
@GarrettBSettles 2 года назад
why the bit about >= 0 ? couldn't you just check if it were defined?
@keerthivasan138
@keerthivasan138 2 года назад
can you find the answer for that
@pppluronwrj
@pppluronwrj 3 года назад
what is null>0?
@venkatesh2788
@venkatesh2788 3 года назад
Sir i can't understand the JavaScript playlist, so kindly make all JavaScript playlist in one video please, it may be 10 hours course also ok please make a video
@Techsithtube
@Techsithtube 3 года назад
Here you go, I created a ru-vid.com/group/PL7pEw9n3GkoWJcepB1U9OaOKMXPJTroZ- for all the videos on similar topics.
@nidhikourav7255
@nidhikourav7255 3 года назад
how does brute force algo works?
@Techsithtube
@Techsithtube 3 года назад
Brute force is obvious but not optimal . In this case you can have two loops and compare every number with every other number to see if it adds up to the total .
@shasankpandey6995
@shasankpandey6995 3 года назад
Hi sir ...can u pls give me refrence of good resource where i can practice for coding round.
@Techsithtube
@Techsithtube 3 года назад
leetcode site is a pretty good reference , they give you solutions to some questions for free and if you pay little money, you get access to all the solutions.
@shasankpandey6995
@shasankpandey6995 3 года назад
@@Techsithtube sir ....i want to request one thing....please make some videos regarding jwt authentication,token refresh,autologout in react....
Далее
Tricky JavaScript interview questions and answers
21:01
Median of two sorted arrays
17:05
Просмотров 16 тыс.
How to Start Leetcode in 2024 (as a beginner)
8:45
Просмотров 675 тыс.
Tricky JavaScript Interview Questions and Answers
16:35
Top Tricky JavaScript Interview Questions and Answers
15:42
Python Programming Practice: LeetCode #1 -- Two Sum
13:09
Девушка и AirPods Max 😳
0:59
Просмотров 16 тыс.
Мечта Каждого Геймера
0:59
Просмотров 1,4 млн