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).