0% completed
Problem Challenge 3: Cycle in a Circular Array (hard)
Problem Statement
We are given an array containing positive and negative numbers. Suppose the array contains a number ‘M’ at a particular index. Now, if ‘M’ is positive we will move forward ‘M’ indices and if ‘M’ is negative move backwards ‘M’ indices. You should assume that the array is circular which means two things:
- If, while moving forward, we reach the end of the array, we will jump to the first element to continue the movement.
- If, while moving backward, we reach the beginning of the array, we will jump to the last element to continue the movement.
.....
.....
.....
Denys Stopkin
· a year ago
Either I don't understand the task or it's incorrect (incomplete). Example array: {3,2,-2,5,6}. The last value gives a circle itself since it goes through the whole array's available index range twice. [0, 1, 2, 3, 4 ] + 6 = 10 10 - arr.size() = 5, which is greater than allowed index is 5 - arr.size() = 0. And here we have circled through the array twice already. Does it mean that this particular example should return true?
In the same case if we start form 2 the sequence would prove the circle exists before the loop would be found