2918. Minimum Equal Sum of Two Arrays After Replacing Zeros
IntuitionApproachComplexity
Time complexity:

Space complexity:
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```java []
class Solution {
    public long minSum(int[] list1, int[] list2) {
        int len1 = list1.length;
        int len2 = list2.length;
        long total1 = 0;
        long total2 = 0;
        int countZero1 = 0;
        int countZero2 = 0;
        
        for (int i = 0; i < len1; i++) {
            total1 += list1[i];
            if (list1[i] == 0) countZero1++;
        }
        
        for (int i = 0; i < len2; i++) {
            total2 += list2[i];
            if (list2[i] == 0) countZero2++;
        }
        
        boolean condition1 = countZero1 == 0 && total1 - countZero2 < total2;
        boolean condition2 = countZero2 == 0 && total2 - countZero1 < total1;
        
        if (condition1 || condition2) {
            return -1;
        }
        
        return Math.max(countZero1 + total1, countZero2 + total2);
    }
}

```
['Java']