Linked List Cycle 2 (LeetCode 142) | Full solution with mathematical proof | Study Algorithms

Sdílet
Vložit
  • čas přidán 8. 07. 2024
  • Given a single linked list that contains a loop, find the node where the cycle starts. A very famous problem and an extension of detecting the loop. Using a slow pointer and fast pointer, can help to determine the meeting point. This video gives a mathematical proof on how the pointers meet at the start of loop. All along with diagrams and a dry-run of code in JAVA.
    Chapters:
    00:00 - Intro
    01:11 - Problem statement and description
    02:11 - Brute Force approach to find the cycle start point
    05:16 - Efficient solution to find the cycle start point
    08:27 - Mathematical proof of Floyd-Warshall algorithm
    14:52 - Dry-run of code
    16:55 - Final Thoughts
    Actual problem on LeetCode: leetcode.com/problems/linked-...
    📚 Links to topics I talk about in the video:
    Detect Cycle in Linked List: • Linked List Cycle (Lee...
    Linked List Introduction: • Linked List Data Struc...
    Linked List Traversals: • Traversing a Linked Li...
    Brute Force Method: • Brute Force algorithms...
    Time Complexity: • Big O Notation Simplif...
    Playlist on Linked Lists: • Linked Lists
    📘 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 #linkedlists

Komentáře • 46

  • @jayachandranpm3981
    @jayachandranpm3981 Před 2 lety +7

    A teacher deserves the highest appreciation in the world.

  • @curiousnerd2253
    @curiousnerd2253 Před 5 měsíci +2

    Oh my god! Why is your solution not the most viewed solution?!. Just amazing! Thank you so much!

  • @shraddhajain8935
    @shraddhajain8935 Před 2 lety +7

    Thanks a lot for such a detailed, simplified, and perfect explanation. I wish this will reach to max students.

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

      Thanks for all the support

  • @jaydeepvasoya6243
    @jaydeepvasoya6243 Před 3 měsíci +2

    mathematical explanation is super...!! thanks a lot..!

  • @astonvaz2247
    @astonvaz2247 Před 3 měsíci +1

    Very well explained. Had seen the solution about moving fast pointer to head but couldn't agree, but now after watching the visual explanation, I'm very clear.
    Thanks again buddy. 👍

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

    Thanks for the explanation! was able to understand the logic behind it!

  • @darkexodus6404
    @darkexodus6404 Před rokem +2

    Brilliant explanation!!

  • @azharsofi2854
    @azharsofi2854 Před rokem +1

    Your art of teaching is amazing

  • @user-fc6xb6ww8r
    @user-fc6xb6ww8r Před rokem

    Great content!

  • @user-dj3hs4ff5v
    @user-dj3hs4ff5v Před 10 měsíci +1

    perfect content!!!

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

    what a question and what an explaination!!!

  • @hieua3137
    @hieua3137 Před 4 dny

    Great Explanation !!!!

  • @Walid-Sahab
    @Walid-Sahab Před 9 měsíci

    what an explanation ❤

  • @yixiangzhang2834
    @yixiangzhang2834 Před rokem

    very well explained.

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

    This mathematical proof is so beautifully explained! I'm loving it baba!

    • @nikoo28
      @nikoo28  Před 3 měsíci

      Happy to hear that!

  • @susmitapatil4847
    @susmitapatil4847 Před 5 měsíci

    Very good teacher he is. He explains every concept very well. keep doing good work. Thanks for providing such content for free

  • @adityaa2303
    @adityaa2303 Před 9 měsíci

    good explanation sir

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

    good explanation

  • @techtuber1344
    @techtuber1344 Před 4 měsíci +1

    best explanation buddy , you got my sub:)

    • @nikoo28
      @nikoo28  Před 4 měsíci +1

      Thanks for the sub! 😄

  • @user-ur7pe9qp4i
    @user-ur7pe9qp4i Před 6 měsíci

    Hitting that subbscribe button as hard as I can.

  • @infinite639
    @infinite639 Před rokem

    Very Nice bro

  • @smitdumore1064
    @smitdumore1064 Před 10 měsíci

    great explanation

    • @nikoo28
      @nikoo28  Před 8 měsíci

      glad you liked it

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

    Thanks for the detailed explanation! I have a question: Why is (n2 - 2n1) always a positive integer? Can it be negative?

  • @manjarijha7755
    @manjarijha7755 Před 2 lety

    Thanks

    • @kashishjaiswal9303
      @kashishjaiswal9303 Před rokem

      tysmm...i wasnt able to understand any solution for this on yt until i saw your vid sir!!😭😭

  • @AzharKhan-e9m
    @AzharKhan-e9m Před 7 dny

    new subscriber

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

    Simplified explaination 👍🏻 Can you please suggest any book to study detailed data structures?

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

      I have links to some books in the video description. Check them out 🙂

    • @tias9719
      @tias9719 Před 2 lety

      @@nikoo28 noted. Thanks

  • @Salah-YT
    @Salah-YT Před 8 měsíci +1

    👍😍😎...

  • @gauravsharma5584
    @gauravsharma5584 Před 8 měsíci

    isnt floyd warshall graph algorithm ??

  • @darkexodus6404
    @darkexodus6404 Před rokem +1

    @nikoo28 At 14:22 Why only slow pointer? Why not fast pointer?

    • @rakheesharma7994
      @rakheesharma7994 Před 10 měsíci

      Because slow pointer is advancing one node at a time and fast is jumping two nodes. Hence we use the movement of slow pointer to get the length.

    • @paparika567
      @paparika567 Před 3 měsíci

      no bro you can take slow pointer as well

    • @AzharKhan-e9m
      @AzharKhan-e9m Před 7 dny

      you can take slow as well but make sure that fast also go only one step like fast=fast.next just as head=head.next beacoz distance is same by mathematical proofs so take as u need

  • @kartikluthra6621
    @kartikluthra6621 Před 9 hodinami

    🙇🏻‍♂

  • @Walid-Sahab
    @Walid-Sahab Před 9 měsíci

    Love from Pakistan ❤

  • @srikanthchebrolu1091
    @srikanthchebrolu1091 Před 3 měsíci

    💌

  • @user-ym8wk9yv3y
    @user-ym8wk9yv3y Před 10 měsíci

    sir second approach is not fine when the loop starts ate head

    • @nikoo28
      @nikoo28  Před 8 měsíci

      can you please elaborate?