✅ Python || Beat 100% in runtime || Simple || Explained
Approach\n\n- Calulate total number of 0 in each array.\n- Calculate sum of each array.\n- Detect impossible cases first:\n  - Calculate min possible, max possi
# Approach\n![Screenshot 2024-04-30 at 13.55.50.png](https://assets.leetcode.com/users/images/55eb72bb-61fe-4ca3-9e64-ed4429139538_1714460938.2601826.png)\n- Calulate total number of 0 in each array.\n- Calculate sum of each array.\n- Detect impossible cases first:\n  - Calculate min possible, max possible sum of each arrays after replacing all 0.\n  - If max possible of an array is smaller than min possible of the other -> Return -1.\n- Return max of min possible sum of 2 arrays, so both arrays can each to that sum.\n\n# Complexity\n- Time complexity:\n$$O(n1 + n2)$$\n\n- Space complexity:\n$$O(1)$$\n\n# Code\n```\nclass Solution:\n    def minSum(self, nums1: List[int], nums2: List[int]) -> int:\n        # Calculate number of 0 in each array\n        numOfZeros1 = nums1.count(0)\n        numOfZeros2 = nums2.count(0)\n        \n       # Calculate sum of each array\n        sum1 = sum(nums1)\n        sum2 = sum(nums2)\n\n        # Calculate min and max possible sum of each array after replacing all 0\n        minNums1 = sum1 + numOfZeros1\n        minNums2 = sum2 + numOfZeros2\n        maxNums1 = inf if numOfZeros1 > 0 else sum1\n        maxNums2 = inf if numOfZeros2 > 0 else sum2\n\n        # If max sum of an array < min sum of the other array -> Impossible to have equal sum\n        if maxNums1 < minNums2 or maxNums2 < minNums1:\n            return -1\n        \n        # Return max of min possible sum of 2 arrays, so both arrays can each to that sum\n        return max(minNums1, minNums2)\n\n```
['Python3']