FunctionRacerProblemsRace

Flips to Make OR Equal

MediumBitsPython, JavaScript, TypeScript, Java, C++

You may flip single bits (a 0 to a 1 or a 1 to a 0) in the binary forms of a and b, as many times as you like and in either number. Return the smallest number of flips after which a | b (bitwise OR) equals c exactly. All three numbers are 31 bit non-negative integers.

Example 1

a 2
b 6
c 5
returns 3

Bit by bit: bit 0 of c is 1 but neither a nor b has it (1 flip); bit 1 of c is 0 but both have it (2 flips); bit 2 is already fine.

Example 2

a 4
b 2
c 7
returns 1

4 | 2 is 6, so only bit 0 is missing: set it in either number.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Bits problems