Made Easy | Greedy | O(n)
Intuition\n\nQuestion asked for minimum sum, each zeroes can be replaced by only +ve positives, \nminimum value they can take is 1.\nNow find min value for nums
# Intuition\n```\nQuestion asked for minimum sum, each zeroes can be replaced by only +ve positives, \nminimum value they can take is 1.\nNow find min value for nums1, nums2.\nAnswer is max(nums1, nums2) so both could reach the sum.\nNote: say nums1 sum=5, nums2 sum = 4.\nBut nums2 doesnt have any zeroes, so we can never increase make \nnums2 to nums1.\n```\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n```\nGreedy\n```\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:$$O(n)$$ \n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:$$O(1)$$ \n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    long long minSum(vector<int>& nums1, vector<int>& nums2) {\n        long long sum1=0, sum2=0, zero1=0, zero2=0;\n        // min value nums1 can go\n        for(auto &x: nums1){\n            sum1+=x;\n            if(x==0) sum1+=1, zero1++;\n        }\n        // min value nums2 can go\n        for(auto &x: nums2){\n            sum2+=x;\n            if(x==0) sum2+=1, zero2++;\n        }\n        // both equal case\n        if(sum1==sum2) return sum1;\n        if(sum1>sum2){\n            // nums2 need to have atleast one zero to increase its sum\n            if(zero2>0) return sum1;\n            return -1;\n        }\n        // nums1 need to have atleast one zero\n        if(zero1>0) return sum2;\n        return -1;\n    }\n};\n```
['C++']