Easy C++ Bottom Up Solution Beats 100%
Complexity
Time complexity: O(n)

Space complexity: O(1)
Code
# Complexity\n- Time complexity: $$O(n)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n- Space complexity: $$O(1)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    int maxNonDecreasingLength(vector<int>& nums1, vector<int>& nums2) {\n        int n = nums1.size(), ans = 1, dp1 = 1, dp2 = 1;\n        for(int i = n - 2 ; i >= 0 ; i--) {\n            int temp1 = 1;\n            int temp2 = 1;\n            if(nums1[i] <= nums1[i + 1]) {\n                temp1 = max(temp1, 1 + dp1);\n            }\n            if(nums1[i] <= nums2[i + 1]) {\n                temp1 = max(temp1, 1 + dp2);\n            }\n            if(nums2[i] <= nums1[i + 1]) {\n                temp2 = max(temp2, 1 + dp1);\n            }\n            if(nums2[i] <= nums2[i + 1]) {\n                temp2 = max(temp2, 1 + dp2);\n            }\n            dp1 = temp1;\n            dp2 = temp2;\n            ans = max(ans, max(dp1, dp2));\n        }\n        return ans;\n    }\n};\n\n// Time complexity: O(n)\n// Space complexity: O(1)\n```
['C++']