ShwStone/humaneval-leetcode huggingface dataset:
def minAbsoluteSumDiff(nums1: List[int], nums2: List[int]) -> int:
    """
    You are given two positive integer arrays nums1 and nums2, both of length n.
    The absolute sum difference of arrays nums1 and nums2 is defined as the sum of |nums1[i] - nums2[i]| for each 0 <= i < n (0-indexed).
    You can replace at most one element of nums1 with any other element in nums1 to minimize the absolute sum difference.
    Return the minimum absolute sum difference after replacing at most one element in the array nums1. Since the answer may be large, return it modulo 109 + 7.
    |x| is defined as:
    
    x if x >= 0, or
    -x if x < 0.
    
    
    Example 1:
    
    >>> minAbsoluteSumDiff(nums1 = [1,7,5], nums2 = [2,3,5])
    >>> 3
    Explanation: There are two possible optimal solutions:
    - Replace the second element with the first: [1,7,5] => [1,1,5], or
    - Replace the second element with the third: [1,7,5] => [1,5,5].
    Both will yield an absolute sum difference of |1-2| + (|1-3| or |5-3|) + |5-5| = 3.
    
    Example 2:
    
    >>> minAbsoluteSumDiff(nums1 = [2,4,6,8,10], nums2 = [2,4,6,8,10])
    >>> 0
    Explanation: nums1 is equal to nums2 so no replacement is needed. This will result in an
    absolute sum difference of 0.
    
    Example 3:
    
    >>> minAbsoluteSumDiff(nums1 = [1,10,4,4,2,7], nums2 = [9,3,5,1,7,4])
    >>> 20
    Explanation: Replace the first element with the second: [1,10,4,4,2,7] => [10,10,4,4,2,7].
    This yields an absolute sum difference of |10-9| + |10-3| + |4-5| + |4-1| + |2-7| + |7-4| = 20
    """
def countDifferentSubsequenceGCDs(nums: List[int]) -> int:
    """
    You are given an array nums that consists of positive integers.
    The GCD of a sequence of numbers is defined as the greatest integer that divides all the numbers in the sequence evenly.
    
    For example, the GCD of the sequence [4,6,16] is 2.
    
    A subsequence of an array is a sequence that can be formed by removing some elements (possibly none) of the array.
    
    For example, [2,5,10] is a subsequence of [1,2,1,2,4,1,5,10].
    
    Return the number of different GCDs among all non-empty subsequences of nums.
    
    Example 1:
    
    
    >>> countDifferentSubsequenceGCDs(nums = [6,10,3])
    >>> 5
    Explanation: The figure shows all the non-empty subsequences and their GCDs.
    The different GCDs are 6, 10, 3, 2, and 1.
    
    Example 2:
    
    >>> countDifferentSubsequenceGCDs(nums = [5,15,40,5,6])
    >>> 7
    """
def maximumInvitations(grid: List[List[int]]) -> int:
    """
    There are m boys and n girls in a class attending an upcoming party.
    You are given an m x n integer matrix grid, where grid[i][j] equals 0 or 1. If grid[i][j] == 1, then that means the ith boy can invite the jth girl to the party. A boy can invite at most one girl, and a girl can accept at most one invitation from a boy.
    Return the maximum possible number of accepted invitations.
    
    Example 1:
    
                   [1,0,1],
                   [0,0,1]]
    >>> maximumInvitations(grid = [[1,1,1],)
    >>> 3
    Explanation: The invitations are sent as follows:
    - The 1st boy invites the 2nd girl.
    - The 2nd boy invites the 1st girl.
    - The 3rd boy invites the 3rd girl.
    Example 2:
    
                   [1,0,0,0],
                   [0,0,1,0],
                   [1,1,1,0]]
    >>> maximumInvitations(grid = [[1,0,1,0],)
    >>> 3
    Explanation: The invitations are sent as follows:
    -The 1st boy invites the 3rd girl.
    -The 2nd boy invites the 1st girl.
    -The 3rd boy invites no one.
    -The 4th boy invites the 2nd girl.
    """
def arraySign(nums: List[int]) -> int:
    """
    Implement a function signFunc(x) that returns:
    
    1 if x is positive.
    -1 if x is negative.
    0 if x is equal to 0.
    
    You are given an integer array nums. Let product be the product of all values in the array nums.
    Return signFunc(product).
    
    Example 1:
    
    >>> arraySign(nums = [-1,-2,-3,-4,3,2,1])
    >>> 1
    Explanation: The product of all values in the array is 144, and signFunc(144) = 1
    
    Example 2:
    
    >>> arraySign(nums = [1,5,0,2,-3])
    >>> 0
    Explanation: The product of all values in the array is 0, and signFunc(0) = 0
    
    Example 3:
    
    >>> arraySign(nums = [-1,1,-1,1,-1])
    >>> -1
    Explanation: The product of all values in the array is -1, and signFunc(-1) = -1
    """
def findTheWinner(n: int, k: int) -> int:
    """
    There are n friends that are playing a game. The friends are sitting in a circle and are numbered from 1 to n in clockwise order. More formally, moving clockwise from the ith friend brings you to the (i+1)th friend for 1 <= i < n, and moving clockwise from the nth friend brings you to the 1st friend.
    The rules of the game are as follows:
    
    Start at the 1st friend.
    Count the next k friends in the clockwise direction including the friend you started at. The counting wraps around the circle and may count some friends more than once.
    The last friend you counted leaves the circle and loses the game.
    If there is still more than one friend in the circle, go back to step 2 starting from the friend immediately clockwise of the friend who just lost and repeat.
    Else, the last friend in the circle wins the game.
    
    Given the number of friends, n, and an integer k, return the winner of the game.
    
    Example 1:
    
    
    >>> findTheWinner(n = 5, k = 2)
    >>> 3
    Explanation: Here are the steps of the game:
    1) Start at friend 1.
    2) Count 2 friends clockwise, which are friends 1 and 2.
    3) Friend 2 leaves the circle. Next start is friend 3.
    4) Count 2 friends clockwise, which are friends 3 and 4.
    5) Friend 4 leaves the circle. Next start is friend 5.
    6) Count 2 friends clockwise, which are friends 5 and 1.
    7) Friend 1 leaves the circle. Next start is friend 3.
    8) Count 2 friends clockwise, which are friends 3 and 5.
    9) Friend 5 leaves the circle. Only friend 3 is left, so they are the winner.
    Example 2:
    
    >>> findTheWinner(n = 6, k = 5)
    >>> 1
    Explanation: The friends leave in this order: 5, 4, 6, 2, 3. The winner is friend 1.
    """
def minSideJumps(obstacles: List[int]) -> int:
    """
    There is a 3 lane road of length n that consists of n + 1 points labeled from 0 to n. A frog starts at point 0 in the second lane and wants to jump to point n. However, there could be obstacles along the way.
    You are given an array obstacles of length n + 1 where each obstacles[i] (ranging from 0 to 3) describes an obstacle on the lane obstacles[i] at point i. If obstacles[i] == 0, there are no obstacles at point i. There will be at most one obstacle in the 3 lanes at each point.
    
    For example, if obstacles[2] == 1, then there is an obstacle on lane 1 at point 2.
    
    The frog can only travel from point i to point i + 1 on the same lane if there is not an obstacle on the lane at point i + 1. To avoid obstacles, the frog can also perform a side jump to jump to another lane (even if they are not adjacent) at the same point if there is no obstacle on the new lane.
    
    For example, the frog can jump from lane 3 at point 3 to lane 1 at point 3.
    
    Return the minimum number of side jumps the frog needs to reach any lane at point n starting from lane 2 at point 0.
    Note: There will be no obstacles on points 0 and n.
    
    Example 1:
    
    
    >>> minSideJumps(obstacles = [0,1,2,3,0])
    >>> 2
    Explanation: The optimal solution is shown by the arrows above. There are 2 side jumps (red arrows).
    Note that the frog can jump over obstacles only when making side jumps (as shown at point 2).
    
    Example 2:
    
    
    >>> minSideJumps(obstacles = [0,1,1,3,3,0])
    >>> 0
    Explanation: There are no obstacles on lane 2. No side jumps are required.
    
    Example 3:
    
    
    >>> minSideJumps(obstacles = [0,2,1,0,3,0])
    >>> 2
    Explanation: The optimal solution is shown by the arrows above. There are 2 side jumps.
    """
def badSensor(sensor1: List[int], sensor2: List[int]) -> int:
    """
    An experiment is being conducted in a lab. To ensure accuracy, there are two sensors collecting data simultaneously. You are given two arrays sensor1 and sensor2, where sensor1[i] and sensor2[i] are the ith data points collected by the two sensors.
    However, this type of sensor has a chance of being defective, which causes exactly one data point to be dropped. After the data is dropped, all the data points to the right of the dropped data are shifted one place to the left, and the last data point is replaced with some random value. It is guaranteed that this random value will not be equal to the dropped value.
    
    For example, if the correct data is [1,2,3,4,5] and 3 is dropped, the sensor could return [1,2,4,5,7] (the last position can be any value, not just 7).
    
    We know that there is a defect in at most one of the sensors. Return the sensor number (1 or 2) with the defect. If there is no defect in either sensor or if it is impossible to determine the defective sensor, return -1.
    
    Example 1:
    
    >>> badSensor(sensor1 = [2,3,4,5], sensor2 = [2,1,3,4])
    >>> 1
    Explanation: Sensor 2 has the correct values.
    The second data point from sensor 2 is dropped, and the last value of sensor 1 is replaced by a 5.
    
    Example 2:
    
    >>> badSensor(sensor1 = [2,2,2,2,2], sensor2 = [2,2,2,2,5])
    >>> -1
    Explanation: It is impossible to determine which sensor has a defect.
    Dropping the last value for either sensor could produce the output for the other sensor.
    
    Example 3:
    
    >>> badSensor(sensor1 = [2,3,2,2,3,2], sensor2 = [2,3,2,3,2,7])
    >>> 2
    Explanation: Sensor 1 has the correct values.
    The fourth data point from sensor 1 is dropped, and the last value of sensor 1 is replaced by a 7.
    """
def minOperations(nums: List[int]) -> int:
    """
    You are given an integer array nums (0-indexed). In one operation, you can choose an element of the array and increment it by 1.\r
    \r
    \r
    	For example, if nums = [1,2,3], you can choose to increment nums[1] to make nums = [1,3,3].\r
    \r
    \r
    Return the minimum number of operations needed to make nums strictly increasing.\r
    \r
    An array nums is strictly increasing if nums[i] < nums[i+1] for all 0 <= i < nums.length - 1. An array of length 1 is trivially strictly increasing.\r
    \r
     \r
    Example 1:\r
    \r
    \r
    >>> minOperations(nums = [1,1,1]\r)
    >>> 3\r
    Explanation: You can do the following operations:\r
    1) Increment nums[2], so nums becomes [1,1,2].\r
    2) Increment nums[1], so nums becomes [1,2,2].\r
    3) Increment nums[2], so nums becomes [1,2,3].\r
    \r
    \r
    Example 2:\r
    \r
    \r
    >>> minOperations(nums = [1,5,2,4,1]\r)
    >>> 14\r
    \r
    \r
    Example 3:\r
    \r
    \r
    >>> minOperations(nums = [8]\r)
    >>> 0\r
    \r
    \r
     \r
    """
def countPoints(points: List[List[int]], queries: List[List[int]]) -> List[int]:
    """
    You are given an array points where points[i] = [xi, yi] is the coordinates of the ith point on a 2D plane. Multiple points can have the same coordinates.
    You are also given an array queries where queries[j] = [xj, yj, rj] describes a circle centered at (xj, yj) with a radius of rj.
    For each query queries[j], compute the number of points inside the jth circle. Points on the border of the circle are considered inside.
    Return an array answer, where answer[j] is the answer to the jth query.
    
    Example 1:
    
    
    >>> countPoints(points = [[1,3],[3,3],[5,3],[2,2]], queries = [[2,3,1],[4,3,1],[1,1,2]])
    >>> [3,2,2]
    Explanation: The points and circles are shown above.
    queries[0] is the green circle, queries[1] is the red circle, and queries[2] is the blue circle.
    
    Example 2:
    
    
    >>> countPoints(points = [[1,1],[2,2],[3,3],[4,4],[5,5]], queries = [[1,2,2],[2,2,2],[4,3,2],[4,3,3]])
    >>> [2,3,2,4]
    Explanation: The points and circles are shown above.
    queries[0] is green, queries[1] is red, queries[2] is blue, and queries[3] is purple.
    """
def getMaximumXor(nums: List[int], maximumBit: int) -> List[int]:
    """
    You are given a sorted array nums of n non-negative integers and an integer maximumBit. You want to perform the following query n times:
    
    Find a non-negative integer k < 2maximumBit such that nums[0] XOR nums[1] XOR ... XOR nums[nums.length-1] XOR k is maximized. k is the answer to the ith query.
    Remove the last element from the current array nums.
    
    Return an array answer, where answer[i] is the answer to the ith query.
    
    Example 1:
    
    >>> getMaximumXor(nums = [0,1,1,3], maximumBit = 2)
    >>> [0,3,2,3]
    Explanation: The queries are answered as follows:
    1st query: nums = [0,1,1,3], k = 0 since 0 XOR 1 XOR 1 XOR 3 XOR 0 = 3.
    2nd query: nums = [0,1,1], k = 3 since 0 XOR 1 XOR 1 XOR 3 = 3.
    3rd query: nums = [0,1], k = 2 since 0 XOR 1 XOR 2 = 3.
    4th query: nums = [0], k = 3 since 0 XOR 3 = 3.
    
    Example 2:
    
    >>> getMaximumXor(nums = [2,3,4,7], maximumBit = 3)
    >>> [5,2,6,5]
    Explanation: The queries are answered as follows:
    1st query: nums = [2,3,4,7], k = 5 since 2 XOR 3 XOR 4 XOR 7 XOR 5 = 7.
    2nd query: nums = [2,3,4], k = 2 since 2 XOR 3 XOR 4 XOR 2 = 7.
    3rd query: nums = [2,3], k = 6 since 2 XOR 3 XOR 6 = 7.
    4th query: nums = [2], k = 5 since 2 XOR 5 = 7.
    
    Example 3:
    
    >>> getMaximumXor(nums = [0,1,2,2,5,7], maximumBit = 3)
    >>> [4,3,6,4,6,7]
    """
def checkIfPangram(sentence: str) -> bool:
    """
    A pangram is a sentence where every letter of the English alphabet appears at least once.
    Given a string sentence containing only lowercase English letters, return true if sentence is a pangram, or false otherwise.
    
    Example 1:
    
    >>> checkIfPangram(sentence = "thequickbrownfoxjumpsoverthelazydog")
    >>> true
    Explanation: sentence contains at least one of every letter of the English alphabet.
    
    Example 2:
    
    >>> checkIfPangram(sentence = "leetcode")
    >>> false
    """
def maxIceCream(costs: List[int], coins: int) -> int:
    """
    It is a sweltering summer day, and a boy wants to buy some ice cream bars.
    At the store, there are n ice cream bars. You are given an array costs of length n, where costs[i] is the price of the ith ice cream bar in coins. The boy initially has coins coins to spend, and he wants to buy as many ice cream bars as possible.
    Note: The boy can buy the ice cream bars in any order.
    Return the maximum number of ice cream bars the boy can buy with coins coins.
    You must solve the problem by counting sort.
    
    Example 1:
    
    >>> maxIceCream(costs = [1,3,2,4,1], coins = 7)
    >>> 4
    Explanation: The boy can buy ice cream bars at indices 0,1,2,4 for a total price of 1 + 3 + 2 + 1 = 7.
    
    Example 2:
    
    >>> maxIceCream(costs = [10,6,8,7,7,8], coins = 5)
    >>> 0
    Explanation: The boy cannot afford any of the ice cream bars.
    
    Example 3:
    
    >>> maxIceCream(costs = [1,6,3,1,2,5], coins = 20)
    >>> 6
    Explanation: The boy can buy all the ice cream bars for a total price of 1 + 6 + 3 + 1 + 2 + 5 = 18.
    """
def getOrder(tasks: List[List[int]]) -> List[int]:
    """
    You are given n​​​​​​ tasks labeled from 0 to n - 1 represented by a 2D integer array tasks, where tasks[i] = [enqueueTimei, processingTimei] means that the i​​​​​​th​​​​ task will be available to process at enqueueTimei and will take processingTimei to finish processing.
    You have a single-threaded CPU that can process at most one task at a time and will act in the following way:
    
    If the CPU is idle and there are no available tasks to process, the CPU remains idle.
    If the CPU is idle and there are available tasks, the CPU will choose the one with the shortest processing time. If multiple tasks have the same shortest processing time, it will choose the task with the smallest index.
    Once a task is started, the CPU will process the entire task without stopping.
    The CPU can finish a task then start a new one instantly.
    
    Return the order in which the CPU will process the tasks.
    
    Example 1:
    
    >>> getOrder(tasks = [[1,2],[2,4],[3,2],[4,1]])
    >>> [0,2,3,1]
    Explanation: The events go as follows:
    - At time = 1, task 0 is available to process. Available tasks = {0}.
    - Also at time = 1, the idle CPU starts processing task 0. Available tasks = {}.
    - At time = 2, task 1 is available to process. Available tasks = {1}.
    - At time = 3, task 2 is available to process. Available tasks = {1, 2}.
    - Also at time = 3, the CPU finishes task 0 and starts processing task 2 as it is the shortest. Available tasks = {1}.
    - At time = 4, task 3 is available to process. Available tasks = {1, 3}.
    - At time = 5, the CPU finishes task 2 and starts processing task 3 as it is the shortest. Available tasks = {1}.
    - At time = 6, the CPU finishes task 3 and starts processing task 1. Available tasks = {}.
    - At time = 10, the CPU finishes task 1 and becomes idle.
    
    Example 2:
    
    >>> getOrder(tasks = [[7,10],[7,12],[7,5],[7,4],[7,2]])
    >>> [4,3,2,0,1]
    Explanation: The events go as follows:
    - At time = 7, all the tasks become available. Available tasks = {0,1,2,3,4}.
    - Also at time = 7, the idle CPU starts processing task 4. Available tasks = {0,1,2,3}.
    - At time = 9, the CPU finishes task 4 and starts processing task 3. Available tasks = {0,1,2}.
    - At time = 13, the CPU finishes task 3 and starts processing task 2. Available tasks = {0,1}.
    - At time = 18, the CPU finishes task 2 and starts processing task 0. Available tasks = {1}.
    - At time = 28, the CPU finishes task 0 and starts processing task 1. Available tasks = {}.
    - At time = 40, the CPU finishes task 1 and becomes idle.
    """
def getXORSum(arr1: List[int], arr2: List[int]) -> int:
    """
    The XOR sum of a list is the bitwise XOR of all its elements. If the list only contains one element, then its XOR sum will be equal to this element.
    
    For example, the XOR sum of [1,2,3,4] is equal to 1 XOR 2 XOR 3 XOR 4 = 4, and the XOR sum of [3] is equal to 3.
    
    You are given two 0-indexed arrays arr1 and arr2 that consist only of non-negative integers.
    Consider the list containing the result of arr1[i] AND arr2[j] (bitwise AND) for every (i, j) pair where 0 <= i < arr1.length and 0 <= j < arr2.length.
    Return the XOR sum of the aforementioned list.
    
    Example 1:
    
    >>> getXORSum(arr1 = [1,2,3], arr2 = [6,5])
    >>> 0
    Explanation: The list = [1 AND 6, 1 AND 5, 2 AND 6, 2 AND 5, 3 AND 6, 3 AND 5] = [0,1,2,0,2,1].
    The XOR sum = 0 XOR 1 XOR 2 XOR 0 XOR 2 XOR 1 = 0.
    
    Example 2:
    
    >>> getXORSum(arr1 = [12], arr2 = [4])
    >>> 4
    Explanation: The list = [12 AND 4] = [4]. The XOR sum = 4.
    """
# class ListNode:
#     def __init__(val=0, next=None):
#         self.val = val
#         self.next = next
class Solution:
    def deleteDuplicatesUnsorted(head: Optional[ListNode]) -> Optional[ListNode]:
    """
    Given the head of a linked list, find all the values that appear more than once in the list and delete the nodes that have any of those values.\r
    \r
    Return the linked list after the deletions.\r
    \r
     \r
    Example 1:\r
    \r
    \r
    >>> __init__(head = [1,2,3,2]\r)
    >>> [1,3]\r
    Explanation: 2 appears twice in the linked list, so all 2's should be deleted. After deleting all 2's, we are left with [1,3].\r
    \r
    \r
    Example 2:\r
    \r
    \r
    >>> __init__(head = [2,1,1,2]\r)
    >>> []\r
    Explanation: 2 and 1 both appear twice. All the elements should be deleted.\r
    \r
    \r
    Example 3:\r
    \r
    \r
    >>> __init__(head = [3,2,2,1,3,2,4]\r)
    >>> [1,4]\r
    Explanation: 3 appears twice and 2 appears three times. After deleting all 3's and 2's, we are left with [1,4].\r
    \r
    \r
     \r
    """
def sumBase(n: int, k: int) -> int:
    """
    Given an integer n (in base 10) and a base k, return the sum of the digits of n after converting n from base 10 to base k.
    After converting, each digit should be interpreted as a base 10 number, and the sum should be returned in base 10.
    
    Example 1:
    
    >>> sumBase(n = 34, k = 6)
    >>> 9
    Explanation: 34 (base 10) expressed in base 6 is 54. 5 + 4 = 9.
    
    Example 2:
    
    >>> sumBase(n = 10, k = 10)
    >>> 1
    Explanation: n is already in base 10. 1 + 0 = 1.
    """
def maxFrequency(nums: List[int], k: int) -> int:
    """
    The frequency of an element is the number of times it occurs in an array.
    You are given an integer array nums and an integer k. In one operation, you can choose an index of nums and increment the element at that index by 1.
    Return the maximum possible frequency of an element after performing at most k operations.
    
    Example 1:
    
    >>> maxFrequency(nums = [1,2,4], k = 5)
    >>> 3
    Explanation: Increment the first element three times and the second element two times to make nums = [4,4,4].
    4 has a frequency of 3.
    Example 2:
    
    >>> maxFrequency(nums = [1,4,8,13], k = 5)
    >>> 2
    Explanation: There are multiple optimal solutions:
    - Increment the first element three times to make nums = [4,4,8,13]. 4 has a frequency of 2.
    - Increment the second element four times to make nums = [1,8,8,13]. 8 has a frequency of 2.
    - Increment the third element five times to make nums = [1,4,13,13]. 13 has a frequency of 2.
    
    Example 3:
    
    >>> maxFrequency(nums = [3,9,6], k = 2)
    >>> 1
    """
def longestBeautifulSubstring(word: str) -> int:
    """
    A string is considered beautiful if it satisfies the following conditions:
    
    Each of the 5 English vowels ('a', 'e', 'i', 'o', 'u') must appear at least once in it.
    The letters must be sorted in alphabetical order (i.e. all 'a's before 'e's, all 'e's before 'i's, etc.).
    
    For example, strings "aeiou" and "aaaaaaeiiiioou" are considered beautiful, but "uaeio", "aeoiu", and "aaaeeeooo" are not beautiful.
    Given a string word consisting of English vowels, return the length of the longest beautiful substring of word. If no such substring exists, return 0.
    A substring is a contiguous sequence of characters in a string.
    
    Example 1:
    
    >>> longestBeautifulSubstring(word = "aeiaaioaaaaeiiiiouuuooaauuaeiu")
    >>> 13
    Explanation: The longest beautiful substring in word is "aaaaeiiiiouuu" of length 13.
    Example 2:
    
    >>> longestBeautifulSubstring(word = "aeeeiiiioooauuuaeiou")
    >>> 5
    Explanation: The longest beautiful substring in word is "aeiou" of length 5.
    
    Example 3:
    
    >>> longestBeautifulSubstring(word = "a")
    >>> 0
    Explanation: There is no beautiful substring, so return 0.
    """