# Find the Minimum Possible Sum of a Beautiful Array

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

An array `nums` is **beautiful** if it meets the following conditions:

* `nums.length == n`.
* `nums` consists of pairwise **distinct** **positive** integers.
* There doesn't exist two **distinct** indices, `i` and `j`, in the range `[0, n - 1]`, such that `nums[i] + nums[j] == target`.

Return *the **minimum** possible sum that a beautiful array could have modulo* `109 + 7`.

**Example 1:**

```

**Input:** n = 2, target = 3
**Output:** 4
**Explanation:** We can see that nums = [1,3] is beautiful.
- The array nums has length n = 2.
- The array nums consists of pairwise distinct positive integers.
- There doesn't exist two distinct indices, i and j, with nums[i] + nums[j] == 3.
It can be proven that 4 is the minimum possible sum that a beautiful array could have.

```

**Example 2:**

```

**Input:** n = 3, target = 3
**Output:** 8
**Explanation:** We can see that nums = [1,3,4] is beautiful.
- The array nums has length n = 3.
- The array nums consists of pairwise distinct positive integers.
- There doesn't exist two distinct indices, i and j, with nums[i] + nums[j] == 3.
It can be proven that 8 is the minimum possible sum that a beautiful array could have.

```

**Example 3:**

```

**Input:** n = 1, target = 1
**Output:** 1
**Explanation:** We can see, that nums = [1] is beautiful.

```

**Constraints:**

* `1 <= n <= 109`
* `1 <= target <= 109`

Please make sure your answer follows the type signature below:

```python3
class Solution:
    def minimumPossibleSum(self, n: int, target: int) -> int:
```

my_solution = Solution()

assert my_solution.minimumPossibleSum(**[2, 3]) == 4
assert my_solution.minimumPossibleSum(**[3, 3]) == 8
assert my_solution.minimumPossibleSum(**[1, 1]) == 1
assert my_solution.minimumPossibleSum(**[16, 6]) == 162
assert my_solution.minimumPossibleSum(**[16, 32]) == 136
assert my_solution.minimumPossibleSum(**[13, 50]) == 91
assert my_solution.minimumPossibleSum(**[36, 21]) == 926
assert my_solution.minimumPossibleSum(**[40, 17]) == 1076
assert my_solution.minimumPossibleSum(**[37, 46]) == 1011
assert my_solution.minimumPossibleSum(**[33, 7]) == 651
assert my_solution.minimumPossibleSum(**[42, 46]) == 1321
assert my_solution.minimumPossibleSum(**[46, 29]) == 1529
assert my_solution.minimumPossibleSum(**[9, 43]) == 45
assert my_solution.minimumPossibleSum(**[30, 31]) == 690
assert my_solution.minimumPossibleSum(**[14, 47]) == 105
assert my_solution.minimumPossibleSum(**[5, 3]) == 19
assert my_solution.minimumPossibleSum(**[41, 23]) == 1191
assert my_solution.minimumPossibleSum(**[17, 13]) == 219
assert my_solution.minimumPossibleSum(**[9, 13]) == 63
assert my_solution.minimumPossibleSum(**[29, 18]) == 595


# Minimum Operations to Form Subsequence With Target Sum

You are given a **0-indexed** array `nums` consisting of **non-negative** powers of `2`, and an integer `target`.

In one operation, you must apply the following changes to the array:

* Choose any element of the array `nums[i]` such that `nums[i] > 1`.
* Remove `nums[i]` from the array.
* Add **two** occurrences of `nums[i] / 2` to the **end** of `nums`.

Return the ***minimum number of operations** you need to perform so that* `nums` *contains a **subsequence** whose elements sum to* `target`. If it is impossible to obtain such a subsequence, return `-1`.

A **subsequence** is an array that can be derived from another array by deleting some or no elements without changing the order of the remaining elements.

**Example 1:**

```

**Input:** nums = [1,2,8], target = 7
**Output:** 1
**Explanation:** In the first operation, we choose element nums[2]. The array becomes equal to nums = [1,2,4,4].
At this stage, nums contains the subsequence [1,2,4] which sums up to 7.
It can be shown that there is no shorter sequence of operations that results in a subsequnce that sums up to 7.

```

**Example 2:**

```

**Input:** nums = [1,32,1,2], target = 12
**Output:** 2
**Explanation:** In the first operation, we choose element nums[1]. The array becomes equal to nums = [1,1,2,16,16].
In the second operation, we choose element nums[3]. The array becomes equal to nums = [1,1,2,16,8,8]
At this stage, nums contains the subsequence [1,1,2,8] which sums up to 12.
It can be shown that there is no shorter sequence of operations that results in a subsequence that sums up to 12.
```

**Example 3:**

```

**Input:** nums = [1,32,1], target = 35
**Output:** -1
**Explanation:** It can be shown that no sequence of operations results in a subsequence that sums up to 35.

```

**Constraints:**

* `1 <= nums.length <= 1000`
* `1 <= nums[i] <= 230`
* `nums` consists only of non-negative powers of two.
* `1 <= target < 231`

Please make sure your answer follows the type signature below:

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

my_solution = Solution()

assert my_solution.minOperations(**[[1, 2, 8], 7]) == 1
assert my_solution.minOperations(**[[1, 32, 1, 2], 12]) == 2
assert my_solution.minOperations(**[[1, 32, 1], 35]) == -1
assert my_solution.minOperations(**[[1], 1]) == 0
assert my_solution.minOperations(**[[16, 128, 32], 1]) == 4
assert my_solution.minOperations(**[[1, 1], 2]) == 0
assert my_solution.minOperations(**[[64, 128, 128], 2]) == 5
assert my_solution.minOperations(**[[2], 2]) == 0
assert my_solution.minOperations(**[[32, 256, 4], 2]) == 1
assert my_solution.minOperations(**[[1, 1, 1], 3]) == 0
assert my_solution.minOperations(**[[1, 256, 16, 128], 3]) == 3
assert my_solution.minOperations(**[[1, 2], 3]) == 0
assert my_solution.minOperations(**[[16, 16, 4], 3]) == 2
assert my_solution.minOperations(**[[1, 1, 1, 1], 4]) == 0
assert my_solution.minOperations(**[[128, 1, 128, 1, 64], 4]) == 4
assert my_solution.minOperations(**[[2, 1, 1], 4]) == 0
assert my_solution.minOperations(**[[8, 2, 64, 32], 4]) == 1
assert my_solution.minOperations(**[[16, 128, 8, 1, 1], 4]) == 1
assert my_solution.minOperations(**[[1, 2, 1], 4]) == 0
assert my_solution.minOperations(**[[128, 8, 8, 2], 4]) == 1


# Maximize Value of Function in a Ball Passing Game

You are given a **0-indexed** integer array `receiver` of length `n` and an integer `k`.

There are `n` players having a **unique id** in the range `[0, n - 1]` who will play a ball passing game, and `receiver[i]` is the id of the player who receives passes from the player with id `i`. Players can pass to themselves, **i.e.** `receiver[i]` may be equal to `i`.

You must choose one of the `n` players as the starting player for the game, and the ball will be passed **exactly** `k` times starting from the chosen player.

For a chosen starting player having id `x`, we define a function `f(x)` that denotes the **sum** of `x` and the **ids** of all players who receive the ball during the `k` passes, **including repetitions**. In other words, `f(x) = x + receiver[x] + receiver[receiver[x]] + ... + receiver(k)[x]`.

Your task is to choose a starting player having id `x` that **maximizes** the value of `f(x)`.

Return *an integer denoting the **maximum** value of the function.*

**Note:** `receiver` may contain duplicates.

**Example 1:**

| Pass Number | Sender ID | Receiver ID | x + Receiver IDs |
| --- | --- | --- | --- |
|  |  |  | 2 |
| 1 | 2 | 1 | 3 |
| 2 | 1 | 0 | 3 |
| 3 | 0 | 2 | 5 |
| 4 | 2 | 1 | 6 |

```

**Input:** receiver = [2,0,1], k = 4
**Output:** 6
**Explanation:** The table above shows a simulation of the game starting with the player having id x = 2.
From the table, f(2) is equal to 6.
It can be shown that 6 is the maximum achievable value of the function.
Hence, the output is 6.

```

**Example 2:**

| Pass Number | Sender ID | Receiver ID | x + Receiver IDs |
| --- | --- | --- | --- |
|  |  |  | 4 |
| 1 | 4 | 3 | 7 |
| 2 | 3 | 2 | 9 |
| 3 | 2 | 1 | 10 |

```

**Input:** receiver = [1,1,1,2,3], k = 3
**Output:** 10
**Explanation:** The table above shows a simulation of the game starting with the player having id x = 4.
From the table, f(4) is equal to 10.
It can be shown that 10 is the maximum achievable value of the function.
Hence, the output is 10.

```

**Constraints:**

* `1 <= receiver.length == n <= 105`
* `0 <= receiver[i] <= n - 1`
* `1 <= k <= 1010`

Please make sure your answer follows the type signature below:

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

my_solution = Solution()

assert my_solution.getMaxFunctionValue(**[[2, 0, 1], 4]) == 6
assert my_solution.getMaxFunctionValue(**[[1, 1, 1, 2, 3], 3]) == 10
assert my_solution.getMaxFunctionValue(**[[0], 1]) == 0
assert my_solution.getMaxFunctionValue(**[[0], 2]) == 0
assert my_solution.getMaxFunctionValue(**[[0], 3]) == 0
assert my_solution.getMaxFunctionValue(**[[0], 100]) == 0
assert my_solution.getMaxFunctionValue(**[[0, 0], 1]) == 1
assert my_solution.getMaxFunctionValue(**[[0, 0], 7]) == 1
assert my_solution.getMaxFunctionValue(**[[0, 0], 10]) == 1
assert my_solution.getMaxFunctionValue(**[[0, 0], 13]) == 1
assert my_solution.getMaxFunctionValue(**[[0, 0], 16]) == 1
assert my_solution.getMaxFunctionValue(**[[0, 1], 1]) == 2
assert my_solution.getMaxFunctionValue(**[[0, 1], 3]) == 4
assert my_solution.getMaxFunctionValue(**[[0, 1], 5]) == 6
assert my_solution.getMaxFunctionValue(**[[0, 1], 8]) == 9
assert my_solution.getMaxFunctionValue(**[[0, 1], 13]) == 14
assert my_solution.getMaxFunctionValue(**[[0, 1], 14]) == 15
assert my_solution.getMaxFunctionValue(**[[0, 1], 15]) == 16
assert my_solution.getMaxFunctionValue(**[[1, 0], 5]) == 3
assert my_solution.getMaxFunctionValue(**[[1, 0], 6]) == 4


# Check if a String Is an Acronym of Words

Given an array of strings `words` and a string `s`, determine if `s` is an **acronym** of words.

The string `s` is considered an acronym of `words` if it can be formed by concatenating the **first** character of each string in `words` **in order**. For example, `"ab"` can be formed from `["apple", "banana"]`, but it can't be formed from `["bear", "aardvark"]`.

Return `true` *if* `s` *is an acronym of* `words`*, and* `false` *otherwise.*

**Example 1:**

```

**Input:** words = ["alice","bob","charlie"], s = "abc"
**Output:** true
**Explanation:** The first character in the words "alice", "bob", and "charlie" are 'a', 'b', and 'c', respectively. Hence, s = "abc" is the acronym.

```

**Example 2:**

```

**Input:** words = ["an","apple"], s = "a"
**Output:** false
**Explanation:** The first character in the words "an" and "apple" are 'a' and 'a', respectively.
The acronym formed by concatenating these characters is "aa".
Hence, s = "a" is not the acronym.

```

**Example 3:**

```

**Input:** words = ["never","gonna","give","up","on","you"], s = "ngguoy"
**Output:** true
**Explanation:** By concatenating the first character of the words in the array, we get the string "ngguoy".
Hence, s = "ngguoy" is the acronym.

```

**Constraints:**

* `1 <= words.length <= 100`
* `1 <= words[i].length <= 10`
* `1 <= s.length <= 100`
* `words[i]` and `s` consist of lowercase English letters.

Please make sure your answer follows the type signature below:

```python3
class Solution:
    def isAcronym(self, words: List[str], s: str) -> bool:
```

my_solution = Solution()

assert my_solution.isAcronym(**[['alice', 'bob', 'charlie'], 'abc']) == True
assert my_solution.isAcronym(**[['an', 'apple'], 'a']) == False
assert my_solution.isAcronym(**[['never', 'gonna', 'give', 'up', 'on', 'you'], 'ngguoy']) == True
assert my_solution.isAcronym(**[['ad', 'uadhrwxki'], 'au']) == True
assert my_solution.isAcronym(**[['afkc', 'icxufam'], 'ai']) == True
assert my_solution.isAcronym(**[['afqcpzsx', 'icenu'], 'yi']) == False
assert my_solution.isAcronym(**[['ahbibag', 'aoximesw'], 'aa']) == True
assert my_solution.isAcronym(**[['auqoc', 'koioxa'], 'ak']) == True
assert my_solution.isAcronym(**[['b', 'x'], 'bx']) == True
assert my_solution.isAcronym(**[['bpctc', 'kaqquqbpmw'], 'bk']) == True
assert my_solution.isAcronym(**[['c', 'df'], 'bd']) == False
assert my_solution.isAcronym(**[['c', 'evlvvhrsqa'], 'ce']) == True
assert my_solution.isAcronym(**[['cfsrsyt', 'md'], 'cm']) == True
assert my_solution.isAcronym(**[['ddnlfpvy', 'exs'], 'de']) == True
assert my_solution.isAcronym(**[['deacf', 'hldiauk'], 'dh']) == True
assert my_solution.isAcronym(**[['dllcn', 'tnzrnzypg'], 'dt']) == True
assert my_solution.isAcronym(**[['dmekslxlpo', 'wqdgxqwdk'], 'dw']) == True
assert my_solution.isAcronym(**[['dv', 'g'], 'sg']) == False
assert my_solution.isAcronym(**[['dvn', 'acafe'], 'dp']) == False
assert my_solution.isAcronym(**[['dwrvgkxdtm', 'wy'], 'hw']) == False


# Determine the Minimum Sum of a k-avoiding Array

You are given two integers, `n` and `k`.

An array of **distinct** positive integers is called a **k-avoiding** array if there does not exist any pair of distinct elements that sum to `k`.

Return *the **minimum** possible sum of a k-avoiding array of length* `n`.

**Example 1:**

```

**Input:** n = 5, k = 4
**Output:** 18
**Explanation:** Consider the k-avoiding array [1,2,4,5,6], which has a sum of 18.
It can be proven that there is no k-avoiding array with a sum less than 18.

```

**Example 2:**

```

**Input:** n = 2, k = 6
**Output:** 3
**Explanation:** We can construct the array [1,2], which has a sum of 3.
It can be proven that there is no k-avoiding array with a sum less than 3.

```

**Constraints:**

* `1 <= n, k <= 50`

Please make sure your answer follows the type signature below:

```python3
class Solution:
    def minimumSum(self, n: int, k: int) -> int:
```

my_solution = Solution()

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


# Maximize the Profit as the Salesman

You are given an integer `n` representing the number of houses on a number line, numbered from `0` to `n - 1`.

Additionally, you are given a 2D integer array `offers` where `offers[i] = [starti, endi, goldi]`, indicating that `ith` buyer wants to buy all the houses from `starti` to `endi` for `goldi` amount of gold.

As a salesman, your goal is to **maximize** your earnings by strategically selecting and selling houses to buyers.

Return *the maximum amount of gold you can earn*.

**Note** that different buyers can't buy the same house, and some houses may remain unsold.

**Example 1:**

```

**Input:** n = 5, offers = [[0,0,1],[0,2,2],[1,3,2]]
**Output:** 3
**Explanation:** There are 5 houses numbered from 0 to 4 and there are 3 purchase offers.
We sell houses in the range [0,0] to 1st buyer for 1 gold and houses in the range [1,3] to 3rd buyer for 2 golds.
It can be proven that 3 is the maximum amount of gold we can achieve.

```

**Example 2:**

```

**Input:** n = 5, offers = [[0,0,1],[0,2,10],[1,3,2]]
**Output:** 10
**Explanation:** There are 5 houses numbered from 0 to 4 and there are 3 purchase offers.
We sell houses in the range [0,2] to 2nd buyer for 10 golds.
It can be proven that 10 is the maximum amount of gold we can achieve.

```

**Constraints:**

* `1 <= n <= 105`
* `1 <= offers.length <= 105`
* `offers[i].length == 3`
* `0 <= starti <= endi <= n - 1`
* `1 <= goldi <= 103`

Please make sure your answer follows the type signature below:

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


# Find the Longest Equal Subarray

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

A subarray is called **equal** if all of its elements are equal. Note that the empty subarray is an **equal** subarray.

Return *the length of the **longest** possible equal subarray after deleting **at most*** `k` *elements from* `nums`.

A **subarray** is a contiguous, possibly empty sequence of elements within an array.

**Example 1:**

```

**Input:** nums = [1,3,2,3,1,3], k = 3
**Output:** 3
**Explanation:** It's optimal to delete the elements at index 2 and index 4.
After deleting them, nums becomes equal to [1, 3, 3, 3].
The longest equal subarray starts at i = 1 and ends at j = 3 with length equal to 3.
It can be proven that no longer equal subarrays can be created.

```

**Example 2:**

```

**Input:** nums = [1,1,2,2,1,1], k = 2
**Output:** 4
**Explanation:** It's optimal to delete the elements at index 2 and index 3.
After deleting them, nums becomes equal to [1, 1, 1, 1].
The array itself is an equal subarray, so the answer is 4.
It can be proven that no longer equal subarrays can be created.

```

**Constraints:**

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

Please make sure your answer follows the type signature below:

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

my_solution = Solution()

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


# Count Pairs Whose Sum is Less than Target

Given a **0-indexed** integer array `nums` of length `n` and an integer `target`, return *the number of pairs* `(i, j)` *where* `0 <= i < j < n` *and* `nums[i] + nums[j] < target`.

**Example 1:**

```

**Input:** nums = [-1,1,2,3,1], target = 2
**Output:** 3
**Explanation:** There are 3 pairs of indices that satisfy the conditions in the statement:
- (0, 1) since 0 < 1 and nums[0] + nums[1] = 0 < target
- (0, 2) since 0 < 2 and nums[0] + nums[2] = 1 < target
- (0, 4) since 0 < 4 and nums[0] + nums[4] = 0 < target
Note that (0, 3) is not counted since nums[0] + nums[3] is not strictly less than the target.

```

**Example 2:**

```

**Input:** nums = [-6,2,5,-2,-7,-1,3], target = -2
**Output:** 10
**Explanation:** There are 10 pairs of indices that satisfy the conditions in the statement:
- (0, 1) since 0 < 1 and nums[0] + nums[1] = -4 < target
- (0, 3) since 0 < 3 and nums[0] + nums[3] = -8 < target
- (0, 4) since 0 < 4 and nums[0] + nums[4] = -13 < target
- (0, 5) since 0 < 5 and nums[0] + nums[5] = -7 < target
- (0, 6) since 0 < 6 and nums[0] + nums[6] = -3 < target
- (1, 4) since 1 < 4 and nums[1] + nums[4] = -5 < target
- (3, 4) since 3 < 4 and nums[3] + nums[4] = -9 < target
- (3, 5) since 3 < 5 and nums[3] + nums[5] = -3 < target
- (4, 5) since 4 < 5 and nums[4] + nums[5] = -8 < target
- (4, 6) since 4 < 6 and nums[4] + nums[6] = -4 < target

```

**Constraints:**

* `1 <= nums.length == n <= 50`
* `-50 <= nums[i], target <= 50`

Please make sure your answer follows the type signature below:

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


# Make String a Subsequence Using Cyclic Increments

You are given two **0-indexed** strings `str1` and `str2`.

In an operation, you select a **set** of indices in `str1`, and for each index `i` in the set, increment `str1[i]` to the next character **cyclically**. That is `'a'` becomes `'b'`, `'b'` becomes `'c'`, and so on, and `'z'` becomes `'a'`.

Return `true` *if it is possible to make* `str2` *a subsequence of* `str1` *by performing the operation **at most once***, *and* `false` *otherwise*.

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

**Example 1:**

```

**Input:** str1 = "abc", str2 = "ad"
**Output:** true
**Explanation:** Select index 2 in str1.
Increment str1[2] to become 'd'.
Hence, str1 becomes "abd" and str2 is now a subsequence. Therefore, true is returned.
```

**Example 2:**

```

**Input:** str1 = "zc", str2 = "ad"
**Output:** true
**Explanation:** Select indices 0 and 1 in str1.
Increment str1[0] to become 'a'.
Increment str1[1] to become 'd'.
Hence, str1 becomes "ad" and str2 is now a subsequence. Therefore, true is returned.
```

**Example 3:**

```

**Input:** str1 = "ab", str2 = "d"
**Output:** false
**Explanation:** In this example, it can be shown that it is impossible to make str2 a subsequence of str1 using the operation at most once.
Therefore, false is returned.
```

**Constraints:**

* `1 <= str1.length <= 105`
* `1 <= str2.length <= 105`
* `str1` and `str2` consist of only lowercase English letters.

Please make sure your answer follows the type signature below:

```python3
class Solution:
    def canMakeSubsequence(self, str1: str, str2: str) -> bool:
```

my_solution = Solution()

assert my_solution.canMakeSubsequence(**['abc', 'ad']) == True
assert my_solution.canMakeSubsequence(**['zc', 'ad']) == True
assert my_solution.canMakeSubsequence(**['ab', 'd']) == False
assert my_solution.canMakeSubsequence(**['a', 'd']) == False
assert my_solution.canMakeSubsequence(**['b', 'c']) == True
assert my_solution.canMakeSubsequence(**['b', 'v']) == False
assert my_solution.canMakeSubsequence(**['c', 'b']) == False
assert my_solution.canMakeSubsequence(**['c', 'k']) == False
assert my_solution.canMakeSubsequence(**['c', 'm']) == False
assert my_solution.canMakeSubsequence(**['d', 'h']) == False
assert my_solution.canMakeSubsequence(**['d', 'm']) == False
assert my_solution.canMakeSubsequence(**['d', 'x']) == False
assert my_solution.canMakeSubsequence(**['f', 'f']) == True
assert my_solution.canMakeSubsequence(**['f', 'g']) == True
assert my_solution.canMakeSubsequence(**['f', 's']) == False
assert my_solution.canMakeSubsequence(**['g', 'g']) == True
assert my_solution.canMakeSubsequence(**['h', 'i']) == True
assert my_solution.canMakeSubsequence(**['i', 'e']) == False
assert my_solution.canMakeSubsequence(**['i', 'j']) == True
assert my_solution.canMakeSubsequence(**['j', 'j']) == True


# Sorting Three Groups

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

The numbers from `0` to `n - 1` are divided into three groups numbered from `1` to `3`, where number `i` belongs to group `nums[i]`. Notice that some groups may be **empty**.

You are allowed to perform this operation any number of times:

* Pick number `x` and change its group. More formally, change `nums[x]` to any number from `1` to `3`.

A new array `res` is constructed using the following procedure:

1. Sort the numbers in each group independently.
2. Append the elements of groups `1`, `2`, and `3` to `res` **in this order**.

Array `nums` is called a **beautiful array** if the constructed array `res` is sorted in **non-decreasing** order.

Return *the **minimum** number of operations to make* `nums` *a **beautiful array***.

**Example 1:**

```

**Input:** nums = [2,1,3,2,1]
**Output:** 3
**Explanation:** It's optimal to perform three operations:
1. change nums[0] to 1.
2. change nums[2] to 1.
3. change nums[3] to 1.
After performing the operations and sorting the numbers in each group, group 1 becomes equal to [0,1,2,3,4] and group 2 and group 3 become empty. Hence, res is equal to [0,1,2,3,4] which is sorted in non-decreasing order.
It can be proven that there is no valid sequence of less than three operations.

```

**Example 2:**

```

**Input:** nums = [1,3,2,1,3,3]
**Output:** 2
**Explanation:** It's optimal to perform two operations:
1. change nums[1] to 1.
2. change nums[2] to 1.
After performing the operations and sorting the numbers in each group, group 1 becomes equal to [0,1,2,3], group 2 becomes empty, and group 3 becomes equal to [4,5]. Hence, res is equal to [0,1,2,3,4,5] which is sorted in non-decreasing order.
It can be proven that there is no valid sequence of less than two operations.

```

**Example 3:**

```

**Input:** nums = [2,2,2,2,3,3]
**Output:** 0
**Explanation:** It's optimal to not perform operations.
After sorting the numbers in each group, group 1 becomes empty, group 2 becomes equal to [0,1,2,3] and group 3 becomes equal to [4,5]. Hence, res is equal to [0,1,2,3,4,5] which is sorted in non-decreasing order.

```

**Constraints:**

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

Please make sure your answer follows the type signature below:

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

my_solution = Solution()

assert my_solution.minimumOperations(**[[2, 1, 3, 2, 1]]) == 3
assert my_solution.minimumOperations(**[[1, 3, 2, 1, 3, 3]]) == 2
assert my_solution.minimumOperations(**[[2, 2, 2, 2, 3, 3]]) == 0
assert my_solution.minimumOperations(**[[1]]) == 0
assert my_solution.minimumOperations(**[[2]]) == 0
assert my_solution.minimumOperations(**[[3]]) == 0
assert my_solution.minimumOperations(**[[1, 2]]) == 0
assert my_solution.minimumOperations(**[[2, 2]]) == 0
assert my_solution.minimumOperations(**[[3, 2]]) == 1
assert my_solution.minimumOperations(**[[1, 3]]) == 0
assert my_solution.minimumOperations(**[[2, 3]]) == 0
assert my_solution.minimumOperations(**[[3, 3]]) == 0
assert my_solution.minimumOperations(**[[1, 1, 2]]) == 0
assert my_solution.minimumOperations(**[[2, 1, 2]]) == 1
assert my_solution.minimumOperations(**[[3, 1, 2]]) == 1
assert my_solution.minimumOperations(**[[1, 2, 2]]) == 0
assert my_solution.minimumOperations(**[[2, 2, 2]]) == 0
assert my_solution.minimumOperations(**[[3, 2, 2]]) == 1
assert my_solution.minimumOperations(**[[1, 3, 2]]) == 1
assert my_solution.minimumOperations(**[[2, 3, 2]]) == 1


# Number of Beautiful Integers in the Range

You are given positive integers `low`, `high`, and `k`.

A number is **beautiful** if it meets both of the following conditions:

* The count of even digits in the number is equal to the count of odd digits.
* The number is divisible by `k`.

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

**Example 1:**

```

**Input:** low = 10, high = 20, k = 3
**Output:** 2
**Explanation:** There are 2 beautiful integers in the given range: [12,18].
- 12 is beautiful because it contains 1 odd digit and 1 even digit, and is divisible by k = 3.
- 18 is beautiful because it contains 1 odd digit and 1 even digit, and is divisible by k = 3.
Additionally we can see that:
- 16 is not beautiful because it is not divisible by k = 3.
- 15 is not beautiful because it does not contain equal counts even and odd digits.
It can be shown that there are only 2 beautiful integers in the given range.

```

**Example 2:**

```

**Input:** low = 1, high = 10, k = 1
**Output:** 1
**Explanation:** There is 1 beautiful integer in the given range: [10].
- 10 is beautiful because it contains 1 odd digit and 1 even digit, and is divisible by k = 1.
It can be shown that there is only 1 beautiful integer in the given range.

```

**Example 3:**

```

**Input:** low = 5, high = 5, k = 2
**Output:** 0
**Explanation:** There are 0 beautiful integers in the given range.
- 5 is not beautiful because it is not divisible by k = 2 and it does not contain equal even and odd digits.

```

**Constraints:**

* `0 < low <= high <= 109`
* `0 < k <= 20`

Please make sure your answer follows the type signature below:

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

my_solution = Solution()

assert my_solution.numberOfBeautifulIntegers(**[10, 20, 3]) == 2
assert my_solution.numberOfBeautifulIntegers(**[1, 10, 1]) == 1
assert my_solution.numberOfBeautifulIntegers(**[5, 5, 2]) == 0
assert my_solution.numberOfBeautifulIntegers(**[3, 31, 16]) == 1
assert my_solution.numberOfBeautifulIntegers(**[25, 31, 11]) == 0
assert my_solution.numberOfBeautifulIntegers(**[9, 25, 4]) == 2
assert my_solution.numberOfBeautifulIntegers(**[58, 72, 16]) == 0
assert my_solution.numberOfBeautifulIntegers(**[5, 79, 12]) == 3
assert my_solution.numberOfBeautifulIntegers(**[26, 74, 7]) == 4
assert my_solution.numberOfBeautifulIntegers(**[36, 65, 7]) == 3
assert my_solution.numberOfBeautifulIntegers(**[12, 84, 8]) == 4
assert my_solution.numberOfBeautifulIntegers(**[13, 91, 13]) == 3
assert my_solution.numberOfBeautifulIntegers(**[8, 18, 4]) == 2
assert my_solution.numberOfBeautifulIntegers(**[22, 59, 6]) == 3
assert my_solution.numberOfBeautifulIntegers(**[15, 27, 9]) == 2
assert my_solution.numberOfBeautifulIntegers(**[4, 9, 19]) == 0
assert my_solution.numberOfBeautifulIntegers(**[14, 81, 17]) == 1
assert my_solution.numberOfBeautifulIntegers(**[12, 33, 18]) == 1
assert my_solution.numberOfBeautifulIntegers(**[10, 17, 8]) == 1
assert my_solution.numberOfBeautifulIntegers(**[42, 58, 3]) == 2


# Max Pair Sum in an Array

You are given a **0-indexed** integer array `nums`. You have to find the **maximum** sum of a pair of numbers from `nums` such that the maximum **digit** in both numbers are equal.

Return *the maximum sum or* `-1` *if no such pair exists*.

**Example 1:**

```

**Input:** nums = [51,71,17,24,42]
**Output:** 88
**Explanation:**
For i = 1 and j = 2, nums[i] and nums[j] have equal maximum digits with a pair sum of 71 + 17 = 88.
For i = 3 and j = 4, nums[i] and nums[j] have equal maximum digits with a pair sum of 24 + 42 = 66.
It can be shown that there are no other pairs with equal maximum digits, so the answer is 88.
```

**Example 2:**

```

**Input:** nums = [1,2,3,4]
**Output:** -1
**Explanation:** No pair exists in nums with equal maximum digits.

```

**Constraints:**

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

Please make sure your answer follows the type signature below:

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


# Minimum Absolute Difference Between Elements With Constraint

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

Find the **minimum absolute difference** between two elements in the array that are at least `x` indices apart.

In other words, find two indices `i` and `j` such that `abs(i - j) >= x` and `abs(nums[i] - nums[j])` is minimized.

Return *an integer denoting the **minimum** absolute difference between two elements that are at least* `x` *indices apart*.

**Example 1:**

```

**Input:** nums = [4,3,2,4], x = 2
**Output:** 0
**Explanation:** We can select nums[0] = 4 and nums[3] = 4.
They are at least 2 indices apart, and their absolute difference is the minimum, 0.
It can be shown that 0 is the optimal answer.

```

**Example 2:**

```

**Input:** nums = [5,3,2,10,15], x = 1
**Output:** 1
**Explanation:** We can select nums[1] = 3 and nums[2] = 2.
They are at least 1 index apart, and their absolute difference is the minimum, 1.
It can be shown that 1 is the optimal answer.

```

**Example 3:**

```

**Input:** nums = [1,2,3,4], x = 3
**Output:** 3
**Explanation:** We can select nums[0] = 1 and nums[3] = 4.
They are at least 3 indices apart, and their absolute difference is the minimum, 3.
It can be shown that 3 is the optimal answer.

```

**Constraints:**

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

Please make sure your answer follows the type signature below:

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

my_solution = Solution()

assert my_solution.minAbsoluteDifference(**[[4, 3, 2, 4], 2]) == 0
assert my_solution.minAbsoluteDifference(**[[5, 3, 2, 10, 15], 1]) == 1
assert my_solution.minAbsoluteDifference(**[[1, 2, 3, 4], 3]) == 3
assert my_solution.minAbsoluteDifference(**[[1, 67], 1]) == 66
assert my_solution.minAbsoluteDifference(**[[7, 398], 1]) == 391
assert my_solution.minAbsoluteDifference(**[[12, 141], 1]) == 129
assert my_solution.minAbsoluteDifference(**[[21, 75], 1]) == 54
assert my_solution.minAbsoluteDifference(**[[22, 147], 1]) == 125
assert my_solution.minAbsoluteDifference(**[[25, 197], 1]) == 172
assert my_solution.minAbsoluteDifference(**[[27, 275], 1]) == 248
assert my_solution.minAbsoluteDifference(**[[37, 192], 1]) == 155
assert my_solution.minAbsoluteDifference(**[[41, 163], 1]) == 122
assert my_solution.minAbsoluteDifference(**[[45, 49], 1]) == 4
assert my_solution.minAbsoluteDifference(**[[48, 195], 1]) == 147
assert my_solution.minAbsoluteDifference(**[[68, 68], 1]) == 0
assert my_solution.minAbsoluteDifference(**[[71, 4], 1]) == 67
assert my_solution.minAbsoluteDifference(**[[72, 169], 1]) == 97
assert my_solution.minAbsoluteDifference(**[[74, 62], 1]) == 12
assert my_solution.minAbsoluteDifference(**[[75, 1], 1]) == 74
assert my_solution.minAbsoluteDifference(**[[76, 49], 1]) == 27


# Apply Operations to Maximize Score

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

Initially, you start with a score of `1`. You have to maximize your score by applying the following operation at most `k` times:

* Choose any **non-empty** subarray `nums[l, ..., r]` that you haven't chosen previously.
* Choose an element `x` of `nums[l, ..., r]` with the highest **prime score**. If multiple such elements exist, choose the one with the smallest index.
* Multiply your score by `x`.

Here, `nums[l, ..., r]` denotes the subarray of `nums` starting at index `l` and ending at the index `r`, both ends being inclusive.

The **prime score** of an integer `x` is equal to the number of distinct prime factors of `x`. For example, the prime score of `300` is `3` since `300 = 2 * 2 * 3 * 5 * 5`.

Return *the **maximum possible score** after applying at most* `k` *operations*.

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

**Example 1:**

```

**Input:** nums = [8,3,9,3,8], k = 2
**Output:** 81
**Explanation:** To get a score of 81, we can apply the following operations:
- Choose subarray nums[2, ..., 2]. nums[2] is the only element in this subarray. Hence, we multiply the score by nums[2]. The score becomes 1 * 9 = 9.
- Choose subarray nums[2, ..., 3]. Both nums[2] and nums[3] have a prime score of 1, but nums[2] has the smaller index. Hence, we multiply the score by nums[2]. The score becomes 9 * 9 = 81.
It can be proven that 81 is the highest score one can obtain.
```

**Example 2:**

```

**Input:** nums = [19,12,14,6,10,18], k = 3
**Output:** 4788
**Explanation:** To get a score of 4788, we can apply the following operations:
- Choose subarray nums[0, ..., 0]. nums[0] is the only element in this subarray. Hence, we multiply the score by nums[0]. The score becomes 1 * 19 = 19.
- Choose subarray nums[5, ..., 5]. nums[5] is the only element in this subarray. Hence, we multiply the score by nums[5]. The score becomes 19 * 18 = 342.
- Choose subarray nums[2, ..., 3]. Both nums[2] and nums[3] have a prime score of 2, but nums[2] has the smaller index. Hence, we multipy the score by nums[2]. The score becomes 342 * 14 = 4788.
It can be proven that 4788 is the highest score one can obtain.

```

**Constraints:**

* `1 <= nums.length == n <= 105`
* `1 <= nums[i] <= 105`
* `1 <= k <= min(n * (n + 1) / 2, 109)`

Please make sure your answer follows the type signature below:

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


# Faulty Keyboard

Your laptop keyboard is faulty, and whenever you type a character `'i'` on it, it reverses the string that you have written. Typing other characters works as expected.

You are given a **0-indexed** string `s`, and you type each character of `s` using your faulty keyboard.

Return *the final string that will be present on your laptop screen.*

**Example 1:**

```

**Input:** s = "string"
**Output:** "rtsng"
**Explanation:**
After typing first character, the text on the screen is "s".
After the second character, the text is "st".
After the third character, the text is "str".
Since the fourth character is an 'i', the text gets reversed and becomes "rts".
After the fifth character, the text is "rtsn".
After the sixth character, the text is "rtsng".
Therefore, we return "rtsng".

```

**Example 2:**

```

**Input:** s = "poiinter"
**Output:** "ponter"
**Explanation:**
After the first character, the text on the screen is "p".
After the second character, the text is "po".
Since the third character you type is an 'i', the text gets reversed and becomes "op".
Since the fourth character you type is an 'i', the text gets reversed and becomes "po".
After the fifth character, the text is "pon".
After the sixth character, the text is "pont".
After the seventh character, the text is "ponte".
After the eighth character, the text is "ponter".
Therefore, we return "ponter".
```

**Constraints:**

* `1 <= s.length <= 100`
* `s` consists of lowercase English letters.
* `s[0] != 'i'`

Please make sure your answer follows the type signature below:

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

my_solution = Solution()

assert my_solution.finalString(**['string']) == rtsng
assert my_solution.finalString(**['poiinter']) == ponter
assert my_solution.finalString(**['goci']) == cog
assert my_solution.finalString(**['ksi']) == sk
assert my_solution.finalString(**['fii']) == f
assert my_solution.finalString(**['qskyviiiii']) == vyksq
assert my_solution.finalString(**['pft']) == pft
assert my_solution.finalString(**['viwif']) == wvf
assert my_solution.finalString(**['wiie']) == we
assert my_solution.finalString(**['kiis']) == ks
assert my_solution.finalString(**['xihbosxitx']) == xsobhxtx
assert my_solution.finalString(**['uwioili']) == lwuo
assert my_solution.finalString(**['aapziai']) == aaapz
assert my_solution.finalString(**['pviist']) == pvst
assert my_solution.finalString(**['miiuiei']) == emu
assert my_solution.finalString(**['diiiiq']) == dq
assert my_solution.finalString(**['eirov']) == erov
assert my_solution.finalString(**['niiiiisiii']) == sn
assert my_solution.finalString(**['siiuii']) == su
assert my_solution.finalString(**['piijciivq']) == pjcvq


# Check if it is Possible to Split Array

You are given an array `nums` of length `n` and an integer `m`. You need to determine if it is possible to split the array into `n` **non-empty** arrays by performing a series of steps.

In each step, you can select an existing array (which may be the result of previous steps) with a length of **at least two** and split it into **two** subarrays, if, **for each** resulting subarray, **at least** one of the following holds:

* The length of the subarray is one, or
* The sum of elements of the subarray is **greater than or equal** to `m`.

Return `true` *if you can split the given array into* `n` *arrays, otherwise return* `false`.

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

**Example 1:**

```

**Input:** nums = [2, 2, 1], m = 4
**Output:** true
**Explanation:** We can split the array into [2, 2] and [1] in the first step. Then, in the second step, we can split [2, 2] into [2] and [2]. As a result, the answer is true.
```

**Example 2:**

```

**Input:** nums = [2, 1, 3], m = 5
**Output:** false
**Explanation:** We can try splitting the array in two different ways: the first way is to have [2, 1] and [3], and the second way is to have [2] and [1, 3]. However, both of these ways are not valid. So, the answer is false.
```

**Example 3:**

```

**Input:** nums = [2, 3, 3, 2, 3], m = 6
**Output:** true
**Explanation:** We can split the array into [2, 3, 3, 2] and [3] in the first step. Then, in the second step, we can split [2, 3, 3, 2] into [2, 3, 3] and [2]. Then, in the third step, we can split [2, 3, 3] into [2] and [3, 3]. And in the last step we can split [3, 3] into [3] and [3]. As a result, the answer is true.

```

**Constraints:**

* `1 <= n == nums.length <= 100`
* `1 <= nums[i] <= 100`
* `1 <= m <= 200`

Please make sure your answer follows the type signature below:

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

my_solution = Solution()

assert my_solution.canSplitArray(**[[2, 2, 1], 4]) == True
assert my_solution.canSplitArray(**[[2, 1, 3], 5]) == False
assert my_solution.canSplitArray(**[[2, 3, 3, 2, 3], 6]) == True
assert my_solution.canSplitArray(**[[1], 1]) == True
assert my_solution.canSplitArray(**[[2], 1]) == True
assert my_solution.canSplitArray(**[[3], 1]) == True
assert my_solution.canSplitArray(**[[1], 2]) == True
assert my_solution.canSplitArray(**[[2], 2]) == True
assert my_solution.canSplitArray(**[[3], 2]) == True
assert my_solution.canSplitArray(**[[3], 3]) == True
assert my_solution.canSplitArray(**[[7], 5]) == True
assert my_solution.canSplitArray(**[[4], 7]) == True
assert my_solution.canSplitArray(**[[9], 7]) == True
assert my_solution.canSplitArray(**[[2], 8]) == True
assert my_solution.canSplitArray(**[[4], 8]) == True
assert my_solution.canSplitArray(**[[10], 11]) == True
assert my_solution.canSplitArray(**[[6], 12]) == True
assert my_solution.canSplitArray(**[[2], 14]) == True
assert my_solution.canSplitArray(**[[3], 18]) == True
assert my_solution.canSplitArray(**[[9, 7], 1]) == True


# Maximum Elegance of a K-Length Subsequence

You are given a **0-indexed** 2D integer array `items` of length `n` and an integer `k`.

`items[i] = [profiti, categoryi]`, where `profiti` and `categoryi` denote the profit and category of the `ith` item respectively.

Let's define the **elegance** of a **subsequence** of `items` as `total_profit + distinct_categories2`, where `total_profit` is the sum of all profits in the subsequence, and `distinct_categories` is the number of **distinct** categories from all the categories in the selected subsequence.

Your task is to find the **maximum elegance** from all subsequences of size `k` in `items`.

Return *an integer denoting the maximum elegance of a subsequence of* `items` *with size exactly* `k`.

**Note:** A subsequence of an array is a new array generated from the original array by deleting some elements (possibly none) without changing the remaining elements' relative order.

**Example 1:**

```

**Input:** items = [[3,2],[5,1],[10,1]], k = 2
**Output:** 17
**Explanation:** In this example, we have to select a subsequence of size 2.
We can select items[0] = [3,2] and items[2] = [10,1].
The total profit in this subsequence is 3 + 10 = 13, and the subsequence contains 2 distinct categories [2,1].
Hence, the elegance is 13 + 22 = 17, and we can show that it is the maximum achievable elegance.

```

**Example 2:**

```

**Input:** items = [[3,1],[3,1],[2,2],[5,3]], k = 3
**Output:** 19
**Explanation:** In this example, we have to select a subsequence of size 3.
We can select items[0] = [3,1], items[2] = [2,2], and items[3] = [5,3].
The total profit in this subsequence is 3 + 2 + 5 = 10, and the subsequence contains 3 distinct categories [1,2,3].
Hence, the elegance is 10 + 32 = 19, and we can show that it is the maximum achievable elegance.
```

**Example 3:**

```

**Input:** items = [[1,1],[2,1],[3,1]], k = 3
**Output:** 7
**Explanation:** In this example, we have to select a subsequence of size 3.
We should select all the items.
The total profit will be 1 + 2 + 3 = 6, and the subsequence contains 1 distinct category [1].
Hence, the maximum elegance is 6 + 12 = 7.
```

**Constraints:**

* `1 <= items.length == n <= 105`
* `items[i].length == 2`
* `items[i][0] == profiti`
* `items[i][1] == categoryi`
* `1 <= profiti <= 109`
* `1 <= categoryi <= n`
* `1 <= k <= n`

Please make sure your answer follows the type signature below:

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

my_solution = Solution()

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


# Account Balance After Rounded Purchase

Initially, you have a bank account balance of `100` dollars.

You are given an integer `purchaseAmount` representing the amount you will spend on a purchase in dollars.

At the store where you will make the purchase, the purchase amount is rounded to the **nearest multiple** of `10`. In other words, you pay a **non-negative** amount, `roundedAmount`, such that `roundedAmount` is a multiple of `10` and `abs(roundedAmount - purchaseAmount)` is **minimized**.

If there is more than one nearest multiple of `10`, the **largest multiple** is chosen.

Return *an integer denoting your account balance after making a purchase worth* `purchaseAmount` *dollars from the store.*

**Note:** `0` is considered to be a multiple of `10` in this problem.

**Example 1:**

```

**Input:** purchaseAmount = 9
**Output:** 90
**Explanation:** In this example, the nearest multiple of 10 to 9 is 10. Hence, your account balance becomes 100 - 10 = 90.

```

**Example 2:**

```

**Input:** purchaseAmount = 15
**Output:** 80
**Explanation:** In this example, there are two nearest multiples of 10 to 15: 10 and 20. So, the larger multiple, 20, is chosen.
Hence, your account balance becomes 100 - 20 = 80.

```

**Constraints:**

* `0 <= purchaseAmount <= 100`

Please make sure your answer follows the type signature below:

```python3
class Solution:
    def accountBalanceAfterPurchase(self, purchaseAmount: int) -> int:
```

my_solution = Solution()

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


# Minimum Seconds to Equalize a Circular Array

You are given a **0-indexed** array `nums` containing `n` integers.

At each second, you perform the following operation on the array:

* For every index `i` in the range `[0, n - 1]`, replace `nums[i]` with either `nums[i]`, `nums[(i - 1 + n) % n]`, or `nums[(i + 1) % n]`.

**Note** that all the elements get replaced simultaneously.

Return *the **minimum** number of seconds needed to make all elements in the array* `nums` *equal*.

**Example 1:**

```

**Input:** nums = [1,2,1,2]
**Output:** 1
**Explanation:** We can equalize the array in 1 second in the following way:
- At 1st second, replace values at each index with [nums[3],nums[1],nums[3],nums[3]]. After replacement, nums = [2,2,2,2].
It can be proven that 1 second is the minimum amount of seconds needed for equalizing the array.

```

**Example 2:**

```

**Input:** nums = [2,1,3,3,2]
**Output:** 2
**Explanation:** We can equalize the array in 2 seconds in the following way:
- At 1st second, replace values at each index with [nums[0],nums[2],nums[2],nums[2],nums[3]]. After replacement, nums = [2,3,3,3,3].
- At 2nd second, replace values at each index with [nums[1],nums[1],nums[2],nums[3],nums[4]]. After replacement, nums = [3,3,3,3,3].
It can be proven that 2 seconds is the minimum amount of seconds needed for equalizing the array.

```

**Example 3:**

```

**Input:** nums = [5,5,5,5]
**Output:** 0
**Explanation:** We don't need to perform any operations as all elements in the initial array are the same.

```

**Constraints:**

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

Please make sure your answer follows the type signature below:

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

my_solution = Solution()

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


# Minimum Time to Make Array Sum At Most x

You are given two **0-indexed** integer arrays `nums1` and `nums2` of equal length. Every second, for all indices `0 <= i < nums1.length`, value of `nums1[i]` is incremented by `nums2[i]`. **After** this is done, you can do the following operation:

* Choose an index `0 <= i < nums1.length` and make `nums1[i] = 0`.

You are also given an integer `x`.

Return *the **minimum** time in which you can make the sum of all elements of* `nums1` *to be **less than or equal** to* `x`, *or* `-1` *if this is not possible.*

**Example 1:**

```

**Input:** nums1 = [1,2,3], nums2 = [1,2,3], x = 4
**Output:** 3
**Explanation:**
For the 1st second, we apply the operation on i = 0. Therefore nums1 = [0,2+2,3+3] = [0,4,6].
For the 2nd second, we apply the operation on i = 1. Therefore nums1 = [0+1,0,6+3] = [1,0,9].
For the 3rd second, we apply the operation on i = 2. Therefore nums1 = [1+1,0+2,0] = [2,2,0].
Now sum of nums1 = 4. It can be shown that these operations are optimal, so we return 3.

```

**Example 2:**

```

**Input:** nums1 = [1,2,3], nums2 = [3,3,3], x = 4
**Output:** -1
**Explanation:** It can be shown that the sum of nums1 will always be greater than x, no matter which operations are performed.

```

**Constraints:**

* `1 <= nums1.length <= 103`
* `1 <= nums1[i] <= 103`
* `0 <= nums2[i] <= 103`
* `nums1.length == nums2.length`
* `0 <= x <= 106`

Please make sure your answer follows the type signature below:

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


# Number of Employees Who Met the Target

There are `n` employees in a company, numbered from `0` to `n - 1`. Each employee `i` has worked for `hours[i]` hours in the company.

The company requires each employee to work for **at least** `target` hours.

You are given a **0-indexed** array of non-negative integers `hours` of length `n` and a non-negative integer `target`.

Return *the integer denoting the number of employees who worked at least* `target` *hours*.

**Example 1:**

```

**Input:** hours = [0,1,2,3,4], target = 2
**Output:** 3
**Explanation:** The company wants each employee to work for at least 2 hours.
- Employee 0 worked for 0 hours and didn't meet the target.
- Employee 1 worked for 1 hours and didn't meet the target.
- Employee 2 worked for 2 hours and met the target.
- Employee 3 worked for 3 hours and met the target.
- Employee 4 worked for 4 hours and met the target.
There are 3 employees who met the target.

```

**Example 2:**

```

**Input:** hours = [5,1,4,2,2], target = 6
**Output:** 0
**Explanation:** The company wants each employee to work for at least 6 hours.
There are 0 employees who met the target.

```

**Constraints:**

* `1 <= n == hours.length <= 50`
* `0 <= hours[i], target <= 105`

Please make sure your answer follows the type signature below:

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

my_solution = Solution()

assert my_solution.numberOfEmployeesWhoMetTarget(**[[0, 1, 2, 3, 4], 2]) == 3
assert my_solution.numberOfEmployeesWhoMetTarget(**[[5, 1, 4, 2, 2], 6]) == 0
assert my_solution.numberOfEmployeesWhoMetTarget(**[[98], 5]) == 1
assert my_solution.numberOfEmployeesWhoMetTarget(**[[19], 13]) == 1
assert my_solution.numberOfEmployeesWhoMetTarget(**[[70], 13]) == 1
assert my_solution.numberOfEmployeesWhoMetTarget(**[[26], 14]) == 1
assert my_solution.numberOfEmployeesWhoMetTarget(**[[2], 16]) == 0
assert my_solution.numberOfEmployeesWhoMetTarget(**[[77], 19]) == 1
assert my_solution.numberOfEmployeesWhoMetTarget(**[[6], 21]) == 0
assert my_solution.numberOfEmployeesWhoMetTarget(**[[27], 21]) == 1
assert my_solution.numberOfEmployeesWhoMetTarget(**[[36], 22]) == 1
assert my_solution.numberOfEmployeesWhoMetTarget(**[[42], 25]) == 1
assert my_solution.numberOfEmployeesWhoMetTarget(**[[70], 27]) == 1
assert my_solution.numberOfEmployeesWhoMetTarget(**[[2], 28]) == 0
assert my_solution.numberOfEmployeesWhoMetTarget(**[[14], 31]) == 0
assert my_solution.numberOfEmployeesWhoMetTarget(**[[45], 34]) == 1
assert my_solution.numberOfEmployeesWhoMetTarget(**[[44], 35]) == 1
assert my_solution.numberOfEmployeesWhoMetTarget(**[[11], 39]) == 0
assert my_solution.numberOfEmployeesWhoMetTarget(**[[71], 39]) == 1
assert my_solution.numberOfEmployeesWhoMetTarget(**[[91], 45]) == 1


# Count Complete Subarrays in an Array

You are given an array `nums` consisting of **positive** integers.

We call a subarray of an array **complete** if the following condition is satisfied:

* The number of **distinct** elements in the subarray is equal to the number of distinct elements in the whole array.

Return *the number of **complete** subarrays*.

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

**Example 1:**

```

**Input:** nums = [1,3,1,2,2]
**Output:** 4
**Explanation:** The complete subarrays are the following: [1,3,1,2], [1,3,1,2,2], [3,1,2] and [3,1,2,2].

```

**Example 2:**

```

**Input:** nums = [5,5,5,5]
**Output:** 10
**Explanation:** The array consists only of the integer 5, so any subarray is complete. The number of subarrays that we can choose is 10.

```

**Constraints:**

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

Please make sure your answer follows the type signature below:

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

my_solution = Solution()

assert my_solution.countCompleteSubarrays(**[[1, 3, 1, 2, 2]]) == 4
assert my_solution.countCompleteSubarrays(**[[5, 5, 5, 5]]) == 10
assert my_solution.countCompleteSubarrays(**[[459, 459, 962, 1579, 1435, 756, 1872, 1597]]) == 2
assert my_solution.countCompleteSubarrays(**[[1786, 1786, 1786, 114]]) == 3
assert my_solution.countCompleteSubarrays(**[[1632, 1632, 528, 359, 1671, 1632, 511, 1087, 424, 1684]]) == 3
assert my_solution.countCompleteSubarrays(**[[1430, 12, 1430, 1075, 1722]]) == 2
assert my_solution.countCompleteSubarrays(**[[1917, 1917, 608, 608, 1313, 751, 558, 1561, 608]]) == 4
assert my_solution.countCompleteSubarrays(**[[254, 1690, 1690, 1068, 1779]]) == 1
assert my_solution.countCompleteSubarrays(**[[1116]]) == 1
assert my_solution.countCompleteSubarrays(**[[1677, 1677, 1352, 1219, 1666, 1677, 1892, 1892, 319]]) == 3
assert my_solution.countCompleteSubarrays(**[[1386, 1997, 1997, 574, 574, 1360, 989]]) == 1
assert my_solution.countCompleteSubarrays(**[[50, 48, 1118, 540, 1248, 1984, 1698, 41, 1984, 186]]) == 1
assert my_solution.countCompleteSubarrays(**[[273, 524, 40, 1323, 1323]]) == 2
assert my_solution.countCompleteSubarrays(**[[246, 376, 828, 191, 1942, 210]]) == 1
assert my_solution.countCompleteSubarrays(**[[463, 1497, 1676, 127, 1379, 17, 1075, 190]]) == 1
assert my_solution.countCompleteSubarrays(**[[765, 1370]]) == 1
assert my_solution.countCompleteSubarrays(**[[1110, 804, 1110, 839, 728, 839]]) == 4
assert my_solution.countCompleteSubarrays(**[[1001]]) == 1
assert my_solution.countCompleteSubarrays(**[[665, 867, 954, 1411, 728, 1006, 372, 1411]]) == 2
assert my_solution.countCompleteSubarrays(**[[1213, 1203, 1277, 369, 1277]]) == 2


# Shortest String That Contains Three Strings

Given three strings `a`, `b`, and `c`, your task is to find a string that has the **minimum** length and contains all three strings as **substrings**.
If there are multiple such strings, return the**lexicographicallysmallest** one.

Return *a string denoting the answer to the problem.*

**Notes**

* A string `a` is **lexicographically smaller** than a string `b` (of the same length) if in the first position where `a` and `b` differ, string `a` has a letter that appears **earlier** in the alphabet than the corresponding letter in `b`.
* A **substring** is a contiguous sequence of characters within a string.

**Example 1:**

```

**Input:** a = "abc", b = "bca", c = "aaa"
**Output:** "aaabca"
**Explanation:**  We show that "aaabca" contains all the given strings: a = ans[2...4], b = ans[3..5], c = ans[0..2]. It can be shown that the length of the resulting string would be at least 6 and "aaabca" is the lexicographically smallest one.
```

**Example 2:**

```

**Input:** a = "ab", b = "ba", c = "aba"
**Output:** "aba"
**Explanation:** We show that the string "aba" contains all the given strings: a = ans[0..1], b = ans[1..2], c = ans[0..2]. Since the length of c is 3, the length of the resulting string would be at least 3. It can be shown that "aba" is the lexicographically smallest one.

```

**Constraints:**

* `1 <= a.length, b.length, c.length <= 100`
* `a`, `b`, `c` consist only of lowercase English letters.

Please make sure your answer follows the type signature below:

```python3
class Solution:
    def minimumString(self, a: str, b: str, c: str) -> str:
```

my_solution = Solution()

assert my_solution.minimumString(**['abc', 'bca', 'aaa']) == aaabca
assert my_solution.minimumString(**['ab', 'ba', 'aba']) == aba
assert my_solution.minimumString(**['xyyyz', 'xzyz', 'zzz']) == xyyyzxzyzzz
assert my_solution.minimumString(**['a', 'a', 'a']) == a
assert my_solution.minimumString(**['a', 'a', 'b']) == ab
assert my_solution.minimumString(**['a', 'c', 'a']) == ac
assert my_solution.minimumString(**['a', 'b', 'b']) == ab
assert my_solution.minimumString(**['a', 'a', 'c']) == ac
assert my_solution.minimumString(**['a', 'c', 'b']) == abc
assert my_solution.minimumString(**['c', 'c', 'a']) == ac
assert my_solution.minimumString(**['k', 'e', 'a']) == aek
assert my_solution.minimumString(**['a', 'b', 'a']) == ab
assert my_solution.minimumString(**['b', 'b', 'a']) == ab
assert my_solution.minimumString(**['b', 'b', 'b']) == b
assert my_solution.minimumString(**['b', 'b', 'c']) == bc
assert my_solution.minimumString(**['c', 'b', 'b']) == bc
assert my_solution.minimumString(**['b', 'c', 'c']) == bc
assert my_solution.minimumString(**['b', 'c', 'a']) == abc
assert my_solution.minimumString(**['c', 'a', 'c']) == ac
assert my_solution.minimumString(**['c', 'b', 'c']) == bc


# Count Stepping Numbers in Range

Given two positive integers `low` and `high` represented as strings, find the count of **stepping numbers** in the inclusive range `[low, high]`.

A **stepping number** is an integer such that all of its adjacent digits have an absolute difference of **exactly** `1`.

Return *an integer denoting the count of stepping numbers in the inclusive range* `[low, high]`*.*

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

**Note:** A stepping number should not have a leading zero.

**Example 1:**

```

**Input:** low = "1", high = "11"
**Output:** 10
**Explanation:** The stepping numbers in the range [1,11] are 1, 2, 3, 4, 5, 6, 7, 8, 9 and 10. There are a total of 10 stepping numbers in the range. Hence, the output is 10.
```

**Example 2:**

```

**Input:** low = "90", high = "101"
**Output:** 2
**Explanation:** The stepping numbers in the range [90,101] are 98 and 101. There are a total of 2 stepping numbers in the range. Hence, the output is 2.
```

**Constraints:**

* `1 <= int(low) <= int(high) < 10100`
* `1 <= low.length, high.length <= 100`
* `low` and `high` consist of only digits.
* `low` and `high` don't have any leading zeros.

Please make sure your answer follows the type signature below:

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

my_solution = Solution()

assert my_solution.countSteppingNumbers(**['1', '11']) == 10
assert my_solution.countSteppingNumbers(**['90', '101']) == 2
assert my_solution.countSteppingNumbers(**['2', '40']) == 14
assert my_solution.countSteppingNumbers(**['26', '60']) == 6
assert my_solution.countSteppingNumbers(**['40', '70']) == 6
assert my_solution.countSteppingNumbers(**['46', '66']) == 3
assert my_solution.countSteppingNumbers(**['58', '58']) == 0
assert my_solution.countSteppingNumbers(**['23', '99']) == 14
assert my_solution.countSteppingNumbers(**['44', '86']) == 7
assert my_solution.countSteppingNumbers(**['20', '111']) == 16
assert my_solution.countSteppingNumbers(**['70', '75']) == 0
assert my_solution.countSteppingNumbers(**['37', '111']) == 12
assert my_solution.countSteppingNumbers(**['17', '149']) == 18
assert my_solution.countSteppingNumbers(**['21', '145']) == 18
assert my_solution.countSteppingNumbers(**['47', '124']) == 12
assert my_solution.countSteppingNumbers(**['81', '91']) == 2
assert my_solution.countSteppingNumbers(**['18', '159']) == 18
assert my_solution.countSteppingNumbers(**['85', '92']) == 2
assert my_solution.countSteppingNumbers(**['66', '112']) == 7
assert my_solution.countSteppingNumbers(**['84', '102']) == 4


# Split Strings by Separator

Given an array of strings `words` and a character `separator`, **split** each string in `words` by `separator`.

Return *an array of strings containing the new strings formed after the splits, **excluding empty strings**.*

**Notes**

* `separator` is used to determine where the split should occur, but it is not included as part of the resulting strings.
* A split may result in more than two strings.
* The resulting strings must maintain the same order as they were initially given.

**Example 1:**

```

**Input:** words = ["one.two.three","four.five","six"], separator = "."
**Output:** ["one","two","three","four","five","six"]
**Explanation:** In this example we split as follows:

"one.two.three" splits into "one", "two", "three"
"four.five" splits into "four", "five"
"six" splits into "six"

Hence, the resulting array is ["one","two","three","four","five","six"].
```

**Example 2:**

```

**Input:** words = ["$easy$","$problem$"], separator = "$"
**Output:** ["easy","problem"]
**Explanation:** In this example we split as follows:

"$easy$" splits into "easy" (excluding empty strings)
"$problem$" splits into "problem" (excluding empty strings)

Hence, the resulting array is ["easy","problem"].

```

**Example 3:**

```

**Input:** words = ["|||"], separator = "|"
**Output:** []
**Explanation:** In this example the resulting split of "|||" will contain only empty strings, so we return an empty array [].
```

**Constraints:**

* `1 <= words.length <= 100`
* `1 <= words[i].length <= 20`
* characters in `words[i]` are either lowercase English letters or characters from the string `".,|$#@"` (excluding the quotes)
* `separator` is a character from the string `".,|$#@"` (excluding the quotes)

Please make sure your answer follows the type signature below:

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

my_solution = Solution()

assert my_solution.splitWordsBySeparator(**[['one.two.three', 'four.five', 'six'], '.']) == ['one', 'two', 'three', 'four', 'five', 'six']
assert my_solution.splitWordsBySeparator(**[['$easy$', '$problem$'], '$']) == ['easy', 'problem']
assert my_solution.splitWordsBySeparator(**[['|||'], '|']) == []
assert my_solution.splitWordsBySeparator(**[['stars.bars.$'], '.']) == ['stars', 'bars', '$']
assert my_solution.splitWordsBySeparator(**[['###x#i@f'], '#']) == ['x', 'i@f']
assert my_solution.splitWordsBySeparator(**[['##q@t#'], '#']) == ['q@t']
assert my_solution.splitWordsBySeparator(**[['#,'], '#']) == [',']
assert my_solution.splitWordsBySeparator(**[['#@'], '@']) == ['#']
assert my_solution.splitWordsBySeparator(**[['#a$f$nwgq#vw'], '$']) == ['#a', 'f', 'nwgq#vw']
assert my_solution.splitWordsBySeparator(**[['#uyddd,trxiwfv'], ',']) == ['#uyddd', 'trxiwfv']
assert my_solution.splitWordsBySeparator(**[['#x'], '$']) == ['#x']
assert my_solution.splitWordsBySeparator(**[['#x#,'], ',']) == ['#x#']
assert my_solution.splitWordsBySeparator(**[['#|'], '#']) == ['|']
assert my_solution.splitWordsBySeparator(**[['#|a|b|##|#|#g#u|'], '|']) == ['#', 'a', 'b', '##', '#', '#g#u']
assert my_solution.splitWordsBySeparator(**[['$$.o.$$.'], '$']) == ['.o.', '.']
assert my_solution.splitWordsBySeparator(**[['$,,'], ',']) == ['$']
assert my_solution.splitWordsBySeparator(**[['$j@@@'], '@']) == ['$j']
assert my_solution.splitWordsBySeparator(**[[',$$'], '$']) == [',']
assert my_solution.splitWordsBySeparator(**[[',,'], '|']) == [',,']
assert my_solution.splitWordsBySeparator(**[[',,,@@n'], ',']) == ['@@n']


# Largest Element in an Array after Merge Operations

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

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

* Choose an integer `i` such that `0 <= i < nums.length - 1` and `nums[i] <= nums[i + 1]`. Replace the element `nums[i + 1]` with `nums[i] + nums[i + 1]` and delete the element `nums[i]` from the array.

Return *the value of the **largest** element that you can possibly obtain in the final array.*

**Example 1:**

```

**Input:** nums = [2,3,7,9,3]
**Output:** 21
**Explanation:** We can apply the following operations on the array:
- Choose i = 0. The resulting array will be nums = [5,7,9,3].
- Choose i = 1. The resulting array will be nums = [5,16,3].
- Choose i = 0. The resulting array will be nums = [21,3].
The largest element in the final array is 21. It can be shown that we cannot obtain a larger element.

```

**Example 2:**

```

**Input:** nums = [5,3,3]
**Output:** 11
**Explanation:** We can do the following operations on the array:
- Choose i = 1. The resulting array will be nums = [5,6].
- Choose i = 0. The resulting array will be nums = [11].
There is only one element in the final array, which is 11.

```

**Constraints:**

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

Please make sure your answer follows the type signature below:

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


# Maximum Number of Groups With Increasing Length

You are given a **0-indexed** array `usageLimits` of length `n`.

Your task is to create **groups** using numbers from `0` to `n - 1`, ensuring that each number, `i`, is used no more than `usageLimits[i]` times in total **across all groups**. You must also satisfy the following conditions:

* Each group must consist of **distinct** numbers, meaning that no duplicate numbers are allowed within a single group.
* Each group (except the first one) must have a length **strictly greater** than the previous group.

Return *an integer denoting the **maximum** number of groups you can create while satisfying these conditions.*

**Example 1:**

```

**Input:** usageLimits = [1,2,5]
**Output:** 3
**Explanation:** In this example, we can use 0 at most once, 1 at most twice, and 2 at most five times.
One way of creating the maximum number of groups while satisfying the conditions is:
Group 1 contains the number [2].
Group 2 contains the numbers [1,2].
Group 3 contains the numbers [0,1,2].
It can be shown that the maximum number of groups is 3.
So, the output is 3.
```

**Example 2:**

```

**Input:** usageLimits = [2,1,2]
**Output:** 2
**Explanation:** In this example, we can use 0 at most twice, 1 at most once, and 2 at most twice.
One way of creating the maximum number of groups while satisfying the conditions is:
Group 1 contains the number [0].
Group 2 contains the numbers [1,2].
It can be shown that the maximum number of groups is 2.
So, the output is 2.

```

**Example 3:**

```

**Input:** usageLimits = [1,1]
**Output:** 1
**Explanation:** In this example, we can use both 0 and 1 at most once.
One way of creating the maximum number of groups while satisfying the conditions is:
Group 1 contains the number [0].
It can be shown that the maximum number of groups is 1.
So, the output is 1.

```

**Constraints:**

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

Please make sure your answer follows the type signature below:

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

my_solution = Solution()

assert my_solution.maxIncreasingGroups(**[[1, 2, 5]]) == 3
assert my_solution.maxIncreasingGroups(**[[2, 1, 2]]) == 2
assert my_solution.maxIncreasingGroups(**[[1, 1]]) == 1
assert my_solution.maxIncreasingGroups(**[[1, 4]]) == 2
assert my_solution.maxIncreasingGroups(**[[1, 5]]) == 2
assert my_solution.maxIncreasingGroups(**[[1, 7]]) == 2
assert my_solution.maxIncreasingGroups(**[[1, 8]]) == 2
assert my_solution.maxIncreasingGroups(**[[2, 1]]) == 2
assert my_solution.maxIncreasingGroups(**[[2, 2]]) == 2
assert my_solution.maxIncreasingGroups(**[[2, 3]]) == 2
assert my_solution.maxIncreasingGroups(**[[2, 4]]) == 2
assert my_solution.maxIncreasingGroups(**[[2, 5]]) == 2
assert my_solution.maxIncreasingGroups(**[[2, 7]]) == 2
assert my_solution.maxIncreasingGroups(**[[2, 8]]) == 2
assert my_solution.maxIncreasingGroups(**[[2, 9]]) == 2
assert my_solution.maxIncreasingGroups(**[[3, 1]]) == 2
assert my_solution.maxIncreasingGroups(**[[3, 4]]) == 2
assert my_solution.maxIncreasingGroups(**[[3, 7]]) == 2
assert my_solution.maxIncreasingGroups(**[[3, 10]]) == 2
assert my_solution.maxIncreasingGroups(**[[4, 1]]) == 2


# Check if Array is Good

You are given an integer array `nums`. We consider an array **good** if it is a permutation of an array `base[n]`.

`base[n] = [1, 2, ..., n - 1, n, n]` (in other words, it is an array of length `n + 1` which contains `1` to `n - 1` exactly once, plus two occurrences of `n`). For example, `base[1] = [1, 1]` and `base[3] = [1, 2, 3, 3]`.

Return `true` *if the given array is good, otherwise return*`false`.

**Note:** A permutation of integers represents an arrangement of these numbers.

**Example 1:**

```

**Input:** nums = [2, 1, 3]
**Output:** false
**Explanation:** Since the maximum element of the array is 3, the only candidate n for which this array could be a permutation of base[n], is n = 3. However, base[3] has four elements but array nums has three. Therefore, it can not be a permutation of base[3] = [1, 2, 3, 3]. So the answer is false.

```

**Example 2:**

```

**Input:** nums = [1, 3, 3, 2]
**Output:** true
**Explanation:** Since the maximum element of the array is 3, the only candidate n for which this array could be a permutation of base[n], is n = 3. It can be seen that nums is a permutation of base[3] = [1, 2, 3, 3] (by swapping the second and fourth elements in nums, we reach base[3]). Therefore, the answer is true.
```

**Example 3:**

```

**Input:** nums = [1, 1]
**Output:** true
**Explanation:** Since the maximum element of the array is 1, the only candidate n for which this array could be a permutation of base[n], is n = 1. It can be seen that nums is a permutation of base[1] = [1, 1]. Therefore, the answer is true.
```

**Example 4:**

```

**Input:** nums = [3, 4, 4, 1, 2, 1]
**Output:** false
**Explanation:** Since the maximum element of the array is 4, the only candidate n for which this array could be a permutation of base[n], is n = 4. However, base[4] has five elements but array nums has six. Therefore, it can not be a permutation of base[4] = [1, 2, 3, 4, 4]. So the answer is false.

```

**Constraints:**

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

Please make sure your answer follows the type signature below:

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

my_solution = Solution()

assert my_solution.isGood(**[[2, 1, 3]]) == False
assert my_solution.isGood(**[[1, 3, 3, 2]]) == True
assert my_solution.isGood(**[[1, 1]]) == True
assert my_solution.isGood(**[[3, 4, 4, 1, 2, 1]]) == False
assert my_solution.isGood(**[[1]]) == False
assert my_solution.isGood(**[[2]]) == False
assert my_solution.isGood(**[[3]]) == False
assert my_solution.isGood(**[[4]]) == False
assert my_solution.isGood(**[[5]]) == False
assert my_solution.isGood(**[[6]]) == False
assert my_solution.isGood(**[[8]]) == False
assert my_solution.isGood(**[[9]]) == False
assert my_solution.isGood(**[[10]]) == False
assert my_solution.isGood(**[[12]]) == False
assert my_solution.isGood(**[[13]]) == False
assert my_solution.isGood(**[[14]]) == False
assert my_solution.isGood(**[[15]]) == False
assert my_solution.isGood(**[[82]]) == False
assert my_solution.isGood(**[[1, 8]]) == False
assert my_solution.isGood(**[[1, 13]]) == False


# Sort Vowels in a String

Given a **0-indexed** string `s`, **permute** `s` to get a new string `t` such that:

* All consonants remain in their original places. More formally, if there is an index `i` with `0 <= i < s.length` such that `s[i]` is a consonant, then `t[i] = s[i]`.
* The vowels must be sorted in the **nondecreasing** order of their **ASCII** values. More formally, for pairs of indices `i`, `j` with `0 <= i < j < s.length` such that `s[i]` and `s[j]` are vowels, then `t[i]` must not have a higher ASCII value than `t[j]`.

Return *the resulting string*.

The vowels are `'a'`, `'e'`, `'i'`, `'o'`, and `'u'`, and they can appear in lowercase or uppercase. Consonants comprise all letters that are not vowels.

**Example 1:**

```

**Input:** s = "lEetcOde"
**Output:** "lEOtcede"
**Explanation:** 'E', 'O', and 'e' are the vowels in s; 'l', 't', 'c', and 'd' are all consonants. The vowels are sorted according to their ASCII values, and the consonants remain in the same places.

```

**Example 2:**

```

**Input:** s = "lYmpH"
**Output:** "lYmpH"
**Explanation:** There are no vowels in s (all characters in s are consonants), so we return "lYmpH".

```

**Constraints:**

* `1 <= s.length <= 105`
* `s` consists only of letters of the English alphabet in **uppercase and lowercase**.

Please make sure your answer follows the type signature below:

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

my_solution = Solution()

assert my_solution.sortVowels(**['lEetcOde']) == lEOtcede
assert my_solution.sortVowels(**['lYmpH']) == lYmpH
assert my_solution.sortVowels(**['mDVD']) == mDVD
assert my_solution.sortVowels(**['xdX']) == xdX
assert my_solution.sortVowels(**['xdE']) == xdE
assert my_solution.sortVowels(**['RiQYo']) == RiQYo
assert my_solution.sortVowels(**['LQRamBOHfq']) == LQROmBaHfq
assert my_solution.sortVowels(**['UpjPbEnOj']) == EpjPbOnUj
assert my_solution.sortVowels(**['ziF']) == ziF
assert my_solution.sortVowels(**['WxkKdjhL']) == WxkKdjhL
assert my_solution.sortVowels(**['uZcPmqAd']) == AZcPmqud
assert my_solution.sortVowels(**['UjshJXjkjS']) == UjshJXjkjS
assert my_solution.sortVowels(**['nElwWTQHJ']) == nElwWTQHJ
assert my_solution.sortVowels(**['kwcJqvsgM']) == kwcJqvsgM
assert my_solution.sortVowels(**['z']) == z
assert my_solution.sortVowels(**['Pz']) == Pz
assert my_solution.sortVowels(**['T']) == T
assert my_solution.sortVowels(**['syRWvFi']) == syRWvFi
assert my_solution.sortVowels(**['G']) == G
assert my_solution.sortVowels(**['MuQYHVy']) == MuQYHVy


# Visit Array Positions to Maximize Score

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

You are **initially** at position `0` in the array and you can visit other positions according to the following rules:

* If you are currently in position `i`, then you can move to **any** position `j` such that `i < j`.
* For each position `i` that you visit, you get a score of `nums[i]`.
* If you move from a position `i` to a position `j` and the **parities** of `nums[i]` and `nums[j]` differ, then you lose a score of `x`.

Return *the **maximum** total score you can get*.

**Note** that initially you have `nums[0]` points.

**Example 1:**

```

**Input:** nums = [2,3,6,1,9,2], x = 5
**Output:** 13
**Explanation:** We can visit the following positions in the array: 0 -> 2 -> 3 -> 4.
The corresponding values are 2, 6, 1 and 9. Since the integers 6 and 1 have different parities, the move 2 -> 3 will make you lose a score of x = 5.
The total score will be: 2 + 6 + 1 + 9 - 5 = 13.

```

**Example 2:**

```

**Input:** nums = [2,4,6,8], x = 3
**Output:** 20
**Explanation:** All the integers in the array have the same parities, so we can visit all of them without losing any score.
The total score is: 2 + 4 + 6 + 8 = 20.

```

**Constraints:**

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

Please make sure your answer follows the type signature below:

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


# Ways to Express an Integer as Sum of Powers

Given two **positive** integers `n` and `x`.

Return *the number of ways* `n` *can be expressed as the sum of the* `xth` *power of **unique** positive integers, in other words, the number of sets of unique integers* `[n1, n2, ..., nk]` *where* `n = n1x + n2x + ... + nkx`*.*

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

For example, if `n = 160` and `x = 3`, one way to express `n` is `n = 23 + 33 + 53`.

**Example 1:**

```

**Input:** n = 10, x = 2
**Output:** 1
**Explanation:** We can express n as the following: n = 32 + 12 = 10.
It can be shown that it is the only way to express 10 as the sum of the 2nd power of unique integers.

```

**Example 2:**

```

**Input:** n = 4, x = 1
**Output:** 2
**Explanation:** We can express n in the following ways:
- n = 41 = 4.
- n = 31 + 11 = 4.

```

**Constraints:**

* `1 <= n <= 300`
* `1 <= x <= 5`

Please make sure your answer follows the type signature below:

```python3
class Solution:
    def numberOfWays(self, n: int, x: int) -> int:
```

my_solution = Solution()

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


# Sum of Squares of Special Elements

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

An element `nums[i]` of `nums` is called **special** if `i` divides `n`, i.e. `n % i == 0`.

Return *the **sum of the squares** of all **special** elements of* `nums`.

**Example 1:**

```

**Input:** nums = [1,2,3,4]
**Output:** 21
**Explanation:** There are exactly 3 special elements in nums: nums[1] since 1 divides 4, nums[2] since 2 divides 4, and nums[4] since 4 divides 4.
Hence, the sum of the squares of all special elements of nums is nums[1] * nums[1] + nums[2] * nums[2] + nums[4] * nums[4] = 1 * 1 + 2 * 2 + 4 * 4 = 21.

```

**Example 2:**

```

**Input:** nums = [2,7,1,19,18,3]
**Output:** 63
**Explanation:** There are exactly 4 special elements in nums: nums[1] since 1 divides 6, nums[2] since 2 divides 6, nums[3] since 3 divides 6, and nums[6] since 6 divides 6.
Hence, the sum of the squares of all special elements of nums is nums[1] * nums[1] + nums[2] * nums[2] + nums[3] * nums[3] + nums[6] * nums[6] = 2 * 2 + 7 * 7 + 1 * 1 + 3 * 3 = 63.

```

**Constraints:**

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

Please make sure your answer follows the type signature below:

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

my_solution = Solution()

assert my_solution.sumOfSquares(**[[1, 2, 3, 4]]) == 21
assert my_solution.sumOfSquares(**[[2, 7, 1, 19, 18, 3]]) == 63
assert my_solution.sumOfSquares(**[[1]]) == 1
assert my_solution.sumOfSquares(**[[2]]) == 4
assert my_solution.sumOfSquares(**[[3]]) == 9
assert my_solution.sumOfSquares(**[[4]]) == 16
assert my_solution.sumOfSquares(**[[5]]) == 25
assert my_solution.sumOfSquares(**[[6]]) == 36
assert my_solution.sumOfSquares(**[[7]]) == 49
assert my_solution.sumOfSquares(**[[8]]) == 64
assert my_solution.sumOfSquares(**[[9]]) == 81
assert my_solution.sumOfSquares(**[[10]]) == 100
assert my_solution.sumOfSquares(**[[11]]) == 121
assert my_solution.sumOfSquares(**[[12]]) == 144
assert my_solution.sumOfSquares(**[[13]]) == 169
assert my_solution.sumOfSquares(**[[14]]) == 196
assert my_solution.sumOfSquares(**[[15]]) == 225
assert my_solution.sumOfSquares(**[[16]]) == 256
assert my_solution.sumOfSquares(**[[17]]) == 289
assert my_solution.sumOfSquares(**[[18]]) == 324


# Maximum Beauty of an Array After Applying Operation

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

In one operation, you can do the following:

* Choose an index `i` that **hasn't been chosen before** from the range `[0, nums.length - 1]`.
* Replace `nums[i]` with any integer from the range `[nums[i] - k, nums[i] + k]`.

The **beauty** of the array is the length of the longest subsequence consisting of equal elements.

Return *the **maximum** possible beauty of the array* `nums` *after applying the operation any number of times.*

**Note** that you can apply the operation to each index **only once**.

A **subsequence** of an array is a new array generated from the original array by deleting some elements (possibly none) without changing the order of the remaining elements.

**Example 1:**

```

**Input:** nums = [4,6,1,2], k = 2
**Output:** 3
**Explanation:** In this example, we apply the following operations:
- Choose index 1, replace it with 4 (from range [4,8]), nums = [4,4,1,2].
- Choose index 3, replace it with 4 (from range [0,4]), nums = [4,4,1,4].
After the applied operations, the beauty of the array nums is 3 (subsequence consisting of indices 0, 1, and 3).
It can be proven that 3 is the maximum possible length we can achieve.

```

**Example 2:**

```

**Input:** nums = [1,1,1,1], k = 10
**Output:** 4
**Explanation:** In this example we don't have to apply any operations.
The beauty of the array nums is 4 (whole array).

```

**Constraints:**

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

Please make sure your answer follows the type signature below:

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

my_solution = Solution()

assert my_solution.maximumBeauty(**[[4, 6, 1, 2], 2]) == 3
assert my_solution.maximumBeauty(**[[1, 1, 1, 1], 10]) == 4
assert my_solution.maximumBeauty(**[[12, 71], 10]) == 1
assert my_solution.maximumBeauty(**[[27, 55], 1]) == 1
assert my_solution.maximumBeauty(**[[52, 34], 21]) == 2
assert my_solution.maximumBeauty(**[[76, 0], 16]) == 1
assert my_solution.maximumBeauty(**[[56, 40], 26]) == 2
assert my_solution.maximumBeauty(**[[49, 26], 12]) == 2
assert my_solution.maximumBeauty(**[[69, 66], 14]) == 2
assert my_solution.maximumBeauty(**[[64, 98], 12]) == 1
assert my_solution.maximumBeauty(**[[83, 81], 7]) == 2
assert my_solution.maximumBeauty(**[[44, 93], 15]) == 1
assert my_solution.maximumBeauty(**[[44, 31], 26]) == 2
assert my_solution.maximumBeauty(**[[70, 60], 15]) == 2
assert my_solution.maximumBeauty(**[[60, 22], 11]) == 1
assert my_solution.maximumBeauty(**[[33, 20], 1]) == 1
assert my_solution.maximumBeauty(**[[64, 24], 4]) == 1
assert my_solution.maximumBeauty(**[[59, 20], 28]) == 2
assert my_solution.maximumBeauty(**[[10, 98], 27]) == 1
assert my_solution.maximumBeauty(**[[54, 21], 20]) == 2


# Minimum Index of a Valid Split

An element `x` of an integer array `arr` of length `m` is **dominant** if `freq(x) * 2 > m`, where `freq(x)` is the number of occurrences of `x` in `arr`. Note that this definition implies that `arr` can have **at most one** dominant element.

You are given a **0-indexed** integer array `nums` of length `n` with one dominant element.

You can split `nums` at an index `i` into two arrays `nums[0, ..., i]` and `nums[i + 1, ..., n - 1]`, but the split is only **valid** if:

* `0 <= i < n - 1`
* `nums[0, ..., i]`, and `nums[i + 1, ..., n - 1]` have the same dominant element.

Here, `nums[i, ..., j]` denotes the subarray of `nums` starting at index `i` and ending at index `j`, both ends being inclusive. Particularly, if `j < i` then `nums[i, ..., j]` denotes an empty subarray.

Return *the **minimum** index of a **valid split***. If no valid split exists, return `-1`.

**Example 1:**

```

**Input:** nums = [1,2,2,2]
**Output:** 2
**Explanation:** We can split the array at index 2 to obtain arrays [1,2,2] and [2].
In array [1,2,2], element 2 is dominant since it occurs twice in the array and 2 * 2 > 3.
In array [2], element 2 is dominant since it occurs once in the array and 1 * 2 > 1.
Both [1,2,2] and [2] have the same dominant element as nums, so this is a valid split.
It can be shown that index 2 is the minimum index of a valid split.
```

**Example 2:**

```

**Input:** nums = [2,1,3,1,1,1,7,1,2,1]
**Output:** 4
**Explanation:** We can split the array at index 4 to obtain arrays [2,1,3,1,1] and [1,7,1,2,1].
In array [2,1,3,1,1], element 1 is dominant since it occurs thrice in the array and 3 * 2 > 5.
In array [1,7,1,2,1], element 1 is dominant since it occurs thrice in the array and 3 * 2 > 5.
Both [2,1,3,1,1] and [1,7,1,2,1] have the same dominant element as nums, so this is a valid split.
It can be shown that index 4 is the minimum index of a valid split.
```

**Example 3:**

```

**Input:** nums = [3,3,3,3,7,2,2]
**Output:** -1
**Explanation:** It can be shown that there is no valid split.

```

**Constraints:**

* `1 <= nums.length <= 105`
* `1 <= nums[i] <= 109`
* `nums` has exactly one dominant element.

Please make sure your answer follows the type signature below:

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

my_solution = Solution()

assert my_solution.minimumIndex(**[[1, 2, 2, 2]]) == 2
assert my_solution.minimumIndex(**[[2, 1, 3, 1, 1, 1, 7, 1, 2, 1]]) == 4
assert my_solution.minimumIndex(**[[3, 3, 3, 3, 7, 2, 2]]) == -1
assert my_solution.minimumIndex(**[[1]]) == -1
assert my_solution.minimumIndex(**[[1, 1]]) == 0
assert my_solution.minimumIndex(**[[1, 1, 1]]) == 0
assert my_solution.minimumIndex(**[[1, 1, 1, 1]]) == 0
assert my_solution.minimumIndex(**[[1, 1, 1, 2]]) == 0
assert my_solution.minimumIndex(**[[1, 1, 1, 3]]) == 0
assert my_solution.minimumIndex(**[[1, 1, 1, 4]]) == 0
assert my_solution.minimumIndex(**[[1, 1, 2]]) == -1
assert my_solution.minimumIndex(**[[1, 1, 2, 1]]) == 0
assert my_solution.minimumIndex(**[[1, 1, 3]]) == -1
assert my_solution.minimumIndex(**[[1, 1, 3, 1]]) == 0
assert my_solution.minimumIndex(**[[1, 1, 4]]) == -1
assert my_solution.minimumIndex(**[[1, 1, 4, 1]]) == 0
assert my_solution.minimumIndex(**[[1, 2, 1]]) == -1
assert my_solution.minimumIndex(**[[1, 2, 1, 1]]) == 0
assert my_solution.minimumIndex(**[[1, 2, 2]]) == -1
assert my_solution.minimumIndex(**[[1, 3, 1]]) == -1


# Length of the Longest Valid Substring

You are given a string `word` and an array of strings `forbidden`.

A string is called **valid** if none of its substrings are present in `forbidden`.

Return *the length of the **longest valid substring** of the string* `word`.

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

**Example 1:**

```

**Input:** word = "cbaaaabc", forbidden = ["aaa","cb"]
**Output:** 4
**Explanation:** There are 11 valid substrings in word: "c", "b", "a", "ba", "aa", "bc", "baa", "aab", "ab", "abc" and "aabc". The length of the longest valid substring is 4.
It can be shown that all other substrings contain either "aaa" or "cb" as a substring.
```

**Example 2:**

```

**Input:** word = "leetcode", forbidden = ["de","le","e"]
**Output:** 4
**Explanation:** There are 11 valid substrings in word: "l", "t", "c", "o", "d", "tc", "co", "od", "tco", "cod", and "tcod". The length of the longest valid substring is 4.
It can be shown that all other substrings contain either "de", "le", or "e" as a substring.

```

**Constraints:**

* `1 <= word.length <= 105`
* `word` consists only of lowercase English letters.
* `1 <= forbidden.length <= 105`
* `1 <= forbidden[i].length <= 10`
* `forbidden[i]` consists only of lowercase English letters.

Please make sure your answer follows the type signature below:

```python3
class Solution:
    def longestValidSubstring(self, word: str, forbidden: List[str]) -> int:
```

my_solution = Solution()

assert my_solution.longestValidSubstring(**['cbaaaabc', ['aaa', 'cb']]) == 4
assert my_solution.longestValidSubstring(**['leetcode', ['de', 'le', 'e']]) == 4
assert my_solution.longestValidSubstring(**['a', ['n']]) == 1
assert my_solution.longestValidSubstring(**['a', ['s']]) == 1
assert my_solution.longestValidSubstring(**['a', ['a']]) == 0
assert my_solution.longestValidSubstring(**['b', ['g']]) == 1
assert my_solution.longestValidSubstring(**['b', ['t']]) == 1
assert my_solution.longestValidSubstring(**['b', ['b']]) == 0
assert my_solution.longestValidSubstring(**['c', ['k']]) == 1
assert my_solution.longestValidSubstring(**['c', ['s']]) == 1
assert my_solution.longestValidSubstring(**['c', ['c']]) == 0
assert my_solution.longestValidSubstring(**['d', ['h']]) == 1
assert my_solution.longestValidSubstring(**['d', ['n']]) == 1
assert my_solution.longestValidSubstring(**['d', ['d']]) == 0
assert my_solution.longestValidSubstring(**['e', ['s']]) == 1
assert my_solution.longestValidSubstring(**['e', ['e']]) == 0
assert my_solution.longestValidSubstring(**['f', ['b']]) == 1
assert my_solution.longestValidSubstring(**['f', ['s']]) == 1
assert my_solution.longestValidSubstring(**['f', ['f']]) == 0
assert my_solution.longestValidSubstring(**['g', ['r']]) == 1


# Find the Maximum Achievable Number

You are given two integers, `num` and `t`.

An integer `x` is called **achievable** if it can become equal to `num` after applying the following operation no more than `t` times:

* Increase or decrease `x` by `1`, and simultaneously increase or decrease `num` by `1`.

Return *the maximum possible achievable number*. It can be proven that there exists at least one achievable number.

**Example 1:**

```

**Input:** num = 4, t = 1
**Output:** 6
**Explanation:** The maximum achievable number is x = 6; it can become equal to num after performing this operation:
1- Decrease x by 1, and increase num by 1. Now, x = 5 and num = 5.
It can be proven that there is no achievable number larger than 6.

```

**Example 2:**

```

**Input:** num = 3, t = 2
**Output:** 7
**Explanation:** The maximum achievable number is x = 7; after performing these operations, x will equal num:
1- Decrease x by 1, and increase num by 1. Now, x = 6 and num = 4.
2- Decrease x by 1, and increase num by 1. Now, x = 5 and num = 5.
It can be proven that there is no achievable number larger than 7.

```

**Constraints:**

* `1 <= num, t <= 50`

Please make sure your answer follows the type signature below:

```python3
class Solution:
    def theMaximumAchievableX(self, num: int, t: int) -> int:
```

my_solution = Solution()

assert my_solution.theMaximumAchievableX(**[4, 1]) == 6
assert my_solution.theMaximumAchievableX(**[3, 2]) == 7
assert my_solution.theMaximumAchievableX(**[1, 1]) == 3
assert my_solution.theMaximumAchievableX(**[1, 2]) == 5
assert my_solution.theMaximumAchievableX(**[1, 3]) == 7
assert my_solution.theMaximumAchievableX(**[1, 4]) == 9
assert my_solution.theMaximumAchievableX(**[1, 5]) == 11
assert my_solution.theMaximumAchievableX(**[1, 6]) == 13
assert my_solution.theMaximumAchievableX(**[1, 7]) == 15
assert my_solution.theMaximumAchievableX(**[1, 8]) == 17
assert my_solution.theMaximumAchievableX(**[1, 9]) == 19
assert my_solution.theMaximumAchievableX(**[1, 10]) == 21
assert my_solution.theMaximumAchievableX(**[1, 11]) == 23
assert my_solution.theMaximumAchievableX(**[1, 12]) == 25
assert my_solution.theMaximumAchievableX(**[1, 13]) == 27
assert my_solution.theMaximumAchievableX(**[1, 14]) == 29
assert my_solution.theMaximumAchievableX(**[1, 15]) == 31
assert my_solution.theMaximumAchievableX(**[1, 16]) == 33
assert my_solution.theMaximumAchievableX(**[1, 17]) == 35
assert my_solution.theMaximumAchievableX(**[1, 18]) == 37


# Maximum Number of Jumps to Reach the Last Index

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

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

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

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

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

**Example 1:**

```

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

**Example 2:**

```

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

**Example 3:**

```

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

```

**Constraints:**

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

Please make sure your answer follows the type signature below:

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

my_solution = Solution()

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