apply-operations-to-maximize-score

Apply Operations to Maximize Score

Prompt:
"""
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)
"""
class Solution:
    def maximumScore(self, nums: List[int], k: int) -> int:

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 complete the code below to solve above prblem:
```python
class Solution:
    def maximumScore(self, nums: List[int], k: int) -> int:

```

my_solution = Solution()

test_input = { "nums": [8,3,9,3,8], "k": 2 }
assert my_solution.maximumScore(**test_input) == 81

test_input = { "nums": [19,12,14,6,10,18], "k": 3 }
assert my_solution.maximumScore(**test_input) == 4788

test_input = { "nums": [3289,2832,14858,22011], "k": 6 }
assert my_solution.maximumScore(**test_input) == 256720975

test_input = { "nums": [1,7,11,1,5], "k": 14 }
assert my_solution.maximumScore(**test_input) == 823751938

test_input = { "nums": [1,1,2,18,1,9,3,1], "k": 32 }
assert my_solution.maximumScore(**test_input) == 346264255

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

test_input = { "nums": [1,2,1,12,1,3], "k": 3 }
assert my_solution.maximumScore(**test_input) == 1728

test_input = { "nums": [12,5,1,6,9,1,17,14], "k": 12 }
assert my_solution.maximumScore(**test_input) == 62996359

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

test_input = { "nums": [1,10,15,1,3], "k": 13 }
assert my_solution.maximumScore(**test_input) == 499978741

test_input = { "nums": [6,1,13,10,1,17,6], "k": 27 }
assert my_solution.maximumScore(**test_input) == 630596200

test_input = { "nums": [1,14], "k": 1 }
assert my_solution.maximumScore(**test_input) == 14

test_input = { "nums": [2,1,14,5,18,1,8,5], "k": 34 }
assert my_solution.maximumScore(**test_input) == 799392504

test_input = { "nums": [5,12,11,15,10,18], "k": 18 }
assert my_solution.maximumScore(**test_input) == 557423913

test_input = { "nums": [4,1], "k": 3 }
assert my_solution.maximumScore(**test_input) == 16

test_input = { "nums": [1,2,5,1,10,1,1], "k": 20 }
assert my_solution.maximumScore(**test_input) == 600000014

test_input = { "nums": [13,16,12,15,12,1,13,1,18,1], "k": 46 }
assert my_solution.maximumScore(**test_input) == 912532739

test_input = { "nums": [10,11], "k": 3 }
assert my_solution.maximumScore(**test_input) == 1100

test_input = { "nums": [15,16,12,1,10,14], "k": 19 }
assert my_solution.maximumScore(**test_input) == 311972352

test_input = { "nums": [14,12,5,2,14], "k": 6 }
assert my_solution.maximumScore(**test_input) == 7529536

test_input = { "nums": [1,13,12,1,9,12,1,18], "k": 31 }
assert my_solution.maximumScore(**test_input) == 846374420

test_input = { "nums": [1,6,14,10,16], "k": 4 }
assert my_solution.maximumScore(**test_input) == 43904

test_input = { "nums": [14,1,9,1,10], "k": 3 }
assert my_solution.maximumScore(**test_input) == 2744

test_input = { "nums": [13,1,1,15,9,1,1], "k": 22 }
assert my_solution.maximumScore(**test_input) == 925331761

test_input = { "nums": [1,17,3,9,10,17,1,1,1,11], "k": 22 }
assert my_solution.maximumScore(**test_input) == 407065837

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

test_input = { "nums": [1,13,4,1,1], "k": 14 }
assert my_solution.maximumScore(**test_input) == 206765780

test_input = { "nums": [3,1,3,10,2,16], "k": 16 }
assert my_solution.maximumScore(**test_input) == 996976007

test_input = { "nums": [1,2,1,1,16,8,11,6], "k": 27 }
assert my_solution.maximumScore(**test_input) == 33977400

test_input = { "nums": [1,10,13,1,9,15,1], "k": 2 }
assert my_solution.maximumScore(**test_input) == 225

test_input = { "nums": [18,1], "k": 3 }
assert my_solution.maximumScore(**test_input) == 324

test_input = { "nums": [16], "k": 1 }
assert my_solution.maximumScore(**test_input) == 16

test_input = { "nums": [14,6,18,10,1,8,1,17], "k": 25 }
assert my_solution.maximumScore(**test_input) == 677968714

test_input = { "nums": [15,16,12], "k": 6 }
assert my_solution.maximumScore(**test_input) == 7776000

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

test_input = { "nums": [13,1,10,1,15,6,1,12,6], "k": 10 }
assert my_solution.maximumScore(**test_input) == 650386593

test_input = { "nums": [1,15,5,1,1,15,1,1], "k": 17 }
assert my_solution.maximumScore(**test_input) == 10486853

test_input = { "nums": [1,9], "k": 2 }
assert my_solution.maximumScore(**test_input) == 81

test_input = { "nums": [13,8,14,6,3,14,13,10,1], "k": 21 }
assert my_solution.maximumScore(**test_input) == 247566578

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

test_input = { "nums": [1,12,5,1,12], "k": 15 }
assert my_solution.maximumScore(**test_input) == 209137175

test_input = { "nums": [1,5,1,11], "k": 4 }
assert my_solution.maximumScore(**test_input) == 3025

test_input = { "nums": [3,6,17,1,1,17,18,12,16,5], "k": 9 }
assert my_solution.maximumScore(**test_input) == 359288982

test_input = { "nums": [2,2,15,2,15,15], "k": 10 }
assert my_solution.maximumScore(**test_input) == 650386593

test_input = { "nums": [1,12], "k": 1 }
assert my_solution.maximumScore(**test_input) == 12

test_input = { "nums": [2,11,1,1], "k": 2 }
assert my_solution.maximumScore(**test_input) == 121

test_input = { "nums": [11,15,18,4,11,7,1,1], "k": 32 }
assert my_solution.maximumScore(**test_input) == 179964426

test_input = { "nums": [10,1,15], "k": 1 }
assert my_solution.maximumScore(**test_input) == 15

test_input = { "nums": [10,1,1,9,14,6,4,18,8], "k": 10 }
assert my_solution.maximumScore(**test_input) == 420565606

test_input = { "nums": [6,8], "k": 3 }
assert my_solution.maximumScore(**test_input) == 288

test_input = { "nums": [13,1,10,6], "k": 4 }
assert my_solution.maximumScore(**test_input) == 16900

test_input = { "nums": [8,10,16,1,1,1], "k": 2 }
assert my_solution.maximumScore(**test_input) == 256

test_input = { "nums": [11,2,1], "k": 4 }
assert my_solution.maximumScore(**test_input) == 2662

test_input = { "nums": [15], "k": 1 }
assert my_solution.maximumScore(**test_input) == 15

test_input = { "nums": [5,5,16,12,8,1,1,7,12], "k": 34 }
assert my_solution.maximumScore(**test_input) == 15762264

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

test_input = { "nums": [3,18,12,8,1,3,6], "k": 23 }
assert my_solution.maximumScore(**test_input) == 18966086

test_input = { "nums": [13,1,5,6], "k": 8 }
assert my_solution.maximumScore(**test_input) == 14236560

test_input = { "nums": [1,1,15,1,9,1,1], "k": 23 }
assert my_solution.maximumScore(**test_input) == 929527145

test_input = { "nums": [6,2,1,17,9,14,1], "k": 25 }
assert my_solution.maximumScore(**test_input) == 808455901

test_input = { "nums": [1,18], "k": 3 }
assert my_solution.maximumScore(**test_input) == 324

test_input = { "nums": [1,10], "k": 2 }
assert my_solution.maximumScore(**test_input) == 100

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

test_input = { "nums": [18,13,12,1,11], "k": 8 }
assert my_solution.maximumScore(**test_input) == 537271275

test_input = { "nums": [10,14,18,6,12,14,3,13], "k": 23 }
assert my_solution.maximumScore(**test_input) == 795923147

test_input = { "nums": [16,1,14,13,3,1], "k": 6 }
assert my_solution.maximumScore(**test_input) == 9834496

test_input = { "nums": [10,4,4,3,10,1], "k": 15 }
assert my_solution.maximumScore(**test_input) == 997200007

test_input = { "nums": [2,4,1,5,14,13,13,17], "k": 19 }
assert my_solution.maximumScore(**test_input) == 241329678

test_input = { "nums": [6,1,15,1,13], "k": 12 }
assert my_solution.maximumScore(**test_input) == 820232542

test_input = { "nums": [14,13,1,14], "k": 5 }
assert my_solution.maximumScore(**test_input) == 537824

test_input = { "nums": [10,4,12,12,16,9,1,18], "k": 36 }
assert my_solution.maximumScore(**test_input) == 892891506

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

test_input = { "nums": [12], "k": 1 }
assert my_solution.maximumScore(**test_input) == 12

test_input = { "nums": [10,17,17,15,1,15,1], "k": 19 }
assert my_solution.maximumScore(**test_input) == 301460564

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

test_input = { "nums": [10,12], "k": 3 }
assert my_solution.maximumScore(**test_input) == 1200

test_input = { "nums": [9,10,2,3,2,1,11,1,1,13], "k": 49 }
assert my_solution.maximumScore(**test_input) == 900432644

test_input = { "nums": [1,10,18,18,3,1,8,1,15,15], "k": 18 }
assert my_solution.maximumScore(**test_input) == 38759446

test_input = { "nums": [15,1,11,13,16], "k": 14 }
assert my_solution.maximumScore(**test_input) == 753886562

test_input = { "nums": [12,1,6,1,1,4,8,17,18,1], "k": 2 }
assert my_solution.maximumScore(**test_input) == 324

test_input = { "nums": [1,1,1,17,8,18,8,1], "k": 14 }
assert my_solution.maximumScore(**test_input) == 958387476

test_input = { "nums": [7,1,6,9,11,7,13,12,1], "k": 39 }
assert my_solution.maximumScore(**test_input) == 21295572

test_input = { "nums": [12,1,1,15,2,1,1,16,1,1], "k": 8 }
assert my_solution.maximumScore(**test_input) == 294967268

test_input = { "nums": [3,14,13,1,11,1,1,1], "k": 22 }
assert my_solution.maximumScore(**test_input) == 810815174

test_input = { "nums": [14,3,6,6,1,7,13,16], "k": 28 }
assert my_solution.maximumScore(**test_input) == 312142986

test_input = { "nums": [3,4,4,15,18,12,6], "k": 8 }
assert my_solution.maximumScore(**test_input) == 428674972

test_input = { "nums": [6,15,17,9,9,17], "k": 5 }
assert my_solution.maximumScore(**test_input) == 1419857

test_input = { "nums": [2,12,1,11,12], "k": 5 }
assert my_solution.maximumScore(**test_input) == 248832

test_input = { "nums": [1,15,15], "k": 4 }
assert my_solution.maximumScore(**test_input) == 50625

test_input = { "nums": [7,11,3,1,12,10], "k": 15 }
assert my_solution.maximumScore(**test_input) == 784368200

test_input = { "nums": [18,1,11,15,16,18,18,13,10,10], "k": 41 }
assert my_solution.maximumScore(**test_input) == 911212578

test_input = { "nums": [11,15,2,14,6,15], "k": 2 }
assert my_solution.maximumScore(**test_input) == 225

test_input = { "nums": [11,2,15,1,1,11,7,1], "k": 16 }
assert my_solution.maximumScore(**test_input) == 734032462

test_input = { "nums": [1,6,12,4,10,13,7,6,17,1], "k": 50 }
assert my_solution.maximumScore(**test_input) == 377786273

test_input = { "nums": [1,5,4,18,12,1,1,1,7,12], "k": 3 }
assert my_solution.maximumScore(**test_input) == 5832

test_input = { "nums": [5,1,17,10,12], "k": 9 }
assert my_solution.maximumScore(**test_input) == 467999979

test_input = { "nums": [6,1,1,4,10,15,16,8], "k": 12 }
assert my_solution.maximumScore(**test_input) == 999939527

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

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

test_input = { "nums": [9,8,14,1,14,14,5,1,6], "k": 44 }
assert my_solution.maximumScore(**test_input) == 439903801


faulty-keyboard

Faulty Keyboard

Prompt:
"""
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'
"""
class Solution:
    def finalString(self, s: str) -> str:

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 complete the code below to solve above prblem:
```python
class Solution:
    def finalString(self, s: str) -> str:

```

my_solution = Solution()

test_input = { "s": "string" }
assert my_solution.finalString(**test_input) == "rtsng"

test_input = { "s": "poiinter" }
assert my_solution.finalString(**test_input) == "ponter"

test_input = { "s": "goci" }
assert my_solution.finalString(**test_input) == "cog"

test_input = { "s": "ksi" }
assert my_solution.finalString(**test_input) == "sk"

test_input = { "s": "fii" }
assert my_solution.finalString(**test_input) == "f"

test_input = { "s": "qskyviiiii" }
assert my_solution.finalString(**test_input) == "vyksq"

test_input = { "s": "pft" }
assert my_solution.finalString(**test_input) == "pft"

test_input = { "s": "viwif" }
assert my_solution.finalString(**test_input) == "wvf"

test_input = { "s": "wiie" }
assert my_solution.finalString(**test_input) == "we"

test_input = { "s": "kiis" }
assert my_solution.finalString(**test_input) == "ks"

test_input = { "s": "xihbosxitx" }
assert my_solution.finalString(**test_input) == "xsobhxtx"

test_input = { "s": "uwioili" }
assert my_solution.finalString(**test_input) == "lwuo"

test_input = { "s": "aapziai" }
assert my_solution.finalString(**test_input) == "aaapz"

test_input = { "s": "pviist" }
assert my_solution.finalString(**test_input) == "pvst"

test_input = { "s": "miiuiei" }
assert my_solution.finalString(**test_input) == "emu"

test_input = { "s": "diiiiq" }
assert my_solution.finalString(**test_input) == "dq"

test_input = { "s": "eirov" }
assert my_solution.finalString(**test_input) == "erov"

test_input = { "s": "niiiiisiii" }
assert my_solution.finalString(**test_input) == "sn"

test_input = { "s": "siiuii" }
assert my_solution.finalString(**test_input) == "su"

test_input = { "s": "piijciivq" }
assert my_solution.finalString(**test_input) == "pjcvq"

test_input = { "s": "tidtwitik" }
assert my_solution.finalString(**test_input) == "ttdtwk"

test_input = { "s": "z" }
assert my_solution.finalString(**test_input) == "z"

test_input = { "s": "ffyuidnn" }
assert my_solution.finalString(**test_input) == "uyffdnn"

test_input = { "s": "xitiiinix" }
assert my_solution.finalString(**test_input) == "nxtx"

test_input = { "s": "ciiiuifab" }
assert my_solution.finalString(**test_input) == "ucfab"

test_input = { "s": "x" }
assert my_solution.finalString(**test_input) == "x"

test_input = { "s": "v" }
assert my_solution.finalString(**test_input) == "v"

test_input = { "s": "liinii" }
assert my_solution.finalString(**test_input) == "ln"

test_input = { "s": "ziii" }
assert my_solution.finalString(**test_input) == "z"

test_input = { "s": "ei" }
assert my_solution.finalString(**test_input) == "e"

test_input = { "s": "tidiiiii" }
assert my_solution.finalString(**test_input) == "dt"

test_input = { "s": "krjiqjii" }
assert my_solution.finalString(**test_input) == "jrkqj"

test_input = { "s": "mxczii" }
assert my_solution.finalString(**test_input) == "mxcz"

test_input = { "s": "bz" }
assert my_solution.finalString(**test_input) == "bz"

test_input = { "s": "zbwri" }
assert my_solution.finalString(**test_input) == "rwbz"

test_input = { "s": "biiq" }
assert my_solution.finalString(**test_input) == "bq"

test_input = { "s": "mmiiliir" }
assert my_solution.finalString(**test_input) == "mmlr"

test_input = { "s": "plibeici" }
assert my_solution.finalString(**test_input) == "clpbe"

test_input = { "s": "cii" }
assert my_solution.finalString(**test_input) == "c"

test_input = { "s": "wiilg" }
assert my_solution.finalString(**test_input) == "wlg"

test_input = { "s": "cdidi" }
assert my_solution.finalString(**test_input) == "dcd"

test_input = { "s": "fsq" }
assert my_solution.finalString(**test_input) == "fsq"

test_input = { "s": "hkjciaiii" }
assert my_solution.finalString(**test_input) == "ahkjc"

test_input = { "s": "l" }
assert my_solution.finalString(**test_input) == "l"

test_input = { "s": "vilcoizi" }
assert my_solution.finalString(**test_input) == "zvlco"

test_input = { "s": "tgigivipx" }
assert my_solution.finalString(**test_input) == "vgtgpx"

test_input = { "s": "ri" }
assert my_solution.finalString(**test_input) == "r"

test_input = { "s": "kficiiioiy" }
assert my_solution.finalString(**test_input) == "ofkcy"

test_input = { "s": "o" }
assert my_solution.finalString(**test_input) == "o"

test_input = { "s": "piifwiiit" }
assert my_solution.finalString(**test_input) == "wfpt"

test_input = { "s": "sifsiui" }
assert my_solution.finalString(**test_input) == "usfs"

test_input = { "s": "sxiuiiiii" }
assert my_solution.finalString(**test_input) == "usx"

test_input = { "s": "tiiiihiw" }
assert my_solution.finalString(**test_input) == "htw"

test_input = { "s": "ko" }
assert my_solution.finalString(**test_input) == "ko"

test_input = { "s": "gagi" }
assert my_solution.finalString(**test_input) == "gag"

test_input = { "s": "yyigiir" }
assert my_solution.finalString(**test_input) == "yygr"

test_input = { "s": "jimiiaci" }
assert my_solution.finalString(**test_input) == "camj"

test_input = { "s": "xiiiei" }
assert my_solution.finalString(**test_input) == "ex"

test_input = { "s": "hwi" }
assert my_solution.finalString(**test_input) == "wh"

test_input = { "s": "ji" }
assert my_solution.finalString(**test_input) == "j"

test_input = { "s": "heii" }
assert my_solution.finalString(**test_input) == "he"

test_input = { "s": "zitjcq" }
assert my_solution.finalString(**test_input) == "ztjcq"

test_input = { "s": "upmipaw" }
assert my_solution.finalString(**test_input) == "mpupaw"

test_input = { "s": "fiixkgp" }
assert my_solution.finalString(**test_input) == "fxkgp"

test_input = { "s": "ldr" }
assert my_solution.finalString(**test_input) == "ldr"

test_input = { "s": "kiboiithi" }
assert my_solution.finalString(**test_input) == "htobk"

test_input = { "s": "svcii" }
assert my_solution.finalString(**test_input) == "svc"

test_input = { "s": "d" }
assert my_solution.finalString(**test_input) == "d"

test_input = { "s": "edgijwiua" }
assert my_solution.finalString(**test_input) == "wjedgua"

test_input = { "s": "wiidqoiwov" }
assert my_solution.finalString(**test_input) == "oqdwwov"

test_input = { "s": "zimxiiqqi" }
assert my_solution.finalString(**test_input) == "qqxmz"

test_input = { "s": "githpgiini" }
assert my_solution.finalString(**test_input) == "ngphtg"

test_input = { "s": "fy" }
assert my_solution.finalString(**test_input) == "fy"

test_input = { "s": "hesi" }
assert my_solution.finalString(**test_input) == "seh"

test_input = { "s": "eiiii" }
assert my_solution.finalString(**test_input) == "e"

test_input = { "s": "be" }
assert my_solution.finalString(**test_input) == "be"

test_input = { "s": "rpi" }
assert my_solution.finalString(**test_input) == "pr"

test_input = { "s": "mi" }
assert my_solution.finalString(**test_input) == "m"

test_input = { "s": "wiiiiii" }
assert my_solution.finalString(**test_input) == "w"

test_input = { "s": "rbiiiii" }
assert my_solution.finalString(**test_input) == "br"

test_input = { "s": "diiii" }
assert my_solution.finalString(**test_input) == "d"

test_input = { "s": "poiiifl" }
assert my_solution.finalString(**test_input) == "opfl"

test_input = { "s": "loifiicii" }
assert my_solution.finalString(**test_input) == "olfc"

test_input = { "s": "bii" }
assert my_solution.finalString(**test_input) == "b"

test_input = { "s": "nirii" }
assert my_solution.finalString(**test_input) == "nr"

test_input = { "s": "wiigipio" }
assert my_solution.finalString(**test_input) == "pwgo"

test_input = { "s": "gimliibin" }
assert my_solution.finalString(**test_input) == "blmgn"

test_input = { "s": "zi" }
assert my_solution.finalString(**test_input) == "z"

test_input = { "s": "tjn" }
assert my_solution.finalString(**test_input) == "tjn"

test_input = { "s": "ly" }
assert my_solution.finalString(**test_input) == "ly"

test_input = { "s": "sqzviyiimi" }
assert my_solution.finalString(**test_input) == "mysqzv"

test_input = { "s": "jhmaxm" }
assert my_solution.finalString(**test_input) == "jhmaxm"

test_input = { "s": "py" }
assert my_solution.finalString(**test_input) == "py"

test_input = { "s": "yyilwiib" }
assert my_solution.finalString(**test_input) == "yylwb"

test_input = { "s": "ryjiilj" }
assert my_solution.finalString(**test_input) == "ryjlj"

test_input = { "s": "tnokpgfii" }
assert my_solution.finalString(**test_input) == "tnokpgf"

test_input = { "s": "niihiliiv" }
assert my_solution.finalString(**test_input) == "hnlv"

test_input = { "s": "gvhms" }
assert my_solution.finalString(**test_input) == "gvhms"

test_input = { "s": "yg" }
assert my_solution.finalString(**test_input) == "yg"

test_input = { "s": "eiiiuizgi" }
assert my_solution.finalString(**test_input) == "gzeu"


check-if-it-is-possible-to-split-array

Check if it is Possible to Split Array

Prompt:
"""
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
"""
class Solution:
    def canSplitArray(self, nums: List[int], m: int) -> bool:

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 complete the code below to solve above prblem:
```python
class Solution:
    def canSplitArray(self, nums: List[int], m: int) -> bool:

```

my_solution = Solution()

test_input = { "nums": [2, 2, 1], "m": 4 }
assert my_solution.canSplitArray(**test_input) == True

test_input = { "nums": [2, 3, 3, 2, 3], "m": 6 }
assert my_solution.canSplitArray(**test_input) == True

test_input = { "nums": [1], "m": 1 }
assert my_solution.canSplitArray(**test_input) == True

test_input = { "nums": [2, 1, 3], "m": 5 }
assert my_solution.canSplitArray(**test_input) == False

test_input = { "nums": [1, 1, 1], "m": 3 }
assert my_solution.canSplitArray(**test_input) == False

test_input = { "nums": [2], "m": 1 }
assert my_solution.canSplitArray(**test_input) == True

test_input = { "nums": [2, 1, 2], "m": 4 }
assert my_solution.canSplitArray(**test_input) == False

test_input = { "nums": [1, 2, 1], "m": 5 }
assert my_solution.canSplitArray(**test_input) == False

test_input = { "nums": [2, 2, 2], "m": 5 }
assert my_solution.canSplitArray(**test_input) == False

test_input = { "nums": [3, 1, 2], "m": 5 }
assert my_solution.canSplitArray(**test_input) == False

test_input = { "nums": [3], "m": 1 }
assert my_solution.canSplitArray(**test_input) == True

test_input = { "nums": [1], "m": 2 }
assert my_solution.canSplitArray(**test_input) == True

test_input = { "nums": [2], "m": 2 }
assert my_solution.canSplitArray(**test_input) == True

test_input = { "nums": [1, 3, 1], "m": 6 }
assert my_solution.canSplitArray(**test_input) == False

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

test_input = { "nums": [2, 1, 1], "m": 6 }
assert my_solution.canSplitArray(**test_input) == False

test_input = { "nums": [2, 2, 1], "m": 6 }
assert my_solution.canSplitArray(**test_input) == False

test_input = { "nums": [2, 2, 3], "m": 6 }
assert my_solution.canSplitArray(**test_input) == False

test_input = { "nums": [3], "m": 2 }
assert my_solution.canSplitArray(**test_input) == True

test_input = { "nums": [3, 1, 1], "m": 6 }
assert my_solution.canSplitArray(**test_input) == False

test_input = { "nums": [3, 1, 3], "m": 6 }
assert my_solution.canSplitArray(**test_input) == False

test_input = { "nums": [3], "m": 3 }
assert my_solution.canSplitArray(**test_input) == True

test_input = { "nums": [7], "m": 5 }
assert my_solution.canSplitArray(**test_input) == True

test_input = { "nums": [4], "m": 7 }
assert my_solution.canSplitArray(**test_input) == True

test_input = { "nums": [9], "m": 7 }
assert my_solution.canSplitArray(**test_input) == True

test_input = { "nums": [2], "m": 8 }
assert my_solution.canSplitArray(**test_input) == True

test_input = { "nums": [3, 2, 2], "m": 6 }
assert my_solution.canSplitArray(**test_input) == False

test_input = { "nums": [4], "m": 8 }
assert my_solution.canSplitArray(**test_input) == True

test_input = { "nums": [10], "m": 11 }
assert my_solution.canSplitArray(**test_input) == True

test_input = { "nums": [6], "m": 12 }
assert my_solution.canSplitArray(**test_input) == True

test_input = { "nums": [3, 2, 3], "m": 6 }
assert my_solution.canSplitArray(**test_input) == False

test_input = { "nums": [3, 3, 6], "m": 10 }
assert my_solution.canSplitArray(**test_input) == False

test_input = { "nums": [2], "m": 14 }
assert my_solution.canSplitArray(**test_input) == True

test_input = { "nums": [5, 3, 6], "m": 10 }
assert my_solution.canSplitArray(**test_input) == False

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

test_input = { "nums": [4, 6, 5], "m": 12 }
assert my_solution.canSplitArray(**test_input) == False

test_input = { "nums": [9, 7], "m": 1 }
assert my_solution.canSplitArray(**test_input) == True

test_input = { "nums": [1, 2], "m": 2 }
assert my_solution.canSplitArray(**test_input) == True

test_input = { "nums": [9, 1, 7], "m": 14 }
assert my_solution.canSplitArray(**test_input) == False

test_input = { "nums": [8, 2, 4], "m": 16 }
assert my_solution.canSplitArray(**test_input) == False

test_input = { "nums": [1, 3], "m": 2 }
assert my_solution.canSplitArray(**test_input) == True

test_input = { "nums": [2, 1], "m": 2 }
assert my_solution.canSplitArray(**test_input) == True

test_input = { "nums": [9, 5, 7], "m": 20 }
assert my_solution.canSplitArray(**test_input) == False

test_input = { "nums": [2, 3], "m": 2 }
assert my_solution.canSplitArray(**test_input) == True

test_input = { "nums": [1, 2, 1, 1], "m": 4 }
assert my_solution.canSplitArray(**test_input) == False

test_input = { "nums": [1, 2, 2, 5], "m": 8 }
assert my_solution.canSplitArray(**test_input) == False

test_input = { "nums": [4, 4, 4, 2], "m": 9 }
assert my_solution.canSplitArray(**test_input) == False

test_input = { "nums": [3, 2], "m": 2 }
assert my_solution.canSplitArray(**test_input) == True

test_input = { "nums": [8, 1, 2, 5], "m": 10 }
assert my_solution.canSplitArray(**test_input) == False

test_input = { "nums": [10, 2, 9, 3], "m": 14 }
assert my_solution.canSplitArray(**test_input) == False

test_input = { "nums": [3, 3], "m": 2 }
assert my_solution.canSplitArray(**test_input) == True

test_input = { "nums": [10, 4, 8, 6], "m": 16 }
assert my_solution.canSplitArray(**test_input) == False

test_input = { "nums": [14, 1, 1, 15], "m": 17 }
assert my_solution.canSplitArray(**test_input) == False

test_input = { "nums": [6, 11, 2, 12], "m": 18 }
assert my_solution.canSplitArray(**test_input) == False

test_input = { "nums": [14, 3, 12, 3], "m": 18 }
assert my_solution.canSplitArray(**test_input) == False

test_input = { "nums": [1, 1], "m": 3 }
assert my_solution.canSplitArray(**test_input) == True

test_input = { "nums": [1, 2], "m": 3 }
assert my_solution.canSplitArray(**test_input) == True

test_input = { "nums": [1, 1, 2, 2, 1], "m": 5 }
assert my_solution.canSplitArray(**test_input) == False

test_input = { "nums": [2, 2, 1, 3, 1], "m": 5 }
assert my_solution.canSplitArray(**test_input) == False

test_input = { "nums": [1, 3], "m": 3 }
assert my_solution.canSplitArray(**test_input) == True

test_input = { "nums": [3, 1, 1, 3, 1], "m": 5 }
assert my_solution.canSplitArray(**test_input) == False

test_input = { "nums": [2, 2], "m": 3 }
assert my_solution.canSplitArray(**test_input) == True

test_input = { "nums": [2, 3], "m": 3 }
assert my_solution.canSplitArray(**test_input) == True

test_input = { "nums": [2, 10], "m": 3 }
assert my_solution.canSplitArray(**test_input) == True

test_input = { "nums": [3, 1], "m": 3 }
assert my_solution.canSplitArray(**test_input) == True

test_input = { "nums": [3, 3], "m": 3 }
assert my_solution.canSplitArray(**test_input) == True

test_input = { "nums": [7, 9], "m": 3 }
assert my_solution.canSplitArray(**test_input) == True

test_input = { "nums": [3, 3, 1, 5, 1], "m": 7 }
assert my_solution.canSplitArray(**test_input) == False

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

test_input = { "nums": [2, 9, 2, 3, 2], "m": 12 }
assert my_solution.canSplitArray(**test_input) == False

test_input = { "nums": [1, 3], "m": 4 }
assert my_solution.canSplitArray(**test_input) == True

test_input = { "nums": [2, 2], "m": 4 }
assert my_solution.canSplitArray(**test_input) == True

test_input = { "nums": [4, 4, 4, 7, 5], "m": 13 }
assert my_solution.canSplitArray(**test_input) == False

test_input = { "nums": [5, 2, 6, 5, 4], "m": 13 }
assert my_solution.canSplitArray(**test_input) == False

test_input = { "nums": [2, 3], "m": 4 }
assert my_solution.canSplitArray(**test_input) == True

test_input = { "nums": [3, 1], "m": 4 }
assert my_solution.canSplitArray(**test_input) == True

test_input = { "nums": [13, 2, 13, 4, 11], "m": 18 }
assert my_solution.canSplitArray(**test_input) == False

test_input = { "nums": [5, 6, 10, 7, 4], "m": 19 }
assert my_solution.canSplitArray(**test_input) == False

test_input = { "nums": [16, 1, 12, 6, 7], "m": 19 }
assert my_solution.canSplitArray(**test_input) == False

test_input = { "nums": [3, 3], "m": 4 }
assert my_solution.canSplitArray(**test_input) == True

test_input = { "nums": [9, 9, 8, 10, 8], "m": 20 }
assert my_solution.canSplitArray(**test_input) == False

test_input = { "nums": [9, 4], "m": 5 }
assert my_solution.canSplitArray(**test_input) == True

test_input = { "nums": [10, 2], "m": 5 }
assert my_solution.canSplitArray(**test_input) == True

test_input = { "nums": [16, 2, 2, 16, 2], "m": 20 }
assert my_solution.canSplitArray(**test_input) == False

test_input = { "nums": [6, 2], "m": 7 }
assert my_solution.canSplitArray(**test_input) == True

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

test_input = { "nums": [5, 1], "m": 8 }
assert my_solution.canSplitArray(**test_input) == True

test_input = { "nums": [1, 4, 4, 2, 1, 5], "m": 9 }
assert my_solution.canSplitArray(**test_input) == False

test_input = { "nums": [2, 5], "m": 12 }
assert my_solution.canSplitArray(**test_input) == True

test_input = { "nums": [10, 9], "m": 15 }
assert my_solution.canSplitArray(**test_input) == True

test_input = { "nums": [8, 4], "m": 18 }
assert my_solution.canSplitArray(**test_input) == True

test_input = { "nums": [3, 4, 3, 5, 2, 1], "m": 9 }
assert my_solution.canSplitArray(**test_input) == False

test_input = { "nums": [3, 7, 2, 8, 2, 4], "m": 11 }
assert my_solution.canSplitArray(**test_input) == False

test_input = { "nums": [8, 1], "m": 19 }
assert my_solution.canSplitArray(**test_input) == True

test_input = { "nums": [1, 1, 2], "m": 3 }
assert my_solution.canSplitArray(**test_input) == True

test_input = { "nums": [5, 1, 1, 9, 1, 5], "m": 11 }
assert my_solution.canSplitArray(**test_input) == False

test_input = { "nums": [1, 1, 3], "m": 3 }
assert my_solution.canSplitArray(**test_input) == True

test_input = { "nums": [6, 4, 7, 2, 5, 4], "m": 12 }
assert my_solution.canSplitArray(**test_input) == False

test_input = { "nums": [1, 2, 1], "m": 3 }
assert my_solution.canSplitArray(**test_input) == True

test_input = { "nums": [1, 3, 1], "m": 3 }
assert my_solution.canSplitArray(**test_input) == True


find-the-safest-path-in-a-grid

Find the Safest Path in a Grid

Prompt:
"""
You are given a 0-indexed 2D matrix grid of size n x n, where (r, c) represents:

 * A cell containing a thief if grid[r][c] = 1
 * An empty cell if grid[r][c] = 0

You are initially positioned at cell (0, 0). In one move, you can move to any adjacent cell in the grid, including cells containing thieves.

The safeness factor of a path on the grid is defined as the minimum manhattan distance from any cell in the path to any thief in the grid.

Return the maximum safeness factor of all paths leading to cell (n - 1, n - 1).

An adjacent cell of cell (r, c), is one of the cells (r, c + 1), (r, c - 1), (r + 1, c) and (r - 1, c) if it exists.

The Manhattan distance between two cells (a, b) and (x, y) is equal to |a - x| + |b - y|, where |val| denotes the absolute value of val.

Example 1:

[https://assets.leetcode.com/uploads/2023/07/02/example1.png]

Input: grid = [[1,0,0],[0,0,0],[0,0,1]]
Output: 0
Explanation: All paths from (0, 0) to (n - 1, n - 1) go through the thieves in cells (0, 0) and (n - 1, n - 1).

Example 2:

[https://assets.leetcode.com/uploads/2023/07/02/example2.png]

Input: grid = [[0,0,1],[0,0,0],[0,0,0]]
Output: 2
Explanation: The path depicted in the picture above has a safeness factor of 2 since:
- The closest cell of the path to the thief at cell (0, 2) is cell (0, 0). The distance between them is | 0 - 0 | + | 0 - 2 | = 2.
It can be shown that there are no other paths with a higher safeness factor.

Example 3:

[https://assets.leetcode.com/uploads/2023/07/02/example3.png]

Input: grid = [[0,0,0,1],[0,0,0,0],[0,0,0,0],[1,0,0,0]]
Output: 2
Explanation: The path depicted in the picture above has a safeness factor of 2 since:
- The closest cell of the path to the thief at cell (0, 3) is cell (1, 2). The distance between them is | 0 - 1 | + | 3 - 2 | = 2.
- The closest cell of the path to the thief at cell (3, 0) is cell (3, 2). The distance between them is | 3 - 3 | + | 0 - 2 | = 2.
It can be shown that there are no other paths with a higher safeness factor.

Constraints:

 * 1 <= grid.length == n <= 400
 * grid[i].length == n
 * grid[i][j] is either 0 or 1.
 * There is at least one thief in the grid.
"""
class Solution:
    def maximumSafenessFactor(self, grid: List[List[int]]) -> int:

You are given a 0-indexed 2D matrix grid of size n x n, where (r, c) represents:

 * A cell containing a thief if grid[r][c] = 1
 * An empty cell if grid[r][c] = 0

You are initially positioned at cell (0, 0). In one move, you can move to any adjacent cell in the grid, including cells containing thieves.

The safeness factor of a path on the grid is defined as the minimum manhattan distance from any cell in the path to any thief in the grid.

Return the maximum safeness factor of all paths leading to cell (n - 1, n - 1).

An adjacent cell of cell (r, c), is one of the cells (r, c + 1), (r, c - 1), (r + 1, c) and (r - 1, c) if it exists.

The Manhattan distance between two cells (a, b) and (x, y) is equal to |a - x| + |b - y|, where |val| denotes the absolute value of val.

Example 1:

[https://assets.leetcode.com/uploads/2023/07/02/example1.png]

Input: grid = [[1,0,0],[0,0,0],[0,0,1]]
Output: 0
Explanation: All paths from (0, 0) to (n - 1, n - 1) go through the thieves in cells (0, 0) and (n - 1, n - 1).

Example 2:

[https://assets.leetcode.com/uploads/2023/07/02/example2.png]

Input: grid = [[0,0,1],[0,0,0],[0,0,0]]
Output: 2
Explanation: The path depicted in the picture above has a safeness factor of 2 since:
- The closest cell of the path to the thief at cell (0, 2) is cell (0, 0). The distance between them is | 0 - 0 | + | 0 - 2 | = 2.
It can be shown that there are no other paths with a higher safeness factor.

Example 3:

[https://assets.leetcode.com/uploads/2023/07/02/example3.png]

Input: grid = [[0,0,0,1],[0,0,0,0],[0,0,0,0],[1,0,0,0]]
Output: 2
Explanation: The path depicted in the picture above has a safeness factor of 2 since:
- The closest cell of the path to the thief at cell (0, 3) is cell (1, 2). The distance between them is | 0 - 1 | + | 3 - 2 | = 2.
- The closest cell of the path to the thief at cell (3, 0) is cell (3, 2). The distance between them is | 3 - 3 | + | 0 - 2 | = 2.
It can be shown that there are no other paths with a higher safeness factor.

Constraints:

 * 1 <= grid.length == n <= 400
 * grid[i].length == n
 * grid[i][j] is either 0 or 1.
 * There is at least one thief in the grid.

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

```

my_solution = Solution()

test_input = { "grid": [[1,0,0],[0,0,0],[0,0,1]] }
assert my_solution.maximumSafenessFactor(**test_input) == 0

test_input = { "grid": [[0,0,1],[0,0,0],[0,0,0]] }
assert my_solution.maximumSafenessFactor(**test_input) == 2

test_input = { "grid": [[0,0,0,1],[0,0,0,0],[0,0,0,0],[1,0,0,0]] }
assert my_solution.maximumSafenessFactor(**test_input) == 2

test_input = { "grid": [[1]] }
assert my_solution.maximumSafenessFactor(**test_input) == 0

test_input = { "grid": [[1,1],[1,1]] }
assert my_solution.maximumSafenessFactor(**test_input) == 0

test_input = { "grid": [[1,1,1],[1,1,1],[1,1,1]] }
assert my_solution.maximumSafenessFactor(**test_input) == 0

test_input = { "grid": [[1,1,1],[1,1,1],[1,1,0]] }
assert my_solution.maximumSafenessFactor(**test_input) == 0

test_input = { "grid": [[1,1,1],[1,1,1],[1,0,1]] }
assert my_solution.maximumSafenessFactor(**test_input) == 0

test_input = { "grid": [[1,1,1],[1,1,1],[1,0,0]] }
assert my_solution.maximumSafenessFactor(**test_input) == 0

test_input = { "grid": [[1,1,1],[1,1,1],[0,1,1]] }
assert my_solution.maximumSafenessFactor(**test_input) == 0

test_input = { "grid": [[1,1,1],[1,1,1],[0,1,0]] }
assert my_solution.maximumSafenessFactor(**test_input) == 0

test_input = { "grid": [[1,1,1],[1,1,1],[0,0,1]] }
assert my_solution.maximumSafenessFactor(**test_input) == 0

test_input = { "grid": [[1,1,1],[1,1,1],[0,0,0]] }
assert my_solution.maximumSafenessFactor(**test_input) == 0

test_input = { "grid": [[1,1,1],[1,1,0],[1,1,1]] }
assert my_solution.maximumSafenessFactor(**test_input) == 0

test_input = { "grid": [[1,1,1],[1,1,0],[1,1,0]] }
assert my_solution.maximumSafenessFactor(**test_input) == 0

test_input = { "grid": [[1,1,1],[1,1,0],[1,0,1]] }
assert my_solution.maximumSafenessFactor(**test_input) == 0

test_input = { "grid": [[1,1,1],[1,1,0],[1,0,0]] }
assert my_solution.maximumSafenessFactor(**test_input) == 0

test_input = { "grid": [[1,1,1],[1,1,0],[0,1,1]] }
assert my_solution.maximumSafenessFactor(**test_input) == 0

test_input = { "grid": [[1,1,1],[1,1,0],[0,1,0]] }
assert my_solution.maximumSafenessFactor(**test_input) == 0

test_input = { "grid": [[1,1,1],[1,1,0],[0,0,1]] }
assert my_solution.maximumSafenessFactor(**test_input) == 0

test_input = { "grid": [[1,1,1],[1,1,0],[0,0,0]] }
assert my_solution.maximumSafenessFactor(**test_input) == 0

test_input = { "grid": [[1,1,1],[1,0,1],[1,1,1]] }
assert my_solution.maximumSafenessFactor(**test_input) == 0

test_input = { "grid": [[1,1,1],[1,0,1],[1,1,0]] }
assert my_solution.maximumSafenessFactor(**test_input) == 0

test_input = { "grid": [[1,1,1],[1,0,1],[1,0,1]] }
assert my_solution.maximumSafenessFactor(**test_input) == 0

test_input = { "grid": [[1,1,1],[1,0,1],[1,0,0]] }
assert my_solution.maximumSafenessFactor(**test_input) == 0

test_input = { "grid": [[1,1,1],[1,0,1],[0,1,1]] }
assert my_solution.maximumSafenessFactor(**test_input) == 0

test_input = { "grid": [[1,1,1],[1,0,1],[0,1,0]] }
assert my_solution.maximumSafenessFactor(**test_input) == 0

test_input = { "grid": [[1,1,1],[1,0,1],[0,0,1]] }
assert my_solution.maximumSafenessFactor(**test_input) == 0

test_input = { "grid": [[1,1,1],[1,0,1],[0,0,0]] }
assert my_solution.maximumSafenessFactor(**test_input) == 0

test_input = { "grid": [[1,1,1],[1,0,0],[1,1,1]] }
assert my_solution.maximumSafenessFactor(**test_input) == 0

test_input = { "grid": [[1,1,1],[1,0,0],[1,1,0]] }
assert my_solution.maximumSafenessFactor(**test_input) == 0

test_input = { "grid": [[1,1,1],[1,0,0],[1,0,1]] }
assert my_solution.maximumSafenessFactor(**test_input) == 0

test_input = { "grid": [[1,1,1],[1,0,0],[1,0,0]] }
assert my_solution.maximumSafenessFactor(**test_input) == 0

test_input = { "grid": [[1,1,1],[1,0,0],[0,1,1]] }
assert my_solution.maximumSafenessFactor(**test_input) == 0

test_input = { "grid": [[1,1,1],[1,0,0],[0,1,0]] }
assert my_solution.maximumSafenessFactor(**test_input) == 0

test_input = { "grid": [[1,1,1],[1,0,0],[0,0,1]] }
assert my_solution.maximumSafenessFactor(**test_input) == 0

test_input = { "grid": [[1,1,1],[1,0,0],[0,0,0]] }
assert my_solution.maximumSafenessFactor(**test_input) == 0

test_input = { "grid": [[1,1],[1,0]] }
assert my_solution.maximumSafenessFactor(**test_input) == 0

test_input = { "grid": [[1,1,1],[0,1,1],[1,1,1]] }
assert my_solution.maximumSafenessFactor(**test_input) == 0

test_input = { "grid": [[1,1,1],[0,1,1],[1,1,0]] }
assert my_solution.maximumSafenessFactor(**test_input) == 0

test_input = { "grid": [[1,1,1],[0,1,1],[1,0,1]] }
assert my_solution.maximumSafenessFactor(**test_input) == 0

test_input = { "grid": [[1,1,1],[0,1,1],[1,0,0]] }
assert my_solution.maximumSafenessFactor(**test_input) == 0

test_input = { "grid": [[1,1,1],[0,1,1],[0,1,1]] }
assert my_solution.maximumSafenessFactor(**test_input) == 0

test_input = { "grid": [[1,1,1],[0,1,1],[0,1,0]] }
assert my_solution.maximumSafenessFactor(**test_input) == 0

test_input = { "grid": [[1,1,1],[0,1,1],[0,0,1]] }
assert my_solution.maximumSafenessFactor(**test_input) == 0

test_input = { "grid": [[1,1,1],[0,1,1],[0,0,0]] }
assert my_solution.maximumSafenessFactor(**test_input) == 0

test_input = { "grid": [[1,1,1],[0,1,0],[1,1,1]] }
assert my_solution.maximumSafenessFactor(**test_input) == 0

test_input = { "grid": [[1,1,1],[0,1,0],[1,1,0]] }
assert my_solution.maximumSafenessFactor(**test_input) == 0

test_input = { "grid": [[1,1,1],[0,1,0],[1,0,1]] }
assert my_solution.maximumSafenessFactor(**test_input) == 0

test_input = { "grid": [[1,1,1],[0,1,0],[1,0,0]] }
assert my_solution.maximumSafenessFactor(**test_input) == 0

test_input = { "grid": [[1,1,1],[0,1,0],[0,1,1]] }
assert my_solution.maximumSafenessFactor(**test_input) == 0

test_input = { "grid": [[1,1,1],[0,1,0],[0,1,0]] }
assert my_solution.maximumSafenessFactor(**test_input) == 0

test_input = { "grid": [[1,1,1],[0,1,0],[0,0,1]] }
assert my_solution.maximumSafenessFactor(**test_input) == 0

test_input = { "grid": [[1,1,1],[0,1,0],[0,0,0]] }
assert my_solution.maximumSafenessFactor(**test_input) == 0

test_input = { "grid": [[1,1,1],[0,0,1],[1,1,1]] }
assert my_solution.maximumSafenessFactor(**test_input) == 0

test_input = { "grid": [[1,1,1],[0,0,1],[1,1,0]] }
assert my_solution.maximumSafenessFactor(**test_input) == 0

test_input = { "grid": [[1,1,1],[0,0,1],[1,0,1]] }
assert my_solution.maximumSafenessFactor(**test_input) == 0

test_input = { "grid": [[1,1,1],[0,0,1],[1,0,0]] }
assert my_solution.maximumSafenessFactor(**test_input) == 0

test_input = { "grid": [[1,1,1],[0,0,1],[0,1,1]] }
assert my_solution.maximumSafenessFactor(**test_input) == 0

test_input = { "grid": [[1,1,1],[0,0,1],[0,1,0]] }
assert my_solution.maximumSafenessFactor(**test_input) == 0

test_input = { "grid": [[1,1,1],[0,0,1],[0,0,1]] }
assert my_solution.maximumSafenessFactor(**test_input) == 0

test_input = { "grid": [[1,1,1],[0,0,1],[0,0,0]] }
assert my_solution.maximumSafenessFactor(**test_input) == 0

test_input = { "grid": [[1,1,1],[0,0,0],[1,1,1]] }
assert my_solution.maximumSafenessFactor(**test_input) == 0

test_input = { "grid": [[1,1,1],[0,0,0],[1,1,0]] }
assert my_solution.maximumSafenessFactor(**test_input) == 0

test_input = { "grid": [[1,1,1],[0,0,0],[1,0,1]] }
assert my_solution.maximumSafenessFactor(**test_input) == 0

test_input = { "grid": [[1,1,1],[0,0,0],[1,0,0]] }
assert my_solution.maximumSafenessFactor(**test_input) == 0

test_input = { "grid": [[1,1,1],[0,0,0],[0,1,1]] }
assert my_solution.maximumSafenessFactor(**test_input) == 0

test_input = { "grid": [[1,1,1],[0,0,0],[0,1,0]] }
assert my_solution.maximumSafenessFactor(**test_input) == 0

test_input = { "grid": [[1,1,1],[0,0,0],[0,0,1]] }
assert my_solution.maximumSafenessFactor(**test_input) == 0

test_input = { "grid": [[1,1,1],[0,0,0],[0,0,0]] }
assert my_solution.maximumSafenessFactor(**test_input) == 0

test_input = { "grid": [[1,1],[0,1]] }
assert my_solution.maximumSafenessFactor(**test_input) == 0

test_input = { "grid": [[1,1,0],[1,1,1],[1,1,1]] }
assert my_solution.maximumSafenessFactor(**test_input) == 0

test_input = { "grid": [[1,1,0],[1,1,1],[1,1,0]] }
assert my_solution.maximumSafenessFactor(**test_input) == 0

test_input = { "grid": [[1,1,0],[1,1,1],[1,0,1]] }
assert my_solution.maximumSafenessFactor(**test_input) == 0

test_input = { "grid": [[1,1,0],[1,1,1],[1,0,0]] }
assert my_solution.maximumSafenessFactor(**test_input) == 0

test_input = { "grid": [[1,1,0],[1,1,1],[0,1,1]] }
assert my_solution.maximumSafenessFactor(**test_input) == 0

test_input = { "grid": [[1,1,0],[1,1,1],[0,1,0]] }
assert my_solution.maximumSafenessFactor(**test_input) == 0

test_input = { "grid": [[1,1,0],[1,1,1],[0,0,1]] }
assert my_solution.maximumSafenessFactor(**test_input) == 0

test_input = { "grid": [[1,1,0],[1,1,1],[0,0,0]] }
assert my_solution.maximumSafenessFactor(**test_input) == 0

test_input = { "grid": [[1,1,0],[1,1,0],[1,1,1]] }
assert my_solution.maximumSafenessFactor(**test_input) == 0

test_input = { "grid": [[1,1,0],[1,1,0],[1,1,0]] }
assert my_solution.maximumSafenessFactor(**test_input) == 0

test_input = { "grid": [[1,1,0],[1,1,0],[1,0,1]] }
assert my_solution.maximumSafenessFactor(**test_input) == 0

test_input = { "grid": [[1,1,0],[1,1,0],[1,0,0]] }
assert my_solution.maximumSafenessFactor(**test_input) == 0

test_input = { "grid": [[1,1,0],[1,1,0],[0,1,1]] }
assert my_solution.maximumSafenessFactor(**test_input) == 0

test_input = { "grid": [[1,1,0],[1,1,0],[0,1,0]] }
assert my_solution.maximumSafenessFactor(**test_input) == 0

test_input = { "grid": [[1,1,0],[1,1,0],[0,0,1]] }
assert my_solution.maximumSafenessFactor(**test_input) == 0

test_input = { "grid": [[1,1,0],[1,1,0],[0,0,0]] }
assert my_solution.maximumSafenessFactor(**test_input) == 0

test_input = { "grid": [[1,1,0],[1,0,1],[1,1,1]] }
assert my_solution.maximumSafenessFactor(**test_input) == 0

test_input = { "grid": [[1,1,0],[1,0,1],[1,1,0]] }
assert my_solution.maximumSafenessFactor(**test_input) == 0

test_input = { "grid": [[1,1,0],[1,0,1],[1,0,1]] }
assert my_solution.maximumSafenessFactor(**test_input) == 0

test_input = { "grid": [[1,1,0],[1,0,1],[1,0,0]] }
assert my_solution.maximumSafenessFactor(**test_input) == 0

test_input = { "grid": [[1,1,0],[1,0,1],[0,1,1]] }
assert my_solution.maximumSafenessFactor(**test_input) == 0

test_input = { "grid": [[1,1,0],[1,0,1],[0,1,0]] }
assert my_solution.maximumSafenessFactor(**test_input) == 0

test_input = { "grid": [[1,1,0],[1,0,1],[0,0,1]] }
assert my_solution.maximumSafenessFactor(**test_input) == 0

test_input = { "grid": [[1,1,0],[1,0,1],[0,0,0]] }
assert my_solution.maximumSafenessFactor(**test_input) == 0

test_input = { "grid": [[1,1,0],[1,0,0],[1,1,1]] }
assert my_solution.maximumSafenessFactor(**test_input) == 0

test_input = { "grid": [[1,1,0],[1,0,0],[1,1,0]] }
assert my_solution.maximumSafenessFactor(**test_input) == 0

test_input = { "grid": [[1,1,0],[1,0,0],[1,0,1]] }
assert my_solution.maximumSafenessFactor(**test_input) == 0

test_input = { "grid": [[1,1,0],[1,0,0],[1,0,0]] }
assert my_solution.maximumSafenessFactor(**test_input) == 0

test_input = { "grid": [[1,1,0],[1,0,0],[0,1,1]] }
assert my_solution.maximumSafenessFactor(**test_input) == 0


maximum-elegance-of-a-k-length-subsequence

Maximum Elegance of a K-Length Subsequence

Prompt:
"""
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
"""
class Solution:
    def findMaximumElegance(self, items: List[List[int]], k: int) -> int:

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 complete the code below to solve above prblem:
```python
class Solution:
    def findMaximumElegance(self, items: List[List[int]], k: int) -> int:

```

my_solution = Solution()

test_input = { "items": [[3,2],[5,1],[10,1]], "k": 2 }
assert my_solution.findMaximumElegance(**test_input) == 17

test_input = { "items": [[3,1],[3,1],[2,2],[5,3]], "k": 3 }
assert my_solution.findMaximumElegance(**test_input) == 19

test_input = { "items": [[1,1],[2,1],[3,1]], "k": 3 }
assert my_solution.findMaximumElegance(**test_input) == 7

test_input = { "items": [[1,1],[1,2]], "k": 2 }
assert my_solution.findMaximumElegance(**test_input) == 6

test_input = { "items": [[1,1],[4,1]], "k": 1 }
assert my_solution.findMaximumElegance(**test_input) == 5

test_input = { "items": [[1,1],[4,1]], "k": 2 }
assert my_solution.findMaximumElegance(**test_input) == 6

test_input = { "items": [[1,1],[6,1]], "k": 1 }
assert my_solution.findMaximumElegance(**test_input) == 7

test_input = { "items": [[1,1],[6,1]], "k": 2 }
assert my_solution.findMaximumElegance(**test_input) == 8

test_input = { "items": [[1,1],[8,2]], "k": 2 }
assert my_solution.findMaximumElegance(**test_input) == 13

test_input = { "items": [[1,2],[6,2]], "k": 1 }
assert my_solution.findMaximumElegance(**test_input) == 7

test_input = { "items": [[1,2],[10,1]], "k": 1 }
assert my_solution.findMaximumElegance(**test_input) == 11

test_input = { "items": [[2,1],[6,1]], "k": 2 }
assert my_solution.findMaximumElegance(**test_input) == 9

test_input = { "items": [[2,1],[7,1]], "k": 2 }
assert my_solution.findMaximumElegance(**test_input) == 10

test_input = { "items": [[2,1],[9,2]], "k": 1 }
assert my_solution.findMaximumElegance(**test_input) == 10

test_input = { "items": [[2,2],[2,2]], "k": 1 }
assert my_solution.findMaximumElegance(**test_input) == 3

test_input = { "items": [[2,2],[2,2]], "k": 2 }
assert my_solution.findMaximumElegance(**test_input) == 5

test_input = { "items": [[2,2],[3,1]], "k": 2 }
assert my_solution.findMaximumElegance(**test_input) == 9

test_input = { "items": [[2,2],[6,1]], "k": 2 }
assert my_solution.findMaximumElegance(**test_input) == 12

test_input = { "items": [[3,1],[1,2]], "k": 2 }
assert my_solution.findMaximumElegance(**test_input) == 8

test_input = { "items": [[3,1],[9,1]], "k": 2 }
assert my_solution.findMaximumElegance(**test_input) == 13

test_input = { "items": [[3,1],[9,2]], "k": 1 }
assert my_solution.findMaximumElegance(**test_input) == 10

test_input = { "items": [[3,1],[10,2]], "k": 2 }
assert my_solution.findMaximumElegance(**test_input) == 17

test_input = { "items": [[3,2],[3,1]], "k": 1 }
assert my_solution.findMaximumElegance(**test_input) == 4

test_input = { "items": [[3,2],[5,2]], "k": 1 }
assert my_solution.findMaximumElegance(**test_input) == 6

test_input = { "items": [[3,2],[10,1]], "k": 2 }
assert my_solution.findMaximumElegance(**test_input) == 17

test_input = { "items": [[3,2],[10,2]], "k": 2 }
assert my_solution.findMaximumElegance(**test_input) == 14

test_input = { "items": [[4,1],[7,2]], "k": 2 }
assert my_solution.findMaximumElegance(**test_input) == 15

test_input = { "items": [[4,1],[9,2]], "k": 1 }
assert my_solution.findMaximumElegance(**test_input) == 10

test_input = { "items": [[4,2],[2,1]], "k": 2 }
assert my_solution.findMaximumElegance(**test_input) == 10

test_input = { "items": [[4,2],[3,1]], "k": 2 }
assert my_solution.findMaximumElegance(**test_input) == 11

test_input = { "items": [[4,2],[5,2]], "k": 1 }
assert my_solution.findMaximumElegance(**test_input) == 6

test_input = { "items": [[4,2],[7,2]], "k": 1 }
assert my_solution.findMaximumElegance(**test_input) == 8

test_input = { "items": [[4,2],[8,1]], "k": 2 }
assert my_solution.findMaximumElegance(**test_input) == 16

test_input = { "items": [[4,2],[10,1]], "k": 2 }
assert my_solution.findMaximumElegance(**test_input) == 18

test_input = { "items": [[5,1],[4,2]], "k": 1 }
assert my_solution.findMaximumElegance(**test_input) == 6

test_input = { "items": [[5,1],[8,1]], "k": 2 }
assert my_solution.findMaximumElegance(**test_input) == 14

test_input = { "items": [[5,1],[8,2]], "k": 1 }
assert my_solution.findMaximumElegance(**test_input) == 9

test_input = { "items": [[5,1],[9,1]], "k": 1 }
assert my_solution.findMaximumElegance(**test_input) == 10

test_input = { "items": [[5,2],[2,1]], "k": 1 }
assert my_solution.findMaximumElegance(**test_input) == 6

test_input = { "items": [[5,2],[4,2]], "k": 2 }
assert my_solution.findMaximumElegance(**test_input) == 10

test_input = { "items": [[5,2],[5,1]], "k": 2 }
assert my_solution.findMaximumElegance(**test_input) == 14

test_input = { "items": [[6,1],[1,1]], "k": 1 }
assert my_solution.findMaximumElegance(**test_input) == 7

test_input = { "items": [[6,1],[4,1]], "k": 1 }
assert my_solution.findMaximumElegance(**test_input) == 7

test_input = { "items": [[6,1],[7,1]], "k": 1 }
assert my_solution.findMaximumElegance(**test_input) == 8

test_input = { "items": [[6,1],[7,2]], "k": 2 }
assert my_solution.findMaximumElegance(**test_input) == 17

test_input = { "items": [[6,1],[8,1]], "k": 2 }
assert my_solution.findMaximumElegance(**test_input) == 15

test_input = { "items": [[6,1],[8,2]], "k": 2 }
assert my_solution.findMaximumElegance(**test_input) == 18

test_input = { "items": [[6,1],[9,1]], "k": 1 }
assert my_solution.findMaximumElegance(**test_input) == 10

test_input = { "items": [[6,2],[2,1]], "k": 1 }
assert my_solution.findMaximumElegance(**test_input) == 7

test_input = { "items": [[6,2],[4,2]], "k": 1 }
assert my_solution.findMaximumElegance(**test_input) == 7

test_input = { "items": [[6,2],[5,1]], "k": 1 }
assert my_solution.findMaximumElegance(**test_input) == 7

test_input = { "items": [[6,2],[6,2]], "k": 1 }
assert my_solution.findMaximumElegance(**test_input) == 7

test_input = { "items": [[6,2],[6,2]], "k": 2 }
assert my_solution.findMaximumElegance(**test_input) == 13

test_input = { "items": [[6,2],[7,1]], "k": 1 }
assert my_solution.findMaximumElegance(**test_input) == 8

test_input = { "items": [[6,2],[7,1]], "k": 2 }
assert my_solution.findMaximumElegance(**test_input) == 17

test_input = { "items": [[6,2],[8,2]], "k": 2 }
assert my_solution.findMaximumElegance(**test_input) == 15

test_input = { "items": [[6,2],[10,2]], "k": 2 }
assert my_solution.findMaximumElegance(**test_input) == 17

test_input = { "items": [[7,1],[1,1]], "k": 1 }
assert my_solution.findMaximumElegance(**test_input) == 8

test_input = { "items": [[7,1],[3,2]], "k": 1 }
assert my_solution.findMaximumElegance(**test_input) == 8

test_input = { "items": [[7,1],[6,1]], "k": 2 }
assert my_solution.findMaximumElegance(**test_input) == 14

test_input = { "items": [[7,2],[5,1]], "k": 2 }
assert my_solution.findMaximumElegance(**test_input) == 16

test_input = { "items": [[7,2],[5,2]], "k": 1 }
assert my_solution.findMaximumElegance(**test_input) == 8

test_input = { "items": [[7,2],[7,2]], "k": 2 }
assert my_solution.findMaximumElegance(**test_input) == 15

test_input = { "items": [[7,2],[10,2]], "k": 2 }
assert my_solution.findMaximumElegance(**test_input) == 18

test_input = { "items": [[8,1],[2,1]], "k": 1 }
assert my_solution.findMaximumElegance(**test_input) == 9

test_input = { "items": [[8,1],[2,2]], "k": 1 }
assert my_solution.findMaximumElegance(**test_input) == 9

test_input = { "items": [[8,1],[4,2]], "k": 1 }
assert my_solution.findMaximumElegance(**test_input) == 9

test_input = { "items": [[8,1],[5,1]], "k": 1 }
assert my_solution.findMaximumElegance(**test_input) == 9

test_input = { "items": [[8,1],[6,2]], "k": 1 }
assert my_solution.findMaximumElegance(**test_input) == 9

test_input = { "items": [[8,1],[8,1]], "k": 2 }
assert my_solution.findMaximumElegance(**test_input) == 17

test_input = { "items": [[8,1],[9,1]], "k": 1 }
assert my_solution.findMaximumElegance(**test_input) == 10

test_input = { "items": [[8,1],[9,2]], "k": 2 }
assert my_solution.findMaximumElegance(**test_input) == 21

test_input = { "items": [[8,2],[1,1]], "k": 1 }
assert my_solution.findMaximumElegance(**test_input) == 9

test_input = { "items": [[8,2],[1,2]], "k": 1 }
assert my_solution.findMaximumElegance(**test_input) == 9

test_input = { "items": [[8,2],[2,1]], "k": 1 }
assert my_solution.findMaximumElegance(**test_input) == 9

test_input = { "items": [[8,2],[8,2]], "k": 1 }
assert my_solution.findMaximumElegance(**test_input) == 9

test_input = { "items": [[8,2],[9,1]], "k": 2 }
assert my_solution.findMaximumElegance(**test_input) == 21

test_input = { "items": [[8,2],[9,2]], "k": 2 }
assert my_solution.findMaximumElegance(**test_input) == 18

test_input = { "items": [[8,2],[10,1]], "k": 2 }
assert my_solution.findMaximumElegance(**test_input) == 22

test_input = { "items": [[9,1],[1,1]], "k": 1 }
assert my_solution.findMaximumElegance(**test_input) == 10

test_input = { "items": [[9,1],[3,2]], "k": 2 }
assert my_solution.findMaximumElegance(**test_input) == 16

test_input = { "items": [[9,1],[4,2]], "k": 2 }
assert my_solution.findMaximumElegance(**test_input) == 17

test_input = { "items": [[9,1],[6,2]], "k": 1 }
assert my_solution.findMaximumElegance(**test_input) == 10

test_input = { "items": [[9,1],[9,2]], "k": 1 }
assert my_solution.findMaximumElegance(**test_input) == 10

test_input = { "items": [[9,1],[10,2]], "k": 1 }
assert my_solution.findMaximumElegance(**test_input) == 11

test_input = { "items": [[9,2],[1,2]], "k": 1 }
assert my_solution.findMaximumElegance(**test_input) == 10

test_input = { "items": [[9,2],[2,1]], "k": 2 }
assert my_solution.findMaximumElegance(**test_input) == 15

test_input = { "items": [[9,2],[6,1]], "k": 2 }
assert my_solution.findMaximumElegance(**test_input) == 19

test_input = { "items": [[9,2],[6,2]], "k": 2 }
assert my_solution.findMaximumElegance(**test_input) == 16

test_input = { "items": [[9,2],[8,2]], "k": 1 }
assert my_solution.findMaximumElegance(**test_input) == 10

test_input = { "items": [[10,1],[2,2]], "k": 1 }
assert my_solution.findMaximumElegance(**test_input) == 11

test_input = { "items": [[10,1],[4,2]], "k": 1 }
assert my_solution.findMaximumElegance(**test_input) == 11

test_input = { "items": [[10,1],[5,1]], "k": 2 }
assert my_solution.findMaximumElegance(**test_input) == 16

test_input = { "items": [[10,1],[5,2]], "k": 2 }
assert my_solution.findMaximumElegance(**test_input) == 19

test_input = { "items": [[10,1],[7,1]], "k": 1 }
assert my_solution.findMaximumElegance(**test_input) == 11

test_input = { "items": [[10,2],[1,2]], "k": 1 }
assert my_solution.findMaximumElegance(**test_input) == 11

test_input = { "items": [[10,2],[4,1]], "k": 1 }
assert my_solution.findMaximumElegance(**test_input) == 11

test_input = { "items": [[10,2],[5,1]], "k": 1 }
assert my_solution.findMaximumElegance(**test_input) == 11

test_input = { "items": [[10,2],[7,1]], "k": 1 }
assert my_solution.findMaximumElegance(**test_input) == 11

test_input = { "items": [[10,2],[8,2]], "k": 2 }
assert my_solution.findMaximumElegance(**test_input) == 19


account-balance-after-rounded-purchase

Account Balance After Rounded Purchase

Prompt:
"""
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
"""
class Solution:
    def accountBalanceAfterPurchase(self, purchaseAmount: int) -> int:

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 complete the code below to solve above prblem:
```python
class Solution:
    def accountBalanceAfterPurchase(self, purchaseAmount: int) -> int:

```

my_solution = Solution()

test_input = { "purchaseAmount": 9 }
assert my_solution.accountBalanceAfterPurchase(**test_input) == 90

test_input = { "purchaseAmount": 15 }
assert my_solution.accountBalanceAfterPurchase(**test_input) == 80

test_input = { "purchaseAmount": 10 }
assert my_solution.accountBalanceAfterPurchase(**test_input) == 90

test_input = { "purchaseAmount": 11 }
assert my_solution.accountBalanceAfterPurchase(**test_input) == 90

test_input = { "purchaseAmount": 12 }
assert my_solution.accountBalanceAfterPurchase(**test_input) == 90

test_input = { "purchaseAmount": 13 }
assert my_solution.accountBalanceAfterPurchase(**test_input) == 90

test_input = { "purchaseAmount": 14 }
assert my_solution.accountBalanceAfterPurchase(**test_input) == 90

test_input = { "purchaseAmount": 16 }
assert my_solution.accountBalanceAfterPurchase(**test_input) == 80

test_input = { "purchaseAmount": 17 }
assert my_solution.accountBalanceAfterPurchase(**test_input) == 80

test_input = { "purchaseAmount": 18 }
assert my_solution.accountBalanceAfterPurchase(**test_input) == 80

test_input = { "purchaseAmount": 19 }
assert my_solution.accountBalanceAfterPurchase(**test_input) == 80

test_input = { "purchaseAmount": 1 }
assert my_solution.accountBalanceAfterPurchase(**test_input) == 100

test_input = { "purchaseAmount": 2 }
assert my_solution.accountBalanceAfterPurchase(**test_input) == 100

test_input = { "purchaseAmount": 3 }
assert my_solution.accountBalanceAfterPurchase(**test_input) == 100

test_input = { "purchaseAmount": 4 }
assert my_solution.accountBalanceAfterPurchase(**test_input) == 100

test_input = { "purchaseAmount": 5 }
assert my_solution.accountBalanceAfterPurchase(**test_input) == 90

test_input = { "purchaseAmount": 6 }
assert my_solution.accountBalanceAfterPurchase(**test_input) == 90

test_input = { "purchaseAmount": 7 }
assert my_solution.accountBalanceAfterPurchase(**test_input) == 90

test_input = { "purchaseAmount": 8 }
assert my_solution.accountBalanceAfterPurchase(**test_input) == 90

test_input = { "purchaseAmount": 20 }
assert my_solution.accountBalanceAfterPurchase(**test_input) == 80

test_input = { "purchaseAmount": 21 }
assert my_solution.accountBalanceAfterPurchase(**test_input) == 80

test_input = { "purchaseAmount": 22 }
assert my_solution.accountBalanceAfterPurchase(**test_input) == 80

test_input = { "purchaseAmount": 23 }
assert my_solution.accountBalanceAfterPurchase(**test_input) == 80

test_input = { "purchaseAmount": 24 }
assert my_solution.accountBalanceAfterPurchase(**test_input) == 80

test_input = { "purchaseAmount": 25 }
assert my_solution.accountBalanceAfterPurchase(**test_input) == 70

test_input = { "purchaseAmount": 26 }
assert my_solution.accountBalanceAfterPurchase(**test_input) == 70

test_input = { "purchaseAmount": 27 }
assert my_solution.accountBalanceAfterPurchase(**test_input) == 70

test_input = { "purchaseAmount": 28 }
assert my_solution.accountBalanceAfterPurchase(**test_input) == 70

test_input = { "purchaseAmount": 29 }
assert my_solution.accountBalanceAfterPurchase(**test_input) == 70

test_input = { "purchaseAmount": 30 }
assert my_solution.accountBalanceAfterPurchase(**test_input) == 70

test_input = { "purchaseAmount": 31 }
assert my_solution.accountBalanceAfterPurchase(**test_input) == 70

test_input = { "purchaseAmount": 32 }
assert my_solution.accountBalanceAfterPurchase(**test_input) == 70

test_input = { "purchaseAmount": 33 }
assert my_solution.accountBalanceAfterPurchase(**test_input) == 70

test_input = { "purchaseAmount": 34 }
assert my_solution.accountBalanceAfterPurchase(**test_input) == 70

test_input = { "purchaseAmount": 35 }
assert my_solution.accountBalanceAfterPurchase(**test_input) == 60

test_input = { "purchaseAmount": 36 }
assert my_solution.accountBalanceAfterPurchase(**test_input) == 60

test_input = { "purchaseAmount": 37 }
assert my_solution.accountBalanceAfterPurchase(**test_input) == 60

test_input = { "purchaseAmount": 38 }
assert my_solution.accountBalanceAfterPurchase(**test_input) == 60

test_input = { "purchaseAmount": 39 }
assert my_solution.accountBalanceAfterPurchase(**test_input) == 60

test_input = { "purchaseAmount": 40 }
assert my_solution.accountBalanceAfterPurchase(**test_input) == 60

test_input = { "purchaseAmount": 41 }
assert my_solution.accountBalanceAfterPurchase(**test_input) == 60

test_input = { "purchaseAmount": 42 }
assert my_solution.accountBalanceAfterPurchase(**test_input) == 60

test_input = { "purchaseAmount": 43 }
assert my_solution.accountBalanceAfterPurchase(**test_input) == 60

test_input = { "purchaseAmount": 44 }
assert my_solution.accountBalanceAfterPurchase(**test_input) == 60

test_input = { "purchaseAmount": 45 }
assert my_solution.accountBalanceAfterPurchase(**test_input) == 50

test_input = { "purchaseAmount": 46 }
assert my_solution.accountBalanceAfterPurchase(**test_input) == 50

test_input = { "purchaseAmount": 47 }
assert my_solution.accountBalanceAfterPurchase(**test_input) == 50

test_input = { "purchaseAmount": 48 }
assert my_solution.accountBalanceAfterPurchase(**test_input) == 50

test_input = { "purchaseAmount": 49 }
assert my_solution.accountBalanceAfterPurchase(**test_input) == 50

test_input = { "purchaseAmount": 50 }
assert my_solution.accountBalanceAfterPurchase(**test_input) == 50

test_input = { "purchaseAmount": 51 }
assert my_solution.accountBalanceAfterPurchase(**test_input) == 50

test_input = { "purchaseAmount": 52 }
assert my_solution.accountBalanceAfterPurchase(**test_input) == 50

test_input = { "purchaseAmount": 53 }
assert my_solution.accountBalanceAfterPurchase(**test_input) == 50

test_input = { "purchaseAmount": 54 }
assert my_solution.accountBalanceAfterPurchase(**test_input) == 50

test_input = { "purchaseAmount": 55 }
assert my_solution.accountBalanceAfterPurchase(**test_input) == 40

test_input = { "purchaseAmount": 56 }
assert my_solution.accountBalanceAfterPurchase(**test_input) == 40

test_input = { "purchaseAmount": 57 }
assert my_solution.accountBalanceAfterPurchase(**test_input) == 40

test_input = { "purchaseAmount": 58 }
assert my_solution.accountBalanceAfterPurchase(**test_input) == 40

test_input = { "purchaseAmount": 59 }
assert my_solution.accountBalanceAfterPurchase(**test_input) == 40

test_input = { "purchaseAmount": 60 }
assert my_solution.accountBalanceAfterPurchase(**test_input) == 40

test_input = { "purchaseAmount": 61 }
assert my_solution.accountBalanceAfterPurchase(**test_input) == 40

test_input = { "purchaseAmount": 62 }
assert my_solution.accountBalanceAfterPurchase(**test_input) == 40

test_input = { "purchaseAmount": 63 }
assert my_solution.accountBalanceAfterPurchase(**test_input) == 40

test_input = { "purchaseAmount": 64 }
assert my_solution.accountBalanceAfterPurchase(**test_input) == 40

test_input = { "purchaseAmount": 65 }
assert my_solution.accountBalanceAfterPurchase(**test_input) == 30

test_input = { "purchaseAmount": 66 }
assert my_solution.accountBalanceAfterPurchase(**test_input) == 30

test_input = { "purchaseAmount": 67 }
assert my_solution.accountBalanceAfterPurchase(**test_input) == 30

test_input = { "purchaseAmount": 68 }
assert my_solution.accountBalanceAfterPurchase(**test_input) == 30

test_input = { "purchaseAmount": 69 }
assert my_solution.accountBalanceAfterPurchase(**test_input) == 30

test_input = { "purchaseAmount": 70 }
assert my_solution.accountBalanceAfterPurchase(**test_input) == 30

test_input = { "purchaseAmount": 71 }
assert my_solution.accountBalanceAfterPurchase(**test_input) == 30

test_input = { "purchaseAmount": 72 }
assert my_solution.accountBalanceAfterPurchase(**test_input) == 30

test_input = { "purchaseAmount": 73 }
assert my_solution.accountBalanceAfterPurchase(**test_input) == 30

test_input = { "purchaseAmount": 74 }
assert my_solution.accountBalanceAfterPurchase(**test_input) == 30

test_input = { "purchaseAmount": 75 }
assert my_solution.accountBalanceAfterPurchase(**test_input) == 20

test_input = { "purchaseAmount": 76 }
assert my_solution.accountBalanceAfterPurchase(**test_input) == 20

test_input = { "purchaseAmount": 77 }
assert my_solution.accountBalanceAfterPurchase(**test_input) == 20

test_input = { "purchaseAmount": 78 }
assert my_solution.accountBalanceAfterPurchase(**test_input) == 20

test_input = { "purchaseAmount": 79 }
assert my_solution.accountBalanceAfterPurchase(**test_input) == 20

test_input = { "purchaseAmount": 80 }
assert my_solution.accountBalanceAfterPurchase(**test_input) == 20

test_input = { "purchaseAmount": 81 }
assert my_solution.accountBalanceAfterPurchase(**test_input) == 20

test_input = { "purchaseAmount": 82 }
assert my_solution.accountBalanceAfterPurchase(**test_input) == 20

test_input = { "purchaseAmount": 83 }
assert my_solution.accountBalanceAfterPurchase(**test_input) == 20

test_input = { "purchaseAmount": 84 }
assert my_solution.accountBalanceAfterPurchase(**test_input) == 20

test_input = { "purchaseAmount": 85 }
assert my_solution.accountBalanceAfterPurchase(**test_input) == 10

test_input = { "purchaseAmount": 86 }
assert my_solution.accountBalanceAfterPurchase(**test_input) == 10

test_input = { "purchaseAmount": 87 }
assert my_solution.accountBalanceAfterPurchase(**test_input) == 10

test_input = { "purchaseAmount": 88 }
assert my_solution.accountBalanceAfterPurchase(**test_input) == 10

test_input = { "purchaseAmount": 89 }
assert my_solution.accountBalanceAfterPurchase(**test_input) == 10

test_input = { "purchaseAmount": 90 }
assert my_solution.accountBalanceAfterPurchase(**test_input) == 10

test_input = { "purchaseAmount": 91 }
assert my_solution.accountBalanceAfterPurchase(**test_input) == 10

test_input = { "purchaseAmount": 92 }
assert my_solution.accountBalanceAfterPurchase(**test_input) == 10

test_input = { "purchaseAmount": 93 }
assert my_solution.accountBalanceAfterPurchase(**test_input) == 10

test_input = { "purchaseAmount": 94 }
assert my_solution.accountBalanceAfterPurchase(**test_input) == 10

test_input = { "purchaseAmount": 95 }
assert my_solution.accountBalanceAfterPurchase(**test_input) == 0

test_input = { "purchaseAmount": 96 }
assert my_solution.accountBalanceAfterPurchase(**test_input) == 0

test_input = { "purchaseAmount": 97 }
assert my_solution.accountBalanceAfterPurchase(**test_input) == 0

test_input = { "purchaseAmount": 98 }
assert my_solution.accountBalanceAfterPurchase(**test_input) == 0

test_input = { "purchaseAmount": 99 }
assert my_solution.accountBalanceAfterPurchase(**test_input) == 0

test_input = { "purchaseAmount": 100 }
assert my_solution.accountBalanceAfterPurchase(**test_input) == 0