ShwStone/humaneval-leetcode huggingface dataset:
def assignTasks(servers: List[int], tasks: List[int]) -> List[int]:
    """
    You are given two 0-indexed integer arrays servers and tasks of lengths n​​​​​​ and m​​​​​​ respectively. servers[i] is the weight of the i​​​​​​th​​​​ server, and tasks[j] is the time needed to process the j​​​​​​th​​​​ task in seconds.
    Tasks are assigned to the servers using a task queue. Initially, all servers are free, and the queue is empty.
    At second j, the jth task is inserted into the queue (starting with the 0th task being inserted at second 0). As long as there are free servers and the queue is not empty, the task in the front of the queue will be assigned to a free server with the smallest weight, and in case of a tie, it is assigned to a free server with the smallest index.
    If there are no free servers and the queue is not empty, we wait until a server becomes free and immediately assign the next task. If multiple servers become free at the same time, then multiple tasks from the queue will be assigned in order of insertion following the weight and index priorities above.
    A server that is assigned task j at second t will be free again at second t + tasks[j].
    Build an array ans​​​​ of length m, where ans[j] is the index of the server the j​​​​​​th task will be assigned to.
    Return the array ans​​​​.
    
    Example 1:
    
    >>> assignTasks(servers = [3,3,2], tasks = [1,2,3,2,1,2])
    >>> [2,2,0,2,1,2]
    Explanation: Events in chronological order go as follows:
    - At second 0, task 0 is added and processed using server 2 until second 1.
    - At second 1, server 2 becomes free. Task 1 is added and processed using server 2 until second 3.
    - At second 2, task 2 is added and processed using server 0 until second 5.
    - At second 3, server 2 becomes free. Task 3 is added and processed using server 2 until second 5.
    - At second 4, task 4 is added and processed using server 1 until second 5.
    - At second 5, all servers become free. Task 5 is added and processed using server 2 until second 7.
    Example 2:
    
    >>> assignTasks(servers = [5,1,4,3,2], tasks = [2,1,2,4,5,2,1])
    >>> [1,4,1,4,1,3,2]
    Explanation: Events in chronological order go as follows:
    - At second 0, task 0 is added and processed using server 1 until second 2.
    - At second 1, task 1 is added and processed using server 4 until second 2.
    - At second 2, servers 1 and 4 become free. Task 2 is added and processed using server 1 until second 4.
    - At second 3, task 3 is added and processed using server 4 until second 7.
    - At second 4, server 1 becomes free. Task 4 is added and processed using server 1 until second 9.
    - At second 5, task 5 is added and processed using server 3 until second 7.
    - At second 6, task 6 is added and processed using server 2 until second 7.
    """
def minSkips(dist: List[int], speed: int, hoursBefore: int) -> int:
    """
    You are given an integer hoursBefore, the number of hours you have to travel to your meeting. To arrive at your meeting, you have to travel through n roads. The road lengths are given as an integer array dist of length n, where dist[i] describes the length of the ith road in kilometers. In addition, you are given an integer speed, which is the speed (in km/h) you will travel at.
    After you travel road i, you must rest and wait for the next integer hour before you can begin traveling on the next road. Note that you do not have to rest after traveling the last road because you are already at the meeting.
    
    For example, if traveling a road takes 1.4 hours, you must wait until the 2 hour mark before traveling the next road. If traveling a road takes exactly 2 hours, you do not need to wait.
    
    However, you are allowed to skip some rests to be able to arrive on time, meaning you do not need to wait for the next integer hour. Note that this means you may finish traveling future roads at different hour marks.
    
    For example, suppose traveling the first road takes 1.4 hours and traveling the second road takes 0.6 hours. Skipping the rest after the first road will mean you finish traveling the second road right at the 2 hour mark, letting you start traveling the third road immediately.
    
    Return the minimum number of skips required to arrive at the meeting on time, or -1 if it is impossible.
    
    Example 1:
    
    >>> minSkips(dist = [1,3,2], speed = 4, hoursBefore = 2)
    >>> 1
    Explanation:
    Without skipping any rests, you will arrive in (1/4 + 3/4) + (3/4 + 1/4) + (2/4) = 2.5 hours.
    You can skip the first rest to arrive in ((1/4 + 0) + (3/4 + 0)) + (2/4) = 1.5 hours.
    Note that the second rest is shortened because you finish traveling the second road at an integer hour due to skipping the first rest.
    
    Example 2:
    
    >>> minSkips(dist = [7,3,5,5], speed = 2, hoursBefore = 10)
    >>> 2
    Explanation:
    Without skipping any rests, you will arrive in (7/2 + 1/2) + (3/2 + 1/2) + (5/2 + 1/2) + (5/2) = 11.5 hours.
    You can skip the first and third rest to arrive in ((7/2 + 0) + (3/2 + 0)) + ((5/2 + 0) + (5/2)) = 10 hours.
    
    Example 3:
    
    >>> minSkips(dist = [7,3,5,5], speed = 1, hoursBefore = 10)
    >>> -1
    Explanation: It is impossible to arrive at the meeting on time even if you skip all the rests.
    """
def twoEggDrop(n: int) -> int:
    """
    You are given two identical eggs and you have access to a building with n floors labeled from 1 to n.
    You know that there exists a floor f where 0 <= f <= n such that any egg dropped at a floor higher than f will break, and any egg dropped at or below floor f will not break.
    In each move, you may take an unbroken egg and drop it from any floor x (where 1 <= x <= n). If the egg breaks, you can no longer use it. However, if the egg does not break, you may reuse it in future moves.
    Return the minimum number of moves that you need to determine with certainty what the value of f is.
    
    Example 1:
    
    >>> twoEggDrop(n = 2)
    >>> 2
    Explanation: We can drop the first egg from floor 1 and the second egg from floor 2.
    If the first egg breaks, we know that f = 0.
    If the second egg breaks but the first egg didn't, we know that f = 1.
    Otherwise, if both eggs survive, we know that f = 2.
    
    Example 2:
    
    >>> twoEggDrop(n = 100)
    >>> 14
    Explanation: One optimal strategy is:
    - Drop the 1st egg at floor 9. If it breaks, we know f is between 0 and 8. Drop the 2nd egg starting from floor 1 and going up one at a time to find f within 8 more drops. Total drops is 1 + 8 = 9.
    - If the 1st egg does not break, drop the 1st egg again at floor 22. If it breaks, we know f is between 9 and 21. Drop the 2nd egg starting from floor 10 and going up one at a time to find f within 12 more drops. Total drops is 2 + 12 = 14.
    - If the 1st egg does not break again, follow a similar process dropping the 1st egg from floors 34, 45, 55, 64, 72, 79, 85, 90, 94, 97, 99, and 100.
    Regardless of the outcome, it takes at most 14 drops to determine f.
    """
def countPairs(nums1: List[int], nums2: List[int]) -> int:
    """
    Given two integer arrays nums1 and nums2 of length n, count the pairs of indices (i, j) such that i < j and nums1[i] + nums1[j] > nums2[i] + nums2[j].
    Return the number of pairs satisfying the condition.
    
    Example 1:
    
    >>> countPairs(nums1 = [2,1,2,1], nums2 = [1,2,1,2])
    >>> 1
    Explanation: The pairs satisfying the condition are:
    - (0, 2) where 2 + 2 > 1 + 1.
    Example 2:
    
    >>> countPairs(nums1 = [1,10,6,2], nums2 = [1,4,1,5])
    >>> 5
    Explanation: The pairs satisfying the condition are:
    - (0, 1) where 1 + 10 > 1 + 4.
    - (0, 2) where 1 + 6 > 1 + 1.
    - (1, 2) where 10 + 6 > 4 + 1.
    - (1, 3) where 10 + 2 > 4 + 5.
    - (2, 3) where 6 + 2 > 1 + 5.
    """
def findRotation(mat: List[List[int]], target: List[List[int]]) -> bool:
    """
    Given two n x n binary matrices mat and target, return true if it is possible to make mat equal to target by rotating mat in 90-degree increments, or false otherwise.
    
    Example 1:
    
    
    >>> findRotation(mat = [[0,1],[1,0]], target = [[1,0],[0,1]])
    >>> true
    Explanation: We can rotate mat 90 degrees clockwise to make mat equal target.
    
    Example 2:
    
    
    >>> findRotation(mat = [[0,1],[1,1]], target = [[1,0],[0,1]])
    >>> false
    Explanation: It is impossible to make mat equal to target by rotating mat.
    
    Example 3:
    
    
    >>> findRotation(mat = [[0,0,0],[0,1,0],[1,1,1]], target = [[1,1,1],[0,1,0],[0,0,0]])
    >>> true
    Explanation: We can rotate mat 90 degrees clockwise two times to make mat equal target.
    """
def reductionOperations(nums: List[int]) -> int:
    """
    Given an integer array nums, your goal is to make all elements in nums equal. To complete one operation, follow these steps:
    
    Find the largest value in nums. Let its index be i (0-indexed) and its value be largest. If there are multiple elements with the largest value, pick the smallest i.
    Find the next largest value in nums strictly smaller than largest. Let its value be nextLargest.
    Reduce nums[i] to nextLargest.
    
    Return the number of operations to make all elements in nums equal.
    
    Example 1:
    
    >>> reductionOperations(nums = [5,1,3])
    >>> 3
    Explanation: It takes 3 operations to make all elements in nums equal:
    1. largest = 5 at index 0. nextLargest = 3. Reduce nums[0] to 3. nums = [3,1,3].
    2. largest = 3 at index 0. nextLargest = 1. Reduce nums[0] to 1. nums = [1,1,3].
    3. largest = 3 at index 2. nextLargest = 1. Reduce nums[2] to 1. nums = [1,1,1].
    
    Example 2:
    
    >>> reductionOperations(nums = [1,1,1])
    >>> 0
    Explanation: All elements in nums are already equal.
    
    Example 3:
    
    >>> reductionOperations(nums = [1,1,2,2,3])
    >>> 4
    Explanation: It takes 4 operations to make all elements in nums equal:
    1. largest = 3 at index 4. nextLargest = 2. Reduce nums[4] to 2. nums = [1,1,2,2,2].
    2. largest = 2 at index 2. nextLargest = 1. Reduce nums[2] to 1. nums = [1,1,1,2,2].
    3. largest = 2 at index 3. nextLargest = 1. Reduce nums[3] to 1. nums = [1,1,1,1,2].
    4. largest = 2 at index 4. nextLargest = 1. Reduce nums[4] to 1. nums = [1,1,1,1,1].
    """
def minFlips(s: str) -> int:
    """
    You are given a binary string s. You are allowed to perform two types of operations on the string in any sequence:
    
    Type-1: Remove the character at the start of the string s and append it to the end of the string.
    Type-2: Pick any character in s and flip its value, i.e., if its value is '0' it becomes '1' and vice-versa.
    
    Return the minimum number of type-2 operations you need to perform such that s becomes alternating.
    The string is called alternating if no two adjacent characters are equal.
    
    For example, the strings "010" and "1010" are alternating, while the string "0100" is not.
    
    
    Example 1:
    
    >>> minFlips(s = "111000")
    >>> 2
    Explanation: Use the first operation two times to make s = "100011".
    Then, use the second operation on the third and sixth elements to make s = "101010".
    
    Example 2:
    
    >>> minFlips(s = "010")
    >>> 0
    Explanation: The string is already alternating.
    
    Example 3:
    
    >>> minFlips(s = "1110")
    >>> 1
    Explanation: Use the second operation on the second element to make s = "1010".
    """
def minWastedSpace(packages: List[int], boxes: List[List[int]]) -> int:
    """
    You have n packages that you are trying to place in boxes, one package in each box. There are m suppliers that each produce boxes of different sizes (with infinite supply). A package can be placed in a box if the size of the package is less than or equal to the size of the box.
    The package sizes are given as an integer array packages, where packages[i] is the size of the ith package. The suppliers are given as a 2D integer array boxes, where boxes[j] is an array of box sizes that the jth supplier produces.
    You want to choose a single supplier and use boxes from them such that the total wasted space is minimized. For each package in a box, we define the space wasted to be size of the box - size of the package. The total wasted space is the sum of the space wasted in all the boxes.
    
    For example, if you have to fit packages with sizes [2,3,5] and the supplier offers boxes of sizes [4,8], you can fit the packages of size-2 and size-3 into two boxes of size-4 and the package with size-5 into a box of size-8. This would result in a waste of (4-2) + (4-3) + (8-5) = 6.
    
    Return the minimum total wasted space by choosing the box supplier optimally, or -1 if it is impossible to fit all the packages inside boxes. Since the answer may be large, return it modulo 109 + 7.
    
    Example 1:
    
    >>> minWastedSpace(packages = [2,3,5], boxes = [[4,8],[2,8]])
    >>> 6
    Explanation: It is optimal to choose the first supplier, using two size-4 boxes and one size-8 box.
    The total waste is (4-2) + (4-3) + (8-5) = 6.
    
    Example 2:
    
    >>> minWastedSpace(packages = [2,3,5], boxes = [[1,4],[2,3],[3,4]])
    >>> -1
    Explanation: There is no box that the package of size 5 can fit in.
    
    Example 3:
    
    >>> minWastedSpace(packages = [3,5,8,10,11,12], boxes = [[12],[11,9],[10,5,14]])
    >>> 9
    Explanation: It is optimal to choose the third supplier, using two size-5 boxes, two size-10 boxes, and two size-14 boxes.
    The total waste is (5-3) + (5-5) + (10-8) + (10-10) + (14-11) + (14-12) = 9.
    """
def maxLength(ribbons: List[int], k: int) -> int:
    """
    You are given an integer array ribbons, where ribbons[i] represents the length of the ith ribbon, and an integer k. You may cut any of the ribbons into any number of segments of positive integer lengths, or perform no cuts at all.
    
    For example, if you have a ribbon of length 4, you can:
    
    
    Keep the ribbon of length 4,
    Cut it into one ribbon of length 3 and one ribbon of length 1,
    Cut it into two ribbons of length 2,
    Cut it into one ribbon of length 2 and two ribbons of length 1, or
    Cut it into four ribbons of length 1.
    
    
    
    Your task is to determine the maximum length of ribbon, x, that allows you to cut at least k ribbons, each of length x. You can discard any leftover ribbon from the cuts. If it is impossible to cut k ribbons of the same length, return 0.
    
    Example 1:
    
    >>> maxLength(ribbons = [9,7,5], k = 3)
    >>> 5
    Explanation:
    - Cut the first ribbon to two ribbons, one of length 5 and one of length 4.
    - Cut the second ribbon to two ribbons, one of length 5 and one of length 2.
    - Keep the third ribbon as it is.
    Now you have 3 ribbons of length 5.
    Example 2:
    
    >>> maxLength(ribbons = [7,5,9], k = 4)
    >>> 4
    Explanation:
    - Cut the first ribbon to two ribbons, one of length 4 and one of length 3.
    - Cut the second ribbon to two ribbons, one of length 4 and one of length 1.
    - Cut the third ribbon to three ribbons, two of length 4 and one of length 1.
    Now you have 4 ribbons of length 4.
    
    Example 3:
    
    >>> maxLength(ribbons = [5,7,9], k = 22)
    >>> 0
    Explanation: You cannot obtain k ribbons of the same positive integer length.
    """
def isCovered(ranges: List[List[int]], left: int, right: int) -> bool:
    """
    You are given a 2D integer array ranges and two integers left and right. Each ranges[i] = [starti, endi] represents an inclusive interval between starti and endi.
    Return true if each integer in the inclusive range [left, right] is covered by at least one interval in ranges. Return false otherwise.
    An integer x is covered by an interval ranges[i] = [starti, endi] if starti <= x <= endi.
    
    Example 1:
    
    >>> isCovered(ranges = [[1,2],[3,4],[5,6]], left = 2, right = 5)
    >>> true
    Explanation: Every integer between 2 and 5 is covered:
    - 2 is covered by the first range.
    - 3 and 4 are covered by the second range.
    - 5 is covered by the third range.
    
    Example 2:
    
    >>> isCovered(ranges = [[1,10],[10,20]], left = 21, right = 21)
    >>> false
    Explanation: 21 is not covered by any range.
    """
def chalkReplacer(chalk: List[int], k: int) -> int:
    """
    There are n students in a class numbered from 0 to n - 1. The teacher will give each student a problem starting with the student number 0, then the student number 1, and so on until the teacher reaches the student number n - 1. After that, the teacher will restart the process, starting with the student number 0 again.
    You are given a 0-indexed integer array chalk and an integer k. There are initially k pieces of chalk. When the student number i is given a problem to solve, they will use chalk[i] pieces of chalk to solve that problem. However, if the current number of chalk pieces is strictly less than chalk[i], then the student number i will be asked to replace the chalk.
    Return the index of the student that will replace the chalk pieces.
    
    Example 1:
    
    >>> chalkReplacer(chalk = [5,1,5], k = 22)
    >>> 0
    Explanation: The students go in turns as follows:
    - Student number 0 uses 5 chalk, so k = 17.
    - Student number 1 uses 1 chalk, so k = 16.
    - Student number 2 uses 5 chalk, so k = 11.
    - Student number 0 uses 5 chalk, so k = 6.
    - Student number 1 uses 1 chalk, so k = 5.
    - Student number 2 uses 5 chalk, so k = 0.
    Student number 0 does not have enough chalk, so they will have to replace it.
    Example 2:
    
    >>> chalkReplacer(chalk = [3,4,1,2], k = 25)
    >>> 1
    Explanation: The students go in turns as follows:
    - Student number 0 uses 3 chalk so k = 22.
    - Student number 1 uses 4 chalk so k = 18.
    - Student number 2 uses 1 chalk so k = 17.
    - Student number 3 uses 2 chalk so k = 15.
    - Student number 0 uses 3 chalk so k = 12.
    - Student number 1 uses 4 chalk so k = 8.
    - Student number 2 uses 1 chalk so k = 7.
    - Student number 3 uses 2 chalk so k = 5.
    - Student number 0 uses 3 chalk so k = 2.
    Student number 1 does not have enough chalk, so they will have to replace it.
    """
def largestMagicSquare(grid: List[List[int]]) -> int:
    """
    A k x k magic square is a k x k grid filled with integers such that every row sum, every column sum, and both diagonal sums are all equal. The integers in the magic square do not have to be distinct. Every 1 x 1 grid is trivially a magic square.
    Given an m x n integer grid, return the size (i.e., the side length k) of the largest magic square that can be found within this grid.
    
    Example 1:
    
    
    >>> largestMagicSquare(grid = [[7,1,4,5,6],[2,5,1,6,4],[1,5,4,3,2],[1,2,7,3,4]])
    >>> 3
    Explanation: The largest magic square has a size of 3.
    Every row sum, column sum, and diagonal sum of this magic square is equal to 12.
    - Row sums: 5+1+6 = 5+4+3 = 2+7+3 = 12
    - Column sums: 5+5+2 = 1+4+7 = 6+3+3 = 12
    - Diagonal sums: 5+4+3 = 6+4+2 = 12
    
    Example 2:
    
    
    >>> largestMagicSquare(grid = [[5,1,3,1],[9,3,3,1],[1,3,3,8]])
    >>> 2
    """
def minOperationsToFlip(expression: str) -> int:
    """
    You are given a valid boolean expression as a string expression consisting of the characters '1','0','&' (bitwise AND operator),'|' (bitwise OR operator),'(', and ')'.
    
    For example, "()1|1" and "(1)&()" are not valid while "1", "(((1))|(0))", and "1|(0&(1))" are valid expressions.
    
    Return the minimum cost to change the final value of the expression.
    
    For example, if expression = "1|1|(0&0)&1", its value is 1|1|(0&0)&1 = 1|1|0&1 = 1|0&1 = 1&1 = 1. We want to apply operations so that the new expression evaluates to 0.
    
    The cost of changing the final value of an expression is the number of operations performed on the expression. The types of operations are described as follows:
    
    Turn a '1' into a '0'.
    Turn a '0' into a '1'.
    Turn a '&' into a '|'.
    Turn a '|' into a '&'.
    
    Note: '&' does not take precedence over '|' in the order of calculation. Evaluate parentheses first, then in left-to-right order.
    
    Example 1:
    
    >>> minOperationsToFlip(expression = "1&(0|1)")
    >>> 1
    Explanation: We can turn "1&(0|1)" into "1&(0&1)" by changing the '|' to a '&' using 1 operation.
    The new expression evaluates to 0.
    
    Example 2:
    
    >>> minOperationsToFlip(expression = "(0&0)&(0&0&0)")
    >>> 3
    Explanation: We can turn "(0&0)&(0&0&0)" into "(0|1)|(0&0&0)" using 3 operations.
    The new expression evaluates to 1.
    
    Example 3:
    
    >>> minOperationsToFlip(expression = "(0|(1|0&1))")
    >>> 1
    Explanation: We can turn "(0|(1|0&1))" into "(0|(0|0&1))" using 1 operation.
    The new expression evaluates to 0.
    """
def makeEqual(words: List[str]) -> bool:
    """
    You are given an array of strings words (0-indexed).
    In one operation, pick two distinct indices i and j, where words[i] is a non-empty string, and move any character from words[i] to any position in words[j].
    Return true if you can make every string in words equal using any number of operations, and false otherwise.
    
    Example 1:
    
    >>> makeEqual(words = ["abc","aabc","bc"])
    >>> true
    Explanation: Move the first 'a' in words[1] to the front of words[2],
    to make words[1] = "abc" and words[2] = "abc".
    All the strings are now equal to "abc", so return true.
    
    Example 2:
    
    >>> makeEqual(words = ["ab","a"])
    >>> false
    Explanation: It is impossible to make all the strings equal using the operation.
    """
def maximumRemovals(s: str, p: str, removable: List[int]) -> int:
    """
    You are given two strings s and p where p is a subsequence of s. You are also given a distinct 0-indexed integer array removable containing a subset of indices of s (s is also 0-indexed).
    You want to choose an integer k (0 <= k <= removable.length) such that, after removing k characters from s using the first k indices in removable, p is still a subsequence of s. More formally, you will mark the character at s[removable[i]] for each 0 <= i < k, then remove all marked characters and check if p is still a subsequence.
    Return the maximum k you can choose such that p is still a subsequence of s after the removals.
    A subsequence of a string is a new string generated from the original string with some characters (can be none) deleted without changing the relative order of the remaining characters.
    
    Example 1:
    
    >>> maximumRemovals(s = "abcacb", p = "ab", removable = [3,1,0])
    >>> 2
    Explanation: After removing the characters at indices 3 and 1, "abcacb" becomes "accb".
    "ab" is a subsequence of "accb".
    If we remove the characters at indices 3, 1, and 0, "abcacb" becomes "ccb", and "ab" is no longer a subsequence.
    Hence, the maximum k is 2.
    
    Example 2:
    
    >>> maximumRemovals(s = "abcbddddd", p = "abcd", removable = [3,2,1,4,5,6])
    >>> 1
    Explanation: After removing the character at index 3, "abcbddddd" becomes "abcddddd".
    "abcd" is a subsequence of "abcddddd".
    
    Example 3:
    
    >>> maximumRemovals(s = "abcab", p = "abc", removable = [0,1,2,3,4])
    >>> 0
    Explanation: If you remove the first index in the array removable, "abc" is no longer a subsequence.
    """