FastPrepMax XOR
Problems/Max XOR

Max XOR

IBM logoIBM● MediumOA

Updated Sep 2026

QuestionFunctionExamplesConstraints

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 b is maximal for a 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 integer
  • int hi: an integer
  • int 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^4
  • 1 ≤ 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

IBM interview experiences

  • IBM Full-Time SWE OA Questions: 1 Experience
  • IBM Software Intern Résumé Rounds: 2 Experiences (Part 3 of 3)
  • IBM Intern Blitz Interviews: 23 Experiences (Part 2 of 3)
  • IBM Software Intern Interviews: 44 Experiences (Part 1 of 3)
  • IBM Software Intern Interview Questions: 15 Experiences
All IBM interview questionsSee IBM hiring insights
Saved
class Solution {
    public int maxXor(int lo, int hi, int k) {
      // write your code here
    }

}
Checking account…