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

"""
Input:
    nums1 (List[int]): [3, 2, 0, 1, 0]
    nums2 (List[int]): [6, 5, 0]
Output:
    12

Constraint:
    1. We have to replace all the 0's? -> True
    2. len(nums1), len(nums2) > 0 -> True

Approach: Finding the minimum sum after replacing 0s
    1. Given an array nums1 = [3, 2, 0, 1, 0],
        1. We know that after replacing, the minimum sum should be
            sum_array + num_zeros = (3 + 2 + 1) + 2 = 8
        2. we can calculate the minimum_sum for both arrays

    2. If min_sum_nums1 < min_sum_nums2:
        1. swap(min_sum_nums1, min_sum_nums2)
        2. swap(num_zeros_nums1, num_zeros_nums2)

    3. Assume min_sum_nums1 > min_sum_nums2:
        1. If num_zeros_nums2 > 0:
            min_equal_sum = min_sum_nums1
        2. Otherwise:
            return -1 because the array with smaller sum cant be increased anymore
    4. if min_sum_nums1 ==min_sum_nums2:
        return min_sum_nums1

TC: O(n), n denotes # elements in two arrays
    We need to calculate the sum - O(n)
SC: O(1)
"""
class Solution:
    def minSum(self, nums1: List[int], nums2: List[int]) -> int:
        # Find the min sum and # zeros for both arrays
        num_zero_1 = nums1.count(0)
        sum1 = sum(nums1) + num_zero_1

        num_zero_2 = nums2.count(0)
        sum2 = sum(nums2) + num_zero_2

        if sum1 < sum2:
            sum1, sum2 = sum2, sum1
            num_zero_1, num_zero_2 = num_zero_2, num_zero_1

        if sum1 > sum2:
            return sum1 if num_zero_2 > 0 else -1 
        return sum1
        
806