-
Notifications
You must be signed in to change notification settings - Fork 110
/
solution.cpp
46 lines (34 loc) · 920 Bytes
/
solution.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <bits/stdc++.h>
using namespace std;
// Complete the maximizingXor function below.
// Checking all the possibilities of l and r and xor them to get maximum of the XORs.
int maximizingXor(int l, int r)
{
int max_xor = -100000;
// Using brute for approach
for(int i =l;i<r;i++)
{
for(int j = l+1;j<=r;j++)
{
if((i^j)>max_xor) // Checking if current XOR is greater than previous ones
{
max_xor = i^j;
}
}
}
return max_xor; // returning the maximum.
}
int main()
{
ofstream fout(getenv("OUTPUT_PATH"));
int l;
cin >> l;
cin.ignore(numeric_limits<streamsize>::max(), '\n');
int r;
cin >> r;
cin.ignore(numeric_limits<streamsize>::max(), '\n');
int result = maximizingXor(l, r);
fout << result << "\n";
fout.close();
return 0;
}