Python 3 - Counting Zeroes + Explanation
In this question we need to at minimum change all zeroes to ones. If we do so, then we know if it\'s impossible to make a sum match if the smaller of the two su
In this question we need to at minimum change all zeroes to ones. If we do so, then we know if it\'s impossible to make a sum match if the smaller of the two sums has no zeroes in it - this is because we have no upwards flexibility on changing at most one of the zeroes to any number to get the two sums to match.\n\nTherefore, we calculate the sums of both arrays, and then count the zeroes of each. We add those counts to the sum and then do our impossibility check: "if the smaller of the two sums does not contain any zeroes in it, then it\'s not possible to increase one of the zero values to some arbitrary positive number to get the sums to match". If this is the case, we return `-1`, otherwise we return the max of the two sums since we can always add to the smaller sum to make them equal.\n```\nclass Solution:\n    def minSum(self, nums1: List[int], nums2: List[int]) -> int:\n        sum_1, sum_2 = sum(nums1), sum(nums2)\n\n        zeroes_in_1 = Solution.__count_zeroes(nums1)\n        zeroes_in_2 = Solution.__count_zeroes(nums2)\n\n        sum_1 += zeroes_in_1\n        sum_2 += zeroes_in_2\n\n        if (sum_1 < sum_2 and zeroes_in_1 == 0) or (sum_2 < sum_1 and zeroes_in_2 == 0):\n            return -1 \n\n        return max(sum_1, sum_2)\n\n    @staticmethod\n    def __count_zeroes(nums: List[int]) -> int:\n        return len([num for num in nums if num == 0])\n```
['Python3']