find-champion-ii

Find Champion II

Prompt:
"""
There are n teams numbered from 0 to n - 1 in a tournament; each team is also a node in a DAG.

You are given the integer n and a 0-indexed 2D integer array edges of length m representing the DAG, where edges[i] = [ui, vi] indicates that there is a directed edge from team ui to team vi in the graph.

A directed edge from a to b in the graph means that team a is stronger than team b and team b is weaker than team a.

Team a will be the champion of the tournament if there is no team b that is stronger than team a.

Return the team that will be the champion of the tournament if there is a unique champion, otherwise, return -1.

Notes

 * A cycle is a series of nodes a1, a2, ..., an, an+1 such that node a1 is the same node as node an+1, the nodes a1, a2, ..., an are distinct, and there is a directed edge from the node ai to node ai+1 for every i in the range [1, n].
 * A DAG is a directed graph that does not have any cycle.

Example 1:

[https://assets.leetcode.com/uploads/2023/10/19/graph-3.png]

Input: n = 3, edges = [[0,1],[1,2]]
Output: 0
Explanation: Team 1 is weaker than team 0. Team 2 is weaker than team 1. So the champion is team 0.

Example 2:

[https://assets.leetcode.com/uploads/2023/10/19/graph-4.png]

Input: n = 4, edges = [[0,2],[1,3],[1,2]]
Output: -1
Explanation: Team 2 is weaker than team 0 and team 1. Team 3 is weaker than team 1. But team 1 and team 0 are not weaker than any other teams. So the answer is -1.

Constraints:

 * 1 <= n <= 100
 * m == edges.length
 * 0 <= m <= n * (n - 1) / 2
 * edges[i].length == 2
 * 0 <= edge[i][j] <= n - 1
 * edges[i][0] != edges[i][1]
 * The input is generated such that if team a is stronger than team b, team b is not stronger than team a.
 * The input is generated such that if team a is stronger than team b and team b is stronger than team c, then team a is stronger than team c.
"""
class Solution:
    def findChampion(self, n: int, edges: List[List[int]]) -> int:

There are n teams numbered from 0 to n - 1 in a tournament; each team is also a node in a DAG.

You are given the integer n and a 0-indexed 2D integer array edges of length m representing the DAG, where edges[i] = [ui, vi] indicates that there is a directed edge from team ui to team vi in the graph.

A directed edge from a to b in the graph means that team a is stronger than team b and team b is weaker than team a.

Team a will be the champion of the tournament if there is no team b that is stronger than team a.

Return the team that will be the champion of the tournament if there is a unique champion, otherwise, return -1.

Notes

 * A cycle is a series of nodes a1, a2, ..., an, an+1 such that node a1 is the same node as node an+1, the nodes a1, a2, ..., an are distinct, and there is a directed edge from the node ai to node ai+1 for every i in the range [1, n].
 * A DAG is a directed graph that does not have any cycle.

Example 1:

[https://assets.leetcode.com/uploads/2023/10/19/graph-3.png]

Input: n = 3, edges = [[0,1],[1,2]]
Output: 0
Explanation: Team 1 is weaker than team 0. Team 2 is weaker than team 1. So the champion is team 0.

Example 2:

[https://assets.leetcode.com/uploads/2023/10/19/graph-4.png]

Input: n = 4, edges = [[0,2],[1,3],[1,2]]
Output: -1
Explanation: Team 2 is weaker than team 0 and team 1. Team 3 is weaker than team 1. But team 1 and team 0 are not weaker than any other teams. So the answer is -1.

Constraints:

 * 1 <= n <= 100
 * m == edges.length
 * 0 <= m <= n * (n - 1) / 2
 * edges[i].length == 2
 * 0 <= edge[i][j] <= n - 1
 * edges[i][0] != edges[i][1]
 * The input is generated such that if team a is stronger than team b, team b is not stronger than team a.
 * The input is generated such that if team a is stronger than team b and team b is stronger than team c, then team a is stronger than team c.

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

```

my_solution = Solution()

test_input = { "n": 3, "edges": [[0,1],[1,2]] }
assert my_solution.findChampion(**test_input) == 0

test_input = { "n": 4, "edges": [[0,2],[1,3],[1,2]] }
assert my_solution.findChampion(**test_input) == -1

test_input = { "n": 1, "edges": [] }
assert my_solution.findChampion(**test_input) == 0

test_input = { "n": 2, "edges": [] }
assert my_solution.findChampion(**test_input) == -1

test_input = { "n": 2, "edges": [[0,1]] }
assert my_solution.findChampion(**test_input) == 0

test_input = { "n": 2, "edges": [[1,0]] }
assert my_solution.findChampion(**test_input) == 1

test_input = { "n": 3, "edges": [] }
assert my_solution.findChampion(**test_input) == -1

test_input = { "n": 3, "edges": [[0,1]] }
assert my_solution.findChampion(**test_input) == -1

test_input = { "n": 3, "edges": [[0,2]] }
assert my_solution.findChampion(**test_input) == -1

test_input = { "n": 3, "edges": [[1,2]] }
assert my_solution.findChampion(**test_input) == -1

test_input = { "n": 3, "edges": [[2,0]] }
assert my_solution.findChampion(**test_input) == -1

test_input = { "n": 3, "edges": [[0,1],[2,1]] }
assert my_solution.findChampion(**test_input) == -1

test_input = { "n": 3, "edges": [[0,2],[0,1]] }
assert my_solution.findChampion(**test_input) == 0

test_input = { "n": 3, "edges": [[0,2],[1,0]] }
assert my_solution.findChampion(**test_input) == 1

test_input = { "n": 3, "edges": [[2,0],[1,0]] }
assert my_solution.findChampion(**test_input) == -1

test_input = { "n": 3, "edges": [[2,0],[2,1]] }
assert my_solution.findChampion(**test_input) == 2

test_input = { "n": 3, "edges": [[2,1],[2,0]] }
assert my_solution.findChampion(**test_input) == 2

test_input = { "n": 3, "edges": [[0,1],[1,2],[0,2]] }
assert my_solution.findChampion(**test_input) == 0

test_input = { "n": 3, "edges": [[0,1],[2,1],[0,2]] }
assert my_solution.findChampion(**test_input) == 0

test_input = { "n": 3, "edges": [[0,2],[0,1],[1,2]] }
assert my_solution.findChampion(**test_input) == 0

test_input = { "n": 3, "edges": [[0,2],[0,1],[2,1]] }
assert my_solution.findChampion(**test_input) == 0

test_input = { "n": 3, "edges": [[0,2],[1,2],[1,0]] }
assert my_solution.findChampion(**test_input) == 1

test_input = { "n": 3, "edges": [[1,0],[0,2],[1,2]] }
assert my_solution.findChampion(**test_input) == 1

test_input = { "n": 3, "edges": [[2,1],[1,0],[2,0]] }
assert my_solution.findChampion(**test_input) == 2

test_input = { "n": 4, "edges": [] }
assert my_solution.findChampion(**test_input) == -1

test_input = { "n": 4, "edges": [[0,2]] }
assert my_solution.findChampion(**test_input) == -1

test_input = { "n": 4, "edges": [[1,0]] }
assert my_solution.findChampion(**test_input) == -1

test_input = { "n": 4, "edges": [[1,3]] }
assert my_solution.findChampion(**test_input) == -1

test_input = { "n": 4, "edges": [[3,2]] }
assert my_solution.findChampion(**test_input) == -1

test_input = { "n": 4, "edges": [[0,1],[2,3]] }
assert my_solution.findChampion(**test_input) == -1

test_input = { "n": 4, "edges": [[0,3],[2,3]] }
assert my_solution.findChampion(**test_input) == -1

test_input = { "n": 4, "edges": [[1,3],[2,1]] }
assert my_solution.findChampion(**test_input) == -1

test_input = { "n": 4, "edges": [[2,1],[1,3]] }
assert my_solution.findChampion(**test_input) == -1

test_input = { "n": 4, "edges": [[3,0],[3,1]] }
assert my_solution.findChampion(**test_input) == -1

test_input = { "n": 4, "edges": [[0,1],[2,0],[2,1]] }
assert my_solution.findChampion(**test_input) == -1

test_input = { "n": 4, "edges": [[0,2],[3,2],[1,2]] }
assert my_solution.findChampion(**test_input) == -1

test_input = { "n": 4, "edges": [[1,0],[2,3],[1,2]] }
assert my_solution.findChampion(**test_input) == 1

test_input = { "n": 4, "edges": [[1,2],[0,3],[1,3]] }
assert my_solution.findChampion(**test_input) == -1

test_input = { "n": 4, "edges": [[1,2],[1,0],[1,3]] }
assert my_solution.findChampion(**test_input) == 1

test_input = { "n": 4, "edges": [[1,3],[1,2],[0,3]] }
assert my_solution.findChampion(**test_input) == -1

test_input = { "n": 4, "edges": [[1,3],[3,0],[2,0]] }
assert my_solution.findChampion(**test_input) == -1

test_input = { "n": 4, "edges": [[3,1],[2,0],[1,2]] }
assert my_solution.findChampion(**test_input) == 3

test_input = { "n": 4, "edges": [[3,1],[2,1],[0,2]] }
assert my_solution.findChampion(**test_input) == -1

test_input = { "n": 4, "edges": [[0,2],[0,3],[1,2],[1,0]] }
assert my_solution.findChampion(**test_input) == 1

test_input = { "n": 4, "edges": [[2,0],[2,3],[3,1],[2,1]] }
assert my_solution.findChampion(**test_input) == 2

test_input = { "n": 4, "edges": [[2,1],[1,0],[3,0],[2,0]] }
assert my_solution.findChampion(**test_input) == -1

test_input = { "n": 4, "edges": [[3,0],[3,1],[2,1],[0,1]] }
assert my_solution.findChampion(**test_input) == -1

test_input = { "n": 4, "edges": [[3,0],[1,0],[1,2],[3,2],[2,0]] }
assert my_solution.findChampion(**test_input) == -1

test_input = { "n": 4, "edges": [[3,0],[2,0],[1,0],[2,3],[1,2]] }
assert my_solution.findChampion(**test_input) == 1

test_input = { "n": 4, "edges": [[3,2],[0,1],[3,0],[3,1],[2,0]] }
assert my_solution.findChampion(**test_input) == 3

test_input = { "n": 4, "edges": [[0,3],[2,3],[2,1],[1,0],[2,0],[1,3]] }
assert my_solution.findChampion(**test_input) == 2

test_input = { "n": 4, "edges": [[1,2],[2,3],[0,2],[0,1],[0,3],[1,3]] }
assert my_solution.findChampion(**test_input) == 0

test_input = { "n": 4, "edges": [[2,1],[3,1],[3,0],[3,2],[2,0],[0,1]] }
assert my_solution.findChampion(**test_input) == 3

test_input = { "n": 4, "edges": [[2,3],[2,1],[0,1],[0,3],[3,1],[0,2]] }
assert my_solution.findChampion(**test_input) == 0

test_input = { "n": 5, "edges": [] }
assert my_solution.findChampion(**test_input) == -1

test_input = { "n": 5, "edges": [[0,2]] }
assert my_solution.findChampion(**test_input) == -1

test_input = { "n": 5, "edges": [[2,0]] }
assert my_solution.findChampion(**test_input) == -1

test_input = { "n": 5, "edges": [[4,0]] }
assert my_solution.findChampion(**test_input) == -1

test_input = { "n": 5, "edges": [[1,4],[2,0]] }
assert my_solution.findChampion(**test_input) == -1

test_input = { "n": 5, "edges": [[2,0],[4,3]] }
assert my_solution.findChampion(**test_input) == -1

test_input = { "n": 5, "edges": [[3,2],[0,2]] }
assert my_solution.findChampion(**test_input) == -1

test_input = { "n": 5, "edges": [[3,4],[2,1]] }
assert my_solution.findChampion(**test_input) == -1

test_input = { "n": 5, "edges": [[0,4],[1,4],[0,1]] }
assert my_solution.findChampion(**test_input) == -1

test_input = { "n": 5, "edges": [[1,3],[4,2],[1,0]] }
assert my_solution.findChampion(**test_input) == -1

test_input = { "n": 5, "edges": [[2,3],[4,1],[3,0]] }
assert my_solution.findChampion(**test_input) == -1

test_input = { "n": 5, "edges": [[0,4],[2,0],[1,3],[2,4]] }
assert my_solution.findChampion(**test_input) == -1

test_input = { "n": 5, "edges": [[0,1],[2,1],[4,1],[4,2],[4,0]] }
assert my_solution.findChampion(**test_input) == -1

test_input = { "n": 5, "edges": [[0,2],[2,1],[3,2],[4,1],[0,4]] }
assert my_solution.findChampion(**test_input) == -1

test_input = { "n": 5, "edges": [[2,3],[0,4],[1,4],[1,0],[4,3]] }
assert my_solution.findChampion(**test_input) == -1

test_input = { "n": 5, "edges": [[3,1],[0,2],[4,2],[0,1],[1,2]] }
assert my_solution.findChampion(**test_input) == -1

test_input = { "n": 5, "edges": [[3,2],[3,4],[3,0],[3,1],[0,2]] }
assert my_solution.findChampion(**test_input) == 3

test_input = { "n": 5, "edges": [[4,0],[3,0],[2,4],[3,4],[4,1]] }
assert my_solution.findChampion(**test_input) == -1

test_input = { "n": 5, "edges": [[4,3],[1,0],[1,2],[3,2],[4,1]] }
assert my_solution.findChampion(**test_input) == 4

test_input = { "n": 5, "edges": [[2,1],[0,3],[0,1],[0,4],[0,2],[4,1]] }
assert my_solution.findChampion(**test_input) == 0

test_input = { "n": 5, "edges": [[2,1],[4,1],[3,0],[2,0],[3,4],[3,2]] }
assert my_solution.findChampion(**test_input) == 3

test_input = { "n": 5, "edges": [[0,1],[0,4],[2,0],[3,4],[3,1],[2,1],[3,0]] }
assert my_solution.findChampion(**test_input) == -1

test_input = { "n": 5, "edges": [[1,4],[3,1],[0,1],[3,0],[0,2],[2,4],[3,4]] }
assert my_solution.findChampion(**test_input) == 3

test_input = { "n": 5, "edges": [[3,2],[1,2],[2,0],[2,4],[1,4],[3,1],[3,4]] }
assert my_solution.findChampion(**test_input) == 3

test_input = { "n": 5, "edges": [[0,4],[0,3],[4,3],[4,2],[1,2],[4,1],[0,1],[3,2]] }
assert my_solution.findChampion(**test_input) == 0

test_input = { "n": 5, "edges": [[4,3],[4,2],[4,1],[2,3],[4,0],[3,1],[2,0],[0,3]] }
assert my_solution.findChampion(**test_input) == 4

test_input = { "n": 5, "edges": [[1,2],[1,4],[2,3],[0,2],[1,0],[1,3],[0,3],[4,3],[0,4]] }
assert my_solution.findChampion(**test_input) == 1

test_input = { "n": 5, "edges": [[1,3],[3,0],[3,4],[2,0],[3,2],[0,4],[2,4],[1,0],[1,2]] }
assert my_solution.findChampion(**test_input) == 1

test_input = { "n": 5, "edges": [[3,0],[4,0],[3,2],[0,1],[0,2],[4,3],[1,2],[4,2],[3,1]] }
assert my_solution.findChampion(**test_input) == 4

test_input = { "n": 5, "edges": [[4,0],[2,3],[4,3],[4,2],[2,0],[4,1],[1,3],[1,0],[3,0]] }
assert my_solution.findChampion(**test_input) == 4

test_input = { "n": 5, "edges": [[0,2],[1,3],[4,1],[4,2],[2,1],[0,3],[0,1],[2,3],[0,4],[4,3]] }
assert my_solution.findChampion(**test_input) == 0

test_input = { "n": 5, "edges": [[2,0],[4,0],[3,4],[4,2],[1,2],[1,0],[3,1],[3,0],[1,4],[3,2]] }
assert my_solution.findChampion(**test_input) == 3

test_input = { "n": 6, "edges": [] }
assert my_solution.findChampion(**test_input) == -1

test_input = { "n": 6, "edges": [[2,1]] }
assert my_solution.findChampion(**test_input) == -1

test_input = { "n": 6, "edges": [[2,3]] }
assert my_solution.findChampion(**test_input) == -1

test_input = { "n": 6, "edges": [[3,5]] }
assert my_solution.findChampion(**test_input) == -1

test_input = { "n": 6, "edges": [[5,4]] }
assert my_solution.findChampion(**test_input) == -1

test_input = { "n": 6, "edges": [[1,2],[4,3]] }
assert my_solution.findChampion(**test_input) == -1

test_input = { "n": 6, "edges": [[0,4],[4,5],[3,1]] }
assert my_solution.findChampion(**test_input) == -1

test_input = { "n": 6, "edges": [[0,4],[5,2],[5,4],[3,0],[1,0]] }
assert my_solution.findChampion(**test_input) == -1

test_input = { "n": 6, "edges": [[1,0],[1,4],[0,2],[3,5],[3,4]] }
assert my_solution.findChampion(**test_input) == -1

test_input = { "n": 6, "edges": [[5,0],[2,4],[0,4],[3,2],[2,0]] }
assert my_solution.findChampion(**test_input) == -1

test_input = { "n": 6, "edges": [[1,2],[3,2],[3,5],[4,0],[1,5],[0,5]] }
assert my_solution.findChampion(**test_input) == -1

test_input = { "n": 6, "edges": [[3,2],[1,2],[3,0],[5,0],[5,1],[5,3]] }
assert my_solution.findChampion(**test_input) == -1

test_input = { "n": 6, "edges": [[4,2],[0,4],[1,3],[3,4],[1,2],[1,0]] }
assert my_solution.findChampion(**test_input) == -1

test_input = { "n": 6, "edges": [[0,5],[2,0],[1,5],[3,2],[2,1],[2,4],[4,5]] }
assert my_solution.findChampion(**test_input) == 3


maximum-score-after-applying-operations-on-a-tree

Maximum Score After Applying Operations on a Tree

Prompt:
"""
There is an undirected tree with n nodes labeled from 0 to n - 1, and rooted at node 0. You are given a 2D integer array edges of length n - 1, where edges[i] = [ai, bi] indicates that there is an edge between nodes ai and bi in the tree.

You are also given a 0-indexed integer array values of length n, where values[i] is the value associated with the ith node.

You start with a score of 0. In one operation, you can:

 * Pick any node i.
 * Add values[i] to your score.
 * Set values[i] to 0.

A tree is healthy if the sum of values on the path from the root to any leaf node is different than zero.

Return the maximum score you can obtain after performing these operations on the tree any number of times so that it remains healthy.

Example 1:

[https://assets.leetcode.com/uploads/2023/10/11/graph-13-1.png]

Input: edges = [[0,1],[0,2],[0,3],[2,4],[4,5]], values = [5,2,5,2,1,1]
Output: 11
Explanation: We can choose nodes 1, 2, 3, 4, and 5. The value of the root is non-zero. Hence, the sum of values on the path from the root to any leaf is different than zero. Therefore, the tree is healthy and the score is values[1] + values[2] + values[3] + values[4] + values[5] = 11.
It can be shown that 11 is the maximum score obtainable after any number of operations on the tree.

Example 2:

[https://assets.leetcode.com/uploads/2023/10/11/graph-14-2.png]

Input: edges = [[0,1],[0,2],[1,3],[1,4],[2,5],[2,6]], values = [20,10,9,7,4,3,5]
Output: 40
Explanation: We can choose nodes 0, 2, 3, and 4.
- The sum of values on the path from 0 to 4 is equal to 10.
- The sum of values on the path from 0 to 3 is equal to 10.
- The sum of values on the path from 0 to 5 is equal to 3.
- The sum of values on the path from 0 to 6 is equal to 5.
Therefore, the tree is healthy and the score is values[0] + values[2] + values[3] + values[4] = 40.
It can be shown that 40 is the maximum score obtainable after any number of operations on the tree.

Constraints:

 * 2 <= n <= 2 * 104
 * edges.length == n - 1
 * edges[i].length == 2
 * 0 <= ai, bi < n
 * values.length == n
 * 1 <= values[i] <= 109
 * The input is generated such that edges represents a valid tree.
"""
class Solution:
    def maximumScoreAfterOperations(self, edges: List[List[int]], values: List[int]) -> int:

There is an undirected tree with n nodes labeled from 0 to n - 1, and rooted at node 0. You are given a 2D integer array edges of length n - 1, where edges[i] = [ai, bi] indicates that there is an edge between nodes ai and bi in the tree.

You are also given a 0-indexed integer array values of length n, where values[i] is the value associated with the ith node.

You start with a score of 0. In one operation, you can:

 * Pick any node i.
 * Add values[i] to your score.
 * Set values[i] to 0.

A tree is healthy if the sum of values on the path from the root to any leaf node is different than zero.

Return the maximum score you can obtain after performing these operations on the tree any number of times so that it remains healthy.

Example 1:

[https://assets.leetcode.com/uploads/2023/10/11/graph-13-1.png]

Input: edges = [[0,1],[0,2],[0,3],[2,4],[4,5]], values = [5,2,5,2,1,1]
Output: 11
Explanation: We can choose nodes 1, 2, 3, 4, and 5. The value of the root is non-zero. Hence, the sum of values on the path from the root to any leaf is different than zero. Therefore, the tree is healthy and the score is values[1] + values[2] + values[3] + values[4] + values[5] = 11.
It can be shown that 11 is the maximum score obtainable after any number of operations on the tree.

Example 2:

[https://assets.leetcode.com/uploads/2023/10/11/graph-14-2.png]

Input: edges = [[0,1],[0,2],[1,3],[1,4],[2,5],[2,6]], values = [20,10,9,7,4,3,5]
Output: 40
Explanation: We can choose nodes 0, 2, 3, and 4.
- The sum of values on the path from 0 to 4 is equal to 10.
- The sum of values on the path from 0 to 3 is equal to 10.
- The sum of values on the path from 0 to 5 is equal to 3.
- The sum of values on the path from 0 to 6 is equal to 5.
Therefore, the tree is healthy and the score is values[0] + values[2] + values[3] + values[4] = 40.
It can be shown that 40 is the maximum score obtainable after any number of operations on the tree.

Constraints:

 * 2 <= n <= 2 * 104
 * edges.length == n - 1
 * edges[i].length == 2
 * 0 <= ai, bi < n
 * values.length == n
 * 1 <= values[i] <= 109
 * The input is generated such that edges represents a valid tree.

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

```


maximum-balanced-subsequence-sum

Maximum Balanced Subsequence Sum

Prompt:
"""
You are given a 0-indexed integer array nums.

A subsequence of nums having length k and consisting of indices i0 < i1 < ... < ik-1 is balanced if the following holds:

 * nums[ij] - nums[ij-1] >= ij - ij-1, for every j in the range [1, k - 1].

A subsequence of nums having length 1 is considered balanced.

Return an integer denoting the maximum possible sum of elements in a balanced subsequence of nums.

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

Example 1:

Input: nums = [3,3,5,6]
Output: 14
Explanation: In this example, the subsequence [3,5,6] consisting of indices 0, 2, and 3 can be selected.
nums[2] - nums[0] >= 2 - 0.
nums[3] - nums[2] >= 3 - 2.
Hence, it is a balanced subsequence, and its sum is the maximum among the balanced subsequences of nums.
The subsequence consisting of indices 1, 2, and 3 is also valid.
It can be shown that it is not possible to get a balanced subsequence with a sum greater than 14.

Example 2:

Input: nums = [5,-1,-3,8]
Output: 13
Explanation: In this example, the subsequence [5,8] consisting of indices 0 and 3 can be selected.
nums[3] - nums[0] >= 3 - 0.
Hence, it is a balanced subsequence, and its sum is the maximum among the balanced subsequences of nums.
It can be shown that it is not possible to get a balanced subsequence with a sum greater than 13.

Example 3:

Input: nums = [-2,-1]
Output: -1
Explanation: In this example, the subsequence [-1] can be selected.
It is a balanced subsequence, and its sum is the maximum among the balanced subsequences of nums.

Constraints:

 * 1 <= nums.length <= 105
 * -109 <= nums[i] <= 109
"""
class Solution:
    def maxBalancedSubsequenceSum(self, nums: List[int]) -> int:

You are given a 0-indexed integer array nums.

A subsequence of nums having length k and consisting of indices i0 < i1 < ... < ik-1 is balanced if the following holds:

 * nums[ij] - nums[ij-1] >= ij - ij-1, for every j in the range [1, k - 1].

A subsequence of nums having length 1 is considered balanced.

Return an integer denoting the maximum possible sum of elements in a balanced subsequence of nums.

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

Example 1:

Input: nums = [3,3,5,6]
Output: 14
Explanation: In this example, the subsequence [3,5,6] consisting of indices 0, 2, and 3 can be selected.
nums[2] - nums[0] >= 2 - 0.
nums[3] - nums[2] >= 3 - 2.
Hence, it is a balanced subsequence, and its sum is the maximum among the balanced subsequences of nums.
The subsequence consisting of indices 1, 2, and 3 is also valid.
It can be shown that it is not possible to get a balanced subsequence with a sum greater than 14.

Example 2:

Input: nums = [5,-1,-3,8]
Output: 13
Explanation: In this example, the subsequence [5,8] consisting of indices 0 and 3 can be selected.
nums[3] - nums[0] >= 3 - 0.
Hence, it is a balanced subsequence, and its sum is the maximum among the balanced subsequences of nums.
It can be shown that it is not possible to get a balanced subsequence with a sum greater than 13.

Example 3:

Input: nums = [-2,-1]
Output: -1
Explanation: In this example, the subsequence [-1] can be selected.
It is a balanced subsequence, and its sum is the maximum among the balanced subsequences of nums.

Constraints:

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

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

```

my_solution = Solution()

test_input = { "nums": [3,3,5,6] }
assert my_solution.maxBalancedSubsequenceSum(**test_input) == 14

test_input = { "nums": [5,-1,-3,8] }
assert my_solution.maxBalancedSubsequenceSum(**test_input) == 13

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

test_input = { "nums": [0] }
assert my_solution.maxBalancedSubsequenceSum(**test_input) == 0

test_input = { "nums": [-47] }
assert my_solution.maxBalancedSubsequenceSum(**test_input) == -47

test_input = { "nums": [-8] }
assert my_solution.maxBalancedSubsequenceSum(**test_input) == -8

test_input = { "nums": [-7] }
assert my_solution.maxBalancedSubsequenceSum(**test_input) == -7

test_input = { "nums": [-6] }
assert my_solution.maxBalancedSubsequenceSum(**test_input) == -6

test_input = { "nums": [-5] }
assert my_solution.maxBalancedSubsequenceSum(**test_input) == -5

test_input = { "nums": [-3] }
assert my_solution.maxBalancedSubsequenceSum(**test_input) == -3

test_input = { "nums": [-2] }
assert my_solution.maxBalancedSubsequenceSum(**test_input) == -2

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

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

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

test_input = { "nums": [4] }
assert my_solution.maxBalancedSubsequenceSum(**test_input) == 4

test_input = { "nums": [5] }
assert my_solution.maxBalancedSubsequenceSum(**test_input) == 5

test_input = { "nums": [7] }
assert my_solution.maxBalancedSubsequenceSum(**test_input) == 7

test_input = { "nums": [8] }
assert my_solution.maxBalancedSubsequenceSum(**test_input) == 8

test_input = { "nums": [9] }
assert my_solution.maxBalancedSubsequenceSum(**test_input) == 9

test_input = { "nums": [45] }
assert my_solution.maxBalancedSubsequenceSum(**test_input) == 45

test_input = { "nums": [-9,-5] }
assert my_solution.maxBalancedSubsequenceSum(**test_input) == -5

test_input = { "nums": [-6,8] }
assert my_solution.maxBalancedSubsequenceSum(**test_input) == 8

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

test_input = { "nums": [-5,0] }
assert my_solution.maxBalancedSubsequenceSum(**test_input) == 0

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

test_input = { "nums": [-2,3] }
assert my_solution.maxBalancedSubsequenceSum(**test_input) == 3

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

test_input = { "nums": [-1,0] }
assert my_solution.maxBalancedSubsequenceSum(**test_input) == 0

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

test_input = { "nums": [0,-3] }
assert my_solution.maxBalancedSubsequenceSum(**test_input) == 0

test_input = { "nums": [0,5] }
assert my_solution.maxBalancedSubsequenceSum(**test_input) == 5

test_input = { "nums": [2,7] }
assert my_solution.maxBalancedSubsequenceSum(**test_input) == 9

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

test_input = { "nums": [6,-8] }
assert my_solution.maxBalancedSubsequenceSum(**test_input) == 6

test_input = { "nums": [7,-2] }
assert my_solution.maxBalancedSubsequenceSum(**test_input) == 7

test_input = { "nums": [7,2] }
assert my_solution.maxBalancedSubsequenceSum(**test_input) == 7

test_input = { "nums": [8,-9] }
assert my_solution.maxBalancedSubsequenceSum(**test_input) == 8

test_input = { "nums": [9,-9] }
assert my_solution.maxBalancedSubsequenceSum(**test_input) == 9

test_input = { "nums": [-43,23,-49] }
assert my_solution.maxBalancedSubsequenceSum(**test_input) == 23

test_input = { "nums": [-9,-6,-5] }
assert my_solution.maxBalancedSubsequenceSum(**test_input) == -5

test_input = { "nums": [-9,-2,4] }
assert my_solution.maxBalancedSubsequenceSum(**test_input) == 4

test_input = { "nums": [-9,5,-6] }
assert my_solution.maxBalancedSubsequenceSum(**test_input) == 5

test_input = { "nums": [-8,9,-9] }
assert my_solution.maxBalancedSubsequenceSum(**test_input) == 9

test_input = { "nums": [-5,-1,-9] }
assert my_solution.maxBalancedSubsequenceSum(**test_input) == -1

test_input = { "nums": [-4,-9,3] }
assert my_solution.maxBalancedSubsequenceSum(**test_input) == 3

test_input = { "nums": [-4,-2,-7] }
assert my_solution.maxBalancedSubsequenceSum(**test_input) == -2

test_input = { "nums": [-3,-4,-2] }
assert my_solution.maxBalancedSubsequenceSum(**test_input) == -2

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

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

test_input = { "nums": [0,-6,-4] }
assert my_solution.maxBalancedSubsequenceSum(**test_input) == 0

test_input = { "nums": [0,-5,4] }
assert my_solution.maxBalancedSubsequenceSum(**test_input) == 4

test_input = { "nums": [1,-4,4] }
assert my_solution.maxBalancedSubsequenceSum(**test_input) == 5

test_input = { "nums": [4,1,-8] }
assert my_solution.maxBalancedSubsequenceSum(**test_input) == 4

test_input = { "nums": [5,-6,-8] }
assert my_solution.maxBalancedSubsequenceSum(**test_input) == 5

test_input = { "nums": [5,-4,-5] }
assert my_solution.maxBalancedSubsequenceSum(**test_input) == 5

test_input = { "nums": [6,-3,9] }
assert my_solution.maxBalancedSubsequenceSum(**test_input) == 15

test_input = { "nums": [6,0,2] }
assert my_solution.maxBalancedSubsequenceSum(**test_input) == 6

test_input = { "nums": [7,-6,0] }
assert my_solution.maxBalancedSubsequenceSum(**test_input) == 7

test_input = { "nums": [8,-7,2] }
assert my_solution.maxBalancedSubsequenceSum(**test_input) == 8

test_input = { "nums": [14,-21,-18] }
assert my_solution.maxBalancedSubsequenceSum(**test_input) == 14

test_input = { "nums": [-9,7,-8,1] }
assert my_solution.maxBalancedSubsequenceSum(**test_input) == 7

test_input = { "nums": [-8,2,-5,-7] }
assert my_solution.maxBalancedSubsequenceSum(**test_input) == 2

test_input = { "nums": [-7,1,-2,-8] }
assert my_solution.maxBalancedSubsequenceSum(**test_input) == 1

test_input = { "nums": [-6,-8,7,-3] }
assert my_solution.maxBalancedSubsequenceSum(**test_input) == 7

test_input = { "nums": [-5,-1,0,6] }
assert my_solution.maxBalancedSubsequenceSum(**test_input) == 6

test_input = { "nums": [-4,8,9,2] }
assert my_solution.maxBalancedSubsequenceSum(**test_input) == 17

test_input = { "nums": [-4,9,7,-4] }
assert my_solution.maxBalancedSubsequenceSum(**test_input) == 9

test_input = { "nums": [-2,-6,0,-5] }
assert my_solution.maxBalancedSubsequenceSum(**test_input) == 0

test_input = { "nums": [-2,-3,9,3] }
assert my_solution.maxBalancedSubsequenceSum(**test_input) == 9

test_input = { "nums": [0,-6,-3,5] }
assert my_solution.maxBalancedSubsequenceSum(**test_input) == 5

test_input = { "nums": [0,1,0,-2] }
assert my_solution.maxBalancedSubsequenceSum(**test_input) == 1

test_input = { "nums": [1,-7,-8,6] }
assert my_solution.maxBalancedSubsequenceSum(**test_input) == 7

test_input = { "nums": [3,-7,9,-3] }
assert my_solution.maxBalancedSubsequenceSum(**test_input) == 12

test_input = { "nums": [3,-7,9,2] }
assert my_solution.maxBalancedSubsequenceSum(**test_input) == 12

test_input = { "nums": [4,-8,-1,8] }
assert my_solution.maxBalancedSubsequenceSum(**test_input) == 12

test_input = { "nums": [5,4,1,0] }
assert my_solution.maxBalancedSubsequenceSum(**test_input) == 5

test_input = { "nums": [7,7,-9,-4] }
assert my_solution.maxBalancedSubsequenceSum(**test_input) == 7

test_input = { "nums": [8,0,4,-2] }
assert my_solution.maxBalancedSubsequenceSum(**test_input) == 8

test_input = { "nums": [9,7,-2,1] }
assert my_solution.maxBalancedSubsequenceSum(**test_input) == 9

test_input = { "nums": [34,34,32,33] }
assert my_solution.maxBalancedSubsequenceSum(**test_input) == 65

test_input = { "nums": [-9,-6,-8,-2,4] }
assert my_solution.maxBalancedSubsequenceSum(**test_input) == 4

test_input = { "nums": [-9,-5,2,2,7] }
assert my_solution.maxBalancedSubsequenceSum(**test_input) == 9

test_input = { "nums": [-9,-2,-6,0,6] }
assert my_solution.maxBalancedSubsequenceSum(**test_input) == 6

test_input = { "nums": [-7,0,-8,-9,-3] }
assert my_solution.maxBalancedSubsequenceSum(**test_input) == 0

test_input = { "nums": [-7,0,9,-4,9] }
assert my_solution.maxBalancedSubsequenceSum(**test_input) == 9

test_input = { "nums": [-6,-2,-8,-4,-8] }
assert my_solution.maxBalancedSubsequenceSum(**test_input) == -2

test_input = { "nums": [-6,2,-3,0,-5] }
assert my_solution.maxBalancedSubsequenceSum(**test_input) == 2

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

test_input = { "nums": [-5,-9,1,3,-5] }
assert my_solution.maxBalancedSubsequenceSum(**test_input) == 4

test_input = { "nums": [-5,1,5,-5,-1] }
assert my_solution.maxBalancedSubsequenceSum(**test_input) == 6

test_input = { "nums": [-3,7,0,4,6] }
assert my_solution.maxBalancedSubsequenceSum(**test_input) == 10

test_input = { "nums": [-2,-2,9,-2,-8] }
assert my_solution.maxBalancedSubsequenceSum(**test_input) == 9

test_input = { "nums": [0,-6,-9,-8,-3] }
assert my_solution.maxBalancedSubsequenceSum(**test_input) == 0

test_input = { "nums": [0,-2,-7,-1,-8] }
assert my_solution.maxBalancedSubsequenceSum(**test_input) == 0

test_input = { "nums": [0,-1,-4,-6,-9] }
assert my_solution.maxBalancedSubsequenceSum(**test_input) == 0

test_input = { "nums": [1,-3,-8,9,-9] }
assert my_solution.maxBalancedSubsequenceSum(**test_input) == 10

test_input = { "nums": [2,-6,-2,0,-3] }
assert my_solution.maxBalancedSubsequenceSum(**test_input) == 2

test_input = { "nums": [2,9,-4,4,2] }
assert my_solution.maxBalancedSubsequenceSum(**test_input) == 11

test_input = { "nums": [4,-1,5,-1,-7] }
assert my_solution.maxBalancedSubsequenceSum(**test_input) == 5

test_input = { "nums": [4,6,-8,-8,-5] }
assert my_solution.maxBalancedSubsequenceSum(**test_input) == 10


find-the-k-or-of-an-array

Find the K-or of an Array

Prompt:
"""
You are given a 0-indexed integer array nums, and an integer k.

The K-or of nums is a non-negative integer that satisfies the following:

 * The ith bit is set in the K-or if and only if there are at least k elements of nums in which bit i is set.

Return the K-or of nums.

Note that a bit i is set in x if (2i AND x) == 2i, where AND is the bitwise AND operator.

Example 1:

Input: nums = [7,12,9,8,9,15], k = 4
Output: 9
Explanation: Bit 0 is set at nums[0], nums[2], nums[4], and nums[5].
Bit 1 is set at nums[0], and nums[5].
Bit 2 is set at nums[0], nums[1], and nums[5].
Bit 3 is set at nums[1], nums[2], nums[3], nums[4], and nums[5].
Only bits 0 and 3 are set in at least k elements of the array, and bits i >= 4 are not set in any of the array's elements. Hence, the answer is 2^0 + 2^3 = 9.

Example 2:

Input: nums = [2,12,1,11,4,5], k = 6
Output: 0
Explanation: Since k == 6 == nums.length, the 6-or of the array is equal to the bitwise AND of all its elements. Hence, the answer is 2 AND 12 AND 1 AND 11 AND 4 AND 5 = 0.

Example 3:

Input: nums = [10,8,5,9,11,6,8], k = 1
Output: 15
Explanation: Since k == 1, the 1-or of the array is equal to the bitwise OR of all its elements. Hence, the answer is 10 OR 8 OR 5 OR 9 OR 11 OR 6 OR 8 = 15.

Constraints:

 * 1 <= nums.length <= 50
 * 0 <= nums[i] < 231
 * 1 <= k <= nums.length
"""
class Solution:
    def findKOr(self, nums: List[int], k: int) -> int:

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

The K-or of nums is a non-negative integer that satisfies the following:

 * The ith bit is set in the K-or if and only if there are at least k elements of nums in which bit i is set.

Return the K-or of nums.

Note that a bit i is set in x if (2i AND x) == 2i, where AND is the bitwise AND operator.

Example 1:

Input: nums = [7,12,9,8,9,15], k = 4
Output: 9
Explanation: Bit 0 is set at nums[0], nums[2], nums[4], and nums[5].
Bit 1 is set at nums[0], and nums[5].
Bit 2 is set at nums[0], nums[1], and nums[5].
Bit 3 is set at nums[1], nums[2], nums[3], nums[4], and nums[5].
Only bits 0 and 3 are set in at least k elements of the array, and bits i >= 4 are not set in any of the array's elements. Hence, the answer is 2^0 + 2^3 = 9.

Example 2:

Input: nums = [2,12,1,11,4,5], k = 6
Output: 0
Explanation: Since k == 6 == nums.length, the 6-or of the array is equal to the bitwise AND of all its elements. Hence, the answer is 2 AND 12 AND 1 AND 11 AND 4 AND 5 = 0.

Example 3:

Input: nums = [10,8,5,9,11,6,8], k = 1
Output: 15
Explanation: Since k == 1, the 1-or of the array is equal to the bitwise OR of all its elements. Hence, the answer is 10 OR 8 OR 5 OR 9 OR 11 OR 6 OR 8 = 15.

Constraints:

 * 1 <= nums.length <= 50
 * 0 <= nums[i] < 231
 * 1 <= k <= nums.length

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

```

my_solution = Solution()

test_input = { "nums": [7,12,9,8,9,15], "k": 4 }
assert my_solution.findKOr(**test_input) == 9

test_input = { "nums": [2,12,1,11,4,5], "k": 6 }
assert my_solution.findKOr(**test_input) == 0

test_input = { "nums": [10,8,5,9,11,6,8], "k": 1 }
assert my_solution.findKOr(**test_input) == 15

test_input = { "nums": [14,7,12,9,8,9,1,15], "k": 4 }
assert my_solution.findKOr(**test_input) == 13

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

test_input = { "nums": [10,8,5,10,11,11,6,8], "k": 1 }
assert my_solution.findKOr(**test_input) == 15

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

test_input = { "nums": [22,7,27,30,15,30,28], "k": 4 }
assert my_solution.findKOr(**test_input) == 30

test_input = { "nums": [24,18,3,23,16,11,27,18,5,29], "k": 6 }
assert my_solution.findKOr(**test_input) == 19

test_input = { "nums": [14,1,2,28,4,15,3,12], "k": 2 }
assert my_solution.findKOr(**test_input) == 15

test_input = { "nums": [7,18,25,11,2], "k": 5 }
assert my_solution.findKOr(**test_input) == 0

test_input = { "nums": [0,4], "k": 2 }
assert my_solution.findKOr(**test_input) == 0

test_input = { "nums": [17,5,14,16,24,30,3,19,31], "k": 1 }
assert my_solution.findKOr(**test_input) == 31

test_input = { "nums": [14,20,23,7,1,12,24,19], "k": 7 }
assert my_solution.findKOr(**test_input) == 0

test_input = { "nums": [5,31,29,22,8,6,23], "k": 4 }
assert my_solution.findKOr(**test_input) == 23

test_input = { "nums": [9,10,30,0,7,19,14,19,20,3], "k": 4 }
assert my_solution.findKOr(**test_input) == 31

test_input = { "nums": [25,6,5,30,27,11,10,30], "k": 2 }
assert my_solution.findKOr(**test_input) == 31

test_input = { "nums": [0,15,16,6,19,5,24,17], "k": 3 }
assert my_solution.findKOr(**test_input) == 23

test_input = { "nums": [19,8,2,28,4,5], "k": 5 }
assert my_solution.findKOr(**test_input) == 0

test_input = { "nums": [13,9,1,15,9,2,19,19], "k": 3 }
assert my_solution.findKOr(**test_input) == 11

test_input = { "nums": [16,6,16,22,8,2,25,30], "k": 1 }
assert my_solution.findKOr(**test_input) == 31

test_input = { "nums": [14,28,23,22], "k": 2 }
assert my_solution.findKOr(**test_input) == 30

test_input = { "nums": [6,26], "k": 2 }
assert my_solution.findKOr(**test_input) == 2

test_input = { "nums": [14,9,22,30,15], "k": 4 }
assert my_solution.findKOr(**test_input) == 14

test_input = { "nums": [12,13,16,25,12,4,8,29], "k": 6 }
assert my_solution.findKOr(**test_input) == 8

test_input = { "nums": [27,29], "k": 2 }
assert my_solution.findKOr(**test_input) == 25

test_input = { "nums": [9,27,27,20,24,13,25,8], "k": 6 }
assert my_solution.findKOr(**test_input) == 8

test_input = { "nums": [22,26,18,26,1], "k": 1 }
assert my_solution.findKOr(**test_input) == 31

test_input = { "nums": [20,20,31,19,29,19], "k": 2 }
assert my_solution.findKOr(**test_input) == 31

test_input = { "nums": [5,8,27,23,3], "k": 2 }
assert my_solution.findKOr(**test_input) == 31

test_input = { "nums": [4,23,0,20,4,19,14,22,26,2], "k": 9 }
assert my_solution.findKOr(**test_input) == 0

test_input = { "nums": [31,26,21,4,9,11,13,24,23,5], "k": 10 }
assert my_solution.findKOr(**test_input) == 0

test_input = { "nums": [4,22], "k": 2 }
assert my_solution.findKOr(**test_input) == 4

test_input = { "nums": [22,17,20,3,21,5,20,25,16], "k": 4 }
assert my_solution.findKOr(**test_input) == 21

test_input = { "nums": [16,15,13,26,15,23,0,12], "k": 4 }
assert my_solution.findKOr(**test_input) == 15

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

test_input = { "nums": [10,26,27,25,3,21,9,3,22], "k": 8 }
assert my_solution.findKOr(**test_input) == 0

test_input = { "nums": [4,11,16], "k": 2 }
assert my_solution.findKOr(**test_input) == 0

test_input = { "nums": [9,27,19,9,24,11], "k": 3 }
assert my_solution.findKOr(**test_input) == 27

test_input = { "nums": [29,19,27,14], "k": 1 }
assert my_solution.findKOr(**test_input) == 31

test_input = { "nums": [27,31,21,8,25], "k": 2 }
assert my_solution.findKOr(**test_input) == 31

test_input = { "nums": [14,1,13,22,27], "k": 5 }
assert my_solution.findKOr(**test_input) == 0

test_input = { "nums": [14,15,17,23,29], "k": 1 }
assert my_solution.findKOr(**test_input) == 31

test_input = { "nums": [19,21], "k": 2 }
assert my_solution.findKOr(**test_input) == 17

test_input = { "nums": [29,9,18,0,30,5,1,9], "k": 1 }
assert my_solution.findKOr(**test_input) == 31

test_input = { "nums": [6,31,11,7,6,2,26,19,17,13], "k": 10 }
assert my_solution.findKOr(**test_input) == 0

test_input = { "nums": [15,8,27,28], "k": 1 }
assert my_solution.findKOr(**test_input) == 31

test_input = { "nums": [28,24,20,31,23,1], "k": 2 }
assert my_solution.findKOr(**test_input) == 31

test_input = { "nums": [8,13,27,24,20,28,15,21,23,6], "k": 9 }
assert my_solution.findKOr(**test_input) == 0

test_input = { "nums": [31,6], "k": 2 }
assert my_solution.findKOr(**test_input) == 6

test_input = { "nums": [3,14,11,17,9], "k": 1 }
assert my_solution.findKOr(**test_input) == 31

test_input = { "nums": [14,11], "k": 2 }
assert my_solution.findKOr(**test_input) == 10

test_input = { "nums": [2,9,11,25,3,2,26,21,13,11], "k": 1 }
assert my_solution.findKOr(**test_input) == 31

test_input = { "nums": [26,7,23,0,16,31,12,18,24], "k": 4 }
assert my_solution.findKOr(**test_input) == 30

test_input = { "nums": [11,30,30,17,10,27,6,31,0], "k": 4 }
assert my_solution.findKOr(**test_input) == 31

test_input = { "nums": [11,9,18,30,27,20,2,17,18,4], "k": 2 }
assert my_solution.findKOr(**test_input) == 31

test_input = { "nums": [2,1,0,30,29,14,13,26,10,22], "k": 10 }
assert my_solution.findKOr(**test_input) == 0

test_input = { "nums": [21,30,30,17,23,8,26,9], "k": 6 }
assert my_solution.findKOr(**test_input) == 16

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

test_input = { "nums": [26,12,19,22,5,6,19,30,24,11], "k": 10 }
assert my_solution.findKOr(**test_input) == 0

test_input = { "nums": [20,10,14], "k": 2 }
assert my_solution.findKOr(**test_input) == 14

test_input = { "nums": [23,17,18,30,3], "k": 1 }
assert my_solution.findKOr(**test_input) == 31

test_input = { "nums": [13,16,12], "k": 1 }
assert my_solution.findKOr(**test_input) == 29

test_input = { "nums": [17,12,5,13,23,19], "k": 3 }
assert my_solution.findKOr(**test_input) == 21

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

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

test_input = { "nums": [28,3,15,30,10,29], "k": 4 }
assert my_solution.findKOr(**test_input) == 14

test_input = { "nums": [0,31,13,24,16,21], "k": 3 }
assert my_solution.findKOr(**test_input) == 29

test_input = { "nums": [11,20,28,29,3,4], "k": 2 }
assert my_solution.findKOr(**test_input) == 31


minimum-equal-sum-of-two-arrays-after-replacing-zeros

Minimum Equal Sum of Two Arrays After Replacing Zeros

Prompt:
"""
You are given two arrays nums1 and nums2 consisting of positive integers.

You have to replace all the 0's in both arrays with strictly positive integers such that the sum of elements of both arrays becomes equal.

Return the minimum equal sum you can obtain, or -1 if it is impossible.

Example 1:

Input: nums1 = [3,2,0,1,0], nums2 = [6,5,0]
Output: 12
Explanation: We can replace 0's in the following way:
- Replace the two 0's in nums1 with the values 2 and 4. The resulting array is nums1 = [3,2,2,1,4].
- Replace the 0 in nums2 with the value 1. The resulting array is nums2 = [6,5,1].
Both arrays have an equal sum of 12. It can be shown that it is the minimum sum we can obtain.

Example 2:

Input: nums1 = [2,0,2,0], nums2 = [1,4]
Output: -1
Explanation: It is impossible to make the sum of both arrays equal.

Constraints:

 * 1 <= nums1.length, nums2.length <= 105
 * 0 <= nums1[i], nums2[i] <= 106
"""
class Solution:
    def minSum(self, nums1: List[int], nums2: List[int]) -> int:

You are given two arrays nums1 and nums2 consisting of positive integers.

You have to replace all the 0's in both arrays with strictly positive integers such that the sum of elements of both arrays becomes equal.

Return the minimum equal sum you can obtain, or -1 if it is impossible.

Example 1:

Input: nums1 = [3,2,0,1,0], nums2 = [6,5,0]
Output: 12
Explanation: We can replace 0's in the following way:
- Replace the two 0's in nums1 with the values 2 and 4. The resulting array is nums1 = [3,2,2,1,4].
- Replace the 0 in nums2 with the value 1. The resulting array is nums2 = [6,5,1].
Both arrays have an equal sum of 12. It can be shown that it is the minimum sum we can obtain.

Example 2:

Input: nums1 = [2,0,2,0], nums2 = [1,4]
Output: -1
Explanation: It is impossible to make the sum of both arrays equal.

Constraints:

 * 1 <= nums1.length, nums2.length <= 105
 * 0 <= nums1[i], nums2[i] <= 106

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

```


minimum-increment-operations-to-make-array-beautiful

Minimum Increment Operations to Make Array Beautiful

Prompt:
"""
You are given a 0-indexed integer array nums having length n, and an integer k.

You can perform the following increment operation any number of times (including zero):

 * Choose an index i in the range [0, n - 1], and increase nums[i] by 1.

An array is considered beautiful if, for any subarray with a size of 3 or more, its maximum element is greater than or equal to k.

Return an integer denoting the minimum number of increment operations needed to make nums beautiful.

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

Example 1:

Input: nums = [2,3,0,0,2], k = 4
Output: 3
Explanation: We can perform the following increment operations to make nums beautiful:
Choose index i = 1 and increase nums[1] by 1 -> [2,4,0,0,2].
Choose index i = 4 and increase nums[4] by 1 -> [2,4,0,0,3].
Choose index i = 4 and increase nums[4] by 1 -> [2,4,0,0,4].
The subarrays with a size of 3 or more are: [2,4,0], [4,0,0], [0,0,4], [2,4,0,0], [4,0,0,4], [2,4,0,0,4].
In all the subarrays, the maximum element is equal to k = 4, so nums is now beautiful.
It can be shown that nums cannot be made beautiful with fewer than 3 increment operations.
Hence, the answer is 3.

Example 2:

Input: nums = [0,1,3,3], k = 5
Output: 2
Explanation: We can perform the following increment operations to make nums beautiful:
Choose index i = 2 and increase nums[2] by 1 -> [0,1,4,3].
Choose index i = 2 and increase nums[2] by 1 -> [0,1,5,3].
The subarrays with a size of 3 or more are: [0,1,5], [1,5,3], [0,1,5,3].
In all the subarrays, the maximum element is equal to k = 5, so nums is now beautiful.
It can be shown that nums cannot be made beautiful with fewer than 2 increment operations.
Hence, the answer is 2.

Example 3:

Input: nums = [1,1,2], k = 1
Output: 0
Explanation: The only subarray with a size of 3 or more in this example is [1,1,2].
The maximum element, 2, is already greater than k = 1, so we don't need any increment operation.
Hence, the answer is 0.

Constraints:

 * 3 <= n == nums.length <= 105
 * 0 <= nums[i] <= 109
 * 0 <= k <= 109
"""
class Solution:
    def minIncrementOperations(self, nums: List[int], k: int) -> int:

You are given a 0-indexed integer array nums having length n, and an integer k.

You can perform the following increment operation any number of times (including zero):

 * Choose an index i in the range [0, n - 1], and increase nums[i] by 1.

An array is considered beautiful if, for any subarray with a size of 3 or more, its maximum element is greater than or equal to k.

Return an integer denoting the minimum number of increment operations needed to make nums beautiful.

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

Example 1:

Input: nums = [2,3,0,0,2], k = 4
Output: 3
Explanation: We can perform the following increment operations to make nums beautiful:
Choose index i = 1 and increase nums[1] by 1 -> [2,4,0,0,2].
Choose index i = 4 and increase nums[4] by 1 -> [2,4,0,0,3].
Choose index i = 4 and increase nums[4] by 1 -> [2,4,0,0,4].
The subarrays with a size of 3 or more are: [2,4,0], [4,0,0], [0,0,4], [2,4,0,0], [4,0,0,4], [2,4,0,0,4].
In all the subarrays, the maximum element is equal to k = 4, so nums is now beautiful.
It can be shown that nums cannot be made beautiful with fewer than 3 increment operations.
Hence, the answer is 3.

Example 2:

Input: nums = [0,1,3,3], k = 5
Output: 2
Explanation: We can perform the following increment operations to make nums beautiful:
Choose index i = 2 and increase nums[2] by 1 -> [0,1,4,3].
Choose index i = 2 and increase nums[2] by 1 -> [0,1,5,3].
The subarrays with a size of 3 or more are: [0,1,5], [1,5,3], [0,1,5,3].
In all the subarrays, the maximum element is equal to k = 5, so nums is now beautiful.
It can be shown that nums cannot be made beautiful with fewer than 2 increment operations.
Hence, the answer is 2.

Example 3:

Input: nums = [1,1,2], k = 1
Output: 0
Explanation: The only subarray with a size of 3 or more in this example is [1,1,2].
The maximum element, 2, is already greater than k = 1, so we don't need any increment operation.
Hence, the answer is 0.

Constraints:

 * 3 <= n == nums.length <= 105
 * 0 <= nums[i] <= 109
 * 0 <= k <= 109

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

```

my_solution = Solution()

test_input = { "nums": [2,3,0,0,2], "k": 4 }
assert my_solution.minIncrementOperations(**test_input) == 3

test_input = { "nums": [0,1,3,3], "k": 5 }
assert my_solution.minIncrementOperations(**test_input) == 2

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

test_input = { "nums": [0,5,5], "k": 8 }
assert my_solution.minIncrementOperations(**test_input) == 3

test_input = { "nums": [0,18,28], "k": 93 }
assert my_solution.minIncrementOperations(**test_input) == 65

test_input = { "nums": [0,24,14], "k": 7 }
assert my_solution.minIncrementOperations(**test_input) == 0

test_input = { "nums": [2,3,4], "k": 3 }
assert my_solution.minIncrementOperations(**test_input) == 0

test_input = { "nums": [3,5,9], "k": 6 }
assert my_solution.minIncrementOperations(**test_input) == 0

test_input = { "nums": [4,3,0], "k": 2 }
assert my_solution.minIncrementOperations(**test_input) == 0

test_input = { "nums": [5,6,5], "k": 9 }
assert my_solution.minIncrementOperations(**test_input) == 3

test_input = { "nums": [6,9,6], "k": 3 }
assert my_solution.minIncrementOperations(**test_input) == 0

test_input = { "nums": [7,9,0], "k": 6 }
assert my_solution.minIncrementOperations(**test_input) == 0

test_input = { "nums": [7,47,16], "k": 39 }
assert my_solution.minIncrementOperations(**test_input) == 0

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

test_input = { "nums": [41,44,37], "k": 55 }
assert my_solution.minIncrementOperations(**test_input) == 11

test_input = { "nums": [48,3,13], "k": 1 }
assert my_solution.minIncrementOperations(**test_input) == 0

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

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

test_input = { "nums": [2,35,41,20], "k": 4 }
assert my_solution.minIncrementOperations(**test_input) == 0

test_input = { "nums": [3,9,9,7], "k": 6 }
assert my_solution.minIncrementOperations(**test_input) == 0

test_input = { "nums": [7,7,2,7], "k": 9 }
assert my_solution.minIncrementOperations(**test_input) == 2

test_input = { "nums": [10,2,0,2], "k": 6 }
assert my_solution.minIncrementOperations(**test_input) == 4

test_input = { "nums": [20,2,22,30], "k": 67 }
assert my_solution.minIncrementOperations(**test_input) == 45

test_input = { "nums": [22,49,0,20], "k": 52 }
assert my_solution.minIncrementOperations(**test_input) == 3

test_input = { "nums": [25,2,1,41], "k": 9 }
assert my_solution.minIncrementOperations(**test_input) == 0

test_input = { "nums": [31,86,1,2], "k": 354 }
assert my_solution.minIncrementOperations(**test_input) == 268

test_input = { "nums": [43,31,14,4], "k": 73 }
assert my_solution.minIncrementOperations(**test_input) == 42

test_input = { "nums": [44,24,28,47], "k": 16 }
assert my_solution.minIncrementOperations(**test_input) == 0

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

test_input = { "nums": [3,7,9,6,0], "k": 7 }
assert my_solution.minIncrementOperations(**test_input) == 0

test_input = { "nums": [5,9,0,10,3], "k": 3 }
assert my_solution.minIncrementOperations(**test_input) == 0

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

test_input = { "nums": [6,14,17,4,7], "k": 22 }
assert my_solution.minIncrementOperations(**test_input) == 5

test_input = { "nums": [10,9,5,2,4], "k": 1 }
assert my_solution.minIncrementOperations(**test_input) == 0

test_input = { "nums": [20,38,29,34,6], "k": 95 }
assert my_solution.minIncrementOperations(**test_input) == 66

test_input = { "nums": [21,45,33,14,22], "k": 58 }
assert my_solution.minIncrementOperations(**test_input) == 25

test_input = { "nums": [32,14,31,43,29], "k": 46 }
assert my_solution.minIncrementOperations(**test_input) == 15

test_input = { "nums": [39,21,10,46,40], "k": 81 }
assert my_solution.minIncrementOperations(**test_input) == 71

test_input = { "nums": [42,7,32,19,4], "k": 66 }
assert my_solution.minIncrementOperations(**test_input) == 34

test_input = { "nums": [74,91,93,96,12], "k": 964 }
assert my_solution.minIncrementOperations(**test_input) == 871

test_input = { "nums": [84,17,58,61,72], "k": 432 }
assert my_solution.minIncrementOperations(**test_input) == 374

test_input = { "nums": [4,0,10,2,10,6], "k": 8 }
assert my_solution.minIncrementOperations(**test_input) == 0

test_input = { "nums": [4,0,22,41,29,28], "k": 30 }
assert my_solution.minIncrementOperations(**test_input) == 8

test_input = { "nums": [4,1,8,0,3,9], "k": 2 }
assert my_solution.minIncrementOperations(**test_input) == 0

test_input = { "nums": [4,7,6,9,2,6], "k": 1 }
assert my_solution.minIncrementOperations(**test_input) == 0

test_input = { "nums": [5,1,3,9,8,8], "k": 4 }
assert my_solution.minIncrementOperations(**test_input) == 0

test_input = { "nums": [6,5,8,6,0,9], "k": 9 }
assert my_solution.minIncrementOperations(**test_input) == 1

test_input = { "nums": [7,4,10,2,0,8], "k": 7 }
assert my_solution.minIncrementOperations(**test_input) == 0

test_input = { "nums": [8,10,7,1,9,6], "k": 1 }
assert my_solution.minIncrementOperations(**test_input) == 0

test_input = { "nums": [9,5,0,10,9,0], "k": 8 }
assert my_solution.minIncrementOperations(**test_input) == 0

test_input = { "nums": [13,34,0,13,9,19], "k": 82 }
assert my_solution.minIncrementOperations(**test_input) == 117

test_input = { "nums": [16,50,23,35,38,13], "k": 34 }
assert my_solution.minIncrementOperations(**test_input) == 0

test_input = { "nums": [20,1,40,48,32,24], "k": 38 }
assert my_solution.minIncrementOperations(**test_input) == 0

test_input = { "nums": [28,5,10,26,38,6], "k": 17 }
assert my_solution.minIncrementOperations(**test_input) == 0

test_input = { "nums": [30,42,46,45,23,31], "k": 13 }
assert my_solution.minIncrementOperations(**test_input) == 0

test_input = { "nums": [3,8,0,6,46,24,31], "k": 30 }
assert my_solution.minIncrementOperations(**test_input) == 22

test_input = { "nums": [4,7,2,10,4,10,5], "k": 10 }
assert my_solution.minIncrementOperations(**test_input) == 3

test_input = { "nums": [8,10,1,5,8,9,7], "k": 4 }
assert my_solution.minIncrementOperations(**test_input) == 0

test_input = { "nums": [10,7,2,5,9,6,3], "k": 2 }
assert my_solution.minIncrementOperations(**test_input) == 0

test_input = { "nums": [10,24,21,42,6,10,43], "k": 55 }
assert my_solution.minIncrementOperations(**test_input) == 56

test_input = { "nums": [18,48,1,19,43,25,49], "k": 21 }
assert my_solution.minIncrementOperations(**test_input) == 0

test_input = { "nums": [37,82,95,82,77,87,93], "k": 239 }
assert my_solution.minIncrementOperations(**test_input) == 296

test_input = { "nums": [40,17,28,38,41,32,9], "k": 97 }
assert my_solution.minIncrementOperations(**test_input) == 125

test_input = { "nums": [41,22,4,41,4,47,36], "k": 25 }
assert my_solution.minIncrementOperations(**test_input) == 0

test_input = { "nums": [42,19,52,36,8,5,9], "k": 656 }
assert my_solution.minIncrementOperations(**test_input) == 1252

test_input = { "nums": [45,58,6,16,70,69,87], "k": 26 }
assert my_solution.minIncrementOperations(**test_input) == 0

test_input = { "nums": [48,24,41,16,4,20,38], "k": 97 }
assert my_solution.minIncrementOperations(**test_input) == 133

test_input = { "nums": [50,3,17,36,16,10,2], "k": 19 }
assert my_solution.minIncrementOperations(**test_input) == 3

test_input = { "nums": [57,41,90,16,41,25,2], "k": 934 }
assert my_solution.minIncrementOperations(**test_input) == 1737

test_input = { "nums": [74,33,13,74,75,95,11], "k": 426 }
assert my_solution.minIncrementOperations(**test_input) == 744

test_input = { "nums": [83,54,75,22,32,59,30], "k": 298 }
assert my_solution.minIncrementOperations(**test_input) == 462

test_input = { "nums": [1,9,3,6,3,1,10,4], "k": 2 }
assert my_solution.minIncrementOperations(**test_input) == 0

test_input = { "nums": [1,29,18,3,38,4,7,47], "k": 67 }
assert my_solution.minIncrementOperations(**test_input) == 87

test_input = { "nums": [2,1,1,7,2,3,5,6], "k": 9 }
assert my_solution.minIncrementOperations(**test_input) == 13

test_input = { "nums": [2,3,6,3,0,0,7,4], "k": 8 }
assert my_solution.minIncrementOperations(**test_input) == 8

test_input = { "nums": [2,9,6,9,1,9,4,0], "k": 6 }
assert my_solution.minIncrementOperations(**test_input) == 0

test_input = { "nums": [5,1,6,9,5,4,9,2], "k": 10 }
assert my_solution.minIncrementOperations(**test_input) == 6

test_input = { "nums": [5,10,8,7,6,7,1,10], "k": 3 }
assert my_solution.minIncrementOperations(**test_input) == 0

test_input = { "nums": [6,7,9,5,0,2,7,7], "k": 1 }
assert my_solution.minIncrementOperations(**test_input) == 0

test_input = { "nums": [7,2,2,6,7,5,0,2], "k": 3 }
assert my_solution.minIncrementOperations(**test_input) == 0

test_input = { "nums": [7,12,36,8,27,48,39,35], "k": 36 }
assert my_solution.minIncrementOperations(**test_input) == 0

test_input = { "nums": [15,47,34,46,42,26,23,11], "k": 15 }
assert my_solution.minIncrementOperations(**test_input) == 0

test_input = { "nums": [19,40,43,32,15,7,43,5], "k": 85 }
assert my_solution.minIncrementOperations(**test_input) == 120

test_input = { "nums": [22,45,6,7,7,23,6,3], "k": 43 }
assert my_solution.minIncrementOperations(**test_input) == 56

test_input = { "nums": [25,1,70,71,54,96,46,77], "k": 549 }
assert my_solution.minIncrementOperations(**test_input) == 932

test_input = { "nums": [33,41,14,18,43,20,49,23], "k": 25 }
assert my_solution.minIncrementOperations(**test_input) == 0

test_input = { "nums": [39,26,16,36,19,5,6,28], "k": 98 }
assert my_solution.minIncrementOperations(**test_input) == 175

test_input = { "nums": [44,44,31,36,1,8,39,46], "k": 45 }
assert my_solution.minIncrementOperations(**test_input) == 16

test_input = { "nums": [2,17,43,26,33,12,37,28,34], "k": 3 }
assert my_solution.minIncrementOperations(**test_input) == 0

test_input = { "nums": [3,1,6,1,0,5,4,5,7], "k": 10 }
assert my_solution.minIncrementOperations(**test_input) == 12

test_input = { "nums": [3,10,4,2,9,8,2,1,4], "k": 7 }
assert my_solution.minIncrementOperations(**test_input) == 3

test_input = { "nums": [7,5,4,7,6,5,10,8,8], "k": 8 }
assert my_solution.minIncrementOperations(**test_input) == 2

test_input = { "nums": [7,40,36,45,42,23,10,33,17], "k": 25 }
assert my_solution.minIncrementOperations(**test_input) == 0

test_input = { "nums": [10,4,7,4,8,7,8,4,6], "k": 3 }
assert my_solution.minIncrementOperations(**test_input) == 0

test_input = { "nums": [12,32,12,13,18,38,21,15,13], "k": 95 }
assert my_solution.minIncrementOperations(**test_input) == 214

test_input = { "nums": [17,50,14,27,10,37,24,35,23], "k": 45 }
assert my_solution.minIncrementOperations(**test_input) == 36

test_input = { "nums": [20,17,29,44,18,20,17,26,2], "k": 1 }
assert my_solution.minIncrementOperations(**test_input) == 0

test_input = { "nums": [28,4,38,38,37,13,47,48,49], "k": 61 }
assert my_solution.minIncrementOperations(**test_input) == 60

test_input = { "nums": [29,0,34,5,5,24,43,23,27], "k": 98 }
assert my_solution.minIncrementOperations(**test_input) == 193

test_input = { "nums": [41,53,77,44,79,66,2,46,64], "k": 204 }
assert my_solution.minIncrementOperations(**test_input) == 405


maximum-points-after-collecting-coins-from-all-nodes

Maximum Points After Collecting Coins From All Nodes

Prompt:
"""
There exists an undirected tree rooted at node 0 with n nodes labeled from 0 to n - 1. You are given a 2D integer array edges of length n - 1, where edges[i] = [ai, bi] indicates that there is an edge between nodes ai and bi in the tree. You are also given a 0-indexed array coins of size n where coins[i] indicates the number of coins in the vertex i, and an integer k.

Starting from the root, you have to collect all the coins such that the coins at a node can only be collected if the coins of its ancestors have been already collected.

Coins at nodei can be collected in one of the following ways:

 * Collect all the coins, but you will get coins[i] - k points. If coins[i] - k is negative then you will lose abs(coins[i] - k) points.
 * Collect all the coins, but you will get floor(coins[i] / 2) points. If this way is used, then for all the nodej present in the subtree of nodei, coins[j] will get reduced to floor(coins[j] / 2).

Return the maximum points you can get after collecting the coins from all the tree nodes.

Example 1:

[https://assets.leetcode.com/uploads/2023/09/18/ex1-copy.png]

Input: edges = [[0,1],[1,2],[2,3]], coins = [10,10,3,3], k = 5
Output: 11
Explanation:
Collect all the coins from node 0 using the first way. Total points = 10 - 5 = 5.
Collect all the coins from node 1 using the first way. Total points = 5 + (10 - 5) = 10.
Collect all the coins from node 2 using the second way so coins left at node 3 will be floor(3 / 2) = 1. Total points = 10 + floor(3 / 2) = 11.
Collect all the coins from node 3 using the second way. Total points = 11 + floor(1 / 2) = 11.
It can be shown that the maximum points we can get after collecting coins from all the nodes is 11.

Example 2:

[https://assets.leetcode.com/uploads/2023/09/18/ex2.png]

Input: edges = [[0,1],[0,2]], coins = [8,4,4], k = 0
Output: 16
Explanation:
Coins will be collected from all the nodes using the first way. Therefore, total points = (8 - 0) + (4 - 0) + (4 - 0) = 16.

Constraints:

 * n == coins.length
 * 2 <= n <= 105
 * 0 <= coins[i] <= 104
 * edges.length == n - 1
 * 0 <= edges[i][0], edges[i][1] < n
 * 0 <= k <= 104
"""
class Solution:
    def maximumPoints(self, edges: List[List[int]], coins: List[int], k: int) -> int:

There exists an undirected tree rooted at node 0 with n nodes labeled from 0 to n - 1. You are given a 2D integer array edges of length n - 1, where edges[i] = [ai, bi] indicates that there is an edge between nodes ai and bi in the tree. You are also given a 0-indexed array coins of size n where coins[i] indicates the number of coins in the vertex i, and an integer k.

Starting from the root, you have to collect all the coins such that the coins at a node can only be collected if the coins of its ancestors have been already collected.

Coins at nodei can be collected in one of the following ways:

 * Collect all the coins, but you will get coins[i] - k points. If coins[i] - k is negative then you will lose abs(coins[i] - k) points.
 * Collect all the coins, but you will get floor(coins[i] / 2) points. If this way is used, then for all the nodej present in the subtree of nodei, coins[j] will get reduced to floor(coins[j] / 2).

Return the maximum points you can get after collecting the coins from all the tree nodes.

Example 1:

[https://assets.leetcode.com/uploads/2023/09/18/ex1-copy.png]

Input: edges = [[0,1],[1,2],[2,3]], coins = [10,10,3,3], k = 5
Output: 11
Explanation:
Collect all the coins from node 0 using the first way. Total points = 10 - 5 = 5.
Collect all the coins from node 1 using the first way. Total points = 5 + (10 - 5) = 10.
Collect all the coins from node 2 using the second way so coins left at node 3 will be floor(3 / 2) = 1. Total points = 10 + floor(3 / 2) = 11.
Collect all the coins from node 3 using the second way. Total points = 11 + floor(1 / 2) = 11.
It can be shown that the maximum points we can get after collecting coins from all the nodes is 11.

Example 2:

[https://assets.leetcode.com/uploads/2023/09/18/ex2.png]

Input: edges = [[0,1],[0,2]], coins = [8,4,4], k = 0
Output: 16
Explanation:
Coins will be collected from all the nodes using the first way. Therefore, total points = (8 - 0) + (4 - 0) + (4 - 0) = 16.

Constraints:

 * n == coins.length
 * 2 <= n <= 105
 * 0 <= coins[i] <= 104
 * edges.length == n - 1
 * 0 <= edges[i][0], edges[i][1] < n
 * 0 <= k <= 104

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

```


subarrays-distinct-element-sum-of-squares-i

Subarrays Distinct Element Sum of Squares I

Prompt:
"""
You are given a 0-indexed integer array nums.

The distinct count of a subarray of nums is defined as:

 * Let nums[i..j] be a subarray of nums consisting of all the indices from i to j such that 0 <= i <= j < nums.length. Then the number of distinct values in nums[i..j] is called the distinct count of nums[i..j].

Return the sum of the squares of distinct counts of all subarrays of nums.

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

Example 1:

Input: nums = [1,2,1]
Output: 15
Explanation: Six possible subarrays are:
[1]: 1 distinct value
[2]: 1 distinct value
[1]: 1 distinct value
[1,2]: 2 distinct values
[2,1]: 2 distinct values
[1,2,1]: 2 distinct values
The sum of the squares of the distinct counts in all subarrays is equal to 12 + 12 + 12 + 22 + 22 + 22 = 15.

Example 2:

Input: nums = [1,1]
Output: 3
Explanation: Three possible subarrays are:
[1]: 1 distinct value
[1]: 1 distinct value
[1,1]: 1 distinct value
The sum of the squares of the distinct counts in all subarrays is equal to 12 + 12 + 12 = 3.

Constraints:

 * 1 <= nums.length <= 100
 * 1 <= nums[i] <= 100
"""
class Solution:
    def sumCounts(self, nums: List[int]) -> int:

You are given a 0-indexed integer array nums.

The distinct count of a subarray of nums is defined as:

 * Let nums[i..j] be a subarray of nums consisting of all the indices from i to j such that 0 <= i <= j < nums.length. Then the number of distinct values in nums[i..j] is called the distinct count of nums[i..j].

Return the sum of the squares of distinct counts of all subarrays of nums.

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

Example 1:

Input: nums = [1,2,1]
Output: 15
Explanation: Six possible subarrays are:
[1]: 1 distinct value
[2]: 1 distinct value
[1]: 1 distinct value
[1,2]: 2 distinct values
[2,1]: 2 distinct values
[1,2,1]: 2 distinct values
The sum of the squares of the distinct counts in all subarrays is equal to 12 + 12 + 12 + 22 + 22 + 22 = 15.

Example 2:

Input: nums = [1,1]
Output: 3
Explanation: Three possible subarrays are:
[1]: 1 distinct value
[1]: 1 distinct value
[1,1]: 1 distinct value
The sum of the squares of the distinct counts in all subarrays is equal to 12 + 12 + 12 = 3.

Constraints:

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

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

```

my_solution = Solution()

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

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

test_input = { "nums": [2,2,5,5] }
assert my_solution.sumCounts(**test_input) == 22

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

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

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

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

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

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

test_input = { "nums": [4,4,2,4,1] }
assert my_solution.sumCounts(**test_input) == 57

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

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

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

test_input = { "nums": [2,5,2,5,3,2,5,2] }
assert my_solution.sumCounts(**test_input) == 205

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

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

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

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

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

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

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

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

test_input = { "nums": [2,5] }
assert my_solution.sumCounts(**test_input) == 6

test_input = { "nums": [1,5,1,4,5] }
assert my_solution.sumCounts(**test_input) == 70

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

test_input = { "nums": [4,5,4,3,3,5,3] }
assert my_solution.sumCounts(**test_input) == 138

test_input = { "nums": [5,4,3] }
assert my_solution.sumCounts(**test_input) == 20

test_input = { "nums": [5,5,3,3,4,5,4,5,5] }
assert my_solution.sumCounts(**test_input) == 234

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

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

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

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

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

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

test_input = { "nums": [2,4] }
assert my_solution.sumCounts(**test_input) == 6

test_input = { "nums": [4,5,4,5] }
assert my_solution.sumCounts(**test_input) == 28

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

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

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

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

test_input = { "nums": [1,1,3,3,3,4,4] }
assert my_solution.sumCounts(**test_input) == 96

test_input = { "nums": [3,2,2,3,4] }
assert my_solution.sumCounts(**test_input) == 57

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

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

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

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

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

test_input = { "nums": [5,4,4,1] }
assert my_solution.sumCounts(**test_input) == 30

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

test_input = { "nums": [5,3] }
assert my_solution.sumCounts(**test_input) == 6

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

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

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

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

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

test_input = { "nums": [1,4,4,1,3] }
assert my_solution.sumCounts(**test_input) == 57

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

test_input = { "nums": [1,4,2,1] }
assert my_solution.sumCounts(**test_input) == 43

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

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

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

test_input = { "nums": [4,3,1,4,3,4,3,4,1] }
assert my_solution.sumCounts(**test_input) == 263

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

test_input = { "nums": [4,5] }
assert my_solution.sumCounts(**test_input) == 6

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

test_input = { "nums": [3,2,4] }
assert my_solution.sumCounts(**test_input) == 20

test_input = { "nums": [5,3,5,2,3,2] }
assert my_solution.sumCounts(**test_input) == 106

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

test_input = { "nums": [4,4,2,4,3] }
assert my_solution.sumCounts(**test_input) == 57

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

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

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

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

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

test_input = { "nums": [5,3,4,4,3,5,4,5] }
assert my_solution.sumCounts(**test_input) == 202

test_input = { "nums": [4,4,2,2,4,1] }
assert my_solution.sumCounts(**test_input) == 80

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

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

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

test_input = { "nums": [4,1,5,1,5,4,5,1] }
assert my_solution.sumCounts(**test_input) == 205

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

test_input = { "nums": [4,2,3,4,2,4,3,3,2] }
assert my_solution.sumCounts(**test_input) == 275

test_input = { "nums": [4,3] }
assert my_solution.sumCounts(**test_input) == 6

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

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

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

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

test_input = { "nums": [5,4,5] }
assert my_solution.sumCounts(**test_input) == 15

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

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

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

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

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

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

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

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

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

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

test_input = { "nums": [3,2,3] }
assert my_solution.sumCounts(**test_input) == 15

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


minimum-number-of-changes-to-make-binary-string-beautiful

Minimum Number of Changes to Make Binary String Beautiful

Prompt:
"""
You are given a 0-indexed binary string s having an even length.

A string is beautiful if it's possible to partition it into one or more substrings such that:

 * Each substring has an even length.
 * Each substring contains only 1's or only 0's.

You can change any character in s to 0 or 1.

Return the minimum number of changes required to make the string s beautiful.

Example 1:

Input: s = "1001"
Output: 2
Explanation: We change s[1] to 1 and s[3] to 0 to get string "1100".
It can be seen that the string "1100" is beautiful because we can partition it into "11|00".
It can be proven that 2 is the minimum number of changes needed to make the string beautiful.

Example 2:

Input: s = "10"
Output: 1
Explanation: We change s[1] to 1 to get string "11".
It can be seen that the string "11" is beautiful because we can partition it into "11".
It can be proven that 1 is the minimum number of changes needed to make the string beautiful.

Example 3:

Input: s = "0000"
Output: 0
Explanation: We don't need to make any changes as the string "0000" is beautiful already.

Constraints:

 * 2 <= s.length <= 105
 * s has an even length.
 * s[i] is either '0' or '1'.
"""
class Solution:
    def minChanges(self, s: str) -> int:

You are given a 0-indexed binary string s having an even length.

A string is beautiful if it's possible to partition it into one or more substrings such that:

 * Each substring has an even length.
 * Each substring contains only 1's or only 0's.

You can change any character in s to 0 or 1.

Return the minimum number of changes required to make the string s beautiful.

Example 1:

Input: s = "1001"
Output: 2
Explanation: We change s[1] to 1 and s[3] to 0 to get string "1100".
It can be seen that the string "1100" is beautiful because we can partition it into "11|00".
It can be proven that 2 is the minimum number of changes needed to make the string beautiful.

Example 2:

Input: s = "10"
Output: 1
Explanation: We change s[1] to 1 to get string "11".
It can be seen that the string "11" is beautiful because we can partition it into "11".
It can be proven that 1 is the minimum number of changes needed to make the string beautiful.

Example 3:

Input: s = "0000"
Output: 0
Explanation: We don't need to make any changes as the string "0000" is beautiful already.

Constraints:

 * 2 <= s.length <= 105
 * s has an even length.
 * s[i] is either '0' or '1'.

Please complete the code below to solve above prblem:
```python
class Solution:
    def minChanges(self, s: str) -> int:

```

my_solution = Solution()

test_input = { "s": "1001" }
assert my_solution.minChanges(**test_input) == 2

test_input = { "s": "10" }
assert my_solution.minChanges(**test_input) == 1

test_input = { "s": "0000" }
assert my_solution.minChanges(**test_input) == 0

test_input = { "s": "11000111" }
assert my_solution.minChanges(**test_input) == 1

test_input = { "s": "01010001" }
assert my_solution.minChanges(**test_input) == 3

test_input = { "s": "010010" }
assert my_solution.minChanges(**test_input) == 2

test_input = { "s": "111111111110010001" }
assert my_solution.minChanges(**test_input) == 3

test_input = { "s": "01010000011001001101" }
assert my_solution.minChanges(**test_input) == 6

test_input = { "s": "011011100001110111" }
assert my_solution.minChanges(**test_input) == 5

test_input = { "s": "1001000010111010" }
assert my_solution.minChanges(**test_input) == 5

test_input = { "s": "0011" }
assert my_solution.minChanges(**test_input) == 0

test_input = { "s": "11100100010010" }
assert my_solution.minChanges(**test_input) == 4

test_input = { "s": "110100" }
assert my_solution.minChanges(**test_input) == 1

test_input = { "s": "01" }
assert my_solution.minChanges(**test_input) == 1

test_input = { "s": "10110010" }
assert my_solution.minChanges(**test_input) == 2

test_input = { "s": "0010" }
assert my_solution.minChanges(**test_input) == 1

test_input = { "s": "01000011000111" }
assert my_solution.minChanges(**test_input) == 2

test_input = { "s": "0001110001" }
assert my_solution.minChanges(**test_input) == 2

test_input = { "s": "000000001010100011" }
assert my_solution.minChanges(**test_input) == 3

test_input = { "s": "100001" }
assert my_solution.minChanges(**test_input) == 2

test_input = { "s": "10010010" }
assert my_solution.minChanges(**test_input) == 3

test_input = { "s": "101100" }
assert my_solution.minChanges(**test_input) == 1

test_input = { "s": "000010" }
assert my_solution.minChanges(**test_input) == 1

test_input = { "s": "011011000001100011" }
assert my_solution.minChanges(**test_input) == 4

test_input = { "s": "01101111" }
assert my_solution.minChanges(**test_input) == 2

test_input = { "s": "000000011101" }
assert my_solution.minChanges(**test_input) == 2

test_input = { "s": "011011011111111011" }
assert my_solution.minChanges(**test_input) == 4

test_input = { "s": "110011" }
assert my_solution.minChanges(**test_input) == 0

test_input = { "s": "1111101111101011" }
assert my_solution.minChanges(**test_input) == 3

test_input = { "s": "11000101011001100110" }
assert my_solution.minChanges(**test_input) == 8

test_input = { "s": "101101101110110010" }
assert my_solution.minChanges(**test_input) == 5

test_input = { "s": "11011110" }
assert my_solution.minChanges(**test_input) == 2

test_input = { "s": "1011100101" }
assert my_solution.minChanges(**test_input) == 4

test_input = { "s": "0011000101001000" }
assert my_solution.minChanges(**test_input) == 3

test_input = { "s": "00" }
assert my_solution.minChanges(**test_input) == 0

test_input = { "s": "10110111010001000010" }
assert my_solution.minChanges(**test_input) == 5

test_input = { "s": "0101" }
assert my_solution.minChanges(**test_input) == 2

test_input = { "s": "0010101100" }
assert my_solution.minChanges(**test_input) == 2

test_input = { "s": "11001110101001" }
assert my_solution.minChanges(**test_input) == 4

test_input = { "s": "010101000011011111" }
assert my_solution.minChanges(**test_input) == 4

test_input = { "s": "0010111010000001" }
assert my_solution.minChanges(**test_input) == 4

test_input = { "s": "0000010101" }
assert my_solution.minChanges(**test_input) == 3

test_input = { "s": "10100011101010" }
assert my_solution.minChanges(**test_input) == 5

test_input = { "s": "101111" }
assert my_solution.minChanges(**test_input) == 1

test_input = { "s": "11" }
assert my_solution.minChanges(**test_input) == 0

test_input = { "s": "110110" }
assert my_solution.minChanges(**test_input) == 2

test_input = { "s": "001001110111010101" }
assert my_solution.minChanges(**test_input) == 6

test_input = { "s": "11110011" }
assert my_solution.minChanges(**test_input) == 0

test_input = { "s": "1100000101101110" }
assert my_solution.minChanges(**test_input) == 4

test_input = { "s": "111010" }
assert my_solution.minChanges(**test_input) == 2

test_input = { "s": "100000100010011100" }
assert my_solution.minChanges(**test_input) == 4

test_input = { "s": "0111" }
assert my_solution.minChanges(**test_input) == 1

test_input = { "s": "0100110011111101" }
assert my_solution.minChanges(**test_input) == 2

test_input = { "s": "010111" }
assert my_solution.minChanges(**test_input) == 2

test_input = { "s": "000100" }
assert my_solution.minChanges(**test_input) == 1

test_input = { "s": "00110111000111110001" }
assert my_solution.minChanges(**test_input) == 3

test_input = { "s": "01010010" }
assert my_solution.minChanges(**test_input) == 3

test_input = { "s": "01110101001001" }
assert my_solution.minChanges(**test_input) == 5

test_input = { "s": "00111100010111" }
assert my_solution.minChanges(**test_input) == 2

test_input = { "s": "001110" }
assert my_solution.minChanges(**test_input) == 1

test_input = { "s": "00010101111101" }
assert my_solution.minChanges(**test_input) == 4

test_input = { "s": "111011" }
assert my_solution.minChanges(**test_input) == 1

test_input = { "s": "011110" }
assert my_solution.minChanges(**test_input) == 2

test_input = { "s": "1010" }
assert my_solution.minChanges(**test_input) == 2

test_input = { "s": "011101010011101011" }
assert my_solution.minChanges(**test_input) == 5

test_input = { "s": "1001110001111100" }
assert my_solution.minChanges(**test_input) == 3

test_input = { "s": "011000101100" }
assert my_solution.minChanges(**test_input) == 3

test_input = { "s": "1110111000111111" }
assert my_solution.minChanges(**test_input) == 2

test_input = { "s": "1110" }
assert my_solution.minChanges(**test_input) == 1

test_input = { "s": "10110110" }
assert my_solution.minChanges(**test_input) == 3

test_input = { "s": "1000" }
assert my_solution.minChanges(**test_input) == 1

test_input = { "s": "0111110110" }
assert my_solution.minChanges(**test_input) == 3

test_input = { "s": "011000011101" }
assert my_solution.minChanges(**test_input) == 4

test_input = { "s": "0100101000010101" }
assert my_solution.minChanges(**test_input) == 6

test_input = { "s": "0100001100" }
assert my_solution.minChanges(**test_input) == 1

test_input = { "s": "100010010010110001" }
assert my_solution.minChanges(**test_input) == 5

test_input = { "s": "101001111001111001" }
assert my_solution.minChanges(**test_input) == 7

test_input = { "s": "111001" }
assert my_solution.minChanges(**test_input) == 2

test_input = { "s": "111010001000" }
assert my_solution.minChanges(**test_input) == 3

test_input = { "s": "0110" }
assert my_solution.minChanges(**test_input) == 2

test_input = { "s": "11011010" }
assert my_solution.minChanges(**test_input) == 3

test_input = { "s": "100111" }
assert my_solution.minChanges(**test_input) == 2

test_input = { "s": "11000110000001" }
assert my_solution.minChanges(**test_input) == 3

test_input = { "s": "010111010011011000" }
assert my_solution.minChanges(**test_input) == 5

test_input = { "s": "000101" }
assert my_solution.minChanges(**test_input) == 2

test_input = { "s": "000010101010101011" }
assert my_solution.minChanges(**test_input) == 6

test_input = { "s": "11011000" }
assert my_solution.minChanges(**test_input) == 2

test_input = { "s": "010101" }
assert my_solution.minChanges(**test_input) == 3

test_input = { "s": "10011010110110101100" }
assert my_solution.minChanges(**test_input) == 7

test_input = { "s": "10100011" }
assert my_solution.minChanges(**test_input) == 2

test_input = { "s": "11010100000000" }
assert my_solution.minChanges(**test_input) == 2

test_input = { "s": "101100101111010011" }
assert my_solution.minChanges(**test_input) == 3

test_input = { "s": "110111111100" }
assert my_solution.minChanges(**test_input) == 1

test_input = { "s": "111110110100" }
assert my_solution.minChanges(**test_input) == 2

test_input = { "s": "011110110101010100" }
assert my_solution.minChanges(**test_input) == 6

test_input = { "s": "000111" }
assert my_solution.minChanges(**test_input) == 1

test_input = { "s": "00000010001101" }
assert my_solution.minChanges(**test_input) == 2

test_input = { "s": "01111001101001" }
assert my_solution.minChanges(**test_input) == 6

test_input = { "s": "010110011101" }
assert my_solution.minChanges(**test_input) == 5

test_input = { "s": "0111011101" }
assert my_solution.minChanges(**test_input) == 3