O(1) space || Easy
\n\n# Code\n\nclass Solution {\npublic:\n    int maxNonDecreasingLength(vector<int>& nums1, vector<int>& nums2) {\n        int n = nums1.size(),pre1=1,pre2=1,n1
\n\n# Code\n```\nclass Solution {\npublic:\n    int maxNonDecreasingLength(vector<int>& nums1, vector<int>& nums2) {\n        int n = nums1.size(),pre1=1,pre2=1,n1=1,n2=1,ans=1;\n        for(int i=1;i<n;i++){\n            n1=1;\n            n2=1;\n            if(nums1[i]>=nums1[i-1]){\n                n1 = pre1+1;\n            }\n            if(nums1[i] >= nums2[i-1]){\n                n1 = max(n1,pre2+1);\n            }\n            \n            if(nums2[i]>=nums2[i-1]){\n                n2 = pre2+1;\n            }\n            if(nums2[i] >= nums1[i-1]){\n                n2 = max(n2,pre1+1);\n            }\n            ans = max(ans,max(n1,n2));\n            pre1=n1;\n            pre2=n2;\n            \n        }\n        return ans;\n    }\n};\n```
['C++']