4 if Statements that's it !! Beats 100% TC & 69% SC
Performance:\n\n\n# Video to refer (Hindi):\nhttps://www.youtube.com/watch?v=fOQ_f3iYLVQ\n# Complexity\n- Time complexity: O(N)\n Add your time complexity here,
# Performance:\n![image.png](https://assets.leetcode.com/users/images/002c92ac-cc87-4715-b173-6bfa3ea2e9e3_1729239675.1859033.png)\n\n# Video to refer (Hindi):\nhttps://www.youtube.com/watch?v=fOQ_f3iYLVQ\n# Complexity\n- Time complexity: O(N)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(2N)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```cpp []\nstatic int speedup = [](){\n    ios::sync_with_stdio(false);\n    cin.tie(NULL);\n    cout.tie(0);\n    return 0;\n}();\nclass Solution {\npublic:\n    int maxNonDecreasingLength(vector<int>& n1, vector<int>& n2) {\n        int ans = 1;\n        int n = n1.size();\n        vector<int> dp1(n, 1), dp2(n, 1);\n        for(int i = 1; i < n; i++){\n            // for dp1 that stores max length from 0 to i in n1\n            if(n1[i - 1] <= n1[i]){\n                dp1[i] = max(dp1[i], dp1[i - 1] + 1);\n            }\n            if(n2[i - 1] <= n1[i]){\n                dp1[i] = max(dp1[i], dp2[i - 1] + 1);\n            }\n            // for dp2 that stores max length from 0 to i in n2\n            if(n2[i - 1] <= n2[i]){\n                dp2[i] = max(dp2[i], dp2[i - 1] + 1);\n            }\n            if(n1[i - 1] <= n2[i]){\n                dp2[i] = max(dp2[i], dp1[i - 1] + 1);\n            }\n            ans = max(ans, max(dp1[i], dp2[i]));\n        }\n        return ans;\n    }\n};\n```
['Array', 'Dynamic Programming', 'C++']