Algorithms
Medium
2762
2868
Continuous Subarrays
continuous-subarrays
"""
You are given a 0-indexed integer array nums. A subarray of nums is called continuous if:

 * Let i, i + 1, ..., j be the indices in the subarray. Then, for each pair of indices i <= i1, i2 <= j, 0 <= |nums[i1] - nums[i2]| <= 2.

Return the total number of continuous subarrays.

A subarray is a contiguous non-empty sequence of elements within an array.

Example 1:

Input: nums = [5,4,2,4]
Output: 8
Explanation:
Continuous subarray of size 1: [5], [4], [2], [4].
Continuous subarray of size 2: [5,4], [4,2], [2,4].
Continuous subarray of size 3: [4,2,4].
Thereare no subarrys of size 4.
Total continuous subarrays = 4 + 3 + 1 = 8.
It can be shown that there are no more continuous subarrays.


Example 2:

Input: nums = [1,2,3]
Output: 6
Explanation:
Continuous subarray of size 1: [1], [2], [3].
Continuous subarray of size 2: [1,2], [2,3].
Continuous subarray of size 3: [1,2,3].
Total continuous subarrays = 3 + 2 + 1 = 6.


Constraints:

 * 1 <= nums.length <= 105
 * 1 <= nums[i] <= 109
"""
class Solution:
    def continuousSubarrays(self, nums: List[int]) -> int:
        
You are given a 0-indexed integer array nums. A subarray of nums is called continuous if:

 * Let i, i + 1, ..., j be the indices in the subarray. Then, for each pair of indices i <= i1, i2 <= j, 0 <= |nums[i1] - nums[i2]| <= 2.

Return the total number of continuous subarrays.

A subarray is a contiguous non-empty sequence of elements within an array.

Example 1:

Input: nums = [5,4,2,4]
Output: 8
Explanation:
Continuous subarray of size 1: [5], [4], [2], [4].
Continuous subarray of size 2: [5,4], [4,2], [2,4].
Continuous subarray of size 3: [4,2,4].
Thereare no subarrys of size 4.
Total continuous subarrays = 4 + 3 + 1 = 8.
It can be shown that there are no more continuous subarrays.


Example 2:

Input: nums = [1,2,3]
Output: 6
Explanation:
Continuous subarray of size 1: [1], [2], [3].
Continuous subarray of size 2: [1,2], [2,3].
Continuous subarray of size 3: [1,2,3].
Total continuous subarrays = 3 + 2 + 1 = 6.


Constraints:

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


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

my_solution = Solution()

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

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

test_input = { "nums": [31,30,31,32] }
assert my_solution.continuousSubarrays(**test_input) == 10

test_input = { "nums": [65,66,67,66,66,65,64,65,65,64] }
assert my_solution.continuousSubarrays(**test_input) == 43

test_input = { "nums": [42,41,42,41,41,40,39,38] }
assert my_solution.continuousSubarrays(**test_input) == 28

test_input = { "nums": [35,35,36,37,36,37,38,37,38] }
assert my_solution.continuousSubarrays(**test_input) == 39

test_input = { "nums": [43,44,43,44] }
assert my_solution.continuousSubarrays(**test_input) == 10

test_input = { "nums": [14,15,15,15,16,16,16,16,15,16] }
assert my_solution.continuousSubarrays(**test_input) == 55

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

test_input = { "nums": [34,34,33,34,33,33,32,31,30,31] }
assert my_solution.continuousSubarrays(**test_input) == 39

test_input = { "nums": [58,59,59,58,59] }
assert my_solution.continuousSubarrays(**test_input) == 15

test_input = { "nums": [10,9,8,7,8,9,9] }
assert my_solution.continuousSubarrays(**test_input) == 24

test_input = { "nums": [65,66,65,64,63,62,62] }
assert my_solution.continuousSubarrays(**test_input) == 20

test_input = { "nums": [65,65,64,65,66,65] }
assert my_solution.continuousSubarrays(**test_input) == 21

test_input = { "nums": [85,84,83,84,83,82] }
assert my_solution.continuousSubarrays(**test_input) == 20

test_input = { "nums": [60,59,60] }
assert my_solution.continuousSubarrays(**test_input) == 6

test_input = { "nums": [96,97,98] }
assert my_solution.continuousSubarrays(**test_input) == 6

test_input = { "nums": [21,22,23,22,23] }
assert my_solution.continuousSubarrays(**test_input) == 15

test_input = { "nums": [76,77,77,78,77,78,78] }
assert my_solution.continuousSubarrays(**test_input) == 28

test_input = { "nums": [27,27,27,26,26,27,27,27,27] }
assert my_solution.continuousSubarrays(**test_input) == 45

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

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

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

test_input = { "nums": [10,10,9,8,9,9,9,8,8] }
assert my_solution.continuousSubarrays(**test_input) == 45

test_input = { "nums": [21,22,22,23,24,24,23,24,23,24] }
assert my_solution.continuousSubarrays(**test_input) == 49

test_input = { "nums": [94,94,94,94,94,93,94] }
assert my_solution.continuousSubarrays(**test_input) == 28

test_input = { "nums": [66,65,64,64,64,65,64,63] }
assert my_solution.continuousSubarrays(**test_input) == 35

test_input = { "nums": [35,35,36,36,35] }
assert my_solution.continuousSubarrays(**test_input) == 15

test_input = { "nums": [35,34,33,34,35,35,34,35,34] }
assert my_solution.continuousSubarrays(**test_input) == 45

test_input = { "nums": [70,69,70,71,70,70,71,71] }
assert my_solution.continuousSubarrays(**test_input) == 36

test_input = { "nums": [49,49,49,50,50,49,50,51,51] }
assert my_solution.continuousSubarrays(**test_input) == 45

test_input = { "nums": [70,71,72,72,72] }
assert my_solution.continuousSubarrays(**test_input) == 15

test_input = { "nums": [73,73,74,75,76,76,75,76] }
assert my_solution.continuousSubarrays(**test_input) == 28

test_input = { "nums": [74,74,74,75,76,75,75,76,77,77] }
assert my_solution.continuousSubarrays(**test_input) == 49

test_input = { "nums": [21,21,20,19,20,20,21,21] }
assert my_solution.continuousSubarrays(**test_input) == 36

test_input = { "nums": [86,85] }
assert my_solution.continuousSubarrays(**test_input) == 3

test_input = { "nums": [94,95,96,96,97,98,99,100,100] }
assert my_solution.continuousSubarrays(**test_input) == 28

test_input = { "nums": [16,17,16] }
assert my_solution.continuousSubarrays(**test_input) == 6

test_input = { "nums": [25,26,26,27,28,27,28,28,27,27] }
assert my_solution.continuousSubarrays(**test_input) == 49

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

test_input = { "nums": [94,95,96,95,94,93,92,91] }
assert my_solution.continuousSubarrays(**test_input) == 24

test_input = { "nums": [84,84,83] }
assert my_solution.continuousSubarrays(**test_input) == 6

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

test_input = { "nums": [53,54,54,55] }
assert my_solution.continuousSubarrays(**test_input) == 10

test_input = { "nums": [67,67,66,67,68,69,70,71,71] }
assert my_solution.continuousSubarrays(**test_input) == 28

test_input = { "nums": [43,42,42,42,43] }
assert my_solution.continuousSubarrays(**test_input) == 15

test_input = { "nums": [93,94,93] }
assert my_solution.continuousSubarrays(**test_input) == 6

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

test_input = { "nums": [54,54,53,54,55,56,57,58,59] }
assert my_solution.continuousSubarrays(**test_input) == 27

test_input = { "nums": [52,51,50,49,48,49,48,47,46] }
assert my_solution.continuousSubarrays(**test_input) == 29

test_input = { "nums": [93,92,91,92,92,92,92] }
assert my_solution.continuousSubarrays(**test_input) == 28

test_input = { "nums": [91,91,90,90,90,91,91,90] }
assert my_solution.continuousSubarrays(**test_input) == 36

test_input = { "nums": [37,37,37,36] }
assert my_solution.continuousSubarrays(**test_input) == 10

test_input = { "nums": [40,39,39,39,39,40,40,41,40,39] }
assert my_solution.continuousSubarrays(**test_input) == 55

test_input = { "nums": [82,83,83,83,83,84] }
assert my_solution.continuousSubarrays(**test_input) == 21

test_input = { "nums": [35,36,36,37,37,37,36,37,36] }
assert my_solution.continuousSubarrays(**test_input) == 45

test_input = { "nums": [50,49,50,51,50] }
assert my_solution.continuousSubarrays(**test_input) == 15

test_input = { "nums": [86,86,86,86,87] }
assert my_solution.continuousSubarrays(**test_input) == 15

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

test_input = { "nums": [96,95,94,93] }
assert my_solution.continuousSubarrays(**test_input) == 9

test_input = { "nums": [56,56,55,55,54,55,54,54,53,52] }
assert my_solution.continuousSubarrays(**test_input) == 47

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

test_input = { "nums": [91,90,91,91] }
assert my_solution.continuousSubarrays(**test_input) == 10

test_input = { "nums": [56,55,55,55] }
assert my_solution.continuousSubarrays(**test_input) == 10

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

test_input = { "nums": [84,85,84,84,85,85,85] }
assert my_solution.continuousSubarrays(**test_input) == 28

test_input = { "nums": [71,71,71,71] }
assert my_solution.continuousSubarrays(**test_input) == 10

test_input = { "nums": [47,47,46] }
assert my_solution.continuousSubarrays(**test_input) == 6

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

test_input = { "nums": [20,20,19,18] }
assert my_solution.continuousSubarrays(**test_input) == 10

test_input = { "nums": [22,23,23,22,22,22,22] }
assert my_solution.continuousSubarrays(**test_input) == 28

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

test_input = { "nums": [93,92,92,91,90,90,89,88] }
assert my_solution.continuousSubarrays(**test_input) == 27

test_input = { "nums": [13,13,12,11] }
assert my_solution.continuousSubarrays(**test_input) == 10

test_input = { "nums": [22,22,22,21,22,21] }
assert my_solution.continuousSubarrays(**test_input) == 21

test_input = { "nums": [24,25,26,26,25,26,25,25,26] }
assert my_solution.continuousSubarrays(**test_input) == 45

test_input = { "nums": [37,36] }
assert my_solution.continuousSubarrays(**test_input) == 3

test_input = { "nums": [52,51] }
assert my_solution.continuousSubarrays(**test_input) == 3

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

test_input = { "nums": [88,88,88,87,87,87,87,88,88] }
assert my_solution.continuousSubarrays(**test_input) == 45

test_input = { "nums": [84,83,83,84,83,82,81] }
assert my_solution.continuousSubarrays(**test_input) == 24

test_input = { "nums": [87,88,88,87,87,88,88,89] }
assert my_solution.continuousSubarrays(**test_input) == 36

test_input = { "nums": [28,28,27] }
assert my_solution.continuousSubarrays(**test_input) == 6

test_input = { "nums": [82,83,83,82] }
assert my_solution.continuousSubarrays(**test_input) == 10

test_input = { "nums": [97,96,96,95,96,95] }
assert my_solution.continuousSubarrays(**test_input) == 21

test_input = { "nums": [72,73,73,74,73,73] }
assert my_solution.continuousSubarrays(**test_input) == 21

test_input = { "nums": [21,21,20] }
assert my_solution.continuousSubarrays(**test_input) == 6

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

test_input = { "nums": [24,24,24,23,22,22,22,23] }
assert my_solution.continuousSubarrays(**test_input) == 36

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

test_input = { "nums": [11,10,9,10,11] }
assert my_solution.continuousSubarrays(**test_input) == 15

test_input = { "nums": [34,34,35,34,35,36,36] }
assert my_solution.continuousSubarrays(**test_input) == 28

test_input = { "nums": [73,74,75,75] }
assert my_solution.continuousSubarrays(**test_input) == 10

test_input = { "nums": [24,23,24,24] }
assert my_solution.continuousSubarrays(**test_input) == 10

test_input = { "nums": [21,22,22,23,22,23,22,23,23,22] }
assert my_solution.continuousSubarrays(**test_input) == 55

test_input = { "nums": [53,53,54,54,54] }
assert my_solution.continuousSubarrays(**test_input) == 15

test_input = { "nums": [94,95,96,96,97,97,98,99] }
assert my_solution.continuousSubarrays(**test_input) == 28

test_input = { "nums": [89,89,89,88,87,87] }
assert my_solution.continuousSubarrays(**test_input) == 21

test_input = { "nums": [89,90] }
assert my_solution.continuousSubarrays(**test_input) == 3

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