Prompt:
def recoverArray(n: int, sums: List[int]) -> List[int]:
    """
    You are given an integer n representing the length of an unknown array that you are trying to recover. You are also given an array sums containing the values of all 2n subset sums of the unknown array (in no particular order).
    Return the array ans of length n representing the unknown array. If multiple answers exist, return any of them.
    An array sub is a subset of an array arr if sub can be obtained from arr by deleting some (possibly zero or all) elements of arr. The sum of the elements in sub is one possible subset sum of arr. The sum of an empty array is considered to be 0.
    Note: Test cases are generated such that there will always be at least one correct answer.

    Example 1:

    >>> recoverArray(n = 3, sums = [-3,-2,-1,0,0,1,2,3])
    >>> [1,2,-3]
    Explanation: [1,2,-3] is able to achieve the given subset sums:
    - []: sum is 0
    - [1]: sum is 1
    - [2]: sum is 2
    - [1,2]: sum is 3
    - [-3]: sum is -3
    - [1,-3]: sum is -2
    - [2,-3]: sum is -1
    - [1,2,-3]: sum is 0
    Note that any permutation of [1,2,-3] and also any permutation of [-1,-2,3] will also be accepted.

    Example 2:

    >>> recoverArray(n = 2, sums = [0,0,0,0])
    >>> [0,0]
    Explanation: The only correct answer is [0,0].

    Example 3:

    >>> recoverArray(n = 4, sums = [0,0,5,5,4,-1,4,9,9,-1,4,3,4,8,3,8])
    >>> [0,-1,4,5]
    Explanation: [0,-1,4,5] is able to achieve the given subset sums.
    """


Prompt:
def widestPairOfIndices(nums1: List[int], nums2: List[int]) -> int:
    """
    You are given two 0-indexed binary arrays nums1 and nums2. Find the widest pair of indices (i, j) such that i <= j and nums1[i] + nums1[i+1] + ... + nums1[j] == nums2[i] + nums2[i+1] + ... + nums2[j].
    The widest pair of indices is the pair with the largest distance between i and j. The distance between a pair of indices is defined as j - i + 1.
    Return the distance of the widest pair of indices. If no pair of indices meets the conditions, return 0.

    Example 1:

    >>> widestPairOfIndices(nums1 = [1,1,0,1], nums2 = [0,1,1,0])
    >>> 3
    Explanation:
    If i = 1 and j = 3:
    nums1[1] + nums1[2] + nums1[3] = 1 + 0 + 1 = 2.
    nums2[1] + nums2[2] + nums2[3] = 1 + 1 + 0 = 2.
    The distance between i and j is j - i + 1 = 3 - 1 + 1 = 3.

    Example 2:

    >>> widestPairOfIndices(nums1 = [0,1], nums2 = [1,1])
    >>> 1
    Explanation:
    If i = 1 and j = 1:
    nums1[1] = 1.
    nums2[1] = 1.
    The distance between i and j is j - i + 1 = 1 - 1 + 1 = 1.

    Example 3:

    >>> widestPairOfIndices(nums1 = [0], nums2 = [1])
    >>> 0
    Explanation:
    There are no pairs of indices that meet the requirements.
    """


Prompt:
def minimumDifference(nums: List[int], k: int) -> int:
    """
    You are given a 0-indexed integer array nums, where nums[i] represents the score of the ith student. You are also given an integer k.
    Pick the scores of any k students from the array so that the difference between the highest and the lowest of the k scores is minimized.
    Return the minimum possible difference.

    Example 1:

    >>> minimumDifference(nums = [90], k = 1)
    >>> 0
    Explanation: There is one way to pick score(s) of one student:
    - [90]. The difference between the highest and lowest score is 90 - 90 = 0.
    The minimum possible difference is 0.

    Example 2:

    >>> minimumDifference(nums = [9,4,1,7], k = 2)
    >>> 2
    Explanation: There are six ways to pick score(s) of two students:
    - [9,4,1,7]. The difference between the highest and lowest score is 9 - 4 = 5.
    - [9,4,1,7]. The difference between the highest and lowest score is 9 - 1 = 8.
    - [9,4,1,7]. The difference between the highest and lowest score is 9 - 7 = 2.
    - [9,4,1,7]. The difference between the highest and lowest score is 4 - 1 = 3.
    - [9,4,1,7]. The difference between the highest and lowest score is 7 - 4 = 3.
    - [9,4,1,7]. The difference between the highest and lowest score is 7 - 1 = 6.
    The minimum possible difference is 2.
    """


Prompt:
def kthLargestNumber(nums: List[str], k: int) -> str:
    """
    You are given an array of strings nums and an integer k. Each string in nums represents an integer without leading zeros.
    Return the string that represents the kth largest integer in nums.
    Note: Duplicate numbers should be counted distinctly. For example, if nums is ["1","2","2"], "2" is the first largest integer, "2" is the second-largest integer, and "1" is the third-largest integer.

    Example 1:

    >>> kthLargestNumber(nums = ["3","6","7","10"], k = 4)
    >>> "3"
    Explanation:
    The numbers in nums sorted in non-decreasing order are ["3","6","7","10"].
    The 4th largest integer in nums is "3".

    Example 2:

    >>> kthLargestNumber(nums = ["2","21","12","1"], k = 3)
    >>> "2"
    Explanation:
    The numbers in nums sorted in non-decreasing order are ["1","2","12","21"].
    The 3rd largest integer in nums is "2".

    Example 3:

    >>> kthLargestNumber(nums = ["0","0"], k = 2)
    >>> "0"
    Explanation:
    The numbers in nums sorted in non-decreasing order are ["0","0"].
    The 2nd largest integer in nums is "0".
    """


Prompt:
def minSessions(tasks: List[int], sessionTime: int) -> int:
    """
    There are n tasks assigned to you. The task times are represented as an integer array tasks of length n, where the ith task takes tasks[i] hours to finish. A work session is when you work for at most sessionTime consecutive hours and then take a break.
    You should finish the given tasks in a way that satisfies the following conditions:

    If you start a task in a work session, you must complete it in the same work session.
    You can start a new task immediately after finishing the previous one.
    You may complete the tasks in any order.

    Given tasks and sessionTime, return the minimum number of work sessions needed to finish all the tasks following the conditions above.
    The tests are generated such that sessionTime is greater than or equal to the maximum element in tasks[i].

    Example 1:

    >>> minSessions(tasks = [1,2,3], sessionTime = 3)
    >>> 2
    Explanation: You can finish the tasks in two work sessions.
    - First work session: finish the first and the second tasks in 1 + 2 = 3 hours.
    - Second work session: finish the third task in 3 hours.

    Example 2:

    >>> minSessions(tasks = [3,1,3,1,1], sessionTime = 8)
    >>> 2
    Explanation: You can finish the tasks in two work sessions.
    - First work session: finish all the tasks except the last one in 3 + 1 + 3 + 1 = 8 hours.
    - Second work session: finish the last task in 1 hour.

    Example 3:

    >>> minSessions(tasks = [1,2,3,4,5], sessionTime = 15)
    >>> 1
    Explanation: You can finish all the tasks in one work session.
    """


Prompt:
def numberOfUniqueGoodSubsequences(binary: str) -> int:
    """
    You are given a binary string binary. A subsequence of binary is considered good if it is not empty and has no leading zeros (with the exception of "0").
    Find the number of unique good subsequences of binary.

    For example, if binary = "001", then all the good subsequences are ["0", "0", "1"], so the unique good subsequences are "0" and "1". Note that subsequences "00", "01", and "001" are not good because they have leading zeros.

    Return the number of unique good subsequences of binary. Since the answer may be very large, return it modulo 109 + 7.
    A subsequence is a sequence that can be derived from another sequence by deleting some or no elements without changing the order of the remaining elements.

    Example 1:

    >>> numberOfUniqueGoodSubsequences(binary = "001")
    >>> 2
    Explanation: The good subsequences of binary are ["0", "0", "1"].
    The unique good subsequences are "0" and "1".

    Example 2:

    >>> numberOfUniqueGoodSubsequences(binary = "11")
    >>> 2
    Explanation: The good subsequences of binary are ["1", "1", "11"].
    The unique good subsequences are "1" and "11".
    Example 3:

    >>> numberOfUniqueGoodSubsequences(binary = "101")
    >>> 5
    Explanation: The good subsequences of binary are ["1", "0", "1", "10", "11", "101"].
    The unique good subsequences are "0", "1", "10", "11", and "101".
    """


Prompt:
def catchMaximumAmountofPeople(team: List[int], dist: int) -> int:
    """
    You are playing a game of tag with your friends. In tag, people are divided into two teams: people who are "it", and people who are not "it". The people who are "it" want to catch as many people as possible who are not "it".
    You are given a 0-indexed integer array team containing only zeros (denoting people who are not "it") and ones (denoting people who are "it"), and an integer dist. A person who is "it" at index i can catch any one person whose index is in the range [i - dist, i + dist] (inclusive) and is not "it".
    Return the maximum number of people that the people who are "it" can catch.

    Example 1:

    >>> catchMaximumAmountofPeople(team = [0,1,0,1,0], dist = 3)
    >>> 2
    Explanation:
    The person who is "it" at index 1 can catch people in the range [i-dist, i+dist] = [1-3, 1+3] = [-2, 4].
    They can catch the person who is not "it" at index 2.
    The person who is "it" at index 3 can catch people in the range [i-dist, i+dist] = [3-3, 3+3] = [0, 6].
    They can catch the person who is not "it" at index 0.
    The person who is not "it" at index 4 will not be caught because the people at indices 1 and 3 are already catching one person.
    Example 2:

    >>> catchMaximumAmountofPeople(team = [1], dist = 1)
    >>> 0
    Explanation:
    There are no people who are not "it" to catch.

    Example 3:

    >>> catchMaximumAmountofPeople(team = [0], dist = 1)
    >>> 0
    Explanation:
    There are no people who are "it" to catch people.
    """


Prompt:
def findMiddleIndex(nums: List[int]) -> int:
    """
    Given a 0-indexed integer array nums, find the leftmost middleIndex (i.e., the smallest amongst all the possible ones).
    A middleIndex is an index where nums[0] + nums[1] + ... + nums[middleIndex-1] == nums[middleIndex+1] + nums[middleIndex+2] + ... + nums[nums.length-1].
    If middleIndex == 0, the left side sum is considered to be 0. Similarly, if middleIndex == nums.length - 1, the right side sum is considered to be 0.
    Return the leftmost middleIndex that satisfies the condition, or -1 if there is no such index.

    Example 1:

    >>> findMiddleIndex(nums = [2,3,-1,8,4])
    >>> 3
    Explanation: The sum of the numbers before index 3 is: 2 + 3 + -1 = 4
    The sum of the numbers after index 3 is: 4 = 4

    Example 2:

    >>> findMiddleIndex(nums = [1,-1,4])
    >>> 2
    Explanation: The sum of the numbers before index 2 is: 1 + -1 = 0
    The sum of the numbers after index 2 is: 0

    Example 3:

    >>> findMiddleIndex(nums = [2,5])
    >>> -1
    Explanation: There is no valid middleIndex.
    """


Prompt:
def findFarmland(land: List[List[int]]) -> List[List[int]]:
    """
    You are given a 0-indexed m x n binary matrix land where a 0 represents a hectare of forested land and a 1 represents a hectare of farmland.
    To keep the land organized, there are designated rectangular areas of hectares that consist entirely of farmland. These rectangular areas are called groups. No two groups are adjacent, meaning farmland in one group is not four-directionally adjacent to another farmland in a different group.
    land can be represented by a coordinate system where the top left corner of land is (0, 0) and the bottom right corner of land is (m-1, n-1). Find the coordinates of the top left and bottom right corner of each group of farmland. A group of farmland with a top left corner at (r1, c1) and a bottom right corner at (r2, c2) is represented by the 4-length array [r1, c1, r2, c2].
    Return a 2D array containing the 4-length arrays described above for each group of farmland in land. If there are no groups of farmland, return an empty array. You may return the answer in any order.

    Example 1:

    >>> findFarmland(land = [[1,0,0],[0,1,1],[0,1,1]])
    >>> [[0,0,0,0],[1,1,2,2]]
    Explanation:
    The first group has a top left corner at land[0][0] and a bottom right corner at land[0][0].
    The second group has a top left corner at land[1][1] and a bottom right corner at land[2][2].

    Example 2:

    >>> findFarmland(land = [[1,1],[1,1]])
    >>> [[0,0,1,1]]
    Explanation:
    The first group has a top left corner at land[0][0] and a bottom right corner at land[1][1].

    Example 3:

    >>> findFarmland(land = [[0]])
    >>> []
    Explanation:
    There are no groups of farmland.
    """


Prompt:
def numberOfGoodSubsets(nums: List[int]) -> int:
    """
    You are given an integer array nums. We call a subset of nums good if its product can be represented as a product of one or more distinct prime numbers.

    For example, if nums = [1, 2, 3, 4]:

    [2, 3], [1, 2, 3], and [1, 3] are good subsets with products 6 = 2*3, 6 = 2*3, and 3 = 3 respectively.
    [1, 4] and [4] are not good subsets with products 4 = 2*2 and 4 = 2*2 respectively.

    Return the number of different good subsets in nums modulo 109 + 7.
    A subset of nums is any array that can be obtained by deleting some (possibly none or all) elements from nums. Two subsets are different if and only if the chosen indices to delete are different.

    Example 1:

    >>> numberOfGoodSubsets(nums = [1,2,3,4])
    >>> 6
    Explanation: The good subsets are:
    - [1,2]: product is 2, which is the product of distinct prime 2.
    - [1,2,3]: product is 6, which is the product of distinct primes 2 and 3.
    - [1,3]: product is 3, which is the product of distinct prime 3.
    - [2]: product is 2, which is the product of distinct prime 2.
    - [2,3]: product is 6, which is the product of distinct primes 2 and 3.
    - [3]: product is 3, which is the product of distinct prime 3.

    Example 2:

    >>> numberOfGoodSubsets(nums = [4,2,3,15])
    >>> 5
    Explanation: The good subsets are:
    - [2]: product is 2, which is the product of distinct prime 2.
    - [2,3]: product is 6, which is the product of distinct primes 2 and 3.
    - [2,15]: product is 30, which is the product of distinct primes 2, 3, and 5.
    - [3]: product is 3, which is the product of distinct prime 3.
    - [15]: product is 15, which is the product of distinct primes 3 and 5.
    """


Prompt:
def countQuadruplets(nums: List[int]) -> int:
    """
    Given a 0-indexed integer array nums, return the number of distinct quadruplets (a, b, c, d) such that:

    nums[a] + nums[b] + nums[c] == nums[d], and
    a < b < c < d

    Example 1:

    >>> countQuadruplets(nums = [1,2,3,6])
    >>> 1
    Explanation: The only quadruplet that satisfies the requirement is (0, 1, 2, 3) because 1 + 2 + 3 == 6.

    Example 2:

    >>> countQuadruplets(nums = [3,3,6,4,5])
    >>> 0
    Explanation: There are no such quadruplets in [3,3,6,4,5].

    Example 3:

    >>> countQuadruplets(nums = [1,1,1,3,5])
    >>> 4
    Explanation: The 4 quadruplets that satisfy the requirement are:
    - (0, 1, 2, 3): 1 + 1 + 1 == 3
    - (0, 1, 3, 4): 1 + 1 + 3 == 5
    - (0, 2, 3, 4): 1 + 1 + 3 == 5
    - (1, 2, 3, 4): 1 + 1 + 3 == 5
    """


Prompt:
def numberOfWeakCharacters(properties: List[List[int]]) -> int:
    """
    You are playing a game that contains multiple characters, and each of the characters has two main properties: attack and defense. You are given a 2D integer array properties where properties[i] = [attacki, defensei] represents the properties of the ith character in the game.
    A character is said to be weak if any other character has both attack and defense levels strictly greater than this character's attack and defense levels. More formally, a character i is said to be weak if there exists another character j where attackj > attacki and defensej > defensei.
    Return the number of weak characters.

    Example 1:

    >>> numberOfWeakCharacters(properties = [[5,5],[6,3],[3,6]])
    >>> 0
    Explanation: No character has strictly greater attack and defense than the other.

    Example 2:

    >>> numberOfWeakCharacters(properties = [[2,2],[3,3]])
    >>> 1
    Explanation: The first character is weak because the second character has a strictly greater attack and defense.

    Example 3:

    >>> numberOfWeakCharacters(properties = [[1,5],[10,4],[4,3]])
    >>> 1
    Explanation: The third character is weak because the second character has a strictly greater attack and defense.
    """


Prompt:
def firstDayBeenInAllRooms(nextVisit: List[int]) -> int:
    """
    There are n rooms you need to visit, labeled from 0 to n - 1. Each day is labeled, starting from 0. You will go in and visit one room a day.
    Initially on day 0, you visit room 0. The order you visit the rooms for the coming days is determined by the following rules and a given 0-indexed array nextVisit of length n:

    Assuming that on a day, you visit room i,
    if you have been in room i an odd number of times (including the current visit), on the next day you will visit a room with a lower or equal room number specified by nextVisit[i] where 0 <= nextVisit[i] <= i;
    if you have been in room i an even number of times (including the current visit), on the next day you will visit room (i + 1) mod n.

    Return the label of the first day where you have been in all the rooms. It can be shown that such a day exists. Since the answer may be very large, return it modulo 109 + 7.

    Example 1:

    >>> firstDayBeenInAllRooms(nextVisit = [0,0])
    >>> 2
    Explanation:
    - On day 0, you visit room 0. The total times you have been in room 0 is 1, which is odd.
      On the next day you will visit room nextVisit[0] = 0
    - On day 1, you visit room 0, The total times you have been in room 0 is 2, which is even.
      On the next day you will visit room (0 + 1) mod 2 = 1
    - On day 2, you visit room 1. This is the first day where you have been in all the rooms.

    Example 2:

    >>> firstDayBeenInAllRooms(nextVisit = [0,0,2])
    >>> 6
    Explanation:
    Your room visiting order for each day is: [0,0,1,0,0,1,2,...].
    Day 6 is the first day where you have been in all the rooms.

    Example 3:

    >>> firstDayBeenInAllRooms(nextVisit = [0,1,2,0])
    >>> 6
    Explanation:
    Your room visiting order for each day is: [0,0,1,1,2,2,3,...].
    Day 6 is the first day where you have been in all the rooms.
    """


Prompt:
def gcdSort(nums: List[int]) -> bool:
    """
    You are given an integer array nums, and you can perform the following operation any number of times on nums:

    Swap the positions of two elements nums[i] and nums[j] if gcd(nums[i], nums[j]) > 1 where gcd(nums[i], nums[j]) is the greatest common divisor of nums[i] and nums[j].

    Return true if it is possible to sort nums in non-decreasing order using the above swap method, or false otherwise.

    Example 1:

    >>> gcdSort(nums = [7,21,3])
    >>> true
    Explanation: We can sort [7,21,3] by performing the following operations:
    - Swap 7 and 21 because gcd(7,21) = 7. nums = [21,7,3]
    - Swap 21 and 3 because gcd(21,3) = 3. nums = [3,7,21]

    Example 2:

    >>> gcdSort(nums = [5,2,6,2])
    >>> false
    Explanation: It is impossible to sort the array because 5 cannot be swapped with any other element.

    Example 3:

    >>> gcdSort(nums = [10,5,9,3,15])
    >>> true
    We can sort [10,5,9,3,15] by performing the following operations:
    - Swap 10 and 15 because gcd(10,15) = 5. nums = [15,5,9,3,10]
    - Swap 15 and 3 because gcd(15,3) = 3. nums = [3,5,9,15,10]
    - Swap 10 and 15 because gcd(10,15) = 5. nums = [3,5,9,10,15]
    """


Prompt:
def findInteger(k: int, digit1: int, digit2: int) -> int:
    """
    Given three integers, k, digit1, and digit2, you want to find the smallest integer that is:

    Larger than k,
    A multiple of k, and
    Comprised of only the digits digit1 and/or digit2.

    Return the smallest such integer. If no such integer exists or the integer exceeds the limit of a signed 32-bit integer (231 - 1), return -1.

    Example 1:

    >>> findInteger(k = 2, digit1 = 0, digit2 = 2)
    >>> 20
    Explanation:
    20 is the first integer larger than 2, a multiple of 2, and comprised of only the digits 0 and/or 2.

    Example 2:

    >>> findInteger(k = 3, digit1 = 4, digit2 = 2)
    >>> 24
    Explanation:
    24 is the first integer larger than 3, a multiple of 3, and comprised of only the digits 4 and/or 2.

    Example 3:

    >>> findInteger(k = 2, digit1 = 0, digit2 = 0)
    >>> -1
    Explanation:
    No integer meets the requirements so return -1.
    """


Prompt:
def reversePrefix(word: str, ch: str) -> str:
    """
    Given a 0-indexed string word and a character ch, reverse the segment of word that starts at index 0 and ends at the index of the first occurrence of ch (inclusive). If the character ch does not exist in word, do nothing.

    For example, if word = "abcdefd" and ch = "d", then you should reverse the segment that starts at 0 and ends at 3 (inclusive). The resulting string will be "dcbaefd".

    Return the resulting string.

    Example 1:

    >>> reversePrefix(word = "abcdefd", ch = "d")
    >>> "dcbaefd"
    Explanation: The first occurrence of "d" is at index 3.
    Reverse the part of word from 0 to 3 (inclusive), the resulting string is "dcbaefd".

    Example 2:

    >>> reversePrefix(word = "xyxzxe", ch = "z")
    >>> "zxyxxe"
    Explanation: The first and only occurrence of "z" is at index 3.
    Reverse the part of word from 0 to 3 (inclusive), the resulting string is "zxyxxe".

    Example 3:

    >>> reversePrefix(word = "abcd", ch = "z")
    >>> "abcd"
    Explanation: "z" does not exist in word.
    You should not do any reverse operation, the resulting string is "abcd".
    """


Prompt:
def interchangeableRectangles(rectangles: List[List[int]]) -> int:
    """
    You are given n rectangles represented by a 0-indexed 2D integer array rectangles, where rectangles[i] = [widthi, heighti] denotes the width and height of the ith rectangle.
    Two rectangles i and j (i < j) are considered interchangeable if they have the same width-to-height ratio. More formally, two rectangles are interchangeable if widthi/heighti == widthj/heightj (using decimal division, not integer division).
    Return the number of pairs of interchangeable rectangles in rectangles.

    Example 1:

    >>> interchangeableRectangles(rectangles = [[4,8],[3,6],[10,20],[15,30]])
    >>> 6
    Explanation: The following are the interchangeable pairs of rectangles by index (0-indexed):
    - Rectangle 0 with rectangle 1: 4/8 == 3/6.
    - Rectangle 0 with rectangle 2: 4/8 == 10/20.
    - Rectangle 0 with rectangle 3: 4/8 == 15/30.
    - Rectangle 1 with rectangle 2: 3/6 == 10/20.
    - Rectangle 1 with rectangle 3: 3/6 == 15/30.
    - Rectangle 2 with rectangle 3: 10/20 == 15/30.

    Example 2:

    >>> interchangeableRectangles(rectangles = [[4,5],[7,8]])
    >>> 0
    Explanation: There are no interchangeable pairs of rectangles.
    """


Prompt:
def maxProduct(s: str) -> int:
    """
    Given a string s, find two disjoint palindromic subsequences of s such that the product of their lengths is maximized. The two subsequences are disjoint if they do not both pick a character at the same index.
    Return the maximum possible product of the lengths of the two palindromic subsequences.
    A subsequence is a string that can be derived from another string by deleting some or no characters without changing the order of the remaining characters. A string is palindromic if it reads the same forward and backward.

    Example 1:

    >>> maxProduct(s = "leetcodecom")
    >>> 9
    Explanation: An optimal solution is to choose "ete" for the 1st subsequence and "cdc" for the 2nd subsequence.
    The product of their lengths is: 3 * 3 = 9.

    Example 2:

    >>> maxProduct(s = "bb")
    >>> 1
    Explanation: An optimal solution is to choose "b" (the first character) for the 1st subsequence and "b" (the second character) for the 2nd subsequence.
    The product of their lengths is: 1 * 1 = 1.

    Example 3:

    >>> maxProduct(s = "accbcaxxcxx")
    >>> 25
    Explanation: An optimal solution is to choose "accca" for the 1st subsequence and "xxcxx" for the 2nd subsequence.
    The product of their lengths is: 5 * 5 = 25.
    """


Prompt:
def smallestMissingValueSubtree(parents: List[int], nums: List[int]) -> List[int]:
    """
    There is a family tree rooted at 0 consisting of n nodes numbered 0 to n - 1. You are given a 0-indexed integer array parents, where parents[i] is the parent for node i. Since node 0 is the root, parents[0] == -1.
    There are 105 genetic values, each represented by an integer in the inclusive range [1, 105]. You are given a 0-indexed integer array nums, where nums[i] is a distinct genetic value for node i.
    Return an array ans of length n where ans[i] is the smallest genetic value that is missing from the subtree rooted at node i.
    The subtree rooted at a node x contains node x and all of its descendant nodes.

    Example 1:

    >>> smallestMissingValueSubtree(parents = [-1,0,0,2], nums = [1,2,3,4])
    >>> [5,1,1,1]
    Explanation: The answer for each subtree is calculated as follows:
    - 0: The subtree contains nodes [0,1,2,3] with values [1,2,3,4]. 5 is the smallest missing value.
    - 1: The subtree contains only node 1 with value 2. 1 is the smallest missing value.
    - 2: The subtree contains nodes [2,3] with values [3,4]. 1 is the smallest missing value.
    - 3: The subtree contains only node 3 with value 4. 1 is the smallest missing value.

    Example 2:

    >>> smallestMissingValueSubtree(parents = [-1,0,1,0,3,3], nums = [5,4,6,2,1,3])
    >>> [7,1,1,4,2,1]
    Explanation: The answer for each subtree is calculated as follows:
    - 0: The subtree contains nodes [0,1,2,3,4,5] with values [5,4,6,2,1,3]. 7 is the smallest missing value.
    - 1: The subtree contains nodes [1,2] with values [4,6]. 1 is the smallest missing value.
    - 2: The subtree contains only node 2 with value 6. 1 is the smallest missing value.
    - 3: The subtree contains nodes [3,4,5] with values [2,1,3]. 4 is the smallest missing value.
    - 4: The subtree contains only node 4 with value 1. 2 is the smallest missing value.
    - 5: The subtree contains only node 5 with value 3. 1 is the smallest missing value.

    Example 3:

    >>> smallestMissingValueSubtree(parents = [-1,2,3,0,2,4,1], nums = [2,3,4,5,6,7,8])
    >>> [1,1,1,1,1,1,1]
    Explanation: The value 1 is missing from all the subtrees.
    """


Prompt:
def findGameWinner(n: int) -> bool:
    """
    A Fibonacci tree is a binary tree created using the order function order(n):

    order(0) is the empty tree.
    order(1) is a binary tree with only one node.
    order(n) is a binary tree that consists of a root node with the left subtree as order(n - 2) and the right subtree as order(n - 1).

    Alice and Bob are playing a game with a Fibonacci tree with Alice staring first. On each turn, a player selects a node and removes that node and its subtree. The player that is forced to delete root loses.
    Given the integer n, return true if Alice wins the game or false if Bob wins, assuming both players play optimally.
    A subtree of a binary tree tree is a tree that consists of a node in tree and all of this node's descendants. The tree tree could also be considered as a subtree of itself.

    Example 1:

    >>> findGameWinner(n = 3)
    >>> true
    Explanation:
    Alice takes the node 1 in the right subtree.
    Bob takes either the 1 in the left subtree or the 2 in the right subtree.
    Alice takes whichever node Bob doesn't take.
    Bob is forced to take the root node 3, so Bob will lose.
    Return true because Alice wins.

    Example 2:

    >>> findGameWinner(n = 1)
    >>> false
    Explanation:
    Alice is forced to take the root node 1, so Alice will lose.
    Return false because Alice loses.

    Example 3:

    >>> findGameWinner(n = 2)
    >>> true
    Explanation:
    Alice takes the node 1.
    Bob is forced to take the root node 2, so Bob will lose.
    Return true because Alice wins.
    """


Prompt:
def countKDifference(nums: List[int], k: int) -> int:
    """
    Given an integer array nums and an integer k, return the number of pairs (i, j) where i < j such that |nums[i] - nums[j]| == k.
    The value of |x| is defined as:

    x if x >= 0.
    -x if x < 0.

    Example 1:

    >>> countKDifference(nums = [1,2,2,1], k = 1)
    >>> 4
    Explanation: The pairs with an absolute difference of 1 are:
    - [1,2,2,1]
    - [1,2,2,1]
    - [1,2,2,1]
    - [1,2,2,1]

    Example 2:

    >>> countKDifference(nums = [1,3], k = 3)
    >>> 0
    Explanation: There are no pairs with an absolute difference of 3.

    Example 3:

    >>> countKDifference(nums = [3,2,1,5,4], k = 2)
    >>> 3
    Explanation: The pairs with an absolute difference of 2 are:
    - [3,2,1,5,4]
    - [3,2,1,5,4]
    - [3,2,1,5,4]
    """


Prompt:
def findOriginalArray(changed: List[int]) -> List[int]:
    """
    An integer array original is transformed into a doubled array changed by appending twice the value of every element in original, and then randomly shuffling the resulting array.
    Given an array changed, return original if changed is a doubled array. If changed is not a doubled array, return an empty array. The elements in original may be returned in any order.

    Example 1:

    >>> findOriginalArray(changed = [1,3,4,2,6,8])
    >>> [1,3,4]
    Explanation: One possible original array could be [1,3,4]:
    - Twice the value of 1 is 1 * 2 = 2.
    - Twice the value of 3 is 3 * 2 = 6.
    - Twice the value of 4 is 4 * 2 = 8.
    Other original arrays could be [4,3,1] or [3,1,4].

    Example 2:

    >>> findOriginalArray(changed = [6,3,0,1])
    >>> []
    Explanation: changed is not a doubled array.

    Example 3:

    >>> findOriginalArray(changed = [1])
    >>> []
    Explanation: changed is not a doubled array.
    """


Prompt:
def maxTaxiEarnings(n: int, rides: List[List[int]]) -> int:
    """
    There are n points on a road you are driving your taxi on. The n points on the road are labeled from 1 to n in the direction you are going, and you want to drive from point 1 to point n to make money by picking up passengers. You cannot change the direction of the taxi.
    The passengers are represented by a 0-indexed 2D integer array rides, where rides[i] = [starti, endi, tipi] denotes the ith passenger requesting a ride from point starti to point endi who is willing to give a tipi dollar tip.
    For each passenger i you pick up, you earn endi - starti + tipi dollars. You may only drive at most one passenger at a time.
    Given n and rides, return the maximum number of dollars you can earn by picking up the passengers optimally.
    Note: You may drop off a passenger and pick up a different passenger at the same point.

    Example 1:

    >>> maxTaxiEarnings(n = 5, rides = [[2,5,4],[1,5,1]])
    >>> 7
    Explanation: We can pick up passenger 0 to earn 5 - 2 + 4 = 7 dollars.

    Example 2:

    >>> maxTaxiEarnings(n = 20, rides = [[1,6,1],[3,10,2],[10,12,3],[11,12,2],[12,15,2],[13,18,1]])
    >>> 20
    Explanation: We will pick up the following passengers:
    - Drive passenger 1 from point 3 to point 10 for a profit of 10 - 3 + 2 = 9 dollars.
    - Drive passenger 2 from point 10 to point 12 for a profit of 12 - 10 + 3 = 5 dollars.
    - Drive passenger 5 from point 13 to point 18 for a profit of 18 - 13 + 1 = 6 dollars.
    We earn 9 + 5 + 6 = 20 dollars in total.
    """


Prompt:
def minOperations(nums: List[int]) -> int:
    """
    You are given an integer array nums. In one operation, you can replace any element in nums with any integer.
    nums is considered continuous if both of the following conditions are fulfilled:

    All elements in nums are unique.
    The difference between the maximum element and the minimum element in nums equals nums.length - 1.

    For example, nums = [4, 2, 5, 3] is continuous, but nums = [1, 2, 3, 5, 6] is not continuous.
    Return the minimum number of operations to make nums continuous.

    Example 1:

    >>> minOperations(nums = [4,2,5,3])
    >>> 0
    Explanation: nums is already continuous.

    Example 2:

    >>> minOperations(nums = [1,2,3,5,6])
    >>> 1
    Explanation: One possible solution is to change the last element to 4.
    The resulting array is [1,2,3,5,4], which is continuous.

    Example 3:

    >>> minOperations(nums = [1,10,100,1000])
    >>> 3
    Explanation: One possible solution is to:
    - Change the second element to 2.
    - Change the third element to 3.
    - Change the fourth element to 4.
    The resulting array is [1,2,3,4], which is continuous.
    """


Prompt:
def finalValueAfterOperations(operations: List[str]) -> int:
    """
    There is a programming language with only four operations and one variable X:

    ++X and X++ increments the value of the variable X by 1.
    --X and X-- decrements the value of the variable X by 1.

    Initially, the value of X is 0.
    Given an array of strings operations containing a list of operations, return the final value of X after performing all the operations.

    Example 1:

    >>> finalValueAfterOperations(operations = ["--X","X++","X++"])
    >>> 1
    Explanation: The operations are performed as follows:
    Initially, X = 0.
    --X: X is decremented by 1, X =  0 - 1 = -1.
    X++: X is incremented by 1, X = -1 + 1 =  0.
    X++: X is incremented by 1, X =  0 + 1 =  1.

    Example 2:

    >>> finalValueAfterOperations(operations = ["++X","++X","X++"])
    >>> 3
    Explanation: The operations are performed as follows:
    Initially, X = 0.
    ++X: X is incremented by 1, X = 0 + 1 = 1.
    ++X: X is incremented by 1, X = 1 + 1 = 2.
    X++: X is incremented by 1, X = 2 + 1 = 3.

    Example 3:

    >>> finalValueAfterOperations(operations = ["X++","++X","--X","X--"])
    >>> 0
    Explanation: The operations are performed as follows:
    Initially, X = 0.
    X++: X is incremented by 1, X = 0 + 1 = 1.
    ++X: X is incremented by 1, X = 1 + 1 = 2.
    --X: X is decremented by 1, X = 2 - 1 = 1.
    X--: X is decremented by 1, X = 1 - 1 = 0.
    """


Prompt:
def sumOfBeauties(nums: List[int]) -> int:
    """
    You are given a 0-indexed integer array nums. For each index i (1 <= i <= nums.length - 2) the beauty of nums[i] equals:

    2, if nums[j] < nums[i] < nums[k], for all 0 <= j < i and for all i < k <= nums.length - 1.
    1, if nums[i - 1] < nums[i] < nums[i + 1], and the previous condition is not satisfied.
    0, if none of the previous conditions holds.

    Return the sum of beauty of all nums[i] where 1 <= i <= nums.length - 2.

    Example 1:

    >>> sumOfBeauties(nums = [1,2,3])
    >>> 2
    Explanation: For each index i in the range 1 <= i <= 1:
    - The beauty of nums[1] equals 2.

    Example 2:

    >>> sumOfBeauties(nums = [2,4,6,4])
    >>> 1
    Explanation: For each index i in the range 1 <= i <= 2:
    - The beauty of nums[1] equals 1.
    - The beauty of nums[2] equals 0.

    Example 3:

    >>> sumOfBeauties(nums = [3,2,1])
    >>> 0
    Explanation: For each index i in the range 1 <= i <= 1:
    - The beauty of nums[1] equals 0.
    """


Prompt:
def longestSubsequenceRepeatedK(s: str, k: int) -> str:
    """
    You are given a string s of length n, and an integer k. You are tasked to find the longest subsequence repeated k times in string s.
    A subsequence is a string that can be derived from another string by deleting some or no characters without changing the order of the remaining characters.
    A subsequence seq is repeated k times in the string s if seq * k is a subsequence of s, where seq * k represents a string constructed by concatenating seq k times.

    For example, "bba" is repeated 2 times in the string "bababcba", because the string "bbabba", constructed by concatenating "bba" 2 times, is a subsequence of the string "bababcba".

    Return the longest subsequence repeated k times in string s. If multiple such subsequences are found, return the lexicographically largest one. If there is no such subsequence, return an empty string.

    Example 1:

    >>> longestSubsequenceRepeatedK(s = "letsleetcode", k = 2)
    >>> "let"
    Explanation: There are two longest subsequences repeated 2 times: "let" and "ete".
    "let" is the lexicographically largest one.

    Example 2:

    >>> longestSubsequenceRepeatedK(s = "bb", k = 2)
    >>> "b"
    Explanation: The longest subsequence repeated 2 times is "b".

    Example 3:

    >>> longestSubsequenceRepeatedK(s = "ab", k = 2)
    >>> ""
    Explanation: There is no subsequence repeated 2 times. Empty string is returned.
    """


Prompt:
def averageHeightOfBuildings(buildings: List[List[int]]) -> List[List[int]]:
    """
    A perfectly straight street is represented by a number line. The street has building(s) on it and is represented by a 2D integer array buildings, where buildings[i] = [starti, endi, heighti]. This means that there is a building with heighti in the half-closed segment [starti, endi).
    You want to describe the heights of the buildings on the street with the minimum number of non-overlapping segments. The street can be represented by the 2D integer array street where street[j] = [leftj, rightj, averagej] describes a half-closed segment [leftj, rightj) of the road where the average heights of the buildings in the segment is averagej.

    For example, if buildings = [[1,5,2],[3,10,4]], the street could be represented by street = [[1,3,2],[3,5,3],[5,10,4]] because:

    From 1 to 3, there is only the first building with an average height of 2 / 1 = 2.
    From 3 to 5, both the first and the second building are there with an average height of (2+4) / 2 = 3.
    From 5 to 10, there is only the second building with an average height of 4 / 1 = 4.

    Given buildings, return the 2D integer array street as described above (excluding any areas of the street where there are no buldings). You may return the array in any order.
    The average of n elements is the sum of the n elements divided (integer division) by n.
    A half-closed segment [a, b) is the section of the number line between points a and b including point a and not including point b.

    Example 1:

    >>> averageHeightOfBuildings(buildings = [[1,4,2],[3,9,4]])
    >>> [[1,3,2],[3,4,3],[4,9,4]]
    Explanation:
    From 1 to 3, there is only the first building with an average height of 2 / 1 = 2.
    From 3 to 4, both the first and the second building are there with an average height of (2+4) / 2 = 3.
    From 4 to 9, there is only the second building with an average height of 4 / 1 = 4.

    Example 2:

    >>> averageHeightOfBuildings(buildings = [[1,3,2],[2,5,3],[2,8,3]])
    >>> [[1,3,2],[3,8,3]]
    Explanation:
    From 1 to 2, there is only the first building with an average height of 2 / 1 = 2.
    From 2 to 3, all three buildings are there with an average height of (2+3+3) / 3 = 2.
    From 3 to 5, both the second and the third building are there with an average height of (3+3) / 2 = 3.
    From 5 to 8, there is only the last building with an average height of 3 / 1 = 3.
    The average height from 1 to 3 is the same so we can group them into one segment.
    The average height from 3 to 8 is the same so we can group them into one segment.

    Example 3:

    >>> averageHeightOfBuildings(buildings = [[1,2,1],[5,6,1]])
    >>> [[1,2,1],[5,6,1]]
    Explanation:
    From 1 to 2, there is only the first building with an average height of 1 / 1 = 1.
    From 2 to 5, there are no buildings, so it is not included in the output.
    From 5 to 6, there is only the second building with an average height of 1 / 1 = 1.
    We cannot group the segments together because an empty space with no buildings seperates the segments.
    """


Prompt:
def maximumDifference(nums: List[int]) -> int:
    """
    Given a 0-indexed integer array nums of size n, find the maximum difference between nums[i] and nums[j] (i.e., nums[j] - nums[i]), such that 0 <= i < j < n and nums[i] < nums[j].
    Return the maximum difference. If no such i and j exists, return -1.

    Example 1:

    >>> maximumDifference(nums = [7,1,5,4])
    >>> 4
    Explanation:
    The maximum difference occurs with i = 1 and j = 2, nums[j] - nums[i] = 5 - 1 = 4.
    Note that with i = 1 and j = 0, the difference nums[j] - nums[i] = 7 - 1 = 6, but i > j, so it is not valid.

    Example 2:

    >>> maximumDifference(nums = [9,4,3,2])
    >>> -1
    Explanation:
    There is no i and j such that i < j and nums[i] < nums[j].

    Example 3:

    >>> maximumDifference(nums = [1,5,2,10])
    >>> 9
    Explanation:
    The maximum difference occurs with i = 0 and j = 3, nums[j] - nums[i] = 10 - 1 = 9.
    """


Prompt:
def gridGame(grid: List[List[int]]) -> int:
    """
    You are given a 0-indexed 2D array grid of size 2 x n, where grid[r][c] represents the number of points at position (r, c) on the matrix. Two robots are playing a game on this matrix.
    Both robots initially start at (0, 0) and want to reach (1, n-1). Each robot may only move to the right ((r, c) to (r, c + 1)) or down ((r, c) to (r + 1, c)).
    At the start of the game, the first robot moves from (0, 0) to (1, n-1), collecting all the points from the cells on its path. For all cells (r, c) traversed on the path, grid[r][c] is set to 0. Then, the second robot moves from (0, 0) to (1, n-1), collecting the points on its path. Note that their paths may intersect with one another.
    The first robot wants to minimize the number of points collected by the second robot. In contrast, the second robot wants to maximize the number of points it collects. If both robots play optimally, return the number of points collected by the second robot.

    Example 1:

    >>> gridGame(grid = [[2,5,4],[1,5,1]])
    >>> 4
    Explanation: The optimal path taken by the first robot is shown in red, and the optimal path taken by the second robot is shown in blue.
    The cells visited by the first robot are set to 0.
    The second robot will collect 0 + 0 + 4 + 0 = 4 points.

    Example 2:

    >>> gridGame(grid = [[3,3,1],[8,5,2]])
    >>> 4
    Explanation: The optimal path taken by the first robot is shown in red, and the optimal path taken by the second robot is shown in blue.
    The cells visited by the first robot are set to 0.
    The second robot will collect 0 + 3 + 1 + 0 = 4 points.

    Example 3:

    >>> gridGame(grid = [[1,3,1,15],[1,3,3,1]])
    >>> 7
    Explanation: The optimal path taken by the first robot is shown in red, and the optimal path taken by the second robot is shown in blue.
    The cells visited by the first robot are set to 0.
    The second robot will collect 0 + 1 + 3 + 3 + 0 = 7 points.
    """


Prompt:
def placeWordInCrossword(board: List[List[str]], word: str) -> bool:
    """
    You are given an m x n matrix board, representing the current state of a crossword puzzle. The crossword contains lowercase English letters (from solved words), ' ' to represent any empty cells, and '#' to represent any blocked cells.
    A word can be placed horizontally (left to right or right to left) or vertically (top to bottom or bottom to top) in the board if:

    It does not occupy a cell containing the character '#'.
    The cell each letter is placed in must either be ' ' (empty) or match the letter already on the board.
    There must not be any empty cells ' ' or other lowercase letters directly left or right of the word if the word was placed horizontally.
    There must not be any empty cells ' ' or other lowercase letters directly above or below the word if the word was placed vertically.

    Given a string word, return true if word can be placed in board, or false otherwise.

    Example 1:

    >>> placeWordInCrossword(board = [["#", " ", "#"], [" ", " ", "#"], ["#", "c", " "]], word = "abc")
    >>> true
    Explanation: The word "abc" can be placed as shown above (top to bottom).

    Example 2:

    >>> placeWordInCrossword(board = [[" ", "#", "a"], [" ", "#", "c"], [" ", "#", "a"]], word = "ac")
    >>> false
    Explanation: It is impossible to place the word because there will always be a space/letter above or below it.
    Example 3:

    >>> placeWordInCrossword(board = [["#", " ", "#"], [" ", " ", "#"], ["#", " ", "c"]], word = "ca")
    >>> true
    Explanation: The word "ca" can be placed as shown above (right to left).
    """


Prompt:
def scoreOfStudents(s: str, answers: List[int]) -> int:
    """
    You are given a string s that contains digits 0-9, addition symbols '+', and multiplication symbols '*' only, representing a valid math expression of single digit numbers (e.g., 3+5*2). This expression was given to n elementary school students. The students were instructed to get the answer of the expression by following this order of operations:

    Compute multiplication, reading from left to right; Then,
    Compute addition, reading from left to right.

    You are given an integer array answers of length n, which are the submitted answers of the students in no particular order. You are asked to grade the answers, by following these rules:

    If an answer equals the correct answer of the expression, this student will be rewarded 5 points;
    Otherwise, if the answer could be interpreted as if the student applied the operators in the wrong order but had correct arithmetic, this student will be rewarded 2 points;
    Otherwise, this student will be rewarded 0 points.

    Return the sum of the points of the students.

    Example 1:

    >>> scoreOfStudents(s = "7+3*1*2", answers = [20,13,42])
    >>> 7
    Explanation: As illustrated above, the correct answer of the expression is 13, therefore one student is rewarded 5 points: [20,13,42]
    A student might have applied the operators in this wrong order: ((7+3)*1)*2 = 20. Therefore one student is rewarded 2 points: [20,13,42]
    The points for the students are: [2,5,0]. The sum of the points is 2+5+0=7.

    Example 2:

    >>> scoreOfStudents(s = "3+5*2", answers = [13,0,10,13,13,16,16])
    >>> 19
    Explanation: The correct answer of the expression is 13, therefore three students are rewarded 5 points each: [13,0,10,13,13,16,16]
    A student might have applied the operators in this wrong order: ((3+5)*2 = 16. Therefore two students are rewarded 2 points: [13,0,10,13,13,16,16]
    The points for the students are: [5,0,0,5,5,2,2]. The sum of the points is 5+0+0+5+5+2+2=19.

    Example 3:

    >>> scoreOfStudents(s = "6+0*1", answers = [12,9,6,4,8,6])
    >>> 10
    Explanation: The correct answer of the expression is 6.
    If a student had incorrectly done (6+0)*1, the answer would also be 6.
    By the rules of grading, the students will still be rewarded 5 points (as they got the correct answer), not 2 points.
    The points for the students are: [0,0,5,0,0,5]. The sum of the points is 10.
    """


Prompt:
def brightestPosition(lights: List[List[int]]) -> int:
    """
    A perfectly straight street is represented by a number line. The street has street lamp(s) on it and is represented by a 2D integer array lights. Each lights[i] = [positioni, rangei] indicates that there is a street lamp at position positioni that lights up the area from [positioni - rangei, positioni + rangei] (inclusive).
    The brightness of a position p is defined as the number of street lamp that light up the position p.
    Given lights, return the brightest position on the street. If there are multiple brightest positions, return the smallest one.

    Example 1:

    >>> brightestPosition(lights = [[-3,2],[1,2],[3,3]])
    >>> -1
    Explanation:
    The first street lamp lights up the area from [(-3) - 2, (-3) + 2] = [-5, -1].
    The second street lamp lights up the area from [1 - 2, 1 + 2] = [-1, 3].
    The third street lamp lights up the area from [3 - 3, 3 + 3] = [0, 6].

    Position -1 has a brightness of 2, illuminated by the first and second street light.
    Positions 0, 1, 2, and 3 have a brightness of 2, illuminated by the second and third street light.
    Out of all these positions, -1 is the smallest, so return it.

    Example 2:

    >>> brightestPosition(lights = [[1,0],[0,1]])
    >>> 1
    Explanation:
    The first street lamp lights up the area from [1 - 0, 1 + 0] = [1, 1].
    The second street lamp lights up the area from [0 - 1, 0 + 1] = [-1, 1].

    Position 1 has a brightness of 2, illuminated by the first and second street light.
    Return 1 because it is the brightest position on the street.

    Example 3:

    >>> brightestPosition(lights = [[1,2]])
    >>> -1
    Explanation:
    The first street lamp lights up the area from [1 - 2, 1 + 2] = [-1, 3].

    Positions -1, 0, 1, 2, and 3 have a brightness of 1, illuminated by the first street light.
    Out of all these positions, -1 is the smallest, so return it.
    """


Prompt:
def construct2DArray(original: List[int], m: int, n: int) -> List[List[int]]:
    """
    You are given a 0-indexed 1-dimensional (1D) integer array original, and two integers, m and n. You are tasked with creating a 2-dimensional (2D) array with  m rows and n columns using all the elements from original.
    The elements from indices 0 to n - 1 (inclusive) of original should form the first row of the constructed 2D array, the elements from indices n to 2 * n - 1 (inclusive) should form the second row of the constructed 2D array, and so on.
    Return an m x n 2D array constructed according to the above procedure, or an empty 2D array if it is impossible.

    Example 1:

    >>> construct2DArray(original = [1,2,3,4], m = 2, n = 2)
    >>> [[1,2],[3,4]]
    Explanation: The constructed 2D array should contain 2 rows and 2 columns.
    The first group of n=2 elements in original, [1,2], becomes the first row in the constructed 2D array.
    The second group of n=2 elements in original, [3,4], becomes the second row in the constructed 2D array.

    Example 2:

    >>> construct2DArray(original = [1,2,3], m = 1, n = 3)
    >>> [[1,2,3]]
    Explanation: The constructed 2D array should contain 1 row and 3 columns.
    Put all three elements in original into the first row of the constructed 2D array.

    Example 3:

    >>> construct2DArray(original = [1,2], m = 1, n = 1)
    >>> []
    Explanation: There are 2 elements in original.
    It is impossible to fit 2 elements in a 1x1 2D array, so return an empty 2D array.
    """


Prompt:
def numOfPairs(nums: List[str], target: str) -> int:
    """
    Given an array of digit strings nums and a digit string target, return the number of pairs of indices (i, j) (where i != j) such that the concatenation of nums[i] + nums[j] equals target.

    Example 1:

    >>> numOfPairs(nums = ["777","7","77","77"], target = "7777")
    >>> 4
    Explanation: Valid pairs are:
    - (0, 1): "777" + "7"
    - (1, 0): "7" + "777"
    - (2, 3): "77" + "77"
    - (3, 2): "77" + "77"

    Example 2:

    >>> numOfPairs(nums = ["123","4","12","34"], target = "1234")
    >>> 2
    Explanation: Valid pairs are:
    - (0, 1): "123" + "4"
    - (2, 3): "12" + "34"

    Example 3:

    >>> numOfPairs(nums = ["1","1","1"], target = "11")
    >>> 6
    Explanation: Valid pairs are:
    - (0, 1): "1" + "1"
    - (1, 0): "1" + "1"
    - (0, 2): "1" + "1"
    - (2, 0): "1" + "1"
    - (1, 2): "1" + "1"
    - (2, 1): "1" + "1"
    """


Prompt:
def maxConsecutiveAnswers(answerKey: str, k: int) -> int:
    """
    A teacher is writing a test with n true/false questions, with 'T' denoting true and 'F' denoting false. He wants to confuse the students by maximizing the number of consecutive questions with the same answer (multiple trues or multiple falses in a row).
    You are given a string answerKey, where answerKey[i] is the original answer to the ith question. In addition, you are given an integer k, the maximum number of times you may perform the following operation:

    Change the answer key for any question to 'T' or 'F' (i.e., set answerKey[i] to 'T' or 'F').

    Return the maximum number of consecutive 'T's or 'F's in the answer key after performing the operation at most k times.

    Example 1:

    >>> maxConsecutiveAnswers(answerKey = "TTFF", k = 2)
    >>> 4
    Explanation: We can replace both the 'F's with 'T's to make answerKey = "TTTT".
    There are four consecutive 'T's.

    Example 2:

    >>> maxConsecutiveAnswers(answerKey = "TFFT", k = 1)
    >>> 3
    Explanation: We can replace the first 'T' with an 'F' to make answerKey = "FFFT".
    Alternatively, we can replace the second 'T' with an 'F' to make answerKey = "TFFF".
    In both cases, there are three consecutive 'F's.

    Example 3:

    >>> maxConsecutiveAnswers(answerKey = "TTFTTFTT", k = 1)
    >>> 5
    Explanation: We can replace the first 'F' to make answerKey = "TTTTTFTT"
    Alternatively, we can replace the second 'F' to make answerKey = "TTFTTTTT".
    In both cases, there are five consecutive 'T's.
    """


Prompt:
def waysToPartition(nums: List[int], k: int) -> int:
    """
    You are given a 0-indexed integer array nums of length n. The number of ways to partition nums is the number of pivot indices that satisfy both conditions:

    1 <= pivot < n
    nums[0] + nums[1] + ... + nums[pivot - 1] == nums[pivot] + nums[pivot + 1] + ... + nums[n - 1]

    You are also given an integer k. You can choose to change the value of one element of nums to k, or to leave the array unchanged.
    Return the maximum possible number of ways to partition nums to satisfy both conditions after changing at most one element.

    Example 1:

    >>> waysToPartition(nums = [2,-1,2], k = 3)
    >>> 1
    Explanation: One optimal approach is to change nums[0] to k. The array becomes [3,-1,2].
    There is one way to partition the array:
    - For pivot = 2, we have the partition [3,-1 | 2]: 3 + -1 == 2.

    Example 2:

    >>> waysToPartition(nums = [0,0,0], k = 1)
    >>> 2
    Explanation: The optimal approach is to leave the array unchanged.
    There are two ways to partition the array:
    - For pivot = 1, we have the partition [0 | 0,0]: 0 == 0 + 0.
    - For pivot = 2, we have the partition [0,0 | 0]: 0 + 0 == 0.

    Example 3:

    >>> waysToPartition(nums = [22,4,-25,-20,-15,15,-16,7,19,-10,0,-13,-14], k = -33)
    >>> 4
    Explanation: One optimal approach is to change nums[2] to k. The array becomes [22,4,-33,-20,-15,15,-16,7,19,-10,0,-13,-14].
    There are four ways to partition the array.
    """


Prompt:
def minimumMoves(s: str) -> int:
    """
    You are given a string s consisting of n characters which are either 'X' or 'O'.
    A move is defined as selecting three consecutive characters of s and converting them to 'O'. Note that if a move is applied to the character 'O', it will stay the same.
    Return the minimum number of moves required so that all the characters of s are converted to 'O'.

    Example 1:

    >>> minimumMoves(s = "XXX")
    >>> 1
    Explanation: XXX -> OOO
    We select all the 3 characters and convert them in one move.

    Example 2:

    >>> minimumMoves(s = "XXOX")
    >>> 2
    Explanation: XXOX -> OOOX -> OOOO
    We select the first 3 characters in the first move, and convert them to 'O'.
    Then we select the last 3 characters and convert them so that the final string contains all 'O's.
    Example 3:

    >>> minimumMoves(s = "OOOO")
    >>> 0
    Explanation: There are no 'X's in s to convert.
    """


Prompt:
def missingRolls(rolls: List[int], mean: int, n: int) -> List[int]:
    """
    You have observations of n + m 6-sided dice rolls with each face numbered from 1 to 6. n of the observations went missing, and you only have the observations of m rolls. Fortunately, you have also calculated the average value of the n + m rolls.
    You are given an integer array rolls of length m where rolls[i] is the value of the ith observation. You are also given the two integers mean and n.
    Return an array of length n containing the missing observations such that the average value of the n + m rolls is exactly mean. If there are multiple valid answers, return any of them. If no such array exists, return an empty array.
    The average value of a set of k numbers is the sum of the numbers divided by k.
    Note that mean is an integer, so the sum of the n + m rolls should be divisible by n + m.

    Example 1:

    >>> missingRolls(rolls = [3,2,4,3], mean = 4, n = 2)
    >>> [6,6]
    Explanation: The mean of all n + m rolls is (3 + 2 + 4 + 3 + 6 + 6) / 6 = 4.

    Example 2:

    >>> missingRolls(rolls = [1,5,6], mean = 3, n = 4)
    >>> [2,3,2,2]
    Explanation: The mean of all n + m rolls is (1 + 5 + 6 + 2 + 3 + 2 + 2) / 7 = 3.

    Example 3:

    >>> missingRolls(rolls = [1,2,3,4], mean = 6, n = 4)
    >>> []
    Explanation: It is impossible for the mean to be 6 no matter what the 4 missing rolls are.
    """


Prompt:
def stoneGameIX(stones: List[int]) -> bool:
    """
    Alice and Bob continue their games with stones. There is a row of n stones, and each stone has an associated value. You are given an integer array stones, where stones[i] is the value of the ith stone.
    Alice and Bob take turns, with Alice starting first. On each turn, the player may remove any stone from stones. The player who removes a stone loses if the sum of the values of all removed stones is divisible by 3. Bob will win automatically if there are no remaining stones (even if it is Alice's turn).
    Assuming both players play optimally, return true if Alice wins and false if Bob wins.

    Example 1:

    >>> stoneGameIX(stones = [2,1])
    >>> true
    Explanation: The game will be played as follows:
    - Turn 1: Alice can remove either stone.
    - Turn 2: Bob removes the remaining stone.
    The sum of the removed stones is 1 + 2 = 3 and is divisible by 3. Therefore, Bob loses and Alice wins the game.

    Example 2:

    >>> stoneGameIX(stones = [2])
    >>> false
    Explanation: Alice will remove the only stone, and the sum of the values on the removed stones is 2.
    Since all the stones are removed and the sum of values is not divisible by 3, Bob wins the game.

    Example 3:

    >>> stoneGameIX(stones = [5,1,2,4,3])
    >>> false
    Explanation: Bob will always win. One possible way for Bob to win is shown below:
    - Turn 1: Alice can remove the second stone with value 1. Sum of removed stones = 1.
    - Turn 2: Bob removes the fifth stone with value 3. Sum of removed stones = 1 + 3 = 4.
    - Turn 3: Alices removes the fourth stone with value 4. Sum of removed stones = 1 + 3 + 4 = 8.
    - Turn 4: Bob removes the third stone with value 2. Sum of removed stones = 1 + 3 + 4 + 2 = 10.
    - Turn 5: Alice removes the first stone with value 5. Sum of removed stones = 1 + 3 + 4 + 2 + 5 = 15.
    Alice loses the game because the sum of the removed stones (15) is divisible by 3. Bob wins the game.
    """


Prompt:
def smallestSubsequence(s: str, k: int, letter: str, repetition: int) -> str:
    """
    You are given a string s, an integer k, a letter letter, and an integer repetition.
    Return the lexicographically smallest subsequence of s of length k that has the letter letter appear at least repetition times. The test cases are generated so that the letter appears in s at least repetition times.
    A subsequence is a string that can be derived from another string by deleting some or no characters without changing the order of the remaining characters.
    A string a is lexicographically smaller than a string b 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.

    Example 1:

    >>> smallestSubsequence(s = "leet", k = 3, letter = "e", repetition = 1)
    >>> "eet"
    Explanation: There are four subsequences of length 3 that have the letter 'e' appear at least 1 time:
    - "lee" (from "leet")
    - "let" (from "leet")
    - "let" (from "leet")
    - "eet" (from "leet")
    The lexicographically smallest subsequence among them is "eet".

    Example 2:

    >>> smallestSubsequence(s = "leetcode", k = 4, letter = "e", repetition = 2)
    >>> "ecde"
    Explanation: "ecde" is the lexicographically smallest subsequence of length 4 that has the letter "e" appear at least 2 times.

    Example 3:

    >>> smallestSubsequence(s = "bb", k = 2, letter = "b", repetition = 2)
    >>> "bb"
    Explanation: "bb" is the only subsequence of length 2 that has the letter "b" appear at least 2 times.
    """


Prompt:
def subarraysWithMoreZerosThanOnes(nums: List[int]) -> int:
    """
    You are given a binary array nums containing only the integers 0 and 1. Return the number of subarrays in nums that have more 1's than 0's. Since the answer may be very large, return it modulo 109 + 7.
    A subarray is a contiguous sequence of elements within an array.

    Example 1:

    >>> subarraysWithMoreZerosThanOnes(nums = [0,1,1,0,1])
    >>> 9
    Explanation:
    The subarrays of size 1 that have more ones than zeros are: [1], [1], [1]
    The subarrays of size 2 that have more ones than zeros are: [1,1]
    The subarrays of size 3 that have more ones than zeros are: [0,1,1], [1,1,0], [1,0,1]
    The subarrays of size 4 that have more ones than zeros are: [1,1,0,1]
    The subarrays of size 5 that have more ones than zeros are: [0,1,1,0,1]

    Example 2:

    >>> subarraysWithMoreZerosThanOnes(nums = [0])
    >>> 0
    Explanation:
    No subarrays have more ones than zeros.

    Example 3:

    >>> subarraysWithMoreZerosThanOnes(nums = [1])
    >>> 1
    Explanation:
    The subarrays of size 1 that have more ones than zeros are: [1]
    """


Prompt:
def twoOutOfThree(nums1: List[int], nums2: List[int], nums3: List[int]) -> List[int]:
    """
    Given three integer arrays nums1, nums2, and nums3, return a distinct array containing all the values that are present in at least two out of the three arrays. You may return the values in any order.

    Example 1:

    >>> twoOutOfThree(nums1 = [1,1,3,2], nums2 = [2,3], nums3 = [3])
    >>> [3,2]
    Explanation: The values that are present in at least two arrays are:
    - 3, in all three arrays.
    - 2, in nums1 and nums2.

    Example 2:

    >>> twoOutOfThree(nums1 = [3,1], nums2 = [2,3], nums3 = [1,2])
    >>> [2,3,1]
    Explanation: The values that are present in at least two arrays are:
    - 2, in nums2 and nums3.
    - 3, in nums1 and nums2.
    - 1, in nums1 and nums3.

    Example 3:

    >>> twoOutOfThree(nums1 = [1,2,2], nums2 = [4,3,3], nums3 = [5])
    >>> []
    Explanation: No value is present in at least two arrays.
    """


Prompt:
def minOperations(grid: List[List[int]], x: int) -> int:
    """
    You are given a 2D integer grid of size m x n and an integer x. In one operation, you can add x to or subtract x from any element in the grid.
    A uni-value grid is a grid where all the elements of it are equal.
    Return the minimum number of operations to make the grid uni-value. If it is not possible, return -1.

    Example 1:

    >>> minOperations(grid = [[2,4],[6,8]], x = 2)
    >>> 4
    Explanation: We can make every element equal to 4 by doing the following:
    - Add x to 2 once.
    - Subtract x from 6 once.
    - Subtract x from 8 twice.
    A total of 4 operations were used.

    Example 2:

    >>> minOperations(grid = [[1,5],[2,3]], x = 1)
    >>> 5
    Explanation: We can make every element equal to 3.

    Example 3:

    >>> minOperations(grid = [[1,2],[3,4]], x = 2)
    >>> -1
    Explanation: It is impossible to make every element equal.
    """


Prompt:
def minimumDifference(nums: List[int]) -> int:
    """
    You are given an integer array nums of 2 * n integers. You need to partition nums into two arrays of length n to minimize the absolute difference of the sums of the arrays. To partition nums, put each element of nums into one of the two arrays.
    Return the minimum possible absolute difference.

    Example 1:

    >>> minimumDifference(nums = [3,9,7,3])
    >>> 2
    Explanation: One optimal partition is: [3,9] and [7,3].
    The absolute difference between the sums of the arrays is abs((3 + 9) - (7 + 3)) = 2.

    Example 2:

    >>> minimumDifference(nums = [-36,36])
    >>> 72
    Explanation: One optimal partition is: [-36] and [36].
    The absolute difference between the sums of the arrays is abs((-36) - (36)) = 72.

    Example 3:

    >>> minimumDifference(nums = [2,-1,0,4,-2,-9])
    >>> 0
    Explanation: One optimal partition is: [2,4,-9] and [-1,0,-2].
    The absolute difference between the sums of the arrays is abs((2 + 4 + -9) - (-1 + 0 + -2)) = 0.
    """


Prompt:
def maximumAlternatingSubarraySum(nums: List[int]) -> int:
    """
    A subarray of a 0-indexed integer array is a contiguous non-empty sequence of elements within an array.
    The alternating subarray sum of a subarray that ranges from index i to j (inclusive, 0 <= i <= j < nums.length) is nums[i] - nums[i+1] + nums[i+2] - ... +/- nums[j].
    Given a 0-indexed integer array nums, return the maximum alternating subarray sum of any subarray of nums.

    Example 1:

    >>> maximumAlternatingSubarraySum(nums = [3,-1,1,2])
    >>> 5
    Explanation:
    The subarray [3,-1,1] has the largest alternating subarray sum.
    The alternating subarray sum is 3 - (-1) + 1 = 5.

    Example 2:

    >>> maximumAlternatingSubarraySum(nums = [2,2,2,2,2])
    >>> 2
    Explanation:
    The subarrays [2], [2,2,2], and [2,2,2,2,2] have the largest alternating subarray sum.
    The alternating subarray sum of [2] is 2.
    The alternating subarray sum of [2,2,2] is 2 - 2 + 2 = 2.
    The alternating subarray sum of [2,2,2,2,2] is 2 - 2 + 2 - 2 + 2 = 2.

    Example 3:

    >>> maximumAlternatingSubarraySum(nums = [1])
    >>> 1
    Explanation:
    There is only one non-empty subarray, which is [1].
    The alternating subarray sum is 1.
    """


Prompt:
def minMovesToSeat(seats: List[int], students: List[int]) -> int:
    """
    There are n availabe seats and n students standing in a room. You are given an array seats of length n, where seats[i] is the position of the ith seat. You are also given the array students of length n, where students[j] is the position of the jth student.
    You may perform the following move any number of times:

    Increase or decrease the position of the ith student by 1 (i.e., moving the ith student from position x to x + 1 or x - 1)

    Return the minimum number of moves required to move each student to a seat such that no two students are in the same seat.
    Note that there may be multiple seats or students in the same position at the beginning.

    Example 1:

    >>> minMovesToSeat(seats = [3,1,5], students = [2,7,4])
    >>> 4
    Explanation: The students are moved as follows:
    - The first student is moved from position 2 to position 1 using 1 move.
    - The second student is moved from position 7 to position 5 using 2 moves.
    - The third student is moved from position 4 to position 3 using 1 move.
    In total, 1 + 2 + 1 = 4 moves were used.

    Example 2:

    >>> minMovesToSeat(seats = [4,1,5,9], students = [1,3,2,6])
    >>> 7
    Explanation: The students are moved as follows:
    - The first student is not moved.
    - The second student is moved from position 3 to position 4 using 1 move.
    - The third student is moved from position 2 to position 5 using 3 moves.
    - The fourth student is moved from position 6 to position 9 using 3 moves.
    In total, 0 + 1 + 3 + 3 = 7 moves were used.

    Example 3:

    >>> minMovesToSeat(seats = [2,2,6,6], students = [1,3,2,6])
    >>> 4
    Explanation: Note that there are two seats at position 2 and two seats at position 6.
    The students are moved as follows:
    - The first student is moved from position 1 to position 2 using 1 move.
    - The second student is moved from position 3 to position 6 using 3 moves.
    - The third student is not moved.
    - The fourth student is not moved.
    In total, 1 + 3 + 0 + 0 = 4 moves were used.
    """


Prompt:
def winnerOfGame(colors: str) -> bool:
    """
    There are n pieces arranged in a line, and each piece is colored either by 'A' or by 'B'. You are given a string colors of length n where colors[i] is the color of the ith piece.
    Alice and Bob are playing a game where they take alternating turns removing pieces from the line. In this game, Alice moves first.

    Alice is only allowed to remove a piece colored 'A' if both its neighbors are also colored 'A'. She is not allowed to remove pieces that are colored 'B'.
    Bob is only allowed to remove a piece colored 'B' if both its neighbors are also colored 'B'. He is not allowed to remove pieces that are colored 'A'.
    Alice and Bob cannot remove pieces from the edge of the line.
    If a player cannot make a move on their turn, that player loses and the other player wins.

    Assuming Alice and Bob play optimally, return true if Alice wins, or return false if Bob wins.

    Example 1:

    >>> winnerOfGame(colors = "AAABABB")
    >>> true
    Explanation:
    AAABABB -> AABABB
    Alice moves first.
    She removes the second 'A' from the left since that is the only 'A' whose neighbors are both 'A'.

    Now it's Bob's turn.
    Bob cannot make a move on his turn since there are no 'B's whose neighbors are both 'B'.
    Thus, Alice wins, so return true.

    Example 2:

    >>> winnerOfGame(colors = "AA")
    >>> false
    Explanation:
    Alice has her turn first.
    There are only two 'A's and both are on the edge of the line, so she cannot move on her turn.
    Thus, Bob wins, so return false.

    Example 3:

    >>> winnerOfGame(colors = "ABBBBBBBAAA")
    >>> false
    Explanation:
    ABBBBBBBAAA -> ABBBBBBBAA
    Alice moves first.
    Her only option is to remove the second to last 'A' from the right.

    ABBBBBBBAA -> ABBBBBBAA
    Next is Bob's turn.
    He has many options for which 'B' piece to remove. He can pick any.

    On Alice's second turn, she has no more pieces that she can remove.
    Thus, Bob wins, so return false.
    """


Prompt:
def networkBecomesIdle(edges: List[List[int]], patience: List[int]) -> int:
    """
    There is a network of n servers, labeled from 0 to n - 1. You are given a 2D integer array edges, where edges[i] = [ui, vi] indicates there is a message channel between servers ui and vi, and they can pass any number of messages to each other directly in one second. You are also given a 0-indexed integer array patience of length n.
    All servers are connected, i.e., a message can be passed from one server to any other server(s) directly or indirectly through the message channels.
    The server labeled 0 is the master server. The rest are data servers. Each data server needs to send its message to the master server for processing and wait for a reply. Messages move between servers optimally, so every message takes the least amount of time to arrive at the master server. The master server will process all newly arrived messages instantly and send a reply to the originating server via the reversed path the message had gone through.
    At the beginning of second 0, each data server sends its message to be processed. Starting from second 1, at the beginning of every second, each data server will check if it has received a reply to the message it sent (including any newly arrived replies) from the master server:

    If it has not, it will resend the message periodically. The data server i will resend the message every patience[i] second(s), i.e., the data server i will resend the message if patience[i] second(s) have elapsed since the last time the message was sent from this server.
    Otherwise, no more resending will occur from this server.

    The network becomes idle when there are no messages passing between servers or arriving at servers.
    Return the earliest second starting from which the network becomes idle.

    Example 1:

    >>> networkBecomesIdle(edges = [[0,1],[1,2]], patience = [0,2,1])
    >>> 8
    Explanation:
    At (the beginning of) second 0,
    - Data server 1 sends its message (denoted 1A) to the master server.
    - Data server 2 sends its message (denoted 2A) to the master server.

    At second 1,
    - Message 1A arrives at the master server. Master server processes message 1A instantly and sends a reply 1A back.
    - Server 1 has not received any reply. 1 second (1 < patience[1] = 2) elapsed since this server has sent the message, therefore it does not resend the message.
    - Server 2 has not received any reply. 1 second (1 == patience[2] = 1) elapsed since this server has sent the message, therefore it resends the message (denoted 2B).

    At second 2,
    - The reply 1A arrives at server 1. No more resending will occur from server 1.
    - Message 2A arrives at the master server. Master server processes message 2A instantly and sends a reply 2A back.
    - Server 2 resends the message (denoted 2C).
    ...
    At second 4,
    - The reply 2A arrives at server 2. No more resending will occur from server 2.
    ...
    At second 7, reply 2D arrives at server 2.

    Starting from the beginning of the second 8, there are no messages passing between servers or arriving at servers.
    This is the time when the network becomes idle.

    Example 2:

    >>> networkBecomesIdle(edges = [[0,1],[0,2],[1,2]], patience = [0,10,10])
    >>> 3
    Explanation: Data servers 1 and 2 receive a reply back at the beginning of second 2.
    From the beginning of the second 3, the network becomes idle.
    """


Prompt:
def kthSmallestProduct(nums1: List[int], nums2: List[int], k: int) -> int:
    """
    Given two sorted 0-indexed integer arrays nums1 and nums2 as well as an integer k, return the kth (1-based) smallest product of nums1[i] * nums2[j] where 0 <= i < nums1.length and 0 <= j < nums2.length.

    Example 1:

    >>> kthSmallestProduct(nums1 = [2,5], nums2 = [3,4], k = 2)
    >>> 8
    Explanation: The 2 smallest products are:
    - nums1[0] * nums2[0] = 2 * 3 = 6
    - nums1[0] * nums2[1] = 2 * 4 = 8
    The 2nd smallest product is 8.

    Example 2:

    >>> kthSmallestProduct(nums1 = [-4,-2,0,3], nums2 = [2,4], k = 6)
    >>> 0
    Explanation: The 6 smallest products are:
    - nums1[0] * nums2[1] = (-4) * 4 = -16
    - nums1[0] * nums2[0] = (-4) * 2 = -8
    - nums1[1] * nums2[1] = (-2) * 4 = -8
    - nums1[1] * nums2[0] = (-2) * 2 = -4
    - nums1[2] * nums2[0] = 0 * 2 = 0
    - nums1[2] * nums2[1] = 0 * 4 = 0
    The 6th smallest product is 0.

    Example 3:

    >>> kthSmallestProduct(nums1 = [-2,-1,0,1,2], nums2 = [-3,-1,2,4,5], k = 3)
    >>> -6
    Explanation: The 3 smallest products are:
    - nums1[0] * nums2[4] = (-2) * 5 = -10
    - nums1[0] * nums2[3] = (-2) * 4 = -8
    - nums1[4] * nums2[0] = 2 * (-3) = -6
    The 3rd smallest product is -6.
    """


Prompt:
def areNumbersAscending(s: str) -> bool:
    """
    A sentence is a list of tokens separated by a single space with no leading or trailing spaces. Every token is either a positive number consisting of digits 0-9 with no leading zeros, or a word consisting of lowercase English letters.

    For example, "a puppy has 2 eyes 4 legs" is a sentence with seven tokens: "2" and "4" are numbers and the other tokens such as "puppy" are words.

    Given a string s representing a sentence, you need to check if all the numbers in s are strictly increasing from left to right (i.e., other than the last number, each number is strictly smaller than the number on its right in s).
    Return true if so, or false otherwise.

    Example 1:

    >>> areNumbersAscending(s = "1 box has 3 blue 4 red 6 green and 12 yellow marbles")
    >>> true
    Explanation: The numbers in s are: 1, 3, 4, 6, 12.
    They are strictly increasing from left to right: 1 < 3 < 4 < 6 < 12.

    Example 2:

    >>> areNumbersAscending(s = "hello world 5 x 5")
    >>> false
    Explanation: The numbers in s are: 5, 5. They are not strictly increasing.

    Example 3:

    >>> areNumbersAscending(s = "sunset is at 7 51 pm overnight lows will be in the low 50 and 60 s")
    >>> false
    Explanation: The numbers in s are: 7, 51, 50, 60. They are not strictly increasing.
    """


Prompt:
def countMaxOrSubsets(nums: List[int]) -> int:
    """
    Given an integer array nums, find the maximum possible bitwise OR of a subset of nums and return the number of different non-empty subsets with the maximum bitwise OR.
    An array a is a subset of an array b if a can be obtained from b by deleting some (possibly zero) elements of b. Two subsets are considered different if the indices of the elements chosen are different.
    The bitwise OR of an array a is equal to a[0] OR a[1] OR ... OR a[a.length - 1] (0-indexed).

    Example 1:

    >>> countMaxOrSubsets(nums = [3,1])
    >>> 2
    Explanation: The maximum possible bitwise OR of a subset is 3. There are 2 subsets with a bitwise OR of 3:
    - [3]
    - [3,1]

    Example 2:

    >>> countMaxOrSubsets(nums = [2,2,2])
    >>> 7
    Explanation: All non-empty subsets of [2,2,2] have a bitwise OR of 2. There are 23 - 1 = 7 total subsets.

    Example 3:

    >>> countMaxOrSubsets(nums = [3,2,1,5])
    >>> 6
    Explanation: The maximum possible bitwise OR of a subset is 7. There are 6 subsets with a bitwise OR of 7:
    - [3,5]
    - [3,1,5]
    - [3,2,5]
    - [3,2,1,5]
    - [2,5]
    - [2,1,5]
    """


Prompt:
def secondMinimum(n: int, edges: List[List[int]], time: int, change: int) -> int:
    """
    A city is represented as a bi-directional connected graph with n vertices where each vertex is labeled from 1 to n (inclusive). The edges in the graph are represented as a 2D integer array edges, where each edges[i] = [ui, vi] denotes a bi-directional edge between vertex ui and vertex vi. Every vertex pair is connected by at most one edge, and no vertex has an edge to itself. The time taken to traverse any edge is time minutes.
    Each vertex has a traffic signal which changes its color from green to red and vice versa every change minutes. All signals change at the same time. You can enter a vertex at any time, but can leave a vertex only when the signal is green. You cannot wait at a vertex if the signal is green.
    The second minimum value is defined as the smallest value strictly larger than the minimum value.

    For example the second minimum value of [2, 3, 4] is 3, and the second minimum value of [2, 2, 4] is 4.

    Given n, edges, time, and change, return the second minimum time it will take to go from vertex 1 to vertex n.
    Notes:

    You can go through any vertex any number of times, including 1 and n.
    You can assume that when the journey starts, all signals have just turned green.

    Example 1:

    >>> secondMinimum(n = 5, edges = [[1,2],[1,3],[1,4],[3,4],[4,5]], time = 3, change = 5)
    >>> 13
    Explanation:
    The figure on the left shows the given graph.
    The blue path in the figure on the right is the minimum time path.
    The time taken is:
    - Start at 1, time elapsed=0
    - 1 -> 4: 3 minutes, time elapsed=3
    - 4 -> 5: 3 minutes, time elapsed=6
    Hence the minimum time needed is 6 minutes.

    The red path shows the path to get the second minimum time.
    - Start at 1, time elapsed=0
    - 1 -> 3: 3 minutes, time elapsed=3
    - 3 -> 4: 3 minutes, time elapsed=6
    - Wait at 4 for 4 minutes, time elapsed=10
    - 4 -> 5: 3 minutes, time elapsed=13
    Hence the second minimum time is 13 minutes.

    Example 2:

    >>> secondMinimum(n = 2, edges = [[1,2]], time = 3, change = 2)
    >>> 11
    Explanation:
    The minimum time path is 1 -> 2 with time = 3 minutes.
    The second minimum time path is 1 -> 2 -> 1 -> 2 with time = 11 minutes.
    """


Prompt:
# class ListNode:
#     def __init__(val=0, next=None):
#         self.val = val
#         self.next = next
class Solution:
    def sortLinkedList(head: Optional[ListNode]) -> Optional[ListNode]:
    """
    Given the head of a singly linked list that is sorted in non-decreasing order using the absolute values of its nodes, return the list sorted in non-decreasing order using the actual values of its nodes.

    Example 1:

    >>> __init__(head = [0,2,-5,5,10,-10])
    >>> [-10,-5,0,2,5,10]
    Explanation:
    The list sorted in non-descending order using the absolute values of the nodes is [0,2,-5,5,10,-10].
    The list sorted in non-descending order using the actual values is [-10,-5,0,2,5,10].

    Example 2:

    >>> __init__(head = [0,1,2])
    >>> [0,1,2]
    Explanation:
    The linked list is already sorted in non-decreasing order.

    Example 3:

    >>> __init__(head = [1])
    >>> [1]
    Explanation:
    The linked list is already sorted in non-decreasing order.
    """


Prompt:
def countValidWords(sentence: str) -> int:
    """
    A sentence consists of lowercase letters ('a' to 'z'), digits ('0' to '9'), hyphens ('-'), punctuation marks ('!', '.', and ','), and spaces (' ') only. Each sentence can be broken down into one or more tokens separated by one or more spaces ' '.
    A token is a valid word if all three of the following are true:

    It only contains lowercase letters, hyphens, and/or punctuation (no digits).
    There is at most one hyphen '-'. If present, it must be surrounded by lowercase characters ("a-b" is valid, but "-ab" and "ab-" are not valid).
    There is at most one punctuation mark. If present, it must be at the end of the token ("ab,", "cd!", and "." are valid, but "a!b" and "c.," are not valid).

    Examples of valid words include "a-b.", "afad", "ba-c", "a!", and "!".
    Given a string sentence, return the number of valid words in sentence.

    Example 1:

    >>> countValidWords(sentence = "cat and  dog")
    >>> 3
    Explanation: The valid words in the sentence are "cat", "and", and "dog".

    Example 2:

    >>> countValidWords(sentence = "!this  1-s b8d!")
    >>> 0
    Explanation: There are no valid words in the sentence.
    "!this" is invalid because it starts with a punctuation mark.
    "1-s" and "b8d" are invalid because they contain digits.

    Example 3:

    >>> countValidWords(sentence = "alice and  bob are playing stone-game10")
    >>> 5
    Explanation: The valid words in the sentence are "alice", "and", "bob", "are", and "playing".
    "stone-game10" is invalid because it contains digits.
    """


Prompt:
def nextBeautifulNumber(n: int) -> int:
    """
    An integer x is numerically balanced if for every digit d in the number x, there are exactly d occurrences of that digit in x.
    Given an integer n, return the smallest numerically balanced number strictly greater than n.

    Example 1:

    >>> nextBeautifulNumber(n = 1)
    >>> 22
    Explanation:
    22 is numerically balanced since:
    - The digit 2 occurs 2 times.
    It is also the smallest numerically balanced number strictly greater than 1.

    Example 2:

    >>> nextBeautifulNumber(n = 1000)
    >>> 1333
    Explanation:
    1333 is numerically balanced since:
    - The digit 1 occurs 1 time.
    - The digit 3 occurs 3 times.
    It is also the smallest numerically balanced number strictly greater than 1000.
    Note that 1022 cannot be the answer because 0 appeared more than 0 times.

    Example 3:

    >>> nextBeautifulNumber(n = 3000)
    >>> 3133
    Explanation:
    3133 is numerically balanced since:
    - The digit 1 occurs 1 time.
    - The digit 3 occurs 3 times.
    It is also the smallest numerically balanced number strictly greater than 3000.
    """


Prompt:
def countHighestScoreNodes(parents: List[int]) -> int:
    """
    There is a binary tree rooted at 0 consisting of n nodes. The nodes are labeled from 0 to n - 1. You are given a 0-indexed integer array parents representing the tree, where parents[i] is the parent of node i. Since node 0 is the root, parents[0] == -1.
    Each node has a score. To find the score of a node, consider if the node and the edges connected to it were removed. The tree would become one or more non-empty subtrees. The size of a subtree is the number of the nodes in it. The score of the node is the product of the sizes of all those subtrees.
    Return the number of nodes that have the highest score.

    Example 1:

    >>> countHighestScoreNodes(parents = [-1,2,0,2,0])
    >>> 3
    Explanation:
    - The score of node 0 is: 3 * 1 = 3
    - The score of node 1 is: 4 = 4
    - The score of node 2 is: 1 * 1 * 2 = 2
    - The score of node 3 is: 4 = 4
    - The score of node 4 is: 4 = 4
    The highest score is 4, and three nodes (node 1, node 3, and node 4) have the highest score.

    Example 2:

    >>> countHighestScoreNodes(parents = [-1,2,0])
    >>> 2
    Explanation:
    - The score of node 0 is: 2 = 2
    - The score of node 1 is: 2 = 2
    - The score of node 2 is: 1 * 1 = 1
    The highest score is 2, and two nodes (node 0 and node 1) have the highest score.
    """


Prompt:
def minimumTime(n: int, relations: List[List[int]], time: List[int]) -> int:
    """
    You are given an integer n, which indicates that there are n courses labeled from 1 to n. You are also given a 2D integer array relations where relations[j] = [prevCoursej, nextCoursej] denotes that course prevCoursej has to be completed before course nextCoursej (prerequisite relationship). Furthermore, you are given a 0-indexed integer array time where time[i] denotes how many months it takes to complete the (i+1)th course.
    You must find the minimum number of months needed to complete all the courses following these rules:

    You may start taking a course at any time if the prerequisites are met.
    Any number of courses can be taken at the same time.

    Return the minimum number of months needed to complete all the courses.
    Note: The test cases are generated such that it is possible to complete every course (i.e., the graph is a directed acyclic graph).

    Example 1:

    >>> minimumTime(n = 3, relations = [[1,3],[2,3]], time = [3,2,5])
    >>> 8
    Explanation: The figure above represents the given graph and the time required to complete each course.
    We start course 1 and course 2 simultaneously at month 0.
    Course 1 takes 3 months and course 2 takes 2 months to complete respectively.
    Thus, the earliest time we can start course 3 is at month 3, and the total time required is 3 + 5 = 8 months.

    Example 2:

    >>> minimumTime(n = 5, relations = [[1,5],[2,5],[3,5],[3,4],[4,5]], time = [1,2,3,4,5])
    >>> 12
    Explanation: The figure above represents the given graph and the time required to complete each course.
    You can start courses 1, 2, and 3 at month 0.
    You can complete them after 1, 2, and 3 months respectively.
    Course 4 can be taken only after course 3 is completed, i.e., after 3 months. It is completed after 3 + 4 = 7 months.
    Course 5 can be taken only after courses 1, 2, 3, and 4 have been completed, i.e., after max(1,2,3,7) = 7 months.
    Thus, the minimum time needed to complete all the courses is 7 + 5 = 12 months.
    """


Prompt:
def minimumCost(sentence: str, k: int) -> int:
    """
    You are given a string sentence containing words separated by spaces, and an integer k. Your task is to separate sentence into rows where the number of characters in each row is at most k. You may assume that sentence does not begin or end with a space, and the words in sentence are separated by a single space.
    You can split sentence into rows by inserting line breaks between words in sentence. A word cannot be split between two rows. Each word must be used exactly once, and the word order cannot be rearranged. Adjacent words in a row should be separated by a single space, and rows should not begin or end with spaces.
    The cost of a row with length n is (k - n)2, and the total cost is the sum of the costs for all rows except the last one.

    For example if sentence = "i love leetcode" and k = 12:

    Separating sentence into "i", "love", and "leetcode" has a cost of (12 - 1)2 + (12 - 4)2 = 185.
    Separating sentence into "i love", and "leetcode" has a cost of (12 - 6)2 = 36.
    Separating sentence into "i", and "love leetcode" is not possible because the length of "love leetcode" is greater than k.

    Return the minimum possible total cost of separating sentence into rows.

    Example 1:

    >>> minimumCost(sentence = "i love leetcode", k = 12)
    >>> 36
    Explanation:
    Separating sentence into "i", "love", and "leetcode" has a cost of (12 - 1)2 + (12 - 4)2 = 185.
    Separating sentence into "i love", and "leetcode" has a cost of (12 - 6)2 = 36.
    Separating sentence into "i", "love leetcode" is not possible because "love leetcode" has length 13.
    36 is the minimum possible total cost so return it.

    Example 2:

    >>> minimumCost(sentence = "apples and bananas taste great", k = 7)
    >>> 21
    Explanation
    Separating sentence into "apples", "and", "bananas", "taste", and "great" has a cost of (7 - 6)2 + (7 - 3)2 + (7 - 7)2 + (7 - 5)2 = 21.
    21 is the minimum possible total cost so return it.

    Example 3:

    >>> minimumCost(sentence = "a", k = 5)
    >>> 0
    Explanation:
    The cost of the last row is not included in the total cost, and since there is only one row, return 0.
    """


Prompt:
def kthDistinct(arr: List[str], k: int) -> str:
    """
    A distinct string is a string that is present only once in an array.
    Given an array of strings arr, and an integer k, return the kth distinct string present in arr. If there are fewer than k distinct strings, return an empty string "".
    Note that the strings are considered in the order in which they appear in the array.

    Example 1:

    >>> kthDistinct(arr = ["d","b","c","b","c","a"], k = 2)
    >>> "a"
    Explanation:
    The only distinct strings in arr are "d" and "a".
    "d" appears 1st, so it is the 1st distinct string.
    "a" appears 2nd, so it is the 2nd distinct string.
    Since k == 2, "a" is returned.

    Example 2:

    >>> kthDistinct(arr = ["aaa","aa","a"], k = 1)
    >>> "aaa"
    Explanation:
    All strings in arr are distinct, so the 1st string "aaa" is returned.

    Example 3:

    >>> kthDistinct(arr = ["a","b","a"], k = 3)
    >>> ""
    Explanation:
    The only distinct string is "b". Since there are fewer than 3 distinct strings, we return an empty string "".
    """


Prompt:
def maxTwoEvents(events: List[List[int]]) -> int:
    """
    You are given a 0-indexed 2D integer array of events where events[i] = [startTimei, endTimei, valuei]. The ith event starts at startTimei and ends at endTimei, and if you attend this event, you will receive a value of valuei. You can choose at most two non-overlapping events to attend such that the sum of their values is maximized.
    Return this maximum sum.
    Note that the start time and end time is inclusive: that is, you cannot attend two events where one of them starts and the other ends at the same time. More specifically, if you attend an event with end time t, the next event must start at or after t + 1.

    Example 1:

    >>> maxTwoEvents(events = [[1,3,2],[4,5,2],[2,4,3]])
    >>> 4
    Explanation: Choose the green events, 0 and 1 for a sum of 2 + 2 = 4.

    Example 2:

    >>> maxTwoEvents(events = [[1,3,2],[4,5,2],[1,5,5]])
    >>> 5
    Explanation: Choose event 2 for a sum of 5.

    Example 3:

    >>> maxTwoEvents(events = [[1,5,3],[1,5,1],[6,6,5]])
    >>> 8
    Explanation: Choose events 0 and 2 for a sum of 3 + 5 = 8.
    """


Prompt:
def platesBetweenCandles(s: str, queries: List[List[int]]) -> List[int]:
    """
    There is a long table with a line of plates and candles arranged on top of it. You are given a 0-indexed string s consisting of characters '*' and '|' only, where a '*' represents a plate and a '|' represents a candle.
    You are also given a 0-indexed 2D integer array queries where queries[i] = [lefti, righti] denotes the substring s[lefti...righti] (inclusive). For each query, you need to find the number of plates between candles that are in the substring. A plate is considered between candles if there is at least one candle to its left and at least one candle to its right in the substring.

    For example, s = "||**||**|*", and a query [3, 8] denotes the substring "*||**|". The number of plates between candles in this substring is 2, as each of the two plates has at least one candle in the substring to its left and right.

    Return an integer array answer where answer[i] is the answer to the ith query.

    Example 1:

    >>> platesBetweenCandles(s = "**|**|***|", queries = [[2,5],[5,9]])
    >>> [2,3]
    Explanation:
    - queries[0] has two plates between candles.
    - queries[1] has three plates between candles.

    Example 2:

    >>> platesBetweenCandles(s = "***|**|*****|**||**|*", queries = [[1,17],[4,5],[14,17],[5,11],[15,16]])
    >>> [9,0,0,0,0]
    Explanation:
    - queries[0] has nine plates between candles.
    - The other queries have zero plates between candles.
    """


Prompt:
def countCombinations(pieces: List[str], positions: List[List[int]]) -> int:
    """
    There is an 8 x 8 chessboard containing n pieces (rooks, queens, or bishops). You are given a string array pieces of length n, where pieces[i] describes the type (rook, queen, or bishop) of the ith piece. In addition, you are given a 2D integer array positions also of length n, where positions[i] = [ri, ci] indicates that the ith piece is currently at the 1-based coordinate (ri, ci) on the chessboard.
    When making a move for a piece, you choose a destination square that the piece will travel toward and stop on.

    A rook can only travel horizontally or vertically from (r, c) to the direction of (r+1, c), (r-1, c), (r, c+1), or (r, c-1).
    A queen can only travel horizontally, vertically, or diagonally from (r, c) to the direction of (r+1, c), (r-1, c), (r, c+1), (r, c-1), (r+1, c+1), (r+1, c-1), (r-1, c+1), (r-1, c-1).
    A bishop can only travel diagonally from (r, c) to the direction of (r+1, c+1), (r+1, c-1), (r-1, c+1), (r-1, c-1).

    You must make a move for every piece on the board simultaneously. A move combination consists of all the moves performed on all the given pieces. Every second, each piece will instantaneously travel one square towards their destination if they are not already at it. All pieces start traveling at the 0th second. A move combination is invalid if, at a given time, two or more pieces occupy the same square.
    Return the number of valid move combinations.
    Notes:

    No two pieces will start in the same square.
    You may choose the square a piece is already on as its destination.
    If two pieces are directly adjacent to each other, it is valid for them to move past each other and swap positions in one second.

    Example 1:

    >>> countCombinations(pieces = ["rook"], positions = [[1,1]])
    >>> 15
    Explanation: The image above shows the possible squares the piece can move to.

    Example 2:

    >>> countCombinations(pieces = ["queen"], positions = [[1,1]])
    >>> 22
    Explanation: The image above shows the possible squares the piece can move to.

    Example 3:

    >>> countCombinations(pieces = ["bishop"], positions = [[4,3]])
    >>> 12
    Explanation: The image above shows the possible squares the piece can move to.
    """


Prompt:
def smallestEqual(nums: List[int]) -> int:
    """
    Given a 0-indexed integer array nums, return the smallest index i of nums such that i mod 10 == nums[i], or -1 if such index does not exist.
    x mod y denotes the remainder when x is divided by y.

    Example 1:

    >>> smallestEqual(nums = [0,1,2])
    >>> 0
    Explanation:
    i=0: 0 mod 10 = 0 == nums[0].
    i=1: 1 mod 10 = 1 == nums[1].
    i=2: 2 mod 10 = 2 == nums[2].
    All indices have i mod 10 == nums[i], so we return the smallest index 0.

    Example 2:

    >>> smallestEqual(nums = [4,3,2,1])
    >>> 2
    Explanation:
    i=0: 0 mod 10 = 0 != nums[0].
    i=1: 1 mod 10 = 1 != nums[1].
    i=2: 2 mod 10 = 2 == nums[2].
    i=3: 3 mod 10 = 3 != nums[3].
    2 is the only index which has i mod 10 == nums[i].

    Example 3:

    >>> smallestEqual(nums = [1,2,3,4,5,6,7,8,9,0])
    >>> -1
    Explanation: No index satisfies i mod 10 == nums[i].
    """


Prompt:
# class ListNode:
#     def __init__(val=0, next=None):
#         self.val = val
#         self.next = next
class Solution:
    def nodesBetweenCriticalPoints(head: Optional[ListNode]) -> List[int]:
    """
    A critical point in a linked list is defined as either a local maxima or a local minima.
    A node is a local maxima if the current node has a value strictly greater than the previous node and the next node.
    A node is a local minima if the current node has a value strictly smaller than the previous node and the next node.
    Note that a node can only be a local maxima/minima if there exists both a previous node and a next node.
    Given a linked list head, return an array of length 2 containing [minDistance, maxDistance] where minDistance is the minimum distance between any two distinct critical points and maxDistance is the maximum distance between any two distinct critical points. If there are fewer than two critical points, return [-1, -1].

    Example 1:

    >>> __init__(head = [3,1])
    >>> [-1,-1]
    Explanation: There are no critical points in [3,1].

    Example 2:

    >>> __init__(head = [5,3,1,2,5,1,2])
    >>> [1,3]
    Explanation: There are three critical points:
    - [5,3,1,2,5,1,2]: The third node is a local minima because 1 is less than 3 and 2.
    - [5,3,1,2,5,1,2]: The fifth node is a local maxima because 5 is greater than 2 and 1.
    - [5,3,1,2,5,1,2]: The sixth node is a local minima because 1 is less than 5 and 2.
    The minimum distance is between the fifth and the sixth node. minDistance = 6 - 5 = 1.
    The maximum distance is between the third and the sixth node. maxDistance = 6 - 3 = 3.

    Example 3:

    >>> __init__(head = [1,3,2,2,3,2,2,2,7])
    >>> [3,3]
    Explanation: There are two critical points:
    - [1,3,2,2,3,2,2,2,7]: The second node is a local maxima because 3 is greater than 1 and 2.
    - [1,3,2,2,3,2,2,2,7]: The fifth node is a local maxima because 3 is greater than 2 and 2.
    Both the minimum and maximum distances are between the second and the fifth node.
    Thus, minDistance and maxDistance is 5 - 2 = 3.
    Note that the last node is not considered a local maxima because it does not have a next node.
    """