# Maximum Number of Jumps to Reach the Last Index

You are given a **0-indexed** array `nums` of `n` integers and an integer `target`.

You are initially positioned at index `0`. In one step, you can jump from index `i` to any index `j` such that:

* `0 <= i < j < n`
* `-target <= nums[j] - nums[i] <= target`

Return *the **maximum number of jumps** you can make to reach index* `n - 1`.

If there is no way to reach index `n - 1`, return `-1`.

**Example 1:**

```

**Input:** nums = [1,3,6,4,1,2], target = 2
**Output:** 3
**Explanation:** To go from index 0 to index n - 1 with the maximum number of jumps, you can perform the following jumping sequence:
- Jump from index 0 to index 1.
- Jump from index 1 to index 3.
- Jump from index 3 to index 5.
It can be proven that there is no other jumping sequence that goes from 0 to n - 1 with more than 3 jumps. Hence, the answer is 3.
```

**Example 2:**

```

**Input:** nums = [1,3,6,4,1,2], target = 3
**Output:** 5
**Explanation:** To go from index 0 to index n - 1 with the maximum number of jumps, you can perform the following jumping sequence:
- Jump from index 0 to index 1.
- Jump from index 1 to index 2.
- Jump from index 2 to index 3.
- Jump from index 3 to index 4.
- Jump from index 4 to index 5.
It can be proven that there is no other jumping sequence that goes from 0 to n - 1 with more than 5 jumps. Hence, the answer is 5.
```

**Example 3:**

```

**Input:** nums = [1,3,6,4,1,2], target = 0
**Output:** -1
**Explanation:** It can be proven that there is no jumping sequence that goes from 0 to n - 1. Hence, the answer is -1.

```

**Constraints:**

* `2 <= nums.length == n <= 1000`
* `-109 <= nums[i] <= 109`
* `0 <= target <= 2 * 109`

Please make sure your answer follows the type signature below:

```python3
class Solution:
    def maximumJumps(self, nums: List[int], target: int) -> int:
```

my_solution = Solution()

assert my_solution.maximumJumps(**[[1, 3, 6, 4, 1, 2], 2]) == 3
assert my_solution.maximumJumps(**[[1, 3, 6, 4, 1, 2], 3]) == 5
assert my_solution.maximumJumps(**[[1, 3, 6, 4, 1, 2], 0]) == -1
assert my_solution.maximumJumps(**[[0, 1], 0]) == -1
assert my_solution.maximumJumps(**[[0, 1], 1]) == 1
assert my_solution.maximumJumps(**[[0, 1], 2]) == 1
assert my_solution.maximumJumps(**[[1, 0], 0]) == -1
assert my_solution.maximumJumps(**[[1, 0], 1]) == 1
assert my_solution.maximumJumps(**[[1, 0], 2]) == 1
assert my_solution.maximumJumps(**[[0, 1, 2], 0]) == -1
assert my_solution.maximumJumps(**[[0, 1, 2], 1]) == 2
assert my_solution.maximumJumps(**[[0, 1, 2], 2]) == 2
assert my_solution.maximumJumps(**[[0, 1, 2], 3]) == 2
assert my_solution.maximumJumps(**[[0, 2, 1], 0]) == -1
assert my_solution.maximumJumps(**[[0, 2, 1], 1]) == 1
assert my_solution.maximumJumps(**[[0, 2, 1], 2]) == 2
assert my_solution.maximumJumps(**[[0, 2, 1], 3]) == 2
assert my_solution.maximumJumps(**[[1, 0, 2], 0]) == -1
assert my_solution.maximumJumps(**[[1, 0, 2], 1]) == 1
assert my_solution.maximumJumps(**[[1, 0, 2], 2]) == 2


# Longest Non-decreasing Subarray From Two Arrays

You are given two **0-indexed** integer arrays `nums1` and `nums2` of length `n`.

Let's define another **0-indexed** integer array, `nums3`, of length `n`. For each index `i` in the range `[0, n - 1]`, you can assign either `nums1[i]` or `nums2[i]` to `nums3[i]`.

Your task is to maximize the length of the **longest non-decreasing subarray** in `nums3` by choosing its values optimally.

Return *an integer representing the length of the **longest non-decreasing** subarray in* `nums3`.

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

**Example 1:**

```

**Input:** nums1 = [2,3,1], nums2 = [1,2,1]
**Output:** 2
**Explanation:** One way to construct nums3 is:
nums3 = [nums1[0], nums2[1], nums2[2]] => [2,2,1].
The subarray starting from index 0 and ending at index 1, [2,2], forms a non-decreasing subarray of length 2.
We can show that 2 is the maximum achievable length.
```

**Example 2:**

```

**Input:** nums1 = [1,3,2,1], nums2 = [2,2,3,4]
**Output:** 4
**Explanation:** One way to construct nums3 is:
nums3 = [nums1[0], nums2[1], nums2[2], nums2[3]] => [1,2,3,4].
The entire array forms a non-decreasing subarray of length 4, making it the maximum achievable length.

```

**Example 3:**

```

**Input:** nums1 = [1,1], nums2 = [2,2]
**Output:** 2
**Explanation:** One way to construct nums3 is:
nums3 = [nums1[0], nums1[1]] => [1,1].
The entire array forms a non-decreasing subarray of length 2, making it the maximum achievable length.

```

**Constraints:**

* `1 <= nums1.length == nums2.length == n <= 105`
* `1 <= nums1[i], nums2[i] <= 109`

Please make sure your answer follows the type signature below:

```python3
class Solution:
    def maxNonDecreasingLength(self, nums1: List[int], nums2: List[int]) -> int:
```

my_solution = Solution()

assert my_solution.maxNonDecreasingLength(**[[2, 3, 1], [1, 2, 1]]) == 2
assert my_solution.maxNonDecreasingLength(**[[1, 3, 2, 1], [2, 2, 3, 4]]) == 4
assert my_solution.maxNonDecreasingLength(**[[1, 1], [2, 2]]) == 2
assert my_solution.maxNonDecreasingLength(**[[1], [1]]) == 1
assert my_solution.maxNonDecreasingLength(**[[1], [2]]) == 1
assert my_solution.maxNonDecreasingLength(**[[1, 4], [4, 19]]) == 2
assert my_solution.maxNonDecreasingLength(**[[1, 8], [10, 1]]) == 2
assert my_solution.maxNonDecreasingLength(**[[1, 11], [9, 1]]) == 2
assert my_solution.maxNonDecreasingLength(**[[1, 13], [18, 1]]) == 2
assert my_solution.maxNonDecreasingLength(**[[1, 19], [12, 20]]) == 2
assert my_solution.maxNonDecreasingLength(**[[1, 19], [18, 9]]) == 2
assert my_solution.maxNonDecreasingLength(**[[2, 20], [1, 18]]) == 2
assert my_solution.maxNonDecreasingLength(**[[3, 5], [13, 3]]) == 2
assert my_solution.maxNonDecreasingLength(**[[3, 6], [10, 12]]) == 2
assert my_solution.maxNonDecreasingLength(**[[3, 7], [8, 3]]) == 2
assert my_solution.maxNonDecreasingLength(**[[3, 8], [15, 2]]) == 2
assert my_solution.maxNonDecreasingLength(**[[3, 9], [11, 3]]) == 2
assert my_solution.maxNonDecreasingLength(**[[3, 12], [7, 3]]) == 2
assert my_solution.maxNonDecreasingLength(**[[3, 12], [20, 3]]) == 2
assert my_solution.maxNonDecreasingLength(**[[3, 20], [5, 17]]) == 2


# Apply Operations to Make All Array Elements Equal to Zero

You are given a **0-indexed** integer array `nums` and a positive integer `k`.

You can apply the following operation on the array **any** number of times:

* Choose **any** subarray of size `k` from the array and **decrease** all its elements by `1`.

Return `true` *if you can make all the array elements equal to* `0`*, or* `false` *otherwise*.

A **subarray** is a contiguous non-empty part of an array.

**Example 1:**

```

**Input:** nums = [2,2,3,1,1,0], k = 3
**Output:** true
**Explanation:** We can do the following operations:
- Choose the subarray [2,2,3]. The resulting array will be nums = [**1**,**1**,**2**,1,1,0].
- Choose the subarray [2,1,1]. The resulting array will be nums = [1,1,**1**,**0**,**0**,0].
- Choose the subarray [1,1,1]. The resulting array will be nums = [**0**,**0**,**0**,0,0,0].

```

**Example 2:**

```

**Input:** nums = [1,3,1,1], k = 2
**Output:** false
**Explanation:** It is not possible to make all the array elements equal to 0.

```

**Constraints:**

* `1 <= k <= nums.length <= 105`
* `0 <= nums[i] <= 106`

Please make sure your answer follows the type signature below:

```python3
class Solution:
    def checkArray(self, nums: List[int], k: int) -> bool:
```


# Longest Alternating Subarray

You are given a **0-indexed** integer array `nums`. A subarray `s` of length `m` is called **alternating** if:

* `m` is greater than `1`.
* `s1 = s0 + 1`.
* The **0-indexed** subarray `s` looks like `[s0, s1, s0, s1,...,s(m-1) % 2]`. In other words, `s1 - s0 = 1`, `s2 - s1 = -1`, `s3 - s2 = 1`, `s4 - s3 = -1`, and so on up to `s[m - 1] - s[m - 2] = (-1)m`.

Return *the maximum length of all **alternating** subarrays present in* `nums` *or* `-1` *if no such subarray exists**.*

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

**Example 1:**

```

**Input:** nums = [2,3,4,3,4]
**Output:** 4
**Explanation:** The alternating subarrays are [3,4], [3,4,3], and [3,4,3,4]. The longest of these is [3,4,3,4], which is of length 4.

```

**Example 2:**

```

**Input:** nums = [4,5,6]
**Output:** 2
**Explanation:** [4,5] and [5,6] are the only two alternating subarrays. They are both of length 2.

```

**Constraints:**

* `2 <= nums.length <= 100`
* `1 <= nums[i] <= 104`

Please make sure your answer follows the type signature below:

```python3
class Solution:
    def alternatingSubarray(self, nums: List[int]) -> int:
```

my_solution = Solution()

assert my_solution.alternatingSubarray(**[[2, 3, 4, 3, 4]]) == 4
assert my_solution.alternatingSubarray(**[[4, 5, 6]]) == 2
assert my_solution.alternatingSubarray(**[[31, 32, 31, 32, 33]]) == 4
assert my_solution.alternatingSubarray(**[[21, 9, 5]]) == -1
assert my_solution.alternatingSubarray(**[[42, 43, 44, 43, 44, 43, 44, 45, 46]]) == 6
assert my_solution.alternatingSubarray(**[[13, 14, 15, 14]]) == 3
assert my_solution.alternatingSubarray(**[[74, 75, 74, 75, 74, 75, 74, 75]]) == 8
assert my_solution.alternatingSubarray(**[[77, 78, 79, 78, 79, 78, 79, 78, 79, 80]]) == 8
assert my_solution.alternatingSubarray(**[[88, 42, 53]]) == -1
assert my_solution.alternatingSubarray(**[[64, 65, 64, 65, 64, 65, 66, 65, 66, 65]]) == 6
assert my_solution.alternatingSubarray(**[[99, 100, 99, 100]]) == 4
assert my_solution.alternatingSubarray(**[[21, 22]]) == 2
assert my_solution.alternatingSubarray(**[[23, 24, 23, 24, 25, 24, 25, 24, 25]]) == 6
assert my_solution.alternatingSubarray(**[[20, 9, 15, 15]]) == -1
assert my_solution.alternatingSubarray(**[[92, 93, 92, 93, 92]]) == 5
assert my_solution.alternatingSubarray(**[[24, 25, 26]]) == 2
assert my_solution.alternatingSubarray(**[[51, 52, 53, 52, 53, 52, 53, 54, 53]]) == 6
assert my_solution.alternatingSubarray(**[[65, 66, 65, 66, 67, 68, 69]]) == 4
assert my_solution.alternatingSubarray(**[[29, 2, 5, 24]]) == -1
assert my_solution.alternatingSubarray(**[[26, 27, 26, 27, 28, 27, 28, 27, 28]]) == 6


# Relocate Marbles

You are given a **0-indexed** integer array `nums` representing the initial positions of some marbles. You are also given two **0-indexed** integer arrays `moveFrom` and `moveTo` of **equal** length.

Throughout `moveFrom.length` steps, you will change the positions of the marbles. On the `ith` step, you will move **all** marbles at position `moveFrom[i]` to position `moveTo[i]`.

After completing all the steps, return *the sorted list of **occupied** positions*.

**Notes:**

* We call a position **occupied** if there is at least one marble in that position.
* There may be multiple marbles in a single position.

**Example 1:**

```

**Input:** nums = [1,6,7,8], moveFrom = [1,7,2], moveTo = [2,9,5]
**Output:** [5,6,8,9]
**Explanation:** Initially, the marbles are at positions 1,6,7,8.
At the i = 0th step, we move the marbles at position 1 to position 2. Then, positions 2,6,7,8 are occupied.
At the i = 1st step, we move the marbles at position 7 to position 9. Then, positions 2,6,8,9 are occupied.
At the i = 2nd step, we move the marbles at position 2 to position 5. Then, positions 5,6,8,9 are occupied.
At the end, the final positions containing at least one marbles are [5,6,8,9].
```

**Example 2:**

```

**Input:** nums = [1,1,3,3], moveFrom = [1,3], moveTo = [2,2]
**Output:** [2]
**Explanation:** Initially, the marbles are at positions [1,1,3,3].
At the i = 0th step, we move all the marbles at position 1 to position 2. Then, the marbles are at positions [2,2,3,3].
At the i = 1st step, we move all the marbles at position 3 to position 2. Then, the marbles are at positions [2,2,2,2].
Since 2 is the only occupied position, we return [2].

```

**Constraints:**

* `1 <= nums.length <= 105`
* `1 <= moveFrom.length <= 105`
* `moveFrom.length == moveTo.length`
* `1 <= nums[i], moveFrom[i], moveTo[i] <= 109`
* The test cases are generated such that there is at least a marble in `moveFrom[i]` at the moment we want to apply the `ith` move.

Please make sure your answer follows the type signature below:

```python3
class Solution:
    def relocateMarbles(self, nums: List[int], moveFrom: List[int], moveTo: List[int]) -> List[int]:
```


# Partition String Into Minimum Beautiful Substrings

Given a binary string `s`, partition the string into one or more **substrings** such that each substring is **beautiful**.

A string is **beautiful** if:

* It doesn't contain leading zeros.
* It's the **binary** representation of a number that is a power of `5`.

Return *the **minimum** number of substrings in such partition.* If it is impossible to partition the string `s` into beautiful substrings, return `-1`.

A **substring** is a contiguous sequence of characters in a string.

**Example 1:**

```

**Input:** s = "1011"
**Output:** 2
**Explanation:** We can paritition the given string into ["101", "1"].
- The string "101" does not contain leading zeros and is the binary representation of integer 51 = 5.
- The string "1" does not contain leading zeros and is the binary representation of integer 50 = 1.
It can be shown that 2 is the minimum number of beautiful substrings that s can be partitioned into.

```

**Example 2:**

```

**Input:** s = "111"
**Output:** 3
**Explanation:** We can paritition the given string into ["1", "1", "1"].
- The string "1" does not contain leading zeros and is the binary representation of integer 50 = 1.
It can be shown that 3 is the minimum number of beautiful substrings that s can be partitioned into.

```

**Example 3:**

```

**Input:** s = "0"
**Output:** -1
**Explanation:** We can not partition the given string into beautiful substrings.

```

**Constraints:**

* `1 <= s.length <= 15`
* `s[i]` is either `'0'` or `'1'`.

Please make sure your answer follows the type signature below:

```python3
class Solution:
    def minimumBeautifulSubstrings(self, s: str) -> int:
```

my_solution = Solution()

assert my_solution.minimumBeautifulSubstrings(**['1011']) == 2
assert my_solution.minimumBeautifulSubstrings(**['111']) == 3
assert my_solution.minimumBeautifulSubstrings(**['0']) == -1
assert my_solution.minimumBeautifulSubstrings(**['100111000110111']) == 4
assert my_solution.minimumBeautifulSubstrings(**['100111000111']) == 3
assert my_solution.minimumBeautifulSubstrings(**['1001110001111']) == 4
assert my_solution.minimumBeautifulSubstrings(**['100111000111101']) == 4
assert my_solution.minimumBeautifulSubstrings(**['10110011100011']) == 3
assert my_solution.minimumBeautifulSubstrings(**['101101']) == 2
assert my_solution.minimumBeautifulSubstrings(**['101101101']) == 3
assert my_solution.minimumBeautifulSubstrings(**['101101101101101']) == 5
assert my_solution.minimumBeautifulSubstrings(**['1011011011101']) == 5
assert my_solution.minimumBeautifulSubstrings(**['10110110111011']) == 6
assert my_solution.minimumBeautifulSubstrings(**['101101101111001']) == 5
assert my_solution.minimumBeautifulSubstrings(**['1011011011111']) == 7
assert my_solution.minimumBeautifulSubstrings(**['101101110011101']) == 5
assert my_solution.minimumBeautifulSubstrings(**['10110111001111']) == 6
assert my_solution.minimumBeautifulSubstrings(**['1011011101101']) == 5
assert my_solution.minimumBeautifulSubstrings(**['101101110110111']) == 7
assert my_solution.minimumBeautifulSubstrings(**['101101110111011']) == 7


# Longest Even Odd Subarray With Threshold

You are given a **0-indexed** integer array `nums` and an integer `threshold`.

Find the length of the **longest subarray** of `nums` starting at index `l` and ending at index `r` `(0 <= l <= r < nums.length)` that satisfies the following conditions:

* `nums[l] % 2 == 0`
* For all indices `i` in the range `[l, r - 1]`, `nums[i] % 2 != nums[i + 1] % 2`
* For all indices `i` in the range `[l, r]`, `nums[i] <= threshold`

Return *an integer denoting the length of the longest such subarray.*

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

**Example 1:**

```

**Input:** nums = [3,2,5,4], threshold = 5
**Output:** 3
**Explanation:** In this example, we can select the subarray that starts at l = 1 and ends at r = 3 => [2,5,4]. This subarray satisfies the conditions.
Hence, the answer is the length of the subarray, 3. We can show that 3 is the maximum possible achievable length.
```

**Example 2:**

```

**Input:** nums = [1,2], threshold = 2
**Output:** 1
**Explanation:** In this example, we can select the subarray that starts at l = 1 and ends at r = 1 => [2].
It satisfies all the conditions and we can show that 1 is the maximum possible achievable length.

```

**Example 3:**

```

**Input:** nums = [2,3,4,5], threshold = 4
**Output:** 3
**Explanation:** In this example, we can select the subarray that starts at l = 0 and ends at r = 2 => [2,3,4].
It satisfies all the conditions.
Hence, the answer is the length of the subarray, 3. We can show that 3 is the maximum possible achievable length.

```

**Constraints:**

* `1 <= nums.length <= 100`
* `1 <= nums[i] <= 100`
* `1 <= threshold <= 100`

Please make sure your answer follows the type signature below:

```python3
class Solution:
    def longestAlternatingSubarray(self, nums: List[int], threshold: int) -> int:
```

my_solution = Solution()

assert my_solution.longestAlternatingSubarray(**[[3, 2, 5, 4], 5]) == 3
assert my_solution.longestAlternatingSubarray(**[[1, 2], 2]) == 1
assert my_solution.longestAlternatingSubarray(**[[2, 3, 4, 5], 4]) == 3
assert my_solution.longestAlternatingSubarray(**[[1], 1]) == 0
assert my_solution.longestAlternatingSubarray(**[[2], 2]) == 1
assert my_solution.longestAlternatingSubarray(**[[3], 3]) == 0
assert my_solution.longestAlternatingSubarray(**[[4], 1]) == 0
assert my_solution.longestAlternatingSubarray(**[[5], 3]) == 0
assert my_solution.longestAlternatingSubarray(**[[6], 5]) == 0
assert my_solution.longestAlternatingSubarray(**[[7], 2]) == 0
assert my_solution.longestAlternatingSubarray(**[[8], 1]) == 0
assert my_solution.longestAlternatingSubarray(**[[9], 7]) == 0
assert my_solution.longestAlternatingSubarray(**[[10], 7]) == 0
assert my_solution.longestAlternatingSubarray(**[[1, 3], 16]) == 0
assert my_solution.longestAlternatingSubarray(**[[1, 6], 2]) == 0
assert my_solution.longestAlternatingSubarray(**[[1, 10], 6]) == 0
assert my_solution.longestAlternatingSubarray(**[[1, 10], 7]) == 0
assert my_solution.longestAlternatingSubarray(**[[2, 2], 18]) == 1
assert my_solution.longestAlternatingSubarray(**[[2, 4], 7]) == 1
assert my_solution.longestAlternatingSubarray(**[[2, 5], 2]) == 1


# Prime Pairs With Target Sum

You are given an integer `n`. We say that two integers `x` and `y` form a prime number pair if:

* `1 <= x <= y <= n`
* `x + y == n`
* `x` and `y` are prime numbers

Return *the 2D sorted list of prime number pairs* `[xi, yi]`. The list should be sorted in **increasing** order of `xi`. If there are no prime number pairs at all, return *an empty array*.

**Note:** A prime number is a natural number greater than `1` with only two factors, itself and `1`.

**Example 1:**

```

**Input:** n = 10
**Output:** [[3,7],[5,5]]
**Explanation:** In this example, there are two prime pairs that satisfy the criteria.
These pairs are [3,7] and [5,5], and we return them in the sorted order as described in the problem statement.

```

**Example 2:**

```

**Input:** n = 2
**Output:** []
**Explanation:** We can show that there is no prime number pair that gives a sum of 2, so we return an empty array.

```

**Constraints:**

* `1 <= n <= 106`

Please make sure your answer follows the type signature below:

```python3
class Solution:
    def findPrimePairs(self, n: int) -> List[List[int]]:
```

my_solution = Solution()

assert my_solution.findPrimePairs(**[10]) == [[3, 7], [5, 5]]
assert my_solution.findPrimePairs(**[2]) == []
assert my_solution.findPrimePairs(**[1]) == []
assert my_solution.findPrimePairs(**[3]) == []
assert my_solution.findPrimePairs(**[4]) == [[2, 2]]
assert my_solution.findPrimePairs(**[5]) == [[2, 3]]
assert my_solution.findPrimePairs(**[6]) == [[3, 3]]
assert my_solution.findPrimePairs(**[7]) == [[2, 5]]
assert my_solution.findPrimePairs(**[8]) == [[3, 5]]
assert my_solution.findPrimePairs(**[9]) == [[2, 7]]
assert my_solution.findPrimePairs(**[11]) == []
assert my_solution.findPrimePairs(**[12]) == [[5, 7]]
assert my_solution.findPrimePairs(**[13]) == [[2, 11]]
assert my_solution.findPrimePairs(**[14]) == [[3, 11], [7, 7]]
assert my_solution.findPrimePairs(**[15]) == [[2, 13]]
assert my_solution.findPrimePairs(**[16]) == [[3, 13], [5, 11]]
assert my_solution.findPrimePairs(**[17]) == []
assert my_solution.findPrimePairs(**[18]) == [[5, 13], [7, 11]]
assert my_solution.findPrimePairs(**[19]) == [[2, 17]]
assert my_solution.findPrimePairs(**[20]) == [[3, 17], [7, 13]]


# 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`

Please make sure your answer follows the type signature below:

```python3
class Solution:
    def continuousSubarrays(self, nums: List[int]) -> int:
```

my_solution = Solution()

assert my_solution.continuousSubarrays(**[[5, 4, 2, 4]]) == 8
assert my_solution.continuousSubarrays(**[[1, 2, 3]]) == 6
assert my_solution.continuousSubarrays(**[[31, 30, 31, 32]]) == 10
assert my_solution.continuousSubarrays(**[[65, 66, 67, 66, 66, 65, 64, 65, 65, 64]]) == 43
assert my_solution.continuousSubarrays(**[[42, 41, 42, 41, 41, 40, 39, 38]]) == 28
assert my_solution.continuousSubarrays(**[[35, 35, 36, 37, 36, 37, 38, 37, 38]]) == 39
assert my_solution.continuousSubarrays(**[[43, 44, 43, 44]]) == 10
assert my_solution.continuousSubarrays(**[[14, 15, 15, 15, 16, 16, 16, 16, 15, 16]]) == 55
assert my_solution.continuousSubarrays(**[[21]]) == 1
assert my_solution.continuousSubarrays(**[[34, 34, 33, 34, 33, 33, 32, 31, 30, 31]]) == 39
assert my_solution.continuousSubarrays(**[[58, 59, 59, 58, 59]]) == 15
assert my_solution.continuousSubarrays(**[[10, 9, 8, 7, 8, 9, 9]]) == 24
assert my_solution.continuousSubarrays(**[[65, 66, 65, 64, 63, 62, 62]]) == 20
assert my_solution.continuousSubarrays(**[[65, 65, 64, 65, 66, 65]]) == 21
assert my_solution.continuousSubarrays(**[[85, 84, 83, 84, 83, 82]]) == 20
assert my_solution.continuousSubarrays(**[[60, 59, 60]]) == 6
assert my_solution.continuousSubarrays(**[[96, 97, 98]]) == 6
assert my_solution.continuousSubarrays(**[[21, 22, 23, 22, 23]]) == 15
assert my_solution.continuousSubarrays(**[[76, 77, 77, 78, 77, 78, 78]]) == 28
assert my_solution.continuousSubarrays(**[[27, 27, 27, 26, 26, 27, 27, 27, 27]]) == 45


# Sum of Imbalance Numbers of All Subarrays

The **imbalance number** of a **0-indexed** integer array `arr` of length `n` is defined as the number of indices in `sarr = sorted(arr)` such that:

* `0 <= i < n - 1`, and
* `sarr[i+1] - sarr[i] > 1`

Here, `sorted(arr)` is the function that returns the sorted version of `arr`.

Given a **0-indexed** integer array `nums`, return *the **sum of imbalance numbers** of all its **subarrays***.

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

**Example 1:**

```

**Input:** nums = [2,3,1,4]
**Output:** 3
**Explanation:** There are 3 subarrays with non-zeroimbalance numbers:
- Subarray [3, 1] with an imbalance number of 1.
- Subarray [3, 1, 4] with an imbalance number of 1.
- Subarray [1, 4] with an imbalance number of 1.
The imbalance number of all other subarrays is 0. Hence, the sum of imbalance numbers of all the subarrays of nums is 3.

```

**Example 2:**

```

**Input:** nums = [1,3,3,3,5]
**Output:** 8
**Explanation:** There are 7 subarrays with non-zero imbalance numbers:
- Subarray [1, 3] with an imbalance number of 1.
- Subarray [1, 3, 3] with an imbalance number of 1.
- Subarray [1, 3, 3, 3] with an imbalance number of 1.
- Subarray [1, 3, 3, 3, 5] with an imbalance number of 2.
- Subarray [3, 3, 3, 5] with an imbalance number of 1.
- Subarray [3, 3, 5] with an imbalance number of 1.
- Subarray [3, 5] with an imbalance number of 1.
The imbalance number of all other subarrays is 0. Hence, the sum of imbalance numbers of all the subarrays of nums is 8.
```

**Constraints:**

* `1 <= nums.length <= 1000`
* `1 <= nums[i] <= nums.length`

Please make sure your answer follows the type signature below:

```python3
class Solution:
    def sumImbalanceNumbers(self, nums: List[int]) -> int:
```

my_solution = Solution()

assert my_solution.sumImbalanceNumbers(**[[2, 3, 1, 4]]) == 3
assert my_solution.sumImbalanceNumbers(**[[1, 3, 3, 3, 5]]) == 8
assert my_solution.sumImbalanceNumbers(**[[1]]) == 0
assert my_solution.sumImbalanceNumbers(**[[1, 1]]) == 0
assert my_solution.sumImbalanceNumbers(**[[1, 2]]) == 0
assert my_solution.sumImbalanceNumbers(**[[2, 1]]) == 0
assert my_solution.sumImbalanceNumbers(**[[2, 2]]) == 0
assert my_solution.sumImbalanceNumbers(**[[1, 1, 1]]) == 0
assert my_solution.sumImbalanceNumbers(**[[1, 1, 2]]) == 0
assert my_solution.sumImbalanceNumbers(**[[1, 1, 3]]) == 2
assert my_solution.sumImbalanceNumbers(**[[1, 2, 1]]) == 0
assert my_solution.sumImbalanceNumbers(**[[1, 2, 2]]) == 0
assert my_solution.sumImbalanceNumbers(**[[1, 2, 3]]) == 0
assert my_solution.sumImbalanceNumbers(**[[1, 3, 1]]) == 3
assert my_solution.sumImbalanceNumbers(**[[1, 3, 2]]) == 1
assert my_solution.sumImbalanceNumbers(**[[1, 3, 3]]) == 2
assert my_solution.sumImbalanceNumbers(**[[2, 1, 1]]) == 0
assert my_solution.sumImbalanceNumbers(**[[2, 1, 2]]) == 0
assert my_solution.sumImbalanceNumbers(**[[2, 1, 3]]) == 1
assert my_solution.sumImbalanceNumbers(**[[2, 2, 1]]) == 0


# Number of Beautiful Pairs

You are given a **0-indexed** integer array `nums`. A pair of indices `i`, `j` where `0 <= i < j < nums.length` is called beautiful if the **first digit** of `nums[i]` and the **last digit** of `nums[j]` are **coprime**.

Return *the total number of beautiful pairs in* `nums`.

Two integers `x` and `y` are **coprime** if there is no integer greater than 1 that divides both of them. In other words, `x` and `y` are coprime if `gcd(x, y) == 1`, where `gcd(x, y)` is the **greatest common divisor** of `x` and `y`.

**Example 1:**

```

**Input:** nums = [2,5,1,4]
**Output:** 5
**Explanation:** There are 5 beautiful pairs in nums:
When i = 0 and j = 1: the first digit of nums[0] is 2, and the last digit of nums[1] is 5. We can confirm that 2 and 5 are coprime, since gcd(2,5) == 1.
When i = 0 and j = 2: the first digit of nums[0] is 2, and the last digit of nums[2] is 1. Indeed, gcd(2,1) == 1.
When i = 1 and j = 2: the first digit of nums[1] is 5, and the last digit of nums[2] is 1. Indeed, gcd(5,1) == 1.
When i = 1 and j = 3: the first digit of nums[1] is 5, and the last digit of nums[3] is 4. Indeed, gcd(5,4) == 1.
When i = 2 and j = 3: the first digit of nums[2] is 1, and the last digit of nums[3] is 4. Indeed, gcd(1,4) == 1.
Thus, we return 5.

```

**Example 2:**

```

**Input:** nums = [11,21,12]
**Output:** 2
**Explanation:** There are 2 beautiful pairs:
When i = 0 and j = 1: the first digit of nums[0] is 1, and the last digit of nums[1] is 1. Indeed, gcd(1,1) == 1.
When i = 0 and j = 2: the first digit of nums[0] is 1, and the last digit of nums[2] is 2. Indeed, gcd(1,2) == 1.
Thus, we return 2.

```

**Constraints:**

* `2 <= nums.length <= 100`
* `1 <= nums[i] <= 9999`
* `nums[i] % 10 != 0`

Please make sure your answer follows the type signature below:

```python3
class Solution:
    def countBeautifulPairs(self, nums: List[int]) -> int:
```

my_solution = Solution()

assert my_solution.countBeautifulPairs(**[[2, 5, 1, 4]]) == 5
assert my_solution.countBeautifulPairs(**[[11, 21, 12]]) == 2
assert my_solution.countBeautifulPairs(**[[31, 25, 72, 79, 74]]) == 7
assert my_solution.countBeautifulPairs(**[[84, 91, 18, 59, 27, 9, 81, 33, 17, 58]]) == 37
assert my_solution.countBeautifulPairs(**[[8, 75, 28, 35, 21, 13, 21]]) == 19
assert my_solution.countBeautifulPairs(**[[35, 52, 74, 92, 25, 65, 77, 1, 73, 32]]) == 37
assert my_solution.countBeautifulPairs(**[[68, 8, 84, 14, 88, 42, 53]]) == 7
assert my_solution.countBeautifulPairs(**[[64, 23, 99, 83, 5, 21, 76, 34, 99, 63]]) == 25
assert my_solution.countBeautifulPairs(**[[18, 64, 12, 21]]) == 5
assert my_solution.countBeautifulPairs(**[[78, 36, 58, 88]]) == 6
assert my_solution.countBeautifulPairs(**[[99, 26, 92, 91, 53, 24, 25, 92, 73]]) == 22
assert my_solution.countBeautifulPairs(**[[51, 65, 87, 6, 17, 32, 14, 42, 46]]) == 19
assert my_solution.countBeautifulPairs(**[[43, 9, 75, 76, 25, 96, 46, 85, 19, 29]]) == 32
assert my_solution.countBeautifulPairs(**[[5, 24]]) == 1
assert my_solution.countBeautifulPairs(**[[26, 76, 24, 96, 82, 97, 97, 72, 35]]) == 25
assert my_solution.countBeautifulPairs(**[[77, 82, 94, 55]]) == 5
assert my_solution.countBeautifulPairs(**[[82, 3, 89, 52, 96, 72, 27, 59]]) == 17
assert my_solution.countBeautifulPairs(**[[97, 6, 46, 88, 41, 52, 46, 4, 17]]) == 17
assert my_solution.countBeautifulPairs(**[[95, 6]]) == 0
assert my_solution.countBeautifulPairs(**[[69, 63, 24, 1, 71, 55, 46, 4, 61]]) == 26


# Minimum Operations to Make the Integer Zero

You are given two integers `num1` and `num2`.

In one operation, you can choose integer `i` in the range `[0, 60]` and subtract `2i + num2` from `num1`.

Return *the integer denoting the **minimum** number of operations needed to make* `num1` *equal to* `0`.

If it is impossible to make `num1` equal to `0`, return `-1`.

**Example 1:**

```

**Input:** num1 = 3, num2 = -2
**Output:** 3
**Explanation:** We can make 3 equal to 0 with the following operations:
- We choose i = 2 and substract 22 + (-2) from 3, 3 - (4 + (-2)) = 1.
- We choose i = 2 and substract 22 + (-2) from 1, 1 - (4 + (-2)) = -1.
- We choose i = 0 and substract 20 + (-2) from -1, (-1) - (1 + (-2)) = 0.
It can be proven, that 3 is the minimum number of operations that we need to perform.

```

**Example 2:**

```

**Input:** num1 = 5, num2 = 7
**Output:** -1
**Explanation:** It can be proven, that it is impossible to make 5 equal to 0 with the given operation.

```

**Constraints:**

* `1 <= num1 <= 109`
* `-109 <= num2 <= 109`

Please make sure your answer follows the type signature below:

```python3
class Solution:
    def makeTheIntegerZero(self, num1: int, num2: int) -> int:
```

my_solution = Solution()

assert my_solution.makeTheIntegerZero(**[3, -2]) == 3
assert my_solution.makeTheIntegerZero(**[5, 7]) == -1
assert my_solution.makeTheIntegerZero(**[5, -21]) == 3
assert my_solution.makeTheIntegerZero(**[2, 71]) == -1
assert my_solution.makeTheIntegerZero(**[59, 70]) == -1
assert my_solution.makeTheIntegerZero(**[12, -55]) == 4
assert my_solution.makeTheIntegerZero(**[71, -13]) == 5
assert my_solution.makeTheIntegerZero(**[52, -12]) == 1
assert my_solution.makeTheIntegerZero(**[3, -75]) == 6
assert my_solution.makeTheIntegerZero(**[20, -12]) == 1
assert my_solution.makeTheIntegerZero(**[29, -37]) == 3
assert my_solution.makeTheIntegerZero(**[6, -2]) == 1
assert my_solution.makeTheIntegerZero(**[14, 33]) == -1
assert my_solution.makeTheIntegerZero(**[16, -11]) == 3
assert my_solution.makeTheIntegerZero(**[16, -21]) == 4
assert my_solution.makeTheIntegerZero(**[8, -6]) == 2
assert my_solution.makeTheIntegerZero(**[34, 9]) == 2
assert my_solution.makeTheIntegerZero(**[17, -65]) == 4
assert my_solution.makeTheIntegerZero(**[74, 1]) == 2
assert my_solution.makeTheIntegerZero(**[16, 10]) == -1


# Ways to Split Array Into Good Subarrays

You are given a binary array `nums`.

A subarray of an array is **good** if it contains **exactly** **one** element with the value `1`.

Return *an integer denoting the number of ways to split the array* `nums` *into **good** subarrays*. As the number may be too large, return it **modulo** `109 + 7`.

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

**Example 1:**

```

**Input:** nums = [0,1,0,0,1]
**Output:** 3
**Explanation:** There are 3 ways to split nums into good subarrays:
- [0,1] [0,0,1]
- [0,1,0] [0,1]
- [0,1,0,0] [1]

```

**Example 2:**

```

**Input:** nums = [0,1,0]
**Output:** 1
**Explanation:** There is 1 way to split nums into good subarrays:
- [0,1,0]

```

**Constraints:**

* `1 <= nums.length <= 105`
* `0 <= nums[i] <= 1`

Please make sure your answer follows the type signature below:

```python3
class Solution:
    def numberOfGoodSubarraySplits(self, nums: List[int]) -> int:
```

my_solution = Solution()

assert my_solution.numberOfGoodSubarraySplits(**[[0, 1, 0, 0, 1]]) == 3
assert my_solution.numberOfGoodSubarraySplits(**[[0, 1, 0]]) == 1
assert my_solution.numberOfGoodSubarraySplits(**[[0, 1, 0, 0]]) == 1
assert my_solution.numberOfGoodSubarraySplits(**[[0, 0, 1, 1]]) == 1
assert my_solution.numberOfGoodSubarraySplits(**[[1, 0, 0, 0, 0, 0, 1, 0, 1]]) == 12
assert my_solution.numberOfGoodSubarraySplits(**[[0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1]]) == 8
assert my_solution.numberOfGoodSubarraySplits(**[[0, 1, 1, 1, 0, 1, 1, 0, 0, 0]]) == 2
assert my_solution.numberOfGoodSubarraySplits(**[[0, 1, 0, 0, 1, 0, 1, 0, 1, 1]]) == 12
assert my_solution.numberOfGoodSubarraySplits(**[[1, 0, 1, 1, 0, 1, 0, 0, 1]]) == 12
assert my_solution.numberOfGoodSubarraySplits(**[[0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 1]]) == 6
assert my_solution.numberOfGoodSubarraySplits(**[[0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1]]) == 18
assert my_solution.numberOfGoodSubarraySplits(**[[0, 0, 1]]) == 1
assert my_solution.numberOfGoodSubarraySplits(**[[1, 1, 0, 1, 1, 1, 1, 1]]) == 2
assert my_solution.numberOfGoodSubarraySplits(**[[0, 1]]) == 1
assert my_solution.numberOfGoodSubarraySplits(**[[1, 0, 1, 1, 0, 0, 1, 0, 0, 1, 0]]) == 18
assert my_solution.numberOfGoodSubarraySplits(**[[1, 0, 1, 0, 0]]) == 2
assert my_solution.numberOfGoodSubarraySplits(**[[1, 1, 0]]) == 1
assert my_solution.numberOfGoodSubarraySplits(**[[1, 0, 0, 1, 0, 0, 1, 1]]) == 9
assert my_solution.numberOfGoodSubarraySplits(**[[1, 0, 1, 1, 0, 0]]) == 2
assert my_solution.numberOfGoodSubarraySplits(**[[1]]) == 1


# Find Maximum Number of String Pairs

You are given a **0-indexed** array `words` consisting of **distinct** strings.

The string `words[i]` can be paired with the string `words[j]` if:

* The string `words[i]` is equal to the reversed string of `words[j]`.
* `0 <= i < j < words.length`.

Return *the **maximum** number of pairs that can be formed from the array* `words`*.*

Note that each string can belong in **at most one** pair.

**Example 1:**

```

**Input:** words = ["cd","ac","dc","ca","zz"]
**Output:** 2
**Explanation:** In this example, we can form 2 pair of strings in the following way:
- We pair the 0th string with the 2nd string, as the reversed string of word[0] is "dc" and is equal to words[2].
- We pair the 1st string with the 3rd string, as the reversed string of word[1] is "ca" and is equal to words[3].
It can be proven that 2 is the maximum number of pairs that can be formed.
```

**Example 2:**

```

**Input:** words = ["ab","ba","cc"]
**Output:** 1
**Explanation:** In this example, we can form 1 pair of strings in the following way:
- We pair the 0th string with the 1st string, as the reversed string of words[1] is "ab" and is equal to words[0].
It can be proven that 1 is the maximum number of pairs that can be formed.

```

**Example 3:**

```

**Input:** words = ["aa","ab"]
**Output:** 0
**Explanation:** In this example, we are unable to form any pair of strings.

```

**Constraints:**

* `1 <= words.length <= 50`
* `words[i].length == 2`
* `words` consists of distinct strings.
* `words[i]` contains only lowercase English letters.

Please make sure your answer follows the type signature below:

```python3
class Solution:
    def maximumNumberOfStringPairs(self, words: List[str]) -> int:
```

my_solution = Solution()

assert my_solution.maximumNumberOfStringPairs(**[['cd', 'ac', 'dc', 'ca', 'zz']]) == 2
assert my_solution.maximumNumberOfStringPairs(**[['ab', 'ba', 'cc']]) == 1
assert my_solution.maximumNumberOfStringPairs(**[['aa', 'ab']]) == 0
assert my_solution.maximumNumberOfStringPairs(**[['ku', 'dd', 'gu', 'uk']]) == 1
assert my_solution.maximumNumberOfStringPairs(**[['qf', 'ke', 'rh', 'bl']]) == 0
assert my_solution.maximumNumberOfStringPairs(**[['zs', 'pp', 'sz', 'ie']]) == 1
assert my_solution.maximumNumberOfStringPairs(**[['wk', 'xf', 'ot', 'je', 'hd', 'kw', 'fx', 'to', 'ej']]) == 4
assert my_solution.maximumNumberOfStringPairs(**[['wm', 'lg', 'wy', 'ge', 'zq', 'kn', 'tx', 'dr', 'ws', 'iy']]) == 0
assert my_solution.maximumNumberOfStringPairs(**[['ny', 'gz', 'yr', 'kt', 'qd', 'yn', 'zg', 'ry', 'tk', 'dq']]) == 5
assert my_solution.maximumNumberOfStringPairs(**[['xi', 'nw', 'qp', 'to', 'oo', 'xp', 'ix', 'wn', 'pq']]) == 3
assert my_solution.maximumNumberOfStringPairs(**[['ws', 'zt', 'sw']]) == 1
assert my_solution.maximumNumberOfStringPairs(**[['qb', 'pl', 'ir', 'jj', 'pu', 'dn', 'bq', 'lp']]) == 2
assert my_solution.maximumNumberOfStringPairs(**[['cw', 'fg', 'wc', 'gf']]) == 2
assert my_solution.maximumNumberOfStringPairs(**[['ip', 'pi']]) == 1
assert my_solution.maximumNumberOfStringPairs(**[['ik', 'mn', 'hq', 'fx', 'ki']]) == 1
assert my_solution.maximumNumberOfStringPairs(**[['jn', 'ik', 'ry']]) == 0
assert my_solution.maximumNumberOfStringPairs(**[['aa', 'wj', 'zp', 'df', 'xb', 'sa', 'jw', 'pz']]) == 2
assert my_solution.maximumNumberOfStringPairs(**[['hw', 'pa', 'xx', 'la', 'am', 'vg']]) == 0
assert my_solution.maximumNumberOfStringPairs(**[['hj']]) == 0
assert my_solution.maximumNumberOfStringPairs(**[['tg', 'gf', 'oz', 'nd', 'ks', 'fo', 'ac', 'gl', 'gt', 'fg']]) == 2


# Construct the Longest New String

You are given three integers `x`, `y`, and `z`.

You have `x` strings equal to `"AA"`, `y` strings equal to `"BB"`, and `z` strings equal to `"AB"`. You want to choose some (possibly all or none) of these strings and concatenate them in some order to form a new string. This new string must not contain `"AAA"` or `"BBB"` as a substring.

Return *the maximum possible length of the new string*.

A **substring** is a contiguous **non-empty** sequence of characters within a string.

**Example 1:**

```

**Input:** x = 2, y = 5, z = 1
**Output:** 12
**Explanation:** We can concactenate the strings "BB", "AA", "BB", "AA", "BB", and "AB" in that order. Then, our new string is "BBAABBAABBAB".
That string has length 12, and we can show that it is impossible to construct a string of longer length.

```

**Example 2:**

```

**Input:** x = 3, y = 2, z = 2
**Output:** 14
**Explanation:** We can concactenate the strings "AB", "AB", "AA", "BB", "AA", "BB", and "AA" in that order. Then, our new string is "ABABAABBAABBAA".
That string has length 14, and we can show that it is impossible to construct a string of longer length.

```

**Constraints:**

* `1 <= x, y, z <= 50`

Please make sure your answer follows the type signature below:

```python3
class Solution:
    def longestString(self, x: int, y: int, z: int) -> int:
```

my_solution = Solution()

assert my_solution.longestString(**[2, 5, 1]) == 12
assert my_solution.longestString(**[3, 2, 2]) == 14
assert my_solution.longestString(**[1, 34, 1]) == 8
assert my_solution.longestString(**[1, 39, 14]) == 34
assert my_solution.longestString(**[1, 24, 7]) == 20
assert my_solution.longestString(**[1, 43, 40]) == 86
assert my_solution.longestString(**[1, 34, 39]) == 84
assert my_solution.longestString(**[1, 10, 29]) == 64
assert my_solution.longestString(**[1, 11, 9]) == 24
assert my_solution.longestString(**[1, 34, 3]) == 12
assert my_solution.longestString(**[1, 26, 35]) == 76
assert my_solution.longestString(**[1, 43, 24]) == 54
assert my_solution.longestString(**[1, 28, 11]) == 28
assert my_solution.longestString(**[1, 40, 21]) == 48
assert my_solution.longestString(**[1, 4, 20]) == 46
assert my_solution.longestString(**[1, 41, 30]) == 66
assert my_solution.longestString(**[1, 37, 7]) == 20
assert my_solution.longestString(**[1, 23, 25]) == 56
assert my_solution.longestString(**[1, 8, 5]) == 16
assert my_solution.longestString(**[1, 14, 8]) == 22


# Decremental String Concatenation

You are given a **0-indexed** array `words` containing `n` strings.

Let's define a **join** operation `join(x, y)` between two strings `x` and `y` as concatenating them into `xy`. However, if the last character of `x` is equal to the first character of `y`, one of them is **deleted**.

For example `join("ab", "ba") = "aba"` and `join("ab", "cde") = "abcde"`.

You are to perform `n - 1` **join** operations. Let `str0 = words[0]`. Starting from `i = 1` up to `i = n - 1`, for the `ith` operation, you can do one of the following:

* Make `stri = join(stri - 1, words[i])`
* Make `stri = join(words[i], stri - 1)`

Your task is to **minimize** the length of `strn - 1`.

Return *an integer denoting the minimum possible length of* `strn - 1`.

**Example 1:**

```

**Input:** words = ["aa","ab","bc"]
**Output:** 4
**Explanation:** In this example, we can perform join operations in the following order to minimize the length of str2:
str0 = "aa"
str1 = join(str0, "ab") = "aab"
str2 = join(str1, "bc") = "aabc"
It can be shown that the minimum possible length of str2 is 4.
```

**Example 2:**

```

**Input:** words = ["ab","b"]
**Output:** 2
**Explanation:** In this example, str0 = "ab", there are two ways to get str1:
join(str0, "b") = "ab" or join("b", str0) = "bab".
The first string, "ab", has the minimum length. Hence, the answer is 2.

```

**Example 3:**

```

**Input:** words = ["aaa","c","aba"]
**Output:** 6
**Explanation:** In this example, we can perform join operations in the following order to minimize the length of str2:
str0 = "aaa"
str1 = join(str0, "c") = "aaac"
str2 = join("aba", str1) = "abaaac"
It can be shown that the minimum possible length of str2 is 6.

```

**Constraints:**

* `1 <= words.length <= 1000`
* `1 <= words[i].length <= 50`
* Each character in `words[i]` is an English lowercase letter

Please make sure your answer follows the type signature below:

```python3
class Solution:
    def minimizeConcatenatedLength(self, words: List[str]) -> int:
```

my_solution = Solution()

assert my_solution.minimizeConcatenatedLength(**[['aa', 'ab', 'bc']]) == 4
assert my_solution.minimizeConcatenatedLength(**[['ab', 'b']]) == 2
assert my_solution.minimizeConcatenatedLength(**[['aaa', 'c', 'aba']]) == 6
assert my_solution.minimizeConcatenatedLength(**[['a', 'a']]) == 1
assert my_solution.minimizeConcatenatedLength(**[['a', 'ab']]) == 2
assert my_solution.minimizeConcatenatedLength(**[['a', 'b']]) == 2
assert my_solution.minimizeConcatenatedLength(**[['a', 'ca']]) == 2
assert my_solution.minimizeConcatenatedLength(**[['a', 'cb']]) == 3
assert my_solution.minimizeConcatenatedLength(**[['aa', 'a']]) == 2
assert my_solution.minimizeConcatenatedLength(**[['aa', 'b']]) == 3
assert my_solution.minimizeConcatenatedLength(**[['aa', 'ca']]) == 3
assert my_solution.minimizeConcatenatedLength(**[['aa', 'ccc']]) == 5
assert my_solution.minimizeConcatenatedLength(**[['aab', 'b']]) == 3
assert my_solution.minimizeConcatenatedLength(**[['aab', 'ba']]) == 4
assert my_solution.minimizeConcatenatedLength(**[['aab', 'bb']]) == 4
assert my_solution.minimizeConcatenatedLength(**[['aab', 'bba']]) == 5
assert my_solution.minimizeConcatenatedLength(**[['aab', 'c']]) == 4
assert my_solution.minimizeConcatenatedLength(**[['aac', 'b']]) == 4
assert my_solution.minimizeConcatenatedLength(**[['ab', 'acb']]) == 5
assert my_solution.minimizeConcatenatedLength(**[['ab', 'bc']]) == 3


# Count Zero Request Servers

You are given an integer `n` denoting the total number of servers and a **2D** **0-indexed** integer array `logs`, where `logs[i] = [server_id, time]` denotes that the server with id `server_id` received a request at time `time`.

You are also given an integer `x` and a **0-indexed** integer array `queries`.

Return *a **0-indexed** integer array* `arr` *of length* `queries.length` *where* `arr[i]` *represents the number of servers that **did not receive** any requests during the time interval* `[queries[i] - x, queries[i]]`.

Note that the time intervals are inclusive.

**Example 1:**

```

**Input:** n = 3, logs = [[1,3],[2,6],[1,5]], x = 5, queries = [10,11]
**Output:** [1,2]
**Explanation:**
For queries[0]: The servers with ids 1 and 2 get requests in the duration of [5, 10]. Hence, only server 3 gets zero requests.
For queries[1]: Only the server with id 2 gets a request in duration of [6,11]. Hence, the servers with ids 1 and 3 are the only servers that do not receive any requests during that time period.

```

**Example 2:**

```

**Input:** n = 3, logs = [[2,4],[2,1],[1,2],[3,1]], x = 2, queries = [3,4]
**Output:** [0,1]
**Explanation:**
For queries[0]: All servers get at least one request in the duration of [1, 3].
For queries[1]: Only server with id 3 gets no request in the duration [2,4].

```

**Constraints:**

* `1 <= n <= 105`
* `1 <= logs.length <= 105`
* `1 <= queries.length <= 105`
* `logs[i].length == 2`
* `1 <= logs[i][0] <= n`
* `1 <= logs[i][1] <= 106`
* `1 <= x <= 105`
* `x < queries[i] <= 106`

Please make sure your answer follows the type signature below:

```python3
class Solution:
    def countServers(self, n: int, logs: List[List[int]], x: int, queries: List[int]) -> List[int]:
```


# Total Distance Traveled

A truck has two fuel tanks. You are given two integers, `mainTank` representing the fuel present in the main tank in liters and `additionalTank` representing the fuel present in the additional tank in liters.

The truck has a mileage of `10` km per liter. Whenever `5` liters of fuel get used up in the main tank, if the additional tank has at least `1` liters of fuel, `1` liters of fuel will be transferred from the additional tank to the main tank.

Return *the maximum distance which can be traveled.*

**Note:** Injection from the additional tank is not continuous. It happens suddenly and immediately for every 5 liters consumed.

**Example 1:**

```

**Input:** mainTank = 5, additionalTank = 10
**Output:** 60
**Explanation:**
After spending 5 litre of fuel, fuel remaining is (5 - 5 + 1) = 1 litre and distance traveled is 50km.
After spending another 1 litre of fuel, no fuel gets injected in the main tank and the main tank becomes empty.
Total distance traveled is 60km.

```

**Example 2:**

```

**Input:** mainTank = 1, additionalTank = 2
**Output:** 10
**Explanation:**
After spending 1 litre of fuel, the main tank becomes empty.
Total distance traveled is 10km.

```

**Constraints:**

* `1 <= mainTank, additionalTank <= 100`

Please make sure your answer follows the type signature below:

```python3
class Solution:
    def distanceTraveled(self, mainTank: int, additionalTank: int) -> int:
```

my_solution = Solution()

assert my_solution.distanceTraveled(**[5, 10]) == 60
assert my_solution.distanceTraveled(**[1, 2]) == 10
assert my_solution.distanceTraveled(**[1, 1]) == 10
assert my_solution.distanceTraveled(**[1, 3]) == 10
assert my_solution.distanceTraveled(**[1, 4]) == 10
assert my_solution.distanceTraveled(**[1, 5]) == 10
assert my_solution.distanceTraveled(**[1, 6]) == 10
assert my_solution.distanceTraveled(**[1, 7]) == 10
assert my_solution.distanceTraveled(**[1, 8]) == 10
assert my_solution.distanceTraveled(**[1, 9]) == 10
assert my_solution.distanceTraveled(**[1, 10]) == 10
assert my_solution.distanceTraveled(**[1, 11]) == 10
assert my_solution.distanceTraveled(**[1, 12]) == 10
assert my_solution.distanceTraveled(**[1, 13]) == 10
assert my_solution.distanceTraveled(**[1, 14]) == 10
assert my_solution.distanceTraveled(**[1, 15]) == 10
assert my_solution.distanceTraveled(**[1, 16]) == 10
assert my_solution.distanceTraveled(**[1, 17]) == 10
assert my_solution.distanceTraveled(**[1, 18]) == 10
assert my_solution.distanceTraveled(**[1, 19]) == 10


# Find the Value of the Partition

You are given a **positive** integer array `nums`.

Partition `nums` into two arrays, `nums1` and `nums2`, such that:

* Each element of the array `nums` belongs to either the array `nums1` or the array `nums2`.
* Both arrays are **non-empty**.
* The value of the partition is **minimized**.

The value of the partition is `|max(nums1) - min(nums2)|`.

Here, `max(nums1)` denotes the maximum element of the array `nums1`, and `min(nums2)` denotes the minimum element of the array `nums2`.

Return *the integer denoting the value of such partition*.

**Example 1:**

```

**Input:** nums = [1,3,2,4]
**Output:** 1
**Explanation:** We can partition the array nums into nums1 = [1,2] and nums2 = [3,4].
- The maximum element of the array nums1 is equal to 2.
- The minimum element of the array nums2 is equal to 3.
The value of the partition is |2 - 3| = 1.
It can be proven that 1 is the minimum value out of all partitions.

```

**Example 2:**

```

**Input:** nums = [100,1,10]
**Output:** 9
**Explanation:** We can partition the array nums into nums1 = [10] and nums2 = [100,1].
- The maximum element of the array nums1 is equal to 10.
- The minimum element of the array nums2 is equal to 1.
The value of the partition is |10 - 1| = 9.
It can be proven that 9 is the minimum value out of all partitions.

```

**Constraints:**

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

Please make sure your answer follows the type signature below:

```python3
class Solution:
    def findValueOfPartition(self, nums: List[int]) -> int:
```

my_solution = Solution()

assert my_solution.findValueOfPartition(**[[1, 3, 2, 4]]) == 1
assert my_solution.findValueOfPartition(**[[100, 1, 10]]) == 9
assert my_solution.findValueOfPartition(**[[59, 51, 1, 98, 73]]) == 8
assert my_solution.findValueOfPartition(**[[84, 11, 100, 100, 75]]) == 0
assert my_solution.findValueOfPartition(**[[59, 76, 2, 26, 49]]) == 10
assert my_solution.findValueOfPartition(**[[78, 36, 2, 70, 64, 24, 34, 63, 21, 49]]) == 1
assert my_solution.findValueOfPartition(**[[43, 35, 19, 1, 21, 11, 59, 38, 47, 1]]) == 0
assert my_solution.findValueOfPartition(**[[35, 74, 58, 56]]) == 2
assert my_solution.findValueOfPartition(**[[54, 75, 6, 20, 49, 94, 97, 20, 97]]) == 0
assert my_solution.findValueOfPartition(**[[92, 13, 30, 32, 89]]) == 2
assert my_solution.findValueOfPartition(**[[49, 10, 36]]) == 13
assert my_solution.findValueOfPartition(**[[37, 50, 25, 65, 41, 31]]) == 4
assert my_solution.findValueOfPartition(**[[14, 20, 59, 42]]) == 6
assert my_solution.findValueOfPartition(**[[43, 57, 73, 45, 30, 77, 17, 38, 20]]) == 2
assert my_solution.findValueOfPartition(**[[11, 17, 65, 55, 85, 74, 32]]) == 6
assert my_solution.findValueOfPartition(**[[84, 93]]) == 9
assert my_solution.findValueOfPartition(**[[31, 61, 78, 15, 52]]) == 9
assert my_solution.findValueOfPartition(**[[100, 65, 64, 8, 61, 17]]) == 1
assert my_solution.findValueOfPartition(**[[3, 72, 8, 90]]) == 5
assert my_solution.findValueOfPartition(**[[55, 55, 23]]) == 0


# Special Permutations

You are given a **0-indexed** integer array `nums` containing `n` **distinct** positive integers. A permutation of `nums` is called special if:

* For all indexes `0 <= i < n - 1`, either `nums[i] % nums[i+1] == 0` or `nums[i+1] % nums[i] == 0`.

Return *the total number of special permutations.*As the answer could be large, return it **modulo**`109+ 7`.

**Example 1:**

```

**Input:** nums = [2,3,6]
**Output:** 2
**Explanation:** [3,6,2] and [2,6,3] are the two special permutations of nums.

```

**Example 2:**

```

**Input:** nums = [1,4,3]
**Output:** 2
**Explanation:** [3,1,4] and [4,1,3] are the two special permutations of nums.

```

**Constraints:**

* `2 <= nums.length <= 14`
* `1 <= nums[i] <= 109`

Please make sure your answer follows the type signature below:

```python3
class Solution:
    def specialPerm(self, nums: List[int]) -> int:
```

my_solution = Solution()

assert my_solution.specialPerm(**[[2, 3, 6]]) == 2
assert my_solution.specialPerm(**[[1, 4, 3]]) == 2
assert my_solution.specialPerm(**[[31, 93]]) == 2
assert my_solution.specialPerm(**[[20, 100, 50, 5, 10, 70, 7]]) == 48
assert my_solution.specialPerm(**[[24, 3, 27, 54, 9, 90, 30, 60, 20, 100]]) == 4
assert my_solution.specialPerm(**[[3, 21, 84, 14, 56, 7]]) == 34
assert my_solution.specialPerm(**[[6, 30, 3, 9, 36, 72, 18, 54]]) == 1440
assert my_solution.specialPerm(**[[14, 28, 84, 21, 63, 9, 27, 81]]) == 8
assert my_solution.specialPerm(**[[64, 8, 1, 3, 30]]) == 8
assert my_solution.specialPerm(**[[83, 105]]) == 0
assert my_solution.specialPerm(**[[99, 11, 44, 88, 22, 66, 33]]) == 72
assert my_solution.specialPerm(**[[87, 29]]) == 2
assert my_solution.specialPerm(**[[29, 87]]) == 2
assert my_solution.specialPerm(**[[30, 6, 54, 27, 81, 9, 90, 15]]) == 56
assert my_solution.specialPerm(**[[2, 14, 70]]) == 6
assert my_solution.specialPerm(**[[74, 37]]) == 2
assert my_solution.specialPerm(**[[68, 17, 51]]) == 2
assert my_solution.specialPerm(**[[66, 11, 99, 33]]) == 12
assert my_solution.specialPerm(**[[24, 72, 12]]) == 6
assert my_solution.specialPerm(**[[94, 47]]) == 2


# Painting the Walls

You are given two **0-indexed** integer arrays, `cost` and `time`, of size `n` representing the costs and the time taken to paint `n` different walls respectively. There are two painters available:

* A**paid painter** that paints the `ith` wall in `time[i]` units of time and takes `cost[i]` units of money.
* A**free painter** that paints **any** wall in `1` unit of time at a cost of `0`. But the free painter can only be used if the paid painter is already **occupied**.

Return *the minimum amount of money required to paint the* `n`*walls.*

**Example 1:**

```

**Input:** cost = [1,2,3,2], time = [1,2,3,2]
**Output:** 3
**Explanation:** The walls at index 0 and 1 will be painted by the paid painter, and it will take 3 units of time; meanwhile, the free painter will paint the walls at index 2 and 3, free of cost in 2 units of time. Thus, the total cost is 1 + 2 = 3.

```

**Example 2:**

```

**Input:** cost = [2,3,4,2], time = [1,1,1,1]
**Output:** 4
**Explanation:** The walls at index 0 and 3 will be painted by the paid painter, and it will take 2 units of time; meanwhile, the free painter will paint the walls at index 1 and 2, free of cost in 2 units of time. Thus, the total cost is 2 + 2 = 4.

```

**Constraints:**

* `1 <= cost.length <= 500`
* `cost.length == time.length`
* `1 <= cost[i] <= 106`
* `1 <= time[i] <= 500`

Please make sure your answer follows the type signature below:

```python3
class Solution:
    def paintWalls(self, cost: List[int], time: List[int]) -> int:
```


# Neither Minimum nor Maximum

Given an integer array `nums` containing **distinct** **positive** integers, find and return **any** number from the array that is neither the **minimum** nor the **maximum** value in the array, or **`-1`** if there is no such number.

Return *the selected integer.*

**Example 1:**

```

**Input:** nums = [3,2,1,4]
**Output:** 2
**Explanation:** In this example, the minimum value is 1 and the maximum value is 4. Therefore, either 2 or 3 can be valid answers.

```

**Example 2:**

```

**Input:** nums = [1,2]
**Output:** -1
**Explanation:** Since there is no number in nums that is neither the maximum nor the minimum, we cannot select a number that satisfies the given condition. Therefore, there is no answer.

```

**Example 3:**

```

**Input:** nums = [2,1,3]
**Output:** 2
**Explanation:** Since 2 is neither the maximum nor the minimum value in nums, it is the only valid answer.

```

**Constraints:**

* `1 <= nums.length <= 100`
* `1 <= nums[i] <= 100`
* All values in `nums` are distinct

Please make sure your answer follows the type signature below:

```python3
class Solution:
    def findNonMinOrMax(self, nums: List[int]) -> int:
```

my_solution = Solution()

assert my_solution.findNonMinOrMax(**[[3, 2, 1, 4]]) == 2
assert my_solution.findNonMinOrMax(**[[1, 2]]) == -1
assert my_solution.findNonMinOrMax(**[[2, 1, 3]]) == 2
assert my_solution.findNonMinOrMax(**[[1]]) == -1
assert my_solution.findNonMinOrMax(**[[2]]) == -1
assert my_solution.findNonMinOrMax(**[[5]]) == -1
assert my_solution.findNonMinOrMax(**[[6]]) == -1
assert my_solution.findNonMinOrMax(**[[7]]) == -1
assert my_solution.findNonMinOrMax(**[[8]]) == -1
assert my_solution.findNonMinOrMax(**[[9]]) == -1
assert my_solution.findNonMinOrMax(**[[10]]) == -1
assert my_solution.findNonMinOrMax(**[[11]]) == -1
assert my_solution.findNonMinOrMax(**[[12]]) == -1
assert my_solution.findNonMinOrMax(**[[13]]) == -1
assert my_solution.findNonMinOrMax(**[[14]]) == -1
assert my_solution.findNonMinOrMax(**[[15]]) == -1
assert my_solution.findNonMinOrMax(**[[17]]) == -1
assert my_solution.findNonMinOrMax(**[[18]]) == -1
assert my_solution.findNonMinOrMax(**[[20]]) == -1
assert my_solution.findNonMinOrMax(**[[22]]) == -1


# Lexicographically Smallest String After Substring Operation

You are given a string `s` consisting of only lowercase English letters. In one operation, you can do the following:

* Select any non-empty substring of `s`, possibly the entire string, then replace each one of its characters with the previous character of the English alphabet. For example, 'b' is converted to 'a', and 'a' is converted to 'z'.

Return *the **lexicographically smallest** string you can obtain after performing the above operation **exactly once**.*

A **substring** is a contiguous sequence of characters in a string.

A string `x` is **lexicographically smaller** than a string `y` of the same length if `x[i]` comes before `y[i]` in alphabetic order for the first position `i` such that `x[i] != y[i]`.

**Example 1:**

```

**Input:** s = "cbabc"
**Output:** "baabc"
**Explanation:** We apply the operation on the substring starting at index 0, and ending at index 1 inclusive.
It can be proven that the resulting string is the lexicographically smallest.

```

**Example 2:**

```

**Input:** s = "acbbc"
**Output:** "abaab"
**Explanation:** We apply the operation on the substring starting at index 1, and ending at index 4 inclusive.
It can be proven that the resulting string is the lexicographically smallest.

```

**Example 3:**

```

**Input:** s = "leetcode"
**Output:** "kddsbncd"
**Explanation:** We apply the operation on the entire string.
It can be proven that the resulting string is the lexicographically smallest.

```

**Constraints:**

* `1 <= s.length <= 3 * 105`
* `s` consists of lowercase English letters

Please make sure your answer follows the type signature below:

```python3
class Solution:
    def smallestString(self, s: str) -> str:
```

my_solution = Solution()

assert my_solution.smallestString(**['cbabc']) == baabc
assert my_solution.smallestString(**['acbbc']) == abaab
assert my_solution.smallestString(**['leetcode']) == kddsbncd
assert my_solution.smallestString(**['a']) == z
assert my_solution.smallestString(**['b']) == a
assert my_solution.smallestString(**['c']) == b
assert my_solution.smallestString(**['d']) == c
assert my_solution.smallestString(**['e']) == d
assert my_solution.smallestString(**['f']) == e
assert my_solution.smallestString(**['g']) == f
assert my_solution.smallestString(**['h']) == g
assert my_solution.smallestString(**['i']) == h
assert my_solution.smallestString(**['j']) == i
assert my_solution.smallestString(**['k']) == j
assert my_solution.smallestString(**['l']) == k
assert my_solution.smallestString(**['m']) == l
assert my_solution.smallestString(**['n']) == m
assert my_solution.smallestString(**['o']) == n
assert my_solution.smallestString(**['p']) == o
assert my_solution.smallestString(**['q']) == p

Output: baabc

Output: abaab

Output: kddsbncd

Output: z

Output: a

Output: b

Output: c

Output: d

Output: e

Output: f

Output: g

Output: h

Output: i

Output: j

Output: k

Output: l

Output: m

Output: n

Output: o

Output: p


# Collecting Chocolates

You are given a **0-indexed** integer array `nums` of size `n` representing the cost of collecting different chocolates. The cost of collecting the chocolate at the index `i` is `nums[i]`. Each chocolate is of a different type, and initially, the chocolate at the index `i` is of `ith` type.

In one operation, you can do the following with an incurred **cost** of `x`:

* Simultaneously change the chocolate of `ith` type to `((i + 1) mod n)th` type for all chocolates.

Return *the minimum cost to collect chocolates of all types, given that you can perform as many operations as you would like.*

**Example 1:**

```

**Input:** nums = [20,1,15], x = 5
**Output:** 13
**Explanation:** Initially, the chocolate types are [0,1,2]. We will buy the 1st type of chocolate at a cost of 1.
Now, we will perform the operation at a cost of 5, and the types of chocolates will become [1,2,0]. We will buy the 2ndtype of chocolate at a cost of 1.
Now, we will again perform the operation at a cost of 5, and the chocolate types will become [2,0,1]. We will buy the 0th type of chocolate at a cost of 1.
Thus, the total cost will become (1 + 5 + 1 + 5 + 1) = 13. We can prove that this is optimal.

```

**Example 2:**

```

**Input:** nums = [1,2,3], x = 4
**Output:** 6
**Explanation:** We will collect all three types of chocolates at their own price without performing any operations. Therefore, the total cost is 1 + 2 + 3 = 6.

```

**Constraints:**

* `1 <= nums.length <= 1000`
* `1 <= nums[i] <= 109`
* `1 <= x <= 109`

Please make sure your answer follows the type signature below:

```python3
class Solution:
    def minCost(self, nums: List[int], x: int) -> int:
```


# Maximum Sum Queries

You are given two **0-indexed** integer arrays `nums1` and `nums2`, each of length `n`, and a **1-indexed 2D array** `queries` where `queries[i] = [xi, yi]`.

For the `ith` query, find the **maximum value** of `nums1[j] + nums2[j]` among all indices `j` `(0 <= j < n)`, where `nums1[j] >= xi` and `nums2[j] >= yi`, or **-1** if there is no `j` satisfying the constraints.

Return *an array* `answer` *where* `answer[i]` *is the answer to the* `ith` *query.*

**Example 1:**

```

**Input:** nums1 = [4,3,1,2], nums2 = [2,4,9,5], queries = [[4,1],[1,3],[2,5]]
**Output:** [6,10,7]
**Explanation:**
For the 1st query xi = 4 and yi = 1, we can select index j = 0 since nums1[j] >= 4 and nums2[j] >= 1. The sum nums1[j] + nums2[j] is 6, and we can show that 6 is the maximum we can obtain.

For the 2nd query xi = 1 and yi = 3, we can select index j = 2 since nums1[j] >= 1 and nums2[j] >= 3. The sum nums1[j] + nums2[j] is 10, and we can show that 10 is the maximum we can obtain.

For the 3rd query xi = 2 and yi = 5, we can select index j = 3 since nums1[j] >= 2 and nums2[j] >= 5. The sum nums1[j] + nums2[j] is 7, and we can show that 7 is the maximum we can obtain.

Therefore, we return [6,10,7].

```

**Example 2:**

```

**Input:** nums1 = [3,2,5], nums2 = [2,3,4], queries = [[4,4],[3,2],[1,1]]
**Output:** [9,9,9]
**Explanation:** For this example, we can use index j = 2 for all the queries since it satisfies the constraints for each query.

```

**Example 3:**

```

**Input:** nums1 = [2,1], nums2 = [2,3], queries = [[3,3]]
**Output:** [-1]
**Explanation:** There is one query in this example with xi = 3 and yi = 3. For every index, j, either nums1[j] < xi or nums2[j] < yi. Hence, there is no solution.

```

**Constraints:**

* `nums1.length == nums2.length`
* `n == nums1.length`
* `1 <= n <= 105`
* `1 <= nums1[i], nums2[i] <= 109`
* `1 <= queries.length <= 105`
* `queries[i].length == 2`
* `xi == queries[i][1]`
* `yi == queries[i][2]`
* `1 <= xi, yi <= 109`

Please make sure your answer follows the type signature below:

```python3
class Solution:
    def maximumSumQueries(self, nums1: List[int], nums2: List[int], queries: List[List[int]]) -> List[int]:
```


# Find the Longest Semi-Repetitive Substring

You are given a **0-indexed** string `s` that consists of digits from `0` to `9`.

A string `t` is called a **semi-repetitive** if there is at most one consecutive pair of the same digits inside `t`. For example, `0010`, `002020`, `0123`, `2002`, and `54944` are semi-repetitive while `00101022`, and `1101234883` are not.

Return *the length of the longest semi-repetitive substring inside* `s`.

A **substring** is a contiguous **non-empty** sequence of characters within a string.

**Example 1:**

```

**Input:** s = "52233"
**Output:** 4
**Explanation:** The longest semi-repetitive substring is "5223", which starts at i = 0 and ends at j = 3.

```

**Example 2:**

```

**Input:** s = "5494"
**Output:** 4
**Explanation:** s is a semi-reptitive string, so the answer is 4.

```

**Example 3:**

```

**Input:** s = "1111111"
**Output:** 2
**Explanation:** The longest semi-repetitive substring is "11", which starts at i = 0 and ends at j = 1.

```

**Constraints:**

* `1 <= s.length <= 50`
* `'0' <= s[i] <= '9'`

Please make sure your answer follows the type signature below:

```python3
class Solution:
    def longestSemiRepetitiveSubstring(self, s: str) -> int:
```

my_solution = Solution()

assert my_solution.longestSemiRepetitiveSubstring(**['52233']) == 4
assert my_solution.longestSemiRepetitiveSubstring(**['5494']) == 4
assert my_solution.longestSemiRepetitiveSubstring(**['1111111']) == 2
assert my_solution.longestSemiRepetitiveSubstring(**['0']) == 1
assert my_solution.longestSemiRepetitiveSubstring(**['1']) == 1
assert my_solution.longestSemiRepetitiveSubstring(**['2']) == 1
assert my_solution.longestSemiRepetitiveSubstring(**['3']) == 1
assert my_solution.longestSemiRepetitiveSubstring(**['4']) == 1
assert my_solution.longestSemiRepetitiveSubstring(**['5']) == 1
assert my_solution.longestSemiRepetitiveSubstring(**['6']) == 1
assert my_solution.longestSemiRepetitiveSubstring(**['7']) == 1
assert my_solution.longestSemiRepetitiveSubstring(**['8']) == 1
assert my_solution.longestSemiRepetitiveSubstring(**['9']) == 1
assert my_solution.longestSemiRepetitiveSubstring(**['00']) == 2
assert my_solution.longestSemiRepetitiveSubstring(**['01']) == 2
assert my_solution.longestSemiRepetitiveSubstring(**['02']) == 2
assert my_solution.longestSemiRepetitiveSubstring(**['03']) == 2
assert my_solution.longestSemiRepetitiveSubstring(**['04']) == 2
assert my_solution.longestSemiRepetitiveSubstring(**['05']) == 2
assert my_solution.longestSemiRepetitiveSubstring(**['06']) == 2


# Movement of Robots

Some robots are standing on an infinite number line with their initial coordinates given by a **0-indexed** integer array `nums` and will start moving once given the command to move. The robots will move a unit distance each second.

You are given a string `s` denoting the direction in which robots will move on command. `'L'` means the robot will move towards the left side or negative side of the number line, whereas `'R'` means the robot will move towards the right side or positive side of the number line.

If two robots collide, they will start moving in opposite directions.

Return *the sum of distances between all the pairs of robots* `d` *seconds after the command.* Since the sum can be very large, return it modulo `109 + 7`.

**Note:**

* For two robots at the index `i` and `j`, pair `(i,j)` and pair `(j,i)` are considered the same pair.
* When robots collide, they **instantly change** their directions without wasting any time.
* Collision happens when two robots share the same place in a moment.
	+ For example, if a robot is positioned in 0 going to the right and another is positioned in 2 going to the left, the next second they'll be both in 1 and they will change direction and the next second the first one will be in 0, heading left, and another will be in 2, heading right.
	+ For example, if a robot is positioned in 0 going to the right and another is positioned in 1 going to the left, the next second the first one will be in 0, heading left, and another will be in 1, heading right.

**Example 1:**

```

**Input:** nums = [-2,0,2], s = "RLL", d = 3
**Output:** 8
**Explanation:**
After 1 second, the positions are [-1,-1,1]. Now, the robot at index 0 will move left, and the robot at index 1 will move right.
After 2 seconds, the positions are [-2,0,0]. Now, the robot at index 1 will move left, and the robot at index 2 will move right.
After 3 seconds, the positions are [-3,-1,1].
The distance between the robot at index 0 and 1 is abs(-3 - (-1)) = 2.
The distance between the robot at index 0 and 2 is abs(-3 - 1) = 4.
The distance between the robot at index 1 and 2 is abs(-1 - 1) = 2.
The sum of the pairs of all distances = 2 + 4 + 2 = 8.

```

**Example 2:**

```

**Input:** nums = [1,0], s = "RL", d = 2
**Output:** 5
**Explanation:**
After 1 second, the positions are [2,-1].
After 2 seconds, the positions are [3,-2].
The distance between the two robots is abs(-2 - 3) = 5.

```

**Constraints:**

* `2 <= nums.length <= 105`
* `-2 * 109 <= nums[i] <= 2 * 109`
* `0 <= d <= 109`
* `nums.length == s.length`
* `s` consists of 'L' and 'R' only
* `nums[i]` will be unique.

Please make sure your answer follows the type signature below:

```python3
class Solution:
    def sumDistance(self, nums: List[int], s: str, d: int) -> int:
```


# Find a Good Subset of the Matrix

You are given a **0-indexed** `m x n` binary matrix `grid`.

Let us call a **non-empty** subset of rows **good** if the sum of each column of the subset is at most half of the length of the subset.

More formally, if the length of the chosen subset of rows is `k`, then the sum of each column should be at most `floor(k / 2)`.

Return *an integer array that contains row indices of a good subset sorted in **ascending** order.*

If there are multiple good subsets, you can return any of them. If there are no good subsets, return an empty array.

A **subset** of rows of the matrix `grid` is any matrix that can be obtained by deleting some (possibly none or all) rows from `grid`.

**Example 1:**

```

**Input:** grid = [[0,1,1,0],[0,0,0,1],[1,1,1,1]]
**Output:** [0,1]
**Explanation:** We can choose the 0th and 1st rows to create a good subset of rows.
The length of the chosen subset is 2.
- The sum of the 0th column is 0 + 0 = 0, which is at most half of the length of the subset.
- The sum of the 1st column is 1 + 0 = 1, which is at most half of the length of the subset.
- The sum of the 2nd column is 1 + 0 = 1, which is at most half of the length of the subset.
- The sum of the 3rd column is 0 + 1 = 1, which is at most half of the length of the subset.

```

**Example 2:**

```

**Input:** grid = [[0]]
**Output:** [0]
**Explanation:** We can choose the 0th row to create a good subset of rows.
The length of the chosen subset is 1.
- The sum of the 0th column is 0, which is at most half of the length of the subset.

```

**Example 3:**

```

**Input:** grid = [[1,1,1],[1,1,1]]
**Output:** []
**Explanation:** It is impossible to choose any subset of rows to create a good subset.

```

**Constraints:**

* `m == grid.length`
* `n == grid[i].length`
* `1 <= m <= 104`
* `1 <= n <= 5`
* `grid[i][j]` is either `0` or `1`.

Please make sure your answer follows the type signature below:

```python3
class Solution:
    def goodSubsetofBinaryMatrix(self, grid: List[List[int]]) -> List[int]:
```


# Minimize String Length

Given a **0-indexed** string `s`, repeatedly perform the following operation **any** number of times:

* Choose an index `i` in the string, and let `c` be the character in position `i`. **Delete** the **closest occurrence** of `c` to the **left** of `i` (if any) and the **closest occurrence** of `c` to the **right** of `i` (if any).

Your task is to **minimize** the length of `s` by performing the above operation any number of times.

Return *an integer denoting the length of the **minimized** string.*

**Example 1:**

```

**Input:** s = "aaabc"
**Output:** 3
**Explanation:** In this example, s is "aaabc". We can start by selecting the character 'a' at index 1. We then remove the closest 'a' to the left of index 1, which is at index 0, and the closest 'a' to the right of index 1, which is at index 2. After this operation, the string becomes "abc". Any further operation we perform on the string will leave it unchanged. Therefore, the length of the minimized string is 3.
```

**Example 2:**

```

**Input:** s = "cbbd"
**Output:** 3
**Explanation:** For this we can start with character 'b' at index 1. There is no occurrence of 'b' to the left of index 1, but there is one to the right at index 2, so we delete the 'b' at index 2. The string becomes "cbd" and further operations will leave it unchanged. Hence, the minimized length is 3.

```

**Example 3:**

```

**Input:** s = "dddaaa"
**Output:** 2
**Explanation:** For this, we can start with the character 'd' at index 1. The closest occurrence of a 'd' to its left is at index 0, and the closest occurrence of a 'd' to its right is at index 2. We delete both index 0 and 2, so the string becomes "daaa". In the new string, we can select the character 'a' at index 2. The closest occurrence of an 'a' to its left is at index 1, and the closest occurrence of an 'a' to its right is at index 3. We delete both of them, and the string becomes "da". We cannot minimize this further, so the minimized length is 2.

```

**Constraints:**

* `1 <= s.length <= 100`
* `s` contains only lowercase English letters

Please make sure your answer follows the type signature below:

```python3
class Solution:
    def minimizedStringLength(self, s: str) -> int:
```

my_solution = Solution()

assert my_solution.minimizedStringLength(**['aaabc']) == 3
assert my_solution.minimizedStringLength(**['cbbd']) == 3
assert my_solution.minimizedStringLength(**['dddaaa']) == 2
assert my_solution.minimizedStringLength(**['a']) == 1
assert my_solution.minimizedStringLength(**['b']) == 1
assert my_solution.minimizedStringLength(**['c']) == 1
assert my_solution.minimizedStringLength(**['d']) == 1
assert my_solution.minimizedStringLength(**['e']) == 1
assert my_solution.minimizedStringLength(**['f']) == 1
assert my_solution.minimizedStringLength(**['g']) == 1
assert my_solution.minimizedStringLength(**['h']) == 1
assert my_solution.minimizedStringLength(**['i']) == 1
assert my_solution.minimizedStringLength(**['j']) == 1
assert my_solution.minimizedStringLength(**['k']) == 1
assert my_solution.minimizedStringLength(**['l']) == 1
assert my_solution.minimizedStringLength(**['m']) == 1
assert my_solution.minimizedStringLength(**['n']) == 1
assert my_solution.minimizedStringLength(**['o']) == 1
assert my_solution.minimizedStringLength(**['p']) == 1
assert my_solution.minimizedStringLength(**['q']) == 1


# Semi-Ordered Permutation

You are given a **0-indexed** permutation of `n` integers `nums`.

A permutation is called **semi-ordered** if the first number equals `1` and the last number equals `n`. You can perform the below operation as many times as you want until you make `nums` a **semi-ordered** permutation:

* Pick two adjacent elements in `nums`, then swap them.

Return *the minimum number of operations to make* `nums` *a **semi-ordered permutation***.

A **permutation** is a sequence of integers from `1` to `n` of length `n` containing each number exactly once.

**Example 1:**

```

**Input:** nums = [2,1,4,3]
**Output:** 2
**Explanation:** We can make the permutation semi-ordered using these sequence of operations:
1 - swap i = 0 and j = 1. The permutation becomes [1,2,4,3].
2 - swap i = 2 and j = 3. The permutation becomes [1,2,3,4].
It can be proved that there is no sequence of less than two operations that make nums a semi-ordered permutation.

```

**Example 2:**

```

**Input:** nums = [2,4,1,3]
**Output:** 3
**Explanation:** We can make the permutation semi-ordered using these sequence of operations:
1 - swap i = 1 and j = 2. The permutation becomes [2,1,4,3].
2 - swap i = 0 and j = 1. The permutation becomes [1,2,4,3].
3 - swap i = 2 and j = 3. The permutation becomes [1,2,3,4].
It can be proved that there is no sequence of less than three operations that make nums a semi-ordered permutation.

```

**Example 3:**

```

**Input:** nums = [1,3,4,2,5]
**Output:** 0
**Explanation:** The permutation is already a semi-ordered permutation.

```

**Constraints:**

* `2 <= nums.length == n <= 50`
* `1 <= nums[i] <= 50`
* `nums is a permutation.`

Please make sure your answer follows the type signature below:

```python3
class Solution:
    def semiOrderedPermutation(self, nums: List[int]) -> int:
```

my_solution = Solution()

assert my_solution.semiOrderedPermutation(**[[2, 1, 4, 3]]) == 2
assert my_solution.semiOrderedPermutation(**[[2, 4, 1, 3]]) == 3
assert my_solution.semiOrderedPermutation(**[[1, 3, 4, 2, 5]]) == 0
assert my_solution.semiOrderedPermutation(**[[1, 2]]) == 0
assert my_solution.semiOrderedPermutation(**[[2, 1]]) == 1
assert my_solution.semiOrderedPermutation(**[[1, 2, 3]]) == 0
assert my_solution.semiOrderedPermutation(**[[2, 1, 3]]) == 1
assert my_solution.semiOrderedPermutation(**[[2, 3, 1]]) == 2
assert my_solution.semiOrderedPermutation(**[[1, 3, 2]]) == 1
assert my_solution.semiOrderedPermutation(**[[3, 1, 2]]) == 2
assert my_solution.semiOrderedPermutation(**[[3, 2, 1]]) == 3
assert my_solution.semiOrderedPermutation(**[[1, 2, 3, 4]]) == 0
assert my_solution.semiOrderedPermutation(**[[2, 1, 3, 4]]) == 1
assert my_solution.semiOrderedPermutation(**[[2, 3, 1, 4]]) == 2
assert my_solution.semiOrderedPermutation(**[[2, 3, 4, 1]]) == 3
assert my_solution.semiOrderedPermutation(**[[1, 3, 2, 4]]) == 0
assert my_solution.semiOrderedPermutation(**[[3, 1, 2, 4]]) == 1
assert my_solution.semiOrderedPermutation(**[[3, 2, 1, 4]]) == 2
assert my_solution.semiOrderedPermutation(**[[3, 2, 4, 1]]) == 3
assert my_solution.semiOrderedPermutation(**[[1, 3, 4, 2]]) == 1


# Count of Integers

You are given two numeric strings `num1` and `num2` and two integers `max_sum` and `min_sum`. We denote an integer `x` to be *good* if:

* `num1 <= x <= num2`
* `min_sum <= digit_sum(x) <= max_sum`.

Return *the number of good integers*. Since the answer may be large, return it modulo `109 + 7`.

Note that `digit_sum(x)` denotes the sum of the digits of `x`.

**Example 1:**

```

**Input:** num1 = "1", num2 = "12", min_sum = 1, max_sum = 8
**Output:** 11
**Explanation:** There are 11 integers whose sum of digits lies between 1 and 8 are 1,2,3,4,5,6,7,8,10,11, and 12. Thus, we return 11.

```

**Example 2:**

```

**Input:** num1 = "1", num2 = "5", min_sum = 1, max_sum = 5
**Output:** 5
**Explanation:** The 5 integers whose sum of digits lies between 1 and 5 are 1,2,3,4, and 5. Thus, we return 5.

```

**Constraints:**

* `1 <= num1 <= num2 <= 1022`
* `1 <= min_sum <= max_sum <= 400`

Please make sure your answer follows the type signature below:

```python3
class Solution:
    def count(self, num1: str, num2: str, min_sum: int, max_sum: int) -> int:
```


# Remove Trailing Zeros From a String

Given a **positive** integer `num` represented as a string, return *the integer* `num` *without trailing zeros as a string*.

**Example 1:**

```

**Input:** num = "51230100"
**Output:** "512301"
**Explanation:** Integer "51230100" has 2 trailing zeros, we remove them and return integer "512301".

```

**Example 2:**

```

**Input:** num = "123"
**Output:** "123"
**Explanation:** Integer "123" has no trailing zeros, we return integer "123".

```

**Constraints:**

* `1 <= num.length <= 1000`
* `num` consists of only digits.
* `num` doesn't have any leading zeros.

Please make sure your answer follows the type signature below:

```python3
class Solution:
    def removeTrailingZeros(self, num: str) -> str:
```


# Minimum Cost to Make All Characters Equal

You are given a **0-indexed** binary string `s` of length `n` on which you can apply two types of operations:

* Choose an index `i` and invert all characters from index `0` to index `i` (both inclusive), with a cost of `i + 1`
* Choose an index `i` and invert all characters from index `i` to index `n - 1` (both inclusive), with a cost of `n - i`

Return *the **minimum cost** to make all characters of the string **equal***.

**Invert** a character means if its value is '0' it becomes '1' and vice-versa.

**Example 1:**

```

**Input:** s = "0011"
**Output:** 2
**Explanation:** Apply the second operation with i = 2 to obtain s = "0000" for a cost of 2. It can be shown that 2 is the minimum cost to make all characters equal.

```

**Example 2:**

```

**Input:** s = "010101"
**Output:** 9
**Explanation:** Apply the first operation with i = 2 to obtain s = "101101" for a cost of 3.
Apply the first operation with i = 1 to obtain s = "011101" for a cost of 2.
Apply the first operation with i = 0 to obtain s = "111101" for a cost of 1.
Apply the second operation with i = 4 to obtain s = "111110" for a cost of 2.
Apply the second operation with i = 5 to obtain s = "111111" for a cost of 1.
The total cost to make all characters equal is 9. It can be shown that 9 is the minimum cost to make all characters equal.

```

**Constraints:**

* `1 <= s.length == n <= 105`
* `s[i]` is either `'0'` or `'1'`

Please make sure your answer follows the type signature below:

```python3
class Solution:
    def minimumCost(self, s: str) -> int:
```

my_solution = Solution()

assert my_solution.minimumCost(**['0011']) == 2
assert my_solution.minimumCost(**['010101']) == 9
assert my_solution.minimumCost(**['0']) == 0
assert my_solution.minimumCost(**['00']) == 0
assert my_solution.minimumCost(**['000']) == 0
assert my_solution.minimumCost(**['0000']) == 0
assert my_solution.minimumCost(**['00000']) == 0
assert my_solution.minimumCost(**['000000']) == 0
assert my_solution.minimumCost(**['0000000']) == 0
assert my_solution.minimumCost(**['00000000']) == 0
assert my_solution.minimumCost(**['000000000']) == 0
assert my_solution.minimumCost(**['000000001']) == 1
assert my_solution.minimumCost(**['00000001']) == 1
assert my_solution.minimumCost(**['000000010']) == 3
assert my_solution.minimumCost(**['000000011']) == 2
assert my_solution.minimumCost(**['0000001']) == 1
assert my_solution.minimumCost(**['00000010']) == 3
assert my_solution.minimumCost(**['000000100']) == 5
assert my_solution.minimumCost(**['000000101']) == 6
assert my_solution.minimumCost(**['00000011']) == 2


# Buy Two Chocolates

You are given an integer array `prices` representing the prices of various chocolates in a store. You are also given a single integer `money`, which represents your initial amount of money.

You must buy **exactly** two chocolates in such a way that you still have some **non-negative** leftover money. You would like to minimize the sum of the prices of the two chocolates you buy.

Return *the amount of money you will have leftover after buying the two chocolates*. If there is no way for you to buy two chocolates without ending up in debt, return `money`. Note that the leftover must be non-negative.

**Example 1:**

```

**Input:** prices = [1,2,2], money = 3
**Output:** 0
**Explanation:** Purchase the chocolates priced at 1 and 2 units respectively. You will have 3 - 3 = 0 units of money afterwards. Thus, we return 0.

```

**Example 2:**

```

**Input:** prices = [3,2,3], money = 3
**Output:** 3
**Explanation:** You cannot buy 2 chocolates without going in debt, so we return 3.

```

**Constraints:**

* `2 <= prices.length <= 50`
* `1 <= prices[i] <= 100`
* `1 <= money <= 100`

Please make sure your answer follows the type signature below:

```python3
class Solution:
    def buyChoco(self, prices: List[int], money: int) -> int:
```


# Extra Characters in a String

You are given a **0-indexed** string `s` and a dictionary of words `dictionary`. You have to break `s` into one or more **non-overlapping** substrings such that each substring is present in `dictionary`. There may be some **extra characters** in `s` which are not present in any of the substrings.

Return *the **minimum** number of extra characters left over if you break up* `s` *optimally.*

**Example 1:**

```

**Input:** s = "leetscode", dictionary = ["leet","code","leetcode"]
**Output:** 1
**Explanation:** We can break s in two substrings: "leet" from index 0 to 3 and "code" from index 5 to 8. There is only 1 unused character (at index 4), so we return 1.

```

**Example 2:**

```

**Input:** s = "sayhelloworld", dictionary = ["hello","world"]
**Output:** 3
**Explanation:** We can break s in two substrings: "hello" from index 3 to 7 and "world" from index 8 to 12. The characters at indices 0, 1, 2 are not used in any substring and thus are considered as extra characters. Hence, we return 3.

```

**Constraints:**

* `1 <= s.length <= 50`
* `1 <= dictionary.length <= 50`
* `1 <= dictionary[i].length <= 50`
* `dictionary[i]` and `s` consists of only lowercase English letters
* `dictionary` contains distinct words

Please make sure your answer follows the type signature below:

```python3
class Solution:
    def minExtraChar(self, s: str, dictionary: List[str]) -> int:
```

my_solution = Solution()

assert my_solution.minExtraChar(**['leetscode', ['leet', 'code', 'leetcode']]) == 1
assert my_solution.minExtraChar(**['sayhelloworld', ['hello', 'world']]) == 3
assert my_solution.minExtraChar(**['dwmodizxvvbosxxw', ['ox', 'lb', 'diz', 'gu', 'v', 'ksv', 'o', 'nuq', 'r', 'txhe', 'e', 'wmo', 'cehy', 'tskz', 'ds', 'kzbu']]) == 7
assert my_solution.minExtraChar(**['ecolloycollotkvzqpdaumuqgs', ['flbri', 'uaaz', 'numy', 'laper', 'ioqyt', 'tkvz', 'ndjb', 'gmg', 'gdpbo', 'x', 'collo', 'vuh', 'qhozp', 'iwk', 'paqgn', 'm', 'mhx', 'jgren', 'qqshd', 'qr', 'qpdau', 'oeeuq', 'c', 'qkot', 'uxqvx', 'lhgid', 'vchsk', 'drqx', 'keaua', 'yaru', 'mla', 'shz', 'lby', 'vdxlv', 'xyai', 'lxtgl', 'inz', 'brhi', 'iukt', 'f', 'lbjou', 'vb', 'sz', 'ilkra', 'izwk', 'muqgs', 'gom', 'je']]) == 2
assert my_solution.minExtraChar(**['eglglxa', ['rs', 'j', 'h', 'g', 'fy', 'l', 'fc', 's', 'zf', 'i', 'k', 'x', 'gl', 'qr', 'qj', 'b', 'm', 'cm', 'pe', 'y', 'ei', 'wg', 'e', 'c', 'll', 'u', 'lb', 'kc', 'r', 'gs', 'p', 'ga', 'pq', 'o', 'wq', 'mp', 'ms', 'vp', 'kg', 'cu']]) == 1
assert my_solution.minExtraChar(**['kngmktvcxrwubjzk', ['ktvc', 'pajp', 'x', 'emye', 'hde', 'haol', 'ubjz', 'tc', 'rb', 'kng', 'li', 'fph', 'd', 'rgrg']]) == 4
assert my_solution.minExtraChar(**['voctvochpgutoywpnafylzelqsnzsbandjcqdciyoefi', ['tf', 'v', 'wadrya', 'a', 'cqdci', 'uqfg', 'voc', 'zelqsn', 'band', 'b', 'yoefi', 'utoywp', 'herqqn', 'umra', 'frfuyj', 'vczatj', 'sdww']]) == 11
assert my_solution.minExtraChar(**['nwlztjn', ['a', 'f', 'v', 'me', 'm', 'bv', 'g', 'ss', 'tu', 'jm', 'z', 'kg', 'l', 'go', 'cn', 'uj', 'kx', 'w', 'qz', 'e', 'ut', 'tf', 'zn', 'ha', 'ke', 'af', 'aj', 'ls', 'r', 'no', 'pm', 'qn', 'yw', 'cs', 'oz', 'b']]) == 4
assert my_solution.minExtraChar(**['smsvy', ['j', 'p', 'y', 'r', 't', 'nj', 'k', 'xj', 'vg', 'da', 'm', 'u', 'yq', 'as', 'wh', 'b', 'vo', 'h', 'wb', 'z', 'np', 'uy', 'i', 'f', 'w', 'wg', 's', 'ls', 'xf', 'ou', 'mj', 'pf']]) == 1
assert my_solution.minExtraChar(**['azchrwjli', ['nrd', 'ulh', 'r', 'u', 'm', 'ue', 'jzd', 'zch', 'pbl', 'op', 'mw', 'wjl', 'wv', 'e']]) == 2
assert my_solution.minExtraChar(**['octncmdbgnxapjoqlofuzypthlytkmchayflwky', ['m', 'its', 'imaby', 'pa', 'ijmnvj', 'k', 'mhka', 'n', 'y', 'nc', 'wq', 'p', 'mjqqa', 'ht', 'dfoa', 'yqa', 'kk', 'pixq', 'ixsdln', 'rh', 'dwl', 'dbgnxa', 'kmpfz', 'nhxjm', 'wg', 'wky', 'oct', 'og', 'uhin', 'zxb', 'qz', 'tpf', 'hlrc', 'j', 'l', 'tew', 'xbn', 'a', 'uzypt', 'uvln', 'mchay', 'onnbi', 'hlytk', 'pjoqlo', 'dxsjr', 'u', 'uj']]) == 2
assert my_solution.minExtraChar(**['rqdrlfpthqkevauuks', ['pt', 'r', 'luet', 'hn', 'djj', 'nqk', 'yztb', 'yvrm', 'hjw', 'fon', 'hqke', 'btr', 'fg', 'guo', 'un', 'eyl', 'x', 'b', 'wj', 'yzy', 'dpj', 'z', 'oj', 'uu', 'fmp', 'ypmv', 'qd', 'rz', 'efj', 'sfc']]) == 6
assert my_solution.minExtraChar(**['etzdfxoxyajiothfsxxcxoxhfsxxcbvfmtcibmjkhniq', ['nio', 'y', 'jkhni', 'bu', 'hfsxxc', 'iacjvr', 'xox', 'vrslt', 'bvfm', 'gi', 'tjazf', 'ipfexh', 'tcib', 'crx', 'umxvs', 'q', 'e', 'rlpgq']]) == 10
assert my_solution.minExtraChar(**['t', ['q', 'f', 'b', 's', 'k', 't', 'p', 'i', 'o', 'v', 'l', 'u', 'c', 'm', 'r', 'd', 'g', 'e', 'j', 'h', 'y']]) == 0
assert my_solution.minExtraChar(**['cmizgedmufhbnqge', ['yid', 'u', 'jii', 'rdg', 'zcy', 'uo', 'buy', 's', 'vhn', 'ae', 'fygs', 'vlw', 'hv', 'nqge', 'fhb', 'oh', 'm', 'z', 't', 'rqwf', 'iqp', 'xan', 'ir', 'cmi', 'bim', 'bbd', 'jf', 'gs', 'vj']]) == 3
assert my_solution.minExtraChar(**['ybo', ['k', 'w', 'n', 's', 'v', 'i', 'q', 'j', 'h', 'o', 't', 'y', 'g', 'e', 'z', 'a', 'c', 'x', 'd', 'l', 'f']]) == 1
assert my_solution.minExtraChar(**['msgaxldzkgi', ['ax', 'ms', 'hvb', 'w', 'z', 'ajc', 'ti', 'cn', 'x', 'j', 'gi', 'r', 'nj', 'f', 'xr', 'iuz', 'ya', 'gty', 'hgs', 'ug', 'mfv', 'bw', 'vr', 'oe', 'xv', 'jf', 'vy', 'q', 'qf', 'oo', 'iq', 't', 'v', 'htx', 'g', 'gjp', 'dis', 'gt', 'gv', 'wu', 'vtx', 'cmo', 'wdl', 'b']]) == 3
assert my_solution.minExtraChar(**['jztkzefkuhgldeuxumtecjfhwkumklktbvoefjzgbvoebvoeo', ['tkzef', 'teq', 'idx', 'czset', 'jfh', 'fjz', 'nij', 'hpr', 'rhijyw', 'bvoe', 'k', 'umklkt', 'szbescz', 'pyiri', 'bc', 'fzyzcgc', 'lf', 's', 'kxalcws', 'w', 'euxumt', 'hlroawe', 'yvoyx', 'ucvzmc', 'blr', 'piasks', 'fblc']]) == 11
assert my_solution.minExtraChar(**['pkfydgpkffmfam', ['pk', 'f', 'kdy', 'tw', 'm']]) == 4
assert my_solution.minExtraChar(**['pucblaexghipwhcfkhwawsuszagdlajctwevqiccnqpyt', ['pyvu', 'vt', 'it', 'jc', 'ex', 'zmn', 'qahtts', 'c', 'q', 'jlui', 'zx', 'gt', 'djb', 'ywdyt', 'dc', 'fhw', 'ninhz', 'vqic', 'ern', 'dwzyiq', 'cvh', 'ualv', 'jgmal', 'soj', 'khwaw', 'zejzs', 'cjqrt', 'la', 'pucb', 'uc', 'ezqcsl', 'uxx', 'pvz', 'uownow', 'f', 'ipwhcf', 'us', 'cx', 'k']]) == 14

ox lb diz gu v ksv o nuq r txhe e wmo cehy tskz ds kzbu

flbri uaaz numy laper ioqyt tkvz ndjb gmg gdpbo x collo vuh qhozp iwk paqgn m mhx jgren qqshd qr qpdau oeeuq c qkot uxqvx lhgid vchsk drqx keaua yaru mla shz lby vdxlv xyai lxtgl inz brhi iukt f lbjou vb sz ilkra izwk muqgs gom je

rs j h g fy l fc s zf i k x gl qr qj b m cm pe y ei wg e c ll u lb kc r gs p ga pq o wq mp ms vp kg cu

ktvc pajp x emye hde haol ubjz tc rb kng li fph d rgrg

tf v wadrya a cqdci uqfg voc zelqsn band b yoefi utoywp herqqn umra frfuyj vczatj sdww

a f v me m bv g ss tu jm z kg l go cn uj kx w qz e ut tf zn ha ke af aj ls r no pm qn yw cs oz b

j p y r t nj k xj vg da m u yq as wh b vo h wb z np uy i f w wg s ls xf ou mj pf

nrd ulh r u m ue jzd zch pbl op mw wjl wv e

m its imaby pa ijmnvj k mhka n y nc wq p mjqqa ht dfoa yqa kk pixq ixsdln rh dwl dbgnxa kmpfz nhxjm wg wky oct og uhin zxb qz tpf hlrc j l tew xbn a uzypt uvln mchay onnbi hlytk pjoqlo dxsjr u uj

pt r luet hn djj nqk yztb yvrm hjw fon hqke btr fg guo un eyl x b wj yzy dpj z oj uu fmp ypmv qd rz efj sfc

nio y jkhni bu hfsxxc iacjvr xox vrslt bvfm gi tjazf ipfexh tcib crx umxvs q e rlpgq

q f b s k t p i o v l u c m r d g e j h y

yid u jii rdg zcy uo buy s vhn ae fygs vlw hv nqge fhb oh m z t rqwf iqp xan ir cmi bim bbd jf gs vj

k w n s v i q j h o t y g e z a c x d l f

ax ms hvb w z ajc ti cn x j gi r nj f xr iuz ya gty hgs ug mfv bw vr oe xv jf vy q qf oo iq t v htx g gjp dis gt gv wu vtx cmo wdl b

tkzef teq idx czset jfh fjz nij hpr rhijyw bvoe k umklkt szbescz pyiri bc fzyzcgc lf s kxalcws w euxumt hlroawe yvoyx ucvzmc blr piasks fblc

pyvu vt it jc ex zmn qahtts c q jlui zx gt djb ywdyt dc fhw ninhz vqic ern dwzyiq cvh ualv jgmal soj khwaw zejzs cjqrt la pucb uc ezqcsl uxx pvz uownow f ipwhcf us cx k


# Maximum Strength of a Group

You are given a **0-indexed** integer array `nums` representing the score of students in an exam. The teacher would like to form one **non-empty** group of students with maximal **strength**, where the strength of a group of students of indices `i0`, `i1`, `i2`, ... , `ik` is defined as `nums[i0] * nums[i1] * nums[i2] * ... * nums[ik]`.

Return *the maximum strength of a group the teacher can create*.

**Example 1:**

```

**Input:** nums = [3,-1,-5,2,5,-9]
**Output:** 1350
**Explanation:** One way to form a group of maximal strength is to group the students at indices [0,2,3,4,5]. Their strength is 3 * (-5) * 2 * 5 * (-9) = 1350, which we can show is optimal.

```

**Example 2:**

```

**Input:** nums = [-4,-5,-4]
**Output:** 20
**Explanation:** Group the students at indices [0, 1] . Then, we’ll have a resulting strength of 20. We cannot achieve greater strength.

```

**Constraints:**

* `1 <= nums.length <= 13`
* `-9 <= nums[i] <= 9`

Please make sure your answer follows the type signature below:

```python3
class Solution:
    def maxStrength(self, nums: List[int]) -> int:
```


# Greatest Common Divisor Traversal

You are given a **0-indexed** integer array `nums`, and you are allowed to **traverse** between its indices. You can traverse between index `i` and index `j`, `i != j`, if and only if `gcd(nums[i], nums[j]) > 1`, where `gcd` is the **greatest common divisor**.

Your task is to determine if for **every pair** of indices `i` and `j` in nums, where `i < j`, there exists a **sequence of traversals** that can take us from `i` to `j`.

Return `true` *if it is possible to traverse between all such pairs of indices,* *or* `false` *otherwise.*

**Example 1:**

```

**Input:** nums = [2,3,6]
**Output:** true
**Explanation:** In this example, there are 3 possible pairs of indices: (0, 1), (0, 2), and (1, 2).
To go from index 0 to index 1, we can use the sequence of traversals 0 -> 2 -> 1, where we move from index 0 to index 2 because gcd(nums[0], nums[2]) = gcd(2, 6) = 2 > 1, and then move from index 2 to index 1 because gcd(nums[2], nums[1]) = gcd(6, 3) = 3 > 1.
To go from index 0 to index 2, we can just go directly because gcd(nums[0], nums[2]) = gcd(2, 6) = 2 > 1. Likewise, to go from index 1 to index 2, we can just go directly because gcd(nums[1], nums[2]) = gcd(3, 6) = 3 > 1.

```

**Example 2:**

```

**Input:** nums = [3,9,5]
**Output:** false
**Explanation:** No sequence of traversals can take us from index 0 to index 2 in this example. So, we return false.

```

**Example 3:**

```

**Input:** nums = [4,3,12,8]
**Output:** true
**Explanation:** There are 6 possible pairs of indices to traverse between: (0, 1), (0, 2), (0, 3), (1, 2), (1, 3), and (2, 3). A valid sequence of traversals exists for each pair, so we return true.

```

**Constraints:**

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

Please make sure your answer follows the type signature below:

```python3
class Solution:
    def canTraverseAllPairs(self, nums: List[int]) -> bool:
```

my_solution = Solution()

assert my_solution.canTraverseAllPairs(**[[2, 3, 6]]) == True
assert my_solution.canTraverseAllPairs(**[[3, 9, 5]]) == False
assert my_solution.canTraverseAllPairs(**[[4, 3, 12, 8]]) == True
assert my_solution.canTraverseAllPairs(**[[10]]) == True
assert my_solution.canTraverseAllPairs(**[[11]]) == True
assert my_solution.canTraverseAllPairs(**[[14]]) == True
assert my_solution.canTraverseAllPairs(**[[20]]) == True
assert my_solution.canTraverseAllPairs(**[[28]]) == True
assert my_solution.canTraverseAllPairs(**[[30]]) == True
assert my_solution.canTraverseAllPairs(**[[35]]) == True
assert my_solution.canTraverseAllPairs(**[[42]]) == True
assert my_solution.canTraverseAllPairs(**[[44]]) == True
assert my_solution.canTraverseAllPairs(**[[98]]) == True
assert my_solution.canTraverseAllPairs(**[[20, 6]]) == True
assert my_solution.canTraverseAllPairs(**[[28, 39]]) == False
assert my_solution.canTraverseAllPairs(**[[30, 14]]) == True
assert my_solution.canTraverseAllPairs(**[[30, 30]]) == True
assert my_solution.canTraverseAllPairs(**[[33, 60]]) == True
assert my_solution.canTraverseAllPairs(**[[35, 26]]) == False
assert my_solution.canTraverseAllPairs(**[[42, 42]]) == True


# Minimum String Length After Removing Substrings

You are given a string `s` consisting only of **uppercase** English letters.

You can apply some operations to this string where, in one operation, you can remove **any** occurrence of one of the substrings `"AB"` or `"CD"` from `s`.

Return *the **minimum** possible length of the resulting string that you can obtain*.

**Note** that the string concatenates after removing the substring and could produce new `"AB"` or `"CD"` substrings.

**Example 1:**

```

**Input:** s = "ABFCACDB"
**Output:** 2
**Explanation:** We can do the following operations:
- Remove the substring "ABFCACDB", so s = "FCACDB".
- Remove the substring "FCACDB", so s = "FCAB".
- Remove the substring "FCAB", so s = "FC".
So the resulting length of the string is 2.
It can be shown that it is the minimum length that we can obtain.
```

**Example 2:**

```

**Input:** s = "ACBBD"
**Output:** 5
**Explanation:** We cannot do any operations on the string so the length remains the same.

```

**Constraints:**

* `1 <= s.length <= 100`
* `s` consists only of uppercase English letters.

Please make sure your answer follows the type signature below:

```python3
class Solution:
    def minLength(self, s: str) -> int:
```

my_solution = Solution()

assert my_solution.minLength(**['ABFCACDB']) == 2
assert my_solution.minLength(**['ACBBD']) == 5
assert my_solution.minLength(**['A']) == 1
assert my_solution.minLength(**['D']) == 1
assert my_solution.minLength(**['Z']) == 1
assert my_solution.minLength(**['CCCCDDDD']) == 0
assert my_solution.minLength(**['AATQCABDCBE']) == 7
assert my_solution.minLength(**['ZKPT']) == 4
assert my_solution.minLength(**['CCDDACDB']) == 0
assert my_solution.minLength(**['EUO']) == 3
assert my_solution.minLength(**['ABG']) == 1
assert my_solution.minLength(**['FACDHM']) == 4
assert my_solution.minLength(**['WCCDD']) == 1
assert my_solution.minLength(**['CCDDLLDW']) == 4
assert my_solution.minLength(**['GYCD']) == 2
assert my_solution.minLength(**['CABDCABDAB']) == 0
assert my_solution.minLength(**['ZCABDRIL']) == 4
assert my_solution.minLength(**['P']) == 1
assert my_solution.minLength(**['L']) == 1
assert my_solution.minLength(**['BQHSABE']) == 5