Рет қаралды 10,773
A really interesting problem where you are required to determine if there is a cycle in a linked list. A loop/cycle is formed if one of the pointers in the linked list points to an internal node in the same list. There are a lot of ways to solve this problem and hence it is very important for interviews. The video explores how you can use a hash table to keep a track of unique nodes and then it demonstrates how the hare tortoise algorithm actually works. A dry-run of code in JAVA is also included.
Chapters:
00:00 - Intro
01:29 - Problem statement and description
03:46 - Brute Force approach to detect a cycle
07:55 - Idea behind an efficient approach (Rabbit/Tortoise method)
10:40 - Efficient solution (Floyd Warshall algorithm)
12:42 - Dry-run to detect cycle
15:02 - Final Thoughts
📚 Links to topics I talk about in the video:
Linked List: • Linked List Data Struc...
Traversing Linked Lists: • Traversing a Linked Li...
Double Linked Lists: • Double Linked List Dat...
Linked Lists playlist: • Linked Lists
📘 A text based explanation is available at: studyalgorithms.com
Problem on LeetCode: leetcode.com/problems/linked-...
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