1829. Maximum XOR for Each Query

class Solution:
def getMaximumXor(self, nums: List[int], maximumBit: int) -> List[int]:
xor_=0
result=[]
start=1<<(maximumBit-1)
for i in nums:
xor_^=i
while(True):
if(not nums):
return( result)
val=0
mask=start
while(mask):
val<<=1
if(xor_&mask!=0):
val|=0
else:
val|=1
mask>>=1
result.append(val)
xor_^=nums[-1]
nums.pop(-1);
class Solution:
def getMaximumXor(self, nums):
mask=(1<<maximumBit)-1
for i in range(len(nums)):
mask^=nums[i]
nums[i]=mask
return(nums[::-1])

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Dhanarajappu

Dhanarajappu

Tech-Enthusiast, Coder,Explorer,Geeky,Software Engineer |A piece of code delivers everything that you need. The world is all about codes.