AlgoViz
← All drills
🧠 Drill · Think it through

Two walkers in the same chain

The problem

You have a singly linked list: each node only knows the next node, and you cannot jump to position k or read the length up front. Some buggy code may have made a later node point back to an earlier one, forming a loop. Return whether following next from the head eventually cycles forever instead of reaching an end, using only constant extra memory.

Don't jump to code. Walk the four questions an expert asks first — you'll build the habit, not just the answer.

1

Restate it

Before anything else — did you read what's actually being asked? Strip the story to the bare goal.

Strip away the setup. What single yes/no are we deciding?