FastPrepMaximize Binary XOR with a Set-Bit Limit
Problems/Maximize Binary XOR with a Set-Bit Limit

Maximize Binary XOR with a Set-Bit Limit

JP Morgan Chase logoJP Morgan Chase● EasyFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a JP Morgan Chase phone screen. The interview report asks for a string with a limited number of set bits that maximizes XOR, with high-order zero bits first. Our version is about 97% the same as the reported question.

You are given a binary string x, its required bitLength, and an integer maxSet. Construct a binary string y of exactly bitLength bits containing at most maxSet bits equal to 1 so that the numeric value of x XOR y is maximized.

Return y, preserving leading zeros.

Function

maximizeXor(x: String, bitLength: int, maxSet: int) → String

Examples

Example 1

x = "10100"bitLength = 5maxSet = 2return = "01010"

Set the two highest-order positions where x has zero, producing XOR value 11110.

Example 2

x = "10100"bitLength = 5maxSet = 5return = "01011"

All zero-bits of x can be flipped; extra one-bits would reduce the XOR value.

Example 3

x = "111"bitLength = 3maxSet = 2return = "000"

Any one-bit in y would turn a high XOR bit off.

Constraints

  • 1 <= bitLength <= 200000
  • x.length == bitLength and x contains only 0 and 1.
  • 0 <= maxSet <= bitLength.

More JP Morgan Chase interview questions

  • Longest Consecutive SequencePHONE SCREEN · Seen Nov 2026
  • Top K Frequent Values Across Key-Partitioned ShardsPHONE SCREEN · Seen Sep 2026
  • Best Time to Buy and Sell StockPHONE SCREEN · Seen Aug 2026
  • All Index Pairs Sum to KPHONE SCREEN · Seen Aug 2026
  • LFU CacheONSITE INTERVIEW · Seen Nov 2026
  • LRU CacheONSITE INTERVIEW · Seen Nov 2026
  • Find Total CostOA · Seen Oct 2026
  • Minimum Meeting RoomsOA · Seen Oct 2026
  • Count Dropped RequestsOA · Seen Oct 2026
  • Maximize Minimum Deployment DifficultyOA · Seen Oct 2026

Similar questions at other companies

  • IP Range to CIDR BlocksAirbnb · PHONE SCREENAirbnb interview questions
  • Minimum No-Repeat Segments After One Character RemovalSalesforce · OASalesforce interview questions
  • Convert an IPv4 Range to Minimal CIDR BlocksOpenAI · ONSITE INTERVIEWOpenAI interview questions
  • Minimum Insertions to Balance ParenthesesGoogle · PHONE SCREENGoogle interview questions
  • Integer to Binary RepresentationThe Walt Disney Company · PHONE SCREENThe Walt Disney Company interview questions
  • Wrap Text with Retained Boundary SpacesAtlassian · PHONE SCREENAtlassian interview questions
  • Palindrome After At Most One DeletionAdobe · PHONE SCREENAdobe interview questions
  • Spelling Bee Word FilterBloomberg LP · PHONE SCREENBloomberg LP interview questions
  • Wrap Words from Existing Text LinesCompass International Holdings · PHONE SCREENCompass International Holdings interview questions
  • Largest Number Below N from Reusable DigitsByteDance · PHONE SCREENByteDance interview questions

JP Morgan Chase interview experiences

  • JPMorgan Chase Experienced SWE Java Interview: 1 Experience
  • JPMorgan Quant Stats Superdays: 3 Experiences (Part 3 of 3)
  • JPMorgan Quant Modeling Superdays: 7 Experiences (Part 2 of 3)
  • JPMorgan Quant Intern Superday: 19 Experiences (Part 1 of 3)
  • JP Morgan Chase Data and AI Intern Superday: 11 Experiences
  • JPMorgan Code for Good India 2024: 6 Experiences (Part 5 of 5)
All JP Morgan Chase interview questionsSee JP Morgan Chase hiring insights
Saved
class Solution {
    public String maximizeXor(String x, int bitLength, int maxSet) {
        // Write your code here.
    }

}
Checking account…