ShwStone/humaneval-leetcode huggingface dataset:
def countTexts(pressedKeys: str) -> int:
    """
    Alice is texting Bob using her phone. The mapping of digits to letters is shown in the figure below.
    
    In order to add a letter, Alice has to press the key of the corresponding digit i times, where i is the position of the letter in the key.
    
    For example, to add the letter 's', Alice has to press '7' four times. Similarly, to add the letter 'k', Alice has to press '5' twice.
    Note that the digits '0' and '1' do not map to any letters, so Alice does not use them.
    
    However, due to an error in transmission, Bob did not receive Alice's text message but received a string of pressed keys instead.
    
    For example, when Alice sent the message "bob", Bob received the string "2266622".
    
    Given a string pressedKeys representing the string received by Bob, return the total number of possible text messages Alice could have sent.
    Since the answer may be very large, return it modulo 109 + 7.
    
    Example 1:
    
    >>> countTexts(pressedKeys = "22233")
    >>> 8
    Explanation:
    The possible text messages Alice could have sent are:
    "aaadd", "abdd", "badd", "cdd", "aaae", "abe", "bae", and "ce".
    Since there are 8 possible messages, we return 8.
    
    Example 2:
    
    >>> countTexts(pressedKeys = "222222222222222222222222222222222222")
    >>> 82876089
    Explanation:
    There are 2082876103 possible text messages Alice could have sent.
    Since we need to return the answer modulo 109 + 7, we return 2082876103 % (109 + 7) = 82876089.
    """
def hasValidPath(grid: List[List[str]]) -> bool:
    """
    A parentheses string is a non-empty string consisting only of '(' and ')'. It is valid if any of the following conditions is true:
    
    It is ().
    It can be written as AB (A concatenated with B), where A and B are valid parentheses strings.
    It can be written as (A), where A is a valid parentheses string.
    
    You are given an m x n matrix of parentheses grid. A valid parentheses string path in the grid is a path satisfying all of the following conditions:
    
    The path starts from the upper left cell (0, 0).
    The path ends at the bottom-right cell (m - 1, n - 1).
    The path only ever moves down or right.
    The resulting parentheses string formed by the path is valid.
    
    Return true if there exists a valid parentheses string path in the grid. Otherwise, return false.
    
    Example 1:
    
    
    >>> hasValidPath(grid = [["(","(","("],[")","(",")"],["(","(",")"],["(","(",")"]])
    >>> true
    Explanation: The above diagram shows two possible paths that form valid parentheses strings.
    The first path shown results in the valid parentheses string "()(())".
    The second path shown results in the valid parentheses string "((()))".
    Note that there may be other valid parentheses string paths.
    
    Example 2:
    
    
    >>> hasValidPath(grid = [[")",")"],["(","("]])
    >>> false
    Explanation: The two possible paths form the parentheses strings "))(" and ")((". Since neither of them are valid parentheses strings, we return false.
    """
def minimumKeypresses(s: str) -> int:
    """
    You have a keypad with 9 buttons, numbered from 1 to 9, each mapped to lowercase English letters. You can choose which characters each button is matched to as long as:
    
    All 26 lowercase English letters are mapped to.
    Each character is mapped to by exactly 1 button.
    Each button maps to at most 3 characters.
    
    To type the first character matched to a button, you press the button once. To type the second character, you press the button twice, and so on.
    Given a string s, return the minimum number of keypresses needed to type s using your keypad.
    Note that the characters mapped to by each button, and the order they are mapped in cannot be changed.
    
    Example 1:
    
    
    >>> minimumKeypresses(s = "apple")
    >>> 5
    Explanation: One optimal way to setup your keypad is shown above.
    Type 'a' by pressing button 1 once.
    Type 'p' by pressing button 6 once.
    Type 'p' by pressing button 6 once.
    Type 'l' by pressing button 5 once.
    Type 'e' by pressing button 3 once.
    A total of 5 button presses are needed, so return 5.
    
    Example 2:
    
    
    >>> minimumKeypresses(s = "abcdefghijkl")
    >>> 15
    Explanation: One optimal way to setup your keypad is shown above.
    The letters 'a' to 'i' can each be typed by pressing a button once.
    Type 'j' by pressing button 1 twice.
    Type 'k' by pressing button 2 twice.
    Type 'l' by pressing button 3 twice.
    A total of 15 button presses are needed, so return 15.
    """
def divisorSubstrings(num: int, k: int) -> int:
    """
    The k-beauty of an integer num is defined as the number of substrings of num when it is read as a string that meet the following conditions:
    
    It has a length of k.
    It is a divisor of num.
    
    Given integers num and k, return the k-beauty of num.
    Note:
    
    Leading zeros are allowed.
    0 is not a divisor of any value.
    
    A substring is a contiguous sequence of characters in a string.
    
    Example 1:
    
    >>> divisorSubstrings(num = 240, k = 2)
    >>> 2
    Explanation: The following are the substrings of num of length k:
    - "24" from "240": 24 is a divisor of 240.
    - "40" from "240": 40 is a divisor of 240.
    Therefore, the k-beauty is 2.
    
    Example 2:
    
    >>> divisorSubstrings(num = 430043, k = 2)
    >>> 2
    Explanation: The following are the substrings of num of length k:
    - "43" from "430043": 43 is a divisor of 430043.
    - "30" from "430043": 30 is not a divisor of 430043.
    - "00" from "430043": 0 is not a divisor of 430043.
    - "04" from "430043": 4 is not a divisor of 430043.
    - "43" from "430043": 43 is a divisor of 430043.
    Therefore, the k-beauty is 2.
    """
def waysToSplitArray(nums: List[int]) -> int:
    """
    You are given a 0-indexed integer array nums of length n.
    nums contains a valid split at index i if the following are true:
    
    The sum of the first i + 1 elements is greater than or equal to the sum of the last n - i - 1 elements.
    There is at least one element to the right of i. That is, 0 <= i < n - 1.
    
    Return the number of valid splits in nums.
    
    Example 1:
    
    >>> waysToSplitArray(nums = [10,4,-8,7])
    >>> 2
    Explanation:
    There are three ways of splitting nums into two non-empty parts:
    - Split nums at index 0. Then, the first part is [10], and its sum is 10. The second part is [4,-8,7], and its sum is 3. Since 10 >= 3, i = 0 is a valid split.
    - Split nums at index 1. Then, the first part is [10,4], and its sum is 14. The second part is [-8,7], and its sum is -1. Since 14 >= -1, i = 1 is a valid split.
    - Split nums at index 2. Then, the first part is [10,4,-8], and its sum is 6. The second part is [7], and its sum is 7. Since 6 < 7, i = 2 is not a valid split.
    Thus, the number of valid splits in nums is 2.
    
    Example 2:
    
    >>> waysToSplitArray(nums = [2,3,1,0])
    >>> 2
    Explanation:
    There are two valid splits in nums:
    - Split nums at index 1. Then, the first part is [2,3], and its sum is 5. The second part is [1,0], and its sum is 1. Since 5 >= 1, i = 1 is a valid split.
    - Split nums at index 2. Then, the first part is [2,3,1], and its sum is 6. The second part is [0], and its sum is 0. Since 6 >= 0, i = 2 is a valid split.
    """
def maximumWhiteTiles(tiles: List[List[int]], carpetLen: int) -> int:
    """
    You are given a 2D integer array tiles where tiles[i] = [li, ri] represents that every tile j in the range li <= j <= ri is colored white.
    You are also given an integer carpetLen, the length of a single carpet that can be placed anywhere.
    Return the maximum number of white tiles that can be covered by the carpet.
    
    Example 1:
    
    
    >>> maximumWhiteTiles(tiles = [[1,5],[10,11],[12,18],[20,25],[30,32]], carpetLen = 10)
    >>> 9
    Explanation: Place the carpet starting on tile 10.
    It covers 9 white tiles, so we return 9.
    Note that there may be other places where the carpet covers 9 white tiles.
    It can be shown that the carpet cannot cover more than 9 white tiles.
    
    Example 2:
    
    
    >>> maximumWhiteTiles(tiles = [[10,11],[1,1]], carpetLen = 2)
    >>> 2
    Explanation: Place the carpet starting on tile 10.
    It covers 2 white tiles, so we return 2.
    """
def largestVariance(s: str) -> int:
    """
    The variance of a string is defined as the largest difference between the number of occurrences of any 2 characters present in the string. Note the two characters may or may not be the same.
    Given a string s consisting of lowercase English letters only, return the largest variance possible among all substrings of s.
    A substring is a contiguous sequence of characters within a string.
    
    Example 1:
    
    >>> largestVariance(s = "aababbb")
    >>> 3
    Explanation:
    All possible variances along with their respective substrings are listed below:
    - Variance 0 for substrings "a", "aa", "ab", "abab", "aababb", "ba", "b", "bb", and "bbb".
    - Variance 1 for substrings "aab", "aba", "abb", "aabab", "ababb", "aababbb", and "bab".
    - Variance 2 for substrings "aaba", "ababbb", "abbb", and "babb".
    - Variance 3 for substring "babbb".
    Since the largest possible variance is 3, we return it.
    
    Example 2:
    
    >>> largestVariance(s = "abcde")
    >>> 0
    Explanation:
    No letter occurs more than once in s, so the variance of every substring is 0.
    """
def removeAnagrams(words: List[str]) -> List[str]:
    """
    You are given a 0-indexed string array words, where words[i] consists of lowercase English letters.
    In one operation, select any index i such that 0 < i < words.length and words[i - 1] and words[i] are anagrams, and delete words[i] from words. Keep performing this operation as long as you can select an index that satisfies the conditions.
    Return words after performing all operations. It can be shown that selecting the indices for each operation in any arbitrary order will lead to the same result.
    An Anagram is a word or phrase formed by rearranging the letters of a different word or phrase using all the original letters exactly once. For example, "dacb" is an anagram of "abdc".
    
    Example 1:
    
    >>> removeAnagrams(words = ["abba","baba","bbaa","cd","cd"])
    >>> ["abba","cd"]
    Explanation:
    One of the ways we can obtain the resultant array is by using the following operations:
    - Since words[2] = "bbaa" and words[1] = "baba" are anagrams, we choose index 2 and delete words[2].
      Now words = ["abba","baba","cd","cd"].
    - Since words[1] = "baba" and words[0] = "abba" are anagrams, we choose index 1 and delete words[1].
      Now words = ["abba","cd","cd"].
    - Since words[2] = "cd" and words[1] = "cd" are anagrams, we choose index 2 and delete words[2].
      Now words = ["abba","cd"].
    We can no longer perform any operations, so ["abba","cd"] is the final answer.
    Example 2:
    
    >>> removeAnagrams(words = ["a","b","c","d","e"])
    >>> ["a","b","c","d","e"]
    Explanation:
    No two adjacent strings in words are anagrams of each other, so no operations are performed.
    """
def maxConsecutive(bottom: int, top: int, special: List[int]) -> int:
    """
    Alice manages a company and has rented some floors of a building as office space. Alice has decided some of these floors should be special floors, used for relaxation only.
    You are given two integers bottom and top, which denote that Alice has rented all the floors from bottom to top (inclusive). You are also given the integer array special, where special[i] denotes a special floor that Alice has designated for relaxation.
    Return the maximum number of consecutive floors without a special floor.
    
    Example 1:
    
    >>> maxConsecutive(bottom = 2, top = 9, special = [4,6])
    >>> 3
    Explanation: The following are the ranges (inclusive) of consecutive floors without a special floor:
    - (2, 3) with a total amount of 2 floors.
    - (5, 5) with a total amount of 1 floor.
    - (7, 9) with a total amount of 3 floors.
    Therefore, we return the maximum number which is 3 floors.
    
    Example 2:
    
    >>> maxConsecutive(bottom = 6, top = 8, special = [7,6,8])
    >>> 0
    Explanation: Every floor rented is a special floor, so we return 0.
    """
def largestCombination(candidates: List[int]) -> int:
    """
    The bitwise AND of an array nums is the bitwise AND of all integers in nums.
    
    For example, for nums = [1, 5, 3], the bitwise AND is equal to 1 & 5 & 3 = 1.
    Also, for nums = [7], the bitwise AND is 7.
    
    You are given an array of positive integers candidates. Compute the bitwise AND for all possible combinations of elements in the candidates array.
    Return the size of the largest combination of candidates with a bitwise AND greater than 0.
    
    Example 1:
    
    >>> largestCombination(candidates = [16,17,71,62,12,24,14])
    >>> 4
    Explanation: The combination [16,17,62,24] has a bitwise AND of 16 & 17 & 62 & 24 = 16 > 0.
    The size of the combination is 4.
    It can be shown that no combination with a size greater than 4 has a bitwise AND greater than 0.
    Note that more than one combination may have the largest size.
    For example, the combination [62,12,24,14] has a bitwise AND of 62 & 12 & 24 & 14 = 8 > 0.
    
    Example 2:
    
    >>> largestCombination(candidates = [8,8])
    >>> 2
    Explanation: The largest combination [8,8] has a bitwise AND of 8 & 8 = 8 > 0.
    The size of the combination is 2, so we return 2.
    """
def closestNode(n: int, edges: List[List[int]], query: List[List[int]]) -> List[int]:
    """
    You are given a positive integer n representing the number of nodes in a tree, numbered from 0 to n - 1 (inclusive). You are also given a 2D integer array edges of length n - 1, where edges[i] = [node1i, node2i] denotes that there is a bidirectional edge connecting node1i and node2i in the tree.
    You are given a 0-indexed integer array query of length m where query[i] = [starti, endi, nodei] means that for the ith query, you are tasked with finding the node on the path from starti to endi that is closest to nodei.
    Return an integer array answer of length m, where answer[i] is the answer to the ith query.
    
    Example 1:
    
    
    >>> closestNode(n = 7, edges = [[0,1],[0,2],[0,3],[1,4],[2,5],[2,6]], query = [[5,3,4],[5,3,6]])
    >>> [0,2]
    Explanation:
    The path from node 5 to node 3 consists of the nodes 5, 2, 0, and 3.
    The distance between node 4 and node 0 is 2.
    Node 0 is the node on the path closest to node 4, so the answer to the first query is 0.
    The distance between node 6 and node 2 is 1.
    Node 2 is the node on the path closest to node 6, so the answer to the second query is 2.
    
    Example 2:
    
    
    >>> closestNode(n = 3, edges = [[0,1],[1,2]], query = [[0,1,2]])
    >>> [1]
    Explanation:
    The path from node 0 to node 1 consists of the nodes 0, 1.
    The distance between node 2 and node 1 is 1.
    Node 1 is the node on the path closest to node 2, so the answer to the first query is 1.
    
    Example 3:
    
    
    >>> closestNode(n = 3, edges = [[0,1],[1,2]], query = [[0,0,0]])
    >>> [0]
    Explanation:
    The path from node 0 to node 0 consists of the node 0.
    Since 0 is the only node on the path, the answer to the first query is 0.
    """
def percentageLetter(s: str, letter: str) -> int:
    """
    Given a string s and a character letter, return the percentage of characters in s that equal letter rounded down to the nearest whole percent.
    
    Example 1:
    
    >>> percentageLetter(s = "foobar", letter = "o")
    >>> 33
    Explanation:
    The percentage of characters in s that equal the letter 'o' is 2 / 6 * 100% = 33% when rounded down, so we return 33.
    
    Example 2:
    
    >>> percentageLetter(s = "jjjj", letter = "k")
    >>> 0
    Explanation:
    The percentage of characters in s that equal the letter 'k' is 0%, so we return 0.
    """
def maximumBags(capacity: List[int], rocks: List[int], additionalRocks: int) -> int:
    """
    You have n bags numbered from 0 to n - 1. You are given two 0-indexed integer arrays capacity and rocks. The ith bag can hold a maximum of capacity[i] rocks and currently contains rocks[i] rocks. You are also given an integer additionalRocks, the number of additional rocks you can place in any of the bags.
    Return the maximum number of bags that could have full capacity after placing the additional rocks in some bags.
    
    Example 1:
    
    >>> maximumBags(capacity = [2,3,4,5], rocks = [1,2,4,4], additionalRocks = 2)
    >>> 3
    Explanation:
    Place 1 rock in bag 0 and 1 rock in bag 1.
    The number of rocks in each bag are now [2,3,4,4].
    Bags 0, 1, and 2 have full capacity.
    There are 3 bags at full capacity, so we return 3.
    It can be shown that it is not possible to have more than 3 bags at full capacity.
    Note that there may be other ways of placing the rocks that result in an answer of 3.
    
    Example 2:
    
    >>> maximumBags(capacity = [10,2,2], rocks = [2,2,0], additionalRocks = 100)
    >>> 3
    Explanation:
    Place 8 rocks in bag 0 and 2 rocks in bag 2.
    The number of rocks in each bag are now [10,2,2].
    Bags 0, 1, and 2 have full capacity.
    There are 3 bags at full capacity, so we return 3.
    It can be shown that it is not possible to have more than 3 bags at full capacity.
    Note that we did not use all of the additional rocks.
    """
def minimumLines(stockPrices: List[List[int]]) -> int:
    """
    You are given a 2D integer array stockPrices where stockPrices[i] = [dayi, pricei] indicates the price of the stock on day dayi is pricei. A line chart is created from the array by plotting the points on an XY plane with the X-axis representing the day and the Y-axis representing the price and connecting adjacent points. One such example is shown below:
    
    Return the minimum number of lines needed to represent the line chart.
    
    Example 1:
    
    
    >>> minimumLines(stockPrices = [[1,7],[2,6],[3,5],[4,4],[5,4],[6,3],[7,2],[8,1]])
    >>> 3
    Explanation:
    The diagram above represents the input, with the X-axis representing the day and Y-axis representing the price.
    The following 3 lines can be drawn to represent the line chart:
    - Line 1 (in red) from (1,7) to (4,4) passing through (1,7), (2,6), (3,5), and (4,4).
    - Line 2 (in blue) from (4,4) to (5,4).
    - Line 3 (in green) from (5,4) to (8,1) passing through (5,4), (6,3), (7,2), and (8,1).
    It can be shown that it is not possible to represent the line chart using less than 3 lines.
    
    Example 2:
    
    
    >>> minimumLines(stockPrices = [[3,4],[1,2],[7,8],[2,3]])
    >>> 1
    Explanation:
    As shown in the diagram above, the line chart can be represented with a single line.
    """
def totalStrength(strength: List[int]) -> int:
    """
    As the ruler of a kingdom, you have an army of wizards at your command.
    You are given a 0-indexed integer array strength, where strength[i] denotes the strength of the ith wizard. For a contiguous group of wizards (i.e. the wizards' strengths form a subarray of strength), the total strength is defined as the product of the following two values:
    
    The strength of the weakest wizard in the group.
    The total of all the individual strengths of the wizards in the group.
    
    Return the sum of the total strengths of all contiguous groups of wizards. Since the answer may be very large, return it modulo 109 + 7.
    A subarray is a contiguous non-empty sequence of elements within an array.
    
    Example 1:
    
    >>> totalStrength(strength = [1,3,1,2])
    >>> 44
    Explanation: The following are all the contiguous groups of wizards:
    - [1] from [1,3,1,2] has a total strength of min([1]) * sum([1]) = 1 * 1 = 1
    - [3] from [1,3,1,2] has a total strength of min([3]) * sum([3]) = 3 * 3 = 9
    - [1] from [1,3,1,2] has a total strength of min([1]) * sum([1]) = 1 * 1 = 1
    - [2] from [1,3,1,2] has a total strength of min([2]) * sum([2]) = 2 * 2 = 4
    - [1,3] from [1,3,1,2] has a total strength of min([1,3]) * sum([1,3]) = 1 * 4 = 4
    - [3,1] from [1,3,1,2] has a total strength of min([3,1]) * sum([3,1]) = 1 * 4 = 4
    - [1,2] from [1,3,1,2] has a total strength of min([1,2]) * sum([1,2]) = 1 * 3 = 3
    - [1,3,1] from [1,3,1,2] has a total strength of min([1,3,1]) * sum([1,3,1]) = 1 * 5 = 5
    - [3,1,2] from [1,3,1,2] has a total strength of min([3,1,2]) * sum([3,1,2]) = 1 * 6 = 6
    - [1,3,1,2] from [1,3,1,2] has a total strength of min([1,3,1,2]) * sum([1,3,1,2]) = 1 * 7 = 7
    The sum of all the total strengths is 1 + 9 + 1 + 4 + 4 + 4 + 3 + 5 + 6 + 7 = 44.
    
    Example 2:
    
    >>> totalStrength(strength = [5,4,6])
    >>> 213
    Explanation: The following are all the contiguous groups of wizards:
    - [5] from [5,4,6] has a total strength of min([5]) * sum([5]) = 5 * 5 = 25
    - [4] from [5,4,6] has a total strength of min([4]) * sum([4]) = 4 * 4 = 16
    - [6] from [5,4,6] has a total strength of min([6]) * sum([6]) = 6 * 6 = 36
    - [5,4] from [5,4,6] has a total strength of min([5,4]) * sum([5,4]) = 4 * 9 = 36
    - [4,6] from [5,4,6] has a total strength of min([4,6]) * sum([4,6]) = 4 * 10 = 40
    - [5,4,6] from [5,4,6] has a total strength of min([5,4,6]) * sum([5,4,6]) = 4 * 15 = 60
    The sum of all the total strengths is 25 + 16 + 36 + 36 + 40 + 60 = 213.
    """
def seePeople(heights: List[List[int]]) -> List[List[int]]:
    """
    You are given an m x n 0-indexed 2D array of positive integers heights where heights[i][j] is the height of the person standing at position (i, j).
    A person standing at position (row1, col1) can see a person standing at position (row2, col2) if:
    
    The person at (row2, col2) is to the right or below the person at (row1, col1). More formally, this means that either row1 == row2 and col1 < col2 or row1 < row2 and col1 == col2.
    Everyone in between them is shorter than both of them.
    
    Return an m x n 2D array of integers answer where answer[i][j] is the number of people that the person at position (i, j) can see.
    
    Example 1:
    
    
    >>> seePeople(heights = [[3,1,4,2,5]])
    >>> [[2,1,2,1,0]]
    Explanation:
    - The person at (0, 0) can see the people at (0, 1) and (0, 2).
      Note that he cannot see the person at (0, 4) because the person at (0, 2) is taller than him.
    - The person at (0, 1) can see the person at (0, 2).
    - The person at (0, 2) can see the people at (0, 3) and (0, 4).
    - The person at (0, 3) can see the person at (0, 4).
    - The person at (0, 4) cannot see anybody.
    
    Example 2:
    
    
    >>> seePeople(heights = [[5,1],[3,1],[4,1]])
    >>> [[3,1],[2,1],[1,0]]
    Explanation:
    - The person at (0, 0) can see the people at (0, 1), (1, 0) and (2, 0).
    - The person at (0, 1) can see the person at (1, 1).
    - The person at (1, 0) can see the people at (1, 1) and (2, 0).
    - The person at (1, 1) can see the person at (2, 1).
    - The person at (2, 0) can see the person at (2, 1).
    - The person at (2, 1) cannot see anybody.
    """