Circular Linked List Detection

You are provided with the head of a linked list containing integers. Your task is to determine if the linked list is circular.

Note:
  • A linked list is considered circular if it contains no node having a next pointer equal to NULL, and all nodes form a closed loop, meaning the next pointer of the last node points back to the first node.
  • An empty linked list is also considered circular.
  • All integers in the linked list are unique.
  • In the input, the next pointer of a node with the i-th integer is linked to the node with the data of the (i+1)-th integer, if such a node exists. If no (i+1)-th integer exists, the next pointer is set to NULL.

Input:

The first line of input contains an integer T, denoting the number of test cases.
The first line of each test case consists of an integer N, denoting the number of links in the linked list.
The second line of each test case consists of N space-separated integers representing the data of the linked list and their connections as per the description above.

Output:

For each test case, output 'True' or 'False' indicating if the linked list is circular.

Example:

Input:
T = 2
3
1 2 3
1
1
Output:
False
True

Constraints:

  • 1 ≤ T ≤ 102
  • 1 ≤ D ≤ 106, where D is the data stored in a node
  • 0 ≤ N ≤ 104
  • Time Limit: 1 sec
AnswerBot
1y

The task is to determine whether a given linked list is circular or not.

  • A linked list is circular if the next pointer of the last node points to the first node.

  • An empty linked list is also considered ...read more

Help your peers!
Select
Add answer anonymously...

Decimal Point Analytics Software Developer Intern interview questions & answers

A Software Developer Intern was asked 8mo agoQ. Given an array of integers, find the first repeating element in the array.
A Software Developer Intern was asked 8mo agoQ. Define the four pillars of OOPS.
A Software Developer Intern was asked Q. Rahul and Minimum Subarray Challenge Rahul, who is passionate about programming,...read more

Popular interview questions of Software Developer Intern

A Software Developer Intern was asked 8mo agoQ1. Given an array of integers, find the first repeating element in the array.
A Software Developer Intern was asked 8mo agoQ2. Define the four pillars of OOPS.
A Software Developer Intern was asked Q3. Rahul and Minimum Subarray Challenge Rahul, who is passionate about programming,...read more
Decimal Point Analytics Software Developer Intern Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits