ShwStone/humaneval-leetcode huggingface dataset:
def findValidSplit(nums: List[int]) -> int:
    """
    You are given a 0-indexed integer array nums of length n.
    A split at an index i where 0 <= i <= n - 2 is called valid if the product of the first i + 1 elements and the product of the remaining elements are coprime.
    
    For example, if nums = [2, 3, 3], then a split at the index i = 0 is valid because 2 and 9 are coprime, while a split at the index i = 1 is not valid because 6 and 3 are not coprime. A split at the index i = 2 is not valid because i == n - 1.
    
    Return the smallest index i at which the array can be split validly or -1 if there is no such split.
    Two values val1 and val2 are coprime if gcd(val1, val2) == 1 where gcd(val1, val2) is the greatest common divisor of val1 and val2.
    
    Example 1:
    
    
    >>> findValidSplit(nums = [4,7,8,15,3,5])
    >>> 2
    Explanation: The table above shows the values of the product of the first i + 1 elements, the remaining elements, and their gcd at each index i.
    The only valid split is at index 2.
    
    Example 2:
    
    
    >>> findValidSplit(nums = [4,7,15,8,3,5])
    >>> -1
    Explanation: The table above shows the values of the product of the first i + 1 elements, the remaining elements, and their gcd at each index i.
    There is no valid split.
    """
def waysToReachTarget(target: int, types: List[List[int]]) -> int:
    """
    There is a test that has n types of questions. You are given an integer target and a 0-indexed 2D integer array types where types[i] = [counti, marksi] indicates that there are counti questions of the ith type, and each one of them is worth marksi points.
    
    
    Return the number of ways you can earn exactly target points in the exam. Since the answer may be too large, return it modulo 109 + 7.
    Note that questions of the same type are indistinguishable.
    
    For example, if there are 3 questions of the same type, then solving the 1st and 2nd questions is the same as solving the 1st and 3rd questions, or the 2nd and 3rd questions.
    
    
    Example 1:
    
    >>> waysToReachTarget(target = 6, types = [[6,1],[3,2],[2,3]])
    >>> 7
    Explanation: You can earn 6 points in one of the seven ways:
    - Solve 6 questions of the 0th type: 1 + 1 + 1 + 1 + 1 + 1 = 6
    - Solve 4 questions of the 0th type and 1 question of the 1st type: 1 + 1 + 1 + 1 + 2 = 6
    - Solve 2 questions of the 0th type and 2 questions of the 1st type: 1 + 1 + 2 + 2 = 6
    - Solve 3 questions of the 0th type and 1 question of the 2nd type: 1 + 1 + 1 + 3 = 6
    - Solve 1 question of the 0th type, 1 question of the 1st type and 1 question of the 2nd type: 1 + 2 + 3 = 6
    - Solve 3 questions of the 1st type: 2 + 2 + 2 = 6
    - Solve 2 questions of the 2nd type: 3 + 3 = 6
    
    Example 2:
    
    >>> waysToReachTarget(target = 5, types = [[50,1],[50,2],[50,5]])
    >>> 4
    Explanation: You can earn 5 points in one of the four ways:
    - Solve 5 questions of the 0th type: 1 + 1 + 1 + 1 + 1 = 5
    - Solve 3 questions of the 0th type and 1 question of the 1st type: 1 + 1 + 1 + 2 = 5
    - Solve 1 questions of the 0th type and 2 questions of the 1st type: 1 + 2 + 2 = 5
    - Solve 1 question of the 2nd type: 5
    
    Example 3:
    
    >>> waysToReachTarget(target = 18, types = [[6,1],[3,2],[2,3]])
    >>> 1
    Explanation: You can only earn 18 points by answering all questions.
    """
def vowelStrings(words: List[str], left: int, right: int) -> int:
    """
    You are given a 0-indexed array of string words and two integers left and right.
    A string is called a vowel string if it starts with a vowel character and ends with a vowel character where vowel characters are 'a', 'e', 'i', 'o', and 'u'.
    Return the number of vowel strings words[i] where i belongs to the inclusive range [left, right].
    
    Example 1:
    
    >>> vowelStrings(words = ["are","amy","u"], left = 0, right = 2)
    >>> 2
    Explanation:
    - "are" is a vowel string because it starts with 'a' and ends with 'e'.
    - "amy" is not a vowel string because it does not end with a vowel.
    - "u" is a vowel string because it starts with 'u' and ends with 'u'.
    The number of vowel strings in the mentioned range is 2.
    
    Example 2:
    
    >>> vowelStrings(words = ["hey","aeo","mu","ooo","artro"], left = 1, right = 4)
    >>> 3
    Explanation:
    - "aeo" is a vowel string because it starts with 'a' and ends with 'o'.
    - "mu" is not a vowel string because it does not start with a vowel.
    - "ooo" is a vowel string because it starts with 'o' and ends with 'o'.
    - "artro" is a vowel string because it starts with 'a' and ends with 'o'.
    The number of vowel strings in the mentioned range is 3.
    """
def maxScore(nums: List[int]) -> int:
    """
    You are given a 0-indexed integer array nums. You can rearrange the elements of nums to any order (including the given order).
    Let prefix be the array containing the prefix sums of nums after rearranging it. In other words, prefix[i] is the sum of the elements from 0 to i in nums after rearranging it. The score of nums is the number of positive integers in the array prefix.
    Return the maximum score you can achieve.
    
    Example 1:
    
    >>> maxScore(nums = [2,-1,0,1,-3,3,-3])
    >>> 6
    Explanation: We can rearrange the array into nums = [2,3,1,-1,-3,0,-3].
    prefix = [2,5,6,5,2,2,-1], so the score is 6.
    It can be shown that 6 is the maximum score we can obtain.
    
    Example 2:
    
    >>> maxScore(nums = [-2,-3,0])
    >>> 0
    Explanation: Any rearrangement of the array will result in a score of 0.
    """
def beautifulSubarrays(nums: List[int]) -> int:
    """
    You are given a 0-indexed integer array nums. In one operation, you can:
    
    Choose two different indices i and j such that 0 <= i, j < nums.length.
    Choose a non-negative integer k such that the kth bit (0-indexed) in the binary representation of nums[i] and nums[j] is 1.
    Subtract 2k from nums[i] and nums[j].
    
    A subarray is beautiful if it is possible to make all of its elements equal to 0 after applying the above operation any number of times.
    Return the number of beautiful subarrays in the array nums.
    A subarray is a contiguous non-empty sequence of elements within an array.
    
    Example 1:
    
    >>> beautifulSubarrays(nums = [4,3,1,2,4])
    >>> 2
    Explanation: There are 2 beautiful subarrays in nums: [4,3,1,2,4] and [4,3,1,2,4].
    - We can make all elements in the subarray [3,1,2] equal to 0 in the following way:
      - Choose [3, 1, 2] and k = 1. Subtract 21 from both numbers. The subarray becomes [1, 1, 0].
      - Choose [1, 1, 0] and k = 0. Subtract 20 from both numbers. The subarray becomes [0, 0, 0].
    - We can make all elements in the subarray [4,3,1,2,4] equal to 0 in the following way:
      - Choose [4, 3, 1, 2, 4] and k = 2. Subtract 22 from both numbers. The subarray becomes [0, 3, 1, 2, 0].
      - Choose [0, 3, 1, 2, 0] and k = 0. Subtract 20 from both numbers. The subarray becomes [0, 2, 0, 2, 0].
      - Choose [0, 2, 0, 2, 0] and k = 1. Subtract 21 from both numbers. The subarray becomes [0, 0, 0, 0, 0].
    
    Example 2:
    
    >>> beautifulSubarrays(nums = [1,10,4])
    >>> 0
    Explanation: There are no beautiful subarrays in nums.
    """
def findMinimumTime(tasks: List[List[int]]) -> int:
    """
    There is a computer that can run an unlimited number of tasks at the same time. You are given a 2D integer array tasks where tasks[i] = [starti, endi, durationi] indicates that the ith task should run for a total of durationi seconds (not necessarily continuous) within the inclusive time range [starti, endi].
    You may turn on the computer only when it needs to run a task. You can also turn it off if it is idle.
    Return the minimum time during which the computer should be turned on to complete all tasks.
    
    Example 1:
    
    >>> findMinimumTime(tasks = [[2,3,1],[4,5,1],[1,5,2]])
    >>> 2
    Explanation:
    - The first task can be run in the inclusive time range [2, 2].
    - The second task can be run in the inclusive time range [5, 5].
    - The third task can be run in the two inclusive time ranges [2, 2] and [5, 5].
    The computer will be on for a total of 2 seconds.
    
    Example 2:
    
    >>> findMinimumTime(tasks = [[1,3,2],[2,5,3],[5,6,2]])
    >>> 4
    Explanation:
    - The first task can be run in the inclusive time range [2, 3].
    - The second task can be run in the inclusive time ranges [2, 3] and [5, 5].
    - The third task can be run in the two inclusive time range [5, 6].
    The computer will be on for a total of 4 seconds.
    """
def distMoney(money: int, children: int) -> int:
    """
    You are given an integer money denoting the amount of money (in dollars) that you have and another integer children denoting the number of children that you must distribute the money to.
    You have to distribute the money according to the following rules:
    
    All money must be distributed.
    Everyone must receive at least 1 dollar.
    Nobody receives 4 dollars.
    
    Return the maximum number of children who may receive exactly 8 dollars if you distribute the money according to the aforementioned rules. If there is no way to distribute the money, return -1.
    
    Example 1:
    
    >>> distMoney(money = 20, children = 3)
    >>> 1
    Explanation:
    The maximum number of children with 8 dollars will be 1. One of the ways to distribute the money is:
    - 8 dollars to the first child.
    - 9 dollars to the second child.
    - 3 dollars to the third child.
    It can be proven that no distribution exists such that number of children getting 8 dollars is greater than 1.
    
    Example 2:
    
    >>> distMoney(money = 16, children = 2)
    >>> 2
    Explanation: Each child can be given 8 dollars.
    """
def maximizeGreatness(nums: List[int]) -> int:
    """
    You are given a 0-indexed integer array nums. You are allowed to permute nums into a new array perm of your choosing.
    We define the greatness of nums be the number of indices 0 <= i < nums.length for which perm[i] > nums[i].
    Return the maximum possible greatness you can achieve after permuting nums.
    
    Example 1:
    
    >>> maximizeGreatness(nums = [1,3,5,2,1,3,1])
    >>> 4
    Explanation: One of the optimal rearrangements is perm = [2,5,1,3,3,1,1].
    At indices = 0, 1, 3, and 4, perm[i] > nums[i]. Hence, we return 4.
    Example 2:
    
    >>> maximizeGreatness(nums = [1,2,3,4])
    >>> 3
    Explanation: We can prove the optimal perm is [2,3,4,1].
    At indices = 0, 1, and 2, perm[i] > nums[i]. Hence, we return 3.
    """
def findScore(nums: List[int]) -> int:
    """
    You are given an array nums consisting of positive integers.
    Starting with score = 0, apply the following algorithm:
    
    Choose the smallest integer of the array that is not marked. If there is a tie, choose the one with the smallest index.
    Add the value of the chosen integer to score.
    Mark the chosen element and its two adjacent elements if they exist.
    Repeat until all the array elements are marked.
    
    Return the score you get after applying the above algorithm.
    
    Example 1:
    
    >>> findScore(nums = [2,1,3,4,5,2])
    >>> 7
    Explanation: We mark the elements as follows:
    - 1 is the smallest unmarked element, so we mark it and its two adjacent elements: [2,1,3,4,5,2].
    - 2 is the smallest unmarked element, so we mark it and its left adjacent element: [2,1,3,4,5,2].
    - 4 is the only remaining unmarked element, so we mark it: [2,1,3,4,5,2].
    Our score is 1 + 2 + 4 = 7.
    
    Example 2:
    
    >>> findScore(nums = [2,3,5,1,3,2])
    >>> 5
    Explanation: We mark the elements as follows:
    - 1 is the smallest unmarked element, so we mark it and its two adjacent elements: [2,3,5,1,3,2].
    - 2 is the smallest unmarked element, since there are two of them, we choose the left-most one, so we mark the one at index 0 and its right adjacent element: [2,3,5,1,3,2].
    - 2 is the only remaining unmarked element, so we mark it: [2,3,5,1,3,2].
    Our score is 1 + 2 + 2 = 5.
    """
def repairCars(ranks: List[int], cars: int) -> int:
    """
    You are given an integer array ranks representing the ranks of some mechanics. ranksi is the rank of the ith mechanic. A mechanic with a rank r can repair n cars in r * n2 minutes.
    You are also given an integer cars representing the total number of cars waiting in the garage to be repaired.
    Return the minimum time taken to repair all the cars.
    Note: All the mechanics can repair the cars simultaneously.
    
    Example 1:
    
    >>> repairCars(ranks = [4,2,3,1], cars = 10)
    >>> 16
    Explanation:
    - The first mechanic will repair two cars. The time required is 4 * 2 * 2 = 16 minutes.
    - The second mechanic will repair two cars. The time required is 2 * 2 * 2 = 8 minutes.
    - The third mechanic will repair two cars. The time required is 3 * 2 * 2 = 12 minutes.
    - The fourth mechanic will repair four cars. The time required is 1 * 4 * 4 = 16 minutes.
    It can be proved that the cars cannot be repaired in less than 16 minutes.​​​​​
    
    Example 2:
    
    >>> repairCars(ranks = [5,1,8], cars = 6)
    >>> 16
    Explanation:
    - The first mechanic will repair one car. The time required is 5 * 1 * 1 = 5 minutes.
    - The second mechanic will repair four cars. The time required is 1 * 4 * 4 = 16 minutes.
    - The third mechanic will repair one car. The time required is 8 * 1 * 1 = 8 minutes.
    It can be proved that the cars cannot be repaired in less than 16 minutes.​​​​​
    """
def evenOddBit(n: int) -> List[int]:
    """
    You are given a positive integer n.
    Let even denote the number of even indices in the binary representation of n with value 1.
    Let odd denote the number of odd indices in the binary representation of n with value 1.
    Note that bits are indexed from right to left in the binary representation of a number.
    Return the array [even, odd].
    
    Example 1:
    
    >>> evenOddBit(n = 50)
    >>> [1,2]
    Explanation:
    The binary representation of 50 is 110010.
    It contains 1 on indices 1, 4, and 5.
    
    Example 2:
    
    >>> evenOddBit(n = 2)
    >>> [0,1]
    Explanation:
    The binary representation of 2 is 10.
    It contains 1 only on index 1.
    """
def checkValidGrid(grid: List[List[int]]) -> bool:
    """
    There is a knight on an n x n chessboard. In a valid configuration, the knight starts at the top-left cell of the board and visits every cell on the board exactly once.
    You are given an n x n integer matrix grid consisting of distinct integers from the range [0, n * n - 1] where grid[row][col] indicates that the cell (row, col) is the grid[row][col]th cell that the knight visited. The moves are 0-indexed.
    Return true if grid represents a valid configuration of the knight's movements or false otherwise.
    Note that a valid knight move consists of moving two squares vertically and one square horizontally, or two squares horizontally and one square vertically. The figure below illustrates all the possible eight moves of a knight from some cell.
    
    
    Example 1:
    
    
    >>> checkValidGrid(grid = [[0,11,16,5,20],[17,4,19,10,15],[12,1,8,21,6],[3,18,23,14,9],[24,13,2,7,22]])
    >>> true
    Explanation: The above diagram represents the grid. It can be shown that it is a valid configuration.
    
    Example 2:
    
    
    >>> checkValidGrid(grid = [[0,3,6],[5,8,1],[2,7,4]])
    >>> false
    Explanation: The above diagram represents the grid. The 8th move of the knight is not valid considering its position after the 7th move.
    """
def beautifulSubsets(nums: List[int], k: int) -> int:
    """
    You are given an array nums of positive integers and a positive integer k.
    A subset of nums is beautiful if it does not contain two integers with an absolute difference equal to k.
    Return the number of non-empty beautiful subsets of the array nums.
    A subset of nums is an array that can be obtained by deleting some (possibly none) elements from nums. Two subsets are different if and only if the chosen indices to delete are different.
    
    Example 1:
    
    >>> beautifulSubsets(nums = [2,4,6], k = 2)
    >>> 4
    Explanation: The beautiful subsets of the array nums are: [2], [4], [6], [2, 6].
    It can be proved that there are only 4 beautiful subsets in the array [2,4,6].
    
    Example 2:
    
    >>> beautifulSubsets(nums = [1], k = 1)
    >>> 1
    Explanation: The beautiful subset of the array nums is [1].
    It can be proved that there is only 1 beautiful subset in the array [1].
    """
def findSmallestInteger(nums: List[int], value: int) -> int:
    """
    You are given a 0-indexed integer array nums and an integer value.
    In one operation, you can add or subtract value from any element of nums.
    
    For example, if nums = [1,2,3] and value = 2, you can choose to subtract value from nums[0] to make nums = [-1,2,3].
    
    The MEX (minimum excluded) of an array is the smallest missing non-negative integer in it.
    
    For example, the MEX of [-1,2,3] is 0 while the MEX of [1,0,3] is 2.
    
    Return the maximum MEX of nums after applying the mentioned operation any number of times.
    
    Example 1:
    
    >>> findSmallestInteger(nums = [1,-10,7,13,6,8], value = 5)
    >>> 4
    Explanation: One can achieve this result by applying the following operations:
    - Add value to nums[1] twice to make nums = [1,0,7,13,6,8]
    - Subtract value from nums[2] once to make nums = [1,0,2,13,6,8]
    - Subtract value from nums[3] twice to make nums = [1,0,2,3,6,8]
    The MEX of nums is 4. It can be shown that 4 is the maximum MEX we can achieve.
    
    Example 2:
    
    >>> findSmallestInteger(nums = [1,-10,7,13,6,8], value = 7)
    >>> 2
    Explanation: One can achieve this result by applying the following operation:
    - subtract value from nums[2] once to make nums = [1,-10,0,13,6,8]
    The MEX of nums is 2. It can be shown that 2 is the maximum MEX we can achieve.
    """
def makePrefSumNonNegative(nums: List[int]) -> int:
    """
    You are given a 0-indexed integer array nums. You can apply the following operation any number of times:
    
    Pick any element from nums and put it at the end of nums.
    
    The prefix sum array of nums is an array prefix of the same length as nums such that prefix[i] is the sum of all the integers nums[j] where j is in the inclusive range [0, i].
    Return the minimum number of operations such that the prefix sum array does not contain negative integers. The test cases are generated such that it is always possible to make the prefix sum array non-negative.
    
    Example 1:
    
    >>> makePrefSumNonNegative(nums = [2,3,-5,4])
    >>> 0
    Explanation: we do not need to do any operations.
    The array is [2,3,-5,4]. The prefix sum array is [2, 5, 0, 4].
    
    Example 2:
    
    >>> makePrefSumNonNegative(nums = [3,-5,-2,6])
    >>> 1
    Explanation: we can do one operation on index 1.
    The array after the operation is [3,-2,6,-5]. The prefix sum array is [3, 1, 7, 2].
    """
def kItemsWithMaximumSum(numOnes: int, numZeros: int, numNegOnes: int, k: int) -> int:
    """
    There is a bag that consists of items, each item has a number 1, 0, or -1 written on it.
    You are given four non-negative integers numOnes, numZeros, numNegOnes, and k.
    The bag initially contains:
    
    numOnes items with 1s written on them.
    numZeroes items with 0s written on them.
    numNegOnes items with -1s written on them.
    
    We want to pick exactly k items among the available items. Return the maximum possible sum of numbers written on the items.
    
    Example 1:
    
    >>> kItemsWithMaximumSum(numOnes = 3, numZeros = 2, numNegOnes = 0, k = 2)
    >>> 2
    Explanation: We have a bag of items with numbers written on them {1, 1, 1, 0, 0}. We take 2 items with 1 written on them and get a sum in a total of 2.
    It can be proven that 2 is the maximum possible sum.
    
    Example 2:
    
    >>> kItemsWithMaximumSum(numOnes = 3, numZeros = 2, numNegOnes = 0, k = 4)
    >>> 3
    Explanation: We have a bag of items with numbers written on them {1, 1, 1, 0, 0}. We take 3 items with 1 written on them, and 1 item with 0 written on it, and get a sum in a total of 3.
    It can be proven that 3 is the maximum possible sum.
    """
def primeSubOperation(nums: List[int]) -> bool:
    """
    You are given a 0-indexed integer array nums of length n.
    You can perform the following operation as many times as you want:
    
    Pick an index i that you haven’t picked before, and pick a prime p strictly less than nums[i], then subtract p from nums[i].
    
    Return true if you can make nums a strictly increasing array using the above operation and false otherwise.
    A strictly increasing array is an array whose each element is strictly greater than its preceding element.
    
    Example 1:
    
    >>> primeSubOperation(nums = [4,9,6,10])
    >>> true
    Explanation: In the first operation: Pick i = 0 and p = 3, and then subtract 3 from nums[0], so that nums becomes [1,9,6,10].
    In the second operation: i = 1, p = 7, subtract 7 from nums[1], so nums becomes equal to [1,2,6,10].
    After the second operation, nums is sorted in strictly increasing order, so the answer is true.
    Example 2:
    
    >>> primeSubOperation(nums = [6,8,11,12])
    >>> true
    Explanation: Initially nums is sorted in strictly increasing order, so we don't need to make any operations.
    Example 3:
    
    >>> primeSubOperation(nums = [5,8,3])
    >>> false
    Explanation: It can be proven that there is no way to perform operations to make nums sorted in strictly increasing order, so the answer is false.
    """
def minOperations(nums: List[int], queries: List[int]) -> List[int]:
    """
    You are given an array nums consisting of positive integers.
    You are also given an integer array queries of size m. For the ith query, you want to make all of the elements of nums equal to queries[i]. You can perform the following operation on the array any number of times:
    
    Increase or decrease an element of the array by 1.
    
    Return an array answer of size m where answer[i] is the minimum number of operations to make all elements of nums equal to queries[i].
    Note that after each query the array is reset to its original state.
    
    Example 1:
    
    >>> minOperations(nums = [3,1,6,8], queries = [1,5])
    >>> [14,10]
    Explanation: For the first query we can do the following operations:
    - Decrease nums[0] 2 times, so that nums = [1,1,6,8].
    - Decrease nums[2] 5 times, so that nums = [1,1,1,8].
    - Decrease nums[3] 7 times, so that nums = [1,1,1,1].
    So the total number of operations for the first query is 2 + 5 + 7 = 14.
    For the second query we can do the following operations:
    - Increase nums[0] 2 times, so that nums = [5,1,6,8].
    - Increase nums[1] 4 times, so that nums = [5,5,6,8].
    - Decrease nums[2] 1 time, so that nums = [5,5,5,8].
    - Decrease nums[3] 3 times, so that nums = [5,5,5,5].
    So the total number of operations for the second query is 2 + 4 + 1 + 3 = 10.
    
    Example 2:
    
    >>> minOperations(nums = [2,9,6,3], queries = [10])
    >>> [20]
    Explanation: We can increase each value in the array to 10. The total number of operations will be 8 + 1 + 4 + 7 = 20.
    """