Skip to content
LC-1829 Medium LeetCode

1829. Maximum XOR for Each Query

Read the full problem statement on LeetCode.
Difficulty: medium Acceptance: 85% Topics: Array, Bit Manipulation, Prefix Sum
View full problem on LeetCode
Reference solution (spoiler · python)
# Time:  O(n)
# Space: O(1)

class Solution(object):
    def getMaximumXor(self, nums, maximumBit):
        """
        :type nums: List[int]
        :type maximumBit: int
        :rtype: List[int]
        """
        result = [0]*len(nums)
        mask = 2**maximumBit-1
        for i in xrange(len(nums)):
            mask ^= nums[i]
            result[-1-i] = mask
        return result

Solution from kamyu104/LeetCode-Solutions · MIT