Problem Brief

Max XOR

OA

For two positive integers, lo and hi, and a limit k, find two integers, a and b, satisfying the following criteria. Return the value of a e b. The symbol denotes the bitwise XOR operator.

  • lo <= a < b <= hi
  • The value of a e b is maximal for a e b ≤ k.

Function Description

Complete the function maxXor in the editor below. The function must return an integer denoting the maximum possible value of a e b for all a e b ≤ k.

maxXor has the following parameters:

  • int lo: an integer
  • int hi: an integer
  • int k: an integer

1Example 1

Input
lo = 3, hi = 5, k = 6
Output
6
Explanation

The maximal useable XORed value is 6 because it is the maximal value that is less than or equal to the limit k = 6.

Constraints

Limits and guarantees your solution can rely on.

  • 1 ≤ lo < hi ≤ 10^4
  • 1 ≤ k ≤ 10^4
public int maxXor(int lo, int hi, int k) {
  // write your code here
}
Input

lo

3

hi

5

k

6

Output

6

Sign in to submit your solution.