Tap here to switch tabs
Problem
Submissions

Problem: Number of Bit Changes to Make Two Integers Equal

Number of Bit Changes to Make Two Integers Equal asks you to turn a positive integer n into k by changing its set bits to zero, returning the operation count or minus one if impossible.

Statement

You are given two positive integers n and k.

In a single operation, you can choose any bit in the binary representation of n that is equal to 11 and change it to 00.

Return the number of operations needed to make n equal to k. If it is impossible to make n equal to k, return −1-1.

Constraints:

  • 1≤1 \leq n, k ≤106\leq 10^6

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Number of Bit Changes to Make Two Integers Equal

Number of Bit Changes to Make Two Integers Equal asks you to turn a positive integer n into k by changing its set bits to zero, returning the operation count or minus one if impossible.

Statement

You are given two positive integers n and k.

In a single operation, you can choose any bit in the binary representation of n that is equal to 11 and change it to 00.

Return the number of operations needed to make n equal to k. If it is impossible to make n equal to k, return −1-1.

Constraints:

  • 1≤1 \leq n, k ≤106\leq 10^6