diff --git a/kt/maximum-xor-for-each-query.kt b/kt/maximum-xor-for-each-query.kt new file mode 100644 index 0000000..26b490a --- /dev/null +++ b/kt/maximum-xor-for-each-query.kt @@ -0,0 +1,15 @@ +class Solution { + fun getMaximumXor( + nums: IntArray, + maximumBit: Int, + ): IntArray { + val mask = 1.shl(maximumBit) - 1 + + var runningXor = nums.reduce { x, y -> x.xor(y) } + return IntArray(nums.size) { i -> + val current = runningXor.xor(mask) + runningXor = runningXor.xor(nums[nums.size - 1 - i]) + current + } + } +}