</>
ShikshaCSLearn. Code. Grow.
🔍
☕ Support Us
ShikshaCSâ€ēPractice Problems
DSAMediumLinked List

Detect a Cycle in a Linked List

📋 Problem

Given a linked list, determine whether it has a cycle (a node's next pointer eventually loops back to an earlier node).

🧭 Approach

Use Floyd's Cycle Detection (the 'tortoise and hare' technique): one pointer (slow) moves one step at a time, another (fast) moves two steps at a time. If there's a cycle, the fast pointer will eventually 'lap' the slow pointer and they'll meet. If fast reaches the end (NULL), there's no cycle.

← Back to all Problems