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.
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.
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.
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.
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??
best easy explaination ever i searched!
Glad I could help you out :)
You made it easily understandable with the help of clearly drawing example...Thanks!
i have seen multiple videos before watching yours.. but you made me to understand the logic.thank you so muchhh00....
great explaination bhaiya keep making such awesome videos for us.
so glad you liked it
Hey, this is giving time limit exceeded on leetcode.. can you please help
Hi, thank you so much for this explanation. Why the variable headNode never used?
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.
@@nikoo28is this python language
no java@@zack176
NICE SUPER EXCELLENT MOTIVATED
Super approach!
sir but we are creating a new list doesn't it consumes extra space
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.
best sir jii very good explanations ❤❤
Excellent Explanation
Glad it was helpful!
great explaination bhaiya
returnNode = returnNode.next code line is not explained. Can you please.
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.
@@nikoo28 how is it constant space? are not we storing them in returnNode? so it should be O(n + m) space and time also???
Thanks. Keep doing the good work
Sir, could you please do lectures on Python data structures
what data structures are you looking for?
@@nikoo28 stacks,queues,linked lists,hash maps,collection frameworks
Thanks
Nikhil, Can you please do a video on Merge K Sorted List?
Yes, I plan to do it, it will be very similar to this approach though
@@nikoo28 Thank you!
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?
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.
this was the best man .....
thanks brother!!
Bhaiya thanku 😊
It results in a runtime error
great job
Why are we assigning the dummy node to another node??
We need a starting point for our result. This dummy node serves the purpose.
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??
Because we are playing with pointers. Watch my introductory videos on linked lists for a better understanding :)
NIcely Done!
Sir, it is saying time limit exceeded
yes and also it s giving :
java.lang.NullPointerException: Cannot read field "val" because "" is null
this error can u tell. me why?:
did you check out the code on github given in the video description?
What is the last line tell me🤧🤧🤧🤧🤬
man why have u made this video when u did not explain each line.
Which part are you facing a problem at? I can help you out further.
@@nikoo2805 last line
chup reh
we understood bro