educative.io

What if the circular loop-sequence is just 1 rather than 2?

Would the method still work if the circular loop was loop-back only 1 element rather than 2?

Hello @Aeshan_Wijetunge,

In the given code, the condition Math.abs(nums[pointer] % nums.length) == 0 used in the isNotCycle() function checks if moving the pointer takes it back to the same value. This condition is used to determine if there’s a cycle of length 1. If there’s one, the isNotCycle() function return TRUE.

Taking an example of a test case [-5, -4, -3, -2, -1] . We can see that moving the pointer from -5 would take it back to the same index again and again. However, if the circular loop consists of only one loop-back element, the isNotCycle() function will return TRUE, indicating that a cycle is not possible.

Hope this answers your query. Feel free to drop in more feedback and suggestions.

Regards,
Dian