Easy DP
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:\nO(2*N), N is size of array\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    vector<vector<int>> dp;\n\n    int solve(vector<int>& nums1, vector<int>& nums2, int idx, int arrayNum) {\n        if (idx == nums1.size() - 1) {\n            return 1;\n        }\n\n        if(dp[idx][arrayNum] != -1) {\n            return dp[idx][arrayNum];\n        }\n\n        int v1 = nums1[idx];\n        if (arrayNum == 1) {\n            v1 = nums2[idx];\n        }\n\n        int nxt1 = nums1[idx + 1];\n        int nxt2 = nums2[idx + 1];\n        int first = 1;\n        int second = 1;\n        if (nxt1 >= v1) {\n            first = 1 + solve(nums1, nums2, idx + 1, 0);\n        }\n\n        if (nxt2 >= v1) {\n            second = 1 + solve(nums1, nums2, idx + 1, 1);\n        }\n\n        return dp[idx][arrayNum]=max(first,second);\n    }\n\n    int maxNonDecreasingLength(vector<int>& nums1, vector<int>& nums2) {\n        dp.resize(nums1.size(),vector<int>(2,-1));\n        int maxVal = 1;\n        for (int i = 0; i < nums1.size(); i++) {\n            int first = solve(nums1, nums2, i, 0);\n            int second = solve(nums1, nums2, i, 1);\n            maxVal = max(maxVal, max(first, second));\n        }\n\n        return maxVal;\n    }\n};\n```
['C++']