ShwStone/humaneval-leetcode huggingface dataset:
def mergeTriplets(triplets: List[List[int]], target: List[int]) -> bool:
    """
    A triplet is an array of three integers. You are given a 2D integer array triplets, where triplets[i] = [ai, bi, ci] describes the ith triplet. You are also given an integer array target = [x, y, z] that describes the triplet you want to obtain.
    To obtain target, you may apply the following operation on triplets any number of times (possibly zero):
    
    Choose two indices (0-indexed) i and j (i != j) and update triplets[j] to become [max(ai, aj), max(bi, bj), max(ci, cj)].
    
    
    For example, if triplets[i] = [2, 5, 3] and triplets[j] = [1, 7, 5], triplets[j] will be updated to [max(2, 1), max(5, 7), max(3, 5)] = [2, 7, 5].
    
    
    
    Return true if it is possible to obtain the target triplet [x, y, z] as an element of triplets, or false otherwise.
    
    Example 1:
    
    >>> mergeTriplets(triplets = [[2,5,3],[1,8,4],[1,7,5]], target = [2,7,5])
    >>> true
    Explanation: Perform the following operations:
    - Choose the first and last triplets [[2,5,3],[1,8,4],[1,7,5]]. Update the last triplet to be [max(2,1), max(5,7), max(3,5)] = [2,7,5]. triplets = [[2,5,3],[1,8,4],[2,7,5]]
    The target triplet [2,7,5] is now an element of triplets.
    
    Example 2:
    
    >>> mergeTriplets(triplets = [[3,4,5],[4,5,6]], target = [3,2,5])
    >>> false
    Explanation: It is impossible to have [3,2,5] as an element because there is no 2 in any of the triplets.
    
    Example 3:
    
    >>> mergeTriplets(triplets = [[2,5,3],[2,3,4],[1,2,5],[5,2,3]], target = [5,5,5])
    >>> true
    Explanation: Perform the following operations:
    - Choose the first and third triplets [[2,5,3],[2,3,4],[1,2,5],[5,2,3]]. Update the third triplet to be [max(2,1), max(5,2), max(3,5)] = [2,5,5]. triplets = [[2,5,3],[2,3,4],[2,5,5],[5,2,3]].
    - Choose the third and fourth triplets [[2,5,3],[2,3,4],[2,5,5],[5,2,3]]. Update the fourth triplet to be [max(2,5), max(5,2), max(5,3)] = [5,5,5]. triplets = [[2,5,3],[2,3,4],[2,5,5],[5,5,5]].
    The target triplet [5,5,5] is now an element of triplets.
    """
def earliestAndLatest(n: int, firstPlayer: int, secondPlayer: int) -> List[int]:
    """
    There is a tournament where n players are participating. The players are standing in a single row and are numbered from 1 to n based on their initial standing position (player 1 is the first player in the row, player 2 is the second player in the row, etc.).
    The tournament consists of multiple rounds (starting from round number 1). In each round, the ith player from the front of the row competes against the ith player from the end of the row, and the winner advances to the next round. When the number of players is odd for the current round, the player in the middle automatically advances to the next round.
    
    For example, if the row consists of players 1, 2, 4, 6, 7
    
    Player 1 competes against player 7.
    Player 2 competes against player 6.
    Player 4 automatically advances to the next round.
    
    
    
    After each round is over, the winners are lined back up in the row based on the original ordering assigned to them initially (ascending order).
    The players numbered firstPlayer and secondPlayer are the best in the tournament. They can win against any other player before they compete against each other. If any two other players compete against each other, either of them might win, and thus you may choose the outcome of this round.
    Given the integers n, firstPlayer, and secondPlayer, return an integer array containing two values, the earliest possible round number and the latest possible round number in which these two players will compete against each other, respectively.
    
    Example 1:
    
    >>> earliestAndLatest(n = 11, firstPlayer = 2, secondPlayer = 4)
    >>> [3,4]
    Explanation:
    One possible scenario which leads to the earliest round number:
    First round: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11
    Second round: 2, 3, 4, 5, 6, 11
    Third round: 2, 3, 4
    One possible scenario which leads to the latest round number:
    First round: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11
    Second round: 1, 2, 3, 4, 5, 6
    Third round: 1, 2, 4
    Fourth round: 2, 4
    
    Example 2:
    
    >>> earliestAndLatest(n = 5, firstPlayer = 1, secondPlayer = 5)
    >>> [1,1]
    Explanation: The players numbered 1 and 5 compete in the first round.
    There is no way to make them compete in any other round.
    """
def findPeakGrid(mat: List[List[int]]) -> List[int]:
    """
    A peak element in a 2D grid is an element that is strictly greater than all of its adjacent neighbors to the left, right, top, and bottom.
    Given a 0-indexed m x n matrix mat where no two adjacent cells are equal, find any peak element mat[i][j] and return the length 2 array [i,j].
    You may assume that the entire matrix is surrounded by an outer perimeter with the value -1 in each cell.
    You must write an algorithm that runs in O(m log(n)) or O(n log(m)) time.
    
    Example 1:
    
    
    >>> findPeakGrid(mat = [[1,4],[3,2]])
    >>> [0,1]
    Explanation: Both 3 and 4 are peak elements so [1,0] and [0,1] are both acceptable answers.
    
    Example 2:
    
    
    >>> findPeakGrid(mat = [[10,20,15],[21,30,14],[7,16,32]])
    >>> [1,1]
    Explanation: Both 30 and 32 are peak elements so [1,1] and [2,2] are both acceptable answers.
    """
def maxDepthBST(order: List[int]) -> int:
    """
    You are given a 0-indexed integer array order of length n, a permutation of integers from 1 to n representing the order of insertion into a binary search tree.
    A binary search tree is defined as follows:
    
    The left subtree of a node contains only nodes with keys less than the node's key.
    The right subtree of a node contains only nodes with keys greater than the node's key.
    Both the left and right subtrees must also be binary search trees.
    
    The binary search tree is constructed as follows:
    
    order[0] will be the root of the binary search tree.
    All subsequent elements are inserted as the child of any existing node such that the binary search tree properties hold.
    
    Return the depth of the binary search tree.
    A binary tree's depth is the number of nodes along the longest path from the root node down to the farthest leaf node.
    
    Example 1:
    
    
    >>> maxDepthBST(order = [2,1,4,3])
    >>> 3
    Explanation: The binary search tree has a depth of 3 with path 2->3->4.
    
    Example 2:
    
    
    >>> maxDepthBST(order = [2,1,3,4])
    >>> 3
    Explanation: The binary search tree has a depth of 3 with path 2->3->4.
    
    Example 3:
    
    
    >>> maxDepthBST(order = [1,2,3,4])
    >>> 4
    Explanation: The binary search tree has a depth of 4 with path 1->2->3->4.
    """
def largestOddNumber(num: str) -> str:
    """
    You are given a string num, representing a large integer. Return the largest-valued odd integer (as a string) that is a non-empty substring of num, or an empty string "" if no odd integer exists.
    A substring is a contiguous sequence of characters within a string.
    
    Example 1:
    
    >>> largestOddNumber(num = "52")
    >>> "5"
    Explanation: The only non-empty substrings are "5", "2", and "52". "5" is the only odd number.
    
    Example 2:
    
    >>> largestOddNumber(num = "4206")
    >>> ""
    Explanation: There are no odd numbers in "4206".
    
    Example 3:
    
    >>> largestOddNumber(num = "35427")
    >>> "35427"
    Explanation: "35427" is already an odd number.
    """
def numberOfRounds(loginTime: str, logoutTime: str) -> int:
    """
    You are participating in an online chess tournament. There is a chess round that starts every 15 minutes. The first round of the day starts at 00:00, and after every 15 minutes, a new round starts.
    
    For example, the second round starts at 00:15, the fourth round starts at 00:45, and the seventh round starts at 01:30.
    
    You are given two strings loginTime and logoutTime where:
    
    loginTime is the time you will login to the game, and
    logoutTime is the time you will logout from the game.
    
    If logoutTime is earlier than loginTime, this means you have played from loginTime to midnight and from midnight to logoutTime.
    Return the number of full chess rounds you have played in the tournament.
    Note: All the given times follow the 24-hour clock. That means the first round of the day starts at 00:00 and the last round of the day starts at 23:45.
    
    Example 1:
    
    >>> numberOfRounds(loginTime = "09:31", logoutTime = "10:14")
    >>> 1
    Explanation: You played one full round from 09:45 to 10:00.
    You did not play the full round from 09:30 to 09:45 because you logged in at 09:31 after it began.
    You did not play the full round from 10:00 to 10:15 because you logged out at 10:14 before it ended.
    
    Example 2:
    
    >>> numberOfRounds(loginTime = "21:30", logoutTime = "03:00")
    >>> 22
    Explanation: You played 10 full rounds from 21:30 to 00:00 and 12 full rounds from 00:00 to 03:00.
    10 + 12 = 22.
    """
def countSubIslands(grid1: List[List[int]], grid2: List[List[int]]) -> int:
    """
    You are given two m x n binary matrices grid1 and grid2 containing only 0's (representing water) and 1's (representing land). An island is a group of 1's connected 4-directionally (horizontal or vertical). Any cells outside of the grid are considered water cells.
    An island in grid2 is considered a sub-island if there is an island in grid1 that contains all the cells that make up this island in grid2.
    Return the number of islands in grid2 that are considered sub-islands.
    
    Example 1:
    
    
    >>> countSubIslands(grid1 = [[1,1,1,0,0],[0,1,1,1,1],[0,0,0,0,0],[1,0,0,0,0],[1,1,0,1,1]], grid2 = [[1,1,1,0,0],[0,0,1,1,1],[0,1,0,0,0],[1,0,1,1,0],[0,1,0,1,0]])
    >>> 3
    Explanation: In the picture above, the grid on the left is grid1 and the grid on the right is grid2.
    The 1s colored red in grid2 are those considered to be part of a sub-island. There are three sub-islands.
    
    Example 2:
    
    
    >>> countSubIslands(grid1 = [[1,0,1,0,1],[1,1,1,1,1],[0,0,0,0,0],[1,1,1,1,1],[1,0,1,0,1]], grid2 = [[0,0,0,0,0],[1,1,1,1,1],[0,1,0,1,0],[0,1,0,1,0],[1,0,0,0,1]])
    >>> 2
    Explanation: In the picture above, the grid on the left is grid1 and the grid on the right is grid2.
    The 1s colored red in grid2 are those considered to be part of a sub-island. There are two sub-islands.
    """
def minDifference(nums: List[int], queries: List[List[int]]) -> List[int]:
    """
    The minimum absolute difference of an array a is defined as the minimum value of |a[i] - a[j]|, where 0 <= i < j < a.length and a[i] != a[j]. If all elements of a are the same, the minimum absolute difference is -1.
    
    For example, the minimum absolute difference of the array [5,2,3,7,2] is |2 - 3| = 1. Note that it is not 0 because a[i] and a[j] must be different.
    
    You are given an integer array nums and the array queries where queries[i] = [li, ri]. For each query i, compute the minimum absolute difference of the subarray nums[li...ri] containing the elements of nums between the 0-based indices li and ri (inclusive).
    Return an array ans where ans[i] is the answer to the ith query.
    A subarray is a contiguous sequence of elements in an array.
    The value of |x| is defined as:
    
    x if x >= 0.
    -x if x < 0.
    
    
    Example 1:
    
    >>> minDifference(nums = [1,3,4,8], queries = [[0,1],[1,2],[2,3],[0,3]])
    >>> [2,1,4,1]
    Explanation: The queries are processed as follows:
    - queries[0] = [0,1]: The subarray is [1,3] and the minimum absolute difference is |1-3| = 2.
    - queries[1] = [1,2]: The subarray is [3,4] and the minimum absolute difference is |3-4| = 1.
    - queries[2] = [2,3]: The subarray is [4,8] and the minimum absolute difference is |4-8| = 4.
    - queries[3] = [0,3]: The subarray is [1,3,4,8] and the minimum absolute difference is |3-4| = 1.
    
    Example 2:
    
    >>> minDifference(nums = [4,5,2,2,7,10], queries = [[2,3],[0,2],[0,5],[3,5]])
    >>> [-1,1,1,3]
    Explanation: The queries are processed as follows:
    - queries[0] = [2,3]: The subarray is [2,2] and the minimum absolute difference is -1 because all the
      elements are the same.
    - queries[1] = [0,2]: The subarray is [4,5,2] and the minimum absolute difference is |4-5| = 1.
    - queries[2] = [0,5]: The subarray is [4,5,2,2,7,10] and the minimum absolute difference is |4-5| = 1.
    - queries[3] = [3,5]: The subarray is [2,7,10] and the minimum absolute difference is |7-10| = 3.
    """
def nimGame(piles: List[int]) -> bool:
    """
    Alice and Bob take turns playing a game with Alice starting first.
    In this game, there are n piles of stones. On each player's turn, the player should remove any positive number of stones from a non-empty pile of his or her choice. The first player who cannot make a move loses, and the other player wins.
    Given an integer array piles, where piles[i] is the number of stones in the ith pile, return true if Alice wins, or false if Bob wins.
    Both Alice and Bob play optimally.
    
    Example 1:
    
    >>> nimGame(piles = [1])
    >>> true
    Explanation: There is only one possible scenario:
    - On the first turn, Alice removes one stone from the first pile. piles = [0].
    - On the second turn, there are no stones left for Bob to remove. Alice wins.
    
    Example 2:
    
    >>> nimGame(piles = [1,1])
    >>> false
    Explanation: It can be proven that Bob will always win. One possible scenario is:
    - On the first turn, Alice removes one stone from the first pile. piles = [0,1].
    - On the second turn, Bob removes one stone from the second pile. piles = [0,0].
    - On the third turn, there are no stones left for Alice to remove. Bob wins.
    
    Example 3:
    
    >>> nimGame(piles = [1,2,3])
    >>> false
    Explanation: It can be proven that Bob will always win. One possible scenario is:
    - On the first turn, Alice removes three stones from the third pile. piles = [1,2,0].
    - On the second turn, Bob removes one stone from the second pile. piles = [1,1,0].
    - On the third turn, Alice removes one stone from the first pile. piles = [0,1,0].
    - On the fourth turn, Bob removes one stone from the second pile. piles = [0,0,0].
    - On the fifth turn, there are no stones left for Alice to remove. Bob wins.
    """
def canBeIncreasing(nums: List[int]) -> bool:
    """
    Given a 0-indexed integer array nums, return true if it can be made strictly increasing after removing exactly one element, or false otherwise. If the array is already strictly increasing, return true.
    The array nums is strictly increasing if nums[i - 1] < nums[i] for each index (1 <= i < nums.length).
    
    Example 1:
    
    >>> canBeIncreasing(nums = [1,2,10,5,7])
    >>> true
    Explanation: By removing 10 at index 2 from nums, it becomes [1,2,5,7].
    [1,2,5,7] is strictly increasing, so return true.
    
    Example 2:
    
    >>> canBeIncreasing(nums = [2,3,1,2])
    >>> false
    Explanation:
    [3,1,2] is the result of removing the element at index 0.
    [2,1,2] is the result of removing the element at index 1.
    [2,3,2] is the result of removing the element at index 2.
    [2,3,1] is the result of removing the element at index 3.
    No resulting array is strictly increasing, so return false.
    Example 3:
    
    >>> canBeIncreasing(nums = [1,1,1])
    >>> false
    Explanation: The result of removing any element is [1,1].
    [1,1] is not strictly increasing, so return false.
    """
def removeOccurrences(s: str, part: str) -> str:
    """
    Given two strings s and part, perform the following operation on s until all occurrences of the substring part are removed:
    
    Find the leftmost occurrence of the substring part and remove it from s.
    
    Return s after removing all occurrences of part.
    A substring is a contiguous sequence of characters in a string.
    
    Example 1:
    
    >>> removeOccurrences(s = "daabcbaabcbc", part = "abc")
    >>> "dab"
    Explanation: The following operations are done:
    - s = "daabcbaabcbc", remove "abc" starting at index 2, so s = "dabaabcbc".
    - s = "dabaabcbc", remove "abc" starting at index 4, so s = "dababc".
    - s = "dababc", remove "abc" starting at index 3, so s = "dab".
    Now s has no occurrences of "abc".
    
    Example 2:
    
    >>> removeOccurrences(s = "axxxxyyyyb", part = "xy")
    >>> "ab"
    Explanation: The following operations are done:
    - s = "axxxxyyyyb", remove "xy" starting at index 4 so s = "axxxyyyb".
    - s = "axxxyyyb", remove "xy" starting at index 3 so s = "axxyyb".
    - s = "axxyyb", remove "xy" starting at index 2 so s = "axyb".
    - s = "axyb", remove "xy" starting at index 1 so s = "ab".
    Now s has no occurrences of "xy".
    """
def maxAlternatingSum(nums: List[int]) -> int:
    """
    The alternating sum of a 0-indexed array is defined as the sum of the elements at even indices minus the sum of the elements at odd indices.\r
    \r
    \r
    	For example, the alternating sum of [4,2,5,3] is (4 + 5) - (2 + 3) = 4.\r
    \r
    \r
    Given an array nums, return the maximum alternating sum of any subsequence of nums (after reindexing the elements of the subsequence).\r
    \r
    \r
    \r
    \r
    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.\r
    \r
     \r
    Example 1:\r
    \r
    \r
    >>> maxAlternatingSum(nums = [4,2,5,3]\r)
    >>> 7\r
    Explanation: It is optimal to choose the subsequence [4,2,5] with alternating sum (4 + 5) - 2 = 7.\r
    \r
    \r
    Example 2:\r
    \r
    \r
    >>> maxAlternatingSum(nums = [5,6,7,8]\r)
    >>> 8\r
    Explanation: It is optimal to choose the subsequence [8] with alternating sum 8.\r
    \r
    \r
    Example 3:\r
    \r
    \r
    >>> maxAlternatingSum(nums = [6,2,1,2,4,5]\r)
    >>> 10\r
    Explanation: It is optimal to choose the subsequence [6,1,5] with alternating sum (6 + 5) - 1 = 10.\r
    \r
    \r
     \r
    """
def maxProductDifference(nums: List[int]) -> int:
    """
    The product difference between two pairs (a, b) and (c, d) is defined as (a * b) - (c * d).\r
    \r
    \r
    	For example, the product difference between (5, 6) and (2, 7) is (5 * 6) - (2 * 7) = 16.\r
    \r
    \r
    Given an integer array nums, choose four distinct indices w, x, y, and z such that the product difference between pairs (nums[w], nums[x]) and (nums[y], nums[z]) is maximized.\r
    \r
    Return the maximum such product difference.\r
    \r
     \r
    Example 1:\r
    \r
    \r
    >>> maxProductDifference(nums = [5,6,2,7,4]\r)
    >>> 34\r
    Explanation: We can choose indices 1 and 3 for the first pair (6, 7) and indices 2 and 4 for the second pair (2, 4).\r
    The product difference is (6 * 7) - (2 * 4) = 34.\r
    \r
    \r
    Example 2:\r
    \r
    \r
    >>> maxProductDifference(nums = [4,2,5,9,7,4,8]\r)
    >>> 64\r
    Explanation: We can choose indices 3 and 6 for the first pair (9, 8) and indices 1 and 5 for the second pair (2, 4).\r
    The product difference is (9 * 8) - (2 * 4) = 64.\r
    \r
    \r
     \r
    """
def rotateGrid(grid: List[List[int]], k: int) -> List[List[int]]:
    """
    You are given an m x n integer matrix grid​​​, where m and n are both even integers, and an integer k.\r
    \r
    The matrix is composed of several layers, which is shown in the below image, where each color is its own layer:\r
    \r
    \r
    \r
    A cyclic rotation of the matrix is done by cyclically rotating each layer in the matrix. To cyclically rotate a layer once, each element in the layer will take the place of the adjacent element in the counter-clockwise direction. An example rotation is shown below:\r
    \r
    Return the matrix after applying k cyclic rotations to it.\r
    \r
     \r
    Example 1:\r
    \r
    \r
    >>> rotateGrid(grid = [[40,10],[30,20]], k = 1\r)
    >>> [[10,20],[40,30]]\r
    Explanation: The figures above represent the grid at every state.\r
    \r
    \r
    Example 2:\r
      \r
    \r
    \r
    >>> rotateGrid(grid = [[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]], k = 2\r)
    >>> [[3,4,8,12],[2,11,10,16],[1,7,6,15],[5,9,13,14]]\r
    Explanation: The figures above represent the grid at every state.\r
    \r
    \r
     \r
    """
def wonderfulSubstrings(word: str) -> int:
    """
    A wonderful string is a string where at most one letter appears an odd number of times.\r
    \r
    \r
    	For example, "ccjjc" and "abab" are wonderful, but "ab" is not.\r
    \r
    \r
    Given a string word that consists of the first ten lowercase English letters ('a' through 'j'), return the number of wonderful non-empty substrings in word. If the same substring appears multiple times in word, then count each occurrence separately.\r
    \r
    A substring is a contiguous sequence of characters in a string.\r
    \r
     \r
    Example 1:\r
    \r
    \r
    >>> wonderfulSubstrings(word = "aba"\r)
    >>> 4\r
    Explanation: The four wonderful substrings are underlined below:\r
    - "aba" -> "a"\r
    - "aba" -> "b"\r
    - "aba" -> "a"\r
    - "aba" -> "aba"\r
    \r
    \r
    Example 2:\r
    \r
    \r
    >>> wonderfulSubstrings(word = "aabb"\r)
    >>> 9\r
    Explanation: The nine wonderful substrings are underlined below:\r
    - "aabb" -> "a"\r
    - "aabb" -> "aa"\r
    - "aabb" -> "aab"\r
    - "aabb" -> "aabb"\r
    - "aabb" -> "a"\r
    - "aabb" -> "abb"\r
    - "aabb" -> "b"\r
    - "aabb" -> "bb"\r
    - "aabb" -> "b"\r
    \r
    \r
    Example 3:\r
    \r
    \r
    >>> wonderfulSubstrings(word = "he"\r)
    >>> 2\r
    Explanation: The two wonderful substrings are underlined below:\r
    - "he" -> "h"\r
    - "he" -> "e"\r
    \r
    \r
     \r
    """
def waysToBuildRooms(prevRoom: List[int]) -> int:
    """
    You are an ant tasked with adding n new rooms numbered 0 to n-1 to your colony. You are given the expansion plan as a 0-indexed integer array of length n, prevRoom, where prevRoom[i] indicates that you must build room prevRoom[i] before building room i, and these two rooms must be connected directly. Room 0 is already built, so prevRoom[0] = -1. The expansion plan is given such that once all the rooms are built, every room will be reachable from room 0.\r
    \r
    You can only build one room at a time, and you can travel freely between rooms you have already built only if they are connected. You can choose to build any room as long as its previous room is already built.\r
    \r
    Return the number of different orders you can build all the rooms in. Since the answer may be large, return it modulo 109 + 7.\r
    \r
     \r
    Example 1:\r
    \r
    \r
    >>> waysToBuildRooms(prevRoom = [-1,0,1]\r)
    >>> 1\r
    Explanation: There is only one way to build the additional rooms: 0 → 1 → 2\r
    \r
    \r
    Example 2:\r
    \r
    \r
    \r
    >>> waysToBuildRooms(prevRoom = [-1,0,0,1,2]\r)
    >>> 6\r
    Explanation:\r
    The 6 ways are:\r
    0 → 1 → 3 → 2 → 4\r
    0 → 2 → 4 → 1 → 3\r
    0 → 1 → 2 → 3 → 4\r
    0 → 1 → 2 → 4 → 3\r
    0 → 2 → 1 → 3 → 4\r
    0 → 2 → 1 → 4 → 3\r
    \r
    \r
     \r
    """