C++ | DP | Tabulation
\n\n# Code\n\nclass Solution {\npublic:\n    int maxNonDecreasingLength(vector<int>& nums1, vector<int>& nums2) {\n        int ans = 1;\n        int n = nums1.s
\n\n# Code\n```\nclass Solution {\npublic:\n    int maxNonDecreasingLength(vector<int>& nums1, vector<int>& nums2) {\n        int ans = 1;\n        int n = nums1.size();\n        vector<vector<int>> tab(n, vector<int>(2, 0));\n        tab[0][0] = 1, tab[0][1] = 1;\n        for (int i = 1; i < n; i++){\n            int a = 1, b = 1;\n            if(nums1[i] >= nums1[i - 1]){\n                a = 1 + tab[i - 1][0];\n            }\n            if(nums1[i] >= nums2[i - 1]){\n                b = 1 + tab[i - 1][1];\n            }\n            tab[i][0] = max(a, b);\n            a = 1, b = 1;\n            if(nums2[i] >= nums1[i - 1]){\n                a = 1 + tab[i - 1][0];\n            }\n            if(nums2[i] >= nums2[i - 1]){\n                b = 1 + tab[i - 1][1];\n            }\n            tab[i][1] = max(a, b);\n            ans = max({ans, tab[i][0], tab[i][1]});\n        }\n        return ans;\n    }\n};\n```
['C++']