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.
My nooby explanation:
Slow pointer speed = 1 node per unit time = n.
Fast pointer speed = 2 node per unit time =2n.
Stick the slow pointer to the start of the loop then fast pointer's relative speed= n.
Let loop be consisting of m nodes.
Then fast pointer takes 1 round covering m nodes to meet slow pointer at speed n.
At its original speed 2n, it must take 2 rounds!! :-o
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 →
My nooby explanation: Slow pointer speed = 1 node per unit time = n. Fast pointer speed = 2 node per unit time =2n. Stick the slow pointer to the start of the loop then fast pointer's relative speed= n. Let loop be consisting of m nodes. Then fast pointer takes 1 round covering m nodes to meet slow pointer at speed n. At its original speed 2n, it must take 2 rounds!! :-o