ShwStone/humaneval-leetcode huggingface dataset:
def getMaximumGold(grid: List[List[int]]) -> int:
    """
    In a gold mine grid of size m x n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty.
    Return the maximum amount of gold you can collect under the conditions:
    
    Every time you are located in a cell you will collect all the gold in that cell.
    From your position, you can walk one step to the left, right, up, or down.
    You can't visit the same cell more than once.
    Never visit a cell with 0 gold.
    You can start and stop collecting gold from any position in the grid that has some gold.
    
    
    Example 1:
    
    >>> getMaximumGold(grid = [[0,6,0],[5,8,7],[0,9,0]])
    >>> 24
    Explanation:
    [[0,6,0],
     [5,8,7],
     [0,9,0]]
    Path to get the maximum gold, 9 -> 8 -> 7.
    
    Example 2:
    
    >>> getMaximumGold(grid = [[1,0,7],[2,0,6],[3,4,5],[0,3,0],[9,0,20]])
    >>> 28
    Explanation:
    [[1,0,7],
     [2,0,6],
     [3,4,5],
     [0,3,0],
     [9,0,20]]
    Path to get the maximum gold, 1 -> 2 -> 3 -> 4 -> 5 -> 6 -> 7.
    """
def countVowelPermutation(n: int) -> int:
    """
    Given an integer n, your task is to count how many strings of length n can be formed under the following rules:
    
    Each character is a lower case vowel ('a', 'e', 'i', 'o', 'u')
    Each vowel 'a' may only be followed by an 'e'.
    Each vowel 'e' may only be followed by an 'a' or an 'i'.
    Each vowel 'i' may not be followed by another 'i'.
    Each vowel 'o' may only be followed by an 'i' or a 'u'.
    Each vowel 'u' may only be followed by an 'a'.
    
    Since the answer may be too large, return it modulo 10^9 + 7.
    
    Example 1:
    
    >>> countVowelPermutation(n = 1)
    >>> 5
    Explanation: All possible strings are: "a", "e", "i" , "o" and "u".
    
    Example 2:
    
    >>> countVowelPermutation(n = 2)
    >>> 10
    Explanation: All possible strings are: "ae", "ea", "ei", "ia", "ie", "io", "iu", "oi", "ou" and "ua".
    
    Example 3:
    
    >>> countVowelPermutation(n = 5)
    >>> 68
    """
def balancedStringSplit(s: str) -> int:
    """
    Balanced strings are those that have an equal quantity of 'L' and 'R' characters.
    Given a balanced string s, split it into some number of substrings such that:
    
    Each substring is balanced.
    
    Return the maximum number of balanced strings you can obtain.
    
    Example 1:
    
    >>> balancedStringSplit(s = "RLRRLLRLRL")
    >>> 4
    Explanation: s can be split into "RL", "RRLL", "RL", "RL", each substring contains same number of 'L' and 'R'.
    
    Example 2:
    
    >>> balancedStringSplit(s = "RLRRRLLRLL")
    >>> 2
    Explanation: s can be split into "RL", "RRRLLRLL", each substring contains same number of 'L' and 'R'.
    Note that s cannot be split into "RL", "RR", "RL", "LR", "LL", because the 2nd and 5th substrings are not balanced.
    Example 3:
    
    >>> balancedStringSplit(s = "LLLLRRRR")
    >>> 1
    Explanation: s can be split into "LLLLRRRR".
    """
def queensAttacktheKing(queens: List[List[int]], king: List[int]) -> List[List[int]]:
    """
    On a 0-indexed 8 x 8 chessboard, there can be multiple black queens and one white king.
    You are given a 2D integer array queens where queens[i] = [xQueeni, yQueeni] represents the position of the ith black queen on the chessboard. You are also given an integer array king of length 2 where king = [xKing, yKing] represents the position of the white king.
    Return the coordinates of the black queens that can directly attack the king. You may return the answer in any order.
    
    Example 1:
    
    
    >>> queensAttacktheKing(queens = [[0,1],[1,0],[4,0],[0,4],[3,3],[2,4]], king = [0,0])
    >>> [[0,1],[1,0],[3,3]]
    Explanation: The diagram above shows the three queens that can directly attack the king and the three queens that cannot attack the king (i.e., marked with red dashes).
    
    Example 2:
    
    
    >>> queensAttacktheKing(queens = [[0,0],[1,1],[2,2],[3,4],[3,5],[4,4],[4,5]], king = [3,3])
    >>> [[2,2],[3,4],[4,4]]
    Explanation: The diagram above shows the three queens that can directly attack the king and the three queens that cannot attack the king (i.e., marked with red dashes).
    """
def dieSimulator(n: int, rollMax: List[int]) -> int:
    """
    A die simulator generates a random number from 1 to 6 for each roll. You introduced a constraint to the generator such that it cannot roll the number i more than rollMax[i] (1-indexed) consecutive times.
    Given an array of integers rollMax and an integer n, return the number of distinct sequences that can be obtained with exact n rolls. Since the answer may be too large, return it modulo 109 + 7.
    Two sequences are considered different if at least one element differs from each other.
    
    Example 1:
    
    >>> dieSimulator(n = 2, rollMax = [1,1,2,2,2,3])
    >>> 34
    Explanation: There will be 2 rolls of die, if there are no constraints on the die, there are 6 * 6 = 36 possible combinations. In this case, looking at rollMax array, the numbers 1 and 2 appear at most once consecutively, therefore sequences (1,1) and (2,2) cannot occur, so the final answer is 36-2 = 34.
    
    Example 2:
    
    >>> dieSimulator(n = 2, rollMax = [1,1,1,1,1,1])
    >>> 30
    
    Example 3:
    
    >>> dieSimulator(n = 3, rollMax = [1,1,1,2,2,3])
    >>> 181
    """
def maxEqualFreq(nums: List[int]) -> int:
    """
    Given an array nums of positive integers, return the longest possible length of an array prefix of nums, such that it is possible to remove exactly one element from this prefix so that every number that has appeared in it will have the same number of occurrences.
    If after removing one element there are no remaining elements, it's still considered that every appeared number has the same number of ocurrences (0).
    
    Example 1:
    
    >>> maxEqualFreq(nums = [2,2,1,1,5,3,3,5])
    >>> 7
    Explanation: For the subarray [2,2,1,1,5,3,3] of length 7, if we remove nums[4] = 5, we will get [2,2,1,1,3,3], so that each number will appear exactly twice.
    
    Example 2:
    
    >>> maxEqualFreq(nums = [1,1,1,2,2,2,3,3,3,4,4,4,5])
    >>> 13
    """
def nthPersonGetsNthSeat(n: int) -> float:
    """
    n passengers board an airplane with exactly n seats. The first passenger has lost the ticket and picks a seat randomly. But after that, the rest of the passengers will:
    
    Take their own seat if it is still available, and
    Pick other seats randomly when they find their seat occupied
    
    Return the probability that the nth person gets his own seat.
    
    Example 1:
    
    >>> nthPersonGetsNthSeat(n = 1)
    >>> 1.00000
    Explanation: The first person can only get the first seat.
    Example 2:
    
    >>> nthPersonGetsNthSeat(n = 2)
    >>> 0.50000
    Explanation: The second person has a probability of 0.5 to get the second seat (when first person gets the first seat).
    """
def missingNumber(arr: List[int]) -> int:
    """
    In some array arr, the values were in arithmetic progression: the values arr[i + 1] - arr[i] are all equal for every 0 <= i < arr.length - 1.
    A value from arr was removed that was not the first or last value in the array.
    Given arr, return the removed value.
    
    Example 1:
    
    >>> missingNumber(arr = [5,7,11,13])
    >>> 9
    Explanation: The previous array was [5,7,9,11,13].
    
    Example 2:
    
    >>> missingNumber(arr = [15,13,12])
    >>> 14
    Explanation: The previous array was [15,14,13,12].
    """
def minAvailableDuration(slots1: List[List[int]], slots2: List[List[int]], duration: int) -> List[int]:
    """
    Given the availability time slots arrays slots1 and slots2 of two people and a meeting duration duration, return the earliest time slot that works for both of them and is of duration duration.
    If there is no common time slot that satisfies the requirements, return an empty array.
    The format of a time slot is an array of two elements [start, end] representing an inclusive time range from start to end.
    It is guaranteed that no two availability slots of the same person intersect with each other. That is, for any two time slots [start1, end1] and [start2, end2] of the same person, either start1 > end2 or start2 > end1.
    
    Example 1:
    
    >>> minAvailableDuration(slots1 = [[10,50],[60,120],[140,210]], slots2 = [[0,15],[60,70]], duration = 8)
    >>> [60,68]
    
    Example 2:
    
    >>> minAvailableDuration(slots1 = [[10,50],[60,120],[140,210]], slots2 = [[0,15],[60,70]], duration = 12)
    >>> []
    """
def probabilityOfHeads(prob: List[float], target: int) -> float:
    """
    You have some coins.  The i-th coin has a probability prob[i] of facing heads when tossed.
    Return the probability that the number of coins facing heads equals target if you toss every coin exactly once.
    
    Example 1:
    >>> probabilityOfHeads(prob = [0.4], target = 1)
    >>> 0.40000
    Example 2:
    >>> probabilityOfHeads(prob = [0.5,0.5,0.5,0.5,0.5], target = 0)
    >>> 0.03125
    """
def maximizeSweetness(sweetness: List[int], k: int) -> int:
    """
    You have one chocolate bar that consists of some chunks. Each chunk has its own sweetness given by the array sweetness.
    You want to share the chocolate with your k friends so you start cutting the chocolate bar into k + 1 pieces using k cuts, each piece consists of some consecutive chunks.
    Being generous, you will eat the piece with the minimum total sweetness and give the other pieces to your friends.
    Find the maximum total sweetness of the piece you can get by cutting the chocolate bar optimally.
    
    Example 1:
    
    >>> maximizeSweetness(sweetness = [1,2,3,4,5,6,7,8,9], k = 5)
    >>> 6
    Explanation: You can divide the chocolate to [1,2,3], [4,5], [6], [7], [8], [9]
    
    Example 2:
    
    >>> maximizeSweetness(sweetness = [5,6,7,8,9,1,2,3,4], k = 8)
    >>> 1
    Explanation: There is only one way to cut the bar into 9 pieces.
    
    Example 3:
    
    >>> maximizeSweetness(sweetness = [1,2,2,1,2,2,1,2,2], k = 2)
    >>> 5
    Explanation: You can divide the chocolate to [1,2,2], [1,2,2], [1,2,2]
    """
def checkStraightLine(coordinates: List[List[int]]) -> bool:
    """
    You are given an array coordinates, coordinates[i] = [x, y], where [x, y] represents the coordinate of a point. Check if these points make a straight line in the XY plane.
    
    
    Example 1:
    
    
    >>> checkStraightLine(coordinates = [[1,2],[2,3],[3,4],[4,5],[5,6],[6,7]])
    >>> true
    
    Example 2:
    
    
    >>> checkStraightLine(coordinates = [[1,1],[2,2],[3,4],[4,5],[5,6],[7,7]])
    >>> false
    """
def removeSubfolders(folder: List[str]) -> List[str]:
    """
    Given a list of folders folder, return the folders after removing all sub-folders in those folders. You may return the answer in any order.
    If a folder[i] is located within another folder[j], it is called a sub-folder of it. A sub-folder of folder[j] must start with folder[j], followed by a "/". For example, "/a/b" is a sub-folder of "/a", but "/b" is not a sub-folder of "/a/b/c".
    The format of a path is one or more concatenated strings of the form: '/' followed by one or more lowercase English letters.
    
    For example, "/leetcode" and "/leetcode/problems" are valid paths while an empty string and "/" are not.
    
    
    Example 1:
    
    >>> removeSubfolders(folder = ["/a","/a/b","/c/d","/c/d/e","/c/f"])
    >>> ["/a","/c/d","/c/f"]
    Explanation: Folders "/a/b" is a subfolder of "/a" and "/c/d/e" is inside of folder "/c/d" in our filesystem.
    
    Example 2:
    
    >>> removeSubfolders(folder = ["/a","/a/b/c","/a/b/d"])
    >>> ["/a"]
    Explanation: Folders "/a/b/c" and "/a/b/d" will be removed because they are subfolders of "/a".
    
    Example 3:
    
    >>> removeSubfolders(folder = ["/a/b/c","/a/b/ca","/a/b/d"])
    >>> ["/a/b/c","/a/b/ca","/a/b/d"]
    """
def balancedString(s: str) -> int:
    """
    You are given a string s of length n containing only four kinds of characters: 'Q', 'W', 'E', and 'R'.
    A string is said to be balanced if each of its characters appears n / 4 times where n is the length of the string.
    Return the minimum length of the substring that can be replaced with any other string of the same length to make s balanced. If s is already balanced, return 0.
    
    Example 1:
    
    >>> balancedString(s = "QWER")
    >>> 0
    Explanation: s is already balanced.
    
    Example 2:
    
    >>> balancedString(s = "QQWE")
    >>> 1
    Explanation: We need to replace a 'Q' to 'R', so that "RQWE" (or "QRWE") is balanced.
    
    Example 3:
    
    >>> balancedString(s = "QQQW")
    >>> 2
    Explanation: We can replace the first "QQ" to "ER".
    """
def jobScheduling(startTime: List[int], endTime: List[int], profit: List[int]) -> int:
    """
    We have n jobs, where every job is scheduled to be done from startTime[i] to endTime[i], obtaining a profit of profit[i].
    You're given the startTime, endTime and profit arrays, return the maximum profit you can take such that there are no two jobs in the subset with overlapping time range.
    If you choose a job that ends at time X you will be able to start another job that starts at time X.
    
    Example 1:
    
    
    >>> jobScheduling(startTime = [1,2,3,3], endTime = [3,4,5,6], profit = [50,10,40,70])
    >>> 120
    Explanation: The subset chosen is the first and fourth job.
    Time range [1-3]+[3-6] , we get profit of 120 = 50 + 70.
    
    Example 2:
    
    
    >>> jobScheduling(startTime = [1,2,3,4,6], endTime = [3,5,10,6,9], profit = [20,20,100,70,60])
    >>> 150
    Explanation: The subset chosen is the first, fourth and fifth job.
    Profit obtained 150 = 20 + 70 + 60.
    
    Example 3:
    
    
    >>> jobScheduling(startTime = [1,1,1], endTime = [2,3,4], profit = [5,6,4])
    >>> 6
    """
def circularPermutation(n: int, start: int) -> List[int]:
    """
    Given 2 integers n and start. Your task is return any permutation p of (0,1,2.....,2^n -1) such that :\r
    \r
    \r
    	p[0] = start\r
    	p[i] and p[i+1] differ by only one bit in their binary representation.\r
    	p[0] and p[2^n -1] must also differ by only one bit in their binary representation.\r
    \r
    \r
     \r
    Example 1:\r
    \r
    \r
    >>> circularPermutation(n = 2, start = 3\r)
    >>> [3,2,0,1]\r
    Explanation: The binary representation of the permutation is (11,10,00,01). \r
    All the adjacent element differ by one bit. Another valid permutation is [3,1,0,2]\r
    \r
    \r
    Example 2:\r
    \r
    \r
    >>> circularPermutation(n = 3, start = 2\r)
    >>> [2,6,7,5,4,0,1,3]\r
    Explanation: The binary representation of the permutation is (010,110,111,101,100,000,001,011).\r
    \r
    \r
     \r
    """
def maxLength(arr: List[str]) -> int:
    """
    You are given an array of strings arr. A string s is formed by the concatenation of a subsequence of arr that has unique characters.
    Return the maximum possible length of s.
    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:
    
    >>> maxLength(arr = ["un","iq","ue"])
    >>> 4
    Explanation: All the valid concatenations are:
    - ""
    - "un"
    - "iq"
    - "ue"
    - "uniq" ("un" + "iq")
    - "ique" ("iq" + "ue")
    Maximum length is 4.
    
    Example 2:
    
    >>> maxLength(arr = ["cha","r","act","ers"])
    >>> 6
    Explanation: Possible longest valid concatenations are "chaers" ("cha" + "ers") and "acters" ("act" + "ers").
    
    Example 3:
    
    >>> maxLength(arr = ["abcdefghijklmnopqrstuvwxyz"])
    >>> 26
    Explanation: The only string in arr has all 26 characters.
    """
def tilingRectangle(n: int, m: int) -> int:
    """
    Given a rectangle of size n x m, return the minimum number of integer-sided squares that tile the rectangle.
    
    Example 1:
    
    
    >>> tilingRectangle(n = 2, m = 3)
    >>> 3
    Explanation: 3 squares are necessary to cover the rectangle.
    2 (squares of 1x1)
    1 (square of 2x2)
    Example 2:
    
    
    >>> tilingRectangle(n = 5, m = 8)
    >>> 5
    
    Example 3:
    
    
    >>> tilingRectangle(n = 11, m = 13)
    >>> 6
    """
# This is HtmlParser's API interface.
# You should not implement it, or speculate about its implementation
# """
#class HtmlParser(object):
#    def getUrls(url):
#        """
#        :type url: str
#        :rtype List[str]
#        """

class Solution:
    def crawl(startUrl: str, htmlParser: 'HtmlParser') -> List[str]:
    """
    Given a URL startUrl and an interface HtmlParser, implement a Multi-threaded web crawler to crawl all links that are under the same hostname as startUrl.
    Return all URLs obtained by your web crawler in any order.
    Your crawler should:
    
    Start from the page: startUrl
    Call HtmlParser.getUrls(url) to get all URLs from a webpage of a given URL.
    Do not crawl the same link twice.
    Explore only the links that are under the same hostname as startUrl.
    
    
    As shown in the example URL above, the hostname is example.org. For simplicity's sake, you may assume all URLs use HTTP protocol without any port specified. For example, the URLs http://leetcode.com/problems and http://leetcode.com/contest are under the same hostname, while URLs http://example.org/test and http://example.com/abc are not under the same hostname.
    The HtmlParser interface is defined as such:
    
    interface HtmlParser {
      // Return a list of all urls from a webpage of given url.
      // This is a blocking call, that means it will do HTTP request and return when this request is finished.
      public List getUrls(String url);
    }
    
    Note that getUrls(String url) simulates performing an HTTP request. You can treat it as a blocking function call that waits for an HTTP request to finish. It is guaranteed that getUrls(String url) will return the URLs within 15ms.  Single-threaded solutions will exceed the time limit so, can your multi-threaded web crawler do better?
    Below are two examples explaining the functionality of the problem. For custom testing purposes, you'll have three variables urls, edges and startUrl. Notice that you will only have access to startUrl in your code, while urls and edges are not directly accessible to you in code.
    
    Example 1:
    
    
    urls = [
      "http://news.yahoo.com",
      "http://news.yahoo.com/news",
      "http://news.yahoo.com/news/topics/",
      "http://news.google.com",
      "http://news.yahoo.com/us"
    ]
    edges = [[2,0],[2,1],[3,2],[3,1],[0,4]]
    startUrl = "http://news.yahoo.com/news/topics/"
    >>> getUrls()
    >>> [
      "http://news.yahoo.com",
      "http://news.yahoo.com/news",
      "http://news.yahoo.com/news/topics/",
      "http://news.yahoo.com/us"
    ]
    
    Example 2:
    
    
    urls = [
      "http://news.yahoo.com",
      "http://news.yahoo.com/news",
      "http://news.yahoo.com/news/topics/",
      "http://news.google.com"
    ]
    edges = [[0,2],[2,1],[3,2],[3,1],[3,0]]
    startUrl = "http://news.google.com"
    >>> getUrls()
    >>> ["http://news.google.com"]
    Explanation: The startUrl links to all other pages that do not share the same hostname.
    """
def transformArray(arr: List[int]) -> List[int]:
    """
    Given an initial array arr, every day you produce a new array using the array of the previous day.
    On the i-th day, you do the following operations on the array of day i-1 to produce the array of day i:
    
    If an element is smaller than both its left neighbor and its right neighbor, then this element is incremented.
    If an element is bigger than both its left neighbor and its right neighbor, then this element is decremented.
    The first and last elements never change.
    
    After some days, the array does not change. Return that final array.
    
    Example 1:
    
    >>> transformArray(arr = [6,2,3,4])
    >>> [6,3,3,4]
    Explanation:
    On the first day, the array is changed from [6,2,3,4] to [6,3,3,4].
    No more operations can be done to this array.
    
    Example 2:
    
    >>> transformArray(arr = [1,6,3,4,3,5])
    >>> [1,4,4,4,4,5]
    Explanation:
    On the first day, the array is changed from [1,6,3,4,3,5] to [1,5,4,3,4,5].
    On the second day, the array is changed from [1,5,4,3,4,5] to [1,4,4,4,4,5].
    No more operations can be done to this array.
    """
def treeDiameter(edges: List[List[int]]) -> int:
    """
    The diameter of a tree is the number of edges in the longest path in that tree.
    There is an undirected tree of n nodes labeled from 0 to n - 1. You are given a 2D array edges where edges.length == n - 1 and edges[i] = [ai, bi] indicates that there is an undirected edge between nodes ai and bi in the tree.
    Return the diameter of the tree.
    
    Example 1:
    
    
    >>> treeDiameter(edges = [[0,1],[0,2]])
    >>> 2
    Explanation: The longest path of the tree is the path 1 - 0 - 2.
    
    Example 2:
    
    
    >>> treeDiameter(edges = [[0,1],[1,2],[2,3],[1,4],[4,5]])
    >>> 4
    Explanation: The longest path of the tree is the path 3 - 2 - 1 - 4 - 5.
    """
def minimumMoves(arr: List[int]) -> int:
    """
    You are given an integer array arr.
    In one move, you can select a palindromic subarray arr[i], arr[i + 1], ..., arr[j] where i <= j, and remove that subarray from the given array. Note that after removing a subarray, the elements on the left and on the right of that subarray move to fill the gap left by the removal.
    Return the minimum number of moves needed to remove all numbers from the array.
    
    Example 1:
    
    >>> minimumMoves(arr = [1,2])
    >>> 2
    
    Example 2:
    
    >>> minimumMoves(arr = [1,3,4,1,5])
    >>> 3
    Explanation: Remove [4] then remove [1,3,1] then remove [5].
    """
def minimumSwap(s1: str, s2: str) -> int:
    """
    You are given two strings s1 and s2 of equal length consisting of letters "x" and "y" only. Your task is to make these two strings equal to each other. You can swap any two characters that belong to different strings, which means: swap s1[i] and s2[j].
    Return the minimum number of swaps required to make s1 and s2 equal, or return -1 if it is impossible to do so.
    
    Example 1:
    
    >>> minimumSwap(s1 = "xx", s2 = "yy")
    >>> 1
    Explanation: Swap s1[0] and s2[1], s1 = "yx", s2 = "yx".
    
    Example 2:
    
    >>> minimumSwap(s1 = "xy", s2 = "yx")
    >>> 2
    Explanation: Swap s1[0] and s2[0], s1 = "yy", s2 = "xx".
    Swap s1[0] and s2[1], s1 = "xy", s2 = "xy".
    Note that you cannot swap s1[0] and s1[1] to make s1 equal to "yx", cause we can only swap chars in different strings.
    
    Example 3:
    
    >>> minimumSwap(s1 = "xx", s2 = "xy")
    >>> -1
    """
def numberOfSubarrays(nums: List[int], k: int) -> int:
    """
    Given an array of integers nums and an integer k. A continuous subarray is called nice if there are k odd numbers on it.
    Return the number of nice sub-arrays.
    
    Example 1:
    
    >>> numberOfSubarrays(nums = [1,1,2,1,1], k = 3)
    >>> 2
    Explanation: The only sub-arrays with 3 odd numbers are [1,1,2,1] and [1,2,1,1].
    
    Example 2:
    
    >>> numberOfSubarrays(nums = [2,4,6], k = 1)
    >>> 0
    Explanation: There are no odd numbers in the array.
    
    Example 3:
    
    >>> numberOfSubarrays(nums = [2,2,2,1,2,2,1,2,2,2], k = 2)
    >>> 16
    """