ShwStone/humaneval-leetcode huggingface dataset:
def countPaths(n: int, roads: List[List[int]]) -> int:
    """
    You are in a city that consists of n intersections numbered from 0 to n - 1 with bi-directional roads between some intersections. The inputs are generated such that you can reach any intersection from any other intersection and that there is at most one road between any two intersections.
    You are given an integer n and a 2D integer array roads where roads[i] = [ui, vi, timei] means that there is a road between intersections ui and vi that takes timei minutes to travel. You want to know in how many ways you can travel from intersection 0 to intersection n - 1 in the shortest amount of time.
    Return the number of ways you can arrive at your destination in the shortest amount of time. Since the answer may be large, return it modulo 109 + 7.
    
    Example 1:
    
    
    >>> countPaths(n = 7, roads = [[0,6,7],[0,1,2],[1,2,3],[1,3,3],[6,3,3],[3,5,1],[6,5,1],[2,5,1],[0,4,5],[4,6,2]])
    >>> 4
    Explanation: The shortest amount of time it takes to go from intersection 0 to intersection 6 is 7 minutes.
    The four ways to get there in 7 minutes are:
    - 0 ➝ 6
    - 0 ➝ 4 ➝ 6
    - 0 ➝ 1 ➝ 2 ➝ 5 ➝ 6
    - 0 ➝ 1 ➝ 3 ➝ 5 ➝ 6
    
    Example 2:
    
    >>> countPaths(n = 2, roads = [[1,0,10]])
    >>> 1
    Explanation: There is only one way to go from intersection 0 to intersection 1, and it takes 10 minutes.
    """
def numberOfCombinations(num: str) -> int:
    """
    You wrote down many positive integers in a string called num. However, you realized that you forgot to add commas to seperate the different numbers. You remember that the list of integers was non-decreasing and that no integer had leading zeros.
    Return the number of possible lists of integers that you could have written down to get the string num. Since the answer may be large, return it modulo 109 + 7.
    
    Example 1:
    
    >>> numberOfCombinations(num = "327")
    >>> 2
    Explanation: You could have written down the numbers:
    3, 27
    327
    
    Example 2:
    
    >>> numberOfCombinations(num = "094")
    >>> 0
    Explanation: No numbers can have leading zeros and all numbers must be positive.
    
    Example 3:
    
    >>> numberOfCombinations(num = "0")
    >>> 0
    Explanation: No numbers can have leading zeros and all numbers must be positive.
    """
def findGCD(nums: List[int]) -> int:
    """
    Given an integer array nums, return the greatest common divisor of the smallest number and largest number in nums.
    The greatest common divisor of two numbers is the largest positive integer that evenly divides both numbers.
    
    Example 1:
    
    >>> findGCD(nums = [2,5,6,9,10])
    >>> 2
    Explanation:
    The smallest number in nums is 2.
    The largest number in nums is 10.
    The greatest common divisor of 2 and 10 is 2.
    
    Example 2:
    
    >>> findGCD(nums = [7,5,6,8,3])
    >>> 1
    Explanation:
    The smallest number in nums is 3.
    The largest number in nums is 8.
    The greatest common divisor of 3 and 8 is 1.
    
    Example 3:
    
    >>> findGCD(nums = [3,3])
    >>> 3
    Explanation:
    The smallest number in nums is 3.
    The largest number in nums is 3.
    The greatest common divisor of 3 and 3 is 3.
    """
def findDifferentBinaryString(nums: List[str]) -> str:
    """
    Given an array of strings nums containing n unique binary strings each of length n, return a binary string of length n that does not appear in nums. If there are multiple answers, you may return any of them.
    
    Example 1:
    
    >>> findDifferentBinaryString(nums = ["01","10"])
    >>> "11"
    Explanation: "11" does not appear in nums. "00" would also be correct.
    
    Example 2:
    
    >>> findDifferentBinaryString(nums = ["00","01"])
    >>> "11"
    Explanation: "11" does not appear in nums. "10" would also be correct.
    
    Example 3:
    
    >>> findDifferentBinaryString(nums = ["111","011","001"])
    >>> "101"
    Explanation: "101" does not appear in nums. "000", "010", "100", and "110" would also be correct.
    """
def minimizeTheDifference(mat: List[List[int]], target: int) -> int:
    """
    You are given an m x n integer matrix mat and an integer target.
    Choose one integer from each row in the matrix such that the absolute difference between target and the sum of the chosen elements is minimized.
    Return the minimum absolute difference.
    The absolute difference between two numbers a and b is the absolute value of a - b.
    
    Example 1:
    
    
    >>> minimizeTheDifference(mat = [[1,2,3],[4,5,6],[7,8,9]], target = 13)
    >>> 0
    Explanation: One possible choice is to:
    - Choose 1 from the first row.
    - Choose 5 from the second row.
    - Choose 7 from the third row.
    The sum of the chosen elements is 13, which equals the target, so the absolute difference is 0.
    
    Example 2:
    
    
    >>> minimizeTheDifference(mat = [[1],[2],[3]], target = 100)
    >>> 94
    Explanation: The best possible choice is to:
    - Choose 1 from the first row.
    - Choose 2 from the second row.
    - Choose 3 from the third row.
    The sum of the chosen elements is 6, and the absolute difference is 94.
    
    Example 3:
    
    
    >>> minimizeTheDifference(mat = [[1,2,9,8,7]], target = 6)
    >>> 1
    Explanation: The best choice is to choose 7 from the first row.
    The absolute difference is 1.
    """
def recoverArray(n: int, sums: List[int]) -> List[int]:
    """
    You are given an integer n representing the length of an unknown array that you are trying to recover. You are also given an array sums containing the values of all 2n subset sums of the unknown array (in no particular order).
    Return the array ans of length n representing the unknown array. If multiple answers exist, return any of them.
    An array sub is a subset of an array arr if sub can be obtained from arr by deleting some (possibly zero or all) elements of arr. The sum of the elements in sub is one possible subset sum of arr. The sum of an empty array is considered to be 0.
    Note: Test cases are generated such that there will always be at least one correct answer.
    
    Example 1:
    
    >>> recoverArray(n = 3, sums = [-3,-2,-1,0,0,1,2,3])
    >>> [1,2,-3]
    Explanation: [1,2,-3] is able to achieve the given subset sums:
    - []: sum is 0
    - [1]: sum is 1
    - [2]: sum is 2
    - [1,2]: sum is 3
    - [-3]: sum is -3
    - [1,-3]: sum is -2
    - [2,-3]: sum is -1
    - [1,2,-3]: sum is 0
    Note that any permutation of [1,2,-3] and also any permutation of [-1,-2,3] will also be accepted.
    
    Example 2:
    
    >>> recoverArray(n = 2, sums = [0,0,0,0])
    >>> [0,0]
    Explanation: The only correct answer is [0,0].
    
    Example 3:
    
    >>> recoverArray(n = 4, sums = [0,0,5,5,4,-1,4,9,9,-1,4,3,4,8,3,8])
    >>> [0,-1,4,5]
    Explanation: [0,-1,4,5] is able to achieve the given subset sums.
    """
def widestPairOfIndices(nums1: List[int], nums2: List[int]) -> int:
    """
    You are given two 0-indexed binary arrays nums1 and nums2. Find the widest pair of indices (i, j) such that i <= j and nums1[i] + nums1[i+1] + ... + nums1[j] == nums2[i] + nums2[i+1] + ... + nums2[j].
    The widest pair of indices is the pair with the largest distance between i and j. The distance between a pair of indices is defined as j - i + 1.
    Return the distance of the widest pair of indices. If no pair of indices meets the conditions, return 0.
    
    Example 1:
    
    >>> widestPairOfIndices(nums1 = [1,1,0,1], nums2 = [0,1,1,0])
    >>> 3
    Explanation:
    If i = 1 and j = 3:
    nums1[1] + nums1[2] + nums1[3] = 1 + 0 + 1 = 2.
    nums2[1] + nums2[2] + nums2[3] = 1 + 1 + 0 = 2.
    The distance between i and j is j - i + 1 = 3 - 1 + 1 = 3.
    
    Example 2:
    
    >>> widestPairOfIndices(nums1 = [0,1], nums2 = [1,1])
    >>> 1
    Explanation:
    If i = 1 and j = 1:
    nums1[1] = 1.
    nums2[1] = 1.
    The distance between i and j is j - i + 1 = 1 - 1 + 1 = 1.
    
    Example 3:
    
    >>> widestPairOfIndices(nums1 = [0], nums2 = [1])
    >>> 0
    Explanation:
    There are no pairs of indices that meet the requirements.
    """
def minimumDifference(nums: List[int], k: int) -> int:
    """
    You are given a 0-indexed integer array nums, where nums[i] represents the score of the ith student. You are also given an integer k.
    Pick the scores of any k students from the array so that the difference between the highest and the lowest of the k scores is minimized.
    Return the minimum possible difference.
    
    Example 1:
    
    >>> minimumDifference(nums = [90], k = 1)
    >>> 0
    Explanation: There is one way to pick score(s) of one student:
    - [90]. The difference between the highest and lowest score is 90 - 90 = 0.
    The minimum possible difference is 0.
    
    Example 2:
    
    >>> minimumDifference(nums = [9,4,1,7], k = 2)
    >>> 2
    Explanation: There are six ways to pick score(s) of two students:
    - [9,4,1,7]. The difference between the highest and lowest score is 9 - 4 = 5.
    - [9,4,1,7]. The difference between the highest and lowest score is 9 - 1 = 8.
    - [9,4,1,7]. The difference between the highest and lowest score is 9 - 7 = 2.
    - [9,4,1,7]. The difference between the highest and lowest score is 4 - 1 = 3.
    - [9,4,1,7]. The difference between the highest and lowest score is 7 - 4 = 3.
    - [9,4,1,7]. The difference between the highest and lowest score is 7 - 1 = 6.
    The minimum possible difference is 2.
    """
def kthLargestNumber(nums: List[str], k: int) -> str:
    """
    You are given an array of strings nums and an integer k. Each string in nums represents an integer without leading zeros.
    Return the string that represents the kth largest integer in nums.
    Note: Duplicate numbers should be counted distinctly. For example, if nums is ["1","2","2"], "2" is the first largest integer, "2" is the second-largest integer, and "1" is the third-largest integer.
    
    Example 1:
    
    >>> kthLargestNumber(nums = ["3","6","7","10"], k = 4)
    >>> "3"
    Explanation:
    The numbers in nums sorted in non-decreasing order are ["3","6","7","10"].
    The 4th largest integer in nums is "3".
    
    Example 2:
    
    >>> kthLargestNumber(nums = ["2","21","12","1"], k = 3)
    >>> "2"
    Explanation:
    The numbers in nums sorted in non-decreasing order are ["1","2","12","21"].
    The 3rd largest integer in nums is "2".
    
    Example 3:
    
    >>> kthLargestNumber(nums = ["0","0"], k = 2)
    >>> "0"
    Explanation:
    The numbers in nums sorted in non-decreasing order are ["0","0"].
    The 2nd largest integer in nums is "0".
    """
def minSessions(tasks: List[int], sessionTime: int) -> int:
    """
    There are n tasks assigned to you. The task times are represented as an integer array tasks of length n, where the ith task takes tasks[i] hours to finish. A work session is when you work for at most sessionTime consecutive hours and then take a break.
    You should finish the given tasks in a way that satisfies the following conditions:
    
    If you start a task in a work session, you must complete it in the same work session.
    You can start a new task immediately after finishing the previous one.
    You may complete the tasks in any order.
    
    Given tasks and sessionTime, return the minimum number of work sessions needed to finish all the tasks following the conditions above.
    The tests are generated such that sessionTime is greater than or equal to the maximum element in tasks[i].
    
    Example 1:
    
    >>> minSessions(tasks = [1,2,3], sessionTime = 3)
    >>> 2
    Explanation: You can finish the tasks in two work sessions.
    - First work session: finish the first and the second tasks in 1 + 2 = 3 hours.
    - Second work session: finish the third task in 3 hours.
    
    Example 2:
    
    >>> minSessions(tasks = [3,1,3,1,1], sessionTime = 8)
    >>> 2
    Explanation: You can finish the tasks in two work sessions.
    - First work session: finish all the tasks except the last one in 3 + 1 + 3 + 1 = 8 hours.
    - Second work session: finish the last task in 1 hour.
    
    Example 3:
    
    >>> minSessions(tasks = [1,2,3,4,5], sessionTime = 15)
    >>> 1
    Explanation: You can finish all the tasks in one work session.
    """
def numberOfUniqueGoodSubsequences(binary: str) -> int:
    """
    You are given a binary string binary. A subsequence of binary is considered good if it is not empty and has no leading zeros (with the exception of "0").
    Find the number of unique good subsequences of binary.
    
    For example, if binary = "001", then all the good subsequences are ["0", "0", "1"], so the unique good subsequences are "0" and "1". Note that subsequences "00", "01", and "001" are not good because they have leading zeros.
    
    Return the number of unique good subsequences of binary. Since the answer may be very large, return it modulo 109 + 7.
    A subsequence is a sequence that can be derived from another sequence by deleting some or no elements without changing the order of the remaining elements.
    
    Example 1:
    
    >>> numberOfUniqueGoodSubsequences(binary = "001")
    >>> 2
    Explanation: The good subsequences of binary are ["0", "0", "1"].
    The unique good subsequences are "0" and "1".
    
    Example 2:
    
    >>> numberOfUniqueGoodSubsequences(binary = "11")
    >>> 2
    Explanation: The good subsequences of binary are ["1", "1", "11"].
    The unique good subsequences are "1" and "11".
    Example 3:
    
    >>> numberOfUniqueGoodSubsequences(binary = "101")
    >>> 5
    Explanation: The good subsequences of binary are ["1", "0", "1", "10", "11", "101"].
    The unique good subsequences are "0", "1", "10", "11", and "101".
    """
def catchMaximumAmountofPeople(team: List[int], dist: int) -> int:
    """
    You are playing a game of tag with your friends. In tag, people are divided into two teams: people who are "it", and people who are not "it". The people who are "it" want to catch as many people as possible who are not "it".
    You are given a 0-indexed integer array team containing only zeros (denoting people who are not "it") and ones (denoting people who are "it"), and an integer dist. A person who is "it" at index i can catch any one person whose index is in the range [i - dist, i + dist] (inclusive) and is not "it".
    Return the maximum number of people that the people who are "it" can catch.
    
    Example 1:
    
    >>> catchMaximumAmountofPeople(team = [0,1,0,1,0], dist = 3)
    >>> 2
    Explanation:
    The person who is "it" at index 1 can catch people in the range [i-dist, i+dist] = [1-3, 1+3] = [-2, 4].
    They can catch the person who is not "it" at index 2.
    The person who is "it" at index 3 can catch people in the range [i-dist, i+dist] = [3-3, 3+3] = [0, 6].
    They can catch the person who is not "it" at index 0.
    The person who is not "it" at index 4 will not be caught because the people at indices 1 and 3 are already catching one person.
    Example 2:
    
    >>> catchMaximumAmountofPeople(team = [1], dist = 1)
    >>> 0
    Explanation:
    There are no people who are not "it" to catch.
    
    Example 3:
    
    >>> catchMaximumAmountofPeople(team = [0], dist = 1)
    >>> 0
    Explanation:
    There are no people who are "it" to catch people.
    """
def findMiddleIndex(nums: List[int]) -> int:
    """
    Given a 0-indexed integer array nums, find the leftmost middleIndex (i.e., the smallest amongst all the possible ones).
    A middleIndex is an index where nums[0] + nums[1] + ... + nums[middleIndex-1] == nums[middleIndex+1] + nums[middleIndex+2] + ... + nums[nums.length-1].
    If middleIndex == 0, the left side sum is considered to be 0. Similarly, if middleIndex == nums.length - 1, the right side sum is considered to be 0.
    Return the leftmost middleIndex that satisfies the condition, or -1 if there is no such index.
    
    Example 1:
    
    >>> findMiddleIndex(nums = [2,3,-1,8,4])
    >>> 3
    Explanation: The sum of the numbers before index 3 is: 2 + 3 + -1 = 4
    The sum of the numbers after index 3 is: 4 = 4
    
    Example 2:
    
    >>> findMiddleIndex(nums = [1,-1,4])
    >>> 2
    Explanation: The sum of the numbers before index 2 is: 1 + -1 = 0
    The sum of the numbers after index 2 is: 0
    
    Example 3:
    
    >>> findMiddleIndex(nums = [2,5])
    >>> -1
    Explanation: There is no valid middleIndex.
    """
def findFarmland(land: List[List[int]]) -> List[List[int]]:
    """
    You are given a 0-indexed m x n binary matrix land where a 0 represents a hectare of forested land and a 1 represents a hectare of farmland.
    To keep the land organized, there are designated rectangular areas of hectares that consist entirely of farmland. These rectangular areas are called groups. No two groups are adjacent, meaning farmland in one group is not four-directionally adjacent to another farmland in a different group.
    land can be represented by a coordinate system where the top left corner of land is (0, 0) and the bottom right corner of land is (m-1, n-1). Find the coordinates of the top left and bottom right corner of each group of farmland. A group of farmland with a top left corner at (r1, c1) and a bottom right corner at (r2, c2) is represented by the 4-length array [r1, c1, r2, c2].
    Return a 2D array containing the 4-length arrays described above for each group of farmland in land. If there are no groups of farmland, return an empty array. You may return the answer in any order.
    
    Example 1:
    
    
    >>> findFarmland(land = [[1,0,0],[0,1,1],[0,1,1]])
    >>> [[0,0,0,0],[1,1,2,2]]
    Explanation:
    The first group has a top left corner at land[0][0] and a bottom right corner at land[0][0].
    The second group has a top left corner at land[1][1] and a bottom right corner at land[2][2].
    
    Example 2:
    
    
    >>> findFarmland(land = [[1,1],[1,1]])
    >>> [[0,0,1,1]]
    Explanation:
    The first group has a top left corner at land[0][0] and a bottom right corner at land[1][1].
    
    Example 3:
    
    
    >>> findFarmland(land = [[0]])
    >>> []
    Explanation:
    There are no groups of farmland.
    """
def numberOfGoodSubsets(nums: List[int]) -> int:
    """
    You are given an integer array nums. We call a subset of nums good if its product can be represented as a product of one or more distinct prime numbers.
    
    For example, if nums = [1, 2, 3, 4]:
    
    
    [2, 3], [1, 2, 3], and [1, 3] are good subsets with products 6 = 2*3, 6 = 2*3, and 3 = 3 respectively.
    [1, 4] and [4] are not good subsets with products 4 = 2*2 and 4 = 2*2 respectively.
    
    
    
    Return the number of different good subsets in nums modulo 109 + 7.
    A subset of nums is any array that can be obtained by deleting some (possibly none or all) elements from nums. Two subsets are different if and only if the chosen indices to delete are different.
    
    Example 1:
    
    >>> numberOfGoodSubsets(nums = [1,2,3,4])
    >>> 6
    Explanation: The good subsets are:
    - [1,2]: product is 2, which is the product of distinct prime 2.
    - [1,2,3]: product is 6, which is the product of distinct primes 2 and 3.
    - [1,3]: product is 3, which is the product of distinct prime 3.
    - [2]: product is 2, which is the product of distinct prime 2.
    - [2,3]: product is 6, which is the product of distinct primes 2 and 3.
    - [3]: product is 3, which is the product of distinct prime 3.
    
    Example 2:
    
    >>> numberOfGoodSubsets(nums = [4,2,3,15])
    >>> 5
    Explanation: The good subsets are:
    - [2]: product is 2, which is the product of distinct prime 2.
    - [2,3]: product is 6, which is the product of distinct primes 2 and 3.
    - [2,15]: product is 30, which is the product of distinct primes 2, 3, and 5.
    - [3]: product is 3, which is the product of distinct prime 3.
    - [15]: product is 15, which is the product of distinct primes 3 and 5.
    """
def countQuadruplets(nums: List[int]) -> int:
    """
    Given a 0-indexed integer array nums, return the number of distinct quadruplets (a, b, c, d) such that:
    
    nums[a] + nums[b] + nums[c] == nums[d], and
    a < b < c < d
    
    
    Example 1:
    
    >>> countQuadruplets(nums = [1,2,3,6])
    >>> 1
    Explanation: The only quadruplet that satisfies the requirement is (0, 1, 2, 3) because 1 + 2 + 3 == 6.
    
    Example 2:
    
    >>> countQuadruplets(nums = [3,3,6,4,5])
    >>> 0
    Explanation: There are no such quadruplets in [3,3,6,4,5].
    
    Example 3:
    
    >>> countQuadruplets(nums = [1,1,1,3,5])
    >>> 4
    Explanation: The 4 quadruplets that satisfy the requirement are:
    - (0, 1, 2, 3): 1 + 1 + 1 == 3
    - (0, 1, 3, 4): 1 + 1 + 3 == 5
    - (0, 2, 3, 4): 1 + 1 + 3 == 5
    - (1, 2, 3, 4): 1 + 1 + 3 == 5
    """
def numberOfWeakCharacters(properties: List[List[int]]) -> int:
    """
    You are playing a game that contains multiple characters, and each of the characters has two main properties: attack and defense. You are given a 2D integer array properties where properties[i] = [attacki, defensei] represents the properties of the ith character in the game.
    A character is said to be weak if any other character has both attack and defense levels strictly greater than this character's attack and defense levels. More formally, a character i is said to be weak if there exists another character j where attackj > attacki and defensej > defensei.
    Return the number of weak characters.
    
    Example 1:
    
    >>> numberOfWeakCharacters(properties = [[5,5],[6,3],[3,6]])
    >>> 0
    Explanation: No character has strictly greater attack and defense than the other.
    
    Example 2:
    
    >>> numberOfWeakCharacters(properties = [[2,2],[3,3]])
    >>> 1
    Explanation: The first character is weak because the second character has a strictly greater attack and defense.
    
    Example 3:
    
    >>> numberOfWeakCharacters(properties = [[1,5],[10,4],[4,3]])
    >>> 1
    Explanation: The third character is weak because the second character has a strictly greater attack and defense.
    """
def firstDayBeenInAllRooms(nextVisit: List[int]) -> int:
    """
    There are n rooms you need to visit, labeled from 0 to n - 1. Each day is labeled, starting from 0. You will go in and visit one room a day.
    Initially on day 0, you visit room 0. The order you visit the rooms for the coming days is determined by the following rules and a given 0-indexed array nextVisit of length n:
    
    Assuming that on a day, you visit room i,
    if you have been in room i an odd number of times (including the current visit), on the next day you will visit a room with a lower or equal room number specified by nextVisit[i] where 0 <= nextVisit[i] <= i;
    if you have been in room i an even number of times (including the current visit), on the next day you will visit room (i + 1) mod n.
    
    Return the label of the first day where you have been in all the rooms. It can be shown that such a day exists. Since the answer may be very large, return it modulo 109 + 7.
    
    Example 1:
    
    >>> firstDayBeenInAllRooms(nextVisit = [0,0])
    >>> 2
    Explanation:
    - On day 0, you visit room 0. The total times you have been in room 0 is 1, which is odd.
      On the next day you will visit room nextVisit[0] = 0
    - On day 1, you visit room 0, The total times you have been in room 0 is 2, which is even.
      On the next day you will visit room (0 + 1) mod 2 = 1
    - On day 2, you visit room 1. This is the first day where you have been in all the rooms.
    
    Example 2:
    
    >>> firstDayBeenInAllRooms(nextVisit = [0,0,2])
    >>> 6
    Explanation:
    Your room visiting order for each day is: [0,0,1,0,0,1,2,...].
    Day 6 is the first day where you have been in all the rooms.
    
    Example 3:
    
    >>> firstDayBeenInAllRooms(nextVisit = [0,1,2,0])
    >>> 6
    Explanation:
    Your room visiting order for each day is: [0,0,1,1,2,2,3,...].
    Day 6 is the first day where you have been in all the rooms.
    """