Minimum Sum Calculation: O(n) time, O(1) space, easy to read and understand
Intuition\nTo solve the problem of calculating the minimum sum of two lists, where zeroes can be substituted, we need to consider each list\'s non-zero elements
# Intuition\nTo solve the problem of calculating the minimum sum of two lists, where zeroes can be substituted, we need to consider each list\'s non-zero elements and the count of zeroes. The goal is to find the minimum possible sum for each list and determine if a valid solution exists.\n\n# Approach\n1. **Traverse Each List**: Calculate the sum of non-zero elements and count the zeroes for both lists.\n2. **Calculate Minimum Possible Sums**: For each list, add the count of zeroes to the sum of non-zero elements.\n3. **Handle Edge Cases**:\n   - If both lists have no zeroes and their sums differ, return -1 (no valid solution).\n   - If one list has zeroes and the other does not, ensure the minimum possible sum condition holds.\n4. **Determine Result**: Return the maximum of the minimum possible sums from both lists.\n\n# Complexity\n- **Time Complexity**: \\(O(n)\\), where \\(n\\) is the length of the input lists. Each list is traversed once.\n- **Space Complexity**: \\(O(1)\\), using a constant amount of extra space.\n\n# Code\n```python\nfrom typing import List\n\nclass Solution:\n    def minSum(self, nums1: List[int], nums2: List[int]) -> int:\n        count1 = sum(num for num in nums1 if num != 0)\n        zeros1 = nums1.count(0)\n        count2 = sum(num for num in nums2 if num != 0)\n        zeros2 = nums2.count(0)\n\n        min1 = count1 + zeros1\n        min2 = count2 + zeros2\n\n        if zeros1 == 0 and zeros2 == 0 and count1 != count2:\n            return -1\n\n        if zeros1 == 0 and zeros2 != 0 and not (min2 <= min1):\n            return -1\n\n        if zeros1 != 0 and zeros2 == 0 and not (min1 <= min2):\n            return -1\n\n        return max(min1, min2)\n```
['Python3']