This is one of very typical technical interview question to be asked to check your problem solving skill in data structures.

Lets say you have a singly linkedlist and you have to detect if there is any loop or cycle in it, this problem can be easily solved using a famous algorith Tortoise and Hare algorithm.

This algorithm runs in O(n) time, and i explained below:

1. Assign 2 pointers (lets say A and B) to starting node and increase A by one element and B by 2 elements forward until both are equal or faster element is NULL.

2. if both are equal means Loop exists.

3. if B becomes NULL loop doesn't exist.

there may be some additional questions like, find out the starting element of loop, find number of elements in loop. so be prepared for those.

I will cater additional question in another posts.

Lets say you have a singly linkedlist and you have to detect if there is any loop or cycle in it, this problem can be easily solved using a famous algorith Tortoise and Hare algorithm.

This algorithm runs in O(n) time, and i explained below:

1. Assign 2 pointers (lets say A and B) to starting node and increase A by one element and B by 2 elements forward until both are equal or faster element is NULL.

2. if both are equal means Loop exists.

3. if B becomes NULL loop doesn't exist.

there may be some additional questions like, find out the starting element of loop, find number of elements in loop. so be prepared for those.

I will cater additional question in another posts.