ShwStone/humaneval-leetcode huggingface dataset:
def minDeletionSize(strs: List[str]) -> int:
    """
    You are given an array of n strings strs, all of the same length.
    We may choose any deletion indices, and we delete all the characters in those indices for each string.
    For example, if we have strs = ["abcdef","uvwxyz"] and deletion indices {0, 2, 3}, then the final array after deletions is ["bef", "vyz"].
    Suppose we chose a set of deletion indices answer such that after deletions, the final array has its elements in lexicographic order (i.e., strs[0] <= strs[1] <= strs[2] <= ... <= strs[n - 1]). Return the minimum possible value of answer.length.
    
    Example 1:
    
    >>> minDeletionSize(strs = ["ca","bb","ac"])
    >>> 1
    Explanation:
    After deleting the first column, strs = ["a", "b", "c"].
    Now strs is in lexicographic order (ie. strs[0] <= strs[1] <= strs[2]).
    We require at least 1 deletion since initially strs was not in lexicographic order, so the answer is 1.
    
    Example 2:
    
    >>> minDeletionSize(strs = ["xc","yb","za"])
    >>> 0
    Explanation:
    strs is already in lexicographic order, so we do not need to delete anything.
    Note that the rows of strs are not necessarily in lexicographic order:
    i.e., it is NOT necessarily true that (strs[0][0] <= strs[0][1] <= ...)
    
    Example 3:
    
    >>> minDeletionSize(strs = ["zyx","wvu","tsr"])
    >>> 3
    Explanation: We have to delete every column.
    """
def tallestBillboard(rods: List[int]) -> int:
    """
    You are installing a billboard and want it to have the largest height. The billboard will have two steel supports, one on each side. Each steel support must be an equal height.
    You are given a collection of rods that can be welded together. For example, if you have rods of lengths 1, 2, and 3, you can weld them together to make a support of length 6.
    Return the largest possible height of your billboard installation. If you cannot support the billboard, return 0.
    
    Example 1:
    
    >>> tallestBillboard(rods = [1,2,3,6])
    >>> 6
    Explanation: We have two disjoint subsets {1,2,3} and {6}, which have the same sum = 6.
    
    Example 2:
    
    >>> tallestBillboard(rods = [1,2,3,4,5,6])
    >>> 10
    Explanation: We have two disjoint subsets {2,3,5} and {4,6}, which have the same sum = 10.
    
    Example 3:
    
    >>> tallestBillboard(rods = [1,2])
    >>> 0
    Explanation: The billboard cannot be supported, so we return 0.
    """
def prisonAfterNDays(cells: List[int], n: int) -> List[int]:
    """
    There are 8 prison cells in a row and each cell is either occupied or vacant.
    Each day, whether the cell is occupied or vacant changes according to the following rules:
    
    If a cell has two adjacent neighbors that are both occupied or both vacant, then the cell becomes occupied.
    Otherwise, it becomes vacant.
    
    Note that because the prison is a row, the first and the last cells in the row can't have two adjacent neighbors.
    You are given an integer array cells where cells[i] == 1 if the ith cell is occupied and cells[i] == 0 if the ith cell is vacant, and you are given an integer n.
    Return the state of the prison after n days (i.e., n such changes described above).
    
    Example 1:
    
    >>> prisonAfterNDays(cells = [0,1,0,1,1,0,0,1], n = 7)
    >>> [0,0,1,1,0,0,0,0]
    Explanation: The following table summarizes the state of the prison on each day:
    Day 0: [0, 1, 0, 1, 1, 0, 0, 1]
    Day 1: [0, 1, 1, 0, 0, 0, 0, 0]
    Day 2: [0, 0, 0, 0, 1, 1, 1, 0]
    Day 3: [0, 1, 1, 0, 0, 1, 0, 0]
    Day 4: [0, 0, 0, 0, 0, 1, 0, 0]
    Day 5: [0, 1, 1, 1, 0, 1, 0, 0]
    Day 6: [0, 0, 1, 0, 1, 1, 0, 0]
    Day 7: [0, 0, 1, 1, 0, 0, 0, 0]
    
    Example 2:
    
    >>> prisonAfterNDays(cells = [1,0,0,1,0,0,1,0], n = 1000000000)
    >>> [0,0,1,1,1,1,1,0]
    """
# class TreeNode:
#     def __init__(val=0, left=None, right=None):
#         self.val = val
#         self.left = left
#         self.right = right
class Solution:
    def isCompleteTree(root: Optional[TreeNode]) -> bool:
    """
    Given the root of a binary tree, determine if it is a complete binary tree.
    In a complete binary tree, every level, except possibly the last, is completely filled, and all nodes in the last level are as far left as possible. It can have between 1 and 2h nodes inclusive at the last level h.
    
    Example 1:
    
    
    >>> __init__(root = [1,2,3,4,5,6])
    >>> true
    Explanation: Every level before the last is full (ie. levels with node-values {1} and {2, 3}), and all nodes in the last level ({4, 5, 6}) are as far left as possible.
    
    Example 2:
    
    
    >>> __init__(root = [1,2,3,4,5,null,7])
    >>> false
    Explanation: The node with value 7 isn't as far left as possible.
    """
def regionsBySlashes(grid: List[str]) -> int:
    """
    An n x n grid is composed of 1 x 1 squares where each 1 x 1 square consists of a '/', '\', or blank space ' '. These characters divide the square into contiguous regions.
    Given the grid grid represented as a string array, return the number of regions.
    Note that backslash characters are escaped, so a '\' is represented as '\\'.
    
    Example 1:
    
    
    >>> regionsBySlashes(grid = [" /","/ "])
    >>> 2
    
    Example 2:
    
    
    >>> regionsBySlashes(grid = [" /","  "])
    >>> 1
    
    Example 3:
    
    
    >>> regionsBySlashes(grid = ["/\\","\\/"])
    >>> 5
    Explanation: Recall that because \ characters are escaped, "\\/" refers to \/, and "/\\" refers to /\.
    """
def minDeletionSize(strs: List[str]) -> int:
    """
    You are given an array of n strings strs, all of the same length.
    We may choose any deletion indices, and we delete all the characters in those indices for each string.
    For example, if we have strs = ["abcdef","uvwxyz"] and deletion indices {0, 2, 3}, then the final array after deletions is ["bef", "vyz"].
    Suppose we chose a set of deletion indices answer such that after deletions, the final array has every string (row) in lexicographic order. (i.e., (strs[0][0] <= strs[0][1] <= ... <= strs[0][strs[0].length - 1]), and (strs[1][0] <= strs[1][1] <= ... <= strs[1][strs[1].length - 1]), and so on). Return the minimum possible value of answer.length.
    
    Example 1:
    
    >>> minDeletionSize(strs = ["babca","bbazb"])
    >>> 3
    Explanation: After deleting columns 0, 1, and 4, the final array is strs = ["bc", "az"].
    Both these rows are individually in lexicographic order (ie. strs[0][0] <= strs[0][1] and strs[1][0] <= strs[1][1]).
    Note that strs[0] > strs[1] - the array strs is not necessarily in lexicographic order.
    Example 2:
    
    >>> minDeletionSize(strs = ["edcba"])
    >>> 4
    Explanation: If we delete less than 4 columns, the only row will not be lexicographically sorted.
    
    Example 3:
    
    >>> minDeletionSize(strs = ["ghi","def","abc"])
    >>> 0
    Explanation: All rows are already lexicographically sorted.
    """
def repeatedNTimes(nums: List[int]) -> int:
    """
    You are given an integer array nums with the following properties:
    
    nums.length == 2 * n.
    nums contains n + 1 unique elements.
    Exactly one element of nums is repeated n times.
    
    Return the element that is repeated n times.
    
    Example 1:
    >>> repeatedNTimes(nums = [1,2,3,3])
    >>> 3
    Example 2:
    >>> repeatedNTimes(nums = [2,1,2,5,3,2])
    >>> 2
    Example 3:
    >>> repeatedNTimes(nums = [5,1,5,2,5,3,5,4])
    >>> 5
    """
def maxWidthRamp(nums: List[int]) -> int:
    """
    A ramp in an integer array nums is a pair (i, j) for which i < j and nums[i] <= nums[j]. The width of such a ramp is j - i.
    Given an integer array nums, return the maximum width of a ramp in nums. If there is no ramp in nums, return 0.
    
    Example 1:
    
    >>> maxWidthRamp(nums = [6,0,8,2,1,5])
    >>> 4
    Explanation: The maximum width ramp is achieved at (i, j) = (1, 5): nums[1] = 0 and nums[5] = 5.
    
    Example 2:
    
    >>> maxWidthRamp(nums = [9,8,1,0,1,9,4,0,4,1])
    >>> 7
    Explanation: The maximum width ramp is achieved at (i, j) = (2, 9): nums[2] = 1 and nums[9] = 1.
    """
def minAreaFreeRect(points: List[List[int]]) -> float:
    """
    You are given an array of points in the X-Y plane points where points[i] = [xi, yi].
    Return the minimum area of any rectangle formed from these points, with sides not necessarily parallel to the X and Y axes. If there is not any such rectangle, return 0.
    Answers within 10-5 of the actual answer will be accepted.
    
    Example 1:
    
    
    >>> minAreaFreeRect(points = [[1,2],[2,1],[1,0],[0,1]])
    >>> 2.00000
    Explanation: The minimum area rectangle occurs at [1,2],[2,1],[1,0],[0,1], with an area of 2.
    
    Example 2:
    
    
    >>> minAreaFreeRect(points = [[0,1],[2,1],[1,1],[1,0],[2,0]])
    >>> 1.00000
    Explanation: The minimum area rectangle occurs at [1,0],[1,1],[2,1],[2,0], with an area of 1.
    
    Example 3:
    
    
    >>> minAreaFreeRect(points = [[0,3],[1,2],[3,1],[1,3],[2,1]])
    >>> 0
    Explanation: There is no possible rectangle to form from these points.
    """
def leastOpsExpressTarget(x: int, target: int) -> int:
    """
    Given a single positive integer x, we will write an expression of the form x (op1) x (op2) x (op3) x ... where each operator op1, op2, etc. is either addition, subtraction, multiplication, or division (+, -, *, or /). For example, with x = 3, we might write 3 * 3 / 3 + 3 - 3 which is a value of 3.
    When writing such an expression, we adhere to the following conventions:
    
    The division operator (/) returns rational numbers.
    There are no parentheses placed anywhere.
    We use the usual order of operations: multiplication and division happen before addition and subtraction.
    It is not allowed to use the unary negation operator (-). For example, "x - x" is a valid expression as it only uses subtraction, but "-x + x" is not because it uses negation.
    
    We would like to write an expression with the least number of operators such that the expression equals the given target. Return the least number of operators used.
    
    Example 1:
    
    >>> leastOpsExpressTarget(x = 3, target = 19)
    >>> 5
    Explanation: 3 * 3 + 3 * 3 + 3 / 3.
    The expression contains 5 operations.
    
    Example 2:
    
    >>> leastOpsExpressTarget(x = 5, target = 501)
    >>> 8
    Explanation: 5 * 5 * 5 * 5 - 5 * 5 * 5 + 5 / 5.
    The expression contains 8 operations.
    
    Example 3:
    
    >>> leastOpsExpressTarget(x = 100, target = 100000000)
    >>> 3
    Explanation: 100 * 100 * 100 * 100.
    The expression contains 3 operations.
    """
# class TreeNode:
#     def __init__(val=0, left=None, right=None):
#         self.val = val
#         self.left = left
#         self.right = right
class Solution:
    def isUnivalTree(root: Optional[TreeNode]) -> bool:
    """
    A binary tree is uni-valued if every node in the tree has the same value.
    Given the root of a binary tree, return true if the given tree is uni-valued, or false otherwise.
    
    Example 1:
    
    
    >>> __init__(root = [1,1,1,1,1,null,1])
    >>> true
    
    Example 2:
    
    
    >>> __init__(root = [2,2,2,5,2])
    >>> false
    """
def spellchecker(wordlist: List[str], queries: List[str]) -> List[str]:
    """
    Given a wordlist, we want to implement a spellchecker that converts a query word into a correct word.
    For a given query word, the spell checker handles two categories of spelling mistakes:
    
    Capitalization: If the query matches a word in the wordlist (case-insensitive), then the query word is returned with the same case as the case in the wordlist.
    
    
    Example: wordlist = ["yellow"], query = "YellOw": correct = "yellow"
    Example: wordlist = ["Yellow"], query = "yellow": correct = "Yellow"
    Example: wordlist = ["yellow"], query = "yellow": correct = "yellow"
    
    
    Vowel Errors: If after replacing the vowels ('a', 'e', 'i', 'o', 'u') of the query word with any vowel individually, it matches a word in the wordlist (case-insensitive), then the query word is returned with the same case as the match in the wordlist.
    
    Example: wordlist = ["YellOw"], query = "yollow": correct = "YellOw"
    Example: wordlist = ["YellOw"], query = "yeellow": correct = "" (no match)
    Example: wordlist = ["YellOw"], query = "yllw": correct = "" (no match)
    
    
    
    In addition, the spell checker operates under the following precedence rules:
    
    When the query exactly matches a word in the wordlist (case-sensitive), you should return the same word back.
    When the query matches a word up to capitlization, you should return the first such match in the wordlist.
    When the query matches a word up to vowel errors, you should return the first such match in the wordlist.
    If the query has no matches in the wordlist, you should return the empty string.
    
    Given some queries, return a list of words answer, where answer[i] is the correct word for query = queries[i].
    
    Example 1:
    >>> spellchecker(wordlist = ["KiTe","kite","hare","Hare"], queries = ["kite","Kite","KiTe","Hare","HARE","Hear","hear","keti","keet","keto"])
    >>> ["kite","KiTe","KiTe","Hare","hare","","","KiTe","","KiTe"]
    Example 2:
    >>> spellchecker(wordlist = ["yellow"], queries = ["YellOw"])
    >>> ["yellow"]
    """
def numsSameConsecDiff(n: int, k: int) -> List[int]:
    """
    Given two integers n and k, return an array of all the integers of length n where the difference between every two consecutive digits is k. You may return the answer in any order.
    Note that the integers should not have leading zeros. Integers as 02 and 043 are not allowed.
    
    Example 1:
    
    >>> numsSameConsecDiff(n = 3, k = 7)
    >>> [181,292,707,818,929]
    Explanation: Note that 070 is not a valid number, because it has leading zeroes.
    
    Example 2:
    
    >>> numsSameConsecDiff(n = 2, k = 1)
    >>> [10,12,21,23,32,34,43,45,54,56,65,67,76,78,87,89,98]
    """
# class TreeNode:
#     def __init__(val=0, left=None, right=None):
#         self.val = val
#         self.left = left
#         self.right = right
class Solution:
    def minCameraCover(root: Optional[TreeNode]) -> int:
    """
    You are given the root of a binary tree. We install cameras on the tree nodes where each camera at a node can monitor its parent, itself, and its immediate children.
    Return the minimum number of cameras needed to monitor all nodes of the tree.
    
    Example 1:
    
    
    >>> __init__(root = [0,0,null,0,0])
    >>> 1
    Explanation: One camera is enough to monitor all nodes if placed as shown.
    
    Example 2:
    
    
    >>> __init__(root = [0,0,null,0,null,0,null,null,0])
    >>> 2
    Explanation: At least two cameras are needed to monitor all nodes of the tree. The above image shows one of the valid configurations of camera placement.
    """
def pancakeSort(arr: List[int]) -> List[int]:
    """
    Given an array of integers arr, sort the array by performing a series of pancake flips.
    In one pancake flip we do the following steps:
    
    Choose an integer k where 1 <= k <= arr.length.
    Reverse the sub-array arr[0...k-1] (0-indexed).
    
    For example, if arr = [3,2,1,4] and we performed a pancake flip choosing k = 3, we reverse the sub-array [3,2,1], so arr = [1,2,3,4] after the pancake flip at k = 3.
    Return an array of the k-values corresponding to a sequence of pancake flips that sort arr. Any valid answer that sorts the array within 10 * arr.length flips will be judged as correct.
    
    Example 1:
    
    >>> pancakeSort(arr = [3,2,4,1])
    >>> [4,2,4,3]
    Explanation:
    We perform 4 pancake flips, with k values 4, 2, 4, and 3.
    Starting state: arr = [3, 2, 4, 1]
    After 1st flip (k = 4): arr = [1, 4, 2, 3]
    After 2nd flip (k = 2): arr = [4, 1, 2, 3]
    After 3rd flip (k = 4): arr = [3, 2, 1, 4]
    After 4th flip (k = 3): arr = [1, 2, 3, 4], which is sorted.
    
    Example 2:
    
    >>> pancakeSort(arr = [1,2,3])
    >>> []
    Explanation: The input is already sorted, so there is no need to flip anything.
    Note that other answers, such as [3, 3], would also be accepted.
    """
def powerfulIntegers(x: int, y: int, bound: int) -> List[int]:
    """
    Given three integers x, y, and bound, return a list of all the powerful integers that have a value less than or equal to bound.
    An integer is powerful if it can be represented as xi + yj for some integers i >= 0 and j >= 0.
    You may return the answer in any order. In your answer, each value should occur at most once.
    
    Example 1:
    
    >>> powerfulIntegers(x = 2, y = 3, bound = 10)
    >>> [2,3,4,5,7,9,10]
    Explanation:
    2 = 20 + 30
    3 = 21 + 30
    4 = 20 + 31
    5 = 21 + 31
    7 = 22 + 31
    9 = 23 + 30
    10 = 20 + 32
    
    Example 2:
    
    >>> powerfulIntegers(x = 3, y = 5, bound = 15)
    >>> [2,4,6,8,10,14]
    """
# class TreeNode:
#     def __init__(val=0, left=None, right=None):
#         self.val = val
#         self.left = left
#         self.right = right
class Solution:
    def flipMatchVoyage(root: Optional[TreeNode], voyage: List[int]) -> List[int]:
    """
    You are given the root of a binary tree with n nodes, where each node is uniquely assigned a value from 1 to n. You are also given a sequence of n values voyage, which is the desired pre-order traversal of the binary tree.
    Any node in the binary tree can be flipped by swapping its left and right subtrees. For example, flipping node 1 will have the following effect:
    
    Flip the smallest number of nodes so that the pre-order traversal of the tree matches voyage.
    Return a list of the values of all flipped nodes. You may return the answer in any order. If it is impossible to flip the nodes in the tree to make the pre-order traversal match voyage, return the list [-1].
    
    Example 1:
    
    
    >>> __init__(root = [1,2], voyage = [2,1])
    >>> [-1]
    Explanation: It is impossible to flip the nodes such that the pre-order traversal matches voyage.
    
    Example 2:
    
    
    >>> __init__(root = [1,2,3], voyage = [1,3,2])
    >>> [1]
    Explanation: Flipping node 1 swaps nodes 2 and 3, so the pre-order traversal matches voyage.
    Example 3:
    
    
    >>> __init__(root = [1,2,3], voyage = [1,2,3])
    >>> []
    Explanation: The tree's pre-order traversal already matches voyage, so no nodes need to be flipped.
    """
def isRationalEqual(s: str, t: str) -> bool:
    """
    Given two strings s and t, each of which represents a non-negative rational number, return true if and only if they represent the same number. The strings may use parentheses to denote the repeating part of the rational number.
    A rational number can be represented using up to three parts: , , and a . The number will be represented in one of the following three ways:
    
    
    
    For example, 12, 0, and 123.
    
    
    <.>
    
    For example, 0.5, 1., 2.12, and 123.0001.
    
    
    <.><(><)>
    
    For example, 0.1(6), 1.(9), 123.00(1212).
    
    
    
    The repeating portion of a decimal expansion is conventionally denoted within a pair of round brackets. For example:
    
    1/6 = 0.16666666... = 0.1(6) = 0.1666(6) = 0.166(66).
    
    
    Example 1:
    
    >>> isRationalEqual(s = "0.(52)", t = "0.5(25)")
    >>> true
    Explanation: Because "0.(52)" represents 0.52525252..., and "0.5(25)" represents 0.52525252525..... , the strings represent the same number.
    
    Example 2:
    
    >>> isRationalEqual(s = "0.1666(6)", t = "0.166(66)")
    >>> true
    
    Example 3:
    
    >>> isRationalEqual(s = "0.9(9)", t = "1.")
    >>> true
    Explanation: "0.9(9)" represents 0.999999999... repeated forever, which equals 1.  [See this link for an explanation.]
    "1." represents the number 1, which is formed correctly: (IntegerPart) = "1" and (NonRepeatingPart) = "".
    """
def kClosest(points: List[List[int]], k: int) -> List[List[int]]:
    """
    Given an array of points where points[i] = [xi, yi] represents a point on the X-Y plane and an integer k, return the k closest points to the origin (0, 0).
    The distance between two points on the X-Y plane is the Euclidean distance (i.e., √(x1 - x2)2 + (y1 - y2)2).
    You may return the answer in any order. The answer is guaranteed to be unique (except for the order that it is in).
    
    Example 1:
    
    
    >>> kClosest(points = [[1,3],[-2,2]], k = 1)
    >>> [[-2,2]]
    Explanation:
    The distance between (1, 3) and the origin is sqrt(10).
    The distance between (-2, 2) and the origin is sqrt(8).
    Since sqrt(8) < sqrt(10), (-2, 2) is closer to the origin.
    We only want the closest k = 1 points from the origin, so the answer is just [[-2,2]].
    
    Example 2:
    
    >>> kClosest(points = [[3,3],[5,-1],[-2,4]], k = 2)
    >>> [[3,3],[-2,4]]
    Explanation: The answer [[-2,4],[3,3]] would also be accepted.
    """
def subarraysDivByK(nums: List[int], k: int) -> int:
    """
    Given an integer array nums and an integer k, return the number of non-empty subarrays that have a sum divisible by k.
    A subarray is a contiguous part of an array.
    
    Example 1:
    
    >>> subarraysDivByK(nums = [4,5,0,-2,-3,1], k = 5)
    >>> 7
    Explanation: There are 7 subarrays with a sum divisible by k = 5:
    [4, 5, 0, -2, -3, 1], [5], [5, 0], [5, 0, -2, -3], [0], [0, -2, -3], [-2, -3]
    
    Example 2:
    
    >>> subarraysDivByK(nums = [5], k = 9)
    >>> 0
    """
def largestPerimeter(nums: List[int]) -> int:
    """
    Given an integer array nums, return the largest perimeter of a triangle with a non-zero area, formed from three of these lengths. If it is impossible to form any triangle of a non-zero area, return 0.
    
    Example 1:
    
    >>> largestPerimeter(nums = [2,1,2])
    >>> 5
    Explanation: You can form a triangle with three side lengths: 1, 2, and 2.
    
    Example 2:
    
    >>> largestPerimeter(nums = [1,2,1,10])
    >>> 0
    Explanation:
    You cannot use the side lengths 1, 1, and 2 to form a triangle.
    You cannot use the side lengths 1, 1, and 10 to form a triangle.
    You cannot use the side lengths 1, 2, and 10 to form a triangle.
    As we cannot use any three side lengths to form a triangle of non-zero area, we return 0.
    """
def sortedSquares(nums: List[int]) -> List[int]:
    """
    Given an integer array nums sorted in non-decreasing order, return an array of the squares of each number sorted in non-decreasing order.
    
    Example 1:
    
    >>> sortedSquares(nums = [-4,-1,0,3,10])
    >>> [0,1,9,16,100]
    Explanation: After squaring, the array becomes [16,1,0,9,100].
    After sorting, it becomes [0,1,9,16,100].
    
    Example 2:
    
    >>> sortedSquares(nums = [-7,-3,2,3,11])
    >>> [4,9,9,49,121]
    """
def maxTurbulenceSize(arr: List[int]) -> int:
    """
    Given an integer array arr, return the length of a maximum size turbulent subarray of arr.
    A subarray is turbulent if the comparison sign flips between each adjacent pair of elements in the subarray.
    More formally, a subarray [arr[i], arr[i + 1], ..., arr[j]] of arr is said to be turbulent if and only if:
    
    For i <= k < j:
    
    
    arr[k] > arr[k + 1] when k is odd, and
    arr[k] < arr[k + 1] when k is even.
    
    
    Or, for i <= k < j:
    
    arr[k] > arr[k + 1] when k is even, and
    arr[k] < arr[k + 1] when k is odd.
    
    
    
    
    Example 1:
    
    >>> maxTurbulenceSize(arr = [9,4,2,10,7,8,8,1,9])
    >>> 5
    Explanation: arr[1] > arr[2] < arr[3] > arr[4] < arr[5]
    
    Example 2:
    
    >>> maxTurbulenceSize(arr = [4,8,12,16])
    >>> 2
    
    Example 3:
    
    >>> maxTurbulenceSize(arr = [100])
    >>> 1
    """