educative.io

Educative

Why does -- "INCREASING pointer 1 by K Steps" -- this approach work?

ABSOLUTELY did not come to my mind, why we should move the Pointer_1 by K Steps at first, and keep it there, and then move them both together.

this feels like a memorized solution rather than an intuitive one.

Can someone please provide an alternative Easy to understand solution?

Hey,

There could be definitely other solutions to this problem.

The main issue is that once a pointer is at the beginning of the cycle “it won’t know that”.

Here’s a simpler explanation:

IF the first pointer is ought to be K nodes ahead AND still pointing towards the same node as the second pointer. That would mean that the first pointer has looped back to the beginning of the cycle.

1 Like