DP - Solution - Python
\n\n# Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\nO(n)\n\n# Code\n\nclass Solution(object):\n    def maxNonDecreasingLength(self, nums1, nums2)
\n\n# Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\nO(n)\n\n# Code\n```\nclass Solution(object):\n    def maxNonDecreasingLength(self, nums1, nums2):\n        n = len(nums1)\n        dp1 = [1] * n\n        dp2 = [1] * n\n\n        for i in range(1, n):\n            if nums1[i] >= nums1[i-1]:\n                dp1[i] = max(dp1[i], dp1[i-1] + 1)\n            if nums1[i] >= nums2[i-1]:\n                dp1[i] = max(dp1[i], dp2[i-1] + 1)\n                \n                \n            if nums2[i] >= nums2[i-1]:\n                dp2[i] = dp2[i-1] + 1\n            if (nums2[i] >= nums1[i-1]):\n                dp2[i] = max(dp2[i], dp1[i-1] + 1)\n        return max(max(dp1), max(dp2))\n```
['Python']