ShwStone/humaneval-leetcode huggingface dataset:
def countPyramids(grid: List[List[int]]) -> int:
    """
    A farmer has a rectangular grid of land with m rows and n columns that can be divided into unit cells. Each cell is either fertile (represented by a 1) or barren (represented by a 0). All cells outside the grid are considered barren.
    A pyramidal plot of land can be defined as a set of cells with the following criteria:
    
    The number of cells in the set has to be greater than 1 and all cells must be fertile.
    The apex of a pyramid is the topmost cell of the pyramid. The height of a pyramid is the number of rows it covers. Let (r, c) be the apex of the pyramid, and its height be h. Then, the plot comprises of cells (i, j) where r <= i <= r + h - 1 and c - (i - r) <= j <= c + (i - r).
    
    An inverse pyramidal plot of land can be defined as a set of cells with similar criteria:
    
    The number of cells in the set has to be greater than 1 and all cells must be fertile.
    The apex of an inverse pyramid is the bottommost cell of the inverse pyramid. The height of an inverse pyramid is the number of rows it covers. Let (r, c) be the apex of the pyramid, and its height be h. Then, the plot comprises of cells (i, j) where r - h + 1 <= i <= r and c - (r - i) <= j <= c + (r - i).
    
    Some examples of valid and invalid pyramidal (and inverse pyramidal) plots are shown below. Black cells indicate fertile cells.
    
    Given a 0-indexed m x n binary matrix grid representing the farmland, return the total number of pyramidal and inverse pyramidal plots that can be found in grid.
    
    Example 1:
    
    
    >>> countPyramids(grid = [[0,1,1,0],[1,1,1,1]])
    >>> 2
    Explanation: The 2 possible pyramidal plots are shown in blue and red respectively.
    There are no inverse pyramidal plots in this grid.
    Hence total number of pyramidal and inverse pyramidal plots is 2 + 0 = 2.
    
    Example 2:
    
    
    >>> countPyramids(grid = [[1,1,1],[1,1,1]])
    >>> 2
    Explanation: The pyramidal plot is shown in blue, and the inverse pyramidal plot is shown in red.
    Hence the total number of plots is 1 + 1 = 2.
    
    Example 3:
    
    
    >>> countPyramids(grid = [[1,1,1,1,0],[1,1,1,1,1],[1,1,1,1,1],[0,1,0,0,1]])
    >>> 13
    Explanation: There are 7 pyramidal plots, 3 of which are shown in the 2nd and 3rd figures.
    There are 6 inverse pyramidal plots, 2 of which are shown in the last figure.
    The total number of plots is 7 + 6 = 13.
    """
def targetIndices(nums: List[int], target: int) -> List[int]:
    """
    You are given a 0-indexed integer array nums and a target element target.
    A target index is an index i such that nums[i] == target.
    Return a list of the target indices of nums after sorting nums in non-decreasing order. If there are no target indices, return an empty list. The returned list must be sorted in increasing order.
    
    Example 1:
    
    >>> targetIndices(nums = [1,2,5,2,3], target = 2)
    >>> [1,2]
    Explanation: After sorting, nums is [1,2,2,3,5].
    The indices where nums[i] == 2 are 1 and 2.
    
    Example 2:
    
    >>> targetIndices(nums = [1,2,5,2,3], target = 3)
    >>> [3]
    Explanation: After sorting, nums is [1,2,2,3,5].
    The index where nums[i] == 3 is 3.
    
    Example 3:
    
    >>> targetIndices(nums = [1,2,5,2,3], target = 5)
    >>> [4]
    Explanation: After sorting, nums is [1,2,2,3,5].
    The index where nums[i] == 5 is 4.
    """
def getAverages(nums: List[int], k: int) -> List[int]:
    """
    You are given a 0-indexed array nums of n integers, and an integer k.
    The k-radius average for a subarray of nums centered at some index i with the radius k is the average of all elements in nums between the indices i - k and i + k (inclusive). If there are less than k elements before or after the index i, then the k-radius average is -1.
    Build and return an array avgs of length n where avgs[i] is the k-radius average for the subarray centered at index i.
    The average of x elements is the sum of the x elements divided by x, using integer division. The integer division truncates toward zero, which means losing its fractional part.
    
    For example, the average of four elements 2, 3, 1, and 5 is (2 + 3 + 1 + 5) / 4 = 11 / 4 = 2.75, which truncates to 2.
    
    
    Example 1:
    
    
    >>> getAverages(nums = [7,4,3,9,1,8,5,2,6], k = 3)
    >>> [-1,-1,-1,5,4,4,-1,-1,-1]
    Explanation:
    - avg[0], avg[1], and avg[2] are -1 because there are less than k elements before each index.
    - The sum of the subarray centered at index 3 with radius 3 is: 7 + 4 + 3 + 9 + 1 + 8 + 5 = 37.
      Using integer division, avg[3] = 37 / 7 = 5.
    - For the subarray centered at index 4, avg[4] = (4 + 3 + 9 + 1 + 8 + 5 + 2) / 7 = 4.
    - For the subarray centered at index 5, avg[5] = (3 + 9 + 1 + 8 + 5 + 2 + 6) / 7 = 4.
    - avg[6], avg[7], and avg[8] are -1 because there are less than k elements after each index.
    
    Example 2:
    
    >>> getAverages(nums = [100000], k = 0)
    >>> [100000]
    Explanation:
    - The sum of the subarray centered at index 0 with radius 0 is: 100000.
      avg[0] = 100000 / 1 = 100000.
    
    Example 3:
    
    >>> getAverages(nums = [8], k = 100000)
    >>> [-1]
    Explanation:
    - avg[0] is -1 because there are less than k elements before and after index 0.
    """
def minimumDeletions(nums: List[int]) -> int:
    """
    You are given a 0-indexed array of distinct integers nums.
    There is an element in nums that has the lowest value and an element that has the highest value. We call them the minimum and maximum respectively. Your goal is to remove both these elements from the array.
    A deletion is defined as either removing an element from the front of the array or removing an element from the back of the array.
    Return the minimum number of deletions it would take to remove both the minimum and maximum element from the array.
    
    Example 1:
    
    >>> minimumDeletions(nums = [2,10,7,5,4,1,8,6])
    >>> 5
    Explanation:
    The minimum element in the array is nums[5], which is 1.
    The maximum element in the array is nums[1], which is 10.
    We can remove both the minimum and maximum by removing 2 elements from the front and 3 elements from the back.
    This results in 2 + 3 = 5 deletions, which is the minimum number possible.
    
    Example 2:
    
    >>> minimumDeletions(nums = [0,-4,19,1,8,-2,-3,5])
    >>> 3
    Explanation:
    The minimum element in the array is nums[1], which is -4.
    The maximum element in the array is nums[2], which is 19.
    We can remove both the minimum and maximum by removing 3 elements from the front.
    This results in only 3 deletions, which is the minimum number possible.
    
    Example 3:
    
    >>> minimumDeletions(nums = [101])
    >>> 1
    Explanation:
    There is only one element in the array, which makes it both the minimum and maximum element.
    We can remove it with 1 deletion.
    """
def findAllPeople(n: int, meetings: List[List[int]], firstPerson: int) -> List[int]:
    """
    You are given an integer n indicating there are n people numbered from 0 to n - 1. You are also given a 0-indexed 2D integer array meetings where meetings[i] = [xi, yi, timei] indicates that person xi and person yi have a meeting at timei. A person may attend multiple meetings at the same time. Finally, you are given an integer firstPerson.
    Person 0 has a secret and initially shares the secret with a person firstPerson at time 0. This secret is then shared every time a meeting takes place with a person that has the secret. More formally, for every meeting, if a person xi has the secret at timei, then they will share the secret with person yi, and vice versa.
    The secrets are shared instantaneously. That is, a person may receive the secret and share it with people in other meetings within the same time frame.
    Return a list of all the people that have the secret after all the meetings have taken place. You may return the answer in any order.
    
    Example 1:
    
    >>> findAllPeople(n = 6, meetings = [[1,2,5],[2,3,8],[1,5,10]], firstPerson = 1)
    >>> [0,1,2,3,5]
    Explanation:
    At time 0, person 0 shares the secret with person 1.
    At time 5, person 1 shares the secret with person 2.
    At time 8, person 2 shares the secret with person 3.
    At time 10, person 1 shares the secret with person 5.​​​​
    Thus, people 0, 1, 2, 3, and 5 know the secret after all the meetings.
    
    Example 2:
    
    >>> findAllPeople(n = 4, meetings = [[3,1,3],[1,2,2],[0,3,3]], firstPerson = 3)
    >>> [0,1,3]
    Explanation:
    At time 0, person 0 shares the secret with person 3.
    At time 2, neither person 1 nor person 2 know the secret.
    At time 3, person 3 shares the secret with person 0 and person 1.
    Thus, people 0, 1, and 3 know the secret after all the meetings.
    
    Example 3:
    
    >>> findAllPeople(n = 5, meetings = [[3,4,2],[1,2,1],[2,3,1]], firstPerson = 1)
    >>> [0,1,2,3,4]
    Explanation:
    At time 0, person 0 shares the secret with person 1.
    At time 1, person 1 shares the secret with person 2, and person 2 shares the secret with person 3.
    Note that person 2 can share the secret at the same time as receiving it.
    At time 2, person 3 shares the secret with person 4.
    Thus, people 0, 1, 2, 3, and 4 know the secret after all the meetings.
    """
def minimumCost(n: int, highways: List[List[int]], discounts: int) -> int:
    """
    A series of highways connect n cities numbered from 0 to n - 1. You are given a 2D integer array highways where highways[i] = [city1i, city2i, tolli] indicates that there is a highway that connects city1i and city2i, allowing a car to go from city1i to city2i and vice versa for a cost of tolli.
    You are also given an integer discounts which represents the number of discounts you have. You can use a discount to travel across the ith highway for a cost of tolli / 2 (integer division). Each discount may only be used once, and you can only use at most one discount per highway.
    Return the minimum total cost to go from city 0 to city n - 1, or -1 if it is not possible to go from city 0 to city n - 1.
    
    Example 1:
    
    
    >>> minimumCost(n = 5, highways = [[0,1,4],[2,1,3],[1,4,11],[3,2,3],[3,4,2]], discounts = 1)
    >>> 9
    Explanation:
    Go from 0 to 1 for a cost of 4.
    Go from 1 to 4 and use a discount for a cost of 11 / 2 = 5.
    The minimum cost to go from 0 to 4 is 4 + 5 = 9.
    
    Example 2:
    
    
    >>> minimumCost(n = 4, highways = [[1,3,17],[1,2,7],[3,2,5],[0,1,6],[3,0,20]], discounts = 20)
    >>> 8
    Explanation:
    Go from 0 to 1 and use a discount for a cost of 6 / 2 = 3.
    Go from 1 to 2 and use a discount for a cost of 7 / 2 = 3.
    Go from 2 to 3 and use a discount for a cost of 5 / 2 = 2.
    The minimum cost to go from 0 to 3 is 3 + 3 + 2 = 8.
    
    Example 3:
    
    
    >>> minimumCost(n = 4, highways = [[0,1,3],[2,3,2]], discounts = 0)
    >>> -1
    Explanation:
    It is impossible to go from 0 to 3 so return -1.
    """
def findEvenNumbers(digits: List[int]) -> List[int]:
    """
    You are given an integer array digits, where each element is a digit. The array may contain duplicates.
    You need to find all the unique integers that follow the given requirements:
    
    The integer consists of the concatenation of three elements from digits in any arbitrary order.
    The integer does not have leading zeros.
    The integer is even.
    
    For example, if the given digits were [1, 2, 3], integers 132 and 312 follow the requirements.
    Return a sorted array of the unique integers.
    
    Example 1:
    
    >>> findEvenNumbers(digits = [2,1,3,0])
    >>> [102,120,130,132,210,230,302,310,312,320]
    Explanation: All the possible integers that follow the requirements are in the output array.
    Notice that there are no odd integers or integers with leading zeros.
    
    Example 2:
    
    >>> findEvenNumbers(digits = [2,2,8,8,2])
    >>> [222,228,282,288,822,828,882]
    Explanation: The same digit can be used as many times as it appears in digits.
    In this example, the digit 8 is used twice each time in 288, 828, and 882.
    
    Example 3:
    
    >>> findEvenNumbers(digits = [3,7,5])
    >>> []
    Explanation: No even integers can be formed using the given digits.
    """
# class ListNode:
#     def __init__(val=0, next=None):
#         self.val = val
#         self.next = next
class Solution:
    def deleteMiddle(head: Optional[ListNode]) -> Optional[ListNode]:
    """
    You are given the head of a linked list. Delete the middle node, and return the head of the modified linked list.
    The middle node of a linked list of size n is the ⌊n / 2⌋th node from the start using 0-based indexing, where ⌊x⌋ denotes the largest integer less than or equal to x.
    
    For n = 1, 2, 3, 4, and 5, the middle nodes are 0, 1, 1, 2, and 2, respectively.
    
    
    Example 1:
    
    
    >>> __init__(head = [1,3,4,7,1,2,6])
    >>> [1,3,4,1,2,6]
    Explanation:
    The above figure represents the given linked list. The indices of the nodes are written below.
    Since n = 7, node 3 with value 7 is the middle node, which is marked in red.
    We return the new list after removing this node.
    
    Example 2:
    
    
    >>> __init__(head = [1,2,3,4])
    >>> [1,2,4]
    Explanation:
    The above figure represents the given linked list.
    For n = 4, node 2 with value 3 is the middle node, which is marked in red.
    
    Example 3:
    
    
    >>> __init__(head = [2,1])
    >>> [2]
    Explanation:
    The above figure represents the given linked list.
    For n = 2, node 1 with value 1 is the middle node, which is marked in red.
    Node 0 with value 2 is the only node remaining after removing node 1.
    """
# class TreeNode:
#     def __init__(val=0, left=None, right=None):
#         self.val = val
#         self.left = left
#         self.right = right
class Solution:
    def getDirections(root: Optional[TreeNode], startValue: int, destValue: int) -> str:
    """
    You are given the root of a binary tree with n nodes. Each node is uniquely assigned a value from 1 to n. You are also given an integer startValue representing the value of the start node s, and a different integer destValue representing the value of the destination node t.
    Find the shortest path starting from node s and ending at node t. Generate step-by-step directions of such path as a string consisting of only the uppercase letters 'L', 'R', and 'U'. Each letter indicates a specific direction:
    
    'L' means to go from a node to its left child node.
    'R' means to go from a node to its right child node.
    'U' means to go from a node to its parent node.
    
    Return the step-by-step directions of the shortest path from node s to node t.
    
    Example 1:
    
    
    >>> __init__(root = [5,1,2,3,null,6,4], startValue = 3, destValue = 6)
    >>> "UURL"
    Explanation: The shortest path is: 3 → 1 → 5 → 2 → 6.
    
    Example 2:
    
    
    >>> __init__(root = [2,1], startValue = 2, destValue = 1)
    >>> "L"
    Explanation: The shortest path is: 2 → 1.
    """
def validArrangement(pairs: List[List[int]]) -> List[List[int]]:
    """
    You are given a 0-indexed 2D integer array pairs where pairs[i] = [starti, endi]. An arrangement of pairs is valid if for every index i where 1 <= i < pairs.length, we have endi-1 == starti.
    Return any valid arrangement of pairs.
    Note: The inputs will be generated such that there exists a valid arrangement of pairs.
    
    Example 1:
    
    >>> validArrangement(pairs = [[5,1],[4,5],[11,9],[9,4]])
    >>> [[11,9],[9,4],[4,5],[5,1]]
    Explanation:
    This is a valid arrangement since endi-1 always equals starti.
    end0 = 9 == 9 = start1
    end1 = 4 == 4 = start2
    end2 = 5 == 5 = start3
    
    Example 2:
    
    >>> validArrangement(pairs = [[1,3],[3,2],[2,1]])
    >>> [[1,3],[3,2],[2,1]]
    Explanation:
    This is a valid arrangement since endi-1 always equals starti.
    end0 = 3 == 3 = start1
    end1 = 2 == 2 = start2
    The arrangements [[2,1],[1,3],[3,2]] and [[3,2],[2,1],[1,3]] are also valid.
    
    Example 3:
    
    >>> validArrangement(pairs = [[1,2],[1,3],[2,1]])
    >>> [[1,2],[2,1],[1,3]]
    Explanation:
    This is a valid arrangement since endi-1 always equals starti.
    end0 = 2 == 2 = start1
    end1 = 1 == 1 = start2
    """
def largestEvenSum(nums: List[int], k: int) -> int:
    """
    You are given an integer array nums and an integer k. Find the largest even sum of any subsequence of nums that has a length of k.
    Return this sum, or -1 if such a sum does not exist.
    A subsequence is an array that can be derived from another array by deleting some or no elements without changing the order of the remaining elements.
    
    Example 1:
    
    >>> largestEvenSum(nums = [4,1,5,3,1], k = 3)
    >>> 12
    Explanation:
    The subsequence with the largest possible even sum is [4,5,3]. It has a sum of 4 + 5 + 3 = 12.
    
    Example 2:
    
    >>> largestEvenSum(nums = [4,6,2], k = 3)
    >>> 12
    Explanation:
    The subsequence with the largest possible even sum is [4,6,2]. It has a sum of 4 + 6 + 2 = 12.
    
    Example 3:
    
    >>> largestEvenSum(nums = [1,3,5], k = 1)
    >>> -1
    Explanation:
    No subsequence of nums with length 1 has an even sum.
    """
def maxSubsequence(nums: List[int], k: int) -> List[int]:
    """
    You are given an integer array nums and an integer k. You want to find a subsequence of nums of length k that has the largest sum.
    Return any such subsequence as an integer array of length k.
    A subsequence is an array that can be derived from another array by deleting some or no elements without changing the order of the remaining elements.
    
    Example 1:
    
    >>> maxSubsequence(nums = [2,1,3,3], k = 2)
    >>> [3,3]
    Explanation:
    The subsequence has the largest sum of 3 + 3 = 6.
    Example 2:
    
    >>> maxSubsequence(nums = [-1,-2,3,4], k = 3)
    >>> [-1,3,4]
    Explanation:
    The subsequence has the largest sum of -1 + 3 + 4 = 6.
    
    Example 3:
    
    >>> maxSubsequence(nums = [3,4,3,3], k = 2)
    >>> [3,4]
    Explanation:
    The subsequence has the largest sum of 3 + 4 = 7.
    Another possible subsequence is [4, 3].
    """
def goodDaysToRobBank(security: List[int], time: int) -> List[int]:
    """
    You and a gang of thieves are planning on robbing a bank. You are given a 0-indexed integer array security, where security[i] is the number of guards on duty on the ith day. The days are numbered starting from 0. You are also given an integer time.
    The ith day is a good day to rob the bank if:
    
    There are at least time days before and after the ith day,
    The number of guards at the bank for the time days before i are non-increasing, and
    The number of guards at the bank for the time days after i are non-decreasing.
    
    More formally, this means day i is a good day to rob the bank if and only if security[i - time] >= security[i - time + 1] >= ... >= security[i] <= ... <= security[i + time - 1] <= security[i + time].
    Return a list of all days (0-indexed) that are good days to rob the bank. The order that the days are returned in does not matter.
    
    Example 1:
    
    >>> goodDaysToRobBank(security = [5,3,3,3,5,6,2], time = 2)
    >>> [2,3]
    Explanation:
    On day 2, we have security[0] >= security[1] >= security[2] <= security[3] <= security[4].
    On day 3, we have security[1] >= security[2] >= security[3] <= security[4] <= security[5].
    No other days satisfy this condition, so days 2 and 3 are the only good days to rob the bank.
    
    Example 2:
    
    >>> goodDaysToRobBank(security = [1,1,1,1,1], time = 0)
    >>> [0,1,2,3,4]
    Explanation:
    Since time equals 0, every day is a good day to rob the bank, so return every day.
    
    Example 3:
    
    >>> goodDaysToRobBank(security = [1,2,3,4,5,6], time = 2)
    >>> []
    Explanation:
    No day has 2 days before it that have a non-increasing number of guards.
    Thus, no day is a good day to rob the bank, so return an empty list.
    """
def maximumDetonation(bombs: List[List[int]]) -> int:
    """
    You are given a list of bombs. The range of a bomb is defined as the area where its effect can be felt. This area is in the shape of a circle with the center as the location of the bomb.
    The bombs are represented by a 0-indexed 2D integer array bombs where bombs[i] = [xi, yi, ri]. xi and yi denote the X-coordinate and Y-coordinate of the location of the ith bomb, whereas ri denotes the radius of its range.
    You may choose to detonate a single bomb. When a bomb is detonated, it will detonate all bombs that lie in its range. These bombs will further detonate the bombs that lie in their ranges.
    Given the list of bombs, return the maximum number of bombs that can be detonated if you are allowed to detonate only one bomb.
    
    Example 1:
    
    
    >>> maximumDetonation(bombs = [[2,1,3],[6,1,4]])
    >>> 2
    Explanation:
    The above figure shows the positions and ranges of the 2 bombs.
    If we detonate the left bomb, the right bomb will not be affected.
    But if we detonate the right bomb, both bombs will be detonated.
    So the maximum bombs that can be detonated is max(1, 2) = 2.
    
    Example 2:
    
    
    >>> maximumDetonation(bombs = [[1,1,5],[10,10,5]])
    >>> 1
    Explanation:
    Detonating either bomb will not detonate the other bomb, so the maximum number of bombs that can be detonated is 1.
    
    Example 3:
    
    
    >>> maximumDetonation(bombs = [[1,2,3],[2,3,1],[3,4,2],[4,5,3],[5,6,4]])
    >>> 5
    Explanation:
    The best bomb to detonate is bomb 0 because:
    - Bomb 0 detonates bombs 1 and 2. The red circle denotes the range of bomb 0.
    - Bomb 2 detonates bomb 3. The blue circle denotes the range of bomb 2.
    - Bomb 3 detonates bomb 4. The green circle denotes the range of bomb 3.
    Thus all 5 bombs are detonated.
    """
def countPoints(rings: str) -> int:
    """
    There are n rings and each ring is either red, green, or blue. The rings are distributed across ten rods labeled from 0 to 9.
    You are given a string rings of length 2n that describes the n rings that are placed onto the rods. Every two characters in rings forms a color-position pair that is used to describe each ring where:
    
    The first character of the ith pair denotes the ith ring's color ('R', 'G', 'B').
    The second character of the ith pair denotes the rod that the ith ring is placed on ('0' to '9').
    
    For example, "R3G2B1" describes n == 3 rings: a red ring placed onto the rod labeled 3, a green ring placed onto the rod labeled 2, and a blue ring placed onto the rod labeled 1.
    Return the number of rods that have all three colors of rings on them.
    
    Example 1:
    
    
    >>> countPoints(rings = "B0B6G0R6R0R6G9")
    >>> 1
    Explanation:
    - The rod labeled 0 holds 3 rings with all colors: red, green, and blue.
    - The rod labeled 6 holds 3 rings, but it only has red and blue.
    - The rod labeled 9 holds only a green ring.
    Thus, the number of rods with all three colors is 1.
    
    Example 2:
    
    
    >>> countPoints(rings = "B0R0G0R9R0B0G0")
    >>> 1
    Explanation:
    - The rod labeled 0 holds 6 rings with all colors: red, green, and blue.
    - The rod labeled 9 holds only a red ring.
    Thus, the number of rods with all three colors is 1.
    
    Example 3:
    
    >>> countPoints(rings = "G4")
    >>> 0
    Explanation:
    Only one ring is given. Thus, no rods have all three colors.
    """