Prompt:
def mctFromLeafValues(arr: List[int]) -> int:
    """
    Given an array arr of positive integers, consider all binary trees such that:

    Each node has either 0 or 2 children;
    The values of arr correspond to the values of each leaf in an in-order traversal of the tree.
    The value of each non-leaf node is equal to the product of the largest leaf value in its left and right subtree, respectively.

    Among all possible binary trees considered, return the smallest possible sum of the values of each non-leaf node. It is guaranteed this sum fits into a 32-bit integer.
    A node is a leaf if and only if it has zero children.

    Example 1:

    >>> mctFromLeafValues(arr = [6,2,4])
    >>> 32
    Explanation: There are two possible trees shown.
    The first has a non-leaf node sum 36, and the second has non-leaf node sum 32.

    Example 2:

    >>> mctFromLeafValues(arr = [4,11])
    >>> 44
    """


Prompt:
def maxAbsValExpr(arr1: List[int], arr2: List[int]) -> int:
    """
    Given two arrays of integers with equal lengths, return the maximum value of:\r
    \r
    |arr1[i] - arr1[j]| + |arr2[i] - arr2[j]| + |i - j|\r
    \r
    where the maximum is taken over all 0 <= i, j < arr1.length.\r

    Example 1:

    >>> maxAbsValExpr(arr1 = [1,2,3,4], arr2 = [-1,4,5,6])
    >>> 13

    Example 2:

    >>> maxAbsValExpr(arr1 = [1,-2,-5,0,10], arr2 = [0,-2,-1,-7,-4])
    >>> 20
    """


Prompt:
def largestUniqueNumber(nums: List[int]) -> int:
    """
    Given an integer array nums, return the largest integer that only occurs once. If no integer occurs once, return -1.

    Example 1:

    >>> largestUniqueNumber(nums = [5,7,3,9,4,9,8,3,1])
    >>> 8
    Explanation: The maximum integer in the array is 9 but it is repeated. The number 8 occurs only once, so it is the answer.
    Example 2:

    >>> largestUniqueNumber(nums = [9,9,8,8])
    >>> -1
    Explanation: There is no number that occurs only once.
    """


Prompt:
def isArmstrong(n: int) -> bool:
    """
    Given an integer n, return true if and only if it is an Armstrong number.
    The k-digit number n is an Armstrong number if and only if the kth power of each digit sums to n.

    Example 1:

    >>> isArmstrong(n = 153)
    >>> true
    Explanation: 153 is a 3-digit number, and 153 = 13 + 53 + 33.

    Example 2:

    >>> isArmstrong(n = 123)
    >>> false
    Explanation: 123 is a 3-digit number, and 123 != 13 + 23 + 33 = 36.
    """


Prompt:
def minimumCost(n: int, connections: List[List[int]]) -> int:
    """
    There are n cities labeled from 1 to n. You are given the integer n and an array connections where connections[i] = [xi, yi, costi] indicates that the cost of connecting city xi and city yi (bidirectional connection) is costi.
    Return the minimum cost to connect all the n cities such that there is at least one path between each pair of cities. If it is impossible to connect all the n cities, return -1,
    The cost is the sum of the connections' costs used.

    Example 1:

    >>> minimumCost(n = 3, connections = [[1,2,5],[1,3,6],[2,3,1]])
    >>> 6
    Explanation: Choosing any 2 edges will connect all cities so we choose the minimum 2.

    Example 2:

    >>> minimumCost(n = 4, connections = [[1,2,3],[3,4,4]])
    >>> -1
    Explanation: There is no way to connect all cities even if all edges are used.
    """


Prompt:
def minimumSemesters(n: int, relations: List[List[int]]) -> int:
    """
    You are given an integer n, which indicates that there are n courses labeled from 1 to n. You are also given an array relations where relations[i] = [prevCoursei, nextCoursei], representing a prerequisite relationship between course prevCoursei and course nextCoursei: course prevCoursei has to be taken before course nextCoursei.
    In one semester, you can take any number of courses as long as you have taken all the prerequisites in the previous semester for the courses you are taking.
    Return the minimum number of semesters needed to take all courses. If there is no way to take all the courses, return -1.

    Example 1:

    >>> minimumSemesters(n = 3, relations = [[1,3],[2,3]])
    >>> 2
    Explanation: The figure above represents the given graph.
    In the first semester, you can take courses 1 and 2.
    In the second semester, you can take course 3.

    Example 2:

    >>> minimumSemesters(n = 3, relations = [[1,2],[2,3],[3,1]])
    >>> -1
    Explanation: No course can be studied because they are prerequisites of each other.
    """


Prompt:
def tribonacci(n: int) -> int:
    """
    The Tribonacci sequence Tn is defined as follows:
    T0 = 0, T1 = 1, T2 = 1, and Tn+3 = Tn + Tn+1 + Tn+2 for n >= 0.
    Given n, return the value of Tn.

    Example 1:

    >>> tribonacci(n = 4)
    >>> 4
    Explanation:
    T_3 = 0 + 1 + 1 = 2
    T_4 = 1 + 1 + 2 = 4

    Example 2:

    >>> tribonacci(n = 25)
    >>> 1389537
    """


Prompt:
def alphabetBoardPath(target: str) -> str:
    """
    On an alphabet board, we start at position (0, 0), corresponding to character board[0][0].\r
    \r
    Here, board = ["abcde", "fghij", "klmno", "pqrst", "uvwxy", "z"], as shown in the diagram below.\r
    \r
    \r
    \r
    We may make the following moves:\r
    \r
    \r
    	'U' moves our position up one row, if the position exists on the board;\r
    	'D' moves our position down one row, if the position exists on the board;\r
    	'L' moves our position left one column, if the position exists on the board;\r
    	'R' moves our position right one column, if the position exists on the board;\r
    	'!' adds the character board[r][c] at our current position (r, c) to the answer.\r
    \r
    \r
    (Here, the only positions that exist on the board are positions with letters on them.)\r
    \r
    Return a sequence of moves that makes our answer equal to target in the minimum number of moves.  You may return any path that does so.\r
    \r
     \r
    Example 1:\r
    >>> alphabetBoardPath(target = "leet"\r)
    >>> "DDR!UURRR!!DDD!"\r
    Example 2:\r
    >>> alphabetBoardPath(target = "code"\r)
    >>> "RR!DDRR!UUL!R!"\r
    \r
     \r
    """


Prompt:
def largest1BorderedSquare(grid: List[List[int]]) -> int:
    """
    Given a 2D grid of 0s and 1s, return the number of elements in the largest square subgrid that has all 1s on its border, or 0 if such a subgrid doesn't exist in the grid.\r
    \r
     \r
    Example 1:\r
    \r
    \r
    >>> largest1BorderedSquare(grid = [[1,1,1],[1,0,1],[1,1,1]]\r)
    >>> 9\r
    \r
    \r
    Example 2:\r
    \r
    \r
    >>> largest1BorderedSquare(grid = [[1,1,0,0]]\r)
    >>> 1\r
    \r
    \r
     \r
    """


Prompt:
def stoneGameII(piles: List[int]) -> int:
    """
    Alice and Bob continue their games with piles of stones. There are a number of piles arranged in a row, and each pile has a positive integer number of stones piles[i]. The objective of the game is to end with the most stones.
    Alice and Bob take turns, with Alice starting first.
    On each player's turn, that player can take all the stones in the first X remaining piles, where 1 <= X <= 2M. Then, we set M = max(M, X). Initially, M = 1.
    The game continues until all the stones have been taken.
    Assuming Alice and Bob play optimally, return the maximum number of stones Alice can get.

    Example 1:

    >>> stoneGameII(piles = [2,7,9,4,4])
    >>> 10
    Explanation:

    If Alice takes one pile at the beginning, Bob takes two piles, then Alice takes 2 piles again. Alice can get 2 + 4 + 4 = 10 stones in total.
    If Alice takes two piles at the beginning, then Bob can take all three piles left. In this case, Alice get 2 + 7 = 9 stones in total.

    So we return 10 since it's larger.

    Example 2:

    >>> stoneGameII(piles = [1,2,3,4,5,100])
    >>> 104
    """


Prompt:
def longestCommonSubsequence(text1: str, text2: str) -> int:
    """
    Given two strings text1 and text2, return the length of their longest common subsequence. If there is no common subsequence, return 0.
    A subsequence of a string is a new string generated from the original string with some characters (can be none) deleted without changing the relative order of the remaining characters.

    For example, "ace" is a subsequence of "abcde".

    A common subsequence of two strings is a subsequence that is common to both strings.

    Example 1:

    >>> longestCommonSubsequence(text1 = "abcde", text2 = "ace")
    >>> 3
    Explanation: The longest common subsequence is "ace" and its length is 3.

    Example 2:

    >>> longestCommonSubsequence(text1 = "abc", text2 = "abc")
    >>> 3
    Explanation: The longest common subsequence is "abc" and its length is 3.

    Example 3:

    >>> longestCommonSubsequence(text1 = "abc", text2 = "def")
    >>> 0
    Explanation: There is no such common subsequence, so the result is 0.
    """


Prompt:
def movesToMakeZigzag(nums: List[int]) -> int:
    """
    Given an array nums of integers, a move consists of choosing any element and decreasing it by 1.
    An array A is a zigzag array if either:

    Every even-indexed element is greater than adjacent elements, ie. A[0] > A[1] < A[2] > A[3] < A[4] > ...
    OR, every odd-indexed element is greater than adjacent elements, ie. A[0] < A[1] > A[2] < A[3] > A[4] < ...

    Return the minimum number of moves to transform the given array nums into a zigzag array.

    Example 1:

    >>> movesToMakeZigzag(nums = [1,2,3])
    >>> 2
    Explanation: We can decrease 2 to 0 or 3 to 1.

    Example 2:

    >>> movesToMakeZigzag(nums = [9,6,1,6,2])
    >>> 4
    """


Prompt:
# class TreeNode:
#     def __init__(val=0, left=None, right=None):
#         self.val = val
#         self.left = left
#         self.right = right
class Solution:
    def btreeGameWinningMove(root: Optional[TreeNode], n: int, x: int) -> bool:
    """
    Two players play a turn based game on a binary tree. We are given the root of this binary tree, and the number of nodes n in the tree. n is odd, and each node has a distinct value from 1 to n.
    Initially, the first player names a value x with 1 <= x <= n, and the second player names a value y with 1 <= y <= n and y != x. The first player colors the node with value x red, and the second player colors the node with value y blue.
    Then, the players take turns starting with the first player. In each turn, that player chooses a node of their color (red if player 1, blue if player 2) and colors an uncolored neighbor of the chosen node (either the left child, right child, or parent of the chosen node.)
    If (and only if) a player cannot choose such a node in this way, they must pass their turn. If both players pass their turn, the game ends, and the winner is the player that colored more nodes.
    You are the second player. If it is possible to choose such a y to ensure you win the game, return true. If it is not possible, return false.

    Example 1:

    >>> __init__(root = [1,2,3,4,5,6,7,8,9,10,11], n = 11, x = 3)
    >>> true
    Explanation: The second player can choose the node with value 2.

    Example 2:

    >>> __init__(root = [1,2,3], n = 3, x = 1)
    >>> false
    """


Prompt:
def longestDecomposition(text: str) -> int:
    """
    You are given a string text. You should split it to k substrings (subtext1, subtext2, ..., subtextk) such that:

    subtexti is a non-empty string.
    The concatenation of all the substrings is equal to text (i.e., subtext1 + subtext2 + ... + subtextk == text).
    subtexti == subtextk - i + 1 for all valid values of i (i.e., 1 <= i <= k).

    Return the largest possible value of k.

    Example 1:

    >>> longestDecomposition(text = "ghiabcdefhelloadamhelloabcdefghi")
    >>> 7
    Explanation: We can split the string on "(ghi)(abcdef)(hello)(adam)(hello)(abcdef)(ghi)".

    Example 2:

    >>> longestDecomposition(text = "merchant")
    >>> 1
    Explanation: We can split the string on "(merchant)".

    Example 3:

    >>> longestDecomposition(text = "antaprezatepzapreanta")
    >>> 11
    Explanation: We can split the string on "(a)(nt)(a)(pre)(za)(tep)(za)(pre)(a)(nt)(a)".
    """


Prompt:
def isMajorityElement(nums: List[int], target: int) -> bool:
    """
    Given an integer array nums sorted in non-decreasing order and an integer target, return true if target is a majority element, or false otherwise.
    A majority element in an array nums is an element that appears more than nums.length / 2 times in the array.

    Example 1:

    >>> isMajorityElement(nums = [2,4,5,5,5,5,5,6,6], target = 5)
    >>> true
    Explanation: The value 5 appears 5 times and the length of the array is 9.
    Thus, 5 is a majority element because 5 > 9/2 is true.

    Example 2:

    >>> isMajorityElement(nums = [10,100,101,101], target = 101)
    >>> false
    Explanation: The value 101 appears 2 times and the length of the array is 4.
    Thus, 101 is not a majority element because 2 > 4/2 is false.
    """


Prompt:
def minSwaps(data: List[int]) -> int:
    """
    Given a binary array data, return the minimum number of swaps required to group all 1’s present in the array together in any place in the array.

    Example 1:

    >>> minSwaps(data = [1,0,1,0,1])
    >>> 1
    Explanation: There are 3 ways to group all 1's together:
    [1,1,1,0,0] using 1 swap.
    [0,1,1,1,0] using 2 swaps.
    [0,0,1,1,1] using 1 swap.
    The minimum is 1.

    Example 2:

    >>> minSwaps(data = [0,0,0,1,0])
    >>> 0
    Explanation: Since there is only one 1 in the array, no swaps are needed.

    Example 3:

    >>> minSwaps(data = [1,0,1,0,1,0,0,1,1,0,1])
    >>> 3
    Explanation: One possible solution that uses 3 swaps is [0,0,0,0,0,1,1,1,1,1,1].
    """


Prompt:
def mostVisitedPattern(username: List[str], timestamp: List[int], website: List[str]) -> List[str]:
    """
    You are given two string arrays username and website and an integer array timestamp. All the given arrays are of the same length and the tuple [username[i], website[i], timestamp[i]] indicates that the user username[i] visited the website website[i] at time timestamp[i].
    A pattern is a list of three websites (not necessarily distinct).

    For example, ["home", "away", "love"], ["leetcode", "love", "leetcode"], and ["luffy", "luffy", "luffy"] are all patterns.

    The score of a pattern is the number of users that visited all the websites in the pattern in the same order they appeared in the pattern.

    For example, if the pattern is ["home", "away", "love"], the score is the number of users x such that x visited "home" then visited "away" and visited "love" after that.
    Similarly, if the pattern is ["leetcode", "love", "leetcode"], the score is the number of users x such that x visited "leetcode" then visited "love" and visited "leetcode" one more time after that.
    Also, if the pattern is ["luffy", "luffy", "luffy"], the score is the number of users x such that x visited "luffy" three different times at different timestamps.

    Return the pattern with the largest score. If there is more than one pattern with the same largest score, return the lexicographically smallest such pattern.
    Note that the websites in a pattern do not need to be visited contiguously, they only need to be visited in the order they appeared in the pattern.

    Example 1:

    >>> mostVisitedPattern(username = ["joe","joe","joe","james","james","james","james","mary","mary","mary"], timestamp = [1,2,3,4,5,6,7,8,9,10], website = ["home","about","career","home","cart","maps","home","home","about","career"])
    >>> ["home","about","career"]
    Explanation: The tuples in this example are:
    ["joe","home",1],["joe","about",2],["joe","career",3],["james","home",4],["james","cart",5],["james","maps",6],["james","home",7],["mary","home",8],["mary","about",9], and ["mary","career",10].
    The pattern ("home", "about", "career") has score 2 (joe and mary).
    The pattern ("home", "cart", "maps") has score 1 (james).
    The pattern ("home", "cart", "home") has score 1 (james).
    The pattern ("home", "maps", "home") has score 1 (james).
    The pattern ("cart", "maps", "home") has score 1 (james).
    The pattern ("home", "home", "home") has score 0 (no user visited home 3 times).

    Example 2:

    >>> mostVisitedPattern(username = ["ua","ua","ua","ub","ub","ub"], timestamp = [1,2,3,4,5,6], website = ["a","b","a","a","b","c"])
    >>> ["a","b","a"]
    """


Prompt:
def canConvert(str1: str, str2: str) -> bool:
    """
    Given two strings str1 and str2 of the same length, determine whether you can transform str1 into str2 by doing zero or more conversions.
    In one conversion you can convert all occurrences of one character in str1 to any other lowercase English character.
    Return true if and only if you can transform str1 into str2.

    Example 1:

    >>> canConvert(str1 = "aabcc", str2 = "ccdee")
    >>> true
    Explanation: Convert 'c' to 'e' then 'b' to 'd' then 'a' to 'c'. Note that the order of conversions matter.

    Example 2:

    >>> canConvert(str1 = "leetcode", str2 = "codeleet")
    >>> false
    Explanation: There is no way to transform str1 to str2.
    """


Prompt:
def dayOfYear(date: str) -> int:
    """
    Given a string date representing a Gregorian calendar date formatted as YYYY-MM-DD, return the day number of the year.

    Example 1:

    >>> dayOfYear(date = "2019-01-09")
    >>> 9
    Explanation: Given date is the 9th day of the year in 2019.

    Example 2:

    >>> dayOfYear(date = "2019-02-10")
    >>> 41
    """


Prompt:
def numRollsToTarget(n: int, k: int, target: int) -> int:
    """
    You have n dice, and each dice has k faces numbered from 1 to k.
    Given three integers n, k, and target, return the number of possible ways (out of the kn total ways) to roll the dice, so the sum of the face-up numbers equals target. Since the answer may be too large, return it modulo 109 + 7.

    Example 1:

    >>> numRollsToTarget(n = 1, k = 6, target = 3)
    >>> 1
    Explanation: You throw one die with 6 faces.
    There is only one way to get a sum of 3.

    Example 2:

    >>> numRollsToTarget(n = 2, k = 6, target = 7)
    >>> 6
    Explanation: You throw two dice, each with 6 faces.
    There are 6 ways to get a sum of 7: 1+6, 2+5, 3+4, 4+3, 5+2, 6+1.

    Example 3:

    >>> numRollsToTarget(n = 30, k = 30, target = 500)
    >>> 222616187
    Explanation: The answer must be returned modulo 109 + 7.
    """


Prompt:
def maxRepOpt1(text: str) -> int:
    """
    You are given a string text. You can swap two of the characters in the text.
    Return the length of the longest substring with repeated characters.

    Example 1:

    >>> maxRepOpt1(text = "ababa")
    >>> 3
    Explanation: We can swap the first 'b' with the last 'a', or the last 'b' with the first 'a'. Then, the longest repeated character substring is "aaa" with length 3.

    Example 2:

    >>> maxRepOpt1(text = "aaabaaa")
    >>> 6
    Explanation: Swap 'b' with the last 'a' (or the first 'a'), and we get longest repeated character substring "aaaaaa" with length 6.

    Example 3:

    >>> maxRepOpt1(text = "aaaaa")
    >>> 5
    Explanation: No need to swap, longest repeated character substring is "aaaaa" with length is 5.
    """


Prompt:
def countCharacters(words: List[str], chars: str) -> int:
    """
    You are given an array of strings words and a string chars.
    A string is good if it can be formed by characters from chars (each character can only be used once).
    Return the sum of lengths of all good strings in words.

    Example 1:

    >>> countCharacters(words = ["cat","bt","hat","tree"], chars = "atach")
    >>> 6
    Explanation: The strings that can be formed are "cat" and "hat" so the answer is 3 + 3 = 6.

    Example 2:

    >>> countCharacters(words = ["hello","world","leetcode"], chars = "welldonehoneyr")
    >>> 10
    Explanation: The strings that can be formed are "hello" and "world" so the answer is 5 + 5 = 10.
    """


Prompt:
# class TreeNode:
#     def __init__(val=0, left=None, right=None):
#         self.val = val
#         self.left = left
#         self.right = right
class Solution:
    def maxLevelSum(root: Optional[TreeNode]) -> int:
    """
    Given the root of a binary tree, the level of its root is 1, the level of its children is 2, and so on.
    Return the smallest level x such that the sum of all the values of nodes at level x is maximal.

    Example 1:

    >>> __init__(root = [1,7,0,7,-8,null,null])
    >>> 2
    Explanation:
    Level 1 sum = 1.
    Level 2 sum = 7 + 0 = 7.
    Level 3 sum = 7 + -8 = -1.
    So we return the level with the maximum sum which is level 2.

    Example 2:

    >>> __init__(root = [989,null,10250,98693,-89388,null,null,null,-32127])
    >>> 2
    """


Prompt:
def maxDistance(grid: List[List[int]]) -> int:
    """
    Given an n x n grid containing only values 0 and 1, where 0 represents water and 1 represents land, find a water cell such that its distance to the nearest land cell is maximized, and return the distance. If no land or water exists in the grid, return -1.
    The distance used in this problem is the Manhattan distance: the distance between two cells (x0, y0) and (x1, y1) is |x0 - x1| + |y0 - y1|.

    Example 1:

    >>> maxDistance(grid = [[1,0,1],[0,0,0],[1,0,1]])
    >>> 2
    Explanation: The cell (1, 1) is as far as possible from all the land with distance 2.

    Example 2:

    >>> maxDistance(grid = [[1,0,0],[0,0,0],[0,0,0]])
    >>> 4
    Explanation: The cell (2, 2) is as far as possible from all the land with distance 4.
    """


Prompt:
def lastSubstring(s: str) -> str:
    """
    Given a string s, return the last substring of s in lexicographical order.

    Example 1:

    >>> lastSubstring(s = "abab")
    >>> "bab"
    Explanation: The substrings are ["a", "ab", "aba", "abab", "b", "ba", "bab"]. The lexicographically maximum substring is "bab".

    Example 2:

    >>> lastSubstring(s = "leetcode")
    >>> "tcode"
    """


Prompt:
def calculateTime(keyboard: str, word: str) -> int:
    """
    There is a special keyboard with all keys in a single row.
    Given a string keyboard of length 26 indicating the layout of the keyboard (indexed from 0 to 25). Initially, your finger is at index 0. To type a character, you have to move your finger to the index of the desired character. The time taken to move your finger from index i to index j is |i - j|.
    You want to type a string word. Write a function to calculate how much time it takes to type it with one finger.

    Example 1:

    >>> calculateTime(keyboard = "abcdefghijklmnopqrstuvwxyz", word = "cba")
    >>> 4
    Explanation: The index moves from 0 to 2 to write 'c' then to 1 to write 'b' then to 0 again to write 'a'.
    Total time = 2 + 1 + 1 = 4.

    Example 2:

    >>> calculateTime(keyboard = "pqrstuvwxyzabcdefghijklmno", word = "leetcode")
    >>> 73
    """


Prompt:
def connectSticks(sticks: List[int]) -> int:
    """
    You have some number of sticks with positive integer lengths. These lengths are given as an array sticks, where sticks[i] is the length of the ith stick.
    You can connect any two sticks of lengths x and y into one stick by paying a cost of x + y. You must connect all the sticks until there is only one stick remaining.
    Return the minimum cost of connecting all the given sticks into one stick in this way.

    Example 1:

    >>> connectSticks(sticks = [2,4,3])
    >>> 14
    Explanation: You start with sticks = [2,4,3].
    1. Combine sticks 2 and 3 for a cost of 2 + 3 = 5. Now you have sticks = [5,4].
    2. Combine sticks 5 and 4 for a cost of 5 + 4 = 9. Now you have sticks = [9].
    There is only one stick left, so you are done. The total cost is 5 + 9 = 14.

    Example 2:

    >>> connectSticks(sticks = [1,8,3,5])
    >>> 30
    Explanation: You start with sticks = [1,8,3,5].
    1. Combine sticks 1 and 3 for a cost of 1 + 3 = 4. Now you have sticks = [4,8,5].
    2. Combine sticks 4 and 5 for a cost of 4 + 5 = 9. Now you have sticks = [9,8].
    3. Combine sticks 9 and 8 for a cost of 9 + 8 = 17. Now you have sticks = [17].
    There is only one stick left, so you are done. The total cost is 4 + 9 + 17 = 30.

    Example 3:

    >>> connectSticks(sticks = [5])
    >>> 0
    Explanation: There is only one stick, so you don't need to do anything. The total cost is 0.
    """


Prompt:
def minCostToSupplyWater(n: int, wells: List[int], pipes: List[List[int]]) -> int:
    """
    There are n houses in a village. We want to supply water for all the houses by building wells and laying pipes.
    For each house i, we can either build a well inside it directly with cost wells[i - 1] (note the -1 due to 0-indexing), or pipe in water from another well to it. The costs to lay pipes between houses are given by the array pipes where each pipes[j] = [house1j, house2j, costj] represents the cost to connect house1j and house2j together using a pipe. Connections are bidirectional, and there could be multiple valid connections between the same two houses with different costs.
    Return the minimum total cost to supply water to all houses.

    Example 1:

    >>> minCostToSupplyWater(n = 3, wells = [1,2,2], pipes = [[1,2,1],[2,3,1]])
    >>> 3
    Explanation: The image shows the costs of connecting houses using pipes.
    The best strategy is to build a well in the first house with cost 1 and connect the other houses to it with cost 2 so the total cost is 3.

    Example 2:

    >>> minCostToSupplyWater(n = 2, wells = [1,1], pipes = [[1,2,1],[1,2,2]])
    >>> 2
    Explanation: We can supply water with cost two using one of the three options:
    Option 1:
      - Build a well inside house 1 with cost 1.
      - Build a well inside house 2 with cost 1.
    The total cost will be 2.
    Option 2:
      - Build a well inside house 1 with cost 1.
      - Connect house 2 with house 1 with cost 1.
    The total cost will be 2.
    Option 3:
      - Build a well inside house 2 with cost 1.
      - Connect house 1 with house 2 with cost 1.
    The total cost will be 2.
    Note that we can connect houses 1 and 2 with cost 1 or with cost 2 but we will always choose the cheapest option.
    """


Prompt:
def invalidTransactions(transactions: List[str]) -> List[str]:
    """
    A transaction is possibly invalid if:

    the amount exceeds $1000, or;
    if it occurs within (and including) 60 minutes of another transaction with the same name in a different city.

    You are given an array of strings transaction where transactions[i] consists of comma-separated values representing the name, time (in minutes), amount, and city of the transaction.
    Return a list of transactions that are possibly invalid. You may return the answer in any order.

    Example 1:

    >>> invalidTransactions(transactions = ["alice,20,800,mtv","alice,50,100,beijing"])
    >>> ["alice,20,800,mtv","alice,50,100,beijing"]
    Explanation: The first transaction is invalid because the second transaction occurs within a difference of 60 minutes, have the same name and is in a different city. Similarly the second one is invalid too.
    Example 2:

    >>> invalidTransactions(transactions = ["alice,20,800,mtv","alice,50,1200,mtv"])
    >>> ["alice,50,1200,mtv"]

    Example 3:

    >>> invalidTransactions(transactions = ["alice,20,800,mtv","bob,50,1200,mtv"])
    >>> ["bob,50,1200,mtv"]
    """


Prompt:
def numSmallerByFrequency(queries: List[str], words: List[str]) -> List[int]:
    """
    Let the function f(s) be the frequency of the lexicographically smallest character in a non-empty string s. For example, if s = "dcce" then f(s) = 2 because the lexicographically smallest character is 'c', which has a frequency of 2.
    You are given an array of strings words and another array of query strings queries. For each query queries[i], count the number of words in words such that f(queries[i]) < f(W) for each W in words.
    Return an integer array answer, where each answer[i] is the answer to the ith query.

    Example 1:

    >>> numSmallerByFrequency(queries = ["cbd"], words = ["zaaaz"])
    >>> [1]
    Explanation: On the first query we have f("cbd") = 1, f("zaaaz") = 3 so f("cbd") < f("zaaaz").

    Example 2:

    >>> numSmallerByFrequency(queries = ["bbb","cc"], words = ["a","aa","aaa","aaaa"])
    >>> [1,2]
    Explanation: On the first query only f("bbb") < f("aaaa"). On the second query both f("aaa") and f("aaaa") are both > f("cc").
    """


Prompt:
# class ListNode:
#     def __init__(val=0, next=None):
#         self.val = val
#         self.next = next
class Solution:
    def removeZeroSumSublists(head: Optional[ListNode]) -> Optional[ListNode]:
    """
    Given the head of a linked list, we repeatedly delete consecutive sequences of nodes that sum to 0 until there are no such sequences.\r
    \r
    After doing so, return the head of the final linked list.  You may return any such answer.\r

    (Note that in the examples below, all sequences are serializations of ListNode objects.)
    Example 1:

    >>> __init__(head = [1,2,-3,3,1])
    >>> [3,1]
    Note: The answer [1,2,1] would also be accepted.

    Example 2:

    >>> __init__(head = [1,2,3,-3,4])
    >>> [1,2,4]

    Example 3:

    >>> __init__(head = [1,2,3,-3,-2])
    >>> [1]
    """


Prompt:
def numPrimeArrangements(n: int) -> int:
    """
    Return the number of permutations of 1 to n so that prime numbers are at prime indices (1-indexed.)
    (Recall that an integer is prime if and only if it is greater than 1, and cannot be written as a product of two positive integers both smaller than it.)
    Since the answer may be large, return the answer modulo 10^9 + 7.

    Example 1:

    >>> numPrimeArrangements(n = 5)
    >>> 12
    Explanation: For example [1,2,5,4,3] is a valid permutation, but [5,2,3,4,1] is not because the prime number 5 is at index 1.

    Example 2:

    >>> numPrimeArrangements(n = 100)
    >>> 682289015
    """


Prompt:
def dietPlanPerformance(calories: List[int], k: int, lower: int, upper: int) -> int:
    """
    A dieter consumes calories[i] calories on the i-th day.
    Given an integer k, for every consecutive sequence of k days (calories[i], calories[i+1], ..., calories[i+k-1] for all 0 <= i <= n-k), they look at T, the total calories consumed during that sequence of k days (calories[i] + calories[i+1] + ... + calories[i+k-1]):

    If T < lower, they performed poorly on their diet and lose 1 point;
    If T > upper, they performed well on their diet and gain 1 point;
    Otherwise, they performed normally and there is no change in points.

    Initially, the dieter has zero points. Return the total number of points the dieter has after dieting for calories.length days.
    Note that the total points can be negative.

    Example 1:

    >>> dietPlanPerformance(calories = [1,2,3,4,5], k = 1, lower = 3, upper = 3)
    >>> 0
    Explanation: Since k = 1, we consider each element of the array separately and compare it to lower and upper.
    calories[0] and calories[1] are less than lower so 2 points are lost.
    calories[3] and calories[4] are greater than upper so 2 points are gained.

    Example 2:

    >>> dietPlanPerformance(calories = [3,2], k = 2, lower = 0, upper = 1)
    >>> 1
    Explanation: Since k = 2, we consider subarrays of length 2.
    calories[0] + calories[1] > upper so 1 point is gained.

    Example 3:

    >>> dietPlanPerformance(calories = [6,5,0,0], k = 2, lower = 1, upper = 5)
    >>> 0
    Explanation:
    calories[0] + calories[1] > upper so 1 point is gained.
    lower <= calories[1] + calories[2] <= upper so no change in points.
    calories[2] + calories[3] < lower so 1 point is lost.
    """


Prompt:
def canMakePaliQueries(s: str, queries: List[List[int]]) -> List[bool]:
    """
    You are given a string s and array queries where queries[i] = [lefti, righti, ki]. We may rearrange the substring s[lefti...righti] for each query and then choose up to ki of them to replace with any lowercase English letter.
    If the substring is possible to be a palindrome string after the operations above, the result of the query is true. Otherwise, the result is false.
    Return a boolean array answer where answer[i] is the result of the ith query queries[i].
    Note that each letter is counted individually for replacement, so if, for example s[lefti...righti] = "aaa", and ki = 2, we can only replace two of the letters. Also, note that no query modifies the initial string s.

    Example :

    >>> canMakePaliQueries(s = "abcda", queries = [[3,3,0],[1,2,0],[0,3,1],[0,3,2],[0,4,1]])
    >>> [true,false,false,true,true]
    Explanation:
    queries[0]: substring = "d", is palidrome.
    queries[1]: substring = "bc", is not palidrome.
    queries[2]: substring = "abcd", is not palidrome after replacing only 1 character.
    queries[3]: substring = "abcd", could be changed to "abba" which is palidrome. Also this can be changed to "baab" first rearrange it "bacd" then replace "cd" with "ab".
    queries[4]: substring = "abcda", could be changed to "abcba" which is palidrome.

    Example 2:

    >>> canMakePaliQueries(s = "lyb", queries = [[0,1,0],[2,2,1]])
    >>> [false,true]
    """


Prompt:
def findNumOfValidWords(words: List[str], puzzles: List[str]) -> List[int]:
    """
    With respect to a given puzzle string, a word is valid if both the following conditions are satisfied:

    word contains the first letter of puzzle.
    For each letter in word, that letter is in puzzle.

    For example, if the puzzle is "abcdefg", then valid words are "faced", "cabbage", and "baggage", while
    invalid words are "beefed" (does not include 'a') and "based" (includes 's' which is not in the puzzle).

    Return an array answer, where answer[i] is the number of words in the given word list words that is valid with respect to the puzzle puzzles[i].

    Example 1:

    >>> findNumOfValidWords(words = ["aaaa","asas","able","ability","actt","actor","access"], puzzles = ["aboveyz","abrodyz","abslute","absoryz","actresz","gaswxyz"])
    >>> [1,1,3,2,4,0]
    Explanation:
    1 valid word for "aboveyz" : "aaaa"
    1 valid word for "abrodyz" : "aaaa"
    3 valid words for "abslute" : "aaaa", "asas", "able"
    2 valid words for "absoryz" : "aaaa", "asas"
    4 valid words for "actresz" : "aaaa", "asas", "actt", "access"
    There are no valid words for "gaswxyz" cause none of the words in the list contains letter 'g'.

    Example 2:

    >>> findNumOfValidWords(words = ["apple","pleas","please"], puzzles = ["aelwxyz","aelpxyz","aelpsxy","saelpxy","xaelpsy"])
    >>> [0,1,3,2,0]
    """


Prompt:
def countLetters(s: str) -> int:
    """
    Given a string s, return the number of substrings that have only one distinct letter.

    Example 1:

    >>> countLetters(s = "aaaba")
    >>> 8
    Explanation: The substrings with one distinct letter are "aaa", "aa", "a", "b".
    "aaa" occurs 1 time.
    "aa" occurs 2 times.
    "a" occurs 4 times.
    "b" occurs 1 time.
    So the answer is 1 + 2 + 4 + 1 = 8.

    Example 2:

    >>> countLetters(s = "aaaaaaaaaa")
    >>> 55
    """


Prompt:
def beforeAndAfterPuzzles(phrases: List[str]) -> List[str]:
    """
    Given a list of phrases, generate a list of Before and After puzzles.
    A phrase is a string that consists of lowercase English letters and spaces only. No space appears in the start or the end of a phrase. There are no consecutive spaces in a phrase.
    Before and After puzzles are phrases that are formed by merging two phrases where the last word of the first phrase is the same as the first word of the second phrase.
    Return the Before and After puzzles that can be formed by every two phrases phrases[i] and phrases[j] where i != j. Note that the order of matching two phrases matters, we want to consider both orders.
    You should return a list of distinct strings sorted lexicographically.

    Example 1:

    >>> beforeAndAfterPuzzles(phrases = ["writing code","code rocks"])
    >>> ["writing code rocks"]

    Example 2:

                      "a quick bite to eat",
                      "a chip off the old block",
                      "chocolate bar",
                      "mission impossible",
                      "a man on a mission",
                      "block party",
                      "eat my words",
                      "bar of soap"]
    >>> beforeAndAfterPuzzles(phrases = ["mission statement",)
    >>> ["a chip off the old block party",
             "a man on a mission impossible",
             "a man on a mission statement",
             "a quick bite to eat my words",
             "chocolate bar of soap"]

    Example 3:

    >>> beforeAndAfterPuzzles(phrases = ["a","b","a"])
    >>> ["a"]
    """


Prompt:
def shortestDistanceColor(colors: List[int], queries: List[List[int]]) -> List[int]:
    """
    You are given an array colors, in which there are three colors: 1, 2 and 3.
    You are also given some queries. Each query consists of two integers i and c, return the shortest distance between the given index i and the target color c. If there is no solution return -1.

    Example 1:

    >>> shortestDistanceColor(colors = [1,1,2,1,3,2,2,3,3], queries = [[1,3],[2,2],[6,1]])
    >>> [3,0,3]
    Explanation:
    The nearest 3 from index 1 is at index 4 (3 steps away).
    The nearest 2 from index 2 is at index 2 itself (0 steps away).
    The nearest 1 from index 6 is at index 3 (3 steps away).

    Example 2:

    >>> shortestDistanceColor(colors = [1,2], queries = [[0,3]])
    >>> [-1]
    Explanation: There is no 3 in the array.
    """


Prompt:
def maximumNumberOfOnes(width: int, height: int, sideLength: int, maxOnes: int) -> int:
    """
    Consider a matrix M with dimensions width * height, such that every cell has value 0 or 1, and any square sub-matrix of M of size sideLength * sideLength has at most maxOnes ones.
    Return the maximum possible number of ones that the matrix M can have.

    Example 1:

    >>> maximumNumberOfOnes(width = 3, height = 3, sideLength = 2, maxOnes = 1)
    >>> 4
    Explanation:
    In a 3*3 matrix, no 2*2 sub-matrix can have more than 1 one.
    The best solution that has 4 ones is:
    [1,0,1]
    [0,0,0]
    [1,0,1]

    Example 2:

    >>> maximumNumberOfOnes(width = 3, height = 3, sideLength = 2, maxOnes = 2)
    >>> 6
    Explanation:
    [1,0,1]
    [1,0,1]
    [1,0,1]
    """


Prompt:
def distanceBetweenBusStops(distance: List[int], start: int, destination: int) -> int:
    """
    A bus has n stops numbered from 0 to n - 1 that form a circle. We know the distance between all pairs of neighboring stops where distance[i] is the distance between the stops number i and (i + 1) % n.\r
    \r
    The bus goes along both directions i.e. clockwise and counterclockwise.\r
    \r
    Return the shortest distance between the given start and destination stops.\r
    \r
     \r
    Example 1:\r
    \r
    \r
    \r
    \r
    >>> distanceBetweenBusStops(distance = [1,2,3,4], start = 0, destination = 1\r)
    >>> 1\r
    Explanation: Distance between 0 and 1 is 1 or 9, minimum is 1.\r
    \r
     \r
    \r
    Example 2:\r
    \r
    \r
    \r
    \r
    >>> distanceBetweenBusStops(distance = [1,2,3,4], start = 0, destination = 2\r)
    >>> 3\r
    Explanation: Distance between 0 and 2 is 3 or 7, minimum is 3.\r
    \r
    \r
     \r
    \r
    Example 3:\r
    \r
    \r
    \r
    \r
    >>> distanceBetweenBusStops(distance = [1,2,3,4], start = 0, destination = 3\r)
    >>> 4\r
    Explanation: Distance between 0 and 3 is 6 or 4, minimum is 4.\r
    \r
    \r
     \r
    """


Prompt:
def dayOfTheWeek(day: int, month: int, year: int) -> str:
    """
    Given a date, return the corresponding day of the week for that date.
    The input is given as three integers representing the day, month and year respectively.
    Return the answer as one of the following values {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}.

    Example 1:

    >>> dayOfTheWeek(day = 31, month = 8, year = 2019)
    >>> "Saturday"

    Example 2:

    >>> dayOfTheWeek(day = 18, month = 7, year = 1999)
    >>> "Sunday"

    Example 3:

    >>> dayOfTheWeek(day = 15, month = 8, year = 1993)
    >>> "Sunday"
    """


Prompt:
def maximumSum(arr: List[int]) -> int:
    """
    Given an array of integers, return the maximum sum for a non-empty subarray (contiguous elements) with at most one element deletion. In other words, you want to choose a subarray and optionally delete one element from it so that there is still at least one element left and the sum of the remaining elements is maximum possible.
    Note that the subarray needs to be non-empty after deleting one element.

    Example 1:

    >>> maximumSum(arr = [1,-2,0,3])
    >>> 4
    Explanation: Because we can choose [1, -2, 0, 3] and drop -2, thus the subarray [1, 0, 3] becomes the maximum value.
    Example 2:

    >>> maximumSum(arr = [1,-2,-2,3])
    >>> 3
    Explanation: We just choose [3] and it's the maximum sum.

    Example 3:

    >>> maximumSum(arr = [-1,-1,-1,-1])
    >>> -1
    Explanation: The final subarray needs to be non-empty. You can't choose [-1] and delete -1 from it, then get an empty subarray to make the sum equals to 0.
    """


Prompt:
def makeArrayIncreasing(arr1: List[int], arr2: List[int]) -> int:
    """
    Given two integer arrays arr1 and arr2, return the minimum number of operations (possibly zero) needed to make arr1 strictly increasing.
    In one operation, you can choose two indices 0 <= i < arr1.length and 0 <= j < arr2.length and do the assignment arr1[i] = arr2[j].
    If there is no way to make arr1 strictly increasing, return -1.

    Example 1:

    >>> makeArrayIncreasing(arr1 = [1,5,3,6,7], arr2 = [1,3,2,4])
    >>> 1
    Explanation: Replace 5 with 2, then arr1 = [1, 2, 3, 6, 7].

    Example 2:

    >>> makeArrayIncreasing(arr1 = [1,5,3,6,7], arr2 = [4,3,1])
    >>> 2
    Explanation: Replace 5 with 3 and then replace 3 with 4. arr1 = [1, 3, 4, 6, 7].

    Example 3:

    >>> makeArrayIncreasing(arr1 = [1,5,3,6,7], arr2 = [1,6,3,3])
    >>> -1
    Explanation: You can't make arr1 strictly increasing.
    """


Prompt:
def maxNumberOfBalloons(text: str) -> int:
    """
    Given a string text, you want to use the characters of text to form as many instances of the word "balloon" as possible.
    You can use each character in text at most once. Return the maximum number of instances that can be formed.

    Example 1:

    >>> maxNumberOfBalloons(text = "nlaebolko")
    >>> 1

    Example 2:

    >>> maxNumberOfBalloons(text = "loonbalxballpoon")
    >>> 2

    Example 3:

    >>> maxNumberOfBalloons(text = "leetcode")
    >>> 0
    """


Prompt:
def reverseParentheses(s: str) -> str:
    """
    You are given a string s that consists of lower case English letters and brackets.
    Reverse the strings in each pair of matching parentheses, starting from the innermost one.
    Your result should not contain any brackets.

    Example 1:

    >>> reverseParentheses(s = "(abcd)")
    >>> "dcba"

    Example 2:

    >>> reverseParentheses(s = "(u(love)i)")
    >>> "iloveu"
    Explanation: The substring "love" is reversed first, then the whole string is reversed.

    Example 3:

    >>> reverseParentheses(s = "(ed(et(oc))el)")
    >>> "leetcode"
    Explanation: First, we reverse the substring "oc", then "etco", and finally, the whole string.
    """


Prompt:
def kConcatenationMaxSum(arr: List[int], k: int) -> int:
    """
    Given an integer array arr and an integer k, modify the array by repeating it k times.
    For example, if arr = [1, 2] and k = 3 then the modified array will be [1, 2, 1, 2, 1, 2].
    Return the maximum sub-array sum in the modified array. Note that the length of the sub-array can be 0 and its sum in that case is 0.
    As the answer can be very large, return the answer modulo 109 + 7.

    Example 1:

    >>> kConcatenationMaxSum(arr = [1,2], k = 3)
    >>> 9

    Example 2:

    >>> kConcatenationMaxSum(arr = [1,-2,1], k = 5)
    >>> 2

    Example 3:

    >>> kConcatenationMaxSum(arr = [-1,-2], k = 7)
    >>> 0
    """


Prompt:
def criticalConnections(n: int, connections: List[List[int]]) -> List[List[int]]:
    """
    There are n servers numbered from 0 to n - 1 connected by undirected server-to-server connections forming a network where connections[i] = [ai, bi] represents a connection between servers ai and bi. Any server can reach other servers directly or indirectly through the network.
    A critical connection is a connection that, if removed, will make some servers unable to reach some other server.
    Return all critical connections in the network in any order.

    Example 1:

    >>> criticalConnections(n = 4, connections = [[0,1],[1,2],[2,0],[1,3]])
    >>> [[1,3]]
    Explanation: [[3,1]] is also accepted.

    Example 2:

    >>> criticalConnections(n = 2, connections = [[0,1]])
    >>> [[0,1]]
    """


Prompt:
def maxNumberOfApples(weight: List[int]) -> int:
    """
    You have some apples and a basket that can carry up to 5000 units of weight.
    Given an integer array weight where weight[i] is the weight of the ith apple, return the maximum number of apples you can put in the basket.

    Example 1:

    >>> maxNumberOfApples(weight = [100,200,150,1000])
    >>> 4
    Explanation: All 4 apples can be carried by the basket since their sum of weights is 1450.

    Example 2:

    >>> maxNumberOfApples(weight = [900,950,800,1000,700,800])
    >>> 5
    Explanation: The sum of weights of the 6 apples exceeds 5000 so we choose any 5 of them.
    """


Prompt:
def minKnightMoves(x: int, y: int) -> int:
    """
    In an infinite chess board with coordinates from -infinity to +infinity, you have a knight at square [0, 0].
    A knight has 8 possible moves it can make, as illustrated below. Each move is two squares in a cardinal direction, then one square in an orthogonal direction.

    Return the minimum number of steps needed to move the knight to the square [x, y]. It is guaranteed the answer exists.

    Example 1:

    >>> minKnightMoves(x = 2, y = 1)
    >>> 1
    Explanation: [0, 0] → [2, 1]

    Example 2:

    >>> minKnightMoves(x = 5, y = 5)
    >>> 4
    Explanation: [0, 0] → [2, 1] → [4, 2] → [3, 4] → [5, 5]
    """


Prompt:
def smallestCommonElement(mat: List[List[int]]) -> int:
    """
    Given an m x n matrix mat where every row is sorted in strictly increasing order, return the smallest common element in all rows.
    If there is no common element, return -1.

    Example 1:

    >>> smallestCommonElement(mat = [[1,2,3,4,5],[2,4,5,8,10],[3,5,7,9,11],[1,3,5,7,9]])
    >>> 5

    Example 2:

    >>> smallestCommonElement(mat = [[1,2,3],[2,3,4],[2,3,5]])
    >>> 2
    """


Prompt:
def minBuildTime(blocks: List[int], split: int) -> int:
    """
    You are given a list of blocks, where blocks[i] = t means that the i-th block needs t units of time to be built. A block can only be built by exactly one worker.
    A worker can either split into two workers (number of workers increases by one) or build a block then go home. Both decisions cost some time.
    The time cost of spliting one worker into two workers is given as an integer split. Note that if two workers split at the same time, they split in parallel so the cost would be split.
    Output the minimum time needed to build all blocks.
    Initially, there is only one worker.

    Example 1:

    >>> minBuildTime(blocks = [1], split = 1)
    >>> 1
    Explanation: We use 1 worker to build 1 block in 1 time unit.

    Example 2:

    >>> minBuildTime(blocks = [1,2], split = 5)
    >>> 7
    Explanation: We split the worker into 2 workers in 5 time units then assign each of them to a block so the cost is 5 + max(1, 2) = 7.

    Example 3:

    >>> minBuildTime(blocks = [1,2,3], split = 1)
    >>> 4
    Explanation: Split 1 worker into 2, then assign the first worker to the last block and split the second worker into 2.
    Then, use the two unassigned workers to build the first two blocks.
    The cost is 1 + max(3, 1 + max(1, 2)) = 4.
    """


Prompt:
def minimumAbsDifference(arr: List[int]) -> List[List[int]]:
    """
    Given an array of distinct integers arr, find all pairs of elements with the minimum absolute difference of any two elements.
    Return a list of pairs in ascending order(with respect to pairs), each pair [a, b] follows

    a, b are from arr
    a < b
    b - a equals to the minimum absolute difference of any two elements in arr

    Example 1:

    >>> minimumAbsDifference(arr = [4,2,1,3])
    >>> [[1,2],[2,3],[3,4]]
    Explanation: The minimum absolute difference is 1. List all pairs with difference equal to 1 in ascending order.
    Example 2:

    >>> minimumAbsDifference(arr = [1,3,6,10,15])
    >>> [[1,3]]

    Example 3:

    >>> minimumAbsDifference(arr = [3,8,-10,23,19,-4,-14,27])
    >>> [[-14,-10],[19,23],[23,27]]
    """


Prompt:
def nthUglyNumber(n: int, a: int, b: int, c: int) -> int:
    """
    An ugly number is a positive integer that is divisible by a, b, or c.
    Given four integers n, a, b, and c, return the nth ugly number.

    Example 1:

    >>> nthUglyNumber(n = 3, a = 2, b = 3, c = 5)
    >>> 4
    Explanation: The ugly numbers are 2, 3, 4, 5, 6, 8, 9, 10... The 3rd is 4.

    Example 2:

    >>> nthUglyNumber(n = 4, a = 2, b = 3, c = 4)
    >>> 6
    Explanation: The ugly numbers are 2, 3, 4, 6, 8, 9, 10, 12... The 4th is 6.

    Example 3:

    >>> nthUglyNumber(n = 5, a = 2, b = 11, c = 13)
    >>> 10
    Explanation: The ugly numbers are 2, 4, 6, 8, 10, 11, 12, 13... The 5th is 10.
    """


Prompt:
def smallestStringWithSwaps(s: str, pairs: List[List[int]]) -> str:
    """
    You are given a string s, and an array of pairs of indices in the string pairs where pairs[i] = [a, b] indicates 2 indices(0-indexed) of the string.
    You can swap the characters at any pair of indices in the given pairs any number of times.
    Return the lexicographically smallest string that s can be changed to after using the swaps.

    Example 1:

    >>> smallestStringWithSwaps(s = "dcab", pairs = [[0,3],[1,2]])
    >>> "bacd"
    Explaination:
    Swap s[0] and s[3], s = "bcad"
    Swap s[1] and s[2], s = "bacd"

    Example 2:

    >>> smallestStringWithSwaps(s = "dcab", pairs = [[0,3],[1,2],[0,2]])
    >>> "abcd"
    Explaination:
    Swap s[0] and s[3], s = "bcad"
    Swap s[0] and s[2], s = "acbd"
    Swap s[1] and s[2], s = "abcd"
    Example 3:

    >>> smallestStringWithSwaps(s = "cba", pairs = [[0,1],[1,2]])
    >>> "abc"
    Explaination:
    Swap s[0] and s[1], s = "bca"
    Swap s[1] and s[2], s = "bac"
    Swap s[0] and s[1], s = "abc"
    """


Prompt:
def sortItems(n: int, m: int, group: List[int], beforeItems: List[List[int]]) -> List[int]:
    """
    There are n items each belonging to zero or one of m groups where group[i] is the group that the i-th item belongs to and it's equal to -1 if the i-th item belongs to no group. The items and the groups are zero indexed. A group can have no item belonging to it.
    Return a sorted list of the items such that:

    The items that belong to the same group are next to each other in the sorted list.
    There are some relations between these items where beforeItems[i] is a list containing all the items that should come before the i-th item in the sorted array (to the left of the i-th item).

    Return any solution if there is more than one solution and return an empty list if there is no solution.

    Example 1:

    >>> sortItems(n = 8, m = 2, group = [-1,-1,1,0,0,1,0,-1], beforeItems = [[],[6],[5],[6],[3,6],[],[],[]])
    >>> [6,3,4,1,5,2,0,7]

    Example 2:

    >>> sortItems(n = 8, m = 2, group = [-1,-1,1,0,0,1,0,-1], beforeItems = [[],[6],[5],[6],[3],[],[4],[]])
    >>> []
    Explanation: This is the same as example 1 except that 4 needs to be before 6 in the sorted list.
    """


Prompt:
def uniqueOccurrences(arr: List[int]) -> bool:
    """
    Given an array of integers arr, return true if the number of occurrences of each value in the array is unique or false otherwise.

    Example 1:

    >>> uniqueOccurrences(arr = [1,2,2,1,1,3])
    >>> true
    Explanation: The value 1 has 3 occurrences, 2 has 2 and 3 has 1. No two values have the same number of occurrences.
    Example 2:

    >>> uniqueOccurrences(arr = [1,2])
    >>> false

    Example 3:

    >>> uniqueOccurrences(arr = [-3,0,1,-3,1,1,1,-3,10,0])
    >>> true
    """


Prompt:
def equalSubstring(s: str, t: str, maxCost: int) -> int:
    """
    You are given two strings s and t of the same length and an integer maxCost.
    You want to change s to t. Changing the ith character of s to ith character of t costs |s[i] - t[i]| (i.e., the absolute difference between the ASCII values of the characters).
    Return the maximum length of a substring of s that can be changed to be the same as the corresponding substring of t with a cost less than or equal to maxCost. If there is no substring from s that can be changed to its corresponding substring from t, return 0.

    Example 1:

    >>> equalSubstring(s = "abcd", t = "bcdf", maxCost = 3)
    >>> 3
    Explanation: "abc" of s can change to "bcd".
    That costs 3, so the maximum length is 3.

    Example 2:

    >>> equalSubstring(s = "abcd", t = "cdef", maxCost = 3)
    >>> 1
    Explanation: Each character in s costs 2 to change to character in t,  so the maximum length is 1.

    Example 3:

    >>> equalSubstring(s = "abcd", t = "acde", maxCost = 0)
    >>> 1
    Explanation: You cannot make any change, so the maximum length is 1.
    """


Prompt:
def removeDuplicates(s: str, k: int) -> str:
    """
    You are given a string s and an integer k, a k duplicate removal consists of choosing k adjacent and equal letters from s and removing them, causing the left and the right side of the deleted substring to concatenate together.
    We repeatedly make k duplicate removals on s until we no longer can.
    Return the final string after all such duplicate removals have been made. It is guaranteed that the answer is unique.

    Example 1:

    >>> removeDuplicates(s = "abcd", k = 2)
    >>> "abcd"
    Explanation: There's nothing to delete.
    Example 2:

    >>> removeDuplicates(s = "deeedbbcccbdaa", k = 3)
    >>> "aa"
    Explanation:
    First delete "eee" and "ccc", get "ddbbbdaa"
    Then delete "bbb", get "dddaa"
    Finally delete "ddd", get "aa"
    Example 3:

    >>> removeDuplicates(s = "pbbcggttciiippooaais", k = 2)
    >>> "ps"
    """


Prompt:
def minimumMoves(grid: List[List[int]]) -> int:
    """
    In an n*n grid, there is a snake that spans 2 cells and starts moving from the top left corner at (0, 0) and (0, 1). The grid has empty cells represented by zeros and blocked cells represented by ones. The snake wants to reach the lower right corner at (n-1, n-2) and (n-1, n-1).
    In one move the snake can:

    Move one cell to the right if there are no blocked cells there. This move keeps the horizontal/vertical position of the snake as it is.
    Move down one cell if there are no blocked cells there. This move keeps the horizontal/vertical position of the snake as it is.
    Rotate clockwise if it's in a horizontal position and the two cells under it are both empty. In that case the snake moves from (r, c) and (r, c+1) to (r, c) and (r+1, c).

    Rotate counterclockwise if it's in a vertical position and the two cells to its right are both empty. In that case the snake moves from (r, c) and (r+1, c) to (r, c) and (r, c+1).

    Return the minimum number of moves to reach the target.
    If there is no way to reach the target, return -1.

    Example 1:

                   [1,1,0,0,1,0],
                   [0,0,0,0,1,1],
                   [0,0,1,0,1,0],
                   [0,1,1,0,0,0],
                   [0,1,1,0,0,0]]
    >>> minimumMoves(grid = [[0,0,0,0,0,1],)
    >>> 11
    Explanation:
    One possible solution is [right, right, rotate clockwise, right, down, down, down, down, rotate counterclockwise, right, down].

    Example 2:

                   [0,0,0,0,1,1],
                   [1,1,0,0,0,1],
                   [1,1,1,0,0,1],
                   [1,1,1,0,0,1],
                   [1,1,1,0,0,0]]
    >>> minimumMoves(grid = [[0,0,1,1,1,1],)
    >>> 9
    """


Prompt:
def arraysIntersection(arr1: List[int], arr2: List[int], arr3: List[int]) -> List[int]:
    """
    Given three integer arrays arr1, arr2 and arr3 sorted in strictly increasing order, return a sorted array of only the integers that appeared in all three arrays.

    Example 1:

    >>> arraysIntersection(arr1 = [1,2,3,4,5], arr2 = [1,2,5,7,9], arr3 = [1,3,4,5,8])
    >>> [1,5]
    Explanation: Only 1 and 5 appeared in the three arrays.

    Example 2:

    >>> arraysIntersection(arr1 = [197,418,523,876,1356], arr2 = [501,880,1593,1710,1870], arr3 = [521,682,1337,1395,1764])
    >>> []
    """


Prompt:
# class TreeNode:
#     def __init__(val=0, left=None, right=None):
#         self.val = val
#         self.left = left
#         self.right = right
class Solution:
    def twoSumBSTs(root1: Optional[TreeNode], root2: Optional[TreeNode], target: int) -> bool:
    """
    Given the roots of two binary search trees, root1 and root2, return true if and only if there is a node in the first tree and a node in the second tree whose values sum up to a given integer target.

    Example 1:

    >>> __init__(root1 = [2,1,4], root2 = [1,0,3], target = 5)
    >>> true
    Explanation: 2 and 3 sum up to 5.

    Example 2:

    >>> __init__(root1 = [0,-10,10], root2 = [5,1,7,0,2], target = 18)
    >>> false
    """


Prompt:
def countSteppingNumbers(low: int, high: int) -> List[int]:
    """
    A stepping number is an integer such that all of its adjacent digits have an absolute difference of exactly 1.

    For example, 321 is a stepping number while 421 is not.

    Given two integers low and high, return a sorted list of all the stepping numbers in the inclusive range [low, high].

    Example 1:

    >>> countSteppingNumbers(low = 0, high = 21)
    >>> [0,1,2,3,4,5,6,7,8,9,10,12,21]

    Example 2:

    >>> countSteppingNumbers(low = 10, high = 15)
    >>> [10,12]
    """


Prompt:
def isValidPalindrome(s: str, k: int) -> bool:
    """
    Given a string s and an integer k, return true if s is a k-palindrome.
    A string is k-palindrome if it can be transformed into a palindrome by removing at most k characters from it.

    Example 1:

    >>> isValidPalindrome(s = "abcdeca", k = 2)
    >>> true
    Explanation: Remove 'b' and 'e' characters.

    Example 2:

    >>> isValidPalindrome(s = "abbababa", k = 1)
    >>> true
    """


Prompt:
def minCostToMoveChips(position: List[int]) -> int:
    """
    We have n chips, where the position of the ith chip is position[i].
    We need to move all the chips to the same position. In one step, we can change the position of the ith chip from position[i] to:

    position[i] + 2 or position[i] - 2 with cost = 0.
    position[i] + 1 or position[i] - 1 with cost = 1.

    Return the minimum cost needed to move all the chips to the same position.

    Example 1:

    >>> minCostToMoveChips(position = [1,2,3])
    >>> 1
    Explanation: First step: Move the chip at position 3 to position 1 with cost = 0.
    Second step: Move the chip at position 2 to position 1 with cost = 1.
    Total cost is 1.

    Example 2:

    >>> minCostToMoveChips(position = [2,2,2,3,3])
    >>> 2
    Explanation: We can move the two chips at position  3 to position 2. Each move has cost = 1. The total cost = 2.

    Example 3:

    >>> minCostToMoveChips(position = [1,1000000000])
    >>> 1
    """


Prompt:
def longestSubsequence(arr: List[int], difference: int) -> int:
    """
    Given an integer array arr and an integer difference, return the length of the longest subsequence in arr which is an arithmetic sequence such that the difference between adjacent elements in the subsequence equals difference.
    A subsequence is a sequence that can be derived from arr by deleting some or no elements without changing the order of the remaining elements.

    Example 1:

    >>> longestSubsequence(arr = [1,2,3,4], difference = 1)
    >>> 4
    Explanation: The longest arithmetic subsequence is [1,2,3,4].
    Example 2:

    >>> longestSubsequence(arr = [1,3,5,7], difference = 1)
    >>> 1
    Explanation: The longest arithmetic subsequence is any single element.

    Example 3:

    >>> longestSubsequence(arr = [1,5,7,8,5,3,4,2,1], difference = -2)
    >>> 4
    Explanation: The longest arithmetic subsequence is [7,5,3,1].
    """


Prompt:
def getMaximumGold(grid: List[List[int]]) -> int:
    """
    In a gold mine grid of size m x n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty.
    Return the maximum amount of gold you can collect under the conditions:

    Every time you are located in a cell you will collect all the gold in that cell.
    From your position, you can walk one step to the left, right, up, or down.
    You can't visit the same cell more than once.
    Never visit a cell with 0 gold.
    You can start and stop collecting gold from any position in the grid that has some gold.

    Example 1:

    >>> getMaximumGold(grid = [[0,6,0],[5,8,7],[0,9,0]])
    >>> 24
    Explanation:
    [[0,6,0],
     [5,8,7],
     [0,9,0]]
    Path to get the maximum gold, 9 -> 8 -> 7.

    Example 2:

    >>> getMaximumGold(grid = [[1,0,7],[2,0,6],[3,4,5],[0,3,0],[9,0,20]])
    >>> 28
    Explanation:
    [[1,0,7],
     [2,0,6],
     [3,4,5],
     [0,3,0],
     [9,0,20]]
    Path to get the maximum gold, 1 -> 2 -> 3 -> 4 -> 5 -> 6 -> 7.
    """


Prompt:
def countVowelPermutation(n: int) -> int:
    """
    Given an integer n, your task is to count how many strings of length n can be formed under the following rules:

    Each character is a lower case vowel ('a', 'e', 'i', 'o', 'u')
    Each vowel 'a' may only be followed by an 'e'.
    Each vowel 'e' may only be followed by an 'a' or an 'i'.
    Each vowel 'i' may not be followed by another 'i'.
    Each vowel 'o' may only be followed by an 'i' or a 'u'.
    Each vowel 'u' may only be followed by an 'a'.

    Since the answer may be too large, return it modulo 10^9 + 7.

    Example 1:

    >>> countVowelPermutation(n = 1)
    >>> 5
    Explanation: All possible strings are: "a", "e", "i" , "o" and "u".

    Example 2:

    >>> countVowelPermutation(n = 2)
    >>> 10
    Explanation: All possible strings are: "ae", "ea", "ei", "ia", "ie", "io", "iu", "oi", "ou" and "ua".

    Example 3:

    >>> countVowelPermutation(n = 5)
    >>> 68
    """


Prompt:
def balancedStringSplit(s: str) -> int:
    """
    Balanced strings are those that have an equal quantity of 'L' and 'R' characters.
    Given a balanced string s, split it into some number of substrings such that:

    Each substring is balanced.

    Return the maximum number of balanced strings you can obtain.

    Example 1:

    >>> balancedStringSplit(s = "RLRRLLRLRL")
    >>> 4
    Explanation: s can be split into "RL", "RRLL", "RL", "RL", each substring contains same number of 'L' and 'R'.

    Example 2:

    >>> balancedStringSplit(s = "RLRRRLLRLL")
    >>> 2
    Explanation: s can be split into "RL", "RRRLLRLL", each substring contains same number of 'L' and 'R'.
    Note that s cannot be split into "RL", "RR", "RL", "LR", "LL", because the 2nd and 5th substrings are not balanced.
    Example 3:

    >>> balancedStringSplit(s = "LLLLRRRR")
    >>> 1
    Explanation: s can be split into "LLLLRRRR".
    """


Prompt:
def queensAttacktheKing(queens: List[List[int]], king: List[int]) -> List[List[int]]:
    """
    On a 0-indexed 8 x 8 chessboard, there can be multiple black queens and one white king.
    You are given a 2D integer array queens where queens[i] = [xQueeni, yQueeni] represents the position of the ith black queen on the chessboard. You are also given an integer array king of length 2 where king = [xKing, yKing] represents the position of the white king.
    Return the coordinates of the black queens that can directly attack the king. You may return the answer in any order.

    Example 1:

    >>> queensAttacktheKing(queens = [[0,1],[1,0],[4,0],[0,4],[3,3],[2,4]], king = [0,0])
    >>> [[0,1],[1,0],[3,3]]
    Explanation: The diagram above shows the three queens that can directly attack the king and the three queens that cannot attack the king (i.e., marked with red dashes).

    Example 2:

    >>> queensAttacktheKing(queens = [[0,0],[1,1],[2,2],[3,4],[3,5],[4,4],[4,5]], king = [3,3])
    >>> [[2,2],[3,4],[4,4]]
    Explanation: The diagram above shows the three queens that can directly attack the king and the three queens that cannot attack the king (i.e., marked with red dashes).
    """


Prompt:
def dieSimulator(n: int, rollMax: List[int]) -> int:
    """
    A die simulator generates a random number from 1 to 6 for each roll. You introduced a constraint to the generator such that it cannot roll the number i more than rollMax[i] (1-indexed) consecutive times.
    Given an array of integers rollMax and an integer n, return the number of distinct sequences that can be obtained with exact n rolls. Since the answer may be too large, return it modulo 109 + 7.
    Two sequences are considered different if at least one element differs from each other.

    Example 1:

    >>> dieSimulator(n = 2, rollMax = [1,1,2,2,2,3])
    >>> 34
    Explanation: There will be 2 rolls of die, if there are no constraints on the die, there are 6 * 6 = 36 possible combinations. In this case, looking at rollMax array, the numbers 1 and 2 appear at most once consecutively, therefore sequences (1,1) and (2,2) cannot occur, so the final answer is 36-2 = 34.

    Example 2:

    >>> dieSimulator(n = 2, rollMax = [1,1,1,1,1,1])
    >>> 30

    Example 3:

    >>> dieSimulator(n = 3, rollMax = [1,1,1,2,2,3])
    >>> 181
    """


Prompt:
def maxEqualFreq(nums: List[int]) -> int:
    """
    Given an array nums of positive integers, return the longest possible length of an array prefix of nums, such that it is possible to remove exactly one element from this prefix so that every number that has appeared in it will have the same number of occurrences.
    If after removing one element there are no remaining elements, it's still considered that every appeared number has the same number of ocurrences (0).

    Example 1:

    >>> maxEqualFreq(nums = [2,2,1,1,5,3,3,5])
    >>> 7
    Explanation: For the subarray [2,2,1,1,5,3,3] of length 7, if we remove nums[4] = 5, we will get [2,2,1,1,3,3], so that each number will appear exactly twice.

    Example 2:

    >>> maxEqualFreq(nums = [1,1,1,2,2,2,3,3,3,4,4,4,5])
    >>> 13
    """


Prompt:
def nthPersonGetsNthSeat(n: int) -> float:
    """
    n passengers board an airplane with exactly n seats. The first passenger has lost the ticket and picks a seat randomly. But after that, the rest of the passengers will:

    Take their own seat if it is still available, and
    Pick other seats randomly when they find their seat occupied

    Return the probability that the nth person gets his own seat.

    Example 1:

    >>> nthPersonGetsNthSeat(n = 1)
    >>> 1.00000
    Explanation: The first person can only get the first seat.
    Example 2:

    >>> nthPersonGetsNthSeat(n = 2)
    >>> 0.50000
    Explanation: The second person has a probability of 0.5 to get the second seat (when first person gets the first seat).
    """


Prompt:
def missingNumber(arr: List[int]) -> int:
    """
    In some array arr, the values were in arithmetic progression: the values arr[i + 1] - arr[i] are all equal for every 0 <= i < arr.length - 1.
    A value from arr was removed that was not the first or last value in the array.
    Given arr, return the removed value.

    Example 1:

    >>> missingNumber(arr = [5,7,11,13])
    >>> 9
    Explanation: The previous array was [5,7,9,11,13].

    Example 2:

    >>> missingNumber(arr = [15,13,12])
    >>> 14
    Explanation: The previous array was [15,14,13,12].
    """


Prompt:
def minAvailableDuration(slots1: List[List[int]], slots2: List[List[int]], duration: int) -> List[int]:
    """
    Given the availability time slots arrays slots1 and slots2 of two people and a meeting duration duration, return the earliest time slot that works for both of them and is of duration duration.
    If there is no common time slot that satisfies the requirements, return an empty array.
    The format of a time slot is an array of two elements [start, end] representing an inclusive time range from start to end.
    It is guaranteed that no two availability slots of the same person intersect with each other. That is, for any two time slots [start1, end1] and [start2, end2] of the same person, either start1 > end2 or start2 > end1.

    Example 1:

    >>> minAvailableDuration(slots1 = [[10,50],[60,120],[140,210]], slots2 = [[0,15],[60,70]], duration = 8)
    >>> [60,68]

    Example 2:

    >>> minAvailableDuration(slots1 = [[10,50],[60,120],[140,210]], slots2 = [[0,15],[60,70]], duration = 12)
    >>> []
    """


Prompt:
def probabilityOfHeads(prob: List[float], target: int) -> float:
    """
    You have some coins.  The i-th coin has a probability prob[i] of facing heads when tossed.
    Return the probability that the number of coins facing heads equals target if you toss every coin exactly once.

    Example 1:
    >>> probabilityOfHeads(prob = [0.4], target = 1)
    >>> 0.40000
    Example 2:
    >>> probabilityOfHeads(prob = [0.5,0.5,0.5,0.5,0.5], target = 0)
    >>> 0.03125
    """


Prompt:
def maximizeSweetness(sweetness: List[int], k: int) -> int:
    """
    You have one chocolate bar that consists of some chunks. Each chunk has its own sweetness given by the array sweetness.
    You want to share the chocolate with your k friends so you start cutting the chocolate bar into k + 1 pieces using k cuts, each piece consists of some consecutive chunks.
    Being generous, you will eat the piece with the minimum total sweetness and give the other pieces to your friends.
    Find the maximum total sweetness of the piece you can get by cutting the chocolate bar optimally.

    Example 1:

    >>> maximizeSweetness(sweetness = [1,2,3,4,5,6,7,8,9], k = 5)
    >>> 6
    Explanation: You can divide the chocolate to [1,2,3], [4,5], [6], [7], [8], [9]

    Example 2:

    >>> maximizeSweetness(sweetness = [5,6,7,8,9,1,2,3,4], k = 8)
    >>> 1
    Explanation: There is only one way to cut the bar into 9 pieces.

    Example 3:

    >>> maximizeSweetness(sweetness = [1,2,2,1,2,2,1,2,2], k = 2)
    >>> 5
    Explanation: You can divide the chocolate to [1,2,2], [1,2,2], [1,2,2]
    """


Prompt:
def checkStraightLine(coordinates: List[List[int]]) -> bool:
    """
    You are given an array coordinates, coordinates[i] = [x, y], where [x, y] represents the coordinate of a point. Check if these points make a straight line in the XY plane.

    Example 1:

    >>> checkStraightLine(coordinates = [[1,2],[2,3],[3,4],[4,5],[5,6],[6,7]])
    >>> true

    Example 2:

    >>> checkStraightLine(coordinates = [[1,1],[2,2],[3,4],[4,5],[5,6],[7,7]])
    >>> false
    """


Prompt:
def removeSubfolders(folder: List[str]) -> List[str]:
    """
    Given a list of folders folder, return the folders after removing all sub-folders in those folders. You may return the answer in any order.
    If a folder[i] is located within another folder[j], it is called a sub-folder of it. A sub-folder of folder[j] must start with folder[j], followed by a "/". For example, "/a/b" is a sub-folder of "/a", but "/b" is not a sub-folder of "/a/b/c".
    The format of a path is one or more concatenated strings of the form: '/' followed by one or more lowercase English letters.

    For example, "/leetcode" and "/leetcode/problems" are valid paths while an empty string and "/" are not.

    Example 1:

    >>> removeSubfolders(folder = ["/a","/a/b","/c/d","/c/d/e","/c/f"])
    >>> ["/a","/c/d","/c/f"]
    Explanation: Folders "/a/b" is a subfolder of "/a" and "/c/d/e" is inside of folder "/c/d" in our filesystem.

    Example 2:

    >>> removeSubfolders(folder = ["/a","/a/b/c","/a/b/d"])
    >>> ["/a"]
    Explanation: Folders "/a/b/c" and "/a/b/d" will be removed because they are subfolders of "/a".

    Example 3:

    >>> removeSubfolders(folder = ["/a/b/c","/a/b/ca","/a/b/d"])
    >>> ["/a/b/c","/a/b/ca","/a/b/d"]
    """


Prompt:
def balancedString(s: str) -> int:
    """
    You are given a string s of length n containing only four kinds of characters: 'Q', 'W', 'E', and 'R'.
    A string is said to be balanced if each of its characters appears n / 4 times where n is the length of the string.
    Return the minimum length of the substring that can be replaced with any other string of the same length to make s balanced. If s is already balanced, return 0.

    Example 1:

    >>> balancedString(s = "QWER")
    >>> 0
    Explanation: s is already balanced.

    Example 2:

    >>> balancedString(s = "QQWE")
    >>> 1
    Explanation: We need to replace a 'Q' to 'R', so that "RQWE" (or "QRWE") is balanced.

    Example 3:

    >>> balancedString(s = "QQQW")
    >>> 2
    Explanation: We can replace the first "QQ" to "ER".
    """


Prompt:
def jobScheduling(startTime: List[int], endTime: List[int], profit: List[int]) -> int:
    """
    We have n jobs, where every job is scheduled to be done from startTime[i] to endTime[i], obtaining a profit of profit[i].
    You're given the startTime, endTime and profit arrays, return the maximum profit you can take such that there are no two jobs in the subset with overlapping time range.
    If you choose a job that ends at time X you will be able to start another job that starts at time X.

    Example 1:

    >>> jobScheduling(startTime = [1,2,3,3], endTime = [3,4,5,6], profit = [50,10,40,70])
    >>> 120
    Explanation: The subset chosen is the first and fourth job.
    Time range [1-3]+[3-6] , we get profit of 120 = 50 + 70.

    Example 2:

    >>> jobScheduling(startTime = [1,2,3,4,6], endTime = [3,5,10,6,9], profit = [20,20,100,70,60])
    >>> 150
    Explanation: The subset chosen is the first, fourth and fifth job.
    Profit obtained 150 = 20 + 70 + 60.

    Example 3:

    >>> jobScheduling(startTime = [1,1,1], endTime = [2,3,4], profit = [5,6,4])
    >>> 6
    """


Prompt:
def circularPermutation(n: int, start: int) -> List[int]:
    """
    Given 2 integers n and start. Your task is return any permutation p of (0,1,2.....,2^n -1) such that :\r
    \r
    \r
    	p[0] = start\r
    	p[i] and p[i+1] differ by only one bit in their binary representation.\r
    	p[0] and p[2^n -1] must also differ by only one bit in their binary representation.\r
    \r
    \r
     \r
    Example 1:\r
    \r
    \r
    >>> circularPermutation(n = 2, start = 3\r)
    >>> [3,2,0,1]\r
    Explanation: The binary representation of the permutation is (11,10,00,01). \r
    All the adjacent element differ by one bit. Another valid permutation is [3,1,0,2]\r
    \r
    \r
    Example 2:\r
    \r
    \r
    >>> circularPermutation(n = 3, start = 2\r)
    >>> [2,6,7,5,4,0,1,3]\r
    Explanation: The binary representation of the permutation is (010,110,111,101,100,000,001,011).\r
    \r
    \r
     \r
    """


Prompt:
def maxLength(arr: List[str]) -> int:
    """
    You are given an array of strings arr. A string s is formed by the concatenation of a subsequence of arr that has unique characters.
    Return the maximum possible length of s.
    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.

    Example 1:

    >>> maxLength(arr = ["un","iq","ue"])
    >>> 4
    Explanation: All the valid concatenations are:
    - ""
    - "un"
    - "iq"
    - "ue"
    - "uniq" ("un" + "iq")
    - "ique" ("iq" + "ue")
    Maximum length is 4.

    Example 2:

    >>> maxLength(arr = ["cha","r","act","ers"])
    >>> 6
    Explanation: Possible longest valid concatenations are "chaers" ("cha" + "ers") and "acters" ("act" + "ers").

    Example 3:

    >>> maxLength(arr = ["abcdefghijklmnopqrstuvwxyz"])
    >>> 26
    Explanation: The only string in arr has all 26 characters.
    """


Prompt:
def tilingRectangle(n: int, m: int) -> int:
    """
    Given a rectangle of size n x m, return the minimum number of integer-sided squares that tile the rectangle.

    Example 1:

    >>> tilingRectangle(n = 2, m = 3)
    >>> 3
    Explanation: 3 squares are necessary to cover the rectangle.
    2 (squares of 1x1)
    1 (square of 2x2)
    Example 2:

    >>> tilingRectangle(n = 5, m = 8)
    >>> 5

    Example 3:

    >>> tilingRectangle(n = 11, m = 13)
    >>> 6
    """


Prompt:
# This is HtmlParser's API interface.
# You should not implement it, or speculate about its implementation
# """
#class HtmlParser(object):
#    def getUrls(url):
#        """
#        :type url: str
#        :rtype List[str]
#        """

class Solution:
    def crawl(startUrl: str, htmlParser: 'HtmlParser') -> List[str]:
    """
    Given a URL startUrl and an interface HtmlParser, implement a Multi-threaded web crawler to crawl all links that are under the same hostname as startUrl.
    Return all URLs obtained by your web crawler in any order.
    Your crawler should:

    Start from the page: startUrl
    Call HtmlParser.getUrls(url) to get all URLs from a webpage of a given URL.
    Do not crawl the same link twice.
    Explore only the links that are under the same hostname as startUrl.

    As shown in the example URL above, the hostname is example.org. For simplicity's sake, you may assume all URLs use HTTP protocol without any port specified. For example, the URLs http://leetcode.com/problems and http://leetcode.com/contest are under the same hostname, while URLs http://example.org/test and http://example.com/abc are not under the same hostname.
    The HtmlParser interface is defined as such:

    interface HtmlParser {
      // Return a list of all urls from a webpage of given url.
      // This is a blocking call, that means it will do HTTP request and return when this request is finished.
      public List getUrls(String url);
    }

    Note that getUrls(String url) simulates performing an HTTP request. You can treat it as a blocking function call that waits for an HTTP request to finish. It is guaranteed that getUrls(String url) will return the URLs within 15ms.  Single-threaded solutions will exceed the time limit so, can your multi-threaded web crawler do better?
    Below are two examples explaining the functionality of the problem. For custom testing purposes, you'll have three variables urls, edges and startUrl. Notice that you will only have access to startUrl in your code, while urls and edges are not directly accessible to you in code.

    Example 1:

    urls = [
      "http://news.yahoo.com",
      "http://news.yahoo.com/news",
      "http://news.yahoo.com/news/topics/",
      "http://news.google.com",
      "http://news.yahoo.com/us"
    ]
    edges = [[2,0],[2,1],[3,2],[3,1],[0,4]]
    startUrl = "http://news.yahoo.com/news/topics/"
    >>> getUrls()
    >>> [
      "http://news.yahoo.com",
      "http://news.yahoo.com/news",
      "http://news.yahoo.com/news/topics/",
      "http://news.yahoo.com/us"
    ]

    Example 2:

    urls = [
      "http://news.yahoo.com",
      "http://news.yahoo.com/news",
      "http://news.yahoo.com/news/topics/",
      "http://news.google.com"
    ]
    edges = [[0,2],[2,1],[3,2],[3,1],[3,0]]
    startUrl = "http://news.google.com"
    >>> getUrls()
    >>> ["http://news.google.com"]
    Explanation: The startUrl links to all other pages that do not share the same hostname.
    """


Prompt:
def transformArray(arr: List[int]) -> List[int]:
    """
    Given an initial array arr, every day you produce a new array using the array of the previous day.
    On the i-th day, you do the following operations on the array of day i-1 to produce the array of day i:

    If an element is smaller than both its left neighbor and its right neighbor, then this element is incremented.
    If an element is bigger than both its left neighbor and its right neighbor, then this element is decremented.
    The first and last elements never change.

    After some days, the array does not change. Return that final array.

    Example 1:

    >>> transformArray(arr = [6,2,3,4])
    >>> [6,3,3,4]
    Explanation:
    On the first day, the array is changed from [6,2,3,4] to [6,3,3,4].
    No more operations can be done to this array.

    Example 2:

    >>> transformArray(arr = [1,6,3,4,3,5])
    >>> [1,4,4,4,4,5]
    Explanation:
    On the first day, the array is changed from [1,6,3,4,3,5] to [1,5,4,3,4,5].
    On the second day, the array is changed from [1,5,4,3,4,5] to [1,4,4,4,4,5].
    No more operations can be done to this array.
    """


Prompt:
def treeDiameter(edges: List[List[int]]) -> int:
    """
    The diameter of a tree is the number of edges in the longest path in that tree.
    There is an undirected tree of n nodes labeled from 0 to n - 1. You are given a 2D array edges where edges.length == n - 1 and edges[i] = [ai, bi] indicates that there is an undirected edge between nodes ai and bi in the tree.
    Return the diameter of the tree.

    Example 1:

    >>> treeDiameter(edges = [[0,1],[0,2]])
    >>> 2
    Explanation: The longest path of the tree is the path 1 - 0 - 2.

    Example 2:

    >>> treeDiameter(edges = [[0,1],[1,2],[2,3],[1,4],[4,5]])
    >>> 4
    Explanation: The longest path of the tree is the path 3 - 2 - 1 - 4 - 5.
    """


Prompt:
def minimumMoves(arr: List[int]) -> int:
    """
    You are given an integer array arr.
    In one move, you can select a palindromic subarray arr[i], arr[i + 1], ..., arr[j] where i <= j, and remove that subarray from the given array. Note that after removing a subarray, the elements on the left and on the right of that subarray move to fill the gap left by the removal.
    Return the minimum number of moves needed to remove all numbers from the array.

    Example 1:

    >>> minimumMoves(arr = [1,2])
    >>> 2

    Example 2:

    >>> minimumMoves(arr = [1,3,4,1,5])
    >>> 3
    Explanation: Remove [4] then remove [1,3,1] then remove [5].
    """


Prompt:
def minimumSwap(s1: str, s2: str) -> int:
    """
    You are given two strings s1 and s2 of equal length consisting of letters "x" and "y" only. Your task is to make these two strings equal to each other. You can swap any two characters that belong to different strings, which means: swap s1[i] and s2[j].
    Return the minimum number of swaps required to make s1 and s2 equal, or return -1 if it is impossible to do so.

    Example 1:

    >>> minimumSwap(s1 = "xx", s2 = "yy")
    >>> 1
    Explanation: Swap s1[0] and s2[1], s1 = "yx", s2 = "yx".

    Example 2:

    >>> minimumSwap(s1 = "xy", s2 = "yx")
    >>> 2
    Explanation: Swap s1[0] and s2[0], s1 = "yy", s2 = "xx".
    Swap s1[0] and s2[1], s1 = "xy", s2 = "xy".
    Note that you cannot swap s1[0] and s1[1] to make s1 equal to "yx", cause we can only swap chars in different strings.

    Example 3:

    >>> minimumSwap(s1 = "xx", s2 = "xy")
    >>> -1
    """


Prompt:
def numberOfSubarrays(nums: List[int], k: int) -> int:
    """
    Given an array of integers nums and an integer k. A continuous subarray is called nice if there are k odd numbers on it.
    Return the number of nice sub-arrays.

    Example 1:

    >>> numberOfSubarrays(nums = [1,1,2,1,1], k = 3)
    >>> 2
    Explanation: The only sub-arrays with 3 odd numbers are [1,1,2,1] and [1,2,1,1].

    Example 2:

    >>> numberOfSubarrays(nums = [2,4,6], k = 1)
    >>> 0
    Explanation: There are no odd numbers in the array.

    Example 3:

    >>> numberOfSubarrays(nums = [2,2,2,1,2,2,1,2,2,2], k = 2)
    >>> 16
    """


Prompt:
def minRemoveToMakeValid(s: str) -> str:
    """
    Given a string s of '(' , ')' and lowercase English characters.
    Your task is to remove the minimum number of parentheses ( '(' or ')', in any positions ) so that the resulting parentheses string is valid and return any valid string.
    Formally, a parentheses string is valid if and only if:

    It is the empty string, contains only lowercase characters, or
    It can be written as AB (A concatenated with B), where A and B are valid strings, or
    It can be written as (A), where A is a valid string.

    Example 1:

    >>> minRemoveToMakeValid(s = "lee(t(c)o)de)")
    >>> "lee(t(c)o)de"
    Explanation: "lee(t(co)de)" , "lee(t(c)ode)" would also be accepted.

    Example 2:

    >>> minRemoveToMakeValid(s = "a)b(c)d")
    >>> "ab(c)d"

    Example 3:

    >>> minRemoveToMakeValid(s = "))((")
    >>> ""
    Explanation: An empty string is also valid.
    """


Prompt:
def isGoodArray(nums: List[int]) -> bool:
    """
    Given an array nums of positive integers. Your task is to select some subset of nums, multiply each element by an integer and add all these numbers. The array is said to be good if you can obtain a sum of 1 from the array by any possible subset and multiplicand.
    Return True if the array is good otherwise return False.

    Example 1:

    >>> isGoodArray(nums = [12,5,7,23])
    >>> true
    Explanation: Pick numbers 5 and 7.
    5*3 + 7*(-2) = 1

    Example 2:

    >>> isGoodArray(nums = [29,6,10])
    >>> true
    Explanation: Pick numbers 29, 6 and 10.
    29*1 + 6*(-3) + 10*(-1) = 1

    Example 3:

    >>> isGoodArray(nums = [3,6])
    >>> false
    """


Prompt:
def oddCells(m: int, n: int, indices: List[List[int]]) -> int:
    """
    There is an m x n matrix that is initialized to all 0's. There is also a 2D array indices where each indices[i] = [ri, ci] represents a 0-indexed location to perform some increment operations on the matrix.
    For each location indices[i], do both of the following:

    Increment all the cells on row ri.
    Increment all the cells on column ci.

    Given m, n, and indices, return the number of odd-valued cells in the matrix after applying the increment to all locations in indices.

    Example 1:

    >>> oddCells(m = 2, n = 3, indices = [[0,1],[1,1]])
    >>> 6
    Explanation: Initial matrix = [[0,0,0],[0,0,0]].
    After applying first increment it becomes [[1,2,1],[0,1,0]].
    The final matrix is [[1,3,1],[1,3,1]], which contains 6 odd numbers.

    Example 2:

    >>> oddCells(m = 2, n = 2, indices = [[1,1],[0,0]])
    >>> 0
    Explanation: Final matrix = [[2,2],[2,2]]. There are no odd numbers in the final matrix.
    """


Prompt:
def reconstructMatrix(upper: int, lower: int, colsum: List[int]) -> List[List[int]]:
    """
    Given the following details of a matrix with n columns and 2 rows :

    The matrix is a binary matrix, which means each element in the matrix can be 0 or 1.
    The sum of elements of the 0-th(upper) row is given as upper.
    The sum of elements of the 1-st(lower) row is given as lower.
    The sum of elements in the i-th column(0-indexed) is colsum[i], where colsum is given as an integer array with length n.

    Your task is to reconstruct the matrix with upper, lower and colsum.
    Return it as a 2-D integer array.
    If there are more than one valid solution, any of them will be accepted.
    If no valid solution exists, return an empty 2-D array.

    Example 1:

    >>> reconstructMatrix(upper = 2, lower = 1, colsum = [1,1,1])
    >>> [[1,1,0],[0,0,1]]
    Explanation: [[1,0,1],[0,1,0]], and [[0,1,1],[1,0,0]] are also correct answers.

    Example 2:

    >>> reconstructMatrix(upper = 2, lower = 3, colsum = [2,2,1,1])
    >>> []

    Example 3:

    >>> reconstructMatrix(upper = 5, lower = 5, colsum = [2,1,2,0,1,0,1,2,0,1])
    >>> [[1,1,1,0,1,0,0,1,0,0],[1,0,1,0,0,0,1,1,0,1]]
    """


Prompt:
def closedIsland(grid: List[List[int]]) -> int:
    """
    Given a 2D grid consists of 0s (land) and 1s (water).  An island is a maximal 4-directionally connected group of 0s and a closed island is an island totally (all left, top, right, bottom) surrounded by 1s.
    Return the number of closed islands.

    Example 1:

    >>> closedIsland(grid = [[1,1,1,1,1,1,1,0],[1,0,0,0,0,1,1,0],[1,0,1,0,1,1,1,0],[1,0,0,0,0,1,0,1],[1,1,1,1,1,1,1,0]])
    >>> 2
    Explanation:
    Islands in gray are closed because they are completely surrounded by water (group of 1s).
    Example 2:

    >>> closedIsland(grid = [[0,0,1,0,0],[0,1,0,1,0],[0,1,1,1,0]])
    >>> 1

    Example 3:

                   [1,0,0,0,0,0,1],
                   [1,0,1,1,1,0,1],
                   [1,0,1,0,1,0,1],
                   [1,0,1,1,1,0,1],
                   [1,0,0,0,0,0,1],
                   [1,1,1,1,1,1,1]]
    >>> closedIsland(grid = [[1,1,1,1,1,1,1],)
    >>> 2
    """


Prompt:
def maxScoreWords(words: List[str], letters: List[str], score: List[int]) -> int:
    """
    Given a list of words, list of  single letters (might be repeating) and score of every character.
    Return the maximum score of any valid set of words formed by using the given letters (words[i] cannot be used two or more times).
    It is not necessary to use all characters in letters and each letter can only be used once. Score of letters 'a', 'b', 'c', ... ,'z' is given by score[0], score[1], ... , score[25] respectively.

    Example 1:

    >>> maxScoreWords(words = ["dog","cat","dad","good"], letters = ["a","a","c","d","d","d","g","o","o"], score = [1,0,9,5,0,0,3,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0])
    >>> 23
    Explanation:
    Score  a=1, c=9, d=5, g=3, o=2
    Given letters, we can form the words "dad" (5+1+5) and "good" (3+2+2+5) with a score of 23.
    Words "dad" and "dog" only get a score of 21.
    Example 2:

    >>> maxScoreWords(words = ["xxxz","ax","bx","cx"], letters = ["z","a","b","c","x","x","x"], score = [4,4,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,5,0,10])
    >>> 27
    Explanation:
    Score  a=4, b=4, c=4, x=5, z=10
    Given letters, we can form the words "ax" (4+5), "bx" (4+5) and "cx" (4+5) with a score of 27.
    Word "xxxz" only get a score of 25.
    Example 3:

    >>> maxScoreWords(words = ["leetcode"], letters = ["l","e","t","c","o","d"], score = [0,0,1,1,1,0,0,0,0,0,0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0])
    >>> 0
    Explanation:
    Letter "e" can only be used once.
    """


Prompt:
def encode(num: int) -> str:
    """
    Given a non-negative integer num, Return its encoding string.\r
    \r
    The encoding is done by converting the integer to a string using a secret function that you should deduce from the following table:\r
    \r
    \r
    \r
     \r
    Example 1:\r
    \r
    \r
    >>> encode(num = 23\r)
    >>> "1000"\r
    \r
    \r
    Example 2:\r
    \r
    \r
    >>> encode(num = 107\r)
    >>> "101100"\r
    \r
    \r
     \r
    """


Prompt:
def findSmallestRegion(regions: List[List[str]], region1: str, region2: str) -> str:
    """
    You are given some lists of regions where the first region of each list includes all other regions in that list.
    Naturally, if a region x contains another region y then x is bigger than y. Also, by definition, a region x contains itself.
    Given two regions: region1 and region2, return the smallest region that contains both of them.
    If you are given regions r1, r2, and r3 such that r1 includes r3, it is guaranteed there is no r2 such that r2 includes r3.
    It is guaranteed the smallest region exists.

    Example 1:

    regions = [["Earth","North America","South America"],
    ["North America","United States","Canada"],
    ["United States","New York","Boston"],
    ["Canada","Ontario","Quebec"],
    ["South America","Brazil"]],
    region1 = "Quebec",
    region2 = "New York"
    >>> findSmallestRegion()
    >>> "North America"

    Example 2:

    >>> findSmallestRegion(regions = [["Earth", "North America", "South America"],["North America", "United States", "Canada"],["United States", "New York", "Boston"],["Canada", "Ontario", "Quebec"],["South America", "Brazil"]], region1 = "Canada", region2 = "South America")
    >>> "Earth"
    """


Prompt:
def generateSentences(synonyms: List[List[str]], text: str) -> List[str]:
    """
    You are given a list of equivalent string pairs synonyms where synonyms[i] = [si, ti] indicates that si and ti are equivalent strings. You are also given a sentence text.
    Return all possible synonymous sentences sorted lexicographically.

    Example 1:

    >>> generateSentences(synonyms = [["happy","joy"],["sad","sorrow"],["joy","cheerful"]], text = "I am happy today but was sad yesterday")
    >>> ["I am cheerful today but was sad yesterday","I am cheerful today but was sorrow yesterday","I am happy today but was sad yesterday","I am happy today but was sorrow yesterday","I am joy today but was sad yesterday","I am joy today but was sorrow yesterday"]

    Example 2:

    >>> generateSentences(synonyms = [["happy","joy"],["cheerful","glad"]], text = "I am happy today but was sad yesterday")
    >>> ["I am happy today but was sad yesterday","I am joy today but was sad yesterday"]
    """


Prompt:
def numberOfWays(numPeople: int) -> int:
    """
    You are given an even number of people numPeople that stand around a circle and each person shakes hands with someone else so that there are numPeople / 2 handshakes total.
    Return the number of ways these handshakes could occur such that none of the handshakes cross.
    Since the answer could be very large, return it modulo 109 + 7.

    Example 1:

    >>> numberOfWays(numPeople = 4)
    >>> 2
    Explanation: There are two ways to do it, the first way is [(1,2),(3,4)] and the second one is [(2,3),(4,1)].

    Example 2:

    >>> numberOfWays(numPeople = 6)
    >>> 5
    """


Prompt:
def shiftGrid(grid: List[List[int]], k: int) -> List[List[int]]:
    """
    Given a 2D grid of size m x n and an integer k. You need to shift the grid k times.
    In one shift operation:

    Element at grid[i][j] moves to grid[i][j + 1].
    Element at grid[i][n - 1] moves to grid[i + 1][0].
    Element at grid[m - 1][n - 1] moves to grid[0][0].

    Return the 2D grid after applying shift operation k times.

    Example 1:

    >>> shiftGrid(grid = [[1,2,3],[4,5,6],[7,8,9]], k = 1)
    >>> [[9,1,2],[3,4,5],[6,7,8]]

    Example 2:

    >>> shiftGrid(grid = [[3,8,1,9],[19,7,2,5],[4,6,11,10],[12,0,21,13]], k = 4)
    >>> [[12,0,21,13],[3,8,1,9],[19,7,2,5],[4,6,11,10]]

    Example 3:

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


Prompt:
def maxSumDivThree(nums: List[int]) -> int:
    """
    Given an integer array nums, return the maximum possible sum of elements of the array such that it is divisible by three.

    Example 1:

    >>> maxSumDivThree(nums = [3,6,5,1,8])
    >>> 18
    Explanation: Pick numbers 3, 6, 1 and 8 their sum is 18 (maximum sum divisible by 3).
    Example 2:

    >>> maxSumDivThree(nums = [4])
    >>> 0
    Explanation: Since 4 is not divisible by 3, do not pick any number.

    Example 3:

    >>> maxSumDivThree(nums = [1,2,3,4,4])
    >>> 12
    Explanation: Pick numbers 1, 3, 4 and 4 their sum is 12 (maximum sum divisible by 3).
    """


Prompt:
def minPushBox(grid: List[List[str]]) -> int:
    """
    A storekeeper is a game in which the player pushes boxes around in a warehouse trying to get them to target locations.
    The game is represented by an m x n grid of characters grid where each element is a wall, floor, or box.
    Your task is to move the box 'B' to the target position 'T' under the following rules:

    The character 'S' represents the player. The player can move up, down, left, right in grid if it is a floor (empty cell).
    The character '.' represents the floor which means a free cell to walk.
    The character '#' represents the wall which means an obstacle (impossible to walk there).
    There is only one box 'B' and one target cell 'T' in the grid.
    The box can be moved to an adjacent free cell by standing next to the box and then moving in the direction of the box. This is a push.
    The player cannot walk through the box.

    Return the minimum number of pushes to move the box to the target. If there is no way to reach the target, return -1.

    Example 1:

                   ["#","T","#","#","#","#"],
                   ["#",".",".","B",".","#"],
                   ["#",".","#","#",".","#"],
                   ["#",".",".",".","S","#"],
                   ["#","#","#","#","#","#"]]
    >>> minPushBox(grid = [["#","#","#","#","#","#"],)
    >>> 3
    Explanation: We return only the number of times the box is pushed.
    Example 2:

                   ["#","T","#","#","#","#"],
                   ["#",".",".","B",".","#"],
                   ["#","#","#","#",".","#"],
                   ["#",".",".",".","S","#"],
                   ["#","#","#","#","#","#"]]
    >>> minPushBox(grid = [["#","#","#","#","#","#"],)
    >>> -1

    Example 3:

                   ["#","T",".",".","#","#"],
                   ["#",".","#","B",".","#"],
                   ["#",".",".",".",".","#"],
                   ["#",".",".",".","S","#"],
                   ["#","#","#","#","#","#"]]
    >>> minPushBox(grid = [["#","#","#","#","#","#"],)
    >>> 5
    Explanation: push the box down, left, left, up and up.
    """


Prompt:
def minTimeToVisitAllPoints(points: List[List[int]]) -> int:
    """
    On a 2D plane, there are n points with integer coordinates points[i] = [xi, yi]. Return the minimum time in seconds to visit all the points in the order given by points.
    You can move according to these rules:

    In 1 second, you can either:

    move vertically by one unit,
    move horizontally by one unit, or
    move diagonally sqrt(2) units (in other words, move one unit vertically then one unit horizontally in 1 second).

    You have to visit the points in the same order as they appear in the array.
    You are allowed to pass through points that appear later in the order, but these do not count as visits.

    Example 1:

    >>> minTimeToVisitAllPoints(points = [[1,1],[3,4],[-1,0]])
    >>> 7
    Explanation: One optimal path is [1,1] -> [2,2] -> [3,3] -> [3,4] -> [2,3] -> [1,2] -> [0,1] -> [-1,0]
    Time from [1,1] to [3,4] = 3 seconds
    Time from [3,4] to [-1,0] = 4 seconds
    Total time = 7 seconds
    Example 2:

    >>> minTimeToVisitAllPoints(points = [[3,2],[-2,2]])
    >>> 5
    """


Prompt:
def countServers(grid: List[List[int]]) -> int:
    """
    You are given a map of a server center, represented as a m * n integer matrix grid, where 1 means that on that cell there is a server and 0 means that it is no server. Two servers are said to communicate if they are on the same row or on the same column.

    Return the number of servers that communicate with any other server.

    Example 1:

    >>> countServers(grid = [[1,0],[0,1]])
    >>> 0
    Explanation: No servers can communicate with others.
    Example 2:

    >>> countServers(grid = [[1,0],[1,1]])
    >>> 3
    Explanation: All three servers can communicate with at least one other server.

    Example 3:

    >>> countServers(grid = [[1,1,0,0],[0,0,1,0],[0,0,1,0],[0,0,0,1]])
    >>> 4
    Explanation: The two servers in the first row can communicate with each other. The two servers in the third column can communicate with each other. The server at right bottom corner can't communicate with any other server.
    """