Java || DP
\n# Code\n\nclass Solution {\n    public int maxNonDecreasingLength(int[] nums1, int[] nums2) {\n        int n = nums1.length;\n        if (n == 1) return 1;   
\n# Code\n```\nclass Solution {\n    public int maxNonDecreasingLength(int[] nums1, int[] nums2) {\n        int n = nums1.length;\n        if (n == 1) return 1;       \n        \n        int[][] dp = new int[n][2];\n        for (int[] d : dp) Arrays.fill(d, 1);\n        int max = 1;\n        for (int i = 1; i < n; i++) {\n            if (nums1[i] >= nums1[i - 1]) dp[i][0] = Math.max(dp[i][0], dp[i - 1][0] + 1);\n            if (nums1[i] >= nums2[i - 1]) dp[i][0] = Math.max(dp[i][0], dp[i - 1][1] + 1);\n            \n            if (nums2[i] >= nums1[i - 1]) dp[i][1] = Math.max(dp[i][1], dp[i - 1][0] + 1);\n            if (nums2[i] >= nums2[i - 1]) dp[i][1] = Math.max(dp[i][1], dp[i - 1][1] + 1);\n            \n            max = Math.max(max, dp[i][0]);\n            max = Math.max(max, dp[i][1]);\n        }\n\n        return max;\n        \n        \n    }\n}\n```
['Java']