Circular Linked List problem

i am not getting the problem as while creating the linked list when last element ‘3’ is pushed it is pointing to null so how does it form a loop?
and i know the concept of how to detect a loop and remove loop but not getting how input forms loop.

Hi vipin
suppose
Sample Input
1 2 3 4 5 2 3 -1
means 5 is connected to 2 to form a loop.
Make a map of (int,Node*) which stores pair(node data, node address) .
Keep track of last stored node in map.
Before entering into map check if pair exist. If it does’nt exist, enter it into map,
else point the last stored node in map to this repeated node. The loop is made.

Hope it helps :slight_smile:

1 Like

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.