Tap here to switch tabs
Problem
Submissions

Problem: Minimize XOR

med
30 min
Try to solve the Minimize XOR problem.

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

med
30 min
Try to solve the Minimize XOR problem.

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