educative.io

Given Solution has a Bug!

I believe the given solution has a bug. Consider the following input: arr=[1]. Clearly arr has a cycle of length 1, but if you test that input on the solution, it will say that it contains no loops!

In fact, I believe the given solution will fail any time there is more than one element in the input array, and all of the elements that have a cycle are a cycle of length 1 (points back to itself).

1 Like

Hi Nickolas,

The problem statement says that the cycle should have more than one element. And it should detect a loop at the beginning and end. So according to the given requirements, the provided solution is correct.