codes and a window width width. A *window* is width consecutive elements of the array; there are len(codes) - width + 1 windows in total.
One change writes any non-negative integer into any element of the array. The goal is for the bitwise XOR of the elements of every window to be 0.
Return the minimum number of changes.codes=[6, 3, 5, 6, 3, 1], width=3 → 1
The windows [6, 3, 5], [3, 5, 6] and [5, 6, 3] already give 0, but the last window [6, 3, 1] gives 4. Changing the last number to 5 fixes it with one change.
codes=[7, 0, 4], width=1 → 2
With width 1 each window is a single number, so every number must become 0. Both 7 and 4 have to change.
codes=[1, 2, 3, 1, 2, 3, 1], width=3 → 0
1 XOR 2 XOR 3 = 0, and every window of three consecutive numbers holds exactly 1, 2 and 3, so nothing needs to change.
width ≤ len(codes) ≤ 2000codes[i] < 1024codes=[6, 3, 5, 6, 3, 1], width=3
1
Run checks the first 3 tests in your browser. Submit checks all 116 tests on the server, hidden ones included.