ShwStone/humaneval-leetcode huggingface dataset:
def busiestServers(k: int, arrival: List[int], load: List[int]) -> List[int]:
    """
    You have k servers numbered from 0 to k-1 that are being used to handle multiple requests simultaneously. Each server has infinite computational capacity but cannot handle more than one request at a time. The requests are assigned to servers according to a specific algorithm:
    
    The ith (0-indexed) request arrives.
    If all servers are busy, the request is dropped (not handled at all).
    If the (i % k)th server is available, assign the request to that server.
    Otherwise, assign the request to the next available server (wrapping around the list of servers and starting from 0 if necessary). For example, if the ith server is busy, try to assign the request to the (i+1)th server, then the (i+2)th server, and so on.
    
    You are given a strictly increasing array arrival of positive integers, where arrival[i] represents the arrival time of the ith request, and another array load, where load[i] represents the load of the ith request (the time it takes to complete). Your goal is to find the busiest server(s). A server is considered busiest if it handled the most number of requests successfully among all the servers.
    Return a list containing the IDs (0-indexed) of the busiest server(s). You may return the IDs in any order.
    
    Example 1:
    
    
    >>> busiestServers(k = 3, arrival = [1,2,3,4,5], load = [5,2,3,3,3])
    >>> [1]
    Explanation:
    All of the servers start out available.
    The first 3 requests are handled by the first 3 servers in order.
    Request 3 comes in. Server 0 is busy, so it's assigned to the next available server, which is 1.
    Request 4 comes in. It cannot be handled since all servers are busy, so it is dropped.
    Servers 0 and 2 handled one request each, while server 1 handled two requests. Hence server 1 is the busiest server.
    
    Example 2:
    
    >>> busiestServers(k = 3, arrival = [1,2,3,4], load = [1,2,1,2])
    >>> [0]
    Explanation:
    The first 3 requests are handled by first 3 servers.
    Request 3 comes in. It is handled by server 0 since the server is available.
    Server 0 handled two requests, while servers 1 and 2 handled one request each. Hence server 0 is the busiest server.
    
    Example 3:
    
    >>> busiestServers(k = 3, arrival = [1,2,3], load = [10,12,11])
    >>> [0,1,2]
    Explanation: Each server handles a single request, so they are all considered the busiest.
    """
def specialArray(nums: List[int]) -> int:
    """
    You are given an array nums of non-negative integers. nums is considered special if there exists a number x such that there are exactly x numbers in nums that are greater than or equal to x.
    Notice that x does not have to be an element in nums.
    Return x if the array is special, otherwise, return -1. It can be proven that if nums is special, the value for x is unique.
    
    Example 1:
    
    >>> specialArray(nums = [3,5])
    >>> 2
    Explanation: There are 2 values (3 and 5) that are greater than or equal to 2.
    
    Example 2:
    
    >>> specialArray(nums = [0,0])
    >>> -1
    Explanation: No numbers fit the criteria for x.
    If x = 0, there should be 0 numbers >= x, but there are 2.
    If x = 1, there should be 1 number >= x, but there are 0.
    If x = 2, there should be 2 numbers >= x, but there are 0.
    x cannot be greater since there are only 2 numbers in nums.
    
    Example 3:
    
    >>> specialArray(nums = [0,4,3,0,4])
    >>> 3
    Explanation: There are 3 values that are greater than or equal to 3.
    """
# class TreeNode:
#     def __init__(val=0, left=None, right=None):
#         self.val = val
#         self.left = left
#         self.right = right
class Solution:
    def isEvenOddTree(root: Optional[TreeNode]) -> bool:
    """
    A binary tree is named Even-Odd if it meets the following conditions:
    
    The root of the binary tree is at level index 0, its children are at level index 1, their children are at level index 2, etc.
    For every even-indexed level, all nodes at the level have odd integer values in strictly increasing order (from left to right).
    For every odd-indexed level, all nodes at the level have even integer values in strictly decreasing order (from left to right).
    
    Given the root of a binary tree, return true if the binary tree is Even-Odd, otherwise return false.
    
    Example 1:
    
    
    >>> __init__(root = [1,10,4,3,null,7,9,12,8,6,null,null,2])
    >>> true
    Explanation: The node values on each level are:
    Level 0: [1]
    Level 1: [10,4]
    Level 2: [3,7,9]
    Level 3: [12,8,6,2]
    Since levels 0 and 2 are all odd and increasing and levels 1 and 3 are all even and decreasing, the tree is Even-Odd.
    
    Example 2:
    
    
    >>> __init__(root = [5,4,2,3,3,7])
    >>> false
    Explanation: The node values on each level are:
    Level 0: [5]
    Level 1: [4,2]
    Level 2: [3,3,7]
    Node values in level 2 must be in strictly increasing order, so the tree is not Even-Odd.
    
    Example 3:
    
    
    >>> __init__(root = [5,9,1,3,5,7])
    >>> false
    Explanation: Node values in the level 1 should be even integers.
    """
def visiblePoints(points: List[List[int]], angle: int, location: List[int]) -> int:
    """
    You are given an array points, an integer angle, and your location, where location = [posx, posy] and points[i] = [xi, yi] both denote integral coordinates on the X-Y plane.
    Initially, you are facing directly east from your position. You cannot move from your position, but you can rotate. In other words, posx and posy cannot be changed. Your field of view in degrees is represented by angle, determining how wide you can see from any given view direction. Let d be the amount in degrees that you rotate counterclockwise. Then, your field of view is the inclusive range of angles [d - angle/2, d + angle/2].
    
    Your browser does not support the video tag or this video format.
    
    You can see some set of points if, for each point, the angle formed by the point, your position, and the immediate east direction from your position is in your field of view.
    There can be multiple points at one coordinate. There may be points at your location, and you can always see these points regardless of your rotation. Points do not obstruct your vision to other points.
    Return the maximum number of points you can see.
    
    Example 1:
    
    
    >>> visiblePoints(points = [[2,1],[2,2],[3,3]], angle = 90, location = [1,1])
    >>> 3
    Explanation: The shaded region represents your field of view. All points can be made visible in your field of view, including [3,3] even though [2,2] is in front and in the same line of sight.
    
    Example 2:
    
    >>> visiblePoints(points = [[2,1],[2,2],[3,4],[1,1]], angle = 90, location = [1,1])
    >>> 4
    Explanation: All points can be made visible in your field of view, including the one at your location.
    
    Example 3:
    
    
    >>> visiblePoints(points = [[1,0],[2,1]], angle = 13, location = [1,1])
    >>> 1
    Explanation: You can only see one of the two points, as shown above.
    """
def minimumOneBitOperations(n: int) -> int:
    """
    Given an integer n, you must transform it into 0 using the following operations any number of times:
    
    Change the rightmost (0th) bit in the binary representation of n.
    Change the ith bit in the binary representation of n if the (i-1)th bit is set to 1 and the (i-2)th through 0th bits are set to 0.
    
    Return the minimum number of operations to transform n into 0.
    
    Example 1:
    
    >>> minimumOneBitOperations(n = 3)
    >>> 2
    Explanation: The binary representation of 3 is "11".
    "11" -> "01" with the 2nd operation since the 0th bit is 1.
    "01" -> "00" with the 1st operation.
    
    Example 2:
    
    >>> minimumOneBitOperations(n = 6)
    >>> 4
    Explanation: The binary representation of 6 is "110".
    "110" -> "010" with the 2nd operation since the 1st bit is 1 and 0th through 0th bits are 0.
    "010" -> "011" with the 1st operation.
    "011" -> "001" with the 2nd operation since the 0th bit is 1.
    "001" -> "000" with the 1st operation.
    """
def maxDepth(s: str) -> int:
    """
    Given a valid parentheses string s, return the nesting depth of s. The nesting depth is the maximum number of nested parentheses.
    
    Example 1:
    
    >>> maxDepth(s = "(1+(2*3)+((8)/4))+1")
    >>> 3
    Explanation:
    Digit 8 is inside of 3 nested parentheses in the string.
    
    Example 2:
    
    >>> maxDepth(s = "(1)+((2))+(((3)))")
    >>> 3
    Explanation:
    Digit 3 is inside of 3 nested parentheses in the string.
    
    Example 3:
    
    >>> maxDepth(s = "()(())((()()))")
    >>> 3
    """
def maximalNetworkRank(n: int, roads: List[List[int]]) -> int:
    """
    There is an infrastructure of n cities with some number of roads connecting these cities. Each roads[i] = [ai, bi] indicates that there is a bidirectional road between cities ai and bi.
    The network rank of two different cities is defined as the total number of directly connected roads to either city. If a road is directly connected to both cities, it is only counted once.
    The maximal network rank of the infrastructure is the maximum network rank of all pairs of different cities.
    Given the integer n and the array roads, return the maximal network rank of the entire infrastructure.
    
    Example 1:
    
    
    >>> maximalNetworkRank(n = 4, roads = [[0,1],[0,3],[1,2],[1,3]])
    >>> 4
    Explanation: The network rank of cities 0 and 1 is 4 as there are 4 roads that are connected to either 0 or 1. The road between 0 and 1 is only counted once.
    
    Example 2:
    
    
    >>> maximalNetworkRank(n = 5, roads = [[0,1],[0,3],[1,2],[1,3],[2,3],[2,4]])
    >>> 5
    Explanation: There are 5 roads that are connected to cities 1 or 2.
    
    Example 3:
    
    >>> maximalNetworkRank(n = 8, roads = [[0,1],[1,2],[2,3],[2,4],[5,6],[5,7]])
    >>> 5
    Explanation: The network rank of 2 and 5 is 5. Notice that all the cities do not have to be connected.
    """
def checkPalindromeFormation(a: str, b: str) -> bool:
    """
    You are given two strings a and b of the same length. Choose an index and split both strings at the same index, splitting a into two strings: aprefix and asuffix where a = aprefix + asuffix, and splitting b into two strings: bprefix and bsuffix where b = bprefix + bsuffix. Check if aprefix + bsuffix or bprefix + asuffix forms a palindrome.
    When you split a string s into sprefix and ssuffix, either ssuffix or sprefix is allowed to be empty. For example, if s = "abc", then "" + "abc", "a" + "bc", "ab" + "c" , and "abc" + "" are valid splits.
    Return true if it is possible to form a palindrome string, otherwise return false.
    Notice that x + y denotes the concatenation of strings x and y.
    
    Example 1:
    
    >>> checkPalindromeFormation(a = "x", b = "y")
    >>> true
    Explaination: If either a or b are palindromes the answer is true since you can split in the following way:
    aprefix = "", asuffix = "x"
    bprefix = "", bsuffix = "y"
    Then, aprefix + bsuffix = "" + "y" = "y", which is a palindrome.
    
    Example 2:
    
    >>> checkPalindromeFormation(a = "xbdef", b = "xecab")
    >>> false
    
    Example 3:
    
    >>> checkPalindromeFormation(a = "ulacfd", b = "jizalu")
    >>> true
    Explaination: Split them at index 3:
    aprefix = "ula", asuffix = "cfd"
    bprefix = "jiz", bsuffix = "alu"
    Then, aprefix + bsuffix = "ula" + "alu" = "ulaalu", which is a palindrome.
    """
def countSubgraphsForEachDiameter(n: int, edges: List[List[int]]) -> List[int]:
    """
    There are n cities numbered from 1 to n. You are given an array edges of size n-1, where edges[i] = [ui, vi] represents a bidirectional edge between cities ui and vi. There exists a unique path between each pair of cities. In other words, the cities form a tree.\r
    \r
    A subtree is a subset of cities where every city is reachable from every other city in the subset, where the path between each pair passes through only the cities from the subset. Two subtrees are different if there is a city in one subtree that is not present in the other.\r
    \r
    For each d from 1 to n-1, find the number of subtrees in which the maximum distance between any two cities in the subtree is equal to d.\r
    \r
    Return an array of size n-1 where the dth element (1-indexed) is the number of subtrees in which the maximum distance between any two cities is equal to d.\r
    \r
    Notice that the distance between the two cities is the number of edges in the path between them.\r
    \r
     \r
    Example 1:\r
    \r
    \r
    \r
    \r
    >>> countSubgraphsForEachDiameter(n = 4, edges = [[1,2],[2,3],[2,4]]\r)
    >>> [3,4,0]\r
    Explanation:\r
    The subtrees with subsets {1,2}, {2,3} and {2,4} have a max distance of 1.\r
    The subtrees with subsets {1,2,3}, {1,2,4}, {2,3,4} and {1,2,3,4} have a max distance of 2.\r
    No subtree has two nodes where the max distance between them is 3.\r
    \r
    \r
    Example 2:\r
    \r
    \r
    >>> countSubgraphsForEachDiameter(n = 2, edges = [[1,2]]\r)
    >>> [1]\r
    \r
    \r
    Example 3:\r
    \r
    \r
    >>> countSubgraphsForEachDiameter(n = 3, edges = [[1,2],[2,3]]\r)
    >>> [2,1]\r
    \r
    \r
     \r
    """
def trimMean(arr: List[int]) -> float:
    """
    Given an integer array arr, return the mean of the remaining integers after removing the smallest 5% and the largest 5% of the elements.
    Answers within 10-5 of the actual answer will be considered accepted.
    
    Example 1:
    
    >>> trimMean(arr = [1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3])
    >>> 2.00000
    Explanation: After erasing the minimum and the maximum values of this array, all elements are equal to 2, so the mean is 2.
    
    Example 2:
    
    >>> trimMean(arr = [6,2,7,5,1,2,0,3,10,2,5,0,5,5,0,8,7,6,8,0])
    >>> 4.00000
    
    Example 3:
    
    >>> trimMean(arr = [6,0,7,0,7,5,7,8,3,4,0,7,8,1,6,8,1,1,2,4,8,1,9,5,4,3,8,5,10,8,6,6,1,0,6,10,8,2,3,4])
    >>> 4.77778
    """
def bestCoordinate(towers: List[List[int]], radius: int) -> List[int]:
    """
    You are given an array of network towers towers, where towers[i] = [xi, yi, qi] denotes the ith network tower with location (xi, yi) and quality factor qi. All the coordinates are integral coordinates on the X-Y plane, and the distance between the two coordinates is the Euclidean distance.
    You are also given an integer radius where a tower is reachable if the distance is less than or equal to radius. Outside that distance, the signal becomes garbled, and the tower is not reachable.
    The signal quality of the ith tower at a coordinate (x, y) is calculated with the formula ⌊qi / (1 + d)⌋, where d is the distance between the tower and the coordinate. The network quality at a coordinate is the sum of the signal qualities from all the reachable towers.
    Return the array [cx, cy] representing the integral coordinate (cx, cy) where the network quality is maximum. If there are multiple coordinates with the same network quality, return the lexicographically minimum non-negative coordinate.
    Note:
    
    A coordinate (x1, y1) is lexicographically smaller than (x2, y2) if either:
    
    
    x1 < x2, or
    x1 == x2 and y1 < y2.
    
    
    ⌊val⌋ is the greatest integer less than or equal to val (the floor function).
    
    
    Example 1:
    
    
    >>> bestCoordinate(towers = [[1,2,5],[2,1,7],[3,1,9]], radius = 2)
    >>> [2,1]
    Explanation: At coordinate (2, 1) the total quality is 13.
    - Quality of 7 from (2, 1) results in ⌊7 / (1 + sqrt(0)⌋ = ⌊7⌋ = 7
    - Quality of 5 from (1, 2) results in ⌊5 / (1 + sqrt(2)⌋ = ⌊2.07⌋ = 2
    - Quality of 9 from (3, 1) results in ⌊9 / (1 + sqrt(1)⌋ = ⌊4.5⌋ = 4
    No other coordinate has a higher network quality.
    Example 2:
    
    >>> bestCoordinate(towers = [[23,11,21]], radius = 9)
    >>> [23,11]
    Explanation: Since there is only one tower, the network quality is highest right at the tower's location.
    
    Example 3:
    
    >>> bestCoordinate(towers = [[1,2,13],[2,1,7],[0,1,9]], radius = 2)
    >>> [1,2]
    Explanation: Coordinate (1, 2) has the highest network quality.
    """
def numberOfSets(n: int, k: int) -> int:
    """
    Given n points on a 1-D plane, where the ith point (from 0 to n-1) is at x = i, find the number of ways we can draw exactly k non-overlapping line segments such that each segment covers two or more points. The endpoints of each segment must have integral coordinates. The k line segments do not have to cover all n points, and they are allowed to share endpoints.
    Return the number of ways we can draw k non-overlapping line segments. Since this number can be huge, return it modulo 109 + 7.
    
    Example 1:
    
    
    >>> numberOfSets(n = 4, k = 2)
    >>> 5
    Explanation: The two line segments are shown in red and blue.
    The image above shows the 5 different ways {(0,2),(2,3)}, {(0,1),(1,3)}, {(0,1),(2,3)}, {(1,2),(2,3)}, {(0,1),(1,2)}.
    
    Example 2:
    
    >>> numberOfSets(n = 3, k = 1)
    >>> 3
    Explanation: The 3 ways are {(0,1)}, {(0,2)}, {(1,2)}.
    
    Example 3:
    
    >>> numberOfSets(n = 30, k = 7)
    >>> 796297179
    Explanation: The total number of possible ways to draw 7 line segments is 3796297200. Taking this number modulo 109 + 7 gives us 796297179.
    """
def maxLengthBetweenEqualCharacters(s: str) -> int:
    """
    Given a string s, return the length of the longest substring between two equal characters, excluding the two characters. If there is no such substring return -1.
    A substring is a contiguous sequence of characters within a string.
    
    Example 1:
    
    >>> maxLengthBetweenEqualCharacters(s = "aa")
    >>> 0
    Explanation: The optimal substring here is an empty substring between the two 'a's.
    Example 2:
    
    >>> maxLengthBetweenEqualCharacters(s = "abca")
    >>> 2
    Explanation: The optimal substring here is "bc".
    
    Example 3:
    
    >>> maxLengthBetweenEqualCharacters(s = "cbzxy")
    >>> -1
    Explanation: There are no characters that appear twice in s.
    """
def findLexSmallestString(s: str, a: int, b: int) -> str:
    """
    You are given a string s of even length consisting of digits from 0 to 9, and two integers a and b.
    You can apply either of the following two operations any number of times and in any order on s:
    
    Add a to all odd indices of s (0-indexed). Digits post 9 are cycled back to 0. For example, if s = "3456" and a = 5, s becomes "3951".
    Rotate s to the right by b positions. For example, if s = "3456" and b = 1, s becomes "6345".
    
    Return the lexicographically smallest string you can obtain by applying the above operations any number of times on s.
    A string a is lexicographically smaller than a string b (of the same length) if in the first position where a and b differ, string a has a letter that appears earlier in the alphabet than the corresponding letter in b. For example, "0158" is lexicographically smaller than "0190" because the first position they differ is at the third letter, and '5' comes before '9'.
    
    Example 1:
    
    >>> findLexSmallestString(s = "5525", a = 9, b = 2)
    >>> "2050"
    Explanation: We can apply the following operations:
    Start:  "5525"
    Rotate: "2555"
    Add:    "2454"
    Add:    "2353"
    Rotate: "5323"
    Add:    "5222"
    Add:    "5121"
    Rotate: "2151"
    Add:    "2050"​​​​​
    There is no way to obtain a string that is lexicographically smaller than "2050".
    
    Example 2:
    
    >>> findLexSmallestString(s = "74", a = 5, b = 1)
    >>> "24"
    Explanation: We can apply the following operations:
    Start:  "74"
    Rotate: "47"
    ​​​​​​​Add:    "42"
    ​​​​​​​Rotate: "24"​​​​​​​​​​​​
    There is no way to obtain a string that is lexicographically smaller than "24".
    
    Example 3:
    
    >>> findLexSmallestString(s = "0011", a = 4, b = 2)
    >>> "0011"
    Explanation: There are no sequence of operations that will give us a lexicographically smaller string than "0011".
    """
def bestTeamScore(scores: List[int], ages: List[int]) -> int:
    """
    You are the manager of a basketball team. For the upcoming tournament, you want to choose the team with the highest overall score. The score of the team is the sum of scores of all the players in the team.
    However, the basketball team is not allowed to have conflicts. A conflict exists if a younger player has a strictly higher score than an older player. A conflict does not occur between players of the same age.
    Given two lists, scores and ages, where each scores[i] and ages[i] represents the score and age of the ith player, respectively, return the highest overall score of all possible basketball teams.
    
    Example 1:
    
    >>> bestTeamScore(scores = [1,3,5,10,15], ages = [1,2,3,4,5])
    >>> 34
    Explanation: You can choose all the players.
    
    Example 2:
    
    >>> bestTeamScore(scores = [4,5,6,5], ages = [2,1,2,1])
    >>> 16
    Explanation: It is best to choose the last 3 players. Notice that you are allowed to choose multiple people of the same age.
    
    Example 3:
    
    >>> bestTeamScore(scores = [1,2,3,5], ages = [8,9,10,1])
    >>> 6
    Explanation: It is best to choose the first 3 players.
    """
def areConnected(n: int, threshold: int, queries: List[List[int]]) -> List[bool]:
    """
    We have n cities labeled from 1 to n. Two different cities with labels x and y are directly connected by a bidirectional road if and only if x and y share a common divisor strictly greater than some threshold. More formally, cities with labels x and y have a road between them if there exists an integer z such that all of the following are true:
    
    x % z == 0,
    y % z == 0, and
    z > threshold.
    
    Given the two integers, n and threshold, and an array of queries, you must determine for each queries[i] = [ai, bi] if cities ai and bi are connected directly or indirectly. (i.e. there is some path between them).
    Return an array answer, where answer.length == queries.length and answer[i] is true if for the ith query, there is a path between ai and bi, or answer[i] is false if there is no path.
    
    Example 1:
    
    
    >>> areConnected(n = 6, threshold = 2, queries = [[1,4],[2,5],[3,6]])
    >>> [false,false,true]
    Explanation: The divisors for each number:
    1:   1
    2:   1, 2
    3:   1, 3
    4:   1, 2, 4
    5:   1, 5
    6:   1, 2, 3, 6
    Using the underlined divisors above the threshold, only cities 3 and 6 share a common divisor, so they are the
    only ones directly connected. The result of each query:
    [1,4]   1 is not connected to 4
    [2,5]   2 is not connected to 5
    [3,6]   3 is connected to 6 through path 3--6
    
    Example 2:
    
    
    >>> areConnected(n = 6, threshold = 0, queries = [[4,5],[3,4],[3,2],[2,6],[1,3]])
    >>> [true,true,true,true,true]
    Explanation: The divisors for each number are the same as the previous example. However, since the threshold is 0,
    all divisors can be used. Since all numbers share 1 as a divisor, all cities are connected.
    
    Example 3:
    
    
    >>> areConnected(n = 5, threshold = 1, queries = [[4,5],[4,5],[3,2],[2,3],[3,4]])
    >>> [false,false,false,false,false]
    Explanation: Only cities 2 and 4 share a common divisor 2 which is strictly greater than the threshold 1, so they are the only ones directly connected.
    Please notice that there can be multiple queries for the same pair of nodes [x, y], and that the query [x, y] is equivalent to the query [y, x].
    """