Minimum Flips to Make a OR b Equal to c

Given 3 positive numbers a, b, and c, return the minimum number of flips required in some bits of a and b to make (a OR b == c).

A flip operation consists of changing any single bit from 1 to 0 or changing a bit from 0 to 1 in their binary representation.

Example 1
Inputa = 2, b = 6, c = 5
Output3
After flips, a = 1 and b = 4, so (a OR b == c).
Example 2
Inputa = 4, b = 2, c = 7
Output1
One bit flip is enough to make (a OR b == c).

Constraints

  • 1 <= a <= 10^9
  • 1 <= b <= 10^9
  • 1 <= c <= 10^9

Asked at 2 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate