110 % understandable || Recursion
\n\n# Code\n\nclass Solution {\npublic:\n    int dp[100005][3];\n    \n    int solve(int i,int prenum,vector<int> &nums1,vector<int> &nums2)\n    {\n        if(
\n\n# Code\n```\nclass Solution {\npublic:\n    int dp[100005][3];\n    \n    int solve(int i,int prenum,vector<int> &nums1,vector<int> &nums2)\n    {\n        if(i>=nums1.size()) return 0; //base case \n         \n        if(dp[i][prenum]!=-1) return dp[i][prenum];\n        int ans=0;\n        if(prenum==0) //if not choosen any array(nums) till now \n        {\n            int nottake=solve(i+1,0,nums1,nums2); //not choosing element from any of them \n            int take1=1+solve(i+1,1,nums1,nums2); // nums1 choosen as a first index \n            \n            int take2=1+solve(i+1,2,nums1,nums2); //nums2 choosen as a first index \n            ans=max({nottake,take1,take2}); //take maximum \n            \n        }\n        else \n        {\n            if(prenum==1) //previous choosen element was from nums1\n            {\n                if(nums1[i]>=nums1[i-1]) ans=max(ans,1+solve(i+1,1,nums1,nums2)); //if curr element of nums1 is greater or equal of previous element \n                if(nums2[i]>=nums1[i-1]) ans=max(ans,1+solve(i+1,2,nums1,nums2)); //if curr element of nums2 is greater or equal of previous element\n                \n            }\n            else if(prenum==2) //previous choosen element was from nums2\n            {\n                if(nums1[i] >=nums2[i-1]) ans=max(ans,1+solve(i+1,1,nums1,nums2));  //if curr element of nums1 is greater or equal of previous element \n                \n                if(nums2[i]>=nums2[i-1]) ans=max(ans,1+solve(i+1,2,nums1,nums2)); //if curr element of nums2 is greater or equal of previous element \n                \n                \n            }\n           \n            \n        }\n        return dp[i][prenum]= ans;\n        \n    }\n    int maxNonDecreasingLength(vector<int>& nums1, vector<int>& nums2) {\n        \n        memset(dp,-1,sizeof(dp));\n        int ans=solve(0,0,nums1,nums2);\n        return ans;\n        \n       \n    }\n};\n```
['Dynamic Programming', 'Recursion', 'Memoization']