Linked List Cycle 2 (LeetCode 142) | Full solution with mathematical proof | Study Algorithms
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
A teacher deserves the highest appreciation in the world.
Oh my god! Why is your solution not the most viewed solution?!. Just amazing! Thank you so much!
You're welcome!
Thanks a lot for such a detailed, simplified, and perfect explanation. I wish this will reach to max students.
Thanks for all the support
mathematical explanation is super...!! thanks a lot..!
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. 👍
Thanks for the explanation! was able to understand the logic behind it!
Brilliant explanation!!
Your art of teaching is amazing
Great content!
perfect content!!!
what a question and what an explaination!!!
Great Explanation !!!!
what an explanation ❤
very well explained.
This mathematical proof is so beautifully explained! I'm loving it baba!
Happy to hear that!
Very good teacher he is. He explains every concept very well. keep doing good work. Thanks for providing such content for free
Thanks a ton
good explanation sir
good explanation
best explanation buddy , you got my sub:)
Thanks for the sub! 😄
Hitting that subbscribe button as hard as I can.
Very Nice bro
great explanation
glad you liked it
Thanks for the detailed explanation! I have a question: Why is (n2 - 2n1) always a positive integer? Can it be negative?
Thanks
tysmm...i wasnt able to understand any solution for this on yt until i saw your vid sir!!😭😭
new subscriber
Simplified explaination 👍🏻 Can you please suggest any book to study detailed data structures?
I have links to some books in the video description. Check them out 🙂
@@nikoo28 noted. Thanks
👍😍😎...
isnt floyd warshall graph algorithm ??
@nikoo28 At 14:22 Why only slow pointer? Why not fast pointer?
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.
no bro you can take slow pointer as well
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
🙇🏻♂
Love from Pakistan ❤
💌
sir second approach is not fine when the loop starts ate head
can you please elaborate?