Remove Loop In Singly Linked List

easy
1. You are given a linked list with N nodes.
    2. You are also given a number X. It denotes the position of the node(from head)
       to which the last node will get connected. If it is 0 then there is no loop.
    3. You have to write a function that removes the loop from the linked list, 
       if present.
    4. display is a utility function which displays the contents of Linked List,
       feel free to use it for debugging purposes.
    5. main takes input from the users and creates the Linked List. You can use
       display to know its contents.
    6. This is a functional problem. 
    7. You should code only the removeTheLoop function. It takes as input the
       head of the linked list.
    8. Don't change the code of Node, main and display and other functions already
       defined.

Input Format

First line takes N, the number of elements in the list. Second line takes input N space separated numbers representing elements of the linked list. Next Line takes input X, denoting that last node is connected with Xth node of linked list. Input is handled for you.

Output Format

If the function is correct and the loop gets removed, the answer will be 1. Else, 0. 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
1
Previous
Rearrange Linked List Odd Even
Next
Reverse Linked List From M To N

Related Questions