Problem
You get three positive integers a, b and c. A flip changes one bit in the binary form of a or b. It changes a 1 to a 0, or a 0 to a 1.
Return the minimum number of flips that make a OR b equal to c. OR is the bitwise OR operation. The result of a OR b has a 1 bit at each position where a or b has a 1 bit.
Example 1
- Input:
- a = 1, b = 4, c = 6
- Output:
- 2
- Explanation:
- In binary,
a = 001,b = 100andc = 110. Flip bit 0 ofato 0, and flip bit 1 ofaorbto 1.
Example 2
- Input:
- a = 7, b = 7, c = 1
- Output:
- 4
- Explanation:
- Bits 1 and 2 must be 0 in both
aandb. That needs four flips.
Example 3
- Input:
- a = 5, b = 2, c = 7
- Output:
- 0
- Explanation:
101 OR 010is already111.
Constraints
- 1 <= a <= 10^9
- 1 <= b <= 10^9
- 1 <= c <= 10^9
SysRound wrote this statement. A reference solution checks every example.
Related questions
Continue with questions that share topics or the same question type.
Sources · 1 reference
These records explain where the question appears. A company tag or candidate report does not guarantee a future interview question.
Hello Interview · 1 record
No company association
Leetcode 1318. Minimum Flips to Make a OR b Equal to c
Reported date not specified · 0 source reports
Source snapshot: Nov 12, 2026
View source