# Find Indices With Index and Value Difference I

You are given a **0-indexed** integer array `nums` having length `n`, an integer `indexDifference`, and an integer `valueDifference`.

Your task is to find **two** indices `i` and `j`, both in the range `[0, n - 1]`, that satisfy the following conditions:

* `abs(i - j) >= indexDifference`, and
* `abs(nums[i] - nums[j]) >= valueDifference`

Return *an integer array* `answer`, *where* `answer = [i, j]` *if there are two such indices*, *and* `answer = [-1, -1]` *otherwise*. If there are multiple choices for the two indices, return *any of them*.

**Note:** `i` and `j` may be **equal**.

**Example 1:**

```

**Input:** nums = [5,1,4,1], indexDifference = 2, valueDifference = 4
**Output:** [0,3]
**Explanation:** In this example, i = 0 and j = 3 can be selected.
abs(0 - 3) >= 2 and abs(nums[0] - nums[3]) >= 4.
Hence, a valid answer is [0,3].
[3,0] is also a valid answer.

```

**Example 2:**

```

**Input:** nums = [2,1], indexDifference = 0, valueDifference = 0
**Output:** [0,0]
**Explanation:** In this example, i = 0 and j = 0 can be selected.
abs(0 - 0) >= 0 and abs(nums[0] - nums[0]) >= 0.
Hence, a valid answer is [0,0].
Other valid answers are [0,1], [1,0], and [1,1].

```

**Example 3:**

```

**Input:** nums = [1,2,3], indexDifference = 2, valueDifference = 4
**Output:** [-1,-1]
**Explanation:** In this example, it can be shown that it is impossible to find two indices that satisfy both conditions.
Hence, [-1,-1] is returned.
```

**Constraints:**

* `1 <= n == nums.length <= 100`
* `0 <= nums[i] <= 50`
* `0 <= indexDifference <= 100`
* `0 <= valueDifference <= 50`

Please make sure your answer follows the type signature below:

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

my_solution = Solution()

assert my_solution.findIndices(**[[5, 1, 4, 1], 2, 4]) == [0, 3]
assert my_solution.findIndices(**[[2, 1], 0, 0]) == [0, 0]
assert my_solution.findIndices(**[[1, 2, 3], 2, 4]) == [-1, -1]
assert my_solution.findIndices(**[[0], 0, 0]) == [0, 0]
assert my_solution.findIndices(**[[3], 0, 0]) == [0, 0]
assert my_solution.findIndices(**[[3], 1, 1]) == [-1, -1]
assert my_solution.findIndices(**[[4], 1, 0]) == [-1, -1]
assert my_solution.findIndices(**[[5], 1, 3]) == [-1, -1]
assert my_solution.findIndices(**[[7], 1, 7]) == [-1, -1]
assert my_solution.findIndices(**[[8], 0, 2]) == [-1, -1]
assert my_solution.findIndices(**[[8], 1, 7]) == [-1, -1]
assert my_solution.findIndices(**[[10], 0, 9]) == [-1, -1]
assert my_solution.findIndices(**[[11], 1, 0]) == [-1, -1]
assert my_solution.findIndices(**[[18], 1, 4]) == [-1, -1]
assert my_solution.findIndices(**[[38], 1, 34]) == [-1, -1]
assert my_solution.findIndices(**[[40], 1, 2]) == [-1, -1]
assert my_solution.findIndices(**[[5, 10], 1, 2]) == [0, 1]
assert my_solution.findIndices(**[[5, 48], 0, 29]) == [0, 1]
assert my_solution.findIndices(**[[6, 3], 1, 2]) == [0, 1]
assert my_solution.findIndices(**[[7, 6], 1, 0]) == [0, 1]


# Shortest and Lexicographically Smallest Beautiful String

You are given a binary string `s` and a positive integer `k`.

A substring of `s` is **beautiful** if the number of `1`'s in it is exactly `k`.

Let `len` be the length of the **shortest** beautiful substring.

Return *the lexicographically **smallest** beautiful substring of string* `s` *with length equal to* `len`. If `s` doesn't contain a beautiful substring, return *an **empty** string*.

A string `a` is lexicographically **larger** than a string `b` (of the same length) if in the first position where `a` and `b` differ, `a` has a character strictly larger than the corresponding character in `b`.

* For example, `"abcd"` is lexicographically larger than `"abcc"` because the first position they differ is at the fourth character, and `d` is greater than `c`.

**Example 1:**

```

**Input:** s = "100011001", k = 3
**Output:** "11001"
**Explanation:** There are 7 beautiful substrings in this example:
1. The substring "100011001".
2. The substring "100011001".
3. The substring "100011001".
4. The substring "100011001".
5. The substring "100011001".
6. The substring "100011001".
7. The substring "100011001".
The length of the shortest beautiful substring is 5.
The lexicographically smallest beautiful substring with length 5 is the substring "11001".

```

**Example 2:**

```

**Input:** s = "1011", k = 2
**Output:** "11"
**Explanation:** There are 3 beautiful substrings in this example:
1. The substring "1011".
2. The substring "1011".
3. The substring "1011".
The length of the shortest beautiful substring is 2.
The lexicographically smallest beautiful substring with length 2 is the substring "11".

```

**Example 3:**

```

**Input:** s = "000", k = 1
**Output:** ""
**Explanation:** There are no beautiful substrings in this example.

```

**Constraints:**

* `1 <= s.length <= 100`
* `1 <= k <= s.length`

Please make sure your answer follows the type signature below:

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

my_solution = Solution()

assert my_solution.shortestBeautifulSubstring(**['100011001', 3]) == 11001
assert my_solution.shortestBeautifulSubstring(**['100011001', 3]) == 11001
assert my_solution.shortestBeautifulSubstring(**['100011001', 3]) == 11001
assert my_solution.shortestBeautifulSubstring(**['100011001', 3]) == 11001
assert my_solution.shortestBeautifulSubstring(**['100011001', 3]) == 11001
assert my_solution.shortestBeautifulSubstring(**['100011001', 3]) == 11001
assert my_solution.shortestBeautifulSubstring(**['100011001', 3]) == 11001
assert my_solution.shortestBeautifulSubstring(**['100011001', 3]) == 11001
assert my_solution.shortestBeautifulSubstring(**['100011001', 3]) == 11001
assert my_solution.shortestBeautifulSubstring(**['100011001', 3]) == 11001
assert my_solution.shortestBeautifulSubstring(**['100011001', 3]) == 11001
assert my_solution.shortestBeautifulSubstring(**['100011001', 3]) == 11001
assert my_solution.shortestBeautifulSubstring(**['100011001', 3]) == 11001
assert my_solution.shortestBeautifulSubstring(**['100011001', 3]) == 11001
assert my_solution.shortestBeautifulSubstring(**['100011001', 3]) == 11001
assert my_solution.shortestBeautifulSubstring(**['100011001', 3]) == 11001
assert my_solution.shortestBeautifulSubstring(**['100011001', 3]) == 11001
assert my_solution.shortestBeautifulSubstring(**['100011001', 3]) == 11001
assert my_solution.shortestBeautifulSubstring(**['100011001', 3]) == 11001
assert my_solution.shortestBeautifulSubstring(**['100011001', 3]) == 11001


# Find Indices With Index and Value Difference II

You are given a **0-indexed** integer array `nums` having length `n`, an integer `indexDifference`, and an integer `valueDifference`.

Your task is to find **two** indices `i` and `j`, both in the range `[0, n - 1]`, that satisfy the following conditions:

* `abs(i - j) >= indexDifference`, and
* `abs(nums[i] - nums[j]) >= valueDifference`

Return *an integer array* `answer`, *where* `answer = [i, j]` *if there are two such indices*, *and* `answer = [-1, -1]` *otherwise*. If there are multiple choices for the two indices, return *any of them*.

**Note:** `i` and `j` may be **equal**.

**Example 1:**

```

**Input:** nums = [5,1,4,1], indexDifference = 2, valueDifference = 4
**Output:** [0,3]
**Explanation:** In this example, i = 0 and j = 3 can be selected.
abs(0 - 3) >= 2 and abs(nums[0] - nums[3]) >= 4.
Hence, a valid answer is [0,3].
[3,0] is also a valid answer.

```

**Example 2:**

```

**Input:** nums = [2,1], indexDifference = 0, valueDifference = 0
**Output:** [0,0]
**Explanation:** In this example, i = 0 and j = 0 can be selected.
abs(0 - 0) >= 0 and abs(nums[0] - nums[0]) >= 0.
Hence, a valid answer is [0,0].
Other valid answers are [0,1], [1,0], and [1,1].

```

**Example 3:**

```

**Input:** nums = [1,2,3], indexDifference = 2, valueDifference = 4
**Output:** [-1,-1]
**Explanation:** In this example, it can be shown that it is impossible to find two indices that satisfy both conditions.
Hence, [-1,-1] is returned.
```

**Constraints:**

* `1 <= n == nums.length <= 105`
* `0 <= nums[i] <= 109`
* `0 <= indexDifference <= 105`
* `0 <= valueDifference <= 109`

Please make sure your answer follows the type signature below:

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

my_solution = Solution()

assert my_solution.findIndices(**[[5, 1, 4, 1], 2, 4]) == [0, 3]
assert my_solution.findIndices(**[[2, 1], 0, 0]) == [0, 0]
assert my_solution.findIndices(**[[1, 2, 3], 2, 4]) == [-1, -1]
assert my_solution.findIndices(**[[1], 0, 1]) == [-1, -1]
assert my_solution.findIndices(**[[1], 1, 0]) == [-1, -1]
assert my_solution.findIndices(**[[2], 0, 2]) == [-1, -1]
assert my_solution.findIndices(**[[6], 1, 4]) == [-1, -1]
assert my_solution.findIndices(**[[7], 0, 0]) == [0, 0]
assert my_solution.findIndices(**[[8], 1, 6]) == [-1, -1]
assert my_solution.findIndices(**[[9], 0, 1]) == [-1, -1]
assert my_solution.findIndices(**[[9], 1, 9]) == [-1, -1]
assert my_solution.findIndices(**[[12], 0, 5]) == [-1, -1]
assert my_solution.findIndices(**[[16], 0, 16]) == [-1, -1]
assert my_solution.findIndices(**[[16], 1, 6]) == [-1, -1]
assert my_solution.findIndices(**[[46], 0, 36]) == [-1, -1]
assert my_solution.findIndices(**[[0, 10], 2, 4]) == [-1, -1]
assert my_solution.findIndices(**[[2, 7], 2, 7]) == [-1, -1]
assert my_solution.findIndices(**[[5, 1], 2, 5]) == [-1, -1]
assert my_solution.findIndices(**[[5, 12], 0, 10]) == [-1, -1]
assert my_solution.findIndices(**[[8, 0], 1, 7]) == [0, 1]


# Construct Product Matrix

Given a **0-indexed** 2D integer matrix `grid` of size `n * m`, we define a **0-indexed** 2D matrix `p` of size `n * m` as the **product** matrix of `grid` if the following condition is met:

* Each element `p[i][j]` is calculated as the product of all elements in `grid` except for the element `grid[i][j]`. This product is then taken modulo `12345`.

Return *the product matrix of* `grid`.

**Example 1:**

```

**Input:** grid = [[1,2],[3,4]]
**Output:** [[24,12],[8,6]]
**Explanation:** p[0][0] = grid[0][1] * grid[1][0] * grid[1][1] = 2 * 3 * 4 = 24
p[0][1] = grid[0][0] * grid[1][0] * grid[1][1] = 1 * 3 * 4 = 12
p[1][0] = grid[0][0] * grid[0][1] * grid[1][1] = 1 * 2 * 4 = 8
p[1][1] = grid[0][0] * grid[0][1] * grid[1][0] = 1 * 2 * 3 = 6
So the answer is [[24,12],[8,6]].
```

**Example 2:**

```

**Input:** grid = [[12345],[2],[1]]
**Output:** [[2],[0],[0]]
**Explanation:** p[0][0] = grid[0][1] * grid[0][2] = 2 * 1 = 2.
p[0][1] = grid[0][0] * grid[0][2] = 12345 * 1 = 12345. 12345 % 12345 = 0. So p[0][1] = 0.
p[0][2] = grid[0][0] * grid[0][1] = 12345 * 2 = 24690. 24690 % 12345 = 0. So p[0][2] = 0.
So the answer is [[2],[0],[0]].
```

**Constraints:**

* `1 <= n == grid.length <= 105`
* `1 <= m == grid[i].length <= 105`
* `2 <= n * m <= 105`
* `1 <= grid[i][j] <= 109`

Please make sure your answer follows the type signature below:

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


# Last Visited Integers

Given a **0-indexed** array of strings `words` where `words[i]` is either a positive integer represented as a string or the string `"prev"`.

Start iterating from the beginning of the array; for every `"prev"` string seen in `words`, find the **last visited integer** in `words` which is defined as follows:

* Let `k` be the number of consecutive `"prev"` strings seen so far (containing the current string). Let `nums` be the **0-indexed** array of **integers** seen so far and `nums_reverse` be the reverse of `nums`, then the integer at `(k - 1)th` index of `nums_reverse` will be the **last visited integer** for this `"prev"`.
* If `k` is **greater** than the total visited integers, then the last visited integer will be `-1`.

Return *an integer array containing the last visited integers.*

**Example 1:**

```

**Input:** words = ["1","2","prev","prev","prev"]
**Output:** [2,1,-1]
**Explanation:**
For "prev" at index = 2, last visited integer will be 2 as here the number of consecutive "prev" strings is 1, and in the array reverse_nums, 2 will be the first element.
For "prev" at index = 3, last visited integer will be 1 as there are a total of two consecutive "prev" strings including this "prev" which are visited, and 1 is the second last visited integer.
For "prev" at index = 4, last visited integer will be -1 as there are a total of three consecutive "prev" strings including this "prev" which are visited, but the total number of integers visited is two.

```

**Example 2:**

```

**Input:** words = ["1","prev","2","prev","prev"]
**Output:** [1,2,1]
**Explanation:**
For "prev" at index = 1, last visited integer will be 1.
For "prev" at index = 3, last visited integer will be 2.
For "prev" at index = 4, last visited integer will be 1 as there are a total of two consecutive "prev" strings including this "prev" which are visited, and 1 is the second last visited integer.

```

**Constraints:**

* `1 <= words.length <= 100`
* `words[i] == "prev"` or `1 <= int(words[i]) <= 100`

Please make sure your answer follows the type signature below:

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

my_solution = Solution()

assert my_solution.lastVisitedIntegers(**[['1', '2', 'prev', 'prev', 'prev']]) == [2, 1, -1]
assert my_solution.lastVisitedIntegers(**[['1', 'prev', '2', 'prev', 'prev']]) == [1, 2, 1]
assert my_solution.lastVisitedIntegers(**[['prev', 'prev', 'prev', '27']]) == [-1, -1, -1]
assert my_solution.lastVisitedIntegers(**[['17', '42']]) == []
assert my_solution.lastVisitedIntegers(**[['prev']]) == [-1]
assert my_solution.lastVisitedIntegers(**[['prev', 'prev', 'prev', '52', 'prev']]) == [-1, -1, -1, 52]
assert my_solution.lastVisitedIntegers(**[['prev', 'prev', '68', 'prev', 'prev', '53', '40', '23', 'prev']]) == [-1, -1, 68, -1, 23]
assert my_solution.lastVisitedIntegers(**[['99', '23', 'prev']]) == [23]
assert my_solution.lastVisitedIntegers(**[['prev', 'prev', 'prev', '58', '99', 'prev', '10', 'prev']]) == [-1, -1, -1, 99, 10]
assert my_solution.lastVisitedIntegers(**[['prev', '51', 'prev', 'prev']]) == [-1, 51, -1]
assert my_solution.lastVisitedIntegers(**[['prev', '46', '9', 'prev']]) == [-1, 9]
assert my_solution.lastVisitedIntegers(**[['prev', 'prev', 'prev', 'prev', 'prev', '26']]) == [-1, -1, -1, -1, -1]
assert my_solution.lastVisitedIntegers(**[['prev', '21', 'prev', '76', '82', 'prev', '96', 'prev', '57', 'prev']]) == [-1, 21, 82, 96, 57]
assert my_solution.lastVisitedIntegers(**[['52', '4', 'prev', 'prev', 'prev', '69']]) == [4, 52, -1]
assert my_solution.lastVisitedIntegers(**[['24', 'prev']]) == [24]
assert my_solution.lastVisitedIntegers(**[['46', 'prev', '78', 'prev', '83', '21', 'prev', '94', '50']]) == [46, 78, 21]
assert my_solution.lastVisitedIntegers(**[['14', '66', 'prev', 'prev', '46', 'prev']]) == [66, 14, 46]
assert my_solution.lastVisitedIntegers(**[['35', '90']]) == []
assert my_solution.lastVisitedIntegers(**[['prev', '9', 'prev', '8', 'prev']]) == [-1, 9, 8]
assert my_solution.lastVisitedIntegers(**[['prev', 'prev', '88', '71', '47', '65', '24', '39']]) == [-1, -1]


# Longest Unequal Adjacent Groups Subsequence I

You are given an integer `n`, a **0-indexed** string array `words`, and a **0-indexed** **binary** array `groups`, both arrays having length `n`.

You need to select the **longest** **subsequence** from an array of indices `[0, 1, ..., n - 1]`, such that for the subsequence denoted as `[i0, i1, ..., ik - 1]` having length `k`, `groups[ij] != groups[ij + 1]`, for each `j` where `0 < j + 1 < k`.

Return *a string array containing the words corresponding to the indices **(in order)** in the selected subsequence*. If there are multiple answers, return *any of them*.

A **subsequence** of an array is a new array that is formed from the original array by deleting some (possibly none) of the elements without disturbing the relative positions of the remaining elements.

**Note:** strings in `words` may be **unequal** in length.

**Example 1:**

```

**Input:** n = 3, words = ["e","a","b"], groups = [0,0,1]
**Output:** ["e","b"]
**Explanation:** A subsequence that can be selected is [0,2] because groups[0] != groups[2].
So, a valid answer is [words[0],words[2]] = ["e","b"].
Another subsequence that can be selected is [1,2] because groups[1] != groups[2].
This results in [words[1],words[2]] = ["a","b"].
It is also a valid answer.
It can be shown that the length of the longest subsequence of indices that satisfies the condition is 2.
```

**Example 2:**

```

**Input:** n = 4, words = ["a","b","c","d"], groups = [1,0,1,1]
**Output:** ["a","b","c"]
**Explanation:** A subsequence that can be selected is [0,1,2] because groups[0] != groups[1] and groups[1] != groups[2].
So, a valid answer is [words[0],words[1],words[2]] = ["a","b","c"].
Another subsequence that can be selected is [0,1,3] because groups[0] != groups[1] and groups[1] != groups[3].
This results in [words[0],words[1],words[3]] = ["a","b","d"].
It is also a valid answer.
It can be shown that the length of the longest subsequence of indices that satisfies the condition is 3.

```

**Constraints:**

* `1 <= n == words.length == groups.length <= 100`
* `1 <= words[i].length <= 10`
* `0 <= groups[i] < 2`
* `words` consists of **distinct** strings.
* `words[i]` consists of lowercase English letters.

Please make sure your answer follows the type signature below:

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

my_solution = Solution()

assert my_solution.getWordsInLongestSubsequence(**[3, ['e', 'a', 'b'], [0, 0, 1]]) == ['e', 'b']
assert my_solution.getWordsInLongestSubsequence(**[4, ['a', 'b', 'c', 'd'], [1, 0, 1, 1]]) == ['a', 'b', 'c']
assert my_solution.getWordsInLongestSubsequence(**[1, ['c'], [0]]) == ['c']
assert my_solution.getWordsInLongestSubsequence(**[1, ['d'], [1]]) == ['d']
assert my_solution.getWordsInLongestSubsequence(**[1, ['e'], [0]]) == ['e']
assert my_solution.getWordsInLongestSubsequence(**[1, ['fe'], [0]]) == ['fe']
assert my_solution.getWordsInLongestSubsequence(**[1, ['frl'], [1]]) == ['frl']
assert my_solution.getWordsInLongestSubsequence(**[1, ['ha'], [1]]) == ['ha']
assert my_solution.getWordsInLongestSubsequence(**[1, ['l'], [0]]) == ['l']
assert my_solution.getWordsInLongestSubsequence(**[1, ['n'], [1]]) == ['n']
assert my_solution.getWordsInLongestSubsequence(**[1, ['s'], [1]]) == ['s']
assert my_solution.getWordsInLongestSubsequence(**[2, ['d', 'g'], [0, 1]]) == ['d', 'g']
assert my_solution.getWordsInLongestSubsequence(**[2, ['lr', 'h'], [0, 0]]) == ['lr']
assert my_solution.getWordsInLongestSubsequence(**[2, ['wx', 'h'], [0, 1]]) == ['wx', 'h']
assert my_solution.getWordsInLongestSubsequence(**[2, ['yw', 'n'], [0, 1]]) == ['yw', 'n']
assert my_solution.getWordsInLongestSubsequence(**[2, ['z', 'n'], [0, 0]]) == ['z']
assert my_solution.getWordsInLongestSubsequence(**[2, ['zr', 'a'], [0, 0]]) == ['zr']
assert my_solution.getWordsInLongestSubsequence(**[3, ['h', 'vv', 'kp'], [0, 1, 0]]) == ['h', 'vv', 'kp']
assert my_solution.getWordsInLongestSubsequence(**[3, ['m', 'v', 'y'], [0, 1, 0]]) == ['m', 'v', 'y']
assert my_solution.getWordsInLongestSubsequence(**[3, ['o', 'cfy', 'en'], [1, 0, 0]]) == ['o', 'cfy']


# Longest Unequal Adjacent Groups Subsequence II

You are given an integer `n`, a **0-indexed** string array `words`, and a **0-indexed** array `groups`, both arrays having length `n`.

The **hamming distance** between two strings of equal length is the number of positions at which the corresponding characters are **different**.

You need to select the **longest** **subsequence** from an array of indices `[0, 1, ..., n - 1]`, such that for the subsequence denoted as `[i0, i1, ..., ik - 1]` having length `k`, the following holds:

* For **adjacent** indices in the subsequence, their corresponding groups are **unequal**, i.e., `groups[ij] != groups[ij + 1]`, for each `j` where `0 < j + 1 < k`.
* `words[ij]` and `words[ij + 1]` are **equal** in length, and the **hamming distance** between them is `1`, where `0 < j + 1 < k`, for all indices in the subsequence.

Return *a string array containing the words corresponding to the indices **(in order)** in the selected subsequence*. If there are multiple answers, return *any of them*.

A **subsequence** of an array is a new array that is formed from the original array by deleting some (possibly none) of the elements without disturbing the relative positions of the remaining elements.

**Note:** strings in `words` may be **unequal** in length.

**Example 1:**

```

**Input:** n = 3, words = ["bab","dab","cab"], groups = [1,2,2]
**Output:** ["bab","cab"]
**Explanation:** A subsequence that can be selected is [0,2].
- groups[0] != groups[2]
- words[0].length == words[2].length, and the hamming distance between them is 1.
So, a valid answer is [words[0],words[2]] = ["bab","cab"].
Another subsequence that can be selected is [0,1].
- groups[0] != groups[1]
- words[0].length == words[1].length, and the hamming distance between them is 1.
So, another valid answer is [words[0],words[1]] = ["bab","dab"].
It can be shown that the length of the longest subsequence of indices that satisfies the conditions is 2.
```

**Example 2:**

```

**Input:** n = 4, words = ["a","b","c","d"], groups = [1,2,3,4]
**Output:** ["a","b","c","d"]
**Explanation:** We can select the subsequence [0,1,2,3].
It satisfies both conditions.
Hence, the answer is [words[0],words[1],words[2],words[3]] = ["a","b","c","d"].
It has the longest length among all subsequences of indices that satisfy the conditions.
Hence, it is the only answer.

```

**Constraints:**

* `1 <= n == words.length == groups.length <= 1000`
* `1 <= words[i].length <= 10`
* `1 <= groups[i] <= n`
* `words` consists of **distinct** strings.
* `words[i]` consists of lowercase English letters.

Please make sure your answer follows the type signature below:

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

my_solution = Solution()

assert my_solution.getWordsInLongestSubsequence(**[3, ['bab', 'dab', 'cab'], [1, 2, 2]]) == ['bab', 'cab']
assert my_solution.getWordsInLongestSubsequence(**[4, ['a', 'b', 'c', 'd'], [1, 2, 3, 4]]) == ['a', 'b', 'c', 'd']
assert my_solution.getWordsInLongestSubsequence(**[1, ['abbbb'], [1]]) == ['abbbb']
assert my_solution.getWordsInLongestSubsequence(**[1, ['ad'], [1]]) == ['ad']
assert my_solution.getWordsInLongestSubsequence(**[1, ['baaccb'], [1]]) == ['baaccb']
assert my_solution.getWordsInLongestSubsequence(**[1, ['bc'], [1]]) == ['bc']
assert my_solution.getWordsInLongestSubsequence(**[1, ['bdb'], [1]]) == ['bdb']
assert my_solution.getWordsInLongestSubsequence(**[1, ['cc'], [1]]) == ['cc']
assert my_solution.getWordsInLongestSubsequence(**[1, ['cd'], [1]]) == ['cd']
assert my_solution.getWordsInLongestSubsequence(**[1, ['cdb'], [1]]) == ['cdb']
assert my_solution.getWordsInLongestSubsequence(**[1, ['cea'], [1]]) == ['cea']
assert my_solution.getWordsInLongestSubsequence(**[1, ['cebbbb'], [1]]) == ['cebbbb']
assert my_solution.getWordsInLongestSubsequence(**[1, ['da'], [1]]) == ['da']
assert my_solution.getWordsInLongestSubsequence(**[1, ['daab'], [1]]) == ['daab']
assert my_solution.getWordsInLongestSubsequence(**[2, ['adbe', 'acace'], [2, 2]]) == ['acace']
assert my_solution.getWordsInLongestSubsequence(**[2, ['ba', 'dc'], [1, 1]]) == ['dc']
assert my_solution.getWordsInLongestSubsequence(**[2, ['baa', 'ada'], [1, 2]]) == ['ada']
assert my_solution.getWordsInLongestSubsequence(**[2, ['bebea', 'ddecc'], [1, 1]]) == ['ddecc']
assert my_solution.getWordsInLongestSubsequence(**[2, ['cedbca', 'db'], [1, 1]]) == ['db']
assert my_solution.getWordsInLongestSubsequence(**[2, ['dbcdd', 'baba'], [2, 1]]) == ['baba']


# Count of Sub-Multisets With Bounded Sum

You are given a **0-indexed** array `nums` of non-negative integers, and two integers `l` and `r`.

Return *the **count of sub-multisets** within* `nums` *where the sum of elements in each subset falls within the inclusive range of* `[l, r]`.

Since the answer may be large, return it modulo `109 + 7`.

A **sub-multiset** is an **unordered** collection of elements of the array in which a given value `x` can occur `0, 1, ..., occ[x]` times, where `occ[x]` is the number of occurrences of `x` in the array.

**Note** that:

* Two **sub-multisets** are the same if sorting both sub-multisets results in identical multisets.
* The sum of an **empty** multiset is `0`.

**Example 1:**

```

**Input:** nums = [1,2,2,3], l = 6, r = 6
**Output:** 1
**Explanation:** The only subset of nums that has a sum of 6 is {1, 2, 3}.

```

**Example 2:**

```

**Input:** nums = [2,1,4,2,7], l = 1, r = 5
**Output:** 7
**Explanation:** The subsets of nums that have a sum within the range [1, 5] are {1}, {2}, {4}, {2, 2}, {1, 2}, {1, 4}, and {1, 2, 2}.

```

**Example 3:**

```

**Input:** nums = [1,2,1,3,5,2], l = 3, r = 5
**Output:** 9
**Explanation:** The subsets of nums that have a sum within the range [3, 5] are {3}, {5}, {1, 2}, {1, 3}, {2, 2}, {2, 3}, {1, 1, 2}, {1, 1, 3}, and {1, 2, 2}.
```

**Constraints:**

* `1 <= nums.length <= 2 * 104`
* `0 <= nums[i] <= 2 * 104`
* Sum of `nums` does not exceed `2 * 104`.
* `0 <= l <= r <= 2 * 104`

Please make sure your answer follows the type signature below:

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

my_solution = Solution()

assert my_solution.countSubMultisets(**[[1, 2, 2, 3], 6, 6]) == 1
assert my_solution.countSubMultisets(**[[2, 1, 4, 2, 7], 1, 5]) == 7
assert my_solution.countSubMultisets(**[[1, 2, 1, 3, 5, 2], 3, 5]) == 9
assert my_solution.countSubMultisets(**[[0, 0, 1, 2, 3], 2, 3]) == 9
assert my_solution.countSubMultisets(**[[0, 0, 0, 0, 0], 0, 0]) == 6
assert my_solution.countSubMultisets(**[[0, 0, 0, 1, 2, 5, 2, 3], 0, 3]) == 20
assert my_solution.countSubMultisets(**[[1, 1], 2, 2]) == 1
assert my_solution.countSubMultisets(**[[1, 1, 1], 2, 2]) == 1
assert my_solution.countSubMultisets(**[[1, 1, 2], 2, 4]) == 4
assert my_solution.countSubMultisets(**[[1, 2, 1], 2, 2]) == 2
assert my_solution.countSubMultisets(**[[1, 2, 2], 3, 5]) == 3
assert my_solution.countSubMultisets(**[[2, 1, 1], 1, 2]) == 3
assert my_solution.countSubMultisets(**[[2, 1, 2], 2, 2]) == 1
assert my_solution.countSubMultisets(**[[2, 2, 1], 4, 5]) == 2
assert my_solution.countSubMultisets(**[[2, 2, 2], 3, 6]) == 2
assert my_solution.countSubMultisets(**[[1, 1, 1, 1], 3, 3]) == 1
assert my_solution.countSubMultisets(**[[1, 1, 1, 2], 1, 1]) == 1
assert my_solution.countSubMultisets(**[[1, 1, 1, 3], 4, 4]) == 1
assert my_solution.countSubMultisets(**[[1, 1, 2, 1], 3, 4]) == 3
assert my_solution.countSubMultisets(**[[1, 1, 2, 2], 2, 3]) == 3


# Divisible and Non-divisible Sums Difference

You are given positive integers `n` and `m`.

Define two integers, `num1` and `num2`, as follows:

* `num1`: The sum of all integers in the range `[1, n]` that are **not divisible** by `m`.
* `num2`: The sum of all integers in the range `[1, n]` that are **divisible** by `m`.

Return *the integer* `num1 - num2`.

**Example 1:**

```

**Input:** n = 10, m = 3
**Output:** 19
**Explanation:** In the given example:
- Integers in the range [1, 10] that are not divisible by 3 are [1,2,4,5,7,8,10], num1 is the sum of those integers = 37.
- Integers in the range [1, 10] that are divisible by 3 are [3,6,9], num2 is the sum of those integers = 18.
We return 37 - 18 = 19 as the answer.

```

**Example 2:**

```

**Input:** n = 5, m = 6
**Output:** 15
**Explanation:** In the given example:
- Integers in the range [1, 5] that are not divisible by 6 are [1,2,3,4,5], num1 is the sum of those integers = 15.
- Integers in the range [1, 5] that are divisible by 6 are [], num2 is the sum of those integers = 0.
We return 15 - 0 = 15 as the answer.

```

**Example 3:**

```

**Input:** n = 5, m = 1
**Output:** -15
**Explanation:** In the given example:
- Integers in the range [1, 5] that are not divisible by 1 are [], num1 is the sum of those integers = 0.
- Integers in the range [1, 5] that are divisible by 1 are [1,2,3,4,5], num2 is the sum of those integers = 15.
We return 0 - 15 = -15 as the answer.

```

**Constraints:**

* `1 <= n, m <= 1000`

Please make sure your answer follows the type signature below:

```python3
class Solution:
    def differenceOfSums(self, n: int, m: int) -> int:
```

my_solution = Solution()

assert my_solution.differenceOfSums(**[10, 3]) == 19
assert my_solution.differenceOfSums(**[5, 6]) == 15
assert my_solution.differenceOfSums(**[5, 1]) == -15
assert my_solution.differenceOfSums(**[15, 9]) == 102
assert my_solution.differenceOfSums(**[8, 10]) == 36
assert my_solution.differenceOfSums(**[23, 36]) == 276
assert my_solution.differenceOfSums(**[1, 32]) == 1
assert my_solution.differenceOfSums(**[36, 7]) == 456
assert my_solution.differenceOfSums(**[3, 8]) == 6
assert my_solution.differenceOfSums(**[4, 2]) == -2
assert my_solution.differenceOfSums(**[9, 7]) == 31
assert my_solution.differenceOfSums(**[20, 9]) == 156
assert my_solution.differenceOfSums(**[3, 19]) == 6
assert my_solution.differenceOfSums(**[6, 16]) == 21
assert my_solution.differenceOfSums(**[6, 1]) == -21
assert my_solution.differenceOfSums(**[5, 25]) == 15
assert my_solution.differenceOfSums(**[9, 3]) == 9
assert my_solution.differenceOfSums(**[8, 23]) == 36
assert my_solution.differenceOfSums(**[17, 1]) == -153
assert my_solution.differenceOfSums(**[18, 9]) == 117


# Minimum Processing Time

You have `n` processors each having `4` cores and `n * 4` tasks that need to be executed such that each core should perform only **one** task.

Given a **0-indexed** integer array `processorTime` representing the time at which each processor becomes available for the first time and a **0-indexed** integer array `tasks` representing the time it takes to execute each task, return *the **minimum** time when all of the tasks have been executed by the processors.*

**Note:** Each core executes the task independently of the others.

**Example 1:**

```

**Input:** processorTime = [8,10], tasks = [2,2,3,1,8,7,4,5]
**Output:** 16
**Explanation:**
It's optimal to assign the tasks at indexes 4, 5, 6, 7 to the first processor which becomes available at time = 8, and the tasks at indexes 0, 1, 2, 3 to the second processor which becomes available at time = 10.
Time taken by the first processor to finish execution of all tasks = max(8 + 8, 8 + 7, 8 + 4, 8 + 5) = 16.
Time taken by the second processor to finish execution of all tasks = max(10 + 2, 10 + 2, 10 + 3, 10 + 1) = 13.
Hence, it can be shown that the minimum time taken to execute all the tasks is 16.
```

**Example 2:**

```

**Input:** processorTime = [10,20], tasks = [2,3,1,2,5,8,4,3]
**Output:** 23
**Explanation:**
It's optimal to assign the tasks at indexes 1, 4, 5, 6 to the first processor which becomes available at time = 10, and the tasks at indexes 0, 2, 3, 7 to the second processor which becomes available at time = 20.
Time taken by the first processor to finish execution of all tasks = max(10 + 3, 10 + 5, 10 + 8, 10 + 4) = 18.
Time taken by the second processor to finish execution of all tasks = max(20 + 2, 20 + 1, 20 + 2, 20 + 3) = 23.
Hence, it can be shown that the minimum time taken to execute all the tasks is 23.

```

**Constraints:**

* `1 <= n == processorTime.length <= 25000`
* `1 <= tasks.length <= 105`
* `0 <= processorTime[i] <= 109`
* `1 <= tasks[i] <= 109`
* `tasks.length == 4 * n`

Please make sure your answer follows the type signature below:

```python3
class Solution:
    def minProcessingTime(self, processorTime: List[int], tasks: List[int]) -> int:
```


# Apply Operations to Make Two Strings Equal

You are given two **0-indexed** binary strings `s1` and `s2`, both of length `n`, and a positive integer `x`.

You can perform any of the following operations on the string `s1` **any** number of times:

* Choose two indices `i` and `j`, and flip both `s1[i]` and `s1[j]`. The cost of this operation is `x`.
* Choose an index `i` such that `i < n - 1` and flip both `s1[i]` and `s1[i + 1]`. The cost of this operation is `1`.

Return *the **minimum** cost needed to make the strings* `s1` *and* `s2` *equal, or return* `-1` *if it is impossible.*

**Note** that flipping a character means changing it from `0` to `1` or vice-versa.

**Example 1:**

```

**Input:** s1 = "1100011000", s2 = "0101001010", x = 2
**Output:** 4
**Explanation:** We can do the following operations:
- Choose i = 3 and apply the second operation. The resulting string is s1 = "110**11**11000".
- Choose i = 4 and apply the second operation. The resulting string is s1 = "1101**00**1000".
- Choose i = 0 and j = 8 and apply the first operation. The resulting string is s1 = "**0**1010010**1**0" = s2.
The total cost is 1 + 1 + 2 = 4. It can be shown that it is the minimum cost possible.

```

**Example 2:**

```

**Input:** s1 = "10110", s2 = "00011", x = 4
**Output:** -1
**Explanation:** It is not possible to make the two strings equal.

```

**Constraints:**

* `n == s1.length == s2.length`
* `1 <= n, x <= 500`
* `s1` and `s2` consist only of the characters `'0'` and `'1'`.

Please make sure your answer follows the type signature below:

```python3
class Solution:
    def minOperations(self, s1: str, s2: str, x: int) -> int:
```


# Apply Operations on Array to Maximize Sum of Squares

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

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

* Choose any two distinct indices `i` and `j` and **simultaneously** update the values of `nums[i]` to `(nums[i] AND nums[j])` and `nums[j]` to `(nums[i] OR nums[j])`. Here, `OR` denotes the bitwise `OR` operation, and `AND` denotes the bitwise `AND` operation.

You have to choose `k` elements from the final array and calculate the sum of their **squares**.

Return *the **maximum** sum of squares you can achieve*.

Since the answer can be very large, return it **modulo** `109 + 7`.

**Example 1:**

```

**Input:** nums = [2,6,5,8], k = 2
**Output:** 261
**Explanation:** We can do the following operations on the array:
- Choose i = 0 and j = 3, then change nums[0] to (2 AND 8) = 0 and nums[3] to (2 OR 8) = 10. The resulting array is nums = [0,6,5,10].
- Choose i = 2 and j = 3, then change nums[2] to (5 AND 10) = 0 and nums[3] to (5 OR 10) = 15. The resulting array is nums = [0,6,0,15].
We can choose the elements 15 and 6 from the final array. The sum of squares is 152 + 62 = 261.
It can be shown that this is the maximum value we can get.

```

**Example 2:**

```

**Input:** nums = [4,5,4,7], k = 3
**Output:** 90
**Explanation:** We do not need to apply any operations.
We can choose the elements 7, 5, and 4 with a sum of squares: 72 + 52 + 42 = 90.
It can be shown that this is the maximum value we can get.

```

**Constraints:**

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

Please make sure your answer follows the type signature below:

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


# Maximum Value of an Ordered Triplet I

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

Return ***the maximum value over all triplets of indices*** `(i, j, k)` *such that* `i < j < k`. If all such triplets have a negative value, return `0`.

The **value of a triplet of indices** `(i, j, k)` is equal to `(nums[i] - nums[j]) * nums[k]`.

**Example 1:**

```

**Input:** nums = [12,6,1,2,7]
**Output:** 77
**Explanation:** The value of the triplet (0, 2, 4) is (nums[0] - nums[2]) * nums[4] = 77.
It can be shown that there are no ordered triplets of indices with a value greater than 77.

```

**Example 2:**

```

**Input:** nums = [1,10,3,4,19]
**Output:** 133
**Explanation:** The value of the triplet (1, 2, 4) is (nums[1] - nums[2]) * nums[4] = 133.
It can be shown that there are no ordered triplets of indices with a value greater than 133.

```

**Example 3:**

```

**Input:** nums = [1,2,3]
**Output:** 0
**Explanation:** The only ordered triplet of indices (0, 1, 2) has a negative value of (nums[0] - nums[1]) * nums[2] = -3. Hence, the answer would be 0.

```

**Constraints:**

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

Please make sure your answer follows the type signature below:

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


# Maximum Value of an Ordered Triplet II

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

Return ***the maximum value over all triplets of indices*** `(i, j, k)` *such that* `i < j < k`*.* If all such triplets have a negative value, return `0`.

The **value of a triplet of indices** `(i, j, k)` is equal to `(nums[i] - nums[j]) * nums[k]`.

**Example 1:**

```

**Input:** nums = [12,6,1,2,7]
**Output:** 77
**Explanation:** The value of the triplet (0, 2, 4) is (nums[0] - nums[2]) * nums[4] = 77.
It can be shown that there are no ordered triplets of indices with a value greater than 77.

```

**Example 2:**

```

**Input:** nums = [1,10,3,4,19]
**Output:** 133
**Explanation:** The value of the triplet (1, 2, 4) is (nums[1] - nums[2]) * nums[4] = 133.
It can be shown that there are no ordered triplets of indices with a value greater than 133.

```

**Example 3:**

```

**Input:** nums = [1,2,3]
**Output:** 0
**Explanation:** The only ordered triplet of indices (0, 1, 2) has a negative value of (nums[0] - nums[1]) * nums[2] = -3. Hence, the answer would be 0.

```

**Constraints:**

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

Please make sure your answer follows the type signature below:

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


# Minimum Size Subarray in Infinite Array

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

A **0-indexed** array `infinite_nums` is generated by infinitely appending the elements of `nums` to itself.

Return *the length of the **shortest** subarray of the array* `infinite_nums` *with a sum equal to* `target`*.* If there is no such subarray return `-1`.

**Example 1:**

```

**Input:** nums = [1,2,3], target = 5
**Output:** 2
**Explanation:** In this example infinite_nums = [1,2,3,1,2,3,1,2,...].
The subarray in the range [1,2], has the sum equal to target = 5 and length = 2.
It can be proven that 2 is the shortest length of a subarray with sum equal to target = 5.

```

**Example 2:**

```

**Input:** nums = [1,1,1,2,3], target = 4
**Output:** 2
**Explanation:** In this example infinite_nums = [1,1,1,2,3,1,1,1,2,3,1,1,...].
The subarray in the range [4,5], has the sum equal to target = 4 and length = 2.
It can be proven that 2 is the shortest length of a subarray with sum equal to target = 4.

```

**Example 3:**

```

**Input:** nums = [2,4,6,8], target = 3
**Output:** -1
**Explanation:** In this example infinite_nums = [2,4,6,8,2,4,6,8,...].
It can be proven that there is no subarray with sum equal to target = 3.

```

**Constraints:**

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

Please make sure your answer follows the type signature below:

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


# Minimum Operations to Collect Elements

You are given an array `nums` of positive integers and an integer `k`.

In one operation, you can remove the last element of the array and add it to your collection.

Return *the **minimum number of operations** needed to collect elements* `1, 2, ..., k`.

**Example 1:**

```

**Input:** nums = [3,1,5,4,2], k = 2
**Output:** 4
**Explanation:** After 4 operations, we collect elements 2, 4, 5, and 1, in this order. Our collection contains elements 1 and 2. Hence, the answer is 4.

```

**Example 2:**

```

**Input:** nums = [3,1,5,4,2], k = 5
**Output:** 5
**Explanation:** After 5 operations, we collect elements 2, 4, 5, 1, and 3, in this order. Our collection contains elements 1 through 5. Hence, the answer is 5.

```

**Example 3:**

```

**Input:** nums = [3,2,5,3,1], k = 3
**Output:** 4
**Explanation:** After 4 operations, we collect elements 1, 3, 5, and 2, in this order. Our collection contains elements 1 through 3. Hence, the answer is 4.

```

**Constraints:**

* `1 <= nums.length <= 50`
* `1 <= nums[i] <= nums.length`
* `1 <= k <= nums.length`
* The input is generated such that you can collect elements `1, 2, ..., k`.

Please make sure your answer follows the type signature below:

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

my_solution = Solution()

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


# Minimum Number of Operations to Make Array Empty

You are given a **0-indexed** array `nums` consisting of positive integers.

There are two types of operations that you can apply on the array **any** number of times:

* Choose **two** elements with **equal** values and **delete** them from the array.
* Choose **three** elements with **equal** values and **delete** them from the array.

Return *the **minimum** number of operations required to make the array empty, or* `-1` *if it is not possible*.

**Example 1:**

```

**Input:** nums = [2,3,3,2,2,4,2,3,4]
**Output:** 4
**Explanation:** We can apply the following operations to make the array empty:
- Apply the first operation on the elements at indices 0 and 3. The resulting array is nums = [3,3,2,4,2,3,4].
- Apply the first operation on the elements at indices 2 and 4. The resulting array is nums = [3,3,4,3,4].
- Apply the second operation on the elements at indices 0, 1, and 3. The resulting array is nums = [4,4].
- Apply the first operation on the elements at indices 0 and 1. The resulting array is nums = [].
It can be shown that we cannot make the array empty in less than 4 operations.

```

**Example 2:**

```

**Input:** nums = [2,1,2,2,3,3]
**Output:** -1
**Explanation:** It is impossible to empty the array.

```

**Constraints:**

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

Please make sure your answer follows the type signature below:

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


# Split Array Into Maximum Number of Subarrays

You are given an array `nums` consisting of **non-negative** integers.

We define the score of subarray `nums[l..r]` such that `l <= r` as `nums[l] AND nums[l + 1] AND ... AND nums[r]` where **AND** is the bitwise `AND` operation.

Consider splitting the array into one or more subarrays such that the following conditions are satisfied:

* **E****ach** element of the array belongs to **exactly** one subarray.
* The sum of scores of the subarrays is the **minimum** possible.

Return *the **maximum** number of subarrays in a split that satisfies the conditions above.*

A **subarray** is a contiguous part of an array.

**Example 1:**

```

**Input:** nums = [1,0,2,0,1,2]
**Output:** 3
**Explanation:** We can split the array into the following subarrays:
- [1,0]. The score of this subarray is 1 AND 0 = 0.
- [2,0]. The score of this subarray is 2 AND 0 = 0.
- [1,2]. The score of this subarray is 1 AND 2 = 0.
The sum of scores is 0 + 0 + 0 = 0, which is the minimum possible score that we can obtain.
It can be shown that we cannot split the array into more than 3 subarrays with a total score of 0. So we return 3.

```

**Example 2:**

```

**Input:** nums = [5,7,1,3]
**Output:** 1
**Explanation:** We can split the array into one subarray: [5,7,1,3] with a score of 1, which is the minimum possible score that we can obtain.
It can be shown that we cannot split the array into more than 1 subarray with a total score of 1. So we return 1.

```

**Constraints:**

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

Please make sure your answer follows the type signature below:

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

my_solution = Solution()

assert my_solution.maxSubarrays(**[[1, 0, 2, 0, 1, 2]]) == 3
assert my_solution.maxSubarrays(**[[5, 7, 1, 3]]) == 1
assert my_solution.maxSubarrays(**[[1, 0, 2, 1]]) == 2
assert my_solution.maxSubarrays(**[[0]]) == 1
assert my_solution.maxSubarrays(**[[0, 0]]) == 2
assert my_solution.maxSubarrays(**[[100000]]) == 1
assert my_solution.maxSubarrays(**[[1, 2, 2, 1]]) == 2
assert my_solution.maxSubarrays(**[[30, 18, 19, 20, 11, 21, 12, 22, 26]]) == 2
assert my_solution.maxSubarrays(**[[0, 8, 0, 0, 0, 23]]) == 4
assert my_solution.maxSubarrays(**[[8, 10, 23, 26, 21, 28, 21, 14, 21, 14, 9, 16, 24, 29, 7, 26]]) == 4
assert my_solution.maxSubarrays(**[[18, 12, 16, 28, 7, 15, 24, 7, 8, 26, 22, 6, 23, 7, 17, 1, 16]]) == 6
assert my_solution.maxSubarrays(**[[22]]) == 1
assert my_solution.maxSubarrays(**[[15, 24, 20, 28, 11, 16, 0, 0, 0, 22, 7, 18]]) == 5
assert my_solution.maxSubarrays(**[[0, 0, 27]]) == 2
assert my_solution.maxSubarrays(**[[18, 7, 20, 10, 0, 14, 0, 28, 7, 0, 0, 9, 12, 0]]) == 6
assert my_solution.maxSubarrays(**[[0, 29, 16, 0, 6, 17]]) == 3
assert my_solution.maxSubarrays(**[[4, 7, 13, 0, 23, 6, 4]]) == 1
assert my_solution.maxSubarrays(**[[4, 27]]) == 1
assert my_solution.maxSubarrays(**[[29, 5, 0, 25, 0, 15, 19, 24, 20, 0, 23]]) == 4
assert my_solution.maxSubarrays(**[[24, 6]]) == 1


# Maximum Odd Binary Number

You are given a **binary** string `s` that contains at least one `'1'`.

You have to **rearrange** the bits in such a way that the resulting binary number is the **maximum odd binary number** that can be created from this combination.

Return *a string representing the maximum odd binary number that can be created from the given combination.*

**Note** that the resulting string **can** have leading zeros.

**Example 1:**

```

**Input:** s = "010"
**Output:** "001"
**Explanation:** Because there is just one '1', it must be in the last position. So the answer is "001".

```

**Example 2:**

```

**Input:** s = "0101"
**Output:** "1001"
**Explanation:** One of the '1's must be in the last position. The maximum number that can be made with the remaining digits is "100". So the answer is "1001".

```

**Constraints:**

* `1 <= s.length <= 100`
* `s` consists only of `'0'` and `'1'`.
* `s` contains at least one `'1'`.

Please make sure your answer follows the type signature below:

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

my_solution = Solution()

assert my_solution.maximumOddBinaryNumber(**['010']) == 001
assert my_solution.maximumOddBinaryNumber(**['0101']) == 1001
assert my_solution.maximumOddBinaryNumber(**['1']) == 1
assert my_solution.maximumOddBinaryNumber(**['01']) == 01
assert my_solution.maximumOddBinaryNumber(**['10']) == 01
assert my_solution.maximumOddBinaryNumber(**['11']) == 11
assert my_solution.maximumOddBinaryNumber(**['001']) == 001
assert my_solution.maximumOddBinaryNumber(**['011']) == 101
assert my_solution.maximumOddBinaryNumber(**['100']) == 001
assert my_solution.maximumOddBinaryNumber(**['101']) == 101
assert my_solution.maximumOddBinaryNumber(**['110']) == 101
assert my_solution.maximumOddBinaryNumber(**['111']) == 111
assert my_solution.maximumOddBinaryNumber(**['0010']) == 0001
assert my_solution.maximumOddBinaryNumber(**['0011']) == 1001
assert my_solution.maximumOddBinaryNumber(**['0100']) == 0001
assert my_solution.maximumOddBinaryNumber(**['0111']) == 1101
assert my_solution.maximumOddBinaryNumber(**['1000']) == 0001
assert my_solution.maximumOddBinaryNumber(**['1001']) == 1001
assert my_solution.maximumOddBinaryNumber(**['1011']) == 1101
assert my_solution.maximumOddBinaryNumber(**['1100']) == 1001


# Beautiful Towers I

You are given a **0-indexed** array `maxHeights` of `n` integers.

You are tasked with building `n` towers in the coordinate line. The `ith` tower is built at coordinate `i` and has a height of `heights[i]`.

A configuration of towers is **beautiful** if the following conditions hold:

1. `1 <= heights[i] <= maxHeights[i]`
2. `heights` is a **mountain** array.

Array `heights` is a **mountain** if there exists an index `i` such that:

* For all `0 < j <= i`, `heights[j - 1] <= heights[j]`
* For all `i <= k < n - 1`, `heights[k + 1] <= heights[k]`

Return *the **maximum possible sum of heights** of a beautiful configuration of towers*.

**Example 1:**

```

**Input:** maxHeights = [5,3,4,1,1]
**Output:** 13
**Explanation:** One beautiful configuration with a maximum sum is heights = [5,3,3,1,1]. This configuration is beautiful since:
- 1 <= heights[i] <= maxHeights[i]
- heights is a mountain of peak i = 0.
It can be shown that there exists no other beautiful configuration with a sum of heights greater than 13.
```

**Example 2:**

```

**Input:** maxHeights = [6,5,3,9,2,7]
**Output:** 22
**Explanation:** One beautiful configuration with a maximum sum is heights = [3,3,3,9,2,2]. This configuration is beautiful since:
- 1 <= heights[i] <= maxHeights[i]
- heights is a mountain of peak i = 3.
It can be shown that there exists no other beautiful configuration with a sum of heights greater than 22.
```

**Example 3:**

```

**Input:** maxHeights = [3,2,5,5,2,3]
**Output:** 18
**Explanation:** One beautiful configuration with a maximum sum is heights = [2,2,5,5,2,2]. This configuration is beautiful since:
- 1 <= heights[i] <= maxHeights[i]
- heights is a mountain of peak i = 2.
Note that, for this configuration, i = 3 can also be considered a peak.
It can be shown that there exists no other beautiful configuration with a sum of heights greater than 18.

```

**Constraints:**

* `1 <= n == maxHeights <= 103`
* `1 <= maxHeights[i] <= 109`

Please make sure your answer follows the type signature below:

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

my_solution = Solution()

assert my_solution.maximumSumOfHeights(**[[5, 3, 4, 1, 1]]) == 13
assert my_solution.maximumSumOfHeights(**[[6, 5, 3, 9, 2, 7]]) == 22
assert my_solution.maximumSumOfHeights(**[[3, 2, 5, 5, 2, 3]]) == 18
assert my_solution.maximumSumOfHeights(**[[1000000000]]) == 1000000000
assert my_solution.maximumSumOfHeights(**[[1]]) == 1
assert my_solution.maximumSumOfHeights(**[[933754743]]) == 933754743
assert my_solution.maximumSumOfHeights(**[[1, 1000000000]]) == 1000000001
assert my_solution.maximumSumOfHeights(**[[1000000000, 1000000000]]) == 2000000000
assert my_solution.maximumSumOfHeights(**[[999999999, 1000000000]]) == 1999999999
assert my_solution.maximumSumOfHeights(**[[1000000000, 999999999]]) == 1999999999
assert my_solution.maximumSumOfHeights(**[[30, 1]]) == 31
assert my_solution.maximumSumOfHeights(**[[1, 12, 19]]) == 32
assert my_solution.maximumSumOfHeights(**[[1000000000, 1000000000, 1000000000]]) == 3000000000
assert my_solution.maximumSumOfHeights(**[[999999999, 1000000000, 999999999]]) == 2999999998
assert my_solution.maximumSumOfHeights(**[[1000000000, 999999999, 999999998]]) == 2999999997
assert my_solution.maximumSumOfHeights(**[[999999998, 999999999, 1000000000]]) == 2999999997
assert my_solution.maximumSumOfHeights(**[[1, 1, 1]]) == 3
assert my_solution.maximumSumOfHeights(**[[1, 1, 4, 3, 3, 3, 6]]) == 20
assert my_solution.maximumSumOfHeights(**[[2, 4, 1, 3, 5]]) == 11
assert my_solution.maximumSumOfHeights(**[[1, 5, 2, 5, 6, 4, 6, 3, 4, 5]]) == 33


# Beautiful Towers II

You are given a **0-indexed** array `maxHeights` of `n` integers.

You are tasked with building `n` towers in the coordinate line. The `ith` tower is built at coordinate `i` and has a height of `heights[i]`.

A configuration of towers is **beautiful** if the following conditions hold:

1. `1 <= heights[i] <= maxHeights[i]`
2. `heights` is a **mountain** array.

Array `heights` is a **mountain** if there exists an index `i` such that:

* For all `0 < j <= i`, `heights[j - 1] <= heights[j]`
* For all `i <= k < n - 1`, `heights[k + 1] <= heights[k]`

Return *the **maximum possible sum of heights** of a beautiful configuration of towers*.

**Example 1:**

```

**Input:** maxHeights = [5,3,4,1,1]
**Output:** 13
**Explanation:** One beautiful configuration with a maximum sum is heights = [5,3,3,1,1]. This configuration is beautiful since:
- 1 <= heights[i] <= maxHeights[i]
- heights is a mountain of peak i = 0.
It can be shown that there exists no other beautiful configuration with a sum of heights greater than 13.
```

**Example 2:**

```

**Input:** maxHeights = [6,5,3,9,2,7]
**Output:** 22
**Explanation:** One beautiful configuration with a maximum sum is heights = [3,3,3,9,2,2]. This configuration is beautiful since:
- 1 <= heights[i] <= maxHeights[i]
- heights is a mountain of peak i = 3.
It can be shown that there exists no other beautiful configuration with a sum of heights greater than 22.
```

**Example 3:**

```

**Input:** maxHeights = [3,2,5,5,2,3]
**Output:** 18
**Explanation:** One beautiful configuration with a maximum sum is heights = [2,2,5,5,2,2]. This configuration is beautiful since:
- 1 <= heights[i] <= maxHeights[i]
- heights is a mountain of peak i = 2.
Note that, for this configuration, i = 3 can also be considered a peak.
It can be shown that there exists no other beautiful configuration with a sum of heights greater than 18.

```

**Constraints:**

* `1 <= n == maxHeights <= 105`
* `1 <= maxHeights[i] <= 109`

Please make sure your answer follows the type signature below:

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

my_solution = Solution()

assert my_solution.maximumSumOfHeights(**[[5, 3, 4, 1, 1]]) == 13
assert my_solution.maximumSumOfHeights(**[[6, 5, 3, 9, 2, 7]]) == 22
assert my_solution.maximumSumOfHeights(**[[3, 2, 5, 5, 2, 3]]) == 18
assert my_solution.maximumSumOfHeights(**[[1000000000]]) == 1000000000
assert my_solution.maximumSumOfHeights(**[[1]]) == 1
assert my_solution.maximumSumOfHeights(**[[352939501]]) == 352939501
assert my_solution.maximumSumOfHeights(**[[1, 1000000000]]) == 1000000001
assert my_solution.maximumSumOfHeights(**[[1000000000, 1000000000]]) == 2000000000
assert my_solution.maximumSumOfHeights(**[[999999999, 1000000000]]) == 1999999999
assert my_solution.maximumSumOfHeights(**[[1000000000, 999999999]]) == 1999999999
assert my_solution.maximumSumOfHeights(**[[2, 1]]) == 3
assert my_solution.maximumSumOfHeights(**[[26, 30, 30]]) == 86
assert my_solution.maximumSumOfHeights(**[[1000000000, 1000000000, 1000000000]]) == 3000000000
assert my_solution.maximumSumOfHeights(**[[999999999, 1000000000, 999999999]]) == 2999999998
assert my_solution.maximumSumOfHeights(**[[1000000000, 999999999, 999999998]]) == 2999999997
assert my_solution.maximumSumOfHeights(**[[999999998, 999999999, 1000000000]]) == 2999999997
assert my_solution.maximumSumOfHeights(**[[1, 1, 1]]) == 3
assert my_solution.maximumSumOfHeights(**[[1, 1, 5, 6, 2, 2, 3]]) == 19
assert my_solution.maximumSumOfHeights(**[[3, 5, 3, 5, 1, 5, 4, 4, 4]]) == 22
assert my_solution.maximumSumOfHeights(**[[4, 2, 4, 2, 1, 5, 4, 6]]) == 19


# Sum of Values at Indices With K Set Bits

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

Return *an integer that denotes the **sum** of elements in* `nums` *whose corresponding **indices** have **exactly*** `k` *set bits in their binary representation.*

The **set bits** in an integer are the `1`'s present when it is written in binary.

* For example, the binary representation of `21` is `10101`, which has `3` set bits.

**Example 1:**

```

**Input:** nums = [5,10,1,5,2], k = 1
**Output:** 13
**Explanation:** The binary representation of the indices are:
0 = 0002
1 = 0012
2 = 0102
3 = 0112
4 = 1002Indices 1, 2, and 4 have k = 1 set bits in their binary representation.
Hence, the answer is nums[1] + nums[2] + nums[4] = 13.
```

**Example 2:**

```

**Input:** nums = [4,3,2,1], k = 2
**Output:** 1
**Explanation:** The binary representation of the indices are:
0 = 002
1 = 012
2 = 102
3 = 112Only index 3 has k = 2 set bits in its binary representation.
Hence, the answer is nums[3] = 1.

```

**Constraints:**

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

Please make sure your answer follows the type signature below:

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

my_solution = Solution()

assert my_solution.sumIndicesWithKSetBits(**[[5, 10, 1, 5, 2], 1]) == 13
assert my_solution.sumIndicesWithKSetBits(**[[4, 3, 2, 1], 2]) == 1
assert my_solution.sumIndicesWithKSetBits(**[[1], 0]) == 1
assert my_solution.sumIndicesWithKSetBits(**[[100000], 0]) == 100000
assert my_solution.sumIndicesWithKSetBits(**[[2, 2], 1]) == 2
assert my_solution.sumIndicesWithKSetBits(**[[2, 4], 1]) == 4
assert my_solution.sumIndicesWithKSetBits(**[[2, 7], 1]) == 7
assert my_solution.sumIndicesWithKSetBits(**[[3, 3], 1]) == 3
assert my_solution.sumIndicesWithKSetBits(**[[3, 9], 1]) == 9
assert my_solution.sumIndicesWithKSetBits(**[[4, 7], 1]) == 7
assert my_solution.sumIndicesWithKSetBits(**[[4, 8], 1]) == 8
assert my_solution.sumIndicesWithKSetBits(**[[6, 6], 1]) == 6
assert my_solution.sumIndicesWithKSetBits(**[[7, 2], 1]) == 2
assert my_solution.sumIndicesWithKSetBits(**[[7, 4], 1]) == 4
assert my_solution.sumIndicesWithKSetBits(**[[8, 4], 1]) == 4
assert my_solution.sumIndicesWithKSetBits(**[[8, 9], 1]) == 9
assert my_solution.sumIndicesWithKSetBits(**[[9, 9], 1]) == 9
assert my_solution.sumIndicesWithKSetBits(**[[15, 43], 1]) == 43
assert my_solution.sumIndicesWithKSetBits(**[[35, 86], 1]) == 86
assert my_solution.sumIndicesWithKSetBits(**[[36, 14], 1]) == 14


# Happy Students

You are given a **0-indexed** integer array `nums` of length `n` where `n` is the total number of students in the class. The class teacher tries to select a group of students so that all the students remain happy.

The `ith` student will become happy if one of these two conditions is met:

* The student is selected and the total number of selected students is **strictly greater than** `nums[i]`.
* The student is not selected and the total number of selected students is **strictly** **less than** `nums[i]`.

Return *the number of ways to select a group of students so that everyone remains happy.*

**Example 1:**

```

**Input:** nums = [1,1]
**Output:** 2
**Explanation:**
The two possible ways are:
The class teacher selects no student.
The class teacher selects both students to form the group.
If the class teacher selects just one student to form a group then the both students will not be happy. Therefore, there are only two possible ways.

```

**Example 2:**

```

**Input:** nums = [6,0,3,3,6,7,2,7]
**Output:** 3
**Explanation:**
The three possible ways are:
The class teacher selects the student with index = 1 to form the group.
The class teacher selects the students with index = 1, 2, 3, 6 to form the group.
The class teacher selects all the students to form the group.

```

**Constraints:**

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

Please make sure your answer follows the type signature below:

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


# Maximum Number of Alloys

You are the owner of a company that creates alloys using various types of metals. There are `n` different types of metals available, and you have access to `k` machines that can be used to create alloys. Each machine requires a specific amount of each metal type to create an alloy.

For the `ith` machine to create an alloy, it needs `composition[i][j]` units of metal of type `j`. Initially, you have `stock[i]` units of metal type `i`, and purchasing one unit of metal type `i` costs `cost[i]` coins.

Given integers `n`, `k`, `budget`, a **1-indexed** 2D array `composition`, and **1-indexed** arrays `stock` and `cost`, your goal is to **maximize** the number of alloys the company can create while staying within the budget of `budget` coins.

**All alloys must be created with the same machine.**

Return *the maximum number of alloys that the company can create*.

**Example 1:**

```

**Input:** n = 3, k = 2, budget = 15, composition = [[1,1,1],[1,1,10]], stock = [0,0,0], cost = [1,2,3]
**Output:** 2
**Explanation:** It is optimal to use the 1st machine to create alloys.
To create 2 alloys we need to buy the:
- 2 units of metal of the 1st type.
- 2 units of metal of the 2nd type.
- 2 units of metal of the 3rd type.
In total, we need 2 * 1 + 2 * 2 + 2 * 3 = 12 coins, which is smaller than or equal to budget = 15.
Notice that we have 0 units of metal of each type and we have to buy all the required units of metal.
It can be proven that we can create at most 2 alloys.

```

**Example 2:**

```

**Input:** n = 3, k = 2, budget = 15, composition = [[1,1,1],[1,1,10]], stock = [0,0,100], cost = [1,2,3]
**Output:** 5
**Explanation:** It is optimal to use the 2nd machine to create alloys.
To create 5 alloys we need to buy:
- 5 units of metal of the 1st type.
- 5 units of metal of the 2nd type.
- 0 units of metal of the 3rd type.
In total, we need 5 * 1 + 5 * 2 + 0 * 3 = 15 coins, which is smaller than or equal to budget = 15.
It can be proven that we can create at most 5 alloys.

```

**Example 3:**

```

**Input:** n = 2, k = 3, budget = 10, composition = [[2,1],[1,2],[1,1]], stock = [1,1], cost = [5,5]
**Output:** 2
**Explanation:** It is optimal to use the 3rd machine to create alloys.
To create 2 alloys we need to buy the:
- 1 unit of metal of the 1st type.
- 1 unit of metal of the 2nd type.
In total, we need 1 * 5 + 1 * 5 = 10 coins, which is smaller than or equal to budget = 10.
It can be proven that we can create at most 2 alloys.

```

**Constraints:**

* `1 <= n, k <= 100`
* `0 <= budget <= 108`
* `composition.length == k`
* `composition[i].length == n`
* `1 <= composition[i][j] <= 100`
* `stock.length == cost.length == n`
* `0 <= stock[i] <= 108`
* `1 <= cost[i] <= 100`

Please make sure your answer follows the type signature below:

```python3
class Solution:
    def maxNumberOfAlloys(self, n: int, k: int, budget: int, composition: List[List[int]], stock: List[int], cost: List[int]) -> int:
```


# Maximum Element-Sum of a Complete Subset of Indices

You are given a **1****-indexed** array `nums` of `n` integers.

A set of numbers is **complete** if the product of every pair of its elements is a perfect square.

For a subset of the indices set `{1, 2, ..., n}` represented as `{i1, i2, ..., ik}`, we define its **element-sum** as: `nums[i1] + nums[i2] + ... + nums[ik]`.

Return *the **maximum element-sum** of a **complete** subset of the indices set* `{1, 2, ..., n}`.

A perfect square is a number that can be expressed as the product of an integer by itself.

**Example 1:**

```

**Input:** nums = [8,7,3,5,7,2,4,9]
**Output:** 16
**Explanation:** Apart from the subsets consisting of a single index, there are two other complete subsets of indices: {1,4} and {2,8}.
The sum of the elements corresponding to indices 1 and 4 is equal to nums[1] + nums[4] = 8 + 5 = 13.
The sum of the elements corresponding to indices 2 and 8 is equal to nums[2] + nums[8] = 7 + 9 = 16.
Hence, the maximum element-sum of a complete subset of indices is 16.

```

**Example 2:**

```

**Input:** nums = [5,10,3,10,1,13,7,9,4]
**Output:** 19
**Explanation:** Apart from the subsets consisting of a single index, there are four other complete subsets of indices: {1,4}, {1,9}, {2,8}, {4,9}, and {1,4,9}.
The sum of the elements corresponding to indices 1 and 4 is equal to nums[1] + nums[4] = 5 + 10 = 15.
The sum of the elements corresponding to indices 1 and 9 is equal to nums[1] + nums[9] = 5 + 4 = 9.
The sum of the elements corresponding to indices 2 and 8 is equal to nums[2] + nums[8] = 10 + 9 = 19.
The sum of the elements corresponding to indices 4 and 9 is equal to nums[4] + nums[9] = 10 + 4 = 14.
The sum of the elements corresponding to indices 1, 4, and 9 is equal to nums[1] + nums[4] + nums[9] = 5 + 10 + 4 = 19.
Hence, the maximum element-sum of a complete subset of indices is 19.

```

**Constraints:**

* `1 <= n == nums.length <= 104`
* `1 <= nums[i] <= 109`

Please make sure your answer follows the type signature below:

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


# Minimum Right Shifts to Sort the Array

You are given a **0-indexed** array `nums` of length `n` containing **distinct** positive integers. Return *the **minimum** number of **right shifts** required to sort* `nums` *and* `-1` *if this is not possible.*

A **right shift** is defined as shifting the element at index `i` to index `(i + 1) % n`, for all indices.

**Example 1:**

```

**Input:** nums = [3,4,5,1,2]
**Output:** 2
**Explanation:**
After the first right shift, nums = [2,3,4,5,1].
After the second right shift, nums = [1,2,3,4,5].
Now nums is sorted; therefore the answer is 2.

```

**Example 2:**

```

**Input:** nums = [1,3,5]
**Output:** 0
**Explanation:** nums is already sorted therefore, the answer is 0.
```

**Example 3:**

```

**Input:** nums = [2,1,4]
**Output:** -1
**Explanation:** It's impossible to sort the array using right shifts.

```

**Constraints:**

* `1 <= nums.length <= 100`
* `1 <= nums[i] <= 100`
* `nums` contains distinct integers.

Please make sure your answer follows the type signature below:

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

my_solution = Solution()

assert my_solution.minimumRightShifts(**[[3, 4, 5, 1, 2]]) == 2
assert my_solution.minimumRightShifts(**[[1, 3, 5]]) == 0
assert my_solution.minimumRightShifts(**[[2, 1, 4]]) == -1
assert my_solution.minimumRightShifts(**[[31, 72, 79, 25]]) == 1
assert my_solution.minimumRightShifts(**[[27, 33, 42, 58, 81, 8, 9, 17]]) == 3
assert my_solution.minimumRightShifts(**[[72, 13, 21, 35, 52]]) == 4
assert my_solution.minimumRightShifts(**[[65, 73, 77, 1]]) == 1
assert my_solution.minimumRightShifts(**[[100, 8, 14, 68, 80, 84]]) == 5
assert my_solution.minimumRightShifts(**[[53, 60, 64, 69, 98, 40]]) == 1
assert my_solution.minimumRightShifts(**[[21]]) == 0
assert my_solution.minimumRightShifts(**[[78, 12, 18, 21, 23, 36, 64, 70]]) == 7
assert my_solution.minimumRightShifts(**[[25, 26, 53, 91, 92, 99, 10, 24]]) == 2
assert my_solution.minimumRightShifts(**[[63, 51, 65, 87, 6, 17, 32, 14, 42, 46]]) == -1
assert my_solution.minimumRightShifts(**[[43, 46, 75, 76, 85, 96, 9, 19, 25]]) == 3
assert my_solution.minimumRightShifts(**[[5]]) == 0
assert my_solution.minimumRightShifts(**[[35, 72, 76, 82, 96, 97, 24, 26]]) == 2
assert my_solution.minimumRightShifts(**[[82, 30, 94, 55, 76, 51, 3, 89, 52, 96]]) == -1
assert my_solution.minimumRightShifts(**[[57, 59, 88, 97, 6, 27, 41, 46, 52]]) == 5
assert my_solution.minimumRightShifts(**[[17]]) == 0
assert my_solution.minimumRightShifts(**[[62]]) == 0


# Minimum Array Length After Pair Removals

You are given a **0-indexed** **sorted** array of integers `nums`.

You can perform the following operation any number of times:

* Choose **two** indices, `i` and `j`, where `i < j`, such that `nums[i] < nums[j]`.
* Then, remove the elements at indices `i` and `j` from `nums`. The remaining elements retain their original order, and the array is re-indexed.

Return *an integer that denotes the **minimum** length of* `nums` *after performing the operation any number of times (**including zero**).*

Note that `nums` is sorted in **non-decreasing** order.

**Example 1:**

```

**Input:** nums = [1,3,4,9]
**Output:** 0
**Explanation:** Initially, nums = [1, 3, 4, 9].
In the first operation, we can choose index 0 and 1 because nums[0] < nums[1] <=> 1 < 3.
Remove indices 0 and 1, and nums becomes [4, 9].
For the next operation, we can choose index 0 and 1 because nums[0] < nums[1] <=> 4 < 9.
Remove indices 0 and 1, and nums becomes an empty array [].
Hence, the minimum length achievable is 0.
```

**Example 2:**

```

**Input:** nums = [2,3,6,9]
**Output:** 0
**Explanation:** Initially, nums = [2, 3, 6, 9].
In the first operation, we can choose index 0 and 2 because nums[0] < nums[2] <=> 2 < 6.
Remove indices 0 and 2, and nums becomes [3, 9].
For the next operation, we can choose index 0 and 1 because nums[0] < nums[1] <=> 3 < 9.
Remove indices 0 and 1, and nums becomes an empty array [].
Hence, the minimum length achievable is 0.

```

**Example 3:**

```

**Input:** nums = [1,1,2]
**Output:** 1
**Explanation:** Initially, nums = [1, 1, 2].
In an operation, we can choose index 0 and 2 because nums[0] < nums[2] <=> 1 < 2.
Remove indices 0 and 2, and nums becomes [1].
It is no longer possible to perform an operation on the array.
Hence, the minimum achievable length is 1.

```

**Constraints:**

* `1 <= nums.length <= 105`
* `1 <= nums[i] <= 109`
* `nums` is sorted in **non-decreasing** order.

Please make sure your answer follows the type signature below:

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

my_solution = Solution()

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


# Count Pairs of Points With Distance k

You are given a **2D** integer array `coordinates` and an integer `k`, where `coordinates[i] = [xi, yi]` are the coordinates of the `ith` point in a 2D plane.

We define the **distance** between two points `(x1, y1)` and `(x2, y2)` as `(x1 XOR x2) + (y1 XOR y2)` where `XOR` is the bitwise `XOR` operation.

Return *the number of pairs* `(i, j)` *such that* `i < j` *and the distance between points* `i` *and* `j` *is equal to* `k`.

**Example 1:**

```

**Input:** coordinates = [[1,2],[4,2],[1,3],[5,2]], k = 5
**Output:** 2
**Explanation:** We can choose the following pairs:
- (0,1): Because we have (1 XOR 4) + (2 XOR 2) = 5.
- (2,3): Because we have (1 XOR 5) + (3 XOR 2) = 5.

```

**Example 2:**

```

**Input:** coordinates = [[1,3],[1,3],[1,3],[1,3],[1,3]], k = 0
**Output:** 10
**Explanation:** Any two chosen pairs will have a distance of 0. There are 10 ways to choose two pairs.

```

**Constraints:**

* `2 <= coordinates.length <= 50000`
* `0 <= xi, yi <= 106`
* `0 <= k <= 100`

Please make sure your answer follows the type signature below:

```python3
class Solution:
    def countPairs(self, coordinates: List[List[int]], k: int) -> int:
```


# Points That Intersect With Cars

You are given a **0-indexed** 2D integer array `nums` representing the coordinates of the cars parking on a number line. For any index `i`, `nums[i] = [starti, endi]` where `starti` is the starting point of the `ith` car and `endi` is the ending point of the `ith` car.

Return *the number of integer points on the line that are covered with **any part** of a car.*

**Example 1:**

```

**Input:** nums = [[3,6],[1,5],[4,7]]
**Output:** 7
**Explanation:** All the points from 1 to 7 intersect at least one car, therefore the answer would be 7.

```

**Example 2:**

```

**Input:** nums = [[1,3],[5,8]]
**Output:** 7
**Explanation:** Points intersecting at least one car are 1, 2, 3, 5, 6, 7, 8. There are a total of 7 points, therefore the answer would be 7.

```

**Constraints:**

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

Please make sure your answer follows the type signature below:

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


# String Transformation

You are given two strings `s` and `t` of equal length `n`. You can perform the following operation on the string `s`:

* Remove a **suffix** of `s` of length `l` where `0 < l < n` and append it at the start of `s`.

 For example, let `s = 'abcd'` then in one operation you can remove the suffix `'cd'` and append it in front of `s` making `s = 'cdab'`.

You are also given an integer `k`. Return *the number of ways in which* `s` *can be transformed into* `t` *in **exactly*** `k` *operations.*

Since the answer can be large, return it **modulo** `109 + 7`.

**Example 1:**

```

**Input:** s = "abcd", t = "cdab", k = 2
**Output:** 2
**Explanation:**
First way:
In first operation, choose suffix from index = 3, so resulting s = "dabc".
In second operation, choose suffix from index = 3, so resulting s = "cdab".

Second way:
In first operation, choose suffix from index = 1, so resulting s = "bcda".
In second operation, choose suffix from index = 1, so resulting s = "cdab".

```

**Example 2:**

```

**Input:** s = "ababab", t = "ababab", k = 1
**Output:** 2
**Explanation:**
First way:
Choose suffix from index = 2, so resulting s = "ababab".

Second way:
Choose suffix from index = 4, so resulting s = "ababab".

```

**Constraints:**

* `2 <= s.length <= 5 * 105`
* `1 <= k <= 1015`
* `s.length == t.length`
* `s` and `t` consist of only lowercase English alphabets.

Please make sure your answer follows the type signature below:

```python3
class Solution:
    def numberOfWays(self, s: str, t: str, k: int) -> int:
```

my_solution = Solution()

assert my_solution.numberOfWays(**['abcd', 'cdab', 2]) == 2
assert my_solution.numberOfWays(**['ababab', 'ababab', 1]) == 2
assert my_solution.numberOfWays(**['goxoq', 'dfqgl', 244326024901249]) == 0
assert my_solution.numberOfWays(**['ceoceo', 'eoceoc', 4]) == 208
assert my_solution.numberOfWays(**['ib', 'ib', 10]) == 1
assert my_solution.numberOfWays(**['ttttttt', 'ttttttt', 5]) == 7776
assert my_solution.numberOfWays(**['aaaa', 'aaaa', 8]) == 6561
assert my_solution.numberOfWays(**['meplrmeplr', 'eplrmeplrm', 7]) == 956594
assert my_solution.numberOfWays(**['dsmn', 'smnd', 3]) == 7
assert my_solution.numberOfWays(**['jjj', 'jjj', 10]) == 1024
assert my_solution.numberOfWays(**['rrrrr', 'rrrrr', 1]) == 4
assert my_solution.numberOfWays(**['fefe', 'fefe', 9]) == 9841
assert my_solution.numberOfWays(**['pfly', 'wvqr', 840550364246523]) == 0
assert my_solution.numberOfWays(**['ltjwwltjww', 'jwwltjwwlt', 1]) == 2
assert my_solution.numberOfWays(**['mb', 'mb', 3]) == 0
assert my_solution.numberOfWays(**['jjjjjjjjjj', 'jjjjjjjjjj', 3]) == 729
assert my_solution.numberOfWays(**['oqytlmi', 'lmioqyt', 8]) == 239945
assert my_solution.numberOfWays(**['hpcg', 'pcgh', 5]) == 61
assert my_solution.numberOfWays(**['bqbqbqbqbq', 'bqbqbqbqbq', 9]) == 193710244
assert my_solution.numberOfWays(**['ccccccccc', 'ccccccccc', 7]) == 2097152


#   Count Symmetric Integers

You are given two positive integers `low` and `high`.

An integer `x` consisting of `2 * n` digits is **symmetric** if the sum of the first `n` digits of `x` is equal to the sum of the last `n` digits of `x`. Numbers with an odd number of digits are never symmetric.

Return *the **number of symmetric** integers in the range* `[low, high]`.

**Example 1:**

```

**Input:** low = 1, high = 100
**Output:** 9
**Explanation:** There are 9 symmetric integers between 1 and 100: 11, 22, 33, 44, 55, 66, 77, 88, and 99.

```

**Example 2:**

```

**Input:** low = 1200, high = 1230
**Output:** 4
**Explanation:** There are 4 symmetric integers between 1200 and 1230: 1203, 1212, 1221, and 1230.

```

**Constraints:**

* `1 <= low <= high <= 104`

Please make sure your answer follows the type signature below:

```python3
class Solution:
    def countSymmetricIntegers(self, low: int, high: int) -> int:
```

my_solution = Solution()

assert my_solution.countSymmetricIntegers(**[1, 100]) == 9
assert my_solution.countSymmetricIntegers(**[1200, 1230]) == 4
assert my_solution.countSymmetricIntegers(**[1, 1]) == 0
assert my_solution.countSymmetricIntegers(**[1, 2]) == 0
assert my_solution.countSymmetricIntegers(**[1, 3]) == 0
assert my_solution.countSymmetricIntegers(**[1, 4]) == 0
assert my_solution.countSymmetricIntegers(**[1, 5]) == 0
assert my_solution.countSymmetricIntegers(**[1, 6]) == 0
assert my_solution.countSymmetricIntegers(**[1, 7]) == 0
assert my_solution.countSymmetricIntegers(**[1, 8]) == 0
assert my_solution.countSymmetricIntegers(**[1, 9]) == 0
assert my_solution.countSymmetricIntegers(**[1, 10]) == 0
assert my_solution.countSymmetricIntegers(**[1, 11]) == 1
assert my_solution.countSymmetricIntegers(**[1, 12]) == 1
assert my_solution.countSymmetricIntegers(**[1, 13]) == 1
assert my_solution.countSymmetricIntegers(**[1, 14]) == 1
assert my_solution.countSymmetricIntegers(**[1, 15]) == 1
assert my_solution.countSymmetricIntegers(**[1, 16]) == 1
assert my_solution.countSymmetricIntegers(**[1, 17]) == 1
assert my_solution.countSymmetricIntegers(**[1, 18]) == 1


# Minimum Operations to Make a Special Number

You are given a **0-indexed** string `num` representing a non-negative integer.

In one operation, you can pick any digit of `num` and delete it. Note that if you delete all the digits of `num`, `num` becomes `0`.

Return *the **minimum number of operations** required to make* `num` *special*.

An integer `x` is considered **special** if it is divisible by `25`.

**Example 1:**

```

**Input:** num = "2245047"
**Output:** 2
**Explanation:** Delete digits num[5] and num[6]. The resulting number is "22450" which is special since it is divisible by 25.
It can be shown that 2 is the minimum number of operations required to get a special number.
```

**Example 2:**

```

**Input:** num = "2908305"
**Output:** 3
**Explanation:** Delete digits num[3], num[4], and num[6]. The resulting number is "2900" which is special since it is divisible by 25.
It can be shown that 3 is the minimum number of operations required to get a special number.
```

**Example 3:**

```

**Input:** num = "10"
**Output:** 1
**Explanation:** Delete digit num[0]. The resulting number is "0" which is special since it is divisible by 25.
It can be shown that 1 is the minimum number of operations required to get a special number.

```

**Constraints:**

* `1 <= num.length <= 100`
* `num` only consists of digits `'0'` through `'9'`.
* `num` does not contain any leading zeros.

Please make sure your answer follows the type signature below:

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

my_solution = Solution()

assert my_solution.minimumOperations(**['2245047']) == 2
assert my_solution.minimumOperations(**['2908305']) == 3
assert my_solution.minimumOperations(**['10']) == 1
assert my_solution.minimumOperations(**['1']) == 1
assert my_solution.minimumOperations(**['2']) == 1
assert my_solution.minimumOperations(**['3']) == 1
assert my_solution.minimumOperations(**['4']) == 1
assert my_solution.minimumOperations(**['5']) == 1
assert my_solution.minimumOperations(**['6']) == 1
assert my_solution.minimumOperations(**['7']) == 1
assert my_solution.minimumOperations(**['8']) == 1
assert my_solution.minimumOperations(**['9']) == 1
assert my_solution.minimumOperations(**['11']) == 2
assert my_solution.minimumOperations(**['12']) == 2
assert my_solution.minimumOperations(**['13']) == 2
assert my_solution.minimumOperations(**['14']) == 2
assert my_solution.minimumOperations(**['15']) == 2
assert my_solution.minimumOperations(**['16']) == 2
assert my_solution.minimumOperations(**['17']) == 2
assert my_solution.minimumOperations(**['18']) == 2


# Count of Interesting Subarrays

You are given a **0-indexed** integer array `nums`, an integer `modulo`, and an integer `k`.

Your task is to find the count of subarrays that are **interesting**.

A **subarray** `nums[l..r]` is **interesting** if the following condition holds:

* Let `cnt` be the number of indices `i` in the range `[l, r]` such that `nums[i] % modulo == k`. Then, `cnt % modulo == k`.

Return *an integer denoting the count of interesting subarrays.*

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

**Example 1:**

```

**Input:** nums = [3,2,4], modulo = 2, k = 1
**Output:** 3
**Explanation:** In this example the interesting subarrays are:
The subarray nums[0..0] which is [3].
- There is only one index, i = 0, in the range [0, 0] that satisfies nums[i] % modulo == k.
- Hence, cnt = 1 and cnt % modulo == k.
The subarray nums[0..1] which is [3,2].
- There is only one index, i = 0, in the range [0, 1] that satisfies nums[i] % modulo == k.
- Hence, cnt = 1 and cnt % modulo == k.
The subarray nums[0..2] which is [3,2,4].
- There is only one index, i = 0, in the range [0, 2] that satisfies nums[i] % modulo == k.
- Hence, cnt = 1 and cnt % modulo == k.
It can be shown that there are no other interesting subarrays. So, the answer is 3.
```

**Example 2:**

```

**Input:** nums = [3,1,9,6], modulo = 3, k = 0
**Output:** 2
**Explanation:** In this example the interesting subarrays are:
The subarray nums[0..3] which is [3,1,9,6].
- There are three indices, i = 0, 2, 3, in the range [0, 3] that satisfy nums[i] % modulo == k.
- Hence, cnt = 3 and cnt % modulo == k.
The subarray nums[1..1] which is [1].
- There is no index, i, in the range [1, 1] that satisfies nums[i] % modulo == k.
- Hence, cnt = 0 and cnt % modulo == k.
It can be shown that there are no other interesting subarrays. So, the answer is 2.
```

**Constraints:**

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

Please make sure your answer follows the type signature below:

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

my_solution = Solution()

assert my_solution.countInterestingSubarrays(**[[3, 2, 4], 2, 1]) == 3
assert my_solution.countInterestingSubarrays(**[[3, 1, 9, 6], 3, 0]) == 2
assert my_solution.countInterestingSubarrays(**[[11, 12, 21, 31], 10, 1]) == 5
assert my_solution.countInterestingSubarrays(**[[2, 4], 7, 2]) == 0
assert my_solution.countInterestingSubarrays(**[[2, 7], 7, 0]) == 1
assert my_solution.countInterestingSubarrays(**[[2, 45], 13, 2]) == 0
assert my_solution.countInterestingSubarrays(**[[3, 3], 5, 3]) == 0
assert my_solution.countInterestingSubarrays(**[[3, 4], 8, 3]) == 0
assert my_solution.countInterestingSubarrays(**[[4, 5], 1, 0]) == 3
assert my_solution.countInterestingSubarrays(**[[5, 1], 6, 1]) == 2
assert my_solution.countInterestingSubarrays(**[[7, 2], 7, 0]) == 1
assert my_solution.countInterestingSubarrays(**[[7, 4], 7, 0]) == 1
assert my_solution.countInterestingSubarrays(**[[8, 8], 4, 0]) == 0
assert my_solution.countInterestingSubarrays(**[[9, 2], 2, 0]) == 1
assert my_solution.countInterestingSubarrays(**[[18, 43], 3, 0]) == 1
assert my_solution.countInterestingSubarrays(**[[19, 67], 47, 19]) == 0
assert my_solution.countInterestingSubarrays(**[[20, 8], 41, 8]) == 0
assert my_solution.countInterestingSubarrays(**[[26, 5], 21, 5]) == 0
assert my_solution.countInterestingSubarrays(**[[81, 36], 4, 0]) == 1
assert my_solution.countInterestingSubarrays(**[[2, 1, 5], 9, 1]) == 4


# Check if Strings Can be Made Equal With Operations I

You are given two strings `s1` and `s2`, both of length `4`, consisting of **lowercase** English letters.

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

* Choose any two indices `i` and `j` such that `j - i = 2`, then **swap** the two characters at those indices in the string.

Return `true` *if you can make the strings* `s1` *and* `s2` *equal, and* `false` *otherwise*.

**Example 1:**

```

**Input:** s1 = "abcd", s2 = "cdab"
**Output:** true
**Explanation:** We can do the following operations on s1:
- Choose the indices i = 0, j = 2. The resulting string is s1 = "cbad".
- Choose the indices i = 1, j = 3. The resulting string is s1 = "cdab" = s2.

```

**Example 2:**

```

**Input:** s1 = "abcd", s2 = "dacb"
**Output:** false
**Explanation:** It is not possible to make the two strings equal.

```

**Constraints:**

* `s1.length == s2.length == 4`
* `s1` and `s2` consist only of lowercase English letters.

Please make sure your answer follows the type signature below:

```python3
class Solution:
    def canBeEqual(self, s1: str, s2: str) -> bool:
```

my_solution = Solution()

assert my_solution.canBeEqual(**['abcd', 'cdab']) == True
assert my_solution.canBeEqual(**['abcd', 'dacb']) == False
assert my_solution.canBeEqual(**['bnxw', 'bwxn']) == True
assert my_solution.canBeEqual(**['gudo', 'ogdu']) == False
assert my_solution.canBeEqual(**['xsvc', 'vcxs']) == True
assert my_solution.canBeEqual(**['hvsz', 'hzsv']) == True
assert my_solution.canBeEqual(**['zzon', 'zozn']) == False
assert my_solution.canBeEqual(**['zrmq', 'mrzq']) == True
assert my_solution.canBeEqual(**['cmpr', 'rmcp']) == False
assert my_solution.canBeEqual(**['qnde', 'flsi']) == False
assert my_solution.canBeEqual(**['kina', 'kina']) == True
assert my_solution.canBeEqual(**['vofo', 'oofv']) == False
assert my_solution.canBeEqual(**['riti', 'riti']) == True
assert my_solution.canBeEqual(**['ifjz', 'jzfi']) == False
assert my_solution.canBeEqual(**['hazw', 'pfmp']) == False
assert my_solution.canBeEqual(**['goze', 'gezo']) == True
assert my_solution.canBeEqual(**['gcdm', 'dmgc']) == True
assert my_solution.canBeEqual(**['fymg', 'famj']) == False
assert my_solution.canBeEqual(**['seeo', 'vfvm']) == False
assert my_solution.canBeEqual(**['kvne', 'nekv']) == True


# Check if Strings Can be Made Equal With Operations II

You are given two strings `s1` and `s2`, both of length `n`, consisting of **lowercase** English letters.

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

* Choose any two indices `i` and `j` such that `i < j` and the difference `j - i` is **even**, then **swap** the two characters at those indices in the string.

Return `true` *if you can make the strings* `s1` *and* `s2` *equal, and*`false` *otherwise*.

**Example 1:**

```

**Input:** s1 = "abcdba", s2 = "cabdab"
**Output:** true
**Explanation:** We can apply the following operations on s1:
- Choose the indices i = 0, j = 2. The resulting string is s1 = "cbadba".
- Choose the indices i = 2, j = 4. The resulting string is s1 = "cbbdaa".
- Choose the indices i = 1, j = 5. The resulting string is s1 = "cabdab" = s2.

```

**Example 2:**

```

**Input:** s1 = "abe", s2 = "bea"
**Output:** false
**Explanation:** It is not possible to make the two strings equal.

```

**Constraints:**

* `n == s1.length == s2.length`
* `1 <= n <= 105`
* `s1` and `s2` consist only of lowercase English letters.

Please make sure your answer follows the type signature below:

```python3
class Solution:
    def checkStrings(self, s1: str, s2: str) -> bool:
```

my_solution = Solution()

assert my_solution.checkStrings(**['abcdba', 'cabdab']) == True
assert my_solution.checkStrings(**['abe', 'bea']) == False
assert my_solution.checkStrings(**['ublnlasppynwgx', 'ganplbuylnswpx']) == True
assert my_solution.checkStrings(**['aavizsxpqhxztrwi', 'zvisqatzpaxhixwr']) == False
assert my_solution.checkStrings(**['jghn', 'jghn']) == True
assert my_solution.checkStrings(**['slmqqdbrwyvm', 'qyldmmwsrqvb']) == False
assert my_solution.checkStrings(**['pqtsprqmvi', 'qrvqpitmps']) == True
assert my_solution.checkStrings(**['shvqocguj', 'vqsghujco']) == False
assert my_solution.checkStrings(**['usvpwcehhvlg', 'ehuvvshcwplg']) == True
assert my_solution.checkStrings(**['ppmfd', 'pfdpm']) == True
assert my_solution.checkStrings(**['ktjpralqanofuuqsyal', 'qjlornpasktfuyluaqa']) == False
assert my_solution.checkStrings(**['epjtzubboiallzd', 'dboilpzzjteualb']) == True
assert my_solution.checkStrings(**['mgflranpdjdkrh', 'fpcgobmkdxbzyl']) == False
assert my_solution.checkStrings(**['jh', 'fy']) == False
assert my_solution.checkStrings(**['c', 'c']) == True
assert my_solution.checkStrings(**['kfqofkvsoiiirznw', 'hosthwbinxrsikkf']) == False
assert my_solution.checkStrings(**['ntuuwwh', 'jyjwmdf']) == False
assert my_solution.checkStrings(**['oziiqbotydegrm', 'ytizriobogqmed']) == True
assert my_solution.checkStrings(**['ztmuzn', 'muztzn']) == True
assert my_solution.checkStrings(**['lcgcm', 'brdxe']) == False


# Maximum Sum of Almost Unique Subarray

You are given an integer array `nums` and two positive integers `m` and `k`.

Return *the **maximum sum** out of all **almost unique** subarrays of length* `k` *of* `nums`. If no such subarray exists, return `0`.

A subarray of `nums` is **almost unique** if it contains at least `m` distinct elements.

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

**Example 1:**

```

**Input:** nums = [2,6,7,3,1,7], m = 3, k = 4
**Output:** 18
**Explanation:** There are 3 almost unique subarrays of size k = 4. These subarrays are [2, 6, 7, 3], [6, 7, 3, 1], and [7, 3, 1, 7]. Among these subarrays, the one with the maximum sum is [2, 6, 7, 3] which has a sum of 18.

```

**Example 2:**

```

**Input:** nums = [5,9,9,2,4,5,4], m = 1, k = 3
**Output:** 23
**Explanation:** There are 5 almost unique subarrays of size k. These subarrays are [5, 9, 9], [9, 9, 2], [9, 2, 4], [2, 4, 5], and [4, 5, 4]. Among these subarrays, the one with the maximum sum is [5, 9, 9] which has a sum of 23.

```

**Example 3:**

```

**Input:** nums = [1,2,1,2,1,2,1], m = 3, k = 3
**Output:** 0
**Explanation:** There are no subarrays of size k = 3 that contain at least m = 3 distinct elements in the given array [1,2,1,2,1,2,1]. Therefore, no almost unique subarrays exist, and the maximum sum is 0.

```

**Constraints:**

* `1 <= nums.length <= 2 * 104`
* `1 <= m <= k <= nums.length`
* `1 <= nums[i] <= 109`

Please make sure your answer follows the type signature below:

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


# Count K-Subsequences of a String With Maximum Beauty

You are given a string `s` and an integer `k`.

A **k-subsequence** is a **subsequence** of `s`, having length `k`, and all its characters are **unique**, **i.e**., every character occurs once.

Let `f(c)` denote the number of times the character `c` occurs in `s`.

The **beauty** of a **k-subsequence** is the **sum** of `f(c)` for every character `c` in the k-subsequence.

For example, consider `s = "abbbdd"` and `k = 2`:

* `f('a') = 1`, `f('b') = 3`, `f('d') = 2`
* Some k-subsequences of `s` are:
	+ `"**ab**bbdd"` -> `"ab"` having a beauty of `f('a') + f('b') = 4`
	+ `"**a**bbb**d**d"` -> `"ad"` having a beauty of `f('a') + f('d') = 3`
	+ `"a**b**bb**d**d"` -> `"bd"` having a beauty of `f('b') + f('d') = 5`

Return *an integer denoting the number of k-subsequences* *whose **beauty** is the **maximum** among all **k-subsequences***. Since the answer may be too large, return it modulo `109 + 7`.

A subsequence of a string is a new string formed from the original string by deleting some (possibly none) of the characters without disturbing the relative positions of the remaining characters.

**Notes**

* `f(c)` is the number of times a character `c` occurs in `s`, not a k-subsequence.
* Two k-subsequences are considered different if one is formed by an index that is not present in the other. So, two k-subsequences may form the same string.

**Example 1:**

```

**Input:** s = "bcca", k = 2
**Output:** 4
**Explanation:** From s we have f('a') = 1, f('b') = 1, and f('c') = 2.
The k-subsequences of s are:
**bc**ca having a beauty of f('b') + f('c') = 3
**b**c**c**a having a beauty of f('b') + f('c') = 3
**b**cc**a** having a beauty of f('b') + f('a') = 2
b**c**c**a**having a beauty of f('c') + f('a') = 3
bc**ca** having a beauty of f('c') + f('a') = 3
There are 4 k-subsequences that have the maximum beauty, 3.
Hence, the answer is 4.

```

**Example 2:**

```

**Input:** s = "abbcd", k = 4
**Output:** 2
**Explanation:** From s we have f('a') = 1, f('b') = 2, f('c') = 1, and f('d') = 1.
The k-subsequences of s are:
**ab**b**cd** having a beauty of f('a') + f('b') + f('c') + f('d') = 5
**a**b**bcd** having a beauty of f('a') + f('b') + f('c') + f('d') = 5
There are 2 k-subsequences that have the maximum beauty, 5.
Hence, the answer is 2.

```

**Constraints:**

* `1 <= s.length <= 2 * 105`
* `1 <= k <= s.length`
* `s` consists only of lowercase English letters.

Please make sure your answer follows the type signature below:

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

my_solution = Solution()

assert my_solution.countKSubsequencesWithMaxBeauty(**['bcca', 2]) == 4
assert my_solution.countKSubsequencesWithMaxBeauty(**['abbcd', 4]) == 2
assert my_solution.countKSubsequencesWithMaxBeauty(**['am', 2]) == 1
assert my_solution.countKSubsequencesWithMaxBeauty(**['az', 2]) == 1
assert my_solution.countKSubsequencesWithMaxBeauty(**['ci', 1]) == 2
assert my_solution.countKSubsequencesWithMaxBeauty(**['dd', 2]) == 0
assert my_solution.countKSubsequencesWithMaxBeauty(**['di', 2]) == 1
assert my_solution.countKSubsequencesWithMaxBeauty(**['dw', 2]) == 1
assert my_solution.countKSubsequencesWithMaxBeauty(**['ef', 1]) == 2
assert my_solution.countKSubsequencesWithMaxBeauty(**['gq', 2]) == 1
assert my_solution.countKSubsequencesWithMaxBeauty(**['hj', 1]) == 2
assert my_solution.countKSubsequencesWithMaxBeauty(**['hx', 1]) == 2
assert my_solution.countKSubsequencesWithMaxBeauty(**['ii', 2]) == 0
assert my_solution.countKSubsequencesWithMaxBeauty(**['il', 2]) == 1
assert my_solution.countKSubsequencesWithMaxBeauty(**['jb', 1]) == 2
assert my_solution.countKSubsequencesWithMaxBeauty(**['kx', 1]) == 2
assert my_solution.countKSubsequencesWithMaxBeauty(**['qh', 2]) == 1
assert my_solution.countKSubsequencesWithMaxBeauty(**['qk', 2]) == 1
assert my_solution.countKSubsequencesWithMaxBeauty(**['qr', 2]) == 1
assert my_solution.countKSubsequencesWithMaxBeauty(**['rg', 2]) == 1


# Furthest Point From Origin

You are given a string `moves` of length `n` consisting only of characters `'L'`, `'R'`, and `'_'`. The string represents your movement on a number line starting from the origin `0`.

In the `ith` move, you can choose one of the following directions:

* move to the left if `moves[i] = 'L'` or `moves[i] = '_'`
* move to the right if `moves[i] = 'R'` or `moves[i] = '_'`

Return *the **distance from the origin** of the **furthest** point you can get to after* `n` *moves*.

**Example 1:**

```

**Input:** moves = "L_RL__R"
**Output:** 3
**Explanation:** The furthest point we can reach from the origin 0 is point -3 through the following sequence of moves "LLRLLLR".

```

**Example 2:**

```

**Input:** moves = "_R__LL_"
**Output:** 5
**Explanation:** The furthest point we can reach from the origin 0 is point -5 through the following sequence of moves "LRLLLLL".

```

**Example 3:**

```

**Input:** moves = "_______"
**Output:** 7
**Explanation:** The furthest point we can reach from the origin 0 is point 7 through the following sequence of moves "RRRRRRR".

```

**Constraints:**

* `1 <= moves.length == n <= 50`
* `moves` consists only of characters `'L'`, `'R'` and `'_'`.

Please make sure your answer follows the type signature below:

```python3
class Solution:
    def furthestDistanceFromOrigin(self, moves: str) -> int:
```

my_solution = Solution()

assert my_solution.furthestDistanceFromOrigin(**['L_RL__R']) == 3
assert my_solution.furthestDistanceFromOrigin(**['_R__LL_']) == 5
assert my_solution.furthestDistanceFromOrigin(**['_______']) == 7
assert my_solution.furthestDistanceFromOrigin(**['L']) == 1
assert my_solution.furthestDistanceFromOrigin(**['R']) == 1
assert my_solution.furthestDistanceFromOrigin(**['_']) == 1
assert my_solution.furthestDistanceFromOrigin(**['LL']) == 2
assert my_solution.furthestDistanceFromOrigin(**['LR']) == 0
assert my_solution.furthestDistanceFromOrigin(**['L_']) == 2
assert my_solution.furthestDistanceFromOrigin(**['RL']) == 0
assert my_solution.furthestDistanceFromOrigin(**['RR']) == 2
assert my_solution.furthestDistanceFromOrigin(**['R_']) == 2
assert my_solution.furthestDistanceFromOrigin(**['_L']) == 2
assert my_solution.furthestDistanceFromOrigin(**['_R']) == 2
assert my_solution.furthestDistanceFromOrigin(**['__']) == 2
assert my_solution.furthestDistanceFromOrigin(**['LLL']) == 3
assert my_solution.furthestDistanceFromOrigin(**['LLR']) == 1
assert my_solution.furthestDistanceFromOrigin(**['LL_']) == 3
assert my_solution.furthestDistanceFromOrigin(**['LRL']) == 1
assert my_solution.furthestDistanceFromOrigin(**['LRR']) == 1