💥💥 Beats 100% on runtime and memory {EXPLAINED]
\n\n\n# Intuition\nThe problem involves navigating two sorted arrays to find the maximum score by summing unique values along valid paths. The key insight is th
![image.png](https://assets.leetcode.com/users/images/c6c0a90a-a65c-47e4-9e0f-7b45fd8f97b1_1727383156.3754368.png)\n\n\n# Intuition\nThe problem involves navigating two sorted arrays to find the maximum score by summing unique values along valid paths. The key insight is that we can switch between the two arrays when we encounter common elements, allowing us to collect more values.\n\n# Approach\nUse two pointers to traverse both arrays simultaneously, accumulating sums until a common element is found, at which point add the maximum of the two accumulated sums plus the common element to the total score, then reset the sums.\n\n# Complexity\n- Time complexity:\n O(n + m), where n and m are the lengths of the two arrays, since we traverse each array once.\n\n- Space complexity:\nO(1), as we only use a constant amount of extra space for variables.\n\n# Code\n```csharp []\npublic class Solution {\n    public int MaxSum(int[] nums1, int[] nums2) {\n        const int MOD = 1000000007;\n        int i = 0, j = 0;\n        long sum1 = 0, sum2 = 0, maxSum = 0;\n\n        // Traverse both arrays until we reach the end of either\n        while (i < nums1.Length || j < nums2.Length) {\n            // Get the current values of nums1 and nums2 or set to int.MaxValue if we\'ve exhausted one array\n            int val1 = i < nums1.Length ? nums1[i] : int.MaxValue;\n            int val2 = j < nums2.Length ? nums2[j] : int.MaxValue;\n\n            // If the value from nums1 is less than the value from nums2\n            if (val1 < val2) {\n                sum1 += val1; // Accumulate sum from nums1\n                i++; // Move to the next element in nums1\n            } \n            // If the value from nums2 is less than the value from nums1\n            else if (val1 > val2) {\n                sum2 += val2; // Accumulate sum from nums2\n                j++; // Move to the next element in nums2\n            } \n            // When we encounter a common element in both arrays\n            else {\n                // Update the maxSum with the maximum of the two sums and add the common value\n                maxSum = (maxSum + Math.Max(sum1, sum2) + val1) % MOD;\n                sum1 = 0; // Reset sum1 for the next segment\n                sum2 = 0; // Reset sum2 for the next segment\n                i++; // Move past the common element in nums1\n                j++; // Move past the common element in nums2\n            }\n        }\n\n        // After finishing the traversal, add any remaining sums\n        maxSum = (maxSum + Math.Max(sum1, sum2)) % MOD;\n\n        return (int)maxSum; // Return the final maximum score modulo 10^9 + 7\n    }\n}\n\n```
['C#']