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

แชร์
ฝัง
  • เผยแพร่เมื่อ 28 ต.ค. 2024

ความคิดเห็น • 51

  • @ashok2089
    @ashok2089 8 หลายเดือนก่อน +3

    You made it easily understandable with the help of clearly drawing example...Thanks!

  • @souravdebnathx
    @souravdebnathx 3 ปีที่แล้ว +10

    best easy explaination ever i searched!

    • @nikoo28
      @nikoo28  3 ปีที่แล้ว +1

      Glad I could help you out :)

  • @satyamgupta6030
    @satyamgupta6030 ปีที่แล้ว +2

    great explaination bhaiya keep making such awesome videos for us.

    • @nikoo28
      @nikoo28  ปีที่แล้ว +1

      so glad you liked it

  • @taniyasharma8924
    @taniyasharma8924 3 หลายเดือนก่อน +1

    Hey, this is giving time limit exceeded on leetcode.. can you please help

  • @gokulnaathb2627
    @gokulnaathb2627 8 หลายเดือนก่อน

    Super approach!

  • @vikasvarma9462
    @vikasvarma9462 2 หลายเดือนก่อน

    best sir jii very good explanations ❤❤

  • @ellase8747
    @ellase8747 3 ปีที่แล้ว +3

    Hi, thank you so much for this explanation. Why the variable headNode never used?

    • @nikoo28
      @nikoo28  3 ปีที่แล้ว +2

      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

  • @zewdih3871
    @zewdih3871 11 หลายเดือนก่อน

    Excellent Explanation

    • @nikoo28
      @nikoo28  10 หลายเดือนก่อน

      Glad it was helpful!

  • @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.

  • @ganeshjaggineni4097
    @ganeshjaggineni4097 ปีที่แล้ว +1

    NICE SUPER EXCELLENT MOTIVATED

  • @somsaichowdhary861
    @somsaichowdhary861 ปีที่แล้ว

    great explaination bhaiya

  • @ekacaesium4043
    @ekacaesium4043 9 หลายเดือนก่อน

    this was the best man .....

  • @SOURAV-tu5jw
    @SOURAV-tu5jw 3 ปีที่แล้ว +1

    Thanks. Keep doing the good work

  • @BhavanaHemaSree
    @BhavanaHemaSree ปีที่แล้ว +1

    sir but we are creating a new list doesn't it consumes extra space

    • @nikoo28
      @nikoo28  ปีที่แล้ว +1

      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.

  • @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!

  • @rakshan4253
    @rakshan4253 10 หลายเดือนก่อน

    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 :)

  • @robinsingh202
    @robinsingh202 ปีที่แล้ว +1

    NIcely Done!

  • @souravdebnathx
    @souravdebnathx 3 ปีที่แล้ว +1

    thanks brother!!

  • @pinkeshpatel1940
    @pinkeshpatel1940 3 ปีที่แล้ว +1

    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???

  • @KothapalliKeerthi
    @KothapalliKeerthi ปีที่แล้ว +1

    Sir, could you please do lectures on Python data structures

    • @nikoo28
      @nikoo28  ปีที่แล้ว +1

      what data structures are you looking for?

    • @KeerthiKothapalli-g1k
      @KeerthiKothapalli-g1k ปีที่แล้ว

      @@nikoo28 stacks,queues,linked lists,hash maps,collection frameworks

  • @subee128
    @subee128 10 หลายเดือนก่อน +1

    Thanks

  • @everyontech2716
    @everyontech2716 ปีที่แล้ว

    great job

  • @sarthakgupta096
    @sarthakgupta096 8 หลายเดือนก่อน

    Bhaiya thanku 😊

  • @vaishnevprabu6474
    @vaishnevprabu6474 5 หลายเดือนก่อน

    It results in a runtime error

  • @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.

  • @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 ปีที่แล้ว +1

      we understood bro