100% || O(n) Solution without extra space || Beginner friendly
Intuition\nThe intuition behind the approach is to iterate over the arrays nums1 and nums2 simultaneously and track the lengths of the non-decreasing subsequenc
# Intuition\nThe intuition behind the approach is to iterate over the arrays nums1 and nums2 simultaneously and track the lengths of the non-decreasing subsequences that can be formed by merging the elements of the two arrays.\n\n\n# Complexity\n- Time complexity: $$O(n)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(1)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    int maxNonDecreasingLength(vector<int>& nums1, vector<int>& nums2) {\n        int n = nums2.size();\n        int ml = 0;\n        int prev1 = 1, prev2 = 1;\n\n        if (n == 1) {\n            return 1;\n        }\n\n        for (int i = 1; i < n; i++) {\n            int current1 = 1, current2 = 1;\n\n            if (nums1[i] >= nums1[i - 1]) {\n                current1 = max(current1, prev1 + 1);\n            }\n\n            if (nums2[i] >= nums2[i - 1]) {\n                current2 = max(current2, prev2 + 1);\n            }\n\n            if (nums1[i] >= nums2[i - 1]) {\n                current1 = max(current1, prev2 + 1);\n            }\n\n            if (nums2[i] >= nums1[i - 1]) {\n                current2 = max(current2, prev1 + 1);\n            }\n\n            ml = max(ml, max(current1, current2));\n            prev1 = current1;\n            prev2 = current2;\n        }\n\n        return ml;\n    }\n};\n\n```
['C++']