**Compilation/Execution Result:**

Given a linked list, check if the the linked list has a loop. Linked list can contain self loop.

**Input:**

In this problem, method takes one argument: the head of the linked list. The function should not read any input from stdin/console.

The node structure has a data part which stores the data and a next pointer which points to the next element of the linked list.

There are multiple test cases. For each test case, this method will be called individually.

**Output:**

Return 1 if linked list has a loop else 0.

**Constraints:**

1<=T<=50

1<=N<=300

**Example:**

**Input:**

2

3

1 3 4

2

4

1 8 3 4

0

**Output:**

True

False

**Explaination:**

In above test case N = 3

The linked list with nodes N = 3 is given. Then value of x=2 is given which means last node is connected with xth node of linked list. Therefore, there exists a loop.

For N = 4

x = 0 means then lastNode->next = NULL, then the Linked list does not contains any loop.

Author: bhawnamait

Pulkit Gupta 2 | 130 |

Relentless | 124 |

Ibrahim Nash | 94 |

nancygarg258_pec | 90 |

darkswordsman | 90 |

Ibrahim Nash | 602 |

KartikAgarwal | 541 |

rs119574 | 371 |

surbhi_7 | 356 |

Little Noah | 335 |

akhayrutdinov | 4261 |

sanjay05 | 3633 |

Ibrahim Nash | 3162 |

Quandray | 3028 |

Michael Riegger | 2359 |