# Hackerrank Maximizing XOR Solution

Problem Statement
Given two integers: L and R,
find the maximal values of A xor B given, L ≤ A ≤ B ≤ R
Input Format
The input contains two lines, L is present in the first line.
R in the second line.
Constraints
1 ≤ L ≤ R ≤ 103
Output Format
The maximal value as mentioned in the problem statement.
Sample Input#00
1
10

Sample Output#00
15

Sample Input#01
10
15

Sample Output#01
7

Explanation
In the second sample let's say L=10R=15, then all pairs which comply to above condition are
1010=0
1011=1
1012=6
1013=7
1014=4
1015=5
1111=0
1112=7
1113=6
1114=5
1115=4
1212=0
1213=1
1214=2
1215=3
1313=0
1314=3
1315=2
1414=0
1415=1
1515=0
Here two pairs (10,13) and (11,12) have maximum xor value 7 and this is the answer.

Source Code:
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <assert.h>
int maxXor(int l, int r) {

for(i=l;i<=r;i++){
for(j=i;j<=r;j++){

temp = (i | j) & ~(i & j);
}
}

}
int main() {
int res;
int _l;
scanf("%d", &_l);

int _r;
scanf("%d", &_r);

res = maxXor(_l, _r);
printf("%d\n", res);

return 0;
}

** The above solution is my own code and it may not be the optimal solution or optimal way to approach the problem but it passes all the testcases in Hackerrank. So if you have any optimal approaches feel free to paste the code as the comment below..... :) :) :)