ShwStone/humaneval-leetcode huggingface dataset:
def categorizeBox(length: int, width: int, height: int, mass: int) -> str:
    """
    Given four integers length, width, height, and mass, representing the dimensions and mass of a box, respectively, return a string representing the category of the box.
    
    The box is "Bulky" if:
    
    
    Any of the dimensions of the box is greater or equal to 104.
    Or, the volume of the box is greater or equal to 109.
    
    
    If the mass of the box is greater or equal to 100, it is "Heavy".
    If the box is both "Bulky" and "Heavy", then its category is "Both".
    If the box is neither "Bulky" nor "Heavy", then its category is "Neither".
    If the box is "Bulky" but not "Heavy", then its category is "Bulky".
    If the box is "Heavy" but not "Bulky", then its category is "Heavy".
    
    Note that the volume of the box is the product of its length, width and height.
    
    Example 1:
    
    >>> categorizeBox(length = 1000, width = 35, height = 700, mass = 300)
    >>> "Heavy"
    Explanation:
    None of the dimensions of the box is greater or equal to 104.
    Its volume = 24500000 <= 109. So it cannot be categorized as "Bulky".
    However mass >= 100, so the box is "Heavy".
    Since the box is not "Bulky" but "Heavy", we return "Heavy".
    Example 2:
    
    >>> categorizeBox(length = 200, width = 50, height = 800, mass = 50)
    >>> "Neither"
    Explanation:
    None of the dimensions of the box is greater or equal to 104.
    Its volume = 8 * 106 <= 109. So it cannot be categorized as "Bulky".
    Its mass is also less than 100, so it cannot be categorized as "Heavy" either.
    Since its neither of the two above categories, we return "Neither".
    """
def xorBeauty(nums: List[int]) -> int:
    """
    You are given a 0-indexed integer array nums.
    The effective value of three indices i, j, and k is defined as ((nums[i] | nums[j]) & nums[k]).
    The xor-beauty of the array is the XORing of the effective values of all the possible triplets of indices (i, j, k) where 0 <= i, j, k < n.
    Return the xor-beauty of nums.
    Note that:
    
    val1 | val2 is bitwise OR of val1 and val2.
    val1 & val2 is bitwise AND of val1 and val2.
    
    
    Example 1:
    
    >>> xorBeauty(nums = [1,4])
    >>> 5
    Explanation:
    The triplets and their corresponding effective values are listed below:
    - (0,0,0) with effective value ((1 | 1) & 1) = 1
    - (0,0,1) with effective value ((1 | 1) & 4) = 0
    - (0,1,0) with effective value ((1 | 4) & 1) = 1
    - (0,1,1) with effective value ((1 | 4) & 4) = 4
    - (1,0,0) with effective value ((4 | 1) & 1) = 1
    - (1,0,1) with effective value ((4 | 1) & 4) = 4
    - (1,1,0) with effective value ((4 | 4) & 1) = 0
    - (1,1,1) with effective value ((4 | 4) & 4) = 4
    Xor-beauty of array will be bitwise XOR of all beauties = 1 ^ 0 ^ 1 ^ 4 ^ 1 ^ 4 ^ 0 ^ 4 = 5.
    Example 2:
    
    >>> xorBeauty(nums = [15,45,20,2,34,35,5,44,32,30])
    >>> 34
    Explanation: The xor-beauty of the given array is 34.
    """
def maxPower(stations: List[int], r: int, k: int) -> int:
    """
    You are given a 0-indexed integer array stations of length n, where stations[i] represents the number of power stations in the ith city.
    Each power station can provide power to every city in a fixed range. In other words, if the range is denoted by r, then a power station at city i can provide power to all cities j such that |i - j| <= r and 0 <= i, j <= n - 1.
    
    Note that |x| denotes absolute value. For example, |7 - 5| = 2 and |3 - 10| = 7.
    
    The power of a city is the total number of power stations it is being provided power from.
    The government has sanctioned building k more power stations, each of which can be built in any city, and have the same range as the pre-existing ones.
    Given the two integers r and k, return the maximum possible minimum power of a city, if the additional power stations are built optimally.
    Note that you can build the k power stations in multiple cities.
    
    Example 1:
    
    >>> maxPower(stations = [1,2,4,5,0], r = 1, k = 2)
    >>> 5
    Explanation:
    One of the optimal ways is to install both the power stations at city 1.
    So stations will become [1,4,4,5,0].
    - City 0 is provided by 1 + 4 = 5 power stations.
    - City 1 is provided by 1 + 4 + 4 = 9 power stations.
    - City 2 is provided by 4 + 4 + 5 = 13 power stations.
    - City 3 is provided by 5 + 4 = 9 power stations.
    - City 4 is provided by 5 + 0 = 5 power stations.
    So the minimum power of a city is 5.
    Since it is not possible to obtain a larger power, we return 5.
    
    Example 2:
    
    >>> maxPower(stations = [4,4,4,4], r = 0, k = 3)
    >>> 4
    Explanation:
    It can be proved that we cannot make the minimum power of a city greater than 4.
    """
def maximumCount(nums: List[int]) -> int:
    """
    Given an array nums sorted in non-decreasing order, return the maximum between the number of positive integers and the number of negative integers.
    
    In other words, if the number of positive integers in nums is pos and the number of negative integers is neg, then return the maximum of pos and neg.
    
    Note that 0 is neither positive nor negative.
    
    Example 1:
    
    >>> maximumCount(nums = [-2,-1,-1,1,2,3])
    >>> 3
    Explanation: There are 3 positive integers and 3 negative integers. The maximum count among them is 3.
    
    Example 2:
    
    >>> maximumCount(nums = [-3,-2,-1,0,0,1,2])
    >>> 3
    Explanation: There are 2 positive integers and 3 negative integers. The maximum count among them is 3.
    
    Example 3:
    
    >>> maximumCount(nums = [5,20,66,1314])
    >>> 4
    Explanation: There are 4 positive integers and 0 negative integers. The maximum count among them is 4.
    """
def maxKelements(nums: List[int], k: int) -> int:
    """
    You are given a 0-indexed integer array nums and an integer k. You have a starting score of 0.
    In one operation:
    
    choose an index i such that 0 <= i < nums.length,
    increase your score by nums[i], and
    replace nums[i] with ceil(nums[i] / 3).
    
    Return the maximum possible score you can attain after applying exactly k operations.
    The ceiling function ceil(val) is the least integer greater than or equal to val.
    
    Example 1:
    
    >>> maxKelements(nums = [10,10,10,10,10], k = 5)
    >>> 50
    Explanation: Apply the operation to each array element exactly once. The final score is 10 + 10 + 10 + 10 + 10 = 50.
    
    Example 2:
    
    >>> maxKelements(nums = [1,10,3,3,3], k = 3)
    >>> 17
    Explanation: You can do the following operations:
    Operation 1: Select i = 1, so nums becomes [1,4,3,3,3]. Your score increases by 10.
    Operation 2: Select i = 1, so nums becomes [1,2,3,3,3]. Your score increases by 4.
    Operation 3: Select i = 2, so nums becomes [1,2,1,3,3]. Your score increases by 3.
    The final score is 10 + 4 + 3 = 17.
    """
def isItPossible(word1: str, word2: str) -> bool:
    """
    You are given two 0-indexed strings word1 and word2.
    A move consists of choosing two indices i and j such that 0 <= i < word1.length and 0 <= j < word2.length and swapping word1[i] with word2[j].
    Return true if it is possible to get the number of distinct characters in word1 and word2 to be equal with exactly one move. Return false otherwise.
    
    Example 1:
    
    >>> isItPossible(word1 = "ac", word2 = "b")
    >>> false
    Explanation: Any pair of swaps would yield two distinct characters in the first string, and one in the second string.
    
    Example 2:
    
    >>> isItPossible(word1 = "abcc", word2 = "aab")
    >>> true
    Explanation: We swap index 2 of the first string with index 0 of the second string. The resulting strings are word1 = "abac" and word2 = "cab", which both have 3 distinct characters.
    
    Example 3:
    
    >>> isItPossible(word1 = "abcde", word2 = "fghij")
    >>> true
    Explanation: Both resulting strings will have 5 distinct characters, regardless of which indices we swap.
    """
def findCrossingTime(n: int, k: int, time: List[List[int]]) -> int:
    """
    There are k workers who want to move n boxes from the right (old) warehouse to the left (new) warehouse. You are given the two integers n and k, and a 2D integer array time of size k x 4 where time[i] = [righti, picki, lefti, puti].
    The warehouses are separated by a river and connected by a bridge. Initially, all k workers are waiting on the left side of the bridge. To move the boxes, the ith worker can do the following:
    
    Cross the bridge to the right side in righti minutes.
    Pick a box from the right warehouse in picki minutes.
    Cross the bridge to the left side in lefti minutes.
    Put the box into the left warehouse in puti minutes.
    
    The ith worker is less efficient than the jth worker if either condition is met:
    
    lefti + righti > leftj + rightj
    lefti + righti == leftj + rightj and i > j
    
    The following rules regulate the movement of the workers through the bridge:
    
    Only one worker can use the bridge at a time.
    When the bridge is unused prioritize the least efficient worker (who have picked up the box) on the right side to cross. If not, prioritize the least efficient worker on the left side to cross.
    If enough workers have already been dispatched from the left side to pick up all the remaining boxes, no more workers will be sent from the left side.
    
    Return the elapsed minutes at which the last box reaches the left side of the bridge.
    
    Example 1:
    
    >>> findCrossingTime(n = 1, k = 3, time = [[1,1,2,1],[1,1,3,1],[1,1,4,1]])
    >>> 6
    Explanation:
    
    From 0 to 1 minutes: worker 2 crosses the bridge to the right.
    From 1 to 2 minutes: worker 2 picks up a box from the right warehouse.
    From 2 to 6 minutes: worker 2 crosses the bridge to the left.
    From 6 to 7 minutes: worker 2 puts a box at the left warehouse.
    The whole process ends after 7 minutes. We return 6 because the problem asks for the instance of time at which the last worker reaches the left side of the bridge.
    
    
    Example 2:
    
    >>> findCrossingTime(n = 3, k = 2, time = [[1,5,1,8],[10,10,10,10]])
    >>> 37
    Explanation:
    
    
    
    The last box reaches the left side at 37 seconds. Notice, how we do not put the last boxes down, as that would take more time, and they are already on the left with the workers.
    """
def goodBinaryStrings(minLength: int, maxLength: int, oneGroup: int, zeroGroup: int) -> int:
    """
    You are given four integers minLength, maxLength, oneGroup and zeroGroup.
    A binary string is good if it satisfies the following conditions:
    
    The length of the string is in the range [minLength, maxLength].
    The size of each block of consecutive 1's is a multiple of oneGroup.
    
    For example in a binary string 00110111100 sizes of each block of consecutive ones are [2,4].
    
    
    The size of each block of consecutive 0's is a multiple of zeroGroup.
    
    For example, in a binary string 00110111100 sizes of each block of consecutive zeros are [2,1,2].
    
    
    
    Return the number of good binary strings. Since the answer may be too large, return it modulo 109 + 7.
    Note that 0 is considered a multiple of all the numbers.
    
    Example 1:
    
    >>> goodBinaryStrings(minLength = 2, maxLength = 3, oneGroup = 1, zeroGroup = 2)
    >>> 5
    Explanation: There are 5 good binary strings in this example: "00", "11", "001", "100", and "111".
    It can be proven that there are only 5 good strings satisfying all conditions.
    
    Example 2:
    
    >>> goodBinaryStrings(minLength = 4, maxLength = 4, oneGroup = 4, zeroGroup = 3)
    >>> 1
    Explanation: There is only 1 good binary string in this example: "1111".
    It can be proven that there is only 1 good string satisfying all conditions.
    """
def timeTaken(arrival: List[int], state: List[int]) -> List[int]:
    """
    There are n persons numbered from 0 to n - 1 and a door. Each person can enter or exit through the door once, taking one second.
    You are given a non-decreasing integer array arrival of size n, where arrival[i] is the arrival time of the ith person at the door. You are also given an array state of size n, where state[i] is 0 if person i wants to enter through the door or 1 if they want to exit through the door.
    If two or more persons want to use the door at the same time, they follow the following rules:
    
    If the door was not used in the previous second, then the person who wants to exit goes first.
    If the door was used in the previous second for entering, the person who wants to enter goes first.
    If the door was used in the previous second for exiting, the person who wants to exit goes first.
    If multiple persons want to go in the same direction, the person with the smallest index goes first.
    
    Return an array answer of size n where answer[i] is the second at which the ith person crosses the door.
    Note that:
    
    Only one person can cross the door at each second.
    A person may arrive at the door and wait without entering or exiting to follow the mentioned rules.
    
    
    Example 1:
    
    >>> timeTaken(arrival = [0,1,1,2,4], state = [0,1,0,0,1])
    >>> [0,3,1,2,4]
    Explanation: At each second we have the following:
    - At t = 0: Person 0 is the only one who wants to enter, so they just enter through the door.
    - At t = 1: Person 1 wants to exit, and person 2 wants to enter. Since the door was used the previous second for entering, person 2 enters.
    - At t = 2: Person 1 still wants to exit, and person 3 wants to enter. Since the door was used the previous second for entering, person 3 enters.
    - At t = 3: Person 1 is the only one who wants to exit, so they just exit through the door.
    - At t = 4: Person 4 is the only one who wants to exit, so they just exit through the door.
    
    Example 2:
    
    >>> timeTaken(arrival = [0,0,0], state = [1,0,1])
    >>> [0,2,1]
    Explanation: At each second we have the following:
    - At t = 0: Person 1 wants to enter while persons 0 and 2 want to exit. Since the door was not used in the previous second, the persons who want to exit get to go first. Since person 0 has a smaller index, they exit first.
    - At t = 1: Person 1 wants to enter, and person 2 wants to exit. Since the door was used in the previous second for exiting, person 2 exits.
    - At t = 2: Person 1 is the only one who wants to enter, so they just enter through the door.
    """
def differenceOfSum(nums: List[int]) -> int:
    """
    You are given a positive integer array nums.
    
    The element sum is the sum of all the elements in nums.
    The digit sum is the sum of all the digits (not necessarily distinct) that appear in nums.
    
    Return the absolute difference between the element sum and digit sum of nums.
    Note that the absolute difference between two integers x and y is defined as |x - y|.
    
    Example 1:
    
    >>> differenceOfSum(nums = [1,15,6,3])
    >>> 9
    Explanation:
    The element sum of nums is 1 + 15 + 6 + 3 = 25.
    The digit sum of nums is 1 + 1 + 5 + 6 + 3 = 16.
    The absolute difference between the element sum and digit sum is |25 - 16| = 9.
    
    Example 2:
    
    >>> differenceOfSum(nums = [1,2,3,4])
    >>> 0
    Explanation:
    The element sum of nums is 1 + 2 + 3 + 4 = 10.
    The digit sum of nums is 1 + 2 + 3 + 4 = 10.
    The absolute difference between the element sum and digit sum is |10 - 10| = 0.
    """
def rangeAddQueries(n: int, queries: List[List[int]]) -> List[List[int]]:
    """
    You are given a positive integer n, indicating that we initially have an n x n 0-indexed integer matrix mat filled with zeroes.
    You are also given a 2D integer array query. For each query[i] = [row1i, col1i, row2i, col2i], you should do the following operation:
    
    Add 1 to every element in the submatrix with the top left corner (row1i, col1i) and the bottom right corner (row2i, col2i). That is, add 1 to mat[x][y] for all row1i <= x <= row2i and col1i <= y <= col2i.
    
    Return the matrix mat after performing every query.
    
    Example 1:
    
    
    >>> rangeAddQueries(n = 3, queries = [[1,1,2,2],[0,0,1,1]])
    >>> [[1,1,0],[1,2,1],[0,1,1]]
    Explanation: The diagram above shows the initial matrix, the matrix after the first query, and the matrix after the second query.
    - In the first query, we add 1 to every element in the submatrix with the top left corner (1, 1) and bottom right corner (2, 2).
    - In the second query, we add 1 to every element in the submatrix with the top left corner (0, 0) and bottom right corner (1, 1).
    
    Example 2:
    
    
    >>> rangeAddQueries(n = 2, queries = [[0,0,1,1]])
    >>> [[1,1],[1,1]]
    Explanation: The diagram above shows the initial matrix and the matrix after the first query.
    - In the first query we add 1 to every element in the matrix.
    """
def countGood(nums: List[int], k: int) -> int:
    """
    Given an integer array nums and an integer k, return the number of good subarrays of nums.
    A subarray arr is good if there are at least k pairs of indices (i, j) such that i < j and arr[i] == arr[j].
    A subarray is a contiguous non-empty sequence of elements within an array.
    
    Example 1:
    
    >>> countGood(nums = [1,1,1,1,1], k = 10)
    >>> 1
    Explanation: The only good subarray is the array nums itself.
    
    Example 2:
    
    >>> countGood(nums = [3,1,4,3,2,2,4], k = 2)
    >>> 4
    Explanation: There are 4 different good subarrays:
    - [3,1,4,3,2,2] that has 2 pairs.
    - [3,1,4,3,2,2,4] that has 3 pairs.
    - [1,4,3,2,2,4] that has 2 pairs.
    - [4,3,2,2,4] that has 2 pairs.
    """
def maxOutput(n: int, edges: List[List[int]], price: List[int]) -> int:
    """
    There exists an undirected and initially unrooted tree with n nodes indexed from 0 to n - 1. You are given the integer n and 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.
    Each node has an associated price. You are given an integer array price, where price[i] is the price of the ith node.
    The price sum of a given path is the sum of the prices of all nodes lying on that path.
    The tree can be rooted at any node root of your choice. The incurred cost after choosing root is the difference between the maximum and minimum price sum amongst all paths starting at root.
    Return the maximum possible cost amongst all possible root choices.
    
    Example 1:
    
    
    >>> maxOutput(n = 6, edges = [[0,1],[1,2],[1,3],[3,4],[3,5]], price = [9,8,7,6,10,5])
    >>> 24
    Explanation: The diagram above denotes the tree after rooting it at node 2. The first part (colored in red) shows the path with the maximum price sum. The second part (colored in blue) shows the path with the minimum price sum.
    - The first path contains nodes [2,1,3,4]: the prices are [7,8,6,10], and the sum of the prices is 31.
    - The second path contains the node [2] with the price [7].
    The difference between the maximum and minimum price sum is 24. It can be proved that 24 is the maximum cost.
    
    Example 2:
    
    
    >>> maxOutput(n = 3, edges = [[0,1],[1,2]], price = [1,1,1])
    >>> 2
    Explanation: The diagram above denotes the tree after rooting it at node 0. The first part (colored in red) shows the path with the maximum price sum. The second part (colored in blue) shows the path with the minimum price sum.
    - The first path contains nodes [0,1,2]: the prices are [1,1,1], and the sum of the prices is 3.
    - The second path contains node [0] with a price [1].
    The difference between the maximum and minimum price sum is 2. It can be proved that 2 is the maximum cost.
    """
def getCommon(nums1: List[int], nums2: List[int]) -> int:
    """
    Given two integer arrays nums1 and nums2, sorted in non-decreasing order, return the minimum integer common to both arrays. If there is no common integer amongst nums1 and nums2, return -1.
    Note that an integer is said to be common to nums1 and nums2 if both arrays have at least one occurrence of that integer.
    
    Example 1:
    
    >>> getCommon(nums1 = [1,2,3], nums2 = [2,4])
    >>> 2
    Explanation: The smallest element common to both arrays is 2, so we return 2.
    
    Example 2:
    
    >>> getCommon(nums1 = [1,2,3,6], nums2 = [2,3,4,5])
    >>> 2
    Explanation: There are two common elements in the array 2 and 3 out of which 2 is the smallest, so 2 is returned.
    """
def minOperations(nums1: List[int], nums2: List[int], k: int) -> int:
    """
    You are given two integer arrays nums1 and nums2 of equal length n and an integer k. You can perform the following operation on nums1:
    
    Choose two indexes i and j and increment nums1[i] by k and decrement nums1[j] by k. In other words, nums1[i] = nums1[i] + k and nums1[j] = nums1[j] - k.
    
    nums1 is said to be equal to nums2 if for all indices i such that 0 <= i < n, nums1[i] == nums2[i].
    Return the minimum number of operations required to make nums1 equal to nums2. If it is impossible to make them equal, return -1.
    
    Example 1:
    
    >>> minOperations(nums1 = [4,3,1,4], nums2 = [1,3,7,1], k = 3)
    >>> 2
    Explanation: In 2 operations, we can transform nums1 to nums2.
    1st operation: i = 2, j = 0. After applying the operation, nums1 = [1,3,4,4].
    2nd operation: i = 2, j = 3. After applying the operation, nums1 = [1,3,7,1].
    One can prove that it is impossible to make arrays equal in fewer operations.
    Example 2:
    
    >>> minOperations(nums1 = [3,8,5,2], nums2 = [2,4,1,6], k = 1)
    >>> -1
    Explanation: It can be proved that it is impossible to make the two arrays equal.
    """
def maxScore(nums1: List[int], nums2: List[int], k: int) -> int:
    """
    You are given two 0-indexed integer arrays nums1 and nums2 of equal length n and a positive integer k. You must choose a subsequence of indices from nums1 of length k.
    For chosen indices i0, i1, ..., ik - 1, your score is defined as:
    
    The sum of the selected elements from nums1 multiplied with the minimum of the selected elements from nums2.
    It can defined simply as: (nums1[i0] + nums1[i1] +...+ nums1[ik - 1]) * min(nums2[i0] , nums2[i1], ... ,nums2[ik - 1]).
    
    Return the maximum possible score.
    A subsequence of indices of an array is a set that can be derived from the set {0, 1, ..., n-1} by deleting some or no elements.
    
    Example 1:
    
    >>> maxScore(nums1 = [1,3,3,2], nums2 = [2,1,3,4], k = 3)
    >>> 12
    Explanation:
    The four possible subsequence scores are:
    - We choose the indices 0, 1, and 2 with score = (1+3+3) * min(2,1,3) = 7.
    - We choose the indices 0, 1, and 3 with score = (1+3+2) * min(2,1,4) = 6.
    - We choose the indices 0, 2, and 3 with score = (1+3+2) * min(2,3,4) = 12.
    - We choose the indices 1, 2, and 3 with score = (3+3+2) * min(1,3,4) = 8.
    Therefore, we return the max score, which is 12.
    
    Example 2:
    
    >>> maxScore(nums1 = [4,2,3,1,1], nums2 = [7,5,10,9,6], k = 1)
    >>> 30
    Explanation:
    Choosing index 2 is optimal: nums1[2] * nums2[2] = 3 * 10 = 30 is the maximum possible score.
    """
def isReachable(targetX: int, targetY: int) -> bool:
    """
    There exists an infinitely large grid. You are currently at point (1, 1), and you need to reach the point (targetX, targetY) using a finite number of steps.
    In one step, you can move from point (x, y) to any one of the following points:
    
    (x, y - x)
    (x - y, y)
    (2 * x, y)
    (x, 2 * y)
    
    Given two integers targetX and targetY representing the X-coordinate and Y-coordinate of your final position, return true if you can reach the point from (1, 1) using some number of steps, and false otherwise.
    
    Example 1:
    
    >>> isReachable(targetX = 6, targetY = 9)
    >>> false
    Explanation: It is impossible to reach (6,9) from (1,1) using any sequence of moves, so false is returned.
    
    Example 2:
    
    >>> isReachable(targetX = 4, targetY = 7)
    >>> true
    Explanation: You can follow the path (1,1) -> (1,2) -> (1,4) -> (1,8) -> (1,7) -> (2,7) -> (4,7).
    """