Doug
BAN USER
So, if I read it correctly we are checking whether the cycle passes through the start index.
In which case this code should work:
static boolean cyclesThroughStart(int start, int... arr) {
int slowIdx = start;
int fastIdx = start;
do {
slowIdx = f(arr,slowIdx);
fastIdx = f(arr,f(arr,fastIdx));
if (slowIdx == start || fastIdx == start) {
return true;
}
} while(slowIdx != fastIdx);
return false;
}
static int f(int[] arr,int idx) {
idx += arr[idx];
return Math.abs(idx % arr.length);
}
Repraginieharris, IIT Exam at Altera
I am Ragini, and I have lived in Washington for 2 years. My current job is Web Designer in Corinthian ...
RepAlmaRJude, Quality Assurance Engineer at Brocade
I am Alma from Livermore USA, I also enjoy reading – my favourite topics being social history, the development and use ...
Replisaramsey773, Blockchain Developer at Adjetter Media Network Pvt Ltd.
I'm a 27 year-old blogger, make-up junkie and follower of Christ.I love all things that bring happiness. My ...
BFS in largest first order, and then reverse the result:
- Doug November 11, 2016