C++ || Easy solution || Greedy || O(n) time and O(1) space complexity
\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
\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```\nclass Solution {\npublic:\n    long long minSum(vector<int>& nums1, vector<int>& nums2) {\n\n        long long sum1 = 0;\n        long long sum2 = 0;\n\n        int zeroes_1 = 0;\n        int zeroes_2 = 0;\n\n        for(int n : nums1){\n            if(n == 0) zeroes_1++;\n            else sum1 += n;\n        }\n\n        for(int n : nums2){\n            if(n == 0) zeroes_2++;\n            else sum2 += n;\n        }\n        \n        if(sum1 == sum2 && zeroes_1 != 0 && zeroes_2 != 0) return sum1 + max(zeroes_1, zeroes_2);\n        else{\n            if((zeroes_1 == 0 && sum2 + zeroes_2> sum1) || (zeroes_2 == 0 && sum1 + zeroes_1 > sum2)) return -1;\n        }\n\n        long long ans = 0;\n\n        if(sum1 > sum2){\n            if(zeroes_1 >= zeroes_2) ans = sum1 + zeroes_1;\n            else if(zeroes_1 < zeroes_2) ans = max(sum1 + zeroes_1, sum2 + zeroes_2);\n        }\n        else{\n            if(zeroes_1 <= zeroes_2) ans = sum2 + zeroes_2;\n            else if(zeroes_1 > zeroes_2) ans = max(sum1 + zeroes_1, sum2 + zeroes_2);\n        }\n\n        return ans; \n\n    }\n};\n```
['Array', 'Greedy', 'C++']