2
public int[] decrypt(int[] code, int k) {3
int[] res = new int[code.length];4
if (k == 0) return res;5
// Define the initial window and initial sum6
int start = 1, end = k, sum = 0;7
if (k < 0) { // If k < 0, the starting point will be end of the array.9
start = code.length - k;10
end = code.length - 1;12
for (int i = start; i <= end; i++) sum += code[i];13
// Scan through the code array as i moving to the right, update the window sum.14
for (int i = 0; i < code.length; i++) {16
sum -= code[(start++) % code.length];17
sum += code[(++end) % code.length];