ShwStone/humaneval-leetcode huggingface dataset:
def gridGame(grid: List[List[int]]) -> int:
    """
    You are given a 0-indexed 2D array grid of size 2 x n, where grid[r][c] represents the number of points at position (r, c) on the matrix. Two robots are playing a game on this matrix.
    Both robots initially start at (0, 0) and want to reach (1, n-1). Each robot may only move to the right ((r, c) to (r, c + 1)) or down ((r, c) to (r + 1, c)).
    At the start of the game, the first robot moves from (0, 0) to (1, n-1), collecting all the points from the cells on its path. For all cells (r, c) traversed on the path, grid[r][c] is set to 0. Then, the second robot moves from (0, 0) to (1, n-1), collecting the points on its path. Note that their paths may intersect with one another.
    The first robot wants to minimize the number of points collected by the second robot. In contrast, the second robot wants to maximize the number of points it collects. If both robots play optimally, return the number of points collected by the second robot.
    
    Example 1:
    
    
    >>> gridGame(grid = [[2,5,4],[1,5,1]])
    >>> 4
    Explanation: The optimal path taken by the first robot is shown in red, and the optimal path taken by the second robot is shown in blue.
    The cells visited by the first robot are set to 0.
    The second robot will collect 0 + 0 + 4 + 0 = 4 points.
    
    Example 2:
    
    
    >>> gridGame(grid = [[3,3,1],[8,5,2]])
    >>> 4
    Explanation: The optimal path taken by the first robot is shown in red, and the optimal path taken by the second robot is shown in blue.
    The cells visited by the first robot are set to 0.
    The second robot will collect 0 + 3 + 1 + 0 = 4 points.
    
    Example 3:
    
    
    >>> gridGame(grid = [[1,3,1,15],[1,3,3,1]])
    >>> 7
    Explanation: The optimal path taken by the first robot is shown in red, and the optimal path taken by the second robot is shown in blue.
    The cells visited by the first robot are set to 0.
    The second robot will collect 0 + 1 + 3 + 3 + 0 = 7 points.
    """
def placeWordInCrossword(board: List[List[str]], word: str) -> bool:
    """
    You are given an m x n matrix board, representing the current state of a crossword puzzle. The crossword contains lowercase English letters (from solved words), ' ' to represent any empty cells, and '#' to represent any blocked cells.
    A word can be placed horizontally (left to right or right to left) or vertically (top to bottom or bottom to top) in the board if:
    
    It does not occupy a cell containing the character '#'.
    The cell each letter is placed in must either be ' ' (empty) or match the letter already on the board.
    There must not be any empty cells ' ' or other lowercase letters directly left or right of the word if the word was placed horizontally.
    There must not be any empty cells ' ' or other lowercase letters directly above or below the word if the word was placed vertically.
    
    Given a string word, return true if word can be placed in board, or false otherwise.
    
    Example 1:
    
    
    >>> placeWordInCrossword(board = [["#", " ", "#"], [" ", " ", "#"], ["#", "c", " "]], word = "abc")
    >>> true
    Explanation: The word "abc" can be placed as shown above (top to bottom).
    
    Example 2:
    
    
    >>> placeWordInCrossword(board = [[" ", "#", "a"], [" ", "#", "c"], [" ", "#", "a"]], word = "ac")
    >>> false
    Explanation: It is impossible to place the word because there will always be a space/letter above or below it.
    Example 3:
    
    
    >>> placeWordInCrossword(board = [["#", " ", "#"], [" ", " ", "#"], ["#", " ", "c"]], word = "ca")
    >>> true
    Explanation: The word "ca" can be placed as shown above (right to left).
    """
def scoreOfStudents(s: str, answers: List[int]) -> int:
    """
    You are given a string s that contains digits 0-9, addition symbols '+', and multiplication symbols '*' only, representing a valid math expression of single digit numbers (e.g., 3+5*2). This expression was given to n elementary school students. The students were instructed to get the answer of the expression by following this order of operations:
    
    Compute multiplication, reading from left to right; Then,
    Compute addition, reading from left to right.
    
    You are given an integer array answers of length n, which are the submitted answers of the students in no particular order. You are asked to grade the answers, by following these rules:
    
    If an answer equals the correct answer of the expression, this student will be rewarded 5 points;
    Otherwise, if the answer could be interpreted as if the student applied the operators in the wrong order but had correct arithmetic, this student will be rewarded 2 points;
    Otherwise, this student will be rewarded 0 points.
    
    Return the sum of the points of the students.
    
    Example 1:
    
    
    >>> scoreOfStudents(s = "7+3*1*2", answers = [20,13,42])
    >>> 7
    Explanation: As illustrated above, the correct answer of the expression is 13, therefore one student is rewarded 5 points: [20,13,42]
    A student might have applied the operators in this wrong order: ((7+3)*1)*2 = 20. Therefore one student is rewarded 2 points: [20,13,42]
    The points for the students are: [2,5,0]. The sum of the points is 2+5+0=7.
    
    Example 2:
    
    >>> scoreOfStudents(s = "3+5*2", answers = [13,0,10,13,13,16,16])
    >>> 19
    Explanation: The correct answer of the expression is 13, therefore three students are rewarded 5 points each: [13,0,10,13,13,16,16]
    A student might have applied the operators in this wrong order: ((3+5)*2 = 16. Therefore two students are rewarded 2 points: [13,0,10,13,13,16,16]
    The points for the students are: [5,0,0,5,5,2,2]. The sum of the points is 5+0+0+5+5+2+2=19.
    
    Example 3:
    
    >>> scoreOfStudents(s = "6+0*1", answers = [12,9,6,4,8,6])
    >>> 10
    Explanation: The correct answer of the expression is 6.
    If a student had incorrectly done (6+0)*1, the answer would also be 6.
    By the rules of grading, the students will still be rewarded 5 points (as they got the correct answer), not 2 points.
    The points for the students are: [0,0,5,0,0,5]. The sum of the points is 10.
    """
def brightestPosition(lights: List[List[int]]) -> int:
    """
    A perfectly straight street is represented by a number line. The street has street lamp(s) on it and is represented by a 2D integer array lights. Each lights[i] = [positioni, rangei] indicates that there is a street lamp at position positioni that lights up the area from [positioni - rangei, positioni + rangei] (inclusive).
    The brightness of a position p is defined as the number of street lamp that light up the position p.
    Given lights, return the brightest position on the street. If there are multiple brightest positions, return the smallest one.
    
    Example 1:
    
    
    >>> brightestPosition(lights = [[-3,2],[1,2],[3,3]])
    >>> -1
    Explanation:
    The first street lamp lights up the area from [(-3) - 2, (-3) + 2] = [-5, -1].
    The second street lamp lights up the area from [1 - 2, 1 + 2] = [-1, 3].
    The third street lamp lights up the area from [3 - 3, 3 + 3] = [0, 6].
    
    Position -1 has a brightness of 2, illuminated by the first and second street light.
    Positions 0, 1, 2, and 3 have a brightness of 2, illuminated by the second and third street light.
    Out of all these positions, -1 is the smallest, so return it.
    
    Example 2:
    
    >>> brightestPosition(lights = [[1,0],[0,1]])
    >>> 1
    Explanation:
    The first street lamp lights up the area from [1 - 0, 1 + 0] = [1, 1].
    The second street lamp lights up the area from [0 - 1, 0 + 1] = [-1, 1].
    
    Position 1 has a brightness of 2, illuminated by the first and second street light.
    Return 1 because it is the brightest position on the street.
    
    Example 3:
    
    >>> brightestPosition(lights = [[1,2]])
    >>> -1
    Explanation:
    The first street lamp lights up the area from [1 - 2, 1 + 2] = [-1, 3].
    
    Positions -1, 0, 1, 2, and 3 have a brightness of 1, illuminated by the first street light.
    Out of all these positions, -1 is the smallest, so return it.
    """
def construct2DArray(original: List[int], m: int, n: int) -> List[List[int]]:
    """
    You are given a 0-indexed 1-dimensional (1D) integer array original, and two integers, m and n. You are tasked with creating a 2-dimensional (2D) array with  m rows and n columns using all the elements from original.
    The elements from indices 0 to n - 1 (inclusive) of original should form the first row of the constructed 2D array, the elements from indices n to 2 * n - 1 (inclusive) should form the second row of the constructed 2D array, and so on.
    Return an m x n 2D array constructed according to the above procedure, or an empty 2D array if it is impossible.
    
    Example 1:
    
    
    >>> construct2DArray(original = [1,2,3,4], m = 2, n = 2)
    >>> [[1,2],[3,4]]
    Explanation: The constructed 2D array should contain 2 rows and 2 columns.
    The first group of n=2 elements in original, [1,2], becomes the first row in the constructed 2D array.
    The second group of n=2 elements in original, [3,4], becomes the second row in the constructed 2D array.
    
    Example 2:
    
    >>> construct2DArray(original = [1,2,3], m = 1, n = 3)
    >>> [[1,2,3]]
    Explanation: The constructed 2D array should contain 1 row and 3 columns.
    Put all three elements in original into the first row of the constructed 2D array.
    
    Example 3:
    
    >>> construct2DArray(original = [1,2], m = 1, n = 1)
    >>> []
    Explanation: There are 2 elements in original.
    It is impossible to fit 2 elements in a 1x1 2D array, so return an empty 2D array.
    """
def numOfPairs(nums: List[str], target: str) -> int:
    """
    Given an array of digit strings nums and a digit string target, return the number of pairs of indices (i, j) (where i != j) such that the concatenation of nums[i] + nums[j] equals target.
    
    Example 1:
    
    >>> numOfPairs(nums = ["777","7","77","77"], target = "7777")
    >>> 4
    Explanation: Valid pairs are:
    - (0, 1): "777" + "7"
    - (1, 0): "7" + "777"
    - (2, 3): "77" + "77"
    - (3, 2): "77" + "77"
    
    Example 2:
    
    >>> numOfPairs(nums = ["123","4","12","34"], target = "1234")
    >>> 2
    Explanation: Valid pairs are:
    - (0, 1): "123" + "4"
    - (2, 3): "12" + "34"
    
    Example 3:
    
    >>> numOfPairs(nums = ["1","1","1"], target = "11")
    >>> 6
    Explanation: Valid pairs are:
    - (0, 1): "1" + "1"
    - (1, 0): "1" + "1"
    - (0, 2): "1" + "1"
    - (2, 0): "1" + "1"
    - (1, 2): "1" + "1"
    - (2, 1): "1" + "1"
    """
def maxConsecutiveAnswers(answerKey: str, k: int) -> int:
    """
    A teacher is writing a test with n true/false questions, with 'T' denoting true and 'F' denoting false. He wants to confuse the students by maximizing the number of consecutive questions with the same answer (multiple trues or multiple falses in a row).
    You are given a string answerKey, where answerKey[i] is the original answer to the ith question. In addition, you are given an integer k, the maximum number of times you may perform the following operation:
    
    Change the answer key for any question to 'T' or 'F' (i.e., set answerKey[i] to 'T' or 'F').
    
    Return the maximum number of consecutive 'T's or 'F's in the answer key after performing the operation at most k times.
    
    Example 1:
    
    >>> maxConsecutiveAnswers(answerKey = "TTFF", k = 2)
    >>> 4
    Explanation: We can replace both the 'F's with 'T's to make answerKey = "TTTT".
    There are four consecutive 'T's.
    
    Example 2:
    
    >>> maxConsecutiveAnswers(answerKey = "TFFT", k = 1)
    >>> 3
    Explanation: We can replace the first 'T' with an 'F' to make answerKey = "FFFT".
    Alternatively, we can replace the second 'T' with an 'F' to make answerKey = "TFFF".
    In both cases, there are three consecutive 'F's.
    
    Example 3:
    
    >>> maxConsecutiveAnswers(answerKey = "TTFTTFTT", k = 1)
    >>> 5
    Explanation: We can replace the first 'F' to make answerKey = "TTTTTFTT"
    Alternatively, we can replace the second 'F' to make answerKey = "TTFTTTTT".
    In both cases, there are five consecutive 'T's.
    """
def waysToPartition(nums: List[int], k: int) -> int:
    """
    You are given a 0-indexed integer array nums of length n. The number of ways to partition nums is the number of pivot indices that satisfy both conditions:
    
    1 <= pivot < n
    nums[0] + nums[1] + ... + nums[pivot - 1] == nums[pivot] + nums[pivot + 1] + ... + nums[n - 1]
    
    You are also given an integer k. You can choose to change the value of one element of nums to k, or to leave the array unchanged.
    Return the maximum possible number of ways to partition nums to satisfy both conditions after changing at most one element.
    
    Example 1:
    
    >>> waysToPartition(nums = [2,-1,2], k = 3)
    >>> 1
    Explanation: One optimal approach is to change nums[0] to k. The array becomes [3,-1,2].
    There is one way to partition the array:
    - For pivot = 2, we have the partition [3,-1 | 2]: 3 + -1 == 2.
    
    Example 2:
    
    >>> waysToPartition(nums = [0,0,0], k = 1)
    >>> 2
    Explanation: The optimal approach is to leave the array unchanged.
    There are two ways to partition the array:
    - For pivot = 1, we have the partition [0 | 0,0]: 0 == 0 + 0.
    - For pivot = 2, we have the partition [0,0 | 0]: 0 + 0 == 0.
    
    Example 3:
    
    >>> waysToPartition(nums = [22,4,-25,-20,-15,15,-16,7,19,-10,0,-13,-14], k = -33)
    >>> 4
    Explanation: One optimal approach is to change nums[2] to k. The array becomes [22,4,-33,-20,-15,15,-16,7,19,-10,0,-13,-14].
    There are four ways to partition the array.
    """
def minimumMoves(s: str) -> int:
    """
    You are given a string s consisting of n characters which are either 'X' or 'O'.
    A move is defined as selecting three consecutive characters of s and converting them to 'O'. Note that if a move is applied to the character 'O', it will stay the same.
    Return the minimum number of moves required so that all the characters of s are converted to 'O'.
    
    Example 1:
    
    >>> minimumMoves(s = "XXX")
    >>> 1
    Explanation: XXX -> OOO
    We select all the 3 characters and convert them in one move.
    
    Example 2:
    
    >>> minimumMoves(s = "XXOX")
    >>> 2
    Explanation: XXOX -> OOOX -> OOOO
    We select the first 3 characters in the first move, and convert them to 'O'.
    Then we select the last 3 characters and convert them so that the final string contains all 'O's.
    Example 3:
    
    >>> minimumMoves(s = "OOOO")
    >>> 0
    Explanation: There are no 'X's in s to convert.
    """
def missingRolls(rolls: List[int], mean: int, n: int) -> List[int]:
    """
    You have observations of n + m 6-sided dice rolls with each face numbered from 1 to 6. n of the observations went missing, and you only have the observations of m rolls. Fortunately, you have also calculated the average value of the n + m rolls.
    You are given an integer array rolls of length m where rolls[i] is the value of the ith observation. You are also given the two integers mean and n.
    Return an array of length n containing the missing observations such that the average value of the n + m rolls is exactly mean. If there are multiple valid answers, return any of them. If no such array exists, return an empty array.
    The average value of a set of k numbers is the sum of the numbers divided by k.
    Note that mean is an integer, so the sum of the n + m rolls should be divisible by n + m.
    
    Example 1:
    
    >>> missingRolls(rolls = [3,2,4,3], mean = 4, n = 2)
    >>> [6,6]
    Explanation: The mean of all n + m rolls is (3 + 2 + 4 + 3 + 6 + 6) / 6 = 4.
    
    Example 2:
    
    >>> missingRolls(rolls = [1,5,6], mean = 3, n = 4)
    >>> [2,3,2,2]
    Explanation: The mean of all n + m rolls is (1 + 5 + 6 + 2 + 3 + 2 + 2) / 7 = 3.
    
    Example 3:
    
    >>> missingRolls(rolls = [1,2,3,4], mean = 6, n = 4)
    >>> []
    Explanation: It is impossible for the mean to be 6 no matter what the 4 missing rolls are.
    """
def stoneGameIX(stones: List[int]) -> bool:
    """
    Alice and Bob continue their games with stones. There is a row of n stones, and each stone has an associated value. You are given an integer array stones, where stones[i] is the value of the ith stone.
    Alice and Bob take turns, with Alice starting first. On each turn, the player may remove any stone from stones. The player who removes a stone loses if the sum of the values of all removed stones is divisible by 3. Bob will win automatically if there are no remaining stones (even if it is Alice's turn).
    Assuming both players play optimally, return true if Alice wins and false if Bob wins.
    
    Example 1:
    
    >>> stoneGameIX(stones = [2,1])
    >>> true
    Explanation: The game will be played as follows:
    - Turn 1: Alice can remove either stone.
    - Turn 2: Bob removes the remaining stone.
    The sum of the removed stones is 1 + 2 = 3 and is divisible by 3. Therefore, Bob loses and Alice wins the game.
    
    Example 2:
    
    >>> stoneGameIX(stones = [2])
    >>> false
    Explanation: Alice will remove the only stone, and the sum of the values on the removed stones is 2.
    Since all the stones are removed and the sum of values is not divisible by 3, Bob wins the game.
    
    Example 3:
    
    >>> stoneGameIX(stones = [5,1,2,4,3])
    >>> false
    Explanation: Bob will always win. One possible way for Bob to win is shown below:
    - Turn 1: Alice can remove the second stone with value 1. Sum of removed stones = 1.
    - Turn 2: Bob removes the fifth stone with value 3. Sum of removed stones = 1 + 3 = 4.
    - Turn 3: Alices removes the fourth stone with value 4. Sum of removed stones = 1 + 3 + 4 = 8.
    - Turn 4: Bob removes the third stone with value 2. Sum of removed stones = 1 + 3 + 4 + 2 = 10.
    - Turn 5: Alice removes the first stone with value 5. Sum of removed stones = 1 + 3 + 4 + 2 + 5 = 15.
    Alice loses the game because the sum of the removed stones (15) is divisible by 3. Bob wins the game.
    """
def smallestSubsequence(s: str, k: int, letter: str, repetition: int) -> str:
    """
    You are given a string s, an integer k, a letter letter, and an integer repetition.
    Return the lexicographically smallest subsequence of s of length k that has the letter letter appear at least repetition times. The test cases are generated so that the letter appears in s at least repetition times.
    A subsequence is a string that can be derived from another string by deleting some or no characters without changing the order of the remaining characters.
    A string a is lexicographically smaller than a string b if in the first position where a and b differ, string a has a letter that appears earlier in the alphabet than the corresponding letter in b.
    
    Example 1:
    
    >>> smallestSubsequence(s = "leet", k = 3, letter = "e", repetition = 1)
    >>> "eet"
    Explanation: There are four subsequences of length 3 that have the letter 'e' appear at least 1 time:
    - "lee" (from "leet")
    - "let" (from "leet")
    - "let" (from "leet")
    - "eet" (from "leet")
    The lexicographically smallest subsequence among them is "eet".
    
    Example 2:
    
    
    >>> smallestSubsequence(s = "leetcode", k = 4, letter = "e", repetition = 2)
    >>> "ecde"
    Explanation: "ecde" is the lexicographically smallest subsequence of length 4 that has the letter "e" appear at least 2 times.
    
    Example 3:
    
    >>> smallestSubsequence(s = "bb", k = 2, letter = "b", repetition = 2)
    >>> "bb"
    Explanation: "bb" is the only subsequence of length 2 that has the letter "b" appear at least 2 times.
    """
def subarraysWithMoreZerosThanOnes(nums: List[int]) -> int:
    """
    You are given a binary array nums containing only the integers 0 and 1. Return the number of subarrays in nums that have more 1's than 0's. Since the answer may be very large, return it modulo 109 + 7.
    A subarray is a contiguous sequence of elements within an array.
    
    Example 1:
    
    >>> subarraysWithMoreZerosThanOnes(nums = [0,1,1,0,1])
    >>> 9
    Explanation:
    The subarrays of size 1 that have more ones than zeros are: [1], [1], [1]
    The subarrays of size 2 that have more ones than zeros are: [1,1]
    The subarrays of size 3 that have more ones than zeros are: [0,1,1], [1,1,0], [1,0,1]
    The subarrays of size 4 that have more ones than zeros are: [1,1,0,1]
    The subarrays of size 5 that have more ones than zeros are: [0,1,1,0,1]
    
    Example 2:
    
    >>> subarraysWithMoreZerosThanOnes(nums = [0])
    >>> 0
    Explanation:
    No subarrays have more ones than zeros.
    
    Example 3:
    
    >>> subarraysWithMoreZerosThanOnes(nums = [1])
    >>> 1
    Explanation:
    The subarrays of size 1 that have more ones than zeros are: [1]
    """
def twoOutOfThree(nums1: List[int], nums2: List[int], nums3: List[int]) -> List[int]:
    """
    Given three integer arrays nums1, nums2, and nums3, return a distinct array containing all the values that are present in at least two out of the three arrays. You may return the values in any order.
    
    Example 1:
    
    >>> twoOutOfThree(nums1 = [1,1,3,2], nums2 = [2,3], nums3 = [3])
    >>> [3,2]
    Explanation: The values that are present in at least two arrays are:
    - 3, in all three arrays.
    - 2, in nums1 and nums2.
    
    Example 2:
    
    >>> twoOutOfThree(nums1 = [3,1], nums2 = [2,3], nums3 = [1,2])
    >>> [2,3,1]
    Explanation: The values that are present in at least two arrays are:
    - 2, in nums2 and nums3.
    - 3, in nums1 and nums2.
    - 1, in nums1 and nums3.
    
    Example 3:
    
    >>> twoOutOfThree(nums1 = [1,2,2], nums2 = [4,3,3], nums3 = [5])
    >>> []
    Explanation: No value is present in at least two arrays.
    """
def minOperations(grid: List[List[int]], x: int) -> int:
    """
    You are given a 2D integer grid of size m x n and an integer x. In one operation, you can add x to or subtract x from any element in the grid.
    A uni-value grid is a grid where all the elements of it are equal.
    Return the minimum number of operations to make the grid uni-value. If it is not possible, return -1.
    
    Example 1:
    
    
    >>> minOperations(grid = [[2,4],[6,8]], x = 2)
    >>> 4
    Explanation: We can make every element equal to 4 by doing the following:
    - Add x to 2 once.
    - Subtract x from 6 once.
    - Subtract x from 8 twice.
    A total of 4 operations were used.
    
    Example 2:
    
    
    >>> minOperations(grid = [[1,5],[2,3]], x = 1)
    >>> 5
    Explanation: We can make every element equal to 3.
    
    Example 3:
    
    
    >>> minOperations(grid = [[1,2],[3,4]], x = 2)
    >>> -1
    Explanation: It is impossible to make every element equal.
    """
def minimumDifference(nums: List[int]) -> int:
    """
    You are given an integer array nums of 2 * n integers. You need to partition nums into two arrays of length n to minimize the absolute difference of the sums of the arrays. To partition nums, put each element of nums into one of the two arrays.
    Return the minimum possible absolute difference.
    
    Example 1:
    
    
    >>> minimumDifference(nums = [3,9,7,3])
    >>> 2
    Explanation: One optimal partition is: [3,9] and [7,3].
    The absolute difference between the sums of the arrays is abs((3 + 9) - (7 + 3)) = 2.
    
    Example 2:
    
    >>> minimumDifference(nums = [-36,36])
    >>> 72
    Explanation: One optimal partition is: [-36] and [36].
    The absolute difference between the sums of the arrays is abs((-36) - (36)) = 72.
    
    Example 3:
    
    
    >>> minimumDifference(nums = [2,-1,0,4,-2,-9])
    >>> 0
    Explanation: One optimal partition is: [2,4,-9] and [-1,0,-2].
    The absolute difference between the sums of the arrays is abs((2 + 4 + -9) - (-1 + 0 + -2)) = 0.
    """