Python3 DP | Explained solution
Intuition\nThe problem seems have a solution using dp since we need to have a maximum count of the longest sub having more ways of choosing from where to start 
# Intuition\nThe problem seems have a solution using dp since we need to have a maximum count of the longest sub having more ways of choosing from where to start and with which value.\n\n# Approach\nWe have 2 numbers at each index from where we can pick. First number will be the minimum and the second the maximum. We maintain 2 previous distances and 2 current distances, each one for the min val and the max. The start value for each current distance is 1 since we can return 1 distance array of one index. We update the current distance based on the condition that current max is >= previous max/min and the same for current min.\nA good example is this one:\n\n    nums1 = [11, 7, 7, 9]\n    nums2 = [19, 19, 1, 7]\n    DP = [[1, 1], [1, 1], [1, 1], [1, 1]]\n    Where DP[i][0] = for min val and DP[i][1] for max val.\n    DP will become:\n\n    [1,1]   [1,2]   [1,2]    [3, 3]\n    11      7       1        7\n    19      19      7        9\nAt index 1 if we pick 7, it is lower than both previous min and max so the value of distance is 1. If we pick 19 it is bigger than both prev min and mix so we update it to 2. The same process happens for every index.\n\nIf you like it, please upvote!\n\n# Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\nO(1)\n\n# Code\n```\nclass Solution:\n    def maxNonDecreasingLength(self, nums1: List[int], nums2: List[int]) -> int:\n        curr_min, curr_max = 0, 0  \n        prev_min, prev_max = 0, 0  \n        prev_min_d, prev_max_d = 0, 0  # previous distance based on the minimum number and maximum number \n        res = 0\n\n        for i in range(len(nums1)):\n            curr_min_d, curr_max_d = 1, 1  # current distance based on the minimum number and maximum number       \n\n            curr_min = min(nums1[i], nums2[i])\n            curr_max = max(nums1[i], nums2[i])\n\n            if curr_min >= prev_min:\n                curr_min_d = max(curr_min_d, prev_min_d+1)\n            if curr_min >= prev_max:\n                curr_min_d = max(curr_min_d, prev_max_d+1)\n\n            if curr_max >= prev_min:\n                curr_max_d = max(curr_max_d, prev_min_d+1)\n            if curr_max >= prev_max:\n                curr_max_d = max(curr_max_d, prev_max_d+1)\n\n            prev_min, prev_max = curr_min, curr_max\n            prev_min_d, prev_max_d = curr_min_d, curr_max_d\n\n            res = max(res, curr_min_d, curr_max_d)\n        return res\n```
['Dynamic Programming', 'Python3']