Easy Video Solution 🔥 || Simple Maths ✅ || C++,JAVA,PYTHON 🔥
Intuition\n Describe your first thoughts on how to solve this problem. \nTake few inputs and analyze all the edge scenarios\n\n# Detailed and easy Video Solutio
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nTake few inputs and analyze all the edge scenarios\n\n# ***Detailed and easy Video Solution***\n\nhttps://youtu.be/CXi39p1nTtE\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nOur code aims to equalize the sums of two arrays, v1 and v2, by replacing zeros with strictly positive integers. It calculates the initial sums and counts the number of zeros in both arrays. To achieve equal sums, it compares the sums and zeros. If the sum of the first array is greater, it swaps the arrays. Then, it checks if the two arrays have no zeros; in that case, it returns -1 since there are no zeros to replace. If the sums are still not equal and the second array has no zeros, it\'s also impossible to equalize the sums, so it returns -1. Otherwise, it returns the modified sum of the first array, which now has non-zero values.\n\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n    O(N)\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n    O(1)\n\n```C++ []\nclass Solution {\npublic:\n    long long minSum(vector<int>& v1, vector<int>& v2) {\n        long long s1=0,s2=0;\n        int c1=0,c2=0;\n        int n=v1.size(),m=v2.size();\n        for(auto i:v1)\n        {\n            if(i==0)\n                c1++;\n            s1=s1+i;\n        }\n        for(auto i:v2)\n        {\n            if(i==0)\n                c2++;\n            s2=s2+i;\n        }\n        s1=s1+c1;\n        s2=s2+c2;\n        if(s2>s1)\n        {\n            swap(s1,s2);\n            swap(c1,c2);\n        }\n        if(s1!=s2 && c1==0 && c2==0)\n            return -1;\n        if(s1!=s2 && c2==0)\n            return -1;\n        return s1;\n        \n    }\n};\n```\n```python []\nclass Solution:\n    def minSum(self, v1, v2):\n        s1, s2 = 0, 0\n        c1, c2 = 0, 0\n        n, m = len(v1), len(v2)\n        for i in v1:\n            if i == 0:\n                c1 += 1\n            s1 += i\n        for i in v2:\n            if i == 0:\n                c2 += 1\n            s2 += i\n        s1 = s1 + c1\n        s2 = s2 + c2\n        if s2 > s1:\n            s1, s2 = s2, s1\n            c1, c2 = c2, c1\n        if s1 != s2 and c1 == 0 and c2 == 0:\n            return -1\n        if s1 != s2 and c2 == 0:\n            return -1\n        return s1\n\n```\n```java []\nimport java.util.List;\n\npublic class Solution {\n    public long minSum(List<Integer> v1, List<Integer> v2) {\n        long s1 = 0, s2 = 0;\n        int c1 = 0, c2 = 0;\n        int n = v1.size(), m = v2.size();\n        for (int i : v1) {\n            if (i == 0)\n                c1++;\n            s1 += i;\n        }\n        for (int i : v2) {\n            if (i == 0)\n                c2++;\n            s2 += i;\n        }\n        s1 = s1 + c1;\n        s2 = s2 + c2;\n        if (s2 > s1) {\n            long temp = s1;\n            s1 = s2;\n            s2 = temp;\n            int tempCount = c1;\n            c1 = c2;\n            c2 = tempCount;\n        }\n        if (s1 != s2 && c1 == 0 && c2 == 0)\n            return -1;\n        if (s1 != s2 && c2 == 0)\n            return -1;\n        return s1;\n    }\n}\n```\n\n# ***If you like the solution Please Upvote and subscribe to my youtube channel***\n***It Motivates me to record more videos***\n\n ***Thank you*** \uD83D\uDE00
['Math', 'Greedy', 'Python', 'C++', 'Java']