<p>You are given two arrays <code>nums1</code> and <code>nums2</code> consisting of positive integers.</p>

<p>You have to replace <strong>all</strong> the <code>0</code>&#39;s in both arrays with <strong>strictly</strong> positive integers such that the sum of elements of both arrays becomes <strong>equal</strong>.</p>

<p>Return <em>the <strong>minimum</strong> equal sum you can obtain, or </em><code>-1</code><em> if it is impossible</em>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> nums1 = [3,2,0,1,0], nums2 = [6,5,0]
<strong>Output:</strong> 12
<strong>Explanation:</strong> We can replace 0&#39;s in the following way:
- Replace the two 0&#39;s in nums1 with the values 2 and 4. The resulting array is nums1 = [3,2,2,1,4].
- Replace the 0 in nums2 with the value 1. The resulting array is nums2 = [6,5,1].
Both arrays have an equal sum of 12. It can be shown that it is the minimum sum we can obtain.
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> nums1 = [2,0,2,0], nums2 = [1,4]
<strong>Output:</strong> -1
<strong>Explanation:</strong> It is impossible to make the sum of both arrays equal.
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= nums1.length, nums2.length &lt;= 10<sup>5</sup></code></li>
	<li><code>0 &lt;= nums1[i], nums2[i] &lt;= 10<sup>6</sup></code></li>
</ul>

class Solution:
    def minSum(self, nums1: List[int], nums2: List[int]) -> int:
        # two arrays, nums1 and nums2
        # Have to replace all 0s in both arrays with positive integers such that the sum of elements of both arrays becomes equal

        # Find the minimum sum where sum(nums1) == sum(nums2) or -1 if the sum of one array is > sum(other)

        # return -1 if sum(arr) + numZeros(arr) > sum(other arr) IF other arr has no zeros 
        # return -1 if sum(nums1) != sum(nums2) if both don't have zeros

        # Keep track of sum(non-zero elements) for both arrays, 
        # Keep track of the number of zeros for each array
        # Minimum equal sum (if possible) is going to be as follows
        # THIS ASSUMES BOTH ARRAYS HAVE AT LEAST ONE ZERO
        # max(sum(nums1) + numZeros(nums1), sum(nums2) + numZeros(nums2))

        # If nums1 AND nums2 doesn't have zeros, return sum(nums1) if sum(nums1) == sum(nums2) else -1
        # If nums1 doesn't have zeros, return sum(nums1) >= sum(nums2) + numZeros(nums2)
        # If nums2 doesn't have zeros, return sum(nums2) >= sum(nums1) + numZeros(nums1)
        # If both have zeros, return max(sum(nums1) + numZeros(nums1), sum(nums2) + numZeros(nums2))
        one_has_zeros = True if 0 in nums1 else False
        two_has_zeros = True if 0 in nums2 else False
        
        def numZeros(arr):
            count = Counter(arr)
            if 0 in count:
               return count[0]
            else:
                return 0
        
        if one_has_zeros and two_has_zeros:
            return max(sum(nums1) + numZeros(nums1), sum(nums2) + numZeros(nums2))
        elif one_has_zeros:
            return sum(nums2) if sum(nums2) >= sum(nums1) + numZeros(nums1) else -1
        elif two_has_zeros:
            return sum(nums1) if sum(nums1) >= sum(nums2) + numZeros(nums2) else -1
        else:
            return sum(nums1) if sum(nums1) == sum(nums2) else -1

        return - 1
        
871