Test if single linked list is circular by traversing it only once
- by user1589754
I am a fresher and I was asked this question in a recent interview I gave.
The question was --- By traversing each element of linked list just once find if the single linked list is circular at any point.
To this I answered that we will store reference of each node while traversing the list in another linked list and for every node in the list being tested we will find if the reference exists in the list I am storing the references.
The interviewer said that he needs a more optimized way to solve this problem.
Can anyone please tell me what would be a more optimized method to solve this problem.