ShwStone/humaneval-leetcode huggingface dataset:
def minPathCost(grid: List[List[int]], moveCost: List[List[int]]) -> int:
    """
    You are given a 0-indexed m x n integer matrix grid consisting of distinct integers from 0 to m * n - 1. You can move in this matrix from a cell to any other cell in the next row. That is, if you are in cell (x, y) such that x < m - 1, you can move to any of the cells (x + 1, 0), (x + 1, 1), ..., (x + 1, n - 1). Note that it is not possible to move from cells in the last row.
    Each possible move has a cost given by a 0-indexed 2D array moveCost of size (m * n) x n, where moveCost[i][j] is the cost of moving from a cell with value i to a cell in column j of the next row. The cost of moving from cells in the last row of grid can be ignored.
    The cost of a path in grid is the sum of all values of cells visited plus the sum of costs of all the moves made. Return the minimum cost of a path that starts from any cell in the first row and ends at any cell in the last row.
    
    Example 1:
    
    
    >>> minPathCost(grid = [[5,3],[4,0],[2,1]], moveCost = [[9,8],[1,5],[10,12],[18,6],[2,4],[14,3]])
    >>> 17
    Explanation: The path with the minimum possible cost is the path 5 -> 0 -> 1.
    - The sum of the values of cells visited is 5 + 0 + 1 = 6.
    - The cost of moving from 5 to 0 is 3.
    - The cost of moving from 0 to 1 is 8.
    So the total cost of the path is 6 + 3 + 8 = 17.
    
    Example 2:
    
    >>> minPathCost(grid = [[5,1,2],[4,0,3]], moveCost = [[12,10,15],[20,23,8],[21,7,1],[8,1,13],[9,10,25],[5,3,2]])
    >>> 6
    Explanation: The path with the minimum possible cost is the path 2 -> 3.
    - The sum of the values of cells visited is 2 + 3 = 5.
    - The cost of moving from 2 to 3 is 1.
    So the total cost of this path is 5 + 1 = 6.
    """
def distributeCookies(cookies: List[int], k: int) -> int:
    """
    You are given an integer array cookies, where cookies[i] denotes the number of cookies in the ith bag. You are also given an integer k that denotes the number of children to distribute all the bags of cookies to. All the cookies in the same bag must go to the same child and cannot be split up.
    The unfairness of a distribution is defined as the maximum total cookies obtained by a single child in the distribution.
    Return the minimum unfairness of all distributions.
    
    Example 1:
    
    >>> distributeCookies(cookies = [8,15,10,20,8], k = 2)
    >>> 31
    Explanation: One optimal distribution is [8,15,8] and [10,20]
    - The 1st child receives [8,15,8] which has a total of 8 + 15 + 8 = 31 cookies.
    - The 2nd child receives [10,20] which has a total of 10 + 20 = 30 cookies.
    The unfairness of the distribution is max(31,30) = 31.
    It can be shown that there is no distribution with an unfairness less than 31.
    
    Example 2:
    
    >>> distributeCookies(cookies = [6,1,3,2,2,4,1,2], k = 3)
    >>> 7
    Explanation: One optimal distribution is [6,1], [3,2,2], and [4,1,2]
    - The 1st child receives [6,1] which has a total of 6 + 1 = 7 cookies.
    - The 2nd child receives [3,2,2] which has a total of 3 + 2 + 2 = 7 cookies.
    - The 3rd child receives [4,1,2] which has a total of 4 + 1 + 2 = 7 cookies.
    The unfairness of the distribution is max(7,7,7) = 7.
    It can be shown that there is no distribution with an unfairness less than 7.
    """
def distinctNames(ideas: List[str]) -> int:
    """
    You are given an array of strings ideas that represents a list of names to be used in the process of naming a company. The process of naming a company is as follows:
    
    Choose 2 distinct names from ideas, call them ideaA and ideaB.
    Swap the first letters of ideaA and ideaB with each other.
    If both of the new names are not found in the original ideas, then the name ideaA ideaB (the concatenation of ideaA and ideaB, separated by a space) is a valid company name.
    Otherwise, it is not a valid name.
    
    Return the number of distinct valid names for the company.
    
    Example 1:
    
    >>> distinctNames(ideas = ["coffee","donuts","time","toffee"])
    >>> 6
    Explanation: The following selections are valid:
    - ("coffee", "donuts"): The company name created is "doffee conuts".
    - ("donuts", "coffee"): The company name created is "conuts doffee".
    - ("donuts", "time"): The company name created is "tonuts dime".
    - ("donuts", "toffee"): The company name created is "tonuts doffee".
    - ("time", "donuts"): The company name created is "dime tonuts".
    - ("toffee", "donuts"): The company name created is "doffee tonuts".
    Therefore, there are a total of 6 distinct company names.
    
    The following are some examples of invalid selections:
    - ("coffee", "time"): The name "toffee" formed after swapping already exists in the original array.
    - ("time", "toffee"): Both names are still the same after swapping and exist in the original array.
    - ("coffee", "toffee"): Both names formed after swapping already exist in the original array.
    
    Example 2:
    
    >>> distinctNames(ideas = ["lack","back"])
    >>> 0
    Explanation: There are no valid selections. Therefore, 0 is returned.
    """
def checkContradictions(equations: List[List[str]], values: List[float]) -> bool:
    """
    You are given a 2D array of strings equations and an array of real numbers values, where equations[i] = [Ai, Bi] and values[i] means that Ai / Bi = values[i].
    Determine if there exists a contradiction in the equations. Return true if there is a contradiction, or false otherwise.
    Note:
    
    When checking if two numbers are equal, check that their absolute difference is less than 10-5.
    The testcases are generated such that there are no cases targeting precision, i.e. using double is enough to solve the problem.
    
    
    Example 1:
    
    >>> checkContradictions(equations = [["a","b"],["b","c"],["a","c"]], values = [3,0.5,1.5])
    >>> false
    Explanation:
    The given equations are: a / b = 3, b / c = 0.5, a / c = 1.5
    There are no contradictions in the equations. One possible assignment to satisfy all equations is:
    a = 3, b = 1 and c = 2.
    
    Example 2:
    
    >>> checkContradictions(equations = [["le","et"],["le","code"],["code","et"]], values = [2,5,0.5])
    >>> true
    Explanation:
    The given equations are: le / et = 2, le / code = 5, code / et = 0.5
    Based on the first two equations, we get code / et = 0.4.
    Since the third equation is code / et = 0.5, we get a contradiction.
    """
def greatestLetter(s: str) -> str:
    """
    Given a string of English letters s, return the greatest English letter which occurs as both a lowercase and uppercase letter in s. The returned letter should be in uppercase. If no such letter exists, return an empty string.
    An English letter b is greater than another letter a if b appears after a in the English alphabet.
    
    Example 1:
    
    >>> greatestLetter(s = "lEeTcOdE")
    >>> "E"
    Explanation:
    The letter 'E' is the only letter to appear in both lower and upper case.
    
    Example 2:
    
    >>> greatestLetter(s = "arRAzFif")
    >>> "R"
    Explanation:
    The letter 'R' is the greatest letter to appear in both lower and upper case.
    Note that 'A' and 'F' also appear in both lower and upper case, but 'R' is greater than 'F' or 'A'.
    
    Example 3:
    
    >>> greatestLetter(s = "AbCdEfGhIjK")
    >>> ""
    Explanation:
    There is no letter that appears in both lower and upper case.
    """
def minimumNumbers(num: int, k: int) -> int:
    """
    Given two integers num and k, consider a set of positive integers with the following properties:
    
    The units digit of each integer is k.
    The sum of the integers is num.
    
    Return the minimum possible size of such a set, or -1 if no such set exists.
    Note:
    
    The set can contain multiple instances of the same integer, and the sum of an empty set is considered 0.
    The units digit of a number is the rightmost digit of the number.
    
    
    Example 1:
    
    >>> minimumNumbers(num = 58, k = 9)
    >>> 2
    Explanation:
    One valid set is [9,49], as the sum is 58 and each integer has a units digit of 9.
    Another valid set is [19,39].
    It can be shown that 2 is the minimum possible size of a valid set.
    
    Example 2:
    
    >>> minimumNumbers(num = 37, k = 2)
    >>> -1
    Explanation: It is not possible to obtain a sum of 37 using only integers that have a units digit of 2.
    
    Example 3:
    
    >>> minimumNumbers(num = 0, k = 7)
    >>> 0
    Explanation: The sum of an empty set is considered 0.
    """
def longestSubsequence(s: str, k: int) -> int:
    """
    You are given a binary string s and a positive integer k.
    Return the length of the longest subsequence of s that makes up a binary number less than or equal to k.
    Note:
    
    The subsequence can contain leading zeroes.
    The empty string is considered to be equal to 0.
    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.
    
    
    Example 1:
    
    >>> longestSubsequence(s = "1001010", k = 5)
    >>> 5
    Explanation: The longest subsequence of s that makes up a binary number less than or equal to 5 is "00010", as this number is equal to 2 in decimal.
    Note that "00100" and "00101" are also possible, which are equal to 4 and 5 in decimal, respectively.
    The length of this subsequence is 5, so 5 is returned.
    
    Example 2:
    
    >>> longestSubsequence(s = "00101001", k = 1)
    >>> 6
    Explanation: "000001" is the longest subsequence of s that makes up a binary number less than or equal to 1, as this number is equal to 1 in decimal.
    The length of this subsequence is 6, so 6 is returned.
    """
def sellingWood(m: int, n: int, prices: List[List[int]]) -> int:
    """
    You are given two integers m and n that represent the height and width of a rectangular piece of wood. You are also given a 2D integer array prices, where prices[i] = [hi, wi, pricei] indicates you can sell a rectangular piece of wood of height hi and width wi for pricei dollars.
    To cut a piece of wood, you must make a vertical or horizontal cut across the entire height or width of the piece to split it into two smaller pieces. After cutting a piece of wood into some number of smaller pieces, you can sell pieces according to prices. You may sell multiple pieces of the same shape, and you do not have to sell all the shapes. The grain of the wood makes a difference, so you cannot rotate a piece to swap its height and width.
    Return the maximum money you can earn after cutting an m x n piece of wood.
    Note that you can cut the piece of wood as many times as you want.
    
    Example 1:
    
    
    >>> sellingWood(m = 3, n = 5, prices = [[1,4,2],[2,2,7],[2,1,3]])
    >>> 19
    Explanation: The diagram above shows a possible scenario. It consists of:
    - 2 pieces of wood shaped 2 x 2, selling for a price of 2 * 7 = 14.
    - 1 piece of wood shaped 2 x 1, selling for a price of 1 * 3 = 3.
    - 1 piece of wood shaped 1 x 4, selling for a price of 1 * 2 = 2.
    This obtains a total of 14 + 3 + 2 = 19 money earned.
    It can be shown that 19 is the maximum amount of money that can be earned.
    
    Example 2:
    
    
    >>> sellingWood(m = 4, n = 6, prices = [[3,2,10],[1,4,2],[4,1,3]])
    >>> 32
    Explanation: The diagram above shows a possible scenario. It consists of:
    - 3 pieces of wood shaped 3 x 2, selling for a price of 3 * 10 = 30.
    - 1 piece of wood shaped 1 x 4, selling for a price of 1 * 2 = 2.
    This obtains a total of 30 + 2 = 32 money earned.
    It can be shown that 32 is the maximum amount of money that can be earned.
    Notice that we cannot rotate the 1 x 4 piece of wood to obtain a 4 x 1 piece of wood.
    """
def countAsterisks(s: str) -> int:
    """
    You are given a string s, where every two consecutive vertical bars '|' are grouped into a pair. In other words, the 1st and 2nd '|' make a pair, the 3rd and 4th '|' make a pair, and so forth.
    Return the number of '*' in s, excluding the '*' between each pair of '|'.
    Note that each '|' will belong to exactly one pair.
    
    Example 1:
    
    >>> countAsterisks(s = "l|*e*et|c**o|*de|")
    >>> 2
    Explanation: The considered characters are underlined: "l|*e*et|c**o|*de|".
    The characters between the first and second '|' are excluded from the answer.
    Also, the characters between the third and fourth '|' are excluded from the answer.
    There are 2 asterisks considered. Therefore, we return 2.
    Example 2:
    
    >>> countAsterisks(s = "iamprogrammer")
    >>> 0
    Explanation: In this example, there are no asterisks in s. Therefore, we return 0.
    
    Example 3:
    
    >>> countAsterisks(s = "yo|uar|e**|b|e***au|tifu|l")
    >>> 5
    Explanation: The considered characters are underlined: "yo|uar|e**|b|e***au|tifu|l". There are 5 asterisks considered. Therefore, we return 5.
    """
def countPairs(n: int, edges: List[List[int]]) -> int:
    """
    You are given an integer n. There is an undirected graph with n nodes, numbered from 0 to n - 1. You are given a 2D integer array edges where edges[i] = [ai, bi] denotes that there exists an undirected edge connecting nodes ai and bi.
    Return the number of pairs of different nodes that are unreachable from each other.
    
    Example 1:
    
    
    >>> countPairs(n = 3, edges = [[0,1],[0,2],[1,2]])
    >>> 0
    Explanation: There are no pairs of nodes that are unreachable from each other. Therefore, we return 0.
    
    Example 2:
    
    
    >>> countPairs(n = 7, edges = [[0,2],[0,5],[2,4],[1,6],[5,4]])
    >>> 14
    Explanation: There are 14 pairs of nodes that are unreachable from each other:
    [[0,1],[0,3],[0,6],[1,2],[1,3],[1,4],[1,5],[2,3],[2,6],[3,4],[3,5],[3,6],[4,6],[5,6]].
    Therefore, we return 14.
    """
def maximumXOR(nums: List[int]) -> int:
    """
    You are given a 0-indexed integer array nums. In one operation, select any non-negative integer x and an index i, then update nums[i] to be equal to nums[i] AND (nums[i] XOR x).
    Note that AND is the bitwise AND operation and XOR is the bitwise XOR operation.
    Return the maximum possible bitwise XOR of all elements of nums after applying the operation any number of times.
    
    Example 1:
    
    >>> maximumXOR(nums = [3,2,4,6])
    >>> 7
    Explanation: Apply the operation with x = 4 and i = 3, num[3] = 6 AND (6 XOR 4) = 6 AND 2 = 2.
    Now, nums = [3, 2, 4, 2] and the bitwise XOR of all the elements = 3 XOR 2 XOR 4 XOR 2 = 7.
    It can be shown that 7 is the maximum possible bitwise XOR.
    Note that other operations may be used to achieve a bitwise XOR of 7.
    Example 2:
    
    >>> maximumXOR(nums = [1,2,3,9,2])
    >>> 11
    Explanation: Apply the operation zero times.
    The bitwise XOR of all the elements = 1 XOR 2 XOR 3 XOR 9 XOR 2 = 11.
    It can be shown that 11 is the maximum possible bitwise XOR.
    """
def distinctSequences(n: int) -> int:
    """
    You are given an integer n. You roll a fair 6-sided dice n times. Determine the total number of distinct sequences of rolls possible such that the following conditions are satisfied:
    
    The greatest common divisor of any adjacent values in the sequence is equal to 1.
    There is at least a gap of 2 rolls between equal valued rolls. More formally, if the value of the ith roll is equal to the value of the jth roll, then abs(i - j) > 2.
    
    Return the total number of distinct sequences possible. Since the answer may be very large, return it modulo 109 + 7.
    Two sequences are considered distinct if at least one element is different.
    
    Example 1:
    
    >>> distinctSequences(n = 4)
    >>> 184
    Explanation: Some of the possible sequences are (1, 2, 3, 4), (6, 1, 2, 3), (1, 2, 3, 1), etc.
    Some invalid sequences are (1, 2, 1, 3), (1, 2, 3, 6).
    (1, 2, 1, 3) is invalid since the first and third roll have an equal value and abs(1 - 3) = 2 (i and j are 1-indexed).
    (1, 2, 3, 6) is invalid since the greatest common divisor of 3 and 6 = 3.
    There are a total of 184 distinct sequences possible, so we return 184.
    Example 2:
    
    >>> distinctSequences(n = 2)
    >>> 22
    Explanation: Some of the possible sequences are (1, 2), (2, 1), (3, 2).
    Some invalid sequences are (3, 6), (2, 4) since the greatest common divisor is not equal to 1.
    There are a total of 22 distinct sequences possible, so we return 22.
    """
def checkXMatrix(grid: List[List[int]]) -> bool:
    """
    A square matrix is said to be an X-Matrix if both of the following conditions hold:
    
    All the elements in the diagonals of the matrix are non-zero.
    All other elements are 0.
    
    Given a 2D integer array grid of size n x n representing a square matrix, return true if grid is an X-Matrix. Otherwise, return false.
    
    Example 1:
    
    
    >>> checkXMatrix(grid = [[2,0,0,1],[0,3,1,0],[0,5,2,0],[4,0,0,2]])
    >>> true
    Explanation: Refer to the diagram above.
    An X-Matrix should have the green elements (diagonals) be non-zero and the red elements be 0.
    Thus, grid is an X-Matrix.
    
    Example 2:
    
    
    >>> checkXMatrix(grid = [[5,7,0],[0,3,1],[0,5,0]])
    >>> false
    Explanation: Refer to the diagram above.
    An X-Matrix should have the green elements (diagonals) be non-zero and the red elements be 0.
    Thus, grid is not an X-Matrix.
    """
def countHousePlacements(n: int) -> int:
    """
    There is a street with n * 2 plots, where there are n plots on each side of the street. The plots on each side are numbered from 1 to n. On each plot, a house can be placed.
    Return the number of ways houses can be placed such that no two houses are adjacent to each other on the same side of the street. Since the answer may be very large, return it modulo 109 + 7.
    Note that if a house is placed on the ith plot on one side of the street, a house can also be placed on the ith plot on the other side of the street.
    
    Example 1:
    
    >>> countHousePlacements(n = 1)
    >>> 4
    Explanation:
    Possible arrangements:
    1. All plots are empty.
    2. A house is placed on one side of the street.
    3. A house is placed on the other side of the street.
    4. Two houses are placed, one on each side of the street.
    
    Example 2:
    
    
    >>> countHousePlacements(n = 2)
    >>> 9
    Explanation: The 9 possible arrangements are shown in the diagram above.
    """
def maximumsSplicedArray(nums1: List[int], nums2: List[int]) -> int:
    """
    You are given two 0-indexed integer arrays nums1 and nums2, both of length n.
    You can choose two integers left and right where 0 <= left <= right < n and swap the subarray nums1[left...right] with the subarray nums2[left...right].
    
    For example, if nums1 = [1,2,3,4,5] and nums2 = [11,12,13,14,15] and you choose left = 1 and right = 2, nums1 becomes [1,12,13,4,5] and nums2 becomes [11,2,3,14,15].
    
    You may choose to apply the mentioned operation once or not do anything.
    The score of the arrays is the maximum of sum(nums1) and sum(nums2), where sum(arr) is the sum of all the elements in the array arr.
    Return the maximum possible score.
    A subarray is a contiguous sequence of elements within an array. arr[left...right] denotes the subarray that contains the elements of nums between indices left and right (inclusive).
    
    Example 1:
    
    >>> maximumsSplicedArray(nums1 = [60,60,60], nums2 = [10,90,10])
    >>> 210
    Explanation: Choosing left = 1 and right = 1, we have nums1 = [60,90,60] and nums2 = [10,60,10].
    The score is max(sum(nums1), sum(nums2)) = max(210, 80) = 210.
    Example 2:
    
    >>> maximumsSplicedArray(nums1 = [20,40,20,70,30], nums2 = [50,20,50,40,20])
    >>> 220
    Explanation: Choosing left = 3, right = 4, we have nums1 = [20,40,20,40,20] and nums2 = [50,20,50,70,30].
    The score is max(sum(nums1), sum(nums2)) = max(140, 220) = 220.
    
    Example 3:
    
    >>> maximumsSplicedArray(nums1 = [7,11,13], nums2 = [1,1,1])
    >>> 31
    Explanation: We choose not to swap any subarray.
    The score is max(sum(nums1), sum(nums2)) = max(31, 3) = 31.
    """
def minimumScore(nums: List[int], edges: List[List[int]]) -> int:
    """
    There is an undirected connected tree with n nodes labeled from 0 to n - 1 and n - 1 edges.
    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.
    Remove two distinct edges of the tree to form three connected components. For a pair of removed edges, the following steps are defined:
    
    Get the XOR of all the values of the nodes for each of the three components respectively.
    The difference between the largest XOR value and the smallest XOR value is the score of the pair.
    
    
    For example, say the three components have the node values: [4,5,7], [1,9], and [3,3,3]. The three XOR values are 4 ^ 5 ^ 7 = 6, 1 ^ 9 = 8, and 3 ^ 3 ^ 3 = 3. The largest XOR value is 8 and the smallest XOR value is 3. The score is then 8 - 3 = 5.
    
    Return the minimum score of any possible pair of edge removals on the given tree.
    
    Example 1:
    
    
    >>> minimumScore(nums = [1,5,5,4,11], edges = [[0,1],[1,2],[1,3],[3,4]])
    >>> 9
    Explanation: The diagram above shows a way to make a pair of removals.
    - The 1st component has nodes [1,3,4] with values [5,4,11]. Its XOR value is 5 ^ 4 ^ 11 = 10.
    - The 2nd component has node [0] with value [1]. Its XOR value is 1 = 1.
    - The 3rd component has node [2] with value [5]. Its XOR value is 5 = 5.
    The score is the difference between the largest and smallest XOR value which is 10 - 1 = 9.
    It can be shown that no other pair of removals will obtain a smaller score than 9.
    
    Example 2:
    
    
    >>> minimumScore(nums = [5,5,2,4,4,2], edges = [[0,1],[1,2],[5,2],[4,3],[1,3]])
    >>> 0
    Explanation: The diagram above shows a way to make a pair of removals.
    - The 1st component has nodes [3,4] with values [4,4]. Its XOR value is 4 ^ 4 = 0.
    - The 2nd component has nodes [1,0] with values [5,5]. Its XOR value is 5 ^ 5 = 0.
    - The 3rd component has nodes [2,5] with values [2,2]. Its XOR value is 2 ^ 2 = 0.
    The score is the difference between the largest and smallest XOR value which is 0 - 0 = 0.
    We cannot obtain a smaller score than 0.
    """
def minimumTime(jobs: List[int], workers: List[int]) -> int:
    """
    You are given two 0-indexed integer arrays jobs and workers of equal length, where jobs[i] is the amount of time needed to complete the ith job, and workers[j] is the amount of time the jth worker can work each day.
    Each job should be assigned to exactly one worker, such that each worker completes exactly one job.
    Return the minimum number of days needed to complete all the jobs after assignment.
    
    Example 1:
    
    >>> minimumTime(jobs = [5,2,4], workers = [1,7,5])
    >>> 2
    Explanation:
    - Assign the 2nd worker to the 0th job. It takes them 1 day to finish the job.
    - Assign the 0th worker to the 1st job. It takes them 2 days to finish the job.
    - Assign the 1st worker to the 2nd job. It takes them 1 day to finish the job.
    It takes 2 days for all the jobs to be completed, so return 2.
    It can be proven that 2 days is the minimum number of days needed.
    
    Example 2:
    
    >>> minimumTime(jobs = [3,18,15,9], workers = [6,5,1,3])
    >>> 3
    Explanation:
    - Assign the 2nd worker to the 0th job. It takes them 3 days to finish the job.
    - Assign the 0th worker to the 1st job. It takes them 3 days to finish the job.
    - Assign the 1st worker to the 2nd job. It takes them 3 days to finish the job.
    - Assign the 3rd worker to the 3rd job. It takes them 3 days to finish the job.
    It takes 3 days for all the jobs to be completed, so return 3.
    It can be proven that 3 days is the minimum number of days needed.
    """