ShwStone/humaneval-leetcode huggingface dataset:
def earliestFullBloom(plantTime: List[int], growTime: List[int]) -> int:
    """
    You have n flower seeds. Every seed must be planted first before it can begin to grow, then bloom. Planting a seed takes time and so does the growth of a seed. You are given two 0-indexed integer arrays plantTime and growTime, of length n each:
    
    plantTime[i] is the number of full days it takes you to plant the ith seed. Every day, you can work on planting exactly one seed. You do not have to work on planting the same seed on consecutive days, but the planting of a seed is not complete until you have worked plantTime[i] days on planting it in total.
    growTime[i] is the number of full days it takes the ith seed to grow after being completely planted. After the last day of its growth, the flower blooms and stays bloomed forever.
    
    From the beginning of day 0, you can plant the seeds in any order.
    Return the earliest possible day where all seeds are blooming.
    
    Example 1:
    
    
    >>> earliestFullBloom(plantTime = [1,4,3], growTime = [2,3,1])
    >>> 9
    Explanation: The grayed out pots represent planting days, colored pots represent growing days, and the flower represents the day it blooms.
    One optimal way is:
    On day 0, plant the 0th seed. The seed grows for 2 full days and blooms on day 3.
    On days 1, 2, 3, and 4, plant the 1st seed. The seed grows for 3 full days and blooms on day 8.
    On days 5, 6, and 7, plant the 2nd seed. The seed grows for 1 full day and blooms on day 9.
    Thus, on day 9, all the seeds are blooming.
    
    Example 2:
    
    
    >>> earliestFullBloom(plantTime = [1,2,3,2], growTime = [2,1,2,1])
    >>> 9
    Explanation: The grayed out pots represent planting days, colored pots represent growing days, and the flower represents the day it blooms.
    One optimal way is:
    On day 1, plant the 0th seed. The seed grows for 2 full days and blooms on day 4.
    On days 0 and 3, plant the 1st seed. The seed grows for 1 full day and blooms on day 5.
    On days 2, 4, and 5, plant the 2nd seed. The seed grows for 2 full days and blooms on day 8.
    On days 6 and 7, plant the 3rd seed. The seed grows for 1 full day and blooms on day 9.
    Thus, on day 9, all the seeds are blooming.
    
    Example 3:
    
    >>> earliestFullBloom(plantTime = [1], growTime = [1])
    >>> 2
    Explanation: On day 0, plant the 0th seed. The seed grows for 1 full day and blooms on day 2.
    Thus, on day 2, all the seeds are blooming.
    """
def equalizeWater(buckets: List[int], loss: int) -> float:
    """
    You have n buckets each containing some gallons of water in it, represented by a 0-indexed integer array buckets, where the ith bucket contains buckets[i] gallons of water. You are also given an integer loss.
    You want to make the amount of water in each bucket equal. You can pour any amount of water from one bucket to another bucket (not necessarily an integer). However, every time you pour k gallons of water, you spill loss percent of k.
    Return the maximum amount of water in each bucket after making the amount of water equal. Answers within 10-5 of the actual answer will be accepted.
    
    Example 1:
    
    >>> equalizeWater(buckets = [1,2,7], loss = 80)
    >>> 2.00000
    Explanation: Pour 5 gallons of water from buckets[2] to buckets[0].
    5 * 80% = 4 gallons are spilled and buckets[0] only receives 5 - 4 = 1 gallon of water.
    All buckets have 2 gallons of water in them so return 2.
    
    Example 2:
    
    >>> equalizeWater(buckets = [2,4,6], loss = 50)
    >>> 3.50000
    Explanation: Pour 0.5 gallons of water from buckets[1] to buckets[0].
    0.5 * 50% = 0.25 gallons are spilled and buckets[0] only receives 0.5 - 0.25 = 0.25 gallons of water.
    Now, buckets = [2.25, 3.5, 6].
    Pour 2.5 gallons of water from buckets[2] to buckets[0].
    2.5 * 50% = 1.25 gallons are spilled and buckets[0] only receives 2.5 - 1.25 = 1.25 gallons of water.
    All buckets have 3.5 gallons of water in them so return 3.5.
    
    Example 3:
    
    >>> equalizeWater(buckets = [3,3,3,3], loss = 40)
    >>> 3.00000
    Explanation: All buckets already have the same amount of water in them.
    """
def divideString(s: str, k: int, fill: str) -> List[str]:
    """
    A string s can be partitioned into groups of size k using the following procedure:
    
    The first group consists of the first k characters of the string, the second group consists of the next k characters of the string, and so on. Each element can be a part of exactly one group.
    For the last group, if the string does not have k characters remaining, a character fill is used to complete the group.
    
    Note that the partition is done so that after removing the fill character from the last group (if it exists) and concatenating all the groups in order, the resultant string should be s.
    Given the string s, the size of each group k and the character fill, return a string array denoting the composition of every group s has been divided into, using the above procedure.
    
    Example 1:
    
    >>> divideString(s = "abcdefghi", k = 3, fill = "x")
    >>> ["abc","def","ghi"]
    Explanation:
    The first 3 characters "abc" form the first group.
    The next 3 characters "def" form the second group.
    The last 3 characters "ghi" form the third group.
    Since all groups can be completely filled by characters from the string, we do not need to use fill.
    Thus, the groups formed are "abc", "def", and "ghi".
    
    Example 2:
    
    >>> divideString(s = "abcdefghij", k = 3, fill = "x")
    >>> ["abc","def","ghi","jxx"]
    Explanation:
    Similar to the previous example, we are forming the first three groups "abc", "def", and "ghi".
    For the last group, we can only use the character 'j' from the string. To complete this group, we add 'x' twice.
    Thus, the 4 groups formed are "abc", "def", "ghi", and "jxx".
    """
def minMoves(target: int, maxDoubles: int) -> int:
    """
    You are playing a game with integers. You start with the integer 1 and you want to reach the integer target.
    In one move, you can either:
    
    Increment the current integer by one (i.e., x = x + 1).
    Double the current integer (i.e., x = 2 * x).
    
    You can use the increment operation any number of times, however, you can only use the double operation at most maxDoubles times.
    Given the two integers target and maxDoubles, return the minimum number of moves needed to reach target starting with 1.
    
    Example 1:
    
    >>> minMoves(target = 5, maxDoubles = 0)
    >>> 4
    Explanation: Keep incrementing by 1 until you reach target.
    
    Example 2:
    
    >>> minMoves(target = 19, maxDoubles = 2)
    >>> 7
    Explanation: Initially, x = 1
    Increment 3 times so x = 4
    Double once so x = 8
    Increment once so x = 9
    Double again so x = 18
    Increment once so x = 19
    
    Example 3:
    
    >>> minMoves(target = 10, maxDoubles = 4)
    >>> 4
    Explanation: Initially, x = 1
    Increment once so x = 2
    Double once so x = 4
    Increment once so x = 5
    Double again so x = 10
    """
def mostPoints(questions: List[List[int]]) -> int:
    """
    You are given a 0-indexed 2D integer array questions where questions[i] = [pointsi, brainpoweri].
    The array describes the questions of an exam, where you have to process the questions in order (i.e., starting from question 0) and make a decision whether to solve or skip each question. Solving question i will earn you pointsi points but you will be unable to solve each of the next brainpoweri questions. If you skip question i, you get to make the decision on the next question.
    
    For example, given questions = [[3, 2], [4, 3], [4, 4], [2, 5]]:
    
    
    If question 0 is solved, you will earn 3 points but you will be unable to solve questions 1 and 2.
    If instead, question 0 is skipped and question 1 is solved, you will earn 4 points but you will be unable to solve questions 2 and 3.
    
    
    
    Return the maximum points you can earn for the exam.
    
    Example 1:
    
    >>> mostPoints(questions = [[3,2],[4,3],[4,4],[2,5]])
    >>> 5
    Explanation: The maximum points can be earned by solving questions 0 and 3.
    - Solve question 0: Earn 3 points, will be unable to solve the next 2 questions
    - Unable to solve questions 1 and 2
    - Solve question 3: Earn 2 points
    Total points earned: 3 + 2 = 5. There is no other way to earn 5 or more points.
    
    Example 2:
    
    >>> mostPoints(questions = [[1,1],[2,2],[3,3],[4,4],[5,5]])
    >>> 7
    Explanation: The maximum points can be earned by solving questions 1 and 4.
    - Skip question 0
    - Solve question 1: Earn 2 points, will be unable to solve the next 2 questions
    - Unable to solve questions 2 and 3
    - Solve question 4: Earn 5 points
    Total points earned: 2 + 5 = 7. There is no other way to earn 7 or more points.
    """
def maxRunTime(n: int, batteries: List[int]) -> int:
    """
    You have n computers. You are given the integer n and a 0-indexed integer array batteries where the ith battery can run a computer for batteries[i] minutes. You are interested in running all n computers simultaneously using the given batteries.
    Initially, you can insert at most one battery into each computer. After that and at any integer time moment, you can remove a battery from a computer and insert another battery any number of times. The inserted battery can be a totally new battery or a battery from another computer. You may assume that the removing and inserting processes take no time.
    Note that the batteries cannot be recharged.
    Return the maximum number of minutes you can run all the n computers simultaneously.
    
    Example 1:
    
    
    >>> maxRunTime(n = 2, batteries = [3,3,3])
    >>> 4
    Explanation:
    Initially, insert battery 0 into the first computer and battery 1 into the second computer.
    After two minutes, remove battery 1 from the second computer and insert battery 2 instead. Note that battery 1 can still run for one minute.
    At the end of the third minute, battery 0 is drained, and you need to remove it from the first computer and insert battery 1 instead.
    By the end of the fourth minute, battery 1 is also drained, and the first computer is no longer running.
    We can run the two computers simultaneously for at most 4 minutes, so we return 4.
    
    
    Example 2:
    
    
    >>> maxRunTime(n = 2, batteries = [1,1,1,1])
    >>> 2
    Explanation:
    Initially, insert battery 0 into the first computer and battery 2 into the second computer.
    After one minute, battery 0 and battery 2 are drained so you need to remove them and insert battery 1 into the first computer and battery 3 into the second computer.
    After another minute, battery 1 and battery 3 are also drained so the first and second computers are no longer running.
    We can run the two computers simultaneously for at most 2 minutes, so we return 2.
    """
def countSubranges(nums1: List[int], nums2: List[int]) -> int:
    """
    You are given two 0-indexed integer arrays nums1 and nums2 of length n.
    A range [l, r] (inclusive) where 0 <= l <= r < n is balanced if:
    
    For every i in the range [l, r], you pick either nums1[i] or nums2[i].
    The sum of the numbers you pick from nums1 equals to the sum of the numbers you pick from nums2 (the sum is considered to be 0 if you pick no numbers from an array).
    
    Two balanced ranges from [l1, r1] and [l2, r2] are considered to be different if at least one of the following is true:
    
    l1 != l2
    r1 != r2
    nums1[i] is picked in the first range, and nums2[i] is picked in the second range or vice versa for at least one i.
    
    Return the number of different ranges that are balanced. Since the answer may be very large, return it modulo 109 + 7.
    
    Example 1:
    
    >>> countSubranges(nums1 = [1,2,5], nums2 = [2,6,3])
    >>> 3
    Explanation: The balanced ranges are:
    - [0, 1] where we choose nums2[0], and nums1[1].
      The sum of the numbers chosen from nums1 equals the sum of the numbers chosen from nums2: 2 = 2.
    - [0, 2] where we choose nums1[0], nums2[1], and nums1[2].
      The sum of the numbers chosen from nums1 equals the sum of the numbers chosen from nums2: 1 + 5 = 6.
    - [0, 2] where we choose nums1[0], nums1[1], and nums2[2].
      The sum of the numbers chosen from nums1 equals the sum of the numbers chosen from nums2: 1 + 2 = 3.
    Note that the second and third balanced ranges are different.
    In the second balanced range, we choose nums2[1] and in the third balanced range, we choose nums1[1].
    
    Example 2:
    
    >>> countSubranges(nums1 = [0,1], nums2 = [1,0])
    >>> 4
    Explanation: The balanced ranges are:
    - [0, 0] where we choose nums1[0].
      The sum of the numbers chosen from nums1 equals the sum of the numbers chosen from nums2: 0 = 0.
    - [1, 1] where we choose nums2[1].
      The sum of the numbers chosen from nums1 equals the sum of the numbers chosen from nums2: 0 = 0.
    - [0, 1] where we choose nums1[0] and nums2[1].
      The sum of the numbers chosen from nums1 equals the sum of the numbers chosen from nums2: 0 = 0.
    - [0, 1] where we choose nums2[0] and nums1[1].
      The sum of the numbers chosen from nums1 equals the sum of the numbers chosen from nums2: 1 = 1.
    """
def minimumCost(cost: List[int]) -> int:
    """
    A shop is selling candies at a discount. For every two candies sold, the shop gives a third candy for free.
    The customer can choose any candy to take away for free as long as the cost of the chosen candy is less than or equal to the minimum cost of the two candies bought.
    
    For example, if there are 4 candies with costs 1, 2, 3, and 4, and the customer buys candies with costs 2 and 3, they can take the candy with cost 1 for free, but not the candy with cost 4.
    
    Given a 0-indexed integer array cost, where cost[i] denotes the cost of the ith candy, return the minimum cost of buying all the candies.
    
    Example 1:
    
    >>> minimumCost(cost = [1,2,3])
    >>> 5
    Explanation: We buy the candies with costs 2 and 3, and take the candy with cost 1 for free.
    The total cost of buying all candies is 2 + 3 = 5. This is the only way we can buy the candies.
    Note that we cannot buy candies with costs 1 and 3, and then take the candy with cost 2 for free.
    The cost of the free candy has to be less than or equal to the minimum cost of the purchased candies.
    
    Example 2:
    
    >>> minimumCost(cost = [6,5,7,9,2,2])
    >>> 23
    Explanation: The way in which we can get the minimum cost is described below:
    - Buy candies with costs 9 and 7
    - Take the candy with cost 6 for free
    - We buy candies with costs 5 and 2
    - Take the last remaining candy with cost 2 for free
    Hence, the minimum cost to buy all candies is 9 + 7 + 5 + 2 = 23.
    
    Example 3:
    
    >>> minimumCost(cost = [5,5])
    >>> 10
    Explanation: Since there are only 2 candies, we buy both of them. There is not a third candy we can take for free.
    Hence, the minimum cost to buy all candies is 5 + 5 = 10.
    """
def numberOfArrays(differences: List[int], lower: int, upper: int) -> int:
    """
    You are given a 0-indexed array of n integers differences, which describes the differences between each pair of consecutive integers of a hidden sequence of length (n + 1). More formally, call the hidden sequence hidden, then we have that differences[i] = hidden[i + 1] - hidden[i].
    You are further given two integers lower and upper that describe the inclusive range of values [lower, upper] that the hidden sequence can contain.
    
    For example, given differences = [1, -3, 4], lower = 1, upper = 6, the hidden sequence is a sequence of length 4 whose elements are in between 1 and 6 (inclusive).
    
    
    [3, 4, 1, 5] and [4, 5, 2, 6] are possible hidden sequences.
    [5, 6, 3, 7] is not possible since it contains an element greater than 6.
    [1, 2, 3, 4] is not possible since the differences are not correct.
    
    
    
    Return the number of possible hidden sequences there are. If there are no possible sequences, return 0.
    
    Example 1:
    
    >>> numberOfArrays(differences = [1,-3,4], lower = 1, upper = 6)
    >>> 2
    Explanation: The possible hidden sequences are:
    - [3, 4, 1, 5]
    - [4, 5, 2, 6]
    Thus, we return 2.
    
    Example 2:
    
    >>> numberOfArrays(differences = [3,-4,5,1,-2], lower = -4, upper = 5)
    >>> 4
    Explanation: The possible hidden sequences are:
    - [-3, 0, -4, 1, 2, 0]
    - [-2, 1, -3, 2, 3, 1]
    - [-1, 2, -2, 3, 4, 2]
    - [0, 3, -1, 4, 5, 3]
    Thus, we return 4.
    
    Example 3:
    
    >>> numberOfArrays(differences = [4,-7,2], lower = 3, upper = 6)
    >>> 0
    Explanation: There are no possible hidden sequences. Thus, we return 0.
    """
def highestRankedKItems(grid: List[List[int]], pricing: List[int], start: List[int], k: int) -> List[List[int]]:
    """
    You are given a 0-indexed 2D integer array grid of size m x n that represents a map of the items in a shop. The integers in the grid represent the following:
    
    0 represents a wall that you cannot pass through.
    1 represents an empty cell that you can freely move to and from.
    All other positive integers represent the price of an item in that cell. You may also freely move to and from these item cells.
    
    It takes 1 step to travel between adjacent grid cells.
    You are also given integer arrays pricing and start where pricing = [low, high] and start = [row, col] indicates that you start at the position (row, col) and are interested only in items with a price in the range of [low, high] (inclusive). You are further given an integer k.
    You are interested in the positions of the k highest-ranked items whose prices are within the given price range. The rank is determined by the first of these criteria that is different:
    
    Distance, defined as the length of the shortest path from the start (shorter distance has a higher rank).
    Price (lower price has a higher rank, but it must be in the price range).
    The row number (smaller row number has a higher rank).
    The column number (smaller column number has a higher rank).
    
    Return the k highest-ranked items within the price range sorted by their rank (highest to lowest). If there are fewer than k reachable items within the price range, return all of them.
    
    Example 1:
    
    
    >>> highestRankedKItems(grid = [[1,2,0,1],[1,3,0,1],[0,2,5,1]], pricing = [2,5], start = [0,0], k = 3)
    >>> [[0,1],[1,1],[2,1]]
    Explanation: You start at (0,0).
    With a price range of [2,5], we can take items from (0,1), (1,1), (2,1) and (2,2).
    The ranks of these items are:
    - (0,1) with distance 1
    - (1,1) with distance 2
    - (2,1) with distance 3
    - (2,2) with distance 4
    Thus, the 3 highest ranked items in the price range are (0,1), (1,1), and (2,1).
    
    Example 2:
    
    
    >>> highestRankedKItems(grid = [[1,2,0,1],[1,3,3,1],[0,2,5,1]], pricing = [2,3], start = [2,3], k = 2)
    >>> [[2,1],[1,2]]
    Explanation: You start at (2,3).
    With a price range of [2,3], we can take items from (0,1), (1,1), (1,2) and (2,1).
    The ranks of these items are:
    - (2,1) with distance 2, price 2
    - (1,2) with distance 2, price 3
    - (1,1) with distance 3
    - (0,1) with distance 4
    Thus, the 2 highest ranked items in the price range are (2,1) and (1,2).
    
    Example 3:
    
    
    >>> highestRankedKItems(grid = [[1,1,1],[0,0,1],[2,3,4]], pricing = [2,3], start = [0,0], k = 3)
    >>> [[2,1],[2,0]]
    Explanation: You start at (0,0).
    With a price range of [2,3], we can take items from (2,0) and (2,1).
    The ranks of these items are:
    - (2,1) with distance 5
    - (2,0) with distance 6
    Thus, the 2 highest ranked items in the price range are (2,1) and (2,0).
    Note that k = 3 but there are only 2 reachable items within the price range.
    """
def numberOfWays(corridor: str) -> int:
    """
    Along a long library corridor, there is a line of seats and decorative plants. You are given a 0-indexed string corridor of length n consisting of letters 'S' and 'P' where each 'S' represents a seat and each 'P' represents a plant.
    One room divider has already been installed to the left of index 0, and another to the right of index n - 1. Additional room dividers can be installed. For each position between indices i - 1 and i (1 <= i <= n - 1), at most one divider can be installed.
    Divide the corridor into non-overlapping sections, where each section has exactly two seats with any number of plants. There may be multiple ways to perform the division. Two ways are different if there is a position with a room divider installed in the first way but not in the second way.
    Return the number of ways to divide the corridor. Since the answer may be very large, return it modulo 109 + 7. If there is no way, return 0.
    
    Example 1:
    
    
    >>> numberOfWays(corridor = "SSPPSPS")
    >>> 3
    Explanation: There are 3 different ways to divide the corridor.
    The black bars in the above image indicate the two room dividers already installed.
    Note that in each of the ways, each section has exactly two seats.
    
    Example 2:
    
    
    >>> numberOfWays(corridor = "PPSPSP")
    >>> 1
    Explanation: There is only 1 way to divide the corridor, by not installing any additional dividers.
    Installing any would create some section that does not have exactly two seats.
    
    Example 3:
    
    
    >>> numberOfWays(corridor = "S")
    >>> 0
    Explanation: There is no way to divide the corridor because there will always be a section that does not have exactly two seats.
    """
def countElements(nums: List[int]) -> int:
    """
    Given an integer array nums, return the number of elements that have both a strictly smaller and a strictly greater element appear in nums.
    
    Example 1:
    
    >>> countElements(nums = [11,7,2,15])
    >>> 2
    Explanation: The element 7 has the element 2 strictly smaller than it and the element 11 strictly greater than it.
    Element 11 has element 7 strictly smaller than it and element 15 strictly greater than it.
    In total there are 2 elements having both a strictly smaller and a strictly greater element appear in nums.
    
    Example 2:
    
    >>> countElements(nums = [-3,3,3,90])
    >>> 2
    Explanation: The element 3 has the element -3 strictly smaller than it and the element 90 strictly greater than it.
    Since there are two elements with the value 3, in total there are 2 elements having both a strictly smaller and a strictly greater element appear in nums.
    """
def rearrangeArray(nums: List[int]) -> List[int]:
    """
    You are given a 0-indexed integer array nums of even length consisting of an equal number of positive and negative integers.
    You should return the array of nums such that the the array follows the given conditions:
    
    Every consecutive pair of integers have opposite signs.
    For all integers with the same sign, the order in which they were present in nums is preserved.
    The rearranged array begins with a positive integer.
    
    Return the modified array after rearranging the elements to satisfy the aforementioned conditions.
    
    Example 1:
    
    >>> rearrangeArray(nums = [3,1,-2,-5,2,-4])
    >>> [3,-2,1,-5,2,-4]
    Explanation:
    The positive integers in nums are [3,1,2]. The negative integers are [-2,-5,-4].
    The only possible way to rearrange them such that they satisfy all conditions is [3,-2,1,-5,2,-4].
    Other ways such as [1,-2,2,-5,3,-4], [3,1,2,-2,-5,-4], [-2,3,-5,1,-4,2] are incorrect because they do not satisfy one or more conditions.
    
    Example 2:
    
    >>> rearrangeArray(nums = [-1,1])
    >>> [1,-1]
    Explanation:
    1 is the only positive integer and -1 the only negative integer in nums.
    So nums is rearranged to [1,-1].
    """