ShwStone/humaneval-leetcode huggingface dataset:
def totalFruit(fruits: List[int]) -> int:
    """
    You are visiting a farm that has a single row of fruit trees arranged from left to right. The trees are represented by an integer array fruits where fruits[i] is the type of fruit the ith tree produces.
    You want to collect as much fruit as possible. However, the owner has some strict rules that you must follow:
    
    You only have two baskets, and each basket can only hold a single type of fruit. There is no limit on the amount of fruit each basket can hold.
    Starting from any tree of your choice, you must pick exactly one fruit from every tree (including the start tree) while moving to the right. The picked fruits must fit in one of your baskets.
    Once you reach a tree with fruit that cannot fit in your baskets, you must stop.
    
    Given the integer array fruits, return the maximum number of fruits you can pick.
    
    Example 1:
    
    >>> totalFruit(fruits = [1,2,1])
    >>> 3
    Explanation: We can pick from all 3 trees.
    
    Example 2:
    
    >>> totalFruit(fruits = [0,1,2,2])
    >>> 3
    Explanation: We can pick from trees [1,2,2].
    If we had started at the first tree, we would only pick from trees [0,1].
    
    Example 3:
    
    >>> totalFruit(fruits = [1,2,3,2,2])
    >>> 4
    Explanation: We can pick from trees [2,3,2,2].
    If we had started at the first tree, we would only pick from trees [1,2].
    """
def sortArrayByParity(nums: List[int]) -> List[int]:
    """
    Given an integer array nums, move all the even integers at the beginning of the array followed by all the odd integers.
    Return any array that satisfies this condition.
    
    Example 1:
    
    >>> sortArrayByParity(nums = [3,1,2,4])
    >>> [2,4,3,1]
    Explanation: The outputs [4,2,3,1], [2,4,1,3], and [4,2,1,3] would also be accepted.
    
    Example 2:
    
    >>> sortArrayByParity(nums = [0])
    >>> [0]
    """
def superpalindromesInRange(left: str, right: str) -> int:
    """
    Let's say a positive integer is a super-palindrome if it is a palindrome, and it is also the square of a palindrome.
    Given two positive integers left and right represented as strings, return the number of super-palindromes integers in the inclusive range [left, right].
    
    Example 1:
    
    >>> superpalindromesInRange(left = "4", right = "1000")
    >>> 4
    Explanation: 4, 9, 121, and 484 are superpalindromes.
    Note that 676 is not a superpalindrome: 26 * 26 = 676, but 26 is not a palindrome.
    
    Example 2:
    
    >>> superpalindromesInRange(left = "1", right = "2")
    >>> 1
    """
def sumSubarrayMins(arr: List[int]) -> int:
    """
    Given an array of integers arr, find the sum of min(b), where b ranges over every (contiguous) subarray of arr. Since the answer may be large, return the answer modulo 109 + 7.
    
    Example 1:
    
    >>> sumSubarrayMins(arr = [3,1,2,4])
    >>> 17
    Explanation:
    Subarrays are [3], [1], [2], [4], [3,1], [1,2], [2,4], [3,1,2], [1,2,4], [3,1,2,4].
    Minimums are 3, 1, 2, 4, 1, 1, 2, 1, 1, 1.
    Sum is 17.
    
    Example 2:
    
    >>> sumSubarrayMins(arr = [11,81,94,43,3])
    >>> 444
    """
def smallestRangeI(nums: List[int], k: int) -> int:
    """
    You are given an integer array nums and an integer k.
    In one operation, you can choose any index i where 0 <= i < nums.length and change nums[i] to nums[i] + x where x is an integer from the range [-k, k]. You can apply this operation at most once for each index i.
    The score of nums is the difference between the maximum and minimum elements in nums.
    Return the minimum score of nums after applying the mentioned operation at most once for each index in it.
    
    Example 1:
    
    >>> smallestRangeI(nums = [1], k = 0)
    >>> 0
    Explanation: The score is max(nums) - min(nums) = 1 - 1 = 0.
    
    Example 2:
    
    >>> smallestRangeI(nums = [0,10], k = 2)
    >>> 6
    Explanation: Change nums to be [2, 8]. The score is max(nums) - min(nums) = 8 - 2 = 6.
    
    Example 3:
    
    >>> smallestRangeI(nums = [1,3,6], k = 3)
    >>> 0
    Explanation: Change nums to be [4, 4, 4]. The score is max(nums) - min(nums) = 4 - 4 = 0.
    """
def snakesAndLadders(board: List[List[int]]) -> int:
    """
    You are given an n x n integer matrix board where the cells are labeled from 1 to n2 in a Boustrophedon style starting from the bottom left of the board (i.e. board[n - 1][0]) and alternating direction each row.
    You start on square 1 of the board. In each move, starting from square curr, do the following:
    
    Choose a destination square next with a label in the range [curr + 1, min(curr + 6, n2)].
    
    
    This choice simulates the result of a standard 6-sided die roll: i.e., there are always at most 6 destinations, regardless of the size of the board.
    
    
    If next has a snake or ladder, you must move to the destination of that snake or ladder. Otherwise, you move to next.
    The game ends when you reach the square n2.
    
    A board square on row r and column c has a snake or ladder if board[r][c] != -1. The destination of that snake or ladder is board[r][c]. Squares 1 and n2 are not the starting points of any snake or ladder.
    Note that you only take a snake or ladder at most once per dice roll. If the destination to a snake or ladder is the start of another snake or ladder, you do not follow the subsequent snake or ladder.
    
    For example, suppose the board is [[-1,4],[-1,3]], and on the first move, your destination square is 2. You follow the ladder to square 3, but do not follow the subsequent ladder to 4.
    
    Return the least number of dice rolls required to reach the square n2. If it is not possible to reach the square, return -1.
    
    Example 1:
    
    
    >>> snakesAndLadders(board = [[-1,-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1],[-1,35,-1,-1,13,-1],[-1,-1,-1,-1,-1,-1],[-1,15,-1,-1,-1,-1]])
    >>> 4
    Explanation:
    In the beginning, you start at square 1 (at row 5, column 0).
    You decide to move to square 2 and must take the ladder to square 15.
    You then decide to move to square 17 and must take the snake to square 13.
    You then decide to move to square 14 and must take the ladder to square 35.
    You then decide to move to square 36, ending the game.
    This is the lowest possible number of moves to reach the last square, so return 4.
    
    Example 2:
    
    >>> snakesAndLadders(board = [[-1,-1],[-1,3]])
    >>> 1
    """
def smallestRangeII(nums: List[int], k: int) -> int:
    """
    You are given an integer array nums and an integer k.
    For each index i where 0 <= i < nums.length, change nums[i] to be either nums[i] + k or nums[i] - k.
    The score of nums is the difference between the maximum and minimum elements in nums.
    Return the minimum score of nums after changing the values at each index.
    
    Example 1:
    
    >>> smallestRangeII(nums = [1], k = 0)
    >>> 0
    Explanation: The score is max(nums) - min(nums) = 1 - 1 = 0.
    
    Example 2:
    
    >>> smallestRangeII(nums = [0,10], k = 2)
    >>> 6
    Explanation: Change nums to be [2, 8]. The score is max(nums) - min(nums) = 8 - 2 = 6.
    
    Example 3:
    
    >>> smallestRangeII(nums = [1,3,6], k = 3)
    >>> 3
    Explanation: Change nums to be [4, 6, 3]. The score is max(nums) - min(nums) = 6 - 3 = 3.
    """
def sortArray(nums: List[int]) -> List[int]:
    """
    Given an array of integers nums, sort the array in ascending order and return it.
    You must solve the problem without using any built-in functions in O(nlog(n)) time complexity and with the smallest space complexity possible.
    
    Example 1:
    
    >>> sortArray(nums = [5,2,3,1])
    >>> [1,2,3,5]
    Explanation: After sorting the array, the positions of some numbers are not changed (for example, 2 and 3), while the positions of other numbers are changed (for example, 1 and 5).
    
    Example 2:
    
    >>> sortArray(nums = [5,1,1,2,0,0])
    >>> [0,0,1,1,2,5]
    Explanation: Note that the values of nums are not necessairly unique.
    """
def catMouseGame(graph: List[List[int]]) -> int:
    """
    A game on an undirected graph is played by two players, Mouse and Cat, who alternate turns.
    The graph is given as follows: graph[a] is a list of all nodes b such that ab is an edge of the graph.
    The mouse starts at node 1 and goes first, the cat starts at node 2 and goes second, and there is a hole at node 0.
    During each player's turn, they must travel along one edge of the graph that meets where they are.  For example, if the Mouse is at node 1, it must travel to any node in graph[1].
    Additionally, it is not allowed for the Cat to travel to the Hole (node 0).
    Then, the game can end in three ways:
    
    If ever the Cat occupies the same node as the Mouse, the Cat wins.
    If ever the Mouse reaches the Hole, the Mouse wins.
    If ever a position is repeated (i.e., the players are in the same position as a previous turn, and it is the same player's turn to move), the game is a draw.
    
    Given a graph, and assuming both players play optimally, return
    
    1 if the mouse wins the game,
    2 if the cat wins the game, or
    0 if the game is a draw.
    
    
    Example 1:
    
    
    >>> catMouseGame(graph = [[2,5],[3],[0,4,5],[1,4,5],[2,3],[0,2,3]])
    >>> 0
    
    Example 2:
    
    
    >>> catMouseGame(graph = [[1,3],[0],[3],[0,2]])
    >>> 1
    """
def hasGroupsSizeX(deck: List[int]) -> bool:
    """
    You are given an integer array deck where deck[i] represents the number written on the ith card.
    Partition the cards into one or more groups such that:
    
    Each group has exactly x cards where x > 1, and
    All the cards in one group have the same integer written on them.
    
    Return true if such partition is possible, or false otherwise.
    
    Example 1:
    
    >>> hasGroupsSizeX(deck = [1,2,3,4,4,3,2,1])
    >>> true
    Explanation: Possible partition [1,1],[2,2],[3,3],[4,4].
    
    Example 2:
    
    >>> hasGroupsSizeX(deck = [1,1,1,2,2,2,3,3])
    >>> false
    Explanation: No possible partition.
    """
def partitionDisjoint(nums: List[int]) -> int:
    """
    Given an integer array nums, partition it into two (contiguous) subarrays left and right so that:
    
    Every element in left is less than or equal to every element in right.
    left and right are non-empty.
    left has the smallest possible size.
    
    Return the length of left after such a partitioning.
    Test cases are generated such that partitioning exists.
    
    Example 1:
    
    >>> partitionDisjoint(nums = [5,0,3,8,6])
    >>> 3
    Explanation: left = [5,0,3], right = [8,6]
    
    Example 2:
    
    >>> partitionDisjoint(nums = [1,1,1,0,6,12])
    >>> 4
    Explanation: left = [1,1,1,0], right = [6,12]
    """
def wordSubsets(words1: List[str], words2: List[str]) -> List[str]:
    """
    You are given two string arrays words1 and words2.
    A string b is a subset of string a if every letter in b occurs in a including multiplicity.
    
    For example, "wrr" is a subset of "warrior" but is not a subset of "world".
    
    A string a from words1 is universal if for every string b in words2, b is a subset of a.
    Return an array of all the universal strings in words1. You may return the answer in any order.
    
    Example 1:
    
    >>> wordSubsets(words1 = ["amazon","apple","facebook","google","leetcode"], words2 = ["e","o"])
    >>> ["facebook","google","leetcode"]
    
    Example 2:
    
    >>> wordSubsets(words1 = ["amazon","apple","facebook","google","leetcode"], words2 = ["lc","eo"])
    >>> ["leetcode"]
    
    Example 3:
    
    >>> wordSubsets(words1 = ["acaac","cccbb","aacbb","caacc","bcbbb"], words2 = ["c","cc","b"])
    >>> ["cccbb"]
    """
def reverseOnlyLetters(s: str) -> str:
    """
    Given a string s, reverse the string according to the following rules:
    
    All the characters that are not English letters remain in the same position.
    All the English letters (lowercase or uppercase) should be reversed.
    
    Return s after reversing it.
    
    Example 1:
    >>> reverseOnlyLetters(s = "ab-cd")
    >>> "dc-ba"
    Example 2:
    >>> reverseOnlyLetters(s = "a-bC-dEf-ghIj")
    >>> "j-Ih-gfE-dCba"
    Example 3:
    >>> reverseOnlyLetters(s = "Test1ng-Leet=code-Q!")
    >>> "Qedo1ct-eeLg=ntse-T!"
    """
def maxSubarraySumCircular(nums: List[int]) -> int:
    """
    Given a circular integer array nums of length n, return the maximum possible sum of a non-empty subarray of nums.
    A circular array means the end of the array connects to the beginning of the array. Formally, the next element of nums[i] is nums[(i + 1) % n] and the previous element of nums[i] is nums[(i - 1 + n) % n].
    A subarray may only include each element of the fixed buffer nums at most once. Formally, for a subarray nums[i], nums[i + 1], ..., nums[j], there does not exist i <= k1, k2 <= j with k1 % n == k2 % n.
    
    Example 1:
    
    >>> maxSubarraySumCircular(nums = [1,-2,3,-2])
    >>> 3
    Explanation: Subarray [3] has maximum sum 3.
    
    Example 2:
    
    >>> maxSubarraySumCircular(nums = [5,-3,5])
    >>> 10
    Explanation: Subarray [5,5] has maximum sum 5 + 5 = 10.
    
    Example 3:
    
    >>> maxSubarraySumCircular(nums = [-3,-2,-3])
    >>> -2
    Explanation: Subarray [-2] has maximum sum -2.
    """
def numMusicPlaylists(n: int, goal: int, k: int) -> int:
    """
    Your music player contains n different songs. You want to listen to goal songs (not necessarily different) during your trip. To avoid boredom, you will create a playlist so that:
    
    Every song is played at least once.
    A song can only be played again only if k other songs have been played.
    
    Given n, goal, and k, return the number of possible playlists that you can create. Since the answer can be very large, return it modulo 109 + 7.
    
    Example 1:
    
    >>> numMusicPlaylists(n = 3, goal = 3, k = 1)
    >>> 6
    Explanation: There are 6 possible playlists: [1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], and [3, 2, 1].
    
    Example 2:
    
    >>> numMusicPlaylists(n = 2, goal = 3, k = 0)
    >>> 6
    Explanation: There are 6 possible playlists: [1, 1, 2], [1, 2, 1], [2, 1, 1], [2, 2, 1], [2, 1, 2], and [1, 2, 2].
    
    Example 3:
    
    >>> numMusicPlaylists(n = 2, goal = 3, k = 1)
    >>> 2
    Explanation: There are 2 possible playlists: [1, 2, 1] and [2, 1, 2].
    """
def minAddToMakeValid(s: str) -> int:
    """
    A parentheses string is valid if and only if:
    
    It is the empty string,
    It can be written as AB (A concatenated with B), where A and B are valid strings, or
    It can be written as (A), where A is a valid string.
    
    You are given a parentheses string s. In one move, you can insert a parenthesis at any position of the string.
    
    For example, if s = "()))", you can insert an opening parenthesis to be "(()))" or a closing parenthesis to be "())))".
    
    Return the minimum number of moves required to make s valid.
    
    Example 1:
    
    >>> minAddToMakeValid(s = "())")
    >>> 1
    
    Example 2:
    
    >>> minAddToMakeValid(s = "(((")
    >>> 3
    """
def sortArrayByParityII(nums: List[int]) -> List[int]:
    """
    Given an array of integers nums, half of the integers in nums are odd, and the other half are even.
    Sort the array so that whenever nums[i] is odd, i is odd, and whenever nums[i] is even, i is even.
    Return any answer array that satisfies this condition.
    
    Example 1:
    
    >>> sortArrayByParityII(nums = [4,2,5,7])
    >>> [4,5,2,7]
    Explanation: [4,7,2,5], [2,5,4,7], [2,7,4,5] would also have been accepted.
    
    Example 2:
    
    >>> sortArrayByParityII(nums = [2,3])
    >>> [2,3]
    """
def threeSumMulti(arr: List[int], target: int) -> int:
    """
    Given an integer array arr, and an integer target, return the number of tuples i, j, k such that i < j < k and arr[i] + arr[j] + arr[k] == target.
    As the answer can be very large, return it modulo 109 + 7.
    
    Example 1:
    
    >>> threeSumMulti(arr = [1,1,2,2,3,3,4,4,5,5], target = 8)
    >>> 20
    Explanation:
    Enumerating by the values (arr[i], arr[j], arr[k]):
    (1, 2, 5) occurs 8 times;
    (1, 3, 4) occurs 8 times;
    (2, 2, 4) occurs 2 times;
    (2, 3, 3) occurs 2 times.
    
    Example 2:
    
    >>> threeSumMulti(arr = [1,1,2,2,2,2], target = 5)
    >>> 12
    Explanation:
    arr[i] = 1, arr[j] = arr[k] = 2 occurs 12 times:
    We choose one 1 from [1,1] in 2 ways,
    and two 2s from [2,2,2,2] in 6 ways.
    
    Example 3:
    
    >>> threeSumMulti(arr = [2,1,3], target = 6)
    >>> 1
    Explanation: (1, 2, 3) occured one time in the array so we return 1.
    """
def minMalwareSpread(graph: List[List[int]], initial: List[int]) -> int:
    """
    You are given a network of n nodes represented as an n x n adjacency matrix graph, where the ith node is directly connected to the jth node if graph[i][j] == 1.
    Some nodes initial are initially infected by malware. Whenever two nodes are directly connected, and at least one of those two nodes is infected by malware, both nodes will be infected by malware. This spread of malware will continue until no more nodes can be infected in this manner.
    Suppose M(initial) is the final number of nodes infected with malware in the entire network after the spread of malware stops. We will remove exactly one node from initial.
    Return the node that, if removed, would minimize M(initial). If multiple nodes could be removed to minimize M(initial), return such a node with the smallest index.
    Note that if a node was removed from the initial list of infected nodes, it might still be infected later due to the malware spread.
    
    Example 1:
    >>> minMalwareSpread(graph = [[1,1,0],[1,1,0],[0,0,1]], initial = [0,1])
    >>> 0
    Example 2:
    >>> minMalwareSpread(graph = [[1,0,0],[0,1,0],[0,0,1]], initial = [0,2])
    >>> 0
    Example 3:
    >>> minMalwareSpread(graph = [[1,1,1],[1,1,1],[1,1,1]], initial = [1,2])
    >>> 1
    """
def isLongPressedName(name: str, typed: str) -> bool:
    """
    Your friend is typing his name into a keyboard. Sometimes, when typing a character c, the key might get long pressed, and the character will be typed 1 or more times.
    You examine the typed characters of the keyboard. Return True if it is possible that it was your friends name, with some characters (possibly none) being long pressed.
    
    Example 1:
    
    >>> isLongPressedName(name = "alex", typed = "aaleex")
    >>> true
    Explanation: 'a' and 'e' in 'alex' were long pressed.
    
    Example 2:
    
    >>> isLongPressedName(name = "saeed", typed = "ssaaedd")
    >>> false
    Explanation: 'e' must have been pressed twice, but it was not in the typed output.
    """
def minFlipsMonoIncr(s: str) -> int:
    """
    A binary string is monotone increasing if it consists of some number of 0's (possibly none), followed by some number of 1's (also possibly none).
    You are given a binary string s. You can flip s[i] changing it from 0 to 1 or from 1 to 0.
    Return the minimum number of flips to make s monotone increasing.
    
    Example 1:
    
    >>> minFlipsMonoIncr(s = "00110")
    >>> 1
    Explanation: We flip the last digit to get 00111.
    
    Example 2:
    
    >>> minFlipsMonoIncr(s = "010110")
    >>> 2
    Explanation: We flip to get 011111, or alternatively 000111.
    
    Example 3:
    
    >>> minFlipsMonoIncr(s = "00011000")
    >>> 2
    Explanation: We flip to get 00000000.
    """
def threeEqualParts(arr: List[int]) -> List[int]:
    """
    You are given an array arr which consists of only zeros and ones, divide the array into three non-empty parts such that all of these parts represent the same binary value.
    If it is possible, return any [i, j] with i + 1 < j, such that:
    
    arr[0], arr[1], ..., arr[i] is the first part,
    arr[i + 1], arr[i + 2], ..., arr[j - 1] is the second part, and
    arr[j], arr[j + 1], ..., arr[arr.length - 1] is the third part.
    All three parts have equal binary values.
    
    If it is not possible, return [-1, -1].
    Note that the entire part is used when considering what binary value it represents. For example, [1,1,0] represents 6 in decimal, not 3. Also, leading zeros are allowed, so [0,1,1] and [1,1] represent the same value.
    
    Example 1:
    >>> threeEqualParts(arr = [1,0,1,0,1])
    >>> [0,3]
    Example 2:
    >>> threeEqualParts(arr = [1,1,0,1,1])
    >>> [-1,-1]
    Example 3:
    >>> threeEqualParts(arr = [1,1,0,0,1])
    >>> [0,2]
    """
def minMalwareSpread(graph: List[List[int]], initial: List[int]) -> int:
    """
    You are given a network of n nodes represented as an n x n adjacency matrix graph, where the ith node is directly connected to the jth node if graph[i][j] == 1.
    Some nodes initial are initially infected by malware. Whenever two nodes are directly connected, and at least one of those two nodes is infected by malware, both nodes will be infected by malware. This spread of malware will continue until no more nodes can be infected in this manner.
    Suppose M(initial) is the final number of nodes infected with malware in the entire network after the spread of malware stops.
    We will remove exactly one node from initial, completely removing it and any connections from this node to any other node.
    Return the node that, if removed, would minimize M(initial). If multiple nodes could be removed to minimize M(initial), return such a node with the smallest index.
    
    Example 1:
    >>> minMalwareSpread(graph = [[1,1,0],[1,1,0],[0,0,1]], initial = [0,1])
    >>> 0
    Example 2:
    >>> minMalwareSpread(graph = [[1,1,0],[1,1,1],[0,1,1]], initial = [0,1])
    >>> 1
    Example 3:
    >>> minMalwareSpread(graph = [[1,1,0,0],[1,1,1,0],[0,1,1,1],[0,0,1,1]], initial = [0,1])
    >>> 1
    """
def numUniqueEmails(emails: List[str]) -> int:
    """
    Every valid email consists of a local name and a domain name, separated by the '@' sign. Besides lowercase letters, the email may contain one or more '.' or '+'.
    
    For example, in "alice@leetcode.com", "alice" is the local name, and "leetcode.com" is the domain name.
    
    If you add periods '.' between some characters in the local name part of an email address, mail sent there will be forwarded to the same address without dots in the local name. Note that this rule does not apply to domain names.
    
    For example, "alice.z@leetcode.com" and "alicez@leetcode.com" forward to the same email address.
    
    If you add a plus '+' in the local name, everything after the first plus sign will be ignored. This allows certain emails to be filtered. Note that this rule does not apply to domain names.
    
    For example, "m.y+name@email.com" will be forwarded to "my@email.com".
    
    It is possible to use both of these rules at the same time.
    Given an array of strings emails where we send one email to each emails[i], return the number of different addresses that actually receive mails.
    
    Example 1:
    
    >>> numUniqueEmails(emails = ["test.email+alex@leetcode.com","test.e.mail+bob.cathy@leetcode.com","testemail+david@lee.tcode.com"])
    >>> 2
    Explanation: "testemail@leetcode.com" and "testemail@lee.tcode.com" actually receive mails.
    
    Example 2:
    
    >>> numUniqueEmails(emails = ["a@leetcode.com","b@leetcode.com","c@leetcode.com"])
    >>> 3
    """
def numSubarraysWithSum(nums: List[int], goal: int) -> int:
    """
    Given a binary array nums and an integer goal, return the number of non-empty subarrays with a sum goal.
    A subarray is a contiguous part of the array.
    
    Example 1:
    
    >>> numSubarraysWithSum(nums = [1,0,1,0,1], goal = 2)
    >>> 4
    Explanation: The 4 subarrays are bolded and underlined below:
    [1,0,1,0,1]
    [1,0,1,0,1]
    [1,0,1,0,1]
    [1,0,1,0,1]
    
    Example 2:
    
    >>> numSubarraysWithSum(nums = [0,0,0,0,0], goal = 0)
    >>> 15
    """