Short python solution using 2 candidates
The idea is  there are only 2 candidates a[0] or b[0] when starting, lets evaluate both and find if solution exists.\n\nall(map(partial(ispresent, a[0]), range(
The idea is  there are only 2 candidates a[0] or b[0] when starting, lets evaluate both and find if solution exists.\n\nall(map(partial(ispresent, a[0]), range(n)) checks if a[0] is present in every domino. if it is present, then the answer = we need to flip the number of positions that don\'t have a[0], given by \nmin(n-ca[a[0]], n-cb[a[0]]). \n\nWe take the min number of flips from both a and b.\n\nWe apply the same procedure to candidate b[0]\n\n```\ndef minDominoRotations(self, a: List[int], b: List[int]) -> int:\n        ispresent = lambda x, i: a[i] == x or b[i] == x \n        ca, cb, n = Counter(a), Counter(b), len(a)\n        res1, res2 = math.inf, math.inf\n        if all(map(partial(ispresent, a[0]), range(n))):\n            res1 = min(n-ca[a[0]], n-cb[a[0]])\n        if all(map(partial(ispresent, b[0]), range(n))):\n            res2 = min(n-ca[b[0]], n-cb[b[0]])\n        res = min(res1, res2)\n        return -1 if res == math.inf else res\n```
[]