ShwStone/humaneval-leetcode huggingface dataset:
def alternateDigitSum(n: int) -> int:
    """
    You are given a positive integer n. Each digit of n has a sign according to the following rules:
    
    The most significant digit is assigned a positive sign.
    Each other digit has an opposite sign to its adjacent digits.
    
    Return the sum of all digits with their corresponding sign.
    
    Example 1:
    
    >>> alternateDigitSum(n = 521)
    >>> 4
    Explanation: (+5) + (-2) + (+1) = 4.
    
    Example 2:
    
    >>> alternateDigitSum(n = 111)
    >>> 1
    Explanation: (+1) + (-1) + (+1) = 1.
    
    Example 3:
    
    >>> alternateDigitSum(n = 886996)
    >>> 0
    Explanation: (+8) + (-8) + (+6) + (-9) + (+9) + (-6) = 0.
    """
def sortTheStudents(score: List[List[int]], k: int) -> List[List[int]]:
    """
    There is a class with m students and n exams. You are given a 0-indexed m x n integer matrix score, where each row represents one student and score[i][j] denotes the score the ith student got in the jth exam. The matrix score contains distinct integers only.
    You are also given an integer k. Sort the students (i.e., the rows of the matrix) by their scores in the kth (0-indexed) exam from the highest to the lowest.
    Return the matrix after sorting it.
    
    Example 1:
    
    
    >>> sortTheStudents(score = [[10,6,9,1],[7,5,11,2],[4,8,3,15]], k = 2)
    >>> [[7,5,11,2],[10,6,9,1],[4,8,3,15]]
    Explanation: In the above diagram, S denotes the student, while E denotes the exam.
    - The student with index 1 scored 11 in exam 2, which is the highest score, so they got first place.
    - The student with index 0 scored 9 in exam 2, which is the second highest score, so they got second place.
    - The student with index 2 scored 3 in exam 2, which is the lowest score, so they got third place.
    
    Example 2:
    
    
    >>> sortTheStudents(score = [[3,4],[5,6]], k = 0)
    >>> [[5,6],[3,4]]
    Explanation: In the above diagram, S denotes the student, while E denotes the exam.
    - The student with index 1 scored 5 in exam 0, which is the highest score, so they got first place.
    - The student with index 0 scored 3 in exam 0, which is the lowest score, so they got second place.
    """
def makeStringsEqual(s: str, target: str) -> bool:
    """
    You are given two 0-indexed binary strings s and target of the same length n. You can do the following operation on s any number of times:
    
    Choose two different indices i and j where 0 <= i, j < n.
    Simultaneously, replace s[i] with (s[i] OR s[j]) and s[j] with (s[i] XOR s[j]).
    
    For example, if s = "0110", you can choose i = 0 and j = 2, then simultaneously replace s[0] with (s[0] OR s[2] = 0 OR 1 = 1), and s[2] with (s[0] XOR s[2] = 0 XOR 1 = 1), so we will have s = "1110".
    Return true if you can make the string s equal to target, or false otherwise.
    
    Example 1:
    
    >>> makeStringsEqual(s = "1010", target = "0110")
    >>> true
    Explanation: We can do the following operations:
    - Choose i = 2 and j = 0. We have now s = "0010".
    - Choose i = 2 and j = 1. We have now s = "0110".
    Since we can make s equal to target, we return true.
    
    Example 2:
    
    >>> makeStringsEqual(s = "11", target = "00")
    >>> false
    Explanation: It is not possible to make s equal to target with any number of operations.
    """
def minCost(nums: List[int], k: int) -> int:
    """
    You are given an integer array nums and an integer k.
    Split the array into some number of non-empty subarrays. The cost of a split is the sum of the importance value of each subarray in the split.
    Let trimmed(subarray) be the version of the subarray where all numbers which appear only once are removed.
    
    For example, trimmed([3,1,2,4,3,4]) = [3,4,3,4].
    
    The importance value of a subarray is k + trimmed(subarray).length.
    
    For example, if a subarray is [1,2,3,3,3,4,4], then trimmed([1,2,3,3,3,4,4]) = [3,3,3,4,4].The importance value of this subarray will be k + 5.
    
    Return the minimum possible cost of a split of nums.
    A subarray is a contiguous non-empty sequence of elements within an array.
    
    Example 1:
    
    >>> minCost(nums = [1,2,1,2,1,3,3], k = 2)
    >>> 8
    Explanation: We split nums to have two subarrays: [1,2], [1,2,1,3,3].
    The importance value of [1,2] is 2 + (0) = 2.
    The importance value of [1,2,1,3,3] is 2 + (2 + 2) = 6.
    The cost of the split is 2 + 6 = 8. It can be shown that this is the minimum possible cost among all the possible splits.
    
    Example 2:
    
    >>> minCost(nums = [1,2,1,2,1], k = 2)
    >>> 6
    Explanation: We split nums to have two subarrays: [1,2], [1,2,1].
    The importance value of [1,2] is 2 + (0) = 2.
    The importance value of [1,2,1] is 2 + (2) = 4.
    The cost of the split is 2 + 4 = 6. It can be shown that this is the minimum possible cost among all the possible splits.
    
    Example 3:
    
    >>> minCost(nums = [1,2,1,2,1], k = 5)
    >>> 10
    Explanation: We split nums to have one subarray: [1,2,1,2,1].
    The importance value of [1,2,1,2,1] is 5 + (3 + 2) = 10.
    The cost of the split is 10. It can be shown that this is the minimum possible cost among all the possible splits.
    """
def maxPrice(items: List[List[int]], capacity: int) -> float:
    """
    You are given a 2D integer array items where items[i] = [pricei, weighti] denotes the price and weight of the ith item, respectively.
    You are also given a positive integer capacity.
    Each item can be divided into two items with ratios part1 and part2, where part1 + part2 == 1.
    
    The weight of the first item is weighti * part1 and the price of the first item is pricei * part1.
    Similarly, the weight of the second item is weighti * part2 and the price of the second item is pricei * part2.
    
    Return the maximum total price to fill a bag of capacity capacity with given items. If it is impossible to fill a bag return -1. Answers within 10-5 of the actual answer will be considered accepted.
    
    Example 1:
    
    >>> maxPrice(items = [[50,1],[10,8]], capacity = 5)
    >>> 55.00000
    Explanation:
    We divide the 2nd item into two parts with part1 = 0.5 and part2 = 0.5.
    The price and weight of the 1st item are 5, 4. And similarly, the price and the weight of the 2nd item are 5, 4.
    The array items after operation becomes [[50,1],[5,4],[5,4]].
    To fill a bag with capacity 5 we take the 1st element with a price of 50 and the 2nd element with a price of 5.
    It can be proved that 55.0 is the maximum total price that we can achieve.
    
    Example 2:
    
    >>> maxPrice(items = [[100,30]], capacity = 50)
    >>> -1.00000
    Explanation: It is impossible to fill a bag with the given item.
    """
def distinctIntegers(n: int) -> int:
    """
    You are given a positive integer n, that is initially placed on a board. Every day, for 109 days, you perform the following procedure:
    
    For each number x present on the board, find all numbers 1 <= i <= n such that x % i == 1.
    Then, place those numbers on the board.
    
    Return the number of distinct integers present on the board after 109 days have elapsed.
    Note:
    
    Once a number is placed on the board, it will remain on it until the end.
    % stands for the modulo operation. For example, 14 % 3 is 2.
    
    
    Example 1:
    
    >>> distinctIntegers(n = 5)
    >>> 4
    Explanation: Initially, 5 is present on the board.
    The next day, 2 and 4 will be added since 5 % 2 == 1 and 5 % 4 == 1.
    After that day, 3 will be added to the board because 4 % 3 == 1.
    At the end of a billion days, the distinct numbers on the board will be 2, 3, 4, and 5.
    
    Example 2:
    
    >>> distinctIntegers(n = 3)
    >>> 2
    Explanation:
    Since 3 % 2 == 1, 2 will be added to the board.
    After a billion days, the only two distinct numbers on the board are 2 and 3.
    """
def putMarbles(weights: List[int], k: int) -> int:
    """
    You have k bags. You are given a 0-indexed integer array weights where weights[i] is the weight of the ith marble. You are also given the integer k.
    Divide the marbles into the k bags according to the following rules:
    
    No bag is empty.
    If the ith marble and jth marble are in a bag, then all marbles with an index between the ith and jth indices should also be in that same bag.
    If a bag consists of all the marbles with an index from i to j inclusively, then the cost of the bag is weights[i] + weights[j].
    
    The score after distributing the marbles is the sum of the costs of all the k bags.
    Return the difference between the maximum and minimum scores among marble distributions.
    
    Example 1:
    
    >>> putMarbles(weights = [1,3,5,1], k = 2)
    >>> 4
    Explanation:
    The distribution [1],[3,5,1] results in the minimal score of (1+1) + (3+1) = 6.
    The distribution [1,3],[5,1], results in the maximal score of (1+3) + (5+1) = 10.
    Thus, we return their difference 10 - 6 = 4.
    
    Example 2:
    
    >>> putMarbles(weights = [1, 3], k = 2)
    >>> 0
    Explanation: The only distribution possible is [1],[3].
    Since both the maximal and minimal score are the same, we return 0.
    """
def countQuadruplets(nums: List[int]) -> int:
    """
    Given a 0-indexed integer array nums of size n containing all numbers from 1 to n, return the number of increasing quadruplets.
    A quadruplet (i, j, k, l) is increasing if:
    
    0 <= i < j < k < l < n, and
    nums[i] < nums[k] < nums[j] < nums[l].
    
    
    Example 1:
    
    >>> countQuadruplets(nums = [1,3,2,4,5])
    >>> 2
    Explanation:
    - When i = 0, j = 1, k = 2, and l = 3, nums[i] < nums[k] < nums[j] < nums[l].
    - When i = 0, j = 1, k = 2, and l = 4, nums[i] < nums[k] < nums[j] < nums[l].
    There are no other quadruplets, so we return 2.
    
    Example 2:
    
    >>> countQuadruplets(nums = [1,2,3,4])
    >>> 0
    Explanation: There exists only one quadruplet with i = 0, j = 1, k = 2, l = 3, but since nums[j] < nums[k], we return 0.
    """
def separateDigits(nums: List[int]) -> List[int]:
    """
    Given an array of positive integers nums, return an array answer that consists of the digits of each integer in nums after separating them in the same order they appear in nums.
    To separate the digits of an integer is to get all the digits it has in the same order.
    
    For example, for the integer 10921, the separation of its digits is [1,0,9,2,1].
    
    
    Example 1:
    
    >>> separateDigits(nums = [13,25,83,77])
    >>> [1,3,2,5,8,3,7,7]
    Explanation:
    - The separation of 13 is [1,3].
    - The separation of 25 is [2,5].
    - The separation of 83 is [8,3].
    - The separation of 77 is [7,7].
    answer = [1,3,2,5,8,3,7,7]. Note that answer contains the separations in the same order.
    
    Example 2:
    
    >>> separateDigits(nums = [7,1,3,9])
    >>> [7,1,3,9]
    Explanation: The separation of each integer in nums is itself.
    answer = [7,1,3,9].
    """
def maxCount(banned: List[int], n: int, maxSum: int) -> int:
    """
    You are given an integer array banned and two integers n and maxSum. You are choosing some number of integers following the below rules:
    
    The chosen integers have to be in the range [1, n].
    Each integer can be chosen at most once.
    The chosen integers should not be in the array banned.
    The sum of the chosen integers should not exceed maxSum.
    
    Return the maximum number of integers you can choose following the mentioned rules.
    
    Example 1:
    
    >>> maxCount(banned = [1,6,5], n = 5, maxSum = 6)
    >>> 2
    Explanation: You can choose the integers 2 and 4.
    2 and 4 are from the range [1, 5], both did not appear in banned, and their sum is 6, which did not exceed maxSum.
    
    Example 2:
    
    >>> maxCount(banned = [1,2,3,4,5,6,7], n = 8, maxSum = 1)
    >>> 0
    Explanation: You cannot choose any integer while following the mentioned conditions.
    
    Example 3:
    
    >>> maxCount(banned = [11], n = 7, maxSum = 50)
    >>> 7
    Explanation: You can choose the integers 1, 2, 3, 4, 5, 6, and 7.
    They are from the range [1, 7], all did not appear in banned, and their sum is 28, which did not exceed maxSum.
    """
def maximizeWin(prizePositions: List[int], k: int) -> int:
    """
    There are some prizes on the X-axis. You are given an integer array prizePositions that is sorted in non-decreasing order, where prizePositions[i] is the position of the ith prize. There could be different prizes at the same position on the line. You are also given an integer k.
    You are allowed to select two segments with integer endpoints. The length of each segment must be k. You will collect all prizes whose position falls within at least one of the two selected segments (including the endpoints of the segments). The two selected segments may intersect.
    
    For example if k = 2, you can choose segments [1, 3] and [2, 4], and you will win any prize i that satisfies 1 <= prizePositions[i] <= 3 or 2 <= prizePositions[i] <= 4.
    
    Return the maximum number of prizes you can win if you choose the two segments optimally.
    
    Example 1:
    
    >>> maximizeWin(prizePositions = [1,1,2,2,3,3,5], k = 2)
    >>> 7
    Explanation: In this example, you can win all 7 prizes by selecting two segments [1, 3] and [3, 5].
    
    Example 2:
    
    >>> maximizeWin(prizePositions = [1,2,3,4], k = 0)
    >>> 2
    Explanation: For this example, one choice for the segments is [3, 3] and [4, 4], and you will be able to get 2 prizes.
    """
def isPossibleToCutPath(grid: List[List[int]]) -> bool:
    """
    You are given a 0-indexed m x n binary matrix grid. You can move from a cell (row, col) to any of the cells (row + 1, col) or (row, col + 1) that has the value 1. The matrix is disconnected if there is no path from (0, 0) to (m - 1, n - 1).
    You can flip the value of at most one (possibly none) cell. You cannot flip the cells (0, 0) and (m - 1, n - 1).
    Return true if it is possible to make the matrix disconnect or false otherwise.
    Note that flipping a cell changes its value from 0 to 1 or from 1 to 0.
    
    Example 1:
    
    
    >>> isPossibleToCutPath(grid = [[1,1,1],[1,0,0],[1,1,1]])
    >>> true
    Explanation: We can change the cell shown in the diagram above. There is no path from (0, 0) to (2, 2) in the resulting grid.
    
    Example 2:
    
    
    >>> isPossibleToCutPath(grid = [[1,1,1],[1,0,1],[1,1,1]])
    >>> false
    Explanation: It is not possible to change at most one cell such that there is not path from (0, 0) to (2, 2).
    """
def maxCount(banned: List[int], n: int, maxSum: int) -> int:
    """
    You are given an integer array banned and two integers n and maxSum. You are choosing some number of integers following the below rules:
    
    The chosen integers have to be in the range [1, n].
    Each integer can be chosen at most once.
    The chosen integers should not be in the array banned.
    The sum of the chosen integers should not exceed maxSum.
    
    Return the maximum number of integers you can choose following the mentioned rules.
    
    Example 1:
    
    >>> maxCount(banned = [1,4,6], n = 6, maxSum = 4)
    >>> 1
    Explanation: You can choose the integer 3.
    3 is in the range [1, 6], and do not appear in banned. The sum of the chosen integers is 3, which does not exceed maxSum.
    
    Example 2:
    
    >>> maxCount(banned = [4,3,5,6], n = 7, maxSum = 18)
    >>> 3
    Explanation: You can choose the integers 1, 2, and 7.
    All these integers are in the range [1, 7], all do not appear in banned, and their sum is 10, which does not exceed maxSum.
    """
def pickGifts(gifts: List[int], k: int) -> int:
    """
    You are given an integer array gifts denoting the number of gifts in various piles. Every second, you do the following:
    
    Choose the pile with the maximum number of gifts.
    If there is more than one pile with the maximum number of gifts, choose any.
    Reduce the number of gifts in the pile to the floor of the square root of the original number of gifts in the pile.
    
    Return the number of gifts remaining after k seconds.
    
    Example 1:
    
    >>> pickGifts(gifts = [25,64,9,4,100], k = 4)
    >>> 29
    Explanation:
    The gifts are taken in the following way:
    - In the first second, the last pile is chosen and 10 gifts are left behind.
    - Then the second pile is chosen and 8 gifts are left behind.
    - After that the first pile is chosen and 5 gifts are left behind.
    - Finally, the last pile is chosen again and 3 gifts are left behind.
    The final remaining gifts are [5,8,9,4,3], so the total number of gifts remaining is 29.
    
    Example 2:
    
    >>> pickGifts(gifts = [1,1,1,1], k = 4)
    >>> 4
    Explanation:
    In this case, regardless which pile you choose, you have to leave behind 1 gift in each pile.
    That is, you can't take any pile with you.
    So, the total gifts remaining are 4.
    """
def vowelStrings(words: List[str], queries: List[List[int]]) -> List[int]:
    """
    You are given a 0-indexed array of strings words and a 2D array of integers queries.
    Each query queries[i] = [li, ri] asks us to find the number of strings present at the indices ranging from li to ri (both inclusive) of words that start and end with a vowel.
    Return an array ans of size queries.length, where ans[i] is the answer to the ith query.
    Note that the vowel letters are 'a', 'e', 'i', 'o', and 'u'.
    
    Example 1:
    
    >>> vowelStrings(words = ["aba","bcb","ece","aa","e"], queries = [[0,2],[1,4],[1,1]])
    >>> [2,3,0]
    Explanation: The strings starting and ending with a vowel are "aba", "ece", "aa" and "e".
    The answer to the query [0,2] is 2 (strings "aba" and "ece").
    to query [1,4] is 3 (strings "ece", "aa", "e").
    to query [1,1] is 0.
    We return [2,3,0].
    
    Example 2:
    
    >>> vowelStrings(words = ["a","e","i"], queries = [[0,2],[0,1],[2,2]])
    >>> [3,2,1]
    Explanation: Every string satisfies the conditions, so we return [3,2,1].
    """
def minCapability(nums: List[int], k: int) -> int:
    """
    There are several consecutive houses along a street, each of which has some money inside. There is also a robber, who wants to steal money from the homes, but he refuses to steal from adjacent homes.
    The capability of the robber is the maximum amount of money he steals from one house of all the houses he robbed.
    You are given an integer array nums representing how much money is stashed in each house. More formally, the ith house from the left has nums[i] dollars.
    You are also given an integer k, representing the minimum number of houses the robber will steal from. It is always possible to steal at least k houses.
    Return the minimum capability of the robber out of all the possible ways to steal at least k houses.
    
    Example 1:
    
    >>> minCapability(nums = [2,3,5,9], k = 2)
    >>> 5
    Explanation:
    There are three ways to rob at least 2 houses:
    - Rob the houses at indices 0 and 2. Capability is max(nums[0], nums[2]) = 5.
    - Rob the houses at indices 0 and 3. Capability is max(nums[0], nums[3]) = 9.
    - Rob the houses at indices 1 and 3. Capability is max(nums[1], nums[3]) = 9.
    Therefore, we return min(5, 9, 9) = 5.
    
    Example 2:
    
    >>> minCapability(nums = [2,7,9,3,1], k = 2)
    >>> 2
    Explanation: There are 7 ways to rob the houses. The way which leads to minimum capability is to rob the house at index 0 and 4. Return max(nums[0], nums[4]) = 2.
    """
def minCost(basket1: List[int], basket2: List[int]) -> int:
    """
    You have two fruit baskets containing n fruits each. You are given two 0-indexed integer arrays basket1 and basket2 representing the cost of fruit in each basket. You want to make both baskets equal. To do so, you can use the following operation as many times as you want:
    
    Chose two indices i and j, and swap the ith fruit of basket1 with the jth fruit of basket2.
    The cost of the swap is min(basket1[i],basket2[j]).
    
    Two baskets are considered equal if sorting them according to the fruit cost makes them exactly the same baskets.
    Return the minimum cost to make both the baskets equal or -1 if impossible.
    
    Example 1:
    
    >>> minCost(basket1 = [4,2,2,2], basket2 = [1,4,1,2])
    >>> 1
    Explanation: Swap index 1 of basket1 with index 0 of basket2, which has cost 1. Now basket1 = [4,1,2,2] and basket2 = [2,4,1,2]. Rearranging both the arrays makes them equal.
    
    Example 2:
    
    >>> minCost(basket1 = [2,3,4,1], basket2 = [3,2,5,1])
    >>> -1
    Explanation: It can be shown that it is impossible to make both the baskets equal.
    """
def findTheArrayConcVal(nums: List[int]) -> int:
    """
    You are given a 0-indexed integer array nums.
    The concatenation of two numbers is the number formed by concatenating their numerals.
    
    For example, the concatenation of 15, 49 is 1549.
    
    The concatenation value of nums is initially equal to 0. Perform this operation until nums becomes empty:
    
    If nums has a size greater than one, add the value of the concatenation of the first and the last element to the concatenation value of nums, and remove those two elements from nums. For example, if the nums was [1, 2, 4, 5, 6], add 16 to the concatenation value.
    If only one element exists in nums, add its value to the concatenation value of nums, then remove it.
    
    Return the concatenation value of nums.
    
    Example 1:
    
    >>> findTheArrayConcVal(nums = [7,52,2,4])
    >>> 596
    Explanation: Before performing any operation, nums is [7,52,2,4] and concatenation value is 0.
     - In the first operation:
    We pick the first element, 7, and the last element, 4.
    Their concatenation is 74, and we add it to the concatenation value, so it becomes equal to 74.
    Then we delete them from nums, so nums becomes equal to [52,2].
     - In the second operation:
    We pick the first element, 52, and the last element, 2.
    Their concatenation is 522, and we add it to the concatenation value, so it becomes equal to 596.
    Then we delete them from the nums, so nums becomes empty.
    Since the concatenation value is 596 so the answer is 596.
    
    Example 2:
    
    >>> findTheArrayConcVal(nums = [5,14,13,8,12])
    >>> 673
    Explanation: Before performing any operation, nums is [5,14,13,8,12] and concatenation value is 0.
     - In the first operation:
    We pick the first element, 5, and the last element, 12.
    Their concatenation is 512, and we add it to the concatenation value, so it becomes equal to 512.
    Then we delete them from the nums, so nums becomes equal to [14,13,8].
     - In the second operation:
    We pick the first element, 14, and the last element, 8.
    Their concatenation is 148, and we add it to the concatenation value, so it becomes equal to 660.
    Then we delete them from the nums, so nums becomes equal to [13].
     - In the third operation:
    nums has only one element, so we pick 13 and add it to the concatenation value, so it becomes equal to 673.
    Then we delete it from nums, so nums become empty.
    Since the concatenation value is 673 so the answer is 673.
    """
def countFairPairs(nums: List[int], lower: int, upper: int) -> int:
    """
    Given a 0-indexed integer array nums of size n and two integers lower and upper, return the number of fair pairs.
    A pair (i, j) is fair if:
    
    0 <= i < j < n, and
    lower <= nums[i] + nums[j] <= upper
    
    
    Example 1:
    
    >>> countFairPairs(nums = [0,1,7,4,4,5], lower = 3, upper = 6)
    >>> 6
    Explanation: There are 6 fair pairs: (0,3), (0,4), (0,5), (1,3), (1,4), and (1,5).
    
    Example 2:
    
    >>> countFairPairs(nums = [1,7,9,2,5], lower = 11, upper = 11)
    >>> 1
    Explanation: There is a single fair pair: (2,3).
    """