ShwStone/humaneval-leetcode huggingface dataset:
def diffWaysToCompute(expression: str) -> List[int]:
    """
    Given a string expression of numbers and operators, return all possible results from computing all the different possible ways to group numbers and operators. You may return the answer in any order.
    The test cases are generated such that the output values fit in a 32-bit integer and the number of different results does not exceed 104.
    
    Example 1:
    
    >>> diffWaysToCompute(expression = "2-1-1")
    >>> [0,2]
    Explanation:
    ((2-1)-1) = 0
    (2-(1-1)) = 2
    
    Example 2:
    
    >>> diffWaysToCompute(expression = "2*3-4*5")
    >>> [-34,-14,-10,-10,10]
    Explanation:
    (2*(3-(4*5))) = -34
    ((2*3)-(4*5)) = -14
    ((2*(3-4))*5) = -10
    (2*((3-4)*5)) = -10
    (((2*3)-4)*5) = 10
    """
def isAnagram(s: str, t: str) -> bool:
    """
    Given two strings s and t, return true if t is an anagram of s, and false otherwise.
    
    Example 1:
    
    >>> isAnagram(s = "anagram", t = "nagaram")
    >>> true
    
    Example 2:
    
    >>> isAnagram(s = "rat", t = "car")
    >>> false
    """
def shortestDistance(wordsDict: List[str], word1: str, word2: str) -> int:
    """
    Given an array of strings wordsDict and two different strings that already exist in the array word1 and word2, return the shortest distance between these two words in the list.
    
    Example 1:
    
    >>> shortestDistance(wordsDict = ["practice", "makes", "perfect", "coding", "makes"], word1 = "coding", word2 = "practice")
    >>> 3
    
    Example 2:
    
    >>> shortestDistance(wordsDict = ["practice", "makes", "perfect", "coding", "makes"], word1 = "makes", word2 = "coding")
    >>> 1
    """
def shortestWordDistance(wordsDict: List[str], word1: str, word2: str) -> int:
    """
    Given an array of strings wordsDict and two strings that already exist in the array word1 and word2, return the shortest distance between the occurrence of these two words in the list.
    Note that word1 and word2 may be the same. It is guaranteed that they represent two individual words in the list.
    
    Example 1:
    >>> shortestWordDistance(wordsDict = ["practice", "makes", "perfect", "coding", "makes"], word1 = "makes", word2 = "coding")
    >>> 1
    Example 2:
    >>> shortestWordDistance(wordsDict = ["practice", "makes", "perfect", "coding", "makes"], word1 = "makes", word2 = "makes")
    >>> 3
    """
def isStrobogrammatic(num: str) -> bool:
    """
    Given a string num which represents an integer, return true if num is a strobogrammatic number.
    A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked at upside down).
    
    Example 1:
    
    >>> isStrobogrammatic(num = "69")
    >>> true
    
    Example 2:
    
    >>> isStrobogrammatic(num = "88")
    >>> true
    
    Example 3:
    
    >>> isStrobogrammatic(num = "962")
    >>> false
    """
def findStrobogrammatic(n: int) -> List[str]:
    """
    Given an integer n, return all the strobogrammatic numbers that are of length n. You may return the answer in any order.
    A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked at upside down).
    
    Example 1:
    >>> findStrobogrammatic(n = 2)
    >>> ["11","69","88","96"]
    Example 2:
    >>> findStrobogrammatic(n = 1)
    >>> ["0","1","8"]
    """
def strobogrammaticInRange(low: str, high: str) -> int:
    """
    Given two strings low and high that represent two integers low and high where low <= high, return the number of strobogrammatic numbers in the range [low, high].
    A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked at upside down).
    
    Example 1:
    >>> strobogrammaticInRange(low = "50", high = "100")
    >>> 3
    Example 2:
    >>> strobogrammaticInRange(low = "0", high = "0")
    >>> 1
    """
def groupStrings(strings: List[str]) -> List[List[str]]:
    """
    Perform the following shift operations on a string:
    
    Right shift: Replace every letter with the successive letter of the English alphabet, where 'z' is replaced by 'a'. For example, "abc" can be right-shifted to "bcd" or "xyz" can be right-shifted to "yza".
    Left shift: Replace every letter with the preceding letter of the English alphabet, where 'a' is replaced by 'z'. For example, "bcd" can be left-shifted to "abc" or "yza" can be left-shifted to "xyz".
    
    We can keep shifting the string in both directions to form an endless shifting sequence.
    
    For example, shift "abc" to form the sequence: ... <-> "abc" <-> "bcd" <-> ... <-> "xyz" <-> "yza" <-> .... <-> "zab" <-> "abc" <-> ...
    
    You are given an array of strings strings, group together all strings[i] that belong to the same shifting sequence. You may return the answer in any order.
    
    Example 1:
    
    >>> groupStrings(strings = ["abc","bcd","acef","xyz","az","ba","a","z"])
    >>> [["acef"],["a","z"],["abc","bcd","xyz"],["az","ba"]]
    
    Example 2:
    
    >>> groupStrings(strings = ["a"])
    >>> [["a"]]
    """
# class TreeNode:
#     def __init__(val=0, left=None, right=None):
#         self.val = val
#         self.left = left
#         self.right = right
class Solution:
    def countUnivalSubtrees(root: Optional[TreeNode]) -> int:
    """
    Given the root of a binary tree, return the number of uni-value subtrees.
    A uni-value subtree means all nodes of the subtree have the same value.
    
    Example 1:
    
    
    >>> __init__(root = [5,1,5,5,5,null,5])
    >>> 4
    
    Example 2:
    
    >>> __init__(root = [])
    >>> 0
    
    Example 3:
    
    >>> __init__(root = [5,5,5,5,5,null,5])
    >>> 6
    """
def canAttendMeetings(intervals: List[List[int]]) -> bool:
    """
    Given an array of meeting time intervals where intervals[i] = [starti, endi], determine if a person could attend all meetings.
    
    Example 1:
    >>> canAttendMeetings(intervals = [[0,30],[5,10],[15,20]])
    >>> false
    Example 2:
    >>> canAttendMeetings(intervals = [[7,10],[2,4]])
    >>> true
    """
def minMeetingRooms(intervals: List[List[int]]) -> int:
    """
    Given an array of meeting time intervals intervals where intervals[i] = [starti, endi], return the minimum number of conference rooms required.
    
    Example 1:
    >>> minMeetingRooms(intervals = [[0,30],[5,10],[15,20]])
    >>> 2
    Example 2:
    >>> minMeetingRooms(intervals = [[7,10],[2,4]])
    >>> 1
    """
def getFactors(n: int) -> List[List[int]]:
    """
    Numbers can be regarded as the product of their factors.
    
    For example, 8 = 2 x 2 x 2 = 2 x 4.
    
    Given an integer n, return all possible combinations of its factors. You may return the answer in any order.
    Note that the factors should be in the range [2, n - 1].
    
    Example 1:
    
    >>> getFactors(n = 1)
    >>> []
    
    Example 2:
    
    >>> getFactors(n = 12)
    >>> [[2,6],[3,4],[2,2,3]]
    
    Example 3:
    
    >>> getFactors(n = 37)
    >>> []
    """
def verifyPreorder(preorder: List[int]) -> bool:
    """
    Given an array of unique integers preorder, return true if it is the correct preorder traversal sequence of a binary search tree.
    
    Example 1:
    
    
    >>> verifyPreorder(preorder = [5,2,1,3,6])
    >>> true
    
    Example 2:
    
    >>> verifyPreorder(preorder = [5,2,6,1,3])
    >>> false
    """
def minCost(costs: List[List[int]]) -> int:
    """
    There is a row of n houses, where each house can be painted one of three colors: red, blue, or green. The cost of painting each house with a certain color is different. You have to paint all the houses such that no two adjacent houses have the same color.
    The cost of painting each house with a certain color is represented by an n x 3 cost matrix costs.
    
    For example, costs[0][0] is the cost of painting house 0 with the color red; costs[1][2] is the cost of painting house 1 with color green, and so on...
    
    Return the minimum cost to paint all houses.
    
    Example 1:
    
    >>> minCost(costs = [[17,2,17],[16,16,5],[14,3,19]])
    >>> 10
    Explanation: Paint house 0 into blue, paint house 1 into green, paint house 2 into blue.
    Minimum cost: 2 + 5 + 3 = 10.
    
    Example 2:
    
    >>> minCost(costs = [[7,6,2]])
    >>> 2
    """
# class TreeNode:
#     def __init__(val=0, left=None, right=None):
#         self.val = val
#         self.left = left
#         self.right = right
class Solution:
    def binaryTreePaths(root: Optional[TreeNode]) -> List[str]:
    """
    Given the root of a binary tree, return all root-to-leaf paths in any order.
    A leaf is a node with no children.
    
    Example 1:
    
    
    >>> __init__(root = [1,2,3,null,5])
    >>> ["1->2->5","1->3"]
    
    Example 2:
    
    >>> __init__(root = [1])
    >>> ["1"]
    """
def addDigits(num: int) -> int:
    """
    Given an integer num, repeatedly add all its digits until the result has only one digit, and return it.
    
    Example 1:
    
    >>> addDigits(num = 38)
    >>> 2
    Explanation: The process is
    38 --> 3 + 8 --> 11
    11 --> 1 + 1 --> 2
    Since 2 has only one digit, return it.
    
    Example 2:
    
    >>> addDigits(num = 0)
    >>> 0
    """
def threeSumSmaller(nums: List[int], target: int) -> int:
    """
    Given an array of n integers nums and an integer target, find the number of index triplets i, j, k with 0 <= i < j < k < n that satisfy the condition nums[i] + nums[j] + nums[k] < target.
    
    Example 1:
    
    >>> threeSumSmaller(nums = [-2,0,1,3], target = 2)
    >>> 2
    Explanation: Because there are two triplets which sums are less than 2:
    [-2,0,1]
    [-2,0,3]
    
    Example 2:
    
    >>> threeSumSmaller(nums = [], target = 0)
    >>> 0
    
    Example 3:
    
    >>> threeSumSmaller(nums = [0], target = 0)
    >>> 0
    """
def singleNumber(nums: List[int]) -> List[int]:
    """
    Given an integer array nums, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once. You can return the answer in any order.
    You must write an algorithm that runs in linear runtime complexity and uses only constant extra space.
    
    Example 1:
    
    >>> singleNumber(nums = [1,2,1,3,2,5])
    >>> [3,5]
    Explanation:  [5, 3] is also a valid answer.
    
    Example 2:
    
    >>> singleNumber(nums = [-1,0])
    >>> [-1,0]
    
    Example 3:
    
    >>> singleNumber(nums = [0,1])
    >>> [1,0]
    """
def validTree(n: int, edges: List[List[int]]) -> bool:
    """
    You have a graph of n nodes labeled from 0 to n - 1. You are given an integer n and a list of edges where edges[i] = [ai, bi] indicates that there is an undirected edge between nodes ai and bi in the graph.
    Return true if the edges of the given graph make up a valid tree, and false otherwise.
    
    Example 1:
    
    
    >>> validTree(n = 5, edges = [[0,1],[0,2],[0,3],[1,4]])
    >>> true
    
    Example 2:
    
    
    >>> validTree(n = 5, edges = [[0,1],[1,2],[2,3],[1,3],[1,4]])
    >>> false
    """
def isUgly(n: int) -> bool:
    """
    An ugly number is a positive integer which does not have a prime factor other than 2, 3, and 5.
    Given an integer n, return true if n is an ugly number.
    
    Example 1:
    
    >>> isUgly(n = 6)
    >>> true
    Explanation: 6 = 2 × 3
    
    Example 2:
    
    >>> isUgly(n = 1)
    >>> true
    Explanation: 1 has no prime factors.
    
    Example 3:
    
    >>> isUgly(n = 14)
    >>> false
    Explanation: 14 is not ugly since it includes the prime factor 7.
    """
def nthUglyNumber(n: int) -> int:
    """
    An ugly number is a positive integer whose prime factors are limited to 2, 3, and 5.
    Given an integer n, return the nth ugly number.
    
    Example 1:
    
    >>> nthUglyNumber(n = 10)
    >>> 12
    Explanation: [1, 2, 3, 4, 5, 6, 8, 9, 10, 12] is the sequence of the first 10 ugly numbers.
    
    Example 2:
    
    >>> nthUglyNumber(n = 1)
    >>> 1
    Explanation: 1 has no prime factors, therefore all of its prime factors are limited to 2, 3, and 5.
    """
def minCostII(costs: List[List[int]]) -> int:
    """
    There are a row of n houses, each house can be painted with one of the k colors. The cost of painting each house with a certain color is different. You have to paint all the houses such that no two adjacent houses have the same color.
    The cost of painting each house with a certain color is represented by an n x k cost matrix costs.
    
    For example, costs[0][0] is the cost of painting house 0 with color 0; costs[1][2] is the cost of painting house 1 with color 2, and so on...
    
    Return the minimum cost to paint all houses.
    
    Example 1:
    
    >>> minCostII(costs = [[1,5,3],[2,9,4]])
    >>> 5
    Explanation:
    Paint house 0 into color 0, paint house 1 into color 2. Minimum cost: 1 + 4 = 5;
    Or paint house 0 into color 2, paint house 1 into color 0. Minimum cost: 3 + 2 = 5.
    
    Example 2:
    
    >>> minCostII(costs = [[1,3],[2,4]])
    >>> 5
    """
def canPermutePalindrome(s: str) -> bool:
    """
    Given a string s, return true if a permutation of the string could form a palindrome and false otherwise.
    
    Example 1:
    
    >>> canPermutePalindrome(s = "code")
    >>> false
    
    Example 2:
    
    >>> canPermutePalindrome(s = "aab")
    >>> true
    
    Example 3:
    
    >>> canPermutePalindrome(s = "carerac")
    >>> true
    """
def generatePalindromes(s: str) -> List[str]:
    """
    Given a string s, return all the palindromic permutations (without duplicates) of it.
    You may return the answer in any order. If s has no palindromic permutation, return an empty list.
    
    Example 1:
    >>> generatePalindromes(s = "aabb")
    >>> ["abba","baab"]
    Example 2:
    >>> generatePalindromes(s = "abc")
    >>> []
    """
def missingNumber(nums: List[int]) -> int:
    """
    Given an array nums containing n distinct numbers in the range [0, n], return the only number in the range that is missing from the array.
    
    Example 1:
    
    >>> missingNumber(nums = [3,0,1])
    >>> 2
    Explanation:
    n = 3 since there are 3 numbers, so all numbers are in the range [0,3]. 2 is the missing number in the range since it does not appear in nums.
    
    Example 2:
    
    >>> missingNumber(nums = [0,1])
    >>> 2
    Explanation:
    n = 2 since there are 2 numbers, so all numbers are in the range [0,2]. 2 is the missing number in the range since it does not appear in nums.
    
    Example 3:
    
    >>> missingNumber(nums = [9,6,4,2,3,5,7,0,1])
    >>> 8
    Explanation:
    n = 9 since there are 9 numbers, so all numbers are in the range [0,9]. 8 is the missing number in the range since it does not appear in nums.
    """
def alienOrder(words: List[str]) -> str:
    """
    There is a new alien language that uses the English alphabet. However, the order of the letters is unknown to you.
    You are given a list of strings words from the alien language's dictionary. Now it is claimed that the strings in words are sorted lexicographically by the rules of this new language.
    If this claim is incorrect, and the given arrangement of string in words cannot correspond to any order of letters, return "".
    Otherwise, return a string of the unique letters in the new alien language sorted in lexicographically increasing order by the new language's rules. If there are multiple solutions, return any of them.
    
    Example 1:
    
    >>> alienOrder(words = ["wrt","wrf","er","ett","rftt"])
    >>> "wertf"
    
    Example 2:
    
    >>> alienOrder(words = ["z","x"])
    >>> "zx"
    
    Example 3:
    
    >>> alienOrder(words = ["z","x","z"])
    >>> ""
    Explanation: The order is invalid, so return "".
    """
# class TreeNode:
#     def __init__(val=0, left=None, right=None):
#         self.val = val
#         self.left = left
#         self.right = right
class Solution:
    def closestValue(root: Optional[TreeNode], target: float) -> int:
    """
    Given the root of a binary search tree and a target value, return the value in the BST that is closest to the target. If there are multiple answers, print the smallest.
    
    Example 1:
    
    
    >>> __init__(root = [4,2,5,1,3], target = 3.714286)
    >>> 4
    
    Example 2:
    
    >>> __init__(root = [1], target = 4.428571)
    >>> 1
    """
# class TreeNode:
#     def __init__(val=0, left=None, right=None):
#         self.val = val
#         self.left = left
#         self.right = right
class Solution:
    def closestKValues(root: Optional[TreeNode], target: float, k: int) -> List[int]:
    """
    Given the root of a binary search tree, a target value, and an integer k, return the k values in the BST that are closest to the target. You may return the answer in any order.
    You are guaranteed to have only one unique set of k values in the BST that are closest to the target.
    
    Example 1:
    
    
    >>> __init__(root = [4,2,5,1,3], target = 3.714286, k = 2)
    >>> [4,3]
    
    Example 2:
    
    >>> __init__(root = [1], target = 0.000000, k = 1)
    >>> [1]
    """
def numberToWords(num: int) -> str:
    """
    Convert a non-negative integer num to its English words representation.
    
    Example 1:
    
    >>> numberToWords(num = 123)
    >>> "One Hundred Twenty Three"
    
    Example 2:
    
    >>> numberToWords(num = 12345)
    >>> "Twelve Thousand Three Hundred Forty Five"
    
    Example 3:
    
    >>> numberToWords(num = 1234567)
    >>> "One Million Two Hundred Thirty Four Thousand Five Hundred Sixty Seven"
    """
def hIndex(citations: List[int]) -> int:
    """
    Given an array of integers citations where citations[i] is the number of citations a researcher received for their ith paper, return the researcher's h-index.
    According to the definition of h-index on Wikipedia: The h-index is defined as the maximum value of h such that the given researcher has published at least h papers that have each been cited at least h times.
    
    Example 1:
    
    >>> hIndex(citations = [3,0,6,1,5])
    >>> 3
    Explanation: [3,0,6,1,5] means the researcher has 5 papers in total and each of them had received 3, 0, 6, 1, 5 citations respectively.
    Since the researcher has 3 papers with at least 3 citations each and the remaining two with no more than 3 citations each, their h-index is 3.
    
    Example 2:
    
    >>> hIndex(citations = [1,3,1])
    >>> 1
    """
def hIndex(citations: List[int]) -> int:
    """
    Given an array of integers citations where citations[i] is the number of citations a researcher received for their ith paper and citations is sorted in ascending order, return the researcher's h-index.
    According to the definition of h-index on Wikipedia: The h-index is defined as the maximum value of h such that the given researcher has published at least h papers that have each been cited at least h times.
    You must write an algorithm that runs in logarithmic time.
    
    Example 1:
    
    >>> hIndex(citations = [0,1,3,5,6])
    >>> 3
    Explanation: [0,1,3,5,6] means the researcher has 5 papers in total and each of them had received 0, 1, 3, 5, 6 citations respectively.
    Since the researcher has 3 papers with at least 3 citations each and the remaining two with no more than 3 citations each, their h-index is 3.
    
    Example 2:
    
    >>> hIndex(citations = [1,2,100])
    >>> 2
    """
def numWays(n: int, k: int) -> int:
    """
    You are painting a fence of n posts with k different colors. You must paint the posts following these rules:
    
    Every post must be painted exactly one color.
    There cannot be three or more consecutive posts with the same color.
    
    Given the two integers n and k, return the number of ways you can paint the fence.
    
    Example 1:
    
    
    >>> numWays(n = 3, k = 2)
    >>> 6
    Explanation: All the possibilities are shown.
    Note that painting all the posts red or all the posts green is invalid because there cannot be three posts in a row with the same color.
    
    Example 2:
    
    >>> numWays(n = 1, k = 1)
    >>> 1
    
    Example 3:
    
    >>> numWays(n = 7, k = 2)
    >>> 42
    """
# def isBadVersion(version: int) -> bool:

class Solution:
    def firstBadVersion(n: int) -> int:
    """
    You are a product manager and currently leading a team to develop a new product. Unfortunately, the latest version of your product fails the quality check. Since each version is developed based on the previous version, all the versions after a bad version are also bad.
    Suppose you have n versions [1, 2, ..., n] and you want to find out the first bad one, which causes all the following ones to be bad.
    You are given an API bool isBadVersion(version) which returns whether version is bad. Implement a function to find the first bad version. You should minimize the number of calls to the API.
    
    Example 1:
    
    >>> isBadVersion(n = 5, bad = 4)
    >>> 4
    Explanation:
    call isBadVersion(3) -> false
    call isBadVersion(5) -> true
    call isBadVersion(4) -> true
    Then 4 is the first bad version.
    
    Example 2:
    
    >>> isBadVersion(n = 1, bad = 1)
    >>> 1
    """
def numSquares(n: int) -> int:
    """
    Given an integer n, return the least number of perfect square numbers that sum to n.
    A perfect square is an integer that is the square of an integer; in other words, it is the product of some integer with itself. For example, 1, 4, 9, and 16 are perfect squares while 3 and 11 are not.
    
    Example 1:
    
    >>> numSquares(n = 12)
    >>> 3
    Explanation: 12 = 4 + 4 + 4.
    
    Example 2:
    
    >>> numSquares(n = 13)
    >>> 2
    Explanation: 13 = 4 + 9.
    """
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 = [3,5,2,1,6,4])
    >>> [3,5,1,6,2,4]
    Explanation: [1,6,2,5,3,4] is also accepted.
    
    Example 2:
    
    >>> wiggleSort(nums = [6,6,5,6,3,8])
    >>> [6,6,5,6,3,8]
    """
def addOperators(num: str, target: int) -> List[str]:
    """
    Given a string num that contains only digits and an integer target, return all possibilities to insert the binary operators '+', '-', and/or '*' between the digits of num so that the resultant expression evaluates to the target value.
    Note that operands in the returned expressions should not contain leading zeros.
    
    Example 1:
    
    >>> addOperators(num = "123", target = 6)
    >>> ["1*2*3","1+2+3"]
    Explanation: Both "1*2*3" and "1+2+3" evaluate to 6.
    
    Example 2:
    
    >>> addOperators(num = "232", target = 8)
    >>> ["2*3+2","2+3*2"]
    Explanation: Both "2*3+2" and "2+3*2" evaluate to 8.
    
    Example 3:
    
    >>> addOperators(num = "3456237490", target = 9191)
    >>> []
    Explanation: There are no expressions that can be created from "3456237490" to evaluate to 9191.
    """
def moveZeroes(nums: List[int]) -> None:
        """
        Do not return anything, modify nums in-place instead.
        """
    """
    Given an integer array nums, move all 0's to the end of it while maintaining the relative order of the non-zero elements.
    Note that you must do this in-place without making a copy of the array.
    
    Example 1:
    >>> moveZeroes(nums = [0,1,0,3,12])
    >>> [1,3,12,0,0]
    Example 2:
    >>> moveZeroes(nums = [0])
    >>> [0]
    """