Interview Query

Cyclic Detection

Start Timer

0:00:00

Upvote
2
Downvote
Save question
Mark as completed
View comments (2)
Next question

Given a ListNode representing the head of a linked list, write a function is_cyclic which returns True if a linked list is cyclic and False if it is not. A linked list is cyclic when there is no tail to the linked list, and the supposed tail is attached to another node inside the list itself, creating a cycle.

A ListNode is defined as:

class ListNode:
	value: ListNode = None
  next: ListNode = None

Example:

Input:

image

Output:

def is_cyclic(head) -> True
.
.
.
.
.


Comments

Loading comments