ShwStone/humaneval-leetcode huggingface dataset:
def maxDivScore(nums: List[int], divisors: List[int]) -> int:
    """
    You are given two integer arrays nums and divisors.
    The divisibility score of divisors[i] is the number of indices j such that nums[j] is divisible by divisors[i].
    Return the integer divisors[i] with the maximum divisibility score. If multiple integers have the maximum score, return the smallest one.
    
    Example 1:
    
    >>> maxDivScore(nums = [2,9,15,50], divisors = [5,3,7,2])
    >>> 2
    Explanation:
    The divisibility score of divisors[0] is 2 since nums[2] and nums[3] are divisible by 5.
    The divisibility score of divisors[1] is 2 since nums[1] and nums[2] are divisible by 3.
    The divisibility score of divisors[2] is 0 since none of the numbers in nums is divisible by 7.
    The divisibility score of divisors[3] is 2 since nums[0] and nums[3] are divisible by 2.
    As divisors[0], divisors[1], and divisors[3] have the same divisibility score, we return the smaller one which is divisors[3].
    
    Example 2:
    
    >>> maxDivScore(nums = [4,7,9,3,9], divisors = [5,2,3])
    >>> 3
    Explanation:
    The divisibility score of divisors[0] is 0 since none of numbers in nums is divisible by 5.
    The divisibility score of divisors[1] is 1 since only nums[0] is divisible by 2.
    The divisibility score of divisors[2] is 3 since nums[2], nums[3] and nums[4] are divisible by 3.
    
    Example 3:
    
    >>> maxDivScore(nums = [20,14,21,10], divisors = [10,16,20])
    >>> 10
    Explanation:
    The divisibility score of divisors[0] is 2 since nums[0] and nums[3] are divisible by 10.
    The divisibility score of divisors[1] is 0 since none of the numbers in nums is divisible by 16.
    The divisibility score of divisors[2] is 1 since nums[0] is divisible by 20.
    """
def addMinimum(word: str) -> int:
    """
    Given a string word to which you can insert letters "a", "b" or "c" anywhere and any number of times, return the minimum number of letters that must be inserted so that word becomes valid.
    A string is called valid if it can be formed by concatenating the string "abc" several times.
    
    Example 1:
    
    >>> addMinimum(word = "b")
    >>> 2
    Explanation: Insert the letter "a" right before "b", and the letter "c" right next to "b" to obtain the valid string "abc".
    
    Example 2:
    
    >>> addMinimum(word = "aaa")
    >>> 6
    Explanation: Insert letters "b" and "c" next to each "a" to obtain the valid string "abcabcabc".
    
    Example 3:
    
    >>> addMinimum(word = "abc")
    >>> 0
    Explanation: word is already valid. No modifications are needed.
    """
def minimumTotalPrice(n: int, edges: List[List[int]], price: List[int], trips: List[List[int]]) -> int:
    """
    There exists an undirected and 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.
    Additionally, you are given a 2D integer array trips, where trips[i] = [starti, endi] indicates that you start the ith trip from the node starti and travel to the node endi by any path you like.
    Before performing your first trip, you can choose some non-adjacent nodes and halve the prices.
    Return the minimum total price sum to perform all the given trips.
    
    Example 1:
    
    
    >>> minimumTotalPrice(n = 4, edges = [[0,1],[1,2],[1,3]], price = [2,2,10,6], trips = [[0,3],[2,1],[2,3]])
    >>> 23
    Explanation: The diagram above denotes the tree after rooting it at node 2. The first part shows the initial tree and the second part shows the tree after choosing nodes 0, 2, and 3, and making their price half.
    For the 1st trip, we choose path [0,1,3]. The price sum of that path is 1 + 2 + 3 = 6.
    For the 2nd trip, we choose path [2,1]. The price sum of that path is 2 + 5 = 7.
    For the 3rd trip, we choose path [2,1,3]. The price sum of that path is 5 + 2 + 3 = 10.
    The total price sum of all trips is 6 + 7 + 10 = 23.
    It can be proven, that 23 is the minimum answer that we can achieve.
    
    Example 2:
    
    
    >>> minimumTotalPrice(n = 2, edges = [[0,1]], price = [2,2], trips = [[0,0]])
    >>> 1
    Explanation: The diagram above denotes the tree after rooting it at node 0. The first part shows the initial tree and the second part shows the tree after choosing node 0, and making its price half.
    For the 1st trip, we choose path [0]. The price sum of that path is 1.
    The total price sum of all trips is 1. It can be proven, that 1 is the minimum answer that we can achieve.
    """
def colorRed(n: int) -> List[List[int]]:
    """
    You are given an integer n. Consider an equilateral triangle of side length n, broken up into n2 unit equilateral triangles. The triangle has n 1-indexed rows where the ith row has 2i - 1 unit equilateral triangles.
    The triangles in the ith row are also 1-indexed with coordinates from (i, 1) to (i, 2i - 1). The following image shows a triangle of side length 4 with the indexing of its triangle.
    
    Two triangles are neighbors if they share a side. For example:
    
    Triangles (1,1) and (2,2) are neighbors
    Triangles (3,2) and (3,3) are neighbors.
    Triangles (2,2) and (3,3) are not neighbors because they do not share any side.
    
    Initially, all the unit triangles are white. You want to choose k triangles and color them red. We will then run the following algorithm:
    
    Choose a white triangle that has at least two red neighbors.
    
    
    If there is no such triangle, stop the algorithm.
    
    
    Color that triangle red.
    Go to step 1.
    
    Choose the minimum k possible and set k triangles red before running this algorithm such that after the algorithm stops, all unit triangles are colored red.
    Return a 2D list of the coordinates of the triangles that you will color red initially. The answer has to be of the smallest size possible. If there are multiple valid solutions, return any.
    
    Example 1:
    
    
    >>> colorRed(n = 3)
    >>> [[1,1],[2,1],[2,3],[3,1],[3,5]]
    Explanation: Initially, we choose the shown 5 triangles to be red. Then, we run the algorithm:
    - Choose (2,2) that has three red neighbors and color it red.
    - Choose (3,2) that has two red neighbors and color it red.
    - Choose (3,4) that has three red neighbors and color it red.
    - Choose (3,3) that has three red neighbors and color it red.
    It can be shown that choosing any 4 triangles and running the algorithm will not make all triangles red.
    
    Example 2:
    
    
    >>> colorRed(n = 2)
    >>> [[1,1],[2,1],[2,3]]
    Explanation: Initially, we choose the shown 3 triangles to be red. Then, we run the algorithm:
    - Choose (2,2) that has three red neighbors and color it red.
    It can be shown that choosing any 2 triangles and running the algorithm will not make all triangles red.
    """
def findDelayedArrivalTime(arrivalTime: int, delayedTime: int) -> int:
    """
    You are given a positive integer arrivalTime denoting the arrival time of a train in hours, and another positive integer delayedTime denoting the amount of delay in hours.
    Return the time when the train will arrive at the station.
    Note that the time in this problem is in 24-hours format.
    
    Example 1:
    
    >>> findDelayedArrivalTime(arrivalTime = 15, delayedTime = 5)
    >>> 20
    Explanation: Arrival time of the train was 15:00 hours. It is delayed by 5 hours. Now it will reach at 15+5 = 20 (20:00 hours).
    
    Example 2:
    
    >>> findDelayedArrivalTime(arrivalTime = 13, delayedTime = 11)
    >>> 0
    Explanation: Arrival time of the train was 13:00 hours. It is delayed by 11 hours. Now it will reach at 13+11=24 (Which is denoted by 00:00 in 24 hours format so return 0).
    """
def sumOfMultiples(n: int) -> int:
    """
    Given a positive integer n, find the sum of all integers in the range [1, n] inclusive that are divisible by 3, 5, or 7.
    Return an integer denoting the sum of all numbers in the given range satisfying the constraint.
    
    Example 1:
    
    >>> sumOfMultiples(n = 7)
    >>> 21
    Explanation: Numbers in the range [1, 7] that are divisible by 3, 5, or 7 are 3, 5, 6, 7. The sum of these numbers is 21.
    
    Example 2:
    
    >>> sumOfMultiples(n = 10)
    >>> 40
    Explanation: Numbers in the range [1, 10] that are divisible by 3, 5, or 7 are 3, 5, 6, 7, 9, 10. The sum of these numbers is 40.
    
    Example 3:
    
    >>> sumOfMultiples(n = 9)
    >>> 30
    Explanation: Numbers in the range [1, 9] that are divisible by 3, 5, or 7 are 3, 5, 6, 7, 9. The sum of these numbers is 30.
    """
def getSubarrayBeauty(nums: List[int], k: int, x: int) -> List[int]:
    """
    Given an integer array nums containing n integers, find the beauty of each subarray of size k.
    The beauty of a subarray is the xth smallest integer in the subarray if it is negative, or 0 if there are fewer than x negative integers.
    Return an integer array containing n - k + 1 integers, which denote the beauty of the subarrays in order from the first index in the array.
    
    
    A subarray is a contiguous non-empty sequence of elements within an array.
    
    
    
    Example 1:
    
    >>> getSubarrayBeauty(nums = [1,-1,-3,-2,3], k = 3, x = 2)
    >>> [-1,-2,-2]
    Explanation: There are 3 subarrays with size k = 3.
    The first subarray is [1, -1, -3] and the 2nd smallest negative integer is -1.
    The second subarray is [-1, -3, -2] and the 2nd smallest negative integer is -2.
    The third subarray is [-3, -2, 3] and the 2nd smallest negative integer is -2.
    Example 2:
    
    >>> getSubarrayBeauty(nums = [-1,-2,-3,-4,-5], k = 2, x = 2)
    >>> [-1,-2,-3,-4]
    Explanation: There are 4 subarrays with size k = 2.
    For [-1, -2], the 2nd smallest negative integer is -1.
    For [-2, -3], the 2nd smallest negative integer is -2.
    For [-3, -4], the 2nd smallest negative integer is -3.
    For [-4, -5], the 2nd smallest negative integer is -4.
    Example 3:
    
    >>> getSubarrayBeauty(nums = [-3,1,2,-3,0,-3], k = 2, x = 1)
    >>> [-3,0,-3,-3,-3]
    Explanation: There are 5 subarrays with size k = 2.
    For [-3, 1], the 1st smallest negative integer is -3.
    For [1, 2], there is no negative integer so the beauty is 0.
    For [2, -3], the 1st smallest negative integer is -3.
    For [-3, 0], the 1st smallest negative integer is -3.
    For [0, -3], the 1st smallest negative integer is -3.
    """
def minOperations(nums: List[int]) -> int:
    """
    You are given a 0-indexed array nums consisiting of positive integers. You can do the following operation on the array any number of times:
    
    Select an index i such that 0 <= i < n - 1 and replace either of nums[i] or nums[i+1] with their gcd value.
    
    Return the minimum number of operations to make all elements of nums equal to 1. If it is impossible, return -1.
    The gcd of two integers is the greatest common divisor of the two integers.
    
    Example 1:
    
    >>> minOperations(nums = [2,6,3,4])
    >>> 4
    Explanation: We can do the following operations:
    - Choose index i = 2 and replace nums[2] with gcd(3,4) = 1. Now we have nums = [2,6,1,4].
    - Choose index i = 1 and replace nums[1] with gcd(6,1) = 1. Now we have nums = [2,1,1,4].
    - Choose index i = 0 and replace nums[0] with gcd(2,1) = 1. Now we have nums = [1,1,1,4].
    - Choose index i = 2 and replace nums[3] with gcd(1,4) = 1. Now we have nums = [1,1,1,1].
    
    Example 2:
    
    >>> minOperations(nums = [2,10,6,14])
    >>> -1
    Explanation: It can be shown that it is impossible to make all the elements equal to 1.
    """
def findMaximalUncoveredRanges(n: int, ranges: List[List[int]]) -> List[List[int]]:
    """
    You are given an integer n which is the length of a 0-indexed array nums, and a 0-indexed 2D-array ranges, which is a list of sub-ranges of nums (sub-ranges may overlap).
    Each row ranges[i] has exactly 2 cells:
    
    ranges[i][0], which shows the start of the ith range (inclusive)
    ranges[i][1], which shows the end of the ith range (inclusive)
    
    These ranges cover some cells of nums and leave some cells uncovered. Your task is to find all of the uncovered ranges with maximal length.
    Return a 2D-array answer of the uncovered ranges, sorted by the starting point in ascending order.
    By all of the uncovered ranges with maximal length, we mean satisfying two conditions:
    
    Each uncovered cell should belong to exactly one sub-range
    There should not exist two ranges (l1, r1) and (l2, r2) such that r1 + 1 = l2
    
    
    Example 1:
    
    >>> findMaximalUncoveredRanges(n = 10, ranges = [[3,5],[7,8]])
    >>> [[0,2],[6,6],[9,9]]
    Explanation: The ranges (3, 5) and (7, 8) are covered, so if we simplify the array nums to a binary array where 0 shows an uncovered cell and 1 shows a covered cell, the array becomes [0,0,0,1,1,1,0,1,1,0] in which we can observe that the ranges (0, 2), (6, 6) and (9, 9) aren't covered.
    
    Example 2:
    
    >>> findMaximalUncoveredRanges(n = 3, ranges = [[0,2]])
    >>> []
    Explanation: In this example, the whole of the array nums is covered and there are no uncovered cells so the output is an empty array.
    
    Example 3:
    
    >>> findMaximalUncoveredRanges(n = 7, ranges = [[2,4],[0,3]])
    >>> [[5,6]]
    Explanation: The ranges (0, 3) and (2, 4) are covered, so if we simplify the array nums to a binary array where 0 shows an uncovered cell and 1 shows a covered cell, the array becomes [1,1,1,1,1,0,0] in which we can observe that the range (5, 6) is uncovered.
    """
def maximizeSum(nums: List[int], k: int) -> int:
    """
    You are given a 0-indexed integer array nums and an integer k. Your task is to perform the following operation exactly k times in order to maximize your score:
    
    Select an element m from nums.
    Remove the selected element m from the array.
    Add a new element with a value of m + 1 to the array.
    Increase your score by m.
    
    Return the maximum score you can achieve after performing the operation exactly k times.
    
    Example 1:
    
    >>> maximizeSum(nums = [1,2,3,4,5], k = 3)
    >>> 18
    Explanation: We need to choose exactly 3 elements from nums to maximize the sum.
    For the first iteration, we choose 5. Then sum is 5 and nums = [1,2,3,4,6]
    For the second iteration, we choose 6. Then sum is 5 + 6 and nums = [1,2,3,4,7]
    For the third iteration, we choose 7. Then sum is 5 + 6 + 7 = 18 and nums = [1,2,3,4,8]
    So, we will return 18.
    It can be proven, that 18 is the maximum answer that we can achieve.
    
    Example 2:
    
    >>> maximizeSum(nums = [5,5,5], k = 2)
    >>> 11
    Explanation: We need to choose exactly 2 elements from nums to maximize the sum.
    For the first iteration, we choose 5. Then sum is 5 and nums = [5,5,6]
    For the second iteration, we choose 6. Then sum is 5 + 6 = 11 and nums = [5,5,7]
    So, we will return 11.
    It can be proven, that 11 is the maximum answer that we can achieve.
    """
def findThePrefixCommonArray(A: List[int], B: List[int]) -> List[int]:
    """
    You are given two 0-indexed integer permutations A and B of length n.
    A prefix common array of A and B is an array C such that C[i] is equal to the count of numbers that are present at or before the index i in both A and B.
    Return the prefix common array of A and B.
    A sequence of n integers is called a permutation if it contains all integers from 1 to n exactly once.
    
    Example 1:
    
    >>> findThePrefixCommonArray(A = [1,3,2,4], B = [3,1,2,4])
    >>> [0,2,3,4]
    Explanation: At i = 0: no number is common, so C[0] = 0.
    At i = 1: 1 and 3 are common in A and B, so C[1] = 2.
    At i = 2: 1, 2, and 3 are common in A and B, so C[2] = 3.
    At i = 3: 1, 2, 3, and 4 are common in A and B, so C[3] = 4.
    
    Example 2:
    
    >>> findThePrefixCommonArray(A = [2,3,1], B = [3,1,2])
    >>> [0,1,3]
    Explanation: At i = 0: no number is common, so C[0] = 0.
    At i = 1: only 3 is common in A and B, so C[1] = 1.
    At i = 2: 1, 2, and 3 are common in A and B, so C[2] = 3.
    """
def findMaxFish(grid: List[List[int]]) -> int:
    """
    You are given a 0-indexed 2D matrix grid of size m x n, where (r, c) represents:
    
    A land cell if grid[r][c] = 0, or
    A water cell containing grid[r][c] fish, if grid[r][c] > 0.
    
    A fisher can start at any water cell (r, c) and can do the following operations any number of times:
    
    Catch all the fish at cell (r, c), or
    Move to any adjacent water cell.
    
    Return the maximum number of fish the fisher can catch if he chooses his starting cell optimally, or 0 if no water cell exists.
    An adjacent cell of the cell (r, c), is one of the cells (r, c + 1), (r, c - 1), (r + 1, c) or (r - 1, c) if it exists.
    
    Example 1:
    
    
    >>> findMaxFish(grid = [[0,2,1,0],[4,0,0,3],[1,0,0,4],[0,3,2,0]])
    >>> 7
    Explanation: The fisher can start at cell (1,3) and collect 3 fish, then move to cell (2,3) and collect 4 fish.
    
    Example 2:
    
    
    >>> findMaxFish(grid = [[1,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,1]])
    >>> 1
    Explanation: The fisher can start at cells (0,0) or (3,3) and collect a single fish.
    """
def countOperationsToEmptyArray(nums: List[int]) -> int:
    """
    You are given an integer array nums containing distinct numbers, and you can perform the following operations until the array is empty:
    
    If the first element has the smallest value, remove it
    Otherwise, put the first element at the end of the array.
    
    Return an integer denoting the number of operations it takes to make nums empty.
    
    Example 1:
    
    >>> countOperationsToEmptyArray(nums = [3,4,-1])
    >>> 5
    
    
    
    
    Operation
    Array
    
    
    
    
    1
    [4, -1, 3]
    
    
    2
    [-1, 3, 4]
    
    
    3
    [3, 4]
    
    
    4
    [4]
    
    
    5
    []
    
    
    
    Example 2:
    
    >>> countOperationsToEmptyArray(nums = [1,2,4,3])
    >>> 5
    
    
    
    
    Operation
    Array
    
    
    
    
    1
    [2, 4, 3]
    
    
    2
    [4, 3]
    
    
    3
    [3, 4]
    
    
    4
    [4]
    
    
    5
    []
    
    
    
    Example 3:
    
    >>> countOperationsToEmptyArray(nums = [1,2,3])
    >>> 3
    
    
    
    
    Operation
    Array
    
    
    
    
    1
    [2, 3]
    
    
    2
    [3]
    
    
    3
    []
    """
def isWinner(player1: List[int], player2: List[int]) -> int:
    """
    You are given two 0-indexed integer arrays player1 and player2, representing the number of pins that player 1 and player 2 hit in a bowling game, respectively.
    The bowling game consists of n turns, and the number of pins in each turn is exactly 10.
    Assume a player hits xi pins in the ith turn. The value of the ith turn for the player is:
    
    2xi if the player hits 10 pins in either (i - 1)th or (i - 2)th turn.
    Otherwise, it is xi.
    
    The score of the player is the sum of the values of their n turns.
    Return
    
    1 if the score of player 1 is more than the score of player 2,
    2 if the score of player 2 is more than the score of player 1, and
    0 in case of a draw.
    
    
    Example 1:
    
    >>> isWinner(player1 = [5,10,3,2], player2 = [6,5,7,3])
    >>> 1
    Explanation:
    The score of player 1 is 5 + 10 + 2*3 + 2*2 = 25.
    The score of player 2 is 6 + 5 + 7 + 3 = 21.
    
    Example 2:
    
    >>> isWinner(player1 = [3,5,7,6], player2 = [8,10,10,2])
    >>> 2
    Explanation:
    The score of player 1 is 3 + 5 + 7 + 6 = 21.
    The score of player 2 is 8 + 10 + 2*10 + 2*2 = 42.
    
    Example 3:
    
    >>> isWinner(player1 = [2,3], player2 = [4,1])
    >>> 0
    Explanation:
    The score of player1 is 2 + 3 = 5.
    The score of player2 is 4 + 1 = 5.
    
    Example 4:
    
    >>> isWinner(player1 = [1,1,1,10,10,10,10], player2 = [10,10,10,10,1,1,1])
    >>> 2
    Explanation:
    The score of player1 is 1 + 1 + 1 + 10 + 2*10 + 2*10 + 2*10 = 73.
    The score of player2 is 10 + 2*10 + 2*10 + 2*10 + 2*1 + 2*1 + 1 = 75.
    """
def firstCompleteIndex(arr: List[int], mat: List[List[int]]) -> int:
    """
    You are given a 0-indexed integer array arr, and an m x n integer matrix mat. arr and mat both contain all the integers in the range [1, m * n].
    Go through each index i in arr starting from index 0 and paint the cell in mat containing the integer arr[i].
    Return the smallest index i at which either a row or a column will be completely painted in mat.
    
    Example 1:
    
    
    >>> firstCompleteIndex(arr = [1,3,4,2], mat = [[1,4],[2,3]])
    >>> 2
    Explanation: The moves are shown in order, and both the first row and second column of the matrix become fully painted at arr[2].
    
    Example 2:
    
    
    >>> firstCompleteIndex(arr = [2,8,7,4,1,3,5,6,9], mat = [[3,2,5],[1,4,6],[8,7,9]])
    >>> 3
    Explanation: The second column becomes fully painted at arr[3].
    """
def minimumCost(start: List[int], target: List[int], specialRoads: List[List[int]]) -> int:
    """
    You are given an array start where start = [startX, startY] represents your initial position (startX, startY) in a 2D space. You are also given the array target where target = [targetX, targetY] represents your target position (targetX, targetY).
    The cost of going from a position (x1, y1) to any other position in the space (x2, y2) is |x2 - x1| + |y2 - y1|.
    There are also some special roads. You are given a 2D array specialRoads where specialRoads[i] = [x1i, y1i, x2i, y2i, costi] indicates that the ith special road goes in one direction from (x1i, y1i) to (x2i, y2i) with a cost equal to costi. You can use each special road any number of times.
    Return the minimum cost required to go from (startX, startY) to (targetX, targetY).
    
    Example 1:
    
    >>> minimumCost(start = [1,1], target = [4,5], specialRoads = [[1,2,3,3,2],[3,4,4,5,1]])
    >>> 5
    Explanation:
    
    (1,1) to (1,2) with a cost of |1 - 1| + |2 - 1| = 1.
    (1,2) to (3,3). Use specialRoads[0] with the cost 2.
    (3,3) to (3,4) with a cost of |3 - 3| + |4 - 3| = 1.
    (3,4) to (4,5). Use specialRoads[1] with the cost 1.
    
    So the total cost is 1 + 2 + 1 + 1 = 5.
    
    Example 2:
    
    >>> minimumCost(start = [3,2], target = [5,7], specialRoads = [[5,7,3,2,1],[3,2,3,4,4],[3,3,5,5,5],[3,4,5,6,6]])
    >>> 7
    Explanation:
    It is optimal not to use any special edges and go directly from the starting to the ending position with a cost |5 - 3| + |7 - 2| = 7.
    Note that the specialRoads[0] is directed from (5,7) to (3,2).
    
    Example 3:
    
    >>> minimumCost(start = [1,1], target = [10,4], specialRoads = [[4,2,1,1,3],[1,2,7,4,4],[10,3,6,1,2],[6,1,1,2,3]])
    >>> 8
    Explanation:
    
    (1,1) to (1,2) with a cost of |1 - 1| + |2 - 1| = 1.
    (1,2) to (7,4). Use specialRoads[1] with the cost 4.
    (7,4) to (10,4) with a cost of |10 - 7| + |4 - 4| = 3.
    """