Intuitive dp solution using c++
Intuitionif you look carefully you have 4 choices
nums1[i] paired with nums1[i+1]
nums2[i] paired with nums2[i+1]
nums1[i] paired with nums2[i+1]
nums2[i] paire
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
if you look carefully you have 4 choices
nums1[i] paired with nums1[i+1]
nums2[i] paired with nums2[i+1]
nums1[i] paired with nums2[i+1]
nums2[i] paired with nums1[i+1]
since there are choices and we need to choose any of the one in order to reach the optimal solution, dynamic programming can be a choice
# Approach
<!-- Describe your approach to solving the problem. -->
dp[i] denotes the length of max non decreasing subarray ending at index i
since there are two arrays , to simplify logic we are going to make 2 dp arrays namely dp1 and dp2 (for nums1 and nums2 respectively)
we are initializing the dp arrays with 1 as every element of the nums arrays are in itself max non decreasing subarray of length 1 :)
ps: see the state transition from the code carefully they are self explainatory 
*if u still have any doubts u can comment below
# Complexity
- Time complexity: o(n)
<!-- Add your time complexity here, e.g. $$O(n)$$ --> 

- Space complexity: o(1)
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```cpp []
class Solution {
public:
    int maxNonDecreasingLength(vector<int>& nums1, vector<int>& nums2) {
        int n = nums1.size();
        if(n==0) return 0;
        if(n==1) return 1;
        vector<int> dp1(n,1), dp2(n,1);
        int ans = 0;
        for(int i = 1; i<n; i++){
            if(nums1[i-1]<=nums1[i]){
                dp1[i] = max(dp1[i],1+ dp1[i-1]);
            }
            if(nums2[i-1]<=nums2[i]){
                dp2[i] = max(dp2[i],1 + dp2[i-1]);
            }
            if(nums1[i-1]<=nums2[i]){
                dp2[i] = max(dp2[i],1 + dp1[i-1]); 
            }
            if(nums2[i-1]<=nums1[i]){
                dp1[i] = max(dp1[i],1 + dp2[i-1]);
            }
            ans = max({ans, dp1[i], dp2[i]});
        }
        return ans;
    }
};
```
['C++']