PEC-CSS/Open-Source

Detect Loop in linked list

Gauravsharma-20 opened this issue · 1 comments

Given a linked list of N nodes. The task is to check if the linked list has a loop. Linked list can contain self loop.

Input:
N = 4
value[] = {1,8,3,4}
x = 0

Output: False
Explanation: For N = 4 ,x = 0 means
then lastNode->next = NULL, then
the Linked list does not contains
any loop.

Your Task:
The task is to complete the function detectloop() which contains reference to the head as only argument. This function should return true if linked list contains loop, else return false.

Expected Time Complexity: O(N)

Can you assign me to this ?
I can solve it with
Time: O(N)
Space: O(1)