Merge Two Sorted Linked Lists (LeetCode 21) | Full solution with Examples | Study Algorithms

  Рет қаралды 33,038

Nikhil Lohia

Nikhil Lohia

Күн бұрын

Пікірлер: 51
@ashok2089
@ashok2089 9 ай бұрын
You made it easily understandable with the help of clearly drawing example...Thanks!
@souravdebnathx
@souravdebnathx 3 жыл бұрын
best easy explaination ever i searched!
@nikoo28
@nikoo28 3 жыл бұрын
Glad I could help you out :)
@vikasvarma9462
@vikasvarma9462 2 ай бұрын
best sir jii very good explanations ❤❤
@satyamgupta6030
@satyamgupta6030 Жыл бұрын
great explaination bhaiya keep making such awesome videos for us.
@nikoo28
@nikoo28 Жыл бұрын
so glad you liked it
@gokulnaathb2627
@gokulnaathb2627 8 ай бұрын
Super approach!
@taniyasharma8924
@taniyasharma8924 3 ай бұрын
Hey, this is giving time limit exceeded on leetcode.. can you please help
@ganeshjaggineni4097
@ganeshjaggineni4097 Жыл бұрын
NICE SUPER EXCELLENT MOTIVATED
@zewdih3871
@zewdih3871 11 ай бұрын
Excellent Explanation
@nikoo28
@nikoo28 10 ай бұрын
Glad it was helpful!
@ellase8747
@ellase8747 3 жыл бұрын
Hi, thank you so much for this explanation. Why the variable headNode never used?
@nikoo28
@nikoo28 3 жыл бұрын
We need a starting point when creating a new list. This headnode acts as a sentinel node which is used for temporary purpose and such that we don’t lose track of the starting point.
@zack176
@zack176 Жыл бұрын
​@@nikoo28is this python language
@priyanshgarg1292
@priyanshgarg1292 Жыл бұрын
no java@@zack176
@somsaichowdhary861
@somsaichowdhary861 Жыл бұрын
great explaination bhaiya
@ekacaesium72
@ekacaesium72 9 ай бұрын
this was the best man .....
@preetijavali6595
@preetijavali6595 8 ай бұрын
Hi Thanks again for the video. The part where appending remaining list if any one ofthem reach to null, doesn't that code become unreachable?
@nikoo28
@nikoo28 8 ай бұрын
no, because you are running the first loop only until one of the list reaches null. So it could be possible that l2 reaches null first, while not l1 Then you will jump at the lower portion of code.
@ashok2089
@ashok2089 3 ай бұрын
Nikhil, Can you please do a video on Merge K Sorted List?
@nikoo28
@nikoo28 3 ай бұрын
Yes, I plan to do it, it will be very similar to this approach though
@ashok2089
@ashok2089 3 ай бұрын
@@nikoo28 Thank you!
@SOURAV-tu5jw
@SOURAV-tu5jw 3 жыл бұрын
Thanks. Keep doing the good work
@BhavanaHemaSree
@BhavanaHemaSree Жыл бұрын
sir but we are creating a new list doesn't it consumes extra space
@nikoo28
@nikoo28 Жыл бұрын
we are not creating a new list, we are just assigning pointers. This is the beauty of a linked list. :) Watch my theoretical videos on linked lists for a better understanding.
@robinsingh202
@robinsingh202 Жыл бұрын
NIcely Done!
@subee128
@subee128 10 ай бұрын
Thanks
@souravdebnathx
@souravdebnathx 3 жыл бұрын
thanks brother!!
@everyontech2716
@everyontech2716 Жыл бұрын
great job
@rakshan4253
@rakshan4253 11 ай бұрын
Just my doubt if anyone can clear will be really helpful , why headNode is never used but at last headNode is returned? it will be having the sorted list??
@nikoo28
@nikoo28 10 ай бұрын
Because we are playing with pointers. Watch my introductory videos on linked lists for a better understanding :)
@KothapalliKeerthi
@KothapalliKeerthi Жыл бұрын
Sir, could you please do lectures on Python data structures
@nikoo28
@nikoo28 Жыл бұрын
what data structures are you looking for?
@KeerthiKothapalli-g1k
@KeerthiKothapalli-g1k Жыл бұрын
@@nikoo28 stacks,queues,linked lists,hash maps,collection frameworks
@pinkeshpatel1940
@pinkeshpatel1940 3 жыл бұрын
returnNode = returnNode.next code line is not explained. Can you please.
@nikoo28
@nikoo28 3 жыл бұрын
That is because the initial node we created was a temporary node. So that we have something to start building. The actual merged list starts from the next node. Hence we return the next.
@swetaswarnakar828
@swetaswarnakar828 2 жыл бұрын
@@nikoo28 how is it constant space? are not we storing them in returnNode? so it should be O(n + m) space and time also???
@sarthakgupta096
@sarthakgupta096 9 ай бұрын
Bhaiya thanku 😊
@midhuns2934
@midhuns2934 3 жыл бұрын
Why are we assigning the dummy node to another node??
@nikoo28
@nikoo28 3 жыл бұрын
We need a starting point for our result. This dummy node serves the purpose.
@vaishnevprabu6474
@vaishnevprabu6474 5 ай бұрын
It results in a runtime error
@gurunathkulkarni6397
@gurunathkulkarni6397 Жыл бұрын
Sir, it is saying time limit exceeded
@aashushaikh5843
@aashushaikh5843 Жыл бұрын
yes and also it s giving : java.lang.NullPointerException: Cannot read field "val" because "" is null this error can u tell. me why?:
@nikoo28
@nikoo28 Жыл бұрын
did you check out the code on github given in the video description?
@trader184
@trader184 Жыл бұрын
What is the last line tell me🤧🤧🤧🤧🤬
@anshukumarchoudhary3833
@anshukumarchoudhary3833 2 жыл бұрын
man why have u made this video when u did not explain each line.
@nikoo2805
@nikoo2805 2 жыл бұрын
Which part are you facing a problem at? I can help you out further.
@trader184
@trader184 Жыл бұрын
@@nikoo2805 last line
@TuringTested01
@TuringTested01 Жыл бұрын
chup reh
@priyanshgarg1292
@priyanshgarg1292 Жыл бұрын
we understood bro
Merge Two Sorted Lists - Leetcode 21 - Linked Lists (Python)
9:41
ROSÉ & Bruno Mars - APT. (Official Music Video)
02:54
ROSÉ
Рет қаралды 263 МЛН
Каха и лужа  #непосредственнокаха
00:15
😜 #aminkavitaminka #aminokka #аминкавитаминка
00:14
Аминка Витаминка
Рет қаралды 2,6 МЛН
I gave 127 interviews. Top 5 Algorithms they asked me.
8:36
Sahil & Sarra
Рет қаралды 668 М.
L23. Merge two sorted Linked Lists
18:55
take U forward
Рет қаралды 67 М.
Merge two sorted Linked Lists to form a new Sorted Linked List
13:59
Vivekanand Khyade - Algorithm Every Day
Рет қаралды 172 М.
Merge Two Sorted Lists - Leetcode 21 - Python
6:16
NeetCode
Рет қаралды 382 М.