Greedy || O(n) || 100% Beats
Approach\nWe first find the sum of both the arrays. If there is a case where number of zeros in an array is zero and the sum of array is less than the sum of an
# Approach\nWe first find the sum of both the arrays. If there is a case where number of zeros in an array is zero and the sum of array is less than the sum of another array + number of it\'s zeros, then obviously two of them can never have the same sum after replacement. Hence we return $-1$ in such cases.\n\nIn all the other cases we find what is the maximum value between $sum\\_one + zero\\_one$ and $sum\\_two + zero\\_two$. Whatever is the maximum of them we return it. Why?\nBecauses **minimum replacement** we can do is by 1, so obviously the bigger value will be the minimum we can get by doing replacements by 1 and the smaller one will just have to match it.\n\n# Complexity\n- Time complexity:\n$$O(n)$$\n\n- Space complexity:\n$$O(1)$$\n\n# Code\n```\nclass Solution\n{\npublic:\n    long long minSum(vector<int> &nums1, vector<int> &nums2)\n    {\n        long long sum_one = 0, sum_two = 0;\n        int zero_one = 0, zero_two = 0;\n        for (int num : nums1)\n        {\n            sum_one += num;\n            zero_one += (num == 0);\n        }\n        for (int num : nums2)\n        {\n            sum_two += num;\n            zero_two += (num == 0);\n        }\n        if ((zero_one == 0 && sum_one < sum_two + zero_two) || (zero_two == 0 && sum_two < sum_one + zero_one))\n            return -1;\n        return max(sum_one + zero_one, sum_two + zero_two);\n    }\n};\n```
['C++']