ShwStone/humaneval-leetcode huggingface dataset:
def anagramMappings(nums1: List[int], nums2: List[int]) -> List[int]:
    """
    You are given two integer arrays nums1 and nums2 where nums2 is an anagram of nums1. Both arrays may contain duplicates.
    Return an index mapping array mapping from nums1 to nums2 where mapping[i] = j means the ith element in nums1 appears in nums2 at index j. If there are multiple answers, return any of them.
    An array a is an anagram of an array b means b is made by randomizing the order of the elements in a.
    
    Example 1:
    
    >>> anagramMappings(nums1 = [12,28,46,32,50], nums2 = [50,12,32,46,28])
    >>> [1,4,3,2,0]
    Explanation: As mapping[0] = 1 because the 0th element of nums1 appears at nums2[1], and mapping[1] = 4 because the 1st element of nums1 appears at nums2[4], and so on.
    
    Example 2:
    
    >>> anagramMappings(nums1 = [84,46], nums2 = [84,46])
    >>> [0,1]
    """
def makeLargestSpecial(s: str) -> str:
    """
    Special binary strings are binary strings with the following two properties:
    
    The number of 0's is equal to the number of 1's.
    Every prefix of the binary string has at least as many 1's as 0's.
    
    You are given a special binary string s.
    A move consists of choosing two consecutive, non-empty, special substrings of s, and swapping them. Two strings are consecutive if the last character of the first string is exactly one index before the first character of the second string.
    Return the lexicographically largest resulting string possible after applying the mentioned operations on the string.
    
    Example 1:
    
    >>> makeLargestSpecial(s = "11011000")
    >>> "11100100"
    Explanation: The strings "10" [occuring at s[1]] and "1100" [at s[3]] are swapped.
    This is the lexicographically largest string possible after some number of swaps.
    
    Example 2:
    
    >>> makeLargestSpecial(s = "10")
    >>> "10"
    """
def countPrimeSetBits(left: int, right: int) -> int:
    """
    Given two integers left and right, return the count of numbers in the inclusive range [left, right] having a prime number of set bits in their binary representation.
    Recall that the number of set bits an integer has is the number of 1's present when written in binary.
    
    For example, 21 written in binary is 10101, which has 3 set bits.
    
    
    Example 1:
    
    >>> countPrimeSetBits(left = 6, right = 10)
    >>> 4
    Explanation:
    6  -> 110 (2 set bits, 2 is prime)
    7  -> 111 (3 set bits, 3 is prime)
    8  -> 1000 (1 set bit, 1 is not prime)
    9  -> 1001 (2 set bits, 2 is prime)
    10 -> 1010 (2 set bits, 2 is prime)
    4 numbers have a prime number of set bits.
    
    Example 2:
    
    >>> countPrimeSetBits(left = 10, right = 15)
    >>> 5
    Explanation:
    10 -> 1010 (2 set bits, 2 is prime)
    11 -> 1011 (3 set bits, 3 is prime)
    12 -> 1100 (2 set bits, 2 is prime)
    13 -> 1101 (3 set bits, 3 is prime)
    14 -> 1110 (3 set bits, 3 is prime)
    15 -> 1111 (4 set bits, 4 is not prime)
    5 numbers have a prime number of set bits.
    """
def partitionLabels(s: str) -> List[int]:
    """
    You are given a string s. We want to partition the string into as many parts as possible so that each letter appears in at most one part. For example, the string "ababcc" can be partitioned into ["abab", "cc"], but partitions such as ["aba", "bcc"] or ["ab", "ab", "cc"] are invalid.
    Note that the partition is done so that after concatenating all the parts in order, the resultant string should be s.
    Return a list of integers representing the size of these parts.
    
    Example 1:
    
    >>> partitionLabels(s = "ababcbacadefegdehijhklij")
    >>> [9,7,8]
    Explanation:
    The partition is "ababcbaca", "defegde", "hijhklij".
    This is a partition so that each letter appears in at most one part.
    A partition like "ababcbacadefegde", "hijhklij" is incorrect, because it splits s into less parts.
    
    Example 2:
    
    >>> partitionLabels(s = "eccbbbbdec")
    >>> [10]
    """
def orderOfLargestPlusSign(n: int, mines: List[List[int]]) -> int:
    """
    You are given an integer n. You have an n x n binary grid grid with all values initially 1's except for some indices given in the array mines. The ith element of the array mines is defined as mines[i] = [xi, yi] where grid[xi][yi] == 0.
    Return the order of the largest axis-aligned plus sign of 1's contained in grid. If there is none, return 0.
    An axis-aligned plus sign of 1's of order k has some center grid[r][c] == 1 along with four arms of length k - 1 going up, down, left, and right, and made of 1's. Note that there could be 0's or 1's beyond the arms of the plus sign, only the relevant area of the plus sign is checked for 1's.
    
    Example 1:
    
    
    >>> orderOfLargestPlusSign(n = 5, mines = [[4,2]])
    >>> 2
    Explanation: In the above grid, the largest plus sign can only be of order 2. One of them is shown.
    
    Example 2:
    
    
    >>> orderOfLargestPlusSign(n = 1, mines = [[0,0]])
    >>> 0
    Explanation: There is no plus sign, so return 0.
    """
def minSwapsCouples(row: List[int]) -> int:
    """
    There are n couples sitting in 2n seats arranged in a row and want to hold hands.
    The people and seats are represented by an integer array row where row[i] is the ID of the person sitting in the ith seat. The couples are numbered in order, the first couple being (0, 1), the second couple being (2, 3), and so on with the last couple being (2n - 2, 2n - 1).
    Return the minimum number of swaps so that every couple is sitting side by side. A swap consists of choosing any two people, then they stand up and switch seats.
    
    Example 1:
    
    >>> minSwapsCouples(row = [0,2,1,3])
    >>> 1
    Explanation: We only need to swap the second (row[1]) and third (row[2]) person.
    
    Example 2:
    
    >>> minSwapsCouples(row = [3,2,0,1])
    >>> 0
    Explanation: All couples are already seated side by side.
    """
def isToeplitzMatrix(matrix: List[List[int]]) -> bool:
    """
    Given an m x n matrix, return true if the matrix is Toeplitz. Otherwise, return false.
    A matrix is Toeplitz if every diagonal from top-left to bottom-right has the same elements.
    
    Example 1:
    
    
    >>> isToeplitzMatrix(matrix = [[1,2,3,4],[5,1,2,3],[9,5,1,2]])
    >>> true
    Explanation:
    In the above grid, the diagonals are:
    "[9]", "[5, 5]", "[1, 1, 1]", "[2, 2, 2]", "[3, 3]", "[4]".
    In each diagonal all elements are the same, so the answer is True.
    
    Example 2:
    
    
    >>> isToeplitzMatrix(matrix = [[1,2],[2,2]])
    >>> false
    Explanation:
    The diagonal "[1, 2]" has different elements.
    """
def reorganizeString(s: str) -> str:
    """
    Given a string s, rearrange the characters of s so that any two adjacent characters are not the same.
    Return any possible rearrangement of s or return "" if not possible.
    
    Example 1:
    >>> reorganizeString(s = "aab")
    >>> "aba"
    Example 2:
    >>> reorganizeString(s = "aaab")
    >>> ""
    """
def maxChunksToSorted(arr: List[int]) -> int:
    """
    You are given an integer array arr.
    We split arr into some number of chunks (i.e., partitions), and individually sort each chunk. After concatenating them, the result should equal the sorted array.
    Return the largest number of chunks we can make to sort the array.
    
    Example 1:
    
    >>> maxChunksToSorted(arr = [5,4,3,2,1])
    >>> 1
    Explanation:
    Splitting into two or more chunks will not return the required result.
    For example, splitting into [5, 4], [3, 2, 1] will result in [4, 5, 1, 2, 3], which isn't sorted.
    
    Example 2:
    
    >>> maxChunksToSorted(arr = [2,1,3,4,4])
    >>> 4
    Explanation:
    We can split into two chunks, such as [2, 1], [3, 4, 4].
    However, splitting into [2, 1], [3], [4], [4] is the highest number of chunks possible.
    """
def maxChunksToSorted(arr: List[int]) -> int:
    """
    You are given an integer array arr of length n that represents a permutation of the integers in the range [0, n - 1].
    We split arr into some number of chunks (i.e., partitions), and individually sort each chunk. After concatenating them, the result should equal the sorted array.
    Return the largest number of chunks we can make to sort the array.
    
    Example 1:
    
    >>> maxChunksToSorted(arr = [4,3,2,1,0])
    >>> 1
    Explanation:
    Splitting into two or more chunks will not return the required result.
    For example, splitting into [4, 3], [2, 1, 0] will result in [3, 4, 0, 1, 2], which isn't sorted.
    
    Example 2:
    
    >>> maxChunksToSorted(arr = [1,0,2,3,4])
    >>> 4
    Explanation:
    We can split into two chunks, such as [1, 0], [2, 3, 4].
    However, splitting into [1, 0], [2], [3], [4] is the highest number of chunks possible.
    """
def basicCalculatorIV(expression: str, evalvars: List[str], evalints: List[int]) -> List[str]:
    """
    Given an expression such as expression = "e + 8 - a + 5" and an evaluation map such as {"e": 1} (given in terms of evalvars = ["e"] and evalints = [1]), return a list of tokens representing the simplified expression, such as ["-1*a","14"]
    
    An expression alternates chunks and symbols, with a space separating each chunk and symbol.
    A chunk is either an expression in parentheses, a variable, or a non-negative integer.
    A variable is a string of lowercase letters (not including digits.) Note that variables can be multiple letters, and note that variables never have a leading coefficient or unary operator like "2x" or "-x".
    
    Expressions are evaluated in the usual order: brackets first, then multiplication, then addition and subtraction.
    
    For example, expression = "1 + 2 * 3" has an answer of ["7"].
    
    The format of the output is as follows:
    
    For each term of free variables with a non-zero coefficient, we write the free variables within a term in sorted order lexicographically.
    
    For example, we would never write a term like "b*a*c", only "a*b*c".
    
    
    Terms have degrees equal to the number of free variables being multiplied, counting multiplicity. We write the largest degree terms of our answer first, breaking ties by lexicographic order ignoring the leading coefficient of the term.
    
    For example, "a*a*b*c" has degree 4.
    
    
    The leading coefficient of the term is placed directly to the left with an asterisk separating it from the variables (if they exist.) A leading coefficient of 1 is still printed.
    An example of a well-formatted answer is ["-2*a*a*a", "3*a*a*b", "3*b*b", "4*a", "5*c", "-6"].
    Terms (including constant terms) with coefficient 0 are not included.
    
    For example, an expression of "0" has an output of [].
    
    
    
    Note: You may assume that the given expression is always valid. All intermediate results will be in the range of [-231, 231 - 1].
    
    Example 1:
    
    >>> basicCalculatorIV(expression = "e + 8 - a + 5", evalvars = ["e"], evalints = [1])
    >>> ["-1*a","14"]
    
    Example 2:
    
    >>> basicCalculatorIV(expression = "e - 8 + temperature - pressure", evalvars = ["e", "temperature"], evalints = [1, 12])
    >>> ["-1*pressure","5"]
    
    Example 3:
    
    >>> basicCalculatorIV(expression = "(e + 8) * (e - 8)", evalvars = [], evalints = [])
    >>> ["1*e*e","-64"]
    """
def numJewelsInStones(jewels: str, stones: str) -> int:
    """
    You're given strings jewels representing the types of stones that are jewels, and stones representing the stones you have. Each character in stones is a type of stone you have. You want to know how many of the stones you have are also jewels.
    Letters are case sensitive, so "a" is considered a different type of stone from "A".
    
    Example 1:
    >>> numJewelsInStones(jewels = "aA", stones = "aAAbbbb")
    >>> 3
    Example 2:
    >>> numJewelsInStones(jewels = "z", stones = "ZZ")
    >>> 0
    """
def calculate(s: str) -> int:
    """
    Implement a basic calculator to evaluate a simple expression string.
    The expression string contains only non-negative integers, '+', '-', '*', '/' operators, and open '(' and closing parentheses ')'. The integer division should truncate toward zero.
    You may assume that the given expression is always valid. All intermediate results will be in the range of [-231, 231 - 1].
    Note: You are not allowed to use any built-in function which evaluates strings as mathematical expressions, such as eval().
    
    Example 1:
    
    >>> calculate(s = "1+1")
    >>> 2
    
    Example 2:
    
    >>> calculate(s = "6-4/2")
    >>> 4
    
    Example 3:
    
    >>> calculate(s = "2*(5+5*2)/3+(6/2+8)")
    >>> 21
    """
def slidingPuzzle(board: List[List[int]]) -> int:
    """
    On an 2 x 3 board, there are five tiles labeled from 1 to 5, and an empty square represented by 0. A move consists of choosing 0 and a 4-directionally adjacent number and swapping it.
    The state of the board is solved if and only if the board is [[1,2,3],[4,5,0]].
    Given the puzzle board board, return the least number of moves required so that the state of the board is solved. If it is impossible for the state of the board to be solved, return -1.
    
    Example 1:
    
    
    >>> slidingPuzzle(board = [[1,2,3],[4,0,5]])
    >>> 1
    Explanation: Swap the 0 and the 5 in one move.
    
    Example 2:
    
    
    >>> slidingPuzzle(board = [[1,2,3],[5,4,0]])
    >>> -1
    Explanation: No number of moves will make the board solved.
    
    Example 3:
    
    
    >>> slidingPuzzle(board = [[4,1,2],[5,0,3]])
    >>> 5
    Explanation: 5 is the smallest number of moves that solves the board.
    An example path:
    After move 0: [[4,1,2],[5,0,3]]
    After move 1: [[4,1,2],[0,5,3]]
    After move 2: [[0,1,2],[4,5,3]]
    After move 3: [[1,0,2],[4,5,3]]
    After move 4: [[1,2,0],[4,5,3]]
    After move 5: [[1,2,3],[4,5,0]]
    """
def minmaxGasDist(stations: List[int], k: int) -> float:
    """
    You are given an integer array stations that represents the positions of the gas stations on the x-axis. You are also given an integer k.
    You should add k new gas stations. You can add the stations anywhere on the x-axis, and not necessarily on an integer position.
    Let penalty() be the maximum distance between adjacent gas stations after adding the k new stations.
    Return the smallest possible value of penalty(). Answers within 10-6 of the actual answer will be accepted.
    
    Example 1:
    >>> minmaxGasDist(stations = [1,2,3,4,5,6,7,8,9,10], k = 9)
    >>> 0.50000
    Example 2:
    >>> minmaxGasDist(stations = [23,24,36,39,46,56,57,65,84,98], k = 1)
    >>> 14.00000
    """
def isIdealPermutation(nums: List[int]) -> bool:
    """
    You are given an integer array nums of length n which represents a permutation of all the integers in the range [0, n - 1].
    The number of global inversions is the number of the different pairs (i, j) where:
    
    0 <= i < j < n
    nums[i] > nums[j]
    
    The number of local inversions is the number of indices i where:
    
    0 <= i < n - 1
    nums[i] > nums[i + 1]
    
    Return true if the number of global inversions is equal to the number of local inversions.
    
    Example 1:
    
    >>> isIdealPermutation(nums = [1,0,2])
    >>> true
    Explanation: There is 1 global inversion and 1 local inversion.
    
    Example 2:
    
    >>> isIdealPermutation(nums = [1,2,0])
    >>> false
    Explanation: There are 2 global inversions and 1 local inversion.
    """
def canTransform(start: str, result: str) -> bool:
    """
    In a string composed of 'L', 'R', and 'X' characters, like "RXXLRXRXL", a move consists of either replacing one occurrence of "XL" with "LX", or replacing one occurrence of "RX" with "XR". Given the starting string start and the ending string result, return True if and only if there exists a sequence of moves to transform start to result.
    
    Example 1:
    
    >>> canTransform(start = "RXXLRXRXL", result = "XRLXXRRLX")
    >>> true
    Explanation: We can transform start to result following these steps:
    RXXLRXRXL ->
    XRXLRXRXL ->
    XRLXRXRXL ->
    XRLXXRRXL ->
    XRLXXRRLX
    
    Example 2:
    
    >>> canTransform(start = "X", result = "L")
    >>> false
    """
def swimInWater(grid: List[List[int]]) -> int:
    """
    You are given an n x n integer matrix grid where each value grid[i][j] represents the elevation at that point (i, j).
    The rain starts to fall. At time t, the depth of the water everywhere is t. You can swim from a square to another 4-directionally adjacent square if and only if the elevation of both squares individually are at most t. You can swim infinite distances in zero time. Of course, you must stay within the boundaries of the grid during your swim.
    Return the least time until you can reach the bottom right square (n - 1, n - 1) if you start at the top left square (0, 0).
    
    Example 1:
    
    
    >>> swimInWater(grid = [[0,2],[1,3]])
    >>> 3
    Explanation:
    At time 0, you are in grid location (0, 0).
    You cannot go anywhere else because 4-directionally adjacent neighbors have a higher elevation than t = 0.
    You cannot reach point (1, 1) until time 3.
    When the depth of water is 3, we can swim anywhere inside the grid.
    
    Example 2:
    
    
    >>> swimInWater(grid = [[0,1,2,3,4],[24,23,22,21,5],[12,13,14,15,16],[11,17,18,19,20],[10,9,8,7,6]])
    >>> 16
    Explanation: The final route is shown.
    We need to wait until time 16 so that (0, 0) and (4, 4) are connected.
    """
def kthGrammar(n: int, k: int) -> int:
    """
    We build a table of n rows (1-indexed). We start by writing 0 in the 1st row. Now in every subsequent row, we look at the previous row and replace each occurrence of 0 with 01, and each occurrence of 1 with 10.
    
    For example, for n = 3, the 1st row is 0, the 2nd row is 01, and the 3rd row is 0110.
    
    Given two integer n and k, return the kth (1-indexed) symbol in the nth row of a table of n rows.
    
    Example 1:
    
    >>> kthGrammar(n = 1, k = 1)
    >>> 0
    Explanation: row 1: 0
    
    Example 2:
    
    >>> kthGrammar(n = 2, k = 1)
    >>> 0
    Explanation:
    row 1: 0
    row 2: 01
    
    Example 3:
    
    >>> kthGrammar(n = 2, k = 2)
    >>> 1
    Explanation:
    row 1: 0
    row 2: 01
    """
def reachingPoints(sx: int, sy: int, tx: int, ty: int) -> bool:
    """
    Given four integers sx, sy, tx, and ty, return true if it is possible to convert the point (sx, sy) to the point (tx, ty) through some operations, or false otherwise.
    The allowed operation on some point (x, y) is to convert it to either (x, x + y) or (x + y, y).
    
    Example 1:
    
    >>> reachingPoints(sx = 1, sy = 1, tx = 3, ty = 5)
    >>> true
    Explanation:
    One series of moves that transforms the starting point to the target is:
    (1, 1) -> (1, 2)
    (1, 2) -> (3, 2)
    (3, 2) -> (3, 5)
    
    Example 2:
    
    >>> reachingPoints(sx = 1, sy = 1, tx = 2, ty = 2)
    >>> false
    
    Example 3:
    
    >>> reachingPoints(sx = 1, sy = 1, tx = 1, ty = 1)
    >>> true
    """
def numRabbits(answers: List[int]) -> int:
    """
    There is a forest with an unknown number of rabbits. We asked n rabbits "How many rabbits have the same color as you?" and collected the answers in an integer array answers where answers[i] is the answer of the ith rabbit.
    Given the array answers, return the minimum number of rabbits that could be in the forest.
    
    Example 1:
    
    >>> numRabbits(answers = [1,1,2])
    >>> 5
    Explanation:
    The two rabbits that answered "1" could both be the same color, say red.
    The rabbit that answered "2" can't be red or the answers would be inconsistent.
    Say the rabbit that answered "2" was blue.
    Then there should be 2 other blue rabbits in the forest that didn't answer into the array.
    The smallest possible number of rabbits in the forest is therefore 5: 3 that answered plus 2 that didn't.
    
    Example 2:
    
    >>> numRabbits(answers = [10,10,10])
    >>> 11
    """
def movesToChessboard(board: List[List[int]]) -> int:
    """
    You are given an n x n binary grid board. In each move, you can swap any two rows with each other, or any two columns with each other.
    Return the minimum number of moves to transform the board into a chessboard board. If the task is impossible, return -1.
    A chessboard board is a board where no 0's and no 1's are 4-directionally adjacent.
    
    Example 1:
    
    
    >>> movesToChessboard(board = [[0,1,1,0],[0,1,1,0],[1,0,0,1],[1,0,0,1]])
    >>> 2
    Explanation: One potential sequence of moves is shown.
    The first move swaps the first and second column.
    The second move swaps the second and third row.
    
    Example 2:
    
    
    >>> movesToChessboard(board = [[0,1],[1,0]])
    >>> 0
    Explanation: Also note that the board with 0 in the top left corner, is also a valid chessboard.
    
    Example 3:
    
    
    >>> movesToChessboard(board = [[1,0],[1,0]])
    >>> -1
    Explanation: No matter what sequence of moves you make, you cannot end with a valid chessboard.
    """
# class TreeNode:
#     def __init__(val=0, left=None, right=None):
#         self.val = val
#         self.left = left
#         self.right = right
class Solution:
    def minDiffInBST(root: Optional[TreeNode]) -> int:
    """
    Given the root of a Binary Search Tree (BST), return the minimum difference between the values of any two different nodes in the tree.
    
    Example 1:
    
    
    >>> __init__(root = [4,2,6,1,3])
    >>> 1
    
    Example 2:
    
    
    >>> __init__(root = [1,0,48,null,null,12,49])
    >>> 1
    """
def letterCasePermutation(s: str) -> List[str]:
    """
    Given a string s, you can transform every letter individually to be lowercase or uppercase to create another string.
    Return a list of all possible strings we could create. Return the output in any order.
    
    Example 1:
    
    >>> letterCasePermutation(s = "a1b2")
    >>> ["a1b2","a1B2","A1b2","A1B2"]
    
    Example 2:
    
    >>> letterCasePermutation(s = "3z4")
    >>> ["3z4","3Z4"]
    """
def isBipartite(graph: List[List[int]]) -> bool:
    """
    There is an undirected graph with n nodes, where each node is numbered between 0 and n - 1. You are given a 2D array graph, where graph[u] is an array of nodes that node u is adjacent to. More formally, for each v in graph[u], there is an undirected edge between node u and node v. The graph has the following properties:
    
    There are no self-edges (graph[u] does not contain u).
    There are no parallel edges (graph[u] does not contain duplicate values).
    If v is in graph[u], then u is in graph[v] (the graph is undirected).
    The graph may not be connected, meaning there may be two nodes u and v such that there is no path between them.
    
    A graph is bipartite if the nodes can be partitioned into two independent sets A and B such that every edge in the graph connects a node in set A and a node in set B.
    Return true if and only if it is bipartite.
    
    Example 1:
    
    
    >>> isBipartite(graph = [[1,2,3],[0,2],[0,1,3],[0,2]])
    >>> false
    Explanation: There is no way to partition the nodes into two independent sets such that every edge connects a node in one and a node in the other.
    Example 2:
    
    
    >>> isBipartite(graph = [[1,3],[0,2],[1,3],[0,2]])
    >>> true
    Explanation: We can partition the nodes into two sets: {0, 2} and {1, 3}.
    """