Prompt:
def makeTheIntegerZero(num1: int, num2: int) -> int:
    """
    You are given two integers num1 and num2.
    In one operation, you can choose integer i in the range [0, 60] and subtract 2i + num2 from num1.
    Return the integer denoting the minimum number of operations needed to make num1 equal to 0.
    If it is impossible to make num1 equal to 0, return -1.

    Example 1:

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

    Example 2:

    >>> makeTheIntegerZero(num1 = 5, num2 = 7)
    >>> -1
    Explanation: It can be proven, that it is impossible to make 5 equal to 0 with the given operation.
    """


Prompt:
def numberOfGoodSubarraySplits(nums: List[int]) -> int:
    """
    You are given a binary array nums.
    A subarray of an array is good if it contains exactly one element with the value 1.
    Return an integer denoting the number of ways to split the array nums into good subarrays. As the number may be too large, return it modulo 109 + 7.
    A subarray is a contiguous non-empty sequence of elements within an array.

    Example 1:

    >>> numberOfGoodSubarraySplits(nums = [0,1,0,0,1])
    >>> 3
    Explanation: There are 3 ways to split nums into good subarrays:
    - [0,1] [0,0,1]
    - [0,1,0] [0,1]
    - [0,1,0,0] [1]

    Example 2:

    >>> numberOfGoodSubarraySplits(nums = [0,1,0])
    >>> 1
    Explanation: There is 1 way to split nums into good subarrays:
    - [0,1,0]
    """


Prompt:
def survivedRobotsHealths(positions: List[int], healths: List[int], directions: str) -> List[int]:
    """
    There are n 1-indexed robots, each having a position on a line, health, and movement direction.
    You are given 0-indexed integer arrays positions, healths, and a string directions (directions[i] is either 'L' for left or 'R' for right). All integers in positions are unique.
    All robots start moving on the line simultaneously at the same speed in their given directions. If two robots ever share the same position while moving, they will collide.
    If two robots collide, the robot with lower health is removed from the line, and the health of the other robot decreases by one. The surviving robot continues in the same direction it was going. If both robots have the same health, they are both removed from the line.
    Your task is to determine the health of the robots that survive the collisions, in the same order that the robots were given, i.e. final health of robot 1 (if survived), final health of robot 2 (if survived), and so on. If there are no survivors, return an empty array.
    Return an array containing the health of the remaining robots (in the order they were given in the input), after no further collisions can occur.
    Note: The positions may be unsorted.

    Example 1:

    >>> survivedRobotsHealths(positions = [5,4,3,2,1], healths = [2,17,9,15,10], directions = "RRRRR")
    >>> [2,17,9,15,10]
    Explanation: No collision occurs in this example, since all robots are moving in the same direction. So, the health of the robots in order from the first robot is returned, [2, 17, 9, 15, 10].

    Example 2:

    >>> survivedRobotsHealths(positions = [3,5,2,6], healths = [10,10,15,12], directions = "RLRL")
    >>> [14]
    Explanation: There are 2 collisions in this example. Firstly, robot 1 and robot 2 will collide, and since both have the same health, they will be removed from the line. Next, robot 3 and robot 4 will collide and since robot 4's health is smaller, it gets removed, and robot 3's health becomes 15 - 1 = 14. Only robot 3 remains, so we return [14].

    Example 3:

    >>> survivedRobotsHealths(positions = [1,2,5,6], healths = [10,10,11,11], directions = "RLRL")
    >>> []
    Explanation: Robot 1 and robot 2 will collide and since both have the same health, they are both removed. Robot 3 and 4 will collide and since both have the same health, they are both removed. So, we return an empty array, [].
    """


Prompt:
def longestAlternatingSubarray(nums: List[int], threshold: int) -> int:
    """
    You are given a 0-indexed integer array nums and an integer threshold.
    Find the length of the longest subarray of nums starting at index l and ending at index r (0 <= l <= r < nums.length) that satisfies the following conditions:

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

    Return an integer denoting the length of the longest such subarray.
    Note: A subarray is a contiguous non-empty sequence of elements within an array.

    Example 1:

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

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

    Example 3:

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


Prompt:
def findPrimePairs(n: int) -> List[List[int]]:
    """
    You are given an integer n. We say that two integers x and y form a prime number pair if:

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

    Return the 2D sorted list of prime number pairs [xi, yi]. The list should be sorted in increasing order of xi. If there are no prime number pairs at all, return an empty array.
    Note: A prime number is a natural number greater than 1 with only two factors, itself and 1.

    Example 1:

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

    Example 2:

    >>> findPrimePairs(n = 2)
    >>> []
    Explanation: We can show that there is no prime number pair that gives a sum of 2, so we return an empty array.
    """


Prompt:
def continuousSubarrays(nums: List[int]) -> int:
    """
    You are given a 0-indexed integer array nums. A subarray of nums is called continuous if:

    Let i, i + 1, ..., j be the indices in the subarray. Then, for each pair of indices i <= i1, i2 <= j, 0 <= |nums[i1] - nums[i2]| <= 2.

    Return the total number of continuous subarrays.
    A subarray is a contiguous non-empty sequence of elements within an array.

    Example 1:

    >>> continuousSubarrays(nums = [5,4,2,4])
    >>> 8
    Explanation:
    Continuous subarray of size 1: [5], [4], [2], [4].
    Continuous subarray of size 2: [5,4], [4,2], [2,4].
    Continuous subarray of size 3: [4,2,4].
    There are no subarrys of size 4.
    Total continuous subarrays = 4 + 3 + 1 = 8.
    It can be shown that there are no more continuous subarrays.

    Example 2:

    >>> continuousSubarrays(nums = [1,2,3])
    >>> 6
    Explanation:
    Continuous subarray of size 1: [1], [2], [3].
    Continuous subarray of size 2: [1,2], [2,3].
    Continuous subarray of size 3: [1,2,3].
    Total continuous subarrays = 3 + 2 + 1 = 6.
    """


Prompt:
def sumImbalanceNumbers(nums: List[int]) -> int:
    """
    The imbalance number of a 0-indexed integer array arr of length n is defined as the number of indices in sarr = sorted(arr) such that:

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

    Here, sorted(arr) is the function that returns the sorted version of arr.
    Given a 0-indexed integer array nums, return the sum of imbalance numbers of all its subarrays.
    A subarray is a contiguous non-empty sequence of elements within an array.

    Example 1:

    >>> sumImbalanceNumbers(nums = [2,3,1,4])
    >>> 3
    Explanation: There are 3 subarrays with non-zero imbalance numbers:
    - Subarray [3, 1] with an imbalance number of 1.
    - Subarray [3, 1, 4] with an imbalance number of 1.
    - Subarray [1, 4] with an imbalance number of 1.
    The imbalance number of all other subarrays is 0. Hence, the sum of imbalance numbers of all the subarrays of nums is 3.

    Example 2:

    >>> sumImbalanceNumbers(nums = [1,3,3,3,5])
    >>> 8
    Explanation: There are 7 subarrays with non-zero imbalance numbers:
    - Subarray [1, 3] with an imbalance number of 1.
    - Subarray [1, 3, 3] with an imbalance number of 1.
    - Subarray [1, 3, 3, 3] with an imbalance number of 1.
    - Subarray [1, 3, 3, 3, 5] with an imbalance number of 2.
    - Subarray [3, 3, 3, 5] with an imbalance number of 1.
    - Subarray [3, 3, 5] with an imbalance number of 1.
    - Subarray [3, 5] with an imbalance number of 1.
    The imbalance number of all other subarrays is 0. Hence, the sum of imbalance numbers of all the subarrays of nums is 8.
    """


Prompt:
def isPreorder(nodes: List[List[int]]) -> bool:
    """
    Given a 0-indexed integer 2D array nodes, your task is to determine if the given array represents the preorder traversal of some binary tree.
    For each index i, nodes[i] = [id, parentId], where id is the id of the node at the index i and parentId is the id of its parent in the tree (if the node has no parent, then parentId == -1).
    Return true if the given array represents the preorder traversal of some tree, and false otherwise.
    Note: the preorder traversal of a tree is a recursive way to traverse a tree in which we first visit the current node, then we do the preorder traversal for the left child, and finally, we do it for the right child.

    Example 1:

    >>> isPreorder(nodes = [[0,-1],[1,0],[2,0],[3,2],[4,2]])
    >>> true
    Explanation: The given nodes make the tree in the picture below.
    We can show that this is the preorder traversal of the tree, first we visit node 0, then we do the preorder traversal of the right child which is [1], then we do the preorder traversal of the left child which is [2,3,4].

    Example 2:

    >>> isPreorder(nodes = [[0,-1],[1,0],[2,0],[3,1],[4,1]])
    >>> false
    Explanation: The given nodes make the tree in the picture below.
    For the preorder traversal, first we visit node 0, then we do the preorder traversal of the right child which is [1,3,4], but we can see that in the given order, 2 comes between 1 and 3, so, it's not the preorder traversal of the tree.
    """


Prompt:
def alternatingSubarray(nums: List[int]) -> int:
    """
    You are given a 0-indexed integer array nums. A subarray s of length m is called alternating if:

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

    Return the maximum length of all alternating subarrays present in nums or -1 if no such subarray exists.
    A subarray is a contiguous non-empty sequence of elements within an array.

    Example 1:

    >>> alternatingSubarray(nums = [2,3,4,3,4])
    >>> 4
    Explanation:
    The alternating subarrays are [2, 3], [3,4], [3,4,3], and [3,4,3,4]. The longest of these is [3,4,3,4], which is of length 4.

    Example 2:

    >>> alternatingSubarray(nums = [4,5,6])
    >>> 2
    Explanation:
    [4,5] and [5,6] are the only two alternating subarrays. They are both of length 2.
    """


Prompt:
def relocateMarbles(nums: List[int], moveFrom: List[int], moveTo: List[int]) -> List[int]:
    """
    You are given a 0-indexed integer array nums representing the initial positions of some marbles. You are also given two 0-indexed integer arrays moveFrom and moveTo of equal length.
    Throughout moveFrom.length steps, you will change the positions of the marbles. On the ith step, you will move all marbles at position moveFrom[i] to position moveTo[i].
    After completing all the steps, return the sorted list of occupied positions.
    Notes:

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

    Example 1:

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

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


Prompt:
def minimumBeautifulSubstrings(s: str) -> int:
    """
    Given a binary string s, partition the string into one or more substrings such that each substring is beautiful.
    A string is beautiful if:

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

    Return the minimum number of substrings in such partition. If it is impossible to partition the string s into beautiful substrings, return -1.
    A substring is a contiguous sequence of characters in a string.

    Example 1:

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

    Example 2:

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

    Example 3:

    >>> minimumBeautifulSubstrings(s = "0")
    >>> -1
    Explanation: We can not partition the given string into beautiful substrings.
    """


Prompt:
def countBlackBlocks(m: int, n: int, coordinates: List[List[int]]) -> List[int]:
    """
    You are given two integers m and n representing the dimensions of a 0-indexed m x n grid.
    You are also given a 0-indexed 2D integer matrix coordinates, where coordinates[i] = [x, y] indicates that the cell with coordinates [x, y] is colored black. All cells in the grid that do not appear in coordinates are white.
    A block is defined as a 2 x 2 submatrix of the grid. More formally, a block with cell [x, y] as its top-left corner where 0 <= x < m - 1 and 0 <= y < n - 1 contains the coordinates [x, y], [x + 1, y], [x, y + 1], and [x + 1, y + 1].
    Return a 0-indexed integer array arr of size 5 such that arr[i] is the number of blocks that contains exactly i black cells.

    Example 1:

    >>> countBlackBlocks(m = 3, n = 3, coordinates = [[0,0]])
    >>> [3,1,0,0,0]
    Explanation: The grid looks like this:

    There is only 1 block with one black cell, and it is the block starting with cell [0,0].
    The other 3 blocks start with cells [0,1], [1,0] and [1,1]. They all have zero black cells.
    Thus, we return [3,1,0,0,0].

    Example 2:

    >>> countBlackBlocks(m = 3, n = 3, coordinates = [[0,0],[1,1],[0,2]])
    >>> [0,2,2,0,0]
    Explanation: The grid looks like this:

    There are 2 blocks with two black cells (the ones starting with cell coordinates [0,0] and [0,1]).
    The other 2 blocks have starting cell coordinates of [1,0] and [1,1]. They both have 1 black cell.
    Therefore, we return [0,2,2,0,0].
    """


Prompt:
def theMaximumAchievableX(num: int, t: int) -> int:
    """
    Given two integers, num and t. A number x is achievable if it can become equal to num after applying the following operation at most t times:

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

    Return the maximum possible value of x.

    Example 1:

    >>> theMaximumAchievableX(num = 4, t = 1)
    >>> 6
    Explanation:
    Apply the following operation once to make the maximum achievable number equal to num:

    Decrease the maximum achievable number by 1, and increase num by 1.

    Example 2:

    >>> theMaximumAchievableX(num = 3, t = 2)
    >>> 7
    Explanation:
    Apply the following operation twice to make the maximum achievable number equal to num:

    Decrease the maximum achievable number by 1, and increase num by 1.
    """


Prompt:
def maximumJumps(nums: List[int], target: int) -> int:
    """
    You are given a 0-indexed array nums of n integers and an integer target.
    You are initially positioned at index 0. In one step, you can jump from index i to any index j such that:

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

    Return the maximum number of jumps you can make to reach index n - 1.
    If there is no way to reach index n - 1, return -1.

    Example 1:

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

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

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


Prompt:
def maxNonDecreasingLength(nums1: List[int], nums2: List[int]) -> int:
    """
    You are given two 0-indexed integer arrays nums1 and nums2 of length n.
    Let's define another 0-indexed integer array, nums3, of length n. For each index i in the range [0, n - 1], you can assign either nums1[i] or nums2[i] to nums3[i].
    Your task is to maximize the length of the longest non-decreasing subarray in nums3 by choosing its values optimally.
    Return an integer representing the length of the longest non-decreasing subarray in nums3.
    Note: A subarray is a contiguous non-empty sequence of elements within an array.

    Example 1:

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

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

    Example 3:

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


Prompt:
def checkArray(nums: List[int], k: int) -> bool:
    """
    You are given a 0-indexed integer array nums and a positive integer k.
    You can apply the following operation on the array any number of times:

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

    Return true if you can make all the array elements equal to 0, or false otherwise.
    A subarray is a contiguous non-empty part of an array.

    Example 1:

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

    Example 2:

    >>> checkArray(nums = [1,3,1,1], k = 2)
    >>> false
    Explanation: It is not possible to make all the array elements equal to 0.
    """


Prompt:
# class TreeNode:
#     def __init__(val=0, left=None, right=None):
#         self.val = val
#         self.left = left
#         self.right = right
class Solution:
    def heightOfTree(root: Optional[TreeNode]) -> int:
    """
    You are given a root, which is the root of a special binary tree with n nodes. The nodes of the special binary tree are numbered from 1 to n. Suppose the tree has k leaves in the following order: b1 < b2 < ... < bk.
    The leaves of this tree have a special property! That is, for every leaf bi, the following conditions hold:

    The right child of bi is bi + 1 if i < k, and b1 otherwise.
    The left child of bi is bi - 1 if i > 1, and bk otherwise.

    Return the height of the given tree.
    Note: The height of a binary tree is the length of the longest path from the root to any other node.

    Example 1:

    >>> __init__(root = [1,2,3,null,null,4,5])
    >>> 2
    Explanation: The given tree is shown in the following picture. Each leaf's left child is the leaf to its left (shown with the blue edges). Each leaf's right child is the leaf to its right (shown with the red edges). We can see that the graph has a height of 2.

    Example 2:

    >>> __init__(root = [1,2])
    >>> 1
    Explanation: The given tree is shown in the following picture. There is only one leaf, so it doesn't have any left or right child. We can see that the graph has a height of 1.

    Example 3:

    >>> __init__(root = [1,2,3,null,null,4,null,5,6])
    >>> 3
    Explanation: The given tree is shown in the following picture. Each leaf's left child is the leaf to its left (shown with the blue edges). Each leaf's right child is the leaf to its right (shown with the red edges). We can see that the graph has a height of 3.
    """


Prompt:
def sumOfSquares(nums: List[int]) -> int:
    """
    You are given a 1-indexed integer array nums of length n.
    An element nums[i] of nums is called special if i divides n, i.e. n % i == 0.
    Return the sum of the squares of all special elements of nums.

    Example 1:

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

    Example 2:

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


Prompt:
def maximumBeauty(nums: List[int], k: int) -> int:
    """
    You are given a 0-indexed array nums and a non-negative integer k.
    In one operation, you can do the following:

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

    The beauty of the array is the length of the longest subsequence consisting of equal elements.
    Return the maximum possible beauty of the array nums after applying the operation any number of times.
    Note that you can apply the operation to each index only once.
    A subsequence of an array is a new array generated from the original array by deleting some elements (possibly none) without changing the order of the remaining elements.

    Example 1:

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

    Example 2:

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


Prompt:
def minimumIndex(nums: List[int]) -> int:
    """
    An element x of an integer array arr of length m is dominant if more than half the elements of arr have a value of x.
    You are given a 0-indexed integer array nums of length n with one dominant element.
    You can split nums at an index i into two arrays nums[0, ..., i] and nums[i + 1, ..., n - 1], but the split is only valid if:

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

    Here, nums[i, ..., j] denotes the subarray of nums starting at index i and ending at index j, both ends being inclusive. Particularly, if j < i then nums[i, ..., j] denotes an empty subarray.
    Return the minimum index of a valid split. If no valid split exists, return -1.

    Example 1:

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

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

    >>> minimumIndex(nums = [3,3,3,3,7,2,2])
    >>> -1
    Explanation: It can be shown that there is no valid split.
    """


Prompt:
def longestValidSubstring(word: str, forbidden: List[str]) -> int:
    """
    You are given a string word and an array of strings forbidden.
    A string is called valid if none of its substrings are present in forbidden.
    Return the length of the longest valid substring of the string word.
    A substring is a contiguous sequence of characters in a string, possibly empty.

    Example 1:

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

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


Prompt:
# class CategoryHandler:
#     def haveSameCategory(a: int, b: int) -> bool:
#         pass
class Solution:
    def numberOfCategories(n: int, categoryHandler: Optional['CategoryHandler']) -> int:
    """
    You are given an integer n and an object categoryHandler of class CategoryHandler.
    There are n elements, numbered from 0 to n - 1. Each element has a category, and your task is to find the number of unique categories.
    The class CategoryHandler contains the following function, which may help you:

    boolean haveSameCategory(integer a, integer b): Returns true if a and b are in the same category and false otherwise. Also, if either a or b is not a valid number (i.e. it's greater than or equal to nor less than 0), it returns false.

    Return the number of unique categories.

    Example 1:

    >>> haveSameCategory(n = 6, categoryHandler = [1,1,2,2,3,3])
    >>> 3
    Explanation: There are 6 elements in this example. The first two elements belong to category 1, the second two belong to category 2, and the last two elements belong to category 3. So there are 3 unique categories.

    Example 2:

    >>> haveSameCategory(n = 5, categoryHandler = [1,2,3,4,5])
    >>> 5
    Explanation: There are 5 elements in this example. Each element belongs to a unique category. So there are 5 unique categories.

    Example 3:

    >>> haveSameCategory(n = 3, categoryHandler = [1,1,1])
    >>> 1
    Explanation: There are 3 elements in this example. All of them belong to one category. So there is only 1 unique category.
    """


Prompt:
def isGood(nums: List[int]) -> bool:
    """
    You are given an integer array nums. We consider an array good if it is a permutation of an array base[n].
    base[n] = [1, 2, ..., n - 1, n, n] (in other words, it is an array of length n + 1 which contains 1 to n - 1 exactly once, plus two occurrences of n). For example, base[1] = [1, 1] and base[3] = [1, 2, 3, 3].
    Return true if the given array is good, otherwise return false.
    Note: A permutation of integers represents an arrangement of these numbers.

    Example 1:

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

    Example 2:

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

    >>> isGood(nums = [1, 1])
    >>> true
    Explanation: Since the maximum element of the array is 1, the only candidate n for which this array could be a permutation of base[n], is n = 1. It can be seen that nums is a permutation of base[1] = [1, 1]. Therefore, the answer is true.
    Example 4:

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


Prompt:
def sortVowels(s: str) -> str:
    """
    Given a 0-indexed string s, permute s to get a new string t such that:

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

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

    Example 1:

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

    Example 2:

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


Prompt:
def maxScore(nums: List[int], x: int) -> int:
    """
    You are given a 0-indexed integer array nums and a positive integer x.
    You are initially at position 0 in the array and you can visit other positions according to the following rules:

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

    Return the maximum total score you can get.
    Note that initially you have nums[0] points.

    Example 1:

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

    Example 2:

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


Prompt:
def numberOfWays(n: int, x: int) -> int:
    """
    Given two positive integers n and x.
    Return the number of ways n can be expressed as the sum of the xth power of unique positive integers, in other words, the number of sets of unique integers [n1, n2, ..., nk] where n = n1x + n2x + ... + nkx.
    Since the result can be very large, return it modulo 109 + 7.
    For example, if n = 160 and x = 3, one way to express n is n = 23 + 33 + 53.

    Example 1:

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

    Example 2:

    >>> numberOfWays(n = 4, x = 1)
    >>> 2
    Explanation: We can express n in the following ways:
    - n = 41 = 4.
    - n = 31 + 11 = 4.
    """


Prompt:
def splitWordsBySeparator(words: List[str], separator: str) -> List[str]:
    """
    Given an array of strings words and a character separator, split each string in words by separator.
    Return an array of strings containing the new strings formed after the splits, excluding empty strings.
    Notes

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

    Example 1:

    >>> splitWordsBySeparator(words = ["one.two.three","four.five","six"], separator = ".")
    >>> ["one","two","three","four","five","six"]
    Explanation: In this example we split as follows:

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

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

    >>> splitWordsBySeparator(words = ["$easy$","$problem$"], separator = "$")
    >>> ["easy","problem"]
    Explanation: In this example we split as follows:

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

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

    Example 3:

    >>> splitWordsBySeparator(words = ["|||"], separator = "|")
    >>> []
    Explanation: In this example the resulting split of "|||" will contain only empty strings, so we return an empty array [].
    """


Prompt:
def maxArrayValue(nums: List[int]) -> int:
    """
    You are given a 0-indexed array nums consisting of positive integers.
    You can do the following operation on the array any number of times:

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

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

    Example 1:

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

    Example 2:

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


Prompt:
def maxIncreasingGroups(usageLimits: List[int]) -> int:
    """
    You are given a 0-indexed array usageLimits of length n.
    Your task is to create groups using numbers from 0 to n - 1, ensuring that each number, i, is used no more than usageLimits[i] times in total across all groups. You must also satisfy the following conditions:

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

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

    Example 1:

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

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

    Example 3:

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


Prompt:
def countPalindromePaths(parent: List[int], s: str) -> int:
    """
    You are given a tree (i.e. a connected, undirected graph that has no cycles) rooted at node 0 consisting of n nodes numbered from 0 to n - 1. The tree is represented by a 0-indexed array parent of size n, where parent[i] is the parent of node i. Since node 0 is the root, parent[0] == -1.
    You are also given a string s of length n, where s[i] is the character assigned to the edge between i and parent[i]. s[0] can be ignored.
    Return the number of pairs of nodes (u, v) such that u < v and the characters assigned to edges on the path from u to v can be rearranged to form a palindrome.
    A string is a palindrome when it reads the same backwards as forwards.

    Example 1:

    >>> countPalindromePaths(parent = [-1,0,0,1,1,2], s = "acaabc")
    >>> 8
    Explanation: The valid pairs are:
    - All the pairs (0,1), (0,2), (1,3), (1,4) and (2,5) result in one character which is always a palindrome.
    - The pair (2,3) result in the string "aca" which is a palindrome.
    - The pair (1,5) result in the string "cac" which is a palindrome.
    - The pair (3,5) result in the string "acac" which can be rearranged into the palindrome "acca".

    Example 2:

    >>> countPalindromePaths(parent = [-1,0,0,0,0], s = "aaaaa")
    >>> 10
    Explanation: Any pair of nodes (u,v) where u < v is valid.
    """


Prompt:
# class TreeNode:
#     def __init__(val=0, left=None, right=None):
#         self.val = val
#         self.left = left
#         self.right = right
class Solution:
    def countGreatEnoughNodes(root: Optional[TreeNode], k: int) -> int:
    """
    You are given a root to a binary tree and an integer k. A node of this tree is called great enough if the followings hold:

    Its subtree has at least k nodes.
    Its value is greater than the value of at least k nodes in its subtree.

    Return the number of nodes in this tree that are great enough.
    The node u is in the subtree of the node v, if u == v or v is an ancestor of u.

    Example 1:

    >>> __init__(root = [7,6,5,4,3,2,1], k = 2)
    >>> 3
    Explanation: Number the nodes from 1 to 7.
    The values in the subtree of node 1: {1,2,3,4,5,6,7}. Since node.val == 7, there are 6 nodes having a smaller value than its value. So it's great enough.
    The values in the subtree of node 2: {3,4,6}. Since node.val == 6, there are 2 nodes having a smaller value than its value. So it's great enough.
    The values in the subtree of node 3: {1,2,5}. Since node.val == 5, there are 2 nodes having a smaller value than its value. So it's great enough.
    It can be shown that other nodes are not great enough.
    See the picture below for a better understanding.

    Example 2:

    >>> __init__(root = [1,2,3], k = 1)
    >>> 0
    Explanation: Number the nodes from 1 to 3.
    The values in the subtree of node 1: {1,2,3}. Since node.val == 1, there are no nodes having a smaller value than its value. So it's not great enough.
    The values in the subtree of node 2: {2}. Since node.val == 2, there are no nodes having a smaller value than its value. So it's not great enough.
    The values in the subtree of node 3: {3}. Since node.val == 3, there are no nodes having a smaller value than its value. So it's not great enough.
    See the picture below for a better understanding.

    Example 3:

    >>> __init__(root = [3,2,2], k = 2)
    >>> 1
    Explanation: Number the nodes from 1 to 3.
    The values in the subtree of node 1: {2,2,3}. Since node.val == 3, there are 2 nodes having a smaller value than its value. So it's great enough.
    The values in the subtree of node 2: {2}. Since node.val == 2, there are no nodes having a smaller value than its value. So it's not great enough.
    The values in the subtree of node 3: {2}. Since node.val == 2, there are no nodes having a smaller value than its value. So it's not great enough.
    See the picture below for a better understanding.
    """


Prompt:
def numberOfEmployeesWhoMetTarget(hours: List[int], target: int) -> int:
    """
    There are n employees in a company, numbered from 0 to n - 1. Each employee i has worked for hours[i] hours in the company.
    The company requires each employee to work for at least target hours.
    You are given a 0-indexed array of non-negative integers hours of length n and a non-negative integer target.
    Return the integer denoting the number of employees who worked at least target hours.

    Example 1:

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

    Example 2:

    >>> numberOfEmployeesWhoMetTarget(hours = [5,1,4,2,2], target = 6)
    >>> 0
    Explanation: The company wants each employee to work for at least 6 hours.
    There are 0 employees who met the target.
    """


Prompt:
def countCompleteSubarrays(nums: List[int]) -> int:
    """
    You are given an array nums consisting of positive integers.
    We call a subarray of an array complete if the following condition is satisfied:

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

    Return the number of complete subarrays.
    A subarray is a contiguous non-empty part of an array.

    Example 1:

    >>> countCompleteSubarrays(nums = [1,3,1,2,2])
    >>> 4
    Explanation: The complete subarrays are the following: [1,3,1,2], [1,3,1,2,2], [3,1,2] and [3,1,2,2].

    Example 2:

    >>> countCompleteSubarrays(nums = [5,5,5,5])
    >>> 10
    Explanation: The array consists only of the integer 5, so any subarray is complete. The number of subarrays that we can choose is 10.
    """


Prompt:
def minimumString(a: str, b: str, c: str) -> str:
    """
    Given three strings a, b, and c, your task is to find a string that has the minimum length and contains all three strings as substrings.
    If there are multiple such strings, return the lexicographically smallest one.
    Return a string denoting the answer to the problem.
    Notes

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

    Example 1:

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

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


Prompt:
def countSteppingNumbers(low: str, high: str) -> int:
    """
    Given two positive integers low and high represented as strings, find the count of stepping numbers in the inclusive range [low, high].
    A stepping number is an integer such that all of its adjacent digits have an absolute difference of exactly 1.
    Return an integer denoting the count of stepping numbers in the inclusive range [low, high].
    Since the answer may be very large, return it modulo 109 + 7.
    Note: A stepping number should not have a leading zero.

    Example 1:

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

    >>> countSteppingNumbers(low = "90", high = "101")
    >>> 2
    Explanation: The stepping numbers in the range [90,101] are 98 and 101. There are a total of 2 stepping numbers in the range. Hence, the output is 2.
    """


Prompt:
def kthLuckyNumber(k: int) -> str:
    """
    We know that 4 and 7 are lucky digits. Also, a number is called lucky if it contains only lucky digits.
    You are given an integer k, return the kth lucky number represented as a string.

    Example 1:

    >>> kthLuckyNumber(k = 4)
    >>> "47"
    Explanation: The first lucky number is 4, the second one is 7, the third one is 44 and the fourth one is 47.

    Example 2:

    >>> kthLuckyNumber(k = 10)
    >>> "477"
    Explanation: Here are lucky numbers sorted in increasing order:
    4, 7, 44, 47, 74, 77, 444, 447, 474, 477. So the 10th lucky number is 477.
    Example 3:

    >>> kthLuckyNumber(k = 1000)
    >>> "777747447"
    Explanation: It can be shown that the 1000th lucky number is 777747447.
    """


Prompt:
def accountBalanceAfterPurchase(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, in other words, its price.
    When making the purchase, first the purchaseAmount is rounded to the nearest multiple of 10. Let us call this value roundedAmount. Then, roundedAmount dollars are removed from your bank account.
    Return an integer denoting your final bank account balance after this purchase.
    Notes:

    0 is considered to be a multiple of 10 in this problem.
    When rounding, 5 is rounded upward (5 is rounded to 10, 15 is rounded to 20, 25 to 30, and so on).

    Example 1:

    >>> accountBalanceAfterPurchase(purchaseAmount = 9)
    >>> 90
    Explanation:
    The nearest multiple of 10 to 9 is 10. So your account balance becomes 100 - 10 = 90.

    Example 2:

    >>> accountBalanceAfterPurchase(purchaseAmount = 15)
    >>> 80
    Explanation:
    The nearest multiple of 10 to 15 is 20. So your account balance becomes 100 - 20 = 80.

    Example 3:

    >>> accountBalanceAfterPurchase(purchaseAmount = 10)
    >>> 90
    Explanation:
    10 is a multiple of 10 itself. So your account balance becomes 100 - 10 = 90.
    """


Prompt:
# class ListNode:
#     def __init__(val=0, next=None):
#         self.val = val
#         self.next = next
class Solution:
    def insertGreatestCommonDivisors(head: Optional[ListNode]) -> Optional[ListNode]:
    """
    Given the head of a linked list head, in which each node contains an integer value.
    Between every pair of adjacent nodes, insert a new node with a value equal to the greatest common divisor of them.
    Return the linked list after insertion.
    The greatest common divisor of two numbers is the largest positive integer that evenly divides both numbers.

    Example 1:

    >>> __init__(head = [18,6,10,3])
    >>> [18,6,6,2,10,1,3]
    Explanation: The 1st diagram denotes the initial linked list and the 2nd diagram denotes the linked list after inserting the new nodes (nodes in blue are the inserted nodes).
    - We insert the greatest common divisor of 18 and 6 = 6 between the 1st and the 2nd nodes.
    - We insert the greatest common divisor of 6 and 10 = 2 between the 2nd and the 3rd nodes.
    - We insert the greatest common divisor of 10 and 3 = 1 between the 3rd and the 4th nodes.
    There are no more adjacent nodes, so we return the linked list.

    Example 2:

    >>> __init__(head = [7])
    >>> [7]
    Explanation: The 1st diagram denotes the initial linked list and the 2nd diagram denotes the linked list after inserting the new nodes.
    There are no pairs of adjacent nodes, so we return the initial linked list.
    """


Prompt:
def minimumSeconds(nums: List[int]) -> int:
    """
    You are given a 0-indexed array nums containing n integers.
    At each second, you perform the following operation on the array:

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

    Note that all the elements get replaced simultaneously.
    Return the minimum number of seconds needed to make all elements in the array nums equal.

    Example 1:

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

    Example 2:

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

    Example 3:

    >>> minimumSeconds(nums = [5,5,5,5])
    >>> 0
    Explanation: We don't need to perform any operations as all elements in the initial array are the same.
    """


Prompt:
def minimumTime(nums1: List[int], nums2: List[int], x: int) -> int:
    """
    You are given two 0-indexed integer arrays nums1 and nums2 of equal length. Every second, for all indices 0 <= i < nums1.length, value of nums1[i] is incremented by nums2[i]. After this is done, you can do the following operation:

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

    You are also given an integer x.
    Return the minimum time in which you can make the sum of all elements of nums1 to be less than or equal to x, or -1 if this is not possible.

    Example 1:

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

    Example 2:

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


Prompt:
def finalString(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:

    >>> finalString(s = "string")
    >>> "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:

    >>> finalString(s = "poiinter")
    >>> "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".
    """


Prompt:
def canSplitArray(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 arrays of size 1 by performing a series of steps.
    An array is called good if:

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

    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 arrays, if both resulting arrays are good.
    Return true if you can split the given array into n arrays, otherwise return false.

    Example 1:

    >>> canSplitArray(nums = [2, 2, 1], m = 4)
    >>> true
    Explanation:

    Split [2, 2, 1] to [2, 2] and [1]. The array [1] has a length of one, and the array [2, 2] has the sum of its elements equal to 4 >= m, so both are good arrays.
    Split [2, 2] to [2] and [2]. both arrays have the length of one, so both are good arrays.

    Example 2:

    >>> canSplitArray(nums = [2, 1, 3], m = 5)
    >>> false
    Explanation:
    The first move has to be either of the following:

    Split [2, 1, 3] to [2, 1] and [3]. The array [2, 1] has neither length of one nor sum of elements greater than or equal to m.
    Split [2, 1, 3] to [2] and [1, 3]. The array [1, 3] has neither length of one nor sum of elements greater than or equal to m.

    So as both moves are invalid (they do not divide the array into two good arrays), we are unable to split nums into n arrays of size 1.

    Example 3:

    >>> canSplitArray(nums = [2, 3, 3, 2, 3], m = 6)
    >>> true
    Explanation:

    Split [2, 3, 3, 2, 3] to [2] and [3, 3, 2, 3].
    Split [3, 3, 2, 3] to [3, 3, 2] and [3].
    Split [3, 3, 2] to [3, 3] and [2].
    Split [3, 3] to [3] and [3].
    """


Prompt:
def maximumSafenessFactor(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:

    >>> maximumSafenessFactor(grid = [[1,0,0],[0,0,0],[0,0,1]])
    >>> 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:

    >>> maximumSafenessFactor(grid = [[0,0,1],[0,0,0],[0,0,0]])
    >>> 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:

    >>> maximumSafenessFactor(grid = [[0,0,0,1],[0,0,0,0],[0,0,0,0],[1,0,0,0]])
    >>> 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.
    """


Prompt:
def findMaximumElegance(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:

    >>> findMaximumElegance(items = [[3,2],[5,1],[10,1]], k = 2)
    >>> 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:

    >>> findMaximumElegance(items = [[3,1],[3,1],[2,2],[5,3]], k = 3)
    >>> 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:

    >>> findMaximumElegance(items = [[1,1],[2,1],[3,1]], k = 3)
    >>> 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.
    """


Prompt:
def minimumSeconds(land: List[List[str]]) -> int:
    """
    You are given an n * m 0-indexed grid of string land. Right now, you are standing at the cell that contains "S", and you want to get to the cell containing "D". There are three other types of cells in this land:

    ".": These cells are empty.
    "X": These cells are stone.
    "*": These cells are flooded.

    At each second, you can move to a cell that shares a side with your current cell (if it exists). Also, at each second, every empty cell that shares a side with a flooded cell becomes flooded as well.
    There are two problems ahead of your journey:

    You can't step on stone cells.
    You can't step on flooded cells since you will drown (also, you can't step on a cell that will be flooded at the same time as you step on it).

    Return the minimum time it takes you to reach the destination in seconds, or -1 if it is impossible.
    Note that the destination will never be flooded.

    Example 1:

    >>> minimumSeconds(land = [["D",".","*"],[".",".","."],[".","S","."]])
    >>> 3
    Explanation: The picture below shows the simulation of the land second by second. The blue cells are flooded, and the gray cells are stone.
    Picture (0) shows the initial state and picture (3) shows the final state when we reach destination. As you see, it takes us 3 second to reach destination and the answer would be 3.
    It can be shown that 3 is the minimum time needed to reach from S to D.

    Example 2:

    >>> minimumSeconds(land = [["D","X","*"],[".",".","."],[".",".","S"]])
    >>> -1
    Explanation: The picture below shows the simulation of the land second by second. The blue cells are flooded, and the gray cells are stone.
    Picture (0) shows the initial state. As you see, no matter which paths we choose, we will drown at the 3rd second. Also the minimum path takes us 4 seconds to reach from S to D.
    So the answer would be -1.

    Example 3:

    >>> minimumSeconds(land = [["D",".",".",".","*","."],[".","X",".","X",".","."],[".",".",".",".","S","."]])
    >>> 6
    Explanation: It can be shown that we can reach destination in 6 seconds. Also it can be shown that 6 is the minimum seconds one need to reach from S to D.
    """


Prompt:
def maxSum(nums: List[int]) -> int:
    """
    You are given an integer array nums. You have to find the maximum sum of a pair of numbers from nums such that the largest digit in both numbers is equal.
    For example, 2373 is made up of three distinct digits: 2, 3, and 7, where 7 is the largest among them.
    Return the maximum sum or -1 if no such pair exists.

    Example 1:

    >>> maxSum(nums = [112,131,411])
    >>> -1
    Explanation:
    Each numbers largest digit in order is [2,3,4].

    Example 2:

    >>> maxSum(nums = [2536,1613,3366,162])
    >>> 5902
    Explanation:
    All the numbers have 6 as their largest digit, so the answer is 2536 + 3366 = 5902.

    Example 3:

    >>> maxSum(nums = [51,71,17,24,42])
    >>> 88
    Explanation:
    Each number's largest digit in order is [5,7,7,4,4].
    So we have only two possible pairs, 71 + 17 = 88 and 24 + 42 = 66.
    """


Prompt:
# class ListNode:
#     def __init__(val=0, next=None):
#         self.val = val
#         self.next = next
class Solution:
    def doubleIt(head: Optional[ListNode]) -> Optional[ListNode]:
    """
    You are given the head of a non-empty linked list representing a non-negative integer without leading zeroes.
    Return the head of the linked list after doubling it.

    Example 1:

    >>> __init__(head = [1,8,9])
    >>> [3,7,8]
    Explanation: The figure above corresponds to the given linked list which represents the number 189. Hence, the returned linked list represents the number 189 * 2 = 378.

    Example 2:

    >>> __init__(head = [9,9,9])
    >>> [1,9,9,8]
    Explanation: The figure above corresponds to the given linked list which represents the number 999. Hence, the returned linked list reprersents the number 999 * 2 = 1998.
    """


Prompt:
def minAbsoluteDifference(nums: List[int], x: int) -> int:
    """
    You are given a 0-indexed integer array nums and an integer x.
    Find the minimum absolute difference between two elements in the array that are at least x indices apart.
    In other words, find two indices i and j such that abs(i - j) >= x and abs(nums[i] - nums[j]) is minimized.
    Return an integer denoting the minimum absolute difference between two elements that are at least x indices apart.

    Example 1:

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

    Example 2:

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

    Example 3:

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


Prompt:
def minimumRelativeLosses(prices: List[int], queries: List[List[int]]) -> List[int]:
    """
    You are given an integer array prices, which shows the chocolate prices and a 2D integer array queries, where queries[i] = [ki, mi].
    Alice and Bob went to buy some chocolates, and Alice suggested a way to pay for them, and Bob agreed.
    The terms for each query are as follows:

    If the price of a chocolate is less than or equal to ki, Bob pays for it.
    Otherwise, Bob pays ki of it, and Alice pays the rest.

    Bob wants to select exactly mi chocolates such that his relative loss is minimized, more formally, if, in total, Alice has paid ai and Bob has paid bi, Bob wants to minimize bi - ai.
    Return an integer array ans where ans[i] is Bob's minimum relative loss possible for queries[i].

    Example 1:

    >>> minimumRelativeLosses(prices = [1,9,22,10,19], queries = [[18,4],[5,2]])
    >>> [34,-21]
    Explanation: For the 1st query Bob selects the chocolates with prices [1,9,10,22]. He pays 1 + 9 + 10 + 18 = 38 and Alice pays 0 + 0 + 0 + 4 = 4. So Bob's relative loss is 38 - 4 = 34.
    For the 2nd query Bob selects the chocolates with prices [19,22]. He pays 5 + 5 = 10 and Alice pays 14 + 17 = 31. So Bob's relative loss is 10 - 31 = -21.
    It can be shown that these are the minimum possible relative losses.
    Example 2:

    >>> minimumRelativeLosses(prices = [1,5,4,3,7,11,9], queries = [[5,4],[5,7],[7,3],[4,5]])
    >>> [4,16,7,1]
    Explanation: For the 1st query Bob selects the chocolates with prices [1,3,9,11]. He pays 1 + 3 + 5 + 5 = 14 and Alice pays 0 + 0 + 4 + 6 = 10. So Bob's relative loss is 14 - 10 = 4.
    For the 2nd query Bob has to select all the chocolates. He pays 1 + 5 + 4 + 3 + 5 + 5 + 5 = 28 and Alice pays 0 + 0 + 0 + 0 + 2 + 6 + 4 = 12. So Bob's relative loss is 28 - 12 = 16.
    For the 3rd query Bob selects the chocolates with prices [1,3,11] and he pays 1 + 3 + 7 = 11 and Alice pays 0 + 0 + 4 = 4. So Bob's relative loss is 11 - 4 = 7.
    For the 4th query Bob selects the chocolates with prices [1,3,7,9,11] and he pays 1 + 3 + 4 + 4 + 4 = 16 and Alice pays 0 + 0 + 3 + 5 + 7 = 15. So Bob's relative loss is 16 - 15 = 1.
    It can be shown that these are the minimum possible relative losses.

    Example 3:

    >>> minimumRelativeLosses(prices = [5,6,7], queries = [[10,1],[5,3],[3,3]])
    >>> [5,12,0]
    Explanation: For the 1st query Bob selects the chocolate with price 5 and he pays 5 and Alice pays 0. So Bob's relative loss is 5 - 0 = 5.
    For the 2nd query Bob has to select all the chocolates. He pays 5 + 5 + 5 = 15 and Alice pays 0 + 1 + 2 = 3. So Bob's relative loss is 15 - 3 = 12.
    For the 3rd query Bob has to select all the chocolates. He pays 3 + 3 + 3 = 9 and Alice pays 2 + 3 + 4 = 9. So Bob's relative loss is 9 - 9 = 0.
    It can be shown that these are the minimum possible relative losses.
    """


Prompt:
def countPairs(nums: List[int], target: int) -> int:
    """
    Given a 0-indexed integer array nums of length n and an integer target, return the number of pairs (i, j) where 0 <= i < j < n and nums[i] + nums[j] < target.

    Example 1:

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

    Example 2:

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


Prompt:
def canMakeSubsequence(str1: str, str2: str) -> bool:
    """
    You are given two 0-indexed strings str1 and str2.
    In an operation, you select a set of indices in str1, and for each index i in the set, increment str1[i] to the next character cyclically. That is 'a' becomes 'b', 'b' becomes 'c', and so on, and 'z' becomes 'a'.
    Return true if it is possible to make str2 a subsequence of str1 by performing the operation at most once, and false otherwise.
    Note: A subsequence of a string is a new string that is formed from the original string by deleting some (possibly none) of the characters without disturbing the relative positions of the remaining characters.

    Example 1:

    >>> canMakeSubsequence(str1 = "abc", str2 = "ad")
    >>> true
    Explanation: Select index 2 in str1.
    Increment str1[2] to become 'd'.
    Hence, str1 becomes "abd" and str2 is now a subsequence. Therefore, true is returned.
    Example 2:

    >>> canMakeSubsequence(str1 = "zc", str2 = "ad")
    >>> true
    Explanation: Select indices 0 and 1 in str1.
    Increment str1[0] to become 'a'.
    Increment str1[1] to become 'd'.
    Hence, str1 becomes "ad" and str2 is now a subsequence. Therefore, true is returned.
    Example 3:

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


Prompt:
def minimumOperations(nums: List[int]) -> int:
    """
    You are given an integer array nums. Each element in nums is 1, 2 or 3. In each operation, you can remove an element from nums. Return the minimum number of operations to make nums non-decreasing.

    Example 1:

    >>> minimumOperations(nums = [2,1,3,2,1])
    >>> 3
    Explanation:
    One of the optimal solutions is to remove nums[0], nums[2] and nums[3].

    Example 2:

    >>> minimumOperations(nums = [1,3,2,1,3,3])
    >>> 2
    Explanation:
    One of the optimal solutions is to remove nums[1] and nums[2].

    Example 3:

    >>> minimumOperations(nums = [2,2,2,2,3,3])
    >>> 0
    Explanation:
    nums is already non-decreasing.
    """


Prompt:
def numberOfBeautifulIntegers(low: int, high: int, k: int) -> int:
    """
    You are given positive integers low, high, and k.
    A number is beautiful if it meets both of the following conditions:

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

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

    Example 1:

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

    Example 2:

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

    Example 3:

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


Prompt:
def isAcronym(words: List[str], s: str) -> bool:
    """
    Given an array of strings words and a string s, determine if s is an acronym of words.
    The string s is considered an acronym of words if it can be formed by concatenating the first character of each string in words in order. For example, "ab" can be formed from ["apple", "banana"], but it can't be formed from ["bear", "aardvark"].
    Return true if s is an acronym of words, and false otherwise.

    Example 1:

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

    Example 2:

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

    Example 3:

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


Prompt:
def minimumSum(n: int, k: int) -> int:
    """
    You are given two integers, n and k.
    An array of distinct positive integers is called a k-avoiding array if there does not exist any pair of distinct elements that sum to k.
    Return the minimum possible sum of a k-avoiding array of length n.

    Example 1:

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

    Example 2:

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


Prompt:
def maximizeTheProfit(n: int, offers: List[List[int]]) -> int:
    """
    You are given an integer n representing the number of houses on a number line, numbered from 0 to n - 1.
    Additionally, you are given a 2D integer array offers where offers[i] = [starti, endi, goldi], indicating that ith buyer wants to buy all the houses from starti to endi for goldi amount of gold.
    As a salesman, your goal is to maximize your earnings by strategically selecting and selling houses to buyers.
    Return the maximum amount of gold you can earn.
    Note that different buyers can't buy the same house, and some houses may remain unsold.

    Example 1:

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

    Example 2:

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


Prompt:
def longestEqualSubarray(nums: List[int], k: int) -> int:
    """
    You are given a 0-indexed integer array nums and an integer k.
    A subarray is called equal if all of its elements are equal. Note that the empty subarray is an equal subarray.
    Return the length of the longest possible equal subarray after deleting at most k elements from nums.
    A subarray is a contiguous, possibly empty sequence of elements within an array.

    Example 1:

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

    Example 2:

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


Prompt:
def maximumLengthOfRanges(nums: List[int]) -> List[int]:
    """
    You are given a 0-indexed array nums of distinct integers.
    Let us define a 0-indexed array ans of the same length as nums in the following way:

    ans[i] is the maximum length of a subarray nums[l..r], such that the maximum element in that subarray is equal to nums[i].

    Return the array ans.
    Note that a subarray is a contiguous part of the array.

    Example 1:

    >>> maximumLengthOfRanges(nums = [1,5,4,3,6])
    >>> [1,4,2,1,5]
    Explanation: For nums[0] the longest subarray in which 1 is the maximum is nums[0..0] so ans[0] = 1.
    For nums[1] the longest subarray in which 5 is the maximum is nums[0..3] so ans[1] = 4.
    For nums[2] the longest subarray in which 4 is the maximum is nums[2..3] so ans[2] = 2.
    For nums[3] the longest subarray in which 3 is the maximum is nums[3..3] so ans[3] = 1.
    For nums[4] the longest subarray in which 6 is the maximum is nums[0..4] so ans[4] = 5.

    Example 2:

    >>> maximumLengthOfRanges(nums = [1,2,3,4,5])
    >>> [1,2,3,4,5]
    Explanation: For nums[i] the longest subarray in which it's the maximum is nums[0..i] so ans[i] = i + 1.
    """


Prompt:
def furthestDistanceFromOrigin(moves: str) -> int:
    """
    You are given a string moves of length n consisting only of characters 'L', 'R', and '_'. The string represents your movement on a number line starting from the origin 0.
    In the ith move, you can choose one of the following directions:

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

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

    Example 1:

    >>> furthestDistanceFromOrigin(moves = "L_RL__R")
    >>> 3
    Explanation: The furthest point we can reach from the origin 0 is point -3 through the following sequence of moves "LLRLLLR".

    Example 2:

    >>> furthestDistanceFromOrigin(moves = "_R__LL_")
    >>> 5
    Explanation: The furthest point we can reach from the origin 0 is point -5 through the following sequence of moves "LRLLLLL".

    Example 3:

    >>> furthestDistanceFromOrigin(moves = "_______")
    >>> 7
    Explanation: The furthest point we can reach from the origin 0 is point 7 through the following sequence of moves "RRRRRRR".
    """


Prompt:
def minimumPossibleSum(n: int, target: int) -> int:
    """
    You are given positive integers n and target.
    An array nums is beautiful if it meets the following conditions:

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

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

    Example 1:

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

    Example 2:

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

    Example 3:

    >>> minimumPossibleSum(n = 1, target = 1)
    >>> 1
    Explanation: We can see, that nums = [1] is beautiful.
    """


Prompt:
def minOperations(nums: List[int], target: int) -> int:
    """
    You are given a 0-indexed array nums consisting of non-negative powers of 2, and an integer target.
    In one operation, you must apply the following changes to the array:

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

    Return the minimum number of operations you need to perform so that nums contains a subsequence whose elements sum to target. If it is impossible to obtain such a subsequence, return -1.
    A subsequence is an array that can be derived from another array by deleting some or no elements without changing the order of the remaining elements.

    Example 1:

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

    Example 2:

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

    >>> minOperations(nums = [1,32,1], target = 35)
    >>> -1
    Explanation: It can be shown that no sequence of operations results in a subsequence that sums up to 35.
    """


Prompt:
def getMaxFunctionValue(receiver: List[int], k: int) -> int:
    """
    You are given an integer array receiver of length n and an integer k. n players are playing a ball-passing game.
    You choose the starting player, i. The game proceeds as follows: player i passes the ball to player receiver[i], who then passes it to receiver[receiver[i]], and so on, for k passes in total. The game's score is the sum of the indices of the players who touched the ball, including repetitions, i.e. i + receiver[i] + receiver[receiver[i]] + ... + receiver(k)[i].
    Return the maximum possible score.
    Notes:

    receiver may contain duplicates.
    receiver[i] may be equal to i.

    Example 1:

    >>> getMaxFunctionValue(receiver = [2,0,1], k = 4)
    >>> 6
    Explanation:
    Starting with player i = 2 the initial score is 2:

    Pass
    Sender Index
    Receiver Index
    Score

    1
    2
    1
    3

    2
    1
    0
    3

    3
    0
    2
    5

    4
    2
    1
    6

    Example 2:

    >>> getMaxFunctionValue(receiver = [1,1,1,2,3], k = 3)
    >>> 10
    Explanation:
    Starting with player i = 4 the initial score is 4:

    Pass
    Sender Index
    Receiver Index
    Score

    1
    4
    3
    7

    2
    3
    2
    9

    3
    2
    1
    10
    """


Prompt:
def maximumCoins(heroes: List[int], monsters: List[int], coins: List[int]) -> List[int]:
    """
    There is a battle and n heroes are trying to defeat m monsters. You are given two 1-indexed arrays of positive integers heroes and monsters of length n and m, respectively. heroes[i] is the power of ith hero, and monsters[i] is the power of ith monster.
    The ith hero can defeat the jth monster if monsters[j] <= heroes[i].
    You are also given a 1-indexed array coins of length m consisting of positive integers. coins[i] is the number of coins that each hero earns after defeating the ith monster.
    Return an array ans of length n where ans[i] is the maximum number of coins that the ith hero can collect from this battle.
    Notes

    The health of a hero doesn't get reduced after defeating a monster.
    Multiple heroes can defeat a monster, but each monster can be defeated by a given hero only once.

    Example 1:

    >>> maximumCoins(heroes = [1,4,2], monsters = [1,1,5,2,3], coins = [2,3,4,5,6])
    >>> [5,16,10]
    Explanation: For each hero, we list the index of all the monsters he can defeat:
    1st hero: [1,2] since the power of this hero is 1 and monsters[1], monsters[2] <= 1. So this hero collects coins[1] + coins[2] = 5 coins.
    2nd hero: [1,2,4,5] since the power of this hero is 4 and monsters[1], monsters[2], monsters[4], monsters[5] <= 4. So this hero collects coins[1] + coins[2] + coins[4] + coins[5] = 16 coins.
    3rd hero: [1,2,4] since the power of this hero is 2 and monsters[1], monsters[2], monsters[4] <= 2. So this hero collects coins[1] + coins[2] + coins[4] = 10 coins.
    So the answer would be [5,16,10].
    Example 2:

    >>> maximumCoins(heroes = [5], monsters = [2,3,1,2], coins = [10,6,5,2])
    >>> [23]
    Explanation: This hero can defeat all the monsters since monsters[i] <= 5. So he collects all of the coins: coins[1] + coins[2] + coins[3] + coins[4] = 23, and the answer would be [23].

    Example 3:

    >>> maximumCoins(heroes = [4,4], monsters = [5,7,8], coins = [1,1,1])
    >>> [0,0]
    Explanation: In this example, no hero can defeat a monster. So the answer would be [0,0],
    """


Prompt:
def canBeEqual(s1: str, s2: str) -> bool:
    """
    You are given two strings s1 and s2, both of length 4, consisting of lowercase English letters.
    You can apply the following operation on any of the two strings any number of times:

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

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

    Example 1:

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

    Example 2:

    >>> canBeEqual(s1 = "abcd", s2 = "dacb")
    >>> false
    Explanation: It is not possible to make the two strings equal.
    """


Prompt:
def checkStrings(s1: str, s2: str) -> bool:
    """
    You are given two strings s1 and s2, both of length n, consisting of lowercase English letters.
    You can apply the following operation on any of the two strings any number of times:

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

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

    Example 1:

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

    Example 2:

    >>> checkStrings(s1 = "abe", s2 = "bea")
    >>> false
    Explanation: It is not possible to make the two strings equal.
    """


Prompt:
def maxSum(nums: List[int], m: int, k: int) -> int:
    """
    You are given an integer array nums and two positive integers m and k.
    Return the maximum sum out of all almost unique subarrays of length k of nums. If no such subarray exists, return 0.
    A subarray of nums is almost unique if it contains at least m distinct elements.
    A subarray is a contiguous non-empty sequence of elements within an array.

    Example 1:

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

    Example 2:

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

    Example 3:

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


Prompt:
def countKSubsequencesWithMaxBeauty(s: str, k: int) -> int:
    """
    You are given a string s and an integer k.
    A k-subsequence is a subsequence of s, having length k, and all its characters are unique, i.e., every character occurs once.
    Let f(c) denote the number of times the character c occurs in s.
    The beauty of a k-subsequence is the sum of f(c) for every character c in the k-subsequence.
    For example, consider s = "abbbdd" and k = 2:

    f('a') = 1, f('b') = 3, f('d') = 2
    Some k-subsequences of s are:

    "abbbdd" -> "ab" having a beauty of f('a') + f('b') = 4
    "abbbdd" -> "ad" having a beauty of f('a') + f('d') = 3
    "abbbdd" -> "bd" having a beauty of f('b') + f('d') = 5

    Return an integer denoting the number of k-subsequences whose beauty is the maximum among all k-subsequences. Since the answer may be too large, return it modulo 109 + 7.
    A subsequence of a string is a new string formed from the original string by deleting some (possibly none) of the characters without disturbing the relative positions of the remaining characters.
    Notes

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

    Example 1:

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

    Example 2:

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


Prompt:
def countSymmetricIntegers(low: int, high: int) -> int:
    """
    You are given two positive integers low and high.
    An integer x consisting of 2 * n digits is symmetric if the sum of the first n digits of x is equal to the sum of the last n digits of x. Numbers with an odd number of digits are never symmetric.
    Return the number of symmetric integers in the range [low, high].

    Example 1:

    >>> countSymmetricIntegers(low = 1, high = 100)
    >>> 9
    Explanation: There are 9 symmetric integers between 1 and 100: 11, 22, 33, 44, 55, 66, 77, 88, and 99.

    Example 2:

    >>> countSymmetricIntegers(low = 1200, high = 1230)
    >>> 4
    Explanation: There are 4 symmetric integers between 1200 and 1230: 1203, 1212, 1221, and 1230.
    """


Prompt:
def minimumOperations(num: str) -> int:
    """
    You are given a 0-indexed string num representing a non-negative integer.
    In one operation, you can pick any digit of num and delete it. Note that if you delete all the digits of num, num becomes 0.
    Return the minimum number of operations required to make num special.
    An integer x is considered special if it is divisible by 25.

    Example 1:

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

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

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