ShwStone/humaneval-leetcode huggingface dataset:
def rotateTheBox(boxGrid: List[List[str]]) -> List[List[str]]:
    """
    You are given an m x n matrix of characters boxGrid representing a side-view of a box. Each cell of the box is one of the following:
    
    A stone '#'
    A stationary obstacle '*'
    Empty '.'
    
    The box is rotated 90 degrees clockwise, causing some of the stones to fall due to gravity. Each stone falls down until it lands on an obstacle, another stone, or the bottom of the box. Gravity does not affect the obstacles' positions, and the inertia from the box's rotation does not affect the stones' horizontal positions.
    It is guaranteed that each stone in boxGrid rests on an obstacle, another stone, or the bottom of the box.
    Return an n x m matrix representing the box after the rotation described above.
    
    Example 1:
    
    
    >>> rotateTheBox(boxGrid = [["#",".","#"]])
    >>> [["."],
             ["#"],
             ["#"]]
    
    Example 2:
    
    
                  ["#","#","*","."]]
    >>> rotateTheBox(boxGrid = [["#",".","*","."],)
    >>> [["#","."],
             ["#","#"],
             ["*","*"],
             [".","."]]
    
    Example 3:
    
    
                  ["#","#","#","*",".","."],
                  ["#","#","#",".","#","."]]
    >>> rotateTheBox(boxGrid = [["#","#","*",".","*","."],)
    >>> [[".","#","#"],
             [".","#","#"],
             ["#","#","*"],
             ["#","*","."],
             ["#",".","*"],
             ["#",".","."]]
    """
def sumOfFlooredPairs(nums: List[int]) -> int:
    """
    Given an integer array nums, return the sum of floor(nums[i] / nums[j]) for all pairs of indices 0 <= i, j < nums.length in the array. Since the answer may be too large, return it modulo 109 + 7.
    The floor() function returns the integer part of the division.
    
    Example 1:
    
    >>> sumOfFlooredPairs(nums = [2,5,9])
    >>> 10
    Explanation:
    floor(2 / 5) = floor(2 / 9) = floor(5 / 9) = 0
    floor(2 / 2) = floor(5 / 5) = floor(9 / 9) = 1
    floor(5 / 2) = 2
    floor(9 / 2) = 4
    floor(9 / 5) = 1
    We calculate the floor of the division for every pair of indices in the array then sum them up.
    
    Example 2:
    
    >>> sumOfFlooredPairs(nums = [7,7,7,7,7,7,7])
    >>> 49
    """
def subsetXORSum(nums: List[int]) -> int:
    """
    The XOR total of an array is defined as the bitwise XOR of all its elements, or 0 if the array is empty.
    
    For example, the XOR total of the array [2,5,6] is 2 XOR 5 XOR 6 = 1.
    
    Given an array nums, return the sum of all XOR totals for every subset of nums.
    Note: Subsets with the same elements should be counted multiple times.
    An array a is a subset of an array b if a can be obtained from b by deleting some (possibly zero) elements of b.
    
    Example 1:
    
    >>> subsetXORSum(nums = [1,3])
    >>> 6
    Explanation: The 4 subsets of [1,3] are:
    - The empty subset has an XOR total of 0.
    - [1] has an XOR total of 1.
    - [3] has an XOR total of 3.
    - [1,3] has an XOR total of 1 XOR 3 = 2.
    0 + 1 + 3 + 2 = 6
    
    Example 2:
    
    >>> subsetXORSum(nums = [5,1,6])
    >>> 28
    Explanation: The 8 subsets of [5,1,6] are:
    - The empty subset has an XOR total of 0.
    - [5] has an XOR total of 5.
    - [1] has an XOR total of 1.
    - [6] has an XOR total of 6.
    - [5,1] has an XOR total of 5 XOR 1 = 4.
    - [5,6] has an XOR total of 5 XOR 6 = 3.
    - [1,6] has an XOR total of 1 XOR 6 = 7.
    - [5,1,6] has an XOR total of 5 XOR 1 XOR 6 = 2.
    0 + 5 + 1 + 6 + 4 + 3 + 7 + 2 = 28
    
    Example 3:
    
    >>> subsetXORSum(nums = [3,4,5,6,7,8])
    >>> 480
    Explanation: The sum of all XOR totals for every subset is 480.
    """
def minSwaps(s: str) -> int:
    """
    Given a binary string s, return the minimum number of character swaps to make it alternating, or -1 if it is impossible.
    The string is called alternating if no two adjacent characters are equal. For example, the strings "010" and "1010" are alternating, while the string "0100" is not.
    Any two characters may be swapped, even if they are not adjacent.
    
    Example 1:
    
    >>> minSwaps(s = "111000")
    >>> 1
    Explanation: Swap positions 1 and 4: "111000" -> "101010"
    The string is now alternating.
    
    Example 2:
    
    >>> minSwaps(s = "010")
    >>> 0
    Explanation: The string is already alternating, no swaps are needed.
    
    Example 3:
    
    >>> minSwaps(s = "1110")
    >>> -1
    """
def rearrangeSticks(n: int, k: int) -> int:
    """
    There are n uniquely-sized sticks whose lengths are integers from 1 to n. You want to arrange the sticks such that exactly k sticks are visible from the left. A stick is visible from the left if there are no longer sticks to the left of it.
    
    For example, if the sticks are arranged [1,3,2,5,4], then the sticks with lengths 1, 3, and 5 are visible from the left.
    
    Given n and k, return the number of such arrangements. Since the answer may be large, return it modulo 109 + 7.
    
    Example 1:
    
    >>> rearrangeSticks(n = 3, k = 2)
    >>> 3
    Explanation: [1,3,2], [2,3,1], and [2,1,3] are the only arrangements such that exactly 2 sticks are visible.
    The visible sticks are underlined.
    
    Example 2:
    
    >>> rearrangeSticks(n = 5, k = 5)
    >>> 1
    Explanation: [1,2,3,4,5] is the only arrangement such that all 5 sticks are visible.
    The visible sticks are underlined.
    
    Example 3:
    
    >>> rearrangeSticks(n = 20, k = 11)
    >>> 647427950
    Explanation: There are 647427950 (mod 109 + 7) ways to rearrange the sticks such that exactly 11 sticks are visible.
    """
def findRLEArray(encoded1: List[List[int]], encoded2: List[List[int]]) -> List[List[int]]:
    """
    Run-length encoding is a compression algorithm that allows for an integer array nums with many segments of consecutive repeated numbers to be represented by a (generally smaller) 2D array encoded. Each encoded[i] = [vali, freqi] describes the ith segment of repeated numbers in nums where vali is the value that is repeated freqi times.
    
    For example, nums = [1,1,1,2,2,2,2,2] is represented by the run-length encoded array encoded = [[1,3],[2,5]]. Another way to read this is "three 1's followed by five 2's".
    
    The product of two run-length encoded arrays encoded1 and encoded2 can be calculated using the following steps:
    
    Expand both encoded1 and encoded2 into the full arrays nums1 and nums2 respectively.
    Create a new array prodNums of length nums1.length and set prodNums[i] = nums1[i] * nums2[i].
    Compress prodNums into a run-length encoded array and return it.
    
    You are given two run-length encoded arrays encoded1 and encoded2 representing full arrays nums1 and nums2 respectively. Both nums1 and nums2 have the same length. Each encoded1[i] = [vali, freqi] describes the ith segment of nums1, and each encoded2[j] = [valj, freqj] describes the jth segment of nums2.
    Return the product of encoded1 and encoded2.
    Note: Compression should be done such that the run-length encoded array has the minimum possible length.
    
    Example 1:
    
    >>> findRLEArray(encoded1 = [[1,3],[2,3]], encoded2 = [[6,3],[3,3]])
    >>> [[6,6]]
    Explanation: encoded1 expands to [1,1,1,2,2,2] and encoded2 expands to [6,6,6,3,3,3].
    prodNums = [6,6,6,6,6,6], which is compressed into the run-length encoded array [[6,6]].
    
    Example 2:
    
    >>> findRLEArray(encoded1 = [[1,3],[2,1],[3,2]], encoded2 = [[2,3],[3,3]])
    >>> [[2,3],[6,1],[9,2]]
    Explanation: encoded1 expands to [1,1,1,2,3,3] and encoded2 expands to [2,2,2,3,3,3].
    prodNums = [2,2,2,6,9,9], which is compressed into the run-length encoded array [[2,3],[6,1],[9,2]].
    """
def checkZeroOnes(s: str) -> bool:
    """
    Given a binary string s, return true if the longest contiguous segment of 1's is strictly longer than the longest contiguous segment of 0's in s, or return false otherwise.
    
    For example, in s = "110100010" the longest continuous segment of 1s has length 2, and the longest continuous segment of 0s has length 3.
    
    Note that if there are no 0's, then the longest continuous segment of 0's is considered to have a length 0. The same applies if there is no 1's.
    
    Example 1:
    
    >>> checkZeroOnes(s = "1101")
    >>> true
    Explanation:
    The longest contiguous segment of 1s has length 2: "1101"
    The longest contiguous segment of 0s has length 1: "1101"
    The segment of 1s is longer, so return true.
    
    Example 2:
    
    >>> checkZeroOnes(s = "111000")
    >>> false
    Explanation:
    The longest contiguous segment of 1s has length 3: "111000"
    The longest contiguous segment of 0s has length 3: "111000"
    The segment of 1s is not longer, so return false.
    
    Example 3:
    
    >>> checkZeroOnes(s = "110100010")
    >>> false
    Explanation:
    The longest contiguous segment of 1s has length 2: "110100010"
    The longest contiguous segment of 0s has length 3: "110100010"
    The segment of 1s is not longer, so return false.
    """
def minSpeedOnTime(dist: List[int], hour: float) -> int:
    """
    You are given a floating-point number hour, representing the amount of time you have to reach the office. To commute to the office, you must take n trains in sequential order. You are also given an integer array dist of length n, where dist[i] describes the distance (in kilometers) of the ith train ride.
    Each train can only depart at an integer hour, so you may need to wait in between each train ride.
    
    For example, if the 1st train ride takes 1.5 hours, you must wait for an additional 0.5 hours before you can depart on the 2nd train ride at the 2 hour mark.
    
    Return the minimum positive integer speed (in kilometers per hour) that all the trains must travel at for you to reach the office on time, or -1 if it is impossible to be on time.
    Tests are generated such that the answer will not exceed 107 and hour will have at most two digits after the decimal point.
    
    Example 1:
    
    >>> minSpeedOnTime(dist = [1,3,2], hour = 6)
    >>> 1
    Explanation: At speed 1:
    - The first train ride takes 1/1 = 1 hour.
    - Since we are already at an integer hour, we depart immediately at the 1 hour mark. The second train takes 3/1 = 3 hours.
    - Since we are already at an integer hour, we depart immediately at the 4 hour mark. The third train takes 2/1 = 2 hours.
    - You will arrive at exactly the 6 hour mark.
    
    Example 2:
    
    >>> minSpeedOnTime(dist = [1,3,2], hour = 2.7)
    >>> 3
    Explanation: At speed 3:
    - The first train ride takes 1/3 = 0.33333 hours.
    - Since we are not at an integer hour, we wait until the 1 hour mark to depart. The second train ride takes 3/3 = 1 hour.
    - Since we are already at an integer hour, we depart immediately at the 2 hour mark. The third train takes 2/3 = 0.66667 hours.
    - You will arrive at the 2.66667 hour mark.
    
    Example 3:
    
    >>> minSpeedOnTime(dist = [1,3,2], hour = 1.9)
    >>> -1
    Explanation: It is impossible because the earliest the third train can depart is at the 2 hour mark.
    """
def canReach(s: str, minJump: int, maxJump: int) -> bool:
    """
    You are given a 0-indexed binary string s and two integers minJump and maxJump. In the beginning, you are standing at index 0, which is equal to '0'. You can move from index i to index j if the following conditions are fulfilled:
    
    i + minJump <= j <= min(i + maxJump, s.length - 1), and
    s[j] == '0'.
    
    Return true if you can reach index s.length - 1 in s, or false otherwise.
    
    Example 1:
    
    >>> canReach(s = "011010", minJump = 2, maxJump = 3)
    >>> true
    Explanation:
    In the first step, move from index 0 to index 3.
    In the second step, move from index 3 to index 5.
    
    Example 2:
    
    >>> canReach(s = "01101110", minJump = 2, maxJump = 3)
    >>> false
    """
def stoneGameVIII(stones: List[int]) -> int:
    """
    Alice and Bob take turns playing a game, with Alice starting first.\r
    \r
    There are n stones arranged in a row. On each player's turn, while the number of stones is more than one, they will do the following:\r
    \r
    \r
    	Choose an integer x > 1, and remove the leftmost x stones from the row.\r
    	Add the sum of the removed stones' values to the player's score.\r
    	Place a new stone, whose value is equal to that sum, on the left side of the row.\r
    \r
    \r
    The game stops when only one stone is left in the row.\r
    \r
    The score difference between Alice and Bob is (Alice's score - Bob's score). Alice's goal is to maximize the score difference, and Bob's goal is the minimize the score difference.\r
    \r
    Given an integer array stones of length n where stones[i] represents the value of the ith stone from the left, return the score difference between Alice and Bob if they both play optimally.\r
    \r
     \r
    Example 1:\r
    \r
    \r
    >>> stoneGameVIII(stones = [-1,2,-3,4,-5]\r)
    >>> 5\r
    Explanation:\r
    - Alice removes the first 4 stones, adds (-1) + 2 + (-3) + 4 = 2 to her score, and places a stone of\r
      value 2 on the left. stones = [2,-5].\r
    - Bob removes the first 2 stones, adds 2 + (-5) = -3 to his score, and places a stone of value -3 on\r
      the left. stones = [-3].\r
    The difference between their scores is 2 - (-3) = 5.\r
    \r
    \r
    Example 2:\r
    \r
    \r
    >>> stoneGameVIII(stones = [7,-6,5,10,5,-2,-6]\r)
    >>> 13\r
    Explanation:\r
    - Alice removes all stones, adds 7 + (-6) + 5 + 10 + 5 + (-2) + (-6) = 13 to her score, and places a\r
      stone of value 13 on the left. stones = [13].\r
    The difference between their scores is 13 - 0 = 13.\r
    \r
    \r
    Example 3:\r
    \r
    \r
    >>> stoneGameVIII(stones = [-10,-12]\r)
    >>> -22\r
    Explanation:\r
    - Alice can only make one move, which is to remove both stones. She adds (-10) + (-12) = -22 to her\r
      score and places a stone of value -22 on the left. stones = [-22].\r
    The difference between their scores is (-22) - 0 = -22.\r
    \r
    \r
     \r
    """
def minProductSum(nums1: List[int], nums2: List[int]) -> int:
    """
    The product sum of two equal-length arrays a and b is equal to the sum of a[i] * b[i] for all 0 <= i < a.length (0-indexed).\r
    \r
    \r
    	For example, if a = [1,2,3,4] and b = [5,2,3,1], the product sum would be 1*5 + 2*2 + 3*3 + 4*1 = 22.\r
    \r
    \r
    Given two arrays nums1 and nums2 of length n, return the minimum product sum if you are allowed to rearrange the order of the elements in nums1. \r
    \r
     \r
    Example 1:\r
    \r
    \r
    >>> minProductSum(nums1 = [5,3,4,2], nums2 = [4,2,2,5]\r)
    >>> 40\r
    Explanation: We can rearrange nums1 to become [3,5,4,2]. The product sum of [3,5,4,2] and [4,2,2,5] is 3*4 + 5*2 + 4*2 + 2*5 = 40.\r
    \r
    \r
    Example 2:\r
    \r
    \r
    >>> minProductSum(nums1 = [2,1,4,5,7], nums2 = [3,2,4,8,6]\r)
    >>> 65\r
    Explanation: We can rearrange nums1 to become [5,7,4,1,2]. The product sum of [5,7,4,1,2] and [3,2,4,8,6] is 5*3 + 7*2 + 4*4 + 1*8 + 2*6 = 65.\r
    \r
    \r
     \r
    """
def countGoodSubstrings(s: str) -> int:
    """
    A string is good if there are no repeated characters.
    Given a string s​​​​​, return the number of good substrings of length three in s​​​​​​.
    Note that if there are multiple occurrences of the same substring, every occurrence should be counted.
    A substring is a contiguous sequence of characters in a string.
    
    Example 1:
    
    >>> countGoodSubstrings(s = "xyzzaz")
    >>> 1
    Explanation: There are 4 substrings of size 3: "xyz", "yzz", "zza", and "zaz".
    The only good substring of length 3 is "xyz".
    
    Example 2:
    
    >>> countGoodSubstrings(s = "aababcabc")
    >>> 4
    Explanation: There are 7 substrings of size 3: "aab", "aba", "bab", "abc", "bca", "cab", and "abc".
    The good substrings are "abc", "bca", "cab", and "abc".
    """
def minPairSum(nums: List[int]) -> int:
    """
    The pair sum of a pair (a,b) is equal to a + b. The maximum pair sum is the largest pair sum in a list of pairs.\r
    \r
    \r
    	For example, if we have pairs (1,5), (2,3), and (4,4), the maximum pair sum would be max(1+5, 2+3, 4+4) = max(6, 5, 8) = 8.\r
    \r
    \r
    Given an array nums of even length n, pair up the elements of nums into n / 2 pairs such that:\r
    \r
    \r
    	Each element of nums is in exactly one pair, and\r
    	The maximum pair sum is minimized.\r
    \r
    \r
    Return the minimized maximum pair sum after optimally pairing up the elements.\r
    \r
     \r
    Example 1:\r
    \r
    \r
    >>> minPairSum(nums = [3,5,2,3]\r)
    >>> 7\r
    Explanation: The elements can be paired up into pairs (3,3) and (5,2).\r
    The maximum pair sum is max(3+3, 5+2) = max(6, 7) = 7.\r
    \r
    \r
    Example 2:\r
    \r
    \r
    >>> minPairSum(nums = [3,5,4,2,4,6]\r)
    >>> 8\r
    Explanation: The elements can be paired up into pairs (3,5), (4,4), and (6,2).\r
    The maximum pair sum is max(3+5, 4+4, 6+2) = max(8, 8, 8) = 8.\r
    \r
    \r
     \r
    """
def getBiggestThree(grid: List[List[int]]) -> List[int]:
    """
    You are given an m x n integer matrix grid​​​.
    A rhombus sum is the sum of the elements that form the border of a regular rhombus shape in grid​​​. The rhombus must have the shape of a square rotated 45 degrees with each of the corners centered in a grid cell. Below is an image of four valid rhombus shapes with the corresponding colored cells that should be included in each rhombus sum:
    
    Note that the rhombus can have an area of 0, which is depicted by the purple rhombus in the bottom right corner.
    Return the biggest three distinct rhombus sums in the grid in descending order. If there are less than three distinct values, return all of them.
    
    Example 1:
    
    
    >>> getBiggestThree(grid = [[3,4,5,1,3],[3,3,4,2,3],[20,30,200,40,10],[1,5,5,4,1],[4,3,2,2,5]])
    >>> [228,216,211]
    Explanation: The rhombus shapes for the three biggest distinct rhombus sums are depicted above.
    - Blue: 20 + 3 + 200 + 5 = 228
    - Red: 200 + 2 + 10 + 4 = 216
    - Green: 5 + 200 + 4 + 2 = 211
    
    Example 2:
    
    
    >>> getBiggestThree(grid = [[1,2,3],[4,5,6],[7,8,9]])
    >>> [20,9,8]
    Explanation: The rhombus shapes for the three biggest distinct rhombus sums are depicted above.
    - Blue: 4 + 2 + 6 + 8 = 20
    - Red: 9 (area 0 rhombus in the bottom right corner)
    - Green: 8 (area 0 rhombus in the bottom middle)
    
    Example 3:
    
    >>> getBiggestThree(grid = [[7,7,7]])
    >>> [7]
    Explanation: All three possible rhombus sums are the same, so return [7].
    """
def minimumXORSum(nums1: List[int], nums2: List[int]) -> int:
    """
    You are given two integer arrays nums1 and nums2 of length n.
    The XOR sum of the two integer arrays is (nums1[0] XOR nums2[0]) + (nums1[1] XOR nums2[1]) + ... + (nums1[n - 1] XOR nums2[n - 1]) (0-indexed).
    
    For example, the XOR sum of [1,2,3] and [3,2,1] is equal to (1 XOR 3) + (2 XOR 2) + (3 XOR 1) = 2 + 0 + 2 = 4.
    
    Rearrange the elements of nums2 such that the resulting XOR sum is minimized.
    Return the XOR sum after the rearrangement.
    
    Example 1:
    
    >>> minimumXORSum(nums1 = [1,2], nums2 = [2,3])
    >>> 2
    Explanation: Rearrange nums2 so that it becomes [3,2].
    The XOR sum is (1 XOR 3) + (2 XOR 2) = 2 + 0 = 2.
    Example 2:
    
    >>> minimumXORSum(nums1 = [1,0,3], nums2 = [5,3,4])
    >>> 8
    Explanation: Rearrange nums2 so that it becomes [5,4,3].
    The XOR sum is (1 XOR 5) + (0 XOR 4) + (3 XOR 3) = 4 + 4 + 0 = 8.
    """
def isSumEqual(firstWord: str, secondWord: str, targetWord: str) -> bool:
    """
    The letter value of a letter is its position in the alphabet starting from 0 (i.e. 'a' -> 0, 'b' -> 1, 'c' -> 2, etc.).
    The numerical value of some string of lowercase English letters s is the concatenation of the letter values of each letter in s, which is then converted into an integer.
    
    For example, if s = "acb", we concatenate each letter's letter value, resulting in "021". After converting it, we get 21.
    
    You are given three strings firstWord, secondWord, and targetWord, each consisting of lowercase English letters 'a' through 'j' inclusive.
    Return true if the summation of the numerical values of firstWord and secondWord equals the numerical value of targetWord, or false otherwise.
    
    Example 1:
    
    >>> isSumEqual(firstWord = "acb", secondWord = "cba", targetWord = "cdb")
    >>> true
    Explanation:
    The numerical value of firstWord is "acb" -> "021" -> 21.
    The numerical value of secondWord is "cba" -> "210" -> 210.
    The numerical value of targetWord is "cdb" -> "231" -> 231.
    We return true because 21 + 210 == 231.
    
    Example 2:
    
    >>> isSumEqual(firstWord = "aaa", secondWord = "a", targetWord = "aab")
    >>> false
    Explanation:
    The numerical value of firstWord is "aaa" -> "000" -> 0.
    The numerical value of secondWord is "a" -> "0" -> 0.
    The numerical value of targetWord is "aab" -> "001" -> 1.
    We return false because 0 + 0 != 1.
    
    Example 3:
    
    >>> isSumEqual(firstWord = "aaa", secondWord = "a", targetWord = "aaaa")
    >>> true
    Explanation:
    The numerical value of firstWord is "aaa" -> "000" -> 0.
    The numerical value of secondWord is "a" -> "0" -> 0.
    The numerical value of targetWord is "aaaa" -> "0000" -> 0.
    We return true because 0 + 0 == 0.
    """
def maxValue(n: str, x: int) -> str:
    """
    You are given a very large integer n, represented as a string,​​​​​​ and an integer digit x. The digits in n and the digit x are in the inclusive range [1, 9], and n may represent a negative number.
    You want to maximize n's numerical value by inserting x anywhere in the decimal representation of n​​​​​​. You cannot insert x to the left of the negative sign.
    
    For example, if n = 73 and x = 6, it would be best to insert it between 7 and 3, making n = 763.
    If n = -55 and x = 2, it would be best to insert it before the first 5, making n = -255.
    
    Return a string representing the maximum value of n​​​​​​ after the insertion.
    
    Example 1:
    
    >>> maxValue(n = "99", x = 9)
    >>> "999"
    Explanation: The result is the same regardless of where you insert 9.
    
    Example 2:
    
    >>> maxValue(n = "-13", x = 2)
    >>> "-123"
    Explanation: You can make n one of {-213, -123, -132}, and the largest of those three is -123.
    """