ShwStone/humaneval-leetcode huggingface dataset:
def digitCount(num: str) -> bool:
    """
    You are given a 0-indexed string num of length n consisting of digits.
    Return true if for every index i in the range 0 <= i < n, the digit i occurs num[i] times in num, otherwise return false.
    
    Example 1:
    
    >>> digitCount(num = "1210")
    >>> true
    Explanation:
    num[0] = '1'. The digit 0 occurs once in num.
    num[1] = '2'. The digit 1 occurs twice in num.
    num[2] = '1'. The digit 2 occurs once in num.
    num[3] = '0'. The digit 3 occurs zero times in num.
    The condition holds true for every index in "1210", so return true.
    
    Example 2:
    
    >>> digitCount(num = "030")
    >>> false
    Explanation:
    num[0] = '0'. The digit 0 should occur zero times, but actually occurs twice in num.
    num[1] = '3'. The digit 1 should occur three times, but actually occurs zero times in num.
    num[2] = '0'. The digit 2 occurs zero times in num.
    The indices 0 and 1 both violate the condition, so return false.
    """
def largestWordCount(messages: List[str], senders: List[str]) -> str:
    """
    You have a chat log of n messages. You are given two string arrays messages and senders where messages[i] is a message sent by senders[i].
    A message is list of words that are separated by a single space with no leading or trailing spaces. The word count of a sender is the total number of words sent by the sender. Note that a sender may send more than one message.
    Return the sender with the largest word count. If there is more than one sender with the largest word count, return the one with the lexicographically largest name.
    Note:
    
    Uppercase letters come before lowercase letters in lexicographical order.
    "Alice" and "alice" are distinct.
    
    
    Example 1:
    
    >>> largestWordCount(messages = ["Hello userTwooo","Hi userThree","Wonderful day Alice","Nice day userThree"], senders = ["Alice","userTwo","userThree","Alice"])
    >>> "Alice"
    Explanation: Alice sends a total of 2 + 3 = 5 words.
    userTwo sends a total of 2 words.
    userThree sends a total of 3 words.
    Since Alice has the largest word count, we return "Alice".
    
    Example 2:
    
    >>> largestWordCount(messages = ["How is leetcode for everyone","Leetcode is useful for practice"], senders = ["Bob","Charlie"])
    >>> "Charlie"
    Explanation: Bob sends a total of 5 words.
    Charlie sends a total of 5 words.
    Since there is a tie for the largest word count, we return the sender with the lexicographically larger name, Charlie.
    """
def maximumImportance(n: int, roads: List[List[int]]) -> int:
    """
    You are given an integer n denoting the number of cities in a country. The cities are numbered from 0 to n - 1.
    You are also given a 2D integer array roads where roads[i] = [ai, bi] denotes that there exists a bidirectional road connecting cities ai and bi.
    You need to assign each city with an integer value from 1 to n, where each value can only be used once. The importance of a road is then defined as the sum of the values of the two cities it connects.
    Return the maximum total importance of all roads possible after assigning the values optimally.
    
    Example 1:
    
    
    >>> maximumImportance(n = 5, roads = [[0,1],[1,2],[2,3],[0,2],[1,3],[2,4]])
    >>> 43
    Explanation: The figure above shows the country and the assigned values of [2,4,5,3,1].
    - The road (0,1) has an importance of 2 + 4 = 6.
    - The road (1,2) has an importance of 4 + 5 = 9.
    - The road (2,3) has an importance of 5 + 3 = 8.
    - The road (0,2) has an importance of 2 + 5 = 7.
    - The road (1,3) has an importance of 4 + 3 = 7.
    - The road (2,4) has an importance of 5 + 1 = 6.
    The total importance of all roads is 6 + 9 + 8 + 7 + 7 + 6 = 43.
    It can be shown that we cannot obtain a greater total importance than 43.
    
    Example 2:
    
    
    >>> maximumImportance(n = 5, roads = [[0,3],[2,4],[1,3]])
    >>> 20
    Explanation: The figure above shows the country and the assigned values of [4,3,2,5,1].
    - The road (0,3) has an importance of 4 + 5 = 9.
    - The road (2,4) has an importance of 2 + 1 = 3.
    - The road (1,3) has an importance of 3 + 5 = 8.
    The total importance of all roads is 9 + 3 + 8 = 20.
    It can be shown that we cannot obtain a greater total importance than 20.
    """
def rearrangeCharacters(s: str, target: str) -> int:
    """
    You are given two 0-indexed strings s and target. You can take some letters from s and rearrange them to form new strings.
    Return the maximum number of copies of target that can be formed by taking letters from s and rearranging them.
    
    Example 1:
    
    >>> rearrangeCharacters(s = "ilovecodingonleetcode", target = "code")
    >>> 2
    Explanation:
    For the first copy of "code", take the letters at indices 4, 5, 6, and 7.
    For the second copy of "code", take the letters at indices 17, 18, 19, and 20.
    The strings that are formed are "ecod" and "code" which can both be rearranged into "code".
    We can make at most two copies of "code", so we return 2.
    
    Example 2:
    
    >>> rearrangeCharacters(s = "abcba", target = "abc")
    >>> 1
    Explanation:
    We can make one copy of "abc" by taking the letters at indices 0, 1, and 2.
    We can make at most one copy of "abc", so we return 1.
    Note that while there is an extra 'a' and 'b' at indices 3 and 4, we cannot reuse the letter 'c' at index 2, so we cannot make a second copy of "abc".
    
    Example 3:
    
    >>> rearrangeCharacters(s = "abbaccaddaeea", target = "aaaaa")
    >>> 1
    Explanation:
    We can make one copy of "aaaaa" by taking the letters at indices 0, 3, 6, 9, and 12.
    We can make at most one copy of "aaaaa", so we return 1.
    """
def discountPrices(sentence: str, discount: int) -> str:
    """
    A sentence is a string of single-space separated words where each word can contain digits, lowercase letters, and the dollar sign '$'. A word represents a price if it is a sequence of digits preceded by a dollar sign.
    
    For example, "$100", "$23", and "$6" represent prices while "100", "$", and "$1e5" do not.
    
    You are given a string sentence representing a sentence and an integer discount. For each word representing a price, apply a discount of discount% on the price and update the word in the sentence. All updated prices should be represented with exactly two decimal places.
    Return a string representing the modified sentence.
    Note that all prices will contain at most 10 digits.
    
    Example 1:
    
    >>> discountPrices(sentence = "there are $1 $2 and 5$ candies in the shop", discount = 50)
    >>> "there are $0.50 $1.00 and 5$ candies in the shop"
    Explanation:
    The words which represent prices are "$1" and "$2".
    - A 50% discount on "$1" yields "$0.50", so "$1" is replaced by "$0.50".
    - A 50% discount on "$2" yields "$1". Since we need to have exactly 2 decimal places after a price, we replace "$2" with "$1.00".
    
    Example 2:
    
    >>> discountPrices(sentence = "1 2 $3 4 $5 $6 7 8$ $9 $10$", discount = 100)
    >>> "1 2 $0.00 4 $0.00 $0.00 7 8$ $0.00 $10$"
    Explanation:
    Applying a 100% discount on any price will result in 0.
    The words representing prices are "$3", "$5", "$6", and "$9".
    Each of them is replaced by "$0.00".
    """
def totalSteps(nums: List[int]) -> int:
    """
    You are given a 0-indexed integer array nums. In one step, remove all elements nums[i] where nums[i - 1] > nums[i] for all 0 < i < nums.length.
    Return the number of steps performed until nums becomes a non-decreasing array.
    
    Example 1:
    
    >>> totalSteps(nums = [5,3,4,4,7,3,6,11,8,5,11])
    >>> 3
    Explanation: The following are the steps performed:
    - Step 1: [5,3,4,4,7,3,6,11,8,5,11] becomes [5,4,4,7,6,11,11]
    - Step 2: [5,4,4,7,6,11,11] becomes [5,4,7,11,11]
    - Step 3: [5,4,7,11,11] becomes [5,7,11,11]
    [5,7,11,11] is a non-decreasing array. Therefore, we return 3.
    
    Example 2:
    
    >>> totalSteps(nums = [4,5,7,7,13])
    >>> 0
    Explanation: nums is already a non-decreasing array. Therefore, we return 0.
    """
def minimumObstacles(grid: List[List[int]]) -> int:
    """
    You are given a 0-indexed 2D integer array grid of size m x n. Each cell has one of two values:
    
    0 represents an empty cell,
    1 represents an obstacle that may be removed.
    
    You can move up, down, left, or right from and to an empty cell.
    Return the minimum number of obstacles to remove so you can move from the upper left corner (0, 0) to the lower right corner (m - 1, n - 1).
    
    Example 1:
    
    
    >>> minimumObstacles(grid = [[0,1,1],[1,1,0],[1,1,0]])
    >>> 2
    Explanation: We can remove the obstacles at (0, 1) and (0, 2) to create a path from (0, 0) to (2, 2).
    It can be shown that we need to remove at least 2 obstacles, so we return 2.
    Note that there may be other ways to remove 2 obstacles to create a path.
    
    Example 2:
    
    
    >>> minimumObstacles(grid = [[0,1,0,0,0],[0,1,0,1,0],[0,0,0,1,0]])
    >>> 0
    Explanation: We can move from (0, 0) to (2, 4) without removing any obstacles, so we return 0.
    """
def maximumProfit(present: List[int], future: List[int], budget: int) -> int:
    """
    You are given two 0-indexed integer arrays of the same length present and future where present[i] is the current price of the ith stock and future[i] is the price of the ith stock a year in the future. You may buy each stock at most once. You are also given an integer budget representing the amount of money you currently have.
    Return the maximum amount of profit you can make.
    
    Example 1:
    
    >>> maximumProfit(present = [5,4,6,2,3], future = [8,5,4,3,5], budget = 10)
    >>> 6
    Explanation: One possible way to maximize your profit is to:
    Buy the 0th, 3rd, and 4th stocks for a total of 5 + 2 + 3 = 10.
    Next year, sell all three stocks for a total of 8 + 3 + 5 = 16.
    The profit you made is 16 - 10 = 6.
    It can be shown that the maximum profit you can make is 6.
    
    Example 2:
    
    >>> maximumProfit(present = [2,2,5], future = [3,4,10], budget = 6)
    >>> 5
    Explanation: The only possible way to maximize your profit is to:
    Buy the 2nd stock, and make a profit of 10 - 5 = 5.
    It can be shown that the maximum profit you can make is 5.
    
    Example 3:
    
    >>> maximumProfit(present = [3,3,12], future = [0,3,15], budget = 10)
    >>> 0
    Explanation: One possible way to maximize your profit is to:
    Buy the 1st stock, and make a profit of 3 - 3 = 0.
    It can be shown that the maximum profit you can make is 0.
    """
def minMaxGame(nums: List[int]) -> int:
    """
    You are given a 0-indexed integer array nums whose length is a power of 2.
    Apply the following algorithm on nums:
    
    Let n be the length of nums. If n == 1, end the process. Otherwise, create a new 0-indexed integer array newNums of length n / 2.
    For every even index i where 0 <= i < n / 2, assign the value of newNums[i] as min(nums[2 * i], nums[2 * i + 1]).
    For every odd index i where 0 <= i < n / 2, assign the value of newNums[i] as max(nums[2 * i], nums[2 * i + 1]).
    Replace the array nums with newNums.
    Repeat the entire process starting from step 1.
    
    Return the last number that remains in nums after applying the algorithm.
    
    Example 1:
    
    
    >>> minMaxGame(nums = [1,3,5,2,4,8,2,2])
    >>> 1
    Explanation: The following arrays are the results of applying the algorithm repeatedly.
    First: nums = [1,5,4,2]
    Second: nums = [1,4]
    Third: nums = [1]
    1 is the last remaining number, so we return 1.
    
    Example 2:
    
    >>> minMaxGame(nums = [3])
    >>> 3
    Explanation: 3 is already the last remaining number, so we return 3.
    """
def partitionArray(nums: List[int], k: int) -> int:
    """
    You are given an integer array nums and an integer k. You may partition nums into one or more subsequences such that each element in nums appears in exactly one of the subsequences.
    Return the minimum number of subsequences needed such that the difference between the maximum and minimum values in each subsequence is at most k.
    A subsequence is a sequence that can be derived from another sequence by deleting some or no elements without changing the order of the remaining elements.
    
    Example 1:
    
    >>> partitionArray(nums = [3,6,1,2,5], k = 2)
    >>> 2
    Explanation:
    We can partition nums into the two subsequences [3,1,2] and [6,5].
    The difference between the maximum and minimum value in the first subsequence is 3 - 1 = 2.
    The difference between the maximum and minimum value in the second subsequence is 6 - 5 = 1.
    Since two subsequences were created, we return 2. It can be shown that 2 is the minimum number of subsequences needed.
    
    Example 2:
    
    >>> partitionArray(nums = [1,2,3], k = 1)
    >>> 2
    Explanation:
    We can partition nums into the two subsequences [1,2] and [3].
    The difference between the maximum and minimum value in the first subsequence is 2 - 1 = 1.
    The difference between the maximum and minimum value in the second subsequence is 3 - 3 = 0.
    Since two subsequences were created, we return 2. Note that another optimal solution is to partition nums into the two subsequences [1] and [2,3].
    
    Example 3:
    
    >>> partitionArray(nums = [2,2,4,5], k = 0)
    >>> 3
    Explanation:
    We can partition nums into the three subsequences [2,2], [4], and [5].
    The difference between the maximum and minimum value in the first subsequences is 2 - 2 = 0.
    The difference between the maximum and minimum value in the second subsequences is 4 - 4 = 0.
    The difference between the maximum and minimum value in the third subsequences is 5 - 5 = 0.
    Since three subsequences were created, we return 3. It can be shown that 3 is the minimum number of subsequences needed.
    """
def arrayChange(nums: List[int], operations: List[List[int]]) -> List[int]:
    """
    You are given a 0-indexed array nums that consists of n distinct positive integers. Apply m operations to this array, where in the ith operation you replace the number operations[i][0] with operations[i][1].
    It is guaranteed that in the ith operation:
    
    operations[i][0] exists in nums.
    operations[i][1] does not exist in nums.
    
    Return the array obtained after applying all the operations.
    
    Example 1:
    
    >>> arrayChange(nums = [1,2,4,6], operations = [[1,3],[4,7],[6,1]])
    >>> [3,2,7,1]
    Explanation: We perform the following operations on nums:
    - Replace the number 1 with 3. nums becomes [3,2,4,6].
    - Replace the number 4 with 7. nums becomes [3,2,7,6].
    - Replace the number 6 with 1. nums becomes [3,2,7,1].
    We return the final array [3,2,7,1].
    
    Example 2:
    
    >>> arrayChange(nums = [1,2], operations = [[1,3],[2,1],[3,2]])
    >>> [2,1]
    Explanation: We perform the following operations to nums:
    - Replace the number 1 with 3. nums becomes [3,2].
    - Replace the number 2 with 1. nums becomes [3,1].
    - Replace the number 3 with 2. nums becomes [2,1].
    We return the array [2,1].
    """
def minCost(nums: List[int], costs: List[int]) -> int:
    """
    You are given a 0-indexed integer array nums of length n. You are initially standing at index 0. You can jump from index i to index j where i < j if:
    
    nums[i] <= nums[j] and nums[k] < nums[i] for all indexes k in the range i < k < j, or
    nums[i] > nums[j] and nums[k] >= nums[i] for all indexes k in the range i < k < j.
    
    You are also given an integer array costs of length n where costs[i] denotes the cost of jumping to index i.
    Return the minimum cost to jump to the index n - 1.
    
    Example 1:
    
    >>> minCost(nums = [3,2,4,4,1], costs = [3,7,6,4,2])
    >>> 8
    Explanation: You start at index 0.
    - Jump to index 2 with a cost of costs[2] = 6.
    - Jump to index 4 with a cost of costs[4] = 2.
    The total cost is 8. It can be proven that 8 is the minimum cost needed.
    Two other possible paths are from index 0 -> 1 -> 4 and index 0 -> 2 -> 3 -> 4.
    These have a total cost of 9 and 12, respectively.
    
    Example 2:
    
    >>> minCost(nums = [0,1,2], costs = [1,1,1])
    >>> 2
    Explanation: Start at index 0.
    - Jump to index 1 with a cost of costs[1] = 1.
    - Jump to index 2 with a cost of costs[2] = 1.
    The total cost is 2. Note that you cannot jump directly from index 0 to index 2 because nums[0] <= nums[1].
    """
def strongPasswordCheckerII(password: str) -> bool:
    """
    A password is said to be strong if it satisfies all the following criteria:
    
    It has at least 8 characters.
    It contains at least one lowercase letter.
    It contains at least one uppercase letter.
    It contains at least one digit.
    It contains at least one special character. The special characters are the characters in the following string: "!@#$%^&*()-+".
    It does not contain 2 of the same character in adjacent positions (i.e., "aab" violates this condition, but "aba" does not).
    
    Given a string password, return true if it is a strong password. Otherwise, return false.
    
    Example 1:
    
    >>> strongPasswordCheckerII(password = "IloveLe3tcode!")
    >>> true
    Explanation: The password meets all the requirements. Therefore, we return true.
    
    Example 2:
    
    >>> strongPasswordCheckerII(password = "Me+You--IsMyDream")
    >>> false
    Explanation: The password does not contain a digit and also contains 2 of the same character in adjacent positions. Therefore, we return false.
    
    Example 3:
    
    >>> strongPasswordCheckerII(password = "1aB!")
    >>> false
    Explanation: The password does not meet the length requirement. Therefore, we return false.
    """
def successfulPairs(spells: List[int], potions: List[int], success: int) -> List[int]:
    """
    You are given two positive integer arrays spells and potions, of length n and m respectively, where spells[i] represents the strength of the ith spell and potions[j] represents the strength of the jth potion.
    You are also given an integer success. A spell and potion pair is considered successful if the product of their strengths is at least success.
    Return an integer array pairs of length n where pairs[i] is the number of potions that will form a successful pair with the ith spell.
    
    Example 1:
    
    >>> successfulPairs(spells = [5,1,3], potions = [1,2,3,4,5], success = 7)
    >>> [4,0,3]
    Explanation:
    - 0th spell: 5 * [1,2,3,4,5] = [5,10,15,20,25]. 4 pairs are successful.
    - 1st spell: 1 * [1,2,3,4,5] = [1,2,3,4,5]. 0 pairs are successful.
    - 2nd spell: 3 * [1,2,3,4,5] = [3,6,9,12,15]. 3 pairs are successful.
    Thus, [4,0,3] is returned.
    
    Example 2:
    
    >>> successfulPairs(spells = [3,1,2], potions = [8,5,8], success = 16)
    >>> [2,0,2]
    Explanation:
    - 0th spell: 3 * [8,5,8] = [24,15,24]. 2 pairs are successful.
    - 1st spell: 1 * [8,5,8] = [8,5,8]. 0 pairs are successful.
    - 2nd spell: 2 * [8,5,8] = [16,10,16]. 2 pairs are successful.
    Thus, [2,0,2] is returned.
    """
def matchReplacement(s: str, sub: str, mappings: List[List[str]]) -> bool:
    """
    You are given two strings s and sub. You are also given a 2D character array mappings where mappings[i] = [oldi, newi] indicates that you may perform the following operation any number of times:
    
    Replace a character oldi of sub with newi.
    
    Each character in sub cannot be replaced more than once.
    Return true if it is possible to make sub a substring of s by replacing zero or more characters according to mappings. Otherwise, return false.
    A substring is a contiguous non-empty sequence of characters within a string.
    
    Example 1:
    
    >>> matchReplacement(s = "fool3e7bar", sub = "leet", mappings = [["e","3"],["t","7"],["t","8"]])
    >>> true
    Explanation: Replace the first 'e' in sub with '3' and 't' in sub with '7'.
    Now sub = "l3e7" is a substring of s, so we return true.
    Example 2:
    
    >>> matchReplacement(s = "fooleetbar", sub = "f00l", mappings = [["o","0"]])
    >>> false
    Explanation: The string "f00l" is not a substring of s and no replacements can be made.
    Note that we cannot replace '0' with 'o'.
    
    Example 3:
    
    >>> matchReplacement(s = "Fool33tbaR", sub = "leetd", mappings = [["e","3"],["t","7"],["t","8"],["d","b"],["p","b"]])
    >>> true
    Explanation: Replace the first and second 'e' in sub with '3' and 'd' in sub with 'b'.
    Now sub = "l33tb" is a substring of s, so we return true.
    """
def countSubarrays(nums: List[int], k: int) -> int:
    """
    The score of an array is defined as the product of its sum and its length.
    
    For example, the score of [1, 2, 3, 4, 5] is (1 + 2 + 3 + 4 + 5) * 5 = 75.
    
    Given a positive integer array nums and an integer k, return the number of non-empty subarrays of nums whose score is strictly less than k.
    A subarray is a contiguous sequence of elements within an array.
    
    Example 1:
    
    >>> countSubarrays(nums = [2,1,4,3,5], k = 10)
    >>> 6
    Explanation:
    The 6 subarrays having scores less than 10 are:
    - [2] with score 2 * 1 = 2.
    - [1] with score 1 * 1 = 1.
    - [4] with score 4 * 1 = 4.
    - [3] with score 3 * 1 = 3.
    - [5] with score 5 * 1 = 5.
    - [2,1] with score (2 + 1) * 2 = 6.
    Note that subarrays such as [1,4] and [4,3,5] are not considered because their scores are 10 and 36 respectively, while we need scores strictly less than 10.
    Example 2:
    
    >>> countSubarrays(nums = [1,1,1], k = 5)
    >>> 5
    Explanation:
    Every subarray except [1,1,1] has a score less than 5.
    [1,1,1] has a score (1 + 1 + 1) * 3 = 9, which is greater than 5.
    Thus, there are 5 subarrays having scores less than 5.
    """
def calculateTax(brackets: List[List[int]], income: int) -> float:
    """
    You are given a 0-indexed 2D integer array brackets where brackets[i] = [upperi, percenti] means that the ith tax bracket has an upper bound of upperi and is taxed at a rate of percenti. The brackets are sorted by upper bound (i.e. upperi-1 < upperi for 0 < i < brackets.length).
    Tax is calculated as follows:
    
    The first upper0 dollars earned are taxed at a rate of percent0.
    The next upper1 - upper0 dollars earned are taxed at a rate of percent1.
    The next upper2 - upper1 dollars earned are taxed at a rate of percent2.
    And so on.
    
    You are given an integer income representing the amount of money you earned. Return the amount of money that you have to pay in taxes. Answers within 10-5 of the actual answer will be accepted.
    
    Example 1:
    
    >>> calculateTax(brackets = [[3,50],[7,10],[12,25]], income = 10)
    >>> 2.65000
    Explanation:
    Based on your income, you have 3 dollars in the 1st tax bracket, 4 dollars in the 2nd tax bracket, and 3 dollars in the 3rd tax bracket.
    The tax rate for the three tax brackets is 50%, 10%, and 25%, respectively.
    In total, you pay $3 * 50% + $4 * 10% + $3 * 25% = $2.65 in taxes.
    
    Example 2:
    
    >>> calculateTax(brackets = [[1,0],[4,25],[5,50]], income = 2)
    >>> 0.25000
    Explanation:
    Based on your income, you have 1 dollar in the 1st tax bracket and 1 dollar in the 2nd tax bracket.
    The tax rate for the two tax brackets is 0% and 25%, respectively.
    In total, you pay $1 * 0% + $1 * 25% = $0.25 in taxes.
    
    Example 3:
    
    >>> calculateTax(brackets = [[2,50]], income = 0)
    >>> 0.00000
    Explanation:
    You have no income to tax, so you have to pay a total of $0 in taxes.
    """