DP
IntuitionApproachComplexity
Time complexity:
O(N)
Space complexity:
O(1)Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
O(N)
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
O(1)
# Code
```csharp []
public class Solution {
    public int MaxNonDecreasingLength(int[] nums1, int[] nums2) {
        int len = nums1.Length, maxLen = 1;
        int[] dp = [1, 1];

        for(int i = len-2; i >= 0; i--)
        {
            int next = 0;
            if(nums1[i+1] >= nums1[i])
                next = Math.Max(next, dp[0]);

            if(nums1[i] <= nums2[i+1])
                next = Math.Max(next, dp[1]);

            int dp0 = 1+next;
            next = 0;

            if(nums2[i+1] >= nums2[i])
                next = Math.Max(next, dp[1]);

            if(nums2[i] <= nums1[i+1])
                next = Math.Max(next, dp[0]);

            int dp1 = 1+next;
            dp = [dp0, dp1];
            maxLen = Math.Max(maxLen, Math.Max(dp[0], dp[1]));
        }

        return maxLen;
    }
}
```
['C#']