1. You are given a linked list with N nodes.
2. You are also given a number x which means last node is connected with
xth node of linked list. Therefore, there exists a loop.
3. If x is 0, it means last node is connected to nothing. Therefore, no loop.
4. You have to write a function that checks if the the linked list has a loop.
5. Linked list can contain self loop.
6. display is a utility function which displays the contents of Linked List,
feel free to use it for debugging purposes.
7. main takes input from the users and creates the Linked List. You can use
display to know its contents.
8. This is a functional problem.
9. You should code only the cycle function, feel free to change its
signature if required. It should 1 if the linked list contains loop.
Else return 0.
10. Don't change the code of Node, main and display.Input Format
First line takes N, the number of elements in the list. Next line takes input N space separated numbers reperesenting elements of the linked list. Next line takes input x. Input is handled for you.
Output Format
True if linked list contains loop. Else False. Output is handled for you.
Constraints
1 <= N <= 300 0 <= x <= N
Notice
Try First, Check Solution later
1. You should first read the question and watch the question video.2. Think of a solution approach, then try and submit the question on editor tab.3. We strongly advise you to watch the solution video for prescribed approach.Example
Input
3 1 3 4 2
Output
True