-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathResult.java
More file actions
25 lines (23 loc) · 719 Bytes
/
Result.java
File metadata and controls
25 lines (23 loc) · 719 Bytes
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
package hackrank.algorithm.bit.maxxor;
/**
* @see <a href="https://www.hackerrank.com/challenges/maximizing-xor">Maximizing XOR</a>
*/
public class Result {
/**
* @param l Lower bound integer (inclusive)
* @param r Upper bound integer (inclusive)
* @return Max xor operation value for all permutations of the integers between {@code l} and {@code r}
*/
public static int maximizingXor(int l, int r) {
int bestMax = 0;
for (int i = l; i <= r; i++) {
for (int j = i; j <= r; j++) {
int max = i ^ j;
if (max > bestMax) {
bestMax = max;
}
}
}
return bestMax;
}
}