Circular Linked List
Submissions: 16667   Accuracy:

50.74%

  Difficulty: Basic   Marks: 1

Given a singly linked list, find if the linked list is circular or not. A linked list is called circular if it not NULL terminated and all nodes are connected in the form of a cycle. An empty linked list is considered as circular.

Input:
First line of input contains number of testcases T. For each testcase, first line consists of number of nodes in the linked list and an integer representing if the list is circular list.

Output:
The function should return true if the given linked list is circular, else false.

User Task:
The task is to complete the function isCircular() which checks if the given linked list is circular or not. It should return true or false accordingly.

Constraints:
1 <=T<= 50
1 <=N<= 100
1 <=value<= 1000

Example:
Input:

2
5 1      
1 2 3 4 5
6 0
2 4 6 7 5 1

Output:
1
0

Explanation:
Testcase 1
: k is 1, therefore output is 1.

 

** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Amit Khandelwal, Harshit Sidhwa
Author: kartik


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.


to report an issue on this page.