Prompt:
def longestIdealString(s: str, k: int) -> int:
    """
    You are given a string s consisting of lowercase letters and an integer k. We call a string t ideal if the following conditions are satisfied:

    t is a subsequence of the string s.
    The absolute difference in the alphabet order of every two adjacent letters in t is less than or equal to k.

    Return the length of the longest ideal string.
    A subsequence is a string that can be derived from another string by deleting some or no characters without changing the order of the remaining characters.
    Note that the alphabet order is not cyclic. For example, the absolute difference in the alphabet order of 'a' and 'z' is 25, not 1.

    Example 1:

    >>> longestIdealString(s = "acfgbd", k = 2)
    >>> 4
    Explanation: The longest ideal string is "acbd". The length of this string is 4, so 4 is returned.
    Note that "acfgbd" is not ideal because 'c' and 'f' have a difference of 3 in alphabet order.
    Example 2:

    >>> longestIdealString(s = "abcd", k = 3)
    >>> 4
    Explanation: The longest ideal string is "abcd". The length of this string is 4, so 4 is returned.
    """


Prompt:
def minScore(grid: List[List[int]]) -> List[List[int]]:
    """
    You are given an m x n integer matrix grid containing distinct positive integers.
    You have to replace each integer in the matrix with a positive integer satisfying the following conditions:

    The relative order of every two elements that are in the same row or column should stay the same after the replacements.
    The maximum number in the matrix after the replacements should be as small as possible.

    The relative order stays the same if for all pairs of elements in the original matrix such that grid[r1][c1] > grid[r2][c2] where either r1 == r2 or c1 == c2, then it must be true that grid[r1][c1] > grid[r2][c2] after the replacements.
    For example, if grid = [[2, 4, 5], [7, 3, 9]] then a good replacement could be either grid = [[1, 2, 3], [2, 1, 4]] or grid = [[1, 2, 3], [3, 1, 4]].
    Return the resulting matrix. If there are multiple answers, return any of them.

    Example 1:

    >>> minScore(grid = [[3,1],[2,5]])
    >>> [[2,1],[1,2]]
    Explanation: The above diagram shows a valid replacement.
    The maximum number in the matrix is 2. It can be shown that no smaller value can be obtained.

    Example 2:

    >>> minScore(grid = [[10]])
    >>> [[1]]
    Explanation: We replace the only number in the matrix with 1.
    """


Prompt:
def largestLocal(grid: List[List[int]]) -> List[List[int]]:
    """
    You are given an n x n integer matrix grid.
    Generate an integer matrix maxLocal of size (n - 2) x (n - 2) such that:

    maxLocal[i][j] is equal to the largest value of the 3 x 3 matrix in grid centered around row i + 1 and column j + 1.

    In other words, we want to find the largest value in every contiguous 3 x 3 matrix in grid.
    Return the generated matrix.

    Example 1:

    >>> largestLocal(grid = [[9,9,8,1],[5,6,2,6],[8,2,6,4],[6,2,2,2]])
    >>> [[9,9],[8,6]]
    Explanation: The diagram above shows the original matrix and the generated matrix.
    Notice that each value in the generated matrix corresponds to the largest value of a contiguous 3 x 3 matrix in grid.
    Example 2:

    >>> largestLocal(grid = [[1,1,1,1,1],[1,1,1,1,1],[1,1,2,1,1],[1,1,1,1,1],[1,1,1,1,1]])
    >>> [[2,2,2],[2,2,2],[2,2,2]]
    Explanation: Notice that the 2 is contained within every contiguous 3 x 3 matrix in grid.
    """


Prompt:
def edgeScore(edges: List[int]) -> int:
    """
    You are given a directed graph with n nodes labeled from 0 to n - 1, where each node has exactly one outgoing edge.
    The graph is represented by a given 0-indexed integer array edges of length n, where edges[i] indicates that there is a directed edge from node i to node edges[i].
    The edge score of a node i is defined as the sum of the labels of all the nodes that have an edge pointing to i.
    Return the node with the highest edge score. If multiple nodes have the same edge score, return the node with the smallest index.

    Example 1:

    >>> edgeScore(edges = [1,0,0,0,0,7,7,5])
    >>> 7
    Explanation:
    - The nodes 1, 2, 3 and 4 have an edge pointing to node 0. The edge score of node 0 is 1 + 2 + 3 + 4 = 10.
    - The node 0 has an edge pointing to node 1. The edge score of node 1 is 0.
    - The node 7 has an edge pointing to node 5. The edge score of node 5 is 7.
    - The nodes 5 and 6 have an edge pointing to node 7. The edge score of node 7 is 5 + 6 = 11.
    Node 7 has the highest edge score so return 7.

    Example 2:

    >>> edgeScore(edges = [2,0,0,2])
    >>> 0
    Explanation:
    - The nodes 1 and 2 have an edge pointing to node 0. The edge score of node 0 is 1 + 2 = 3.
    - The nodes 0 and 3 have an edge pointing to node 2. The edge score of node 2 is 0 + 3 = 3.
    Nodes 0 and 2 both have an edge score of 3. Since node 0 has a smaller index, we return 0.
    """


Prompt:
def smallestNumber(pattern: str) -> str:
    """
    You are given a 0-indexed string pattern of length n consisting of the characters 'I' meaning increasing and 'D' meaning decreasing.
    A 0-indexed string num of length n + 1 is created using the following conditions:

    num consists of the digits '1' to '9', where each digit is used at most once.
    If pattern[i] == 'I', then num[i] < num[i + 1].
    If pattern[i] == 'D', then num[i] > num[i + 1].

    Return the lexicographically smallest possible string num that meets the conditions.

    Example 1:

    >>> smallestNumber(pattern = "IIIDIDDD")
    >>> "123549876"
    Explanation:
    At indices 0, 1, 2, and 4 we must have that num[i] < num[i+1].
    At indices 3, 5, 6, and 7 we must have that num[i] > num[i+1].
    Some possible values of num are "245639871", "135749862", and "123849765".
    It can be proven that "123549876" is the smallest possible num that meets the conditions.
    Note that "123414321" is not possible because the digit '1' is used more than once.
    Example 2:

    >>> smallestNumber(pattern = "DDD")
    >>> "4321"
    Explanation:
    Some possible values of num are "9876", "7321", and "8742".
    It can be proven that "4321" is the smallest possible num that meets the conditions.
    """


Prompt:
def countSpecialNumbers(n: int) -> int:
    """
    We call a positive integer special if all of its digits are distinct.
    Given a positive integer n, return the number of special integers that belong to the interval [1, n].

    Example 1:

    >>> countSpecialNumbers(n = 20)
    >>> 19
    Explanation: All the integers from 1 to 20, except 11, are special. Thus, there are 19 special integers.

    Example 2:

    >>> countSpecialNumbers(n = 5)
    >>> 5
    Explanation: All the integers from 1 to 5 are special.

    Example 3:

    >>> countSpecialNumbers(n = 135)
    >>> 110
    Explanation: There are 110 integers from 1 to 135 that are special.
    Some of the integers that are not special are: 22, 114, and 131.
    """


Prompt:
def maxScore(edges: List[List[int]]) -> int:
    """
    You are given a weighted tree consisting of n nodes numbered from 0 to n - 1.
    The tree is rooted at node 0 and represented with a 2D array edges of size n where edges[i] = [pari, weighti] indicates that node pari is the parent of node i, and the edge between them has a weight equal to weighti. Since the root does not have a parent, you have edges[0] = [-1, -1].
    Choose some edges from the tree such that no two chosen edges are adjacent and the sum of the weights of the chosen edges is maximized.
    Return the maximum sum of the chosen edges.
    Note:

    You are allowed to not choose any edges in the tree, the sum of weights in this case will be 0.
    Two edges Edge1 and Edge2 in the tree are adjacent if they have a common node.

    In other words, they are adjacent if Edge1 connects nodes a and b and Edge2 connects nodes b and c.

    Example 1:

    >>> maxScore(edges = [[-1,-1],[0,5],[0,10],[2,6],[2,4]])
    >>> 11
    Explanation: The above diagram shows the edges that we have to choose colored in red.
    The total score is 5 + 6 = 11.
    It can be shown that no better score can be obtained.

    Example 2:

    >>> maxScore(edges = [[-1,-1],[0,5],[0,-6],[0,7]])
    >>> 7
    Explanation: We choose the edge with weight 7.
    Note that we cannot choose more than one edge because all edges are adjacent to each other.
    """


Prompt:
def minimumRecolors(blocks: str, k: int) -> int:
    """
    You are given a 0-indexed string blocks of length n, where blocks[i] is either 'W' or 'B', representing the color of the ith block. The characters 'W' and 'B' denote the colors white and black, respectively.
    You are also given an integer k, which is the desired number of consecutive black blocks.
    In one operation, you can recolor a white block such that it becomes a black block.
    Return the minimum number of operations needed such that there is at least one occurrence of k consecutive black blocks.

    Example 1:

    >>> minimumRecolors(blocks = "WBBWWBBWBW", k = 7)
    >>> 3
    Explanation:
    One way to achieve 7 consecutive black blocks is to recolor the 0th, 3rd, and 4th blocks
    so that blocks = "BBBBBBBWBW".
    It can be shown that there is no way to achieve 7 consecutive black blocks in less than 3 operations.
    Therefore, we return 3.

    Example 2:

    >>> minimumRecolors(blocks = "WBWBBBW", k = 2)
    >>> 0
    Explanation:
    No changes need to be made, since 2 consecutive black blocks already exist.
    Therefore, we return 0.
    """


Prompt:
def secondsToRemoveOccurrences(s: str) -> int:
    """
    You are given a binary string s. In one second, all occurrences of "01" are simultaneously replaced with "10". This process repeats until no occurrences of "01" exist.
    Return the number of seconds needed to complete this process.

    Example 1:

    >>> secondsToRemoveOccurrences(s = "0110101")
    >>> 4
    Explanation:
    After one second, s becomes "1011010".
    After another second, s becomes "1101100".
    After the third second, s becomes "1110100".
    After the fourth second, s becomes "1111000".
    No occurrence of "01" exists any longer, and the process needed 4 seconds to complete,
    so we return 4.

    Example 2:

    >>> secondsToRemoveOccurrences(s = "11100")
    >>> 0
    Explanation:
    No occurrence of "01" exists in s, and the processes needed 0 seconds to complete,
    so we return 0.
    """


Prompt:
def shiftingLetters(s: str, shifts: List[List[int]]) -> str:
    """
    You are given a string s of lowercase English letters and a 2D integer array shifts where shifts[i] = [starti, endi, directioni]. For every i, shift the characters in s from the index starti to the index endi (inclusive) forward if directioni = 1, or shift the characters backward if directioni = 0.
    Shifting a character forward means replacing it with the next letter in the alphabet (wrapping around so that 'z' becomes 'a'). Similarly, shifting a character backward means replacing it with the previous letter in the alphabet (wrapping around so that 'a' becomes 'z').
    Return the final string after all such shifts to s are applied.

    Example 1:

    >>> shiftingLetters(s = "abc", shifts = [[0,1,0],[1,2,1],[0,2,1]])
    >>> "ace"
    Explanation: Firstly, shift the characters from index 0 to index 1 backward. Now s = "zac".
    Secondly, shift the characters from index 1 to index 2 forward. Now s = "zbd".
    Finally, shift the characters from index 0 to index 2 forward. Now s = "ace".
    Example 2:

    >>> shiftingLetters(s = "dztz", shifts = [[0,0,0],[1,1,1]])
    >>> "catz"
    Explanation: Firstly, shift the characters from index 0 to index 0 backward. Now s = "cztz".
    Finally, shift the characters from index 1 to index 1 forward. Now s = "catz".
    """


Prompt:
def maximumSegmentSum(nums: List[int], removeQueries: List[int]) -> List[int]:
    """
    You are given two 0-indexed integer arrays nums and removeQueries, both of length n. For the ith query, the element in nums at the index removeQueries[i] is removed, splitting nums into different segments.
    A segment is a contiguous sequence of positive integers in nums. A segment sum is the sum of every element in a segment.
    Return an integer array answer, of length n, where answer[i] is the maximum segment sum after applying the ith removal.
    Note: The same index will not be removed more than once.

    Example 1:

    >>> maximumSegmentSum(nums = [1,2,5,6,1], removeQueries = [0,3,2,4,1])
    >>> [14,7,2,2,0]
    Explanation: Using 0 to indicate a removed element, the answer is as follows:
    Query 1: Remove the 0th element, nums becomes [0,2,5,6,1] and the maximum segment sum is 14 for segment [2,5,6,1].
    Query 2: Remove the 3rd element, nums becomes [0,2,5,0,1] and the maximum segment sum is 7 for segment [2,5].
    Query 3: Remove the 2nd element, nums becomes [0,2,0,0,1] and the maximum segment sum is 2 for segment [2].
    Query 4: Remove the 4th element, nums becomes [0,2,0,0,0] and the maximum segment sum is 2 for segment [2].
    Query 5: Remove the 1st element, nums becomes [0,0,0,0,0] and the maximum segment sum is 0, since there are no segments.
    Finally, we return [14,7,2,2,0].
    Example 2:

    >>> maximumSegmentSum(nums = [3,2,11,1], removeQueries = [3,2,1,0])
    >>> [16,5,3,0]
    Explanation: Using 0 to indicate a removed element, the answer is as follows:
    Query 1: Remove the 3rd element, nums becomes [3,2,11,0] and the maximum segment sum is 16 for segment [3,2,11].
    Query 2: Remove the 2nd element, nums becomes [3,2,0,0] and the maximum segment sum is 5 for segment [3,2].
    Query 3: Remove the 1st element, nums becomes [3,0,0,0] and the maximum segment sum is 3 for segment [3].
    Query 4: Remove the 0th element, nums becomes [0,0,0,0] and the maximum segment sum is 0, since there are no segments.
    Finally, we return [16,5,3,0].
    """


Prompt:
def minNumberOfHours(initialEnergy: int, initialExperience: int, energy: List[int], experience: List[int]) -> int:
    """
    You are entering a competition, and are given two positive integers initialEnergy and initialExperience denoting your initial energy and initial experience respectively.
    You are also given two 0-indexed integer arrays energy and experience, both of length n.
    You will face n opponents in order. The energy and experience of the ith opponent is denoted by energy[i] and experience[i] respectively. When you face an opponent, you need to have both strictly greater experience and energy to defeat them and move to the next opponent if available.
    Defeating the ith opponent increases your experience by experience[i], but decreases your energy by energy[i].
    Before starting the competition, you can train for some number of hours. After each hour of training, you can either choose to increase your initial experience by one, or increase your initial energy by one.
    Return the minimum number of training hours required to defeat all n opponents.

    Example 1:

    >>> minNumberOfHours(initialEnergy = 5, initialExperience = 3, energy = [1,4,3,2], experience = [2,6,3,1])
    >>> 8
    Explanation: You can increase your energy to 11 after 6 hours of training, and your experience to 5 after 2 hours of training.
    You face the opponents in the following order:
    - You have more energy and experience than the 0th opponent so you win.
      Your energy becomes 11 - 1 = 10, and your experience becomes 5 + 2 = 7.
    - You have more energy and experience than the 1st opponent so you win.
      Your energy becomes 10 - 4 = 6, and your experience becomes 7 + 6 = 13.
    - You have more energy and experience than the 2nd opponent so you win.
      Your energy becomes 6 - 3 = 3, and your experience becomes 13 + 3 = 16.
    - You have more energy and experience than the 3rd opponent so you win.
      Your energy becomes 3 - 2 = 1, and your experience becomes 16 + 1 = 17.
    You did a total of 6 + 2 = 8 hours of training before the competition, so we return 8.
    It can be proven that no smaller answer exists.

    Example 2:

    >>> minNumberOfHours(initialEnergy = 2, initialExperience = 4, energy = [1], experience = [3])
    >>> 0
    Explanation: You do not need any additional energy or experience to win the competition, so we return 0.
    """


Prompt:
def largestPalindromic(num: str) -> str:
    """
    You are given a string num consisting of digits only.
    Return the largest palindromic integer (in the form of a string) that can be formed using digits taken from num. It should not contain leading zeroes.
    Notes:

    You do not need to use all the digits of num, but you must use at least one digit.
    The digits can be reordered.

    Example 1:

    >>> largestPalindromic(num = "444947137")
    >>> "7449447"
    Explanation:
    Use the digits "4449477" from "444947137" to form the palindromic integer "7449447".
    It can be shown that "7449447" is the largest palindromic integer that can be formed.

    Example 2:

    >>> largestPalindromic(num = "00009")
    >>> "9"
    Explanation:
    It can be shown that "9" is the largest palindromic integer that can be formed.
    Note that the integer returned should not contain leading zeroes.
    """


Prompt:
# class TreeNode:
#     def __init__(val=0, left=None, right=None):
#         self.val = val
#         self.left = left
#         self.right = right
class Solution:
    def amountOfTime(root: Optional[TreeNode], start: int) -> int:
    """
    You are given the root of a binary tree with unique values, and an integer start. At minute 0, an infection starts from the node with value start.
    Each minute, a node becomes infected if:

    The node is currently uninfected.
    The node is adjacent to an infected node.

    Return the number of minutes needed for the entire tree to be infected.

    Example 1:

    >>> __init__(root = [1,5,3,null,4,10,6,9,2], start = 3)
    >>> 4
    Explanation: The following nodes are infected during:
    - Minute 0: Node 3
    - Minute 1: Nodes 1, 10 and 6
    - Minute 2: Node 5
    - Minute 3: Node 4
    - Minute 4: Nodes 9 and 2
    It takes 4 minutes for the whole tree to be infected so we return 4.

    Example 2:

    >>> __init__(root = [1], start = 1)
    >>> 0
    Explanation: At minute 0, the only node in the tree is infected so we return 0.
    """


Prompt:
def kSum(nums: List[int], k: int) -> int:
    """
    You are given an integer array nums and a positive integer k. You can choose any subsequence of the array and sum all of its elements together.
    We define the K-Sum of the array as the kth largest subsequence sum that can be obtained (not necessarily distinct).
    Return the K-Sum of the array.
    A subsequence is an array that can be derived from another array by deleting some or no elements without changing the order of the remaining elements.
    Note that the empty subsequence is considered to have a sum of 0.

    Example 1:

    >>> kSum(nums = [2,4,-2], k = 5)
    >>> 2
    Explanation: All the possible subsequence sums that we can obtain are the following sorted in decreasing order:
    - 6, 4, 4, 2, 2, 0, 0, -2.
    The 5-Sum of the array is 2.

    Example 2:

    >>> kSum(nums = [1,-2,3,4,-10,12], k = 16)
    >>> 10
    Explanation: The 16-Sum of the array is 10.
    """


Prompt:
def matrixMedian(grid: List[List[int]]) -> int:
    """
    Given an m x n matrix grid containing an odd number of integers where each row is sorted in non-decreasing order, return the median of the matrix.
    You must solve the problem in less than O(m * n) time complexity.

    Example 1:

    >>> matrixMedian(grid = [[1,1,2],[2,3,3],[1,3,4]])
    >>> 2
    Explanation: The elements of the matrix in sorted order are 1,1,1,2,2,3,3,3,4. The median is 2.

    Example 2:

    >>> matrixMedian(grid = [[1,1,3,3,4]])
    >>> 3
    Explanation: The elements of the matrix in sorted order are 1,1,3,3,4. The median is 3.
    """


Prompt:
def answerQueries(nums: List[int], queries: List[int]) -> List[int]:
    """
    You are given an integer array nums of length n, and an integer array queries of length m.
    Return an array answer of length m where answer[i] is the maximum size of a subsequence that you can take from nums such that the sum of its elements is less than or equal to queries[i].
    A subsequence is an array that can be derived from another array by deleting some or no elements without changing the order of the remaining elements.

    Example 1:

    >>> answerQueries(nums = [4,5,2,1], queries = [3,10,21])
    >>> [2,3,4]
    Explanation: We answer the queries as follows:
    - The subsequence [2,1] has a sum less than or equal to 3. It can be proven that 2 is the maximum size of such a subsequence, so answer[0] = 2.
    - The subsequence [4,5,1] has a sum less than or equal to 10. It can be proven that 3 is the maximum size of such a subsequence, so answer[1] = 3.
    - The subsequence [4,5,2,1] has a sum less than or equal to 21. It can be proven that 4 is the maximum size of such a subsequence, so answer[2] = 4.

    Example 2:

    >>> answerQueries(nums = [2,3,4,5], queries = [1])
    >>> [0]
    Explanation: The empty subsequence is the only subsequence that has a sum less than or equal to 1, so answer[0] = 0.
    """


Prompt:
def removeStars(s: str) -> str:
    """
    You are given a string s, which contains stars *.
    In one operation, you can:

    Choose a star in s.
    Remove the closest non-star character to its left, as well as remove the star itself.

    Return the string after all stars have been removed.
    Note:

    The input will be generated such that the operation is always possible.
    It can be shown that the resulting string will always be unique.

    Example 1:

    >>> removeStars(s = "leet**cod*e")
    >>> "lecoe"
    Explanation: Performing the removals from left to right:
    - The closest character to the 1st star is 't' in "leet**cod*e". s becomes "lee*cod*e".
    - The closest character to the 2nd star is 'e' in "lee*cod*e". s becomes "lecod*e".
    - The closest character to the 3rd star is 'd' in "lecod*e". s becomes "lecoe".
    There are no more stars, so we return "lecoe".
    Example 2:

    >>> removeStars(s = "erase*****")
    >>> ""
    Explanation: The entire string is removed, so we return an empty string.
    """


Prompt:
def garbageCollection(garbage: List[str], travel: List[int]) -> int:
    """
    You are given a 0-indexed array of strings garbage where garbage[i] represents the assortment of garbage at the ith house. garbage[i] consists only of the characters 'M', 'P' and 'G' representing one unit of metal, paper and glass garbage respectively. Picking up one unit of any type of garbage takes 1 minute.
    You are also given a 0-indexed integer array travel where travel[i] is the number of minutes needed to go from house i to house i + 1.
    There are three garbage trucks in the city, each responsible for picking up one type of garbage. Each garbage truck starts at house 0 and must visit each house in order; however, they do not need to visit every house.
    Only one garbage truck may be used at any given moment. While one truck is driving or picking up garbage, the other two trucks cannot do anything.
    Return the minimum number of minutes needed to pick up all the garbage.

    Example 1:

    >>> garbageCollection(garbage = ["G","P","GP","GG"], travel = [2,4,3])
    >>> 21
    Explanation:
    The paper garbage truck:
    1. Travels from house 0 to house 1
    2. Collects the paper garbage at house 1
    3. Travels from house 1 to house 2
    4. Collects the paper garbage at house 2
    Altogether, it takes 8 minutes to pick up all the paper garbage.
    The glass garbage truck:
    1. Collects the glass garbage at house 0
    2. Travels from house 0 to house 1
    3. Travels from house 1 to house 2
    4. Collects the glass garbage at house 2
    5. Travels from house 2 to house 3
    6. Collects the glass garbage at house 3
    Altogether, it takes 13 minutes to pick up all the glass garbage.
    Since there is no metal garbage, we do not need to consider the metal garbage truck.
    Therefore, it takes a total of 8 + 13 = 21 minutes to collect all the garbage.

    Example 2:

    >>> garbageCollection(garbage = ["MMM","PGM","GP"], travel = [3,10])
    >>> 37
    Explanation:
    The metal garbage truck takes 7 minutes to pick up all the metal garbage.
    The paper garbage truck takes 15 minutes to pick up all the paper garbage.
    The glass garbage truck takes 15 minutes to pick up all the glass garbage.
    It takes a total of 7 + 15 + 15 = 37 minutes to collect all the garbage.
    """


Prompt:
def buildMatrix(k: int, rowConditions: List[List[int]], colConditions: List[List[int]]) -> List[List[int]]:
    """
    You are given a positive integer k. You are also given:

    a 2D integer array rowConditions of size n where rowConditions[i] = [abovei, belowi], and
    a 2D integer array colConditions of size m where colConditions[i] = [lefti, righti].

    The two arrays contain integers from 1 to k.
    You have to build a k x k matrix that contains each of the numbers from 1 to k exactly once. The remaining cells should have the value 0.
    The matrix should also satisfy the following conditions:

    The number abovei should appear in a row that is strictly above the row at which the number belowi appears for all i from 0 to n - 1.
    The number lefti should appear in a column that is strictly left of the column at which the number righti appears for all i from 0 to m - 1.

    Return any matrix that satisfies the conditions. If no answer exists, return an empty matrix.

    Example 1:

    >>> buildMatrix(k = 3, rowConditions = [[1,2],[3,2]], colConditions = [[2,1],[3,2]])
    >>> [[3,0,0],[0,0,1],[0,2,0]]
    Explanation: The diagram above shows a valid example of a matrix that satisfies all the conditions.
    The row conditions are the following:
    - Number 1 is in row 1, and number 2 is in row 2, so 1 is above 2 in the matrix.
    - Number 3 is in row 0, and number 2 is in row 2, so 3 is above 2 in the matrix.
    The column conditions are the following:
    - Number 2 is in column 1, and number 1 is in column 2, so 2 is left of 1 in the matrix.
    - Number 3 is in column 0, and number 2 is in column 1, so 3 is left of 2 in the matrix.
    Note that there may be multiple correct answers.

    Example 2:

    >>> buildMatrix(k = 3, rowConditions = [[1,2],[2,3],[3,1],[2,3]], colConditions = [[2,1]])
    >>> []
    Explanation: From the first two conditions, 3 has to be below 1 but the third conditions needs 3 to be above 1 to be satisfied.
    No matrix can satisfy all the conditions, so we return the empty matrix.
    """


Prompt:
def countSubarrays(nums: List[int]) -> int:
    """
    You are given an array nums consisting of positive integers.
    Return the number of subarrays of nums that are in strictly increasing order.
    A subarray is a contiguous part of an array.

    Example 1:

    >>> countSubarrays(nums = [1,3,5,4,4,6])
    >>> 10
    Explanation: The strictly increasing subarrays are the following:
    - Subarrays of length 1: [1], [3], [5], [4], [4], [6].
    - Subarrays of length 2: [1,3], [3,5], [4,6].
    - Subarrays of length 3: [1,3,5].
    The total number of subarrays is 6 + 3 + 1 = 10.

    Example 2:

    >>> countSubarrays(nums = [1,2,3,4,5])
    >>> 15
    Explanation: Every subarray is strictly increasing. There are 15 possible subarrays that we can take.
    """


Prompt:
def findSubarrays(nums: List[int]) -> bool:
    """
    Given a 0-indexed integer array nums, determine whether there exist two subarrays of length 2 with equal sum. Note that the two subarrays must begin at different indices.
    Return true if these subarrays exist, and false otherwise.
    A subarray is a contiguous non-empty sequence of elements within an array.

    Example 1:

    >>> findSubarrays(nums = [4,2,4])
    >>> true
    Explanation: The subarrays with elements [4,2] and [2,4] have the same sum of 6.

    Example 2:

    >>> findSubarrays(nums = [1,2,3,4,5])
    >>> false
    Explanation: No two subarrays of size 2 have the same sum.

    Example 3:

    >>> findSubarrays(nums = [0,0,0])
    >>> true
    Explanation: The subarrays [nums[0],nums[1]] and [nums[1],nums[2]] have the same sum of 0.
    Note that even though the subarrays have the same content, the two subarrays are considered different because they are in different positions in the original array.
    """


Prompt:
def isStrictlyPalindromic(n: int) -> bool:
    """
    An integer n is strictly palindromic if, for every base b between 2 and n - 2 (inclusive), the string representation of the integer n in base b is palindromic.
    Given an integer n, return true if n is strictly palindromic and false otherwise.
    A string is palindromic if it reads the same forward and backward.

    Example 1:

    >>> isStrictlyPalindromic(n = 9)
    >>> false
    Explanation: In base 2: 9 = 1001 (base 2), which is palindromic.
    In base 3: 9 = 100 (base 3), which is not palindromic.
    Therefore, 9 is not strictly palindromic so we return false.
    Note that in bases 4, 5, 6, and 7, n = 9 is also not palindromic.

    Example 2:

    >>> isStrictlyPalindromic(n = 4)
    >>> false
    Explanation: We only consider base 2: 4 = 100 (base 2), which is not palindromic.
    Therefore, we return false.
    """


Prompt:
def maximumRows(matrix: List[List[int]], numSelect: int) -> int:
    """
    You are given an m x n binary matrix matrix and an integer numSelect.
    Your goal is to select exactly numSelect distinct columns from matrix such that you cover as many rows as possible.
    A row is considered covered if all the 1's in that row are also part of a column that you have selected. If a row does not have any 1s, it is also considered covered.
    More formally, let us consider selected = {c1, c2, ...., cnumSelect} as the set of columns selected by you. A row i is covered by selected if:

    For each cell where matrix[i][j] == 1, the column j is in selected.
    Or, no cell in row i has a value of 1.

    Return the maximum number of rows that can be covered by a set of numSelect columns.

    Example 1:

    >>> maximumRows(matrix = [[0,0,0],[1,0,1],[0,1,1],[0,0,1]], numSelect = 2)
    >>> 3
    Explanation:
    One possible way to cover 3 rows is shown in the diagram above.
    We choose s = {0, 2}.
    - Row 0 is covered because it has no occurrences of 1.
    - Row 1 is covered because the columns with value 1, i.e. 0 and 2 are present in s.
    - Row 2 is not covered because matrix[2][1] == 1 but 1 is not present in s.
    - Row 3 is covered because matrix[2][2] == 1 and 2 is present in s.
    Thus, we can cover three rows.
    Note that s = {1, 2} will also cover 3 rows, but it can be shown that no more than three rows can be covered.

    Example 2:

    >>> maximumRows(matrix = [[1],[0]], numSelect = 1)
    >>> 2
    Explanation:
    Selecting the only column will result in both rows being covered since the entire matrix is selected.
    """


Prompt:
def maximumRobots(chargeTimes: List[int], runningCosts: List[int], budget: int) -> int:
    """
    You have n robots. You are given two 0-indexed integer arrays, chargeTimes and runningCosts, both of length n. The ith robot costs chargeTimes[i] units to charge and costs runningCosts[i] units to run. You are also given an integer budget.
    The total cost of running k chosen robots is equal to max(chargeTimes) + k * sum(runningCosts), where max(chargeTimes) is the largest charge cost among the k robots and sum(runningCosts) is the sum of running costs among the k robots.
    Return the maximum number of consecutive robots you can run such that the total cost does not exceed budget.

    Example 1:

    >>> maximumRobots(chargeTimes = [3,6,1,3,4], runningCosts = [2,1,3,4,5], budget = 25)
    >>> 3
    Explanation:
    It is possible to run all individual and consecutive pairs of robots within budget.
    To obtain answer 3, consider the first 3 robots. The total cost will be max(3,6,1) + 3 * sum(2,1,3) = 6 + 3 * 6 = 24 which is less than 25.
    It can be shown that it is not possible to run more than 3 consecutive robots within budget, so we return 3.

    Example 2:

    >>> maximumRobots(chargeTimes = [11,12,19], runningCosts = [10,8,7], budget = 19)
    >>> 0
    Explanation: No robot can be run that does not exceed the budget, so we return 0.
    """


Prompt:
def checkDistances(s: str, distance: List[int]) -> bool:
    """
    You are given a 0-indexed string s consisting of only lowercase English letters, where each letter in s appears exactly twice. You are also given a 0-indexed integer array distance of length 26.
    Each letter in the alphabet is numbered from 0 to 25 (i.e. 'a' -> 0, 'b' -> 1, 'c' -> 2, ... , 'z' -> 25).
    In a well-spaced string, the number of letters between the two occurrences of the ith letter is distance[i]. If the ith letter does not appear in s, then distance[i] can be ignored.
    Return true if s is a well-spaced string, otherwise return false.

    Example 1:

    >>> checkDistances(s = "abaccb", distance = [1,3,0,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0])
    >>> true
    Explanation:
    - 'a' appears at indices 0 and 2 so it satisfies distance[0] = 1.
    - 'b' appears at indices 1 and 5 so it satisfies distance[1] = 3.
    - 'c' appears at indices 3 and 4 so it satisfies distance[2] = 0.
    Note that distance[3] = 5, but since 'd' does not appear in s, it can be ignored.
    Return true because s is a well-spaced string.

    Example 2:

    >>> checkDistances(s = "aa", distance = [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0])
    >>> false
    Explanation:
    - 'a' appears at indices 0 and 1 so there are zero letters between them.
    Because distance[0] = 1, s is not a well-spaced string.
    """


Prompt:
def numberOfWays(startPos: int, endPos: int, k: int) -> int:
    """
    You are given two positive integers startPos and endPos. Initially, you are standing at position startPos on an infinite number line. With one step, you can move either one position to the left, or one position to the right.
    Given a positive integer k, return the number of different ways to reach the position endPos starting from startPos, such that you perform exactly k steps. Since the answer may be very large, return it modulo 109 + 7.
    Two ways are considered different if the order of the steps made is not exactly the same.
    Note that the number line includes negative integers.

    Example 1:

    >>> numberOfWays(startPos = 1, endPos = 2, k = 3)
    >>> 3
    Explanation: We can reach position 2 from 1 in exactly 3 steps in three ways:
    - 1 -> 2 -> 3 -> 2.
    - 1 -> 2 -> 1 -> 2.
    - 1 -> 0 -> 1 -> 2.
    It can be proven that no other way is possible, so we return 3.
    Example 2:

    >>> numberOfWays(startPos = 2, endPos = 5, k = 10)
    >>> 0
    Explanation: It is impossible to reach position 5 from position 2 in exactly 10 steps.
    """


Prompt:
def longestNiceSubarray(nums: List[int]) -> int:
    """
    You are given an array nums consisting of positive integers.
    We call a subarray of nums nice if the bitwise AND of every pair of elements that are in different positions in the subarray is equal to 0.
    Return the length of the longest nice subarray.
    A subarray is a contiguous part of an array.
    Note that subarrays of length 1 are always considered nice.

    Example 1:

    >>> longestNiceSubarray(nums = [1,3,8,48,10])
    >>> 3
    Explanation: The longest nice subarray is [3,8,48]. This subarray satisfies the conditions:
    - 3 AND 8 = 0.
    - 3 AND 48 = 0.
    - 8 AND 48 = 0.
    It can be proven that no longer nice subarray can be obtained, so we return 3.
    Example 2:

    >>> longestNiceSubarray(nums = [3,1,5,11,13])
    >>> 1
    Explanation: The length of the longest nice subarray is 1. Any subarray of length 1 can be chosen.
    """


Prompt:
def mostBooked(n: int, meetings: List[List[int]]) -> int:
    """
    You are given an integer n. There are n rooms numbered from 0 to n - 1.
    You are given a 2D integer array meetings where meetings[i] = [starti, endi] means that a meeting will be held during the half-closed time interval [starti, endi). All the values of starti are unique.
    Meetings are allocated to rooms in the following manner:

    Each meeting will take place in the unused room with the lowest number.
    If there are no available rooms, the meeting will be delayed until a room becomes free. The delayed meeting should have the same duration as the original meeting.
    When a room becomes unused, meetings that have an earlier original start time should be given the room.

    Return the number of the room that held the most meetings. If there are multiple rooms, return the room with the lowest number.
    A half-closed interval [a, b) is the interval between a and b including a and not including b.

    Example 1:

    >>> mostBooked(n = 2, meetings = [[0,10],[1,5],[2,7],[3,4]])
    >>> 0
    Explanation:
    - At time 0, both rooms are not being used. The first meeting starts in room 0.
    - At time 1, only room 1 is not being used. The second meeting starts in room 1.
    - At time 2, both rooms are being used. The third meeting is delayed.
    - At time 3, both rooms are being used. The fourth meeting is delayed.
    - At time 5, the meeting in room 1 finishes. The third meeting starts in room 1 for the time period [5,10).
    - At time 10, the meetings in both rooms finish. The fourth meeting starts in room 0 for the time period [10,11).
    Both rooms 0 and 1 held 2 meetings, so we return 0.

    Example 2:

    >>> mostBooked(n = 3, meetings = [[1,20],[2,10],[3,5],[4,9],[6,8]])
    >>> 1
    Explanation:
    - At time 1, all three rooms are not being used. The first meeting starts in room 0.
    - At time 2, rooms 1 and 2 are not being used. The second meeting starts in room 1.
    - At time 3, only room 2 is not being used. The third meeting starts in room 2.
    - At time 4, all three rooms are being used. The fourth meeting is delayed.
    - At time 5, the meeting in room 2 finishes. The fourth meeting starts in room 2 for the time period [5,10).
    - At time 6, all three rooms are being used. The fifth meeting is delayed.
    - At time 10, the meetings in rooms 1 and 2 finish. The fifth meeting starts in room 1 for the time period [10,12).
    Room 0 held 1 meeting while rooms 1 and 2 each held 2 meetings, so we return 1.
    """


Prompt:
def minimumTime(power: List[int]) -> int:
    """
    You are given an integer array power where power[i] is the power of the ith monster.
    You start with 0 mana points, and each day you increase your mana points by gain where gain initially is equal to 1.
    Each day, after gaining gain mana, you can defeat a monster if your mana points are greater than or equal to the power of that monster. When you defeat a monster:

    your mana points will be reset to 0, and
    the value of gain increases by 1.

    Return the minimum number of days needed to defeat all the monsters.

    Example 1:

    >>> minimumTime(power = [3,1,4])
    >>> 4
    Explanation: The optimal way to beat all the monsters is to:
    - Day 1: Gain 1 mana point to get a total of 1 mana point. Spend all mana points to kill the 2nd monster.
    - Day 2: Gain 2 mana points to get a total of 2 mana points.
    - Day 3: Gain 2 mana points to get a total of 4 mana points. Spend all mana points to kill the 3rd monster.
    - Day 4: Gain 3 mana points to get a total of 3 mana points. Spend all mana points to kill the 1st monster.
    It can be proven that 4 is the minimum number of days needed.

    Example 2:

    >>> minimumTime(power = [1,1,4])
    >>> 4
    Explanation: The optimal way to beat all the monsters is to:
    - Day 1: Gain 1 mana point to get a total of 1 mana point. Spend all mana points to kill the 1st monster.
    - Day 2: Gain 2 mana points to get a total of 2 mana points. Spend all mana points to kill the 2nd monster.
    - Day 3: Gain 3 mana points to get a total of 3 mana points.
    - Day 4: Gain 3 mana points to get a total of 6 mana points. Spend all mana points to kill the 3rd monster.
    It can be proven that 4 is the minimum number of days needed.

    Example 3:

    >>> minimumTime(power = [1,2,4,9])
    >>> 6
    Explanation: The optimal way to beat all the monsters is to:
    - Day 1: Gain 1 mana point to get a total of 1 mana point. Spend all mana points to kill the 1st monster.
    - Day 2: Gain 2 mana points to get a total of 2 mana points. Spend all mana points to kill the 2nd monster.
    - Day 3: Gain 3 mana points to get a total of 3 mana points.
    - Day 4: Gain 3 mana points to get a total of 6 mana points.
    - Day 5: Gain 3 mana points to get a total of 9 mana points. Spend all mana points to kill the 4th monster.
    - Day 6: Gain 4 mana points to get a total of 4 mana points. Spend all mana points to kill the 3rd monster.
    It can be proven that 6 is the minimum number of days needed.
    """


Prompt:
def mostFrequentEven(nums: List[int]) -> int:
    """
    Given an integer array nums, return the most frequent even element.
    If there is a tie, return the smallest one. If there is no such element, return -1.

    Example 1:

    >>> mostFrequentEven(nums = [0,1,2,2,4,4,1])
    >>> 2
    Explanation:
    The even elements are 0, 2, and 4. Of these, 2 and 4 appear the most.
    We return the smallest one, which is 2.
    Example 2:

    >>> mostFrequentEven(nums = [4,4,4,9,2,4])
    >>> 4
    Explanation: 4 is the even element appears the most.

    Example 3:

    >>> mostFrequentEven(nums = [29,47,21,41,13,37,25,7])
    >>> -1
    Explanation: There is no even element.
    """


Prompt:
def partitionString(s: str) -> int:
    """
    Given a string s, partition the string into one or more substrings such that the characters in each substring are unique. That is, no letter appears in a single substring more than once.
    Return the minimum number of substrings in such a partition.
    Note that each character should belong to exactly one substring in a partition.

    Example 1:

    >>> partitionString(s = "abacaba")
    >>> 4
    Explanation:
    Two possible partitions are ("a","ba","cab","a") and ("ab","a","ca","ba").
    It can be shown that 4 is the minimum number of substrings needed.

    Example 2:

    >>> partitionString(s = "ssssss")
    >>> 6
    Explanation:
    The only valid partition is ("s","s","s","s","s","s").
    """


Prompt:
def minGroups(intervals: List[List[int]]) -> int:
    """
    You are given a 2D integer array intervals where intervals[i] = [lefti, righti] represents the inclusive interval [lefti, righti].
    You have to divide the intervals into one or more groups such that each interval is in exactly one group, and no two intervals that are in the same group intersect each other.
    Return the minimum number of groups you need to make.
    Two intervals intersect if there is at least one common number between them. For example, the intervals [1, 5] and [5, 8] intersect.

    Example 1:

    >>> minGroups(intervals = [[5,10],[6,8],[1,5],[2,3],[1,10]])
    >>> 3
    Explanation: We can divide the intervals into the following groups:
    - Group 1: [1, 5], [6, 8].
    - Group 2: [2, 3], [5, 10].
    - Group 3: [1, 10].
    It can be proven that it is not possible to divide the intervals into fewer than 3 groups.

    Example 2:

    >>> minGroups(intervals = [[1,3],[5,6],[8,10],[11,13]])
    >>> 1
    Explanation: None of the intervals overlap, so we can put all of them in one group.
    """


Prompt:
def lengthOfLIS(nums: List[int], k: int) -> int:
    """
    You are given an integer array nums and an integer k.
    Find the longest subsequence of nums that meets the following requirements:

    The subsequence is strictly increasing and
    The difference between adjacent elements in the subsequence is at most k.

    Return the length of the longest subsequence that meets the requirements.
    A subsequence is an array that can be derived from another array by deleting some or no elements without changing the order of the remaining elements.

    Example 1:

    >>> lengthOfLIS(nums = [4,2,1,4,3,4,5,8,15], k = 3)
    >>> 5
    Explanation:
    The longest subsequence that meets the requirements is [1,3,4,5,8].
    The subsequence has a length of 5, so we return 5.
    Note that the subsequence [1,3,4,5,8,15] does not meet the requirements because 15 - 8 = 7 is larger than 3.

    Example 2:

    >>> lengthOfLIS(nums = [7,4,5,1,8,12,4,7], k = 5)
    >>> 4
    Explanation:
    The longest subsequence that meets the requirements is [4,5,8,12].
    The subsequence has a length of 4, so we return 4.

    Example 3:

    >>> lengthOfLIS(nums = [1,5], k = 1)
    >>> 1
    Explanation:
    The longest subsequence that meets the requirements is [1].
    The subsequence has a length of 1, so we return 1.
    """


Prompt:
def countDaysTogether(arriveAlice: str, leaveAlice: str, arriveBob: str, leaveBob: str) -> int:
    """
    Alice and Bob are traveling to Rome for separate business meetings.
    You are given 4 strings arriveAlice, leaveAlice, arriveBob, and leaveBob. Alice will be in the city from the dates arriveAlice to leaveAlice (inclusive), while Bob will be in the city from the dates arriveBob to leaveBob (inclusive). Each will be a 5-character string in the format "MM-DD", corresponding to the month and day of the date.
    Return the total number of days that Alice and Bob are in Rome together.
    You can assume that all dates occur in the same calendar year, which is not a leap year. Note that the number of days per month can be represented as: [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31].

    Example 1:

    >>> countDaysTogether(arriveAlice = "08-15", leaveAlice = "08-18", arriveBob = "08-16", leaveBob = "08-19")
    >>> 3
    Explanation: Alice will be in Rome from August 15 to August 18. Bob will be in Rome from August 16 to August 19. They are both in Rome together on August 16th, 17th, and 18th, so the answer is 3.

    Example 2:

    >>> countDaysTogether(arriveAlice = "10-01", leaveAlice = "10-31", arriveBob = "11-01", leaveBob = "12-31")
    >>> 0
    Explanation: There is no day when Alice and Bob are in Rome together, so we return 0.
    """


Prompt:
def matchPlayersAndTrainers(players: List[int], trainers: List[int]) -> int:
    """
    You are given a 0-indexed integer array players, where players[i] represents the ability of the ith player. You are also given a 0-indexed integer array trainers, where trainers[j] represents the training capacity of the jth trainer.
    The ith player can match with the jth trainer if the player's ability is less than or equal to the trainer's training capacity. Additionally, the ith player can be matched with at most one trainer, and the jth trainer can be matched with at most one player.
    Return the maximum number of matchings between players and trainers that satisfy these conditions.

    Example 1:

    >>> matchPlayersAndTrainers(players = [4,7,9], trainers = [8,2,5,8])
    >>> 2
    Explanation:
    One of the ways we can form two matchings is as follows:
    - players[0] can be matched with trainers[0] since 4 <= 8.
    - players[1] can be matched with trainers[3] since 7 <= 8.
    It can be proven that 2 is the maximum number of matchings that can be formed.

    Example 2:

    >>> matchPlayersAndTrainers(players = [1,1,1], trainers = [10])
    >>> 1
    Explanation:
    The trainer can be matched with any of the 3 players.
    Each player can only be matched with one trainer, so the maximum answer is 1.
    """


Prompt:
def smallestSubarrays(nums: List[int]) -> List[int]:
    """
    You are given a 0-indexed array nums of length n, consisting of non-negative integers. For each index i from 0 to n - 1, you must determine the size of the minimum sized non-empty subarray of nums starting at i (inclusive) that has the maximum possible bitwise OR.

    In other words, let Bij be the bitwise OR of the subarray nums[i...j]. You need to find the smallest subarray starting at i, such that bitwise OR of this subarray is equal to max(Bik) where i <= k <= n - 1.

    The bitwise OR of an array is the bitwise OR of all the numbers in it.
    Return an integer array answer of size n where answer[i] is the length of the minimum sized subarray starting at i with maximum bitwise OR.
    A subarray is a contiguous non-empty sequence of elements within an array.

    Example 1:

    >>> smallestSubarrays(nums = [1,0,2,1,3])
    >>> [3,3,2,2,1]
    Explanation:
    The maximum possible bitwise OR starting at any index is 3.
    - Starting at index 0, the shortest subarray that yields it is [1,0,2].
    - Starting at index 1, the shortest subarray that yields the maximum bitwise OR is [0,2,1].
    - Starting at index 2, the shortest subarray that yields the maximum bitwise OR is [2,1].
    - Starting at index 3, the shortest subarray that yields the maximum bitwise OR is [1,3].
    - Starting at index 4, the shortest subarray that yields the maximum bitwise OR is [3].
    Therefore, we return [3,3,2,2,1].

    Example 2:

    >>> smallestSubarrays(nums = [1,2])
    >>> [2,1]
    Explanation:
    Starting at index 0, the shortest subarray that yields the maximum bitwise OR is of length 2.
    Starting at index 1, the shortest subarray that yields the maximum bitwise OR is of length 1.
    Therefore, we return [2,1].
    """


Prompt:
def minimumMoney(transactions: List[List[int]]) -> int:
    """
    You are given a 0-indexed 2D integer array transactions, where transactions[i] = [costi, cashbacki].
    The array describes transactions, where each transaction must be completed exactly once in some order. At any given moment, you have a certain amount of money. In order to complete transaction i, money >= costi must hold true. After performing a transaction, money becomes money - costi + cashbacki.
    Return the minimum amount of money required before any transaction so that all of the transactions can be completed regardless of the order of the transactions.

    Example 1:

    >>> minimumMoney(transactions = [[2,1],[5,0],[4,2]])
    >>> 10
    Explanation:
    Starting with money = 10, the transactions can be performed in any order.
    It can be shown that starting with money < 10 will fail to complete all transactions in some order.

    Example 2:

    >>> minimumMoney(transactions = [[3,0],[0,3]])
    >>> 3
    Explanation:
    - If transactions are in the order [[3,0],[0,3]], the minimum money required to complete the transactions is 3.
    - If transactions are in the order [[0,3],[3,0]], the minimum money required to complete the transactions is 0.
    Thus, starting with money = 3, the transactions can be performed in any order.
    """


Prompt:
def smallestEvenMultiple(n: int) -> int:
    """
    Given a positive integer n, return the smallest positive integer that is a multiple of both 2 and n.

    Example 1:

    >>> smallestEvenMultiple(n = 5)
    >>> 10
    Explanation: The smallest multiple of both 5 and 2 is 10.

    Example 2:

    >>> smallestEvenMultiple(n = 6)
    >>> 6
    Explanation: The smallest multiple of both 6 and 2 is 6. Note that a number is a multiple of itself.
    """


Prompt:
def longestContinuousSubstring(s: str) -> int:
    """
    An alphabetical continuous string is a string consisting of consecutive letters in the alphabet. In other words, it is any substring of the string "abcdefghijklmnopqrstuvwxyz".

    For example, "abc" is an alphabetical continuous string, while "acb" and "za" are not.

    Given a string s consisting of lowercase letters only, return the length of the longest alphabetical continuous substring.

    Example 1:

    >>> longestContinuousSubstring(s = "abacaba")
    >>> 2
    Explanation: There are 4 distinct continuous substrings: "a", "b", "c" and "ab".
    "ab" is the longest continuous substring.

    Example 2:

    >>> longestContinuousSubstring(s = "abcde")
    >>> 5
    Explanation: "abcde" is the longest continuous substring.
    """


Prompt:
# class TreeNode:
#     def __init__(val=0, left=None, right=None):
#         self.val = val
#         self.left = left
#         self.right = right
class Solution:
    def reverseOddLevels(root: Optional[TreeNode]) -> Optional[TreeNode]:
    """
    Given the root of a perfect binary tree, reverse the node values at each odd level of the tree.

    For example, suppose the node values at level 3 are [2,1,3,4,7,11,29,18], then it should become [18,29,11,7,4,3,1,2].

    Return the root of the reversed tree.
    A binary tree is perfect if all parent nodes have two children and all leaves are on the same level.
    The level of a node is the number of edges along the path between it and the root node.

    Example 1:

    >>> __init__(root = [2,3,5,8,13,21,34])
    >>> [2,5,3,8,13,21,34]
    Explanation:
    The tree has only one odd level.
    The nodes at level 1 are 3, 5 respectively, which are reversed and become 5, 3.

    Example 2:

    >>> __init__(root = [7,13,11])
    >>> [7,11,13]
    Explanation:
    The nodes at level 1 are 13, 11, which are reversed and become 11, 13.

    Example 3:

    >>> __init__(root = [0,1,2,0,0,0,0,1,1,1,1,2,2,2,2])
    >>> [0,2,1,0,0,0,0,2,2,2,2,1,1,1,1]
    Explanation:
    The odd levels have non-zero values.
    The nodes at level 1 were 1, 2, and are 2, 1 after the reversal.
    The nodes at level 3 were 1, 1, 1, 1, 2, 2, 2, 2, and are 2, 2, 2, 2, 1, 1, 1, 1 after the reversal.
    """


Prompt:
def sumPrefixScores(words: List[str]) -> List[int]:
    """
    You are given an array words of size n consisting of non-empty strings.
    We define the score of a string term as the number of strings words[i] such that term is a prefix of words[i].

    For example, if words = ["a", "ab", "abc", "cab"], then the score of "ab" is 2, since "ab" is a prefix of both "ab" and "abc".

    Return an array answer of size n where answer[i] is the sum of scores of every non-empty prefix of words[i].
    Note that a string is considered as a prefix of itself.

    Example 1:

    >>> sumPrefixScores(words = ["abc","ab","bc","b"])
    >>> [5,4,3,2]
    Explanation: The answer for each string is the following:
    - "abc" has 3 prefixes: "a", "ab", and "abc".
    - There are 2 strings with the prefix "a", 2 strings with the prefix "ab", and 1 string with the prefix "abc".
    The total is answer[0] = 2 + 2 + 1 = 5.
    - "ab" has 2 prefixes: "a" and "ab".
    - There are 2 strings with the prefix "a", and 2 strings with the prefix "ab".
    The total is answer[1] = 2 + 2 = 4.
    - "bc" has 2 prefixes: "b" and "bc".
    - There are 2 strings with the prefix "b", and 1 string with the prefix "bc".
    The total is answer[2] = 2 + 1 = 3.
    - "b" has 1 prefix: "b".
    - There are 2 strings with the prefix "b".
    The total is answer[3] = 2.

    Example 2:

    >>> sumPrefixScores(words = ["abcd"])
    >>> [4]
    Explanation:
    "abcd" has 4 prefixes: "a", "ab", "abc", and "abcd".
    Each prefix has a score of one, so the total is answer[0] = 1 + 1 + 1 + 1 = 4.
    """


Prompt:
def closestFair(n: int) -> int:
    """
    You are given a positive integer n.
    We call an integer k fair if the number of even digits in k is equal to the number of odd digits in it.
    Return the smallest fair integer that is greater than or equal to n.

    Example 1:

    >>> closestFair(n = 2)
    >>> 10
    Explanation: The smallest fair integer that is greater than or equal to 2 is 10.
    10 is fair because it has an equal number of even and odd digits (one odd digit and one even digit).
    Example 2:

    >>> closestFair(n = 403)
    >>> 1001
    Explanation: The smallest fair integer that is greater than or equal to 403 is 1001.
    1001 is fair because it has an equal number of even and odd digits (two odd digits and two even digits).
    """


Prompt:
def sortPeople(names: List[str], heights: List[int]) -> List[str]:
    """
    You are given an array of strings names, and an array heights that consists of distinct positive integers. Both arrays are of length n.
    For each index i, names[i] and heights[i] denote the name and height of the ith person.
    Return names sorted in descending order by the people's heights.

    Example 1:

    >>> sortPeople(names = ["Mary","John","Emma"], heights = [180,165,170])
    >>> ["Mary","Emma","John"]
    Explanation: Mary is the tallest, followed by Emma and John.

    Example 2:

    >>> sortPeople(names = ["Alice","Bob","Bob"], heights = [155,185,150])
    >>> ["Bob","Alice","Bob"]
    Explanation: The first Bob is the tallest, followed by Alice and the second Bob.
    """


Prompt:
def longestSubarray(nums: List[int]) -> int:
    """
    You are given an integer array nums of size n.
    Consider a non-empty subarray from nums that has the maximum possible bitwise AND.

    In other words, let k be the maximum value of the bitwise AND of any subarray of nums. Then, only subarrays with a bitwise AND equal to k should be considered.

    Return the length of the longest such subarray.
    The bitwise AND of an array is the bitwise AND of all the numbers in it.
    A subarray is a contiguous sequence of elements within an array.

    Example 1:

    >>> longestSubarray(nums = [1,2,3,3,2,2])
    >>> 2
    Explanation:
    The maximum possible bitwise AND of a subarray is 3.
    The longest subarray with that value is [3,3], so we return 2.

    Example 2:

    >>> longestSubarray(nums = [1,2,3,4])
    >>> 1
    Explanation:
    The maximum possible bitwise AND of a subarray is 4.
    The longest subarray with that value is [4], so we return 1.
    """


Prompt:
def goodIndices(nums: List[int], k: int) -> List[int]:
    """
    You are given a 0-indexed integer array nums of size n and a positive integer k.
    We call an index i in the range k <= i < n - k good if the following conditions are satisfied:

    The k elements that are just before the index i are in non-increasing order.
    The k elements that are just after the index i are in non-decreasing order.

    Return an array of all good indices sorted in increasing order.

    Example 1:

    >>> goodIndices(nums = [2,1,1,1,3,4,1], k = 2)
    >>> [2,3]
    Explanation: There are two good indices in the array:
    - Index 2. The subarray [2,1] is in non-increasing order, and the subarray [1,3] is in non-decreasing order.
    - Index 3. The subarray [1,1] is in non-increasing order, and the subarray [3,4] is in non-decreasing order.
    Note that the index 4 is not good because [4,1] is not non-decreasing.
    Example 2:

    >>> goodIndices(nums = [2,1,1,2], k = 2)
    >>> []
    Explanation: There are no good indices in this array.
    """


Prompt:
def numberOfGoodPaths(vals: List[int], edges: List[List[int]]) -> int:
    """
    There is a tree (i.e. a connected, undirected graph with no cycles) consisting of n nodes numbered from 0 to n - 1 and exactly n - 1 edges.
    You are given a 0-indexed integer array vals of length n where vals[i] denotes the value of the ith node. You are also given a 2D integer array edges where edges[i] = [ai, bi] denotes that there exists an undirected edge connecting nodes ai and bi.
    A good path is a simple path that satisfies the following conditions:

    The starting node and the ending node have the same value.
    All nodes between the starting node and the ending node have values less than or equal to the starting node (i.e. the starting node's value should be the maximum value along the path).

    Return the number of distinct good paths.
    Note that a path and its reverse are counted as the same path. For example, 0 -> 1 is considered to be the same as 1 -> 0. A single node is also considered as a valid path.

    Example 1:

    >>> numberOfGoodPaths(vals = [1,3,2,1,3], edges = [[0,1],[0,2],[2,3],[2,4]])
    >>> 6
    Explanation: There are 5 good paths consisting of a single node.
    There is 1 additional good path: 1 -> 0 -> 2 -> 4.
    (The reverse path 4 -> 2 -> 0 -> 1 is treated as the same as 1 -> 0 -> 2 -> 4.)
    Note that 0 -> 2 -> 3 is not a good path because vals[2] > vals[0].

    Example 2:

    >>> numberOfGoodPaths(vals = [1,1,2,2,3], edges = [[0,1],[1,2],[2,3],[2,4]])
    >>> 7
    Explanation: There are 5 good paths consisting of a single node.
    There are 2 additional good paths: 0 -> 1 and 2 -> 3.

    Example 3:

    >>> numberOfGoodPaths(vals = [1], edges = [])
    >>> 1
    Explanation: The tree consists of only one node, so there is one good path.
    """


Prompt:
def minimumOperations(nums: List[int]) -> int:
    """
    You are given an array nums consisting of positive integers.
    You can perform the following operation on the array any number of times:

    Choose any two adjacent elements and replace them with their sum.

    For example, if nums = [1,2,3,1], you can apply one operation to make it [1,5,1].

    Return the minimum number of operations needed to turn the array into a palindrome.

    Example 1:

    >>> minimumOperations(nums = [4,3,2,1,2,3,1])
    >>> 2
    Explanation: We can turn the array into a palindrome in 2 operations as follows:
    - Apply the operation on the fourth and fifth element of the array, nums becomes equal to [4,3,2,3,3,1].
    - Apply the operation on the fifth and sixth element of the array, nums becomes equal to [4,3,2,3,4].
    The array [4,3,2,3,4] is a palindrome.
    It can be shown that 2 is the minimum number of operations needed.

    Example 2:

    >>> minimumOperations(nums = [1,2,3,4])
    >>> 3
    Explanation: We do the operation 3 times in any position, we obtain the array [10] at the end which is a palindrome.
    """


Prompt:
def equalFrequency(word: str) -> bool:
    """
    You are given a 0-indexed string word, consisting of lowercase English letters. You need to select one index and remove the letter at that index from word so that the frequency of every letter present in word is equal.
    Return true if it is possible to remove one letter so that the frequency of all letters in word are equal, and false otherwise.
    Note:

    The frequency of a letter x is the number of times it occurs in the string.
    You must remove exactly one letter and cannot choose to do nothing.

    Example 1:

    >>> equalFrequency(word = "abcc")
    >>> true
    Explanation: Select index 3 and delete it: word becomes "abc" and each character has a frequency of 1.

    Example 2:

    >>> equalFrequency(word = "aazz")
    >>> false
    Explanation: We must delete a character, so either the frequency of "a" is 1 and the frequency of "z" is 2, or vice versa. It is impossible to make all present letters have equal frequency.
    """


Prompt:
def xorAllNums(nums1: List[int], nums2: List[int]) -> int:
    """
    You are given two 0-indexed arrays, nums1 and nums2, consisting of non-negative integers. Let there be another array, nums3, which contains the bitwise XOR of all pairings of integers between nums1 and nums2 (every integer in nums1 is paired with every integer in nums2 exactly once).
    Return the bitwise XOR of all integers in nums3.

    Example 1:

    >>> xorAllNums(nums1 = [2,1,3], nums2 = [10,2,5,0])
    >>> 13
    Explanation:
    A possible nums3 array is [8,0,7,2,11,3,4,1,9,1,6,3].
    The bitwise XOR of all these numbers is 13, so we return 13.

    Example 2:

    >>> xorAllNums(nums1 = [1,2], nums2 = [3,4])
    >>> 0
    Explanation:
    All possible pairs of bitwise XORs are nums1[0] ^ nums2[0], nums1[0] ^ nums2[1], nums1[1] ^ nums2[0],
    and nums1[1] ^ nums2[1].
    Thus, one possible nums3 array is [2,5,1,6].
    2 ^ 5 ^ 1 ^ 6 = 0, so we return 0.
    """


Prompt:
def numberOfPairs(nums1: List[int], nums2: List[int], diff: int) -> int:
    """
    You are given two 0-indexed integer arrays nums1 and nums2, each of size n, and an integer diff. Find the number of pairs (i, j) such that:

    0 <= i < j <= n - 1 and
    nums1[i] - nums1[j] <= nums2[i] - nums2[j] + diff.

    Return the number of pairs that satisfy the conditions.

    Example 1:

    >>> numberOfPairs(nums1 = [3,2,5], nums2 = [2,2,1], diff = 1)
    >>> 3
    Explanation:
    There are 3 pairs that satisfy the conditions:
    1. i = 0, j = 1: 3 - 2 <= 2 - 2 + 1. Since i < j and 1 <= 1, this pair satisfies the conditions.
    2. i = 0, j = 2: 3 - 5 <= 2 - 1 + 1. Since i < j and -2 <= 2, this pair satisfies the conditions.
    3. i = 1, j = 2: 2 - 5 <= 2 - 1 + 1. Since i < j and -3 <= 2, this pair satisfies the conditions.
    Therefore, we return 3.

    Example 2:

    >>> numberOfPairs(nums1 = [3,-1], nums2 = [-2,2], diff = -1)
    >>> 0
    Explanation:
    Since there does not exist any pair that satisfies the conditions, we return 0.
    """


Prompt:
def commonFactors(a: int, b: int) -> int:
    """
    Given two positive integers a and b, return the number of common factors of a and b.
    An integer x is a common factor of a and b if x divides both a and b.

    Example 1:

    >>> commonFactors(a = 12, b = 6)
    >>> 4
    Explanation: The common factors of 12 and 6 are 1, 2, 3, 6.

    Example 2:

    >>> commonFactors(a = 25, b = 30)
    >>> 2
    Explanation: The common factors of 25 and 30 are 1, 5.
    """


Prompt:
def maxSum(grid: List[List[int]]) -> int:
    """
    You are given an m x n integer matrix grid.
    We define an hourglass as a part of the matrix with the following form:

    Return the maximum sum of the elements of an hourglass.
    Note that an hourglass cannot be rotated and must be entirely contained within the matrix.

    Example 1:

    >>> maxSum(grid = [[6,2,1,3],[4,2,1,5],[9,2,8,7],[4,1,2,9]])
    >>> 30
    Explanation: The cells shown above represent the hourglass with the maximum sum: 6 + 2 + 1 + 2 + 9 + 2 + 8 = 30.

    Example 2:

    >>> maxSum(grid = [[1,2,3],[4,5,6],[7,8,9]])
    >>> 35
    Explanation: There is only one hourglass in the matrix, with the sum: 1 + 2 + 3 + 5 + 7 + 8 + 9 = 35.
    """


Prompt:
def minimizeXor(num1: int, num2: int) -> int:
    """
    Given two positive integers num1 and num2, find the positive integer x such that:

    x has the same number of set bits as num2, and
    The value x XOR num1 is minimal.

    Note that XOR is the bitwise XOR operation.
    Return the integer x. The test cases are generated such that x is uniquely determined.
    The number of set bits of an integer is the number of 1's in its binary representation.

    Example 1:

    >>> minimizeXor(num1 = 3, num2 = 5)
    >>> 3
    Explanation:
    The binary representations of num1 and num2 are 0011 and 0101, respectively.
    The integer 3 has the same number of set bits as num2, and the value 3 XOR 3 = 0 is minimal.

    Example 2:

    >>> minimizeXor(num1 = 1, num2 = 12)
    >>> 3
    Explanation:
    The binary representations of num1 and num2 are 0001 and 1100, respectively.
    The integer 3 has the same number of set bits as num2, and the value 3 XOR 1 = 2 is minimal.
    """


Prompt:
def deleteString(s: str) -> int:
    """
    You are given a string s consisting of only lowercase English letters. In one operation, you can:

    Delete the entire string s, or
    Delete the first i letters of s if the first i letters of s are equal to the following i letters in s, for any i in the range 1 <= i <= s.length / 2.

    For example, if s = "ababc", then in one operation, you could delete the first two letters of s to get "abc", since the first two letters of s and the following two letters of s are both equal to "ab".
    Return the maximum number of operations needed to delete all of s.

    Example 1:

    >>> deleteString(s = "abcabcdabc")
    >>> 2
    Explanation:
    - Delete the first 3 letters ("abc") since the next 3 letters are equal. Now, s = "abcdabc".
    - Delete all the letters.
    We used 2 operations so return 2. It can be proven that 2 is the maximum number of operations needed.
    Note that in the second operation we cannot delete "abc" again because the next occurrence of "abc" does not happen in the next 3 letters.

    Example 2:

    >>> deleteString(s = "aaabaab")
    >>> 4
    Explanation:
    - Delete the first letter ("a") since the next letter is equal. Now, s = "aabaab".
    - Delete the first 3 letters ("aab") since the next 3 letters are equal. Now, s = "aab".
    - Delete the first letter ("a") since the next letter is equal. Now, s = "ab".
    - Delete all the letters.
    We used 4 operations so return 4. It can be proven that 4 is the maximum number of operations needed.

    Example 3:

    >>> deleteString(s = "aaaaa")
    >>> 5
    Explanation: In each operation, we can delete the first letter of s.
    """


Prompt:
def maxTastiness(price: List[int], tastiness: List[int], maxAmount: int, maxCoupons: int) -> int:
    """
    You are given two non-negative integer arrays price and tastiness, both arrays have the same length n. You are also given two non-negative integers maxAmount and maxCoupons.
    For every integer i in range [0, n - 1]:

    price[i] describes the price of ith fruit.
    tastiness[i] describes the tastiness of ith fruit.

    You want to purchase some fruits such that total tastiness is maximized and the total price does not exceed maxAmount.
    Additionally, you can use a coupon to purchase fruit for half of its price (rounded down to the closest integer). You can use at most maxCoupons of such coupons.
    Return the maximum total tastiness that can be purchased.
    Note that:

    You can purchase each fruit at most once.
    You can use coupons on some fruit at most once.

    Example 1:

    >>> maxTastiness(price = [10,20,20], tastiness = [5,8,8], maxAmount = 20, maxCoupons = 1)
    >>> 13
    Explanation: It is possible to make total tastiness 13 in following way:
    - Buy first fruit without coupon, so that total price = 0 + 10 and total tastiness = 0 + 5.
    - Buy second fruit with coupon, so that total price = 10 + 10 and total tastiness = 5 + 8.
    - Do not buy third fruit, so that total price = 20 and total tastiness = 13.
    It can be proven that 13 is the maximum total tastiness that can be obtained.

    Example 2:

    >>> maxTastiness(price = [10,15,7], tastiness = [5,8,20], maxAmount = 10, maxCoupons = 2)
    >>> 28
    Explanation: It is possible to make total tastiness 20 in following way:
    - Do not buy first fruit, so that total price = 0 and total tastiness = 0.
    - Buy second fruit with coupon, so that total price = 0 + 7 and total tastiness = 0 + 8.
    - Buy third fruit with coupon, so that total price = 7 + 3 and total tastiness = 8 + 20.
    It can be proven that 28 is the maximum total tastiness that can be obtained.
    """


Prompt:
def hardestWorker(n: int, logs: List[List[int]]) -> int:
    """
    There are n employees, each with a unique id from 0 to n - 1.
    You are given a 2D integer array logs where logs[i] = [idi, leaveTimei] where:

    idi is the id of the employee that worked on the ith task, and
    leaveTimei is the time at which the employee finished the ith task. All the values leaveTimei are unique.

    Note that the ith task starts the moment right after the (i - 1)th task ends, and the 0th task starts at time 0.
    Return the id of the employee that worked the task with the longest time. If there is a tie between two or more employees, return the smallest id among them.

    Example 1:

    >>> hardestWorker(n = 10, logs = [[0,3],[2,5],[0,9],[1,15]])
    >>> 1
    Explanation:
    Task 0 started at 0 and ended at 3 with 3 units of times.
    Task 1 started at 3 and ended at 5 with 2 units of times.
    Task 2 started at 5 and ended at 9 with 4 units of times.
    Task 3 started at 9 and ended at 15 with 6 units of times.
    The task with the longest time is task 3 and the employee with id 1 is the one that worked on it, so we return 1.

    Example 2:

    >>> hardestWorker(n = 26, logs = [[1,1],[3,7],[2,12],[7,17]])
    >>> 3
    Explanation:
    Task 0 started at 0 and ended at 1 with 1 unit of times.
    Task 1 started at 1 and ended at 7 with 6 units of times.
    Task 2 started at 7 and ended at 12 with 5 units of times.
    Task 3 started at 12 and ended at 17 with 5 units of times.
    The tasks with the longest time is task 1. The employee that worked on it is 3, so we return 3.

    Example 3:

    >>> hardestWorker(n = 2, logs = [[0,10],[1,20]])
    >>> 0
    Explanation:
    Task 0 started at 0 and ended at 10 with 10 units of times.
    Task 1 started at 10 and ended at 20 with 10 units of times.
    The tasks with the longest time are tasks 0 and 1. The employees that worked on them are 0 and 1, so we return the smallest id 0.
    """


Prompt:
def findArray(pref: List[int]) -> List[int]:
    """
    You are given an integer array pref of size n. Find and return the array arr of size n that satisfies:

    pref[i] = arr[0] ^ arr[1] ^ ... ^ arr[i].

    Note that ^ denotes the bitwise-xor operation.
    It can be proven that the answer is unique.

    Example 1:

    >>> findArray(pref = [5,2,0,3,1])
    >>> [5,7,2,3,2]
    Explanation: From the array [5,7,2,3,2] we have the following:
    - pref[0] = 5.
    - pref[1] = 5 ^ 7 = 2.
    - pref[2] = 5 ^ 7 ^ 2 = 0.
    - pref[3] = 5 ^ 7 ^ 2 ^ 3 = 3.
    - pref[4] = 5 ^ 7 ^ 2 ^ 3 ^ 2 = 1.

    Example 2:

    >>> findArray(pref = [13])
    >>> [13]
    Explanation: We have pref[0] = arr[0] = 13.
    """


Prompt:
def robotWithString(s: str) -> str:
    """
    You are given a string s and a robot that currently holds an empty string t. Apply one of the following operations until s and t are both empty:

    Remove the first character of a string s and give it to the robot. The robot will append this character to the string t.
    Remove the last character of a string t and give it to the robot. The robot will write this character on paper.

    Return the lexicographically smallest string that can be written on the paper.

    Example 1:

    >>> robotWithString(s = "zza")
    >>> "azz"
    Explanation: Let p denote the written string.
    Initially p="", s="zza", t="".
    Perform first operation three times p="", s="", t="zza".
    Perform second operation three times p="azz", s="", t="".

    Example 2:

    >>> robotWithString(s = "bac")
    >>> "abc"
    Explanation: Let p denote the written string.
    Perform first operation twice p="", s="c", t="ba".
    Perform second operation twice p="ab", s="c", t="".
    Perform first operation p="ab", s="", t="c".
    Perform second operation p="abc", s="", t="".

    Example 3:

    >>> robotWithString(s = "bdda")
    >>> "addb"
    Explanation: Let p denote the written string.
    Initially p="", s="bdda", t="".
    Perform first operation four times p="", s="", t="bdda".
    Perform second operation four times p="addb", s="", t="".
    """


Prompt:
def numberOfPaths(grid: List[List[int]], k: int) -> int:
    """
    You are given a 0-indexed m x n integer matrix grid and an integer k. You are currently at position (0, 0) and you want to reach position (m - 1, n - 1) moving only down or right.
    Return the number of paths where the sum of the elements on the path is divisible by k. Since the answer may be very large, return it modulo 109 + 7.

    Example 1:

    >>> numberOfPaths(grid = [[5,2,4],[3,0,5],[0,7,2]], k = 3)
    >>> 2
    Explanation: There are two paths where the sum of the elements on the path is divisible by k.
    The first path highlighted in red has a sum of 5 + 2 + 4 + 5 + 2 = 18 which is divisible by 3.
    The second path highlighted in blue has a sum of 5 + 3 + 0 + 5 + 2 = 15 which is divisible by 3.

    Example 2:

    >>> numberOfPaths(grid = [[0,0]], k = 5)
    >>> 1
    Explanation: The path highlighted in red has a sum of 0 + 0 = 0 which is divisible by 5.

    Example 3:

    >>> numberOfPaths(grid = [[7,3,4,9],[2,3,6,2],[2,3,7,0]], k = 1)
    >>> 10
    Explanation: Every integer is divisible by 1 so the sum of the elements on every possible path is divisible by k.
    """


Prompt:
def minimumSplits(nums: List[int]) -> int:
    """
    You are given an array nums consisting of positive integers.
    Split the array into one or more disjoint subarrays such that:

    Each element of the array belongs to exactly one subarray, and
    The GCD of the elements of each subarray is strictly greater than 1.

    Return the minimum number of subarrays that can be obtained after the split.
    Note that:

    The GCD of a subarray is the largest positive integer that evenly divides all the elements of the subarray.
    A subarray is a contiguous part of the array.

    Example 1:

    >>> minimumSplits(nums = [12,6,3,14,8])
    >>> 2
    Explanation: We can split the array into the subarrays: [12,6,3] and [14,8].
    - The GCD of 12, 6 and 3 is 3, which is strictly greater than 1.
    - The GCD of 14 and 8 is 2, which is strictly greater than 1.
    It can be shown that splitting the array into one subarray will make the GCD = 1.

    Example 2:

    >>> minimumSplits(nums = [4,12,6,14])
    >>> 1
    Explanation: We can split the array into only one subarray, which is the whole array.
    """


Prompt:
def countTime(time: str) -> int:
    """
    You are given a string of length 5 called time, representing the current time on a digital clock in the format "hh:mm". The earliest possible time is "00:00" and the latest possible time is "23:59".
    In the string time, the digits represented by the ? symbol are unknown, and must be replaced with a digit from 0 to 9.
    Return an integer answer, the number of valid clock times that can be created by replacing every ? with a digit from 0 to 9.

    Example 1:

    >>> countTime(time = "?5:00")
    >>> 2
    Explanation: We can replace the ? with either a 0 or 1, producing "05:00" or "15:00". Note that we cannot replace it with a 2, since the time "25:00" is invalid. In total, we have two choices.

    Example 2:

    >>> countTime(time = "0?:0?")
    >>> 100
    Explanation: Each ? can be replaced by any digit from 0 to 9, so we have 100 total choices.

    Example 3:

    >>> countTime(time = "??:??")
    >>> 1440
    Explanation: There are 24 possible choices for the hours, and 60 possible choices for the minutes. In total, we have 24 * 60 = 1440 choices.
    """


Prompt:
def productQueries(n: int, queries: List[List[int]]) -> List[int]:
    """
    Given a positive integer n, there exists a 0-indexed array called powers, composed of the minimum number of powers of 2 that sum to n. The array is sorted in non-decreasing order, and there is only one way to form the array.
    You are also given a 0-indexed 2D integer array queries, where queries[i] = [lefti, righti]. Each queries[i] represents a query where you have to find the product of all powers[j] with lefti <= j <= righti.
    Return an array answers, equal in length to queries, where answers[i] is the answer to the ith query. Since the answer to the ith query may be too large, each answers[i] should be returned modulo 109 + 7.

    Example 1:

    >>> productQueries(n = 15, queries = [[0,1],[2,2],[0,3]])
    >>> [2,4,64]
    Explanation:
    For n = 15, powers = [1,2,4,8]. It can be shown that powers cannot be a smaller size.
    Answer to 1st query: powers[0] * powers[1] = 1 * 2 = 2.
    Answer to 2nd query: powers[2] = 4.
    Answer to 3rd query: powers[0] * powers[1] * powers[2] * powers[3] = 1 * 2 * 4 * 8 = 64.
    Each answer modulo 109 + 7 yields the same answer, so [2,4,64] is returned.

    Example 2:

    >>> productQueries(n = 2, queries = [[0,0]])
    >>> [2]
    Explanation:
    For n = 2, powers = [2].
    The answer to the only query is powers[0] = 2. The answer modulo 109 + 7 is the same, so [2] is returned.
    """


Prompt:
def minimizeArrayValue(nums: List[int]) -> int:
    """
    You are given a 0-indexed array nums comprising of n non-negative integers.
    In one operation, you must:

    Choose an integer i such that 1 <= i < n and nums[i] > 0.
    Decrease nums[i] by 1.
    Increase nums[i - 1] by 1.

    Return the minimum possible value of the maximum integer of nums after performing any number of operations.

    Example 1:

    >>> minimizeArrayValue(nums = [3,7,1,6])
    >>> 5
    Explanation:
    One set of optimal operations is as follows:
    1. Choose i = 1, and nums becomes [4,6,1,6].
    2. Choose i = 3, and nums becomes [4,6,2,5].
    3. Choose i = 1, and nums becomes [5,5,2,5].
    The maximum integer of nums is 5. It can be shown that the maximum number cannot be less than 5.
    Therefore, we return 5.

    Example 2:

    >>> minimizeArrayValue(nums = [10,1])
    >>> 10
    Explanation:
    It is optimal to leave nums as is, and since 10 is the maximum value, we return 10.
    """


Prompt:
def componentValue(nums: List[int], edges: List[List[int]]) -> int:
    """
    There is an undirected tree with n nodes labeled from 0 to n - 1.
    You are given a 0-indexed integer array nums of length n where nums[i] represents the value of the ith node. You are also given a 2D integer array edges of length n - 1 where edges[i] = [ai, bi] indicates that there is an edge between nodes ai and bi in the tree.
    You are allowed to delete some edges, splitting the tree into multiple connected components. Let the value of a component be the sum of all nums[i] for which node i is in the component.
    Return the maximum number of edges you can delete, such that every connected component in the tree has the same value.

    Example 1:

    >>> componentValue(nums = [6,2,2,2,6], edges = [[0,1],[1,2],[1,3],[3,4]])
    >>> 2
    Explanation: The above figure shows how we can delete the edges [0,1] and [3,4]. The created components are nodes [0], [1,2,3] and [4]. The sum of the values in each component equals 6. It can be proven that no better deletion exists, so the answer is 2.

    Example 2:

    >>> componentValue(nums = [2], edges = [])
    >>> 0
    Explanation: There are no edges to be deleted.
    """


Prompt:
def findMaxK(nums: List[int]) -> int:
    """
    Given an integer array nums that does not contain any zeros, find the largest positive integer k such that -k also exists in the array.
    Return the positive integer k. If there is no such integer, return -1.

    Example 1:

    >>> findMaxK(nums = [-1,2,-3,3])
    >>> 3
    Explanation: 3 is the only valid k we can find in the array.

    Example 2:

    >>> findMaxK(nums = [-1,10,6,7,-7,1])
    >>> 7
    Explanation: Both 1 and 7 have their corresponding negative values in the array. 7 has a larger value.

    Example 3:

    >>> findMaxK(nums = [-10,8,6,7,-2,-3])
    >>> -1
    Explanation: There is no a single valid k, we return -1.
    """


Prompt:
def countDistinctIntegers(nums: List[int]) -> int:
    """
    You are given an array nums consisting of positive integers.
    You have to take each integer in the array, reverse its digits, and add it to the end of the array. You should apply this operation to the original integers in nums.
    Return the number of distinct integers in the final array.

    Example 1:

    >>> countDistinctIntegers(nums = [1,13,10,12,31])
    >>> 6
    Explanation: After including the reverse of each number, the resulting array is [1,13,10,12,31,1,31,1,21,13].
    The reversed integers that were added to the end of the array are underlined. Note that for the integer 10, after reversing it, it becomes 01 which is just 1.
    The number of distinct integers in this array is 6 (The numbers 1, 10, 12, 13, 21, and 31).
    Example 2:

    >>> countDistinctIntegers(nums = [2,2,2])
    >>> 1
    Explanation: After including the reverse of each number, the resulting array is [2,2,2,2,2,2].
    The number of distinct integers in this array is 1 (The number 2).
    """


Prompt:
def sumOfNumberAndReverse(num: int) -> bool:
    """
    Given a non-negative integer num, return true if num can be expressed as the sum of any non-negative integer and its reverse, or false otherwise.

    Example 1:

    >>> sumOfNumberAndReverse(num = 443)
    >>> true
    Explanation: 172 + 271 = 443 so we return true.

    Example 2:

    >>> sumOfNumberAndReverse(num = 63)
    >>> false
    Explanation: 63 cannot be expressed as the sum of a non-negative integer and its reverse so we return false.

    Example 3:

    >>> sumOfNumberAndReverse(num = 181)
    >>> true
    Explanation: 140 + 041 = 181 so we return true. Note that when a number is reversed, there may be leading zeros.
    """


Prompt:
def countSubarrays(nums: List[int], minK: int, maxK: int) -> int:
    """
    You are given an integer array nums and two integers minK and maxK.
    A fixed-bound subarray of nums is a subarray that satisfies the following conditions:

    The minimum value in the subarray is equal to minK.
    The maximum value in the subarray is equal to maxK.

    Return the number of fixed-bound subarrays.
    A subarray is a contiguous part of an array.

    Example 1:

    >>> countSubarrays(nums = [1,3,5,2,7,5], minK = 1, maxK = 5)
    >>> 2
    Explanation: The fixed-bound subarrays are [1,3,5] and [1,3,5,2].

    Example 2:

    >>> countSubarrays(nums = [1,1,1,1], minK = 1, maxK = 1)
    >>> 10
    Explanation: Every subarray of nums is a fixed-bound subarray. There are 10 possible subarrays.
    """


Prompt:
def numberOfNodes(n: int, queries: List[int]) -> int:
    """
    There is an undirected connected tree with n nodes labeled from 1 to n and n - 1 edges. You are given the integer n. The parent node of a node with a label v is the node with the label floor (v / 2). The root of the tree is the node with the label 1.

    For example, if n = 7, then the node with the label 3 has the node with the label floor(3 / 2) = 1 as its parent, and the node with the label 7 has the node with the label floor(7 / 2) = 3 as its parent.

    You are also given an integer array queries. Initially, every node has a value 0 on it. For each query queries[i], you should flip all values in the subtree of the node with the label queries[i].
    Return the total number of nodes with the value 1 after processing all the queries.
    Note that:

    Flipping the value of a node means that the node with the value 0 becomes 1 and vice versa.
    floor(x) is equivalent to rounding x down to the nearest integer.

    Example 1:

    >>> numberOfNodes(n = 5 , queries = [1,2,5])
    >>> 3
    Explanation: The diagram above shows the tree structure and its status after performing the queries. The blue node represents the value 0, and the red node represents the value 1.
    After processing the queries, there are three red nodes (nodes with value 1): 1, 3, and 5.

    Example 2:

    >>> numberOfNodes(n = 3, queries = [2,3,3])
    >>> 1
    Explanation: The diagram above shows the tree structure and its status after performing the queries. The blue node represents the value 0, and the red node represents the value 1.
    After processing the queries, there are one red node (node with value 1): 2.
    """


Prompt:
def haveConflict(event1: List[str], event2: List[str]) -> bool:
    """
    You are given two arrays of strings that represent two inclusive events that happened on the same day, event1 and event2, where:

    event1 = [startTime1, endTime1] and
    event2 = [startTime2, endTime2].

    Event times are valid 24 hours format in the form of HH:MM.
    A conflict happens when two events have some non-empty intersection (i.e., some moment is common to both events).
    Return true if there is a conflict between two events. Otherwise, return false.

    Example 1:

    >>> haveConflict(event1 = ["01:15","02:00"], event2 = ["02:00","03:00"])
    >>> true
    Explanation: The two events intersect at time 2:00.

    Example 2:

    >>> haveConflict(event1 = ["01:00","02:00"], event2 = ["01:20","03:00"])
    >>> true
    Explanation: The two events intersect starting from 01:20 to 02:00.

    Example 3:

    >>> haveConflict(event1 = ["10:00","11:00"], event2 = ["14:00","15:00"])
    >>> false
    Explanation: The two events do not intersect.
    """


Prompt:
def subarrayGCD(nums: List[int], k: int) -> int:
    """
    Given an integer array nums and an integer k, return the number of subarrays of nums where the greatest common divisor of the subarray's elements is k.
    A subarray is a contiguous non-empty sequence of elements within an array.
    The greatest common divisor of an array is the largest integer that evenly divides all the array elements.

    Example 1:

    >>> subarrayGCD(nums = [9,3,1,2,6,3], k = 3)
    >>> 4
    Explanation: The subarrays of nums where 3 is the greatest common divisor of all the subarray's elements are:
    - [9,3,1,2,6,3]
    - [9,3,1,2,6,3]
    - [9,3,1,2,6,3]
    - [9,3,1,2,6,3]

    Example 2:

    >>> subarrayGCD(nums = [4], k = 7)
    >>> 0
    Explanation: There are no subarrays of nums where 7 is the greatest common divisor of all the subarray's elements.
    """


Prompt:
def minCost(nums: List[int], cost: List[int]) -> int:
    """
    You are given two 0-indexed arrays nums and cost consisting each of n positive integers.
    You can do the following operation any number of times:

    Increase or decrease any element of the array nums by 1.

    The cost of doing one operation on the ith element is cost[i].
    Return the minimum total cost such that all the elements of the array nums become equal.

    Example 1:

    >>> minCost(nums = [1,3,5,2], cost = [2,3,1,14])
    >>> 8
    Explanation: We can make all the elements equal to 2 in the following way:
    - Increase the 0th element one time. The cost is 2.
    - Decrease the 1st element one time. The cost is 3.
    - Decrease the 2nd element three times. The cost is 1 + 1 + 1 = 3.
    The total cost is 2 + 3 + 3 = 8.
    It can be shown that we cannot make the array equal with a smaller cost.

    Example 2:

    >>> minCost(nums = [2,2,2,2,2], cost = [4,2,8,1,3])
    >>> 0
    Explanation: All the elements are already equal, so no operations are needed.
    """


Prompt:
def makeSimilar(nums: List[int], target: List[int]) -> int:
    """
    You are given two positive integer arrays nums and target, of the same length.
    In one operation, you can choose any two distinct indices i and j where 0 <= i, j < nums.length and:

    set nums[i] = nums[i] + 2 and
    set nums[j] = nums[j] - 2.

    Two arrays are considered to be similar if the frequency of each element is the same.
    Return the minimum number of operations required to make nums similar to target. The test cases are generated such that nums can always be similar to target.

    Example 1:

    >>> makeSimilar(nums = [8,12,6], target = [2,14,10])
    >>> 2
    Explanation: It is possible to make nums similar to target in two operations:
    - Choose i = 0 and j = 2, nums = [10,12,4].
    - Choose i = 1 and j = 2, nums = [10,14,2].
    It can be shown that 2 is the minimum number of operations needed.

    Example 2:

    >>> makeSimilar(nums = [1,2,5], target = [4,1,3])
    >>> 1
    Explanation: We can make nums similar to target in one operation:
    - Choose i = 1 and j = 2, nums = [1,4,3].

    Example 3:

    >>> makeSimilar(nums = [1,1,1,1,1], target = [1,1,1,1,1])
    >>> 0
    Explanation: The array nums is already similiar to target.
    """


Prompt:
def countDistinctStrings(s: str, k: int) -> int:
    """
    You are given a binary string s and a positive integer k.
    You can apply the following operation on the string any number of times:

    Choose any substring of size k from s and flip all its characters, that is, turn all 1's into 0's, and all 0's into 1's.

    Return the number of distinct strings you can obtain. Since the answer may be too large, return it modulo 109 + 7.
    Note that:

    A binary string is a string that consists only of the characters 0 and 1.
    A substring is a contiguous part of a string.

    Example 1:

    >>> countDistinctStrings(s = "1001", k = 3)
    >>> 4
    Explanation: We can obtain the following strings:
    - Applying no operation on the string gives s = "1001".
    - Applying one operation on the substring starting at index 0 gives s = "0111".
    - Applying one operation on the substring starting at index 1 gives s = "1110".
    - Applying one operation on both the substrings starting at indices 0 and 1 gives s = "0000".
    It can be shown that we cannot obtain any other string, so the answer is 4.
    Example 2:

    >>> countDistinctStrings(s = "10110", k = 5)
    >>> 2
    Explanation: We can obtain the following strings:
    - Applying no operation on the string gives s = "10110".
    - Applying one operation on the whole string gives s = "01001".
    It can be shown that we cannot obtain any other string, so the answer is 2.
    """


Prompt:
def oddString(words: List[str]) -> str:
    """
    You are given an array of equal-length strings words. Assume that the length of each string is n.
    Each string words[i] can be converted into a difference integer array difference[i] of length n - 1 where difference[i][j] = words[i][j+1] - words[i][j] where 0 <= j <= n - 2. Note that the difference between two letters is the difference between their positions in the alphabet i.e. the position of 'a' is 0, 'b' is 1, and 'z' is 25.

    For example, for the string "acb", the difference integer array is [2 - 0, 1 - 2] = [2, -1].

    All the strings in words have the same difference integer array, except one. You should find that string.
    Return the string in words that has different difference integer array.

    Example 1:

    >>> oddString(words = ["adc","wzy","abc"])
    >>> "abc"
    Explanation:
    - The difference integer array of "adc" is [3 - 0, 2 - 3] = [3, -1].
    - The difference integer array of "wzy" is [25 - 22, 24 - 25]= [3, -1].
    - The difference integer array of "abc" is [1 - 0, 2 - 1] = [1, 1].
    The odd array out is [1, 1], so we return the corresponding string, "abc".

    Example 2:

    >>> oddString(words = ["aaa","bob","ccc","ddd"])
    >>> "bob"
    Explanation: All the integer arrays are [0, 0] except for "bob", which corresponds to [13, -13].
    """


Prompt:
def twoEditWords(queries: List[str], dictionary: List[str]) -> List[str]:
    """
    You are given two string arrays, queries and dictionary. All words in each array comprise of lowercase English letters and have the same length.
    In one edit you can take a word from queries, and change any letter in it to any other letter. Find all words from queries that, after a maximum of two edits, equal some word from dictionary.
    Return a list of all words from queries, that match with some word from dictionary after a maximum of two edits. Return the words in the same order they appear in queries.

    Example 1:

    >>> twoEditWords(queries = ["word","note","ants","wood"], dictionary = ["wood","joke","moat"])
    >>> ["word","note","wood"]
    Explanation:
    - Changing the 'r' in "word" to 'o' allows it to equal the dictionary word "wood".
    - Changing the 'n' to 'j' and the 't' to 'k' in "note" changes it to "joke".
    - It would take more than 2 edits for "ants" to equal a dictionary word.
    - "wood" can remain unchanged (0 edits) and match the corresponding dictionary word.
    Thus, we return ["word","note","wood"].

    Example 2:

    >>> twoEditWords(queries = ["yes"], dictionary = ["not"])
    >>> []
    Explanation:
    Applying any two edits to "yes" cannot make it equal to "not". Thus, we return an empty array.
    """


Prompt:
def destroyTargets(nums: List[int], space: int) -> int:
    """
    You are given a 0-indexed array nums consisting of positive integers, representing targets on a number line. You are also given an integer space.
    You have a machine which can destroy targets. Seeding the machine with some nums[i] allows it to destroy all targets with values that can be represented as nums[i] + c * space, where c is any non-negative integer. You want to destroy the maximum number of targets in nums.
    Return the minimum value of nums[i] you can seed the machine with to destroy the maximum number of targets.

    Example 1:

    >>> destroyTargets(nums = [3,7,8,1,1,5], space = 2)
    >>> 1
    Explanation: If we seed the machine with nums[3], then we destroy all targets equal to 1,3,5,7,9,...
    In this case, we would destroy 5 total targets (all except for nums[2]).
    It is impossible to destroy more than 5 targets, so we return nums[3].

    Example 2:

    >>> destroyTargets(nums = [1,3,5,2,4,6], space = 2)
    >>> 1
    Explanation: Seeding the machine with nums[0], or nums[3] destroys 3 targets.
    It is not possible to destroy more than 3 targets.
    Since nums[0] is the minimal integer that can destroy 3 targets, we return 1.

    Example 3:

    >>> destroyTargets(nums = [6,2,5], space = 100)
    >>> 2
    Explanation: Whatever initial seed we select, we can only destroy 1 target. The minimal seed is nums[1].
    """


Prompt:
def secondGreaterElement(nums: List[int]) -> List[int]:
    """
    You are given a 0-indexed array of non-negative integers nums. For each integer in nums, you must find its respective second greater integer.
    The second greater integer of nums[i] is nums[j] such that:

    j > i
    nums[j] > nums[i]
    There exists exactly one index k such that nums[k] > nums[i] and i < k < j.

    If there is no such nums[j], the second greater integer is considered to be -1.

    For example, in the array [1, 2, 4, 3], the second greater integer of 1 is 4, 2 is 3, and that of 3 and 4 is -1.

    Return an integer array answer, where answer[i] is the second greater integer of nums[i].

    Example 1:

    >>> secondGreaterElement(nums = [2,4,0,9,6])
    >>> [9,6,6,-1,-1]
    Explanation:
    0th index: 4 is the first integer greater than 2, and 9 is the second integer greater than 2, to the right of 2.
    1st index: 9 is the first, and 6 is the second integer greater than 4, to the right of 4.
    2nd index: 9 is the first, and 6 is the second integer greater than 0, to the right of 0.
    3rd index: There is no integer greater than 9 to its right, so the second greater integer is considered to be -1.
    4th index: There is no integer greater than 6 to its right, so the second greater integer is considered to be -1.
    Thus, we return [9,6,6,-1,-1].

    Example 2:

    >>> secondGreaterElement(nums = [3,3])
    >>> [-1,-1]
    Explanation:
    We return [-1,-1] since neither integer has any integer greater than it.
    """


Prompt:
def averageValue(nums: List[int]) -> int:
    """
    Given an integer array nums of positive integers, return the average value of all even integers that are divisible by 3.
    Note that the average of n elements is the sum of the n elements divided by n and rounded down to the nearest integer.

    Example 1:

    >>> averageValue(nums = [1,3,6,10,12,15])
    >>> 9
    Explanation: 6 and 12 are even numbers that are divisible by 3. (6 + 12) / 2 = 9.

    Example 2:

    >>> averageValue(nums = [1,2,4,7,10])
    >>> 0
    Explanation: There is no single number that satisfies the requirement, so return 0.
    """