#3226

Number of Bit Changes to Make Two Integers Equal

easy · 63.4% accepted · 103 likes · top 66%

bit manipulation

Description

You are given two positive integers n and k.

You can choose any bit in the binary representation of n that is equal to 1 and change it to 0.

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

Solution