Checkout your overall progress in every topic here
in DSA topics
Open the topic and solve more problems associated with it to improve your skills
Check out the skill meter for every topic
See how many problems you are left with to solve for cracking any stage. Score more than zero to get your progress counted.
Is it a Circular Linked List?
Avg time to solve 15 mins
Success Rate 85 %
You are given a Singly Linked List of integers. You have to find if the given linked list is circular or not.
A circular linked list is a sequence of elements in which every element has a link to its next element in the sequence and the last element has a link to the first element. This means that circular linked list is similar to the single linked list except that the last node points to the first node in the list.
Detailed explanation ( Input/output format, Notes, Constraints, Images )
The first line of input contains a single integer T, representing the number of test cases or queries to be run.
The first line of each test case contains the elements of the circular linked list separated by a single space and terminated by -1. Hence, -1 would never be a list element.
The second line contains a boolean value ‘val’, if ‘val’ is 1 then the given list is circular.
For each test case, print “True” if the given linked list is circular, else print “False”.
Print the output of each test case in a separate line.
You do not need to print anything, it has already been taken care of. Just implement the given function.
1 <= T <= 10
1 <= N <= 5 * 10^4
-10^9 <= data <= 10^9 and data != -1
0 <= val <= 1
Where 'N' is the number of nodes in the linked list, ‘data’ represents the value of the nodes of the list.
Time Limit: 1 sec
Sample Input 1
1 2 3 4 -1
8 9 8 -1
Sample Output 1
Explanation for Sample Input 1
In the 1st test case, the given list is circular.
In the 2nd test case, the given list is not circular.
In the 3rd test case, the given list is circular.