ShwStone/humaneval-leetcode huggingface dataset:
def kthSmallestPrimeFraction(arr: List[int], k: int) -> List[int]:
    """
    You are given a sorted integer array arr containing 1 and prime numbers, where all the integers of arr are unique. You are also given an integer k.
    For every i and j where 0 <= i < j < arr.length, we consider the fraction arr[i] / arr[j].
    Return the kth smallest fraction considered. Return your answer as an array of integers of size 2, where answer[0] == arr[i] and answer[1] == arr[j].
    
    Example 1:
    
    >>> kthSmallestPrimeFraction(arr = [1,2,3,5], k = 3)
    >>> [2,5]
    Explanation: The fractions to be considered in sorted order are:
    1/5, 1/3, 2/5, 1/2, 3/5, and 2/3.
    The third fraction is 2/5.
    
    Example 2:
    
    >>> kthSmallestPrimeFraction(arr = [1,7], k = 1)
    >>> [1,7]
    """
def findCheapestPrice(n: int, flights: List[List[int]], src: int, dst: int, k: int) -> int:
    """
    There are n cities connected by some number of flights. You are given an array flights where flights[i] = [fromi, toi, pricei] indicates that there is a flight from city fromi to city toi with cost pricei.
    You are also given three integers src, dst, and k, return the cheapest price from src to dst with at most k stops. If there is no such route, return -1.
    
    Example 1:
    
    
    >>> findCheapestPrice(n = 4, flights = [[0,1,100],[1,2,100],[2,0,100],[1,3,600],[2,3,200]], src = 0, dst = 3, k = 1)
    >>> 700
    Explanation:
    The graph is shown above.
    The optimal path with at most 1 stop from city 0 to 3 is marked in red and has cost 100 + 600 = 700.
    Note that the path through cities [0,1,2,3] is cheaper but is invalid because it uses 2 stops.
    
    Example 2:
    
    
    >>> findCheapestPrice(n = 3, flights = [[0,1,100],[1,2,100],[0,2,500]], src = 0, dst = 2, k = 1)
    >>> 200
    Explanation:
    The graph is shown above.
    The optimal path with at most 1 stop from city 0 to 2 is marked in red and has cost 100 + 100 = 200.
    
    Example 3:
    
    
    >>> findCheapestPrice(n = 3, flights = [[0,1,100],[1,2,100],[0,2,500]], src = 0, dst = 2, k = 0)
    >>> 500
    Explanation:
    The graph is shown above.
    The optimal path with no stops from city 0 to 2 is marked in red and has cost 500.
    """
def rotatedDigits(n: int) -> int:
    """
    An integer x is a good if after rotating each digit individually by 180 degrees, we get a valid number that is different from x. Each digit must be rotated - we cannot choose to leave it alone.
    A number is valid if each digit remains a digit after rotation. For example:
    
    0, 1, and 8 rotate to themselves,
    2 and 5 rotate to each other (in this case they are rotated in a different direction, in other words, 2 or 5 gets mirrored),
    6 and 9 rotate to each other, and
    the rest of the numbers do not rotate to any other number and become invalid.
    
    Given an integer n, return the number of good integers in the range [1, n].
    
    Example 1:
    
    >>> rotatedDigits(n = 10)
    >>> 4
    Explanation: There are four good numbers in the range [1, 10] : 2, 5, 6, 9.
    Note that 1 and 10 are not good numbers, since they remain unchanged after rotating.
    
    Example 2:
    
    >>> rotatedDigits(n = 1)
    >>> 0
    
    Example 3:
    
    >>> rotatedDigits(n = 2)
    >>> 1
    """
def escapeGhosts(ghosts: List[List[int]], target: List[int]) -> bool:
    """
    You are playing a simplified PAC-MAN game on an infinite 2-D grid. You start at the point [0, 0], and you are given a destination point target = [xtarget, ytarget] that you are trying to get to. There are several ghosts on the map with their starting positions given as a 2D array ghosts, where ghosts[i] = [xi, yi] represents the starting position of the ith ghost. All inputs are integral coordinates.
    Each turn, you and all the ghosts may independently choose to either move 1 unit in any of the four cardinal directions: north, east, south, or west, or stay still. All actions happen simultaneously.
    You escape if and only if you can reach the target before any ghost reaches you. If you reach any square (including the target) at the same time as a ghost, it does not count as an escape.
    Return true if it is possible to escape regardless of how the ghosts move, otherwise return false.
    
    Example 1:
    
    >>> escapeGhosts(ghosts = [[1,0],[0,3]], target = [0,1])
    >>> true
    Explanation: You can reach the destination (0, 1) after 1 turn, while the ghosts located at (1, 0) and (0, 3) cannot catch up with you.
    
    Example 2:
    
    >>> escapeGhosts(ghosts = [[1,0]], target = [2,0])
    >>> false
    Explanation: You need to reach the destination (2, 0), but the ghost at (1, 0) lies between you and the destination.
    
    Example 3:
    
    >>> escapeGhosts(ghosts = [[2,0]], target = [1,0])
    >>> false
    Explanation: The ghost can reach the target at the same time as you.
    """
def numTilings(n: int) -> int:
    """
    You have two types of tiles: a 2 x 1 domino shape and a tromino shape. You may rotate these shapes.
    
    Given an integer n, return the number of ways to tile an 2 x n board. Since the answer may be very large, return it modulo 109 + 7.
    In a tiling, every square must be covered by a tile. Two tilings are different if and only if there are two 4-directionally adjacent cells on the board such that exactly one of the tilings has both squares occupied by a tile.
    
    Example 1:
    
    
    >>> numTilings(n = 3)
    >>> 5
    Explanation: The five different ways are show above.
    
    Example 2:
    
    >>> numTilings(n = 1)
    >>> 1
    """
def customSortString(order: str, s: str) -> str:
    """
    You are given two strings order and s. All the characters of order are unique and were sorted in some custom order previously.
    Permute the characters of s so that they match the order that order was sorted. More specifically, if a character x occurs before a character y in order, then x should occur before y in the permuted string.
    Return any permutation of s that satisfies this property.
    
    Example 1:
    
    >>> customSortString(order = "cba", s = "abcd")
    >>> "cbad"
    Explanation:  "a", "b", "c" appear in order, so the order of "a", "b", "c" should be "c", "b", and "a".
    Since "d" does not appear in order, it can be at any position in the returned string. "dcba", "cdba", "cbda" are also valid outputs.
    
    Example 2:
    
    >>> customSortString(order = "bcafg", s = "abcd")
    >>> "bcad"
    Explanation:  The characters "b", "c", and "a" from order dictate the order for the characters in s. The character "d" in s does not appear in order, so its position is flexible.
    Following the order of appearance in order, "b", "c", and "a" from s should be arranged as "b", "c", "a". "d" can be placed at any position since it's not in order. The output "bcad" correctly follows this rule. Other arrangements like "dbca" or "bcda" would also be valid, as long as "b", "c", "a" maintain their order.
    """
def numMatchingSubseq(s: str, words: List[str]) -> int:
    """
    Given a string s and an array of strings words, return the number of words[i] that is a subsequence of s.
    A subsequence of a string is a new string generated from the original string with some characters (can be none) deleted without changing the relative order of the remaining characters.
    
    For example, "ace" is a subsequence of "abcde".
    
    
    Example 1:
    
    >>> numMatchingSubseq(s = "abcde", words = ["a","bb","acd","ace"])
    >>> 3
    Explanation: There are three strings in words that are a subsequence of s: "a", "acd", "ace".
    
    Example 2:
    
    >>> numMatchingSubseq(s = "dsahjpjauf", words = ["ahjpjau","ja","ahbwzgqnuk","tnmlanowax"])
    >>> 2
    """
def preimageSizeFZF(k: int) -> int:
    """
    Let f(x) be the number of zeroes at the end of x!. Recall that x! = 1 * 2 * 3 * ... * x and by convention, 0! = 1.
    
    For example, f(3) = 0 because 3! = 6 has no zeroes at the end, while f(11) = 2 because 11! = 39916800 has two zeroes at the end.
    
    Given an integer k, return the number of non-negative integers x have the property that f(x) = k.
    
    Example 1:
    
    >>> preimageSizeFZF(k = 0)
    >>> 5
    Explanation: 0!, 1!, 2!, 3!, and 4! end with k = 0 zeroes.
    
    Example 2:
    
    >>> preimageSizeFZF(k = 5)
    >>> 0
    Explanation: There is no x such that x! ends in k = 5 zeroes.
    
    Example 3:
    
    >>> preimageSizeFZF(k = 3)
    >>> 5
    """
def validTicTacToe(board: List[str]) -> bool:
    """
    Given a Tic-Tac-Toe board as a string array board, return true if and only if it is possible to reach this board position during the course of a valid tic-tac-toe game.
    The board is a 3 x 3 array that consists of characters ' ', 'X', and 'O'. The ' ' character represents an empty square.
    Here are the rules of Tic-Tac-Toe:
    
    Players take turns placing characters into empty squares ' '.
    The first player always places 'X' characters, while the second player always places 'O' characters.
    'X' and 'O' characters are always placed into empty squares, never filled ones.
    The game ends when there are three of the same (non-empty) character filling any row, column, or diagonal.
    The game also ends if all squares are non-empty.
    No more moves can be played if the game is over.
    
    
    Example 1:
    
    
    >>> validTicTacToe(board = ["O  ","   ","   "])
    >>> false
    Explanation: The first player always plays "X".
    
    Example 2:
    
    
    >>> validTicTacToe(board = ["XOX"," X ","   "])
    >>> false
    Explanation: Players take turns making moves.
    
    Example 3:
    
    
    >>> validTicTacToe(board = ["XOX","O O","XOX"])
    >>> true
    """
def numSubarrayBoundedMax(nums: List[int], left: int, right: int) -> int:
    """
    Given an integer array nums and two integers left and right, return the number of contiguous non-empty subarrays such that the value of the maximum array element in that subarray is in the range [left, right].
    The test cases are generated so that the answer will fit in a 32-bit integer.
    
    Example 1:
    
    >>> numSubarrayBoundedMax(nums = [2,1,4,3], left = 2, right = 3)
    >>> 3
    Explanation: There are three subarrays that meet the requirements: [2], [2, 1], [3].
    
    Example 2:
    
    >>> numSubarrayBoundedMax(nums = [2,9,2,5,6], left = 2, right = 8)
    >>> 7
    """
def rotateString(s: str, goal: str) -> bool:
    """
    Given two strings s and goal, return true if and only if s can become goal after some number of shifts on s.
    A shift on s consists of moving the leftmost character of s to the rightmost position.
    
    For example, if s = "abcde", then it will be "bcdea" after one shift.
    
    
    Example 1:
    >>> rotateString(s = "abcde", goal = "cdeab")
    >>> true
    Example 2:
    >>> rotateString(s = "abcde", goal = "abced")
    >>> false
    """
def allPathsSourceTarget(graph: List[List[int]]) -> List[List[int]]:
    """
    Given a directed acyclic graph (DAG) of n nodes labeled from 0 to n - 1, find all possible paths from node 0 to node n - 1 and return them in any order.
    The graph is given as follows: graph[i] is a list of all nodes you can visit from node i (i.e., there is a directed edge from node i to node graph[i][j]).
    
    Example 1:
    
    
    >>> allPathsSourceTarget(graph = [[1,2],[3],[3],[]])
    >>> [[0,1,3],[0,2,3]]
    Explanation: There are two paths: 0 -> 1 -> 3 and 0 -> 2 -> 3.
    
    Example 2:
    
    
    >>> allPathsSourceTarget(graph = [[4,3,1],[3,2,4],[3],[4],[]])
    >>> [[0,4],[0,3,4],[0,1,3,4],[0,1,2,3,4],[0,1,4]]
    """
def bestRotation(nums: List[int]) -> int:
    """
    You are given an array nums. You can rotate it by a non-negative integer k so that the array becomes [nums[k], nums[k + 1], ... nums[nums.length - 1], nums[0], nums[1], ..., nums[k-1]]. Afterward, any entries that are less than or equal to their index are worth one point.
    
    For example, if we have nums = [2,4,1,3,0], and we rotate by k = 2, it becomes [1,3,0,2,4]. This is worth 3 points because 1 > 0 [no points], 3 > 1 [no points], 0 <= 2 [one point], 2 <= 3 [one point], 4 <= 4 [one point].
    
    Return the rotation index k that corresponds to the highest score we can achieve if we rotated nums by it. If there are multiple answers, return the smallest such index k.
    
    Example 1:
    
    >>> bestRotation(nums = [2,3,1,4,0])
    >>> 3
    Explanation: Scores for each k are listed below:
    k = 0,  nums = [2,3,1,4,0],    score 2
    k = 1,  nums = [3,1,4,0,2],    score 3
    k = 2,  nums = [1,4,0,2,3],    score 3
    k = 3,  nums = [4,0,2,3,1],    score 4
    k = 4,  nums = [0,2,3,1,4],    score 3
    So we should choose k = 3, which has the highest score.
    
    Example 2:
    
    >>> bestRotation(nums = [1,3,0,2,4])
    >>> 0
    Explanation: nums will always have 3 points no matter how it shifts.
    So we will choose the smallest k, which is 0.
    """
def champagneTower(poured: int, query_row: int, query_glass: int) -> float:
    """
    We stack glasses in a pyramid, where the first row has 1 glass, the second row has 2 glasses, and so on until the 100th row.  Each glass holds one cup of champagne.\r
    \r
    Then, some champagne is poured into the first glass at the top.  When the topmost glass is full, any excess liquid poured will fall equally to the glass immediately to the left and right of it.  When those glasses become full, any excess champagne will fall equally to the left and right of those glasses, and so on.  (A glass at the bottom row has its excess champagne fall on the floor.)\r
    \r
    For example, after one cup of champagne is poured, the top most glass is full.  After two cups of champagne are poured, the two glasses on the second row are half full.  After three cups of champagne are poured, those two cups become full - there are 3 full glasses total now.  After four cups of champagne are poured, the third row has the middle glass half full, and the two outside glasses are a quarter full, as pictured below.\r
    \r
    \r
    \r
    Now after pouring some non-negative integer cups of champagne, return how full the jth glass in the ith row is (both i and j are 0-indexed.)\r
    \r
     \r
    Example 1:\r
    \r
    \r
    >>> champagneTower(poured = 1, query_row = 1, query_glass = 1\r)
    >>> 0.00000\r
    Explanation: We poured 1 cup of champange to the top glass of the tower (which is indexed as (0, 0)). There will be no excess liquid so all the glasses under the top glass will remain empty.\r
    \r
    \r
    Example 2:\r
    \r
    \r
    >>> champagneTower(poured = 2, query_row = 1, query_glass = 1\r)
    >>> 0.50000\r
    Explanation: We poured 2 cups of champange to the top glass of the tower (which is indexed as (0, 0)). There is one cup of excess liquid. The glass indexed as (1, 0) and the glass indexed as (1, 1) will share the excess liquid equally, and each will get half cup of champange.\r
    \r
    \r
    Example 3:\r
    \r
    \r
    >>> champagneTower(poured = 100000009, query_row = 33, query_glass = 17\r)
    >>> 1.00000\r
    \r
    \r
     \r
    """
def similarRGB(color: str) -> str:
    """
    The red-green-blue color "#AABBCC" can be written as "#ABC" in shorthand.
    
    For example, "#15c" is shorthand for the color "#1155cc".
    
    The similarity between the two colors "#ABCDEF" and "#UVWXYZ" is -(AB - UV)2 - (CD - WX)2 - (EF - YZ)2.
    Given a string color that follows the format "#ABCDEF", return a string represents the color that is most similar to the given color and has a shorthand (i.e., it can be represented as some "#XYZ").
    Any answer which has the same highest similarity as the best answer will be accepted.
    
    Example 1:
    
    >>> similarRGB(color = "#09f166")
    >>> "#11ee66"
    Explanation:
    The similarity is -(0x09 - 0x11)2 -(0xf1 - 0xee)2 - (0x66 - 0x66)2 = -64 -9 -0 = -73.
    This is the highest among any shorthand color.
    
    Example 2:
    
    >>> similarRGB(color = "#4e3fe1")
    >>> "#5544dd"
    """
def minSwap(nums1: List[int], nums2: List[int]) -> int:
    """
    You are given two integer arrays of the same length nums1 and nums2. In one operation, you are allowed to swap nums1[i] with nums2[i].
    
    For example, if nums1 = [1,2,3,8], and nums2 = [5,6,7,4], you can swap the element at i = 3 to obtain nums1 = [1,2,3,4] and nums2 = [5,6,7,8].
    
    Return the minimum number of needed operations to make nums1 and nums2 strictly increasing. The test cases are generated so that the given input always makes it possible.
    An array arr is strictly increasing if and only if arr[0] < arr[1] < arr[2] < ... < arr[arr.length - 1].
    
    Example 1:
    
    >>> minSwap(nums1 = [1,3,5,4], nums2 = [1,2,3,7])
    >>> 1
    Explanation:
    Swap nums1[3] and nums2[3]. Then the sequences are:
    nums1 = [1, 3, 5, 7] and nums2 = [1, 2, 3, 4]
    which are both strictly increasing.
    
    Example 2:
    
    >>> minSwap(nums1 = [0,3,5,8,9], nums2 = [2,1,4,6,9])
    >>> 1
    """
def eventualSafeNodes(graph: List[List[int]]) -> List[int]:
    """
    There is a directed graph of n nodes with each node labeled from 0 to n - 1. The graph is represented by a 0-indexed 2D integer array graph where graph[i] is an integer array of nodes adjacent to node i, meaning there is an edge from node i to each node in graph[i].
    A node is a terminal node if there are no outgoing edges. A node is a safe node if every possible path starting from that node leads to a terminal node (or another safe node).
    Return an array containing all the safe nodes of the graph. The answer should be sorted in ascending order.
    
    Example 1:
    
    
    >>> eventualSafeNodes(graph = [[1,2],[2,3],[5],[0],[5],[],[]])
    >>> [2,4,5,6]
    Explanation: The given graph is shown above.
    Nodes 5 and 6 are terminal nodes as there are no outgoing edges from either of them.
    Every path starting at nodes 2, 4, 5, and 6 all lead to either node 5 or 6.
    Example 2:
    
    >>> eventualSafeNodes(graph = [[1,2,3,4],[1,2],[3,4],[0,4],[]])
    >>> [4]
    Explanation:
    Only node 4 is a terminal node, and every path starting at node 4 leads to node 4.
    """
def hitBricks(grid: List[List[int]], hits: List[List[int]]) -> List[int]:
    """
    You are given an m x n binary grid, where each 1 represents a brick and 0 represents an empty space. A brick is stable if:
    
    It is directly connected to the top of the grid, or
    At least one other brick in its four adjacent cells is stable.
    
    You are also given an array hits, which is a sequence of erasures we want to apply. Each time we want to erase the brick at the location hits[i] = (rowi, coli). The brick on that location (if it exists) will disappear. Some other bricks may no longer be stable because of that erasure and will fall. Once a brick falls, it is immediately erased from the grid (i.e., it does not land on other stable bricks).
    Return an array result, where each result[i] is the number of bricks that will fall after the ith erasure is applied.
    Note that an erasure may refer to a location with no brick, and if it does, no bricks drop.
    
    Example 1:
    
    >>> hitBricks(grid = [[1,0,0,0],[1,1,1,0]], hits = [[1,0]])
    >>> [2]
    Explanation: Starting with the grid:
    [[1,0,0,0],
     [1,1,1,0]]
    We erase the underlined brick at (1,0), resulting in the grid:
    [[1,0,0,0],
     [0,1,1,0]]
    The two underlined bricks are no longer stable as they are no longer connected to the top nor adjacent to another stable brick, so they will fall. The resulting grid is:
    [[1,0,0,0],
     [0,0,0,0]]
    Hence the result is [2].
    
    Example 2:
    
    >>> hitBricks(grid = [[1,0,0,0],[1,1,0,0]], hits = [[1,1],[1,0]])
    >>> [0,0]
    Explanation: Starting with the grid:
    [[1,0,0,0],
     [1,1,0,0]]
    We erase the underlined brick at (1,1), resulting in the grid:
    [[1,0,0,0],
     [1,0,0,0]]
    All remaining bricks are still stable, so no bricks fall. The grid remains the same:
    [[1,0,0,0],
     [1,0,0,0]]
    Next, we erase the underlined brick at (1,0), resulting in the grid:
    [[1,0,0,0],
     [0,0,0,0]]
    Once again, all remaining bricks are still stable, so no bricks fall.
    Hence the result is [0,0].
    """
def uniqueMorseRepresentations(words: List[str]) -> int:
    """
    International Morse Code defines a standard encoding where each letter is mapped to a series of dots and dashes, as follows:
    
    'a' maps to ".-",
    'b' maps to "-...",
    'c' maps to "-.-.", and so on.
    
    For convenience, the full table for the 26 letters of the English alphabet is given below:
    
    [".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."]
    Given an array of strings words where each word can be written as a concatenation of the Morse code of each letter.
    
    For example, "cab" can be written as "-.-..--...", which is the concatenation of "-.-.", ".-", and "-...". We will call such a concatenation the transformation of a word.
    
    Return the number of different transformations among all words we have.
    
    Example 1:
    
    >>> uniqueMorseRepresentations(words = ["gin","zen","gig","msg"])
    >>> 2
    Explanation: The transformation of each word is:
    "gin" -> "--...-."
    "zen" -> "--...-."
    "gig" -> "--...--."
    "msg" -> "--...--."
    There are 2 different transformations: "--...-." and "--...--.".
    
    Example 2:
    
    >>> uniqueMorseRepresentations(words = ["a"])
    >>> 1
    """
def splitArraySameAverage(nums: List[int]) -> bool:
    """
    You are given an integer array nums.
    You should move each element of nums into one of the two arrays A and B such that A and B are non-empty, and average(A) == average(B).
    Return true if it is possible to achieve that and false otherwise.
    Note that for an array arr, average(arr) is the sum of all the elements of arr over the length of arr.
    
    Example 1:
    
    >>> splitArraySameAverage(nums = [1,2,3,4,5,6,7,8])
    >>> true
    Explanation: We can split the array into [1,4,5,8] and [2,3,6,7], and both of them have an average of 4.5.
    
    Example 2:
    
    >>> splitArraySameAverage(nums = [3,1])
    >>> false
    """
def numberOfLines(widths: List[int], s: str) -> List[int]:
    """
    You are given a string s of lowercase English letters and an array widths denoting how many pixels wide each lowercase English letter is. Specifically, widths[0] is the width of 'a', widths[1] is the width of 'b', and so on.
    You are trying to write s across several lines, where each line is no longer than 100 pixels. Starting at the beginning of s, write as many letters on the first line such that the total width does not exceed 100 pixels. Then, from where you stopped in s, continue writing as many letters as you can on the second line. Continue this process until you have written all of s.
    Return an array result of length 2 where:
    
    result[0] is the total number of lines.
    result[1] is the width of the last line in pixels.
    
    
    Example 1:
    
    >>> numberOfLines(widths = [10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10], s = "abcdefghijklmnopqrstuvwxyz")
    >>> [3,60]
    Explanation: You can write s as follows:
    abcdefghij  // 100 pixels wide
    klmnopqrst  // 100 pixels wide
    uvwxyz      // 60 pixels wide
    There are a total of 3 lines, and the last line is 60 pixels wide.
    Example 2:
    
    >>> numberOfLines(widths = [4,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10], s = "bbbcccdddaaa")
    >>> [2,4]
    Explanation: You can write s as follows:
    bbbcccdddaa  // 98 pixels wide
    a            // 4 pixels wide
    There are a total of 2 lines, and the last line is 4 pixels wide.
    """