Skip to content
Decoder

Minimum Flips to Make a OR b Equal to c

Medium

Problem

You have three positive integers a, b and c. A flip changes one bit of a or b (0 to 1 or 1 to 0). Return the minimum number of flips so that a | b == c (bitwise OR).

Example 1

Input
a = 2, b = 6, c = 5
Output
3
Why
a = 010, b = 110, c = 101

Example 2

Input
a = 4, b = 2, c = 7
Output
1

Example 3

Input
a = 1, b = 2, c = 3
Output
0

Constraints

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

Read it once before you touch anything

Want some pressure? Start the timer. In an interview you get about two minutes to understand the problem.

  1. 1Read the goalWhat goes in, what comes out
  2. 2Scan the examplesCheck one by hand
  3. 3Note the constraintsThey set your Big O
Say what it asks in one sentence
Say it out loud first, then compare with ours.