Algorithms
Hard
2972
3248
Count the Number of Incremovable Subarrays II
count-the-number-of-incremovable-subarrays-ii
"""
You are given a 0-indexed array of positive integers nums.
A subarray of nums is called incremovable if nums becomes strictly increasing on removing the subarray. For example, the subarray [3, 4] is an incremovable subarray of [5, 3, 4, 6, 7] because removing this subarray changes the array [5, 3, 4, 6, 7] to [5, 6, 7] which is strictly increasing.
Return the total number of incremovable subarrays of nums.
Note that an empty array is considered strictly increasing.
A subarray is a contiguous non-empty sequence of elements within an array.

Example 1:

Input: nums = [1,2,3,4]
Output: 10
Explanation: The 10 incremovable subarrays are: [1], [2], [3], [4], [1,2], [2,3], [3,4], [1,2,3], [2,3,4], and [1,2,3,4], because on removing any one of these subarrays nums becomes strictly increasing. Note that you cannot select an empty subarray.

Example 2:

Input: nums = [6,5,7,8]
Output: 7
Explanation: The 7 incremovable subarrays are: [5], [6], [5,7], [6,5], [5,7,8], [6,5,7] and [6,5,7,8].
It can be shown that there are only 7 incremovable subarrays in nums.

Example 3:

Input: nums = [8,7,6,6]
Output: 3
Explanation: The 3 incremovable subarrays are: [8,7,6], [7,6,6], and [8,7,6,6]. Note that [8,7] is not an incremovable subarray because after removing [8,7] nums becomes [6,6], which is sorted in ascending order but not strictly increasing.


Constraints:

1 <= nums.length <= 105
1 <= nums[i] <= 109
"""
class Solution:
    def incremovableSubarrayCount(self, nums: List[int]) -> int:
        
You are given a 0-indexed array of positive integers nums.
A subarray of nums is called incremovable if nums becomes strictly increasing on removing the subarray. For example, the subarray [3, 4] is an incremovable subarray of [5, 3, 4, 6, 7] because removing this subarray changes the array [5, 3, 4, 6, 7] to [5, 6, 7] which is strictly increasing.
Return the total number of incremovable subarrays of nums.
Note that an empty array is considered strictly increasing.
A subarray is a contiguous non-empty sequence of elements within an array.

Example 1:

Input: nums = [1,2,3,4]
Output: 10
Explanation: The 10 incremovable subarrays are: [1], [2], [3], [4], [1,2], [2,3], [3,4], [1,2,3], [2,3,4], and [1,2,3,4], because on removing any one of these subarrays nums becomes strictly increasing. Note that you cannot select an empty subarray.

Example 2:

Input: nums = [6,5,7,8]
Output: 7
Explanation: The 7 incremovable subarrays are: [5], [6], [5,7], [6,5], [5,7,8], [6,5,7] and [6,5,7,8].
It can be shown that there are only 7 incremovable subarrays in nums.

Example 3:

Input: nums = [8,7,6,6]
Output: 3
Explanation: The 3 incremovable subarrays are: [8,7,6], [7,6,6], and [8,7,6,6]. Note that [8,7] is not an incremovable subarray because after removing [8,7] nums becomes [6,6], which is sorted in ascending order but not strictly increasing.


Constraints:

1 <= nums.length <= 105
1 <= nums[i] <= 109


Please complete the code below to solve above prblem:
```python
class Solution:
    def incremovableSubarrayCount(self, nums: List[int]) -> int:
        
```

my_solution = Solution()

test_input = { "nums": [1,2,3,4] }
assert my_solution.incremovableSubarrayCount(**test_input) == 10

test_input = { "nums": [6,5,7,8] }
assert my_solution.incremovableSubarrayCount(**test_input) == 7

test_input = { "nums": [8,7,6,6] }
assert my_solution.incremovableSubarrayCount(**test_input) == 3

test_input = { "nums": [1] }
assert my_solution.incremovableSubarrayCount(**test_input) == 1

test_input = { "nums": [2] }
assert my_solution.incremovableSubarrayCount(**test_input) == 1

test_input = { "nums": [3] }
assert my_solution.incremovableSubarrayCount(**test_input) == 1

test_input = { "nums": [4] }
assert my_solution.incremovableSubarrayCount(**test_input) == 1

test_input = { "nums": [5] }
assert my_solution.incremovableSubarrayCount(**test_input) == 1

test_input = { "nums": [6] }
assert my_solution.incremovableSubarrayCount(**test_input) == 1

test_input = { "nums": [7] }
assert my_solution.incremovableSubarrayCount(**test_input) == 1

test_input = { "nums": [8] }
assert my_solution.incremovableSubarrayCount(**test_input) == 1

test_input = { "nums": [9] }
assert my_solution.incremovableSubarrayCount(**test_input) == 1

test_input = { "nums": [10] }
assert my_solution.incremovableSubarrayCount(**test_input) == 1

test_input = { "nums": [4,10] }
assert my_solution.incremovableSubarrayCount(**test_input) == 3

test_input = { "nums": [7,3] }
assert my_solution.incremovableSubarrayCount(**test_input) == 3

test_input = { "nums": [8,5] }
assert my_solution.incremovableSubarrayCount(**test_input) == 3

test_input = { "nums": [8,10] }
assert my_solution.incremovableSubarrayCount(**test_input) == 3

test_input = { "nums": [9,9] }
assert my_solution.incremovableSubarrayCount(**test_input) == 3

test_input = { "nums": [5,5,6] }
assert my_solution.incremovableSubarrayCount(**test_input) == 5

test_input = { "nums": [6,7,5] }
assert my_solution.incremovableSubarrayCount(**test_input) == 4

test_input = { "nums": [8,1,2] }
assert my_solution.incremovableSubarrayCount(**test_input) == 4

test_input = { "nums": [9,2,8] }
assert my_solution.incremovableSubarrayCount(**test_input) == 4

test_input = { "nums": [9,3,8] }
assert my_solution.incremovableSubarrayCount(**test_input) == 4

test_input = { "nums": [1,2,10,6] }
assert my_solution.incremovableSubarrayCount(**test_input) == 7

test_input = { "nums": [1,9,6,9] }
assert my_solution.incremovableSubarrayCount(**test_input) == 7

test_input = { "nums": [4,8,5,9] }
assert my_solution.incremovableSubarrayCount(**test_input) == 8

test_input = { "nums": [6,2,6,4] }
assert my_solution.incremovableSubarrayCount(**test_input) == 3

test_input = { "nums": [10,2,5,7] }
assert my_solution.incremovableSubarrayCount(**test_input) == 5

test_input = { "nums": [1,2,4,7,10] }
assert my_solution.incremovableSubarrayCount(**test_input) == 15

test_input = { "nums": [1,5,9,5,7] }
assert my_solution.incremovableSubarrayCount(**test_input) == 9

test_input = { "nums": [6,6,5,3,5] }
assert my_solution.incremovableSubarrayCount(**test_input) == 4

test_input = { "nums": [8,5,5,3,10] }
assert my_solution.incremovableSubarrayCount(**test_input) == 5

test_input = { "nums": [9,10,1,8,2] }
assert my_solution.incremovableSubarrayCount(**test_input) == 4

test_input = { "nums": [11,50,14,33,45,38,33,19,28,34] }
assert my_solution.incremovableSubarrayCount(**test_input) == 9

test_input = { "nums": [25,9,28,31,38,15,31,44,46,49] }
assert my_solution.incremovableSubarrayCount(**test_input) == 11

test_input = { "nums": [25,26,49,31,40,47,30,29,32,34] }
assert my_solution.incremovableSubarrayCount(**test_input) == 13

test_input = { "nums": [25,39,29,30,40,28,30,39,30,42] }
assert my_solution.incremovableSubarrayCount(**test_input) == 8

test_input = { "nums": [25,41,31,38,30,38,37,41,36,32] }
assert my_solution.incremovableSubarrayCount(**test_input) == 5

test_input = { "nums": [25,45,49,28,47,44,42,34,28,25] }
assert my_solution.incremovableSubarrayCount(**test_input) == 5

test_input = { "nums": [25,46,48,41,29,47,32,34,41,34] }
assert my_solution.incremovableSubarrayCount(**test_input) == 6

test_input = { "nums": [25,47,25,35,48,49,27,37,36,43] }
assert my_solution.incremovableSubarrayCount(**test_input) == 7

test_input = { "nums": [26,26,50,38,30,38,31,26,39,45] }
assert my_solution.incremovableSubarrayCount(**test_input) == 7

test_input = { "nums": [26,32,41,38,45,32,31,27,48,41] }
assert my_solution.incremovableSubarrayCount(**test_input) == 7

test_input = { "nums": [26,45,44,26,33,35,34,36,44,38] }
assert my_solution.incremovableSubarrayCount(**test_input) == 5

test_input = { "nums": [26,49,42,26,37,41,31,36,45,41] }
assert my_solution.incremovableSubarrayCount(**test_input) == 5

test_input = { "nums": [27,39,32,30,38,41,28,26,49,49] }
assert my_solution.incremovableSubarrayCount(**test_input) == 6

test_input = { "nums": [27,43,36,37,33,46,48,35,49,49] }
assert my_solution.incremovableSubarrayCount(**test_input) == 6

test_input = { "nums": [28,17,12,21,21,49,31,30,40,13] }
assert my_solution.incremovableSubarrayCount(**test_input) == 3

test_input = { "nums": [28,30,39,31,33,41,47,36,43,46] }
assert my_solution.incremovableSubarrayCount(**test_input) == 15

test_input = { "nums": [29,27,32,38,26,38,39,30,41,45] }
assert my_solution.incremovableSubarrayCount(**test_input) == 8

test_input = { "nums": [29,31,48,28,27,38,32,28,30,44] }
assert my_solution.incremovableSubarrayCount(**test_input) == 10

test_input = { "nums": [29,34,44,27,45,31,37,32,50,26] }
assert my_solution.incremovableSubarrayCount(**test_input) == 5

test_input = { "nums": [29,38,36,42,31,38,27,48,42,28] }
assert my_solution.incremovableSubarrayCount(**test_input) == 4

test_input = { "nums": [29,46,34,47,46,41,29,29,38,39] }
assert my_solution.incremovableSubarrayCount(**test_input) == 8

test_input = { "nums": [29,49,32,35,38,37,27,25,50,46] }
assert my_solution.incremovableSubarrayCount(**test_input) == 5

test_input = { "nums": [30,27,38,33,28,48,41,30,25,50] }
assert my_solution.incremovableSubarrayCount(**test_input) == 5

test_input = { "nums": [30,29,31,44,31,25,50,35,35,47] }
assert my_solution.incremovableSubarrayCount(**test_input) == 6

test_input = { "nums": [30,30,46,35,31,41,30,37,37,33] }
assert my_solution.incremovableSubarrayCount(**test_input) == 4

test_input = { "nums": [30,41,28,45,35,41,47,32,29,33] }
assert my_solution.incremovableSubarrayCount(**test_input) == 6

test_input = { "nums": [30,45,44,27,43,40,28,34,39,40] }
assert my_solution.incremovableSubarrayCount(**test_input) == 10

test_input = { "nums": [30,49,34,26,50,50,48,49,39,26] }
assert my_solution.incremovableSubarrayCount(**test_input) == 4

test_input = { "nums": [31,34,25,43,38,34,29,50,27,34] }
assert my_solution.incremovableSubarrayCount(**test_input) == 6

test_input = { "nums": [31,35,39,38,41,47,26,43,47,46] }
assert my_solution.incremovableSubarrayCount(**test_input) == 8

test_input = { "nums": [31,37,29,41,32,46,25,28,30,29] }
assert my_solution.incremovableSubarrayCount(**test_input) == 4

test_input = { "nums": [31,38,31,47,25,25,36,29,43,28] }
assert my_solution.incremovableSubarrayCount(**test_input) == 4

test_input = { "nums": [31,41,25,37,43,29,30,26,30,46] }
assert my_solution.incremovableSubarrayCount(**test_input) == 8

test_input = { "nums": [31,42,40,36,39,28,43,29,35,50] }
assert my_solution.incremovableSubarrayCount(**test_input) == 9

test_input = { "nums": [32,29,13,39,34,47,38,15,10,5] }
assert my_solution.incremovableSubarrayCount(**test_input) == 3

test_input = { "nums": [32,35,32,50,32,26,29,49,40,41] }
assert my_solution.incremovableSubarrayCount(**test_input) == 9

test_input = { "nums": [32,37,35,26,45,44,47,29,31,28] }
assert my_solution.incremovableSubarrayCount(**test_input) == 4

test_input = { "nums": [32,43,44,44,36,41,31,33,41,43] }
assert my_solution.incremovableSubarrayCount(**test_input) == 11

test_input = { "nums": [32,50,50,46,32,30,32,32,31,39] }
assert my_solution.incremovableSubarrayCount(**test_input) == 6

test_input = { "nums": [33,27,34,46,42,35,36,49,25,40] }
assert my_solution.incremovableSubarrayCount(**test_input) == 5

test_input = { "nums": [33,28,35,32,36,38,33,47,36,35] }
assert my_solution.incremovableSubarrayCount(**test_input) == 4

test_input = { "nums": [33,31,36,38,39,46,42,41,27,33] }
assert my_solution.incremovableSubarrayCount(**test_input) == 4

test_input = { "nums": [33,45,25,48,45,42,35,38,47,43] }
assert my_solution.incremovableSubarrayCount(**test_input) == 5

test_input = { "nums": [33,46,38,37,42,48,31,43,38,29] }
assert my_solution.incremovableSubarrayCount(**test_input) == 4

test_input = { "nums": [33,48,50,48,46,33,34,26,32,33] }
assert my_solution.incremovableSubarrayCount(**test_input) == 7

test_input = { "nums": [34,25,38,41,31,46,40,46,39,30] }
assert my_solution.incremovableSubarrayCount(**test_input) == 3

test_input = { "nums": [34,38,35,28,30,37,35,25,48,28] }
assert my_solution.incremovableSubarrayCount(**test_input) == 4

test_input = { "nums": [34,47,26,48,30,25,26,43,44,41] }
assert my_solution.incremovableSubarrayCount(**test_input) == 5

test_input = { "nums": [35,22,35,6,20,47,3,29,45,30] }
assert my_solution.incremovableSubarrayCount(**test_input) == 3

test_input = { "nums": [35,25,29,40,32,29,35,39,39,32] }
assert my_solution.incremovableSubarrayCount(**test_input) == 3

test_input = { "nums": [35,26,39,41,26,44,36,26,46,50] }
assert my_solution.incremovableSubarrayCount(**test_input) == 7

test_input = { "nums": [35,27,29,45,29,30,48,42,37,50] }
assert my_solution.incremovableSubarrayCount(**test_input) == 6

test_input = { "nums": [35,31,27,45,39,46,47,49,26,27] }
assert my_solution.incremovableSubarrayCount(**test_input) == 4

test_input = { "nums": [35,39,36,30,32,48,34,25,37,45] }
assert my_solution.incremovableSubarrayCount(**test_input) == 9

test_input = { "nums": [36,26,44,32,36,29,44,28,48,30] }
assert my_solution.incremovableSubarrayCount(**test_input) == 3

test_input = { "nums": [36,28,28,45,40,40,32,48,34,48] }
assert my_solution.incremovableSubarrayCount(**test_input) == 5

test_input = { "nums": [36,28,34,49,48,36,50,25,43,40] }
assert my_solution.incremovableSubarrayCount(**test_input) == 4

test_input = { "nums": [36,30,47,32,32,35,41,49,41,45] }
assert my_solution.incremovableSubarrayCount(**test_input) == 6

test_input = { "nums": [36,31,45,34,47,48,49,31,34,34] }
assert my_solution.incremovableSubarrayCount(**test_input) == 3

test_input = { "nums": [37,33,50,48,25,37,29,49,46,45] }
assert my_solution.incremovableSubarrayCount(**test_input) == 4

test_input = { "nums": [37,35,29,27,39,38,49,48,27,37] }
assert my_solution.incremovableSubarrayCount(**test_input) == 4

test_input = { "nums": [37,40,42,41,30,40,46,44,47,27] }
assert my_solution.incremovableSubarrayCount(**test_input) == 5

test_input = { "nums": [37,43,49,40,30,46,31,44,47,25] }
assert my_solution.incremovableSubarrayCount(**test_input) == 5

test_input = { "nums": [37,45,49,26,32,45,33,40,35,43] }
assert my_solution.incremovableSubarrayCount(**test_input) == 7

test_input = { "nums": [37,50,42,50,40,26,34,25,28,44] }
assert my_solution.incremovableSubarrayCount(**test_input) == 7

test_input = { "nums": [38,28,25,31,28,44,35,26,33,41] }
assert my_solution.incremovableSubarrayCount(**test_input) == 6

test_input = { "nums": [38,30,36,50,36,40,41,25,43,43] }
assert my_solution.incremovableSubarrayCount(**test_input) == 4