Prompt:
def capitalizeTitle(title: str) -> str:
    """
    You are given a string title consisting of one or more words separated by a single space, where each word consists of English letters. Capitalize the string by changing the capitalization of each word such that:

    If the length of the word is 1 or 2 letters, change all letters to lowercase.
    Otherwise, change the first letter to uppercase and the remaining letters to lowercase.

    Return the capitalized title.

    Example 1:

    >>> capitalizeTitle(title = "capiTalIze tHe titLe")
    >>> "Capitalize The Title"
    Explanation:
    Since all the words have a length of at least 3, the first letter of each word is uppercase, and the remaining letters are lowercase.

    Example 2:

    >>> capitalizeTitle(title = "First leTTeR of EACH Word")
    >>> "First Letter of Each Word"
    Explanation:
    The word "of" has length 2, so it is all lowercase.
    The remaining words have a length of at least 3, so the first letter of each remaining word is uppercase, and the remaining letters are lowercase.

    Example 3:

    >>> capitalizeTitle(title = "i lOve leetcode")
    >>> "i Love Leetcode"
    Explanation:
    The word "i" has length 1, so it is lowercase.
    The remaining words have a length of at least 3, so the first letter of each remaining word is uppercase, and the remaining letters are lowercase.
    """


Prompt:
# class ListNode:
#     def __init__(val=0, next=None):
#         self.val = val
#         self.next = next
class Solution:
    def pairSum(head: Optional[ListNode]) -> int:
    """
    In a linked list of size n, where n is even, the ith node (0-indexed) of the linked list is known as the twin of the (n-1-i)th node, if 0 <= i <= (n / 2) - 1.

    For example, if n = 4, then node 0 is the twin of node 3, and node 1 is the twin of node 2. These are the only nodes with twins for n = 4.

    The twin sum is defined as the sum of a node and its twin.
    Given the head of a linked list with even length, return the maximum twin sum of the linked list.

    Example 1:

    >>> __init__(head = [5,4,2,1])
    >>> 6
    Explanation:
    Nodes 0 and 1 are the twins of nodes 3 and 2, respectively. All have twin sum = 6.
    There are no other nodes with twins in the linked list.
    Thus, the maximum twin sum of the linked list is 6.

    Example 2:

    >>> __init__(head = [4,2,2,3])
    >>> 7
    Explanation:
    The nodes with twins present in this linked list are:
    - Node 0 is the twin of node 3 having a twin sum of 4 + 3 = 7.
    - Node 1 is the twin of node 2 having a twin sum of 2 + 2 = 4.
    Thus, the maximum twin sum of the linked list is max(7, 4) = 7.

    Example 3:

    >>> __init__(head = [1,100000])
    >>> 100001
    Explanation:
    There is only one node with a twin in the linked list having twin sum of 1 + 100000 = 100001.
    """


Prompt:
def longestPalindrome(words: List[str]) -> int:
    """
    You are given an array of strings words. Each element of words consists of two lowercase English letters.
    Create the longest possible palindrome by selecting some elements from words and concatenating them in any order. Each element can be selected at most once.
    Return the length of the longest palindrome that you can create. If it is impossible to create any palindrome, return 0.
    A palindrome is a string that reads the same forward and backward.

    Example 1:

    >>> longestPalindrome(words = ["lc","cl","gg"])
    >>> 6
    Explanation: One longest palindrome is "lc" + "gg" + "cl" = "lcggcl", of length 6.
    Note that "clgglc" is another longest palindrome that can be created.

    Example 2:

    >>> longestPalindrome(words = ["ab","ty","yt","lc","cl","ab"])
    >>> 8
    Explanation: One longest palindrome is "ty" + "lc" + "cl" + "yt" = "tylcclyt", of length 8.
    Note that "lcyttycl" is another longest palindrome that can be created.

    Example 3:

    >>> longestPalindrome(words = ["cc","ll","xx"])
    >>> 2
    Explanation: One longest palindrome is "cc", of length 2.
    Note that "ll" is another longest palindrome that can be created, and so is "xx".
    """


Prompt:
def possibleToStamp(grid: List[List[int]], stampHeight: int, stampWidth: int) -> bool:
    """
    You are given an m x n binary matrix grid where each cell is either 0 (empty) or 1 (occupied).
    You are then given stamps of size stampHeight x stampWidth. We want to fit the stamps such that they follow the given restrictions and requirements:

    Cover all the empty cells.
    Do not cover any of the occupied cells.
    We can put as many stamps as we want.
    Stamps can overlap with each other.
    Stamps are not allowed to be rotated.
    Stamps must stay completely inside the grid.

    Return true if it is possible to fit the stamps while following the given restrictions and requirements. Otherwise, return false.

    Example 1:

    >>> possibleToStamp(grid = [[1,0,0,0],[1,0,0,0],[1,0,0,0],[1,0,0,0],[1,0,0,0]], stampHeight = 4, stampWidth = 3)
    >>> true
    Explanation: We have two overlapping stamps (labeled 1 and 2 in the image) that are able to cover all the empty cells.

    Example 2:

    >>> possibleToStamp(grid = [[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]], stampHeight = 2, stampWidth = 2)
    >>> false
    Explanation: There is no way to fit the stamps onto all the empty cells without the stamps going outside the grid.
    """


Prompt:
def checkValid(matrix: List[List[int]]) -> bool:
    """
    An n x n matrix is valid if every row and every column contains all the integers from 1 to n (inclusive).
    Given an n x n integer matrix matrix, return true if the matrix is valid. Otherwise, return false.

    Example 1:

    >>> checkValid(matrix = [[1,2,3],[3,1,2],[2,3,1]])
    >>> true
    Explanation: In this case, n = 3, and every row and column contains the numbers 1, 2, and 3.
    Hence, we return true.

    Example 2:

    >>> checkValid(matrix = [[1,1,1],[1,2,3],[1,2,3]])
    >>> false
    Explanation: In this case, n = 3, but the first row and the first column do not contain the numbers 2 or 3.
    Hence, we return false.
    """


Prompt:
def minSwaps(nums: List[int]) -> int:
    """
    A swap is defined as taking two distinct positions in an array and swapping the values in them.
    A circular array is defined as an array where we consider the first element and the last element to be adjacent.
    Given a binary circular array nums, return the minimum number of swaps required to group all 1's present in the array together at any location.

    Example 1:

    >>> minSwaps(nums = [0,1,0,1,1,0,0])
    >>> 1
    Explanation: Here are a few of the ways to group all the 1's together:
    [0,0,1,1,1,0,0] using 1 swap.
    [0,1,1,1,0,0,0] using 1 swap.
    [1,1,0,0,0,0,1] using 2 swaps (using the circular property of the array).
    There is no way to group all 1's together with 0 swaps.
    Thus, the minimum number of swaps required is 1.

    Example 2:

    >>> minSwaps(nums = [0,1,1,1,0,0,1,1,0])
    >>> 2
    Explanation: Here are a few of the ways to group all the 1's together:
    [1,1,1,0,0,0,0,1,1] using 2 swaps (using the circular property of the array).
    [1,1,1,1,1,0,0,0,0] using 2 swaps.
    There is no way to group all 1's together with 0 or 1 swaps.
    Thus, the minimum number of swaps required is 2.

    Example 3:

    >>> minSwaps(nums = [1,1,0,0,1])
    >>> 0
    Explanation: All the 1's are already grouped together due to the circular property of the array.
    Thus, the minimum number of swaps required is 0.
    """


Prompt:
def wordCount(startWords: List[str], targetWords: List[str]) -> int:
    """
    You are given two 0-indexed arrays of strings startWords and targetWords. Each string consists of lowercase English letters only.
    For each string in targetWords, check if it is possible to choose a string from startWords and perform a conversion operation on it to be equal to that from targetWords.
    The conversion operation is described in the following two steps:

    Append any lowercase letter that is not present in the string to its end.

    For example, if the string is "abc", the letters 'd', 'e', or 'y' can be added to it, but not 'a'. If 'd' is added, the resulting string will be "abcd".

    Rearrange the letters of the new string in any arbitrary order.

    For example, "abcd" can be rearranged to "acbd", "bacd", "cbda", and so on. Note that it can also be rearranged to "abcd" itself.

    Return the number of strings in targetWords that can be obtained by performing the operations on any string of startWords.
    Note that you will only be verifying if the string in targetWords can be obtained from a string in startWords by performing the operations. The strings in startWords do not actually change during this process.

    Example 1:

    >>> wordCount(startWords = ["ant","act","tack"], targetWords = ["tack","act","acti"])
    >>> 2
    Explanation:
    - In order to form targetWords[0] = "tack", we use startWords[1] = "act", append 'k' to it, and rearrange "actk" to "tack".
    - There is no string in startWords that can be used to obtain targetWords[1] = "act".
      Note that "act" does exist in startWords, but we must append one letter to the string before rearranging it.
    - In order to form targetWords[2] = "acti", we use startWords[1] = "act", append 'i' to it, and rearrange "acti" to "acti" itself.

    Example 2:

    >>> wordCount(startWords = ["ab","a"], targetWords = ["abc","abcd"])
    >>> 1
    Explanation:
    - In order to form targetWords[0] = "abc", we use startWords[0] = "ab", add 'c' to it, and rearrange it to "abc".
    - There is no string in startWords that can be used to obtain targetWords[1] = "abcd".
    """


Prompt:
def earliestFullBloom(plantTime: List[int], growTime: List[int]) -> int:
    """
    You have n flower seeds. Every seed must be planted first before it can begin to grow, then bloom. Planting a seed takes time and so does the growth of a seed. You are given two 0-indexed integer arrays plantTime and growTime, of length n each:

    plantTime[i] is the number of full days it takes you to plant the ith seed. Every day, you can work on planting exactly one seed. You do not have to work on planting the same seed on consecutive days, but the planting of a seed is not complete until you have worked plantTime[i] days on planting it in total.
    growTime[i] is the number of full days it takes the ith seed to grow after being completely planted. After the last day of its growth, the flower blooms and stays bloomed forever.

    From the beginning of day 0, you can plant the seeds in any order.
    Return the earliest possible day where all seeds are blooming.

    Example 1:

    >>> earliestFullBloom(plantTime = [1,4,3], growTime = [2,3,1])
    >>> 9
    Explanation: The grayed out pots represent planting days, colored pots represent growing days, and the flower represents the day it blooms.
    One optimal way is:
    On day 0, plant the 0th seed. The seed grows for 2 full days and blooms on day 3.
    On days 1, 2, 3, and 4, plant the 1st seed. The seed grows for 3 full days and blooms on day 8.
    On days 5, 6, and 7, plant the 2nd seed. The seed grows for 1 full day and blooms on day 9.
    Thus, on day 9, all the seeds are blooming.

    Example 2:

    >>> earliestFullBloom(plantTime = [1,2,3,2], growTime = [2,1,2,1])
    >>> 9
    Explanation: The grayed out pots represent planting days, colored pots represent growing days, and the flower represents the day it blooms.
    One optimal way is:
    On day 1, plant the 0th seed. The seed grows for 2 full days and blooms on day 4.
    On days 0 and 3, plant the 1st seed. The seed grows for 1 full day and blooms on day 5.
    On days 2, 4, and 5, plant the 2nd seed. The seed grows for 2 full days and blooms on day 8.
    On days 6 and 7, plant the 3rd seed. The seed grows for 1 full day and blooms on day 9.
    Thus, on day 9, all the seeds are blooming.

    Example 3:

    >>> earliestFullBloom(plantTime = [1], growTime = [1])
    >>> 2
    Explanation: On day 0, plant the 0th seed. The seed grows for 1 full day and blooms on day 2.
    Thus, on day 2, all the seeds are blooming.
    """


Prompt:
def equalizeWater(buckets: List[int], loss: int) -> float:
    """
    You have n buckets each containing some gallons of water in it, represented by a 0-indexed integer array buckets, where the ith bucket contains buckets[i] gallons of water. You are also given an integer loss.
    You want to make the amount of water in each bucket equal. You can pour any amount of water from one bucket to another bucket (not necessarily an integer). However, every time you pour k gallons of water, you spill loss percent of k.
    Return the maximum amount of water in each bucket after making the amount of water equal. Answers within 10-5 of the actual answer will be accepted.

    Example 1:

    >>> equalizeWater(buckets = [1,2,7], loss = 80)
    >>> 2.00000
    Explanation: Pour 5 gallons of water from buckets[2] to buckets[0].
    5 * 80% = 4 gallons are spilled and buckets[0] only receives 5 - 4 = 1 gallon of water.
    All buckets have 2 gallons of water in them so return 2.

    Example 2:

    >>> equalizeWater(buckets = [2,4,6], loss = 50)
    >>> 3.50000
    Explanation: Pour 0.5 gallons of water from buckets[1] to buckets[0].
    0.5 * 50% = 0.25 gallons are spilled and buckets[0] only receives 0.5 - 0.25 = 0.25 gallons of water.
    Now, buckets = [2.25, 3.5, 6].
    Pour 2.5 gallons of water from buckets[2] to buckets[0].
    2.5 * 50% = 1.25 gallons are spilled and buckets[0] only receives 2.5 - 1.25 = 1.25 gallons of water.
    All buckets have 3.5 gallons of water in them so return 3.5.

    Example 3:

    >>> equalizeWater(buckets = [3,3,3,3], loss = 40)
    >>> 3.00000
    Explanation: All buckets already have the same amount of water in them.
    """


Prompt:
def divideString(s: str, k: int, fill: str) -> List[str]:
    """
    A string s can be partitioned into groups of size k using the following procedure:

    The first group consists of the first k characters of the string, the second group consists of the next k characters of the string, and so on. Each element can be a part of exactly one group.
    For the last group, if the string does not have k characters remaining, a character fill is used to complete the group.

    Note that the partition is done so that after removing the fill character from the last group (if it exists) and concatenating all the groups in order, the resultant string should be s.
    Given the string s, the size of each group k and the character fill, return a string array denoting the composition of every group s has been divided into, using the above procedure.

    Example 1:

    >>> divideString(s = "abcdefghi", k = 3, fill = "x")
    >>> ["abc","def","ghi"]
    Explanation:
    The first 3 characters "abc" form the first group.
    The next 3 characters "def" form the second group.
    The last 3 characters "ghi" form the third group.
    Since all groups can be completely filled by characters from the string, we do not need to use fill.
    Thus, the groups formed are "abc", "def", and "ghi".

    Example 2:

    >>> divideString(s = "abcdefghij", k = 3, fill = "x")
    >>> ["abc","def","ghi","jxx"]
    Explanation:
    Similar to the previous example, we are forming the first three groups "abc", "def", and "ghi".
    For the last group, we can only use the character 'j' from the string. To complete this group, we add 'x' twice.
    Thus, the 4 groups formed are "abc", "def", "ghi", and "jxx".
    """


Prompt:
def minMoves(target: int, maxDoubles: int) -> int:
    """
    You are playing a game with integers. You start with the integer 1 and you want to reach the integer target.
    In one move, you can either:

    Increment the current integer by one (i.e., x = x + 1).
    Double the current integer (i.e., x = 2 * x).

    You can use the increment operation any number of times, however, you can only use the double operation at most maxDoubles times.
    Given the two integers target and maxDoubles, return the minimum number of moves needed to reach target starting with 1.

    Example 1:

    >>> minMoves(target = 5, maxDoubles = 0)
    >>> 4
    Explanation: Keep incrementing by 1 until you reach target.

    Example 2:

    >>> minMoves(target = 19, maxDoubles = 2)
    >>> 7
    Explanation: Initially, x = 1
    Increment 3 times so x = 4
    Double once so x = 8
    Increment once so x = 9
    Double again so x = 18
    Increment once so x = 19

    Example 3:

    >>> minMoves(target = 10, maxDoubles = 4)
    >>> 4
    Explanation: Initially, x = 1
    Increment once so x = 2
    Double once so x = 4
    Increment once so x = 5
    Double again so x = 10
    """


Prompt:
def mostPoints(questions: List[List[int]]) -> int:
    """
    You are given a 0-indexed 2D integer array questions where questions[i] = [pointsi, brainpoweri].
    The array describes the questions of an exam, where you have to process the questions in order (i.e., starting from question 0) and make a decision whether to solve or skip each question. Solving question i will earn you pointsi points but you will be unable to solve each of the next brainpoweri questions. If you skip question i, you get to make the decision on the next question.

    For example, given questions = [[3, 2], [4, 3], [4, 4], [2, 5]]:

    If question 0 is solved, you will earn 3 points but you will be unable to solve questions 1 and 2.
    If instead, question 0 is skipped and question 1 is solved, you will earn 4 points but you will be unable to solve questions 2 and 3.

    Return the maximum points you can earn for the exam.

    Example 1:

    >>> mostPoints(questions = [[3,2],[4,3],[4,4],[2,5]])
    >>> 5
    Explanation: The maximum points can be earned by solving questions 0 and 3.
    - Solve question 0: Earn 3 points, will be unable to solve the next 2 questions
    - Unable to solve questions 1 and 2
    - Solve question 3: Earn 2 points
    Total points earned: 3 + 2 = 5. There is no other way to earn 5 or more points.

    Example 2:

    >>> mostPoints(questions = [[1,1],[2,2],[3,3],[4,4],[5,5]])
    >>> 7
    Explanation: The maximum points can be earned by solving questions 1 and 4.
    - Skip question 0
    - Solve question 1: Earn 2 points, will be unable to solve the next 2 questions
    - Unable to solve questions 2 and 3
    - Solve question 4: Earn 5 points
    Total points earned: 2 + 5 = 7. There is no other way to earn 7 or more points.
    """


Prompt:
def maxRunTime(n: int, batteries: List[int]) -> int:
    """
    You have n computers. You are given the integer n and a 0-indexed integer array batteries where the ith battery can run a computer for batteries[i] minutes. You are interested in running all n computers simultaneously using the given batteries.
    Initially, you can insert at most one battery into each computer. After that and at any integer time moment, you can remove a battery from a computer and insert another battery any number of times. The inserted battery can be a totally new battery or a battery from another computer. You may assume that the removing and inserting processes take no time.
    Note that the batteries cannot be recharged.
    Return the maximum number of minutes you can run all the n computers simultaneously.

    Example 1:

    >>> maxRunTime(n = 2, batteries = [3,3,3])
    >>> 4
    Explanation:
    Initially, insert battery 0 into the first computer and battery 1 into the second computer.
    After two minutes, remove battery 1 from the second computer and insert battery 2 instead. Note that battery 1 can still run for one minute.
    At the end of the third minute, battery 0 is drained, and you need to remove it from the first computer and insert battery 1 instead.
    By the end of the fourth minute, battery 1 is also drained, and the first computer is no longer running.
    We can run the two computers simultaneously for at most 4 minutes, so we return 4.

    Example 2:

    >>> maxRunTime(n = 2, batteries = [1,1,1,1])
    >>> 2
    Explanation:
    Initially, insert battery 0 into the first computer and battery 2 into the second computer.
    After one minute, battery 0 and battery 2 are drained so you need to remove them and insert battery 1 into the first computer and battery 3 into the second computer.
    After another minute, battery 1 and battery 3 are also drained so the first and second computers are no longer running.
    We can run the two computers simultaneously for at most 2 minutes, so we return 2.
    """


Prompt:
def countSubranges(nums1: List[int], nums2: List[int]) -> int:
    """
    You are given two 0-indexed integer arrays nums1 and nums2 of length n.
    A range [l, r] (inclusive) where 0 <= l <= r < n is balanced if:

    For every i in the range [l, r], you pick either nums1[i] or nums2[i].
    The sum of the numbers you pick from nums1 equals to the sum of the numbers you pick from nums2 (the sum is considered to be 0 if you pick no numbers from an array).

    Two balanced ranges from [l1, r1] and [l2, r2] are considered to be different if at least one of the following is true:

    l1 != l2
    r1 != r2
    nums1[i] is picked in the first range, and nums2[i] is picked in the second range or vice versa for at least one i.

    Return the number of different ranges that are balanced. Since the answer may be very large, return it modulo 109 + 7.

    Example 1:

    >>> countSubranges(nums1 = [1,2,5], nums2 = [2,6,3])
    >>> 3
    Explanation: The balanced ranges are:
    - [0, 1] where we choose nums2[0], and nums1[1].
      The sum of the numbers chosen from nums1 equals the sum of the numbers chosen from nums2: 2 = 2.
    - [0, 2] where we choose nums1[0], nums2[1], and nums1[2].
      The sum of the numbers chosen from nums1 equals the sum of the numbers chosen from nums2: 1 + 5 = 6.
    - [0, 2] where we choose nums1[0], nums1[1], and nums2[2].
      The sum of the numbers chosen from nums1 equals the sum of the numbers chosen from nums2: 1 + 2 = 3.
    Note that the second and third balanced ranges are different.
    In the second balanced range, we choose nums2[1] and in the third balanced range, we choose nums1[1].

    Example 2:

    >>> countSubranges(nums1 = [0,1], nums2 = [1,0])
    >>> 4
    Explanation: The balanced ranges are:
    - [0, 0] where we choose nums1[0].
      The sum of the numbers chosen from nums1 equals the sum of the numbers chosen from nums2: 0 = 0.
    - [1, 1] where we choose nums2[1].
      The sum of the numbers chosen from nums1 equals the sum of the numbers chosen from nums2: 0 = 0.
    - [0, 1] where we choose nums1[0] and nums2[1].
      The sum of the numbers chosen from nums1 equals the sum of the numbers chosen from nums2: 0 = 0.
    - [0, 1] where we choose nums2[0] and nums1[1].
      The sum of the numbers chosen from nums1 equals the sum of the numbers chosen from nums2: 1 = 1.
    """


Prompt:
def minimumCost(cost: List[int]) -> int:
    """
    A shop is selling candies at a discount. For every two candies sold, the shop gives a third candy for free.
    The customer can choose any candy to take away for free as long as the cost of the chosen candy is less than or equal to the minimum cost of the two candies bought.

    For example, if there are 4 candies with costs 1, 2, 3, and 4, and the customer buys candies with costs 2 and 3, they can take the candy with cost 1 for free, but not the candy with cost 4.

    Given a 0-indexed integer array cost, where cost[i] denotes the cost of the ith candy, return the minimum cost of buying all the candies.

    Example 1:

    >>> minimumCost(cost = [1,2,3])
    >>> 5
    Explanation: We buy the candies with costs 2 and 3, and take the candy with cost 1 for free.
    The total cost of buying all candies is 2 + 3 = 5. This is the only way we can buy the candies.
    Note that we cannot buy candies with costs 1 and 3, and then take the candy with cost 2 for free.
    The cost of the free candy has to be less than or equal to the minimum cost of the purchased candies.

    Example 2:

    >>> minimumCost(cost = [6,5,7,9,2,2])
    >>> 23
    Explanation: The way in which we can get the minimum cost is described below:
    - Buy candies with costs 9 and 7
    - Take the candy with cost 6 for free
    - We buy candies with costs 5 and 2
    - Take the last remaining candy with cost 2 for free
    Hence, the minimum cost to buy all candies is 9 + 7 + 5 + 2 = 23.

    Example 3:

    >>> minimumCost(cost = [5,5])
    >>> 10
    Explanation: Since there are only 2 candies, we buy both of them. There is not a third candy we can take for free.
    Hence, the minimum cost to buy all candies is 5 + 5 = 10.
    """


Prompt:
def numberOfArrays(differences: List[int], lower: int, upper: int) -> int:
    """
    You are given a 0-indexed array of n integers differences, which describes the differences between each pair of consecutive integers of a hidden sequence of length (n + 1). More formally, call the hidden sequence hidden, then we have that differences[i] = hidden[i + 1] - hidden[i].
    You are further given two integers lower and upper that describe the inclusive range of values [lower, upper] that the hidden sequence can contain.

    For example, given differences = [1, -3, 4], lower = 1, upper = 6, the hidden sequence is a sequence of length 4 whose elements are in between 1 and 6 (inclusive).

    [3, 4, 1, 5] and [4, 5, 2, 6] are possible hidden sequences.
    [5, 6, 3, 7] is not possible since it contains an element greater than 6.
    [1, 2, 3, 4] is not possible since the differences are not correct.

    Return the number of possible hidden sequences there are. If there are no possible sequences, return 0.

    Example 1:

    >>> numberOfArrays(differences = [1,-3,4], lower = 1, upper = 6)
    >>> 2
    Explanation: The possible hidden sequences are:
    - [3, 4, 1, 5]
    - [4, 5, 2, 6]
    Thus, we return 2.

    Example 2:

    >>> numberOfArrays(differences = [3,-4,5,1,-2], lower = -4, upper = 5)
    >>> 4
    Explanation: The possible hidden sequences are:
    - [-3, 0, -4, 1, 2, 0]
    - [-2, 1, -3, 2, 3, 1]
    - [-1, 2, -2, 3, 4, 2]
    - [0, 3, -1, 4, 5, 3]
    Thus, we return 4.

    Example 3:

    >>> numberOfArrays(differences = [4,-7,2], lower = 3, upper = 6)
    >>> 0
    Explanation: There are no possible hidden sequences. Thus, we return 0.
    """


Prompt:
def highestRankedKItems(grid: List[List[int]], pricing: List[int], start: List[int], k: int) -> List[List[int]]:
    """
    You are given a 0-indexed 2D integer array grid of size m x n that represents a map of the items in a shop. The integers in the grid represent the following:

    0 represents a wall that you cannot pass through.
    1 represents an empty cell that you can freely move to and from.
    All other positive integers represent the price of an item in that cell. You may also freely move to and from these item cells.

    It takes 1 step to travel between adjacent grid cells.
    You are also given integer arrays pricing and start where pricing = [low, high] and start = [row, col] indicates that you start at the position (row, col) and are interested only in items with a price in the range of [low, high] (inclusive). You are further given an integer k.
    You are interested in the positions of the k highest-ranked items whose prices are within the given price range. The rank is determined by the first of these criteria that is different:

    Distance, defined as the length of the shortest path from the start (shorter distance has a higher rank).
    Price (lower price has a higher rank, but it must be in the price range).
    The row number (smaller row number has a higher rank).
    The column number (smaller column number has a higher rank).

    Return the k highest-ranked items within the price range sorted by their rank (highest to lowest). If there are fewer than k reachable items within the price range, return all of them.

    Example 1:

    >>> highestRankedKItems(grid = [[1,2,0,1],[1,3,0,1],[0,2,5,1]], pricing = [2,5], start = [0,0], k = 3)
    >>> [[0,1],[1,1],[2,1]]
    Explanation: You start at (0,0).
    With a price range of [2,5], we can take items from (0,1), (1,1), (2,1) and (2,2).
    The ranks of these items are:
    - (0,1) with distance 1
    - (1,1) with distance 2
    - (2,1) with distance 3
    - (2,2) with distance 4
    Thus, the 3 highest ranked items in the price range are (0,1), (1,1), and (2,1).

    Example 2:

    >>> highestRankedKItems(grid = [[1,2,0,1],[1,3,3,1],[0,2,5,1]], pricing = [2,3], start = [2,3], k = 2)
    >>> [[2,1],[1,2]]
    Explanation: You start at (2,3).
    With a price range of [2,3], we can take items from (0,1), (1,1), (1,2) and (2,1).
    The ranks of these items are:
    - (2,1) with distance 2, price 2
    - (1,2) with distance 2, price 3
    - (1,1) with distance 3
    - (0,1) with distance 4
    Thus, the 2 highest ranked items in the price range are (2,1) and (1,2).

    Example 3:

    >>> highestRankedKItems(grid = [[1,1,1],[0,0,1],[2,3,4]], pricing = [2,3], start = [0,0], k = 3)
    >>> [[2,1],[2,0]]
    Explanation: You start at (0,0).
    With a price range of [2,3], we can take items from (2,0) and (2,1).
    The ranks of these items are:
    - (2,1) with distance 5
    - (2,0) with distance 6
    Thus, the 2 highest ranked items in the price range are (2,1) and (2,0).
    Note that k = 3 but there are only 2 reachable items within the price range.
    """


Prompt:
def numberOfWays(corridor: str) -> int:
    """
    Along a long library corridor, there is a line of seats and decorative plants. You are given a 0-indexed string corridor of length n consisting of letters 'S' and 'P' where each 'S' represents a seat and each 'P' represents a plant.
    One room divider has already been installed to the left of index 0, and another to the right of index n - 1. Additional room dividers can be installed. For each position between indices i - 1 and i (1 <= i <= n - 1), at most one divider can be installed.
    Divide the corridor into non-overlapping sections, where each section has exactly two seats with any number of plants. There may be multiple ways to perform the division. Two ways are different if there is a position with a room divider installed in the first way but not in the second way.
    Return the number of ways to divide the corridor. Since the answer may be very large, return it modulo 109 + 7. If there is no way, return 0.

    Example 1:

    >>> numberOfWays(corridor = "SSPPSPS")
    >>> 3
    Explanation: There are 3 different ways to divide the corridor.
    The black bars in the above image indicate the two room dividers already installed.
    Note that in each of the ways, each section has exactly two seats.

    Example 2:

    >>> numberOfWays(corridor = "PPSPSP")
    >>> 1
    Explanation: There is only 1 way to divide the corridor, by not installing any additional dividers.
    Installing any would create some section that does not have exactly two seats.

    Example 3:

    >>> numberOfWays(corridor = "S")
    >>> 0
    Explanation: There is no way to divide the corridor because there will always be a section that does not have exactly two seats.
    """


Prompt:
def countElements(nums: List[int]) -> int:
    """
    Given an integer array nums, return the number of elements that have both a strictly smaller and a strictly greater element appear in nums.

    Example 1:

    >>> countElements(nums = [11,7,2,15])
    >>> 2
    Explanation: The element 7 has the element 2 strictly smaller than it and the element 11 strictly greater than it.
    Element 11 has element 7 strictly smaller than it and element 15 strictly greater than it.
    In total there are 2 elements having both a strictly smaller and a strictly greater element appear in nums.

    Example 2:

    >>> countElements(nums = [-3,3,3,90])
    >>> 2
    Explanation: The element 3 has the element -3 strictly smaller than it and the element 90 strictly greater than it.
    Since there are two elements with the value 3, in total there are 2 elements having both a strictly smaller and a strictly greater element appear in nums.
    """


Prompt:
def rearrangeArray(nums: List[int]) -> List[int]:
    """
    You are given a 0-indexed integer array nums of even length consisting of an equal number of positive and negative integers.
    You should return the array of nums such that the the array follows the given conditions:

    Every consecutive pair of integers have opposite signs.
    For all integers with the same sign, the order in which they were present in nums is preserved.
    The rearranged array begins with a positive integer.

    Return the modified array after rearranging the elements to satisfy the aforementioned conditions.

    Example 1:

    >>> rearrangeArray(nums = [3,1,-2,-5,2,-4])
    >>> [3,-2,1,-5,2,-4]
    Explanation:
    The positive integers in nums are [3,1,2]. The negative integers are [-2,-5,-4].
    The only possible way to rearrange them such that they satisfy all conditions is [3,-2,1,-5,2,-4].
    Other ways such as [1,-2,2,-5,3,-4], [3,1,2,-2,-5,-4], [-2,3,-5,1,-4,2] are incorrect because they do not satisfy one or more conditions.

    Example 2:

    >>> rearrangeArray(nums = [-1,1])
    >>> [1,-1]
    Explanation:
    1 is the only positive integer and -1 the only negative integer in nums.
    So nums is rearranged to [1,-1].
    """


Prompt:
def findLonely(nums: List[int]) -> List[int]:
    """
    You are given an integer array nums. A number x is lonely when it appears only once, and no adjacent numbers (i.e. x + 1 and x - 1) appear in the array.
    Return all lonely numbers in nums. You may return the answer in any order.

    Example 1:

    >>> findLonely(nums = [10,6,5,8])
    >>> [10,8]
    Explanation:
    - 10 is a lonely number since it appears exactly once and 9 and 11 does not appear in nums.
    - 8 is a lonely number since it appears exactly once and 7 and 9 does not appear in nums.
    - 5 is not a lonely number since 6 appears in nums and vice versa.
    Hence, the lonely numbers in nums are [10, 8].
    Note that [8, 10] may also be returned.

    Example 2:

    >>> findLonely(nums = [1,3,5,3])
    >>> [1,5]
    Explanation:
    - 1 is a lonely number since it appears exactly once and 0 and 2 does not appear in nums.
    - 5 is a lonely number since it appears exactly once and 4 and 6 does not appear in nums.
    - 3 is not a lonely number since it appears twice.
    Hence, the lonely numbers in nums are [1, 5].
    Note that [5, 1] may also be returned.
    """


Prompt:
def maximumGood(statements: List[List[int]]) -> int:
    """
    There are two types of persons:

    The good person: The person who always tells the truth.
    The bad person: The person who might tell the truth and might lie.

    You are given a 0-indexed 2D integer array statements of size n x n that represents the statements made by n people about each other. More specifically, statements[i][j] could be one of the following:

    0 which represents a statement made by person i that person j is a bad person.
    1 which represents a statement made by person i that person j is a good person.
    2 represents that no statement is made by person i about person j.

    Additionally, no person ever makes a statement about themselves. Formally, we have that statements[i][i] = 2 for all 0 <= i < n.
    Return the maximum number of people who can be good based on the statements made by the n people.

    Example 1:

    >>> maximumGood(statements = [[2,1,2],[1,2,2],[2,0,2]])
    >>> 2
    Explanation: Each person makes a single statement.
    - Person 0 states that person 1 is good.
    - Person 1 states that person 0 is good.
    - Person 2 states that person 1 is bad.
    Let's take person 2 as the key.
    - Assuming that person 2 is a good person:
        - Based on the statement made by person 2, person 1 is a bad person.
        - Now we know for sure that person 1 is bad and person 2 is good.
        - Based on the statement made by person 1, and since person 1 is bad, they could be:
            - telling the truth. There will be a contradiction in this case and this assumption is invalid.
            - lying. In this case, person 0 is also a bad person and lied in their statement.
        - Following that person 2 is a good person, there will be only one good person in the group.
    - Assuming that person 2 is a bad person:
        - Based on the statement made by person 2, and since person 2 is bad, they could be:
            - telling the truth. Following this scenario, person 0 and 1 are both bad as explained before.
                - Following that person 2 is bad but told the truth, there will be no good persons in the group.
            - lying. In this case person 1 is a good person.
                - Since person 1 is a good person, person 0 is also a good person.
                - Following that person 2 is bad and lied, there will be two good persons in the group.
    We can see that at most 2 persons are good in the best case, so we return 2.
    Note that there is more than one way to arrive at this conclusion.

    Example 2:

    >>> maximumGood(statements = [[2,0],[0,2]])
    >>> 1
    Explanation: Each person makes a single statement.
    - Person 0 states that person 1 is bad.
    - Person 1 states that person 0 is bad.
    Let's take person 0 as the key.
    - Assuming that person 0 is a good person:
        - Based on the statement made by person 0, person 1 is a bad person and was lying.
        - Following that person 0 is a good person, there will be only one good person in the group.
    - Assuming that person 0 is a bad person:
        - Based on the statement made by person 0, and since person 0 is bad, they could be:
            - telling the truth. Following this scenario, person 0 and 1 are both bad.
                - Following that person 0 is bad but told the truth, there will be no good persons in the group.
            - lying. In this case person 1 is a good person.
                - Following that person 0 is bad and lied, there will be only one good person in the group.
    We can see that at most, one person is good in the best case, so we return 1.
    Note that there is more than one way to arrive at this conclusion.
    """


Prompt:
def minimumLines(points: List[List[int]]) -> int:
    """
    You are given an array points where points[i] = [xi, yi] represents a point on an X-Y plane.
    Straight lines are going to be added to the X-Y plane, such that every point is covered by at least one line.
    Return the minimum number of straight lines needed to cover all the points.

    Example 1:

    >>> minimumLines(points = [[0,1],[2,3],[4,5],[4,3]])
    >>> 2
    Explanation: The minimum number of straight lines needed is two. One possible solution is to add:
    - One line connecting the point at (0, 1) to the point at (4, 5).
    - Another line connecting the point at (2, 3) to the point at (4, 3).

    Example 2:

    >>> minimumLines(points = [[0,2],[-2,-2],[1,4]])
    >>> 1
    Explanation: The minimum number of straight lines needed is one. The only solution is to add:
    - One line connecting the point at (-2, -2) to the point at (1, 4).
    """


Prompt:
def findFinalValue(nums: List[int], original: int) -> int:
    """
    You are given an array of integers nums. You are also given an integer original which is the first number that needs to be searched for in nums.
    You then do the following steps:

    If original is found in nums, multiply it by two (i.e., set original = 2 * original).
    Otherwise, stop the process.
    Repeat this process with the new number as long as you keep finding the number.

    Return the final value of original.

    Example 1:

    >>> findFinalValue(nums = [5,3,6,1,12], original = 3)
    >>> 24
    Explanation:
    - 3 is found in nums. 3 is multiplied by 2 to obtain 6.
    - 6 is found in nums. 6 is multiplied by 2 to obtain 12.
    - 12 is found in nums. 12 is multiplied by 2 to obtain 24.
    - 24 is not found in nums. Thus, 24 is returned.

    Example 2:

    >>> findFinalValue(nums = [2,7,9], original = 4)
    >>> 4
    Explanation:
    - 4 is not found in nums. Thus, 4 is returned.
    """


Prompt:
def maxScoreIndices(nums: List[int]) -> List[int]:
    """
    You are given a 0-indexed binary array nums of length n. nums can be divided at index i (where 0 <= i <= n) into two arrays (possibly empty) numsleft and numsright:

    numsleft has all the elements of nums between index 0 and i - 1 (inclusive), while numsright has all the elements of nums between index i and n - 1 (inclusive).
    If i == 0, numsleft is empty, while numsright has all the elements of nums.
    If i == n, numsleft has all the elements of nums, while numsright is empty.

    The division score of an index i is the sum of the number of 0's in numsleft and the number of 1's in numsright.
    Return all distinct indices that have the highest possible division score. You may return the answer in any order.

    Example 1:

    >>> maxScoreIndices(nums = [0,0,1,0])
    >>> [2,4]
    Explanation: Division at index
    - 0: numsleft is []. numsright is [0,0,1,0]. The score is 0 + 1 = 1.
    - 1: numsleft is [0]. numsright is [0,1,0]. The score is 1 + 1 = 2.
    - 2: numsleft is [0,0]. numsright is [1,0]. The score is 2 + 1 = 3.
    - 3: numsleft is [0,0,1]. numsright is [0]. The score is 2 + 0 = 2.
    - 4: numsleft is [0,0,1,0]. numsright is []. The score is 3 + 0 = 3.
    Indices 2 and 4 both have the highest possible division score 3.
    Note the answer [4,2] would also be accepted.
    Example 2:

    >>> maxScoreIndices(nums = [0,0,0])
    >>> [3]
    Explanation: Division at index
    - 0: numsleft is []. numsright is [0,0,0]. The score is 0 + 0 = 0.
    - 1: numsleft is [0]. numsright is [0,0]. The score is 1 + 0 = 1.
    - 2: numsleft is [0,0]. numsright is [0]. The score is 2 + 0 = 2.
    - 3: numsleft is [0,0,0]. numsright is []. The score is 3 + 0 = 3.
    Only index 3 has the highest possible division score 3.

    Example 3:

    >>> maxScoreIndices(nums = [1,1])
    >>> [0]
    Explanation: Division at index
    - 0: numsleft is []. numsright is [1,1]. The score is 0 + 2 = 2.
    - 1: numsleft is [1]. numsright is [1]. The score is 0 + 1 = 1.
    - 2: numsleft is [1,1]. numsright is []. The score is 0 + 0 = 0.
    Only index 0 has the highest possible division score 2.
    """


Prompt:
def subStrHash(s: str, power: int, modulo: int, k: int, hashValue: int) -> str:
    """
    The hash of a 0-indexed string s of length k, given integers p and m, is computed using the following function:

    hash(s, p, m) = (val(s[0]) * p0 + val(s[1]) * p1 + ... + val(s[k-1]) * pk-1) mod m.

    Where val(s[i]) represents the index of s[i] in the alphabet from val('a') = 1 to val('z') = 26.
    You are given a string s and the integers power, modulo, k, and hashValue. Return sub, the first substring of s of length k such that hash(sub, power, modulo) == hashValue.
    The test cases will be generated such that an answer always exists.
    A substring is a contiguous non-empty sequence of characters within a string.

    Example 1:

    >>> subStrHash(s = "leetcode", power = 7, modulo = 20, k = 2, hashValue = 0)
    >>> "ee"
    Explanation: The hash of "ee" can be computed to be hash("ee", 7, 20) = (5 * 1 + 5 * 7) mod 20 = 40 mod 20 = 0.
    "ee" is the first substring of length 2 with hashValue 0. Hence, we return "ee".

    Example 2:

    >>> subStrHash(s = "fbxzaad", power = 31, modulo = 100, k = 3, hashValue = 32)
    >>> "fbx"
    Explanation: The hash of "fbx" can be computed to be hash("fbx", 31, 100) = (6 * 1 + 2 * 31 + 24 * 312) mod 100 = 23132 mod 100 = 32.
    The hash of "bxz" can be computed to be hash("bxz", 31, 100) = (2 * 1 + 24 * 31 + 26 * 312) mod 100 = 25732 mod 100 = 32.
    "fbx" is the first substring of length 3 with hashValue 32. Hence, we return "fbx".
    Note that "bxz" also has a hash of 32 but it appears later than "fbx".
    """


Prompt:
def groupStrings(words: List[str]) -> List[int]:
    """
    You are given a 0-indexed array of strings words. Each string consists of lowercase English letters only. No letter occurs more than once in any string of words.
    Two strings s1 and s2 are said to be connected if the set of letters of s2 can be obtained from the set of letters of s1 by any one of the following operations:

    Adding exactly one letter to the set of the letters of s1.
    Deleting exactly one letter from the set of the letters of s1.
    Replacing exactly one letter from the set of the letters of s1 with any letter, including itself.

    The array words can be divided into one or more non-intersecting groups. A string belongs to a group if any one of the following is true:

    It is connected to at least one other string of the group.
    It is the only string present in the group.

    Note that the strings in words should be grouped in such a manner that a string belonging to a group cannot be connected to a string present in any other group. It can be proved that such an arrangement is always unique.
    Return an array ans of size 2 where:

    ans[0] is the maximum number of groups words can be divided into, and
    ans[1] is the size of the largest group.

    Example 1:

    >>> groupStrings(words = ["a","b","ab","cde"])
    >>> [2,3]
    Explanation:
    - words[0] can be used to obtain words[1] (by replacing 'a' with 'b'), and words[2] (by adding 'b'). So words[0] is connected to words[1] and words[2].
    - words[1] can be used to obtain words[0] (by replacing 'b' with 'a'), and words[2] (by adding 'a'). So words[1] is connected to words[0] and words[2].
    - words[2] can be used to obtain words[0] (by deleting 'b'), and words[1] (by deleting 'a'). So words[2] is connected to words[0] and words[1].
    - words[3] is not connected to any string in words.
    Thus, words can be divided into 2 groups ["a","b","ab"] and ["cde"]. The size of the largest group is 3.

    Example 2:

    >>> groupStrings(words = ["a","ab","abc"])
    >>> [1,3]
    Explanation:
    - words[0] is connected to words[1].
    - words[1] is connected to words[0] and words[2].
    - words[2] is connected to words[1].
    Since all strings are connected to each other, they should be grouped together.
    Thus, the size of the largest group is 3.
    """


Prompt:
def amountPainted(paint: List[List[int]]) -> List[int]:
    """
    There is a long and thin painting that can be represented by a number line. You are given a 0-indexed 2D integer array paint of length n, where paint[i] = [starti, endi]. This means that on the ith day you need to paint the area between starti and endi.
    Painting the same area multiple times will create an uneven painting so you only want to paint each area of the painting at most once.
    Return an integer array worklog of length n, where worklog[i] is the amount of new area that you painted on the ith day.

    Example 1:

    >>> amountPainted(paint = [[1,4],[4,7],[5,8]])
    >>> [3,3,1]
    Explanation:
    On day 0, paint everything between 1 and 4.
    The amount of new area painted on day 0 is 4 - 1 = 3.
    On day 1, paint everything between 4 and 7.
    The amount of new area painted on day 1 is 7 - 4 = 3.
    On day 2, paint everything between 7 and 8.
    Everything between 5 and 7 was already painted on day 1.
    The amount of new area painted on day 2 is 8 - 7 = 1.

    Example 2:

    >>> amountPainted(paint = [[1,4],[5,8],[4,7]])
    >>> [3,3,1]
    Explanation:
    On day 0, paint everything between 1 and 4.
    The amount of new area painted on day 0 is 4 - 1 = 3.
    On day 1, paint everything between 5 and 8.
    The amount of new area painted on day 1 is 8 - 5 = 3.
    On day 2, paint everything between 4 and 5.
    Everything between 5 and 7 was already painted on day 1.
    The amount of new area painted on day 2 is 5 - 4 = 1.

    Example 3:

    >>> amountPainted(paint = [[1,5],[2,4]])
    >>> [4,0]
    Explanation:
    On day 0, paint everything between 1 and 5.
    The amount of new area painted on day 0 is 5 - 1 = 4.
    On day 1, paint nothing because everything between 2 and 4 was already painted on day 0.
    The amount of new area painted on day 1 is 0.
    """


Prompt:
def minimumSum(num: int) -> int:
    """
    You are given a positive integer num consisting of exactly four digits. Split num into two new integers new1 and new2 by using the digits found in num. Leading zeros are allowed in new1 and new2, and all the digits found in num must be used.

    For example, given num = 2932, you have the following digits: two 2's, one 9 and one 3. Some of the possible pairs [new1, new2] are [22, 93], [23, 92], [223, 9] and [2, 329].

    Return the minimum possible sum of new1 and new2.

    Example 1:

    >>> minimumSum(num = 2932)
    >>> 52
    Explanation: Some possible pairs [new1, new2] are [29, 23], [223, 9], etc.
    The minimum sum can be obtained by the pair [29, 23]: 29 + 23 = 52.

    Example 2:

    >>> minimumSum(num = 4009)
    >>> 13
    Explanation: Some possible pairs [new1, new2] are [0, 49], [490, 0], etc.
    The minimum sum can be obtained by the pair [4, 9]: 4 + 9 = 13.
    """


Prompt:
def pivotArray(nums: List[int], pivot: int) -> List[int]:
    """
    You are given a 0-indexed integer array nums and an integer pivot. Rearrange nums such that the following conditions are satisfied:

    Every element less than pivot appears before every element greater than pivot.
    Every element equal to pivot appears in between the elements less than and greater than pivot.
    The relative order of the elements less than pivot and the elements greater than pivot is maintained.

    More formally, consider every pi, pj where pi is the new position of the ith element and pj is the new position of the jth element. If i < j and both elements are smaller (or larger) than pivot, then pi < pj.

    Return nums after the rearrangement.

    Example 1:

    >>> pivotArray(nums = [9,12,5,10,14,3,10], pivot = 10)
    >>> [9,5,3,10,10,12,14]
    Explanation:
    The elements 9, 5, and 3 are less than the pivot so they are on the left side of the array.
    The elements 12 and 14 are greater than the pivot so they are on the right side of the array.
    The relative ordering of the elements less than and greater than pivot is also maintained. [9, 5, 3] and [12, 14] are the respective orderings.

    Example 2:

    >>> pivotArray(nums = [-3,4,3,2], pivot = 2)
    >>> [-3,2,4,3]
    Explanation:
    The element -3 is less than the pivot so it is on the left side of the array.
    The elements 4 and 3 are greater than the pivot so they are on the right side of the array.
    The relative ordering of the elements less than and greater than pivot is also maintained. [-3] and [4, 3] are the respective orderings.
    """


Prompt:
def minCostSetTime(startAt: int, moveCost: int, pushCost: int, targetSeconds: int) -> int:
    """
    A generic microwave supports cooking times for:

    at least 1 second.
    at most 99 minutes and 99 seconds.

    To set the cooking time, you push at most four digits. The microwave normalizes what you push as four digits by prepending zeroes. It interprets the first two digits as the minutes and the last two digits as the seconds. It then adds them up as the cooking time. For example,

    You push 9 5 4 (three digits). It is normalized as 0954 and interpreted as 9 minutes and 54 seconds.
    You push 0 0 0 8 (four digits). It is interpreted as 0 minutes and 8 seconds.
    You push 8 0 9 0. It is interpreted as 80 minutes and 90 seconds.
    You push 8 1 3 0. It is interpreted as 81 minutes and 30 seconds.

    You are given integers startAt, moveCost, pushCost, and targetSeconds. Initially, your finger is on the digit startAt. Moving the finger above any specific digit costs moveCost units of fatigue. Pushing the digit below the finger once costs pushCost units of fatigue.
    There can be multiple ways to set the microwave to cook for targetSeconds seconds but you are interested in the way with the minimum cost.
    Return the minimum cost to set targetSeconds seconds of cooking time.
    Remember that one minute consists of 60 seconds.

    Example 1:

    >>> minCostSetTime(startAt = 1, moveCost = 2, pushCost = 1, targetSeconds = 600)
    >>> 6
    Explanation: The following are the possible ways to set the cooking time.
    - 1 0 0 0, interpreted as 10 minutes and 0 seconds.
      The finger is already on digit 1, pushes 1 (with cost 1), moves to 0 (with cost 2), pushes 0 (with cost 1), pushes 0 (with cost 1), and pushes 0 (with cost 1).
      The cost is: 1 + 2 + 1 + 1 + 1 = 6. This is the minimum cost.
    - 0 9 6 0, interpreted as 9 minutes and 60 seconds. That is also 600 seconds.
      The finger moves to 0 (with cost 2), pushes 0 (with cost 1), moves to 9 (with cost 2), pushes 9 (with cost 1), moves to 6 (with cost 2), pushes 6 (with cost 1), moves to 0 (with cost 2), and pushes 0 (with cost 1).
      The cost is: 2 + 1 + 2 + 1 + 2 + 1 + 2 + 1 = 12.
    - 9 6 0, normalized as 0960 and interpreted as 9 minutes and 60 seconds.
      The finger moves to 9 (with cost 2), pushes 9 (with cost 1), moves to 6 (with cost 2), pushes 6 (with cost 1), moves to 0 (with cost 2), and pushes 0 (with cost 1).
      The cost is: 2 + 1 + 2 + 1 + 2 + 1 = 9.

    Example 2:

    >>> minCostSetTime(startAt = 0, moveCost = 1, pushCost = 2, targetSeconds = 76)
    >>> 6
    Explanation: The optimal way is to push two digits: 7 6, interpreted as 76 seconds.
    The finger moves to 7 (with cost 1), pushes 7 (with cost 2), moves to 6 (with cost 1), and pushes 6 (with cost 2). The total cost is: 1 + 2 + 1 + 2 = 6
    Note other possible ways are 0076, 076, 0116, and 116, but none of them produces the minimum cost.
    """


Prompt:
def minimumDifference(nums: List[int]) -> int:
    """
    You are given a 0-indexed integer array nums consisting of 3 * n elements.
    You are allowed to remove any subsequence of elements of size exactly n from nums. The remaining 2 * n elements will be divided into two equal parts:

    The first n elements belonging to the first part and their sum is sumfirst.
    The next n elements belonging to the second part and their sum is sumsecond.

    The difference in sums of the two parts is denoted as sumfirst - sumsecond.

    For example, if sumfirst = 3 and sumsecond = 2, their difference is 1.
    Similarly, if sumfirst = 2 and sumsecond = 3, their difference is -1.

    Return the minimum difference possible between the sums of the two parts after the removal of n elements.

    Example 1:

    >>> minimumDifference(nums = [3,1,2])
    >>> -1
    Explanation: Here, nums has 3 elements, so n = 1.
    Thus we have to remove 1 element from nums and divide the array into two equal parts.
    - If we remove nums[0] = 3, the array will be [1,2]. The difference in sums of the two parts will be 1 - 2 = -1.
    - If we remove nums[1] = 1, the array will be [3,2]. The difference in sums of the two parts will be 3 - 2 = 1.
    - If we remove nums[2] = 2, the array will be [3,1]. The difference in sums of the two parts will be 3 - 1 = 2.
    The minimum difference between sums of the two parts is min(-1,1,2) = -1.

    Example 2:

    >>> minimumDifference(nums = [7,9,5,8,1,3])
    >>> 1
    Explanation: Here n = 2. So we must remove 2 elements and divide the remaining array into two parts containing two elements each.
    If we remove nums[2] = 5 and nums[3] = 8, the resultant array will be [7,9,1,3]. The difference in sums will be (7+9) - (1+3) = 12.
    To obtain the minimum difference, we should remove nums[1] = 9 and nums[4] = 1. The resultant array becomes [7,5,8,3]. The difference in sums of the two parts is (7+5) - (8+3) = 1.
    It can be shown that it is not possible to obtain a difference smaller than 1.
    """


Prompt:
def sortEvenOdd(nums: List[int]) -> List[int]:
    """
    You are given a 0-indexed integer array nums. Rearrange the values of nums according to the following rules:

    Sort the values at odd indices of nums in non-increasing order.

    For example, if nums = [4,1,2,3] before this step, it becomes [4,3,2,1] after. The values at odd indices 1 and 3 are sorted in non-increasing order.

    Sort the values at even indices of nums in non-decreasing order.

    For example, if nums = [4,1,2,3] before this step, it becomes [2,1,4,3] after. The values at even indices 0 and 2 are sorted in non-decreasing order.

    Return the array formed after rearranging the values of nums.

    Example 1:

    >>> sortEvenOdd(nums = [4,1,2,3])
    >>> [2,3,4,1]
    Explanation:
    First, we sort the values present at odd indices (1 and 3) in non-increasing order.
    So, nums changes from [4,1,2,3] to [4,3,2,1].
    Next, we sort the values present at even indices (0 and 2) in non-decreasing order.
    So, nums changes from [4,1,2,3] to [2,3,4,1].
    Thus, the array formed after rearranging the values is [2,3,4,1].

    Example 2:

    >>> sortEvenOdd(nums = [2,1])
    >>> [2,1]
    Explanation:
    Since there is exactly one odd index and one even index, no rearrangement of values takes place.
    The resultant array formed is [2,1], which is the same as the initial array.
    """


Prompt:
def smallestNumber(num: int) -> int:
    """
    You are given an integer num. Rearrange the digits of num such that its value is minimized and it does not contain any leading zeros.
    Return the rearranged number with minimal value.
    Note that the sign of the number does not change after rearranging the digits.

    Example 1:

    >>> smallestNumber(num = 310)
    >>> 103
    Explanation: The possible arrangements for the digits of 310 are 013, 031, 103, 130, 301, 310.
    The arrangement with the smallest value that does not contain any leading zeros is 103.

    Example 2:

    >>> smallestNumber(num = -7605)
    >>> -7650
    Explanation: Some possible arrangements for the digits of -7605 are -7650, -6705, -5076, -0567.
    The arrangement with the smallest value that does not contain any leading zeros is -7650.
    """


Prompt:
def minimumTime(s: str) -> int:
    """
    You are given a 0-indexed binary string s which represents a sequence of train cars. s[i] = '0' denotes that the ith car does not contain illegal goods and s[i] = '1' denotes that the ith car does contain illegal goods.
    As the train conductor, you would like to get rid of all the cars containing illegal goods. You can do any of the following three operations any number of times:

    Remove a train car from the left end (i.e., remove s[0]) which takes 1 unit of time.
    Remove a train car from the right end (i.e., remove s[s.length - 1]) which takes 1 unit of time.
    Remove a train car from anywhere in the sequence which takes 2 units of time.

    Return the minimum time to remove all the cars containing illegal goods.
    Note that an empty sequence of cars is considered to have no cars containing illegal goods.

    Example 1:

    >>> minimumTime(s = "1100101")
    >>> 5
    Explanation:
    One way to remove all the cars containing illegal goods from the sequence is to
    - remove a car from the left end 2 times. Time taken is 2 * 1 = 2.
    - remove a car from the right end. Time taken is 1.
    - remove the car containing illegal goods found in the middle. Time taken is 2.
    This obtains a total time of 2 + 1 + 2 = 5.

    An alternative way is to
    - remove a car from the left end 2 times. Time taken is 2 * 1 = 2.
    - remove a car from the right end 3 times. Time taken is 3 * 1 = 3.
    This also obtains a total time of 2 + 3 = 5.

    5 is the minimum time taken to remove all the cars containing illegal goods.
    There are no other ways to remove them with less time.

    Example 2:

    >>> minimumTime(s = "0010")
    >>> 2
    Explanation:
    One way to remove all the cars containing illegal goods from the sequence is to
    - remove a car from the left end 3 times. Time taken is 3 * 1 = 3.
    This obtains a total time of 3.

    Another way to remove all the cars containing illegal goods from the sequence is to
    - remove the car containing illegal goods found in the middle. Time taken is 2.
    This obtains a total time of 2.

    Another way to remove all the cars containing illegal goods from the sequence is to
    - remove a car from the right end 2 times. Time taken is 2 * 1 = 2.
    This obtains a total time of 2.

    2 is the minimum time taken to remove all the cars containing illegal goods.
    There are no other ways to remove them with less time.
    """


Prompt:
def equalDigitFrequency(s: str) -> int:
    """
    Given a digit string s, return the number of unique substrings of s where every digit appears the same number of times.

    Example 1:

    >>> equalDigitFrequency(s = "1212")
    >>> 5
    Explanation: The substrings that meet the requirements are "1", "2", "12", "21", "1212".
    Note that although the substring "12" appears twice, it is only counted once.

    Example 2:

    >>> equalDigitFrequency(s = "12321")
    >>> 9
    Explanation: The substrings that meet the requirements are "1", "2", "3", "12", "23", "32", "21", "123", "321".
    """


Prompt:
def countOperations(num1: int, num2: int) -> int:
    """
    You are given two non-negative integers num1 and num2.
    In one operation, if num1 >= num2, you must subtract num2 from num1, otherwise subtract num1 from num2.

    For example, if num1 = 5 and num2 = 4, subtract num2 from num1, thus obtaining num1 = 1 and num2 = 4. However, if num1 = 4 and num2 = 5, after one operation, num1 = 4 and num2 = 1.

    Return the number of operations required to make either num1 = 0 or num2 = 0.

    Example 1:

    >>> countOperations(num1 = 2, num2 = 3)
    >>> 3
    Explanation:
    - Operation 1: num1 = 2, num2 = 3. Since num1 < num2, we subtract num1 from num2 and get num1 = 2, num2 = 3 - 2 = 1.
    - Operation 2: num1 = 2, num2 = 1. Since num1 > num2, we subtract num2 from num1.
    - Operation 3: num1 = 1, num2 = 1. Since num1 == num2, we subtract num2 from num1.
    Now num1 = 0 and num2 = 1. Since num1 == 0, we do not need to perform any further operations.
    So the total number of operations required is 3.

    Example 2:

    >>> countOperations(num1 = 10, num2 = 10)
    >>> 1
    Explanation:
    - Operation 1: num1 = 10, num2 = 10. Since num1 == num2, we subtract num2 from num1 and get num1 = 10 - 10 = 0.
    Now num1 = 0 and num2 = 10. Since num1 == 0, we are done.
    So the total number of operations required is 1.
    """


Prompt:
def minimumOperations(nums: List[int]) -> int:
    """
    You are given a 0-indexed array nums consisting of n positive integers.
    The array nums is called alternating if:

    nums[i - 2] == nums[i], where 2 <= i <= n - 1.
    nums[i - 1] != nums[i], where 1 <= i <= n - 1.

    In one operation, you can choose an index i and change nums[i] into any positive integer.
    Return the minimum number of operations required to make the array alternating.

    Example 1:

    >>> minimumOperations(nums = [3,1,3,2,4,3])
    >>> 3
    Explanation:
    One way to make the array alternating is by converting it to [3,1,3,1,3,1].
    The number of operations required in this case is 3.
    It can be proven that it is not possible to make the array alternating in less than 3 operations.

    Example 2:

    >>> minimumOperations(nums = [1,2,2,2,2])
    >>> 2
    Explanation:
    One way to make the array alternating is by converting it to [1,2,1,2,1].
    The number of operations required in this case is 2.
    Note that the array cannot be converted to [2,2,2,2,2] because in this case nums[0] == nums[1] which violates the conditions of an alternating array.
    """


Prompt:
def minimumRemoval(beans: List[int]) -> int:
    """
    You are given an array of positive integers beans, where each integer represents the number of magic beans found in a particular magic bag.
    Remove any number of beans (possibly none) from each bag such that the number of beans in each remaining non-empty bag (still containing at least one bean) is equal. Once a bean has been removed from a bag, you are not allowed to return it to any of the bags.
    Return the minimum number of magic beans that you have to remove.

    Example 1:

    >>> minimumRemoval(beans = [4,1,6,5])
    >>> 4
    Explanation:
    - We remove 1 bean from the bag with only 1 bean.
      This results in the remaining bags: [4,0,6,5]
    - Then we remove 2 beans from the bag with 6 beans.
      This results in the remaining bags: [4,0,4,5]
    - Then we remove 1 bean from the bag with 5 beans.
      This results in the remaining bags: [4,0,4,4]
    We removed a total of 1 + 2 + 1 = 4 beans to make the remaining non-empty bags have an equal number of beans.
    There are no other solutions that remove 4 beans or fewer.

    Example 2:

    >>> minimumRemoval(beans = [2,10,3,2])
    >>> 7
    Explanation:
    - We remove 2 beans from one of the bags with 2 beans.
      This results in the remaining bags: [0,10,3,2]
    - Then we remove 2 beans from the other bag with 2 beans.
      This results in the remaining bags: [0,10,3,0]
    - Then we remove 3 beans from the bag with 3 beans.
      This results in the remaining bags: [0,10,0,0]
    We removed a total of 2 + 2 + 3 = 7 beans to make the remaining non-empty bags have an equal number of beans.
    There are no other solutions that removes 7 beans or fewer.
    """


Prompt:
def maximumANDSum(nums: List[int], numSlots: int) -> int:
    """
    You are given an integer array nums of length n and an integer numSlots such that 2 * numSlots >= n. There are numSlots slots numbered from 1 to numSlots.
    You have to place all n integers into the slots such that each slot contains at most two numbers. The AND sum of a given placement is the sum of the bitwise AND of every number with its respective slot number.

    For example, the AND sum of placing the numbers [1, 3] into slot 1 and [4, 6] into slot 2 is equal to (1 AND 1) + (3 AND 1) + (4 AND 2) + (6 AND 2) = 1 + 1 + 0 + 2 = 4.

    Return the maximum possible AND sum of nums given numSlots slots.

    Example 1:

    >>> maximumANDSum(nums = [1,2,3,4,5,6], numSlots = 3)
    >>> 9
    Explanation: One possible placement is [1, 4] into slot 1, [2, 6] into slot 2, and [3, 5] into slot 3.
    This gives the maximum AND sum of (1 AND 1) + (4 AND 1) + (2 AND 2) + (6 AND 2) + (3 AND 3) + (5 AND 3) = 1 + 0 + 2 + 2 + 3 + 1 = 9.

    Example 2:

    >>> maximumANDSum(nums = [1,3,10,4,7,1], numSlots = 9)
    >>> 24
    Explanation: One possible placement is [1, 1] into slot 1, [3] into slot 3, [4] into slot 4, [7] into slot 7, and [10] into slot 9.
    This gives the maximum AND sum of (1 AND 1) + (1 AND 1) + (3 AND 3) + (4 AND 4) + (7 AND 7) + (10 AND 9) = 1 + 1 + 3 + 4 + 7 + 8 = 24.
    Note that slots 2, 5, 6, and 8 are empty which is permitted.
    """


Prompt:
def removeOnes(grid: List[List[int]]) -> int:
    """
    You are given a 0-indexed m x n binary matrix grid.
    In one operation, you can choose any i and j that meet the following conditions:

    0 <= i < m
    0 <= j < n
    grid[i][j] == 1

    and change the values of all cells in row i and column j to zero.
    Return the minimum number of operations needed to remove all 1's from grid.

    Example 1:

    >>> removeOnes(grid = [[1,1,1],[1,1,1],[0,1,0]])
    >>> 2
    Explanation:
    In the first operation, change all cell values of row 1 and column 1 to zero.
    In the second operation, change all cell values of row 0 and column 0 to zero.

    Example 2:

    >>> removeOnes(grid = [[0,1,0],[1,0,1],[0,1,0]])
    >>> 2
    Explanation:
    In the first operation, change all cell values of row 1 and column 0 to zero.
    In the second operation, change all cell values of row 2 and column 1 to zero.
    Note that we cannot perform an operation using row 1 and column 1 because grid[1][1] != 1.

    Example 3:

    >>> removeOnes(grid = [[0,0],[0,0]])
    >>> 0
    Explanation:
    There are no 1's to remove so return 0.
    """


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

    Example 1:

    >>> countPairs(nums = [3,1,2,2,2,1,3], k = 2)
    >>> 4
    Explanation:
    There are 4 pairs that meet all the requirements:
    - nums[0] == nums[6], and 0 * 6 == 0, which is divisible by 2.
    - nums[2] == nums[3], and 2 * 3 == 6, which is divisible by 2.
    - nums[2] == nums[4], and 2 * 4 == 8, which is divisible by 2.
    - nums[3] == nums[4], and 3 * 4 == 12, which is divisible by 2.

    Example 2:

    >>> countPairs(nums = [1,2,3,4], k = 1)
    >>> 0
    Explanation: Since no value in nums is repeated, there are no pairs (i,j) that meet all the requirements.
    """


Prompt:
def sumOfThree(num: int) -> List[int]:
    """
    Given an integer num, return three consecutive integers (as a sorted array) that sum to num. If num cannot be expressed as the sum of three consecutive integers, return an empty array.

    Example 1:

    >>> sumOfThree(num = 33)
    >>> [10,11,12]
    Explanation: 33 can be expressed as 10 + 11 + 12 = 33.
    10, 11, 12 are 3 consecutive integers, so we return [10, 11, 12].

    Example 2:

    >>> sumOfThree(num = 4)
    >>> []
    Explanation: There is no way to express 4 as the sum of 3 consecutive integers.
    """


Prompt:
def maximumEvenSplit(finalSum: int) -> List[int]:
    """
    You are given an integer finalSum. Split it into a sum of a maximum number of unique positive even integers.

    For example, given finalSum = 12, the following splits are valid (unique positive even integers summing up to finalSum): (12), (2 + 10), (2 + 4 + 6), and (4 + 8). Among them, (2 + 4 + 6) contains the maximum number of integers. Note that finalSum cannot be split into (2 + 2 + 4 + 4) as all the numbers should be unique.

    Return a list of integers that represent a valid split containing a maximum number of integers. If no valid split exists for finalSum, return an empty list. You may return the integers in any order.

    Example 1:

    >>> maximumEvenSplit(finalSum = 12)
    >>> [2,4,6]
    Explanation: The following are valid splits: (12), (2 + 10), (2 + 4 + 6), and (4 + 8).
    (2 + 4 + 6) has the maximum number of integers, which is 3. Thus, we return [2,4,6].
    Note that [2,6,4], [6,2,4], etc. are also accepted.

    Example 2:

    >>> maximumEvenSplit(finalSum = 7)
    >>> []
    Explanation: There are no valid splits for the given finalSum.
    Thus, we return an empty array.

    Example 3:

    >>> maximumEvenSplit(finalSum = 28)
    >>> [6,8,2,12]
    Explanation: The following are valid splits: (2 + 26), (6 + 8 + 2 + 12), and (4 + 24).
    (6 + 8 + 2 + 12) has the maximum number of integers, which is 4. Thus, we return [6,8,2,12].
    Note that [10,2,4,12], [6,2,4,16], etc. are also accepted.
    """


Prompt:
def goodTriplets(nums1: List[int], nums2: List[int]) -> int:
    """
    You are given two 0-indexed arrays nums1 and nums2 of length n, both of which are permutations of [0, 1, ..., n - 1].
    A good triplet is a set of 3 distinct values which are present in increasing order by position both in nums1 and nums2. In other words, if we consider pos1v as the index of the value v in nums1 and pos2v as the index of the value v in nums2, then a good triplet will be a set (x, y, z) where 0 <= x, y, z <= n - 1, such that pos1x < pos1y < pos1z and pos2x < pos2y < pos2z.
    Return the total number of good triplets.

    Example 1:

    >>> goodTriplets(nums1 = [2,0,1,3], nums2 = [0,1,2,3])
    >>> 1
    Explanation:
    There are 4 triplets (x,y,z) such that pos1x < pos1y < pos1z. They are (2,0,1), (2,0,3), (2,1,3), and (0,1,3).
    Out of those triplets, only the triplet (0,1,3) satisfies pos2x < pos2y < pos2z. Hence, there is only 1 good triplet.

    Example 2:

    >>> goodTriplets(nums1 = [4,0,1,3,2], nums2 = [4,1,0,2,3])
    >>> 4
    Explanation: The 4 good triplets are (4,0,3), (4,0,2), (4,1,3), and (4,1,2).
    """


Prompt:
def countEven(num: int) -> int:
    """
    Given a positive integer num, return the number of positive integers less than or equal to num whose digit sums are even.
    The digit sum of a positive integer is the sum of all its digits.

    Example 1:

    >>> countEven(num = 4)
    >>> 2
    Explanation:
    The only integers less than or equal to 4 whose digit sums are even are 2 and 4.

    Example 2:

    >>> countEven(num = 30)
    >>> 14
    Explanation:
    The 14 integers less than or equal to 30 whose digit sums are even are
    2, 4, 6, 8, 11, 13, 15, 17, 19, 20, 22, 24, 26, and 28.
    """


Prompt:
# class ListNode:
#     def __init__(val=0, next=None):
#         self.val = val
#         self.next = next
class Solution:
    def mergeNodes(head: Optional[ListNode]) -> Optional[ListNode]:
    """
    You are given the head of a linked list, which contains a series of integers separated by 0's. The beginning and end of the linked list will have Node.val == 0.
    For every two consecutive 0's, merge all the nodes lying in between them into a single node whose value is the sum of all the merged nodes. The modified list should not contain any 0's.
    Return the head of the modified linked list.

    Example 1:

    >>> __init__(head = [0,3,1,0,4,5,2,0])
    >>> [4,11]
    Explanation:
    The above figure represents the given linked list. The modified list contains
    - The sum of the nodes marked in green: 3 + 1 = 4.
    - The sum of the nodes marked in red: 4 + 5 + 2 = 11.

    Example 2:

    >>> __init__(head = [0,1,0,3,0,2,2,0])
    >>> [1,3,4]
    Explanation:
    The above figure represents the given linked list. The modified list contains
    - The sum of the nodes marked in green: 1 = 1.
    - The sum of the nodes marked in red: 3 = 3.
    - The sum of the nodes marked in yellow: 2 + 2 = 4.
    """


Prompt:
def repeatLimitedString(s: str, repeatLimit: int) -> str:
    """
    You are given a string s and an integer repeatLimit. Construct a new string repeatLimitedString using the characters of s such that no letter appears more than repeatLimit times in a row. You do not have to use all characters from s.
    Return the lexicographically largest repeatLimitedString possible.
    A string a is lexicographically larger than a string b if in the first position where a and b differ, string a has a letter that appears later in the alphabet than the corresponding letter in b. If the first min(a.length, b.length) characters do not differ, then the longer string is the lexicographically larger one.

    Example 1:

    >>> repeatLimitedString(s = "cczazcc", repeatLimit = 3)
    >>> "zzcccac"
    Explanation: We use all of the characters from s to construct the repeatLimitedString "zzcccac".
    The letter 'a' appears at most 1 time in a row.
    The letter 'c' appears at most 3 times in a row.
    The letter 'z' appears at most 2 times in a row.
    Hence, no letter appears more than repeatLimit times in a row and the string is a valid repeatLimitedString.
    The string is the lexicographically largest repeatLimitedString possible so we return "zzcccac".
    Note that the string "zzcccca" is lexicographically larger but the letter 'c' appears more than 3 times in a row, so it is not a valid repeatLimitedString.

    Example 2:

    >>> repeatLimitedString(s = "aababab", repeatLimit = 2)
    >>> "bbabaa"
    Explanation: We use only some of the characters from s to construct the repeatLimitedString "bbabaa".
    The letter 'a' appears at most 2 times in a row.
    The letter 'b' appears at most 2 times in a row.
    Hence, no letter appears more than repeatLimit times in a row and the string is a valid repeatLimitedString.
    The string is the lexicographically largest repeatLimitedString possible so we return "bbabaa".
    Note that the string "bbabaaa" is lexicographically larger but the letter 'a' appears more than 2 times in a row, so it is not a valid repeatLimitedString.
    """


Prompt:
def countPairs(nums: List[int], k: int) -> int:
    """
    Given a 0-indexed integer array nums of length n and an integer k, return the number of pairs (i, j) such that:

    0 <= i < j <= n - 1 and
    nums[i] * nums[j] is divisible by k.

    Example 1:

    >>> countPairs(nums = [1,2,3,4,5], k = 2)
    >>> 7
    Explanation:
    The 7 pairs of indices whose corresponding products are divisible by 2 are
    (0, 1), (0, 3), (1, 2), (1, 3), (1, 4), (2, 3), and (3, 4).
    Their products are 2, 4, 6, 8, 10, 12, and 20 respectively.
    Other pairs such as (0, 2) and (2, 4) have products 3 and 15 respectively, which are not divisible by 2.

    Example 2:

    >>> countPairs(nums = [1,2,3,4], k = 5)
    >>> 0
    Explanation: There does not exist any pair of indices whose corresponding product is divisible by 5.
    """


Prompt:
def buildWall(height: int, width: int, bricks: List[int]) -> int:
    """
    You are given integers height and width which specify the dimensions of a brick wall you are building. You are also given a 0-indexed array of unique integers bricks, where the ith brick has a height of 1 and a width of bricks[i]. You have an infinite supply of each type of brick and bricks may not be rotated.
    Each row in the wall must be exactly width units long. For the wall to be sturdy, adjacent rows in the wall should not join bricks at the same location, except at the ends of the wall.
    Return the number of ways to build a sturdy wall. Since the answer may be very large, return it modulo 109 + 7.

    Example 1:

    >>> buildWall(height = 2, width = 3, bricks = [1,2])
    >>> 2
    Explanation:
    The first two walls in the diagram show the only two ways to build a sturdy brick wall.
    Note that the third wall in the diagram is not sturdy because adjacent rows join bricks 2 units from the left.

    Example 2:

    >>> buildWall(height = 1, width = 1, bricks = [5])
    >>> 0
    Explanation:
    There are no ways to build a sturdy wall because the only type of brick we have is longer than the width of the wall.
    """


Prompt:
def prefixCount(words: List[str], pref: str) -> int:
    """
    You are given an array of strings words and a string pref.
    Return the number of strings in words that contain pref as a prefix.
    A prefix of a string s is any leading contiguous substring of s.

    Example 1:

    >>> prefixCount(words = ["pay","attention","practice","attend"], pref = "at")
    >>> 2
    Explanation: The 2 strings that contain "at" as a prefix are: "attention" and "attend".

    Example 2:

    >>> prefixCount(words = ["leetcode","win","loops","success"], pref = "code")
    >>> 0
    Explanation: There are no strings that contain "code" as a prefix.
    """


Prompt:
def minSteps(s: str, t: str) -> int:
    """
    You are given two strings s and t. In one step, you can append any character to either s or t.
    Return the minimum number of steps to make s and t anagrams of each other.
    An anagram of a string is a string that contains the same characters with a different (or the same) ordering.

    Example 1:

    >>> minSteps(s = "leetcode", t = "coats")
    >>> 7
    Explanation:
    - In 2 steps, we can append the letters in "as" onto s = "leetcode", forming s = "leetcodeas".
    - In 5 steps, we can append the letters in "leede" onto t = "coats", forming t = "coatsleede".
    "leetcodeas" and "coatsleede" are now anagrams of each other.
    We used a total of 2 + 5 = 7 steps.
    It can be shown that there is no way to make them anagrams of each other with less than 7 steps.

    Example 2:

    >>> minSteps(s = "night", t = "thing")
    >>> 0
    Explanation: The given strings are already anagrams of each other. Thus, we do not need any further steps.
    """


Prompt:
def minimumTime(time: List[int], totalTrips: int) -> int:
    """
    You are given an array time where time[i] denotes the time taken by the ith bus to complete one trip.
    Each bus can make multiple trips successively; that is, the next trip can start immediately after completing the current trip. Also, each bus operates independently; that is, the trips of one bus do not influence the trips of any other bus.
    You are also given an integer totalTrips, which denotes the number of trips all buses should make in total. Return the minimum time required for all buses to complete at least totalTrips trips.

    Example 1:

    >>> minimumTime(time = [1,2,3], totalTrips = 5)
    >>> 3
    Explanation:
    - At time t = 1, the number of trips completed by each bus are [1,0,0].
      The total number of trips completed is 1 + 0 + 0 = 1.
    - At time t = 2, the number of trips completed by each bus are [2,1,0].
      The total number of trips completed is 2 + 1 + 0 = 3.
    - At time t = 3, the number of trips completed by each bus are [3,1,1].
      The total number of trips completed is 3 + 1 + 1 = 5.
    So the minimum time needed for all buses to complete at least 5 trips is 3.

    Example 2:

    >>> minimumTime(time = [2], totalTrips = 1)
    >>> 2
    Explanation:
    There is only one bus, and it will complete its first trip at t = 2.
    So the minimum time needed to complete 1 trip is 2.
    """


Prompt:
def minimumFinishTime(tires: List[List[int]], changeTime: int, numLaps: int) -> int:
    """
    You are given a 0-indexed 2D integer array tires where tires[i] = [fi, ri] indicates that the ith tire can finish its xth successive lap in fi * ri(x-1) seconds.

    For example, if fi = 3 and ri = 2, then the tire would finish its 1st lap in 3 seconds, its 2nd lap in 3 * 2 = 6 seconds, its 3rd lap in 3 * 22 = 12 seconds, etc.

    You are also given an integer changeTime and an integer numLaps.
    The race consists of numLaps laps and you may start the race with any tire. You have an unlimited supply of each tire and after every lap, you may change to any given tire (including the current tire type) if you wait changeTime seconds.
    Return the minimum time to finish the race.

    Example 1:

    >>> minimumFinishTime(tires = [[2,3],[3,4]], changeTime = 5, numLaps = 4)
    >>> 21
    Explanation:
    Lap 1: Start with tire 0 and finish the lap in 2 seconds.
    Lap 2: Continue with tire 0 and finish the lap in 2 * 3 = 6 seconds.
    Lap 3: Change tires to a new tire 0 for 5 seconds and then finish the lap in another 2 seconds.
    Lap 4: Continue with tire 0 and finish the lap in 2 * 3 = 6 seconds.
    Total time = 2 + 6 + 5 + 2 + 6 = 21 seconds.
    The minimum time to complete the race is 21 seconds.

    Example 2:

    >>> minimumFinishTime(tires = [[1,10],[2,2],[3,4]], changeTime = 6, numLaps = 5)
    >>> 25
    Explanation:
    Lap 1: Start with tire 1 and finish the lap in 2 seconds.
    Lap 2: Continue with tire 1 and finish the lap in 2 * 2 = 4 seconds.
    Lap 3: Change tires to a new tire 1 for 6 seconds and then finish the lap in another 2 seconds.
    Lap 4: Continue with tire 1 and finish the lap in 2 * 2 = 4 seconds.
    Lap 5: Change tires to tire 0 for 6 seconds then finish the lap in another 1 second.
    Total time = 2 + 4 + 6 + 2 + 4 + 6 + 1 = 25 seconds.
    The minimum time to complete the race is 25 seconds.
    """


Prompt:
def houseOfCards(n: int) -> int:
    """
    You are given an integer n representing the number of playing cards you have. A house of cards meets the following conditions:

    A house of cards consists of one or more rows of triangles and horizontal cards.
    Triangles are created by leaning two cards against each other.
    One card must be placed horizontally between all adjacent triangles in a row.
    Any triangle on a row higher than the first must be placed on a horizontal card from the previous row.
    Each triangle is placed in the leftmost available spot in the row.

    Return the number of distinct house of cards you can build using all n cards. Two houses of cards are considered distinct if there exists a row where the two houses contain a different number of cards.

    Example 1:

    >>> houseOfCards(n = 16)
    >>> 2
    Explanation: The two valid houses of cards are shown.
    The third house of cards in the diagram is not valid because the rightmost triangle on the top row is not placed on top of a horizontal card.

    Example 2:

    >>> houseOfCards(n = 2)
    >>> 1
    Explanation: The one valid house of cards is shown.

    Example 3:

    >>> houseOfCards(n = 4)
    >>> 0
    Explanation: The three houses of cards in the diagram are not valid.
    The first house of cards needs a horizontal card placed between the two triangles.
    The second house of cards uses 5 cards.
    The third house of cards uses 2 cards.
    """


Prompt:
def mostFrequent(nums: List[int], key: int) -> int:
    """
    You are given a 0-indexed integer array nums. You are also given an integer key, which is present in nums.
    For every unique integer target in nums, count the number of times target immediately follows an occurrence of key in nums. In other words, count the number of indices i such that:

    0 <= i <= nums.length - 2,
    nums[i] == key and,
    nums[i + 1] == target.

    Return the target with the maximum count. The test cases will be generated such that the target with maximum count is unique.

    Example 1:

    >>> mostFrequent(nums = [1,100,200,1,100], key = 1)
    >>> 100
    Explanation: For target = 100, there are 2 occurrences at indices 1 and 4 which follow an occurrence of key.
    No other integers follow an occurrence of key, so we return 100.

    Example 2:

    >>> mostFrequent(nums = [2,2,2,2,3], key = 2)
    >>> 2
    Explanation: For target = 2, there are 3 occurrences at indices 1, 2, and 3 which follow an occurrence of key.
    For target = 3, there is only one occurrence at index 4 which follows an occurrence of key.
    target = 2 has the maximum number of occurrences following an occurrence of key, so we return 2.
    """


Prompt:
def sortJumbled(mapping: List[int], nums: List[int]) -> List[int]:
    """
    You are given a 0-indexed integer array mapping which represents the mapping rule of a shuffled decimal system. mapping[i] = j means digit i should be mapped to digit j in this system.
    The mapped value of an integer is the new integer obtained by replacing each occurrence of digit i in the integer with mapping[i] for all 0 <= i <= 9.
    You are also given another integer array nums. Return the array nums sorted in non-decreasing order based on the mapped values of its elements.
    Notes:

    Elements with the same mapped values should appear in the same relative order as in the input.
    The elements of nums should only be sorted based on their mapped values and not be replaced by them.

    Example 1:

    >>> sortJumbled(mapping = [8,9,4,0,2,1,3,5,7,6], nums = [991,338,38])
    >>> [338,38,991]
    Explanation:
    Map the number 991 as follows:
    1. mapping[9] = 6, so all occurrences of the digit 9 will become 6.
    2. mapping[1] = 9, so all occurrences of the digit 1 will become 9.
    Therefore, the mapped value of 991 is 669.
    338 maps to 007, or 7 after removing the leading zeros.
    38 maps to 07, which is also 7 after removing leading zeros.
    Since 338 and 38 share the same mapped value, they should remain in the same relative order, so 338 comes before 38.
    Thus, the sorted array is [338,38,991].

    Example 2:

    >>> sortJumbled(mapping = [0,1,2,3,4,5,6,7,8,9], nums = [789,456,123])
    >>> [123,456,789]
    Explanation: 789 maps to 789, 456 maps to 456, and 123 maps to 123. Thus, the sorted array is [123,456,789].
    """


Prompt:
def getAncestors(n: int, edges: List[List[int]]) -> List[List[int]]:
    """
    You are given a positive integer n representing the number of nodes of a Directed Acyclic Graph (DAG). The nodes are numbered from 0 to n - 1 (inclusive).
    You are also given a 2D integer array edges, where edges[i] = [fromi, toi] denotes that there is a unidirectional edge from fromi to toi in the graph.
    Return a list answer, where answer[i] is the list of ancestors of the ith node, sorted in ascending order.
    A node u is an ancestor of another node v if u can reach v via a set of edges.

    Example 1:

    >>> getAncestors(n = 8, edgeList = [[0,3],[0,4],[1,3],[2,4],[2,7],[3,5],[3,6],[3,7],[4,6]])
    >>> [[],[],[],[0,1],[0,2],[0,1,3],[0,1,2,3,4],[0,1,2,3]]
    Explanation:
    The above diagram represents the input graph.
    - Nodes 0, 1, and 2 do not have any ancestors.
    - Node 3 has two ancestors 0 and 1.
    - Node 4 has two ancestors 0 and 2.
    - Node 5 has three ancestors 0, 1, and 3.
    - Node 6 has five ancestors 0, 1, 2, 3, and 4.
    - Node 7 has four ancestors 0, 1, 2, and 3.

    Example 2:

    >>> getAncestors(n = 5, edgeList = [[0,1],[0,2],[0,3],[0,4],[1,2],[1,3],[1,4],[2,3],[2,4],[3,4]])
    >>> [[],[0],[0,1],[0,1,2],[0,1,2,3]]
    Explanation:
    The above diagram represents the input graph.
    - Node 0 does not have any ancestor.
    - Node 1 has one ancestor 0.
    - Node 2 has two ancestors 0 and 1.
    - Node 3 has three ancestors 0, 1, and 2.
    - Node 4 has four ancestors 0, 1, 2, and 3.
    """


Prompt:
def minMovesToMakePalindrome(s: str) -> int:
    """
    You are given a string s consisting only of lowercase English letters.
    In one move, you can select any two adjacent characters of s and swap them.
    Return the minimum number of moves needed to make s a palindrome.
    Note that the input will be generated such that s can always be converted to a palindrome.

    Example 1:

    >>> minMovesToMakePalindrome(s = "aabb")
    >>> 2
    Explanation:
    We can obtain two palindromes from s, "abba" and "baab".
    - We can obtain "abba" from s in 2 moves: "aabb" -> "abab" -> "abba".
    - We can obtain "baab" from s in 2 moves: "aabb" -> "abab" -> "baab".
    Thus, the minimum number of moves needed to make s a palindrome is 2.

    Example 2:

    >>> minMovesToMakePalindrome(s = "letelt")
    >>> 2
    Explanation:
    One of the palindromes we can obtain from s in 2 moves is "lettel".
    One of the ways we can obtain it is "letelt" -> "letetl" -> "lettel".
    Other palindromes such as "tleelt" can also be obtained in 2 moves.
    It can be shown that it is not possible to obtain a palindrome in less than 2 moves.
    """


Prompt:
def cellsInRange(s: str) -> List[str]:
    """
    A cell (r, c) of an excel sheet is represented as a string "" where:

     denotes the column number c of the cell. It is represented by alphabetical letters.

    For example, the 1st column is denoted by 'A', the 2nd by 'B', the 3rd by 'C', and so on.

     is the row number r of the cell. The rth row is represented by the integer r.

    You are given a string s in the format ":", where  represents the column c1,  represents the row r1,  represents the column c2, and  represents the row r2, such that r1 <= r2 and c1 <= c2.
    Return the list of cells (x, y) such that r1 <= x <= r2 and c1 <= y <= c2. The cells should be represented as strings in the format mentioned above and be sorted in non-decreasing order first by columns and then by rows.

    Example 1:

    >>> cellsInRange(s = "K1:L2")
    >>> ["K1","K2","L1","L2"]
    Explanation:
    The above diagram shows the cells which should be present in the list.
    The red arrows denote the order in which the cells should be presented.

    Example 2:

    >>> cellsInRange(s = "A1:F1")
    >>> ["A1","B1","C1","D1","E1","F1"]
    Explanation:
    The above diagram shows the cells which should be present in the list.
    The red arrow denotes the order in which the cells should be presented.
    """


Prompt:
def minimalKSum(nums: List[int], k: int) -> int:
    """
    You are given an integer array nums and an integer k. Append k unique positive integers that do not appear in nums to nums such that the resulting total sum is minimum.
    Return the sum of the k integers appended to nums.

    Example 1:

    >>> minimalKSum(nums = [1,4,25,10,25], k = 2)
    >>> 5
    Explanation: The two unique positive integers that do not appear in nums which we append are 2 and 3.
    The resulting sum of nums is 1 + 4 + 25 + 10 + 25 + 2 + 3 = 70, which is the minimum.
    The sum of the two integers appended is 2 + 3 = 5, so we return 5.
    Example 2:

    >>> minimalKSum(nums = [5,6], k = 6)
    >>> 25
    Explanation: The six unique positive integers that do not appear in nums which we append are 1, 2, 3, 4, 7, and 8.
    The resulting sum of nums is 5 + 6 + 1 + 2 + 3 + 4 + 7 + 8 = 36, which is the minimum.
    The sum of the six integers appended is 1 + 2 + 3 + 4 + 7 + 8 = 25, so we return 25.
    """


Prompt:
# class TreeNode:
#     def __init__(val=0, left=None, right=None):
#         self.val = val
#         self.left = left
#         self.right = right
class Solution:
    def createBinaryTree(descriptions: List[List[int]]) -> Optional[TreeNode]:
    """
    You are given a 2D integer array descriptions where descriptions[i] = [parenti, childi, isLefti] indicates that parenti is the parent of childi in a binary tree of unique values. Furthermore,

    If isLefti == 1, then childi is the left child of parenti.
    If isLefti == 0, then childi is the right child of parenti.

    Construct the binary tree described by descriptions and return its root.
    The test cases will be generated such that the binary tree is valid.

    Example 1:

    >>> __init__(descriptions = [[20,15,1],[20,17,0],[50,20,1],[50,80,0],[80,19,1]])
    >>> [50,20,80,15,17,19]
    Explanation: The root node is the node with value 50 since it has no parent.
    The resulting binary tree is shown in the diagram.

    Example 2:

    >>> __init__(descriptions = [[1,2,1],[2,3,0],[3,4,1]])
    >>> [1,2,null,null,3,4]
    Explanation: The root node is the node with value 1 since it has no parent.
    The resulting binary tree is shown in the diagram.
    """


Prompt:
def replaceNonCoprimes(nums: List[int]) -> List[int]:
    """
    You are given an array of integers nums. Perform the following steps:

    Find any two adjacent numbers in nums that are non-coprime.
    If no such numbers are found, stop the process.
    Otherwise, delete the two numbers and replace them with their LCM (Least Common Multiple).
    Repeat this process as long as you keep finding two adjacent non-coprime numbers.

    Return the final modified array. It can be shown that replacing adjacent non-coprime numbers in any arbitrary order will lead to the same result.
    The test cases are generated such that the values in the final array are less than or equal to 108.
    Two values x and y are non-coprime if GCD(x, y) > 1 where GCD(x, y) is the Greatest Common Divisor of x and y.

    Example 1:

    >>> replaceNonCoprimes(nums = [6,4,3,2,7,6,2])
    >>> [12,7,6]
    Explanation:
    - (6, 4) are non-coprime with LCM(6, 4) = 12. Now, nums = [12,3,2,7,6,2].
    - (12, 3) are non-coprime with LCM(12, 3) = 12. Now, nums = [12,2,7,6,2].
    - (12, 2) are non-coprime with LCM(12, 2) = 12. Now, nums = [12,7,6,2].
    - (6, 2) are non-coprime with LCM(6, 2) = 6. Now, nums = [12,7,6].
    There are no more adjacent non-coprime numbers in nums.
    Thus, the final modified array is [12,7,6].
    Note that there are other ways to obtain the same resultant array.

    Example 2:

    >>> replaceNonCoprimes(nums = [2,2,1,1,3,3,3])
    >>> [2,1,1,3]
    Explanation:
    - (3, 3) are non-coprime with LCM(3, 3) = 3. Now, nums = [2,2,1,1,3,3].
    - (3, 3) are non-coprime with LCM(3, 3) = 3. Now, nums = [2,2,1,1,3].
    - (2, 2) are non-coprime with LCM(2, 2) = 2. Now, nums = [2,1,1,3].
    There are no more adjacent non-coprime numbers in nums.
    Thus, the final modified array is [2,1,1,3].
    Note that there are other ways to obtain the same resultant array.
    """


Prompt:
def singleDivisorTriplet(nums: List[int]) -> int:
    """
    You are given a 0-indexed array of positive integers nums. A triplet of three distinct indices (i, j, k) is called a single divisor triplet of nums if nums[i] + nums[j] + nums[k] is divisible by exactly one of nums[i], nums[j], or nums[k].
    Return the number of single divisor triplets of nums.

    Example 1:

    >>> singleDivisorTriplet(nums = [4,6,7,3,2])
    >>> 12
    Explanation:
    The triplets (0, 3, 4), (0, 4, 3), (3, 0, 4), (3, 4, 0), (4, 0, 3), and (4, 3, 0) have the values of [4, 3, 2] (or a permutation of [4, 3, 2]).
    4 + 3 + 2 = 9 which is only divisible by 3, so all such triplets are single divisor triplets.
    The triplets (0, 2, 3), (0, 3, 2), (2, 0, 3), (2, 3, 0), (3, 0, 2), and (3, 2, 0) have the values of [4, 7, 3] (or a permutation of [4, 7, 3]).
    4 + 7 + 3 = 14 which is only divisible by 7, so all such triplets are single divisor triplets.
    There are 12 single divisor triplets in total.

    Example 2:

    >>> singleDivisorTriplet(nums = [1,2,2])
    >>> 6
    Explanation:
    The triplets (0, 1, 2), (0, 2, 1), (1, 0, 2), (1, 2, 0), (2, 0, 1), and (2, 1, 0) have the values of [1, 2, 2] (or a permutation of [1, 2, 2]).
    1 + 2 + 2 = 5 which is only divisible by 1, so all such triplets are single divisor triplets.
    There are 6 single divisor triplets in total.

    Example 3:

    >>> singleDivisorTriplet(nums = [1,1,1])
    >>> 0
    Explanation:
    There are no single divisor triplets.
    Note that (0, 1, 2) is not a single divisor triplet because nums[0] + nums[1] + nums[2] = 3 and 3 is divisible by nums[0], nums[1], and nums[2].
    """


Prompt:
def findKDistantIndices(nums: List[int], key: int, k: int) -> List[int]:
    """
    You are given a 0-indexed integer array nums and two integers key and k. A k-distant index is an index i of nums for which there exists at least one index j such that |i - j| <= k and nums[j] == key.
    Return a list of all k-distant indices sorted in increasing order.

    Example 1:

    >>> findKDistantIndices(nums = [3,4,9,1,3,9,5], key = 9, k = 1)
    >>> [1,2,3,4,5,6]
    Explanation: Here, nums[2] == key and nums[5] == key.
    - For index 0, |0 - 2| > k and |0 - 5| > k, so there is no j where |0 - j| <= k and nums[j] == key. Thus, 0 is not a k-distant index.
    - For index 1, |1 - 2| <= k and nums[2] == key, so 1 is a k-distant index.
    - For index 2, |2 - 2| <= k and nums[2] == key, so 2 is a k-distant index.
    - For index 3, |3 - 2| <= k and nums[2] == key, so 3 is a k-distant index.
    - For index 4, |4 - 5| <= k and nums[5] == key, so 4 is a k-distant index.
    - For index 5, |5 - 5| <= k and nums[5] == key, so 5 is a k-distant index.
    - For index 6, |6 - 5| <= k and nums[5] == key, so 6 is a k-distant index.
    Thus, we return [1,2,3,4,5,6] which is sorted in increasing order.

    Example 2:

    >>> findKDistantIndices(nums = [2,2,2,2,2], key = 2, k = 2)
    >>> [0,1,2,3,4]
    Explanation: For all indices i in nums, there exists some index j such that |i - j| <= k and nums[j] == key, so every index is a k-distant index.
    Hence, we return [0,1,2,3,4].
    """