Suppose we have two numbers a and b. We have to find the smallest possible value of (a XOR x) + (b XOR x) for some value of x.
So, if the input is like a = 6; b = 12, then the output will be 10, because if x = 4, then (6 XOR 4) + (12 XOR 4) = 2 + 8 = 10.
Steps
To solve this, we will follow these steps −
return a XOR b
Example
Let us see the following implementation to get better understanding −
#include<bits/stdc++.h>
using namespace std;
int solve(int a, int b){
return (a^b);
}
int main(){
int a = 6;
int b = 12;
cout << solve(a, b) << endl;
}Input
6, 12
Output
10