ShwStone/humaneval-leetcode huggingface dataset:
def maximumSubsequenceCount(text: str, pattern: str) -> int:
    """
    You are given a 0-indexed string text and another 0-indexed string pattern of length 2, both of which consist of only lowercase English letters.
    You can add either pattern[0] or pattern[1] anywhere in text exactly once. Note that the character can be added even at the beginning or at the end of text.
    Return the maximum number of times pattern can occur as a subsequence of the modified text.
    A subsequence is a string that can be derived from another string by deleting some or no characters without changing the order of the remaining characters.
    
    Example 1:
    
    >>> maximumSubsequenceCount(text = "abdcdbc", pattern = "ac")
    >>> 4
    Explanation:
    If we add pattern[0] = 'a' in between text[1] and text[2], we get "abadcdbc". Now, the number of times "ac" occurs as a subsequence is 4.
    Some other strings which have 4 subsequences "ac" after adding a character to text are "aabdcdbc" and "abdacdbc".
    However, strings such as "abdcadbc", "abdccdbc", and "abdcdbcc", although obtainable, have only 3 subsequences "ac" and are thus suboptimal.
    It can be shown that it is not possible to get more than 4 subsequences "ac" by adding only one character.
    
    Example 2:
    
    >>> maximumSubsequenceCount(text = "aabb", pattern = "ab")
    >>> 6
    Explanation:
    Some of the strings which can be obtained from text and have 6 subsequences "ab" are "aaabb", "aaabb", and "aabbb".
    """
def halveArray(nums: List[int]) -> int:
    """
    You are given an array nums of positive integers. In one operation, you can choose any number from nums and reduce it to exactly half the number. (Note that you may choose this reduced number in future operations.)
    Return the minimum number of operations to reduce the sum of nums by at least half.
    
    Example 1:
    
    >>> halveArray(nums = [5,19,8,1])
    >>> 3
    Explanation: The initial sum of nums is equal to 5 + 19 + 8 + 1 = 33.
    The following is one of the ways to reduce the sum by at least half:
    Pick the number 19 and reduce it to 9.5.
    Pick the number 9.5 and reduce it to 4.75.
    Pick the number 8 and reduce it to 4.
    The final array is [5, 4.75, 4, 1] with a total sum of 5 + 4.75 + 4 + 1 = 14.75.
    The sum of nums has been reduced by 33 - 14.75 = 18.25, which is at least half of the initial sum, 18.25 >= 33/2 = 16.5.
    Overall, 3 operations were used so we return 3.
    It can be shown that we cannot reduce the sum by at least half in less than 3 operations.
    
    Example 2:
    
    >>> halveArray(nums = [3,8,20])
    >>> 3
    Explanation: The initial sum of nums is equal to 3 + 8 + 20 = 31.
    The following is one of the ways to reduce the sum by at least half:
    Pick the number 20 and reduce it to 10.
    Pick the number 10 and reduce it to 5.
    Pick the number 3 and reduce it to 1.5.
    The final array is [1.5, 8, 5] with a total sum of 1.5 + 8 + 5 = 14.5.
    The sum of nums has been reduced by 31 - 14.5 = 16.5, which is at least half of the initial sum, 16.5 >= 31/2 = 15.5.
    Overall, 3 operations were used so we return 3.
    It can be shown that we cannot reduce the sum by at least half in less than 3 operations.
    """
def minimumWhiteTiles(floor: str, numCarpets: int, carpetLen: int) -> int:
    """
    You are given a 0-indexed binary string floor, which represents the colors of tiles on a floor:
    
    floor[i] = '0' denotes that the ith tile of the floor is colored black.
    On the other hand, floor[i] = '1' denotes that the ith tile of the floor is colored white.
    
    You are also given numCarpets and carpetLen. You have numCarpets black carpets, each of length carpetLen tiles. Cover the tiles with the given carpets such that the number of white tiles still visible is minimum. Carpets may overlap one another.
    Return the minimum number of white tiles still visible.
    
    Example 1:
    
    
    >>> minimumWhiteTiles(floor = "10110101", numCarpets = 2, carpetLen = 2)
    >>> 2
    Explanation:
    The figure above shows one way of covering the tiles with the carpets such that only 2 white tiles are visible.
    No other way of covering the tiles with the carpets can leave less than 2 white tiles visible.
    
    Example 2:
    
    
    >>> minimumWhiteTiles(floor = "11111", numCarpets = 2, carpetLen = 3)
    >>> 0
    Explanation:
    The figure above shows one way of covering the tiles with the carpets such that no white tiles are visible.
    Note that the carpets are able to overlap one another.
    """
def countHillValley(nums: List[int]) -> int:
    """
    You are given a 0-indexed integer array nums. An index i is part of a hill in nums if the closest non-equal neighbors of i are smaller than nums[i]. Similarly, an index i is part of a valley in nums if the closest non-equal neighbors of i are larger than nums[i]. Adjacent indices i and j are part of the same hill or valley if nums[i] == nums[j].
    Note that for an index to be part of a hill or valley, it must have a non-equal neighbor on both the left and right of the index.
    Return the number of hills and valleys in nums.
    
    Example 1:
    
    >>> countHillValley(nums = [2,4,1,1,6,5])
    >>> 3
    Explanation:
    At index 0: There is no non-equal neighbor of 2 on the left, so index 0 is neither a hill nor a valley.
    At index 1: The closest non-equal neighbors of 4 are 2 and 1. Since 4 > 2 and 4 > 1, index 1 is a hill.
    At index 2: The closest non-equal neighbors of 1 are 4 and 6. Since 1 < 4 and 1 < 6, index 2 is a valley.
    At index 3: The closest non-equal neighbors of 1 are 4 and 6. Since 1 < 4 and 1 < 6, index 3 is a valley, but note that it is part of the same valley as index 2.
    At index 4: The closest non-equal neighbors of 6 are 1 and 5. Since 6 > 1 and 6 > 5, index 4 is a hill.
    At index 5: There is no non-equal neighbor of 5 on the right, so index 5 is neither a hill nor a valley.
    There are 3 hills and valleys so we return 3.
    
    Example 2:
    
    >>> countHillValley(nums = [6,6,5,5,4,1])
    >>> 0
    Explanation:
    At index 0: There is no non-equal neighbor of 6 on the left, so index 0 is neither a hill nor a valley.
    At index 1: There is no non-equal neighbor of 6 on the left, so index 1 is neither a hill nor a valley.
    At index 2: The closest non-equal neighbors of 5 are 6 and 4. Since 5 < 6 and 5 > 4, index 2 is neither a hill nor a valley.
    At index 3: The closest non-equal neighbors of 5 are 6 and 4. Since 5 < 6 and 5 > 4, index 3 is neither a hill nor a valley.
    At index 4: The closest non-equal neighbors of 4 are 5 and 1. Since 4 < 5 and 4 > 1, index 4 is neither a hill nor a valley.
    At index 5: There is no non-equal neighbor of 1 on the right, so index 5 is neither a hill nor a valley.
    There are 0 hills and valleys so we return 0.
    """
def countCollisions(directions: str) -> int:
    """
    There are n cars on an infinitely long road. The cars are numbered from 0 to n - 1 from left to right and each car is present at a unique point.
    You are given a 0-indexed string directions of length n. directions[i] can be either 'L', 'R', or 'S' denoting whether the ith car is moving towards the left, towards the right, or staying at its current point respectively. Each moving car has the same speed.
    The number of collisions can be calculated as follows:
    
    When two cars moving in opposite directions collide with each other, the number of collisions increases by 2.
    When a moving car collides with a stationary car, the number of collisions increases by 1.
    
    After a collision, the cars involved can no longer move and will stay at the point where they collided. Other than that, cars cannot change their state or direction of motion.
    Return the total number of collisions that will happen on the road.
    
    Example 1:
    
    >>> countCollisions(directions = "RLRSLL")
    >>> 5
    Explanation:
    The collisions that will happen on the road are:
    - Cars 0 and 1 will collide with each other. Since they are moving in opposite directions, the number of collisions becomes 0 + 2 = 2.
    - Cars 2 and 3 will collide with each other. Since car 3 is stationary, the number of collisions becomes 2 + 1 = 3.
    - Cars 3 and 4 will collide with each other. Since car 3 is stationary, the number of collisions becomes 3 + 1 = 4.
    - Cars 4 and 5 will collide with each other. After car 4 collides with car 3, it will stay at the point of collision and get hit by car 5. The number of collisions becomes 4 + 1 = 5.
    Thus, the total number of collisions that will happen on the road is 5.
    
    Example 2:
    
    >>> countCollisions(directions = "LLRR")
    >>> 0
    Explanation:
    No cars will collide with each other. Thus, the total number of collisions that will happen on the road is 0.
    """
def maximumBobPoints(numArrows: int, aliceArrows: List[int]) -> List[int]:
    """
    Alice and Bob are opponents in an archery competition. The competition has set the following rules:
    
    Alice first shoots numArrows arrows and then Bob shoots numArrows arrows.
    The points are then calculated as follows:
    
    The target has integer scoring sections ranging from 0 to 11 inclusive.
    For each section of the target with score k (in between 0 to 11), say Alice and Bob have shot ak and bk arrows on that section respectively. If ak >= bk, then Alice takes k points. If ak < bk, then Bob takes k points.
    However, if ak == bk == 0, then nobody takes k points.
    
    
    
    
    
    For example, if Alice and Bob both shot 2 arrows on the section with score 11, then Alice takes 11 points. On the other hand, if Alice shot 0 arrows on the section with score 11 and Bob shot 2 arrows on that same section, then Bob takes 11 points.
    
    
    You are given the integer numArrows and an integer array aliceArrows of size 12, which represents the number of arrows Alice shot on each scoring section from 0 to 11. Now, Bob wants to maximize the total number of points he can obtain.
    Return the array bobArrows which represents the number of arrows Bob shot on each scoring section from 0 to 11. The sum of the values in bobArrows should equal numArrows.
    If there are multiple ways for Bob to earn the maximum total points, return any one of them.
    
    Example 1:
    
    
    >>> maximumBobPoints(numArrows = 9, aliceArrows = [1,1,0,1,0,0,2,1,0,1,2,0])
    >>> [0,0,0,0,1,1,0,0,1,2,3,1]
    Explanation: The table above shows how the competition is scored.
    Bob earns a total point of 4 + 5 + 8 + 9 + 10 + 11 = 47.
    It can be shown that Bob cannot obtain a score higher than 47 points.
    
    Example 2:
    
    
    >>> maximumBobPoints(numArrows = 3, aliceArrows = [0,0,1,0,0,0,0,0,0,0,0,2])
    >>> [0,0,0,0,0,0,0,0,1,1,1,0]
    Explanation: The table above shows how the competition is scored.
    Bob earns a total point of 8 + 9 + 10 = 27.
    It can be shown that Bob cannot obtain a score higher than 27 points.
    """
def longestRepeating(s: str, queryCharacters: str, queryIndices: List[int]) -> List[int]:
    """
    You are given a 0-indexed string s. You are also given a 0-indexed string queryCharacters of length k and a 0-indexed array of integer indices queryIndices of length k, both of which are used to describe k queries.
    The ith query updates the character in s at index queryIndices[i] to the character queryCharacters[i].
    Return an array lengths of length k where lengths[i] is the length of the longest substring of s consisting of only one repeating character after the ith query is performed.
    
    Example 1:
    
    >>> longestRepeating(s = "babacc", queryCharacters = "bcb", queryIndices = [1,3,3])
    >>> [3,3,4]
    Explanation:
    - 1st query updates s = "bbbacc". The longest substring consisting of one repeating character is "bbb" with length 3.
    - 2nd query updates s = "bbbccc".
      The longest substring consisting of one repeating character can be "bbb" or "ccc" with length 3.
    - 3rd query updates s = "bbbbcc". The longest substring consisting of one repeating character is "bbbb" with length 4.
    Thus, we return [3,3,4].
    
    Example 2:
    
    >>> longestRepeating(s = "abyzz", queryCharacters = "aa", queryIndices = [2,1])
    >>> [2,3]
    Explanation:
    - 1st query updates s = "abazz". The longest substring consisting of one repeating character is "zz" with length 2.
    - 2nd query updates s = "aaazz". The longest substring consisting of one repeating character is "aaa" with length 3.
    Thus, we return [2,3].
    """
def minimumHealth(damage: List[int], armor: int) -> int:
    """
    You are playing a game that has n levels numbered from 0 to n - 1. You are given a 0-indexed integer array damage where damage[i] is the amount of health you will lose to complete the ith level.
    You are also given an integer armor. You may use your armor ability at most once during the game on any level which will protect you from at most armor damage.
    You must complete the levels in order and your health must be greater than 0 at all times to beat the game.
    Return the minimum health you need to start with to beat the game.
    
    Example 1:
    
    >>> minimumHealth(damage = [2,7,4,3], armor = 4)
    >>> 13
    Explanation: One optimal way to beat the game starting at 13 health is:
    On round 1, take 2 damage. You have 13 - 2 = 11 health.
    On round 2, take 7 damage. You have 11 - 7 = 4 health.
    On round 3, use your armor to protect you from 4 damage. You have 4 - 0 = 4 health.
    On round 4, take 3 damage. You have 4 - 3 = 1 health.
    Note that 13 is the minimum health you need to start with to beat the game.
    
    Example 2:
    
    >>> minimumHealth(damage = [2,5,3,4], armor = 7)
    >>> 10
    Explanation: One optimal way to beat the game starting at 10 health is:
    On round 1, take 2 damage. You have 10 - 2 = 8 health.
    On round 2, use your armor to protect you from 5 damage. You have 8 - 0 = 8 health.
    On round 3, take 3 damage. You have 8 - 3 = 5 health.
    On round 4, take 4 damage. You have 5 - 4 = 1 health.
    Note that 10 is the minimum health you need to start with to beat the game.
    
    Example 3:
    
    >>> minimumHealth(damage = [3,3,3], armor = 0)
    >>> 10
    Explanation: One optimal way to beat the game starting at 10 health is:
    On round 1, take 3 damage. You have 10 - 3 = 7 health.
    On round 2, take 3 damage. You have 7 - 3 = 4 health.
    On round 3, take 3 damage. You have 4 - 3 = 1 health.
    Note that you did not use your armor ability.
    """
def findDifference(nums1: List[int], nums2: List[int]) -> List[List[int]]:
    """
    Given two 0-indexed integer arrays nums1 and nums2, return a list answer of size 2 where:
    
    answer[0] is a list of all distinct integers in nums1 which are not present in nums2.
    answer[1] is a list of all distinct integers in nums2 which are not present in nums1.
    
    Note that the integers in the lists may be returned in any order.
    
    Example 1:
    
    >>> findDifference(nums1 = [1,2,3], nums2 = [2,4,6])
    >>> [[1,3],[4,6]]
    Explanation:
    For nums1, nums1[1] = 2 is present at index 0 of nums2, whereas nums1[0] = 1 and nums1[2] = 3 are not present in nums2. Therefore, answer[0] = [1,3].
    For nums2, nums2[0] = 2 is present at index 1 of nums1, whereas nums2[1] = 4 and nums2[2] = 6 are not present in nums2. Therefore, answer[1] = [4,6].
    Example 2:
    
    >>> findDifference(nums1 = [1,2,3,3], nums2 = [1,1,2,2])
    >>> [[3],[]]
    Explanation:
    For nums1, nums1[2] and nums1[3] are not present in nums2. Since nums1[2] == nums1[3], their value is only included once and answer[0] = [3].
    Every integer in nums2 is present in nums1. Therefore, answer[1] = [].
    """
def minDeletion(nums: List[int]) -> int:
    """
    You are given a 0-indexed integer array nums. The array nums is beautiful if:
    
    nums.length is even.
    nums[i] != nums[i + 1] for all i % 2 == 0.
    
    Note that an empty array is considered beautiful.
    You can delete any number of elements from nums. When you delete an element, all the elements to the right of the deleted element will be shifted one unit to the left to fill the gap created and all the elements to the left of the deleted element will remain unchanged.
    Return the minimum number of elements to delete from nums to make it beautiful.
    
    Example 1:
    
    >>> minDeletion(nums = [1,1,2,3,5])
    >>> 1
    Explanation: You can delete either nums[0] or nums[1] to make nums = [1,2,3,5] which is beautiful. It can be proven you need at least 1 deletion to make nums beautiful.
    
    Example 2:
    
    >>> minDeletion(nums = [1,1,2,2,3,3])
    >>> 2
    Explanation: You can delete nums[0] and nums[5] to make nums = [1,2,2,3] which is beautiful. It can be proven you need at least 2 deletions to make nums beautiful.
    """
def kthPalindrome(queries: List[int], intLength: int) -> List[int]:
    """
    Given an integer array queries and a positive integer intLength, return an array answer where answer[i] is either the queries[i]th smallest positive palindrome of length intLength or -1 if no such palindrome exists.
    A palindrome is a number that reads the same backwards and forwards. Palindromes cannot have leading zeros.
    
    Example 1:
    
    >>> kthPalindrome(queries = [1,2,3,4,5,90], intLength = 3)
    >>> [101,111,121,131,141,999]
    Explanation:
    The first few palindromes of length 3 are:
    101, 111, 121, 131, 141, 151, 161, 171, 181, 191, 202, ...
    The 90th palindrome of length 3 is 999.
    
    Example 2:
    
    >>> kthPalindrome(queries = [2,4,6], intLength = 4)
    >>> [1111,1331,1551]
    Explanation:
    The first six palindromes of length 4 are:
    1001, 1111, 1221, 1331, 1441, and 1551.
    """
def maxValueOfCoins(piles: List[List[int]], k: int) -> int:
    """
    There are n piles of coins on a table. Each pile consists of a positive number of coins of assorted denominations.
    In one move, you can choose any coin on top of any pile, remove it, and add it to your wallet.
    Given a list piles, where piles[i] is a list of integers denoting the composition of the ith pile from top to bottom, and a positive integer k, return the maximum total value of coins you can have in your wallet if you choose exactly k coins optimally.
    
    Example 1:
    
    
    >>> maxValueOfCoins(piles = [[1,100,3],[7,8,9]], k = 2)
    >>> 101
    Explanation:
    The above diagram shows the different ways we can choose k coins.
    The maximum total we can obtain is 101.
    
    Example 2:
    
    >>> maxValueOfCoins(piles = [[100],[100],[100],[100],[100],[100],[1,1,1,1,1,1,700]], k = 7)
    >>> 706
    Explanation:
    The maximum total can be obtained if we choose all coins from the last pile.
    """
def maximumSumScore(nums: List[int]) -> int:
    """
    You are given a 0-indexed integer array nums of length n.
    The sum score of nums at an index i where 0 <= i < n is the maximum of:
    
    The sum of the first i + 1 elements of nums.
    The sum of the last n - i elements of nums.
    
    Return the maximum sum score of nums at any index.
    
    Example 1:
    
    >>> maximumSumScore(nums = [4,3,-2,5])
    >>> 10
    Explanation:
    The sum score at index 0 is max(4, 4 + 3 + -2 + 5) = max(4, 10) = 10.
    The sum score at index 1 is max(4 + 3, 3 + -2 + 5) = max(7, 6) = 7.
    The sum score at index 2 is max(4 + 3 + -2, -2 + 5) = max(5, 3) = 5.
    The sum score at index 3 is max(4 + 3 + -2 + 5, 5) = max(10, 5) = 10.
    The maximum sum score of nums is 10.
    
    Example 2:
    
    >>> maximumSumScore(nums = [-3,-5])
    >>> -3
    Explanation:
    The sum score at index 0 is max(-3, -3 + -5) = max(-3, -8) = -3.
    The sum score at index 1 is max(-3 + -5, -5) = max(-8, -5) = -5.
    The maximum sum score of nums is -3.
    """
def minBitFlips(start: int, goal: int) -> int:
    """
    A bit flip of a number x is choosing a bit in the binary representation of x and flipping it from either 0 to 1 or 1 to 0.
    
    For example, for x = 7, the binary representation is 111 and we may choose any bit (including any leading zeros not shown) and flip it. We can flip the first bit from the right to get 110, flip the second bit from the right to get 101, flip the fifth bit from the right (a leading zero) to get 10111, etc.
    
    Given two integers start and goal, return the minimum number of bit flips to convert start to goal.
    
    Example 1:
    
    >>> minBitFlips(start = 10, goal = 7)
    >>> 3
    Explanation: The binary representation of 10 and 7 are 1010 and 0111 respectively. We can convert 10 to 7 in 3 steps:
    - Flip the first bit from the right: 1010 -> 1011.
    - Flip the third bit from the right: 1011 -> 1111.
    - Flip the fourth bit from the right: 1111 -> 0111.
    It can be shown we cannot convert 10 to 7 in less than 3 steps. Hence, we return 3.
    Example 2:
    
    >>> minBitFlips(start = 3, goal = 4)
    >>> 3
    Explanation: The binary representation of 3 and 4 are 011 and 100 respectively. We can convert 3 to 4 in 3 steps:
    - Flip the first bit from the right: 011 -> 010.
    - Flip the second bit from the right: 010 -> 000.
    - Flip the third bit from the right: 000 -> 100.
    It can be shown we cannot convert 3 to 4 in less than 3 steps. Hence, we return 3.
    """
def triangularSum(nums: List[int]) -> int:
    """
    You are given a 0-indexed integer array nums, where nums[i] is a digit between 0 and 9 (inclusive).
    The triangular sum of nums is the value of the only element present in nums after the following process terminates:
    
    Let nums comprise of n elements. If n == 1, end the process. Otherwise, create a new 0-indexed integer array newNums of length n - 1.
    For each index i, where 0 <= i < n - 1, assign the value of newNums[i] as (nums[i] + nums[i+1]) % 10, where % denotes modulo operator.
    Replace the array nums with newNums.
    Repeat the entire process starting from step 1.
    
    Return the triangular sum of nums.
    
    Example 1:
    
    
    >>> triangularSum(nums = [1,2,3,4,5])
    >>> 8
    Explanation:
    The above diagram depicts the process from which we obtain the triangular sum of the array.
    Example 2:
    
    >>> triangularSum(nums = [5])
    >>> 5
    Explanation:
    Since there is only one element in nums, the triangular sum is the value of that element itself.
    """
def numberOfWays(s: str) -> int:
    """
    You are given a 0-indexed binary string s which represents the types of buildings along a street where:
    
    s[i] = '0' denotes that the ith building is an office and
    s[i] = '1' denotes that the ith building is a restaurant.
    
    As a city official, you would like to select 3 buildings for random inspection. However, to ensure variety, no two consecutive buildings out of the selected buildings can be of the same type.
    
    For example, given s = "001101", we cannot select the 1st, 3rd, and 5th buildings as that would form "011" which is not allowed due to having two consecutive buildings of the same type.
    
    Return the number of valid ways to select 3 buildings.
    
    Example 1:
    
    >>> numberOfWays(s = "001101")
    >>> 6
    Explanation:
    The following sets of indices selected are valid:
    - [0,2,4] from "001101" forms "010"
    - [0,3,4] from "001101" forms "010"
    - [1,2,4] from "001101" forms "010"
    - [1,3,4] from "001101" forms "010"
    - [2,4,5] from "001101" forms "101"
    - [3,4,5] from "001101" forms "101"
    No other selection is valid. Thus, there are 6 total ways.
    
    Example 2:
    
    >>> numberOfWays(s = "11100")
    >>> 0
    Explanation: It can be shown that there are no valid selections.
    """