Java Clean Top Down 2D DP O(Nx3)
\nclass Solution {\n    private int[][] memo;\n    public int maxNonDecreasingLength(int[] nums1, int[] nums2) {\n        this.memo = new int[nums1.length][3];\
```\nclass Solution {\n    private int[][] memo;\n    public int maxNonDecreasingLength(int[] nums1, int[] nums2) {\n        this.memo = new int[nums1.length][3];\n        for (int[] row : memo) Arrays.fill(row, -1);\n        return dp(new int[][]{nums1, nums2}, 0, -1);\n    }\n\n\n    private int dp(int[][] nums, int i, int prevArr) {\n        if (i >= nums[0].length) {\n            return 0;\n        }\n\n        if (memo[i][prevArr+1] != -1) {\n            return memo[i][prevArr+1];\n        }\n\n        int skip = 0;\n        if (prevArr == -1) {\n            skip = dp(nums, i + 1, prevArr);\n        }\n        int take = 0;\n        \n        if (prevArr == -1 || (nums[prevArr][i-1] <= nums[0][i])) {\n            take = Math.max(take, dp(nums, i + 1, 0) + 1);\n        }\n\n        if (prevArr == -1 || (nums[prevArr][i-1] <= nums[1][i])) {\n            take = Math.max(take, dp(nums, i + 1, 1) + 1);\n        }\n\n        return memo[i][prevArr+1] = Math.max(take, skip);\n\n    }\n}\n```
['Java']