ShwStone/humaneval-leetcode huggingface dataset:
def maxNumber(nums1: List[int], nums2: List[int], k: int) -> List[int]:
    """
    You are given two integer arrays nums1 and nums2 of lengths m and n respectively. nums1 and nums2 represent the digits of two numbers. You are also given an integer k.
    Create the maximum number of length k <= m + n from digits of the two numbers. The relative order of the digits from the same array must be preserved.
    Return an array of the k digits representing the answer.
    
    Example 1:
    
    >>> maxNumber(nums1 = [3,4,6,5], nums2 = [9,1,2,5,8,3], k = 5)
    >>> [9,8,6,5,3]
    
    Example 2:
    
    >>> maxNumber(nums1 = [6,7], nums2 = [6,0,4], k = 5)
    >>> [6,7,6,0,4]
    
    Example 3:
    
    >>> maxNumber(nums1 = [3,9], nums2 = [8,9], k = 3)
    >>> [9,8,9]
    """
def coinChange(coins: List[int], amount: int) -> int:
    """
    You are given an integer array coins representing coins of different denominations and an integer amount representing a total amount of money.
    Return the fewest number of coins that you need to make up that amount. If that amount of money cannot be made up by any combination of the coins, return -1.
    You may assume that you have an infinite number of each kind of coin.
    
    Example 1:
    
    >>> coinChange(coins = [1,2,5], amount = 11)
    >>> 3
    Explanation: 11 = 5 + 5 + 1
    
    Example 2:
    
    >>> coinChange(coins = [2], amount = 3)
    >>> -1
    
    Example 3:
    
    >>> coinChange(coins = [1], amount = 0)
    >>> 0
    """
def countComponents(n: int, edges: List[List[int]]) -> int:
    """
    You have a graph of n nodes. You are given an integer n and an array edges where edges[i] = [ai, bi] indicates that there is an edge between ai and bi in the graph.
    Return the number of connected components in the graph.
    
    Example 1:
    
    
    >>> countComponents(n = 5, edges = [[0,1],[1,2],[3,4]])
    >>> 2
    
    Example 2:
    
    
    >>> countComponents(n = 5, edges = [[0,1],[1,2],[2,3],[3,4]])
    >>> 1
    """
def wiggleSort(nums: List[int]) -> None:
        """
        Do not return anything, modify nums in-place instead.
        """
    """
    Given an integer array nums, reorder it such that nums[0] < nums[1] > nums[2] < nums[3]....
    You may assume the input array always has a valid answer.
    
    Example 1:
    
    >>> wiggleSort(nums = [1,5,1,1,6,4])
    >>> [1,6,1,5,1,4]
    Explanation: [1,4,1,5,1,6] is also accepted.
    
    Example 2:
    
    >>> wiggleSort(nums = [1,3,2,2,3,1])
    >>> [2,3,1,3,1,2]
    """
def maxSubArrayLen(nums: List[int], k: int) -> int:
    """
    Given an integer array nums and an integer k, return the maximum length of a subarray that sums to k. If there is not one, return 0 instead.
    
    Example 1:
    
    >>> maxSubArrayLen(nums = [1,-1,5,-2,3], k = 3)
    >>> 4
    Explanation: The subarray [1, -1, 5, -2] sums to 3 and is the longest.
    
    Example 2:
    
    >>> maxSubArrayLen(nums = [-2,-1,2,1], k = 1)
    >>> 2
    Explanation: The subarray [-1, 2] sums to 1 and is the longest.
    """
def isPowerOfThree(n: int) -> bool:
    """
    Given an integer n, return true if it is a power of three. Otherwise, return false.
    An integer n is a power of three, if there exists an integer x such that n == 3x.
    
    Example 1:
    
    >>> isPowerOfThree(n = 27)
    >>> true
    Explanation: 27 = 33
    
    Example 2:
    
    >>> isPowerOfThree(n = 0)
    >>> false
    Explanation: There is no x where 3x = 0.
    
    Example 3:
    
    >>> isPowerOfThree(n = -1)
    >>> false
    Explanation: There is no x where 3x = (-1).
    """
def countRangeSum(nums: List[int], lower: int, upper: int) -> int:
    """
    Given an integer array nums and two integers lower and upper, return the number of range sums that lie in [lower, upper] inclusive.
    Range sum S(i, j) is defined as the sum of the elements in nums between indices i and j inclusive, where i <= j.
    
    Example 1:
    
    >>> countRangeSum(nums = [-2,5,-1], lower = -2, upper = 2)
    >>> 3
    Explanation: The three ranges are: [0,0], [2,2], and [0,2] and their respective sums are: -2, -1, 2.
    
    Example 2:
    
    >>> countRangeSum(nums = [0], lower = 0, upper = 0)
    >>> 1
    """
# class ListNode:
#     def __init__(val=0, next=None):
#         self.val = val
#         self.next = next
class Solution:
    def oddEvenList(head: Optional[ListNode]) -> Optional[ListNode]:
    """
    Given the head of a singly linked list, group all the nodes with odd indices together followed by the nodes with even indices, and return the reordered list.
    The first node is considered odd, and the second node is even, and so on.
    Note that the relative order inside both the even and odd groups should remain as it was in the input.
    You must solve the problem in O(1) extra space complexity and O(n) time complexity.
    
    Example 1:
    
    
    >>> __init__(head = [1,2,3,4,5])
    >>> [1,3,5,2,4]
    
    Example 2:
    
    
    >>> __init__(head = [2,1,3,5,6,4,7])
    >>> [2,3,6,7,1,5,4]
    """
def longestIncreasingPath(matrix: List[List[int]]) -> int:
    """
    Given an m x n integers matrix, return the length of the longest increasing path in matrix.
    From each cell, you can either move in four directions: left, right, up, or down. You may not move diagonally or move outside the boundary (i.e., wrap-around is not allowed).
    
    Example 1:
    
    
    >>> longestIncreasingPath(matrix = [[9,9,4],[6,6,8],[2,1,1]])
    >>> 4
    Explanation: The longest increasing path is [1, 2, 6, 9].
    
    Example 2:
    
    
    >>> longestIncreasingPath(matrix = [[3,4,5],[3,2,6],[2,2,1]])
    >>> 4
    Explanation: The longest increasing path is [3, 4, 5, 6]. Moving diagonally is not allowed.
    
    Example 3:
    
    >>> longestIncreasingPath(matrix = [[1]])
    >>> 1
    """
def minPatches(nums: List[int], n: int) -> int:
    """
    Given a sorted integer array nums and an integer n, add/patch elements to the array such that any number in the range [1, n] inclusive can be formed by the sum of some elements in the array.
    Return the minimum number of patches required.
    
    Example 1:
    
    >>> minPatches(nums = [1,3], n = 6)
    >>> 1
    Explanation:
    Combinations of nums are [1], [3], [1,3], which form possible sums of: 1, 3, 4.
    Now if we add/patch 2 to nums, the combinations are: [1], [2], [3], [1,3], [2,3], [1,2,3].
    Possible sums are 1, 2, 3, 4, 5, 6, which now covers the range [1, 6].
    So we only need 1 patch.
    
    Example 2:
    
    >>> minPatches(nums = [1,5,10], n = 20)
    >>> 2
    Explanation: The two patches can be [2, 4].
    
    Example 3:
    
    >>> minPatches(nums = [1,2,2], n = 5)
    >>> 0
    """
def isValidSerialization(preorder: str) -> bool:
    """
    One way to serialize a binary tree is to use preorder traversal. When we encounter a non-null node, we record the node's value. If it is a null node, we record using a sentinel value such as '#'.
    
    For example, the above binary tree can be serialized to the string "9,3,4,#,#,1,#,#,2,#,6,#,#", where '#' represents a null node.
    Given a string of comma-separated values preorder, return true if it is a correct preorder traversal serialization of a binary tree.
    It is guaranteed that each comma-separated value in the string must be either an integer or a character '#' representing null pointer.
    You may assume that the input format is always valid.
    
    For example, it could never contain two consecutive commas, such as "1,,3".
    
    Note: You are not allowed to reconstruct the tree.
    
    Example 1:
    >>> isValidSerialization(preorder = "9,3,4,#,#,1,#,#,2,#,6,#,#")
    >>> true
    Example 2:
    >>> isValidSerialization(preorder = "1,#")
    >>> false
    Example 3:
    >>> isValidSerialization(preorder = "9,#,#,1")
    >>> false
    """
def findItinerary(tickets: List[List[str]]) -> List[str]:
    """
    You are given a list of airline tickets where tickets[i] = [fromi, toi] represent the departure and the arrival airports of one flight. Reconstruct the itinerary in order and return it.
    All of the tickets belong to a man who departs from "JFK", thus, the itinerary must begin with "JFK". If there are multiple valid itineraries, you should return the itinerary that has the smallest lexical order when read as a single string.
    
    For example, the itinerary ["JFK", "LGA"] has a smaller lexical order than ["JFK", "LGB"].
    
    You may assume all tickets form at least one valid itinerary. You must use all the tickets once and only once.
    
    Example 1:
    
    
    >>> findItinerary(tickets = [["MUC","LHR"],["JFK","MUC"],["SFO","SJC"],["LHR","SFO"]])
    >>> ["JFK","MUC","LHR","SFO","SJC"]
    
    Example 2:
    
    
    >>> findItinerary(tickets = [["JFK","SFO"],["JFK","ATL"],["SFO","ATL"],["ATL","JFK"],["ATL","SFO"]])
    >>> ["JFK","ATL","JFK","SFO","ATL","SFO"]
    Explanation: Another possible reconstruction is ["JFK","SFO","ATL","JFK","ATL","SFO"] but it is larger in lexical order.
    """
# class TreeNode:
#     def __init__(val=0, left=None, right=None):
#         self.val = val
#         self.left = left
#         self.right = right
class Solution:
    def largestBSTSubtree(root: Optional[TreeNode]) -> int:
    """
    Given the root of a binary tree, find the largest subtree, which is also a Binary Search Tree (BST), where the largest means subtree has the largest number of nodes.
    A Binary Search Tree (BST) is a tree in which all the nodes follow the below-mentioned properties:
    
    The left subtree values are less than the value of their parent (root) node's value.
    The right subtree values are greater than the value of their parent (root) node's value.
    
    Note: A subtree must include all of its descendants.
    
    Example 1:
    
    
    >>> __init__(root = [10,5,15,1,8,null,7])
    >>> 3
    Explanation: The Largest BST Subtree in this case is the highlighted one. The return value is the subtree's size, which is 3.
    Example 2:
    
    >>> __init__(root = [4,2,7,2,3,5,null,2,null,null,null,null,null,1])
    >>> 2
    """
def increasingTriplet(nums: List[int]) -> bool:
    """
    Given an integer array nums, return true if there exists a triple of indices (i, j, k) such that i < j < k and nums[i] < nums[j] < nums[k]. If no such indices exists, return false.
    
    Example 1:
    
    >>> increasingTriplet(nums = [1,2,3,4,5])
    >>> true
    Explanation: Any triplet where i < j < k is valid.
    
    Example 2:
    
    >>> increasingTriplet(nums = [5,4,3,2,1])
    >>> false
    Explanation: No triplet exists.
    
    Example 3:
    
    >>> increasingTriplet(nums = [2,1,5,0,4,6])
    >>> true
    Explanation: The triplet (3, 4, 5) is valid because nums[3] == 0 < nums[4] == 4 < nums[5] == 6.
    """
def isSelfCrossing(distance: List[int]) -> bool:
    """
    You are given an array of integers distance.
    You start at the point (0, 0) on an X-Y plane, and you move distance[0] meters to the north, then distance[1] meters to the west, distance[2] meters to the south, distance[3] meters to the east, and so on. In other words, after each move, your direction changes counter-clockwise.
    Return true if your path crosses itself or false if it does not.
    
    Example 1:
    
    
    >>> isSelfCrossing(distance = [2,1,1,2])
    >>> true
    Explanation: The path crosses itself at the point (0, 1).
    
    Example 2:
    
    
    >>> isSelfCrossing(distance = [1,2,3,4])
    >>> false
    Explanation: The path does not cross itself at any point.
    
    Example 3:
    
    
    >>> isSelfCrossing(distance = [1,1,1,2,1])
    >>> true
    Explanation: The path crosses itself at the point (0, 0).
    """
def palindromePairs(words: List[str]) -> List[List[int]]:
    """
    You are given a 0-indexed array of unique strings words.
    A palindrome pair is a pair of integers (i, j) such that:
    
    0 <= i, j < words.length,
    i != j, and
    words[i] + words[j] (the concatenation of the two strings) is a palindrome.
    
    Return an array of all the palindrome pairs of words.
    You must write an algorithm with O(sum of words[i].length) runtime complexity.
    
    Example 1:
    
    >>> palindromePairs(words = ["abcd","dcba","lls","s","sssll"])
    >>> [[0,1],[1,0],[3,2],[2,4]]
    Explanation: The palindromes are ["abcddcba","dcbaabcd","slls","llssssll"]
    
    Example 2:
    
    >>> palindromePairs(words = ["bat","tab","cat"])
    >>> [[0,1],[1,0]]
    Explanation: The palindromes are ["battab","tabbat"]
    
    Example 3:
    
    >>> palindromePairs(words = ["a",""])
    >>> [[0,1],[1,0]]
    Explanation: The palindromes are ["a","a"]
    """
# class TreeNode:
#     def __init__(val=0, left=None, right=None):
#         self.val = val
#         self.left = left
#         self.right = right
class Solution:
    def rob(root: Optional[TreeNode]) -> int:
    """
    The thief has found himself a new place for his thievery again. There is only one entrance to this area, called root.
    Besides the root, each house has one and only one parent house. After a tour, the smart thief realized that all houses in this place form a binary tree. It will automatically contact the police if two directly-linked houses were broken into on the same night.
    Given the root of the binary tree, return the maximum amount of money the thief can rob without alerting the police.
    
    Example 1:
    
    
    >>> __init__(root = [3,2,3,null,3,null,1])
    >>> 7
    Explanation: Maximum amount of money the thief can rob = 3 + 3 + 1 = 7.
    
    Example 2:
    
    
    >>> __init__(root = [3,4,5,1,3,null,1])
    >>> 9
    Explanation: Maximum amount of money the thief can rob = 4 + 5 = 9.
    """
def countBits(n: int) -> List[int]:
    """
    Given an integer n, return an array ans of length n + 1 such that for each i (0 <= i <= n), ans[i] is the number of 1's in the binary representation of i.
    
    Example 1:
    
    >>> countBits(n = 2)
    >>> [0,1,1]
    Explanation:
    0 --> 0
    1 --> 1
    2 --> 10
    
    Example 2:
    
    >>> countBits(n = 5)
    >>> [0,1,1,2,1,2]
    Explanation:
    0 --> 0
    1 --> 1
    2 --> 10
    3 --> 11
    4 --> 100
    5 --> 101
    """
def lengthOfLongestSubstringKDistinct(s: str, k: int) -> int:
    """
    Given a string s and an integer k, return the length of the longest substring of s that contains at most k distinct characters.
    
    Example 1:
    
    >>> lengthOfLongestSubstringKDistinct(s = "eceba", k = 2)
    >>> 3
    Explanation: The substring is "ece" with length 3.
    Example 2:
    
    >>> lengthOfLongestSubstringKDistinct(s = "aa", k = 1)
    >>> 2
    Explanation: The substring is "aa" with length 2.
    """
def isPowerOfFour(n: int) -> bool:
    """
    Given an integer n, return true if it is a power of four. Otherwise, return false.
    An integer n is a power of four, if there exists an integer x such that n == 4x.
    
    Example 1:
    >>> isPowerOfFour(n = 16)
    >>> true
    Example 2:
    >>> isPowerOfFour(n = 5)
    >>> false
    Example 3:
    >>> isPowerOfFour(n = 1)
    >>> true
    """
def integerBreak(n: int) -> int:
    """
    Given an integer n, break it into the sum of k positive integers, where k >= 2, and maximize the product of those integers.
    Return the maximum product you can get.
    
    Example 1:
    
    >>> integerBreak(n = 2)
    >>> 1
    Explanation: 2 = 1 + 1, 1 × 1 = 1.
    
    Example 2:
    
    >>> integerBreak(n = 10)
    >>> 36
    Explanation: 10 = 3 + 3 + 4, 3 × 3 × 4 = 36.
    """
def reverseString(s: List[str]) -> None:
        """
        Do not return anything, modify s in-place instead.
        """
    """
    Write a function that reverses a string. The input string is given as an array of characters s.
    You must do this by modifying the input array in-place with O(1) extra memory.
    
    Example 1:
    >>> reverseString(s = ["h","e","l","l","o"])
    >>> ["o","l","l","e","h"]
    Example 2:
    >>> reverseString(s = ["H","a","n","n","a","h"])
    >>> ["h","a","n","n","a","H"]
    """
def reverseVowels(s: str) -> str:
    """
    Given a string s, reverse only all the vowels in the string and return it.
    The vowels are 'a', 'e', 'i', 'o', and 'u', and they can appear in both lower and upper cases, more than once.
    
    Example 1:
    
    >>> reverseVowels(s = "IceCreAm")
    >>> "AceCreIm"
    Explanation:
    The vowels in s are ['I', 'e', 'e', 'A']. On reversing the vowels, s becomes "AceCreIm".
    
    Example 2:
    
    >>> reverseVowels(s = "leetcode")
    >>> "leotcede"
    """
def topKFrequent(nums: List[int], k: int) -> List[int]:
    """
    Given an integer array nums and an integer k, return the k most frequent elements. You may return the answer in any order.
    
    Example 1:
    >>> topKFrequent(nums = [1,1,1,2,2,3], k = 2)
    >>> [1,2]
    Example 2:
    >>> topKFrequent(nums = [1], k = 1)
    >>> [1]
    """
def intersection(nums1: List[int], nums2: List[int]) -> List[int]:
    """
    Given two integer arrays nums1 and nums2, return an array of their intersection. Each element in the result must be unique and you may return the result in any order.
    
    Example 1:
    
    >>> intersection(nums1 = [1,2,2,1], nums2 = [2,2])
    >>> [2]
    
    Example 2:
    
    >>> intersection(nums1 = [4,9,5], nums2 = [9,4,9,8,4])
    >>> [9,4]
    Explanation: [4,9] is also accepted.
    """
def intersect(nums1: List[int], nums2: List[int]) -> List[int]:
    """
    Given two integer arrays nums1 and nums2, return an array of their intersection. Each element in the result must appear as many times as it shows in both arrays and you may return the result in any order.
    
    Example 1:
    
    >>> intersect(nums1 = [1,2,2,1], nums2 = [2,2])
    >>> [2,2]
    
    Example 2:
    
    >>> intersect(nums1 = [4,9,5], nums2 = [9,4,9,8,4])
    >>> [4,9]
    Explanation: [9,4] is also accepted.
    """
def numberOfPatterns(m: int, n: int) -> int:
    """
    Android devices have a special lock screen with a 3 x 3 grid of dots. Users can set an "unlock pattern" by connecting the dots in a specific sequence, forming a series of joined line segments where each segment's endpoints are two consecutive dots in the sequence. A sequence of k dots is a valid unlock pattern if both of the following are true:
    
    All the dots in the sequence are distinct.
    If the line segment connecting two consecutive dots in the sequence passes through the center of any other dot, the other dot must have previously appeared in the sequence. No jumps through the center non-selected dots are allowed.
    
    For example, connecting dots 2 and 9 without dots 5 or 6 appearing beforehand is valid because the line from dot 2 to dot 9 does not pass through the center of either dot 5 or 6.
    However, connecting dots 1 and 3 without dot 2 appearing beforehand is invalid because the line from dot 1 to dot 3 passes through the center of dot 2.
    
    
    
    Here are some example valid and invalid unlock patterns:
    
    
    The 1st pattern [4,1,3,6] is invalid because the line connecting dots 1 and 3 pass through dot 2, but dot 2 did not previously appear in the sequence.
    The 2nd pattern [4,1,9,2] is invalid because the line connecting dots 1 and 9 pass through dot 5, but dot 5 did not previously appear in the sequence.
    The 3rd pattern [2,4,1,3,6] is valid because it follows the conditions. The line connecting dots 1 and 3 meets the condition because dot 2 previously appeared in the sequence.
    The 4th pattern [6,5,4,1,9,2] is valid because it follows the conditions. The line connecting dots 1 and 9 meets the condition because dot 5 previously appeared in the sequence.
    
    Given two integers m and n, return the number of unique and valid unlock patterns of the Android grid lock screen that consist of at least m keys and at most n keys.
    Two unlock patterns are considered unique if there is a dot in one sequence that is not in the other, or the order of the dots is different.
    
    Example 1:
    
    >>> numberOfPatterns(m = 1, n = 1)
    >>> 9
    
    Example 2:
    
    >>> numberOfPatterns(m = 1, n = 2)
    >>> 65
    """
def maxEnvelopes(envelopes: List[List[int]]) -> int:
    """
    You are given a 2D array of integers envelopes where envelopes[i] = [wi, hi] represents the width and the height of an envelope.
    One envelope can fit into another if and only if both the width and height of one envelope are greater than the other envelope's width and height.
    Return the maximum number of envelopes you can Russian doll (i.e., put one inside the other).
    Note: You cannot rotate an envelope.
    
    Example 1:
    
    >>> maxEnvelopes(envelopes = [[5,4],[6,4],[6,7],[2,3]])
    >>> 3
    Explanation: The maximum number of envelopes you can Russian doll is 3 ([2,3] => [5,4] => [6,7]).
    
    Example 2:
    
    >>> maxEnvelopes(envelopes = [[1,1],[1,1],[1,1]])
    >>> 1
    """
def isReflected(points: List[List[int]]) -> bool:
    """
    Given n points on a 2D plane, find if there is such a line parallel to the y-axis that reflects the given points symmetrically.
    In other words, answer whether or not if there exists a line that after reflecting all points over the given line, the original points' set is the same as the reflected ones.
    Note that there can be repeated points.
    
    Example 1:
    
    
    >>> isReflected(points = [[1,1],[-1,1]])
    >>> true
    Explanation: We can choose the line x = 0.
    
    Example 2:
    
    
    >>> isReflected(points = [[1,1],[-1,-1]])
    >>> false
    Explanation: We can't choose a line.
    """
def countNumbersWithUniqueDigits(n: int) -> int:
    """
    Given an integer n, return the count of all numbers with unique digits, x, where 0 <= x < 10n.
    
    Example 1:
    
    >>> countNumbersWithUniqueDigits(n = 2)
    >>> 91
    Explanation: The answer should be the total numbers in the range of 0 ≤ x < 100, excluding 11,22,33,44,55,66,77,88,99
    
    Example 2:
    
    >>> countNumbersWithUniqueDigits(n = 0)
    >>> 1
    """
def rearrangeString(s: str, k: int) -> str:
    """
    Given a string s and an integer k, rearrange s such that the same characters are at least distance k from each other. If it is not possible to rearrange the string, return an empty string "".
    
    Example 1:
    
    >>> rearrangeString(s = "aabbcc", k = 3)
    >>> "abcabc"
    Explanation: The same letters are at least a distance of 3 from each other.
    
    Example 2:
    
    >>> rearrangeString(s = "aaabc", k = 3)
    >>> ""
    Explanation: It is not possible to rearrange the string.
    
    Example 3:
    
    >>> rearrangeString(s = "aaadbbcc", k = 2)
    >>> "abacabcd"
    Explanation: The same letters are at least a distance of 2 from each other.
    """
def sortTransformedArray(nums: List[int], a: int, b: int, c: int) -> List[int]:
    """
    Given a sorted integer array nums and three integers a, b and c, apply a quadratic function of the form f(x) = ax2 + bx + c to each element nums[i] in the array, and return the array in a sorted order.
    
    Example 1:
    >>> sortTransformedArray(nums = [-4,-2,2,4], a = 1, b = 3, c = 5)
    >>> [3,9,15,33]
    Example 2:
    >>> sortTransformedArray(nums = [-4,-2,2,4], a = -1, b = 3, c = 5)
    >>> [-23,-5,1,7]
    """
def maxKilledEnemies(grid: List[List[str]]) -> int:
    """
    Given an m x n matrix grid where each cell is either a wall 'W', an enemy 'E' or empty '0', return the maximum enemies you can kill using one bomb. You can only place the bomb in an empty cell.
    The bomb kills all the enemies in the same row and column from the planted point until it hits the wall since it is too strong to be destroyed.
    
    Example 1:
    
    
    >>> maxKilledEnemies(grid = [["0","E","0","0"],["E","0","W","E"],["0","E","0","0"]])
    >>> 3
    
    Example 2:
    
    
    >>> maxKilledEnemies(grid = [["W","W","W"],["0","0","0"],["E","E","E"]])
    >>> 1
    """