How to find the length of a linked list that is having cycles in it?

Posted by Bragaadeesh on Stack Overflow See other posts from Stack Overflow or by Bragaadeesh
Published on 2010-05-05T12:08:25Z Indexed on 2010/05/05 12:28 UTC
Read the original article Hit count: 129

This was one of the interview questions asked. How to find the length of a linked list that is having cycle in it. I know how to calculate whether a linked list has a cycle or not using Hare and Tortoise technique. I even know how to calculate the length by storing the addresses in a hashset.

But what I was not able to tell is how to calculate the length of the linked list without using a external space of O(n). Please help me. Thanks.

© Stack Overflow or respective owner

Related posts about linked-list

Related posts about algorithm