<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>

"""
Analysis
walkthrough
6+6 11+1 = 12
edge cases
- [0] [0]
- [0, 0, 0, 0] [11]
- not possible [0, 0, 0] [2]
Approach
1. sum arrays 
2. count number of zeros
3. make all of them one except one
4. compare them and for the bigger one also make the 1 
5. if bigger one with 0 is still big or equal -> return -1
6. else return the other array's sum

"""


class Solution:
    def minSum(self, nums1: List[int], nums2: List[int]) -> int:
        sum1 = sum(nums1)
        sum2 = sum(nums2)

        zero_count_1 = self.count_zero(nums1)
        zero_count_2 = self.count_zero(nums2)
        
        if zero_count_1 > 1:
            sum1 += zero_count_1 - 1
            zero_count_1 = 1

        if zero_count_2 > 1:
            sum2 += zero_count_2 - 1
            zero_count_2 = 1

        print(sum1, sum2, zero_count_1, zero_count_2)

        if sum1 >= sum2 and zero_count_2 == 0:
            if sum1 == sum2 and zero_count_1 == 0:
                return sum1

            return -1
        if sum2 >= sum1 and zero_count_1 == 0:
            if sum1 == sum2 and zero_count_2 == 0:
                return sum2
            return -1

        if sum1 >= sum2:
            return sum1 + zero_count_1

        if sum2 >= sum1:
            return sum2 + zero_count_2
        

        return -2
    
    def count_zero(self, nums):
        zero_count = 0
        for num in nums:
            if num == 0:
                zero_count += 1
        
        return zero_count













33600