ShwStone/humaneval-leetcode huggingface dataset:
def lengthOfLastWord(s: str) -> int:
    """
    Given a string s consisting of words and spaces, return the length of the last word in the string.
    A word is a maximal substring consisting of non-space characters only.
    
    Example 1:
    
    >>> lengthOfLastWord(s = "Hello World")
    >>> 5
    Explanation: The last word is "World" with length 5.
    
    Example 2:
    
    >>> lengthOfLastWord(s = "   fly me   to   the moon  ")
    >>> 4
    Explanation: The last word is "moon" with length 4.
    
    Example 3:
    
    >>> lengthOfLastWord(s = "luffy is still joyboy")
    >>> 6
    Explanation: The last word is "joyboy" with length 6.
    """
def generateMatrix(n: int) -> List[List[int]]:
    """
    Given a positive integer n, generate an n x n matrix filled with elements from 1 to n2 in spiral order.
    
    Example 1:
    
    
    >>> generateMatrix(n = 3)
    >>> [[1,2,3],[8,9,4],[7,6,5]]
    
    Example 2:
    
    >>> generateMatrix(n = 1)
    >>> [[1]]
    """
def getPermutation(n: int, k: int) -> str:
    """
    The set [1, 2, 3, ..., n] contains a total of n! unique permutations.
    By listing and labeling all of the permutations in order, we get the following sequence for n = 3:
    
    "123"
    "132"
    "213"
    "231"
    "312"
    "321"
    
    Given n and k, return the kth permutation sequence.
    
    Example 1:
    >>> getPermutation(n = 3, k = 3)
    >>> "213"
    Example 2:
    >>> getPermutation(n = 4, k = 9)
    >>> "2314"
    Example 3:
    >>> getPermutation(n = 3, k = 1)
    >>> "123"
    """
# class ListNode:
#     def __init__(val=0, next=None):
#         self.val = val
#         self.next = next
class Solution:
    def rotateRight(head: Optional[ListNode], k: int) -> Optional[ListNode]:
    """
    Given the head of a linked list, rotate the list to the right by k places.
    
    Example 1:
    
    
    >>> __init__(head = [1,2,3,4,5], k = 2)
    >>> [4,5,1,2,3]
    
    Example 2:
    
    
    >>> __init__(head = [0,1,2], k = 4)
    >>> [2,0,1]
    """
def uniquePaths(m: int, n: int) -> int:
    """
    There is a robot on an m x n grid. The robot is initially located at the top-left corner (i.e., grid[0][0]). The robot tries to move to the bottom-right corner (i.e., grid[m - 1][n - 1]). The robot can only move either down or right at any point in time.
    Given the two integers m and n, return the number of possible unique paths that the robot can take to reach the bottom-right corner.
    The test cases are generated so that the answer will be less than or equal to 2 * 109.
    
    Example 1:
    
    
    >>> uniquePaths(m = 3, n = 7)
    >>> 28
    
    Example 2:
    
    >>> uniquePaths(m = 3, n = 2)
    >>> 3
    Explanation: From the top-left corner, there are a total of 3 ways to reach the bottom-right corner:
    1. Right -> Down -> Down
    2. Down -> Down -> Right
    3. Down -> Right -> Down
    """
def uniquePathsWithObstacles(obstacleGrid: List[List[int]]) -> int:
    """
    You are given an m x n integer array grid. There is a robot initially located at the top-left corner (i.e., grid[0][0]). The robot tries to move to the bottom-right corner (i.e., grid[m - 1][n - 1]). The robot can only move either down or right at any point in time.
    An obstacle and space are marked as 1 or 0 respectively in grid. A path that the robot takes cannot include any square that is an obstacle.
    Return the number of possible unique paths that the robot can take to reach the bottom-right corner.
    The testcases are generated so that the answer will be less than or equal to 2 * 109.
    
    Example 1:
    
    
    >>> uniquePathsWithObstacles(obstacleGrid = [[0,0,0],[0,1,0],[0,0,0]])
    >>> 2
    Explanation: There is one obstacle in the middle of the 3x3 grid above.
    There are two ways to reach the bottom-right corner:
    1. Right -> Right -> Down -> Down
    2. Down -> Down -> Right -> Right
    
    Example 2:
    
    
    >>> uniquePathsWithObstacles(obstacleGrid = [[0,1],[0,0]])
    >>> 1
    """
def minPathSum(grid: List[List[int]]) -> int:
    """
    Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right, which minimizes the sum of all numbers along its path.
    Note: You can only move either down or right at any point in time.
    
    Example 1:
    
    
    >>> minPathSum(grid = [[1,3,1],[1,5,1],[4,2,1]])
    >>> 7
    Explanation: Because the path 1 → 3 → 1 → 1 → 1 minimizes the sum.
    
    Example 2:
    
    >>> minPathSum(grid = [[1,2,3],[4,5,6]])
    >>> 12
    """
def isNumber(s: str) -> bool:
    """
    Given a string s, return whether s is a valid number.
    
    For example, all the following are valid numbers: "2", "0089", "-0.1", "+3.14", "4.", "-.9", "2e10", "-90E3", "3e+7", "+6e-1", "53.5e93", "-123.456e789", while the following are not valid numbers: "abc", "1a", "1e", "e3", "99e2.5", "--6", "-+3", "95a54e53".
    Formally, a valid number is defined using one of the following definitions:
    
    An integer number followed by an optional exponent.
    A decimal number followed by an optional exponent.
    
    An integer number is defined with an optional sign '-' or '+' followed by digits.
    A decimal number is defined with an optional sign '-' or '+' followed by one of the following definitions:
    
    Digits followed by a dot '.'.
    Digits followed by a dot '.' followed by digits.
    A dot '.' followed by digits.
    
    An exponent is defined with an exponent notation 'e' or 'E' followed by an integer number.
    The digits are defined as one or more digits.
    
    Example 1:
    
    >>> isNumber(s = "0")
    >>> true
    
    Example 2:
    
    >>> isNumber(s = "e")
    >>> false
    
    Example 3:
    
    >>> isNumber(s = ".")
    >>> false
    """
def plusOne(digits: List[int]) -> List[int]:
    """
    You are given a large integer represented as an integer array digits, where each digits[i] is the ith digit of the integer. The digits are ordered from most significant to least significant in left-to-right order. The large integer does not contain any leading 0's.
    Increment the large integer by one and return the resulting array of digits.
    
    Example 1:
    
    >>> plusOne(digits = [1,2,3])
    >>> [1,2,4]
    Explanation: The array represents the integer 123.
    Incrementing by one gives 123 + 1 = 124.
    Thus, the result should be [1,2,4].
    
    Example 2:
    
    >>> plusOne(digits = [4,3,2,1])
    >>> [4,3,2,2]
    Explanation: The array represents the integer 4321.
    Incrementing by one gives 4321 + 1 = 4322.
    Thus, the result should be [4,3,2,2].
    
    Example 3:
    
    >>> plusOne(digits = [9])
    >>> [1,0]
    Explanation: The array represents the integer 9.
    Incrementing by one gives 9 + 1 = 10.
    Thus, the result should be [1,0].
    """
def addBinary(a: str, b: str) -> str:
    """
    Given two binary strings a and b, return their sum as a binary string.
    
    Example 1:
    >>> addBinary(a = "11", b = "1")
    >>> "100"
    Example 2:
    >>> addBinary(a = "1010", b = "1011")
    >>> "10101"
    """
def fullJustify(words: List[str], maxWidth: int) -> List[str]:
    """
    Given an array of strings words and a width maxWidth, format the text such that each line has exactly maxWidth characters and is fully (left and right) justified.
    You should pack your words in a greedy approach; that is, pack as many words as you can in each line. Pad extra spaces ' ' when necessary so that each line has exactly maxWidth characters.
    Extra spaces between words should be distributed as evenly as possible. If the number of spaces on a line does not divide evenly between words, the empty slots on the left will be assigned more spaces than the slots on the right.
    For the last line of text, it should be left-justified, and no extra space is inserted between words.
    Note:
    
    A word is defined as a character sequence consisting of non-space characters only.
    Each word's length is guaranteed to be greater than 0 and not exceed maxWidth.
    The input array words contains at least one word.
    
    
    Example 1:
    
    >>> fullJustify(words = ["This", "is", "an", "example", "of", "text", "justification."], maxWidth = 16)
    >>>
    [
       "This    is    an",
       "example  of text",
       "justification.  "
    ]
    Example 2:
    
    >>> fullJustify(words = ["What","must","be","acknowledgment","shall","be"], maxWidth = 16)
    >>>
    [
      "What   must   be",
      "acknowledgment  ",
      "shall be        "
    ]
    Explanation: Note that the last line is "shall be    " instead of "shall     be", because the last line must be left-justified instead of fully-justified.
    Note that the second line is also left-justified because it contains only one word.
    Example 3:
    
    >>> fullJustify(words = ["Science","is","what","we","understand","well","enough","to","explain","to","a","computer.","Art","is","everything","else","we","do"], maxWidth = 20)
    >>>
    [
      "Science  is  what we",
      "understand      well",
      "enough to explain to",
      "a  computer.  Art is",
      "everything  else  we",
      "do                  "
    ]
    """
def mySqrt(x: int) -> int:
    """
    Given a non-negative integer x, return the square root of x rounded down to the nearest integer. The returned integer should be non-negative as well.
    You must not use any built-in exponent function or operator.
    
    For example, do not use pow(x, 0.5) in c++ or x ** 0.5 in python.
    
    
    Example 1:
    
    >>> mySqrt(x = 4)
    >>> 2
    Explanation: The square root of 4 is 2, so we return 2.
    
    Example 2:
    
    >>> mySqrt(x = 8)
    >>> 2
    Explanation: The square root of 8 is 2.82842..., and since we round it down to the nearest integer, 2 is returned.
    """
def climbStairs(n: int) -> int:
    """
    You are climbing a staircase. It takes n steps to reach the top.
    Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?
    
    Example 1:
    
    >>> climbStairs(n = 2)
    >>> 2
    Explanation: There are two ways to climb to the top.
    1. 1 step + 1 step
    2. 2 steps
    
    Example 2:
    
    >>> climbStairs(n = 3)
    >>> 3
    Explanation: There are three ways to climb to the top.
    1. 1 step + 1 step + 1 step
    2. 1 step + 2 steps
    3. 2 steps + 1 step
    """
def simplifyPath(path: str) -> str:
    """
    You are given an absolute path for a Unix-style file system, which always begins with a slash '/'. Your task is to transform this absolute path into its simplified canonical path.
    The rules of a Unix-style file system are as follows:
    
    A single period '.' represents the current directory.
    A double period '..' represents the previous/parent directory.
    Multiple consecutive slashes such as '//' and '///' are treated as a single slash '/'.
    Any sequence of periods that does not match the rules above should be treated as a valid directory or file name. For example, '...' and '....' are valid directory or file names.
    
    The simplified canonical path should follow these rules:
    
    The path must start with a single slash '/'.
    Directories within the path must be separated by exactly one slash '/'.
    The path must not end with a slash '/', unless it is the root directory.
    The path must not have any single or double periods ('.' and '..') used to denote current or parent directories.
    
    Return the simplified canonical path.
    
    Example 1:
    
    >>> simplifyPath(path = "/home/")
    >>> "/home"
    Explanation:
    The trailing slash should be removed.
    
    Example 2:
    
    >>> simplifyPath(path = "/home//foo/")
    >>> "/home/foo"
    Explanation:
    Multiple consecutive slashes are replaced by a single one.
    
    Example 3:
    
    >>> simplifyPath(path = "/home/user/Documents/../Pictures")
    >>> "/home/user/Pictures"
    Explanation:
    A double period ".." refers to the directory up a level (the parent directory).
    
    Example 4:
    
    >>> simplifyPath(path = "/../")
    >>> "/"
    Explanation:
    Going one level up from the root directory is not possible.
    
    Example 5:
    
    >>> simplifyPath(path = "/.../a/../b/c/../d/./")
    >>> "/.../b/d"
    Explanation:
    "..." is a valid name for a directory in this problem.
    """
def minDistance(word1: str, word2: str) -> int:
    """
    Given two strings word1 and word2, return the minimum number of operations required to convert word1 to word2.
    You have the following three operations permitted on a word:
    
    Insert a character
    Delete a character
    Replace a character
    
    
    Example 1:
    
    >>> minDistance(word1 = "horse", word2 = "ros")
    >>> 3
    Explanation:
    horse -> rorse (replace 'h' with 'r')
    rorse -> rose (remove 'r')
    rose -> ros (remove 'e')
    
    Example 2:
    
    >>> minDistance(word1 = "intention", word2 = "execution")
    >>> 5
    Explanation:
    intention -> inention (remove 't')
    inention -> enention (replace 'i' with 'e')
    enention -> exention (replace 'n' with 'x')
    exention -> exection (replace 'n' with 'c')
    exection -> execution (insert 'u')
    """
def setZeroes(matrix: List[List[int]]) -> None:
        """
        Do not return anything, modify matrix in-place instead.
        """
    """
    Given an m x n integer matrix matrix, if an element is 0, set its entire row and column to 0's.
    You must do it in place.
    
    Example 1:
    
    
    >>> setZeroes(matrix = [[1,1,1],[1,0,1],[1,1,1]])
    >>> [[1,0,1],[0,0,0],[1,0,1]]
    
    Example 2:
    
    
    >>> setZeroes(matrix = [[0,1,2,0],[3,4,5,2],[1,3,1,5]])
    >>> [[0,0,0,0],[0,4,5,0],[0,3,1,0]]
    """
def searchMatrix(matrix: List[List[int]], target: int) -> bool:
    """
    You are given an m x n integer matrix matrix with the following two properties:
    
    Each row is sorted in non-decreasing order.
    The first integer of each row is greater than the last integer of the previous row.
    
    Given an integer target, return true if target is in matrix or false otherwise.
    You must write a solution in O(log(m * n)) time complexity.
    
    Example 1:
    
    
    >>> searchMatrix(matrix = [[1,3,5,7],[10,11,16,20],[23,30,34,60]], target = 3)
    >>> true
    
    Example 2:
    
    
    >>> searchMatrix(matrix = [[1,3,5,7],[10,11,16,20],[23,30,34,60]], target = 13)
    >>> false
    """
def sortColors(nums: List[int]) -> None:
        """
        Do not return anything, modify nums in-place instead.
        """
    """
    Given an array nums with n objects colored red, white, or blue, sort them in-place so that objects of the same color are adjacent, with the colors in the order red, white, and blue.
    We will use the integers 0, 1, and 2 to represent the color red, white, and blue, respectively.
    You must solve this problem without using the library's sort function.
    
    Example 1:
    
    >>> sortColors(nums = [2,0,2,1,1,0])
    >>> [0,0,1,1,2,2]
    
    Example 2:
    
    >>> sortColors(nums = [2,0,1])
    >>> [0,1,2]
    """
def minWindow(s: str, t: str) -> str:
    """
    Given two strings s and t of lengths m and n respectively, return the minimum window substring of s such that every character in t (including duplicates) is included in the window. If there is no such substring, return the empty string "".
    The testcases will be generated such that the answer is unique.
    
    Example 1:
    
    >>> minWindow(s = "ADOBECODEBANC", t = "ABC")
    >>> "BANC"
    Explanation: The minimum window substring "BANC" includes 'A', 'B', and 'C' from string t.
    
    Example 2:
    
    >>> minWindow(s = "a", t = "a")
    >>> "a"
    Explanation: The entire string s is the minimum window.
    
    Example 3:
    
    >>> minWindow(s = "a", t = "aa")
    >>> ""
    Explanation: Both 'a's from t must be included in the window.
    Since the largest window of s only has one 'a', return empty string.
    """
def combine(n: int, k: int) -> List[List[int]]:
    """
    Given two integers n and k, return all possible combinations of k numbers chosen from the range [1, n].
    You may return the answer in any order.
    
    Example 1:
    
    >>> combine(n = 4, k = 2)
    >>> [[1,2],[1,3],[1,4],[2,3],[2,4],[3,4]]
    Explanation: There are 4 choose 2 = 6 total combinations.
    Note that combinations are unordered, i.e., [1,2] and [2,1] are considered to be the same combination.
    
    Example 2:
    
    >>> combine(n = 1, k = 1)
    >>> [[1]]
    Explanation: There is 1 choose 1 = 1 total combination.
    """
def subsets(nums: List[int]) -> List[List[int]]:
    """
    Given an integer array nums of unique elements, return all possible subsets (the power set).
    The solution set must not contain duplicate subsets. Return the solution in any order.
    
    Example 1:
    
    >>> subsets(nums = [1,2,3])
    >>> [[],[1],[2],[1,2],[3],[1,3],[2,3],[1,2,3]]
    
    Example 2:
    
    >>> subsets(nums = [0])
    >>> [[],[0]]
    """
def exist(board: List[List[str]], word: str) -> bool:
    """
    Given an m x n grid of characters board and a string word, return true if word exists in the grid.
    The word can be constructed from letters of sequentially adjacent cells, where adjacent cells are horizontally or vertically neighboring. The same letter cell may not be used more than once.
    
    Example 1:
    
    
    >>> exist(board = [["A","B","C","E"],["S","F","C","S"],["A","D","E","E"]], word = "ABCCED")
    >>> true
    
    Example 2:
    
    
    >>> exist(board = [["A","B","C","E"],["S","F","C","S"],["A","D","E","E"]], word = "SEE")
    >>> true
    
    Example 3:
    
    
    >>> exist(board = [["A","B","C","E"],["S","F","C","S"],["A","D","E","E"]], word = "ABCB")
    >>> false
    """
def removeDuplicates(nums: List[int]) -> int:
    """
    Given an integer array nums sorted in non-decreasing order, remove some duplicates in-place such that each unique element appears at most twice. The relative order of the elements should be kept the same.
    Since it is impossible to change the length of the array in some languages, you must instead have the result be placed in the first part of the array nums. More formally, if there are k elements after removing the duplicates, then the first k elements of nums should hold the final result. It does not matter what you leave beyond the first k elements.
    Return k after placing the final result in the first k slots of nums.
    Do not allocate extra space for another array. You must do this by modifying the input array in-place with O(1) extra memory.
    Custom Judge:
    The judge will test your solution with the following code:
    
    int[] nums = [...]; // Input array
    int[] expectedNums = [...]; // The expected answer with correct length
    
    int k = removeDuplicates(nums); // Calls your implementation
    
    assert k == expectedNums.length;
    for (int i = 0; i < k; i++) {
        assert nums[i] == expectedNums[i];
    }
    
    If all assertions pass, then your solution will be accepted.
    
    Example 1:
    
    >>> removeDuplicates(nums = [1,1,1,2,2,3])
    >>> 5, nums = [1,1,2,2,3,_]
    Explanation: Your function should return k = 5, with the first five elements of nums being 1, 1, 2, 2 and 3 respectively.
    It does not matter what you leave beyond the returned k (hence they are underscores).
    
    Example 2:
    
    >>> removeDuplicates(nums = [0,0,1,1,1,1,2,3,3])
    >>> 7, nums = [0,0,1,1,2,3,3,_,_]
    Explanation: Your function should return k = 7, with the first seven elements of nums being 0, 0, 1, 1, 2, 3 and 3 respectively.
    It does not matter what you leave beyond the returned k (hence they are underscores).
    """
def search(nums: List[int], target: int) -> bool:
    """
    There is an integer array nums sorted in non-decreasing order (not necessarily with distinct values).
    Before being passed to your function, nums is rotated at an unknown pivot index k (0 <= k < nums.length) such that the resulting array is [nums[k], nums[k+1], ..., nums[n-1], nums[0], nums[1], ..., nums[k-1]] (0-indexed). For example, [0,1,2,4,4,4,5,6,6,7] might be rotated at pivot index 5 and become [4,5,6,6,7,0,1,2,4,4].
    Given the array nums after the rotation and an integer target, return true if target is in nums, or false if it is not in nums.
    You must decrease the overall operation steps as much as possible.
    
    Example 1:
    >>> search(nums = [2,5,6,0,0,1,2], target = 0)
    >>> true
    Example 2:
    >>> search(nums = [2,5,6,0,0,1,2], target = 3)
    >>> false
    """
# class ListNode:
#     def __init__(val=0, next=None):
#         self.val = val
#         self.next = next
class Solution:
    def deleteDuplicates(head: Optional[ListNode]) -> Optional[ListNode]:
    """
    Given the head of a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list. Return the linked list sorted as well.
    
    Example 1:
    
    
    >>> __init__(head = [1,2,3,3,4,4,5])
    >>> [1,2,5]
    
    Example 2:
    
    
    >>> __init__(head = [1,1,1,2,3])
    >>> [2,3]
    """
# class ListNode:
#     def __init__(val=0, next=None):
#         self.val = val
#         self.next = next
class Solution:
    def deleteDuplicates(head: Optional[ListNode]) -> Optional[ListNode]:
    """
    Given the head of a sorted linked list, delete all duplicates such that each element appears only once. Return the linked list sorted as well.
    
    Example 1:
    
    
    >>> __init__(head = [1,1,2])
    >>> [1,2]
    
    Example 2:
    
    
    >>> __init__(head = [1,1,2,3,3])
    >>> [1,2,3]
    """
def largestRectangleArea(heights: List[int]) -> int:
    """
    Given an array of integers heights representing the histogram's bar height where the width of each bar is 1, return the area of the largest rectangle in the histogram.
    
    Example 1:
    
    
    >>> largestRectangleArea(heights = [2,1,5,6,2,3])
    >>> 10
    Explanation: The above is a histogram where width of each bar is 1.
    The largest rectangle is shown in the red area, which has an area = 10 units.
    
    Example 2:
    
    
    >>> largestRectangleArea(heights = [2,4])
    >>> 4
    """
def maximalRectangle(matrix: List[List[str]]) -> int:
    """
    Given a rows x cols binary matrix filled with 0's and 1's, find the largest rectangle containing only 1's and return its area.
    
    Example 1:
    
    
    >>> maximalRectangle(matrix = [["1","0","1","0","0"],["1","0","1","1","1"],["1","1","1","1","1"],["1","0","0","1","0"]])
    >>> 6
    Explanation: The maximal rectangle is shown in the above picture.
    
    Example 2:
    
    >>> maximalRectangle(matrix = [["0"]])
    >>> 0
    
    Example 3:
    
    >>> maximalRectangle(matrix = [["1"]])
    >>> 1
    """
# class ListNode:
#     def __init__(val=0, next=None):
#         self.val = val
#         self.next = next
class Solution:
    def partition(head: Optional[ListNode], x: int) -> Optional[ListNode]:
    """
    Given the head of a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x.
    You should preserve the original relative order of the nodes in each of the two partitions.
    
    Example 1:
    
    
    >>> __init__(head = [1,4,3,2,5,2], x = 3)
    >>> [1,2,2,4,3,5]
    
    Example 2:
    
    >>> __init__(head = [2,1], x = 2)
    >>> [1,2]
    """