


The first line of input contains two values: the number of nodes in the linked list and the value of the kth node from which the last node connects to form the loop while the second line of input contains the given linked list.
The value of k should be greater than or equal to 0 and less than equal to n. For, k equal to 0, there is no loop present in the linked list and for k equal to n, the last node is connected to itself to form the cycle.
The only output line contains the linked list after removing the loop if present.
1 <= N <= 100000.
1 <= ‘VAL’ <= 1000 .
Time limit: 1 sec
We are going to have two loops outer-loop and inner-loop
We are going to maintain a lookup table(a Hashmap) that basically tells if we have already visited a node or not, during the course of traversal.