Memoization | DP | C++
\nclass Solution {\n    int dfs(int i, int n, int choice, vector<int> &nums1, vector<int> &nums2, vector<vector<int>> &dp) {\n        if(i == n) return 0;\n    
```\nclass Solution {\n    int dfs(int i, int n, int choice, vector<int> &nums1, vector<int> &nums2, vector<vector<int>> &dp) {\n        if(i == n) return 0;\n        if(dp[i][choice] != -1) return  dp[i][choice];\n        \n        if(choice == 0) {\n            int notpick = dfs(i + 1, n, choice, nums1, nums2, dp);\n            int pick1 =  1 + dfs(i + 1, n, 1, nums1, nums2, dp);\n            int pick2 =  1 + dfs(i + 1, n, 2, nums1, nums2, dp);\n            return max({notpick, pick1, pick2});\n        }\n        \n        int last = choice == 1 ? nums1[i - 1] : nums2[i - 1];\n        int pick1 = 0, pick2 = 0;\n        \n        int notpick = !choice ? dfs(i + 1, n, choice, nums1, nums2, dp) : 0;\n        if(last <= nums1[i]) {\n            pick1 = 1 + dfs(i + 1, n, 1, nums1, nums2, dp);\n        }\n        if(last <= nums2[i]) {\n            pick2 = 1 + dfs(i + 1, n, 2, nums1, nums2, dp);\n        }\n        return dp[i][choice] = max({notpick, pick1, pick2});\n    }\npublic:\n    int maxNonDecreasingLength(vector<int>& nums1, vector<int>& nums2) {\n        int n = nums1.size();\n        vector<vector<int>> dp(n, vector<int>(3, -1));\n        \n        return dfs(0, n, 0, nums1, nums2, dp);\n    }\n};\n```
['Dynamic Programming', 'Memoization', 'C++']