DP - O(N*min) time, O(min) additional space.
Intuition\n Describe your first thoughts on how to solve this problem. \nConsider dp[i][j] = # of valid sequences of length i where the increasing sequence ends
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nConsider dp[i][j] = # of valid sequences of length i where the increasing sequence ends with value j.\n\nPrint out each row of the table with various test cases, e.g.\n[1,2,4,8]. Whenever nums increases, the next row of dp has 0s added at the front. Note that the next row will not have additional nonzero elements.\n\nTry the test case [8,7,6,5,4]. Each time nums decreases dp[i] is a prefix of dp[i-1]. Note that the row will not have more than nums[i] non-zero elements.\n\nThe nonzero elements in each of the dp rows either stays the same or decreases, reaching a minimum size at an index j where nums[j] = min(nums).\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: $$O(n * min(nums))$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O( min(nums))$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n\n# Code\n```\nclass Solution:\n    def countOfPairs(self, nums: List[int]) -> int:\n        prefix_zeros = 0\n        for i in range(1, len(nums)):\n            prefix_zeros += max(nums[i]-nums[i-1],0)\n        \n        row = len(nums)+1\n        col = (nums[-1])+1 - prefix_zeros\n        if col <= 0:\n            return 0\n        \n        dp = [ 1 ] * (col)\n        for r in range(1,row):\n            for c in range(1,col):\n                dp[c] += dp[c-1]\n                dp[c] %= 10**9+7\n\n        return dp[-1]\n```
['Python3']