Java simple greedy
Ref: https://leetcode.com/problems/get-the-maximum-score/discuss/767987/JavaC%2B%2BPython-Two-Pointers-O(1)-Space\n\n    public int maxSum(int[] a, int[] b) {\n
Ref: https://leetcode.com/problems/get-the-maximum-score/discuss/767987/JavaC%2B%2BPython-Two-Pointers-O(1)-Space\n```\n    public int maxSum(int[] a, int[] b) {\n        int i = 0, j = 0;\n        long m = a.length, n = b.length, suma = 0, sumb = 0, mod = 1_000_000_007;\n        while (i < m || j < n) {\n            if (i < m && (j >= n || a[i] < b[j])) suma += a[i++];\n            else if (j < n && (i >= m || a[i] > b[j])) sumb += b[j++]; \n            else {\n                suma = sumb = (Math.max(suma, sumb) + a[i++]) % mod;\n                j++;\n            }\n        }\n        return (int) (Math.max(suma, sumb) % mod);\n    }\n```\n\n\nInteresting dp problem, how many routes if you can switch.\n```\n    int m, n, dp[][];\n    public int maxSum(int[] a, int[] b) {\n        m = a.length; n = b.length; dp = new int[m + 1][n + 1];\n        return dfs(0, 0, a, b);\n    }\n    \n    private int dfs(int i, int j, int[] a, int[] b) {\n        int i0 = i, j0 = j;\n        if (i >= m || j >= n) return 1;\n        if (dp[i][j] > 0) return dp[i][j];\n        while (a[i] != b[j]) {\n            System.out.println(i + "," + j);\n            while (a[i] < b[j]) if (++i >= m) return 1;\n            while (b[j] < a[i]) if (++j >= n) return 1;\n        }\n        dp[i0][j0] = dfs(i + 1, j, a, b) + dfs(i, j + 1, a, b);\n        return dp[i0][j0];\n    }\n```
[]