ShwStone/humaneval-leetcode huggingface dataset:
def minimumDeviation(nums: List[int]) -> int:
    """
    You are given an array nums of n positive integers.
    You can perform two types of operations on any element of the array any number of times:
    
    If the element is even, divide it by 2.
    
    
    For example, if the array is [1,2,3,4], then you can do this operation on the last element, and the array will be [1,2,3,2].
    
    
    If the element is odd, multiply it by 2.
    
    For example, if the array is [1,2,3,4], then you can do this operation on the first element, and the array will be [2,2,3,4].
    
    
    
    The deviation of the array is the maximum difference between any two elements in the array.
    Return the minimum deviation the array can have after performing some number of operations.
    
    Example 1:
    
    >>> minimumDeviation(nums = [1,2,3,4])
    >>> 1
    Explanation: You can transform the array to [1,2,3,2], then to [2,2,3,2], then the deviation will be 3 - 2 = 1.
    
    Example 2:
    
    >>> minimumDeviation(nums = [4,1,5,20,3])
    >>> 3
    Explanation: You can transform the array after two operations to [4,2,5,5,3], then the deviation will be 5 - 2 = 3.
    
    Example 3:
    
    >>> minimumDeviation(nums = [2,10,8])
    >>> 3
    """
def interpret(command: str) -> str:
    """
    You own a Goal Parser that can interpret a string command. The command consists of an alphabet of "G", "()" and/or "(al)" in some order. The Goal Parser will interpret "G" as the string "G", "()" as the string "o", and "(al)" as the string "al". The interpreted strings are then concatenated in the original order.
    Given the string command, return the Goal Parser's interpretation of command.
    
    Example 1:
    
    >>> interpret(command = "G()(al)")
    >>> "Goal"
    Explanation: The Goal Parser interprets the command as follows:
    G -> G
    () -> o
    (al) -> al
    The final concatenated result is "Goal".
    
    Example 2:
    
    >>> interpret(command = "G()()()()(al)")
    >>> "Gooooal"
    
    Example 3:
    
    >>> interpret(command = "(al)G(al)()()G")
    >>> "alGalooG"
    """
def maxOperations(nums: List[int], k: int) -> int:
    """
    You are given an integer array nums and an integer k.
    In one operation, you can pick two numbers from the array whose sum equals k and remove them from the array.
    Return the maximum number of operations you can perform on the array.
    
    Example 1:
    
    >>> maxOperations(nums = [1,2,3,4], k = 5)
    >>> 2
    Explanation: Starting with nums = [1,2,3,4]:
    - Remove numbers 1 and 4, then nums = [2,3]
    - Remove numbers 2 and 3, then nums = []
    There are no more pairs that sum up to 5, hence a total of 2 operations.
    Example 2:
    
    >>> maxOperations(nums = [3,1,3,4,3], k = 6)
    >>> 1
    Explanation: Starting with nums = [3,1,3,4,3]:
    - Remove the first two 3's, then nums = [1,4,3]
    There are no more pairs that sum up to 6, hence a total of 1 operation.
    """
def concatenatedBinary(n: int) -> int:
    """
    Given an integer n, return the decimal value of the binary string formed by concatenating the binary representations of 1 to n in order, modulo 109 + 7.
    
    Example 1:
    
    >>> concatenatedBinary(n = 1)
    >>> 1
    Explanation: "1" in binary corresponds to the decimal value 1.
    
    Example 2:
    
    >>> concatenatedBinary(n = 3)
    >>> 27
    Explanation: In binary, 1, 2, and 3 corresponds to "1", "10", and "11".
    After concatenating them, we have "11011", which corresponds to the decimal value 27.
    
    Example 3:
    
    >>> concatenatedBinary(n = 12)
    >>> 505379714
    Explanation: The concatenation results in "1101110010111011110001001101010111100".
    The decimal value of that is 118505380540.
    After modulo 109 + 7, the result is 505379714.
    """
def minimumIncompatibility(nums: List[int], k: int) -> int:
    """
    You are given an integer array nums​​​ and an integer k. You are asked to distribute this array into k subsets of equal size such that there are no two equal elements in the same subset.
    A subset's incompatibility is the difference between the maximum and minimum elements in that array.
    Return the minimum possible sum of incompatibilities of the k subsets after distributing the array optimally, or return -1 if it is not possible.
    A subset is a group integers that appear in the array with no particular order.
    
    Example 1:
    
    >>> minimumIncompatibility(nums = [1,2,1,4], k = 2)
    >>> 4
    Explanation: The optimal distribution of subsets is [1,2] and [1,4].
    The incompatibility is (2-1) + (4-1) = 4.
    Note that [1,1] and [2,4] would result in a smaller sum, but the first subset contains 2 equal elements.
    Example 2:
    
    >>> minimumIncompatibility(nums = [6,3,8,1,3,1,2,2], k = 4)
    >>> 6
    Explanation: The optimal distribution of subsets is [1,2], [2,3], [6,8], and [1,3].
    The incompatibility is (2-1) + (3-2) + (8-6) + (3-1) = 6.
    
    Example 3:
    
    >>> minimumIncompatibility(nums = [5,3,3,6,3,3], k = 3)
    >>> -1
    Explanation: It is impossible to distribute nums into 3 subsets where no two elements are equal in the same subset.
    """
def longestPalindromeSubseq(s: str) -> int:
    """
    A subsequence of a string s is considered a good palindromic subsequence if:
    
    It is a subsequence of s.
    It is a palindrome (has the same value if reversed).
    It has an even length.
    No two consecutive characters are equal, except the two middle ones.
    
    For example, if s = "abcabcabb", then "abba" is considered a good palindromic subsequence, while "bcb" (not even length) and "bbbb" (has equal consecutive characters) are not.
    Given a string s, return the length of the longest good palindromic subsequence in s.
    
    Example 1:
    
    >>> longestPalindromeSubseq(s = "bbabab")
    >>> 4
    Explanation: The longest good palindromic subsequence of s is "baab".
    
    Example 2:
    
    >>> longestPalindromeSubseq(s = "dcbccacdb")
    >>> 4
    Explanation: The longest good palindromic subsequence of s is "dccd".
    """
def countConsistentStrings(allowed: str, words: List[str]) -> int:
    """
    You are given a string allowed consisting of distinct characters and an array of strings words. A string is consistent if all characters in the string appear in the string allowed.
    Return the number of consistent strings in the array words.
    
    Example 1:
    
    >>> countConsistentStrings(allowed = "ab", words = ["ad","bd","aaab","baa","badab"])
    >>> 2
    Explanation: Strings "aaab" and "baa" are consistent since they only contain characters 'a' and 'b'.
    
    Example 2:
    
    >>> countConsistentStrings(allowed = "abc", words = ["a","b","c","ab","ac","bc","abc"])
    >>> 7
    Explanation: All strings are consistent.
    
    Example 3:
    
    >>> countConsistentStrings(allowed = "cad", words = ["cc","acd","b","ba","bac","bad","ac","d"])
    >>> 4
    Explanation: Strings "cc", "acd", "ac", and "d" are consistent.
    """
def getSumAbsoluteDifferences(nums: List[int]) -> List[int]:
    """
    You are given an integer array nums sorted in non-decreasing order.
    Build and return an integer array result with the same length as nums such that result[i] is equal to the summation of absolute differences between nums[i] and all the other elements in the array.
    In other words, result[i] is equal to sum(|nums[i]-nums[j]|) where 0 <= j < nums.length and j != i (0-indexed).
    
    Example 1:
    
    >>> getSumAbsoluteDifferences(nums = [2,3,5])
    >>> [4,3,5]
    Explanation: Assuming the arrays are 0-indexed, then
    result[0] = |2-2| + |2-3| + |2-5| = 0 + 1 + 3 = 4,
    result[1] = |3-2| + |3-3| + |3-5| = 1 + 0 + 2 = 3,
    result[2] = |5-2| + |5-3| + |5-5| = 3 + 2 + 0 = 5.
    
    Example 2:
    
    >>> getSumAbsoluteDifferences(nums = [1,4,6,8,10])
    >>> [24,15,13,15,21]
    """
def stoneGameVI(aliceValues: List[int], bobValues: List[int]) -> int:
    """
    Alice and Bob take turns playing a game, with Alice starting first.
    There are n stones in a pile. On each player's turn, they can remove a stone from the pile and receive points based on the stone's value. Alice and Bob may value the stones differently.
    You are given two integer arrays of length n, aliceValues and bobValues. Each aliceValues[i] and bobValues[i] represents how Alice and Bob, respectively, value the ith stone.
    The winner is the person with the most points after all the stones are chosen. If both players have the same amount of points, the game results in a draw. Both players will play optimally. Both players know the other's values.
    Determine the result of the game, and:
    
    If Alice wins, return 1.
    If Bob wins, return -1.
    If the game results in a draw, return 0.
    
    
    Example 1:
    
    >>> stoneGameVI(aliceValues = [1,3], bobValues = [2,1])
    >>> 1
    Explanation:
    If Alice takes stone 1 (0-indexed) first, Alice will receive 3 points.
    Bob can only choose stone 0, and will only receive 2 points.
    Alice wins.
    
    Example 2:
    
    >>> stoneGameVI(aliceValues = [1,2], bobValues = [3,1])
    >>> 0
    Explanation:
    If Alice takes stone 0, and Bob takes stone 1, they will both have 1 point.
    Draw.
    
    Example 3:
    
    >>> stoneGameVI(aliceValues = [2,4,3], bobValues = [1,6,7])
    >>> -1
    Explanation:
    Regardless of how Alice plays, Bob will be able to have more points than Alice.
    For example, if Alice takes stone 1, Bob can take stone 2, and Alice takes stone 0, Alice will have 6 points to Bob's 7.
    Bob wins.
    """
def boxDelivering(boxes: List[List[int]], portsCount: int, maxBoxes: int, maxWeight: int) -> int:
    """
    You have the task of delivering some boxes from storage to their ports using only one ship. However, this ship has a limit on the number of boxes and the total weight that it can carry.
    You are given an array boxes, where boxes[i] = [ports​​i​, weighti], and three integers portsCount, maxBoxes, and maxWeight.
    
    ports​​i is the port where you need to deliver the ith box and weightsi is the weight of the ith box.
    portsCount is the number of ports.
    maxBoxes and maxWeight are the respective box and weight limits of the ship.
    
    The boxes need to be delivered in the order they are given. The ship will follow these steps:
    
    The ship will take some number of boxes from the boxes queue, not violating the maxBoxes and maxWeight constraints.
    For each loaded box in order, the ship will make a trip to the port the box needs to be delivered to and deliver it. If the ship is already at the correct port, no trip is needed, and the box can immediately be delivered.
    The ship then makes a return trip to storage to take more boxes from the queue.
    
    The ship must end at storage after all the boxes have been delivered.
    Return the minimum number of trips the ship needs to make to deliver all boxes to their respective ports.
    
    Example 1:
    
    >>> boxDelivering(boxes = [[1,1],[2,1],[1,1]], portsCount = 2, maxBoxes = 3, maxWeight = 3)
    >>> 4
    Explanation: The optimal strategy is as follows:
    - The ship takes all the boxes in the queue, goes to port 1, then port 2, then port 1 again, then returns to storage. 4 trips.
    So the total number of trips is 4.
    Note that the first and third boxes cannot be delivered together because the boxes need to be delivered in order (i.e. the second box needs to be delivered at port 2 before the third box).
    
    Example 2:
    
    >>> boxDelivering(boxes = [[1,2],[3,3],[3,1],[3,1],[2,4]], portsCount = 3, maxBoxes = 3, maxWeight = 6)
    >>> 6
    Explanation: The optimal strategy is as follows:
    - The ship takes the first box, goes to port 1, then returns to storage. 2 trips.
    - The ship takes the second, third and fourth boxes, goes to port 3, then returns to storage. 2 trips.
    - The ship takes the fifth box, goes to port 2, then returns to storage. 2 trips.
    So the total number of trips is 2 + 2 + 2 = 6.
    
    Example 3:
    
    >>> boxDelivering(boxes = [[1,4],[1,2],[2,1],[2,1],[3,2],[3,4]], portsCount = 3, maxBoxes = 6, maxWeight = 7)
    >>> 6
    Explanation: The optimal strategy is as follows:
    - The ship takes the first and second boxes, goes to port 1, then returns to storage. 2 trips.
    - The ship takes the third and fourth boxes, goes to port 2, then returns to storage. 2 trips.
    - The ship takes the fifth and sixth boxes, goes to port 3, then returns to storage. 2 trips.
    So the total number of trips is 2 + 2 + 2 = 6.
    """
def numberOfMatches(n: int) -> int:
    """
    You are given an integer n, the number of teams in a tournament that has strange rules:
    
    If the current number of teams is even, each team gets paired with another team. A total of n / 2 matches are played, and n / 2 teams advance to the next round.
    If the current number of teams is odd, one team randomly advances in the tournament, and the rest gets paired. A total of (n - 1) / 2 matches are played, and (n - 1) / 2 + 1 teams advance to the next round.
    
    Return the number of matches played in the tournament until a winner is decided.
    
    Example 1:
    
    >>> numberOfMatches(n = 7)
    >>> 6
    Explanation: Details of the tournament:
    - 1st Round: Teams = 7, Matches = 3, and 4 teams advance.
    - 2nd Round: Teams = 4, Matches = 2, and 2 teams advance.
    - 3rd Round: Teams = 2, Matches = 1, and 1 team is declared the winner.
    Total number of matches = 3 + 2 + 1 = 6.
    
    Example 2:
    
    >>> numberOfMatches(n = 14)
    >>> 13
    Explanation: Details of the tournament:
    - 1st Round: Teams = 14, Matches = 7, and 7 teams advance.
    - 2nd Round: Teams = 7, Matches = 3, and 4 teams advance.
    - 3rd Round: Teams = 4, Matches = 2, and 2 teams advance.
    - 4th Round: Teams = 2, Matches = 1, and 1 team is declared the winner.
    Total number of matches = 7 + 3 + 2 + 1 = 13.
    """
def minPartitions(n: str) -> int:
    """
    A decimal number is called deci-binary if each of its digits is either 0 or 1 without any leading zeros. For example, 101 and 1100 are deci-binary, while 112 and 3001 are not.
    Given a string n that represents a positive decimal integer, return the minimum number of positive deci-binary numbers needed so that they sum up to n.
    
    Example 1:
    
    >>> minPartitions(n = "32")
    >>> 3
    Explanation: 10 + 11 + 11 = 32
    
    Example 2:
    
    >>> minPartitions(n = "82734")
    >>> 8
    
    Example 3:
    
    >>> minPartitions(n = "27346209830709182346")
    >>> 9
    """
def stoneGameVII(stones: List[int]) -> int:
    """
    Alice and Bob take turns playing a game, with Alice starting first.
    There are n stones arranged in a row. On each player's turn, they can remove either the leftmost stone or the rightmost stone from the row and receive points equal to the sum of the remaining stones' values in the row. The winner is the one with the higher score when there are no stones left to remove.
    Bob found that he will always lose this game (poor Bob, he always loses), so he decided to minimize the score's difference. Alice's goal is to maximize the difference in the score.
    Given an array of integers stones where stones[i] represents the value of the ith stone from the left, return the difference in Alice and Bob's score if they both play optimally.
    
    Example 1:
    
    >>> stoneGameVII(stones = [5,3,1,4,2])
    >>> 6
    Explanation:
    - Alice removes 2 and gets 5 + 3 + 1 + 4 = 13 points. Alice = 13, Bob = 0, stones = [5,3,1,4].
    - Bob removes 5 and gets 3 + 1 + 4 = 8 points. Alice = 13, Bob = 8, stones = [3,1,4].
    - Alice removes 3 and gets 1 + 4 = 5 points. Alice = 18, Bob = 8, stones = [1,4].
    - Bob removes 1 and gets 4 points. Alice = 18, Bob = 12, stones = [4].
    - Alice removes 4 and gets 0 points. Alice = 18, Bob = 12, stones = [].
    The score difference is 18 - 12 = 6.
    
    Example 2:
    
    >>> stoneGameVII(stones = [7,90,5,1,100,10,10,2])
    >>> 122
    """
def maxHeight(cuboids: List[List[int]]) -> int:
    """
    Given n cuboids where the dimensions of the ith cuboid is cuboids[i] = [widthi, lengthi, heighti] (0-indexed). Choose a subset of cuboids and place them on each other.
    You can place cuboid i on cuboid j if widthi <= widthj and lengthi <= lengthj and heighti <= heightj. You can rearrange any cuboid's dimensions by rotating it to put it on another cuboid.
    Return the maximum height of the stacked cuboids.
    
    Example 1:
    
    
    >>> maxHeight(cuboids = [[50,45,20],[95,37,53],[45,23,12]])
    >>> 190
    Explanation:
    Cuboid 1 is placed on the bottom with the 53x37 side facing down with height 95.
    Cuboid 0 is placed next with the 45x20 side facing down with height 50.
    Cuboid 2 is placed next with the 23x12 side facing down with height 45.
    The total height is 95 + 50 + 45 = 190.
    
    Example 2:
    
    >>> maxHeight(cuboids = [[38,25,45],[76,35,3]])
    >>> 76
    Explanation:
    You can't place any of the cuboids on the other.
    We choose cuboid 1 and rotate it so that the 35x3 side is facing down and its height is 76.
    
    Example 3:
    
    >>> maxHeight(cuboids = [[7,11,17],[7,17,11],[11,7,17],[11,17,7],[17,7,11],[17,11,7]])
    >>> 102
    Explanation:
    After rearranging the cuboids, you can see that all cuboids have the same dimension.
    You can place the 11x7 side down on all cuboids so their heights are 17.
    The maximum height of stacked cuboids is 6 * 17 = 102.
    """
def waysToDistribute(n: int, k: int) -> int:
    """
    There are n unique candies (labeled 1 through n) and k bags. You are asked to distribute all the candies into the bags such that every bag has at least one candy.
    There can be multiple ways to distribute the candies. Two ways are considered different if the candies in one bag in the first way are not all in the same bag in the second way. The order of the bags and the order of the candies within each bag do not matter.
    For example, (1), (2,3) and (2), (1,3) are considered different because candies 2 and 3 in the bag (2,3) in the first way are not in the same bag in the second way (they are split between the bags (2) and (1,3)). However, (1), (2,3) and (3,2), (1) are considered the same because the candies in each bag are all in the same bags in both ways.
    Given two integers, n and k, return the number of different ways to distribute the candies. As the answer may be too large, return it modulo 109 + 7.
    
    Example 1:
    
    
    >>> waysToDistribute(n = 3, k = 2)
    >>> 3
    Explanation: You can distribute 3 candies into 2 bags in 3 ways:
    (1), (2,3)
    (1,2), (3)
    (1,3), (2)
    
    Example 2:
    
    >>> waysToDistribute(n = 4, k = 2)
    >>> 7
    Explanation: You can distribute 4 candies into 2 bags in 7 ways:
    (1), (2,3,4)
    (1,2), (3,4)
    (1,3), (2,4)
    (1,4), (2,3)
    (1,2,3), (4)
    (1,2,4), (3)
    (1,3,4), (2)
    
    Example 3:
    
    >>> waysToDistribute(n = 20, k = 5)
    >>> 206085257
    Explanation: You can distribute 20 candies into 5 bags in 1881780996 ways. 1881780996 modulo 109 + 7 = 206085257.
    """
def reformatNumber(number: str) -> str:
    """
    You are given a phone number as a string number. number consists of digits, spaces ' ', and/or dashes '-'.
    You would like to reformat the phone number in a certain manner. Firstly, remove all spaces and dashes. Then, group the digits from left to right into blocks of length 3 until there are 4 or fewer digits. The final digits are then grouped as follows:
    
    2 digits: A single block of length 2.
    3 digits: A single block of length 3.
    4 digits: Two blocks of length 2 each.
    
    The blocks are then joined by dashes. Notice that the reformatting process should never produce any blocks of length 1 and produce at most two blocks of length 2.
    Return the phone number after formatting.
    
    Example 1:
    
    >>> reformatNumber(number = "1-23-45 6")
    >>> "123-456"
    Explanation: The digits are "123456".
    Step 1: There are more than 4 digits, so group the next 3 digits. The 1st block is "123".
    Step 2: There are 3 digits remaining, so put them in a single block of length 3. The 2nd block is "456".
    Joining the blocks gives "123-456".
    
    Example 2:
    
    >>> reformatNumber(number = "123 4-567")
    >>> "123-45-67"
    Explanation: The digits are "1234567".
    Step 1: There are more than 4 digits, so group the next 3 digits. The 1st block is "123".
    Step 2: There are 4 digits left, so split them into two blocks of length 2. The blocks are "45" and "67".
    Joining the blocks gives "123-45-67".
    
    Example 3:
    
    >>> reformatNumber(number = "123 4-5678")
    >>> "123-456-78"
    Explanation: The digits are "12345678".
    Step 1: The 1st block is "123".
    Step 2: The 2nd block is "456".
    Step 3: There are 2 digits left, so put them in a single block of length 2. The 3rd block is "78".
    Joining the blocks gives "123-456-78".
    """
def maximumUniqueSubarray(nums: List[int]) -> int:
    """
    You are given an array of positive integers nums and want to erase a subarray containing unique elements. The score you get by erasing the subarray is equal to the sum of its elements.
    Return the maximum score you can get by erasing exactly one subarray.
    An array b is called to be a subarray of a if it forms a contiguous subsequence of a, that is, if it is equal to a[l],a[l+1],...,a[r] for some (l,r).
    
    Example 1:
    
    >>> maximumUniqueSubarray(nums = [4,2,4,5,6])
    >>> 17
    Explanation: The optimal subarray here is [2,4,5,6].
    
    Example 2:
    
    >>> maximumUniqueSubarray(nums = [5,2,1,2,5,2,1,2,5])
    >>> 8
    Explanation: The optimal subarray here is [5,2,1] or [1,2,5].
    """
def maxResult(nums: List[int], k: int) -> int:
    """
    You are given a 0-indexed integer array nums and an integer k.
    You are initially standing at index 0. In one move, you can jump at most k steps forward without going outside the boundaries of the array. That is, you can jump from index i to any index in the range [i + 1, min(n - 1, i + k)] inclusive.
    You want to reach the last index of the array (index n - 1). Your score is the sum of all nums[j] for each index j you visited in the array.
    Return the maximum score you can get.
    
    Example 1:
    
    >>> maxResult(nums = [1,-1,-2,4,-7,3], k = 2)
    >>> 7
    Explanation: You can choose your jumps forming the subsequence [1,-1,4,3] (underlined above). The sum is 7.
    
    Example 2:
    
    >>> maxResult(nums = [10,-5,-2,4,0,3], k = 3)
    >>> 17
    Explanation: You can choose your jumps forming the subsequence [10,4,3] (underlined above). The sum is 17.
    
    Example 3:
    
    >>> maxResult(nums = [1,-5,-20,4,-1,3,-6,-3], k = 2)
    >>> 0
    """