C++ | easy DP | few lines | O(N)
Intuition\n Describe your first thoughts on how to solve this problem. \n\nl1 : length of increasing subsequence ending at nums1 i\nl2 : length of increasing su
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\nl1 : length of increasing subsequence ending at nums1 i\nl2 : length of increasing subsequence ending at nums2 i\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\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\t\tint l1 = 1, l2 = 1, ans = 1;\n\t\tint n = nums1.size();\n\t\tfor (int i = 1; i < n; i++) {\n\t\t\tint curL1 = 1, curL2 = 1;\n\t\t\tif (nums1[i - 1] <= nums1[i])\n\t\t\t\tcurL1 = 1 + l1;\n\t\t\tif (nums2[i - 1] <= nums1[i])\n\t\t\t\tcurL1 = max(curL1, 1 + l2);\n\t\t\tif (nums1[i - 1] <= nums2[i]) \n\t\t\t\tcurL2 = 1 + l1;\n\t\t\tif (nums2[i - 1] <= nums2[i]) \n\t\t\t\tcurL2 = max(curL2, 1 + l2);\n\t\t\tl1 = curL1, l2 = curL2;\n\t\t\tans = max({ans, l1, l2});\n\t\t}        \n\t\treturn ans;\n    }\n};\n```
['C++']