ShwStone/humaneval-leetcode huggingface dataset:
def maxTastiness(price: List[int], tastiness: List[int], maxAmount: int, maxCoupons: int) -> int:
    """
    You are given two non-negative integer arrays price and tastiness, both arrays have the same length n. You are also given two non-negative integers maxAmount and maxCoupons.
    For every integer i in range [0, n - 1]:
    
    price[i] describes the price of ith fruit.
    tastiness[i] describes the tastiness of ith fruit.
    
    You want to purchase some fruits such that total tastiness is maximized and the total price does not exceed maxAmount.
    Additionally, you can use a coupon to purchase fruit for half of its price (rounded down to the closest integer). You can use at most maxCoupons of such coupons.
    Return the maximum total tastiness that can be purchased.
    Note that:
    
    You can purchase each fruit at most once.
    You can use coupons on some fruit at most once.
    
    
    Example 1:
    
    >>> maxTastiness(price = [10,20,20], tastiness = [5,8,8], maxAmount = 20, maxCoupons = 1)
    >>> 13
    Explanation: It is possible to make total tastiness 13 in following way:
    - Buy first fruit without coupon, so that total price = 0 + 10 and total tastiness = 0 + 5.
    - Buy second fruit with coupon, so that total price = 10 + 10 and total tastiness = 5 + 8.
    - Do not buy third fruit, so that total price = 20 and total tastiness = 13.
    It can be proven that 13 is the maximum total tastiness that can be obtained.
    
    Example 2:
    
    >>> maxTastiness(price = [10,15,7], tastiness = [5,8,20], maxAmount = 10, maxCoupons = 2)
    >>> 28
    Explanation: It is possible to make total tastiness 20 in following way:
    - Do not buy first fruit, so that total price = 0 and total tastiness = 0.
    - Buy second fruit with coupon, so that total price = 0 + 7 and total tastiness = 0 + 8.
    - Buy third fruit with coupon, so that total price = 7 + 3 and total tastiness = 8 + 20.
    It can be proven that 28 is the maximum total tastiness that can be obtained.
    """
def hardestWorker(n: int, logs: List[List[int]]) -> int:
    """
    There are n employees, each with a unique id from 0 to n - 1.
    You are given a 2D integer array logs where logs[i] = [idi, leaveTimei] where:
    
    idi is the id of the employee that worked on the ith task, and
    leaveTimei is the time at which the employee finished the ith task. All the values leaveTimei are unique.
    
    Note that the ith task starts the moment right after the (i - 1)th task ends, and the 0th task starts at time 0.
    Return the id of the employee that worked the task with the longest time. If there is a tie between two or more employees, return the smallest id among them.
    
    Example 1:
    
    >>> hardestWorker(n = 10, logs = [[0,3],[2,5],[0,9],[1,15]])
    >>> 1
    Explanation:
    Task 0 started at 0 and ended at 3 with 3 units of times.
    Task 1 started at 3 and ended at 5 with 2 units of times.
    Task 2 started at 5 and ended at 9 with 4 units of times.
    Task 3 started at 9 and ended at 15 with 6 units of times.
    The task with the longest time is task 3 and the employee with id 1 is the one that worked on it, so we return 1.
    
    Example 2:
    
    >>> hardestWorker(n = 26, logs = [[1,1],[3,7],[2,12],[7,17]])
    >>> 3
    Explanation:
    Task 0 started at 0 and ended at 1 with 1 unit of times.
    Task 1 started at 1 and ended at 7 with 6 units of times.
    Task 2 started at 7 and ended at 12 with 5 units of times.
    Task 3 started at 12 and ended at 17 with 5 units of times.
    The tasks with the longest time is task 1. The employee that worked on it is 3, so we return 3.
    
    Example 3:
    
    >>> hardestWorker(n = 2, logs = [[0,10],[1,20]])
    >>> 0
    Explanation:
    Task 0 started at 0 and ended at 10 with 10 units of times.
    Task 1 started at 10 and ended at 20 with 10 units of times.
    The tasks with the longest time are tasks 0 and 1. The employees that worked on them are 0 and 1, so we return the smallest id 0.
    """
def findArray(pref: List[int]) -> List[int]:
    """
    You are given an integer array pref of size n. Find and return the array arr of size n that satisfies:
    
    pref[i] = arr[0] ^ arr[1] ^ ... ^ arr[i].
    
    Note that ^ denotes the bitwise-xor operation.
    It can be proven that the answer is unique.
    
    Example 1:
    
    >>> findArray(pref = [5,2,0,3,1])
    >>> [5,7,2,3,2]
    Explanation: From the array [5,7,2,3,2] we have the following:
    - pref[0] = 5.
    - pref[1] = 5 ^ 7 = 2.
    - pref[2] = 5 ^ 7 ^ 2 = 0.
    - pref[3] = 5 ^ 7 ^ 2 ^ 3 = 3.
    - pref[4] = 5 ^ 7 ^ 2 ^ 3 ^ 2 = 1.
    
    Example 2:
    
    >>> findArray(pref = [13])
    >>> [13]
    Explanation: We have pref[0] = arr[0] = 13.
    """
def robotWithString(s: str) -> str:
    """
    You are given a string s and a robot that currently holds an empty string t. Apply one of the following operations until s and t are both empty:
    
    Remove the first character of a string s and give it to the robot. The robot will append this character to the string t.
    Remove the last character of a string t and give it to the robot. The robot will write this character on paper.
    
    Return the lexicographically smallest string that can be written on the paper.
    
    Example 1:
    
    >>> robotWithString(s = "zza")
    >>> "azz"
    Explanation: Let p denote the written string.
    Initially p="", s="zza", t="".
    Perform first operation three times p="", s="", t="zza".
    Perform second operation three times p="azz", s="", t="".
    
    Example 2:
    
    >>> robotWithString(s = "bac")
    >>> "abc"
    Explanation: Let p denote the written string.
    Perform first operation twice p="", s="c", t="ba".
    Perform second operation twice p="ab", s="c", t="".
    Perform first operation p="ab", s="", t="c".
    Perform second operation p="abc", s="", t="".
    
    Example 3:
    
    >>> robotWithString(s = "bdda")
    >>> "addb"
    Explanation: Let p denote the written string.
    Initially p="", s="bdda", t="".
    Perform first operation four times p="", s="", t="bdda".
    Perform second operation four times p="addb", s="", t="".
    """
def numberOfPaths(grid: List[List[int]], k: int) -> int:
    """
    You are given a 0-indexed m x n integer matrix grid and an integer k. You are currently at position (0, 0) and you want to reach position (m - 1, n - 1) moving only down or right.
    Return the number of paths where the sum of the elements on the path is divisible by k. Since the answer may be very large, return it modulo 109 + 7.
    
    Example 1:
    
    
    >>> numberOfPaths(grid = [[5,2,4],[3,0,5],[0,7,2]], k = 3)
    >>> 2
    Explanation: There are two paths where the sum of the elements on the path is divisible by k.
    The first path highlighted in red has a sum of 5 + 2 + 4 + 5 + 2 = 18 which is divisible by 3.
    The second path highlighted in blue has a sum of 5 + 3 + 0 + 5 + 2 = 15 which is divisible by 3.
    
    Example 2:
    
    
    >>> numberOfPaths(grid = [[0,0]], k = 5)
    >>> 1
    Explanation: The path highlighted in red has a sum of 0 + 0 = 0 which is divisible by 5.
    
    Example 3:
    
    
    >>> numberOfPaths(grid = [[7,3,4,9],[2,3,6,2],[2,3,7,0]], k = 1)
    >>> 10
    Explanation: Every integer is divisible by 1 so the sum of the elements on every possible path is divisible by k.
    """
def minimumSplits(nums: List[int]) -> int:
    """
    You are given an array nums consisting of positive integers.
    Split the array into one or more disjoint subarrays such that:
    
    Each element of the array belongs to exactly one subarray, and
    The GCD of the elements of each subarray is strictly greater than 1.
    
    Return the minimum number of subarrays that can be obtained after the split.
    Note that:
    
    The GCD of a subarray is the largest positive integer that evenly divides all the elements of the subarray.
    A subarray is a contiguous part of the array.
    
    
    Example 1:
    
    >>> minimumSplits(nums = [12,6,3,14,8])
    >>> 2
    Explanation: We can split the array into the subarrays: [12,6,3] and [14,8].
    - The GCD of 12, 6 and 3 is 3, which is strictly greater than 1.
    - The GCD of 14 and 8 is 2, which is strictly greater than 1.
    It can be shown that splitting the array into one subarray will make the GCD = 1.
    
    Example 2:
    
    >>> minimumSplits(nums = [4,12,6,14])
    >>> 1
    Explanation: We can split the array into only one subarray, which is the whole array.
    """
def countTime(time: str) -> int:
    """
    You are given a string of length 5 called time, representing the current time on a digital clock in the format "hh:mm". The earliest possible time is "00:00" and the latest possible time is "23:59".
    In the string time, the digits represented by the ? symbol are unknown, and must be replaced with a digit from 0 to 9.
    Return an integer answer, the number of valid clock times that can be created by replacing every ? with a digit from 0 to 9.
    
    Example 1:
    
    >>> countTime(time = "?5:00")
    >>> 2
    Explanation: We can replace the ? with either a 0 or 1, producing "05:00" or "15:00". Note that we cannot replace it with a 2, since the time "25:00" is invalid. In total, we have two choices.
    
    Example 2:
    
    >>> countTime(time = "0?:0?")
    >>> 100
    Explanation: Each ? can be replaced by any digit from 0 to 9, so we have 100 total choices.
    
    Example 3:
    
    >>> countTime(time = "??:??")
    >>> 1440
    Explanation: There are 24 possible choices for the hours, and 60 possible choices for the minutes. In total, we have 24 * 60 = 1440 choices.
    """
def productQueries(n: int, queries: List[List[int]]) -> List[int]:
    """
    Given a positive integer n, there exists a 0-indexed array called powers, composed of the minimum number of powers of 2 that sum to n. The array is sorted in non-decreasing order, and there is only one way to form the array.
    You are also given a 0-indexed 2D integer array queries, where queries[i] = [lefti, righti]. Each queries[i] represents a query where you have to find the product of all powers[j] with lefti <= j <= righti.
    Return an array answers, equal in length to queries, where answers[i] is the answer to the ith query. Since the answer to the ith query may be too large, each answers[i] should be returned modulo 109 + 7.
    
    Example 1:
    
    >>> productQueries(n = 15, queries = [[0,1],[2,2],[0,3]])
    >>> [2,4,64]
    Explanation:
    For n = 15, powers = [1,2,4,8]. It can be shown that powers cannot be a smaller size.
    Answer to 1st query: powers[0] * powers[1] = 1 * 2 = 2.
    Answer to 2nd query: powers[2] = 4.
    Answer to 3rd query: powers[0] * powers[1] * powers[2] * powers[3] = 1 * 2 * 4 * 8 = 64.
    Each answer modulo 109 + 7 yields the same answer, so [2,4,64] is returned.
    
    Example 2:
    
    >>> productQueries(n = 2, queries = [[0,0]])
    >>> [2]
    Explanation:
    For n = 2, powers = [2].
    The answer to the only query is powers[0] = 2. The answer modulo 109 + 7 is the same, so [2] is returned.
    """
def minimizeArrayValue(nums: List[int]) -> int:
    """
    You are given a 0-indexed array nums comprising of n non-negative integers.
    In one operation, you must:
    
    Choose an integer i such that 1 <= i < n and nums[i] > 0.
    Decrease nums[i] by 1.
    Increase nums[i - 1] by 1.
    
    Return the minimum possible value of the maximum integer of nums after performing any number of operations.
    
    Example 1:
    
    >>> minimizeArrayValue(nums = [3,7,1,6])
    >>> 5
    Explanation:
    One set of optimal operations is as follows:
    1. Choose i = 1, and nums becomes [4,6,1,6].
    2. Choose i = 3, and nums becomes [4,6,2,5].
    3. Choose i = 1, and nums becomes [5,5,2,5].
    The maximum integer of nums is 5. It can be shown that the maximum number cannot be less than 5.
    Therefore, we return 5.
    
    Example 2:
    
    >>> minimizeArrayValue(nums = [10,1])
    >>> 10
    Explanation:
    It is optimal to leave nums as is, and since 10 is the maximum value, we return 10.
    """
def componentValue(nums: List[int], edges: List[List[int]]) -> int:
    """
    There is an undirected tree with n nodes labeled from 0 to n - 1.
    You are given a 0-indexed integer array nums of length n where nums[i] represents the value of the ith node. You are also given a 2D integer array edges of length n - 1 where edges[i] = [ai, bi] indicates that there is an edge between nodes ai and bi in the tree.
    You are allowed to delete some edges, splitting the tree into multiple connected components. Let the value of a component be the sum of all nums[i] for which node i is in the component.
    Return the maximum number of edges you can delete, such that every connected component in the tree has the same value.
    
    Example 1:
    
    
    >>> componentValue(nums = [6,2,2,2,6], edges = [[0,1],[1,2],[1,3],[3,4]])
    >>> 2
    Explanation: The above figure shows how we can delete the edges [0,1] and [3,4]. The created components are nodes [0], [1,2,3] and [4]. The sum of the values in each component equals 6. It can be proven that no better deletion exists, so the answer is 2.
    
    Example 2:
    
    >>> componentValue(nums = [2], edges = [])
    >>> 0
    Explanation: There are no edges to be deleted.
    """
def findMaxK(nums: List[int]) -> int:
    """
    Given an integer array nums that does not contain any zeros, find the largest positive integer k such that -k also exists in the array.
    Return the positive integer k. If there is no such integer, return -1.
    
    Example 1:
    
    >>> findMaxK(nums = [-1,2,-3,3])
    >>> 3
    Explanation: 3 is the only valid k we can find in the array.
    
    Example 2:
    
    >>> findMaxK(nums = [-1,10,6,7,-7,1])
    >>> 7
    Explanation: Both 1 and 7 have their corresponding negative values in the array. 7 has a larger value.
    
    Example 3:
    
    >>> findMaxK(nums = [-10,8,6,7,-2,-3])
    >>> -1
    Explanation: There is no a single valid k, we return -1.
    """
def countDistinctIntegers(nums: List[int]) -> int:
    """
    You are given an array nums consisting of positive integers.
    You have to take each integer in the array, reverse its digits, and add it to the end of the array. You should apply this operation to the original integers in nums.
    Return the number of distinct integers in the final array.
    
    Example 1:
    
    >>> countDistinctIntegers(nums = [1,13,10,12,31])
    >>> 6
    Explanation: After including the reverse of each number, the resulting array is [1,13,10,12,31,1,31,1,21,13].
    The reversed integers that were added to the end of the array are underlined. Note that for the integer 10, after reversing it, it becomes 01 which is just 1.
    The number of distinct integers in this array is 6 (The numbers 1, 10, 12, 13, 21, and 31).
    Example 2:
    
    >>> countDistinctIntegers(nums = [2,2,2])
    >>> 1
    Explanation: After including the reverse of each number, the resulting array is [2,2,2,2,2,2].
    The number of distinct integers in this array is 1 (The number 2).
    """
def sumOfNumberAndReverse(num: int) -> bool:
    """
    Given a non-negative integer num, return true if num can be expressed as the sum of any non-negative integer and its reverse, or false otherwise.
    
    Example 1:
    
    >>> sumOfNumberAndReverse(num = 443)
    >>> true
    Explanation: 172 + 271 = 443 so we return true.
    
    Example 2:
    
    >>> sumOfNumberAndReverse(num = 63)
    >>> false
    Explanation: 63 cannot be expressed as the sum of a non-negative integer and its reverse so we return false.
    
    Example 3:
    
    >>> sumOfNumberAndReverse(num = 181)
    >>> true
    Explanation: 140 + 041 = 181 so we return true. Note that when a number is reversed, there may be leading zeros.
    """
def countSubarrays(nums: List[int], minK: int, maxK: int) -> int:
    """
    You are given an integer array nums and two integers minK and maxK.
    A fixed-bound subarray of nums is a subarray that satisfies the following conditions:
    
    The minimum value in the subarray is equal to minK.
    The maximum value in the subarray is equal to maxK.
    
    Return the number of fixed-bound subarrays.
    A subarray is a contiguous part of an array.
    
    Example 1:
    
    >>> countSubarrays(nums = [1,3,5,2,7,5], minK = 1, maxK = 5)
    >>> 2
    Explanation: The fixed-bound subarrays are [1,3,5] and [1,3,5,2].
    
    Example 2:
    
    >>> countSubarrays(nums = [1,1,1,1], minK = 1, maxK = 1)
    >>> 10
    Explanation: Every subarray of nums is a fixed-bound subarray. There are 10 possible subarrays.
    """
def numberOfNodes(n: int, queries: List[int]) -> int:
    """
    There is an undirected connected tree with n nodes labeled from 1 to n and n - 1 edges. You are given the integer n. The parent node of a node with a label v is the node with the label floor (v / 2). The root of the tree is the node with the label 1.
    
    For example, if n = 7, then the node with the label 3 has the node with the label floor(3 / 2) = 1 as its parent, and the node with the label 7 has the node with the label floor(7 / 2) = 3 as its parent.
    
    You are also given an integer array queries. Initially, every node has a value 0 on it. For each query queries[i], you should flip all values in the subtree of the node with the label queries[i].
    Return the total number of nodes with the value 1 after processing all the queries.
    Note that:
    
    Flipping the value of a node means that the node with the value 0 becomes 1 and vice versa.
    floor(x) is equivalent to rounding x down to the nearest integer.
    
    
    Example 1:
    
    
    >>> numberOfNodes(n = 5 , queries = [1,2,5])
    >>> 3
    Explanation: The diagram above shows the tree structure and its status after performing the queries. The blue node represents the value 0, and the red node represents the value 1.
    After processing the queries, there are three red nodes (nodes with value 1): 1, 3, and 5.
    
    Example 2:
    
    
    >>> numberOfNodes(n = 3, queries = [2,3,3])
    >>> 1
    Explanation: The diagram above shows the tree structure and its status after performing the queries. The blue node represents the value 0, and the red node represents the value 1.
    After processing the queries, there are one red node (node with value 1): 2.
    """
def haveConflict(event1: List[str], event2: List[str]) -> bool:
    """
    You are given two arrays of strings that represent two inclusive events that happened on the same day, event1 and event2, where:
    
    event1 = [startTime1, endTime1] and
    event2 = [startTime2, endTime2].
    
    Event times are valid 24 hours format in the form of HH:MM.
    A conflict happens when two events have some non-empty intersection (i.e., some moment is common to both events).
    Return true if there is a conflict between two events. Otherwise, return false.
    
    Example 1:
    
    >>> haveConflict(event1 = ["01:15","02:00"], event2 = ["02:00","03:00"])
    >>> true
    Explanation: The two events intersect at time 2:00.
    
    Example 2:
    
    >>> haveConflict(event1 = ["01:00","02:00"], event2 = ["01:20","03:00"])
    >>> true
    Explanation: The two events intersect starting from 01:20 to 02:00.
    
    Example 3:
    
    >>> haveConflict(event1 = ["10:00","11:00"], event2 = ["14:00","15:00"])
    >>> false
    Explanation: The two events do not intersect.
    """
def subarrayGCD(nums: List[int], k: int) -> int:
    """
    Given an integer array nums and an integer k, return the number of subarrays of nums where the greatest common divisor of the subarray's elements is k.
    A subarray is a contiguous non-empty sequence of elements within an array.
    The greatest common divisor of an array is the largest integer that evenly divides all the array elements.
    
    Example 1:
    
    >>> subarrayGCD(nums = [9,3,1,2,6,3], k = 3)
    >>> 4
    Explanation: The subarrays of nums where 3 is the greatest common divisor of all the subarray's elements are:
    - [9,3,1,2,6,3]
    - [9,3,1,2,6,3]
    - [9,3,1,2,6,3]
    - [9,3,1,2,6,3]
    
    Example 2:
    
    >>> subarrayGCD(nums = [4], k = 7)
    >>> 0
    Explanation: There are no subarrays of nums where 7 is the greatest common divisor of all the subarray's elements.
    """
def minCost(nums: List[int], cost: List[int]) -> int:
    """
    You are given two 0-indexed arrays nums and cost consisting each of n positive integers.
    You can do the following operation any number of times:
    
    Increase or decrease any element of the array nums by 1.
    
    The cost of doing one operation on the ith element is cost[i].
    Return the minimum total cost such that all the elements of the array nums become equal.
    
    Example 1:
    
    >>> minCost(nums = [1,3,5,2], cost = [2,3,1,14])
    >>> 8
    Explanation: We can make all the elements equal to 2 in the following way:
    - Increase the 0th element one time. The cost is 2.
    - Decrease the 1st element one time. The cost is 3.
    - Decrease the 2nd element three times. The cost is 1 + 1 + 1 = 3.
    The total cost is 2 + 3 + 3 = 8.
    It can be shown that we cannot make the array equal with a smaller cost.
    
    Example 2:
    
    >>> minCost(nums = [2,2,2,2,2], cost = [4,2,8,1,3])
    >>> 0
    Explanation: All the elements are already equal, so no operations are needed.
    """
def makeSimilar(nums: List[int], target: List[int]) -> int:
    """
    You are given two positive integer arrays nums and target, of the same length.
    In one operation, you can choose any two distinct indices i and j where 0 <= i, j < nums.length and:
    
    set nums[i] = nums[i] + 2 and
    set nums[j] = nums[j] - 2.
    
    Two arrays are considered to be similar if the frequency of each element is the same.
    Return the minimum number of operations required to make nums similar to target. The test cases are generated such that nums can always be similar to target.
    
    Example 1:
    
    >>> makeSimilar(nums = [8,12,6], target = [2,14,10])
    >>> 2
    Explanation: It is possible to make nums similar to target in two operations:
    - Choose i = 0 and j = 2, nums = [10,12,4].
    - Choose i = 1 and j = 2, nums = [10,14,2].
    It can be shown that 2 is the minimum number of operations needed.
    
    Example 2:
    
    >>> makeSimilar(nums = [1,2,5], target = [4,1,3])
    >>> 1
    Explanation: We can make nums similar to target in one operation:
    - Choose i = 1 and j = 2, nums = [1,4,3].
    
    Example 3:
    
    >>> makeSimilar(nums = [1,1,1,1,1], target = [1,1,1,1,1])
    >>> 0
    Explanation: The array nums is already similiar to target.
    """
def countDistinctStrings(s: str, k: int) -> int:
    """
    You are given a binary string s and a positive integer k.
    You can apply the following operation on the string any number of times:
    
    Choose any substring of size k from s and flip all its characters, that is, turn all 1's into 0's, and all 0's into 1's.
    
    Return the number of distinct strings you can obtain. Since the answer may be too large, return it modulo 109 + 7.
    Note that:
    
    A binary string is a string that consists only of the characters 0 and 1.
    A substring is a contiguous part of a string.
    
    
    Example 1:
    
    >>> countDistinctStrings(s = "1001", k = 3)
    >>> 4
    Explanation: We can obtain the following strings:
    - Applying no operation on the string gives s = "1001".
    - Applying one operation on the substring starting at index 0 gives s = "0111".
    - Applying one operation on the substring starting at index 1 gives s = "1110".
    - Applying one operation on both the substrings starting at indices 0 and 1 gives s = "0000".
    It can be shown that we cannot obtain any other string, so the answer is 4.
    Example 2:
    
    >>> countDistinctStrings(s = "10110", k = 5)
    >>> 2
    Explanation: We can obtain the following strings:
    - Applying no operation on the string gives s = "10110".
    - Applying one operation on the whole string gives s = "01001".
    It can be shown that we cannot obtain any other string, so the answer is 2.
    """