Codility - CyclicRotation

Codility - CyclicRotation

Codility Task:
CyclicRotation

Problem Definition:
Rotate an array to the right by a given number of steps.

Solution:
public int[] solution(int[] array, int k) {
int arrayLength = array.length;
int[] result = new int[arrayLength];
for (int i = 0; i < array.length; i++) {
result[(i + k) % arrayLength] = array[i];
}
return result;
}
view raw .java hosted with ❤ by GitHub

0 comments:

Post a Comment