Tony's solution
Intuition\n Greedy algo round, each time pick smaller one not smaller than last one. Until both smaller than last one. Whenever the bigger one being chosen whic
# Intuition\n<!-- Greedy algo round, each time pick smaller one not smaller than last one. Until both smaller than last one. Whenever the bigger one being chosen which is bigger than last one. Set next start point at\nthe first such case. Keep the greedy algo round until end. Find the round with longest length -->\n\n# Approach\n<!-- Each round, save newstart point and find current longest length.\nAt the end, return the longest length -->\n\n# Complexity\n- Time complexity:\n<!-- Worst case, O(n^2) -->\n\n- Space complexity:\n<!-- O(1), few variables savign newstart info. -->\n\n# Code\n```python3 []\nclass Solution:\n    def maxNonDecreasingLength(self, nums1: List[int], nums2: List[int]) -> int:\n        res = 0\n        len1 = len(nums1)\n        maxlen = 0\n        i = 0\n        start = i\n        lastnum = nums1[i] if nums1[i] < nums2[i] else nums2[i]\n        i = i + 1\n        newstart = None\n        newlastnum = None\n        while i < len1:\n            smaller, bigger = (nums1[i], nums2[i]) if nums1[i] < nums2[i] else (nums2[i], nums1[i])\n            if smaller >= lastnum:\n                lastnum = smaller\n            else:\n                if bigger >= lastnum:\n                    if newstart is None:\n                        newstart = i\n                        newlastnum = smaller\n                    lastnum = bigger\n                else:\n                    # reach the end for this round\n                    l = i - start\n                    if l > maxlen:\n                        maxlen = l\n                    if newstart is not None:\n                        i = newstart\n                        lastnum = newlastnum\n                        newstart = None\n                        newlastnum = None\n                    else:\n                        lastnum = smaller\n                    start = i\n            i = i+1\n        l = i - start\n        if l > maxlen:\n            maxlen = l\n        return maxlen\n```
['Python3']