ShwStone/humaneval-leetcode huggingface dataset:
def strStr(haystack: str, needle: str) -> int:
    """
    Given two strings needle and haystack, return the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.
    
    Example 1:
    
    >>> strStr(haystack = "sadbutsad", needle = "sad")
    >>> 0
    Explanation: "sad" occurs at index 0 and 6.
    The first occurrence is at index 0, so we return 0.
    
    Example 2:
    
    >>> strStr(haystack = "leetcode", needle = "leeto")
    >>> -1
    Explanation: "leeto" did not occur in "leetcode", so we return -1.
    """
def divide(dividend: int, divisor: int) -> int:
    """
    Given two integers dividend and divisor, divide two integers without using multiplication, division, and mod operator.
    The integer division should truncate toward zero, which means losing its fractional part. For example, 8.345 would be truncated to 8, and -2.7335 would be truncated to -2.
    Return the quotient after dividing dividend by divisor.
    Note: Assume we are dealing with an environment that could only store integers within the 32-bit signed integer range: [−231, 231 − 1]. For this problem, if the quotient is strictly greater than 231 - 1, then return 231 - 1, and if the quotient is strictly less than -231, then return -231.
    
    Example 1:
    
    >>> divide(dividend = 10, divisor = 3)
    >>> 3
    Explanation: 10/3 = 3.33333.. which is truncated to 3.
    
    Example 2:
    
    >>> divide(dividend = 7, divisor = -3)
    >>> -2
    Explanation: 7/-3 = -2.33333.. which is truncated to -2.
    """
def findSubstring(s: str, words: List[str]) -> List[int]:
    """
    You are given a string s and an array of strings words. All the strings of words are of the same length.
    A concatenated string is a string that exactly contains all the strings of any permutation of words concatenated.
    
    For example, if words = ["ab","cd","ef"], then "abcdef", "abefcd", "cdabef", "cdefab", "efabcd", and "efcdab" are all concatenated strings. "acdbef" is not a concatenated string because it is not the concatenation of any permutation of words.
    
    Return an array of the starting indices of all the concatenated substrings in s. You can return the answer in any order.
    
    Example 1:
    
    >>> findSubstring(s = "barfoothefoobarman", words = ["foo","bar"])
    >>> [0,9]
    Explanation:
    The substring starting at 0 is "barfoo". It is the concatenation of ["bar","foo"] which is a permutation of words.
    The substring starting at 9 is "foobar". It is the concatenation of ["foo","bar"] which is a permutation of words.
    
    Example 2:
    
    >>> findSubstring(s = "wordgoodgoodgoodbestword", words = ["word","good","best","word"])
    >>> []
    Explanation:
    There is no concatenated substring.
    
    Example 3:
    
    >>> findSubstring(s = "barfoofoobarthefoobarman", words = ["bar","foo","the"])
    >>> [6,9,12]
    Explanation:
    The substring starting at 6 is "foobarthe". It is the concatenation of ["foo","bar","the"].
    The substring starting at 9 is "barthefoo". It is the concatenation of ["bar","the","foo"].
    The substring starting at 12 is "thefoobar". It is the concatenation of ["the","foo","bar"].
    """
def nextPermutation(nums: List[int]) -> None:
        """
        Do not return anything, modify nums in-place instead.
        """
    """
    A permutation of an array of integers is an arrangement of its members into a sequence or linear order.
    
    For example, for arr = [1,2,3], the following are all the permutations of arr: [1,2,3], [1,3,2], [2, 1, 3], [2, 3, 1], [3,1,2], [3,2,1].
    
    The next permutation of an array of integers is the next lexicographically greater permutation of its integer. More formally, if all the permutations of the array are sorted in one container according to their lexicographical order, then the next permutation of that array is the permutation that follows it in the sorted container. If such arrangement is not possible, the array must be rearranged as the lowest possible order (i.e., sorted in ascending order).
    
    For example, the next permutation of arr = [1,2,3] is [1,3,2].
    Similarly, the next permutation of arr = [2,3,1] is [3,1,2].
    While the next permutation of arr = [3,2,1] is [1,2,3] because [3,2,1] does not have a lexicographical larger rearrangement.
    
    Given an array of integers nums, find the next permutation of nums.
    The replacement must be in place and use only constant extra memory.
    
    Example 1:
    
    >>> nextPermutation(nums = [1,2,3])
    >>> [1,3,2]
    
    Example 2:
    
    >>> nextPermutation(nums = [3,2,1])
    >>> [1,2,3]
    
    Example 3:
    
    >>> nextPermutation(nums = [1,1,5])
    >>> [1,5,1]
    """
def longestValidParentheses(s: str) -> int:
    """
    Given a string containing just the characters '(' and ')', return the length of the longest valid (well-formed) parentheses substring.
    
    Example 1:
    
    >>> longestValidParentheses(s = "(()")
    >>> 2
    Explanation: The longest valid parentheses substring is "()".
    
    Example 2:
    
    >>> longestValidParentheses(s = ")()())")
    >>> 4
    Explanation: The longest valid parentheses substring is "()()".
    
    Example 3:
    
    >>> longestValidParentheses(s = "")
    >>> 0
    """
def search(nums: List[int], target: int) -> int:
    """
    There is an integer array nums sorted in ascending order (with distinct values).
    Prior to being passed to your function, nums is possibly rotated at an unknown pivot index k (1 <= 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,5,6,7] might be rotated at pivot index 3 and become [4,5,6,7,0,1,2].
    Given the array nums after the possible rotation and an integer target, return the index of target if it is in nums, or -1 if it is not in nums.
    You must write an algorithm with O(log n) runtime complexity.
    
    Example 1:
    >>> search(nums = [4,5,6,7,0,1,2], target = 0)
    >>> 4
    Example 2:
    >>> search(nums = [4,5,6,7,0,1,2], target = 3)
    >>> -1
    Example 3:
    >>> search(nums = [1], target = 0)
    >>> -1
    """
def searchRange(nums: List[int], target: int) -> List[int]:
    """
    Given an array of integers nums sorted in non-decreasing order, find the starting and ending position of a given target value.
    If target is not found in the array, return [-1, -1].
    You must write an algorithm with O(log n) runtime complexity.
    
    Example 1:
    >>> searchRange(nums = [5,7,7,8,8,10], target = 8)
    >>> [3,4]
    Example 2:
    >>> searchRange(nums = [5,7,7,8,8,10], target = 6)
    >>> [-1,-1]
    Example 3:
    >>> searchRange(nums = [], target = 0)
    >>> [-1,-1]
    """
def searchInsert(nums: List[int], target: int) -> int:
    """
    Given a sorted array of distinct integers and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.
    You must write an algorithm with O(log n) runtime complexity.
    
    Example 1:
    
    >>> searchInsert(nums = [1,3,5,6], target = 5)
    >>> 2
    
    Example 2:
    
    >>> searchInsert(nums = [1,3,5,6], target = 2)
    >>> 1
    
    Example 3:
    
    >>> searchInsert(nums = [1,3,5,6], target = 7)
    >>> 4
    """
def isValidSudoku(board: List[List[str]]) -> bool:
    """
    Determine if a 9 x 9 Sudoku board is valid. Only the filled cells need to be validated according to the following rules:
    
    Each row must contain the digits 1-9 without repetition.
    Each column must contain the digits 1-9 without repetition.
    Each of the nine 3 x 3 sub-boxes of the grid must contain the digits 1-9 without repetition.
    
    Note:
    
    A Sudoku board (partially filled) could be valid but is not necessarily solvable.
    Only the filled cells need to be validated according to the mentioned rules.
    
    
    Example 1:
    
    
    [["5","3",".",".","7",".",".",".","."]
    ,["6",".",".","1","9","5",".",".","."]
    ,[".","9","8",".",".",".",".","6","."]
    ,["8",".",".",".","6",".",".",".","3"]
    ,["4",".",".","8",".","3",".",".","1"]
    ,["7",".",".",".","2",".",".",".","6"]
    ,[".","6",".",".",".",".","2","8","."]
    ,[".",".",".","4","1","9",".",".","5"]
    ,[".",".",".",".","8",".",".","7","9"]]
    >>> isValidSudoku(board =)
    >>> true
    
    Example 2:
    
    [["8","3",".",".","7",".",".",".","."]
    ,["6",".",".","1","9","5",".",".","."]
    ,[".","9","8",".",".",".",".","6","."]
    ,["8",".",".",".","6",".",".",".","3"]
    ,["4",".",".","8",".","3",".",".","1"]
    ,["7",".",".",".","2",".",".",".","6"]
    ,[".","6",".",".",".",".","2","8","."]
    ,[".",".",".","4","1","9",".",".","5"]
    ,[".",".",".",".","8",".",".","7","9"]]
    >>> isValidSudoku(board =)
    >>> false
    Explanation: Same as Example 1, except with the 5 in the top left corner being modified to 8. Since there are two 8's in the top left 3x3 sub-box, it is invalid.
    """
def solveSudoku(board: List[List[str]]) -> None:
        """
        Do not return anything, modify board in-place instead.
        """
    """
    Write a program to solve a Sudoku puzzle by filling the empty cells.
    A sudoku solution must satisfy all of the following rules:
    
    Each of the digits 1-9 must occur exactly once in each row.
    Each of the digits 1-9 must occur exactly once in each column.
    Each of the digits 1-9 must occur exactly once in each of the 9 3x3 sub-boxes of the grid.
    
    The '.' character indicates empty cells.
    
    Example 1:
    
    
    >>> solveSudoku(board = [["5","3",".",".","7",".",".",".","."],["6",".",".","1","9","5",".",".","."],[".","9","8",".",".",".",".","6","."],["8",".",".",".","6",".",".",".","3"],["4",".",".","8",".","3",".",".","1"],["7",".",".",".","2",".",".",".","6"],[".","6",".",".",".",".","2","8","."],[".",".",".","4","1","9",".",".","5"],[".",".",".",".","8",".",".","7","9"]])
    >>> [["5","3","4","6","7","8","9","1","2"],["6","7","2","1","9","5","3","4","8"],["1","9","8","3","4","2","5","6","7"],["8","5","9","7","6","1","4","2","3"],["4","2","6","8","5","3","7","9","1"],["7","1","3","9","2","4","8","5","6"],["9","6","1","5","3","7","2","8","4"],["2","8","7","4","1","9","6","3","5"],["3","4","5","2","8","6","1","7","9"]]
    Explanation: The input board is shown above and the only valid solution is shown below:
    """
def countAndSay(n: int) -> str:
    """
    The count-and-say sequence is a sequence of digit strings defined by the recursive formula:
    
    countAndSay(1) = "1"
    countAndSay(n) is the run-length encoding of countAndSay(n - 1).
    
    Run-length encoding (RLE) is a string compression method that works by replacing consecutive identical characters (repeated 2 or more times) with the concatenation of the character and the number marking the count of the characters (length of the run). For example, to compress the string "3322251" we replace "33" with "23", replace "222" with "32", replace "5" with "15" and replace "1" with "11". Thus the compressed string becomes "23321511".
    Given a positive integer n, return the nth element of the count-and-say sequence.
    
    Example 1:
    
    >>> countAndSay(n = 4)
    >>> "1211"
    Explanation:
    
    countAndSay(1) = "1"
    countAndSay(2) = RLE of "1" = "11"
    countAndSay(3) = RLE of "11" = "21"
    countAndSay(4) = RLE of "21" = "1211"
    
    
    Example 2:
    
    >>> countAndSay(n = 1)
    >>> "1"
    Explanation:
    This is the base case.
    """
def combinationSum(candidates: List[int], target: int) -> List[List[int]]:
    """
    Given an array of distinct integers candidates and a target integer target, return a list of all unique combinations of candidates where the chosen numbers sum to target. You may return the combinations in any order.
    The same number may be chosen from candidates an unlimited number of times. Two combinations are unique if the frequency of at least one of the chosen numbers is different.
    The test cases are generated such that the number of unique combinations that sum up to target is less than 150 combinations for the given input.
    
    Example 1:
    
    >>> combinationSum(candidates = [2,3,6,7], target = 7)
    >>> [[2,2,3],[7]]
    Explanation:
    2 and 3 are candidates, and 2 + 2 + 3 = 7. Note that 2 can be used multiple times.
    7 is a candidate, and 7 = 7.
    These are the only two combinations.
    
    Example 2:
    
    >>> combinationSum(candidates = [2,3,5], target = 8)
    >>> [[2,2,2,2],[2,3,3],[3,5]]
    
    Example 3:
    
    >>> combinationSum(candidates = [2], target = 1)
    >>> []
    """
def combinationSum2(candidates: List[int], target: int) -> List[List[int]]:
    """
    Given a collection of candidate numbers (candidates) and a target number (target), find all unique combinations in candidates where the candidate numbers sum to target.
    Each number in candidates may only be used once in the combination.
    Note: The solution set must not contain duplicate combinations.
    
    Example 1:
    
    >>> combinationSum2(candidates = [10,1,2,7,6,1,5], target = 8)
    >>>
    [
    [1,1,6],
    [1,2,5],
    [1,7],
    [2,6]
    ]
    
    Example 2:
    
    >>> combinationSum2(candidates = [2,5,2,1,2], target = 5)
    >>>
    [
    [1,2,2],
    [5]
    ]
    """
def firstMissingPositive(nums: List[int]) -> int:
    """
    Given an unsorted integer array nums. Return the smallest positive integer that is not present in nums.
    You must implement an algorithm that runs in O(n) time and uses O(1) auxiliary space.
    
    Example 1:
    
    >>> firstMissingPositive(nums = [1,2,0])
    >>> 3
    Explanation: The numbers in the range [1,2] are all in the array.
    
    Example 2:
    
    >>> firstMissingPositive(nums = [3,4,-1,1])
    >>> 2
    Explanation: 1 is in the array but 2 is missing.
    
    Example 3:
    
    >>> firstMissingPositive(nums = [7,8,9,11,12])
    >>> 1
    Explanation: The smallest positive integer 1 is missing.
    """
def trap(height: List[int]) -> int:
    """
    Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it can trap after raining.
    
    Example 1:
    
    
    >>> trap(height = [0,1,0,2,1,0,1,3,2,1,2,1])
    >>> 6
    Explanation: The above elevation map (black section) is represented by array [0,1,0,2,1,0,1,3,2,1,2,1]. In this case, 6 units of rain water (blue section) are being trapped.
    
    Example 2:
    
    >>> trap(height = [4,2,0,3,2,5])
    >>> 9
    """
def multiply(num1: str, num2: str) -> str:
    """
    Given two non-negative integers num1 and num2 represented as strings, return the product of num1 and num2, also represented as a string.
    Note: You must not use any built-in BigInteger library or convert the inputs to integer directly.
    
    Example 1:
    >>> multiply(num1 = "2", num2 = "3")
    >>> "6"
    Example 2:
    >>> multiply(num1 = "123", num2 = "456")
    >>> "56088"
    """
def isMatch(s: str, p: str) -> bool:
    """
    Given an input string (s) and a pattern (p), implement wildcard pattern matching with support for '?' and '*' where:
    
    '?' Matches any single character.
    '*' Matches any sequence of characters (including the empty sequence).
    
    The matching should cover the entire input string (not partial).
    
    Example 1:
    
    >>> isMatch(s = "aa", p = "a")
    >>> false
    Explanation: "a" does not match the entire string "aa".
    
    Example 2:
    
    >>> isMatch(s = "aa", p = "*")
    >>> true
    Explanation: '*' matches any sequence.
    
    Example 3:
    
    >>> isMatch(s = "cb", p = "?a")
    >>> false
    Explanation: '?' matches 'c', but the second letter is 'a', which does not match 'b'.
    """
def jump(nums: List[int]) -> int:
    """
    You are given a 0-indexed array of integers nums of length n. You are initially positioned at nums[0].
    Each element nums[i] represents the maximum length of a forward jump from index i. In other words, if you are at nums[i], you can jump to any nums[i + j] where:
    
    0 <= j <= nums[i] and
    i + j < n
    
    Return the minimum number of jumps to reach nums[n - 1]. The test cases are generated such that you can reach nums[n - 1].
    
    Example 1:
    
    >>> jump(nums = [2,3,1,1,4])
    >>> 2
    Explanation: The minimum number of jumps to reach the last index is 2. Jump 1 step from index 0 to 1, then 3 steps to the last index.
    
    Example 2:
    
    >>> jump(nums = [2,3,0,1,4])
    >>> 2
    """
def permute(nums: List[int]) -> List[List[int]]:
    """
    Given an array nums of distinct integers, return all the possible permutations. You can return the answer in any order.
    
    Example 1:
    >>> permute(nums = [1,2,3])
    >>> [[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]
    Example 2:
    >>> permute(nums = [0,1])
    >>> [[0,1],[1,0]]
    Example 3:
    >>> permute(nums = [1])
    >>> [[1]]
    """
def permuteUnique(nums: List[int]) -> List[List[int]]:
    """
    Given a collection of numbers, nums, that might contain duplicates, return all possible unique permutations in any order.
    
    Example 1:
    
    >>> permuteUnique(nums = [1,1,2])
    >>>
    [[1,1,2],
     [1,2,1],
     [2,1,1]]
    
    Example 2:
    
    >>> permuteUnique(nums = [1,2,3])
    >>> [[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]
    """
def rotate(matrix: List[List[int]]) -> None:
        """
        Do not return anything, modify matrix in-place instead.
        """
    """
    You are given an n x n 2D matrix representing an image, rotate the image by 90 degrees (clockwise).
    You have to rotate the image in-place, which means you have to modify the input 2D matrix directly. DO NOT allocate another 2D matrix and do the rotation.
    
    Example 1:
    
    
    >>> rotate(matrix = [[1,2,3],[4,5,6],[7,8,9]])
    >>> [[7,4,1],[8,5,2],[9,6,3]]
    
    Example 2:
    
    
    >>> rotate(matrix = [[5,1,9,11],[2,4,8,10],[13,3,6,7],[15,14,12,16]])
    >>> [[15,13,2,5],[14,3,4,1],[12,6,8,9],[16,7,10,11]]
    """
def groupAnagrams(strs: List[str]) -> List[List[str]]:
    """
    Given an array of strings strs, group the anagrams together. You can return the answer in any order.
    
    Example 1:
    
    >>> groupAnagrams(strs = ["eat","tea","tan","ate","nat","bat"])
    >>> [["bat"],["nat","tan"],["ate","eat","tea"]]
    Explanation:
    
    There is no string in strs that can be rearranged to form "bat".
    The strings "nat" and "tan" are anagrams as they can be rearranged to form each other.
    The strings "ate", "eat", and "tea" are anagrams as they can be rearranged to form each other.
    
    
    Example 2:
    
    >>> groupAnagrams(strs = [""])
    >>> [[""]]
    
    Example 3:
    
    >>> groupAnagrams(strs = ["a"])
    >>> [["a"]]
    """
def myPow(x: float, n: int) -> float:
    """
    Implement pow(x, n), which calculates x raised to the power n (i.e., xn).
    
    Example 1:
    
    >>> myPow(x = 2.00000, n = 10)
    >>> 1024.00000
    
    Example 2:
    
    >>> myPow(x = 2.10000, n = 3)
    >>> 9.26100
    
    Example 3:
    
    >>> myPow(x = 2.00000, n = -2)
    >>> 0.25000
    Explanation: 2-2 = 1/22 = 1/4 = 0.25
    """
def solveNQueens(n: int) -> List[List[str]]:
    """
    The n-queens puzzle is the problem of placing n queens on an n x n chessboard such that no two queens attack each other.
    Given an integer n, return all distinct solutions to the n-queens puzzle. You may return the answer in any order.
    Each solution contains a distinct board configuration of the n-queens' placement, where 'Q' and '.' both indicate a queen and an empty space, respectively.
    
    Example 1:
    
    
    >>> solveNQueens(n = 4)
    >>> [[".Q..","...Q","Q...","..Q."],["..Q.","Q...","...Q",".Q.."]]
    Explanation: There exist two distinct solutions to the 4-queens puzzle as shown above
    
    Example 2:
    
    >>> solveNQueens(n = 1)
    >>> [["Q"]]
    """
def totalNQueens(n: int) -> int:
    """
    The n-queens puzzle is the problem of placing n queens on an n x n chessboard such that no two queens attack each other.
    Given an integer n, return the number of distinct solutions to the n-queens puzzle.
    
    Example 1:
    
    
    >>> totalNQueens(n = 4)
    >>> 2
    Explanation: There are two distinct solutions to the 4-queens puzzle as shown.
    
    Example 2:
    
    >>> totalNQueens(n = 1)
    >>> 1
    """
def maxSubArray(nums: List[int]) -> int:
    """
    Given an integer array nums, find the subarray with the largest sum, and return its sum.
    
    Example 1:
    
    >>> maxSubArray(nums = [-2,1,-3,4,-1,2,1,-5,4])
    >>> 6
    Explanation: The subarray [4,-1,2,1] has the largest sum 6.
    
    Example 2:
    
    >>> maxSubArray(nums = [1])
    >>> 1
    Explanation: The subarray [1] has the largest sum 1.
    
    Example 3:
    
    >>> maxSubArray(nums = [5,4,-1,7,8])
    >>> 23
    Explanation: The subarray [5,4,-1,7,8] has the largest sum 23.
    """
def spiralOrder(matrix: List[List[int]]) -> List[int]:
    """
    Given an m x n matrix, return all elements of the matrix in spiral order.
    
    Example 1:
    
    
    >>> spiralOrder(matrix = [[1,2,3],[4,5,6],[7,8,9]])
    >>> [1,2,3,6,9,8,7,4,5]
    
    Example 2:
    
    
    >>> spiralOrder(matrix = [[1,2,3,4],[5,6,7,8],[9,10,11,12]])
    >>> [1,2,3,4,8,12,11,10,9,5,6,7]
    """
def canJump(nums: List[int]) -> bool:
    """
    You are given an integer array nums. You are initially positioned at the array's first index, and each element in the array represents your maximum jump length at that position.
    Return true if you can reach the last index, or false otherwise.
    
    Example 1:
    
    >>> canJump(nums = [2,3,1,1,4])
    >>> true
    Explanation: Jump 1 step from index 0 to 1, then 3 steps to the last index.
    
    Example 2:
    
    >>> canJump(nums = [3,2,1,0,4])
    >>> false
    Explanation: You will always arrive at index 3 no matter what. Its maximum jump length is 0, which makes it impossible to reach the last index.
    """
def merge(intervals: List[List[int]]) -> List[List[int]]:
    """
    Given an array of intervals where intervals[i] = [starti, endi], merge all overlapping intervals, and return an array of the non-overlapping intervals that cover all the intervals in the input.
    
    Example 1:
    
    >>> merge(intervals = [[1,3],[2,6],[8,10],[15,18]])
    >>> [[1,6],[8,10],[15,18]]
    Explanation: Since intervals [1,3] and [2,6] overlap, merge them into [1,6].
    
    Example 2:
    
    >>> merge(intervals = [[1,4],[4,5]])
    >>> [[1,5]]
    Explanation: Intervals [1,4] and [4,5] are considered overlapping.
    """
def insert(intervals: List[List[int]], newInterval: List[int]) -> List[List[int]]:
    """
    You are given an array of non-overlapping intervals intervals where intervals[i] = [starti, endi] represent the start and the end of the ith interval and intervals is sorted in ascending order by starti. You are also given an interval newInterval = [start, end] that represents the start and end of another interval.
    Insert newInterval into intervals such that intervals is still sorted in ascending order by starti and intervals still does not have any overlapping intervals (merge overlapping intervals if necessary).
    Return intervals after the insertion.
    Note that you don't need to modify intervals in-place. You can make a new array and return it.
    
    Example 1:
    
    >>> insert(intervals = [[1,3],[6,9]], newInterval = [2,5])
    >>> [[1,5],[6,9]]
    
    Example 2:
    
    >>> insert(intervals = [[1,2],[3,5],[6,7],[8,10],[12,16]], newInterval = [4,8])
    >>> [[1,2],[3,10],[12,16]]
    Explanation: Because the new interval [4,8] overlaps with [3,5],[6,7],[8,10].
    """