ShwStone/humaneval-leetcode huggingface dataset:
def findLonely(nums: List[int]) -> List[int]:
    """
    You are given an integer array nums. A number x is lonely when it appears only once, and no adjacent numbers (i.e. x + 1 and x - 1) appear in the array.
    Return all lonely numbers in nums. You may return the answer in any order.
    
    Example 1:
    
    >>> findLonely(nums = [10,6,5,8])
    >>> [10,8]
    Explanation:
    - 10 is a lonely number since it appears exactly once and 9 and 11 does not appear in nums.
    - 8 is a lonely number since it appears exactly once and 7 and 9 does not appear in nums.
    - 5 is not a lonely number since 6 appears in nums and vice versa.
    Hence, the lonely numbers in nums are [10, 8].
    Note that [8, 10] may also be returned.
    
    Example 2:
    
    >>> findLonely(nums = [1,3,5,3])
    >>> [1,5]
    Explanation:
    - 1 is a lonely number since it appears exactly once and 0 and 2 does not appear in nums.
    - 5 is a lonely number since it appears exactly once and 4 and 6 does not appear in nums.
    - 3 is not a lonely number since it appears twice.
    Hence, the lonely numbers in nums are [1, 5].
    Note that [5, 1] may also be returned.
    """
def minimumLines(points: List[List[int]]) -> int:
    """
    You are given an array points where points[i] = [xi, yi] represents a point on an X-Y plane.
    Straight lines are going to be added to the X-Y plane, such that every point is covered by at least one line.
    Return the minimum number of straight lines needed to cover all the points.
    
    Example 1:
    
    
    >>> minimumLines(points = [[0,1],[2,3],[4,5],[4,3]])
    >>> 2
    Explanation: The minimum number of straight lines needed is two. One possible solution is to add:
    - One line connecting the point at (0, 1) to the point at (4, 5).
    - Another line connecting the point at (2, 3) to the point at (4, 3).
    
    Example 2:
    
    
    >>> minimumLines(points = [[0,2],[-2,-2],[1,4]])
    >>> 1
    Explanation: The minimum number of straight lines needed is one. The only solution is to add:
    - One line connecting the point at (-2, -2) to the point at (1, 4).
    """
def findFinalValue(nums: List[int], original: int) -> int:
    """
    You are given an array of integers nums. You are also given an integer original which is the first number that needs to be searched for in nums.
    You then do the following steps:
    
    If original is found in nums, multiply it by two (i.e., set original = 2 * original).
    Otherwise, stop the process.
    Repeat this process with the new number as long as you keep finding the number.
    
    Return the final value of original.
    
    Example 1:
    
    >>> findFinalValue(nums = [5,3,6,1,12], original = 3)
    >>> 24
    Explanation:
    - 3 is found in nums. 3 is multiplied by 2 to obtain 6.
    - 6 is found in nums. 6 is multiplied by 2 to obtain 12.
    - 12 is found in nums. 12 is multiplied by 2 to obtain 24.
    - 24 is not found in nums. Thus, 24 is returned.
    
    Example 2:
    
    >>> findFinalValue(nums = [2,7,9], original = 4)
    >>> 4
    Explanation:
    - 4 is not found in nums. Thus, 4 is returned.
    """
def maxScoreIndices(nums: List[int]) -> List[int]:
    """
    You are given a 0-indexed binary array nums of length n. nums can be divided at index i (where 0 <= i <= n) into two arrays (possibly empty) numsleft and numsright:
    
    numsleft has all the elements of nums between index 0 and i - 1 (inclusive), while numsright has all the elements of nums between index i and n - 1 (inclusive).
    If i == 0, numsleft is empty, while numsright has all the elements of nums.
    If i == n, numsleft has all the elements of nums, while numsright is empty.
    
    The division score of an index i is the sum of the number of 0's in numsleft and the number of 1's in numsright.
    Return all distinct indices that have the highest possible division score. You may return the answer in any order.
    
    Example 1:
    
    >>> maxScoreIndices(nums = [0,0,1,0])
    >>> [2,4]
    Explanation: Division at index
    - 0: numsleft is []. numsright is [0,0,1,0]. The score is 0 + 1 = 1.
    - 1: numsleft is [0]. numsright is [0,1,0]. The score is 1 + 1 = 2.
    - 2: numsleft is [0,0]. numsright is [1,0]. The score is 2 + 1 = 3.
    - 3: numsleft is [0,0,1]. numsright is [0]. The score is 2 + 0 = 2.
    - 4: numsleft is [0,0,1,0]. numsright is []. The score is 3 + 0 = 3.
    Indices 2 and 4 both have the highest possible division score 3.
    Note the answer [4,2] would also be accepted.
    Example 2:
    
    >>> maxScoreIndices(nums = [0,0,0])
    >>> [3]
    Explanation: Division at index
    - 0: numsleft is []. numsright is [0,0,0]. The score is 0 + 0 = 0.
    - 1: numsleft is [0]. numsright is [0,0]. The score is 1 + 0 = 1.
    - 2: numsleft is [0,0]. numsright is [0]. The score is 2 + 0 = 2.
    - 3: numsleft is [0,0,0]. numsright is []. The score is 3 + 0 = 3.
    Only index 3 has the highest possible division score 3.
    
    Example 3:
    
    >>> maxScoreIndices(nums = [1,1])
    >>> [0]
    Explanation: Division at index
    - 0: numsleft is []. numsright is [1,1]. The score is 0 + 2 = 2.
    - 1: numsleft is [1]. numsright is [1]. The score is 0 + 1 = 1.
    - 2: numsleft is [1,1]. numsright is []. The score is 0 + 0 = 0.
    Only index 0 has the highest possible division score 2.
    """
def subStrHash(s: str, power: int, modulo: int, k: int, hashValue: int) -> str:
    """
    The hash of a 0-indexed string s of length k, given integers p and m, is computed using the following function:
    
    hash(s, p, m) = (val(s[0]) * p0 + val(s[1]) * p1 + ... + val(s[k-1]) * pk-1) mod m.
    
    Where val(s[i]) represents the index of s[i] in the alphabet from val('a') = 1 to val('z') = 26.
    You are given a string s and the integers power, modulo, k, and hashValue. Return sub, the first substring of s of length k such that hash(sub, power, modulo) == hashValue.
    The test cases will be generated such that an answer always exists.
    A substring is a contiguous non-empty sequence of characters within a string.
    
    Example 1:
    
    >>> subStrHash(s = "leetcode", power = 7, modulo = 20, k = 2, hashValue = 0)
    >>> "ee"
    Explanation: The hash of "ee" can be computed to be hash("ee", 7, 20) = (5 * 1 + 5 * 7) mod 20 = 40 mod 20 = 0.
    "ee" is the first substring of length 2 with hashValue 0. Hence, we return "ee".
    
    Example 2:
    
    >>> subStrHash(s = "fbxzaad", power = 31, modulo = 100, k = 3, hashValue = 32)
    >>> "fbx"
    Explanation: The hash of "fbx" can be computed to be hash("fbx", 31, 100) = (6 * 1 + 2 * 31 + 24 * 312) mod 100 = 23132 mod 100 = 32.
    The hash of "bxz" can be computed to be hash("bxz", 31, 100) = (2 * 1 + 24 * 31 + 26 * 312) mod 100 = 25732 mod 100 = 32.
    "fbx" is the first substring of length 3 with hashValue 32. Hence, we return "fbx".
    Note that "bxz" also has a hash of 32 but it appears later than "fbx".
    """
def groupStrings(words: List[str]) -> List[int]:
    """
    You are given a 0-indexed array of strings words. Each string consists of lowercase English letters only. No letter occurs more than once in any string of words.
    Two strings s1 and s2 are said to be connected if the set of letters of s2 can be obtained from the set of letters of s1 by any one of the following operations:
    
    Adding exactly one letter to the set of the letters of s1.
    Deleting exactly one letter from the set of the letters of s1.
    Replacing exactly one letter from the set of the letters of s1 with any letter, including itself.
    
    The array words can be divided into one or more non-intersecting groups. A string belongs to a group if any one of the following is true:
    
    It is connected to at least one other string of the group.
    It is the only string present in the group.
    
    Note that the strings in words should be grouped in such a manner that a string belonging to a group cannot be connected to a string present in any other group. It can be proved that such an arrangement is always unique.
    Return an array ans of size 2 where:
    
    ans[0] is the maximum number of groups words can be divided into, and
    ans[1] is the size of the largest group.
    
    
    Example 1:
    
    >>> groupStrings(words = ["a","b","ab","cde"])
    >>> [2,3]
    Explanation:
    - words[0] can be used to obtain words[1] (by replacing 'a' with 'b'), and words[2] (by adding 'b'). So words[0] is connected to words[1] and words[2].
    - words[1] can be used to obtain words[0] (by replacing 'b' with 'a'), and words[2] (by adding 'a'). So words[1] is connected to words[0] and words[2].
    - words[2] can be used to obtain words[0] (by deleting 'b'), and words[1] (by deleting 'a'). So words[2] is connected to words[0] and words[1].
    - words[3] is not connected to any string in words.
    Thus, words can be divided into 2 groups ["a","b","ab"] and ["cde"]. The size of the largest group is 3.
    
    Example 2:
    
    >>> groupStrings(words = ["a","ab","abc"])
    >>> [1,3]
    Explanation:
    - words[0] is connected to words[1].
    - words[1] is connected to words[0] and words[2].
    - words[2] is connected to words[1].
    Since all strings are connected to each other, they should be grouped together.
    Thus, the size of the largest group is 3.
    """
def amountPainted(paint: List[List[int]]) -> List[int]:
    """
    There is a long and thin painting that can be represented by a number line. You are given a 0-indexed 2D integer array paint of length n, where paint[i] = [starti, endi]. This means that on the ith day you need to paint the area between starti and endi.
    Painting the same area multiple times will create an uneven painting so you only want to paint each area of the painting at most once.
    Return an integer array worklog of length n, where worklog[i] is the amount of new area that you painted on the ith day.
    
    Example 1:
    
    
    >>> amountPainted(paint = [[1,4],[4,7],[5,8]])
    >>> [3,3,1]
    Explanation:
    On day 0, paint everything between 1 and 4.
    The amount of new area painted on day 0 is 4 - 1 = 3.
    On day 1, paint everything between 4 and 7.
    The amount of new area painted on day 1 is 7 - 4 = 3.
    On day 2, paint everything between 7 and 8.
    Everything between 5 and 7 was already painted on day 1.
    The amount of new area painted on day 2 is 8 - 7 = 1.
    
    Example 2:
    
    
    >>> amountPainted(paint = [[1,4],[5,8],[4,7]])
    >>> [3,3,1]
    Explanation:
    On day 0, paint everything between 1 and 4.
    The amount of new area painted on day 0 is 4 - 1 = 3.
    On day 1, paint everything between 5 and 8.
    The amount of new area painted on day 1 is 8 - 5 = 3.
    On day 2, paint everything between 4 and 5.
    Everything between 5 and 7 was already painted on day 1.
    The amount of new area painted on day 2 is 5 - 4 = 1.
    
    Example 3:
    
    
    >>> amountPainted(paint = [[1,5],[2,4]])
    >>> [4,0]
    Explanation:
    On day 0, paint everything between 1 and 5.
    The amount of new area painted on day 0 is 5 - 1 = 4.
    On day 1, paint nothing because everything between 2 and 4 was already painted on day 0.
    The amount of new area painted on day 1 is 0.
    """
def minimumSum(num: int) -> int:
    """
    You are given a positive integer num consisting of exactly four digits. Split num into two new integers new1 and new2 by using the digits found in num. Leading zeros are allowed in new1 and new2, and all the digits found in num must be used.
    
    For example, given num = 2932, you have the following digits: two 2's, one 9 and one 3. Some of the possible pairs [new1, new2] are [22, 93], [23, 92], [223, 9] and [2, 329].
    
    Return the minimum possible sum of new1 and new2.
    
    Example 1:
    
    >>> minimumSum(num = 2932)
    >>> 52
    Explanation: Some possible pairs [new1, new2] are [29, 23], [223, 9], etc.
    The minimum sum can be obtained by the pair [29, 23]: 29 + 23 = 52.
    
    Example 2:
    
    >>> minimumSum(num = 4009)
    >>> 13
    Explanation: Some possible pairs [new1, new2] are [0, 49], [490, 0], etc.
    The minimum sum can be obtained by the pair [4, 9]: 4 + 9 = 13.
    """
def pivotArray(nums: List[int], pivot: int) -> List[int]:
    """
    You are given a 0-indexed integer array nums and an integer pivot. Rearrange nums such that the following conditions are satisfied:
    
    Every element less than pivot appears before every element greater than pivot.
    Every element equal to pivot appears in between the elements less than and greater than pivot.
    The relative order of the elements less than pivot and the elements greater than pivot is maintained.
    
    More formally, consider every pi, pj where pi is the new position of the ith element and pj is the new position of the jth element. If i < j and both elements are smaller (or larger) than pivot, then pi < pj.
    
    
    
    Return nums after the rearrangement.
    
    Example 1:
    
    >>> pivotArray(nums = [9,12,5,10,14,3,10], pivot = 10)
    >>> [9,5,3,10,10,12,14]
    Explanation:
    The elements 9, 5, and 3 are less than the pivot so they are on the left side of the array.
    The elements 12 and 14 are greater than the pivot so they are on the right side of the array.
    The relative ordering of the elements less than and greater than pivot is also maintained. [9, 5, 3] and [12, 14] are the respective orderings.
    
    Example 2:
    
    >>> pivotArray(nums = [-3,4,3,2], pivot = 2)
    >>> [-3,2,4,3]
    Explanation:
    The element -3 is less than the pivot so it is on the left side of the array.
    The elements 4 and 3 are greater than the pivot so they are on the right side of the array.
    The relative ordering of the elements less than and greater than pivot is also maintained. [-3] and [4, 3] are the respective orderings.
    """
def minCostSetTime(startAt: int, moveCost: int, pushCost: int, targetSeconds: int) -> int:
    """
    A generic microwave supports cooking times for:
    
    at least 1 second.
    at most 99 minutes and 99 seconds.
    
    To set the cooking time, you push at most four digits. The microwave normalizes what you push as four digits by prepending zeroes. It interprets the first two digits as the minutes and the last two digits as the seconds. It then adds them up as the cooking time. For example,
    
    You push 9 5 4 (three digits). It is normalized as 0954 and interpreted as 9 minutes and 54 seconds.
    You push 0 0 0 8 (four digits). It is interpreted as 0 minutes and 8 seconds.
    You push 8 0 9 0. It is interpreted as 80 minutes and 90 seconds.
    You push 8 1 3 0. It is interpreted as 81 minutes and 30 seconds.
    
    You are given integers startAt, moveCost, pushCost, and targetSeconds. Initially, your finger is on the digit startAt. Moving the finger above any specific digit costs moveCost units of fatigue. Pushing the digit below the finger once costs pushCost units of fatigue.
    There can be multiple ways to set the microwave to cook for targetSeconds seconds but you are interested in the way with the minimum cost.
    Return the minimum cost to set targetSeconds seconds of cooking time.
    Remember that one minute consists of 60 seconds.
    
    Example 1:
    
    
    >>> minCostSetTime(startAt = 1, moveCost = 2, pushCost = 1, targetSeconds = 600)
    >>> 6
    Explanation: The following are the possible ways to set the cooking time.
    - 1 0 0 0, interpreted as 10 minutes and 0 seconds.
      The finger is already on digit 1, pushes 1 (with cost 1), moves to 0 (with cost 2), pushes 0 (with cost 1), pushes 0 (with cost 1), and pushes 0 (with cost 1).
      The cost is: 1 + 2 + 1 + 1 + 1 = 6. This is the minimum cost.
    - 0 9 6 0, interpreted as 9 minutes and 60 seconds. That is also 600 seconds.
      The finger moves to 0 (with cost 2), pushes 0 (with cost 1), moves to 9 (with cost 2), pushes 9 (with cost 1), moves to 6 (with cost 2), pushes 6 (with cost 1), moves to 0 (with cost 2), and pushes 0 (with cost 1).
      The cost is: 2 + 1 + 2 + 1 + 2 + 1 + 2 + 1 = 12.
    - 9 6 0, normalized as 0960 and interpreted as 9 minutes and 60 seconds.
      The finger moves to 9 (with cost 2), pushes 9 (with cost 1), moves to 6 (with cost 2), pushes 6 (with cost 1), moves to 0 (with cost 2), and pushes 0 (with cost 1).
      The cost is: 2 + 1 + 2 + 1 + 2 + 1 = 9.
    
    Example 2:
    
    
    >>> minCostSetTime(startAt = 0, moveCost = 1, pushCost = 2, targetSeconds = 76)
    >>> 6
    Explanation: The optimal way is to push two digits: 7 6, interpreted as 76 seconds.
    The finger moves to 7 (with cost 1), pushes 7 (with cost 2), moves to 6 (with cost 1), and pushes 6 (with cost 2). The total cost is: 1 + 2 + 1 + 2 = 6
    Note other possible ways are 0076, 076, 0116, and 116, but none of them produces the minimum cost.
    """
def minimumDifference(nums: List[int]) -> int:
    """
    You are given a 0-indexed integer array nums consisting of 3 * n elements.
    You are allowed to remove any subsequence of elements of size exactly n from nums. The remaining 2 * n elements will be divided into two equal parts:
    
    The first n elements belonging to the first part and their sum is sumfirst.
    The next n elements belonging to the second part and their sum is sumsecond.
    
    The difference in sums of the two parts is denoted as sumfirst - sumsecond.
    
    For example, if sumfirst = 3 and sumsecond = 2, their difference is 1.
    Similarly, if sumfirst = 2 and sumsecond = 3, their difference is -1.
    
    Return the minimum difference possible between the sums of the two parts after the removal of n elements.
    
    Example 1:
    
    >>> minimumDifference(nums = [3,1,2])
    >>> -1
    Explanation: Here, nums has 3 elements, so n = 1.
    Thus we have to remove 1 element from nums and divide the array into two equal parts.
    - If we remove nums[0] = 3, the array will be [1,2]. The difference in sums of the two parts will be 1 - 2 = -1.
    - If we remove nums[1] = 1, the array will be [3,2]. The difference in sums of the two parts will be 3 - 2 = 1.
    - If we remove nums[2] = 2, the array will be [3,1]. The difference in sums of the two parts will be 3 - 1 = 2.
    The minimum difference between sums of the two parts is min(-1,1,2) = -1.
    
    Example 2:
    
    >>> minimumDifference(nums = [7,9,5,8,1,3])
    >>> 1
    Explanation: Here n = 2. So we must remove 2 elements and divide the remaining array into two parts containing two elements each.
    If we remove nums[2] = 5 and nums[3] = 8, the resultant array will be [7,9,1,3]. The difference in sums will be (7+9) - (1+3) = 12.
    To obtain the minimum difference, we should remove nums[1] = 9 and nums[4] = 1. The resultant array becomes [7,5,8,3]. The difference in sums of the two parts is (7+5) - (8+3) = 1.
    It can be shown that it is not possible to obtain a difference smaller than 1.
    """
def sortEvenOdd(nums: List[int]) -> List[int]:
    """
    You are given a 0-indexed integer array nums. Rearrange the values of nums according to the following rules:
    
    Sort the values at odd indices of nums in non-increasing order.
    
    
    For example, if nums = [4,1,2,3] before this step, it becomes [4,3,2,1] after. The values at odd indices 1 and 3 are sorted in non-increasing order.
    
    
    Sort the values at even indices of nums in non-decreasing order.
    
    For example, if nums = [4,1,2,3] before this step, it becomes [2,1,4,3] after. The values at even indices 0 and 2 are sorted in non-decreasing order.
    
    
    
    Return the array formed after rearranging the values of nums.
    
    Example 1:
    
    >>> sortEvenOdd(nums = [4,1,2,3])
    >>> [2,3,4,1]
    Explanation:
    First, we sort the values present at odd indices (1 and 3) in non-increasing order.
    So, nums changes from [4,1,2,3] to [4,3,2,1].
    Next, we sort the values present at even indices (0 and 2) in non-decreasing order.
    So, nums changes from [4,1,2,3] to [2,3,4,1].
    Thus, the array formed after rearranging the values is [2,3,4,1].
    
    Example 2:
    
    >>> sortEvenOdd(nums = [2,1])
    >>> [2,1]
    Explanation:
    Since there is exactly one odd index and one even index, no rearrangement of values takes place.
    The resultant array formed is [2,1], which is the same as the initial array.
    """
def smallestNumber(num: int) -> int:
    """
    You are given an integer num. Rearrange the digits of num such that its value is minimized and it does not contain any leading zeros.
    Return the rearranged number with minimal value.
    Note that the sign of the number does not change after rearranging the digits.
    
    Example 1:
    
    >>> smallestNumber(num = 310)
    >>> 103
    Explanation: The possible arrangements for the digits of 310 are 013, 031, 103, 130, 301, 310.
    The arrangement with the smallest value that does not contain any leading zeros is 103.
    
    Example 2:
    
    >>> smallestNumber(num = -7605)
    >>> -7650
    Explanation: Some possible arrangements for the digits of -7605 are -7650, -6705, -5076, -0567.
    The arrangement with the smallest value that does not contain any leading zeros is -7650.
    """
def minimumTime(s: str) -> int:
    """
    You are given a 0-indexed binary string s which represents a sequence of train cars. s[i] = '0' denotes that the ith car does not contain illegal goods and s[i] = '1' denotes that the ith car does contain illegal goods.
    As the train conductor, you would like to get rid of all the cars containing illegal goods. You can do any of the following three operations any number of times:
    
    Remove a train car from the left end (i.e., remove s[0]) which takes 1 unit of time.
    Remove a train car from the right end (i.e., remove s[s.length - 1]) which takes 1 unit of time.
    Remove a train car from anywhere in the sequence which takes 2 units of time.
    
    Return the minimum time to remove all the cars containing illegal goods.
    Note that an empty sequence of cars is considered to have no cars containing illegal goods.
    
    Example 1:
    
    >>> minimumTime(s = "1100101")
    >>> 5
    Explanation:
    One way to remove all the cars containing illegal goods from the sequence is to
    - remove a car from the left end 2 times. Time taken is 2 * 1 = 2.
    - remove a car from the right end. Time taken is 1.
    - remove the car containing illegal goods found in the middle. Time taken is 2.
    This obtains a total time of 2 + 1 + 2 = 5.
    
    An alternative way is to
    - remove a car from the left end 2 times. Time taken is 2 * 1 = 2.
    - remove a car from the right end 3 times. Time taken is 3 * 1 = 3.
    This also obtains a total time of 2 + 3 = 5.
    
    5 is the minimum time taken to remove all the cars containing illegal goods.
    There are no other ways to remove them with less time.
    
    Example 2:
    
    >>> minimumTime(s = "0010")
    >>> 2
    Explanation:
    One way to remove all the cars containing illegal goods from the sequence is to
    - remove a car from the left end 3 times. Time taken is 3 * 1 = 3.
    This obtains a total time of 3.
    
    Another way to remove all the cars containing illegal goods from the sequence is to
    - remove the car containing illegal goods found in the middle. Time taken is 2.
    This obtains a total time of 2.
    
    Another way to remove all the cars containing illegal goods from the sequence is to
    - remove a car from the right end 2 times. Time taken is 2 * 1 = 2.
    This obtains a total time of 2.
    
    2 is the minimum time taken to remove all the cars containing illegal goods.
    There are no other ways to remove them with less time.
    """