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.
Yes it will work for huge lists too . Either this algorithm , or use the Rabbit and Hare algorithm (fast and slow pointer) . that can reduce the time for travelling the list . but either way it's a brute force algorithm . you'll have to travel till the end of list to identify the presence of a cycle
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Cycle Detection
You are viewing a single comment's thread. Return to all comments →
Yes it will work for huge lists too . Either this algorithm , or use the Rabbit and Hare algorithm (fast and slow pointer) . that can reduce the time for travelling the list . but either way it's a brute force algorithm . you'll have to travel till the end of list to identify the presence of a cycle