Detect Cycle in Linked List

00:00
EasyLinked ListTwo PointersFloyds Algorithm
AmazonMicrosoft

Detect if a linked list has a cycle using Floyd two-pointer fast-slow algorithm. Return true if cycle exists.

Examples

Input → 3
Output → 2->0->-4->(back to 2) -> True
Input → 1
Output → 2->(back to 1) -> True
Input → 1
Output → null -> False