HackerRank - Reverse Linked List | Full solution with visuals | Study Algorithms

SdĂ­let
VloĆŸit
  • čas pƙidĂĄn 23. 07. 2024
  • A very popular and famous interview question. In this problem you are given a single Linked List which needs to be reversed such that the last element becomes the first element of the list. You can have several ways to approach this problem. One way could be to create an entirely new list in a reversed order or we can take advantage of the node addresses to manipulate. This video shows you animations which will help you to understand the concept behind it. Along with it, we also write the code.
    Chapters:
    00:00 - Intro
    01:11 - Problem statement and description
    02:01 - Method 1: Creating a new reversed list (using stacks)
    03:59 - Code using stacks
    06:59 - Method 2: Efficient solution by manipulating next nodes
    08:41 - Dry-run of Code
    13:25 - Final Thoughts
    Actual problem on HackerRank: www.hackerrank.com/challenges...
    📚 Links to topics I talk about in the video:
    Stack Data Structure: ‱ Stack Data Structure e...
    Linked Lists: ‱ Linked List Data Struc...
    📘 A text based explanation is available at:
    Code on Github: github.com/nikoo28/java-solut...
    Test-cases on Github: github.com/nikoo28/java-solut...
    📖 Reference Books:
    Starting Learn to Code: amzn.to/36pU0JO
    Favorite book to understand algorithms: amzn.to/39w3YLS
    Favorite book for data structures: amzn.to/3oAVBTk
    Get started for interview preparation: amzn.to/39ysbkJ
    🔗 To see more videos like this, you can show your support on: www.buymeacoffee.com/studyalg...
    đŸŽ„ My Recording Gear:
    Recording Light: amzn.to/3pAqh8O
    Microphone: amzn.to/2MCX7qU
    Recording Camera: amzn.to/3alg9Ky
    Tablet to sketch and draw: amzn.to/3pM6Bi4
    Surface Pen: amzn.to/3pv6tTs
    Laptop to edit videos: amzn.to/2LYpMqn
    đŸ’» Get Social đŸ’»
    Follow on Facebook at: / studyalgos
    Follow on Twitter at: / studyalgorithms
    Follow on Tumblr at: / studyalgos
    Subscribe to RSS feeds: studyalgorithms.com/feed/
    Join fan mail: eepurl.com/g9Dadv
    #hackerrank #programming #interview

Komentáƙe • 23

  • @technicalguy.
    @technicalguy. Pƙed 7 měsĂ­ci +5

    No doubt you're an excellent teacher! ❀

  • @TarunSharma-eg7kl
    @TarunSharma-eg7kl Pƙed 3 lety +2

    Great explanation!

  • @user-he6tz2jz4r
    @user-he6tz2jz4r Pƙed 6 měsĂ­ci +3

    great explanation

  • @Sranju23
    @Sranju23 Pƙed 10 měsĂ­ci +3

    At the end u can just return prevNode without doing head = prevNode... btw nice tutorials 😃

  • @Unknown373d
    @Unknown373d Pƙed měsĂ­cem +1

    nice explanation

  • @xtremeinnovations8599
    @xtremeinnovations8599 Pƙed 7 měsĂ­ci +2

    Thanks!

  • @riyapawar4569
    @riyapawar4569 Pƙed 11 měsĂ­ci +1

    Great ❀❀ too good

  • @syw512
    @syw512 Pƙed rokem +2

    Really like your explanation!! I’m new to programming,you make it really easy for beginners to understand. 👍👍👍

    • @nikoo28
      @nikoo28  Pƙed rokem +1

      Glad I can help you out

    • @syw512
      @syw512 Pƙed rokem +1

      @@nikoo28 looking forward to see more of your videos.

  • @sushant3530
    @sushant3530 Pƙed 2 lety +1

    great

  • @pavanshanmukh6502
    @pavanshanmukh6502 Pƙed 3 měsĂ­ci

    Thank you for your wonderful explanation

    • @nikoo28
      @nikoo28  Pƙed 3 měsĂ­ci

      You are welcome!

  • @reactninja6567
    @reactninja6567 Pƙed 2 lety +2

    thanks a lot ! This was easy to understand.I took a udemy course on dsa But they don't teach with diagrams like you do. Please if you any paid subscription let me know i would buy for sure. Also if possible can u suggest some good resources(books or courses) which are more diagram oriented rather than just running a code .

    • @nikoo28
      @nikoo28  Pƙed 2 lety +2

      Thank you so much for your feedback and motivation. Right now all my content is only on CZcams and the website. Sure, if I add more subscription based course, you will know about it.

    • @reactninja6567
      @reactninja6567 Pƙed 2 lety +1

      @@nikoo28cool! any visual based learning for DSA book/course.can u refer? that would be much helpful.

  • @user-pi1cy9xs3z
    @user-pi1cy9xs3z Pƙed měsĂ­cem

    I'm stuck in last iteration you skipped that part please explain 12:09

    • @nikoo28
      @nikoo28  Pƙed měsĂ­cem

      in the last part, we are just reallocating the head, such that the linked list is actually reversed. Follow the pointers and you will understand.

  • @MaulikDodiaHollywoodMovieLover
    @MaulikDodiaHollywoodMovieLover Pƙed 3 měsĂ­ci

    currNode.next = preNode; ----> Is this statement only assign preNode's value to currNode's next node which is 8. and If this statement is assigning values then how ListNode nextNode = currNode.next; ---> this statement giving us next node. Confusing!

    • @nikoo28
      @nikoo28  Pƙed 3 měsĂ­ci

      did you go over the explanation part or went straight to the code?

    • @MaulikDodiaHollywoodMovieLover
      @MaulikDodiaHollywoodMovieLover Pƙed 3 měsĂ­ci

      @@nikoo28 Yes, I watched it. Didn't get so I asked! Never mind.

  • @johncho9160
    @johncho9160 Pƙed 6 měsĂ­ci +1

    why do you have to initialize the reversedList with Integer.MIN_VALUE? the value we assign does not matter since we are returning reversedList.next at the end anyway?

    • @nikoo28
      @nikoo28  Pƙed 6 měsĂ­ci

      you are correct...it is just a dummy node. You can assign any value to it. It is just for utility.