Problem · Bit Manipulation
Max XOR
Learn this problemProblem statement
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 bis maximal fora e b ≤ k.
Function
maxXor(lo: int, hi: int, k: int) → int
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 integerint hi: an integerint k: an integer
Examples
Example 1
lo = 3hi = 5k = 6return = 6
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
1 ≤ lo < hi ≤ 10^41 ≤ k ≤ 10^4
More IBM problems
- Parent Process NumberOA · Seen Jul 2026
- Request Retry CountOA · Seen Jul 2026
- Count Strictly Increasing Subsequences of Length 3OA · Seen Jul 2026
- Maximum Requests in a Time WindowOA · Seen Jul 2026
- Query Type Frequency WindowOA · Seen Jul 2026
- Minimum Number of Non-Empty Disjoint SegmentsOA · Seen Jul 2026
- Spam Text ClassificationOA · Seen Jul 2026
- Count Ideal NumbersOA · Seen Jun 2026