Skip to content

Practice Minimize XOR

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#2429
LeetCode Problem

Minimize XOR

Problem Statement

Return the positive integer x with the same number of binary one-bits as num2 that minimizes x XOR num1. XOR is bitwise, and the minimizing x is unique.

Source: Minimize XOR on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
num1 = 3, num2 = 5
Output
3

# Example 2

Input
num1 = 1, num2 = 12
Output
3

Constraints

1 <= num1, num2 <= 10^9

Related LeetCode Problems

Practice more problems similar to Minimize XOR.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.