✅☑[C++/Java/Python/JavaScript] || EXPLAINED🔥
PLEASE UPVOTE IF IT HELPED\n\n---\n\n\n# Approaches\n(Also explained in the code)\n\n1. The minSum function takes two vectors of integers, nums1 and nums2, as i
# PLEASE UPVOTE IF IT HELPED\n\n---\n\n\n# Approaches\n**(Also explained in the code)**\n\n1. The `minSum` function takes two vectors of integers, `nums1` and `nums2`, as input.\n\n1. It initializes `sum1` and `count1` to keep track of the sum and count of zeros in `nums1`. Similarly, it initializes `sum2` and `count2` for `nums2`.\n\n1. The function calculates `sum1` and `count1` by iterating through `nums1`. For each element in `nums1`:\n\n    - If the element is non-zero, it adds it to `sum1`.\n    - If the element is zero, it increments both `sum1` and `count1`.\n1. It then calculates `sum2` and `count2` in the same way by iterating through `nums2`.\n\n1. The function compares `sum1` and `sum2`:\n\n    -   If they are equal, it means the sums are already equal, and it returns either sum as the result.\n1. If `sum1` is greater than `sum2`, it checks if `count2` is zero:\n\n    - If `count2` is zero, it\'s not possible to make `sum1` equal to `sum2`, so it returns -1.\n    - Otherwise, it returns `sum1` as the result because it can be increased to match or exceed `sum2`.\n1. If `sum2` is greater than `sum1`, it checks if `count1` is zero:\n\n    - If `count1` is zero, it\'s not possible to make `sum2` equal to `sum1`, so it returns -1.\n    - Otherwise, it returns `sum2` as the result because it can be increased to match or exceed `sum1`.\n\n\n# Complexity\n- *Time complexity:*\n   $$O(n)$$\n    \n\n- *Space complexity:*\n   $$O(1)$$\n    \n\n\n# Code\n```C++ []\n\nclass Solution {\npublic:\n    long long minSum(vector<int>& nums1, vector<int>& nums2) {\n        long long sum1 = 0, cnt1 = 0; // Initialize sum1 and count1.\n        long long sum2 = 0, cnt2 = 0; // Initialize sum2 and count2.\n\n        // Calculate sum1 and count1 from nums1.\n        for (auto ele : nums1) {\n            if (ele)\n                sum1 = sum1 + ele; // Add non-zero elements to sum1.\n            else {\n                sum1++; // Increment sum1 by 1 for zero elements.\n                cnt1++; // Increment count1 for zero elements.\n            }\n        }\n\n        // Calculate sum2 and count2 from nums2.\n        for (auto ele : nums2) {\n            if (ele)\n                sum2 = sum2 + ele; // Add non-zero elements to sum2.\n            else {\n                sum2++; // Increment sum2 by 1 for zero elements.\n                cnt2++; // Increment count2 for zero elements.\n            }\n        }\n\n        // Compare sum1 and sum2.\n        if (sum1 == sum2)\n            return sum1; // If the sums are equal, return either sum.\n\n        // If sum1 is greater than sum2, check if count2 is zero.\n        // If count2 is zero, return -1 as it\'s not possible to make sum1 equal to sum2.\n        if (sum1 > sum2) {\n            if (cnt2 == 0)\n                return -1;\n            return sum1; // Return sum1 if it\'s greater and count2 is not zero.\n        }\n\n        // If sum2 is greater than sum1, check if count1 is zero.\n        // If count1 is zero, return -1 as it\'s not possible to make sum2 equal to sum1.\n        if (cnt1 == 0)\n            return -1;\n        return sum2; // Return sum2 if it\'s greater and count1 is not zero.\n    }\n};\n\n\n```\n```C []\n\n#include <stdio.h>\n#include <stdlib.h>\n\nlong long minSum(int* nums1, int* nums2, int size1, int size2) {\n    long long sum1 = 0, cnt1 = 0;\n    long long sum2 = 0, cnt2 = 0;\n\n    for (int i = 0; i < size1; i++) {\n        if (nums1[i]) {\n            sum1 += nums1[i];\n        } else {\n            sum1++;\n            cnt1++;\n        }\n    }\n\n    for (int i = 0; i < size2; i++) {\n        if (nums2[i]) {\n            sum2 += nums2[i];\n        } else {\n            sum2++;\n            cnt2++;\n        }\n    }\n\n    if (sum1 == sum2)\n        return sum1;\n    else if (sum1 > sum2) {\n        if (cnt2 == 0)\n            return -1;\n        return sum1;\n    }\n\n    if (cnt1 == 0)\n        return -1;\n    return sum2;\n}\n\nint main() {\n    int nums1[] = {1, 0, 2, 0};\n    int size1 = sizeof(nums1) / sizeof(nums1[0]);\n    int nums2[] = {3, 4, 0, 5};\n    int size2 = sizeof(nums2) / sizeof(nums2[0);\n\n    long long result = minSum(nums1, nums2, size1, size2);\n    printf("Minimum Sum: %lld\\n", result);\n\n    return 0;\n}\n\n\n\n```\n```Java []\nimport java.util.ArrayList;\n\npublic class Solution {\n    public long minSum(ArrayList<Integer> nums1, ArrayList<Integer> nums2) {\n        long sum1 = 0, cnt1 = 0;\n        long sum2 = 0, cnt2 = 0;\n\n        for (int ele : nums1) {\n            if (ele != 0) {\n                sum1 += ele;\n            } else {\n                sum1++;\n                cnt1++;\n            }\n        }\n\n        for (int ele : nums2) {\n            if (ele != 0) {\n                sum2 += ele;\n            } else {\n                sum2++;\n                cnt2++;\n            }\n        }\n\n        if (sum1 == sum2)\n            return sum1;\n        else if (sum1 > sum2) {\n            if (cnt2 == 0)\n                return -1;\n            return sum1;\n        }\n\n        if (cnt1 == 0)\n            return -1;\n        return sum2;\n    }\n}\n\n\n```\n\n```python3 []\nclass Solution:\n    def minSum(self, nums1, nums2):\n        sum1, cnt1 = 0, 0\n        sum2, cnt2 = 0, 0\n\n        for ele in nums1:\n            if ele != 0:\n                sum1 += ele\n            else:\n                sum1 += 1\n                cnt1 += 1\n\n        for ele in nums2:\n            if ele != 0:\n                sum2 += ele\n            else:\n                sum2 += 1\n                cnt2 += 1\n\n        if sum1 == sum2:\n            return sum1\n        elif sum1 > sum2:\n            if cnt2 == 0:\n                return -1\n            return sum1\n\n        if cnt1 == 0:\n            return -1\n        return sum2\n\n\n\n```\n```javascript []\nclass Solution {\n    minSum(nums1, nums2) {\n        let sum1 = 0, cnt1 = 0;\n        let sum2 = 0, cnt2 = 0;\n\n        for (let ele of nums1) {\n            if (ele !== 0) {\n                sum1 += ele;\n            } else {\n                sum1++;\n                cnt1++;\n            }\n        }\n\n        for (let ele of nums2) {\n            if (ele !== 0) {\n                sum2 += ele;\n            } else {\n                sum2++;\n                cnt2++;\n            }\n        }\n\n        if (sum1 === sum2)\n            return sum1;\n        else if (sum1 > sum2) {\n            if (cnt2 === 0)\n                return -1;\n            return sum1;\n        }\n\n        if (cnt1 === 0)\n            return -1;\n        return sum2;\n    }\n}\n\n\n```\n\n---\n\n\n\n# PLEASE UPVOTE IF IT HELPED\n\n---\n---\n\n\n---
['C', 'C++', 'Java', 'Python3', 'JavaScript']