1318. Minimum Flips to Make a OR b Equal to c
Intuition\nThe goal is to find the minimum number of bit flips required to make two integers a and b equal to a third integer c. We can achieve this by comparin
# Intuition\nThe goal is to find the minimum number of bit flips required to make two integers a and b equal to a third integer c. We can achieve this by comparing the individual bits of a, b, and c.\n# Approach\nInitialize a variable flips to 0 to keep track of the number of bit flips.\nIterate through the bits of a, b, and c using a while loop until all bits are processed.\nInside the loop:\nGet the least significant bit (LSB) of a, b, and c using bitwise AND (&) with 1 (which checks the rightmost bit).\nCheck if the LSB of c is 0:\nIf yes, increment flips by the sum of the LSBs of a and b. This means we need to flip the bits in a and b to match c.\nIf no, check if both LSBs of a and b are 0 (i.e., they are both 1 in order to match c). In this case, increment flips by 1.\nRight-shift (divide by 2) all three numbers (a, b, and c) to process the next bit.\nReturn the final value of flips, which represents the minimum number of bit flips required to make a and b equal to c.\n# Complexity\n- Time complexity: O(log(max(a, b, c))), where log represents the number of bits in the maximum of a, b, and c.\n- Space complexity: O(1), as we are using a constant amount of extra space.\n\n# Code\n```\nclass Solution:\n    def minFlips(self, a: int, b: int, c: int) -> int:\n        flips = 0\n        while a>0 or b>0 or c>0:\n            bit_a = a&1\n            bit_b = b&1\n            bit_c = c&1\n\n            if bit_c == 0:\n                flips += (bit_a + bit_b)\n            else:\n                if bit_a == 0 and bit_b == 0:\n                    flips+=1\n            a>>=1\n            b>>=1\n            c>>=1\n        return flips\n```
['Bit Manipulation', 'Python', 'Python3']