ShwStone/humaneval-leetcode huggingface dataset:
def areAlmostEqual(s1: str, s2: str) -> bool:
    """
    You are given two strings s1 and s2 of equal length. A string swap is an operation where you choose two indices in a string (not necessarily different) and swap the characters at these indices.
    Return true if it is possible to make both strings equal by performing at most one string swap on exactly one of the strings. Otherwise, return false.
    
    Example 1:
    
    >>> areAlmostEqual(s1 = "bank", s2 = "kanb")
    >>> true
    Explanation: For example, swap the first character with the last character of s2 to make "bank".
    
    Example 2:
    
    >>> areAlmostEqual(s1 = "attack", s2 = "defend")
    >>> false
    Explanation: It is impossible to make them equal with one string swap.
    
    Example 3:
    
    >>> areAlmostEqual(s1 = "kelb", s2 = "kelb")
    >>> true
    Explanation: The two strings are already equal, so no string swap operation is required.
    """
def findCenter(edges: List[List[int]]) -> int:
    """
    There is an undirected star graph consisting of n nodes labeled from 1 to n. A star graph is a graph where there is one center node and exactly n - 1 edges that connect the center node with every other node.
    You are given a 2D integer array edges where each edges[i] = [ui, vi] indicates that there is an edge between the nodes ui and vi. Return the center of the given star graph.
    
    Example 1:
    
    
    >>> findCenter(edges = [[1,2],[2,3],[4,2]])
    >>> 2
    Explanation: As shown in the figure above, node 2 is connected to every other node, so 2 is the center.
    
    Example 2:
    
    >>> findCenter(edges = [[1,2],[5,1],[1,3],[1,4]])
    >>> 1
    """
def maxAverageRatio(classes: List[List[int]], extraStudents: int) -> float:
    """
    There is a school that has classes of students and each class will be having a final exam. You are given a 2D integer array classes, where classes[i] = [passi, totali]. You know beforehand that in the ith class, there are totali total students, but only passi number of students will pass the exam.
    You are also given an integer extraStudents. There are another extraStudents brilliant students that are guaranteed to pass the exam of any class they are assigned to. You want to assign each of the extraStudents students to a class in a way that maximizes the average pass ratio across all the classes.
    The pass ratio of a class is equal to the number of students of the class that will pass the exam divided by the total number of students of the class. The average pass ratio is the sum of pass ratios of all the classes divided by the number of the classes.
    Return the maximum possible average pass ratio after assigning the extraStudents students. Answers within 10-5 of the actual answer will be accepted.
    
    Example 1:
    
    >>> maxAverageRatio(classes = [[1,2],[3,5],[2,2]], extraStudents = 2)
    >>> 0.78333
    Explanation: You can assign the two extra students to the first class. The average pass ratio will be equal to (3/4 + 3/5 + 2/2) / 3 = 0.78333.
    
    Example 2:
    
    >>> maxAverageRatio(classes = [[2,4],[3,9],[4,5],[2,10]], extraStudents = 4)
    >>> 0.53485
    """
def maximumScore(nums: List[int], k: int) -> int:
    """
    You are given an array of integers nums (0-indexed) and an integer k.
    The score of a subarray (i, j) is defined as min(nums[i], nums[i+1], ..., nums[j]) * (j - i + 1). A good subarray is a subarray where i <= k <= j.
    Return the maximum possible score of a good subarray.
    
    Example 1:
    
    >>> maximumScore(nums = [1,4,3,7,4,5], k = 3)
    >>> 15
    Explanation: The optimal subarray is (1, 5) with a score of min(4,3,7,4,5) * (5-1+1) = 3 * 5 = 15.
    
    Example 2:
    
    >>> maximumScore(nums = [5,5,4,5,4,1,1,1], k = 0)
    >>> 20
    Explanation: The optimal subarray is (0, 4) with a score of min(5,5,4,5,4) * (4-0+1) = 4 * 5 = 20.
    """
def countQuadruples(firstString: str, secondString: str) -> int:
    """
    You are given two strings firstString and secondString that are 0-indexed and consist only of lowercase English letters. Count the number of index quadruples (i,j,a,b) that satisfy the following conditions:
    
    0 <= i <= j < firstString.length
    0 <= a <= b < secondString.length
    The substring of firstString that starts at the ith character and ends at the jth character (inclusive) is equal to the substring of secondString that starts at the ath character and ends at the bth character (inclusive).
    j - a is the minimum possible value among all quadruples that satisfy the previous conditions.
    
    Return the number of such quadruples.
    
    Example 1:
    
    >>> countQuadruples(firstString = "abcd", secondString = "bccda")
    >>> 1
    Explanation: The quadruple (0,0,4,4) is the only one that satisfies all the conditions and minimizes j - a.
    
    Example 2:
    
    >>> countQuadruples(firstString = "ab", secondString = "cd")
    >>> 0
    Explanation: There are no quadruples satisfying all the conditions.
    """
def secondHighest(s: str) -> int:
    """
    Given an alphanumeric string s, return the second largest numerical digit that appears in s, or -1 if it does not exist.
    An alphanumeric string is a string consisting of lowercase English letters and digits.
    
    Example 1:
    
    >>> secondHighest(s = "dfa12321afd")
    >>> 2
    Explanation: The digits that appear in s are [1, 2, 3]. The second largest digit is 2.
    
    Example 2:
    
    >>> secondHighest(s = "abc1111")
    >>> -1
    Explanation: The digits that appear in s are [1]. There is no second largest digit.
    """
def getMaximumConsecutive(coins: List[int]) -> int:
    """
    You are given an integer array coins of length n which represents the n coins that you own. The value of the ith coin is coins[i]. You can make some value x if you can choose some of your n coins such that their values sum up to x.
    Return the maximum number of consecutive integer values that you can make with your coins starting from and including 0.
    Note that you may have multiple coins of the same value.
    
    Example 1:
    
    >>> getMaximumConsecutive(coins = [1,3])
    >>> 2
    Explanation: You can make the following values:
    - 0: take []
    - 1: take [1]
    You can make 2 consecutive integer values starting from 0.
    Example 2:
    
    >>> getMaximumConsecutive(coins = [1,1,1,4])
    >>> 8
    Explanation: You can make the following values:
    - 0: take []
    - 1: take [1]
    - 2: take [1,1]
    - 3: take [1,1,1]
    - 4: take [4]
    - 5: take [4,1]
    - 6: take [4,1,1]
    - 7: take [4,1,1,1]
    You can make 8 consecutive integer values starting from 0.
    Example 3:
    
    >>> getMaximumConsecutive(coins = [1,4,10,3,1])
    >>> 20
    """
def maxAscendingSum(nums: List[int]) -> int:
    """
    Given an array of positive integers nums, return the maximum possible sum of an strictly increasing subarray in nums.
    A subarray is defined as a contiguous sequence of numbers in an array.
    
    Example 1:
    
    >>> maxAscendingSum(nums = [10,20,30,5,10,50])
    >>> 65
    Explanation: [5,10,50] is the ascending subarray with the maximum sum of 65.
    
    Example 2:
    
    >>> maxAscendingSum(nums = [10,20,30,40,50])
    >>> 150
    Explanation: [10,20,30,40,50] is the ascending subarray with the maximum sum of 150.
    
    Example 3:
    
    >>> maxAscendingSum(nums = [12,17,15,13,10,11,12])
    >>> 33
    Explanation: [10,11,12] is the ascending subarray with the maximum sum of 33.
    """
def maxValue(n: int, index: int, maxSum: int) -> int:
    """
    You are given three positive integers: n, index, and maxSum. You want to construct an array nums (0-indexed) that satisfies the following conditions:
    
    nums.length == n
    nums[i] is a positive integer where 0 <= i < n.
    abs(nums[i] - nums[i+1]) <= 1 where 0 <= i < n-1.
    The sum of all the elements of nums does not exceed maxSum.
    nums[index] is maximized.
    
    Return nums[index] of the constructed array.
    Note that abs(x) equals x if x >= 0, and -x otherwise.
    
    Example 1:
    
    >>> maxValue(n = 4, index = 2,  maxSum = 6)
    >>> 2
    Explanation: nums = [1,2,2,1] is one array that satisfies all the conditions.
    There are no arrays that satisfy all the conditions and have nums[2] == 3, so 2 is the maximum nums[2].
    
    Example 2:
    
    >>> maxValue(n = 6, index = 1,  maxSum = 10)
    >>> 3
    """
def countPairs(nums: List[int], low: int, high: int) -> int:
    """
    Given a (0-indexed) integer array nums and two integers low and high, return the number of nice pairs.\r
    \r
    A nice pair is a pair (i, j) where 0 <= i < j < nums.length and low <= (nums[i] XOR nums[j]) <= high.\r
    \r
     \r
    Example 1:\r
    \r
    \r
    >>> countPairs(nums = [1,4,2,7], low = 2, high = 6\r)
    >>> 6\r
    Explanation: All nice pairs (i, j) are as follows:\r
        - (0, 1): nums[0] XOR nums[1] = 5 \r
        - (0, 2): nums[0] XOR nums[2] = 3\r
        - (0, 3): nums[0] XOR nums[3] = 6\r
        - (1, 2): nums[1] XOR nums[2] = 6\r
        - (1, 3): nums[1] XOR nums[3] = 3\r
        - (2, 3): nums[2] XOR nums[3] = 5\r
    \r
    \r
    Example 2:\r
    \r
    \r
    >>> countPairs(nums = [9,8,4,2,1], low = 5, high = 14\r)
    >>> 8\r
    Explanation: All nice pairs (i, j) are as follows:\r
    ​​​​​    - (0, 2): nums[0] XOR nums[2] = 13\r
        - (0, 3): nums[0] XOR nums[3] = 11\r
        - (0, 4): nums[0] XOR nums[4] = 8\r
        - (1, 2): nums[1] XOR nums[2] = 12\r
        - (1, 3): nums[1] XOR nums[3] = 10\r
        - (1, 4): nums[1] XOR nums[4] = 9\r
        - (2, 3): nums[2] XOR nums[3] = 6\r
        - (2, 4): nums[2] XOR nums[4] = 5\r
    \r
     \r
    """
def numDifferentIntegers(word: str) -> int:
    """
    You are given a string word that consists of digits and lowercase English letters.
    You will replace every non-digit character with a space. For example, "a123bc34d8ef34" will become " 123  34 8  34". Notice that you are left with some integers that are separated by at least one space: "123", "34", "8", and "34".
    Return the number of different integers after performing the replacement operations on word.
    Two integers are considered different if their decimal representations without any leading zeros are different.
    
    Example 1:
    
    >>> numDifferentIntegers(word = "a123bc34d8ef34")
    >>> 3
    Explanation: The three different integers are "123", "34", and "8". Notice that "34" is only counted once.
    
    Example 2:
    
    >>> numDifferentIntegers(word = "leet1234code234")
    >>> 2
    
    Example 3:
    
    >>> numDifferentIntegers(word = "a1b01c001")
    >>> 1
    Explanation: The three integers "1", "01", and "001" all represent the same integer because
    the leading zeros are ignored when comparing their decimal values.
    """
def reinitializePermutation(n: int) -> int:
    """
    You are given an even integer n​​​​​​. You initially have a permutation perm of size n​​ where perm[i] == i​ (0-indexed)​​​​.
    In one operation, you will create a new array arr, and for each i:
    
    If i % 2 == 0, then arr[i] = perm[i / 2].
    If i % 2 == 1, then arr[i] = perm[n / 2 + (i - 1) / 2].
    
    You will then assign arr​​​​ to perm.
    Return the minimum non-zero number of operations you need to perform on perm to return the permutation to its initial value.
    
    Example 1:
    
    >>> reinitializePermutation(n = 2)
    >>> 1
    Explanation: perm = [0,1] initially.
    After the 1st operation, perm = [0,1]
    So it takes only 1 operation.
    
    Example 2:
    
    >>> reinitializePermutation(n = 4)
    >>> 2
    Explanation: perm = [0,1,2,3] initially.
    After the 1st operation, perm = [0,2,1,3]
    After the 2nd operation, perm = [0,1,2,3]
    So it takes only 2 operations.
    
    Example 3:
    
    >>> reinitializePermutation(n = 6)
    >>> 4
    """
def evaluate(s: str, knowledge: List[List[str]]) -> str:
    """
    You are given a string s that contains some bracket pairs, with each pair containing a non-empty key.
    
    For example, in the string "(name)is(age)yearsold", there are two bracket pairs that contain the keys "name" and "age".
    
    You know the values of a wide range of keys. This is represented by a 2D string array knowledge where each knowledge[i] = [keyi, valuei] indicates that key keyi has a value of valuei.
    You are tasked to evaluate all of the bracket pairs. When you evaluate a bracket pair that contains some key keyi, you will:
    
    Replace keyi and the bracket pair with the key's corresponding valuei.
    If you do not know the value of the key, you will replace keyi and the bracket pair with a question mark "?" (without the quotation marks).
    
    Each key will appear at most once in your knowledge. There will not be any nested brackets in s.
    Return the resulting string after evaluating all of the bracket pairs.
    
    Example 1:
    
    >>> evaluate(s = "(name)is(age)yearsold", knowledge = [["name","bob"],["age","two"]])
    >>> "bobistwoyearsold"
    Explanation:
    The key "name" has a value of "bob", so replace "(name)" with "bob".
    The key "age" has a value of "two", so replace "(age)" with "two".
    
    Example 2:
    
    >>> evaluate(s = "hi(name)", knowledge = [["a","b"]])
    >>> "hi?"
    Explanation: As you do not know the value of the key "name", replace "(name)" with "?".
    
    Example 3:
    
    >>> evaluate(s = "(a)(a)(a)aaa", knowledge = [["a","yes"]])
    >>> "yesyesyesaaa"
    Explanation: The same key can appear multiple times.
    The key "a" has a value of "yes", so replace all occurrences of "(a)" with "yes".
    Notice that the "a"s not in a bracket pair are not evaluated.
    """
def maxNiceDivisors(primeFactors: int) -> int:
    """
    You are given a positive integer primeFactors. You are asked to construct a positive integer n that satisfies the following conditions:\r
    \r
    \r
      The number of prime factors of n (not necessarily distinct) is at most primeFactors.\r
      The number of nice divisors of n is maximized. Note that a divisor of n is nice if it is divisible by every prime factor of n. For example, if n = 12, then its prime factors are [2,2,3], then 6 and 12 are nice divisors, while 3 and 4 are not.\r
    \r
    \r
    Return the number of nice divisors of n. Since that number can be too large, return it modulo 109 + 7.\r
    \r
    Note that a prime number is a natural number greater than 1 that is not a product of two smaller natural numbers. The prime factors of a number n is a list of prime numbers such that their product equals n.\r
    \r
     \r
    Example 1:\r
    \r
    \r
    >>> maxNiceDivisors(primeFactors = 5\r)
    >>> 6\r
    Explanation: 200 is a valid value of n.\r
    It has 5 prime factors: [2,2,2,5,5], and it has 6 nice divisors: [10,20,40,50,100,200].\r
    There is not other value of n that has at most 5 prime factors and more nice divisors.\r
    \r
    \r
    Example 2:\r
    \r
    \r
    >>> maxNiceDivisors(primeFactors = 8\r)
    >>> 18\r
    \r
    \r
     \r
    """
def squareIsWhite(coordinates: str) -> bool:
    """
    You are given coordinates, a string that represents the coordinates of a square of the chessboard. Below is a chessboard for your reference.
    
    Return true if the square is white, and false if the square is black.
    The coordinate will always represent a valid chessboard square. The coordinate will always have the letter first, and the number second.
    
    Example 1:
    
    >>> squareIsWhite(coordinates = "a1")
    >>> false
    Explanation: From the chessboard above, the square with coordinates "a1" is black, so return false.
    
    Example 2:
    
    >>> squareIsWhite(coordinates = "h3")
    >>> true
    Explanation: From the chessboard above, the square with coordinates "h3" is white, so return true.
    
    Example 3:
    
    >>> squareIsWhite(coordinates = "c7")
    >>> false
    """
def areSentencesSimilar(sentence1: str, sentence2: str) -> bool:
    """
    You are given two strings sentence1 and sentence2, each representing a sentence composed of words. A sentence is a list of words that are separated by a single space with no leading or trailing spaces. Each word consists of only uppercase and lowercase English characters.
    Two sentences s1 and s2 are considered similar if it is possible to insert an arbitrary sentence (possibly empty) inside one of these sentences such that the two sentences become equal. Note that the inserted sentence must be separated from existing words by spaces.
    For example,
    
    s1 = "Hello Jane" and s2 = "Hello my name is Jane" can be made equal by inserting "my name is" between "Hello" and "Jane" in s1.
    s1 = "Frog cool" and s2 = "Frogs are cool" are not similar, since although there is a sentence "s are" inserted into s1, it is not separated from "Frog" by a space.
    
    Given two sentences sentence1 and sentence2, return true if sentence1 and sentence2 are similar. Otherwise, return false.
    
    Example 1:
    
    >>> areSentencesSimilar(sentence1 = "My name is Haley", sentence2 = "My Haley")
    >>> true
    Explanation:
    sentence2 can be turned to sentence1 by inserting "name is" between "My" and "Haley".
    
    Example 2:
    
    >>> areSentencesSimilar(sentence1 = "of", sentence2 = "A lot of words")
    >>> false
    Explanation:
    No single sentence can be inserted inside one of the sentences to make it equal to the other.
    
    Example 3:
    
    >>> areSentencesSimilar(sentence1 = "Eating right now", sentence2 = "Eating")
    >>> true
    Explanation:
    sentence2 can be turned to sentence1 by inserting "right now" at the end of the sentence.
    """
def countNicePairs(nums: List[int]) -> int:
    """
    You are given an array nums that consists of non-negative integers. Let us define rev(x) as the reverse of the non-negative integer x. For example, rev(123) = 321, and rev(120) = 21. A pair of indices (i, j) is nice if it satisfies all of the following conditions:
    
    0 <= i < j < nums.length
    nums[i] + rev(nums[j]) == nums[j] + rev(nums[i])
    
    Return the number of nice pairs of indices. Since that number can be too large, return it modulo 109 + 7.
    
    Example 1:
    
    >>> countNicePairs(nums = [42,11,1,97])
    >>> 2
    Explanation: The two pairs are:
     - (0,3) : 42 + rev(97) = 42 + 79 = 121, 97 + rev(42) = 97 + 24 = 121.
     - (1,2) : 11 + rev(1) = 11 + 1 = 12, 1 + rev(11) = 1 + 11 = 12.
    
    Example 2:
    
    >>> countNicePairs(nums = [13,10,35,24,76])
    >>> 4
    """
def maxHappyGroups(batchSize: int, groups: List[int]) -> int:
    """
    There is a donuts shop that bakes donuts in batches of batchSize. They have a rule where they must serve all of the donuts of a batch before serving any donuts of the next batch. You are given an integer batchSize and an integer array groups, where groups[i] denotes that there is a group of groups[i] customers that will visit the shop. Each customer will get exactly one donut.
    When a group visits the shop, all customers of the group must be served before serving any of the following groups. A group will be happy if they all get fresh donuts. That is, the first customer of the group does not receive a donut that was left over from the previous group.
    You can freely rearrange the ordering of the groups. Return the maximum possible number of happy groups after rearranging the groups.
    
    Example 1:
    
    >>> maxHappyGroups(batchSize = 3, groups = [1,2,3,4,5,6])
    >>> 4
    Explanation: You can arrange the groups as [6,2,4,5,1,3]. Then the 1st, 2nd, 4th, and 6th groups will be happy.
    
    Example 2:
    
    >>> maxHappyGroups(batchSize = 4, groups = [1,3,2,5,2,2,1,6])
    >>> 4
    """
def truncateSentence(s: str, k: int) -> str:
    """
    A sentence is a list of words that are separated by a single space with no leading or trailing spaces. Each of the words consists of only uppercase and lowercase English letters (no punctuation).
    
    For example, "Hello World", "HELLO", and "hello world hello world" are all sentences.
    
    You are given a sentence s​​​​​​ and an integer k​​​​​​. You want to truncate s​​​​​​ such that it contains only the first k​​​​​​ words. Return s​​​​​​ after truncating it.
    
    Example 1:
    
    >>> truncateSentence(s = "Hello how are you Contestant", k = 4)
    >>> "Hello how are you"
    Explanation:
    The words in s are ["Hello", "how" "are", "you", "Contestant"].
    The first 4 words are ["Hello", "how", "are", "you"].
    Hence, you should return "Hello how are you".
    
    Example 2:
    
    >>> truncateSentence(s = "What is the solution to this problem", k = 4)
    >>> "What is the solution"
    Explanation:
    The words in s are ["What", "is" "the", "solution", "to", "this", "problem"].
    The first 4 words are ["What", "is", "the", "solution"].
    Hence, you should return "What is the solution".
    Example 3:
    
    >>> truncateSentence(s = "chopper is not a tanuki", k = 5)
    >>> "chopper is not a tanuki"
    """
def findingUsersActiveMinutes(logs: List[List[int]], k: int) -> List[int]:
    """
    You are given the logs for users' actions on LeetCode, and an integer k. The logs are represented by a 2D integer array logs where each logs[i] = [IDi, timei] indicates that the user with IDi performed an action at the minute timei.
    Multiple users can perform actions simultaneously, and a single user can perform multiple actions in the same minute.
    The user active minutes (UAM) for a given user is defined as the number of unique minutes in which the user performed an action on LeetCode. A minute can only be counted once, even if multiple actions occur during it.
    You are to calculate a 1-indexed array answer of size k such that, for each j (1 <= j <= k), answer[j] is the number of users whose UAM equals j.
    Return the array answer as described above.
    
    Example 1:
    
    >>> findingUsersActiveMinutes(logs = [[0,5],[1,2],[0,2],[0,5],[1,3]], k = 5)
    >>> [0,2,0,0,0]
    Explanation:
    The user with ID=0 performed actions at minutes 5, 2, and 5 again. Hence, they have a UAM of 2 (minute 5 is only counted once).
    The user with ID=1 performed actions at minutes 2 and 3. Hence, they have a UAM of 2.
    Since both users have a UAM of 2, answer[2] is 2, and the remaining answer[j] values are 0.
    
    Example 2:
    
    >>> findingUsersActiveMinutes(logs = [[1,1],[2,2],[2,3]], k = 4)
    >>> [1,1,0,0]
    Explanation:
    The user with ID=1 performed a single action at minute 1. Hence, they have a UAM of 1.
    The user with ID=2 performed actions at minutes 2 and 3. Hence, they have a UAM of 2.
    There is one user with a UAM of 1 and one with a UAM of 2.
    Hence, answer[1] = 1, answer[2] = 1, and the remaining values are 0.
    """