We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
This is the most efficient solution for certain linked lists whose cycles are guaranteed to cycle back to the beginning, such as a circle. However, imagine a linked list the shape of the number 9, where the first node is at the bottom of the 9, and the "last" node links back to a node in the middle. If slow stayed at the beginning of the list, fast would get stuck since it would never hit the node that slow is waiting at.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Linked Lists: Detect a Cycle
You are viewing a single comment's thread. Return to all comments →
This is the most efficient solution for certain linked lists whose cycles are guaranteed to cycle back to the beginning, such as a circle. However, imagine a linked list the shape of the number 9, where the first node is at the bottom of the 9, and the "last" node links back to a node in the middle. If slow stayed at the beginning of the list, fast would get stuck since it would never hit the node that slow is waiting at.