Can I get feedback on my code?
Problem:
A zero-indexed array A consisting of N integers is given. Rotation of the array means that each element is shifted right by one index, and the last element of the array is also moved to the first place.
For example, the rotation of array A = [3, 8, 9, 7, 6] is [6, 3, 8, 9, 7]. The goal is to rotate array A K times; that is, each element of A will be shifted to the right by K indexes.
This is one of the lessons on Codility
Here is my solution:
public int[] solution(int[] A, int K) {
// write your code in Java SE 8
int size = A.length;
int[] cyclic = new int [size];
for (int x=0; x<size; x++) {
cyclic[(x + K) % size] = A[x];
}
return cyclic;
}