ShwStone/humaneval-leetcode huggingface dataset:
def sumScores(s: str) -> int:
    """
    You are building a string s of length n one character at a time, prepending each new character to the front of the string. The strings are labeled from 1 to n, where the string with length i is labeled si.
    
    For example, for s = "abaca", s1 == "a", s2 == "ca", s3 == "aca", etc.
    
    The score of si is the length of the longest common prefix between si and sn (Note that s == sn).
    Given the final string s, return the sum of the score of every si.
    
    Example 1:
    
    >>> sumScores(s = "babab")
    >>> 9
    Explanation:
    For s1 == "b", the longest common prefix is "b" which has a score of 1.
    For s2 == "ab", there is no common prefix so the score is 0.
    For s3 == "bab", the longest common prefix is "bab" which has a score of 3.
    For s4 == "abab", there is no common prefix so the score is 0.
    For s5 == "babab", the longest common prefix is "babab" which has a score of 5.
    The sum of the scores is 1 + 0 + 3 + 0 + 5 = 9, so we return 9.
    Example 2:
    
    >>> sumScores(s = "azbazbzaz")
    >>> 14
    Explanation:
    For s2 == "az", the longest common prefix is "az" which has a score of 2.
    For s6 == "azbzaz", the longest common prefix is "azb" which has a score of 3.
    For s9 == "azbazbzaz", the longest common prefix is "azbazbzaz" which has a score of 9.
    For all other si, the score is 0.
    The sum of the scores is 2 + 3 + 9 = 14, so we return 14.
    """
def convertTime(current: str, correct: str) -> int:
    """
    You are given two strings current and correct representing two 24-hour times.
    24-hour times are formatted as "HH:MM", where HH is between 00 and 23, and MM is between 00 and 59. The earliest 24-hour time is 00:00, and the latest is 23:59.
    In one operation you can increase the time current by 1, 5, 15, or 60 minutes. You can perform this operation any number of times.
    Return the minimum number of operations needed to convert current to correct.
    
    Example 1:
    
    >>> convertTime(current = "02:30", correct = "04:35")
    >>> 3
    Explanation:
    We can convert current to correct in 3 operations as follows:
    - Add 60 minutes to current. current becomes "03:30".
    - Add 60 minutes to current. current becomes "04:30".
    - Add 5 minutes to current. current becomes "04:35".
    It can be proven that it is not possible to convert current to correct in fewer than 3 operations.
    Example 2:
    
    >>> convertTime(current = "11:00", correct = "11:01")
    >>> 1
    Explanation: We only have to add one minute to current, so the minimum number of operations needed is 1.
    """
def findWinners(matches: List[List[int]]) -> List[List[int]]:
    """
    You are given an integer array matches where matches[i] = [winneri, loseri] indicates that the player winneri defeated player loseri in a match.
    Return a list answer of size 2 where:
    
    answer[0] is a list of all players that have not lost any matches.
    answer[1] is a list of all players that have lost exactly one match.
    
    The values in the two lists should be returned in increasing order.
    Note:
    
    You should only consider the players that have played at least one match.
    The testcases will be generated such that no two matches will have the same outcome.
    
    
    Example 1:
    
    >>> findWinners(matches = [[1,3],[2,3],[3,6],[5,6],[5,7],[4,5],[4,8],[4,9],[10,4],[10,9]])
    >>> [[1,2,10],[4,5,7,8]]
    Explanation:
    Players 1, 2, and 10 have not lost any matches.
    Players 4, 5, 7, and 8 each have lost one match.
    Players 3, 6, and 9 each have lost two matches.
    Thus, answer[0] = [1,2,10] and answer[1] = [4,5,7,8].
    
    Example 2:
    
    >>> findWinners(matches = [[2,3],[1,3],[5,4],[6,4]])
    >>> [[1,2,5,6],[]]
    Explanation:
    Players 1, 2, 5, and 6 have not lost any matches.
    Players 3 and 4 each have lost two matches.
    Thus, answer[0] = [1,2,5,6] and answer[1] = [].
    """
def maximumCandies(candies: List[int], k: int) -> int:
    """
    You are given a 0-indexed integer array candies. Each element in the array denotes a pile of candies of size candies[i]. You can divide each pile into any number of sub piles, but you cannot merge two piles together.
    You are also given an integer k. You should allocate piles of candies to k children such that each child gets the same number of candies. Each child can be allocated candies from only one pile of candies and some piles of candies may go unused.
    Return the maximum number of candies each child can get.
    
    Example 1:
    
    >>> maximumCandies(candies = [5,8,6], k = 3)
    >>> 5
    Explanation: We can divide candies[1] into 2 piles of size 5 and 3, and candies[2] into 2 piles of size 5 and 1. We now have five piles of candies of sizes 5, 5, 3, 5, and 1. We can allocate the 3 piles of size 5 to 3 children. It can be proven that each child cannot receive more than 5 candies.
    
    Example 2:
    
    >>> maximumCandies(candies = [2,5], k = 11)
    >>> 0
    Explanation: There are 11 children but only 7 candies in total, so it is impossible to ensure each child receives at least one candy. Thus, each child gets no candy and the answer is 0.
    """
def isConsecutive(nums: List[int]) -> bool:
    """
    Given an integer array nums, return true if nums is consecutive, otherwise return false.
    An array is consecutive if it contains every number in the range [x, x + n - 1] (inclusive), where x is the minimum number in the array and n is the length of the array.
    
    Example 1:
    
    >>> isConsecutive(nums = [1,3,4,2])
    >>> true
    Explanation:
    The minimum value is 1 and the length of nums is 4.
    All of the values in the range [x, x + n - 1] = [1, 1 + 4 - 1] = [1, 4] = (1, 2, 3, 4) occur in nums.
    Therefore, nums is consecutive.
    
    Example 2:
    
    >>> isConsecutive(nums = [1,3])
    >>> false
    Explanation:
    The minimum value is 1 and the length of nums is 2.
    The value 2 in the range [x, x + n - 1] = [1, 1 + 2 - 1], = [1, 2] = (1, 2) does not occur in nums.
    Therefore, nums is not consecutive.
    
    Example 3:
    
    >>> isConsecutive(nums = [3,5,4])
    >>> true
    Explanation:
    The minimum value is 3 and the length of nums is 3.
    All of the values in the range [x, x + n - 1] = [3, 3 + 3 - 1] = [3, 5] = (3, 4, 5) occur in nums.
    Therefore, nums is consecutive.
    """
def largestInteger(num: int) -> int:
    """
    You are given a positive integer num. You may swap any two digits of num that have the same parity (i.e. both odd digits or both even digits).
    Return the largest possible value of num after any number of swaps.
    
    Example 1:
    
    >>> largestInteger(num = 1234)
    >>> 3412
    Explanation: Swap the digit 3 with the digit 1, this results in the number 3214.
    Swap the digit 2 with the digit 4, this results in the number 3412.
    Note that there may be other sequences of swaps but it can be shown that 3412 is the largest possible number.
    Also note that we may not swap the digit 4 with the digit 1 since they are of different parities.
    
    Example 2:
    
    >>> largestInteger(num = 65875)
    >>> 87655
    Explanation: Swap the digit 8 with the digit 6, this results in the number 85675.
    Swap the first digit 5 with the digit 7, this results in the number 87655.
    Note that there may be other sequences of swaps but it can be shown that 87655 is the largest possible number.
    """
def minimizeResult(expression: str) -> str:
    """
    You are given a 0-indexed string expression of the form "+" where  and  represent positive integers.
    Add a pair of parentheses to expression such that after the addition of parentheses, expression is a valid mathematical expression and evaluates to the smallest possible value. The left parenthesis must be added to the left of '+' and the right parenthesis must be added to the right of '+'.
    Return expression after adding a pair of parentheses such that expression evaluates to the smallest possible value. If there are multiple answers that yield the same result, return any of them.
    The input has been generated such that the original value of expression, and the value of expression after adding any pair of parentheses that meets the requirements fits within a signed 32-bit integer.
    
    Example 1:
    
    >>> minimizeResult(expression = "247+38")
    >>> "2(47+38)"
    Explanation: The expression evaluates to 2 * (47 + 38) = 2 * 85 = 170.
    Note that "2(4)7+38" is invalid because the right parenthesis must be to the right of the '+'.
    It can be shown that 170 is the smallest possible value.
    
    Example 2:
    
    >>> minimizeResult(expression = "12+34")
    >>> "1(2+3)4"
    Explanation: The expression evaluates to 1 * (2 + 3) * 4 = 1 * 5 * 4 = 20.
    
    Example 3:
    
    >>> minimizeResult(expression = "999+999")
    >>> "(999+999)"
    Explanation: The expression evaluates to 999 + 999 = 1998.
    """
def maximumProduct(nums: List[int], k: int) -> int:
    """
    You are given an array of non-negative integers nums and an integer k. In one operation, you may choose any element from nums and increment it by 1.
    Return the maximum product of nums after at most k operations. Since the answer may be very large, return it modulo 109 + 7. Note that you should maximize the product before taking the modulo.
    
    Example 1:
    
    >>> maximumProduct(nums = [0,4], k = 5)
    >>> 20
    Explanation: Increment the first number 5 times.
    Now nums = [5, 4], with a product of 5 * 4 = 20.
    It can be shown that 20 is maximum product possible, so we return 20.
    Note that there may be other ways to increment nums to have the maximum product.
    
    Example 2:
    
    >>> maximumProduct(nums = [6,3,3,2], k = 2)
    >>> 216
    Explanation: Increment the second number 1 time and increment the fourth number 1 time.
    Now nums = [6, 4, 3, 3], with a product of 6 * 4 * 3 * 3 = 216.
    It can be shown that 216 is maximum product possible, so we return 216.
    Note that there may be other ways to increment nums to have the maximum product.
    """
def maximumBeauty(flowers: List[int], newFlowers: int, target: int, full: int, partial: int) -> int:
    """
    Alice is a caretaker of n gardens and she wants to plant flowers to maximize the total beauty of all her gardens.
    You are given a 0-indexed integer array flowers of size n, where flowers[i] is the number of flowers already planted in the ith garden. Flowers that are already planted cannot be removed. You are then given another integer newFlowers, which is the maximum number of flowers that Alice can additionally plant. You are also given the integers target, full, and partial.
    A garden is considered complete if it has at least target flowers. The total beauty of the gardens is then determined as the sum of the following:
    
    The number of complete gardens multiplied by full.
    The minimum number of flowers in any of the incomplete gardens multiplied by partial. If there are no incomplete gardens, then this value will be 0.
    
    Return the maximum total beauty that Alice can obtain after planting at most newFlowers flowers.
    
    Example 1:
    
    >>> maximumBeauty(flowers = [1,3,1,1], newFlowers = 7, target = 6, full = 12, partial = 1)
    >>> 14
    Explanation: Alice can plant
    - 2 flowers in the 0th garden
    - 3 flowers in the 1st garden
    - 1 flower in the 2nd garden
    - 1 flower in the 3rd garden
    The gardens will then be [3,6,2,2]. She planted a total of 2 + 3 + 1 + 1 = 7 flowers.
    There is 1 garden that is complete.
    The minimum number of flowers in the incomplete gardens is 2.
    Thus, the total beauty is 1 * 12 + 2 * 1 = 12 + 2 = 14.
    No other way of planting flowers can obtain a total beauty higher than 14.
    
    Example 2:
    
    >>> maximumBeauty(flowers = [2,4,5,3], newFlowers = 10, target = 5, full = 2, partial = 6)
    >>> 30
    Explanation: Alice can plant
    - 3 flowers in the 0th garden
    - 0 flowers in the 1st garden
    - 0 flowers in the 2nd garden
    - 2 flowers in the 3rd garden
    The gardens will then be [5,4,5,5]. She planted a total of 3 + 0 + 0 + 2 = 5 flowers.
    There are 3 gardens that are complete.
    The minimum number of flowers in the incomplete gardens is 4.
    Thus, the total beauty is 3 * 2 + 4 * 6 = 6 + 24 = 30.
    No other way of planting flowers can obtain a total beauty higher than 30.
    Note that Alice could make all the gardens complete but in this case, she would obtain a lower total beauty.
    """
def sum(num1: int, num2: int) -> int:
    """
    Given two integers num1 and num2, return the sum of the two integers.
    
    Example 1:
    
    >>> sum(num1 = 12, num2 = 5)
    >>> 17
    Explanation: num1 is 12, num2 is 5, and their sum is 12 + 5 = 17, so 17 is returned.
    
    Example 2:
    
    >>> sum(num1 = -10, num2 = 4)
    >>> -6
    Explanation: num1 + num2 = -6, so -6 is returned.
    """
# class TreeNode:
#     def __init__(val=0, left=None, right=None):
#         self.val = val
#         self.left = left
#         self.right = right
class Solution:
    def checkTree(root: Optional[TreeNode]) -> bool:
    """
    You are given the root of a binary tree that consists of exactly 3 nodes: the root, its left child, and its right child.
    Return true if the value of the root is equal to the sum of the values of its two children, or false otherwise.
    
    Example 1:
    
    
    >>> __init__(root = [10,4,6])
    >>> true
    Explanation: The values of the root, its left child, and its right child are 10, 4, and 6, respectively.
    10 is equal to 4 + 6, so we return true.
    
    Example 2:
    
    
    >>> __init__(root = [5,3,1])
    >>> false
    Explanation: The values of the root, its left child, and its right child are 5, 3, and 1, respectively.
    5 is not equal to 3 + 1, so we return false.
    """
def meetRequirement(n: int, lights: List[List[int]], requirement: List[int]) -> int:
    """
    You are given an integer n. A perfectly straight street is represented by a number line ranging from 0 to n - 1. You are given a 2D integer array lights representing the street lamp(s) on the street. Each lights[i] = [positioni, rangei] indicates that there is a street lamp at position positioni that lights up the area from [max(0, positioni - rangei), min(n - 1, positioni + rangei)] (inclusive).
    The brightness of a position p is defined as the number of street lamps that light up the position p. You are given a 0-indexed integer array requirement of size n where requirement[i] is the minimum brightness of the ith position on the street.
    Return the number of positions i on the street between 0 and n - 1 that have a brightness of at least requirement[i].
    
    Example 1:
    
    
    >>> meetRequirement(n = 5, lights = [[0,1],[2,1],[3,2]], requirement = [0,2,1,4,1])
    >>> 4
    Explanation:
    - The first street lamp lights up the area from [max(0, 0 - 1), min(n - 1, 0 + 1)] = [0, 1] (inclusive).
    - The second street lamp lights up the area from [max(0, 2 - 1), min(n - 1, 2 + 1)] = [1, 3] (inclusive).
    - The third street lamp lights up the area from [max(0, 3 - 2), min(n - 1, 3 + 2)] = [1, 4] (inclusive).
    
    - Position 0 is covered by the first street lamp. It is covered by 1 street lamp which is greater than requirement[0].
    - Position 1 is covered by the first, second, and third street lamps. It is covered by 3 street lamps which is greater than requirement[1].
    - Position 2 is covered by the second and third street lamps. It is covered by 2 street lamps which is greater than requirement[2].
    - Position 3 is covered by the second and third street lamps. It is covered by 2 street lamps which is less than requirement[3].
    - Position 4 is covered by the third street lamp. It is covered by 1 street lamp which is equal to requirement[4].
    
    Positions 0, 1, 2, and 4 meet the requirement so we return 4.
    
    Example 2:
    
    >>> meetRequirement(n = 1, lights = [[0,1]], requirement = [2])
    >>> 0
    Explanation:
    - The first street lamp lights up the area from [max(0, 0 - 1), min(n - 1, 0 + 1)] = [0, 0] (inclusive).
    - Position 0 is covered by the first street lamp. It is covered by 1 street lamp which is less than requirement[0].
    - We return 0 because no position meets their brightness requirement.
    """
def findClosestNumber(nums: List[int]) -> int:
    """
    Given an integer array nums of size n, return the number with the value closest to 0 in nums. If there are multiple answers, return the number with the largest value.
    
    Example 1:
    
    >>> findClosestNumber(nums = [-4,-2,1,4,8])
    >>> 1
    Explanation:
    The distance from -4 to 0 is |-4| = 4.
    The distance from -2 to 0 is |-2| = 2.
    The distance from 1 to 0 is |1| = 1.
    The distance from 4 to 0 is |4| = 4.
    The distance from 8 to 0 is |8| = 8.
    Thus, the closest number to 0 in the array is 1.
    
    Example 2:
    
    >>> findClosestNumber(nums = [2,-1,1])
    >>> 1
    Explanation: 1 and -1 are both the closest numbers to 0, so 1 being larger is returned.
    """
def waysToBuyPensPencils(total: int, cost1: int, cost2: int) -> int:
    """
    You are given an integer total indicating the amount of money you have. You are also given two integers cost1 and cost2 indicating the price of a pen and pencil respectively. You can spend part or all of your money to buy multiple quantities (or none) of each kind of writing utensil.
    Return the number of distinct ways you can buy some number of pens and pencils.
    
    Example 1:
    
    >>> waysToBuyPensPencils(total = 20, cost1 = 10, cost2 = 5)
    >>> 9
    Explanation: The price of a pen is 10 and the price of a pencil is 5.
    - If you buy 0 pens, you can buy 0, 1, 2, 3, or 4 pencils.
    - If you buy 1 pen, you can buy 0, 1, or 2 pencils.
    - If you buy 2 pens, you cannot buy any pencils.
    The total number of ways to buy pens and pencils is 5 + 3 + 1 = 9.
    
    Example 2:
    
    >>> waysToBuyPensPencils(total = 5, cost1 = 10, cost2 = 10)
    >>> 1
    Explanation: The price of both pens and pencils are 10, which cost more than total, so you cannot buy any writing utensils. Therefore, there is only 1 way: buy 0 pens and 0 pencils.
    """
def maximumScore(scores: List[int], edges: List[List[int]]) -> int:
    """
    There is an undirected graph with n nodes, numbered from 0 to n - 1.
    You are given a 0-indexed integer array scores of length n where scores[i] denotes the score of node i. 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 node sequence is valid if it meets the following conditions:
    
    There is an edge connecting every pair of adjacent nodes in the sequence.
    No node appears more than once in the sequence.
    
    The score of a node sequence is defined as the sum of the scores of the nodes in the sequence.
    Return the maximum score of a valid node sequence with a length of 4. If no such sequence exists, return -1.
    
    Example 1:
    
    
    >>> maximumScore(scores = [5,2,9,8,4], edges = [[0,1],[1,2],[2,3],[0,2],[1,3],[2,4]])
    >>> 24
    Explanation: The figure above shows the graph and the chosen node sequence [0,1,2,3].
    The score of the node sequence is 5 + 2 + 9 + 8 = 24.
    It can be shown that no other node sequence has a score of more than 24.
    Note that the sequences [3,1,2,0] and [1,0,2,3] are also valid and have a score of 24.
    The sequence [0,3,2,4] is not valid since no edge connects nodes 0 and 3.
    
    Example 2:
    
    
    >>> maximumScore(scores = [9,20,6,4,11,12], edges = [[0,3],[5,3],[2,4],[1,3]])
    >>> -1
    Explanation: The figure above shows the graph.
    There are no valid node sequences of length 4, so we return -1.
    """
def digitSum(s: str, k: int) -> str:
    """
    You are given a string s consisting of digits and an integer k.
    A round can be completed if the length of s is greater than k. In one round, do the following:
    
    Divide s into consecutive groups of size k such that the first k characters are in the first group, the next k characters are in the second group, and so on. Note that the size of the last group can be smaller than k.
    Replace each group of s with a string representing the sum of all its digits. For example, "346" is replaced with "13" because 3 + 4 + 6 = 13.
    Merge consecutive groups together to form a new string. If the length of the string is greater than k, repeat from step 1.
    
    Return s after all rounds have been completed.
    
    Example 1:
    
    >>> digitSum(s = "11111222223", k = 3)
    >>> "135"
    Explanation:
    - For the first round, we divide s into groups of size 3: "111", "112", "222", and "23".
      ​​​​​Then we calculate the digit sum of each group: 1 + 1 + 1 = 3, 1 + 1 + 2 = 4, 2 + 2 + 2 = 6, and 2 + 3 = 5.
      So, s becomes "3" + "4" + "6" + "5" = "3465" after the first round.
    - For the second round, we divide s into "346" and "5".
      Then we calculate the digit sum of each group: 3 + 4 + 6 = 13, 5 = 5.
      So, s becomes "13" + "5" = "135" after second round.
    Now, s.length <= k, so we return "135" as the answer.
    
    Example 2:
    
    >>> digitSum(s = "00000000", k = 3)
    >>> "000"
    Explanation:
    We divide s into "000", "000", and "00".
    Then we calculate the digit sum of each group: 0 + 0 + 0 = 0, 0 + 0 + 0 = 0, and 0 + 0 = 0.
    s becomes "0" + "0" + "0" = "000", whose length is equal to k, so we return "000".
    """
def minimumRounds(tasks: List[int]) -> int:
    """
    You are given a 0-indexed integer array tasks, where tasks[i] represents the difficulty level of a task. In each round, you can complete either 2 or 3 tasks of the same difficulty level.
    Return the minimum rounds required to complete all the tasks, or -1 if it is not possible to complete all the tasks.
    
    Example 1:
    
    >>> minimumRounds(tasks = [2,2,3,3,2,4,4,4,4,4])
    >>> 4
    Explanation: To complete all the tasks, a possible plan is:
    - In the first round, you complete 3 tasks of difficulty level 2.
    - In the second round, you complete 2 tasks of difficulty level 3.
    - In the third round, you complete 3 tasks of difficulty level 4.
    - In the fourth round, you complete 2 tasks of difficulty level 4.
    It can be shown that all the tasks cannot be completed in fewer than 4 rounds, so the answer is 4.
    
    Example 2:
    
    >>> minimumRounds(tasks = [2,3,3])
    >>> -1
    Explanation: There is only 1 task of difficulty level 2, but in each round, you can only complete either 2 or 3 tasks of the same difficulty level. Hence, you cannot complete all the tasks, and the answer is -1.
    """