ShwStone/humaneval-leetcode huggingface dataset:
def distanceLimitedPathsExist(n: int, edgeList: List[List[int]], queries: List[List[int]]) -> List[bool]:
    """
    An undirected graph of n nodes is defined by edgeList, where edgeList[i] = [ui, vi, disi] denotes an edge between nodes ui and vi with distance disi. Note that there may be multiple edges between two nodes.
    Given an array queries, where queries[j] = [pj, qj, limitj], your task is to determine for each queries[j] whether there is a path between pj and qj such that each edge on the path has a distance strictly less than limitj .
    Return a boolean array answer, where answer.length == queries.length and the jth value of answer is true if there is a path for queries[j] is true, and false otherwise.
    
    Example 1:
    
    
    >>> distanceLimitedPathsExist(n = 3, edgeList = [[0,1,2],[1,2,4],[2,0,8],[1,0,16]], queries = [[0,1,2],[0,2,5]])
    >>> [false,true]
    Explanation: The above figure shows the given graph. Note that there are two overlapping edges between 0 and 1 with distances 2 and 16.
    For the first query, between 0 and 1 there is no path where each distance is less than 2, thus we return false for this query.
    For the second query, there is a path (0 -> 1 -> 2) of two edges with distances less than 5, thus we return true for this query.
    
    Example 2:
    
    
    >>> distanceLimitedPathsExist(n = 5, edgeList = [[0,1,10],[1,2,5],[2,3,9],[3,4,13]], queries = [[0,4,14],[1,4,13]])
    >>> [true,false]
    Explanation: The above figure shows the given graph.
    """
def countDistinct(s: str) -> int:
    """
    Given a string s, return the number of distinct substrings of s.
    A substring of a string is obtained by deleting any number of characters (possibly zero) from the front of the string and any number (possibly zero) from the back of the string.
    
    Example 1:
    
    >>> countDistinct(s = "aabbaba")
    >>> 21
    Explanation: The set of distinct strings is ["a","b","aa","bb","ab","ba","aab","abb","bab","bba","aba","aabb","abba","bbab","baba","aabba","abbab","bbaba","aabbab","abbaba","aabbaba"]
    
    Example 2:
    
    >>> countDistinct(s = "abcdefg")
    >>> 28
    """
def countStudents(students: List[int], sandwiches: List[int]) -> int:
    """
    The school cafeteria offers circular and square sandwiches at lunch break, referred to by numbers 0 and 1 respectively. All students stand in a queue. Each student either prefers square or circular sandwiches.
    The number of sandwiches in the cafeteria is equal to the number of students. The sandwiches are placed in a stack. At each step:
    
    If the student at the front of the queue prefers the sandwich on the top of the stack, they will take it and leave the queue.
    Otherwise, they will leave it and go to the queue's end.
    
    This continues until none of the queue students want to take the top sandwich and are thus unable to eat.
    You are given two integer arrays students and sandwiches where sandwiches[i] is the type of the i​​​​​​th sandwich in the stack (i = 0 is the top of the stack) and students[j] is the preference of the j​​​​​​th student in the initial queue (j = 0 is the front of the queue). Return the number of students that are unable to eat.
    
    Example 1:
    
    >>> countStudents(students = [1,1,0,0], sandwiches = [0,1,0,1])
    >>> 0
    Explanation:
    - Front student leaves the top sandwich and returns to the end of the line making students = [1,0,0,1].
    - Front student leaves the top sandwich and returns to the end of the line making students = [0,0,1,1].
    - Front student takes the top sandwich and leaves the line making students = [0,1,1] and sandwiches = [1,0,1].
    - Front student leaves the top sandwich and returns to the end of the line making students = [1,1,0].
    - Front student takes the top sandwich and leaves the line making students = [1,0] and sandwiches = [0,1].
    - Front student leaves the top sandwich and returns to the end of the line making students = [0,1].
    - Front student takes the top sandwich and leaves the line making students = [1] and sandwiches = [1].
    - Front student takes the top sandwich and leaves the line making students = [] and sandwiches = [].
    Hence all students are able to eat.
    
    Example 2:
    
    >>> countStudents(students = [1,1,1,0,0,1], sandwiches = [1,0,0,0,1,1])
    >>> 3
    """
def averageWaitingTime(customers: List[List[int]]) -> float:
    """
    There is a restaurant with a single chef. You are given an array customers, where customers[i] = [arrivali, timei]:
    
    arrivali is the arrival time of the ith customer. The arrival times are sorted in non-decreasing order.
    timei is the time needed to prepare the order of the ith customer.
    
    When a customer arrives, he gives the chef his order, and the chef starts preparing it once he is idle. The customer waits till the chef finishes preparing his order. The chef does not prepare food for more than one customer at a time. The chef prepares food for customers in the order they were given in the input.
    Return the average waiting time of all customers. Solutions within 10-5 from the actual answer are considered accepted.
    
    Example 1:
    
    >>> averageWaitingTime(customers = [[1,2],[2,5],[4,3]])
    >>> 5.00000
    Explanation:
    1) The first customer arrives at time 1, the chef takes his order and starts preparing it immediately at time 1, and finishes at time 3, so the waiting time of the first customer is 3 - 1 = 2.
    2) The second customer arrives at time 2, the chef takes his order and starts preparing it at time 3, and finishes at time 8, so the waiting time of the second customer is 8 - 2 = 6.
    3) The third customer arrives at time 4, the chef takes his order and starts preparing it at time 8, and finishes at time 11, so the waiting time of the third customer is 11 - 4 = 7.
    So the average waiting time = (2 + 6 + 7) / 3 = 5.
    
    Example 2:
    
    >>> averageWaitingTime(customers = [[5,2],[5,4],[10,3],[20,1]])
    >>> 3.25000
    Explanation:
    1) The first customer arrives at time 5, the chef takes his order and starts preparing it immediately at time 5, and finishes at time 7, so the waiting time of the first customer is 7 - 5 = 2.
    2) The second customer arrives at time 5, the chef takes his order and starts preparing it at time 7, and finishes at time 11, so the waiting time of the second customer is 11 - 5 = 6.
    3) The third customer arrives at time 10, the chef takes his order and starts preparing it at time 11, and finishes at time 14, so the waiting time of the third customer is 14 - 10 = 4.
    4) The fourth customer arrives at time 20, the chef takes his order and starts preparing it immediately at time 20, and finishes at time 21, so the waiting time of the fourth customer is 21 - 20 = 1.
    So the average waiting time = (2 + 6 + 4 + 1) / 4 = 3.25.
    """
def maximumBinaryString(binary: str) -> str:
    """
    You are given a binary string binary consisting of only 0's or 1's. You can apply each of the following operations any number of times:
    
    Operation 1: If the number contains the substring "00", you can replace it with "10".
    
    
    For example, "00010" -> "10010"
    
    
    Operation 2: If the number contains the substring "10", you can replace it with "01".
    
    For example, "00010" -> "00001"
    
    
    
    Return the maximum binary string you can obtain after any number of operations. Binary string x is greater than binary string y if x's decimal representation is greater than y's decimal representation.
    
    Example 1:
    
    >>> maximumBinaryString(binary = "000110")
    >>> "111011"
    Explanation: A valid transformation sequence can be:
    "000110" -> "000101"
    "000101" -> "100101"
    "100101" -> "110101"
    "110101" -> "110011"
    "110011" -> "111011"
    
    Example 2:
    
    >>> maximumBinaryString(binary = "01")
    >>> "01"
    Explanation: "01" cannot be transformed any further.
    """
def minMoves(nums: List[int], k: int) -> int:
    """
    You are given an integer array, nums, and an integer k. nums comprises of only 0's and 1's. In one move, you can choose two adjacent indices and swap their values.
    Return the minimum number of moves required so that nums has k consecutive 1's.
    
    Example 1:
    
    >>> minMoves(nums = [1,0,0,1,0,1], k = 2)
    >>> 1
    Explanation: In 1 move, nums could be [1,0,0,0,1,1] and have 2 consecutive 1's.
    
    Example 2:
    
    >>> minMoves(nums = [1,0,0,0,0,0,1,1], k = 3)
    >>> 5
    Explanation: In 5 moves, the leftmost 1 can be shifted right until nums = [0,0,0,0,0,1,1,1].
    
    Example 3:
    
    >>> minMoves(nums = [1,1,0,1], k = 2)
    >>> 0
    Explanation: nums already has 2 consecutive 1's.
    """
def halvesAreAlike(s: str) -> bool:
    """
    You are given a string s of even length. Split this string into two halves of equal lengths, and let a be the first half and b be the second half.
    Two strings are alike if they have the same number of vowels ('a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'). Notice that s contains uppercase and lowercase letters.
    Return true if a and b are alike. Otherwise, return false.
    
    Example 1:
    
    >>> halvesAreAlike(s = "book")
    >>> true
    Explanation: a = "bo" and b = "ok". a has 1 vowel and b has 1 vowel. Therefore, they are alike.
    
    Example 2:
    
    >>> halvesAreAlike(s = "textbook")
    >>> false
    Explanation: a = "text" and b = "book". a has 1 vowel whereas b has 2. Therefore, they are not alike.
    Notice that the vowel o is counted twice.
    """
def eatenApples(apples: List[int], days: List[int]) -> int:
    """
    There is a special kind of apple tree that grows apples every day for n days. On the ith day, the tree grows apples[i] apples that will rot after days[i] days, that is on day i + days[i] the apples will be rotten and cannot be eaten. On some days, the apple tree does not grow any apples, which are denoted by apples[i] == 0 and days[i] == 0.
    You decided to eat at most one apple a day (to keep the doctors away). Note that you can keep eating after the first n days.
    Given two integer arrays days and apples of length n, return the maximum number of apples you can eat.
    
    Example 1:
    
    >>> eatenApples(apples = [1,2,3,5,2], days = [3,2,1,4,2])
    >>> 7
    Explanation: You can eat 7 apples:
    - On the first day, you eat an apple that grew on the first day.
    - On the second day, you eat an apple that grew on the second day.
    - On the third day, you eat an apple that grew on the second day. After this day, the apples that grew on the third day rot.
    - On the fourth to the seventh days, you eat apples that grew on the fourth day.
    
    Example 2:
    
    >>> eatenApples(apples = [3,0,0,0,0,2], days = [3,0,0,0,0,2])
    >>> 5
    Explanation: You can eat 5 apples:
    - On the first to the third day you eat apples that grew on the first day.
    - Do nothing on the fouth and fifth days.
    - On the sixth and seventh days you eat apples that grew on the sixth day.
    """
def findBall(grid: List[List[int]]) -> List[int]:
    """
    You have a 2-D grid of size m x n representing a box, and you have n balls. The box is open on the top and bottom sides.
    Each cell in the box has a diagonal board spanning two corners of the cell that can redirect a ball to the right or to the left.
    
    A board that redirects the ball to the right spans the top-left corner to the bottom-right corner and is represented in the grid as 1.
    A board that redirects the ball to the left spans the top-right corner to the bottom-left corner and is represented in the grid as -1.
    
    We drop one ball at the top of each column of the box. Each ball can get stuck in the box or fall out of the bottom. A ball gets stuck if it hits a "V" shaped pattern between two boards or if a board redirects the ball into either wall of the box.
    Return an array answer of size n where answer[i] is the column that the ball falls out of at the bottom after dropping the ball from the ith column at the top, or -1 if the ball gets stuck in the box.
    
    Example 1:
    
    
    >>> findBall(grid = [[1,1,1,-1,-1],[1,1,1,-1,-1],[-1,-1,-1,1,1],[1,1,1,1,-1],[-1,-1,-1,-1,-1]])
    >>> [1,-1,-1,-1,-1]
    Explanation: This example is shown in the photo.
    Ball b0 is dropped at column 0 and falls out of the box at column 1.
    Ball b1 is dropped at column 1 and will get stuck in the box between column 2 and 3 and row 1.
    Ball b2 is dropped at column 2 and will get stuck on the box between column 2 and 3 and row 0.
    Ball b3 is dropped at column 3 and will get stuck on the box between column 2 and 3 and row 0.
    Ball b4 is dropped at column 4 and will get stuck on the box between column 2 and 3 and row 1.
    
    Example 2:
    
    >>> findBall(grid = [[-1]])
    >>> [-1]
    Explanation: The ball gets stuck against the left wall.
    
    Example 3:
    
    >>> findBall(grid = [[1,1,1,1,1,1],[-1,-1,-1,-1,-1,-1],[1,1,1,1,1,1],[-1,-1,-1,-1,-1,-1]])
    >>> [0,1,2,3,4,-1]
    """
def maximizeXor(nums: List[int], queries: List[List[int]]) -> List[int]:
    """
    You are given an array nums consisting of non-negative integers. You are also given a queries array, where queries[i] = [xi, mi].
    The answer to the ith query is the maximum bitwise XOR value of xi and any element of nums that does not exceed mi. In other words, the answer is max(nums[j] XOR xi) for all j such that nums[j] <= mi. If all elements in nums are larger than mi, then the answer is -1.
    Return an integer array answer where answer.length == queries.length and answer[i] is the answer to the ith query.
    
    Example 1:
    
    >>> maximizeXor(nums = [0,1,2,3,4], queries = [[3,1],[1,3],[5,6]])
    >>> [3,3,7]
    Explanation:
    1) 0 and 1 are the only two integers not greater than 1. 0 XOR 3 = 3 and 1 XOR 3 = 2. The larger of the two is 3.
    2) 1 XOR 2 = 3.
    3) 5 XOR 2 = 7.
    
    Example 2:
    
    >>> maximizeXor(nums = [5,2,4,6,6,3], queries = [[12,4],[8,1],[6,3]])
    >>> [15,-1,5]
    """
def largestSubarray(nums: List[int], k: int) -> List[int]:
    """
    An array A is larger than some array B if for the first index i where A[i] != B[i], A[i] > B[i].
    For example, consider 0-indexing:
    
    [1,3,2,4] > [1,2,2,4], since at index 1, 3 > 2.
    [1,4,4,4] < [2,1,1,1], since at index 0, 1 < 2.
    
    A subarray is a contiguous subsequence of the array.
    Given an integer array nums of distinct integers, return the largest subarray of nums of length k.
    
    Example 1:
    
    >>> largestSubarray(nums = [1,4,5,2,3], k = 3)
    >>> [5,2,3]
    Explanation: The subarrays of size 3 are: [1,4,5], [4,5,2], and [5,2,3].
    Of these, [5,2,3] is the largest.
    Example 2:
    
    >>> largestSubarray(nums = [1,4,5,2,3], k = 4)
    >>> [4,5,2,3]
    Explanation: The subarrays of size 4 are: [1,4,5,2], and [4,5,2,3].
    Of these, [4,5,2,3] is the largest.
    Example 3:
    
    >>> largestSubarray(nums = [1,4,5,2,3], k = 1)
    >>> [5]
    """
def maximumUnits(boxTypes: List[List[int]], truckSize: int) -> int:
    """
    You are assigned to put some amount of boxes onto one truck. You are given a 2D array boxTypes, where boxTypes[i] = [numberOfBoxesi, numberOfUnitsPerBoxi]:
    
    numberOfBoxesi is the number of boxes of type i.
    numberOfUnitsPerBoxi is the number of units in each box of the type i.
    
    You are also given an integer truckSize, which is the maximum number of boxes that can be put on the truck. You can choose any boxes to put on the truck as long as the number of boxes does not exceed truckSize.
    Return the maximum total number of units that can be put on the truck.
    
    Example 1:
    
    >>> maximumUnits(boxTypes = [[1,3],[2,2],[3,1]], truckSize = 4)
    >>> 8
    Explanation: There are:
    - 1 box of the first type that contains 3 units.
    - 2 boxes of the second type that contain 2 units each.
    - 3 boxes of the third type that contain 1 unit each.
    You can take all the boxes of the first and second types, and one box of the third type.
    The total number of units will be = (1 * 3) + (2 * 2) + (1 * 1) = 8.
    
    Example 2:
    
    >>> maximumUnits(boxTypes = [[5,10],[2,5],[4,7],[3,9]], truckSize = 10)
    >>> 91
    """
def countPairs(deliciousness: List[int]) -> int:
    """
    A good meal is a meal that contains exactly two different food items with a sum of deliciousness equal to a power of two.
    You can pick any two different foods to make a good meal.
    Given an array of integers deliciousness where deliciousness[i] is the deliciousness of the i​​​​​​th​​​​​​​​ item of food, return the number of different good meals you can make from this list modulo 109 + 7.
    Note that items with different indices are considered different even if they have the same deliciousness value.
    
    Example 1:
    
    >>> countPairs(deliciousness = [1,3,5,7,9])
    >>> 4
    Explanation: The good meals are (1,3), (1,7), (3,5) and, (7,9).
    Their respective sums are 4, 8, 8, and 16, all of which are powers of 2.
    
    Example 2:
    
    >>> countPairs(deliciousness = [1,1,1,3,3,3,7])
    >>> 15
    Explanation: The good meals are (1,1) with 3 ways, (1,3) with 9 ways, and (1,7) with 3 ways.
    """
def waysToSplit(nums: List[int]) -> int:
    """
    A split of an integer array is good if:
    
    The array is split into three non-empty contiguous subarrays - named left, mid, right respectively from left to right.
    The sum of the elements in left is less than or equal to the sum of the elements in mid, and the sum of the elements in mid is less than or equal to the sum of the elements in right.
    
    Given nums, an array of non-negative integers, return the number of good ways to split nums. As the number may be too large, return it modulo 109 + 7.
    
    Example 1:
    
    >>> waysToSplit(nums = [1,1,1])
    >>> 1
    Explanation: The only good way to split nums is [1] [1] [1].
    Example 2:
    
    >>> waysToSplit(nums = [1,2,2,2,5,0])
    >>> 3
    Explanation: There are three good ways of splitting nums:
    [1] [2] [2,2,5,0]
    [1] [2,2] [2,5,0]
    [1,2] [2,2] [5,0]
    
    Example 3:
    
    >>> waysToSplit(nums = [3,2,1])
    >>> 0
    Explanation: There is no good way to split nums.
    """
def minOperations(target: List[int], arr: List[int]) -> int:
    """
    You are given an array target that consists of distinct integers and another integer array arr that can have duplicates.
    In one operation, you can insert any integer at any position in arr. For example, if arr = [1,4,1,2], you can add 3 in the middle and make it [1,4,3,1,2]. Note that you can insert the integer at the very beginning or end of the array.
    Return the minimum number of operations needed to make target a subsequence of arr.
    A subsequence of an array is a new array generated from the original array by deleting some elements (possibly none) without changing the remaining elements' relative order. For example, [2,7,4] is a subsequence of [4,2,3,7,2,1,4] (the underlined elements), while [2,4,2] is not.
    
    Example 1:
    
    >>> minOperations(target = [5,1,3], arr = [9,4,2,3,4])
    >>> 2
    Explanation: You can add 5 and 1 in such a way that makes arr = [5,9,4,1,2,3,4], then target will be a subsequence of arr.
    
    Example 2:
    
    >>> minOperations(target = [6,4,8,1,3,2], arr = [4,7,6,2,3,8,6,1])
    >>> 3
    """
def solve(nums: List[int], queries: List[List[int]]) -> List[int]:
    """
    You are given a 0-indexed integer array nums consisting of n non-negative integers.
    You are also given an array queries, where queries[i] = [xi, yi]. The answer to the ith query is the sum of all nums[j] where xi <= j < n and (j - xi) is divisible by yi.
    Return an array answer where answer.length == queries.length and answer[i] is the answer to the ith query modulo 109 + 7.
    
    Example 1:
    
    >>> solve(nums = [0,1,2,3,4,5,6,7], queries = [[0,3],[5,1],[4,2]])
    >>> [9,18,10]
    Explanation: The answers of the queries are as follows:
    1) The j indices that satisfy this query are 0, 3, and 6. nums[0] + nums[3] + nums[6] = 9
    2) The j indices that satisfy this query are 5, 6, and 7. nums[5] + nums[6] + nums[7] = 18
    3) The j indices that satisfy this query are 4 and 6. nums[4] + nums[6] = 10
    
    Example 2:
    
    >>> solve(nums = [100,200,101,201,102,202,103,203], queries = [[0,7]])
    >>> [303]
    """
def totalMoney(n: int) -> int:
    """
    Hercy wants to save money for his first car. He puts money in the Leetcode bank every day.
    He starts by putting in $1 on Monday, the first day. Every day from Tuesday to Sunday, he will put in $1 more than the day before. On every subsequent Monday, he will put in $1 more than the previous Monday.
    Given n, return the total amount of money he will have in the Leetcode bank at the end of the nth day.
    
    Example 1:
    
    >>> totalMoney(n = 4)
    >>> 10
    Explanation: After the 4th day, the total is 1 + 2 + 3 + 4 = 10.
    
    Example 2:
    
    >>> totalMoney(n = 10)
    >>> 37
    Explanation: After the 10th day, the total is (1 + 2 + 3 + 4 + 5 + 6 + 7) + (2 + 3 + 4) = 37. Notice that on the 2nd Monday, Hercy only puts in $2.
    
    Example 3:
    
    >>> totalMoney(n = 20)
    >>> 96
    Explanation: After the 20th day, the total is (1 + 2 + 3 + 4 + 5 + 6 + 7) + (2 + 3 + 4 + 5 + 6 + 7 + 8) + (3 + 4 + 5 + 6 + 7 + 8) = 96.
    """
def maximumGain(s: str, x: int, y: int) -> int:
    """
    You are given a string s and two integers x and y. You can perform two types of operations any number of times.
    
    Remove substring "ab" and gain x points.
    
    
    For example, when removing "ab" from "cabxbae" it becomes "cxbae".
    
    
    Remove substring "ba" and gain y points.
    
    For example, when removing "ba" from "cabxbae" it becomes "cabxe".
    
    
    
    Return the maximum points you can gain after applying the above operations on s.
    
    Example 1:
    
    >>> maximumGain(s = "cdbcbbaaabab", x = 4, y = 5)
    >>> 19
    Explanation:
    - Remove the "ba" underlined in "cdbcbbaaabab". Now, s = "cdbcbbaaab" and 5 points are added to the score.
    - Remove the "ab" underlined in "cdbcbbaaab". Now, s = "cdbcbbaa" and 4 points are added to the score.
    - Remove the "ba" underlined in "cdbcbbaa". Now, s = "cdbcba" and 5 points are added to the score.
    - Remove the "ba" underlined in "cdbcba". Now, s = "cdbc" and 5 points are added to the score.
    Total score = 5 + 4 + 5 + 5 = 19.
    Example 2:
    
    >>> maximumGain(s = "aabbaaxybbaabb", x = 5, y = 4)
    >>> 20
    """
def constructDistancedSequence(n: int) -> List[int]:
    """
    Given an integer n, find a sequence with elements in the range [1, n] that satisfies all of the following:
    
    The integer 1 occurs once in the sequence.
    Each integer between 2 and n occurs twice in the sequence.
    For every integer i between 2 and n, the distance between the two occurrences of i is exactly i.
    
    The distance between two numbers on the sequence, a[i] and a[j], is the absolute difference of their indices, |j - i|.
    Return the lexicographically largest sequence. It is guaranteed that under the given constraints, there is always a solution.
    A sequence a is lexicographically larger than a sequence b (of the same length) if in the first position where a and b differ, sequence a has a number greater than the corresponding number in b. For example, [0,1,9,0] is lexicographically larger than [0,1,5,6] because the first position they differ is at the third number, and 9 is greater than 5.
    
    Example 1:
    
    >>> constructDistancedSequence(n = 3)
    >>> [3,1,2,3,2]
    Explanation: [2,3,2,1,3] is also a valid sequence, but [3,1,2,3,2] is the lexicographically largest valid sequence.
    
    Example 2:
    
    >>> constructDistancedSequence(n = 5)
    >>> [5,3,1,4,3,5,2,4,2]
    """