4 ms·
Yes, I did figure it out. Actually, the answer I came up with was slightly different: it was pretty clear that I had to move the first pointer to get inside the
by alain94040 12y ago
Yes, I did figure it out. Actually, the answer I came up with was slightly different: it was pretty clear that I had to move the first pointer to get inside the cycle. Once I was inside, I thought the second pointer would need to move a lot to find the cycle, rather than just going two hops. So I proposed to advance the first pointer by n, and the second one by exp(n). Maybe it would go faster, who knows.
By the way, this was the question at my first interview ever, so I do remember it quite well.
PS: I interviewed many candidates since, and I would never ask such a question.