Prompt:
from typing import List
def mergeStones(stones: List[int], k: int) -> int:
    """
    There are n piles of stones arranged in a row. The ith pile has stones[i] stones.
    A move consists of merging exactly k consecutive piles into one pile, and the cost of this move is equal to the total number of stones in these k piles.
    Return the minimum cost to merge all piles of stones into one pile. If it is impossible, return -1.

    Example 1:

    >>> mergeStones(stones = [3,2,4,1], k = 2)
    >>> 20
    Explanation: We start with [3, 2, 4, 1].
    We merge [3, 2] for a cost of 5, and we are left with [5, 4, 1].
    We merge [4, 1] for a cost of 5, and we are left with [5, 5].
    We merge [5, 5] for a cost of 10, and we are left with [10].
    The total cost was 20, and this is the minimum possible.

    Example 2:

    >>> mergeStones(stones = [3,2,4,1], k = 3)
    >>> -1
    Explanation: After any merge operation, there are 2 piles left, and we can't merge anymore.  So the task is impossible.

    Example 3:

    >>> mergeStones(stones = [3,5,1,2,6], k = 3)
    >>> 25
    Explanation: We start with [3, 5, 1, 2, 6].
    We merge [5, 1, 2] for a cost of 8, and we are left with [3, 8, 6].
    We merge [3, 8, 6] for a cost of 17, and we are left with [17].
    The total cost was 25, and this is the minimum possible.
    """


Prompt:
from typing import List
def gridIllumination(n: int, lamps: List[List[int]], queries: List[List[int]]) -> List[int]:
    """
    There is a 2D grid of size n x n where each cell of this grid has a lamp that is initially turned off.
    You are given a 2D array of lamp positions lamps, where lamps[i] = [rowi, coli] indicates that the lamp at grid[rowi][coli] is turned on. Even if the same lamp is listed more than once, it is turned on.
    When a lamp is turned on, it illuminates its cell and all other cells in the same row, column, or diagonal.
    You are also given another 2D array queries, where queries[j] = [rowj, colj]. For the jth query, determine whether grid[rowj][colj] is illuminated or not. After answering the jth query, turn off the lamp at grid[rowj][colj] and its 8 adjacent lamps if they exist. A lamp is adjacent if its cell shares either a side or corner with grid[rowj][colj].
    Return an array of integers ans, where ans[j] should be 1 if the cell in the jth query was illuminated, or 0 if the lamp was not.

    Example 1:

    >>> gridIllumination(n = 5, lamps = [[0,0],[4,4]], queries = [[1,1],[1,0]])
    >>> [1,0]
    Explanation: We have the initial grid with all lamps turned off. In the above picture we see the grid after turning on the lamp at grid[0][0] then turning on the lamp at grid[4][4].
    The 0th query asks if the lamp at grid[1][1] is illuminated or not (the blue square). It is illuminated, so set ans[0] = 1. Then, we turn off all lamps in the red square.

    The 1st query asks if the lamp at grid[1][0] is illuminated or not (the blue square). It is not illuminated, so set ans[1] = 0. Then, we turn off all lamps in the red rectangle.

    Example 2:

    >>> gridIllumination(n = 5, lamps = [[0,0],[4,4]], queries = [[1,1],[1,1]])
    >>> [1,1]

    Example 3:

    >>> gridIllumination(n = 5, lamps = [[0,0],[0,4]], queries = [[0,4],[0,1],[1,4]])
    >>> [1,1,0]
    """


Prompt:
from typing import List
def commonChars(words: List[str]) -> List[str]:
    """
    Given a string array words, return an array of all characters that show up in all strings within the words (including duplicates). You may return the answer in any order.

    Example 1:
    >>> commonChars(words = ["bella","label","roller"])
    >>> ["e","l","l"]
    Example 2:
    >>> commonChars(words = ["cool","lock","cook"])
    >>> ["c","o"]
    """


Prompt:
def isValid(s: str) -> bool:
    """
    Given a string s, determine if it is valid.
    A string s is valid if, starting with an empty string t = "", you can transform t into s after performing the following operation any number of times:

    Insert string "abc" into any position in t. More formally, t becomes tleft + "abc" + tright, where t == tleft + tright. Note that tleft and tright may be empty.

    Return true if s is a valid string, otherwise, return false.

    Example 1:

    >>> isValid(s = "aabcbc")
    >>> true
    Explanation:
    "" -> "abc" -> "aabcbc"
    Thus, "aabcbc" is valid.
    Example 2:

    >>> isValid(s = "abcabcababcc")
    >>> true
    Explanation:
    "" -> "abc" -> "abcabc" -> "abcabcabc" -> "abcabcababcc"
    Thus, "abcabcababcc" is valid.

    Example 3:

    >>> isValid(s = "abccba")
    >>> false
    Explanation: It is impossible to get "abccba" using the operation.
    """


Prompt:
from typing import List
def longestOnes(nums: List[int], k: int) -> int:
    """
    Given a binary array nums and an integer k, return the maximum number of consecutive 1's in the array if you can flip at most k 0's.

    Example 1:

    >>> longestOnes(nums = [1,1,1,0,0,0,1,1,1,1,0], k = 2)
    >>> 6
    Explanation: [1,1,1,0,0,1,1,1,1,1,1]
    Bolded numbers were flipped from 0 to 1. The longest subarray is underlined.
    Example 2:

    >>> longestOnes(nums = [0,0,1,1,0,0,1,1,1,0,1,1,0,0,0,1,1,1,1], k = 3)
    >>> 10
    Explanation: [0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,1,1,1,1]
    Bolded numbers were flipped from 0 to 1. The longest subarray is underlined.
    """


Prompt:
from typing import List
def largestSumAfterKNegations(nums: List[int], k: int) -> int:
    """
    Given an integer array nums and an integer k, modify the array in the following way:

    choose an index i and replace nums[i] with -nums[i].

    You should apply this process exactly k times. You may choose the same index i multiple times.
    Return the largest possible sum of the array after modifying it in this way.

    Example 1:

    >>> largestSumAfterKNegations(nums = [4,2,3], k = 1)
    >>> 5
    Explanation: Choose index 1 and nums becomes [4,-2,3].

    Example 2:

    >>> largestSumAfterKNegations(nums = [3,-1,0,2], k = 3)
    >>> 6
    Explanation: Choose indices (1, 2, 2) and nums becomes [3,1,0,2].

    Example 3:

    >>> largestSumAfterKNegations(nums = [2,-3,-1,5,-4], k = 2)
    >>> 13
    Explanation: Choose indices (1, 4) and nums becomes [2,3,-1,5,4].
    """


Prompt:
def clumsy(n: int) -> int:
    """
    The factorial of a positive integer n is the product of all positive integers less than or equal to n.

    For example, factorial(10) = 10 * 9 * 8 * 7 * 6 * 5 * 4 * 3 * 2 * 1.

    We make a clumsy factorial using the integers in decreasing order by swapping out the multiply operations for a fixed rotation of operations with multiply '*', divide '/', add '+', and subtract '-' in this order.

    For example, clumsy(10) = 10 * 9 / 8 + 7 - 6 * 5 / 4 + 3 - 2 * 1.

    However, these operations are still applied using the usual order of operations of arithmetic. We do all multiplication and division steps before any addition or subtraction steps, and multiplication and division steps are processed left to right.
    Additionally, the division that we use is floor division such that 10 * 9 / 8 = 90 / 8 = 11.
    Given an integer n, return the clumsy factorial of n.

    Example 1:

    >>> clumsy(n = 4)
    >>> 7
    Explanation: 7 = 4 * 3 / 2 + 1

    Example 2:

    >>> clumsy(n = 10)
    >>> 12
    Explanation: 12 = 10 * 9 / 8 + 7 - 6 * 5 / 4 + 3 - 2 * 1
    """


Prompt:
from typing import List
def minDominoRotations(tops: List[int], bottoms: List[int]) -> int:
    """
    In a row of dominoes, tops[i] and bottoms[i] represent the top and bottom halves of the ith domino. (A domino is a tile with two numbers from 1 to 6 - one on each half of the tile.)
    We may rotate the ith domino, so that tops[i] and bottoms[i] swap values.
    Return the minimum number of rotations so that all the values in tops are the same, or all the values in bottoms are the same.
    If it cannot be done, return -1.

    Example 1:

    >>> minDominoRotations(tops = [2,1,2,4,2,2], bottoms = [5,2,6,2,3,2])
    >>> 2
    Explanation:
    The first figure represents the dominoes as given by tops and bottoms: before we do any rotations.
    If we rotate the second and fourth dominoes, we can make every value in the top row equal to 2, as indicated by the second figure.

    Example 2:

    >>> minDominoRotations(tops = [3,5,1,2,3], bottoms = [3,6,3,3,4])
    >>> -1
    Explanation:
    In this case, it is not possible to rotate the dominoes to make one row of values equal.
    """


Prompt:
from typing import List, Optional
class TreeNode:
    def __init__(val=0, left=None, right=None):
        self.val = val
        self.left = left
        self.right = right
def bstFromPreorder(preorder: List[int]) -> Optional[TreeNode]:
"""
Given an array of integers preorder, which represents the preorder traversal of a BST (i.e., binary search tree), construct the tree and return its root.
It is guaranteed that there is always possible to find a binary search tree with the given requirements for the given test cases.
A binary search tree is a binary tree where for every node, any descendant of Node.left has a value strictly less than Node.val, and any descendant of Node.right has a value strictly greater than Node.val.
A preorder traversal of a binary tree displays the value of the node first, then traverses Node.left, then traverses Node.right.

Example 1:

>>> bstFromPreorder(preorder = [8,5,1,7,10,12])
>>> [8,5,10,1,7,null,12]

Example 2:

>>> bstFromPreorder(preorder = [1,3])
>>> [1,null,3]
"""


Prompt:
def bitwiseComplement(n: int) -> int:
    """
    The complement of an integer is the integer you get when you flip all the 0's to 1's and all the 1's to 0's in its binary representation.

    For example, The integer 5 is "101" in binary and its complement is "010" which is the integer 2.

    Given an integer n, return its complement.

    Example 1:

    >>> bitwiseComplement(n = 5)
    >>> 2
    Explanation: 5 is "101" in binary, with complement "010" in binary, which is 2 in base-10.

    Example 2:

    >>> bitwiseComplement(n = 7)
    >>> 0
    Explanation: 7 is "111" in binary, with complement "000" in binary, which is 0 in base-10.

    Example 3:

    >>> bitwiseComplement(n = 10)
    >>> 5
    Explanation: 10 is "1010" in binary, with complement "0101" in binary, which is 5 in base-10.
    """


Prompt:
from typing import List
def numPairsDivisibleBy60(time: List[int]) -> int:
    """
    You are given a list of songs where the ith song has a duration of time[i] seconds.
    Return the number of pairs of songs for which their total duration in seconds is divisible by 60. Formally, we want the number of indices i, j such that i < j with (time[i] + time[j]) % 60 == 0.

    Example 1:

    >>> numPairsDivisibleBy60(time = [30,20,150,100,40])
    >>> 3
    Explanation: Three pairs have a total duration divisible by 60:
    (time[0] = 30, time[2] = 150): total duration 180
    (time[1] = 20, time[3] = 100): total duration 120
    (time[1] = 20, time[4] = 40): total duration 60

    Example 2:

    >>> numPairsDivisibleBy60(time = [60,60,60])
    >>> 3
    Explanation: All three pairs have a total duration of 120, which is divisible by 60.
    """


Prompt:
from typing import List
def shipWithinDays(weights: List[int], days: int) -> int:
    """
    A conveyor belt has packages that must be shipped from one port to another within days days.
    The ith package on the conveyor belt has a weight of weights[i]. Each day, we load the ship with packages on the conveyor belt (in the order given by weights). We may not load more weight than the maximum weight capacity of the ship.
    Return the least weight capacity of the ship that will result in all the packages on the conveyor belt being shipped within days days.

    Example 1:

    >>> shipWithinDays(weights = [1,2,3,4,5,6,7,8,9,10], days = 5)
    >>> 15
    Explanation: A ship capacity of 15 is the minimum to ship all the packages in 5 days like this:
    1st day: 1, 2, 3, 4, 5
    2nd day: 6, 7
    3rd day: 8
    4th day: 9
    5th day: 10

    Note that the cargo must be shipped in the order given, so using a ship of capacity 14 and splitting the packages into parts like (2, 3, 4, 5), (1, 6, 7), (8), (9), (10) is not allowed.

    Example 2:

    >>> shipWithinDays(weights = [3,2,2,4,1,4], days = 3)
    >>> 6
    Explanation: A ship capacity of 6 is the minimum to ship all the packages in 3 days like this:
    1st day: 3, 2
    2nd day: 2, 4
    3rd day: 1, 4

    Example 3:

    >>> shipWithinDays(weights = [1,2,3,1,1], days = 4)
    >>> 3
    Explanation:
    1st day: 1
    2nd day: 2
    3rd day: 3
    4th day: 1, 1
    """


Prompt:
def numDupDigitsAtMostN(n: int) -> int:
    """
    Given an integer n, return the number of positive integers in the range [1, n] that have at least one repeated digit.

    Example 1:

    >>> numDupDigitsAtMostN(n = 20)
    >>> 1
    Explanation: The only positive number (<= 20) with at least 1 repeated digit is 11.

    Example 2:

    >>> numDupDigitsAtMostN(n = 100)
    >>> 10
    Explanation: The positive numbers (<= 100) with atleast 1 repeated digit are 11, 22, 33, 44, 55, 66, 77, 88, 99, and 100.

    Example 3:

    >>> numDupDigitsAtMostN(n = 1000)
    >>> 262
    """


Prompt:
from typing import List
def canThreePartsEqualSum(arr: List[int]) -> bool:
    """
    Given an array of integers arr, return true if we can partition the array into three non-empty parts with equal sums.
    Formally, we can partition the array if we can find indexes i + 1 < j with (arr[0] + arr[1] + ... + arr[i] == arr[i + 1] + arr[i + 2] + ... + arr[j - 1] == arr[j] + arr[j + 1] + ... + arr[arr.length - 1])

    Example 1:

    >>> canThreePartsEqualSum(arr = [0,2,1,-6,6,-7,9,1,2,0,1])
    >>> true
    Explanation: 0 + 2 + 1 = -6 + 6 - 7 + 9 + 1 = 2 + 0 + 1

    Example 2:

    >>> canThreePartsEqualSum(arr = [0,2,1,-6,6,7,9,-1,2,0,1])
    >>> false

    Example 3:

    >>> canThreePartsEqualSum(arr = [3,3,6,5,-2,2,5,1,-9,4])
    >>> true
    Explanation: 3 + 3 = 6 = 5 - 2 + 2 + 5 + 1 - 9 + 4
    """


Prompt:
from typing import List
def maxScoreSightseeingPair(values: List[int]) -> int:
    """
    You are given an integer array values where values[i] represents the value of the ith sightseeing spot. Two sightseeing spots i and j have a distance j - i between them.
    The score of a pair (i < j) of sightseeing spots is values[i] + values[j] + i - j: the sum of the values of the sightseeing spots, minus the distance between them.
    Return the maximum score of a pair of sightseeing spots.

    Example 1:

    >>> maxScoreSightseeingPair(values = [8,1,5,2,6])
    >>> 11
    Explanation: i = 0, j = 2, values[i] + values[j] + i - j = 8 + 5 + 0 - 2 = 11

    Example 2:

    >>> maxScoreSightseeingPair(values = [1,2])
    >>> 2
    """


Prompt:
def smallestRepunitDivByK(k: int) -> int:
    """
    Given a positive integer k, you need to find the length of the smallest positive integer n such that n is divisible by k, and n only contains the digit 1.
    Return the length of n. If there is no such n, return -1.
    Note: n may not fit in a 64-bit signed integer.

    Example 1:

    >>> smallestRepunitDivByK(k = 1)
    >>> 1
    Explanation: The smallest answer is n = 1, which has length 1.

    Example 2:

    >>> smallestRepunitDivByK(k = 2)
    >>> -1
    Explanation: There is no such positive integer n divisible by 2.

    Example 3:

    >>> smallestRepunitDivByK(k = 3)
    >>> 3
    Explanation: The smallest answer is n = 111, which has length 3.
    """


Prompt:
def queryString(s: str, n: int) -> bool:
    """
    Given a binary string s and a positive integer n, return true if the binary representation of all the integers in the range [1, n] are substrings of s, or false otherwise.
    A substring is a contiguous sequence of characters within a string.

    Example 1:
    >>> queryString(s = "0110", n = 3)
    >>> true
    Example 2:
    >>> queryString(s = "0110", n = 4)
    >>> false
    """


Prompt:
def baseNeg2(n: int) -> str:
    """
    Given an integer n, return a binary string representing its representation in base -2.
    Note that the returned string should not have leading zeros unless the string is "0".

    Example 1:

    >>> baseNeg2(n = 2)
    >>> "110"
    Explantion: (-2)2 + (-2)1 = 2

    Example 2:

    >>> baseNeg2(n = 3)
    >>> "111"
    Explantion: (-2)2 + (-2)1 + (-2)0 = 3

    Example 3:

    >>> baseNeg2(n = 4)
    >>> "100"
    Explantion: (-2)2 = 4
    """


Prompt:
from typing import List
def prefixesDivBy5(nums: List[int]) -> List[bool]:
    """
    You are given a binary array nums (0-indexed).
    We define xi as the number whose binary representation is the subarray nums[0..i] (from most-significant-bit to least-significant-bit).

    For example, if nums = [1,0,1], then x0 = 1, x1 = 2, and x2 = 5.

    Return an array of booleans answer where answer[i] is true if xi is divisible by 5.

    Example 1:

    >>> prefixesDivBy5(nums = [0,1,1])
    >>> [true,false,false]
    Explanation: The input numbers in binary are 0, 01, 011; which are 0, 1, and 3 in base-10.
    Only the first number is divisible by 5, so answer[0] is true.

    Example 2:

    >>> prefixesDivBy5(nums = [1,1,1])
    >>> [false,false,false]
    """


Prompt:
from typing import List, Optional
class ListNode:
    def __init__(val=0, next=None):
        self.val = val
        self.next = next
def nextLargerNodes(head: Optional[ListNode]) -> List[int]:
"""
You are given the head of a linked list with n nodes.
For each node in the list, find the value of the next greater node. That is, for each node, find the value of the first node that is next to it and has a strictly larger value than it.
Return an integer array answer where answer[i] is the value of the next greater node of the ith node (1-indexed). If the ith node does not have a next greater node, set answer[i] = 0.

Example 1:

>>> nextLargerNodes(head = [2,1,5])
>>> [5,5,0]

Example 2:

>>> nextLargerNodes(head = [2,7,4,3,5])
>>> [7,0,5,5,0]
"""


Prompt:
from typing import List
def numEnclaves(grid: List[List[int]]) -> int:
    """
    You are given an m x n binary matrix grid, where 0 represents a sea cell and 1 represents a land cell.
    A move consists of walking from one land cell to another adjacent (4-directionally) land cell or walking off the boundary of the grid.
    Return the number of land cells in grid for which we cannot walk off the boundary of the grid in any number of moves.

    Example 1:

    >>> numEnclaves(grid = [[0,0,0,0],[1,0,1,0],[0,1,1,0],[0,0,0,0]])
    >>> 3
    Explanation: There are three 1s that are enclosed by 0s, and one 1 that is not enclosed because its on the boundary.

    Example 2:

    >>> numEnclaves(grid = [[0,1,1,0],[0,0,1,0],[0,0,1,0],[0,0,0,0]])
    >>> 0
    Explanation: All 1s are either on the boundary or can reach the boundary.
    """


Prompt:
def removeOuterParentheses(s: str) -> str:
    """
    A valid parentheses string is either empty "", "(" + A + ")", or A + B, where A and B are valid parentheses strings, and + represents string concatenation.

    For example, "", "()", "(())()", and "(()(()))" are all valid parentheses strings.

    A valid parentheses string s is primitive if it is nonempty, and there does not exist a way to split it into s = A + B, with A and B nonempty valid parentheses strings.
    Given a valid parentheses string s, consider its primitive decomposition: s = P1 + P2 + ... + Pk, where Pi are primitive valid parentheses strings.
    Return s after removing the outermost parentheses of every primitive string in the primitive decomposition of s.

    Example 1:

    >>> removeOuterParentheses(s = "(()())(())")
    >>> "()()()"
    Explanation:
    The input string is "(()())(())", with primitive decomposition "(()())" + "(())".
    After removing outer parentheses of each part, this is "()()" + "()" = "()()()".

    Example 2:

    >>> removeOuterParentheses(s = "(()())(())(()(()))")
    >>> "()()()()(())"
    Explanation:
    The input string is "(()())(())(()(()))", with primitive decomposition "(()())" + "(())" + "(()(()))".
    After removing outer parentheses of each part, this is "()()" + "()" + "()(())" = "()()()()(())".

    Example 3:

    >>> removeOuterParentheses(s = "()()")
    >>> ""
    Explanation:
    The input string is "()()", with primitive decomposition "()" + "()".
    After removing outer parentheses of each part, this is "" + "" = "".
    """


Prompt:
from typing import Optional
class TreeNode:
    def __init__(val=0, left=None, right=None):
        self.val = val
        self.left = left
        self.right = right
def sumRootToLeaf(root: Optional[TreeNode]) -> int:
"""
You are given the root of a binary tree where each node has a value 0 or 1. Each root-to-leaf path represents a binary number starting with the most significant bit.

For example, if the path is 0 -> 1 -> 1 -> 0 -> 1, then this could represent 01101 in binary, which is 13.

For all leaves in the tree, consider the numbers represented by the path from the root to that leaf. Return the sum of these numbers.
The test cases are generated so that the answer fits in a 32-bits integer.

Example 1:

>>> sumRootToLeaf(root = [1,0,1,0,1,0,1])
>>> 22
Explanation: (100) + (101) + (110) + (111) = 4 + 5 + 6 + 7 = 22

Example 2:

>>> sumRootToLeaf(root = [0])
>>> 0
"""


Prompt:
from typing import List
def camelMatch(queries: List[str], pattern: str) -> List[bool]:
    """
    Given an array of strings queries and a string pattern, return a boolean array answer where answer[i] is true if queries[i] matches pattern, and false otherwise.
    A query word queries[i] matches pattern if you can insert lowercase English letters into the pattern so that it equals the query. You may insert a character at any position in pattern or you may choose not to insert any characters at all.

    Example 1:

    >>> camelMatch(queries = ["FooBar","FooBarTest","FootBall","FrameBuffer","ForceFeedBack"], pattern = "FB")
    >>> [true,false,true,true,false]
    Explanation: "FooBar" can be generated like this "F" + "oo" + "B" + "ar".
    "FootBall" can be generated like this "F" + "oot" + "B" + "all".
    "FrameBuffer" can be generated like this "F" + "rame" + "B" + "uffer".

    Example 2:

    >>> camelMatch(queries = ["FooBar","FooBarTest","FootBall","FrameBuffer","ForceFeedBack"], pattern = "FoBa")
    >>> [true,false,true,false,false]
    Explanation: "FooBar" can be generated like this "Fo" + "o" + "Ba" + "r".
    "FootBall" can be generated like this "Fo" + "ot" + "Ba" + "ll".

    Example 3:

    >>> camelMatch(queries = ["FooBar","FooBarTest","FootBall","FrameBuffer","ForceFeedBack"], pattern = "FoBaT")
    >>> [false,true,false,false,false]
    Explanation: "FooBarTest" can be generated like this "Fo" + "o" + "Ba" + "r" + "T" + "est".
    """


Prompt:
from typing import List
def videoStitching(clips: List[List[int]], time: int) -> int:
    """
    You are given a series of video clips from a sporting event that lasted time seconds. These video clips can be overlapping with each other and have varying lengths.
    Each video clip is described by an array clips where clips[i] = [starti, endi] indicates that the ith clip started at starti and ended at endi.
    We can cut these clips into segments freely.

    For example, a clip [0, 7] can be cut into segments [0, 1] + [1, 3] + [3, 7].

    Return the minimum number of clips needed so that we can cut the clips into segments that cover the entire sporting event [0, time]. If the task is impossible, return -1.

    Example 1:

    >>> videoStitching(clips = [[0,2],[4,6],[8,10],[1,9],[1,5],[5,9]], time = 10)
    >>> 3
    Explanation: We take the clips [0,2], [8,10], [1,9]; a total of 3 clips.
    Then, we can reconstruct the sporting event as follows:
    We cut [1,9] into segments [1,2] + [2,8] + [8,9].
    Now we have segments [0,2] + [2,8] + [8,10] which cover the sporting event [0, 10].

    Example 2:

    >>> videoStitching(clips = [[0,1],[1,2]], time = 5)
    >>> -1
    Explanation: We cannot cover [0,5] with only [0,1] and [1,2].

    Example 3:

    >>> videoStitching(clips = [[0,1],[6,8],[0,2],[5,6],[0,4],[0,3],[6,7],[1,3],[4,7],[1,4],[2,5],[2,6],[3,4],[4,5],[5,7],[6,9]], time = 9)
    >>> 3
    Explanation: We can take clips [0,4], [4,7], and [6,9].
    """


Prompt:
def divisorGame(n: int) -> bool:
    """
    Alice and Bob take turns playing a game, with Alice starting first.
    Initially, there is a number n on the chalkboard. On each player's turn, that player makes a move consisting of:

    Choosing any x with 0 < x < n and n % x == 0.
    Replacing the number n on the chalkboard with n - x.

    Also, if a player cannot make a move, they lose the game.
    Return true if and only if Alice wins the game, assuming both players play optimally.

    Example 1:

    >>> divisorGame(n = 2)
    >>> true
    Explanation: Alice chooses 1, and Bob has no more moves.

    Example 2:

    >>> divisorGame(n = 3)
    >>> false
    Explanation: Alice chooses 1, Bob chooses 1, and Alice has no more moves.
    """


Prompt:
from typing import Optional
class TreeNode:
    def __init__(val=0, left=None, right=None):
        self.val = val
        self.left = left
        self.right = right
def maxAncestorDiff(root: Optional[TreeNode]) -> int:
"""
Given the root of a binary tree, find the maximum value v for which there exist different nodes a and b where v = |a.val - b.val| and a is an ancestor of b.
A node a is an ancestor of b if either: any child of a is equal to b or any child of a is an ancestor of b.

Example 1:

>>> maxAncestorDiff(root = [8,3,10,1,6,null,14,null,null,4,7,13])
>>> 7
Explanation: We have various ancestor-node differences, some of which are given below :
|8 - 3| = 5
|3 - 7| = 4
|8 - 1| = 7
|10 - 13| = 3
Among all possible differences, the maximum value of 7 is obtained by |8 - 1| = 7.
Example 2:

>>> maxAncestorDiff(root = [1,null,2,null,0,3])
>>> 3
"""


Prompt:
from typing import List
def longestArithSeqLength(nums: List[int]) -> int:
    """
    Given an array nums of integers, return the length of the longest arithmetic subsequence in nums.
    Note that:

    A subsequence is an array that can be derived from another array by deleting some or no elements without changing the order of the remaining elements.
    A sequence seq is arithmetic if seq[i + 1] - seq[i] are all the same value (for 0 <= i < seq.length - 1).

    Example 1:

    >>> longestArithSeqLength(nums = [3,6,9,12])
    >>> 4
    Explanation:  The whole array is an arithmetic sequence with steps of length = 3.

    Example 2:

    >>> longestArithSeqLength(nums = [9,4,7,2,10])
    >>> 3
    Explanation:  The longest arithmetic subsequence is [4,7,10].

    Example 3:

    >>> longestArithSeqLength(nums = [20,1,15,3,10,5,8])
    >>> 4
    Explanation:  The longest arithmetic subsequence is [20,15,10,5].
    """


Prompt:
from typing import Optional
class TreeNode:
    def __init__(val=0, left=None, right=None):
        self.val = val
        self.left = left
        self.right = right
def recoverFromPreorder(traversal: str) -> Optional[TreeNode]:
"""
We run a preorder depth-first search (DFS) on the root of a binary tree.
At each node in this traversal, we output D dashes (where D is the depth of this node), then we output the value of this node.  If the depth of a node is D, the depth of its immediate child is D + 1.  The depth of the root node is 0.
If a node has only one child, that child is guaranteed to be the left child.
Given the output traversal of this traversal, recover the tree and return its root.

Example 1:

>>> recoverFromPreorder(traversal = "1-2--3--4-5--6--7")
>>> [1,2,5,3,4,6,7]

Example 2:

>>> recoverFromPreorder(traversal = "1-2--3---4-5--6---7")
>>> [1,2,5,3,null,6,null,4,null,7]

Example 3:

>>> recoverFromPreorder(traversal = "1-401--349---90--88")
>>> [1,401,null,349,88,90]
"""


Prompt:
from typing import List
def twoCitySchedCost(costs: List[List[int]]) -> int:
    """
    A company is planning to interview 2n people. Given the array costs where costs[i] = [aCosti, bCosti], the cost of flying the ith person to city a is aCosti, and the cost of flying the ith person to city b is bCosti.
    Return the minimum cost to fly every person to a city such that exactly n people arrive in each city.

    Example 1:

    >>> twoCitySchedCost(costs = [[10,20],[30,200],[400,50],[30,20]])
    >>> 110
    Explanation:
    The first person goes to city A for a cost of 10.
    The second person goes to city A for a cost of 30.
    The third person goes to city B for a cost of 50.
    The fourth person goes to city B for a cost of 20.

    The total minimum cost is 10 + 30 + 50 + 20 = 110 to have half the people interviewing in each city.

    Example 2:

    >>> twoCitySchedCost(costs = [[259,770],[448,54],[926,667],[184,139],[840,118],[577,469]])
    >>> 1859

    Example 3:

    >>> twoCitySchedCost(costs = [[515,563],[451,713],[537,709],[343,819],[855,779],[457,60],[650,359],[631,42]])
    >>> 3086
    """


Prompt:
from typing import List
def allCellsDistOrder(rows: int, cols: int, rCenter: int, cCenter: int) -> List[List[int]]:
    """
    You are given four integers row, cols, rCenter, and cCenter. There is a rows x cols matrix and you are on the cell with the coordinates (rCenter, cCenter).
    Return the coordinates of all cells in the matrix, sorted by their distance from (rCenter, cCenter) from the smallest distance to the largest distance. You may return the answer in any order that satisfies this condition.
    The distance between two cells (r1, c1) and (r2, c2) is |r1 - r2| + |c1 - c2|.

    Example 1:

    >>> allCellsDistOrder(rows = 1, cols = 2, rCenter = 0, cCenter = 0)
    >>> [[0,0],[0,1]]
    Explanation: The distances from (0, 0) to other cells are: [0,1]

    Example 2:

    >>> allCellsDistOrder(rows = 2, cols = 2, rCenter = 0, cCenter = 1)
    >>> [[0,1],[0,0],[1,1],[1,0]]
    Explanation: The distances from (0, 1) to other cells are: [0,1,1,2]
    The answer [[0,1],[1,1],[0,0],[1,0]] would also be accepted as correct.

    Example 3:

    >>> allCellsDistOrder(rows = 2, cols = 3, rCenter = 1, cCenter = 2)
    >>> [[1,2],[0,2],[1,1],[0,1],[1,0],[0,0]]
    Explanation: The distances from (1, 2) to other cells are: [0,1,1,2,2,3]
    There are other answers that would also be accepted as correct, such as [[1,2],[1,1],[0,2],[1,0],[0,1],[0,0]].
    """


Prompt:
from typing import List
def maxSumTwoNoOverlap(nums: List[int], firstLen: int, secondLen: int) -> int:
    """
    Given an integer array nums and two integers firstLen and secondLen, return the maximum sum of elements in two non-overlapping subarrays with lengths firstLen and secondLen.
    The array with length firstLen could occur before or after the array with length secondLen, but they have to be non-overlapping.
    A subarray is a contiguous part of an array.

    Example 1:

    >>> maxSumTwoNoOverlap(nums = [0,6,5,2,2,5,1,9,4], firstLen = 1, secondLen = 2)
    >>> 20
    Explanation: One choice of subarrays is [9] with length 1, and [6,5] with length 2.

    Example 2:

    >>> maxSumTwoNoOverlap(nums = [3,8,1,3,2,1,8,9,0], firstLen = 3, secondLen = 2)
    >>> 29
    Explanation: One choice of subarrays is [3,8,1] with length 3, and [8,9] with length 2.

    Example 3:

    >>> maxSumTwoNoOverlap(nums = [2,1,5,6,0,9,5,0,3,8], firstLen = 4, secondLen = 3)
    >>> 31
    Explanation: One choice of subarrays is [5,6,0,9] with length 4, and [0,3,8] with length 3.
    """


Prompt:
from typing import List
def numMovesStones(a: int, b: int, c: int) -> List[int]:
    """
    There are three stones in different positions on the X-axis. You are given three integers a, b, and c, the positions of the stones.
    In one move, you pick up a stone at an endpoint (i.e., either the lowest or highest position stone), and move it to an unoccupied position between those endpoints. Formally, let's say the stones are currently at positions x, y, and z with x < y < z. You pick up the stone at either position x or position z, and move that stone to an integer position k, with x < k < z and k != y.
    The game ends when you cannot make any more moves (i.e., the stones are in three consecutive positions).
    Return an integer array answer of length 2 where:

    answer[0] is the minimum number of moves you can play, and
    answer[1] is the maximum number of moves you can play.

    Example 1:

    >>> numMovesStones(a = 1, b = 2, c = 5)
    >>> [1,2]
    Explanation: Move the stone from 5 to 3, or move the stone from 5 to 4 to 3.

    Example 2:

    >>> numMovesStones(a = 4, b = 3, c = 2)
    >>> [0,0]
    Explanation: We cannot make any moves.

    Example 3:

    >>> numMovesStones(a = 3, b = 5, c = 1)
    >>> [1,2]
    Explanation: Move the stone from 1 to 4; or move the stone from 1 to 2 to 4.
    """


Prompt:
from typing import List
def colorBorder(grid: List[List[int]], row: int, col: int, color: int) -> List[List[int]]:
    """
    You are given an m x n integer matrix grid, and three integers row, col, and color. Each value in the grid represents the color of the grid square at that location.
    Two squares are called adjacent if they are next to each other in any of the 4 directions.
    Two squares belong to the same connected component if they have the same color and they are adjacent.
    The border of a connected component is all the squares in the connected component that are either adjacent to (at least) a square not in the component, or on the boundary of the grid (the first or last row or column).
    You should color the border of the connected component that contains the square grid[row][col] with color.
    Return the final grid.

    Example 1:
    >>> colorBorder(grid = [[1,1],[1,2]], row = 0, col = 0, color = 3)
    >>> [[3,3],[3,2]]
    Example 2:
    >>> colorBorder(grid = [[1,2,2],[2,3,2]], row = 0, col = 1, color = 3)
    >>> [[1,3,3],[2,3,3]]
    Example 3:
    >>> colorBorder(grid = [[1,1,1],[1,1,1],[1,1,1]], row = 1, col = 1, color = 2)
    >>> [[2,2,2],[2,1,2],[2,2,2]]
    """


Prompt:
from typing import List
def maxUncrossedLines(nums1: List[int], nums2: List[int]) -> int:
    """
    You are given two integer arrays nums1 and nums2. We write the integers of nums1 and nums2 (in the order they are given) on two separate horizontal lines.
    We may draw connecting lines: a straight line connecting two numbers nums1[i] and nums2[j] such that:

    nums1[i] == nums2[j], and
    the line we draw does not intersect any other connecting (non-horizontal) line.

    Note that a connecting line cannot intersect even at the endpoints (i.e., each number can only belong to one connecting line).
    Return the maximum number of connecting lines we can draw in this way.

    Example 1:

    >>> maxUncrossedLines(nums1 = [1,4,2], nums2 = [1,2,4])
    >>> 2
    Explanation: We can draw 2 uncrossed lines as in the diagram.
    We cannot draw 3 uncrossed lines, because the line from nums1[1] = 4 to nums2[2] = 4 will intersect the line from nums1[2]=2 to nums2[1]=2.

    Example 2:

    >>> maxUncrossedLines(nums1 = [2,5,1,2,5], nums2 = [10,5,2,1,5,2])
    >>> 3

    Example 3:

    >>> maxUncrossedLines(nums1 = [1,3,7,1,7,5], nums2 = [1,9,2,5,1])
    >>> 2
    """


Prompt:
from typing import List
def isEscapePossible(blocked: List[List[int]], source: List[int], target: List[int]) -> bool:
    """
    There is a 1 million by 1 million grid on an XY-plane, and the coordinates of each grid square are (x, y).
    We start at the source = [sx, sy] square and want to reach the target = [tx, ty] square. There is also an array of blocked squares, where each blocked[i] = [xi, yi] represents a blocked square with coordinates (xi, yi).
    Each move, we can walk one square north, east, south, or west if the square is not in the array of blocked squares. We are also not allowed to walk outside of the grid.
    Return true if and only if it is possible to reach the target square from the source square through a sequence of valid moves.

    Example 1:

    >>> isEscapePossible(blocked = [[0,1],[1,0]], source = [0,0], target = [0,2])
    >>> false
    Explanation: The target square is inaccessible starting from the source square because we cannot move.
    We cannot move north or east because those squares are blocked.
    We cannot move south or west because we cannot go outside of the grid.

    Example 2:

    >>> isEscapePossible(blocked = [], source = [0,0], target = [999999,999999])
    >>> true
    Explanation: Because there are no blocked cells, it is possible to reach the target square.
    """


Prompt:
from typing import List
def isBoomerang(points: List[List[int]]) -> bool:
    """
    Given an array points where points[i] = [xi, yi] represents a point on the X-Y plane, return true if these points are a boomerang.
    A boomerang is a set of three points that are all distinct and not in a straight line.

    Example 1:
    >>> isBoomerang(points = [[1,1],[2,3],[3,2]])
    >>> true
    Example 2:
    >>> isBoomerang(points = [[1,1],[2,2],[3,3]])
    >>> false
    """


Prompt:
from typing import Optional
class TreeNode:
    def __init__(val=0, left=None, right=None):
        self.val = val
        self.left = left
        self.right = right
def bstToGst(root: Optional[TreeNode]) -> Optional[TreeNode]:
"""
Given the root of a Binary Search Tree (BST), convert it to a Greater Tree such that every key of the original BST is changed to the original key plus the sum of all keys greater than the original key in BST.
As a reminder, a binary search tree is a tree that satisfies these constraints:

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.

Example 1:

>>> bstToGst(root = [4,1,6,0,2,5,7,null,null,null,3,null,null,null,8])
>>> [30,36,21,36,35,26,15,null,null,null,33,null,null,null,8]

Example 2:

>>> bstToGst(root = [0,null,1])
>>> [1,null,1]
"""


Prompt:
from typing import List
def minScoreTriangulation(values: List[int]) -> int:
    """
    You have a convex n-sided polygon where each vertex has an integer value. You are given an integer array values where values[i] is the value of the ith vertex in clockwise order.
    Polygon triangulation is a process where you divide a polygon into a set of triangles and the vertices of each triangle must also be vertices of the original polygon. Note that no other shapes other than triangles are allowed in the division. This process will result in n - 2 triangles.
    You will triangulate the polygon. For each triangle, the weight of that triangle is the product of the values at its vertices. The total score of the triangulation is the sum of these weights over all n - 2 triangles.
    Return the minimum possible score that you can achieve with some triangulation of the polygon.

    Example 1:

    >>> minScoreTriangulation(values = [1,2,3])
    >>> 6
    Explanation: The polygon is already triangulated, and the score of the only triangle is 6.

    Example 2:

    >>> minScoreTriangulation(values = [3,7,4,5])
    >>> 144
    Explanation: There are two triangulations, with possible scores: 3*7*5 + 4*5*7 = 245, or 3*4*5 + 3*4*7 = 144.
    The minimum score is 144.

    Example 3:

    >>> minScoreTriangulation(values = [1,3,1,4,1,5])
    >>> 13
    Explanation: The minimum score triangulation is 1*1*3 + 1*1*4 + 1*1*5 + 1*1*1 = 13.
    """


Prompt:
from typing import List
def numMovesStonesII(stones: List[int]) -> List[int]:
    """
    There are some stones in different positions on the X-axis. You are given an integer array stones, the positions of the stones.
    Call a stone an endpoint stone if it has the smallest or largest position. In one move, you pick up an endpoint stone and move it to an unoccupied position so that it is no longer an endpoint stone.

    In particular, if the stones are at say, stones = [1,2,5], you cannot move the endpoint stone at position 5, since moving it to any position (such as 0, or 3) will still keep that stone as an endpoint stone.

    The game ends when you cannot make any more moves (i.e., the stones are in three consecutive positions).
    Return an integer array answer of length 2 where:

    answer[0] is the minimum number of moves you can play, and
    answer[1] is the maximum number of moves you can play.

    Example 1:

    >>> numMovesStonesII(stones = [7,4,9])
    >>> [1,2]
    Explanation: We can move 4 -> 8 for one move to finish the game.
    Or, we can move 9 -> 5, 4 -> 6 for two moves to finish the game.

    Example 2:

    >>> numMovesStonesII(stones = [6,5,4,3,10])
    >>> [2,3]
    Explanation: We can move 3 -> 8 then 10 -> 7 to finish the game.
    Or, we can move 3 -> 7, 4 -> 8, 5 -> 9 to finish the game.
    Notice we cannot move 10 -> 2 to finish the game, because that would be an illegal move.
    """


Prompt:
def isRobotBounded(instructions: str) -> bool:
    """
    On an infinite plane, a robot initially stands at (0, 0) and faces north. Note that:

    The north direction is the positive direction of the y-axis.
    The south direction is the negative direction of the y-axis.
    The east direction is the positive direction of the x-axis.
    The west direction is the negative direction of the x-axis.

    The robot can receive one of three instructions:

    "G": go straight 1 unit.
    "L": turn 90 degrees to the left (i.e., anti-clockwise direction).
    "R": turn 90 degrees to the right (i.e., clockwise direction).

    The robot performs the instructions given in order, and repeats them forever.
    Return true if and only if there exists a circle in the plane such that the robot never leaves the circle.

    Example 1:

    >>> isRobotBounded(instructions = "GGLLGG")
    >>> true
    Explanation: The robot is initially at (0, 0) facing the north direction.
    "G": move one step. Position: (0, 1). Direction: North.
    "G": move one step. Position: (0, 2). Direction: North.
    "L": turn 90 degrees anti-clockwise. Position: (0, 2). Direction: West.
    "L": turn 90 degrees anti-clockwise. Position: (0, 2). Direction: South.
    "G": move one step. Position: (0, 1). Direction: South.
    "G": move one step. Position: (0, 0). Direction: South.
    Repeating the instructions, the robot goes into the cycle: (0, 0) --> (0, 1) --> (0, 2) --> (0, 1) --> (0, 0).
    Based on that, we return true.

    Example 2:

    >>> isRobotBounded(instructions = "GG")
    >>> false
    Explanation: The robot is initially at (0, 0) facing the north direction.
    "G": move one step. Position: (0, 1). Direction: North.
    "G": move one step. Position: (0, 2). Direction: North.
    Repeating the instructions, keeps advancing in the north direction and does not go into cycles.
    Based on that, we return false.

    Example 3:

    >>> isRobotBounded(instructions = "GL")
    >>> true
    Explanation: The robot is initially at (0, 0) facing the north direction.
    "G": move one step. Position: (0, 1). Direction: North.
    "L": turn 90 degrees anti-clockwise. Position: (0, 1). Direction: West.
    "G": move one step. Position: (-1, 1). Direction: West.
    "L": turn 90 degrees anti-clockwise. Position: (-1, 1). Direction: South.
    "G": move one step. Position: (-1, 0). Direction: South.
    "L": turn 90 degrees anti-clockwise. Position: (-1, 0). Direction: East.
    "G": move one step. Position: (0, 0). Direction: East.
    "L": turn 90 degrees anti-clockwise. Position: (0, 0). Direction: North.
    Repeating the instructions, the robot goes into the cycle: (0, 0) --> (0, 1) --> (-1, 1) --> (-1, 0) --> (0, 0).
    Based on that, we return true.
    """


Prompt:
from typing import List
def gardenNoAdj(n: int, paths: List[List[int]]) -> List[int]:
    """
    You have n gardens, labeled from 1 to n, and an array paths where paths[i] = [xi, yi] describes a bidirectional path between garden xi to garden yi. In each garden, you want to plant one of 4 types of flowers.
    All gardens have at most 3 paths coming into or leaving it.
    Your task is to choose a flower type for each garden such that, for any two gardens connected by a path, they have different types of flowers.
    Return any such a choice as an array answer, where answer[i] is the type of flower planted in the (i+1)th garden. The flower types are denoted 1, 2, 3, or 4. It is guaranteed an answer exists.

    Example 1:

    >>> gardenNoAdj(n = 3, paths = [[1,2],[2,3],[3,1]])
    >>> [1,2,3]
    Explanation:
    Gardens 1 and 2 have different types.
    Gardens 2 and 3 have different types.
    Gardens 3 and 1 have different types.
    Hence, [1,2,3] is a valid answer. Other valid answers include [1,2,4], [1,4,2], and [3,2,1].

    Example 2:

    >>> gardenNoAdj(n = 4, paths = [[1,2],[3,4]])
    >>> [1,2,1,2]

    Example 3:

    >>> gardenNoAdj(n = 4, paths = [[1,2],[2,3],[3,4],[4,1],[1,3],[2,4]])
    >>> [1,2,3,4]
    """


Prompt:
from typing import List
def maxSumAfterPartitioning(arr: List[int], k: int) -> int:
    """
    Given an integer array arr, partition the array into (contiguous) subarrays of length at most k. After partitioning, each subarray has their values changed to become the maximum value of that subarray.
    Return the largest sum of the given array after partitioning. Test cases are generated so that the answer fits in a 32-bit integer.

    Example 1:

    >>> maxSumAfterPartitioning(arr = [1,15,7,9,2,5,10], k = 3)
    >>> 84
    Explanation: arr becomes [15,15,15,9,10,10,10]

    Example 2:

    >>> maxSumAfterPartitioning(arr = [1,4,1,5,7,3,6,1,9,9,3], k = 4)
    >>> 83

    Example 3:

    >>> maxSumAfterPartitioning(arr = [1], k = 1)
    >>> 1
    """


Prompt:
def longestDupSubstring(s: str) -> str:
    """
    Given a string s, consider all duplicated substrings: (contiguous) substrings of s that occur 2 or more times. The occurrences may overlap.
    Return any duplicated substring that has the longest possible length. If s does not have a duplicated substring, the answer is "".

    Example 1:
    >>> longestDupSubstring(s = "banana")
    >>> "ana"
    Example 2:
    >>> longestDupSubstring(s = "abcd")
    >>> ""
    """


Prompt:
from typing import List
def lastStoneWeight(stones: List[int]) -> int:
    """
    You are given an array of integers stones where stones[i] is the weight of the ith stone.
    We are playing a game with the stones. On each turn, we choose the heaviest two stones and smash them together. Suppose the heaviest two stones have weights x and y with x <= y. The result of this smash is:

    If x == y, both stones are destroyed, and
    If x != y, the stone of weight x is destroyed, and the stone of weight y has new weight y - x.

    At the end of the game, there is at most one stone left.
    Return the weight of the last remaining stone. If there are no stones left, return 0.

    Example 1:

    >>> lastStoneWeight(stones = [2,7,4,1,8,1])
    >>> 1
    Explanation:
    We combine 7 and 8 to get 1 so the array converts to [2,4,1,1,1] then,
    we combine 2 and 4 to get 2 so the array converts to [2,1,1,1] then,
    we combine 2 and 1 to get 1 so the array converts to [1,1,1] then,
    we combine 1 and 1 to get 0 so the array converts to [1] then that's the value of the last stone.

    Example 2:

    >>> lastStoneWeight(stones = [1])
    >>> 1
    """


Prompt:
def removeDuplicates(s: str) -> str:
    """
    You are given a string s consisting of lowercase English letters. A duplicate removal consists of choosing two adjacent and equal letters and removing them.
    We repeatedly make duplicate removals on s until we no longer can.
    Return the final string after all such duplicate removals have been made. It can be proven that the answer is unique.

    Example 1:

    >>> removeDuplicates(s = "abbaca")
    >>> "ca"
    Explanation:
    For example, in "abbaca" we could remove "bb" since the letters are adjacent and equal, and this is the only possible move.  The result of this move is that the string is "aaca", of which only "aa" is possible, so the final string is "ca".

    Example 2:

    >>> removeDuplicates(s = "azxxzy")
    >>> "ay"
    """


Prompt:
from typing import List
def longestStrChain(words: List[str]) -> int:
    """
    You are given an array of words where each word consists of lowercase English letters.
    wordA is a predecessor of wordB if and only if we can insert exactly one letter anywhere in wordA without changing the order of the other characters to make it equal to wordB.

    For example, "abc" is a predecessor of "abac", while "cba" is not a predecessor of "bcad".

    A word chain is a sequence of words [word1, word2, ..., wordk] with k >= 1, where word1 is a predecessor of word2, word2 is a predecessor of word3, and so on. A single word is trivially a word chain with k == 1.
    Return the length of the longest possible word chain with words chosen from the given list of words.

    Example 1:

    >>> longestStrChain(words = ["a","b","ba","bca","bda","bdca"])
    >>> 4
    Explanation: One of the longest word chains is ["a","ba","bda","bdca"].

    Example 2:

    >>> longestStrChain(words = ["xbc","pcxbcf","xb","cxbc","pcxbc"])
    >>> 5
    Explanation: All the words can be put in a word chain ["xb", "xbc", "cxbc", "pcxbc", "pcxbcf"].

    Example 3:

    >>> longestStrChain(words = ["abcd","dbqca"])
    >>> 1
    Explanation: The trivial word chain ["abcd"] is one of the longest word chains.
    ["abcd","dbqca"] is not a valid word chain because the ordering of the letters is changed.
    """


Prompt:
from typing import List
def lastStoneWeightII(stones: List[int]) -> int:
    """
    You are given an array of integers stones where stones[i] is the weight of the ith stone.
    We are playing a game with the stones. On each turn, we choose any two stones and smash them together. Suppose the stones have weights x and y with x <= y. The result of this smash is:

    If x == y, both stones are destroyed, and
    If x != y, the stone of weight x is destroyed, and the stone of weight y has new weight y - x.

    At the end of the game, there is at most one stone left.
    Return the smallest possible weight of the left stone. If there are no stones left, return 0.

    Example 1:

    >>> lastStoneWeightII(stones = [2,7,4,1,8,1])
    >>> 1
    Explanation:
    We can combine 2 and 4 to get 2, so the array converts to [2,7,1,8,1] then,
    we can combine 7 and 8 to get 1, so the array converts to [2,1,1,1] then,
    we can combine 2 and 1 to get 1, so the array converts to [1,1,1] then,
    we can combine 1 and 1 to get 0, so the array converts to [1], then that's the optimal value.

    Example 2:

    >>> lastStoneWeightII(stones = [31,26,33,21,40])
    >>> 5
    """


Prompt:
from typing import List
def heightChecker(heights: List[int]) -> int:
    """
    A school is trying to take an annual photo of all the students. The students are asked to stand in a single file line in non-decreasing order by height. Let this ordering be represented by the integer array expected where expected[i] is the expected height of the ith student in line.
    You are given an integer array heights representing the current order that the students are standing in. Each heights[i] is the height of the ith student in line (0-indexed).
    Return the number of indices where heights[i] != expected[i].

    Example 1:

    >>> heightChecker(heights = [1,1,4,2,1,3])
    >>> 3
    Explanation:
    heights:  [1,1,4,2,1,3]
    expected: [1,1,1,2,3,4]
    Indices 2, 4, and 5 do not match.

    Example 2:

    >>> heightChecker(heights = [5,1,2,3,4])
    >>> 5
    Explanation:
    heights:  [5,1,2,3,4]
    expected: [1,2,3,4,5]
    All indices do not match.

    Example 3:

    >>> heightChecker(heights = [1,2,3,4,5])
    >>> 0
    Explanation:
    heights:  [1,2,3,4,5]
    expected: [1,2,3,4,5]
    All indices match.
    """


Prompt:
from typing import List
def maxSatisfied(customers: List[int], grumpy: List[int], minutes: int) -> int:
    """
    There is a bookstore owner that has a store open for n minutes. You are given an integer array customers of length n where customers[i] is the number of the customers that enter the store at the start of the ith minute and all those customers leave after the end of that minute.
    During certain minutes, the bookstore owner is grumpy. You are given a binary array grumpy where grumpy[i] is 1 if the bookstore owner is grumpy during the ith minute, and is 0 otherwise.
    When the bookstore owner is grumpy, the customers entering during that minute are not satisfied. Otherwise, they are satisfied.
    The bookstore owner knows a secret technique to remain not grumpy for minutes consecutive minutes, but this technique can only be used once.
    Return the maximum number of customers that can be satisfied throughout the day.

    Example 1:

    >>> maxSatisfied(customers = [1,0,1,2,1,1,7,5], grumpy = [0,1,0,1,0,1,0,1], minutes = 3)
    >>> 16
    Explanation:
    The bookstore owner keeps themselves not grumpy for the last 3 minutes.
    The maximum number of customers that can be satisfied = 1 + 1 + 1 + 1 + 7 + 5 = 16.

    Example 2:

    >>> maxSatisfied(customers = [1], grumpy = [0], minutes = 1)
    >>> 1
    """


Prompt:
from typing import List
def prevPermOpt1(arr: List[int]) -> List[int]:
    """
    Given an array of positive integers arr (not necessarily distinct), return the lexicographically largest permutation that is smaller than arr, that can be made with exactly one swap. If it cannot be done, then return the same array.
    Note that a swap exchanges the positions of two numbers arr[i] and arr[j]

    Example 1:

    >>> prevPermOpt1(arr = [3,2,1])
    >>> [3,1,2]
    Explanation: Swapping 2 and 1.

    Example 2:

    >>> prevPermOpt1(arr = [1,1,5])
    >>> [1,1,5]
    Explanation: This is already the smallest permutation.

    Example 3:

    >>> prevPermOpt1(arr = [1,9,4,6,7])
    >>> [1,7,4,6,9]
    Explanation: Swapping 9 and 7.
    """


Prompt:
from typing import List
def rearrangeBarcodes(barcodes: List[int]) -> List[int]:
    """
    In a warehouse, there is a row of barcodes, where the ith barcode is barcodes[i].
    Rearrange the barcodes so that no two adjacent barcodes are equal. You may return any answer, and it is guaranteed an answer exists.

    Example 1:
    >>> rearrangeBarcodes(barcodes = [1,1,1,2,2,2])
    >>> [2,1,2,1,2,1]
    Example 2:
    >>> rearrangeBarcodes(barcodes = [1,1,1,1,2,2,3,3])
    >>> [1,3,1,3,1,2,1,2]
    """


Prompt:
def shortestWay(source: str, target: str) -> int:
    """
    A subsequence of a string is a new string that is formed from the original string by deleting some (can be none) of the characters without disturbing the relative positions of the remaining characters. (i.e., "ace" is a subsequence of "abcde" while "aec" is not).
    Given two strings source and target, return the minimum number of subsequences of source such that their concatenation equals target. If the task is impossible, return -1.

    Example 1:

    >>> shortestWay(source = "abc", target = "abcbc")
    >>> 2
    Explanation: The target "abcbc" can be formed by "abc" and "bc", which are subsequences of source "abc".

    Example 2:

    >>> shortestWay(source = "abc", target = "acdbc")
    >>> -1
    Explanation: The target string cannot be constructed from the subsequences of source string due to the character "d" in target string.

    Example 3:

    >>> shortestWay(source = "xyz", target = "xzyxz")
    >>> 3
    Explanation: The target string can be constructed as follows "xz" + "y" + "xz".
    """


Prompt:
def confusingNumber(n: int) -> bool:
    """
    A confusing number is a number that when rotated 180 degrees becomes a different number with each digit valid.
    We can rotate digits of a number by 180 degrees to form new digits.

    When 0, 1, 6, 8, and 9 are rotated 180 degrees, they become 0, 1, 9, 8, and 6 respectively.
    When 2, 3, 4, 5, and 7 are rotated 180 degrees, they become invalid.

    Note that after rotating a number, we can ignore leading zeros.

    For example, after rotating 8000, we have 0008 which is considered as just 8.

    Given an integer n, return true if it is a confusing number, or false otherwise.

    Example 1:

    >>> confusingNumber(n = 6)
    >>> true
    Explanation: We get 9 after rotating 6, 9 is a valid number, and 9 != 6.

    Example 2:

    >>> confusingNumber(n = 89)
    >>> true
    Explanation: We get 68 after rotating 89, 68 is a valid number and 68 != 89.

    Example 3:

    >>> confusingNumber(n = 11)
    >>> false
    Explanation: We get 11 after rotating 11, 11 is a valid number but the value remains the same, thus 11 is not a confusing number
    """


Prompt:
from typing import List
def assignBikes(workers: List[List[int]], bikes: List[List[int]]) -> List[int]:
    """
    On a campus represented on the X-Y plane, there are n workers and m bikes, with n <= m.
    You are given an array workers of length n where workers[i] = [xi, yi] is the position of the ith worker. You are also given an array bikes of length m where bikes[j] = [xj, yj] is the position of the jth bike. All the given positions are unique.
    Assign a bike to each worker. Among the available bikes and workers, we choose the (workeri, bikej) pair with the shortest Manhattan distance between each other and assign the bike to that worker.
    If there are multiple (workeri, bikej) pairs with the same shortest Manhattan distance, we choose the pair with the smallest worker index. If there are multiple ways to do that, we choose the pair with the smallest bike index. Repeat this process until there are no available workers.
    Return an array answer of length n, where answer[i] is the index (0-indexed) of the bike that the ith worker is assigned to.
    The Manhattan distance between two points p1 and p2 is Manhattan(p1, p2) = |p1.x - p2.x| + |p1.y - p2.y|.

    Example 1:

    >>> assignBikes(workers = [[0,0],[2,1]], bikes = [[1,2],[3,3]])
    >>> [1,0]
    Explanation: Worker 1 grabs Bike 0 as they are closest (without ties), and Worker 0 is assigned Bike 1. So the output is [1, 0].

    Example 2:

    >>> assignBikes(workers = [[0,0],[1,1],[2,0]], bikes = [[1,0],[2,2],[2,1]])
    >>> [0,2,1]
    Explanation: Worker 0 grabs Bike 0 at first. Worker 1 and Worker 2 share the same distance to Bike 2, thus Worker 1 is assigned to Bike 2, and Worker 2 will take Bike 1. So the output is [0,2,1].
    """


Prompt:
from typing import List
def minimizeError(prices: List[str], target: int) -> str:
    """
    Given an array of prices [p1,p2...,pn] and a target, round each price pi to Roundi(pi) so that the rounded array [Round1(p1),Round2(p2)...,Roundn(pn)] sums to the given target. Each operation Roundi(pi) could be either Floor(pi) or Ceil(pi).
    Return the string "-1" if the rounded array is impossible to sum to target. Otherwise, return the smallest rounding error, which is defined as Σ |Roundi(pi) - (pi)| for i from 1 to n, as a string with three places after the decimal.

    Example 1:

    >>> minimizeError(prices = ["0.700","2.800","4.900"], target = 8)
    >>> "1.000"
    Explanation:
    Use Floor, Ceil and Ceil operations to get (0.7 - 0) + (3 - 2.8) + (5 - 4.9) = 0.7 + 0.2 + 0.1 = 1.0 .

    Example 2:

    >>> minimizeError(prices = ["1.500","2.500","3.500"], target = 10)
    >>> "-1"
    Explanation: It is impossible to meet the target.

    Example 3:

    >>> minimizeError(prices = ["1.500","2.500","3.500"], target = 9)
    >>> "1.500"
    """


Prompt:
from typing import List
def leadsToDestination(n: int, edges: List[List[int]], source: int, destination: int) -> bool:
    """
    Given the edges of a directed graph where edges[i] = [ai, bi] indicates there is an edge between nodes ai and bi, and two nodes source and destination of this graph, determine whether or not all paths starting from source eventually, end at destination, that is:

    At least one path exists from the source node to the destination node
    If a path exists from the source node to a node with no outgoing edges, then that node is equal to destination.
    The number of possible paths from source to destination is a finite number.

    Return true if and only if all roads from source lead to destination.

    Example 1:

    >>> leadsToDestination(n = 3, edges = [[0,1],[0,2]], source = 0, destination = 2)
    >>> false
    Explanation: It is possible to reach and get stuck on both node 1 and node 2.

    Example 2:

    >>> leadsToDestination(n = 4, edges = [[0,1],[0,3],[1,2],[2,1]], source = 0, destination = 3)
    >>> false
    Explanation: We have two possibilities: to end at node 3, or to loop over node 1 and node 2 indefinitely.

    Example 3:

    >>> leadsToDestination(n = 4, edges = [[0,1],[0,2],[1,3],[2,3]], source = 0, destination = 3)
    >>> true
    """


Prompt:
from typing import List
def missingElement(nums: List[int], k: int) -> int:
    """
    Given an integer array nums which is sorted in ascending order and all of its elements are unique and given also an integer k, return the kth missing number starting from the leftmost number of the array.

    Example 1:

    >>> missingElement(nums = [4,7,9,10], k = 1)
    >>> 5
    Explanation: The first missing number is 5.

    Example 2:

    >>> missingElement(nums = [4,7,9,10], k = 3)
    >>> 8
    Explanation: The missing numbers are [5,6,8,...], hence the third missing number is 8.

    Example 3:

    >>> missingElement(nums = [1,2,4], k = 3)
    >>> 6
    Explanation: The missing numbers are [3,5,6,7,...], hence the third missing number is 6.
    """


Prompt:
def smallestEquivalentString(s1: str, s2: str, baseStr: str) -> str:
    """
    You are given two strings of the same length s1 and s2 and a string baseStr.
    We say s1[i] and s2[i] are equivalent characters.

    For example, if s1 = "abc" and s2 = "cde", then we have 'a' == 'c', 'b' == 'd', and 'c' == 'e'.

    Equivalent characters follow the usual rules of any equivalence relation:

    Reflexivity: 'a' == 'a'.
    Symmetry: 'a' == 'b' implies 'b' == 'a'.
    Transitivity: 'a' == 'b' and 'b' == 'c' implies 'a' == 'c'.

    For example, given the equivalency information from s1 = "abc" and s2 = "cde", "acd" and "aab" are equivalent strings of baseStr = "eed", and "aab" is the lexicographically smallest equivalent string of baseStr.
    Return the lexicographically smallest equivalent string of baseStr by using the equivalency information from s1 and s2.

    Example 1:

    >>> smallestEquivalentString(s1 = "parker", s2 = "morris", baseStr = "parser")
    >>> "makkek"
    Explanation: Based on the equivalency information in s1 and s2, we can group their characters as [m,p], [a,o], [k,r,s], [e,i].
    The characters in each group are equivalent and sorted in lexicographical order.
    So the answer is "makkek".

    Example 2:

    >>> smallestEquivalentString(s1 = "hello", s2 = "world", baseStr = "hold")
    >>> "hdld"
    Explanation: Based on the equivalency information in s1 and s2, we can group their characters as [h,w], [d,e,o], [l,r].
    So only the second letter 'o' in baseStr is changed to 'd', the answer is "hdld".

    Example 3:

    >>> smallestEquivalentString(s1 = "leetcode", s2 = "programs", baseStr = "sourcecode")
    >>> "aauaaaaada"
    Explanation: We group the equivalent characters in s1 and s2 as [a,o,e,r,s,c], [l,p], [g,t] and [d,m], thus all letters in baseStr except 'u' and 'd' are transformed to 'a', the answer is "aauaaaaada".
    """


Prompt:
def longestRepeatingSubstring(s: str) -> int:
    """
    Given a string s, return the length of the longest repeating substrings. If no repeating substring exists, return 0.

    Example 1:

    >>> longestRepeatingSubstring(s = "abcd")
    >>> 0
    Explanation: There is no repeating substring.

    Example 2:

    >>> longestRepeatingSubstring(s = "abbaba")
    >>> 2
    Explanation: The longest repeating substrings are "ab" and "ba", each of which occurs twice.

    Example 3:

    >>> longestRepeatingSubstring(s = "aabcaabdaab")
    >>> 3
    Explanation: The longest repeating substring is "aab", which occurs 3 times.
    """


Prompt:
from typing import List
def validSubarrays(nums: List[int]) -> int:
    """
    Given an integer array nums, return the number of non-empty subarrays with the leftmost element of the subarray not larger than other elements in the subarray.
    A subarray is a contiguous part of an array.

    Example 1:

    >>> validSubarrays(nums = [1,4,2,5,3])
    >>> 11
    Explanation: There are 11 valid subarrays: [1],[4],[2],[5],[3],[1,4],[2,5],[1,4,2],[2,5,3],[1,4,2,5],[1,4,2,5,3].

    Example 2:

    >>> validSubarrays(nums = [3,2,1])
    >>> 3
    Explanation: The 3 valid subarrays are: [3],[2],[1].

    Example 3:

    >>> validSubarrays(nums = [2,2,2])
    >>> 6
    Explanation: There are 6 valid subarrays: [2],[2],[2],[2,2],[2,2],[2,2,2].
    """


Prompt:
from typing import List
def fixedPoint(arr: List[int]) -> int:
    """
    Given an array of distinct integers arr, where arr is sorted in ascending order, return the smallest index i that satisfies arr[i] == i. If there is no such index, return -1.

    Example 1:

    >>> fixedPoint(arr = [-10,-5,0,3,7])
    >>> 3
    Explanation: For the given array, arr[0] = -10, arr[1] = -5, arr[2] = 0, arr[3] = 3, thus the output is 3.
    Example 2:

    >>> fixedPoint(arr = [0,2,5,8,17])
    >>> 0
    Explanation: arr[0] = 0, thus the output is 0.
    Example 3:

    >>> fixedPoint(arr = [-10,-5,3,4,7,9])
    >>> -1
    Explanation: There is no such i that arr[i] == i, thus the output is -1.
    """


Prompt:
from typing import List
def indexPairs(text: str, words: List[str]) -> List[List[int]]:
    """
    Given a string text and an array of strings words, return an array of all index pairs [i, j] so that the substring text[i...j] is in words.
    Return the pairs [i, j] in sorted order (i.e., sort them by their first coordinate, and in case of ties sort them by their second coordinate).

    Example 1:

    >>> indexPairs(text = "thestoryofleetcodeandme", words = ["story","fleet","leetcode"])
    >>> [[3,7],[9,13],[10,17]]

    Example 2:

    >>> indexPairs(text = "ababa", words = ["aba","ab"])
    >>> [[0,1],[0,2],[2,3],[2,4]]
    Explanation: Notice that matches can overlap, see "aba" is found in [0,2] and [2,4].
    """


Prompt:
from typing import List
def assignBikes(workers: List[List[int]], bikes: List[List[int]]) -> int:
    """
    On a campus represented as a 2D grid, there are n workers and m bikes, with n <= m. Each worker and bike is a 2D coordinate on this grid.
    We assign one unique bike to each worker so that the sum of the Manhattan distances between each worker and their assigned bike is minimized.
    Return the minimum possible sum of Manhattan distances between each worker and their assigned bike.
    The Manhattan distance between two points p1 and p2 is Manhattan(p1, p2) = |p1.x - p2.x| + |p1.y - p2.y|.

    Example 1:

    >>> assignBikes(workers = [[0,0],[2,1]], bikes = [[1,2],[3,3]])
    >>> 6
    Explanation:
    We assign bike 0 to worker 0, bike 1 to worker 1. The Manhattan distance of both assignments is 3, so the output is 6.

    Example 2:

    >>> assignBikes(workers = [[0,0],[1,1],[2,0]], bikes = [[1,0],[2,2],[2,1]])
    >>> 4
    Explanation:
    We first assign bike 0 to worker 0, then assign bike 1 to worker 1 or worker 2, bike 2 to worker 2 or worker 1. Both assignments lead to sum of the Manhattan distances as 4.

    Example 3:

    >>> assignBikes(workers = [[0,0],[1,0],[2,0],[3,0],[4,0]], bikes = [[0,999],[1,999],[2,999],[3,999],[4,999]])
    >>> 4995
    """


Prompt:
def digitsCount(d: int, low: int, high: int) -> int:
    """
    Given a single-digit integer d and two integers low and high, return the number of times that d occurs as a digit in all integers in the inclusive range [low, high].

    Example 1:

    >>> digitsCount(d = 1, low = 1, high = 13)
    >>> 6
    Explanation: The digit d = 1 occurs 6 times in 1, 10, 11, 12, 13.
    Note that the digit d = 1 occurs twice in the number 11.

    Example 2:

    >>> digitsCount(d = 3, low = 100, high = 250)
    >>> 35
    Explanation: The digit d = 3 occurs 35 times in 103,113,123,130,131,...,238,239,243.
    """


Prompt:
def gcdOfStrings(str1: str, str2: str) -> str:
    """
    For two strings s and t, we say "t divides s" if and only if s = t + t + t + ... + t + t (i.e., t is concatenated with itself one or more times).
    Given two strings str1 and str2, return the largest string x such that x divides both str1 and str2.

    Example 1:

    >>> gcdOfStrings(str1 = "ABCABC", str2 = "ABC")
    >>> "ABC"

    Example 2:

    >>> gcdOfStrings(str1 = "ABABAB", str2 = "ABAB")
    >>> "AB"

    Example 3:

    >>> gcdOfStrings(str1 = "LEET", str2 = "CODE")
    >>> ""
    """


Prompt:
from typing import List
def maxEqualRowsAfterFlips(matrix: List[List[int]]) -> int:
    """
    You are given an m x n binary matrix matrix.
    You can choose any number of columns in the matrix and flip every cell in that column (i.e., Change the value of the cell from 0 to 1 or vice versa).
    Return the maximum number of rows that have all values equal after some number of flips.

    Example 1:

    >>> maxEqualRowsAfterFlips(matrix = [[0,1],[1,1]])
    >>> 1
    Explanation: After flipping no values, 1 row has all values equal.

    Example 2:

    >>> maxEqualRowsAfterFlips(matrix = [[0,1],[1,0]])
    >>> 2
    Explanation: After flipping values in the first column, both rows have equal values.

    Example 3:

    >>> maxEqualRowsAfterFlips(matrix = [[0,0,0],[0,0,1],[1,1,0]])
    >>> 2
    Explanation: After flipping values in the first two columns, the last two rows have equal values.
    """


Prompt:
from typing import List
def addNegabinary(arr1: List[int], arr2: List[int]) -> List[int]:
    """
    Given two numbers arr1 and arr2 in base -2, return the result of adding them together.
    Each number is given in array format:  as an array of 0s and 1s, from most significant bit to least significant bit.  For example, arr = [1,1,0,1] represents the number (-2)^3 + (-2)^2 + (-2)^0 = -3.  A number arr in array, format is also guaranteed to have no leading zeros: either arr == [0] or arr[0] == 1.
    Return the result of adding arr1 and arr2 in the same format: as an array of 0s and 1s with no leading zeros.

    Example 1:

    >>> addNegabinary(arr1 = [1,1,1,1,1], arr2 = [1,0,1])
    >>> [1,0,0,0,0]
    Explanation: arr1 represents 11, arr2 represents 5, the output represents 16.

    Example 2:

    >>> addNegabinary(arr1 = [0], arr2 = [0])
    >>> [0]

    Example 3:

    >>> addNegabinary(arr1 = [0], arr2 = [1])
    >>> [1]
    """


Prompt:
from typing import List
def numSubmatrixSumTarget(matrix: List[List[int]], target: int) -> int:
    """
    Given a matrix and a target, return the number of non-empty submatrices that sum to target.
    A submatrix x1, y1, x2, y2 is the set of all cells matrix[x][y] with x1 <= x <= x2 and y1 <= y <= y2.
    Two submatrices (x1, y1, x2, y2) and (x1', y1', x2', y2') are different if they have some coordinate that is different: for example, if x1 != x1'.

    Example 1:

    >>> numSubmatrixSumTarget(matrix = [[0,1,0],[1,1,1],[0,1,0]], target = 0)
    >>> 4
    Explanation: The four 1x1 submatrices that only contain 0.

    Example 2:

    >>> numSubmatrixSumTarget(matrix = [[1,-1],[-1,1]], target = 0)
    >>> 5
    Explanation: The two 1x2 submatrices, plus the two 2x1 submatrices, plus the 2x2 submatrix.

    Example 3:

    >>> numSubmatrixSumTarget(matrix = [[904]], target = 0)
    >>> 0
    """


Prompt:
from typing import List
def findOcurrences(text: str, first: str, second: str) -> List[str]:
    """
    Given two strings first and second, consider occurrences in some text of the form "first second third", where second comes immediately after first, and third comes immediately after second.
    Return an array of all the words third for each occurrence of "first second third".

    Example 1:
    >>> findOcurrences(text = "alice is a good girl she is a good student", first = "a", second = "good")
    >>> ["girl","student"]
    Example 2:
    >>> findOcurrences(text = "we will we will rock you", first = "we", second = "will")
    >>> ["we","rock"]
    """


Prompt:
def numTilePossibilities(tiles: str) -> int:
    """
    You have n  tiles, where each tile has one letter tiles[i] printed on it.
    Return the number of possible non-empty sequences of letters you can make using the letters printed on those tiles.

    Example 1:

    >>> numTilePossibilities(tiles = "AAB")
    >>> 8
    Explanation: The possible sequences are "A", "B", "AA", "AB", "BA", "AAB", "ABA", "BAA".

    Example 2:

    >>> numTilePossibilities(tiles = "AAABBC")
    >>> 188

    Example 3:

    >>> numTilePossibilities(tiles = "V")
    >>> 1
    """


Prompt:
from typing import Optional
class TreeNode:
    def __init__(val=0, left=None, right=None):
        self.val = val
        self.left = left
        self.right = right
def sufficientSubset(root: Optional[TreeNode], limit: int) -> Optional[TreeNode]:
"""
Given the root of a binary tree and an integer limit, delete all insufficient nodes in the tree simultaneously, and return the root of the resulting binary tree.
A node is insufficient if every root to leaf path intersecting this node has a sum strictly less than limit.
A leaf is a node with no children.

Example 1:

>>> sufficientSubset(root = [1,2,3,4,-99,-99,7,8,9,-99,-99,12,13,-99,14], limit = 1)
>>> [1,2,3,4,null,null,7,8,9,null,14]

Example 2:

>>> sufficientSubset(root = [5,4,8,11,null,17,4,7,1,null,null,5,3], limit = 22)
>>> [5,4,8,11,null,17,4,7,null,null,null,5]

Example 3:

>>> sufficientSubset(root = [1,2,-3,-5,null,4,null], limit = -1)
>>> [1,null,-3,4]
"""


Prompt:
def smallestSubsequence(s: str) -> str:
    """
    Given a string s, return the lexicographically smallest subsequence of s that contains all the distinct characters of s exactly once.

    Example 1:

    >>> smallestSubsequence(s = "bcabc")
    >>> "abc"

    Example 2:

    >>> smallestSubsequence(s = "cbacdcbc")
    >>> "acdb"
    """


Prompt:
from typing import List
def sumOfDigits(nums: List[int]) -> int:
    """
    Given an integer array nums, return 0 if the sum of the digits of the minimum integer in nums is odd, or 1 otherwise.

    Example 1:

    >>> sumOfDigits(nums = [34,23,1,24,75,33,54,8])
    >>> 0
    Explanation: The minimal element is 1, and the sum of those digits is 1 which is odd, so the answer is 0.

    Example 2:

    >>> sumOfDigits(nums = [99,77,33,66,55])
    >>> 1
    Explanation: The minimal element is 33, and the sum of those digits is 3 + 3 = 6 which is even, so the answer is 1.
    """


Prompt:
from typing import List
def highFive(items: List[List[int]]) -> List[List[int]]:
    """
    Given a list of the scores of different students, items, where items[i] = [IDi, scorei] represents one score from a student with IDi, calculate each student's top five average.
    Return the answer as an array of pairs result, where result[j] = [IDj, topFiveAveragej] represents the student with IDj and their top five average. Sort result by IDj in increasing order.
    A student's top five average is calculated by taking the sum of their top five scores and dividing it by 5 using integer division.

    Example 1:

    >>> highFive(items = [[1,91],[1,92],[2,93],[2,97],[1,60],[2,77],[1,65],[1,87],[1,100],[2,100],[2,76]])
    >>> [[1,87],[2,88]]
    Explanation:
    The student with ID = 1 got scores 91, 92, 60, 65, 87, and 100. Their top five average is (100 + 92 + 91 + 87 + 65) / 5 = 87.
    The student with ID = 2 got scores 93, 97, 77, 100, and 76. Their top five average is (100 + 97 + 93 + 77 + 76) / 5 = 88.6, but with integer division their average converts to 88.

    Example 2:

    >>> highFive(items = [[1,100],[7,100],[1,100],[7,100],[1,100],[7,100],[1,100],[7,100],[1,100],[7,100]])
    >>> [[1,100],[7,100]]
    """


Prompt:
from typing import List
def expand(s: str) -> List[str]:
    """
    You are given a string s representing a list of words. Each letter in the word has one or more options.

    If there is one option, the letter is represented as is.
    If there is more than one option, then curly braces delimit the options. For example, "{a,b,c}" represents options ["a", "b", "c"].

    For example, if s = "a{b,c}", the first character is always 'a', but the second character can be 'b' or 'c'. The original list is ["ab", "ac"].
    Return all words that can be formed in this manner, sorted in lexicographical order.

    Example 1:
    >>> expand(s = "{a,b}c{d,e}f")
    >>> ["acdf","acef","bcdf","bcef"]
    Example 2:
    >>> expand(s = "abcd")
    >>> ["abcd"]
    """


Prompt:
def confusingNumberII(n: int) -> int:
    """
    A confusing number is a number that when rotated 180 degrees becomes a different number with each digit valid.
    We can rotate digits of a number by 180 degrees to form new digits.

    When 0, 1, 6, 8, and 9 are rotated 180 degrees, they become 0, 1, 9, 8, and 6 respectively.
    When 2, 3, 4, 5, and 7 are rotated 180 degrees, they become invalid.

    Note that after rotating a number, we can ignore leading zeros.

    For example, after rotating 8000, we have 0008 which is considered as just 8.

    Given an integer n, return the number of confusing numbers in the inclusive range [1, n].

    Example 1:

    >>> confusingNumberII(n = 20)
    >>> 6
    Explanation: The confusing numbers are [6,9,10,16,18,19].
    6 converts to 9.
    9 converts to 6.
    10 converts to 01 which is just 1.
    16 converts to 91.
    18 converts to 81.
    19 converts to 61.

    Example 2:

    >>> confusingNumberII(n = 100)
    >>> 19
    Explanation: The confusing numbers are [6,9,10,16,18,19,60,61,66,68,80,81,86,89,90,91,98,99,100].
    """


Prompt:
from typing import List
def duplicateZeros(arr: List[int]) -> None:
        """
        Do not return anything, modify arr in-place instead.
        """
    """
    Given a fixed-length integer array arr, duplicate each occurrence of zero, shifting the remaining elements to the right.
    Note that elements beyond the length of the original array are not written. Do the above modifications to the input array in place and do not return anything.

    Example 1:

    >>> duplicateZeros(arr = [1,0,2,3,0,4,5,0])
    >>> [1,0,0,2,3,0,0,4]
    Explanation: After calling your function, the input array is modified to: [1,0,0,2,3,0,0,4]

    Example 2:

    >>> duplicateZeros(arr = [1,2,3])
    >>> [1,2,3]
    Explanation: After calling your function, the input array is modified to: [1,2,3]
    """


Prompt:
from typing import List
def largestValsFromLabels(values: List[int], labels: List[int], numWanted: int, useLimit: int) -> int:
    """
    You are given n item's value and label as two integer arrays values and labels. You are also given two integers numWanted and useLimit.
    Your task is to find a subset of items with the maximum sum of their values such that:

    The number of items is at most numWanted.
    The number of items with the same label is at most useLimit.

    Return the maximum sum.

    Example 1:

    >>> largestValsFromLabels(values = [5,4,3,2,1], labels = [1,1,2,2,3], numWanted = 3, useLimit = 1)
    >>> 9
    Explanation:
    The subset chosen is the first, third, and fifth items with the sum of values 5 + 3 + 1.

    Example 2:

    >>> largestValsFromLabels(values = [5,4,3,2,1], labels = [1,3,3,3,2], numWanted = 3, useLimit = 2)
    >>> 12
    Explanation:
    The subset chosen is the first, second, and third items with the sum of values 5 + 4 + 3.

    Example 3:

    >>> largestValsFromLabels(values = [9,8,8,7,6], labels = [0,0,0,1,1], numWanted = 3, useLimit = 1)
    >>> 16
    Explanation:
    The subset chosen is the first and fourth items with the sum of values 9 + 7.
    """


Prompt:
from typing import List
def shortestPathBinaryMatrix(grid: List[List[int]]) -> int:
    """
    Given an n x n binary matrix grid, return the length of the shortest clear path in the matrix. If there is no clear path, return -1.
    A clear path in a binary matrix is a path from the top-left cell (i.e., (0, 0)) to the bottom-right cell (i.e., (n - 1, n - 1)) such that:

    All the visited cells of the path are 0.
    All the adjacent cells of the path are 8-directionally connected (i.e., they are different and they share an edge or a corner).

    The length of a clear path is the number of visited cells of this path.

    Example 1:

    >>> shortestPathBinaryMatrix(grid = [[0,1],[1,0]])
    >>> 2

    Example 2:

    >>> shortestPathBinaryMatrix(grid = [[0,0,0],[1,1,0],[1,1,0]])
    >>> 4

    Example 3:

    >>> shortestPathBinaryMatrix(grid = [[1,0,0],[1,1,0],[1,1,0]])
    >>> -1
    """


Prompt:
def shortestCommonSupersequence(str1: str, str2: str) -> str:
    """
    Given two strings str1 and str2, return the shortest string that has both str1 and str2 as subsequences. If there are multiple valid strings, return any of them.
    A string s is a subsequence of string t if deleting some number of characters from t (possibly 0) results in the string s.

    Example 1:

    >>> shortestCommonSupersequence(str1 = "abac", str2 = "cab")
    >>> "cabac"
    Explanation:
    str1 = "abac" is a subsequence of "cabac" because we can delete the first "c".
    str2 = "cab" is a subsequence of "cabac" because we can delete the last "ac".
    The answer provided is the shortest such string that satisfies these properties.

    Example 2:

    >>> shortestCommonSupersequence(str1 = "aaaaaaaa", str2 = "aaaaaaaa")
    >>> "aaaaaaaa"
    """


Prompt:
from typing import List
def sampleStats(count: List[int]) -> List[float]:
    """
    You are given a large sample of integers in the range [0, 255]. Since the sample is so large, it is represented by an array count where count[k] is the number of times that k appears in the sample.
    Calculate the following statistics:

    minimum: The minimum element in the sample.
    maximum: The maximum element in the sample.
    mean: The average of the sample, calculated as the total sum of all elements divided by the total number of elements.
    median:

    If the sample has an odd number of elements, then the median is the middle element once the sample is sorted.
    If the sample has an even number of elements, then the median is the average of the two middle elements once the sample is sorted.

    mode: The number that appears the most in the sample. It is guaranteed to be unique.

    Return the statistics of the sample as an array of floating-point numbers [minimum, maximum, mean, median, mode]. Answers within 10-5 of the actual answer will be accepted.

    Example 1:

    >>> sampleStats(count = [0,1,3,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0])
    >>> [1.00000,3.00000,2.37500,2.50000,3.00000]
    Explanation: The sample represented by count is [1,2,2,2,3,3,3,3].
    The minimum and maximum are 1 and 3 respectively.
    The mean is (1+2+2+2+3+3+3+3) / 8 = 19 / 8 = 2.375.
    Since the size of the sample is even, the median is the average of the two middle elements 2 and 3, which is 2.5.
    The mode is 3 as it appears the most in the sample.

    Example 2:

    >>> sampleStats(count = [0,4,3,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0])
    >>> [1.00000,4.00000,2.18182,2.00000,1.00000]
    Explanation: The sample represented by count is [1,1,1,1,2,2,2,3,3,4,4].
    The minimum and maximum are 1 and 4 respectively.
    The mean is (1+1+1+1+2+2+2+3+3+4+4) / 11 = 24 / 11 = 2.18181818... (for display purposes, the output shows the rounded number 2.18182).
    Since the size of the sample is odd, the median is the middle element 2.
    The mode is 1 as it appears the most in the sample.
    """


Prompt:
from typing import List
def carPooling(trips: List[List[int]], capacity: int) -> bool:
    """
    There is a car with capacity empty seats. The vehicle only drives east (i.e., it cannot turn around and drive west).
    You are given the integer capacity and an array trips where trips[i] = [numPassengersi, fromi, toi] indicates that the ith trip has numPassengersi passengers and the locations to pick them up and drop them off are fromi and toi respectively. The locations are given as the number of kilometers due east from the car's initial location.
    Return true if it is possible to pick up and drop off all passengers for all the given trips, or false otherwise.

    Example 1:

    >>> carPooling(trips = [[2,1,5],[3,3,7]], capacity = 4)
    >>> false

    Example 2:

    >>> carPooling(trips = [[2,1,5],[3,3,7]], capacity = 5)
    >>> true
    """


Prompt:
from typing import List
def braceExpansionII(expression: str) -> List[str]:
    """
    Under the grammar given below, strings can represent a set of lowercase words. Let R(expr) denote the set of words the expression represents.
    The grammar can best be understood through simple examples:

    Single letters represent a singleton set containing that word.

    R("a") = {"a"}
    R("w") = {"w"}

    When we take a comma-delimited list of two or more expressions, we take the union of possibilities.

    R("{a,b,c}") = {"a","b","c"}
    R("{{a,b},{b,c}}") = {"a","b","c"} (notice the final set only contains each word at most once)

    When we concatenate two expressions, we take the set of possible concatenations between two words where the first word comes from the first expression and the second word comes from the second expression.

    R("{a,b}{c,d}") = {"ac","ad","bc","bd"}
    R("a{b,c}{d,e}f{g,h}") = {"abdfg", "abdfh", "abefg", "abefh", "acdfg", "acdfh", "acefg", "acefh"}

    Formally, the three rules for our grammar:

    For every lowercase letter x, we have R(x) = {x}.
    For expressions e1, e2, ... , ek with k >= 2, we have R({e1, e2, ...}) = R(e1) ∪ R(e2) ∪ ...
    For expressions e1 and e2, we have R(e1 + e2) = {a + b for (a, b) in R(e1) × R(e2)}, where + denotes concatenation, and × denotes the cartesian product.

    Given an expression representing a set of words under the given grammar, return the sorted list of words that the expression represents.

    Example 1:

    >>> braceExpansionII(expression = "{a,b}{c,{d,e}}")
    >>> ["ac","ad","ae","bc","bd","be"]

    Example 2:

    >>> braceExpansionII(expression = "{{a,z},a{b,c},{ab,z}}")
    >>> ["a","ab","ac","z"]
    Explanation: Each distinct word is written only once in the final answer.
    """


Prompt:
from typing import List
def twoSumLessThanK(nums: List[int], k: int) -> int:
    """
    Given an array nums of integers and integer k, return the maximum sum such that there exists i < j with nums[i] + nums[j] = sum and sum < k. If no i, j exist satisfying this equation, return -1.

    Example 1:

    >>> twoSumLessThanK(nums = [34,23,1,24,75,33,54,8], k = 60)
    >>> 58
    Explanation: We can use 34 and 24 to sum 58 which is less than 60.

    Example 2:

    >>> twoSumLessThanK(nums = [10,20,30], k = 15)
    >>> -1
    Explanation: In this case it is not possible to get a pair sum less that 15.
    """


Prompt:
def numKLenSubstrNoRepeats(s: str, k: int) -> int:
    """
    Given a string s and an integer k, return the number of substrings in s of length k with no repeated characters.

    Example 1:

    >>> numKLenSubstrNoRepeats(s = "havefunonleetcode", k = 5)
    >>> 6
    Explanation: There are 6 substrings they are: 'havef','avefu','vefun','efuno','etcod','tcode'.

    Example 2:

    >>> numKLenSubstrNoRepeats(s = "home", k = 5)
    >>> 0
    Explanation: Notice k can be larger than the length of s. In this case, it is not possible to find any substring.
    """


Prompt:
from typing import List
def earliestAcq(logs: List[List[int]], n: int) -> int:
    """
    There are n people in a social group labeled from 0 to n - 1. You are given an array logs where logs[i] = [timestampi, xi, yi] indicates that xi and yi will be friends at the time timestampi.
    Friendship is symmetric. That means if a is friends with b, then b is friends with a. Also, person a is acquainted with a person b if a is friends with b, or a is a friend of someone acquainted with b.
    Return the earliest time for which every person became acquainted with every other person. If there is no such earliest time, return -1.

    Example 1:

    >>> earliestAcq(logs = [[20190101,0,1],[20190104,3,4],[20190107,2,3],[20190211,1,5],[20190224,2,4],[20190301,0,3],[20190312,1,2],[20190322,4,5]], n = 6)
    >>> 20190301
    Explanation:
    The first event occurs at timestamp = 20190101, and after 0 and 1 become friends, we have the following friendship groups [0,1], [2], [3], [4], [5].
    The second event occurs at timestamp = 20190104, and after 3 and 4 become friends, we have the following friendship groups [0,1], [2], [3,4], [5].
    The third event occurs at timestamp = 20190107, and after 2 and 3 become friends, we have the following friendship groups [0,1], [2,3,4], [5].
    The fourth event occurs at timestamp = 20190211, and after 1 and 5 become friends, we have the following friendship groups [0,1,5], [2,3,4].
    The fifth event occurs at timestamp = 20190224, and as 2 and 4 are already friends, nothing happens.
    The sixth event occurs at timestamp = 20190301, and after 0 and 3 become friends, we all become friends.

    Example 2:

    >>> earliestAcq(logs = [[0,2,0],[1,0,1],[3,0,3],[4,1,2],[7,3,1]], n = 4)
    >>> 3
    Explanation: At timestamp = 3, all the persons (i.e., 0, 1, 2, and 3) become friends.
    """


Prompt:
from typing import List
def maximumMinimumPath(grid: List[List[int]]) -> int:
    """
    Given an m x n integer matrix grid, return the maximum score of a path starting at (0, 0) and ending at (m - 1, n - 1) moving in the 4 cardinal directions.
    The score of a path is the minimum value in that path.

    For example, the score of the path 8 → 4 → 5 → 9 is 4.

    Example 1:

    >>> maximumMinimumPath(grid = [[5,4,5],[1,2,6],[7,4,6]])
    >>> 4
    Explanation: The path with the maximum score is highlighted in yellow.

    Example 2:

    >>> maximumMinimumPath(grid = [[2,2,1,2,2,2],[1,2,2,2,1,2]])
    >>> 2

    Example 3:

    >>> maximumMinimumPath(grid = [[3,4,6,3,4],[0,2,1,1,7],[8,8,3,2,7],[3,2,4,9,8],[4,1,2,0,0],[4,6,5,4,3]])
    >>> 3
    """


Prompt:
from typing import List
def distributeCandies(candies: int, num_people: int) -> List[int]:
    """
    We distribute some number of candies, to a row of n = num_people people in the following way:
    We then give 1 candy to the first person, 2 candies to the second person, and so on until we give n candies to the last person.
    Then, we go back to the start of the row, giving n + 1 candies to the first person, n + 2 candies to the second person, and so on until we give 2 * n candies to the last person.
    This process repeats (with us giving one more candy each time, and moving to the start of the row after we reach the end) until we run out of candies.  The last person will receive all of our remaining candies (not necessarily one more than the previous gift).
    Return an array (of length num_people and sum candies) that represents the final distribution of candies.

    Example 1:

    >>> distributeCandies(candies = 7, num_people = 4)
    >>> [1,2,3,1]
    Explanation:
    On the first turn, ans[0] += 1, and the array is [1,0,0,0].
    On the second turn, ans[1] += 2, and the array is [1,2,0,0].
    On the third turn, ans[2] += 3, and the array is [1,2,3,0].
    On the fourth turn, ans[3] += 1 (because there is only one candy left), and the final array is [1,2,3,1].

    Example 2:

    >>> distributeCandies(candies = 10, num_people = 3)
    >>> [5,2,3]
    Explanation:
    On the first turn, ans[0] += 1, and the array is [1,0,0].
    On the second turn, ans[1] += 2, and the array is [1,2,0].
    On the third turn, ans[2] += 3, and the array is [1,2,3].
    On the fourth turn, ans[0] += 4, and the final array is [5,2,3].
    """


Prompt:
from typing import List
def pathInZigZagTree(label: int) -> List[int]:
    """
    In an infinite binary tree where every node has two children, the nodes are labelled in row order.
    In the odd numbered rows (ie., the first, third, fifth,...), the labelling is left to right, while in the even numbered rows (second, fourth, sixth,...), the labelling is right to left.

    Given the label of a node in this tree, return the labels in the path from the root of the tree to the node with that label.

    Example 1:

    >>> pathInZigZagTree(label = 14)
    >>> [1,3,4,14]

    Example 2:

    >>> pathInZigZagTree(label = 26)
    >>> [1,2,6,10,26]
    """


Prompt:
from typing import List
def minHeightShelves(books: List[List[int]], shelfWidth: int) -> int:
    """
    You are given an array books where books[i] = [thicknessi, heighti] indicates the thickness and height of the ith book. You are also given an integer shelfWidth.
    We want to place these books in order onto bookcase shelves that have a total width shelfWidth.
    We choose some of the books to place on this shelf such that the sum of their thickness is less than or equal to shelfWidth, then build another level of the shelf of the bookcase so that the total height of the bookcase has increased by the maximum height of the books we just put down. We repeat this process until there are no more books to place.
    Note that at each step of the above process, the order of the books we place is the same order as the given sequence of books.

    For example, if we have an ordered list of 5 books, we might place the first and second book onto the first shelf, the third book on the second shelf, and the fourth and fifth book on the last shelf.

    Return the minimum possible height that the total bookshelf can be after placing shelves in this manner.

    Example 1:

    >>> minHeightShelves(books = [[1,1],[2,3],[2,3],[1,1],[1,1],[1,1],[1,2]], shelfWidth = 4)
    >>> 6
    Explanation:
    The sum of the heights of the 3 shelves is 1 + 3 + 2 = 6.
    Notice that book number 2 does not have to be on the first shelf.

    Example 2:

    >>> minHeightShelves(books = [[1,3],[2,4],[3,2]], shelfWidth = 6)
    >>> 4
    """


Prompt:
def parseBoolExpr(expression: str) -> bool:
    """
    A boolean expression is an expression that evaluates to either true or false. It can be in one of the following shapes:

    't' that evaluates to true.
    'f' that evaluates to false.
    '!(subExpr)' that evaluates to the logical NOT of the inner expression subExpr.
    '&(subExpr1, subExpr2, ..., subExprn)' that evaluates to the logical AND of the inner expressions subExpr1, subExpr2, ..., subExprn where n >= 1.
    '|(subExpr1, subExpr2, ..., subExprn)' that evaluates to the logical OR of the inner expressions subExpr1, subExpr2, ..., subExprn where n >= 1.

    Given a string expression that represents a boolean expression, return the evaluation of that expression.
    It is guaranteed that the given expression is valid and follows the given rules.

    Example 1:

    >>> parseBoolExpr(expression = "&(|(f))")
    >>> false
    Explanation:
    First, evaluate |(f) --> f. The expression is now "&(f)".
    Then, evaluate &(f) --> f. The expression is now "f".
    Finally, return false.

    Example 2:

    >>> parseBoolExpr(expression = "|(f,f,f,t)")
    >>> true
    Explanation: The evaluation of (false OR false OR false OR true) is true.

    Example 3:

    >>> parseBoolExpr(expression = "!(&(f,t))")
    >>> true
    Explanation:
    First, evaluate &(f,t) --> (false AND true) --> false --> f. The expression is now "!(f)".
    Then, evaluate !(f) --> NOT false --> true. We return true.
    """


Prompt:
def defangIPaddr(address: str) -> str:
    """
    Given a valid (IPv4) IP address, return a defanged version of that IP address.\r
    \r
    A defanged IP address replaces every period "." with "[.]".\r
    \r
     \r
    Example 1:\r
    >>> defangIPaddr(address = "1.1.1.1"\r)
    >>> "1[.]1[.]1[.]1"\r
    Example 2:\r
    >>> defangIPaddr(address = "255.100.50.0"\r)
    >>> "255[.]100[.]50[.]0"\r
    \r
     \r
    """


Prompt:
from typing import List
def corpFlightBookings(bookings: List[List[int]], n: int) -> List[int]:
    """
    There are n flights that are labeled from 1 to n.
    You are given an array of flight bookings bookings, where bookings[i] = [firsti, lasti, seatsi] represents a booking for flights firsti through lasti (inclusive) with seatsi seats reserved for each flight in the range.
    Return an array answer of length n, where answer[i] is the total number of seats reserved for flight i.

    Example 1:

    >>> corpFlightBookings(bookings = [[1,2,10],[2,3,20],[2,5,25]], n = 5)
    >>> [10,55,45,25,25]
    Explanation:
    Flight labels:        1   2   3   4   5
    Booking 1 reserved:  10  10
    Booking 2 reserved:      20  20
    Booking 3 reserved:      25  25  25  25
    Total seats:         10  55  45  25  25
    Hence, answer = [10,55,45,25,25]

    Example 2:

    >>> corpFlightBookings(bookings = [[1,2,10],[2,2,15]], n = 2)
    >>> [10,25]
    Explanation:
    Flight labels:        1   2
    Booking 1 reserved:  10  10
    Booking 2 reserved:      15
    Total seats:         10  25
    Hence, answer = [10,25]
    """