ShwStone/humaneval-leetcode huggingface dataset:
def findMin(nums: List[int]) -> int:
    """
    Suppose an array of length n sorted in ascending order is rotated between 1 and n times. For example, the array nums = [0,1,2,4,5,6,7] might become:
    
    [4,5,6,7,0,1,2] if it was rotated 4 times.
    [0,1,2,4,5,6,7] if it was rotated 7 times.
    
    Notice that rotating an array [a[0], a[1], a[2], ..., a[n-1]] 1 time results in the array [a[n-1], a[0], a[1], a[2], ..., a[n-2]].
    Given the sorted rotated array nums of unique elements, return the minimum element of this array.
    You must write an algorithm that runs in O(log n) time.
    
    Example 1:
    
    >>> findMin(nums = [3,4,5,1,2])
    >>> 1
    Explanation: The original array was [1,2,3,4,5] rotated 3 times.
    
    Example 2:
    
    >>> findMin(nums = [4,5,6,7,0,1,2])
    >>> 0
    Explanation: The original array was [0,1,2,4,5,6,7] and it was rotated 4 times.
    
    Example 3:
    
    >>> findMin(nums = [11,13,15,17])
    >>> 11
    Explanation: The original array was [11,13,15,17] and it was rotated 4 times.
    """
def findMin(nums: List[int]) -> int:
    """
    Suppose an array of length n sorted in ascending order is rotated between 1 and n times. For example, the array nums = [0,1,4,4,5,6,7] might become:
    
    [4,5,6,7,0,1,4] if it was rotated 4 times.
    [0,1,4,4,5,6,7] if it was rotated 7 times.
    
    Notice that rotating an array [a[0], a[1], a[2], ..., a[n-1]] 1 time results in the array [a[n-1], a[0], a[1], a[2], ..., a[n-2]].
    Given the sorted rotated array nums that may contain duplicates, return the minimum element of this array.
    You must decrease the overall operation steps as much as possible.
    
    Example 1:
    >>> findMin(nums = [1,3,5])
    >>> 1
    Example 2:
    >>> findMin(nums = [2,2,2,0,1])
    >>> 0
    """
# class TreeNode:
#     def __init__(val=0, left=None, right=None):
#         self.val = val
#         self.left = left
#         self.right = right
class Solution:
    def upsideDownBinaryTree(root: Optional[TreeNode]) -> Optional[TreeNode]:
    """
    Given the root of a binary tree, turn the tree upside down and return the new root.
    You can turn a binary tree upside down with the following steps:
    
    The original left child becomes the new root.
    The original root becomes the new right child.
    The original right child becomes the new left child.
    
    
    The mentioned steps are done level by level. It is guaranteed that every right node has a sibling (a left node with the same parent) and has no children.
    
    Example 1:
    
    
    >>> __init__(root = [1,2,3,4,5])
    >>> [4,5,2,null,null,3,1]
    
    Example 2:
    
    >>> __init__(root = [])
    >>> []
    
    Example 3:
    
    >>> __init__(root = [1])
    >>> [1]
    """
def lengthOfLongestSubstringTwoDistinct(s: str) -> int:
    """
    Given a string s, return the length of the longest substring that contains at most two distinct characters.
    
    Example 1:
    
    >>> lengthOfLongestSubstringTwoDistinct(s = "eceba")
    >>> 3
    Explanation: The substring is "ece" which its length is 3.
    
    Example 2:
    
    >>> lengthOfLongestSubstringTwoDistinct(s = "ccaabbb")
    >>> 5
    Explanation: The substring is "aabbb" which its length is 5.
    """
# class ListNode:
#     def __init__(x):
#         self.val = x
#         self.next = None

class Solution:
    def getIntersectionNode(headA: ListNode, headB: ListNode) -> Optional[ListNode]:
    """
    Given the heads of two singly linked-lists headA and headB, return the node at which the two lists intersect. If the two linked lists have no intersection at all, return null.
    For example, the following two linked lists begin to intersect at node c1:
    
    The test cases are generated such that there are no cycles anywhere in the entire linked structure.
    Note that the linked lists must retain their original structure after the function returns.
    Custom Judge:
    The inputs to the judge are given as follows (your program is not given these inputs):
    
    intersectVal - The value of the node where the intersection occurs. This is 0 if there is no intersected node.
    listA - The first linked list.
    listB - The second linked list.
    skipA - The number of nodes to skip ahead in listA (starting from the head) to get to the intersected node.
    skipB - The number of nodes to skip ahead in listB (starting from the head) to get to the intersected node.
    
    The judge will then create the linked structure based on these inputs and pass the two heads, headA and headB to your program. If you correctly return the intersected node, then your solution will be accepted.
    
    Example 1:
    
    
    >>> __init__(intersectVal = 8, listA = [4,1,8,4,5], listB = [5,6,1,8,4,5], skipA = 2, skipB = 3)
    >>> Intersected at '8'
    Explanation: The intersected node's value is 8 (note that this must not be 0 if the two lists intersect).
    From the head of A, it reads as [4,1,8,4,5]. From the head of B, it reads as [5,6,1,8,4,5]. There are 2 nodes before the intersected node in A; There are 3 nodes before the intersected node in B.
    - Note that the intersected node's value is not 1 because the nodes with value 1 in A and B (2nd node in A and 3rd node in B) are different node references. In other words, they point to two different locations in memory, while the nodes with value 8 in A and B (3rd node in A and 4th node in B) point to the same location in memory.
    
    Example 2:
    
    
    >>> __init__(intersectVal = 2, listA = [1,9,1,2,4], listB = [3,2,4], skipA = 3, skipB = 1)
    >>> Intersected at '2'
    Explanation: The intersected node's value is 2 (note that this must not be 0 if the two lists intersect).
    From the head of A, it reads as [1,9,1,2,4]. From the head of B, it reads as [3,2,4]. There are 3 nodes before the intersected node in A; There are 1 node before the intersected node in B.
    
    Example 3:
    
    
    >>> __init__(intersectVal = 0, listA = [2,6,4], listB = [1,5], skipA = 3, skipB = 2)
    >>> No intersection
    Explanation: From the head of A, it reads as [2,6,4]. From the head of B, it reads as [1,5]. Since the two lists do not intersect, intersectVal must be 0, while skipA and skipB can be arbitrary values.
    Explanation: The two lists do not intersect, so return null.
    """
def isOneEditDistance(s: str, t: str) -> bool:
    """
    Given two strings s and t, return true if they are both one edit distance apart, otherwise return false.
    A string s is said to be one distance apart from a string t if you can:
    
    Insert exactly one character into s to get t.
    Delete exactly one character from s to get t.
    Replace exactly one character of s with a different character to get t.
    
    
    Example 1:
    
    >>> isOneEditDistance(s = "ab", t = "acb")
    >>> true
    Explanation: We can insert 'c' into s to get t.
    
    Example 2:
    
    >>> isOneEditDistance(s = "", t = "")
    >>> false
    Explanation: We cannot get t from s by only one step.
    """
def findPeakElement(nums: List[int]) -> int:
    """
    A peak element is an element that is strictly greater than its neighbors.
    Given a 0-indexed integer array nums, find a peak element, and return its index. If the array contains multiple peaks, return the index to any of the peaks.
    You may imagine that nums[-1] = nums[n] = -∞. In other words, an element is always considered to be strictly greater than a neighbor that is outside the array.
    You must write an algorithm that runs in O(log n) time.
    
    Example 1:
    
    >>> findPeakElement(nums = [1,2,3,1])
    >>> 2
    Explanation: 3 is a peak element and your function should return the index number 2.
    Example 2:
    
    >>> findPeakElement(nums = [1,2,1,3,5,6,4])
    >>> 5
    Explanation: Your function can return either index number 1 where the peak element is 2, or index number 5 where the peak element is 6.
    """
def findMissingRanges(nums: List[int], lower: int, upper: int) -> List[List[int]]:
    """
    You are given an inclusive range [lower, upper] and a sorted unique integer array nums, where all elements are within the inclusive range.
    A number x is considered missing if x is in the range [lower, upper] and x is not in nums.
    Return the shortest sorted list of ranges that exactly covers all the missing numbers. That is, no element of nums is included in any of the ranges, and each missing number is covered by one of the ranges.
    
    
    Example 1:
    
    >>> findMissingRanges(nums = [0,1,3,50,75], lower = 0, upper = 99)
    >>> [[2,2],[4,49],[51,74],[76,99]]
    Explanation: The ranges are:
    [2,2]
    [4,49]
    [51,74]
    [76,99]
    
    Example 2:
    
    >>> findMissingRanges(nums = [-1], lower = -1, upper = -1)
    >>> []
    Explanation: There are no missing ranges since there are no missing numbers.
    """
def maximumGap(nums: List[int]) -> int:
    """
    Given an integer array nums, return the maximum difference between two successive elements in its sorted form. If the array contains less than two elements, return 0.
    You must write an algorithm that runs in linear time and uses linear extra space.
    
    Example 1:
    
    >>> maximumGap(nums = [3,6,9,1])
    >>> 3
    Explanation: The sorted form of the array is [1,3,6,9], either (3,6) or (6,9) has the maximum difference 3.
    
    Example 2:
    
    >>> maximumGap(nums = [10])
    >>> 0
    Explanation: The array contains less than 2 elements, therefore return 0.
    """
def compareVersion(version1: str, version2: str) -> int:
    """
    Given two version strings, version1 and version2, compare them. A version string consists of revisions separated by dots '.'. The value of the revision is its integer conversion ignoring leading zeros.
    To compare version strings, compare their revision values in left-to-right order. If one of the version strings has fewer revisions, treat the missing revision values as 0.
    Return the following:
    
    If version1 < version2, return -1.
    If version1 > version2, return 1.
    Otherwise, return 0.
    
    
    Example 1:
    
    >>> compareVersion(version1 = "1.2", version2 = "1.10")
    >>> -1
    Explanation:
    version1's second revision is "2" and version2's second revision is "10": 2 < 10, so version1 < version2.
    
    Example 2:
    
    >>> compareVersion(version1 = "1.01", version2 = "1.001")
    >>> 0
    Explanation:
    Ignoring leading zeroes, both "01" and "001" represent the same integer "1".
    
    Example 3:
    
    >>> compareVersion(version1 = "1.0", version2 = "1.0.0.0")
    >>> 0
    Explanation:
    version1 has less revisions, which means every missing revision are treated as "0".
    """
def fractionToDecimal(numerator: int, denominator: int) -> str:
    """
    Given two integers representing the numerator and denominator of a fraction, return the fraction in string format.
    If the fractional part is repeating, enclose the repeating part in parentheses.
    If multiple answers are possible, return any of them.
    It is guaranteed that the length of the answer string is less than 104 for all the given inputs.
    
    Example 1:
    
    >>> fractionToDecimal(numerator = 1, denominator = 2)
    >>> "0.5"
    
    Example 2:
    
    >>> fractionToDecimal(numerator = 2, denominator = 1)
    >>> "2"
    
    Example 3:
    
    >>> fractionToDecimal(numerator = 4, denominator = 333)
    >>> "0.(012)"
    """
def twoSum(numbers: List[int], target: int) -> List[int]:
    """
    Given a 1-indexed array of integers numbers that is already sorted in non-decreasing order, find two numbers such that they add up to a specific target number. Let these two numbers be numbers[index1] and numbers[index2] where 1 <= index1 < index2 <= numbers.length.
    Return the indices of the two numbers, index1 and index2, added by one as an integer array [index1, index2] of length 2.
    The tests are generated such that there is exactly one solution. You may not use the same element twice.
    Your solution must use only constant extra space.
    
    Example 1:
    
    >>> twoSum(numbers = [2,7,11,15], target = 9)
    >>> [1,2]
    Explanation: The sum of 2 and 7 is 9. Therefore, index1 = 1, index2 = 2. We return [1, 2].
    
    Example 2:
    
    >>> twoSum(numbers = [2,3,4], target = 6)
    >>> [1,3]
    Explanation: The sum of 2 and 4 is 6. Therefore index1 = 1, index2 = 3. We return [1, 3].
    
    Example 3:
    
    >>> twoSum(numbers = [-1,0], target = -1)
    >>> [1,2]
    Explanation: The sum of -1 and 0 is -1. Therefore index1 = 1, index2 = 2. We return [1, 2].
    """
def convertToTitle(columnNumber: int) -> str:
    """
    Given an integer columnNumber, return its corresponding column title as it appears in an Excel sheet.
    For example:
    
    A -> 1
    B -> 2
    C -> 3
    ...
    Z -> 26
    AA -> 27
    AB -> 28
    ...
    
    
    Example 1:
    
    >>> convertToTitle(columnNumber = 1)
    >>> "A"
    
    Example 2:
    
    >>> convertToTitle(columnNumber = 28)
    >>> "AB"
    
    Example 3:
    
    >>> convertToTitle(columnNumber = 701)
    >>> "ZY"
    """
def majorityElement(nums: List[int]) -> int:
    """
    Given an array nums of size n, return the majority element.
    The majority element is the element that appears more than ⌊n / 2⌋ times. You may assume that the majority element always exists in the array.
    
    Example 1:
    >>> majorityElement(nums = [3,2,3])
    >>> 3
    Example 2:
    >>> majorityElement(nums = [2,2,1,1,1,2,2])
    >>> 2
    """
def titleToNumber(columnTitle: str) -> int:
    """
    Given a string columnTitle that represents the column title as appears in an Excel sheet, return its corresponding column number.
    For example:
    
    A -> 1
    B -> 2
    C -> 3
    ...
    Z -> 26
    AA -> 27
    AB -> 28
    ...
    
    
    Example 1:
    
    >>> titleToNumber(columnTitle = "A")
    >>> 1
    
    Example 2:
    
    >>> titleToNumber(columnTitle = "AB")
    >>> 28
    
    Example 3:
    
    >>> titleToNumber(columnTitle = "ZY")
    >>> 701
    """
def trailingZeroes(n: int) -> int:
    """
    Given an integer n, return the number of trailing zeroes in n!.
    Note that n! = n * (n - 1) * (n - 2) * ... * 3 * 2 * 1.
    
    Example 1:
    
    >>> trailingZeroes(n = 3)
    >>> 0
    Explanation: 3! = 6, no trailing zero.
    
    Example 2:
    
    >>> trailingZeroes(n = 5)
    >>> 1
    Explanation: 5! = 120, one trailing zero.
    
    Example 3:
    
    >>> trailingZeroes(n = 0)
    >>> 0
    """
def calculateMinimumHP(dungeon: List[List[int]]) -> int:
    """
    The demons had captured the princess and imprisoned her in the bottom-right corner of a dungeon. The dungeon consists of m x n rooms laid out in a 2D grid. Our valiant knight was initially positioned in the top-left room and must fight his way through dungeon to rescue the princess.
    The knight has an initial health point represented by a positive integer. If at any point his health point drops to 0 or below, he dies immediately.
    Some of the rooms are guarded by demons (represented by negative integers), so the knight loses health upon entering these rooms; other rooms are either empty (represented as 0) or contain magic orbs that increase the knight's health (represented by positive integers).
    To reach the princess as quickly as possible, the knight decides to move only rightward or downward in each step.
    Return the knight's minimum initial health so that he can rescue the princess.
    Note that any room can contain threats or power-ups, even the first room the knight enters and the bottom-right room where the princess is imprisoned.
    
    Example 1:
    
    
    >>> calculateMinimumHP(dungeon = [[-2,-3,3],[-5,-10,1],[10,30,-5]])
    >>> 7
    Explanation: The initial health of the knight must be at least 7 if he follows the optimal path: RIGHT-> RIGHT -> DOWN -> DOWN.
    
    Example 2:
    
    >>> calculateMinimumHP(dungeon = [[0]])
    >>> 1
    """
def largestNumber(nums: List[int]) -> str:
    """
    Given a list of non-negative integers nums, arrange them such that they form the largest number and return it.
    Since the result may be very large, so you need to return a string instead of an integer.
    
    Example 1:
    
    >>> largestNumber(nums = [10,2])
    >>> "210"
    
    Example 2:
    
    >>> largestNumber(nums = [3,30,34,5,9])
    >>> "9534330"
    """
def reverseWords(s: List[str]) -> None:
        """
        Do not return anything, modify s in-place instead.
        """
    """
    Given a character array s, reverse the order of the words.
    A word is defined as a sequence of non-space characters. The words in s will be separated by a single space.
    Your code must solve the problem in-place, i.e. without allocating extra space.
    
    Example 1:
    >>> reverseWords(s = ["t","h","e"," ","s","k","y"," ","i","s"," ","b","l","u","e"])
    >>> ["b","l","u","e"," ","i","s"," ","s","k","y"," ","t","h","e"]
    Example 2:
    >>> reverseWords(s = ["a"])
    >>> ["a"]
    """
def findRepeatedDnaSequences(s: str) -> List[str]:
    """
    The DNA sequence is composed of a series of nucleotides abbreviated as 'A', 'C', 'G', and 'T'.
    
    For example, "ACGAATTCCG" is a DNA sequence.
    
    When studying DNA, it is useful to identify repeated sequences within the DNA.
    Given a string s that represents a DNA sequence, return all the 10-letter-long sequences (substrings) that occur more than once in a DNA molecule. You may return the answer in any order.
    
    Example 1:
    >>> findRepeatedDnaSequences(s = "AAAAACCCCCAAAAACCCCCCAAAAAGGGTTT")
    >>> ["AAAAACCCCC","CCCCCAAAAA"]
    Example 2:
    >>> findRepeatedDnaSequences(s = "AAAAAAAAAAAAA")
    >>> ["AAAAAAAAAA"]
    """
def maxProfit(k: int, prices: List[int]) -> int:
    """
    You are given an integer array prices where prices[i] is the price of a given stock on the ith day, and an integer k.
    Find the maximum profit you can achieve. You may complete at most k transactions: i.e. you may buy at most k times and sell at most k times.
    Note: You may not engage in multiple transactions simultaneously (i.e., you must sell the stock before you buy again).
    
    Example 1:
    
    >>> maxProfit(k = 2, prices = [2,4,1])
    >>> 2
    Explanation: Buy on day 1 (price = 2) and sell on day 2 (price = 4), profit = 4-2 = 2.
    
    Example 2:
    
    >>> maxProfit(k = 2, prices = [3,2,6,5,0,3])
    >>> 7
    Explanation: Buy on day 2 (price = 2) and sell on day 3 (price = 6), profit = 6-2 = 4. Then buy on day 5 (price = 0) and sell on day 6 (price = 3), profit = 3-0 = 3.
    """
def rotate(nums: List[int], k: int) -> None:
        """
        Do not return anything, modify nums in-place instead.
        """
    """
    Given an integer array nums, rotate the array to the right by k steps, where k is non-negative.
    
    Example 1:
    
    >>> rotate(nums = [1,2,3,4,5,6,7], k = 3)
    >>> [5,6,7,1,2,3,4]
    Explanation:
    rotate 1 steps to the right: [7,1,2,3,4,5,6]
    rotate 2 steps to the right: [6,7,1,2,3,4,5]
    rotate 3 steps to the right: [5,6,7,1,2,3,4]
    
    Example 2:
    
    >>> rotate(nums = [-1,-100,3,99], k = 2)
    >>> [3,99,-1,-100]
    Explanation:
    rotate 1 steps to the right: [99,-1,-100,3]
    rotate 2 steps to the right: [3,99,-1,-100]
    """
def reverseBits(n: int) -> int:
    """
    Reverse bits of a given 32 bits unsigned integer.
    Note:
    
    Note that in some languages, such as Java, there is no unsigned integer type. In this case, both input and output will be given as a signed integer type. They should not affect your implementation, as the integer's internal binary representation is the same, whether it is signed or unsigned.
    In Java, the compiler represents the signed integers using 2's complement notation. Therefore, in Example 2 above, the input represents the signed integer -3 and the output represents the signed integer -1073741825.
    
    
    Example 1:
    
    >>> reverseBits(n = 00000010100101000001111010011100)
    >>> 964176192 (00111001011110000010100101000000)
    Explanation: The input binary string 00000010100101000001111010011100 represents the unsigned integer 43261596, so return 964176192 which its binary representation is 00111001011110000010100101000000.
    
    Example 2:
    
    >>> reverseBits(n = 11111111111111111111111111111101)
    >>> 3221225471 (10111111111111111111111111111111)
    Explanation: The input binary string 11111111111111111111111111111101 represents the unsigned integer 4294967293, so return 3221225471 which its binary representation is 10111111111111111111111111111111.
    """
def hammingWeight(n: int) -> int:
    """
    Given a positive integer n, write a function that returns the number of set bits in its binary representation (also known as the Hamming weight).
    
    Example 1:
    
    >>> hammingWeight(n = 11)
    >>> 3
    Explanation:
    The input binary string 1011 has a total of three set bits.
    
    Example 2:
    
    >>> hammingWeight(n = 128)
    >>> 1
    Explanation:
    The input binary string 10000000 has a total of one set bit.
    
    Example 3:
    
    >>> hammingWeight(n = 2147483645)
    >>> 30
    Explanation:
    The input binary string 1111111111111111111111111111101 has a total of thirty set bits.
    """
def rob(nums: List[int]) -> int:
    """
    You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent houses have security systems connected and it will automatically contact the police if two adjacent houses were broken into on the same night.
    Given an integer array nums representing the amount of money of each house, return the maximum amount of money you can rob tonight without alerting the police.
    
    Example 1:
    
    >>> rob(nums = [1,2,3,1])
    >>> 4
    Explanation: Rob house 1 (money = 1) and then rob house 3 (money = 3).
    Total amount you can rob = 1 + 3 = 4.
    
    Example 2:
    
    >>> rob(nums = [2,7,9,3,1])
    >>> 12
    Explanation: Rob house 1 (money = 2), rob house 3 (money = 9) and rob house 5 (money = 1).
    Total amount you can rob = 2 + 9 + 1 = 12.
    """
# class TreeNode:
#     def __init__(val=0, left=None, right=None):
#         self.val = val
#         self.left = left
#         self.right = right
class Solution:
    def rightSideView(root: Optional[TreeNode]) -> List[int]:
    """
    Given the root of a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom.
    
    Example 1:
    
    >>> __init__(root = [1,2,3,null,5,null,4])
    >>> [1,3,4]
    Explanation:
    
    
    Example 2:
    
    >>> __init__(root = [1,2,3,4,null,null,null,5])
    >>> [1,3,4,5]
    Explanation:
    
    
    Example 3:
    
    >>> __init__(root = [1,null,3])
    >>> [1,3]
    
    Example 4:
    
    >>> __init__(root = [])
    >>> []
    """
def numIslands(grid: List[List[str]]) -> int:
    """
    Given an m x n 2D binary grid grid which represents a map of '1's (land) and '0's (water), return the number of islands.
    An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You may assume all four edges of the grid are all surrounded by water.
    
    Example 1:
    
      ["1","1","1","1","0"],
      ["1","1","0","1","0"],
      ["1","1","0","0","0"],
      ["0","0","0","0","0"]
    ]
    >>> numIslands(grid = [)
    >>> 1
    
    Example 2:
    
      ["1","1","0","0","0"],
      ["1","1","0","0","0"],
      ["0","0","1","0","0"],
      ["0","0","0","1","1"]
    ]
    >>> numIslands(grid = [)
    >>> 3
    """
def rangeBitwiseAnd(left: int, right: int) -> int:
    """
    Given two integers left and right that represent the range [left, right], return the bitwise AND of all numbers in this range, inclusive.
    
    Example 1:
    
    >>> rangeBitwiseAnd(left = 5, right = 7)
    >>> 4
    
    Example 2:
    
    >>> rangeBitwiseAnd(left = 0, right = 0)
    >>> 0
    
    Example 3:
    
    >>> rangeBitwiseAnd(left = 1, right = 2147483647)
    >>> 0
    """