ShwStone/humaneval-leetcode huggingface dataset:
def countDaysTogether(arriveAlice: str, leaveAlice: str, arriveBob: str, leaveBob: str) -> int:
    """
    Alice and Bob are traveling to Rome for separate business meetings.
    You are given 4 strings arriveAlice, leaveAlice, arriveBob, and leaveBob. Alice will be in the city from the dates arriveAlice to leaveAlice (inclusive), while Bob will be in the city from the dates arriveBob to leaveBob (inclusive). Each will be a 5-character string in the format "MM-DD", corresponding to the month and day of the date.
    Return the total number of days that Alice and Bob are in Rome together.
    You can assume that all dates occur in the same calendar year, which is not a leap year. Note that the number of days per month can be represented as: [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31].
    
    Example 1:
    
    >>> countDaysTogether(arriveAlice = "08-15", leaveAlice = "08-18", arriveBob = "08-16", leaveBob = "08-19")
    >>> 3
    Explanation: Alice will be in Rome from August 15 to August 18. Bob will be in Rome from August 16 to August 19. They are both in Rome together on August 16th, 17th, and 18th, so the answer is 3.
    
    Example 2:
    
    >>> countDaysTogether(arriveAlice = "10-01", leaveAlice = "10-31", arriveBob = "11-01", leaveBob = "12-31")
    >>> 0
    Explanation: There is no day when Alice and Bob are in Rome together, so we return 0.
    """
def matchPlayersAndTrainers(players: List[int], trainers: List[int]) -> int:
    """
    You are given a 0-indexed integer array players, where players[i] represents the ability of the ith player. You are also given a 0-indexed integer array trainers, where trainers[j] represents the training capacity of the jth trainer.
    The ith player can match with the jth trainer if the player's ability is less than or equal to the trainer's training capacity. Additionally, the ith player can be matched with at most one trainer, and the jth trainer can be matched with at most one player.
    Return the maximum number of matchings between players and trainers that satisfy these conditions.
    
    Example 1:
    
    >>> matchPlayersAndTrainers(players = [4,7,9], trainers = [8,2,5,8])
    >>> 2
    Explanation:
    One of the ways we can form two matchings is as follows:
    - players[0] can be matched with trainers[0] since 4 <= 8.
    - players[1] can be matched with trainers[3] since 7 <= 8.
    It can be proven that 2 is the maximum number of matchings that can be formed.
    
    Example 2:
    
    >>> matchPlayersAndTrainers(players = [1,1,1], trainers = [10])
    >>> 1
    Explanation:
    The trainer can be matched with any of the 3 players.
    Each player can only be matched with one trainer, so the maximum answer is 1.
    """
def smallestSubarrays(nums: List[int]) -> List[int]:
    """
    You are given a 0-indexed array nums of length n, consisting of non-negative integers. For each index i from 0 to n - 1, you must determine the size of the minimum sized non-empty subarray of nums starting at i (inclusive) that has the maximum possible bitwise OR.
    
    In other words, let Bij be the bitwise OR of the subarray nums[i...j]. You need to find the smallest subarray starting at i, such that bitwise OR of this subarray is equal to max(Bik) where i <= k <= n - 1.
    
    The bitwise OR of an array is the bitwise OR of all the numbers in it.
    Return an integer array answer of size n where answer[i] is the length of the minimum sized subarray starting at i with maximum bitwise OR.
    A subarray is a contiguous non-empty sequence of elements within an array.
    
    Example 1:
    
    >>> smallestSubarrays(nums = [1,0,2,1,3])
    >>> [3,3,2,2,1]
    Explanation:
    The maximum possible bitwise OR starting at any index is 3.
    - Starting at index 0, the shortest subarray that yields it is [1,0,2].
    - Starting at index 1, the shortest subarray that yields the maximum bitwise OR is [0,2,1].
    - Starting at index 2, the shortest subarray that yields the maximum bitwise OR is [2,1].
    - Starting at index 3, the shortest subarray that yields the maximum bitwise OR is [1,3].
    - Starting at index 4, the shortest subarray that yields the maximum bitwise OR is [3].
    Therefore, we return [3,3,2,2,1].
    
    Example 2:
    
    >>> smallestSubarrays(nums = [1,2])
    >>> [2,1]
    Explanation:
    Starting at index 0, the shortest subarray that yields the maximum bitwise OR is of length 2.
    Starting at index 1, the shortest subarray that yields the maximum bitwise OR is of length 1.
    Therefore, we return [2,1].
    """
def minimumMoney(transactions: List[List[int]]) -> int:
    """
    You are given a 0-indexed 2D integer array transactions, where transactions[i] = [costi, cashbacki].
    The array describes transactions, where each transaction must be completed exactly once in some order. At any given moment, you have a certain amount of money. In order to complete transaction i, money >= costi must hold true. After performing a transaction, money becomes money - costi + cashbacki.
    Return the minimum amount of money required before any transaction so that all of the transactions can be completed regardless of the order of the transactions.
    
    Example 1:
    
    >>> minimumMoney(transactions = [[2,1],[5,0],[4,2]])
    >>> 10
    Explanation:
    Starting with money = 10, the transactions can be performed in any order.
    It can be shown that starting with money < 10 will fail to complete all transactions in some order.
    
    Example 2:
    
    >>> minimumMoney(transactions = [[3,0],[0,3]])
    >>> 3
    Explanation:
    - If transactions are in the order [[3,0],[0,3]], the minimum money required to complete the transactions is 3.
    - If transactions are in the order [[0,3],[3,0]], the minimum money required to complete the transactions is 0.
    Thus, starting with money = 3, the transactions can be performed in any order.
    """
def smallestEvenMultiple(n: int) -> int:
    """
    Given a positive integer n, return the smallest positive integer that is a multiple of both 2 and n.
    
    Example 1:
    
    >>> smallestEvenMultiple(n = 5)
    >>> 10
    Explanation: The smallest multiple of both 5 and 2 is 10.
    
    Example 2:
    
    >>> smallestEvenMultiple(n = 6)
    >>> 6
    Explanation: The smallest multiple of both 6 and 2 is 6. Note that a number is a multiple of itself.
    """
def longestContinuousSubstring(s: str) -> int:
    """
    An alphabetical continuous string is a string consisting of consecutive letters in the alphabet. In other words, it is any substring of the string "abcdefghijklmnopqrstuvwxyz".
    
    For example, "abc" is an alphabetical continuous string, while "acb" and "za" are not.
    
    Given a string s consisting of lowercase letters only, return the length of the longest alphabetical continuous substring.
    
    Example 1:
    
    >>> longestContinuousSubstring(s = "abacaba")
    >>> 2
    Explanation: There are 4 distinct continuous substrings: "a", "b", "c" and "ab".
    "ab" is the longest continuous substring.
    
    Example 2:
    
    >>> longestContinuousSubstring(s = "abcde")
    >>> 5
    Explanation: "abcde" is the longest continuous substring.
    """
# class TreeNode:
#     def __init__(val=0, left=None, right=None):
#         self.val = val
#         self.left = left
#         self.right = right
class Solution:
    def reverseOddLevels(root: Optional[TreeNode]) -> Optional[TreeNode]:
    """
    Given the root of a perfect binary tree, reverse the node values at each odd level of the tree.
    
    For example, suppose the node values at level 3 are [2,1,3,4,7,11,29,18], then it should become [18,29,11,7,4,3,1,2].
    
    Return the root of the reversed tree.
    A binary tree is perfect if all parent nodes have two children and all leaves are on the same level.
    The level of a node is the number of edges along the path between it and the root node.
    
    Example 1:
    
    
    >>> __init__(root = [2,3,5,8,13,21,34])
    >>> [2,5,3,8,13,21,34]
    Explanation:
    The tree has only one odd level.
    The nodes at level 1 are 3, 5 respectively, which are reversed and become 5, 3.
    
    Example 2:
    
    
    >>> __init__(root = [7,13,11])
    >>> [7,11,13]
    Explanation:
    The nodes at level 1 are 13, 11, which are reversed and become 11, 13.
    
    Example 3:
    
    >>> __init__(root = [0,1,2,0,0,0,0,1,1,1,1,2,2,2,2])
    >>> [0,2,1,0,0,0,0,2,2,2,2,1,1,1,1]
    Explanation:
    The odd levels have non-zero values.
    The nodes at level 1 were 1, 2, and are 2, 1 after the reversal.
    The nodes at level 3 were 1, 1, 1, 1, 2, 2, 2, 2, and are 2, 2, 2, 2, 1, 1, 1, 1 after the reversal.
    """
def sumPrefixScores(words: List[str]) -> List[int]:
    """
    You are given an array words of size n consisting of non-empty strings.
    We define the score of a string term as the number of strings words[i] such that term is a prefix of words[i].
    
    For example, if words = ["a", "ab", "abc", "cab"], then the score of "ab" is 2, since "ab" is a prefix of both "ab" and "abc".
    
    Return an array answer of size n where answer[i] is the sum of scores of every non-empty prefix of words[i].
    Note that a string is considered as a prefix of itself.
    
    Example 1:
    
    >>> sumPrefixScores(words = ["abc","ab","bc","b"])
    >>> [5,4,3,2]
    Explanation: The answer for each string is the following:
    - "abc" has 3 prefixes: "a", "ab", and "abc".
    - There are 2 strings with the prefix "a", 2 strings with the prefix "ab", and 1 string with the prefix "abc".
    The total is answer[0] = 2 + 2 + 1 = 5.
    - "ab" has 2 prefixes: "a" and "ab".
    - There are 2 strings with the prefix "a", and 2 strings with the prefix "ab".
    The total is answer[1] = 2 + 2 = 4.
    - "bc" has 2 prefixes: "b" and "bc".
    - There are 2 strings with the prefix "b", and 1 string with the prefix "bc".
    The total is answer[2] = 2 + 1 = 3.
    - "b" has 1 prefix: "b".
    - There are 2 strings with the prefix "b".
    The total is answer[3] = 2.
    
    Example 2:
    
    >>> sumPrefixScores(words = ["abcd"])
    >>> [4]
    Explanation:
    "abcd" has 4 prefixes: "a", "ab", "abc", and "abcd".
    Each prefix has a score of one, so the total is answer[0] = 1 + 1 + 1 + 1 = 4.
    """
def closestFair(n: int) -> int:
    """
    You are given a positive integer n.
    We call an integer k fair if the number of even digits in k is equal to the number of odd digits in it.
    Return the smallest fair integer that is greater than or equal to n.
    
    Example 1:
    
    >>> closestFair(n = 2)
    >>> 10
    Explanation: The smallest fair integer that is greater than or equal to 2 is 10.
    10 is fair because it has an equal number of even and odd digits (one odd digit and one even digit).
    Example 2:
    
    >>> closestFair(n = 403)
    >>> 1001
    Explanation: The smallest fair integer that is greater than or equal to 403 is 1001.
    1001 is fair because it has an equal number of even and odd digits (two odd digits and two even digits).
    """
def sortPeople(names: List[str], heights: List[int]) -> List[str]:
    """
    You are given an array of strings names, and an array heights that consists of distinct positive integers. Both arrays are of length n.
    For each index i, names[i] and heights[i] denote the name and height of the ith person.
    Return names sorted in descending order by the people's heights.
    
    Example 1:
    
    >>> sortPeople(names = ["Mary","John","Emma"], heights = [180,165,170])
    >>> ["Mary","Emma","John"]
    Explanation: Mary is the tallest, followed by Emma and John.
    
    Example 2:
    
    >>> sortPeople(names = ["Alice","Bob","Bob"], heights = [155,185,150])
    >>> ["Bob","Alice","Bob"]
    Explanation: The first Bob is the tallest, followed by Alice and the second Bob.
    """
def longestSubarray(nums: List[int]) -> int:
    """
    You are given an integer array nums of size n.
    Consider a non-empty subarray from nums that has the maximum possible bitwise AND.
    
    In other words, let k be the maximum value of the bitwise AND of any subarray of nums. Then, only subarrays with a bitwise AND equal to k should be considered.
    
    Return the length of the longest such subarray.
    The bitwise AND of an array is the bitwise AND of all the numbers in it.
    A subarray is a contiguous sequence of elements within an array.
    
    Example 1:
    
    >>> longestSubarray(nums = [1,2,3,3,2,2])
    >>> 2
    Explanation:
    The maximum possible bitwise AND of a subarray is 3.
    The longest subarray with that value is [3,3], so we return 2.
    
    Example 2:
    
    >>> longestSubarray(nums = [1,2,3,4])
    >>> 1
    Explanation:
    The maximum possible bitwise AND of a subarray is 4.
    The longest subarray with that value is [4], so we return 1.
    """
def goodIndices(nums: List[int], k: int) -> List[int]:
    """
    You are given a 0-indexed integer array nums of size n and a positive integer k.
    We call an index i in the range k <= i < n - k good if the following conditions are satisfied:
    
    The k elements that are just before the index i are in non-increasing order.
    The k elements that are just after the index i are in non-decreasing order.
    
    Return an array of all good indices sorted in increasing order.
    
    Example 1:
    
    >>> goodIndices(nums = [2,1,1,1,3,4,1], k = 2)
    >>> [2,3]
    Explanation: There are two good indices in the array:
    - Index 2. The subarray [2,1] is in non-increasing order, and the subarray [1,3] is in non-decreasing order.
    - Index 3. The subarray [1,1] is in non-increasing order, and the subarray [3,4] is in non-decreasing order.
    Note that the index 4 is not good because [4,1] is not non-decreasing.
    Example 2:
    
    >>> goodIndices(nums = [2,1,1,2], k = 2)
    >>> []
    Explanation: There are no good indices in this array.
    """
def numberOfGoodPaths(vals: List[int], edges: List[List[int]]) -> int:
    """
    There is a tree (i.e. a connected, undirected graph with no cycles) consisting of n nodes numbered from 0 to n - 1 and exactly n - 1 edges.
    You are given a 0-indexed integer array vals of length n where vals[i] denotes the value of the ith node. You are also given a 2D integer array edges where edges[i] = [ai, bi] denotes that there exists an undirected edge connecting nodes ai and bi.
    A good path is a simple path that satisfies the following conditions:
    
    The starting node and the ending node have the same value.
    All nodes between the starting node and the ending node have values less than or equal to the starting node (i.e. the starting node's value should be the maximum value along the path).
    
    Return the number of distinct good paths.
    Note that a path and its reverse are counted as the same path. For example, 0 -> 1 is considered to be the same as 1 -> 0. A single node is also considered as a valid path.
    
    Example 1:
    
    
    >>> numberOfGoodPaths(vals = [1,3,2,1,3], edges = [[0,1],[0,2],[2,3],[2,4]])
    >>> 6
    Explanation: There are 5 good paths consisting of a single node.
    There is 1 additional good path: 1 -> 0 -> 2 -> 4.
    (The reverse path 4 -> 2 -> 0 -> 1 is treated as the same as 1 -> 0 -> 2 -> 4.)
    Note that 0 -> 2 -> 3 is not a good path because vals[2] > vals[0].
    
    Example 2:
    
    
    >>> numberOfGoodPaths(vals = [1,1,2,2,3], edges = [[0,1],[1,2],[2,3],[2,4]])
    >>> 7
    Explanation: There are 5 good paths consisting of a single node.
    There are 2 additional good paths: 0 -> 1 and 2 -> 3.
    
    Example 3:
    
    
    >>> numberOfGoodPaths(vals = [1], edges = [])
    >>> 1
    Explanation: The tree consists of only one node, so there is one good path.
    """
def minimumOperations(nums: List[int]) -> int:
    """
    You are given an array nums consisting of positive integers.
    You can perform the following operation on the array any number of times:
    
    Choose any two adjacent elements and replace them with their sum.
    
    
    For example, if nums = [1,2,3,1], you can apply one operation to make it [1,5,1].
    
    
    
    Return the minimum number of operations needed to turn the array into a palindrome.
    
    Example 1:
    
    >>> minimumOperations(nums = [4,3,2,1,2,3,1])
    >>> 2
    Explanation: We can turn the array into a palindrome in 2 operations as follows:
    - Apply the operation on the fourth and fifth element of the array, nums becomes equal to [4,3,2,3,3,1].
    - Apply the operation on the fifth and sixth element of the array, nums becomes equal to [4,3,2,3,4].
    The array [4,3,2,3,4] is a palindrome.
    It can be shown that 2 is the minimum number of operations needed.
    
    Example 2:
    
    >>> minimumOperations(nums = [1,2,3,4])
    >>> 3
    Explanation: We do the operation 3 times in any position, we obtain the array [10] at the end which is a palindrome.
    """
def equalFrequency(word: str) -> bool:
    """
    You are given a 0-indexed string word, consisting of lowercase English letters. You need to select one index and remove the letter at that index from word so that the frequency of every letter present in word is equal.
    Return true if it is possible to remove one letter so that the frequency of all letters in word are equal, and false otherwise.
    Note:
    
    The frequency of a letter x is the number of times it occurs in the string.
    You must remove exactly one letter and cannot choose to do nothing.
    
    
    Example 1:
    
    >>> equalFrequency(word = "abcc")
    >>> true
    Explanation: Select index 3 and delete it: word becomes "abc" and each character has a frequency of 1.
    
    Example 2:
    
    >>> equalFrequency(word = "aazz")
    >>> false
    Explanation: We must delete a character, so either the frequency of "a" is 1 and the frequency of "z" is 2, or vice versa. It is impossible to make all present letters have equal frequency.
    """
def xorAllNums(nums1: List[int], nums2: List[int]) -> int:
    """
    You are given two 0-indexed arrays, nums1 and nums2, consisting of non-negative integers. Let there be another array, nums3, which contains the bitwise XOR of all pairings of integers between nums1 and nums2 (every integer in nums1 is paired with every integer in nums2 exactly once).
    Return the bitwise XOR of all integers in nums3.
    
    Example 1:
    
    >>> xorAllNums(nums1 = [2,1,3], nums2 = [10,2,5,0])
    >>> 13
    Explanation:
    A possible nums3 array is [8,0,7,2,11,3,4,1,9,1,6,3].
    The bitwise XOR of all these numbers is 13, so we return 13.
    
    Example 2:
    
    >>> xorAllNums(nums1 = [1,2], nums2 = [3,4])
    >>> 0
    Explanation:
    All possible pairs of bitwise XORs are nums1[0] ^ nums2[0], nums1[0] ^ nums2[1], nums1[1] ^ nums2[0],
    and nums1[1] ^ nums2[1].
    Thus, one possible nums3 array is [2,5,1,6].
    2 ^ 5 ^ 1 ^ 6 = 0, so we return 0.
    """
def numberOfPairs(nums1: List[int], nums2: List[int], diff: int) -> int:
    """
    You are given two 0-indexed integer arrays nums1 and nums2, each of size n, and an integer diff. Find the number of pairs (i, j) such that:
    
    0 <= i < j <= n - 1 and
    nums1[i] - nums1[j] <= nums2[i] - nums2[j] + diff.
    
    Return the number of pairs that satisfy the conditions.
    
    Example 1:
    
    >>> numberOfPairs(nums1 = [3,2,5], nums2 = [2,2,1], diff = 1)
    >>> 3
    Explanation:
    There are 3 pairs that satisfy the conditions:
    1. i = 0, j = 1: 3 - 2 <= 2 - 2 + 1. Since i < j and 1 <= 1, this pair satisfies the conditions.
    2. i = 0, j = 2: 3 - 5 <= 2 - 1 + 1. Since i < j and -2 <= 2, this pair satisfies the conditions.
    3. i = 1, j = 2: 2 - 5 <= 2 - 1 + 1. Since i < j and -3 <= 2, this pair satisfies the conditions.
    Therefore, we return 3.
    
    Example 2:
    
    >>> numberOfPairs(nums1 = [3,-1], nums2 = [-2,2], diff = -1)
    >>> 0
    Explanation:
    Since there does not exist any pair that satisfies the conditions, we return 0.
    """
def commonFactors(a: int, b: int) -> int:
    """
    Given two positive integers a and b, return the number of common factors of a and b.
    An integer x is a common factor of a and b if x divides both a and b.
    
    Example 1:
    
    >>> commonFactors(a = 12, b = 6)
    >>> 4
    Explanation: The common factors of 12 and 6 are 1, 2, 3, 6.
    
    Example 2:
    
    >>> commonFactors(a = 25, b = 30)
    >>> 2
    Explanation: The common factors of 25 and 30 are 1, 5.
    """
def maxSum(grid: List[List[int]]) -> int:
    """
    You are given an m x n integer matrix grid.
    We define an hourglass as a part of the matrix with the following form:
    
    Return the maximum sum of the elements of an hourglass.
    Note that an hourglass cannot be rotated and must be entirely contained within the matrix.
    
    Example 1:
    
    
    >>> maxSum(grid = [[6,2,1,3],[4,2,1,5],[9,2,8,7],[4,1,2,9]])
    >>> 30
    Explanation: The cells shown above represent the hourglass with the maximum sum: 6 + 2 + 1 + 2 + 9 + 2 + 8 = 30.
    
    Example 2:
    
    
    >>> maxSum(grid = [[1,2,3],[4,5,6],[7,8,9]])
    >>> 35
    Explanation: There is only one hourglass in the matrix, with the sum: 1 + 2 + 3 + 5 + 7 + 8 + 9 = 35.
    """
def minimizeXor(num1: int, num2: int) -> int:
    """
    Given two positive integers num1 and num2, find the positive integer x such that:
    
    x has the same number of set bits as num2, and
    The value x XOR num1 is minimal.
    
    Note that XOR is the bitwise XOR operation.
    Return the integer x. The test cases are generated such that x is uniquely determined.
    The number of set bits of an integer is the number of 1's in its binary representation.
    
    Example 1:
    
    >>> minimizeXor(num1 = 3, num2 = 5)
    >>> 3
    Explanation:
    The binary representations of num1 and num2 are 0011 and 0101, respectively.
    The integer 3 has the same number of set bits as num2, and the value 3 XOR 3 = 0 is minimal.
    
    Example 2:
    
    >>> minimizeXor(num1 = 1, num2 = 12)
    >>> 3
    Explanation:
    The binary representations of num1 and num2 are 0001 and 1100, respectively.
    The integer 3 has the same number of set bits as num2, and the value 3 XOR 1 = 2 is minimal.
    """
def deleteString(s: str) -> int:
    """
    You are given a string s consisting of only lowercase English letters. In one operation, you can:
    
    Delete the entire string s, or
    Delete the first i letters of s if the first i letters of s are equal to the following i letters in s, for any i in the range 1 <= i <= s.length / 2.
    
    For example, if s = "ababc", then in one operation, you could delete the first two letters of s to get "abc", since the first two letters of s and the following two letters of s are both equal to "ab".
    Return the maximum number of operations needed to delete all of s.
    
    Example 1:
    
    >>> deleteString(s = "abcabcdabc")
    >>> 2
    Explanation:
    - Delete the first 3 letters ("abc") since the next 3 letters are equal. Now, s = "abcdabc".
    - Delete all the letters.
    We used 2 operations so return 2. It can be proven that 2 is the maximum number of operations needed.
    Note that in the second operation we cannot delete "abc" again because the next occurrence of "abc" does not happen in the next 3 letters.
    
    Example 2:
    
    >>> deleteString(s = "aaabaab")
    >>> 4
    Explanation:
    - Delete the first letter ("a") since the next letter is equal. Now, s = "aabaab".
    - Delete the first 3 letters ("aab") since the next 3 letters are equal. Now, s = "aab".
    - Delete the first letter ("a") since the next letter is equal. Now, s = "ab".
    - Delete all the letters.
    We used 4 operations so return 4. It can be proven that 4 is the maximum number of operations needed.
    
    Example 3:
    
    >>> deleteString(s = "aaaaa")
    >>> 5
    Explanation: In each operation, we can delete the first letter of s.
    """