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.
In my first approach, I was trying to use a hash table to to keep track of all the nodes visited till now. As soon as we get a node which is already present in hash table.. we can say that linked list contains a cycle. However, this approach is relately complex and requires some extra space. Fast and slow pointer method of finding loop in a linked listdata structure is better.
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 →
In my first approach, I was trying to use a hash table to to keep track of all the nodes visited till now. As soon as we get a node which is already present in hash table.. we can say that linked list contains a cycle. However, this approach is relately complex and requires some extra space. Fast and slow pointer method of finding loop in a linked list data structure is better.