Skip to content

Commit

Permalink
Merge pull request #151 from guruc-134/patch-9
Browse files Browse the repository at this point in the history
Create MaximizingXOR
  • Loading branch information
IEEE-IIITSricity committed Oct 6, 2020
2 parents fe9f6df + 6477617 commit ad7470a
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions Bit-Manipulation/MaximizingXOR
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"""
Given two integers,l and r, find the maximal value of a xor b, where a and b satisfy the following condition:
l<=a<=b<=r

example:
l=11
r=12
ans=7

the maximizingXor function It must return an integer representing the maximum value calculated.
maximizingXor has the following parameter(s):

l: an integer, the lower bound, inclusive
r: an integer, the upper bound, inclusive

"""
def maximizingXor(l, r):
m=0
for i in range(l,r+1):
for j in range(i,r+1):
xor=i^j
m=max(m,xor)
return m

0 comments on commit ad7470a

Please sign in to comment.