C++|| Brute Force Recursion with memoization
Intuition\n###### We have to find longest non decreasing subarray , so it can be start from index i == 0 to n -1 and we have to find maximum one from them , we 
# Intuition\n###### We have to find longest non decreasing subarray , so it can be start from index i == 0 to n -1 and we have to find maximum one from them , we can choose from arr1 or arr2 \n\n# Approach\n###### At starting we have nums1 and nums2 and prevArr which tell about the array from which we have choosen our prevElement of our cur subarray , so we can compare b/w the previous guy and cur guy which we have to choose now, so either we can choose a number from nums1 or nums2 which is greater or equal to our previous val otherwise we can not go further , at last we store in our vector dp[i][preArr] to store the ans of subproblem \n\n# Complexity\n- Time complexity:\nO(N)\n\n- Space complexity:\nO(N)\n\n# Code\n```\nclass Solution {\npublic:\n    int dp[100005][3];\n    int solve(int i,int prevArr,vector<int> &nums1,vector<int> &nums2)\n    {\n        if(i>=nums1.size()) return 0;             // if no more element so return 0\n        \n        if(dp[i][prevArr]!=-1) return dp[i][prevArr];\n        int ans=0;\n        if(prevArr==0)\n        {\n             int nontake = solve( i +1, 0,nums1,nums2);         // if we have not choose any val from both array so we have choice that we can start our subarray from pos i + 1 \n            int take1=1+solve(i+1,1,nums1,nums2);    // take val from nums1\n            int take2=1+solve(i+1,2,nums1,nums2);    // take val from nums2\n            ans=max({nontake,take1,take2});            \n           \n        }\n        else \n        {\n            if(prevArr==1)                         // prev array is nums1\n            {\n                if(nums1[i]>=nums1[i-1]) ans=max(ans,1+solve(i+1,1,nums1,nums2)); // we will update our ans if cur val is greater or equal previous value \n                if(nums2[i]>=nums1[i-1]) ans=max(ans,1+solve(i+1,2,nums1,nums2));\n                \n            }\n            else if(prevArr==2)                    // prev array is num2 \n            {\n                if(nums1[i] >=nums2[i-1]) ans=max(ans,1+solve(i+1,1,nums1,nums2));               \n                if(nums2[i]>=nums2[i-1]) ans=max(ans,1+solve(i+1,2,nums1,nums2));               \n            }          \n        }\n\n        return dp[i][prevArr]= ans;\n    }\n    int maxNonDecreasingLength(vector<int>& nums1, vector<int>& nums2) {\n        \n        memset(dp,-1,sizeof(dp));\n        return solve(0,0,nums1,nums2);\n    }\n};\n```\n\n#### if u understand then  upvote
['Dynamic Programming', 'Recursion', 'Memoization', 'C++']