Tap here to switch tabs
Problem
Submissions

Problem: Minimize XOR

Minimize XOR gives two positive integers and asks for an integer with the same number of set bits as the second, while minimizing its XOR value with the first.

Statement

Given two positive integers num1 and num2, find an integer x such that:

  • x has the same number of set bits (11s in binary representation) as num2.

  • The value of x $ ext{XOR}$ num1 is minimized.

Return the integer x.

Constraints:

  • 1≤1 \leq num1, num2 ≤109\leq 10^9

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Minimize XOR

Minimize XOR gives two positive integers and asks for an integer with the same number of set bits as the second, while minimizing its XOR value with the first.

Statement

Given two positive integers num1 and num2, find an integer x such that:

  • x has the same number of set bits (11s in binary representation) as num2.

  • The value of x $ ext{XOR}$ num1 is minimized.

Return the integer x.

Constraints:

  • 1≤1 \leq num1, num2 ≤109\leq 10^9