EASY TO UNDERSTAND SOLUTION || BEATS 80% of Solutions
Complexity\n- Time complexity: O(n)\n\n- Space complexity: O(1)\n\n# Code\n\nclass Solution {\npublic:\n    long long minSum(vector<int>& nums1, vector<int>& nu
# Complexity\n- Time complexity: $$O(n)$$\n\n- Space complexity: $$O(1)$$\n\n# Code\n```\nclass Solution {\npublic:\n    long long minSum(vector<int>& nums1, vector<int>& nums2) {\n        long long sum1 = 0LL, sum2=0LL;\n        int count1 =0, count2=0; //count zero in both arrays\n        for(int x : nums1)\n        {\n            sum1+=x;\n            if(x==0)\n                count1++;\n        }\n        for(int x : nums2)\n        {\n            sum2+=x;\n            if(x==0)\n                count2++;\n        }\n        if(count1==0 && sum2+count2>sum1)\n            return -1;\n        if(count2==0 && sum1+count1>sum2)\n            return -1;\n        \n        return max(sum1+count1, sum2+count2);\n    }\n};\n```
['C++']