Easy Python3 Solution🔥 || includes Explanation and Comments || Bit Manipulation || Beats over 90%
Approach\nFor each bit in c, do:\n- If bit is 0, then make sure the corresponding bits in a and b are also 0. If bit is 1 in either or both of a and b, increase
# Approach\nFor each bit in c, do:\n- If bit is 0, then make sure the corresponding bits in a and b are also 0. If bit is 1 in either or both of a and b, increase flip count by 1 or 2 respectively.\n- If bit is 1, then either of a or b should have the corresponding bit as 1. If neither have, then increase flip count by 1.\n\n# Complexity\n- Time complexity: O(No. of bits)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution:\n    def minFlips(self, a: int, b: int, c: int) -> int:\n        n = ceil(log2(max(a,b,c)))+1\n        flip = 0\n        for i in range(n):\n            mask = 1<<i\n            if c&mask:      #at a position, if c has a 1, then either b or a should have a 1, else flip one bit.\n                if not (a&mask | b&mask):\n                    flip+=1\n            else:           #if c has 0, then both need to be 0. If not, then flip those bits.\n                if a&mask:\n                    flip+=1\n                if b&mask:\n                    flip+=1\n        return flip\n```\n# If this was helpful, might as well drop a like :D
['Bit Manipulation', 'Python3']