Max XOR
Updated
Problem 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 interview questions
- Missing IntervalsOA · Seen Nov 2026
- Count Peaks and ValleysOA · Seen Nov 2026
- Last Object Exit TimeOA · Seen Nov 2026
- Count Strictly Increasing Contiguous WindowsOA · Seen Nov 2026
- Total Each Letter's Count in an Encoded StringOA · Seen Nov 2026
- Count Servers With No Requests in a Time WindowOA · Seen Nov 2026
- Alternate Odd and Even Numbers with Two GoroutinesPHONE SCREEN · Seen Nov 2026
- Longest Substring Without Repeating CharactersPHONE SCREEN · Seen Nov 2026
- Maximum Easy Tasks After RearrangingOA · Seen Nov 2026
- Longest Palindromic SubstringPHONE SCREEN · Seen Oct 2026
Similar questions at other companies
- Minimum No-Repeat Segments After One Character RemovalSalesforce · OASalesforce interview questions
- Minimize the Maximum Array ElementChubb · OAChubb interview questions
- Minimum Operations to Reduce an Integer to ZeroMicrosoft · OAMicrosoft interview questions
- Server SelectionPoint72 · OAPoint72 interview questions
- Minimum Servers for an Exact LoadJP Morgan Chase · OAJP Morgan Chase interview questions
- Minimum Operations To Reduce To ZeroUber · OAUber interview questions
- Maximize PartitionsAmazon · OA
- Maximum XOR SuffixTikTok · OATikTok interview questions
- Minimum Power-of-Two AdjustmentsNVIDIA · OANVIDIA interview questions
- Fewest Steps to Build an Array from ZerosExpedia · OAExpedia interview questions