If this from any Ongoing contest. We should not discuss. 
this question asked in AppPerfect Pvt. Ltd. on campus recruitment drive
NO , take an example:
A = 43 = 101011
B = 3 = 000011
Now nA = 4 , nB = 2
nA>nB so according to your approach remove 2 set bits from right side of A then A = 1010 ie., 10
Now 43 ^ 10 = 33 which is not minimum instead of this we can unset the last diff bits in A
so A = 101000 ie., 40 now 43 ^ 40 = 3 which is minimum
@l_returns @anon55659401 Please see this i m correct or not?
Not from any ongoing challenge 
yeah,same i was thinking!
which college?
See my example ?
Remove means unset the bit . Change from 1 to 0
College of technology and engineering , udaipur
Oh then it will be fine , i wrote bcz in first case u said we have to remove , in second case u said unset to set
There my mean is to unset . Sorry for that
- calculate set bits in A (nA) and B(nB)
- if nA == nB then OUTPUT A
- if nA > nB then
diff = nA - nB
unset the last diff bits in A
and output ans - if nA < nB
diff = nB - nA
then change rightmost diff unset bits to set bits
and output it
What u wrote and deleted?
you can click on pencil like logo on upper right to see what i deleted.
Maybe we could take X = A initially and count the number of set bits in B. If A has extra bits, we make the required number of set bits from LSB equal to zero, and if A has less bits, we make required number of zero bits to 1 from LSB.
calculate set bits in A (nA) and B(nB)
if nA == nB then OUTPUT A
if nA > nB then
diff = nA - nB
unset the last diff bits in A
and output ans
if nA < nB
diff = nB - nA
then change rightmost diff unset bits to set bits
and output it
Is it correct?
Rightmost bits seems a little confusing. Are you referring to least significant bits? If yes, then it seems correct!
rightmost means least significant unset bits
Remove as many set bits as (as long as nB > 0) you can from A starting from left (if we consider it’s binary representation) as it always better and never makes the answer worse and if nB is still left go from right to left in binary representation of A and if this bit is unset set it, do this until nB > 0.