values and a number bits; every element is below 2^bits.
Repeat len(values) times:
1. Pick the number k, 0 ≤ k < 2^bits, that makes the XOR of all current elements together with k as large as possible, and record it.
2. Remove the last element of the array.
Return the recorded numbers in the order you got them.values=[5, 1, 6], bits=3 → [5, 3, 2]
5 XOR 1 XOR 6 = 2, and topping it up to 7 takes 5. Drop the 6: 5 XOR 1 = 4, which needs 3. Drop the 1: 5 is left, which needs 2. The answer is [5, 3, 2].
values=[3, 3], bits=2 → [3, 0]
At first the XOR is 0, so k = 3. After one removal it is 3, so nothing has to be added: k = 0.
values=[5, 1, 6], bits=3
[5, 3, 2]
Run checks the first 3 tests in your browser. Submit checks all 80 tests on the server, hidden ones included.