package leetcode;

import java.util.Arrays;

/**
 * https://leetcode.com/problems/maximum-xor-for-each-query/
 */
public class Problem1829 {
    public int[] getMaximumXor(int[] nums, int maximumBit) {
        // TODO
        return null;
    }

    public static void main(String[] args) {
        Problem1829 prob = new Problem1829();
        System.out.println(Arrays.toString(prob.getMaximumXor(new int[]{0,1,1,3}, 2))); // [0,3,2,3]
        System.out.println(Arrays.toString(prob.getMaximumXor(new int[]{2,3,4,7}, 3))); // [5,2,6,5]
        System.out.println(Arrays.toString(prob.getMaximumXor(new int[]{0,1,2,2,5,7}, 3))); // [4,3,6,4,6,7]
    }
}

package leetcode;

/**
 * https://leetcode.com/problems/maximum-xor-for-each-query/
 */
public class Problem1829 {
    public int[] getMaximumXor(int[] nums, int maximumBit) {
        int[] answer = new int[nums.length];
        int prefixXor = 0;
        for (int i = 0; i < nums.length; i++) {
            prefixXor ^= nums[i];
            int k = ((int) Math.pow(2, maximumBit)) - 1;
            // a ^ b = c --> a ^ c = b
            answer[nums.length - 1 - i] = prefixXor ^ k;
        }
        return answer;
    }
}

Solve problem 1829