Number Of Flips Required To Make a|b Equal to c
If you understand the OR operations clearly, then this problem will be a good challenge for your skills. Make sure you have a clear understanding of OR before moving on.
We'll cover the following...
Introduction
In this question, we will flip the bits to make two numbers equal to the third number.
Let’s see how to achieve this using the OR operator.
Problem statement
We need to write a program with minimum flips to make the two bits’ OR operation equal a number.
Input: a = 2, b = 6, c = 5
Output: 3
Explanation: After flips, a = 1 , b = 4 , c = 5 such that (a OR b == c).
Assume
n
is non-negative. Use the|
operator to achieve this.
Solution
We have three positives numbers, a
, b
, and c
...
Access this course and 1400+ top-rated courses and projects.