Any Hint for : https://hack.codingblocks.com/contests/c/452/498

Hi ,

I am trying to solve this problem, may be I didn’t understand this question properly.

The maximum value of a XOR b, should be XOR of X and Y may be. Any Hint, how to approach this problem?

Thanks,
Pardeep Sharma.

1 Like

Hy pradeep,
There can be some hints for you

  1. If you try brute force then you can achieve the answer
  2. If you can loose some space to save some time you can using a very famous Data Structure
  3. If you want to be most efficient then just get some observation on bits

I didn’t understand the question itself. For example : We are given two numbers X and Y, we have to find Max. XOR out of it, correct?

Suppose X=5, Y=6 , then Max. XOR of X^Y should be 5^6 = 3 and if,
X=5, Y=10, then Max XOR of X^Y should be 5^10 = 15.

So, answer is always XOR of X and Y only. Am I missing something?

Hy Pradeep,
The question says you are given two numbers X and Y.
Let X=5 and Y=7
Then you need to out put the maximum xor of all the pairs that can be formed between X and Y
So all the pairs are (5,6),(5,7),(5,8),(6,7),(6,8),(7,8) You need to xor all these numbers and then return the maxium xor

How come (5,8) (6,8) (7,8) are in pairs when constraint is : x <= a <= b <= y ?

suppose given inputs x = 2 and y = 5
than pair will be (2,5)(3,5)(4,5)
and we need to find the xor of each pair and maximum xor will be answer .

1 Like

This was an easy problem though :smiley: