Watch 10 video solutions for Guess the Number Using Bitwise Questions II, a medium level problem involving Bit Manipulation, Interactive. This walkthrough by NeetCode has 155,494 views views. Want to try solving it yourself? Practice on FleetCode or read the detailed text solution.
There is a number n between 0 and 230 - 1 (both inclusive) that you have to find.
There is a pre-defined API int commonBits(int num) that helps you with your mission. But here is the challenge, every time you call this function, n changes in some way. But keep in mind, that you have to find the initial value of n.
commonBits(int num) acts as follows:
count which is the number of bits where both n and num have the same value in that position of their binary representation.n = n XOR numcount.Return the number n.
Note: In this world, all numbers are between 0 and 230 - 1 (both inclusive), thus for counting common bits, we see only the first 30 bits of those numbers.
Constraints:
0 <= n <= 230 - 10 <= num <= 230 - 1num out of the given range, the output wouldn't be reliable.