Middle of a Linked List (LeetCode 876) | Full Solution with animations | Study Algorithms

Sdílet
Vložit
  • čas přidán 2. 07. 2022
  • Given any type of a list, finding the mid point feels very natural and fundamental. Determining the middle point of a linked list can be a bit tricky as we only have access to the head node. Watch this video to understand how we can use the hare and tortoise algorithm to find the middle of a linked list efficiently. All along with animations and a dry-run of code in JAVA.
    Chapters:
    00:00 - Intro
    - Problem Statement and test-cases
    - Straight forward approach
    - Hare and tortoise algorithm
    - Dry-run of Code
    - Final Thoughts
    📚 Links to topics I talk about in the video:
    Array Data Structure:
    Linked Lists:
    Traversing a Linked List:
    📘 A text based explanation is available at: studyalgorithms.com
    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
    #leetcode #programming #interview

Komentáře • 19

  • @safar19899
    @safar19899 Před rokem +2

    Explanation is gold! Thank you my good sir!

  • @anushka7436
    @anushka7436 Před 4 měsíci

    The way you explain is mind blowing. Keep posting such videos!! Thanks a lot

  • @dhiraj3933
    @dhiraj3933 Před rokem

    Explained Perfectly! Thanks

  • @OluwatosinOseni260
    @OluwatosinOseni260 Před měsícem

    Thank you so much for this explanation and I understood it perfectly

  • @singhshek58
    @singhshek58 Před 9 měsíci +1

    nice explanation sir i understood now slow and fast pointer method .
    Thank you🙂

  • @jokergotham5865
    @jokergotham5865 Před rokem +2

    The way of explaining is amazing......
    infinite likes

  • @deliveringIdeas
    @deliveringIdeas Před 2 lety +1

    Amazing explanation sir!

  • @sakibsyed7626
    @sakibsyed7626 Před 2 lety +1

    Thanks sir for great explanation

  • @ymhuang651
    @ymhuang651 Před rokem +1

    Awesome teaching!

    • @nikoo28
      @nikoo28  Před rokem

      So happy to read this.

  • @brinderdhaliwal3570
    @brinderdhaliwal3570 Před 7 měsíci +1

    Great example

  • @yt_goluyadav
    @yt_goluyadav Před 2 měsíci

    sir what if the length of LL is bigger?

  • @avanishraj386
    @avanishraj386 Před rokem

    while loop looks incorrect as you are saying "or" condition but programmed "and" condition. But, I checked further and confused about why does the program fail when worked with "or " condition?

    • @nikoo28
      @nikoo28  Před rokem

      it just means that you need to run the while loop until both fastPtr and fastPtr.next are not null

  • @kalyanamvenumadhav2245

    Can we use (slowPtr != null) with remaining conditions in while loop I think this will also work
    May I know why you are not adding (slowPtr != null) in while condition.

    • @nikoo28
      @nikoo28  Před rokem

      why do you want to add additional conditions?

    • @kalyanamvenumadhav2245
      @kalyanamvenumadhav2245 Před rokem

      @@nikoo28 we are moving slow pointer along with fast ptr right then why we are not adding slow pointer

    • @dharmeshkase6003
      @dharmeshkase6003 Před 4 měsíci

      @@kalyanamvenumadhav2245 fast pointer is moving twice the speed isnt it obvious it will reach null first.