ShwStone/humaneval-leetcode huggingface dataset:
def countSubstrings(s: str) -> int:
    """
    You are given a string s consisting of digits.
    Return the number of substrings of s divisible by their non-zero last digit.
    Note: A substring may contain leading zeros.
    
    Example 1:
    
    >>> countSubstrings(s = "12936")
    >>> 11
    Explanation:
    Substrings "29", "129", "293" and "2936" are not divisible by their last digit. There are 15 substrings in total, so the answer is 15 - 4 = 11.
    
    Example 2:
    
    >>> countSubstrings(s = "5701283")
    >>> 18
    Explanation:
    Substrings "01", "12", "701", "012", "128", "5701", "7012", "0128", "57012", "70128", "570128", and "701283" are all divisible by their last digit. Additionally, all substrings that are just 1 non-zero digit are divisible by themselves. Since there are 6 such digits, the answer is 12 + 6 = 18.
    
    Example 3:
    
    >>> countSubstrings(s = "1010101010")
    >>> 25
    Explanation:
    Only substrings that end with digit '1' are divisible by their last digit. There are 25 such substrings.
    """
def maxScore(points: List[int], m: int) -> int:
    """
    You are given an array points of size n and an integer m. There is another array gameScore of size n, where gameScore[i] represents the score achieved at the ith game. Initially, gameScore[i] == 0 for all i.
    You start at index -1, which is outside the array (before the first position at index 0). You can make at most m moves. In each move, you can either:
    
    Increase the index by 1 and add points[i] to gameScore[i].
    Decrease the index by 1 and add points[i] to gameScore[i].
    
    Note that the index must always remain within the bounds of the array after the first move.
    Return the maximum possible minimum value in gameScore after at most m moves.
    
    Example 1:
    
    >>> maxScore(points = [2,4], m = 3)
    >>> 4
    Explanation:
    Initially, index i = -1 and gameScore = [0, 0].
    
    
    
    Move
    Index
    gameScore
    
    
    
    
    Increase i
    0
    [2, 0]
    
    
    Increase i
    1
    [2, 4]
    
    
    Decrease i
    0
    [4, 4]
    
    
    
    The minimum value in gameScore is 4, and this is the maximum possible minimum among all configurations. Hence, 4 is the output.
    
    Example 2:
    
    >>> maxScore(points = [1,2,3], m = 5)
    >>> 2
    Explanation:
    Initially, index i = -1 and gameScore = [0, 0, 0].
    
    
    
    Move
    Index
    gameScore
    
    
    
    
    Increase i
    0
    [1, 0, 0]
    
    
    Increase i
    1
    [1, 2, 0]
    
    
    Decrease i
    0
    [2, 2, 0]
    
    
    Increase i
    1
    [2, 4, 0]
    
    
    Increase i
    2
    [2, 4, 3]
    
    
    
    The minimum value in gameScore is 2, and this is the maximum possible minimum among all configurations. Hence, 2 is the output.
    """
def maxStudentsOnBench(students: List[List[int]]) -> int:
    """
    You are given a 2D integer array of student data students, where students[i] = [student_id, bench_id] represents that student student_id is sitting on the bench bench_id.
    Return the maximum number of unique students sitting on any single bench. If no students are present, return 0.
    Note: A student can appear multiple times on the same bench in the input, but they should be counted only once per bench.
    
    Example 1:
    
    >>> maxStudentsOnBench(students = [[1,2],[2,2],[3,3],[1,3],[2,3]])
    >>> 3
    Explanation:
    
    Bench 2 has two unique students: [1, 2].
    Bench 3 has three unique students: [1, 2, 3].
    The maximum number of unique students on a single bench is 3.
    
    
    Example 2:
    
    >>> maxStudentsOnBench(students = [[1,1],[2,1],[3,1],[4,2],[5,2]])
    >>> 3
    Explanation:
    
    Bench 1 has three unique students: [1, 2, 3].
    Bench 2 has two unique students: [4, 5].
    The maximum number of unique students on a single bench is 3.
    
    
    Example 3:
    
    >>> maxStudentsOnBench(students = [[1,1],[1,1]])
    >>> 1
    Explanation:
    
    The maximum number of unique students on a single bench is 1.
    
    
    Example 4:
    
    >>> maxStudentsOnBench(students = [])
    >>> 0
    Explanation:
    
    Since no students are present, the output is 0.
    """
def sumOfGoodNumbers(nums: List[int], k: int) -> int:
    """
    Given an array of integers nums and an integer k, an element nums[i] is considered good if it is strictly greater than the elements at indices i - k and i + k (if those indices exist). If neither of these indices exists, nums[i] is still considered good.
    Return the sum of all the good elements in the array.
    
    Example 1:
    
    >>> sumOfGoodNumbers(nums = [1,3,2,1,5,4], k = 2)
    >>> 12
    Explanation:
    The good numbers are nums[1] = 3, nums[4] = 5, and nums[5] = 4 because they are strictly greater than the numbers at indices i - k and i + k.
    
    Example 2:
    
    >>> sumOfGoodNumbers(nums = [2,1], k = 1)
    >>> 2
    Explanation:
    The only good number is nums[0] = 2 because it is strictly greater than nums[1].
    """
def separateSquares(squares: List[List[int]]) -> float:
    """
    You are given a 2D integer array squares. Each squares[i] = [xi, yi, li] represents the coordinates of the bottom-left point and the side length of a square parallel to the x-axis.
    Find the minimum y-coordinate value of a horizontal line such that the total area of the squares above the line equals the total area of the squares below the line.
    Answers within 10-5 of the actual answer will be accepted.
    Note: Squares may overlap. Overlapping areas should be counted multiple times.
    
    Example 1:
    
    >>> separateSquares(squares = [[0,0,1],[2,2,1]])
    >>> 1.00000
    Explanation:
    
    Any horizontal line between y = 1 and y = 2 will have 1 square unit above it and 1 square unit below it. The lowest option is 1.
    
    Example 2:
    
    >>> separateSquares(squares = [[0,0,2],[1,1,1]])
    >>> 1.16667
    Explanation:
    
    The areas are:
    
    Below the line: 7/6 * 2 (Red) + 1/6 (Blue) = 15/6 = 2.5.
    Above the line: 5/6 * 2 (Red) + 5/6 (Blue) = 15/6 = 2.5.
    
    Since the areas above and below the line are equal, the output is 7/6 = 1.16667.
    """
def separateSquares(squares: List[List[int]]) -> float:
    """
    You are given a 2D integer array squares. Each squares[i] = [xi, yi, li] represents the coordinates of the bottom-left point and the side length of a square parallel to the x-axis.
    Find the minimum y-coordinate value of a horizontal line such that the total area covered by squares above the line equals the total area covered by squares below the line.
    Answers within 10-5 of the actual answer will be accepted.
    Note: Squares may overlap. Overlapping areas should be counted only once in this version.
    
    Example 1:
    
    >>> separateSquares(squares = [[0,0,1],[2,2,1]])
    >>> 1.00000
    Explanation:
    
    Any horizontal line between y = 1 and y = 2 results in an equal split, with 1 square unit above and 1 square unit below. The minimum y-value is 1.
    
    Example 2:
    
    >>> separateSquares(squares = [[0,0,2],[1,1,1]])
    >>> 1.00000
    Explanation:
    
    Since the blue square overlaps with the red square, it will not be counted again. Thus, the line y = 1 splits the squares into two equal parts.
    """
def shortestMatchingSubstring(s: str, p: str) -> int:
    """
    You are given a string s and a pattern string p, where p contains exactly two '*' characters.
    The '*' in p matches any sequence of zero or more characters.
    Return the length of the shortest substring in s that matches p. If there is no such substring, return -1.
    Note: The empty substring is considered valid.
    
    Example 1:
    
    >>> shortestMatchingSubstring(s = "abaacbaecebce", p = "ba*c*ce")
    >>> 8
    Explanation:
    The shortest matching substring of p in s is "baecebce".
    
    Example 2:
    
    >>> shortestMatchingSubstring(s = "baccbaadbc", p = "cc*baa*adb")
    >>> -1
    Explanation:
    There is no matching substring in s.
    
    Example 3:
    
    >>> shortestMatchingSubstring(s = "a", p = "**")
    >>> 0
    Explanation:
    The empty substring is the shortest matching substring.
    
    Example 4:
    
    >>> shortestMatchingSubstring(s = "madlogic", p = "*adlogi*")
    >>> 6
    Explanation:
    The shortest matching substring of p in s is "adlogi".
    """
def hasSpecialSubstring(s: str, k: int) -> bool:
    """
    You are given a string s and an integer k.
    Determine if there exists a substring of length exactly k in s that satisfies the following conditions:
    
    The substring consists of only one distinct character (e.g., "aaa" or "bbb").
    If there is a character immediately before the substring, it must be different from the character in the substring.
    If there is a character immediately after the substring, it must also be different from the character in the substring.
    
    Return true if such a substring exists. Otherwise, return false.
    
    Example 1:
    
    >>> hasSpecialSubstring(s = "aaabaaa", k = 3)
    >>> true
    Explanation:
    The substring s[4..6] == "aaa" satisfies the conditions.
    
    It has a length of 3.
    All characters are the same.
    The character before "aaa" is 'b', which is different from 'a'.
    There is no character after "aaa".
    
    
    Example 2:
    
    >>> hasSpecialSubstring(s = "abc", k = 2)
    >>> false
    Explanation:
    There is no substring of length 2 that consists of one distinct character and satisfies the conditions.
    """
def maxWeight(pizzas: List[int]) -> int:
    """
    You are given an integer array pizzas of size n, where pizzas[i] represents the weight of the ith pizza. Every day, you eat exactly 4 pizzas. Due to your incredible metabolism, when you eat pizzas of weights W, X, Y, and Z, where W <= X <= Y <= Z, you gain the weight of only 1 pizza!
    
    On odd-numbered days (1-indexed), you gain a weight of Z.
    On even-numbered days, you gain a weight of Y.
    
    Find the maximum total weight you can gain by eating all pizzas optimally.
    Note: It is guaranteed that n is a multiple of 4, and each pizza can be eaten only once.
    
    Example 1:
    
    >>> maxWeight(pizzas = [1,2,3,4,5,6,7,8])
    >>> 14
    Explanation:
    
    On day 1, you eat pizzas at indices [1, 2, 4, 7] = [2, 3, 5, 8]. You gain a weight of 8.
    On day 2, you eat pizzas at indices [0, 3, 5, 6] = [1, 4, 6, 7]. You gain a weight of 6.
    
    The total weight gained after eating all the pizzas is 8 + 6 = 14.
    
    Example 2:
    
    >>> maxWeight(pizzas = [2,1,1,1,1,1,1,1])
    >>> 3
    Explanation:
    
    On day 1, you eat pizzas at indices [4, 5, 6, 0] = [1, 1, 1, 2]. You gain a weight of 2.
    On day 2, you eat pizzas at indices [1, 2, 3, 7] = [1, 1, 1, 1]. You gain a weight of 1.
    
    The total weight gained after eating all the pizzas is 2 + 1 = 3.
    """
def maxSubstringLength(s: str, k: int) -> bool:
    """
    Given a string s of length n and an integer k, determine whether it is possible to select k disjoint special substrings.
    A special substring is a substring where:
    
    Any character present inside the substring should not appear outside it in the string.
    The substring is not the entire string s.
    
    Note that all k substrings must be disjoint, meaning they cannot overlap.
    Return true if it is possible to select k such disjoint special substrings; otherwise, return false.
    
    Example 1:
    
    >>> maxSubstringLength(s = "abcdbaefab", k = 2)
    >>> true
    Explanation:
    
    We can select two disjoint special substrings: "cd" and "ef".
    "cd" contains the characters 'c' and 'd', which do not appear elsewhere in s.
    "ef" contains the characters 'e' and 'f', which do not appear elsewhere in s.
    
    
    Example 2:
    
    >>> maxSubstringLength(s = "cdefdc", k = 3)
    >>> false
    Explanation:
    There can be at most 2 disjoint special substrings: "e" and "f". Since k = 3, the output is false.
    
    Example 3:
    
    >>> maxSubstringLength(s = "abeabe", k = 0)
    >>> true
    """
def lenOfVDiagonal(grid: List[List[int]]) -> int:
    """
    You are given a 2D integer matrix grid of size n x m, where each element is either 0, 1, or 2.
    A V-shaped diagonal segment is defined as:
    
    The segment starts with 1.
    The subsequent elements follow this infinite sequence: 2, 0, 2, 0, ....
    The segment:
    
    Starts along a diagonal direction (top-left to bottom-right, bottom-right to top-left, top-right to bottom-left, or bottom-left to top-right).
    Continues the sequence in the same diagonal direction.
    Makes at most one clockwise 90-degree turn to another diagonal direction while maintaining the sequence.
    
    
    
    
    Return the length of the longest V-shaped diagonal segment. If no valid segment exists, return 0.
    
    Example 1:
    
    >>> lenOfVDiagonal(grid = [[2,2,1,2,2],[2,0,2,2,0],[2,0,1,1,0],[1,0,2,2,2],[2,0,0,2,2]])
    >>> 5
    Explanation:
    
    The longest V-shaped diagonal segment has a length of 5 and follows these coordinates: (0,2) → (1,3) → (2,4), takes a 90-degree clockwise turn at (2,4), and continues as (3,3) → (4,2).
    
    Example 2:
    
    >>> lenOfVDiagonal(grid = [[2,2,2,2,2],[2,0,2,2,0],[2,0,1,1,0],[1,0,2,2,2],[2,0,0,2,2]])
    >>> 4
    Explanation:
    
    The longest V-shaped diagonal segment has a length of 4 and follows these coordinates: (2,3) → (3,2), takes a 90-degree clockwise turn at (3,2), and continues as (2,1) → (1,0).
    
    Example 3:
    
    >>> lenOfVDiagonal(grid = [[1,2,2,2,2],[2,2,2,2,0],[2,0,0,0,0],[0,0,2,2,2],[2,0,0,2,0]])
    >>> 5
    Explanation:
    
    The longest V-shaped diagonal segment has a length of 5 and follows these coordinates: (0,0) → (1,1) → (2,2) → (3,3) → (4,4).
    
    Example 4:
    
    >>> lenOfVDiagonal(grid = [[1]])
    >>> 1
    Explanation:
    The longest V-shaped diagonal segment has a length of 1 and follows these coordinates: (0,0).
    """
def longestCommonPrefix(s: str, t: str) -> int:
    """
    You are given two strings s and t.
    Return the length of the longest common prefix between s and t after removing at most one character from s.
    Note: s can be left without any removal.
    
    Example 1:
    
    >>> longestCommonPrefix(s = "madxa", t = "madam")
    >>> 4
    Explanation:
    Removing s[3] from s results in "mada", which has a longest common prefix of length 4 with t.
    
    Example 2:
    
    >>> longestCommonPrefix(s = "leetcode", t = "eetcode")
    >>> 7
    Explanation:
    Removing s[0] from s results in "eetcode", which matches t.
    
    Example 3:
    
    >>> longestCommonPrefix(s = "one", t = "one")
    >>> 3
    Explanation:
    No removal is needed.
    
    Example 4:
    
    >>> longestCommonPrefix(s = "a", t = "b")
    >>> 0
    Explanation:
    s and t cannot have a common prefix.
    """
def hasSameDigits(s: str) -> bool:
    """
    You are given a string s consisting of digits. Perform the following operation repeatedly until the string has exactly two digits:
    
    For each pair of consecutive digits in s, starting from the first digit, calculate a new digit as the sum of the two digits modulo 10.
    Replace s with the sequence of newly calculated digits, maintaining the order in which they are computed.
    
    Return true if the final two digits in s are the same; otherwise, return false.
    
    Example 1:
    
    >>> hasSameDigits(s = "3902")
    >>> true
    Explanation:
    
    Initially, s = "3902"
    First operation:
    
    (s[0] + s[1]) % 10 = (3 + 9) % 10 = 2
    (s[1] + s[2]) % 10 = (9 + 0) % 10 = 9
    (s[2] + s[3]) % 10 = (0 + 2) % 10 = 2
    s becomes "292"
    
    
    Second operation:
    
    (s[0] + s[1]) % 10 = (2 + 9) % 10 = 1
    (s[1] + s[2]) % 10 = (9 + 2) % 10 = 1
    s becomes "11"
    
    
    Since the digits in "11" are the same, the output is true.
    
    
    Example 2:
    
    >>> hasSameDigits(s = "34789")
    >>> false
    Explanation:
    
    Initially, s = "34789".
    After the first operation, s = "7157".
    After the second operation, s = "862".
    After the third operation, s = "48".
    Since '4' != '8', the output is false.
    """
def maxSum(grid: List[List[int]], limits: List[int], k: int) -> int:
    """
    You are given a 2D integer matrix grid of size n x m, an integer array limits of length n, and an integer k. The task is to find the maximum sum of at most k elements from the matrix grid such that:
    
    
    The number of elements taken from the ith row of grid does not exceed limits[i].
    
    
    Return the maximum sum.
    
    Example 1:
    
    >>> maxSum(grid = [[1,2],[3,4]], limits = [1,2], k = 2)
    >>> 7
    Explanation:
    
    From the second row, we can take at most 2 elements. The elements taken are 4 and 3.
    The maximum possible sum of at most 2 selected elements is 4 + 3 = 7.
    
    
    Example 2:
    
    >>> maxSum(grid = [[5,3,7],[8,2,6]], limits = [2,2], k = 3)
    >>> 21
    Explanation:
    
    From the first row, we can take at most 2 elements. The element taken is 7.
    From the second row, we can take at most 2 elements. The elements taken are 8 and 6.
    The maximum possible sum of at most 3 selected elements is 7 + 8 + 6 = 21.
    """
def maxDistance(side: int, points: List[List[int]], k: int) -> int:
    """
    You are given an integer side, representing the edge length of a square with corners at (0, 0), (0, side), (side, 0), and (side, side) on a Cartesian plane.
    You are also given a positive integer k and a 2D integer array points, where points[i] = [xi, yi] represents the coordinate of a point lying on the boundary of the square.
    You need to select k elements among points such that the minimum Manhattan distance between any two points is maximized.
    Return the maximum possible minimum Manhattan distance between the selected k points.
    The Manhattan Distance between two cells (xi, yi) and (xj, yj) is |xi - xj| + |yi - yj|.
    
    Example 1:
    
    >>> maxDistance(side = 2, points = [[0,2],[2,0],[2,2],[0,0]], k = 4)
    >>> 2
    Explanation:
    
    Select all four points.
    
    Example 2:
    
    >>> maxDistance(side = 2, points = [[0,0],[1,2],[2,0],[2,2],[2,1]], k = 4)
    >>> 1
    Explanation:
    
    Select the points (0, 0), (2, 0), (2, 2), and (2, 1).
    
    Example 3:
    
    >>> maxDistance(side = 2, points = [[0,0],[0,1],[0,2],[1,2],[2,0],[2,2],[2,1]], k = 5)
    >>> 1
    Explanation:
    
    Select the points (0, 0), (0, 1), (0, 2), (1, 2), and (2, 2).
    """
def maxCoins(lane1: List[int], lane2: List[int]) -> int:
    """
    Mario drives on a two-lane freeway with coins every mile. You are given two integer arrays, lane1 and lane2, where the value at the ith index represents the number of coins he gains or loses in the ith mile in that lane.
    
    If Mario is in lane 1 at mile i and lane1[i] > 0, Mario gains lane1[i] coins.
    If Mario is in lane 1 at mile i and lane1[i] < 0, Mario pays a toll and loses abs(lane1[i]) coins.
    The same rules apply for lane2.
    
    Mario can enter the freeway anywhere and exit anytime after traveling at least one mile. Mario always enters the freeway on lane 1 but can switch lanes at most 2 times.
    A lane switch is when Mario goes from lane 1 to lane 2 or vice versa.
    Return the maximum number of coins Mario can earn after performing at most 2 lane switches.
    Note: Mario can switch lanes immediately upon entering or just before exiting the freeway.
    
    Example 1:
    
    >>> maxCoins(lane1 = [1,-2,-10,3], lane2 = [-5,10,0,1])
    >>> 14
    Explanation:
    
    Mario drives the first mile on lane 1.
    He then changes to lane 2 and drives for two miles.
    He changes back to lane 1 for the last mile.
    
    Mario collects 1 + 10 + 0 + 3 = 14 coins.
    
    Example 2:
    
    >>> maxCoins(lane1 = [1,-1,-1,-1], lane2 = [0,3,4,-5])
    >>> 8
    Explanation:
    
    Mario starts at mile 0 in lane 1 and drives one mile.
    He then changes to lane 2 and drives for two more miles. He exits the freeway before mile 3.
    
    He collects 1 + 3 + 4 = 8 coins.
    
    Example 3:
    
    >>> maxCoins(lane1 = [-5,-4,-3], lane2 = [-1,2,3])
    >>> 5
    Explanation:
    
    Mario enters at mile 1 and immediately switches to lane 2. He stays here the entire way.
    
    He collects a total of 2 + 3 = 5 coins.
    
    Example 4:
    
    >>> maxCoins(lane1 = [-3,-3,-3], lane2 = [9,-2,4])
    >>> 11
    Explanation:
    
    Mario starts at the beginning of the freeway and immediately switches to lane 2. He stays here the whole way.
    
    He collects a total of 9 + (-2) + 4 = 11 coins.
    
    Example 5:
    
    >>> maxCoins(lane1 = [-10], lane2 = [-2])
    >>> -2
    Explanation:
    
    Since Mario must ride on the freeway for at least one mile, he rides just one mile in lane 2.
    
    He collects a total of -2 coins.
    """
def transformArray(nums: List[int]) -> List[int]:
    """
    You are given an integer array nums. Transform nums by performing the following operations in the exact order specified:
    
    Replace each even number with 0.
    Replace each odd numbers with 1.
    Sort the modified array in non-decreasing order.
    
    Return the resulting array after performing these operations.
    
    Example 1:
    
    >>> transformArray(nums = [4,3,2,1])
    >>> [0,0,1,1]
    Explanation:
    
    Replace the even numbers (4 and 2) with 0 and the odd numbers (3 and 1) with 1. Now, nums = [0, 1, 0, 1].
    After sorting nums in non-descending order, nums = [0, 0, 1, 1].
    
    
    Example 2:
    
    >>> transformArray(nums = [1,5,1,4,2])
    >>> [0,0,1,1,1]
    Explanation:
    
    Replace the even numbers (4 and 2) with 0 and the odd numbers (1, 5 and 1) with 1. Now, nums = [1, 1, 1, 0, 0].
    After sorting nums in non-descending order, nums = [0, 0, 1, 1, 1].
    """
def countArrays(original: List[int], bounds: List[List[int]]) -> int:
    """
    You are given an array original of length n and a 2D array bounds of length n x 2, where bounds[i] = [ui, vi].
    You need to find the number of possible arrays copy of length n such that:
    
    (copy[i] - copy[i - 1]) == (original[i] - original[i - 1]) for 1 <= i <= n - 1.
    ui <= copy[i] <= vi for 0 <= i <= n - 1.
    
    Return the number of such arrays.
    
    Example 1:
    
    >>> countArrays(original = [1,2,3,4], bounds = [[1,2],[2,3],[3,4],[4,5]])
    >>> 2
    Explanation:
    The possible arrays are:
    
    [1, 2, 3, 4]
    [2, 3, 4, 5]
    
    
    Example 2:
    
    >>> countArrays(original = [1,2,3,4], bounds = [[1,10],[2,9],[3,8],[4,7]])
    >>> 4
    Explanation:
    The possible arrays are:
    
    [1, 2, 3, 4]
    [2, 3, 4, 5]
    [3, 4, 5, 6]
    [4, 5, 6, 7]
    
    
    Example 3:
    
    >>> countArrays(original = [1,2,1,2], bounds = [[1,1],[2,3],[3,3],[2,3]])
    >>> 0
    Explanation:
    No array is possible.
    """