ShwStone/humaneval-leetcode huggingface dataset:
def maxBuilding(n: int, restrictions: List[List[int]]) -> int:
    """
    You want to build n new buildings in a city. The new buildings will be built in a line and are labeled from 1 to n.
    However, there are city restrictions on the heights of the new buildings:
    
    The height of each building must be a non-negative integer.
    The height of the first building must be 0.
    The height difference between any two adjacent buildings cannot exceed 1.
    
    Additionally, there are city restrictions on the maximum height of specific buildings. These restrictions are given as a 2D integer array restrictions where restrictions[i] = [idi, maxHeighti] indicates that building idi must have a height less than or equal to maxHeighti.
    It is guaranteed that each building will appear at most once in restrictions, and building 1 will not be in restrictions.
    Return the maximum possible height of the tallest building.
    
    Example 1:
    
    
    >>> maxBuilding(n = 5, restrictions = [[2,1],[4,1]])
    >>> 2
    Explanation: The green area in the image indicates the maximum allowed height for each building.
    We can build the buildings with heights [0,1,2,1,2], and the tallest building has a height of 2.
    Example 2:
    
    
    >>> maxBuilding(n = 6, restrictions = [])
    >>> 5
    Explanation: The green area in the image indicates the maximum allowed height for each building.
    We can build the buildings with heights [0,1,2,3,4,5], and the tallest building has a height of 5.
    
    Example 3:
    
    
    >>> maxBuilding(n = 10, restrictions = [[5,3],[2,5],[7,4],[10,3]])
    >>> 5
    Explanation: The green area in the image indicates the maximum allowed height for each building.
    We can build the buildings with heights [0,1,2,3,3,4,4,5,4,3], and the tallest building has a height of 5.
    """
def nextPalindrome(num: str) -> str:
    """
    You are given a numeric string num, representing a very large palindrome.
    Return the smallest palindrome larger than num that can be created by rearranging its digits. If no such palindrome exists, return an empty string "".
    A palindrome is a number that reads the same backward as forward.
    
    Example 1:
    
    >>> nextPalindrome(num = "1221")
    >>> "2112"
    Explanation: The next palindrome larger than "1221" is "2112".
    
    Example 2:
    
    >>> nextPalindrome(num = "32123")
    >>> ""
    Explanation: No palindromes larger than "32123" can be made by rearranging the digits.
    
    Example 3:
    
    >>> nextPalindrome(num = "45544554")
    >>> "54455445"
    Explanation: The next palindrome larger than "45544554" is "54455445".
    """
def replaceDigits(s: str) -> str:
    """
    You are given a 0-indexed string s that has lowercase English letters in its even indices and digits in its odd indices.
    You must perform an operation shift(c, x), where c is a character and x is a digit, that returns the xth character after c.
    
    For example, shift('a', 5) = 'f' and shift('x', 0) = 'x'.
    
    For every odd index i, you want to replace the digit s[i] with the result of the shift(s[i-1], s[i]) operation.
    Return s after replacing all digits. It is guaranteed that shift(s[i-1], s[i]) will never exceed 'z'.
    Note that shift(c, x) is not a preloaded function, but an operation to be implemented as part of the solution.
    
    Example 1:
    
    >>> replaceDigits(s = "a1c1e1")
    >>> "abcdef"
    Explanation: The digits are replaced as follows:
    - s[1] -> shift('a',1) = 'b'
    - s[3] -> shift('c',1) = 'd'
    - s[5] -> shift('e',1) = 'f'
    Example 2:
    
    >>> replaceDigits(s = "a1b2c3d4e")
    >>> "abbdcfdhe"
    Explanation: The digits are replaced as follows:
    - s[1] -> shift('a',1) = 'b'
    - s[3] -> shift('b',2) = 'd'
    - s[5] -> shift('c',3) = 'f'
    - s[7] -> shift('d',4) = 'h'
    """
def maximumElementAfterDecrementingAndRearranging(arr: List[int]) -> int:
    """
    You are given an array of positive integers arr. Perform some operations (possibly none) on arr so that it satisfies these conditions:
    
    The value of the first element in arr must be 1.
    The absolute difference between any 2 adjacent elements must be less than or equal to 1. In other words, abs(arr[i] - arr[i - 1]) <= 1 for each i where 1 <= i < arr.length (0-indexed). abs(x) is the absolute value of x.
    
    There are 2 types of operations that you can perform any number of times:
    
    Decrease the value of any element of arr to a smaller positive integer.
    Rearrange the elements of arr to be in any order.
    
    Return the maximum possible value of an element in arr after performing the operations to satisfy the conditions.
    
    Example 1:
    
    >>> maximumElementAfterDecrementingAndRearranging(arr = [2,2,1,2,1])
    >>> 2
    Explanation:
    We can satisfy the conditions by rearranging arr so it becomes [1,2,2,2,1].
    The largest element in arr is 2.
    
    Example 2:
    
    >>> maximumElementAfterDecrementingAndRearranging(arr = [100,1,1000])
    >>> 3
    Explanation:
    One possible way to satisfy the conditions is by doing the following:
    1. Rearrange arr so it becomes [1,100,1000].
    2. Decrease the value of the second element to 2.
    3. Decrease the value of the third element to 3.
    Now arr = [1,2,3], which satisfies the conditions.
    The largest element in arr is 3.
    
    Example 3:
    
    >>> maximumElementAfterDecrementingAndRearranging(arr = [1,2,3,4,5])
    >>> 5
    Explanation: The array already satisfies the conditions, and the largest element is 5.
    """
def closestRoom(rooms: List[List[int]], queries: List[List[int]]) -> List[int]:
    """
    There is a hotel with n rooms. The rooms are represented by a 2D integer array rooms where rooms[i] = [roomIdi, sizei] denotes that there is a room with room number roomIdi and size equal to sizei. Each roomIdi is guaranteed to be unique.
    You are also given k queries in a 2D array queries where queries[j] = [preferredj, minSizej]. The answer to the jth query is the room number id of a room such that:
    
    The room has a size of at least minSizej, and
    abs(id - preferredj) is minimized, where abs(x) is the absolute value of x.
    
    If there is a tie in the absolute difference, then use the room with the smallest such id. If there is no such room, the answer is -1.
    Return an array answer of length k where answer[j] contains the answer to the jth query.
    
    Example 1:
    
    >>> closestRoom(rooms = [[2,2],[1,2],[3,2]], queries = [[3,1],[3,3],[5,2]])
    >>> [3,-1,3]
    Explanation: The answers to the queries are as follows:
    Query = [3,1]: Room number 3 is the closest as abs(3 - 3) = 0, and its size of 2 is at least 1. The answer is 3.
    Query = [3,3]: There are no rooms with a size of at least 3, so the answer is -1.
    Query = [5,2]: Room number 3 is the closest as abs(3 - 5) = 2, and its size of 2 is at least 2. The answer is 3.
    Example 2:
    
    >>> closestRoom(rooms = [[1,4],[2,3],[3,5],[4,1],[5,2]], queries = [[2,3],[2,4],[2,5]])
    >>> [2,1,3]
    Explanation: The answers to the queries are as follows:
    Query = [2,3]: Room number 2 is the closest as abs(2 - 2) = 0, and its size of 3 is at least 3. The answer is 2.
    Query = [2,4]: Room numbers 1 and 3 both have sizes of at least 4. The answer is 1 since it is smaller.
    Query = [2,5]: Room number 3 is the only room with a size of at least 5. The answer is 3.
    """
def getMinDistance(nums: List[int], target: int, start: int) -> int:
    """
    Given an integer array nums (0-indexed) and two integers target and start, find an index i such that nums[i] == target and abs(i - start) is minimized. Note that abs(x) is the absolute value of x.
    Return abs(i - start).
    It is guaranteed that target exists in nums.
    
    Example 1:
    
    >>> getMinDistance(nums = [1,2,3,4,5], target = 5, start = 3)
    >>> 1
    Explanation: nums[4] = 5 is the only value equal to target, so the answer is abs(4 - 3) = 1.
    
    Example 2:
    
    >>> getMinDistance(nums = [1], target = 1, start = 0)
    >>> 0
    Explanation: nums[0] = 1 is the only value equal to target, so the answer is abs(0 - 0) = 0.
    
    Example 3:
    
    >>> getMinDistance(nums = [1,1,1,1,1,1,1,1,1,1], target = 1, start = 0)
    >>> 0
    Explanation: Every value of nums is 1, but nums[0] minimizes abs(i - start), which is abs(0 - 0) = 0.
    """
def splitString(s: str) -> bool:
    """
    You are given a string s that consists of only digits.
    Check if we can split s into two or more non-empty substrings such that the numerical values of the substrings are in descending order and the difference between numerical values of every two adjacent substrings is equal to 1.
    
    For example, the string s = "0090089" can be split into ["0090", "089"] with numerical values [90,89]. The values are in descending order and adjacent values differ by 1, so this way is valid.
    Another example, the string s = "001" can be split into ["0", "01"], ["00", "1"], or ["0", "0", "1"]. However all the ways are invalid because they have numerical values [0,1], [0,1], and [0,0,1] respectively, all of which are not in descending order.
    
    Return true if it is possible to split s​​​​​​ as described above, or false otherwise.
    A substring is a contiguous sequence of characters in a string.
    
    Example 1:
    
    >>> splitString(s = "1234")
    >>> false
    Explanation: There is no valid way to split s.
    
    Example 2:
    
    >>> splitString(s = "050043")
    >>> true
    Explanation: s can be split into ["05", "004", "3"] with numerical values [5,4,3].
    The values are in descending order with adjacent values differing by 1.
    
    Example 3:
    
    >>> splitString(s = "9080701")
    >>> false
    Explanation: There is no valid way to split s.
    """
def getMinSwaps(num: str, k: int) -> int:
    """
    You are given a string num, representing a large integer, and an integer k.
    We call some integer wonderful if it is a permutation of the digits in num and is greater in value than num. There can be many wonderful integers. However, we only care about the smallest-valued ones.
    
    For example, when num = "5489355142":
    
    
    The 1st smallest wonderful integer is "5489355214".
    The 2nd smallest wonderful integer is "5489355241".
    The 3rd smallest wonderful integer is "5489355412".
    The 4th smallest wonderful integer is "5489355421".
    
    
    
    Return the minimum number of adjacent digit swaps that needs to be applied to num to reach the kth smallest wonderful integer.
    The tests are generated in such a way that kth smallest wonderful integer exists.
    
    Example 1:
    
    >>> getMinSwaps(num = "5489355142", k = 4)
    >>> 2
    Explanation: The 4th smallest wonderful number is "5489355421". To get this number:
    - Swap index 7 with index 8: "5489355142" -> "5489355412"
    - Swap index 8 with index 9: "5489355412" -> "5489355421"
    
    Example 2:
    
    >>> getMinSwaps(num = "11112", k = 4)
    >>> 4
    Explanation: The 4th smallest wonderful number is "21111". To get this number:
    - Swap index 3 with index 4: "11112" -> "11121"
    - Swap index 2 with index 3: "11121" -> "11211"
    - Swap index 1 with index 2: "11211" -> "12111"
    - Swap index 0 with index 1: "12111" -> "21111"
    
    Example 3:
    
    >>> getMinSwaps(num = "00123", k = 1)
    >>> 1
    Explanation: The 1st smallest wonderful number is "00132". To get this number:
    - Swap index 3 with index 4: "00123" -> "00132"
    """
def minInterval(intervals: List[List[int]], queries: List[int]) -> List[int]:
    """
    You are given a 2D integer array intervals, where intervals[i] = [lefti, righti] describes the ith interval starting at lefti and ending at righti (inclusive). The size of an interval is defined as the number of integers it contains, or more formally righti - lefti + 1.
    You are also given an integer array queries. The answer to the jth query is the size of the smallest interval i such that lefti <= queries[j] <= righti. If no such interval exists, the answer is -1.
    Return an array containing the answers to the queries.
    
    Example 1:
    
    >>> minInterval(intervals = [[1,4],[2,4],[3,6],[4,4]], queries = [2,3,4,5])
    >>> [3,3,1,4]
    Explanation: The queries are processed as follows:
    - Query = 2: The interval [2,4] is the smallest interval containing 2. The answer is 4 - 2 + 1 = 3.
    - Query = 3: The interval [2,4] is the smallest interval containing 3. The answer is 4 - 2 + 1 = 3.
    - Query = 4: The interval [4,4] is the smallest interval containing 4. The answer is 4 - 4 + 1 = 1.
    - Query = 5: The interval [3,6] is the smallest interval containing 5. The answer is 6 - 3 + 1 = 4.
    
    Example 2:
    
    >>> minInterval(intervals = [[2,3],[2,5],[1,8],[20,25]], queries = [2,19,5,22])
    >>> [2,-1,4,6]
    Explanation: The queries are processed as follows:
    - Query = 2: The interval [2,3] is the smallest interval containing 2. The answer is 3 - 2 + 1 = 2.
    - Query = 19: None of the intervals contain 19. The answer is -1.
    - Query = 5: The interval [2,5] is the smallest interval containing 5. The answer is 5 - 2 + 1 = 4.
    - Query = 22: The interval [20,25] is the smallest interval containing 22. The answer is 25 - 20 + 1 = 6.
    """
def distinctNumbers(nums: List[int], k: int) -> List[int]:
    """
    You are given an integer array nums of length n and an integer k. Your task is to find the number of distinct elements in every subarray of size k within nums.
    Return an array ans such that ans[i] is the count of distinct elements in nums[i..(i + k - 1)] for each index 0 <= i < n - k.
    
    Example 1:
    
    >>> distinctNumbers(nums = [1,2,3,2,2,1,3], k = 3)
    >>> [3,2,2,2,3]
    Explanation: The number of distinct elements in each subarray goes as follows:
    - nums[0..2] = [1,2,3] so ans[0] = 3
    - nums[1..3] = [2,3,2] so ans[1] = 2
    - nums[2..4] = [3,2,2] so ans[2] = 2
    - nums[3..5] = [2,2,1] so ans[3] = 2
    - nums[4..6] = [2,1,3] so ans[4] = 3
    
    Example 2:
    
    >>> distinctNumbers(nums = [1,1,1,1,2,3,4], k = 4)
    >>> [1,2,3,4]
    Explanation: The number of distinct elements in each subarray goes as follows:
    - nums[0..3] = [1,1,1,1] so ans[0] = 1
    - nums[1..4] = [1,1,1,2] so ans[1] = 2
    - nums[2..5] = [1,1,2,3] so ans[2] = 3
    - nums[3..6] = [1,2,3,4] so ans[3] = 4
    """
def maximumPopulation(logs: List[List[int]]) -> int:
    """
    You are given a 2D integer array logs where each logs[i] = [birthi, deathi] indicates the birth and death years of the ith person.
    The population of some year x is the number of people alive during that year. The ith person is counted in year x's population if x is in the inclusive range [birthi, deathi - 1]. Note that the person is not counted in the year that they die.
    Return the earliest year with the maximum population.
    
    Example 1:
    
    >>> maximumPopulation(logs = [[1993,1999],[2000,2010]])
    >>> 1993
    Explanation: The maximum population is 1, and 1993 is the earliest year with this population.
    
    Example 2:
    
    >>> maximumPopulation(logs = [[1950,1961],[1960,1971],[1970,1981]])
    >>> 1960
    Explanation:
    The maximum population is 2, and it had happened in years 1960 and 1970.
    The earlier year between them is 1960.
    """
def maxDistance(nums1: List[int], nums2: List[int]) -> int:
    """
    You are given two non-increasing 0-indexed integer arrays nums1​​​​​​ and nums2​​​​​​.
    A pair of indices (i, j), where 0 <= i < nums1.length and 0 <= j < nums2.length, is valid if both i <= j and nums1[i] <= nums2[j]. The distance of the pair is j - i​​​​.
    Return the maximum distance of any valid pair (i, j). If there are no valid pairs, return 0.
    An array arr is non-increasing if arr[i-1] >= arr[i] for every 1 <= i < arr.length.
    
    Example 1:
    
    >>> maxDistance(nums1 = [55,30,5,4,2], nums2 = [100,20,10,10,5])
    >>> 2
    Explanation: The valid pairs are (0,0), (2,2), (2,3), (2,4), (3,3), (3,4), and (4,4).
    The maximum distance is 2 with pair (2,4).
    
    Example 2:
    
    >>> maxDistance(nums1 = [2,2,2], nums2 = [10,10,1])
    >>> 1
    Explanation: The valid pairs are (0,0), (0,1), and (1,1).
    The maximum distance is 1 with pair (0,1).
    
    Example 3:
    
    >>> maxDistance(nums1 = [30,29,19,5], nums2 = [25,25,25,25,25])
    >>> 2
    Explanation: The valid pairs are (2,2), (2,3), (2,4), (3,3), and (3,4).
    The maximum distance is 2 with pair (2,4).
    """
def maxSumMinProduct(nums: List[int]) -> int:
    """
    The min-product of an array is equal to the minimum value in the array multiplied by the array's sum.
    
    For example, the array [3,2,5] (minimum value is 2) has a min-product of 2 * (3+2+5) = 2 * 10 = 20.
    
    Given an array of integers nums, return the maximum min-product of any non-empty subarray of nums. Since the answer may be large, return it modulo 109 + 7.
    Note that the min-product should be maximized before performing the modulo operation. Testcases are generated such that the maximum min-product without modulo will fit in a 64-bit signed integer.
    A subarray is a contiguous part of an array.
    
    Example 1:
    
    >>> maxSumMinProduct(nums = [1,2,3,2])
    >>> 14
    Explanation: The maximum min-product is achieved with the subarray [2,3,2] (minimum value is 2).
    2 * (2+3+2) = 2 * 7 = 14.
    
    Example 2:
    
    >>> maxSumMinProduct(nums = [2,3,3,1,2])
    >>> 18
    Explanation: The maximum min-product is achieved with the subarray [3,3] (minimum value is 3).
    3 * (3+3) = 3 * 6 = 18.
    
    Example 3:
    
    >>> maxSumMinProduct(nums = [3,1,5,6,4,2])
    >>> 60
    Explanation: The maximum min-product is achieved with the subarray [5,6,4] (minimum value is 4).
    4 * (5+6+4) = 4 * 15 = 60.
    """
def largestPathValue(colors: str, edges: List[List[int]]) -> int:
    """
    There is a directed graph of n colored nodes and m edges. The nodes are numbered from 0 to n - 1.\r
    \r
    You are given a string colors where colors[i] is a lowercase English letter representing the color of the ith node in this graph (0-indexed). You are also given a 2D array edges where edges[j] = [aj, bj] indicates that there is a directed edge from node aj to node bj.\r
    \r
    A valid path in the graph is a sequence of nodes x1 -> x2 -> x3 -> ... -> xk such that there is a directed edge from xi to xi+1 for every 1 <= i < k. The color value of the path is the number of nodes that are colored the most frequently occurring color along that path.\r
    \r
    Return the largest color value of any valid path in the given graph, or -1 if the graph contains a cycle.\r
    \r
     \r
    Example 1:\r
    \r
    \r
    \r
    \r
    >>> largestPathValue(colors = "abaca", edges = [[0,1],[0,2],[2,3],[3,4]]\r)
    >>> 3\r
    Explanation: The path 0 -> 2 -> 3 -> 4 contains 3 nodes that are colored "a" (red in the above image).\r
    \r
    \r
    Example 2:\r
    \r
    \r
    \r
    \r
    >>> largestPathValue(colors = "a", edges = [[0,0]]\r)
    >>> -1\r
    Explanation: There is a cycle from 0 to 0.\r
    \r
    \r
     \r
    """
def longestWord(words: List[str]) -> str:
    """
    Given an array of strings words, find the longest string in words such that every prefix of it is also in words.
    
    For example, let words = ["a", "app", "ap"]. The string "app" has prefixes "ap" and "a", all of which are in words.
    
    Return the string described above. If there is more than one string with the same length, return the lexicographically smallest one, and if no string exists, return "".
    
    Example 1:
    
    >>> longestWord(words = ["k","ki","kir","kira", "kiran"])
    >>> "kiran"
    Explanation: "kiran" has prefixes "kira", "kir", "ki", and "k", and all of them appear in words.
    
    Example 2:
    
    >>> longestWord(words = ["a", "banana", "app", "appl", "ap", "apply", "apple"])
    >>> "apple"
    Explanation: Both "apple" and "apply" have all their prefixes in words.
    However, "apple" is lexicographically smaller, so we return that.
    
    Example 3:
    
    >>> longestWord(words = ["abc", "bc", "ab", "qwe"])
    >>> ""
    """
def sortSentence(s: str) -> str:
    """
    A sentence is a list of words that are separated by a single space with no leading or trailing spaces. Each word consists of lowercase and uppercase English letters.
    A sentence can be shuffled by appending the 1-indexed word position to each word then rearranging the words in the sentence.
    
    For example, the sentence "This is a sentence" can be shuffled as "sentence4 a3 is2 This1" or "is2 sentence4 This1 a3".
    
    Given a shuffled sentence s containing no more than 9 words, reconstruct and return the original sentence.
    
    Example 1:
    
    >>> sortSentence(s = "is2 sentence4 This1 a3")
    >>> "This is a sentence"
    Explanation: Sort the words in s to their original positions "This1 is2 a3 sentence4", then remove the numbers.
    
    Example 2:
    
    >>> sortSentence(s = "Myself2 Me1 I4 and3")
    >>> "Me Myself and I"
    Explanation: Sort the words in s to their original positions "Me1 Myself2 and3 I4", then remove the numbers.
    """
def memLeak(memory1: int, memory2: int) -> List[int]:
    """
    You are given two integers memory1 and memory2 representing the available memory in bits on two memory sticks. There is currently a faulty program running that consumes an increasing amount of memory every second.
    At the ith second (starting from 1), i bits of memory are allocated to the stick with more available memory (or from the first memory stick if both have the same available memory). If neither stick has at least i bits of available memory, the program crashes.
    Return an array containing [crashTime, memory1crash, memory2crash], where crashTime is the time (in seconds) when the program crashed and memory1crash and memory2crash are the available bits of memory in the first and second sticks respectively.
    
    Example 1:
    
    >>> memLeak(memory1 = 2, memory2 = 2)
    >>> [3,1,0]
    Explanation: The memory is allocated as follows:
    - At the 1st second, 1 bit of memory is allocated to stick 1. The first stick now has 1 bit of available memory.
    - At the 2nd second, 2 bits of memory are allocated to stick 2. The second stick now has 0 bits of available memory.
    - At the 3rd second, the program crashes. The sticks have 1 and 0 bits available respectively.
    
    Example 2:
    
    >>> memLeak(memory1 = 8, memory2 = 11)
    >>> [6,0,4]
    Explanation: The memory is allocated as follows:
    - At the 1st second, 1 bit of memory is allocated to stick 2. The second stick now has 10 bit of available memory.
    - At the 2nd second, 2 bits of memory are allocated to stick 2. The second stick now has 8 bits of available memory.
    - At the 3rd second, 3 bits of memory are allocated to stick 1. The first stick now has 5 bits of available memory.
    - At the 4th second, 4 bits of memory are allocated to stick 2. The second stick now has 4 bits of available memory.
    - At the 5th second, 5 bits of memory are allocated to stick 1. The first stick now has 0 bits of available memory.
    - At the 6th second, the program crashes. The sticks have 0 and 4 bits available respectively.
    """