346. Check if Linked List is Circular

EasyLinked ListCircular Linked ListFloyd'sTwo Pointer

Given a linked list, determine if it is a true circular linked list (the last node points back to the head). Return true if circular, false otherwise.

Input: Array of values and boolean indicating whether the list is circular.

Output: Boolean true if circular, false otherwise.

Examples

Example 1
Input: [1,2,3,4,5], is_circular=true
Output: true
Explanation: Tail.next=head. Circular.
Example 2
Input: [1,2,3,4,5], is_circular=false
Output: false
Explanation: Tail.next=NULL. Not circular.
Example 3
Input: [1], is_circular=true
Output: true
Explanation: Single self-loop node.

Constraints

Asked by

TCSInfosysWiproCognizantCapgemini
Solve this problem in the editor →