O(1) time complexity DP | C++
Complexity

Time complexity:
O(n)


Space complexity:
O(1)

Code
# Complexity
- Time complexity:
$$O(n)$$

- Space complexity:
$$O(1)$$

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