Skip to content

Latest commit

 

History

History
34 lines (15 loc) · 486 Bytes

File metadata and controls

34 lines (15 loc) · 486 Bytes

Sample Input:

5

1 6 3 7 8

2

Sample Output:

Loop exists

Explaination:

4--> size of linked list

1-->6-->3-->7-->8 =>nodes of linked list

2---> node to be checked


after creating the loop the detect loop fuction is called and the two pointer slow and fast meets if loop exists . For better understanding,refer here:

Time complexity:

O(n)