ShwStone/humaneval-leetcode huggingface dataset:
def removeStars(s: str) -> str:
    """
    You are given a string s, which contains stars *.
    In one operation, you can:
    
    Choose a star in s.
    Remove the closest non-star character to its left, as well as remove the star itself.
    
    Return the string after all stars have been removed.
    Note:
    
    The input will be generated such that the operation is always possible.
    It can be shown that the resulting string will always be unique.
    
    
    Example 1:
    
    >>> removeStars(s = "leet**cod*e")
    >>> "lecoe"
    Explanation: Performing the removals from left to right:
    - The closest character to the 1st star is 't' in "leet**cod*e". s becomes "lee*cod*e".
    - The closest character to the 2nd star is 'e' in "lee*cod*e". s becomes "lecod*e".
    - The closest character to the 3rd star is 'd' in "lecod*e". s becomes "lecoe".
    There are no more stars, so we return "lecoe".
    Example 2:
    
    >>> removeStars(s = "erase*****")
    >>> ""
    Explanation: The entire string is removed, so we return an empty string.
    """
def garbageCollection(garbage: List[str], travel: List[int]) -> int:
    """
    You are given a 0-indexed array of strings garbage where garbage[i] represents the assortment of garbage at the ith house. garbage[i] consists only of the characters 'M', 'P' and 'G' representing one unit of metal, paper and glass garbage respectively. Picking up one unit of any type of garbage takes 1 minute.
    You are also given a 0-indexed integer array travel where travel[i] is the number of minutes needed to go from house i to house i + 1.
    There are three garbage trucks in the city, each responsible for picking up one type of garbage. Each garbage truck starts at house 0 and must visit each house in order; however, they do not need to visit every house.
    Only one garbage truck may be used at any given moment. While one truck is driving or picking up garbage, the other two trucks cannot do anything.
    Return the minimum number of minutes needed to pick up all the garbage.
    
    Example 1:
    
    >>> garbageCollection(garbage = ["G","P","GP","GG"], travel = [2,4,3])
    >>> 21
    Explanation:
    The paper garbage truck:
    1. Travels from house 0 to house 1
    2. Collects the paper garbage at house 1
    3. Travels from house 1 to house 2
    4. Collects the paper garbage at house 2
    Altogether, it takes 8 minutes to pick up all the paper garbage.
    The glass garbage truck:
    1. Collects the glass garbage at house 0
    2. Travels from house 0 to house 1
    3. Travels from house 1 to house 2
    4. Collects the glass garbage at house 2
    5. Travels from house 2 to house 3
    6. Collects the glass garbage at house 3
    Altogether, it takes 13 minutes to pick up all the glass garbage.
    Since there is no metal garbage, we do not need to consider the metal garbage truck.
    Therefore, it takes a total of 8 + 13 = 21 minutes to collect all the garbage.
    
    Example 2:
    
    >>> garbageCollection(garbage = ["MMM","PGM","GP"], travel = [3,10])
    >>> 37
    Explanation:
    The metal garbage truck takes 7 minutes to pick up all the metal garbage.
    The paper garbage truck takes 15 minutes to pick up all the paper garbage.
    The glass garbage truck takes 15 minutes to pick up all the glass garbage.
    It takes a total of 7 + 15 + 15 = 37 minutes to collect all the garbage.
    """
def buildMatrix(k: int, rowConditions: List[List[int]], colConditions: List[List[int]]) -> List[List[int]]:
    """
    You are given a positive integer k. You are also given:
    
    a 2D integer array rowConditions of size n where rowConditions[i] = [abovei, belowi], and
    a 2D integer array colConditions of size m where colConditions[i] = [lefti, righti].
    
    The two arrays contain integers from 1 to k.
    You have to build a k x k matrix that contains each of the numbers from 1 to k exactly once. The remaining cells should have the value 0.
    The matrix should also satisfy the following conditions:
    
    The number abovei should appear in a row that is strictly above the row at which the number belowi appears for all i from 0 to n - 1.
    The number lefti should appear in a column that is strictly left of the column at which the number righti appears for all i from 0 to m - 1.
    
    Return any matrix that satisfies the conditions. If no answer exists, return an empty matrix.
    
    Example 1:
    
    
    >>> buildMatrix(k = 3, rowConditions = [[1,2],[3,2]], colConditions = [[2,1],[3,2]])
    >>> [[3,0,0],[0,0,1],[0,2,0]]
    Explanation: The diagram above shows a valid example of a matrix that satisfies all the conditions.
    The row conditions are the following:
    - Number 1 is in row 1, and number 2 is in row 2, so 1 is above 2 in the matrix.
    - Number 3 is in row 0, and number 2 is in row 2, so 3 is above 2 in the matrix.
    The column conditions are the following:
    - Number 2 is in column 1, and number 1 is in column 2, so 2 is left of 1 in the matrix.
    - Number 3 is in column 0, and number 2 is in column 1, so 3 is left of 2 in the matrix.
    Note that there may be multiple correct answers.
    
    Example 2:
    
    >>> buildMatrix(k = 3, rowConditions = [[1,2],[2,3],[3,1],[2,3]], colConditions = [[2,1]])
    >>> []
    Explanation: From the first two conditions, 3 has to be below 1 but the third conditions needs 3 to be above 1 to be satisfied.
    No matrix can satisfy all the conditions, so we return the empty matrix.
    """
def countSubarrays(nums: List[int]) -> int:
    """
    You are given an array nums consisting of positive integers.
    Return the number of subarrays of nums that are in strictly increasing order.
    A subarray is a contiguous part of an array.
    
    Example 1:
    
    >>> countSubarrays(nums = [1,3,5,4,4,6])
    >>> 10
    Explanation: The strictly increasing subarrays are the following:
    - Subarrays of length 1: [1], [3], [5], [4], [4], [6].
    - Subarrays of length 2: [1,3], [3,5], [4,6].
    - Subarrays of length 3: [1,3,5].
    The total number of subarrays is 6 + 3 + 1 = 10.
    
    Example 2:
    
    >>> countSubarrays(nums = [1,2,3,4,5])
    >>> 15
    Explanation: Every subarray is strictly increasing. There are 15 possible subarrays that we can take.
    """
def findSubarrays(nums: List[int]) -> bool:
    """
    Given a 0-indexed integer array nums, determine whether there exist two subarrays of length 2 with equal sum. Note that the two subarrays must begin at different indices.
    Return true if these subarrays exist, and false otherwise.
    A subarray is a contiguous non-empty sequence of elements within an array.
    
    Example 1:
    
    >>> findSubarrays(nums = [4,2,4])
    >>> true
    Explanation: The subarrays with elements [4,2] and [2,4] have the same sum of 6.
    
    Example 2:
    
    >>> findSubarrays(nums = [1,2,3,4,5])
    >>> false
    Explanation: No two subarrays of size 2 have the same sum.
    
    Example 3:
    
    >>> findSubarrays(nums = [0,0,0])
    >>> true
    Explanation: The subarrays [nums[0],nums[1]] and [nums[1],nums[2]] have the same sum of 0.
    Note that even though the subarrays have the same content, the two subarrays are considered different because they are in different positions in the original array.
    """
def isStrictlyPalindromic(n: int) -> bool:
    """
    An integer n is strictly palindromic if, for every base b between 2 and n - 2 (inclusive), the string representation of the integer n in base b is palindromic.
    Given an integer n, return true if n is strictly palindromic and false otherwise.
    A string is palindromic if it reads the same forward and backward.
    
    Example 1:
    
    >>> isStrictlyPalindromic(n = 9)
    >>> false
    Explanation: In base 2: 9 = 1001 (base 2), which is palindromic.
    In base 3: 9 = 100 (base 3), which is not palindromic.
    Therefore, 9 is not strictly palindromic so we return false.
    Note that in bases 4, 5, 6, and 7, n = 9 is also not palindromic.
    
    Example 2:
    
    >>> isStrictlyPalindromic(n = 4)
    >>> false
    Explanation: We only consider base 2: 4 = 100 (base 2), which is not palindromic.
    Therefore, we return false.
    """
def maximumRows(matrix: List[List[int]], numSelect: int) -> int:
    """
    You are given an m x n binary matrix matrix and an integer numSelect.
    Your goal is to select exactly numSelect distinct columns from matrix such that you cover as many rows as possible.
    A row is considered covered if all the 1's in that row are also part of a column that you have selected. If a row does not have any 1s, it is also considered covered.
    More formally, let us consider selected = {c1, c2, ...., cnumSelect} as the set of columns selected by you. A row i is covered by selected if:
    
    For each cell where matrix[i][j] == 1, the column j is in selected.
    Or, no cell in row i has a value of 1.
    
    Return the maximum number of rows that can be covered by a set of numSelect columns.
    
    Example 1:
    
    
    >>> maximumRows(matrix = [[0,0,0],[1,0,1],[0,1,1],[0,0,1]], numSelect = 2)
    >>> 3
    Explanation:
    One possible way to cover 3 rows is shown in the diagram above.
    We choose s = {0, 2}.
    - Row 0 is covered because it has no occurrences of 1.
    - Row 1 is covered because the columns with value 1, i.e. 0 and 2 are present in s.
    - Row 2 is not covered because matrix[2][1] == 1 but 1 is not present in s.
    - Row 3 is covered because matrix[2][2] == 1 and 2 is present in s.
    Thus, we can cover three rows.
    Note that s = {1, 2} will also cover 3 rows, but it can be shown that no more than three rows can be covered.
    
    Example 2:
    
    
    >>> maximumRows(matrix = [[1],[0]], numSelect = 1)
    >>> 2
    Explanation:
    Selecting the only column will result in both rows being covered since the entire matrix is selected.
    """
def maximumRobots(chargeTimes: List[int], runningCosts: List[int], budget: int) -> int:
    """
    You have n robots. You are given two 0-indexed integer arrays, chargeTimes and runningCosts, both of length n. The ith robot costs chargeTimes[i] units to charge and costs runningCosts[i] units to run. You are also given an integer budget.
    The total cost of running k chosen robots is equal to max(chargeTimes) + k * sum(runningCosts), where max(chargeTimes) is the largest charge cost among the k robots and sum(runningCosts) is the sum of running costs among the k robots.
    Return the maximum number of consecutive robots you can run such that the total cost does not exceed budget.
    
    Example 1:
    
    >>> maximumRobots(chargeTimes = [3,6,1,3,4], runningCosts = [2,1,3,4,5], budget = 25)
    >>> 3
    Explanation:
    It is possible to run all individual and consecutive pairs of robots within budget.
    To obtain answer 3, consider the first 3 robots. The total cost will be max(3,6,1) + 3 * sum(2,1,3) = 6 + 3 * 6 = 24 which is less than 25.
    It can be shown that it is not possible to run more than 3 consecutive robots within budget, so we return 3.
    
    Example 2:
    
    >>> maximumRobots(chargeTimes = [11,12,19], runningCosts = [10,8,7], budget = 19)
    >>> 0
    Explanation: No robot can be run that does not exceed the budget, so we return 0.
    """
def checkDistances(s: str, distance: List[int]) -> bool:
    """
    You are given a 0-indexed string s consisting of only lowercase English letters, where each letter in s appears exactly twice. You are also given a 0-indexed integer array distance of length 26.
    Each letter in the alphabet is numbered from 0 to 25 (i.e. 'a' -> 0, 'b' -> 1, 'c' -> 2, ... , 'z' -> 25).
    In a well-spaced string, the number of letters between the two occurrences of the ith letter is distance[i]. If the ith letter does not appear in s, then distance[i] can be ignored.
    Return true if s is a well-spaced string, otherwise return false.
    
    Example 1:
    
    >>> checkDistances(s = "abaccb", distance = [1,3,0,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0])
    >>> true
    Explanation:
    - 'a' appears at indices 0 and 2 so it satisfies distance[0] = 1.
    - 'b' appears at indices 1 and 5 so it satisfies distance[1] = 3.
    - 'c' appears at indices 3 and 4 so it satisfies distance[2] = 0.
    Note that distance[3] = 5, but since 'd' does not appear in s, it can be ignored.
    Return true because s is a well-spaced string.
    
    Example 2:
    
    >>> checkDistances(s = "aa", distance = [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0])
    >>> false
    Explanation:
    - 'a' appears at indices 0 and 1 so there are zero letters between them.
    Because distance[0] = 1, s is not a well-spaced string.
    """
def numberOfWays(startPos: int, endPos: int, k: int) -> int:
    """
    You are given two positive integers startPos and endPos. Initially, you are standing at position startPos on an infinite number line. With one step, you can move either one position to the left, or one position to the right.
    Given a positive integer k, return the number of different ways to reach the position endPos starting from startPos, such that you perform exactly k steps. Since the answer may be very large, return it modulo 109 + 7.
    Two ways are considered different if the order of the steps made is not exactly the same.
    Note that the number line includes negative integers.
    
    Example 1:
    
    >>> numberOfWays(startPos = 1, endPos = 2, k = 3)
    >>> 3
    Explanation: We can reach position 2 from 1 in exactly 3 steps in three ways:
    - 1 -> 2 -> 3 -> 2.
    - 1 -> 2 -> 1 -> 2.
    - 1 -> 0 -> 1 -> 2.
    It can be proven that no other way is possible, so we return 3.
    Example 2:
    
    >>> numberOfWays(startPos = 2, endPos = 5, k = 10)
    >>> 0
    Explanation: It is impossible to reach position 5 from position 2 in exactly 10 steps.
    """
def longestNiceSubarray(nums: List[int]) -> int:
    """
    You are given an array nums consisting of positive integers.
    We call a subarray of nums nice if the bitwise AND of every pair of elements that are in different positions in the subarray is equal to 0.
    Return the length of the longest nice subarray.
    A subarray is a contiguous part of an array.
    Note that subarrays of length 1 are always considered nice.
    
    Example 1:
    
    >>> longestNiceSubarray(nums = [1,3,8,48,10])
    >>> 3
    Explanation: The longest nice subarray is [3,8,48]. This subarray satisfies the conditions:
    - 3 AND 8 = 0.
    - 3 AND 48 = 0.
    - 8 AND 48 = 0.
    It can be proven that no longer nice subarray can be obtained, so we return 3.
    Example 2:
    
    >>> longestNiceSubarray(nums = [3,1,5,11,13])
    >>> 1
    Explanation: The length of the longest nice subarray is 1. Any subarray of length 1 can be chosen.
    """
def mostBooked(n: int, meetings: List[List[int]]) -> int:
    """
    You are given an integer n. There are n rooms numbered from 0 to n - 1.
    You are given a 2D integer array meetings where meetings[i] = [starti, endi] means that a meeting will be held during the half-closed time interval [starti, endi). All the values of starti are unique.
    Meetings are allocated to rooms in the following manner:
    
    Each meeting will take place in the unused room with the lowest number.
    If there are no available rooms, the meeting will be delayed until a room becomes free. The delayed meeting should have the same duration as the original meeting.
    When a room becomes unused, meetings that have an earlier original start time should be given the room.
    
    Return the number of the room that held the most meetings. If there are multiple rooms, return the room with the lowest number.
    A half-closed interval [a, b) is the interval between a and b including a and not including b.
    
    Example 1:
    
    >>> mostBooked(n = 2, meetings = [[0,10],[1,5],[2,7],[3,4]])
    >>> 0
    Explanation:
    - At time 0, both rooms are not being used. The first meeting starts in room 0.
    - At time 1, only room 1 is not being used. The second meeting starts in room 1.
    - At time 2, both rooms are being used. The third meeting is delayed.
    - At time 3, both rooms are being used. The fourth meeting is delayed.
    - At time 5, the meeting in room 1 finishes. The third meeting starts in room 1 for the time period [5,10).
    - At time 10, the meetings in both rooms finish. The fourth meeting starts in room 0 for the time period [10,11).
    Both rooms 0 and 1 held 2 meetings, so we return 0.
    
    Example 2:
    
    >>> mostBooked(n = 3, meetings = [[1,20],[2,10],[3,5],[4,9],[6,8]])
    >>> 1
    Explanation:
    - At time 1, all three rooms are not being used. The first meeting starts in room 0.
    - At time 2, rooms 1 and 2 are not being used. The second meeting starts in room 1.
    - At time 3, only room 2 is not being used. The third meeting starts in room 2.
    - At time 4, all three rooms are being used. The fourth meeting is delayed.
    - At time 5, the meeting in room 2 finishes. The fourth meeting starts in room 2 for the time period [5,10).
    - At time 6, all three rooms are being used. The fifth meeting is delayed.
    - At time 10, the meetings in rooms 1 and 2 finish. The fifth meeting starts in room 1 for the time period [10,12).
    Room 0 held 1 meeting while rooms 1 and 2 each held 2 meetings, so we return 1.
    """
def minimumTime(power: List[int]) -> int:
    """
    You are given an integer array power where power[i] is the power of the ith monster.
    You start with 0 mana points, and each day you increase your mana points by gain where gain initially is equal to 1.
    Each day, after gaining gain mana, you can defeat a monster if your mana points are greater than or equal to the power of that monster. When you defeat a monster:
    
    your mana points will be reset to 0, and
    the value of gain increases by 1.
    
    Return the minimum number of days needed to defeat all the monsters.
    
    Example 1:
    
    >>> minimumTime(power = [3,1,4])
    >>> 4
    Explanation: The optimal way to beat all the monsters is to:
    - Day 1: Gain 1 mana point to get a total of 1 mana point. Spend all mana points to kill the 2nd monster.
    - Day 2: Gain 2 mana points to get a total of 2 mana points.
    - Day 3: Gain 2 mana points to get a total of 4 mana points. Spend all mana points to kill the 3rd monster.
    - Day 4: Gain 3 mana points to get a total of 3 mana points. Spend all mana points to kill the 1st monster.
    It can be proven that 4 is the minimum number of days needed.
    
    Example 2:
    
    >>> minimumTime(power = [1,1,4])
    >>> 4
    Explanation: The optimal way to beat all the monsters is to:
    - Day 1: Gain 1 mana point to get a total of 1 mana point. Spend all mana points to kill the 1st monster.
    - Day 2: Gain 2 mana points to get a total of 2 mana points. Spend all mana points to kill the 2nd monster.
    - Day 3: Gain 3 mana points to get a total of 3 mana points.
    - Day 4: Gain 3 mana points to get a total of 6 mana points. Spend all mana points to kill the 3rd monster.
    It can be proven that 4 is the minimum number of days needed.
    
    Example 3:
    
    >>> minimumTime(power = [1,2,4,9])
    >>> 6
    Explanation: The optimal way to beat all the monsters is to:
    - Day 1: Gain 1 mana point to get a total of 1 mana point. Spend all mana points to kill the 1st monster.
    - Day 2: Gain 2 mana points to get a total of 2 mana points. Spend all mana points to kill the 2nd monster.
    - Day 3: Gain 3 mana points to get a total of 3 mana points.
    - Day 4: Gain 3 mana points to get a total of 6 mana points.
    - Day 5: Gain 3 mana points to get a total of 9 mana points. Spend all mana points to kill the 4th monster.
    - Day 6: Gain 4 mana points to get a total of 4 mana points. Spend all mana points to kill the 3rd monster.
    It can be proven that 6 is the minimum number of days needed.
    """
def mostFrequentEven(nums: List[int]) -> int:
    """
    Given an integer array nums, return the most frequent even element.
    If there is a tie, return the smallest one. If there is no such element, return -1.
    
    Example 1:
    
    >>> mostFrequentEven(nums = [0,1,2,2,4,4,1])
    >>> 2
    Explanation:
    The even elements are 0, 2, and 4. Of these, 2 and 4 appear the most.
    We return the smallest one, which is 2.
    Example 2:
    
    >>> mostFrequentEven(nums = [4,4,4,9,2,4])
    >>> 4
    Explanation: 4 is the even element appears the most.
    
    Example 3:
    
    >>> mostFrequentEven(nums = [29,47,21,41,13,37,25,7])
    >>> -1
    Explanation: There is no even element.
    """
def partitionString(s: str) -> int:
    """
    Given a string s, partition the string into one or more substrings such that the characters in each substring are unique. That is, no letter appears in a single substring more than once.
    Return the minimum number of substrings in such a partition.
    Note that each character should belong to exactly one substring in a partition.
    
    Example 1:
    
    >>> partitionString(s = "abacaba")
    >>> 4
    Explanation:
    Two possible partitions are ("a","ba","cab","a") and ("ab","a","ca","ba").
    It can be shown that 4 is the minimum number of substrings needed.
    
    Example 2:
    
    >>> partitionString(s = "ssssss")
    >>> 6
    Explanation:
    The only valid partition is ("s","s","s","s","s","s").
    """
def minGroups(intervals: List[List[int]]) -> int:
    """
    You are given a 2D integer array intervals where intervals[i] = [lefti, righti] represents the inclusive interval [lefti, righti].
    You have to divide the intervals into one or more groups such that each interval is in exactly one group, and no two intervals that are in the same group intersect each other.
    Return the minimum number of groups you need to make.
    Two intervals intersect if there is at least one common number between them. For example, the intervals [1, 5] and [5, 8] intersect.
    
    Example 1:
    
    >>> minGroups(intervals = [[5,10],[6,8],[1,5],[2,3],[1,10]])
    >>> 3
    Explanation: We can divide the intervals into the following groups:
    - Group 1: [1, 5], [6, 8].
    - Group 2: [2, 3], [5, 10].
    - Group 3: [1, 10].
    It can be proven that it is not possible to divide the intervals into fewer than 3 groups.
    
    Example 2:
    
    >>> minGroups(intervals = [[1,3],[5,6],[8,10],[11,13]])
    >>> 1
    Explanation: None of the intervals overlap, so we can put all of them in one group.
    """
def lengthOfLIS(nums: List[int], k: int) -> int:
    """
    You are given an integer array nums and an integer k.
    Find the longest subsequence of nums that meets the following requirements:
    
    The subsequence is strictly increasing and
    The difference between adjacent elements in the subsequence is at most k.
    
    Return the length of the longest subsequence that meets the requirements.
    A subsequence is an array that can be derived from another array by deleting some or no elements without changing the order of the remaining elements.
    
    Example 1:
    
    >>> lengthOfLIS(nums = [4,2,1,4,3,4,5,8,15], k = 3)
    >>> 5
    Explanation:
    The longest subsequence that meets the requirements is [1,3,4,5,8].
    The subsequence has a length of 5, so we return 5.
    Note that the subsequence [1,3,4,5,8,15] does not meet the requirements because 15 - 8 = 7 is larger than 3.
    
    Example 2:
    
    >>> lengthOfLIS(nums = [7,4,5,1,8,12,4,7], k = 5)
    >>> 4
    Explanation:
    The longest subsequence that meets the requirements is [4,5,8,12].
    The subsequence has a length of 4, so we return 4.
    
    Example 3:
    
    >>> lengthOfLIS(nums = [1,5], k = 1)
    >>> 1
    Explanation:
    The longest subsequence that meets the requirements is [1].
    The subsequence has a length of 1, so we return 1.
    """