2D Dp | Using Map
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    int lcs(vector<int>& nums1,vector<int>& nums2,int i,int prev,map<pair<int,int>,int> & dp)\n    {\n        int n=nums1.size(); \n        if(i>=n)\n            return 0;\n        if(dp.find({i,prev})!=dp.end())\n            return dp[{i,prev}];\n        \n            int res=INT_MIN;\n            if(nums1[i]>=prev)\n            {\n                res=max(res,1+lcs(nums1,nums2,i+1,nums1[i],dp));\n            }\n            if(nums2[i]>=prev)\n            {\n                res=max(res,1+lcs(nums1,nums2,i+1,nums2[i],dp));\n            }\n            if(res==INT_MIN)\n                return  dp[{i,prev}] = 0;\n            return dp[{i,prev}] = res;\n\n    }\n    int maxNonDecreasingLength(vector<int>& nums1, vector<int>& nums2) \n    {\n        int i;\n        int n=nums2.size();\n        int res=INT_MIN;\n        map<pair<int,int>,int> dp;\n        for(i=0; i<n; i++)\n        {\n            int a=lcs(nums1,nums2,i,nums1[i],dp);\n            int b=lcs(nums1,nums2,i,nums2[i],dp);\n            res=max(res,max(a,b));\n        }\n        return res;\n    }\n};\n```
['Dynamic Programming', 'Memoization', 'Ordered Map', 'C++']