]>]]>>]\")\n >>> true\n Explanation:\n We first separate the code into : start_tag|tag_content|end_tag.\n start_tag -> \"\"\n end_tag -> \"\"\n tag_content could also be separated into : text1|cdata|text2.\n text1 -> \">> ![cdata[]] \"\n cdata -> \"
]>\", where the CDATA_CONTENT is \"]>\"\n text2 -> \"]]>>]\"\n The reason why start_tag is NOT \">>\" is because of the rule 6.\n The reason why cdata is NOT \"
]>]]>\" is because of the rule 7.\n \n Example 3:\n \n >>> isValid(code = \" \")\n >>> false\n Explanation: Unbalanced. If \"\" is closed, then \"\" must be unmatched, and vice versa.\n \"\"\"\n"}
{"task_id": "fraction-addition-and-subtraction", "prompt": "def fractionAddition(expression: str) -> str:\n \"\"\"\n Given a string expression representing an expression of fraction addition and subtraction, return the calculation result in string format.\n The final result should be an irreducible fraction. If your final result is an integer, change it to the format of a fraction that has a denominator 1. So in this case, 2 should be converted to 2/1.\n \n Example 1:\n \n >>> fractionAddition(expression = \"-1/2+1/2\")\n >>> \"0/1\"\n \n Example 2:\n \n >>> fractionAddition(expression = \"-1/2+1/2+1/3\")\n >>> \"1/3\"\n \n Example 3:\n \n >>> fractionAddition(expression = \"1/3-1/2\")\n >>> \"-1/6\"\n \"\"\"\n"}
{"task_id": "valid-square", "prompt": "def validSquare(p1: List[int], p2: List[int], p3: List[int], p4: List[int]) -> bool:\n \"\"\"\n Given the coordinates of four points in 2D space p1, p2, p3 and p4, return true if the four points construct a square.\n The coordinate of a point pi is represented as [xi, yi]. The input is not given in any order.\n A valid square has four equal sides with positive length and four equal angles (90-degree angles).\n \n Example 1:\n \n >>> validSquare(p1 = [0,0], p2 = [1,1], p3 = [1,0], p4 = [0,1])\n >>> true\n \n Example 2:\n \n >>> validSquare(p1 = [0,0], p2 = [1,1], p3 = [1,0], p4 = [0,12])\n >>> false\n \n Example 3:\n \n >>> validSquare(p1 = [1,0], p2 = [-1,0], p3 = [0,1], p4 = [0,-1])\n >>> true\n \"\"\"\n"}
{"task_id": "longest-harmonious-subsequence", "prompt": "def findLHS(nums: List[int]) -> int:\n \"\"\"\n We define a harmonious array as an array where the difference between its maximum value and its minimum value is exactly 1.\n Given an integer array nums, return the length of its longest harmonious subsequence among all its possible subsequences.\n \n Example 1:\n \n >>> findLHS(nums = [1,3,2,2,5,2,3,7])\n >>> 5\n Explanation:\n The longest harmonious subsequence is [3,2,2,2,3].\n \n Example 2:\n \n >>> findLHS(nums = [1,2,3,4])\n >>> 2\n Explanation:\n The longest harmonious subsequences are [1,2], [2,3], and [3,4], all of which have a length of 2.\n \n Example 3:\n \n >>> findLHS(nums = [1,1,1,1])\n >>> 0\n Explanation:\n No harmonic subsequence exists.\n \"\"\"\n"}
{"task_id": "range-addition-ii", "prompt": "def maxCount(m: int, n: int, ops: List[List[int]]) -> int:\n \"\"\"\n You are given an m x n matrix M initialized with all 0's and an array of operations ops, where ops[i] = [ai, bi] means M[x][y] should be incremented by one for all 0 <= x < ai and 0 <= y < bi.\n Count and return the number of maximum integers in the matrix after performing all the operations.\n \n Example 1:\n \n \n >>> maxCount(m = 3, n = 3, ops = [[2,2],[3,3]])\n >>> 4\n Explanation: The maximum integer in M is 2, and there are four of it in M. So return 4.\n \n Example 2:\n \n >>> maxCount(m = 3, n = 3, ops = [[2,2],[3,3],[3,3],[3,3],[2,2],[3,3],[3,3],[3,3],[2,2],[3,3],[3,3],[3,3]])\n >>> 4\n \n Example 3:\n \n >>> maxCount(m = 3, n = 3, ops = [])\n >>> 9\n \"\"\"\n"}
{"task_id": "minimum-index-sum-of-two-lists", "prompt": "def findRestaurant(list1: List[str], list2: List[str]) -> List[str]:\n \"\"\"\n Given two arrays of strings list1 and list2, find the common strings with the least index sum.\n A common string is a string that appeared in both list1 and list2.\n A common string with the least index sum is a common string such that if it appeared at list1[i] and list2[j] then i + j should be the minimum value among all the other common strings.\n Return all the common strings with the least index sum. Return the answer in any order.\n \n Example 1:\n \n >>> findRestaurant(list1 = [\"Shogun\",\"Tapioca Express\",\"Burger King\",\"KFC\"], list2 = [\"Piatti\",\"The Grill at Torrey Pines\",\"Hungry Hunter Steakhouse\",\"Shogun\"])\n >>> [\"Shogun\"]\n Explanation: The only common string is \"Shogun\".\n \n Example 2:\n \n >>> findRestaurant(list1 = [\"Shogun\",\"Tapioca Express\",\"Burger King\",\"KFC\"], list2 = [\"KFC\",\"Shogun\",\"Burger King\"])\n >>> [\"Shogun\"]\n Explanation: The common string with the least index sum is \"Shogun\" with index sum = (0 + 1) = 1.\n \n Example 3:\n \n >>> findRestaurant(list1 = [\"happy\",\"sad\",\"good\"], list2 = [\"sad\",\"happy\",\"good\"])\n >>> [\"sad\",\"happy\"]\n Explanation: There are three common strings:\n \"happy\" with index sum = (0 + 1) = 1.\n \"sad\" with index sum = (1 + 0) = 1.\n \"good\" with index sum = (2 + 2) = 4.\n The strings with the least index sum are \"sad\" and \"happy\".\n \"\"\"\n"}
{"task_id": "non-negative-integers-without-consecutive-ones", "prompt": "def findIntegers(n: int) -> int:\n \"\"\"\n Given a positive integer n, return the number of the integers in the range [0, n] whose binary representations do not contain consecutive ones.\n \n Example 1:\n \n >>> findIntegers(n = 5)\n >>> 5\n Explanation:\n Here are the non-negative integers <= 5 with their corresponding binary representations:\n 0 : 0\n 1 : 1\n 2 : 10\n 3 : 11\n 4 : 100\n 5 : 101\n Among them, only integer 3 disobeys the rule (two consecutive ones) and the other 5 satisfy the rule.\n \n Example 2:\n \n >>> findIntegers(n = 1)\n >>> 2\n \n Example 3:\n \n >>> findIntegers(n = 2)\n >>> 3\n \"\"\"\n"}
{"task_id": "can-place-flowers", "prompt": "def canPlaceFlowers(flowerbed: List[int], n: int) -> bool:\n \"\"\"\n You have a long flowerbed in which some of the plots are planted, and some are not. However, flowers cannot be planted in adjacent plots.\n Given an integer array flowerbed containing 0's and 1's, where 0 means empty and 1 means not empty, and an integer n, return true\u00a0if n new flowers can be planted in the flowerbed without violating the no-adjacent-flowers rule and false otherwise.\n \n Example 1:\n >>> canPlaceFlowers(flowerbed = [1,0,0,0,1], n = 1)\n >>> true\n Example 2:\n >>> canPlaceFlowers(flowerbed = [1,0,0,0,1], n = 2)\n >>> false\n \"\"\"\n"}
{"task_id": "construct-string-from-binary-tree", "prompt": "# class TreeNode:\n# def __init__(val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def tree2str(root: Optional[TreeNode]) -> str:\n \"\"\"\n Given the root node of a binary tree, your task is to create a string representation of the tree following a specific set of formatting rules. The representation should be based on a preorder traversal of the binary tree and must adhere to the following guidelines:\n \n \n Node Representation: Each node in the tree should be represented by its integer value.\n \n \n Parentheses for Children: If a node has at least one child (either left or right), its children should be represented inside parentheses. Specifically:\n \n If a node has a left child, the value of the left child should be enclosed in parentheses immediately following the node's value.\n If a node has a right child, the value of the right child should also be enclosed in parentheses. The parentheses for the right child should follow those of the left child.\n \n \n \n Omitting Empty Parentheses: Any empty parentheses pairs (i.e., ()) should be omitted from the final string representation of the tree, with one specific exception: when a node has a right child but no left child. In such cases, you must include an empty pair of parentheses to indicate the absence of the left child. This ensures that the one-to-one mapping between the string representation and the original binary tree structure is maintained.\n In summary, empty parentheses pairs should be omitted when a node has only a left child or no children. However, when a node has a right child but no left child, an empty pair of parentheses must precede the representation of the right child to reflect the tree's structure accurately.\n \n \n \n Example 1:\n \n \n >>> __init__(root = [1,2,3,4])\n >>> \"1(2(4))(3)\"\n Explanation: Originally, it needs to be \"1(2(4)())(3()())\", but you need to omit all the empty parenthesis pairs. And it will be \"1(2(4))(3)\".\n \n Example 2:\n \n \n >>> __init__(root = [1,2,3,null,4])\n >>> \"1(2()(4))(3)\"\n Explanation: Almost the same as the first example, except the () after 2 is necessary to indicate the absence of a left child for 2 and the presence of a right child.\n \"\"\"\n"}
{"task_id": "find-duplicate-file-in-system", "prompt": "def findDuplicate(paths: List[str]) -> List[List[str]]:\n \"\"\"\n Given a list paths of directory info, including the directory path, and all the files with contents in this directory, return all the duplicate files in the file system in terms of their paths. You may return the answer in any order.\n A group of duplicate files consists of at least two files that have the same content.\n A single directory info string in the input list has the following format:\n \n \"root/d1/d2/.../dm f1.txt(f1_content) f2.txt(f2_content) ... fn.txt(fn_content)\"\n \n It means there are n files (f1.txt, f2.txt ... fn.txt) with content (f1_content, f2_content ... fn_content) respectively in the directory \"root/d1/d2/.../dm\". Note that n >= 1 and m >= 0. If m = 0, it means the directory is just the root directory.\n The output is a list of groups of duplicate file paths. For each group, it contains all the file paths of the files that have the same content. A file path is a string that has the following format:\n \n \"directory_path/file_name.txt\"\n \n \n Example 1:\n >>> findDuplicate(paths = [\"root/a 1.txt(abcd) 2.txt(efgh)\",\"root/c 3.txt(abcd)\",\"root/c/d 4.txt(efgh)\",\"root 4.txt(efgh)\"])\n >>> [[\"root/a/2.txt\",\"root/c/d/4.txt\",\"root/4.txt\"],[\"root/a/1.txt\",\"root/c/3.txt\"]]\n Example 2:\n >>> findDuplicate(paths = [\"root/a 1.txt(abcd) 2.txt(efgh)\",\"root/c 3.txt(abcd)\",\"root/c/d 4.txt(efgh)\"])\n >>> [[\"root/a/2.txt\",\"root/c/d/4.txt\"],[\"root/a/1.txt\",\"root/c/3.txt\"]]\n \"\"\"\n"}
{"task_id": "valid-triangle-number", "prompt": "def triangleNumber(nums: List[int]) -> int:\n \"\"\"\n Given an integer array nums, return the number of triplets chosen from the array that can make triangles if we take them as side lengths of a triangle.\n \n Example 1:\n \n >>> triangleNumber(nums = [2,2,3,4])\n >>> 3\n Explanation: Valid combinations are:\n 2,3,4 (using the first 2)\n 2,3,4 (using the second 2)\n 2,2,3\n \n Example 2:\n \n >>> triangleNumber(nums = [4,2,3,4])\n >>> 4\n \"\"\"\n"}
{"task_id": "add-bold-tag-in-string", "prompt": "def addBoldTag(s: str, words: List[str]) -> str:\n \"\"\"\n You are given a string s and an array of strings words.\n You should add a closed pair of bold tag and to wrap the substrings in s that exist in words.\n \n If two such substrings overlap, you should wrap them together with only one pair of closed bold-tag.\n If two substrings wrapped by bold tags are consecutive, you should combine them.\n \n Return s after adding the bold tags.\n \n Example 1:\n \n >>> addBoldTag(s = \"abcxyz123\", words = [\"abc\",\"123\"])\n >>> \"abcxyz123\"\n Explanation: The two strings of words are substrings of s as following: \"abcxyz123\".\n We add before each substring and after each substring.\n \n Example 2:\n \n >>> addBoldTag(s = \"aaabbb\", words = [\"aa\",\"b\"])\n >>> \"aaabbb\"\n Explanation:\n \"aa\" appears as a substring two times: \"aaabbb\" and \"aaabbb\".\n \"b\" appears as a substring three times: \"aaabbb\", \"aaabbb\", and \"aaabbb\".\n We add before each substring and after each substring: \"aaabbb\".\n Since the first two 's overlap, we merge them: \"aaabbb\".\n Since now the four 's are consecutive, we merge them: \"aaabbb\".\n \"\"\"\n"}
{"task_id": "merge-two-binary-trees", "prompt": "# class TreeNode:\n# def __init__(val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def mergeTrees(root1: Optional[TreeNode], root2: Optional[TreeNode]) -> Optional[TreeNode]:\n \"\"\"\n You are given two binary trees root1 and root2.\n Imagine that when you put one of them to cover the other, some nodes of the two trees are overlapped while the others are not. You need to merge the two trees into a new binary tree. The merge rule is that if two nodes overlap, then sum node values up as the new value of the merged node. Otherwise, the NOT null node will be used as the node of the new tree.\n Return the merged tree.\n Note: The merging process must start from the root nodes of both trees.\n \n Example 1:\n \n \n >>> __init__(root1 = [1,3,2,5], root2 = [2,1,3,null,4,null,7])\n >>> [3,4,5,5,4,null,7]\n \n Example 2:\n \n >>> __init__(root1 = [1], root2 = [1,2])\n >>> [2,2]\n \"\"\"\n"}
{"task_id": "task-scheduler", "prompt": "def leastInterval(tasks: List[str], n: int) -> int:\n \"\"\"\n You are given an array of CPU tasks, each labeled with a letter from A to Z, and a number n. Each CPU interval can be idle or allow the completion of one task. Tasks can be completed in any order, but there's a constraint: there has to be a gap of at least n intervals between two tasks with the same label.\n Return the minimum number of CPU intervals required to complete all tasks.\n \n Example 1:\n \n >>> leastInterval(tasks = [\"A\",\"A\",\"A\",\"B\",\"B\",\"B\"], n = 2)\n >>> 8\n Explanation: A possible sequence is: A -> B -> idle -> A -> B -> idle -> A -> B.\n After completing task A, you must wait two intervals before doing A again. The same applies to task B. In the 3rd interval, neither A nor B can be done, so you idle. By the 4th interval, you can do A again as 2 intervals have passed.\n \n Example 2:\n \n >>> leastInterval(tasks = [\"A\",\"C\",\"A\",\"B\",\"D\",\"B\"], n = 1)\n >>> 6\n Explanation: A possible sequence is: A -> B -> C -> D -> A -> B.\n With a cooling interval of 1, you can repeat a task after just one other task.\n \n Example 3:\n \n >>> leastInterval(tasks = [\"A\",\"A\",\"A\", \"B\",\"B\",\"B\"], n = 3)\n >>> 10\n Explanation: A possible sequence is: A -> B -> idle -> idle -> A -> B -> idle -> idle -> A -> B.\n There are only two types of tasks, A and B, which need to be separated by 3 intervals. This leads to idling twice between repetitions of these tasks.\n \"\"\"\n"}
{"task_id": "add-one-row-to-tree", "prompt": "# class TreeNode:\n# def __init__(val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def addOneRow(root: Optional[TreeNode], val: int, depth: int) -> Optional[TreeNode]:\n \"\"\"\n Given the root of a binary tree and two integers val and depth, add a row of nodes with value val at the given depth depth.\n Note that the root node is at depth 1.\n The adding rule is:\n \n Given the integer depth, for each not null tree node cur at the depth depth - 1, create two tree nodes with value val as cur's left subtree root and right subtree root.\n cur's original left subtree should be the left subtree of the new left subtree root.\n cur's original right subtree should be the right subtree of the new right subtree root.\n If depth == 1 that means there is no depth depth - 1 at all, then create a tree node with value val as the new root of the whole original tree, and the original tree is the new root's left subtree.\n \n \n Example 1:\n \n \n >>> __init__(root = [4,2,6,3,1,5], val = 1, depth = 2)\n >>> [4,1,1,2,null,null,6,3,1,5]\n \n Example 2:\n \n \n >>> __init__(root = [4,2,null,3,1], val = 1, depth = 3)\n >>> [4,2,null,1,1,3,null,null,1]\n \"\"\"\n"}
{"task_id": "maximum-distance-in-arrays", "prompt": "def maxDistance(arrays: List[List[int]]) -> int:\n \"\"\"\n You are given m arrays, where each array is sorted in ascending order.\n You can pick up two integers from two different arrays (each array picks one) and calculate the distance. We define the distance between two integers a and b to be their absolute difference |a - b|.\n Return the maximum distance.\n \n Example 1:\n \n >>> maxDistance(arrays = [[1,2,3],[4,5],[1,2,3]])\n >>> 4\n Explanation: One way to reach the maximum distance 4 is to pick 1 in the first or third array and pick 5 in the second array.\n \n Example 2:\n \n >>> maxDistance(arrays = [[1],[1]])\n >>> 0\n \"\"\"\n"}
{"task_id": "minimum-factorization", "prompt": "def smallestFactorization(num: int) -> int:\n \"\"\"\n Given a positive integer num, return the smallest positive integer x whose multiplication of each digit equals num. If there is no answer or the answer is not fit in 32-bit signed integer, return 0.\n \n Example 1:\n >>> smallestFactorization(num = 48)\n >>> 68\n Example 2:\n >>> smallestFactorization(num = 15)\n >>> 35\n \"\"\"\n"}
{"task_id": "maximum-product-of-three-numbers", "prompt": "def maximumProduct(nums: List[int]) -> int:\n \"\"\"\n Given an integer array nums, find three numbers whose product is maximum and return the maximum product.\n \n Example 1:\n >>> maximumProduct(nums = [1,2,3])\n >>> 6\n Example 2:\n >>> maximumProduct(nums = [1,2,3,4])\n >>> 24\n Example 3:\n >>> maximumProduct(nums = [-1,-2,-3])\n >>> -6\n \"\"\"\n"}
{"task_id": "k-inverse-pairs-array", "prompt": "def kInversePairs(n: int, k: int) -> int:\n \"\"\"\n For an integer array nums, an inverse pair is a pair of integers [i, j] where 0 <= i < j < nums.length and nums[i] > nums[j].\n Given two integers n and k, return the number of different arrays consisting of numbers from 1 to n such that there are exactly k inverse pairs. Since the answer can be huge, return it modulo 109 + 7.\n \n Example 1:\n \n >>> kInversePairs(n = 3, k = 0)\n >>> 1\n Explanation: Only the array [1,2,3] which consists of numbers from 1 to 3 has exactly 0 inverse pairs.\n \n Example 2:\n \n >>> kInversePairs(n = 3, k = 1)\n >>> 2\n Explanation: The array [1,3,2] and [2,1,3] have exactly 1 inverse pair.\n \"\"\"\n"}
{"task_id": "course-schedule-iii", "prompt": "def scheduleCourse(courses: List[List[int]]) -> int:\n \"\"\"\n There are n different online courses numbered from 1 to n. You are given an array courses where courses[i] = [durationi, lastDayi] indicate that the ith course should be taken continuously for durationi days and must be finished before or on lastDayi.\n You will start on the 1st day and you cannot take two or more courses simultaneously.\n Return the maximum number of courses that you can take.\n \n Example 1:\n \n >>> scheduleCourse(courses = [[100,200],[200,1300],[1000,1250],[2000,3200]])\n >>> 3\n Explanation:\n There are totally 4 courses, but you can take 3 courses at most:\n First, take the 1st course, it costs 100 days so you will finish it on the 100th day, and ready to take the next course on the 101st day.\n Second, take the 3rd course, it costs 1000 days so you will finish it on the 1100th day, and ready to take the next course on the 1101st day.\n Third, take the 2nd course, it costs 200 days so you will finish it on the 1300th day.\n The 4th course cannot be taken now, since you will finish it on the 3300th day, which exceeds the closed date.\n \n Example 2:\n \n >>> scheduleCourse(courses = [[1,2]])\n >>> 1\n \n Example 3:\n \n >>> scheduleCourse(courses = [[3,2],[4,3]])\n >>> 0\n \"\"\"\n"}
{"task_id": "smallest-range-covering-elements-from-k-lists", "prompt": "def smallestRange(nums: List[List[int]]) -> List[int]:\n \"\"\"\n You have k lists of sorted integers in non-decreasing\u00a0order. Find the smallest range that includes at least one number from each of the k lists.\n We define the range [a, b] is smaller than range [c, d] if b - a < d - c or a < c if b - a == d - c.\n \n Example 1:\n \n >>> smallestRange(nums = [[4,10,15,24,26],[0,9,12,20],[5,18,22,30]])\n >>> [20,24]\n Explanation:\n List 1: [4, 10, 15, 24,26], 24 is in range [20,24].\n List 2: [0, 9, 12, 20], 20 is in range [20,24].\n List 3: [5, 18, 22, 30], 22 is in range [20,24].\n \n Example 2:\n \n >>> smallestRange(nums = [[1,2,3],[1,2,3],[1,2,3]])\n >>> [1,1]\n \"\"\"\n"}
{"task_id": "sum-of-square-numbers", "prompt": "def judgeSquareSum(c: int) -> bool:\n \"\"\"\n Given a non-negative integer c, decide whether there're two integers a and b such that a2 + b2 = c.\n \n Example 1:\n \n >>> judgeSquareSum(c = 5)\n >>> true\n Explanation: 1 * 1 + 2 * 2 = 5\n \n Example 2:\n \n >>> judgeSquareSum(c = 3)\n >>> false\n \"\"\"\n"}
{"task_id": "find-the-derangement-of-an-array", "prompt": "def findDerangement(n: int) -> int:\n \"\"\"\n In combinatorial mathematics, a derangement is a permutation of the elements of a set, such that no element appears in its original position.\n You are given an integer n. There is originally an array consisting of n integers from 1 to n in ascending order, return the number of derangements it can generate. Since the answer may be huge, return it modulo 109 + 7.\n \n Example 1:\n \n >>> findDerangement(n = 3)\n >>> 2\n Explanation: The original array is [1,2,3]. The two derangements are [2,3,1] and [3,1,2].\n \n Example 2:\n \n >>> findDerangement(n = 2)\n >>> 1\n \"\"\"\n"}
{"task_id": "exclusive-time-of-functions", "prompt": "def exclusiveTime(n: int, logs: List[str]) -> List[int]:\n \"\"\"\n On a single-threaded CPU, we execute a program containing n functions. Each function has a unique ID between 0 and n-1.\n Function calls are stored in a call stack: when a function call starts, its ID is pushed onto the stack, and when a function call ends, its ID is popped off the stack. The function whose ID is at the top of the stack is the current function being executed. Each time a function starts or ends, we write a log with the ID, whether it started or ended, and the timestamp.\n You are given a list logs, where logs[i] represents the ith log message formatted as a string \"{function_id}:{\"start\" | \"end\"}:{timestamp}\". For example, \"0:start:3\" means a function call with function ID 0 started at the beginning of timestamp 3, and \"1:end:2\" means a function call with function ID 1 ended at the end of timestamp 2. Note that a function can be called multiple times, possibly recursively.\n A function's exclusive time is the sum of execution times for all function calls in the program. For example, if a function is called twice, one call executing for 2 time units and another call executing for 1 time unit, the exclusive time is 2 + 1 = 3.\n Return the exclusive time of each function in an array, where the value at the ith index represents the exclusive time for the function with ID i.\n \n Example 1:\n \n \n >>> exclusiveTime(n = 2, logs = [\"0:start:0\",\"1:start:2\",\"1:end:5\",\"0:end:6\"])\n >>> [3,4]\n Explanation:\n Function 0 starts at the beginning of time 0, then it executes 2 for units of time and reaches the end of time 1.\n Function 1 starts at the beginning of time 2, executes for 4 units of time, and ends at the end of time 5.\n Function 0 resumes execution at the beginning of time 6 and executes for 1 unit of time.\n So function 0 spends 2 + 1 = 3 units of total time executing, and function 1 spends 4 units of total time executing.\n \n Example 2:\n \n >>> exclusiveTime(n = 1, logs = [\"0:start:0\",\"0:start:2\",\"0:end:5\",\"0:start:6\",\"0:end:6\",\"0:end:7\"])\n >>> [8]\n Explanation:\n Function 0 starts at the beginning of time 0, executes for 2 units of time, and recursively calls itself.\n Function 0 (recursive call) starts at the beginning of time 2 and executes for 4 units of time.\n Function 0 (initial call) resumes execution then immediately calls itself again.\n Function 0 (2nd recursive call) starts at the beginning of time 6 and executes for 1 unit of time.\n Function 0 (initial call) resumes execution at the beginning of time 7 and executes for 1 unit of time.\n So function 0 spends 2 + 4 + 1 + 1 = 8 units of total time executing.\n \n Example 3:\n \n >>> exclusiveTime(n = 2, logs = [\"0:start:0\",\"0:start:2\",\"0:end:5\",\"1:start:6\",\"1:end:6\",\"0:end:7\"])\n >>> [7,1]\n Explanation:\n Function 0 starts at the beginning of time 0, executes for 2 units of time, and recursively calls itself.\n Function 0 (recursive call) starts at the beginning of time 2 and executes for 4 units of time.\n Function 0 (initial call) resumes execution then immediately calls function 1.\n Function 1 starts at the beginning of time 6, executes 1 unit of time, and ends at the end of time 6.\n Function 0 resumes execution at the beginning of time 6 and executes for 2 units of time.\n So function 0 spends 2 + 4 + 1 = 7 units of total time executing, and function 1 spends 1 unit of total time executing.\n \"\"\"\n"}
{"task_id": "average-of-levels-in-binary-tree", "prompt": "# class TreeNode:\n# def __init__(val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def averageOfLevels(root: Optional[TreeNode]) -> List[float]:\n \"\"\"\n Given the root of a binary tree, return the average value of the nodes on each level in the form of an array. Answers within 10-5 of the actual answer will be accepted.\n \n Example 1:\n \n \n >>> __init__(root = [3,9,20,null,null,15,7])\n >>> [3.00000,14.50000,11.00000]\n Explanation: The average value of nodes on level 0 is 3, on level 1 is 14.5, and on level 2 is 11.\n Hence return [3, 14.5, 11].\n \n Example 2:\n \n \n >>> __init__(root = [3,9,20,15,7])\n >>> [3.00000,14.50000,11.00000]\n \"\"\"\n"}
{"task_id": "shopping-offers", "prompt": "def shoppingOffers(price: List[int], special: List[List[int]], needs: List[int]) -> int:\n \"\"\"\n In LeetCode Store, there are n items to sell. Each item has a price. However, there are some special offers, and a special offer consists of one or more different kinds of items with a sale price.\n You are given an integer array price where price[i] is the price of the ith item, and an integer array needs where needs[i] is the number of pieces of the ith item you want to buy.\n You are also given an array special where special[i] is of size n + 1 where special[i][j] is the number of pieces of the jth item in the ith offer and special[i][n] (i.e., the last integer in the array) is the price of the ith offer.\n Return the lowest price you have to pay for exactly certain items as given, where you could make optimal use of the special offers. You are not allowed to buy more items than you want, even if that would lower the overall price. You could use any of the special offers as many times as you want.\n \n Example 1:\n \n >>> shoppingOffers(price = [2,5], special = [[3,0,5],[1,2,10]], needs = [3,2])\n >>> 14\n Explanation: There are two kinds of items, A and B. Their prices are $2 and $5 respectively.\n In special offer 1, you can pay $5 for 3A and 0B\n In special offer 2, you can pay $10 for 1A and 2B.\n You need to buy 3A and 2B, so you may pay $10 for 1A and 2B (special offer #2), and $4 for 2A.\n \n Example 2:\n \n >>> shoppingOffers(price = [2,3,4], special = [[1,1,0,4],[2,2,1,9]], needs = [1,2,1])\n >>> 11\n Explanation: The price of A is $2, and $3 for B, $4 for C.\n You may pay $4 for 1A and 1B, and $9 for 2A ,2B and 1C.\n You need to buy 1A ,2B and 1C, so you may pay $4 for 1A and 1B (special offer #1), and $3 for 1B, $4 for 1C.\n You cannot add more items, though only $9 for 2A ,2B and 1C.\n \"\"\"\n"}
{"task_id": "decode-ways-ii", "prompt": "def numDecodings(s: str) -> int:\n \"\"\"\n A message containing letters from A-Z can be encoded into numbers using the following mapping:\n \n 'A' -> \"1\"\n 'B' -> \"2\"\n ...\n 'Z' -> \"26\"\n \n To decode an encoded message, all the digits must be grouped then mapped back into letters using the reverse of the mapping above (there may be multiple ways). For example, \"11106\" can be mapped into:\n \n \"AAJF\" with the grouping (1 1 10 6)\n \"KJF\" with the grouping (11 10 6)\n \n Note that the grouping (1 11 06) is invalid because \"06\" cannot be mapped into 'F' since \"6\" is different from \"06\".\n In addition to the mapping above, an encoded message may contain the '*' character, which can represent any digit from '1' to '9' ('0' is excluded). For example, the encoded message \"1*\" may represent any of the encoded messages \"11\", \"12\", \"13\", \"14\", \"15\", \"16\", \"17\", \"18\", or \"19\". Decoding \"1*\" is equivalent to decoding any of the encoded messages it can represent.\n Given a string s consisting of digits and '*' characters, return the number of ways to decode it.\n Since the answer may be very large, return it modulo 109 + 7.\n \n Example 1:\n \n >>> numDecodings(s = \"*\")\n >>> 9\n Explanation: The encoded message can represent any of the encoded messages \"1\", \"2\", \"3\", \"4\", \"5\", \"6\", \"7\", \"8\", or \"9\".\n Each of these can be decoded to the strings \"A\", \"B\", \"C\", \"D\", \"E\", \"F\", \"G\", \"H\", and \"I\" respectively.\n Hence, there are a total of 9 ways to decode \"*\".\n \n Example 2:\n \n >>> numDecodings(s = \"1*\")\n >>> 18\n Explanation: The encoded message can represent any of the encoded messages \"11\", \"12\", \"13\", \"14\", \"15\", \"16\", \"17\", \"18\", or \"19\".\n Each of these encoded messages have 2 ways to be decoded (e.g. \"11\" can be decoded to \"AA\" or \"K\").\n Hence, there are a total of 9 * 2 = 18 ways to decode \"1*\".\n \n Example 3:\n \n >>> numDecodings(s = \"2*\")\n >>> 15\n Explanation: The encoded message can represent any of the encoded messages \"21\", \"22\", \"23\", \"24\", \"25\", \"26\", \"27\", \"28\", or \"29\".\n \"21\", \"22\", \"23\", \"24\", \"25\", and \"26\" have 2 ways of being decoded, but \"27\", \"28\", and \"29\" only have 1 way.\n Hence, there are a total of (6 * 2) + (3 * 1) = 12 + 3 = 15 ways to decode \"2*\".\n \"\"\"\n"}
{"task_id": "solve-the-equation", "prompt": "def solveEquation(equation: str) -> str:\n \"\"\"\n Solve a given equation and return the value of 'x' in the form of a string \"x=#value\". The equation contains only '+', '-' operation, the variable 'x' and its coefficient. You should return \"No solution\" if there is no solution for the equation, or \"Infinite solutions\" if there are infinite solutions for the equation.\n If there is exactly one solution for the equation, we ensure that the value of 'x' is an integer.\n \n Example 1:\n \n >>> solveEquation(equation = \"x+5-3+x=6+x-2\")\n >>> \"x=2\"\n \n Example 2:\n \n >>> solveEquation(equation = \"x=x\")\n >>> \"Infinite solutions\"\n \n Example 3:\n \n >>> solveEquation(equation = \"2x=x\")\n >>> \"x=0\"\n \"\"\"\n"}
{"task_id": "maximum-average-subarray-i", "prompt": "def findMaxAverage(nums: List[int], k: int) -> float:\n \"\"\"\n You are given an integer array nums consisting of n elements, and an integer k.\n Find a contiguous subarray whose length is equal to k that has the maximum average value and return this value. Any answer with a calculation error less than 10-5 will be accepted.\n \n Example 1:\n \n >>> findMaxAverage(nums = [1,12,-5,-6,50,3], k = 4)\n >>> 12.75000\n Explanation: Maximum average is (12 - 5 - 6 + 50) / 4 = 51 / 4 = 12.75\n \n Example 2:\n \n >>> findMaxAverage(nums = [5], k = 1)\n >>> 5.00000\n \"\"\"\n"}
{"task_id": "maximum-average-subarray-ii", "prompt": "def findMaxAverage(nums: List[int], k: int) -> float:\n \"\"\"\n You are given an integer array nums consisting of n elements, and an integer k.\n Find a contiguous subarray whose length is greater than or equal to k that has the maximum average value and return this value. Any answer with a calculation error less than 10-5 will be accepted.\n \n Example 1:\n \n >>> findMaxAverage(nums = [1,12,-5,-6,50,3], k = 4)\n >>> 12.75000\n Explanation:\n - When the length is 4, averages are [0.5, 12.75, 10.5] and the maximum average is 12.75\n - When the length is 5, averages are [10.4, 10.8] and the maximum average is 10.8\n - When the length is 6, averages are [9.16667] and the maximum average is 9.16667\n The maximum average is when we choose a subarray of length 4 (i.e., the sub array [12, -5, -6, 50]) which has the max average 12.75, so we return 12.75\n Note that we do not consider the subarrays of length < 4.\n \n Example 2:\n \n >>> findMaxAverage(nums = [5], k = 1)\n >>> 5.00000\n \"\"\"\n"}
{"task_id": "set-mismatch", "prompt": "def findErrorNums(nums: List[int]) -> List[int]:\n \"\"\"\n You have a set of integers s, which originally contains all the numbers from 1 to n. Unfortunately, due to some error, one of the numbers in s got duplicated to another number in the set, which results in repetition of one number and loss of another number.\n You are given an integer array nums representing the data status of this set after the error.\n Find the number that occurs twice and the number that is missing and return them in the form of an array.\n \n Example 1:\n >>> findErrorNums(nums = [1,2,2,4])\n >>> [2,3]\n Example 2:\n >>> findErrorNums(nums = [1,1])\n >>> [1,2]\n \"\"\"\n"}
{"task_id": "maximum-length-of-pair-chain", "prompt": "def findLongestChain(pairs: List[List[int]]) -> int:\n \"\"\"\n You are given an array of n pairs pairs where pairs[i] = [lefti, righti] and lefti < righti.\n A pair p2 = [c, d] follows a pair p1 = [a, b] if b < c. A chain of pairs can be formed in this fashion.\n Return the length longest chain which can be formed.\n You do not need to use up all the given intervals. You can select pairs in any order.\n \n Example 1:\n \n >>> findLongestChain(pairs = [[1,2],[2,3],[3,4]])\n >>> 2\n Explanation: The longest chain is [1,2] -> [3,4].\n \n Example 2:\n \n >>> findLongestChain(pairs = [[1,2],[7,8],[4,5]])\n >>> 3\n Explanation: The longest chain is [1,2] -> [4,5] -> [7,8].\n \"\"\"\n"}
{"task_id": "palindromic-substrings", "prompt": "def countSubstrings(s: str) -> int:\n \"\"\"\n Given a string s, return the number of palindromic substrings in it.\n A string is a palindrome when it reads the same backward as forward.\n A substring is a contiguous sequence of characters within the string.\n \n Example 1:\n \n >>> countSubstrings(s = \"abc\")\n >>> 3\n Explanation: Three palindromic strings: \"a\", \"b\", \"c\".\n \n Example 2:\n \n >>> countSubstrings(s = \"aaa\")\n >>> 6\n Explanation: Six palindromic strings: \"a\", \"a\", \"a\", \"aa\", \"aa\", \"aaa\".\n \"\"\"\n"}
{"task_id": "replace-words", "prompt": "def replaceWords(dictionary: List[str], sentence: str) -> str:\n \"\"\"\n In English, we have a concept called root, which can be followed by some other word to form another longer word - let's call this word derivative. For example, when the root \"help\" is followed by the word \"ful\", we can form a derivative \"helpful\".\n Given a dictionary consisting of many roots and a sentence consisting of words separated by spaces, replace all the derivatives in the sentence with the root forming it. If a derivative can be replaced by more than one root, replace it with the root that has the shortest length.\n Return the sentence after the replacement.\n \n Example 1:\n \n >>> replaceWords(dictionary = [\"cat\",\"bat\",\"rat\"], sentence = \"the cattle was rattled by the battery\")\n >>> \"the cat was rat by the bat\"\n \n Example 2:\n \n >>> replaceWords(dictionary = [\"a\",\"b\",\"c\"], sentence = \"aadsfasf absbs bbab cadsfafs\")\n >>> \"a a b c\"\n \"\"\"\n"}
{"task_id": "dota2-senate", "prompt": "def predictPartyVictory(senate: str) -> str:\n \"\"\"\n In the world of Dota2, there are two parties: the Radiant and the Dire.\n The Dota2 senate consists of senators coming from two parties. Now the Senate wants to decide on a change in the Dota2 game. The voting for this change is a round-based procedure. In each round, each senator can exercise one of the two rights:\n \n Ban one senator's right: A senator can make another senator lose all his rights in this and all the following rounds.\n Announce the victory: If this senator found the senators who still have rights to vote are all from the same party, he can announce the victory and decide on the change in the game.\n \n Given a string senate representing each senator's party belonging. The character 'R' and 'D' represent the Radiant party and the Dire party. Then if there are n senators, the size of the given string will be n.\n The round-based procedure starts from the first senator to the last senator in the given order. This procedure will last until the end of voting. All the senators who have lost their rights will be skipped during the procedure.\n Suppose every senator is smart enough and will play the best strategy for his own party. Predict which party will finally announce the victory and change the Dota2 game. The output should be \"Radiant\" or \"Dire\".\n \n Example 1:\n \n >>> predictPartyVictory(senate = \"RD\")\n >>> \"Radiant\"\n Explanation:\n The first senator comes from Radiant and he can just ban the next senator's right in round 1.\n And the second senator can't exercise any rights anymore since his right has been banned.\n And in round 2, the first senator can just announce the victory since he is the only guy in the senate who can vote.\n \n Example 2:\n \n >>> predictPartyVictory(senate = \"RDD\")\n >>> \"Dire\"\n Explanation:\n The first senator comes from Radiant and he can just ban the next senator's right in round 1.\n And the second senator can't exercise any rights anymore since his right has been banned.\n And the third senator comes from Dire and he can ban the first senator's right in round 1.\n And in round 2, the third senator can just announce the victory since he is the only guy in the senate who can vote.\n \"\"\"\n"}
{"task_id": "2-keys-keyboard", "prompt": "def minSteps(n: int) -> int:\n \"\"\"\n There is only one character 'A' on the screen of a notepad. You can perform one of two operations on this notepad for each step:\n \n Copy All: You can copy all the characters present on the screen (a partial copy is not allowed).\n Paste: You can paste the characters which are copied last time.\n \n Given an integer n, return the minimum number of operations to get the character 'A' exactly n times on the screen.\n \n Example 1:\n \n >>> minSteps(n = 3)\n >>> 3\n Explanation: Initially, we have one character 'A'.\n In step 1, we use Copy All operation.\n In step 2, we use Paste operation to get 'AA'.\n In step 3, we use Paste operation to get 'AAA'.\n \n Example 2:\n \n >>> minSteps(n = 1)\n >>> 0\n \"\"\"\n"}
{"task_id": "4-keys-keyboard", "prompt": "def maxA(n: int) -> int:\n \"\"\"\n Imagine you have a special keyboard with the following keys:\n \n A: Print one 'A' on the screen.\n Ctrl-A: Select the whole screen.\n Ctrl-C: Copy selection to buffer.\n Ctrl-V: Print buffer on screen appending it after what has already been printed.\n \n Given an integer n, return the maximum number of 'A' you can print on the screen with at most n presses on the keys.\n \n Example 1:\n \n >>> maxA(n = 3)\n >>> 3\n Explanation: We can at most get 3 A's on screen by pressing the following key sequence:\n A, A, A\n \n Example 2:\n \n >>> maxA(n = 7)\n >>> 9\n Explanation: We can at most get 9 A's on screen by pressing following key sequence:\n A, A, A, Ctrl A, Ctrl C, Ctrl V, Ctrl V\n \"\"\"\n"}
{"task_id": "two-sum-iv-input-is-a-bst", "prompt": "# class TreeNode:\n# def __init__(val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def findTarget(root: Optional[TreeNode], k: int) -> bool:\n \"\"\"\n Given the root of a binary search tree and an integer k, return true if there exist two elements in the BST such that their sum is equal to k, or false otherwise.\n \n Example 1:\n \n \n >>> __init__(root = [5,3,6,2,4,null,7], k = 9)\n >>> true\n \n Example 2:\n \n \n >>> __init__(root = [5,3,6,2,4,null,7], k = 28)\n >>> false\n \"\"\"\n"}
{"task_id": "maximum-binary-tree", "prompt": "# class TreeNode:\n# def __init__(val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def constructMaximumBinaryTree(nums: List[int]) -> Optional[TreeNode]:\n \"\"\"\n You are given an integer array nums with no duplicates. A maximum binary tree can be built recursively from nums using the following algorithm:\n \n Create a root node whose value is the maximum value in nums.\n Recursively build the left subtree on the subarray prefix to the left of the maximum value.\n Recursively build the right subtree on the subarray suffix to the right of the maximum value.\n \n Return the maximum binary tree built from nums.\n \n Example 1:\n \n \n >>> __init__(nums = [3,2,1,6,0,5])\n >>> [6,3,5,null,2,0,null,null,1]\n Explanation: The recursive calls are as follow:\n - The largest value in [3,2,1,6,0,5] is 6. Left prefix is [3,2,1] and right suffix is [0,5].\n - The largest value in [3,2,1] is 3. Left prefix is [] and right suffix is [2,1].\n - Empty array, so no child.\n - The largest value in [2,1] is 2. Left prefix is [] and right suffix is [1].\n - Empty array, so no child.\n - Only one element, so child is a node with value 1.\n - The largest value in [0,5] is 5. Left prefix is [0] and right suffix is [].\n - Only one element, so child is a node with value 0.\n - Empty array, so no child.\n \n Example 2:\n \n \n >>> __init__(nums = [3,2,1])\n >>> [3,null,2,null,1]\n \"\"\"\n"}
{"task_id": "print-binary-tree", "prompt": "# class TreeNode:\n# def __init__(val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def printTree(root: Optional[TreeNode]) -> List[List[str]]:\n \"\"\"\n Given the root of a binary tree, construct a 0-indexed m x n string matrix res that represents a formatted layout of the tree. The formatted layout matrix should be constructed using the following rules:\n \n The height of the tree is height\u00a0and the number of rows m should be equal to height + 1.\n The number of columns n should be equal to 2height+1 - 1.\n Place the root node in the middle of the top row (more formally, at location res[0][(n-1)/2]).\n For each node that has been placed in the matrix at position res[r][c], place its left child at res[r+1][c-2height-r-1] and its right child at res[r+1][c+2height-r-1].\n Continue this process until all the nodes in the tree have been placed.\n Any empty cells should contain the empty string \"\".\n \n Return the constructed matrix res.\n \n Example 1:\n \n \n >>> __init__(root = [1,2])\n >>>\n [[\"\",\"1\",\"\"],\n \u00a0[\"2\",\"\",\"\"]]\n \n Example 2:\n \n \n >>> __init__(root = [1,2,3,null,4])\n >>>\n [[\"\",\"\",\"\",\"1\",\"\",\"\",\"\"],\n \u00a0[\"\",\"2\",\"\",\"\",\"\",\"3\",\"\"],\n \u00a0[\"\",\"\",\"4\",\"\",\"\",\"\",\"\"]]\n \"\"\"\n"}
{"task_id": "coin-path", "prompt": "def cheapestJump(coins: List[int], maxJump: int) -> List[int]:\n \"\"\"\n You are given an integer array coins (1-indexed) of length n and an integer maxJump. You can jump to any index i of the array coins if coins[i] != -1 and you have to pay coins[i] when you visit index i. In addition to that, if you are currently at index i, you can only jump to any index i + k where i + k <= n and k is a value in the range [1, maxJump].\n You are initially positioned at index 1 (coins[1] is not -1). You want to find the path that reaches index n with the minimum cost.\n Return an integer array of the indices that you will visit in order so that you can reach index n with the minimum cost. If there are multiple paths with the same cost, return the lexicographically smallest such path. If it is not possible to reach index n, return an empty array.\n A path p1 = [Pa1, Pa2, ..., Pax] of length x is lexicographically smaller than p2 = [Pb1, Pb2, ..., Pbx] of length y, if and only if at the first j where Paj and Pbj differ, Paj < Pbj; when no such j exists, then x < y.\n \n Example 1:\n >>> cheapestJump(coins = [1,2,4,-1,2], maxJump = 2)\n >>> [1,3,5]\n Example 2:\n >>> cheapestJump(coins = [1,2,4,-1,2], maxJump = 1)\n >>> []\n \"\"\"\n"}
{"task_id": "robot-return-to-origin", "prompt": "def judgeCircle(moves: str) -> bool:\n \"\"\"\n There is a robot starting at the position (0, 0), the origin, on a 2D plane. Given a sequence of its moves, judge if this robot ends up at (0, 0) after it completes its moves.\n You are given a string moves that represents the move sequence of the robot where moves[i] represents its ith move. Valid moves are 'R' (right), 'L' (left), 'U' (up), and 'D' (down).\n Return true if the robot returns to the origin after it finishes all of its moves, or false otherwise.\n Note: The way that the robot is \"facing\" is irrelevant. 'R' will always make the robot move to the right once, 'L' will always make it move left, etc. Also, assume that the magnitude of the robot's movement is the same for each move.\n \n Example 1:\n \n >>> judgeCircle(moves = \"UD\")\n >>> true\n Explanation: The robot moves up once, and then down once. All moves have the same magnitude, so it ended up at the origin where it started. Therefore, we return true.\n \n Example 2:\n \n >>> judgeCircle(moves = \"LL\")\n >>> false\n Explanation: The robot moves left twice. It ends up two \"moves\" to the left of the origin. We return false because it is not at the origin at the end of its moves.\n \"\"\"\n"}
{"task_id": "find-k-closest-elements", "prompt": "def findClosestElements(arr: List[int], k: int, x: int) -> List[int]:\n \"\"\"\n Given a sorted integer array arr, two integers k and x, return the k closest integers to x in the array. The result should also be sorted in ascending order.\n An integer a is closer to x than an integer b if:\n \n |a - x| < |b - x|, or\n |a - x| == |b - x| and a < b\n \n \n Example 1:\n \n >>> findClosestElements(arr = [1,2,3,4,5], k = 4, x = 3)\n >>> [1,2,3,4]\n \n Example 2:\n \n >>> findClosestElements(arr = [1,1,2,3,4,5], k = 4, x = -1)\n >>> [1,1,2,3]\n \"\"\"\n"}
{"task_id": "split-array-into-consecutive-subsequences", "prompt": "def isPossible(nums: List[int]) -> bool:\n \"\"\"\n You are given an integer array nums that is sorted in non-decreasing order.\n Determine if it is possible to split nums into one or more subsequences such that both of the following conditions are true:\n \n Each subsequence is a consecutive increasing sequence (i.e. each integer is exactly one more than the previous integer).\n All subsequences have a length of 3 or more.\n \n Return true if you can split nums according to the above conditions, or false otherwise.\n A subsequence of an array is a new array that is formed from the original array by deleting some (can be none) of the elements without disturbing the relative positions of the remaining elements. (i.e., [1,3,5] is a subsequence of [1,2,3,4,5] while [1,3,2] is not).\n \n Example 1:\n \n >>> isPossible(nums = [1,2,3,3,4,5])\n >>> true\n Explanation: nums can be split into the following subsequences:\n [1,2,3,3,4,5] --> 1, 2, 3\n [1,2,3,3,4,5] --> 3, 4, 5\n \n Example 2:\n \n >>> isPossible(nums = [1,2,3,3,4,4,5,5])\n >>> true\n Explanation: nums can be split into the following subsequences:\n [1,2,3,3,4,4,5,5] --> 1, 2, 3, 4, 5\n [1,2,3,3,4,4,5,5] --> 3, 4, 5\n \n Example 3:\n \n >>> isPossible(nums = [1,2,3,4,4,5])\n >>> false\n Explanation: It is impossible to split nums into consecutive increasing subsequences of length 3 or more.\n \"\"\"\n"}
{"task_id": "remove-9", "prompt": "def newInteger(n: int) -> int:\n \"\"\"\n Start from integer 1, remove any integer that contains 9 such as 9, 19, 29...\n Now, you will have a new integer sequence [1, 2, 3, 4, 5, 6, 7, 8, 10, 11, ...].\n Given an integer n, return the nth (1-indexed) integer in the new sequence.\n \n Example 1:\n \n >>> newInteger(n = 9)\n >>> 10\n \n Example 2:\n \n >>> newInteger(n = 10)\n >>> 11\n \"\"\"\n"}
{"task_id": "image-smoother", "prompt": "def imageSmoother(img: List[List[int]]) -> List[List[int]]:\n \"\"\"\n An image smoother is a filter of the size 3 x 3 that can be applied to each cell of an image by rounding down the average of the cell and the eight surrounding cells (i.e., the average of the nine cells in the blue smoother). If one or more of the surrounding cells of a cell is not present, we do not consider it in the average (i.e., the average of the four cells in the red smoother).\n \n Given an m x n integer matrix img representing the grayscale of an image, return the image after applying the smoother on each cell of it.\n \n Example 1:\n \n \n >>> imageSmoother(img = [[1,1,1],[1,0,1],[1,1,1]])\n >>> [[0,0,0],[0,0,0],[0,0,0]]\n Explanation:\n For the points (0,0), (0,2), (2,0), (2,2): floor(3/4) = floor(0.75) = 0\n For the points (0,1), (1,0), (1,2), (2,1): floor(5/6) = floor(0.83333333) = 0\n For the point (1,1): floor(8/9) = floor(0.88888889) = 0\n \n Example 2:\n \n \n >>> imageSmoother(img = [[100,200,100],[200,50,200],[100,200,100]])\n >>> [[137,141,137],[141,138,141],[137,141,137]]\n Explanation:\n For the points (0,0), (0,2), (2,0), (2,2): floor((100+200+200+50)/4) = floor(137.5) = 137\n For the points (0,1), (1,0), (1,2), (2,1): floor((200+200+50+200+100+100)/6) = floor(141.666667) = 141\n For the point (1,1): floor((50+200+200+200+200+100+100+100+100)/9) = floor(138.888889) = 138\n \"\"\"\n"}
{"task_id": "maximum-width-of-binary-tree", "prompt": "# class TreeNode:\n# def __init__(val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def widthOfBinaryTree(root: Optional[TreeNode]) -> int:\n \"\"\"\n Given the root of a binary tree, return the maximum width of the given tree.\n The maximum width of a tree is the maximum width among all levels.\n The width of one level is defined as the length between the end-nodes (the leftmost and rightmost non-null nodes), where the null nodes between the end-nodes that would be present in a complete binary tree extending down to that level are also counted into the length calculation.\n It is guaranteed that the answer will in the range of a 32-bit signed integer.\n \n Example 1:\n \n \n >>> __init__(root = [1,3,2,5,3,null,9])\n >>> 4\n Explanation: The maximum width exists in the third level with length 4 (5,3,null,9).\n \n Example 2:\n \n \n >>> __init__(root = [1,3,2,5,null,null,9,6,null,7])\n >>> 7\n Explanation: The maximum width exists in the fourth level with length 7 (6,null,null,null,null,null,7).\n \n Example 3:\n \n \n >>> __init__(root = [1,3,2,5])\n >>> 2\n Explanation: The maximum width exists in the second level with length 2 (3,2).\n \"\"\"\n"}
{"task_id": "equal-tree-partition", "prompt": "# class TreeNode:\n# def __init__(val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def checkEqualTree(root: Optional[TreeNode]) -> bool:\n \"\"\"\n Given the root of a binary tree, return true if you can partition the tree into two trees with equal sums of values after removing exactly one edge on the original tree.\n \n Example 1:\n \n \n >>> __init__(root = [5,10,10,null,null,2,3])\n >>> true\n \n Example 2:\n \n \n >>> __init__(root = [1,2,10,null,null,2,20])\n >>> false\n Explanation: You cannot split the tree into two trees with equal sums after removing exactly one edge on the tree.\n \"\"\"\n"}
{"task_id": "strange-printer", "prompt": "def strangePrinter(s: str) -> int:\n \"\"\"\n There is a strange printer with the following two special properties:\n \n The printer can only print a sequence of the same character each time.\n At each turn, the printer can print new characters starting from and ending at any place and will cover the original existing characters.\n \n Given a string s, return the minimum number of turns the printer needed to print it.\n \n Example 1:\n \n >>> strangePrinter(s = \"aaabbb\")\n >>> 2\n Explanation: Print \"aaa\" first and then print \"bbb\".\n \n Example 2:\n \n >>> strangePrinter(s = \"aba\")\n >>> 2\n Explanation: Print \"aaa\" first and then print \"b\" from the second place of the string, which will cover the existing character 'a'.\n \"\"\"\n"}
{"task_id": "non-decreasing-array", "prompt": "def checkPossibility(nums: List[int]) -> bool:\n \"\"\"\n Given an array nums with n integers, your task is to check if it could become non-decreasing by modifying at most one element.\n We define an array is non-decreasing if nums[i] <= nums[i + 1] holds for every i (0-based) such that (0 <= i <= n - 2).\n \n Example 1:\n \n >>> checkPossibility(nums = [4,2,3])\n >>> true\n Explanation: You could modify the first 4 to 1 to get a non-decreasing array.\n \n Example 2:\n \n >>> checkPossibility(nums = [4,2,1])\n >>> false\n Explanation: You cannot get a non-decreasing array by modifying at most one element.\n \"\"\"\n"}
{"task_id": "path-sum-iv", "prompt": "def pathSum(nums: List[int]) -> int:\n \"\"\"\n If the depth of a tree is smaller than 5, then this tree can be represented by an array of three-digit integers. You are given an ascending array nums consisting of three-digit integers representing a binary tree with a depth smaller than 5, where for each integer:\n \n The hundreds digit represents the depth d of this node, where 1 <= d <= 4.\n The tens digit represents the position p of this node within its level, where 1 <= p <= 8, corresponding to its position in a full binary tree.\n The units digit represents the value v of this node, where 0 <= v <= 9.\n \n Return the sum of all paths from the root towards the leaves.\n It is guaranteed that the given array represents a valid connected binary tree.\n \n Example 1:\n \n \n >>> pathSum(nums = [113,215,221])\n >>> 12\n Explanation:\n The tree that the list represents is shown.\n The path sum is (3 + 5) + (3 + 1) = 12.\n \n Example 2:\n \n \n >>> pathSum(nums = [113,221])\n >>> 4\n Explanation:\n The tree that the list represents is shown.\n The path sum is (3 + 1) = 4.\n \"\"\"\n"}
{"task_id": "beautiful-arrangement-ii", "prompt": "def constructArray(n: int, k: int) -> List[int]:\n \"\"\"\n Given two integers n and k, construct a list answer that contains n different positive integers ranging from 1 to n and obeys the following requirement:\n \n Suppose this list is answer =\u00a0[a1, a2, a3, ... , an], then the list [|a1 - a2|, |a2 - a3|, |a3 - a4|, ... , |an-1 - an|] has exactly k distinct integers.\n \n Return the list answer. If there multiple valid answers, return any of them.\n \n Example 1:\n \n >>> constructArray(n = 3, k = 1)\n >>> [1,2,3]\n Explanation: The [1,2,3] has three different positive integers ranging from 1 to 3, and the [1,1] has exactly 1 distinct integer: 1\n \n Example 2:\n \n >>> constructArray(n = 3, k = 2)\n >>> [1,3,2]\n Explanation: The [1,3,2] has three different positive integers ranging from 1 to 3, and the [2,1] has exactly 2 distinct integers: 1 and 2.\n \"\"\"\n"}
{"task_id": "kth-smallest-number-in-multiplication-table", "prompt": "def findKthNumber(m: int, n: int, k: int) -> int:\n \"\"\"\n Nearly everyone has used the Multiplication Table. The multiplication table of size m x n is an integer matrix mat where mat[i][j] == i * j (1-indexed).\n Given three integers m, n, and k, return the kth smallest element in the m x n multiplication table.\n \n Example 1:\n \n \n >>> findKthNumber(m = 3, n = 3, k = 5)\n >>> 3\n Explanation: The 5th smallest number is 3.\n \n Example 2:\n \n \n >>> findKthNumber(m = 2, n = 3, k = 6)\n >>> 6\n Explanation: The 6th smallest number is 6.\n \"\"\"\n"}
{"task_id": "trim-a-binary-search-tree", "prompt": "# class TreeNode:\n# def __init__(val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def trimBST(root: Optional[TreeNode], low: int, high: int) -> Optional[TreeNode]:\n \"\"\"\n Given the root of a binary search tree and the lowest and highest boundaries as low and high, trim the tree so that all its elements lies in [low, high]. Trimming the tree should not change the relative structure of the elements that will remain in the tree (i.e., any node's descendant should remain a descendant). It can be proven that there is a unique answer.\n Return the root of the trimmed binary search tree. Note that the root may change depending on the given bounds.\n \n Example 1:\n \n \n >>> __init__(root = [1,0,2], low = 1, high = 2)\n >>> [1,null,2]\n \n Example 2:\n \n \n >>> __init__(root = [3,0,4,null,2,null,null,1], low = 1, high = 3)\n >>> [3,2,null,1]\n \"\"\"\n"}
{"task_id": "maximum-swap", "prompt": "def maximumSwap(num: int) -> int:\n \"\"\"\n You are given an integer num. You can swap two digits at most once to get the maximum valued number.\n Return the maximum valued number you can get.\n \n Example 1:\n \n >>> maximumSwap(num = 2736)\n >>> 7236\n Explanation: Swap the number 2 and the number 7.\n \n Example 2:\n \n >>> maximumSwap(num = 9973)\n >>> 9973\n Explanation: No swap.\n \"\"\"\n"}
{"task_id": "second-minimum-node-in-a-binary-tree", "prompt": "# class TreeNode:\n# def __init__(val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def findSecondMinimumValue(root: Optional[TreeNode]) -> int:\n \"\"\"\n Given a non-empty special binary tree consisting of nodes with the non-negative value, where each node in this tree has exactly two or zero sub-node. If the node has two sub-nodes, then this node's value is the smaller value among its two sub-nodes. More formally, the property\u00a0root.val = min(root.left.val, root.right.val)\u00a0always holds.\n Given such a binary tree, you need to output the second minimum value in the set made of all the nodes' value in the whole tree.\n If no such second minimum value exists, output -1 instead.\n \n \n Example 1:\n \n \n >>> __init__(root = [2,2,5,null,null,5,7])\n >>> 5\n Explanation: The smallest value is 2, the second smallest value is 5.\n \n Example 2:\n \n \n >>> __init__(root = [2,2,2])\n >>> -1\n Explanation: The smallest value is 2, but there isn't any second smallest value.\n \"\"\"\n"}
{"task_id": "bulb-switcher-ii", "prompt": "def flipLights(n: int, presses: int) -> int:\n \"\"\"\n There is a room with n bulbs labeled from 1 to n that all are turned on initially, and four buttons on the wall. Each of the four buttons has a different functionality where:\n \n Button 1: Flips the status of all the bulbs.\n Button 2: Flips the status of all the bulbs with even labels (i.e., 2, 4, ...).\n Button 3: Flips the status of all the bulbs with odd labels (i.e., 1, 3, ...).\n Button 4: Flips the status of all the bulbs with a label j = 3k + 1 where k = 0, 1, 2, ... (i.e., 1, 4, 7, 10, ...).\n \n You must make exactly presses button presses in total. For each press, you may pick any of the four buttons to press.\n Given the two integers n and presses, return the number of different possible statuses after performing all presses button presses.\n \n Example 1:\n \n >>> flipLights(n = 1, presses = 1)\n >>> 2\n Explanation: Status can be:\n - [off] by pressing button 1\n - [on] by pressing button 2\n \n Example 2:\n \n >>> flipLights(n = 2, presses = 1)\n >>> 3\n Explanation: Status can be:\n - [off, off] by pressing button 1\n - [on, off] by pressing button 2\n - [off, on] by pressing button 3\n \n Example 3:\n \n >>> flipLights(n = 3, presses = 1)\n >>> 4\n Explanation: Status can be:\n - [off, off, off] by pressing button 1\n - [off, on, off] by pressing button 2\n - [on, off, on] by pressing button 3\n - [off, on, on] by pressing button 4\n \"\"\"\n"}
{"task_id": "number-of-longest-increasing-subsequence", "prompt": "def findNumberOfLIS(nums: List[int]) -> int:\n \"\"\"\n Given an integer array\u00a0nums, return the number of longest increasing subsequences.\n Notice that the sequence has to be strictly increasing.\n \n Example 1:\n \n >>> findNumberOfLIS(nums = [1,3,5,4,7])\n >>> 2\n Explanation: The two longest increasing subsequences are [1, 3, 4, 7] and [1, 3, 5, 7].\n \n Example 2:\n \n >>> findNumberOfLIS(nums = [2,2,2,2,2])\n >>> 5\n Explanation: The length of the longest increasing subsequence is 1, and there are 5 increasing subsequences of length 1, so output 5.\n \"\"\"\n"}
{"task_id": "longest-continuous-increasing-subsequence", "prompt": "def findLengthOfLCIS(nums: List[int]) -> int:\n \"\"\"\n Given an unsorted array of integers nums, return the length of the longest continuous increasing subsequence (i.e. subarray). The subsequence must be strictly increasing.\n A continuous increasing subsequence is defined by two indices l and r (l < r) such that it is [nums[l], nums[l + 1], ..., nums[r - 1], nums[r]] and for each l <= i < r, nums[i] < nums[i + 1].\n \n Example 1:\n \n >>> findLengthOfLCIS(nums = [1,3,5,4,7])\n >>> 3\n Explanation: The longest continuous increasing subsequence is [1,3,5] with length 3.\n Even though [1,3,5,7] is an increasing subsequence, it is not continuous as elements 5 and 7 are separated by element\n 4.\n \n Example 2:\n \n >>> findLengthOfLCIS(nums = [2,2,2,2,2])\n >>> 1\n Explanation: The longest continuous increasing subsequence is [2] with length 1. Note that it must be strictly\n increasing.\n \"\"\"\n"}
{"task_id": "cut-off-trees-for-golf-event", "prompt": "def cutOffTree(forest: List[List[int]]) -> int:\n \"\"\"\n You are asked to cut off all the trees in a forest for a golf event. The forest is represented as an m x n matrix. In this matrix:\n \n 0 means the cell cannot be walked through.\n 1 represents an empty cell that can be walked through.\n A number greater than 1 represents a tree in a cell that can be walked through, and this number is the tree's height.\n \n In one step, you can walk in any of the four directions: north, east, south, and west. If you are standing in a cell with a tree, you can choose whether to cut it off.\n You must cut off the trees in order from shortest to tallest. When you cut off a tree, the value at its cell becomes 1 (an empty cell).\n Starting from the point (0, 0), return the minimum steps you need to walk to cut off all the trees. If you cannot cut off all the trees, return -1.\n Note: The input is generated such that no two trees have the same height, and there is at least one tree needs to be cut off.\n \n Example 1:\n \n \n >>> cutOffTree(forest = [[1,2,3],[0,0,4],[7,6,5]])\n >>> 6\n Explanation: Following the path above allows you to cut off the trees from shortest to tallest in 6 steps.\n \n Example 2:\n \n \n >>> cutOffTree(forest = [[1,2,3],[0,0,0],[7,6,5]])\n >>> -1\n Explanation: The trees in the bottom row cannot be accessed as the middle row is blocked.\n \n Example 3:\n \n >>> cutOffTree(forest = [[2,3,4],[0,0,5],[8,7,6]])\n >>> 6\n Explanation: You can follow the same path as Example 1 to cut off all the trees.\n Note that you can cut off the first tree at (0, 0) before making any steps.\n \"\"\"\n"}
{"task_id": "valid-parenthesis-string", "prompt": "def checkValidString(s: str) -> bool:\n \"\"\"\n Given a string s containing only three types of characters: '(', ')' and '*', return true if s is valid.\n The following rules define a valid string:\n \n Any left parenthesis '(' must have a corresponding right parenthesis ')'.\n Any right parenthesis ')' must have a corresponding left parenthesis '('.\n Left parenthesis '(' must go before the corresponding right parenthesis ')'.\n '*' could be treated as a single right parenthesis ')' or a single left parenthesis '(' or an empty string \"\".\n \n \n Example 1:\n >>> checkValidString(s = \"()\")\n >>> true\n Example 2:\n >>> checkValidString(s = \"(*)\")\n >>> true\n Example 3:\n >>> checkValidString(s = \"(*))\")\n >>> true\n \"\"\"\n"}
{"task_id": "24-game", "prompt": "def judgePoint24(cards: List[int]) -> bool:\n \"\"\"\n You are given an integer array cards of length 4. You have four cards, each containing a number in the range [1, 9]. You should arrange the numbers on these cards in a mathematical expression using the operators ['+', '-', '*', '/'] and the parentheses '(' and ')' to get the value 24.\n You are restricted with the following rules:\n \n The division operator '/' represents real division, not integer division.\n \n \n For example, 4 / (1 - 2 / 3) = 4 / (1 / 3) = 12.\n \n \n Every operation done is between two numbers. In particular, we cannot use '-' as a unary operator.\n \n For example, if cards = [1, 1, 1, 1], the expression \"-1 - 1 - 1 - 1\" is not allowed.\n \n \n You cannot concatenate numbers together\n \n For example, if cards = [1, 2, 1, 2], the expression \"12 + 12\" is not valid.\n \n \n \n Return true if you can get such expression that evaluates to 24, and false otherwise.\n \n Example 1:\n \n >>> judgePoint24(cards = [4,1,8,7])\n >>> true\n Explanation: (8-4) * (7-1) = 24\n \n Example 2:\n \n >>> judgePoint24(cards = [1,2,1,2])\n >>> false\n \"\"\"\n"}
{"task_id": "valid-palindrome-ii", "prompt": "def validPalindrome(s: str) -> bool:\n \"\"\"\n Given a string s, return true if the s can be palindrome after deleting at most one character from it.\n \n Example 1:\n \n >>> validPalindrome(s = \"aba\")\n >>> true\n \n Example 2:\n \n >>> validPalindrome(s = \"abca\")\n >>> true\n Explanation: You could delete the character 'c'.\n \n Example 3:\n \n >>> validPalindrome(s = \"abc\")\n >>> false\n \"\"\"\n"}
{"task_id": "next-closest-time", "prompt": "def nextClosestTime(time: str) -> str:\n \"\"\"\n Given a time represented in the format \"HH:MM\", form the next closest time by reusing the current digits. There is no limit on how many times a digit can be reused.\n You may assume the given input string is always valid. For example, \"01:34\", \"12:09\" are all valid. \"1:34\", \"12:9\" are all invalid.\n \n Example 1:\n \n >>> nextClosestTime(time = \"19:34\")\n >>> \"19:39\"\n Explanation: The next closest time choosing from digits 1, 9, 3, 4, is 19:39, which occurs 5 minutes later.\n It is not 19:33, because this occurs 23 hours and 59 minutes later.\n \n Example 2:\n \n >>> nextClosestTime(time = \"23:59\")\n >>> \"22:22\"\n Explanation: The next closest time choosing from digits 2, 3, 5, 9, is 22:22.\n It may be assumed that the returned time is next day's time since it is smaller than the input time numerically.\n \"\"\"\n"}
{"task_id": "baseball-game", "prompt": "def calPoints(operations: List[str]) -> int:\n \"\"\"\n You are keeping the scores for a baseball game with strange rules. At the beginning of the game, you start with an empty record.\n You are given a list of strings operations, where operations[i] is the ith operation you must apply to the record and is one of the following:\n \n An integer x.\n \n \n Record a new score of x.\n \n \n '+'.\n \n Record a new score that is the sum of the previous two scores.\n \n \n 'D'.\n \n Record a new score that is the double of the previous score.\n \n \n 'C'.\n \n Invalidate the previous score, removing it from the record.\n \n \n \n Return the sum of all the scores on the record after applying all the operations.\n The test cases are generated such that the answer and all intermediate calculations fit in a 32-bit integer and that all operations are valid.\n \n Example 1:\n \n >>> calPoints(ops = [\"5\",\"2\",\"C\",\"D\",\"+\"])\n >>> 30\n Explanation:\n \"5\" - Add 5 to the record, record is now [5].\n \"2\" - Add 2 to the record, record is now [5, 2].\n \"C\" - Invalidate and remove the previous score, record is now [5].\n \"D\" - Add 2 * 5 = 10 to the record, record is now [5, 10].\n \"+\" - Add 5 + 10 = 15 to the record, record is now [5, 10, 15].\n The total sum is 5 + 10 + 15 = 30.\n \n Example 2:\n \n >>> calPoints(ops = [\"5\",\"-2\",\"4\",\"C\",\"D\",\"9\",\"+\",\"+\"])\n >>> 27\n Explanation:\n \"5\" - Add 5 to the record, record is now [5].\n \"-2\" - Add -2 to the record, record is now [5, -2].\n \"4\" - Add 4 to the record, record is now [5, -2, 4].\n \"C\" - Invalidate and remove the previous score, record is now [5, -2].\n \"D\" - Add 2 * -2 = -4 to the record, record is now [5, -2, -4].\n \"9\" - Add 9 to the record, record is now [5, -2, -4, 9].\n \"+\" - Add -4 + 9 = 5 to the record, record is now [5, -2, -4, 9, 5].\n \"+\" - Add 9 + 5 = 14 to the record, record is now [5, -2, -4, 9, 5, 14].\n The total sum is 5 + -2 + -4 + 9 + 5 + 14 = 27.\n \n Example 3:\n \n >>> calPoints(ops = [\"1\",\"C\"])\n >>> 0\n Explanation:\n \"1\" - Add 1 to the record, record is now [1].\n \"C\" - Invalidate and remove the previous score, record is now [].\n Since the record is empty, the total sum is 0.\n \"\"\"\n"}
{"task_id": "k-empty-slots", "prompt": "def kEmptySlots(bulbs: List[int], k: int) -> int:\n \"\"\"\n You have n bulbs in a row numbered from 1 to n. Initially, all the bulbs are turned off. We turn on exactly one bulb every day until all bulbs are on after n days.\n You are given an array bulbs\u00a0of length n\u00a0where bulbs[i] = x means that on the (i+1)th day, we will turn on the bulb at position x\u00a0where\u00a0i\u00a0is\u00a00-indexed\u00a0and\u00a0x\u00a0is\u00a01-indexed.\n Given an integer k, return\u00a0the minimum day number such that there exists two turned on bulbs that have exactly\u00a0k bulbs between them that are all turned off. If there isn't such day, return -1.\n \n Example 1:\n \n >>> kEmptySlots(bulbs = [1,3,2], k = 1)\n >>> 2\n Explanation:\n On the first day: bulbs[0] = 1, first bulb is turned on: [1,0,0]\n On the second day: bulbs[1] = 3, third bulb is turned on: [1,0,1]\n On the third day: bulbs[2] = 2, second bulb is turned on: [1,1,1]\n We return 2 because on the second day, there were two on bulbs with one off bulb between them.\n Example 2:\n \n >>> kEmptySlots(bulbs = [1,2,3], k = 1)\n >>> -1\n \"\"\"\n"}
{"task_id": "redundant-connection", "prompt": "def findRedundantConnection(edges: List[List[int]]) -> List[int]:\n \"\"\"\n In this problem, a tree is an undirected graph that is connected and has no cycles.\n You are given a graph that started as a tree with n nodes labeled from 1 to n, with one additional edge added. The added edge has two different vertices chosen from 1 to n, and was not an edge that already existed. The graph is represented as an array edges of length n where edges[i] = [ai, bi] indicates that there is an edge between nodes ai and bi in the graph.\n Return an edge that can be removed so that the resulting graph is a tree of n nodes. If there are multiple answers, return the answer that occurs last in the input.\n \n Example 1:\n \n \n >>> findRedundantConnection(edges = [[1,2],[1,3],[2,3]])\n >>> [2,3]\n \n Example 2:\n \n \n >>> findRedundantConnection(edges = [[1,2],[2,3],[3,4],[1,4],[1,5]])\n >>> [1,4]\n \"\"\"\n"}
{"task_id": "redundant-connection-ii", "prompt": "def findRedundantDirectedConnection(edges: List[List[int]]) -> List[int]:\n \"\"\"\n In this problem, a rooted tree is a directed graph such that, there is exactly one node (the root) for which all other nodes are descendants of this node, plus every node has exactly one parent, except for the root node which has no parents.\n The given input is a directed graph that started as a rooted tree with n nodes (with distinct values from 1 to n), with one additional directed edge added. The added edge has two different vertices chosen from 1 to n, and was not an edge that already existed.\n The resulting graph is given as a 2D-array of edges. Each element of edges is a pair [ui, vi] that represents a directed edge connecting nodes ui and vi, where ui is a parent of child vi.\n Return an edge that can be removed so that the resulting graph is a rooted tree of n nodes. If there are multiple answers, return the answer that occurs last in the given 2D-array.\n \n Example 1:\n \n \n >>> findRedundantDirectedConnection(edges = [[1,2],[1,3],[2,3]])\n >>> [2,3]\n \n Example 2:\n \n \n >>> findRedundantDirectedConnection(edges = [[1,2],[2,3],[3,4],[4,1],[1,5]])\n >>> [4,1]\n \"\"\"\n"}
{"task_id": "repeated-string-match", "prompt": "def repeatedStringMatch(a: str, b: str) -> int:\n \"\"\"\n Given two strings a and b, return the minimum number of times you should repeat string a so that string b is a substring of it. If it is impossible for b\u200b\u200b\u200b\u200b\u200b\u200b to be a substring of a after repeating it, return -1.\n Notice: string \"abc\" repeated 0 times is \"\", repeated 1 time is \"abc\" and repeated 2 times is \"abcabc\".\n \n Example 1:\n \n >>> repeatedStringMatch(a = \"abcd\", b = \"cdabcdab\")\n >>> 3\n Explanation: We return 3 because by repeating a three times \"abcdabcdabcd\", b is a substring of it.\n \n Example 2:\n \n >>> repeatedStringMatch(a = \"a\", b = \"aa\")\n >>> 2\n \"\"\"\n"}
{"task_id": "longest-univalue-path", "prompt": "# class TreeNode:\n# def __init__(val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def longestUnivaluePath(root: Optional[TreeNode]) -> int:\n \"\"\"\n Given the root of a binary tree, return the length of the longest path, where each node in the path has the same value. This path may or may not pass through the root.\n The length of the path between two nodes is represented by the number of edges between them.\n \n Example 1:\n \n \n >>> __init__(root = [5,4,5,1,1,null,5])\n >>> 2\n Explanation: The shown image shows that the longest path of the same value (i.e. 5).\n \n Example 2:\n \n \n >>> __init__(root = [1,4,5,4,4,null,5])\n >>> 2\n Explanation: The shown image shows that the longest path of the same value (i.e. 4).\n \"\"\"\n"}
{"task_id": "knight-probability-in-chessboard", "prompt": "def knightProbability(n: int, k: int, row: int, column: int) -> float:\n \"\"\"\n On an n x n chessboard, a knight starts at the cell (row, column) and attempts to make exactly k moves. The rows and columns are 0-indexed, so the top-left cell is (0, 0), and the bottom-right cell is (n - 1, n - 1).\n A chess knight has eight possible moves it can make, as illustrated below. Each move is two cells in a cardinal direction, then one cell in an orthogonal direction.\n \n Each time the knight is to move, it chooses one of eight possible moves uniformly at random (even if the piece would go off the chessboard) and moves there.\n The knight continues moving until it has made exactly k moves or has moved off the chessboard.\n Return the probability that the knight remains on the board after it has stopped moving.\n \n Example 1:\n \n >>> knightProbability(n = 3, k = 2, row = 0, column = 0)\n >>> 0.06250\n Explanation: There are two moves (to (1,2), (2,1)) that will keep the knight on the board.\n From each of those positions, there are also two moves that will keep the knight on the board.\n The total probability the knight stays on the board is 0.0625.\n \n Example 2:\n \n >>> knightProbability(n = 1, k = 0, row = 0, column = 0)\n >>> 1.00000\n \"\"\"\n"}
{"task_id": "maximum-sum-of-3-non-overlapping-subarrays", "prompt": "def maxSumOfThreeSubarrays(nums: List[int], k: int) -> List[int]:\n \"\"\"\n Given an integer array nums and an integer k, find three non-overlapping subarrays of length k with maximum sum and return them.\n Return the result as a list of indices representing the starting position of each interval (0-indexed). If there are multiple answers, return the lexicographically smallest one.\n \n Example 1:\n \n >>> maxSumOfThreeSubarrays(nums = [1,2,1,2,6,7,5,1], k = 2)\n >>> [0,3,5]\n Explanation: Subarrays [1, 2], [2, 6], [7, 5] correspond to the starting indices [0, 3, 5].\n We could have also taken [2, 1], but an answer of [1, 3, 5] would be lexicographically smaller.\n \n Example 2:\n \n >>> maxSumOfThreeSubarrays(nums = [1,2,1,2,1,2,1,2,1], k = 2)\n >>> [0,2,4]\n \"\"\"\n"}
{"task_id": "stickers-to-spell-word", "prompt": "def minStickers(stickers: List[str], target: str) -> int:\n \"\"\"\n We are given n different types of stickers. Each sticker has a lowercase English word on it.\n You would like to spell out the given string target by cutting individual letters from your collection of stickers and rearranging them. You can use each sticker more than once if you want, and you have infinite quantities of each sticker.\n Return the minimum number of stickers that you need to spell out target. If the task is impossible, return -1.\n Note: In all test cases, all words were chosen randomly from the 1000 most common US English words, and target was chosen as a concatenation of two random words.\n \n Example 1:\n \n >>> minStickers(stickers = [\"with\",\"example\",\"science\"], target = \"thehat\")\n >>> 3\n Explanation:\n We can use 2 \"with\" stickers, and 1 \"example\" sticker.\n After cutting and rearrange the letters of those stickers, we can form the target \"thehat\".\n Also, this is the minimum number of stickers necessary to form the target string.\n \n Example 2:\n \n >>> minStickers(stickers = [\"notice\",\"possible\"], target = \"basicbasic\")\n >>> -1\n Explanation:\n We cannot form the target \"basicbasic\" from cutting letters from the given stickers.\n \"\"\"\n"}
{"task_id": "top-k-frequent-words", "prompt": "def topKFrequent(words: List[str], k: int) -> List[str]:\n \"\"\"\n Given an array of strings words and an integer k, return the k most frequent strings.\n Return the answer sorted by the frequency from highest to lowest. Sort the words with the same frequency by their lexicographical order.\n \n Example 1:\n \n >>> topKFrequent(words = [\"i\",\"love\",\"leetcode\",\"i\",\"love\",\"coding\"], k = 2)\n >>> [\"i\",\"love\"]\n Explanation: \"i\" and \"love\" are the two most frequent words.\n Note that \"i\" comes before \"love\" due to a lower alphabetical order.\n \n Example 2:\n \n >>> topKFrequent(words = [\"the\",\"day\",\"is\",\"sunny\",\"the\",\"the\",\"the\",\"sunny\",\"is\",\"is\"], k = 4)\n >>> [\"the\",\"is\",\"sunny\",\"day\"]\n Explanation: \"the\", \"is\", \"sunny\" and \"day\" are the four most frequent words, with the number of occurrence being 4, 3, 2 and 1 respectively.\n \"\"\"\n"}
{"task_id": "binary-number-with-alternating-bits", "prompt": "def hasAlternatingBits(n: int) -> bool:\n \"\"\"\n Given a positive integer, check whether it has alternating bits: namely, if two adjacent bits will always have different values.\n \n Example 1:\n \n >>> hasAlternatingBits(n = 5)\n >>> true\n Explanation: The binary representation of 5 is: 101\n \n Example 2:\n \n >>> hasAlternatingBits(n = 7)\n >>> false\n Explanation: The binary representation of 7 is: 111.\n Example 3:\n \n >>> hasAlternatingBits(n = 11)\n >>> false\n Explanation: The binary representation of 11 is: 1011.\n \"\"\"\n"}
{"task_id": "number-of-distinct-islands", "prompt": "def numDistinctIslands(grid: List[List[int]]) -> int:\n \"\"\"\n You are given an m x n binary matrix grid. An island is a group of 1's (representing land) connected 4-directionally (horizontal or vertical.) You may assume all four edges of the grid are surrounded by water.\n An island is considered to be the same as another if and only if one island can be translated (and not rotated or reflected) to equal the other.\n Return the number of distinct islands.\n \n Example 1:\n \n \n >>> numDistinctIslands(grid = [[1,1,0,0,0],[1,1,0,0,0],[0,0,0,1,1],[0,0,0,1,1]])\n >>> 1\n \n Example 2:\n \n \n >>> numDistinctIslands(grid = [[1,1,0,1,1],[1,0,0,0,0],[0,0,0,0,1],[1,1,0,1,1]])\n >>> 3\n \"\"\"\n"}
{"task_id": "max-area-of-island", "prompt": "def maxAreaOfIsland(grid: List[List[int]]) -> int:\n \"\"\"\n You are given an m x n binary matrix grid. An island is a group of 1's (representing land) connected 4-directionally (horizontal or vertical.) You may assume all four edges of the grid are surrounded by water.\n The area of an island is the number of cells with a value 1 in the island.\n Return the maximum area of an island in grid. If there is no island, return 0.\n \n Example 1:\n \n \n >>> maxAreaOfIsland(grid = [[0,0,1,0,0,0,0,1,0,0,0,0,0],[0,0,0,0,0,0,0,1,1,1,0,0,0],[0,1,1,0,1,0,0,0,0,0,0,0,0],[0,1,0,0,1,1,0,0,1,0,1,0,0],[0,1,0,0,1,1,0,0,1,1,1,0,0],[0,0,0,0,0,0,0,0,0,0,1,0,0],[0,0,0,0,0,0,0,1,1,1,0,0,0],[0,0,0,0,0,0,0,1,1,0,0,0,0]])\n >>> 6\n Explanation: The answer is not 11, because the island must be connected 4-directionally.\n \n Example 2:\n \n >>> maxAreaOfIsland(grid = [[0,0,0,0,0,0,0,0]])\n >>> 0\n \"\"\"\n"}
{"task_id": "count-binary-substrings", "prompt": "def countBinarySubstrings(s: str) -> int:\n \"\"\"\n Given a binary string s, return the number of non-empty substrings that have the same number of 0's and 1's, and all the 0's and all the 1's in these substrings are grouped consecutively.\n Substrings that occur multiple times are counted the number of times they occur.\n \n Example 1:\n \n >>> countBinarySubstrings(s = \"00110011\")\n >>> 6\n Explanation: There are 6 substrings that have equal number of consecutive 1's and 0's: \"0011\", \"01\", \"1100\", \"10\", \"0011\", and \"01\".\n Notice that some of these substrings repeat and are counted the number of times they occur.\n Also, \"00110011\" is not a valid substring because all the 0's (and 1's) are not grouped together.\n \n Example 2:\n \n >>> countBinarySubstrings(s = \"10101\")\n >>> 4\n Explanation: There are 4 substrings: \"10\", \"01\", \"10\", \"01\" that have equal number of consecutive 1's and 0's.\n \"\"\"\n"}
{"task_id": "degree-of-an-array", "prompt": "def findShortestSubArray(nums: List[int]) -> int:\n \"\"\"\n Given a non-empty array of non-negative integers nums, the degree of this array is defined as the maximum frequency of any one of its elements.\n Your task is to find the smallest possible length of a (contiguous) subarray of nums, that has the same degree as nums.\n \n Example 1:\n \n >>> findShortestSubArray(nums = [1,2,2,3,1])\n >>> 2\n Explanation:\n The input array has a degree of 2 because both elements 1 and 2 appear twice.\n Of the subarrays that have the same degree:\n [1, 2, 2, 3, 1], [1, 2, 2, 3], [2, 2, 3, 1], [1, 2, 2], [2, 2, 3], [2, 2]\n The shortest length is 2. So return 2.\n \n Example 2:\n \n >>> findShortestSubArray(nums = [1,2,2,3,1,4,2])\n >>> 6\n Explanation:\n The degree is 3 because the element 2 is repeated 3 times.\n So [2,2,3,1,4,2] is the shortest subarray, therefore returning 6.\n \"\"\"\n"}
{"task_id": "partition-to-k-equal-sum-subsets", "prompt": "def canPartitionKSubsets(nums: List[int], k: int) -> bool:\n \"\"\"\n Given an integer array nums and an integer k, return true if it is possible to divide this array into k non-empty subsets whose sums are all equal.\n \n Example 1:\n \n >>> canPartitionKSubsets(nums = [4,3,2,3,5,2,1], k = 4)\n >>> true\n Explanation: It is possible to divide it into 4 subsets (5), (1, 4), (2,3), (2,3) with equal sums.\n \n Example 2:\n \n >>> canPartitionKSubsets(nums = [1,2,3,4], k = 3)\n >>> false\n \"\"\"\n"}
{"task_id": "falling-squares", "prompt": "def fallingSquares(positions: List[List[int]]) -> List[int]:\n \"\"\"\n There are several squares being dropped onto the X-axis of a 2D plane.\n You are given a 2D integer array positions where positions[i] = [lefti, sideLengthi] represents the ith square with a side length of sideLengthi that is dropped with its left edge aligned with X-coordinate lefti.\n Each square is dropped one at a time from a height above any landed squares. It then falls downward (negative Y direction) until it either lands on the top side of another square or on the X-axis. A square brushing the left/right side of another square does not count as landing on it. Once it lands, it freezes in place and cannot be moved.\n After each square is dropped, you must record the height of the current tallest stack of squares.\n Return an integer array ans where ans[i] represents the height described above after dropping the ith square.\n \n Example 1:\n \n \n >>> fallingSquares(positions = [[1,2],[2,3],[6,1]])\n >>> [2,5,5]\n Explanation:\n After the first drop, the tallest stack is square 1 with a height of 2.\n After the second drop, the tallest stack is squares 1 and 2 with a height of 5.\n After the third drop, the tallest stack is still squares 1 and 2 with a height of 5.\n Thus, we return an answer of [2, 5, 5].\n \n Example 2:\n \n >>> fallingSquares(positions = [[100,100],[200,100]])\n >>> [100,100]\n Explanation:\n After the first drop, the tallest stack is square 1 with a height of 100.\n After the second drop, the tallest stack is either square 1 or square 2, both with heights of 100.\n Thus, we return an answer of [100, 100].\n Note that square 2 only brushes the right side of square 1, which does not count as landing on it.\n \"\"\"\n"}
{"task_id": "search-in-a-binary-search-tree", "prompt": "# class TreeNode:\n# def __init__(val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def searchBST(root: Optional[TreeNode], val: int) -> Optional[TreeNode]:\n \"\"\"\n You are given the root of a binary search tree (BST) and an integer val.\n Find the node in the BST that the node's value equals val and return the subtree rooted with that node. If such a node does not exist, return null.\n \n Example 1:\n \n \n >>> __init__(root = [4,2,7,1,3], val = 2)\n >>> [2,1,3]\n \n Example 2:\n \n \n >>> __init__(root = [4,2,7,1,3], val = 5)\n >>> []\n \"\"\"\n"}
{"task_id": "insert-into-a-binary-search-tree", "prompt": "# class TreeNode:\n# def __init__(val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def insertIntoBST(root: Optional[TreeNode], val: int) -> Optional[TreeNode]:\n \"\"\"\n You are given the root node of a binary search tree (BST) and a value to insert into the tree. Return the root node of the BST after the insertion. It is guaranteed that the new value does not exist in the original BST.\n Notice\u00a0that there may exist\u00a0multiple valid ways for the\u00a0insertion, as long as the tree remains a BST after insertion. You can return any of them.\n \n Example 1:\n \n \n >>> __init__(root = [4,2,7,1,3], val = 5)\n >>> [4,2,7,1,3,5]\n Explanation: Another accepted tree is:\n \n \n Example 2:\n \n >>> __init__(root = [40,20,60,10,30,50,70], val = 25)\n >>> [40,20,60,10,30,50,70,null,null,25]\n \n Example 3:\n \n >>> __init__(root = [4,2,7,1,3,null,null,null,null,null,null], val = 5)\n >>> [4,2,7,1,3,5]\n \"\"\"\n"}
{"task_id": "binary-search", "prompt": "def search(nums: List[int], target: int) -> int:\n \"\"\"\n Given an array of integers nums which is sorted in ascending order, and an integer target, write a function to search target in nums. If target exists, then return its index. Otherwise, return -1.\n You must write an algorithm with O(log n) runtime complexity.\n \n Example 1:\n \n >>> search(nums = [-1,0,3,5,9,12], target = 9)\n >>> 4\n Explanation: 9 exists in nums and its index is 4\n \n Example 2:\n \n >>> search(nums = [-1,0,3,5,9,12], target = 2)\n >>> -1\n Explanation: 2 does not exist in nums so return -1\n \"\"\"\n"}
{"task_id": "to-lower-case", "prompt": "def toLowerCase(s: str) -> str:\n \"\"\"\n Given a string s, return the string after replacing every uppercase letter with the same lowercase letter.\n \n Example 1:\n \n >>> toLowerCase(s = \"Hello\")\n >>> \"hello\"\n \n Example 2:\n \n >>> toLowerCase(s = \"here\")\n >>> \"here\"\n \n Example 3:\n \n >>> toLowerCase(s = \"LOVELY\")\n >>> \"lovely\"\n \"\"\"\n"}
{"task_id": "number-of-distinct-islands-ii", "prompt": "def numDistinctIslands2(grid: List[List[int]]) -> int:\n \"\"\"\n You are given an m x n binary matrix grid. An island is a group of 1's (representing land) connected 4-directionally (horizontal or vertical.) You may assume all four edges of the grid are surrounded by water.\n An island is considered to be the same as another if they have the same shape, or have the same shape after rotation (90, 180, or 270 degrees only) or reflection (left/right direction or up/down direction).\n Return the number of distinct islands.\n \n Example 1:\n \n \n >>> numDistinctIslands2(grid = [[1,1,0,0,0],[1,0,0,0,0],[0,0,0,0,1],[0,0,0,1,1]])\n >>> 1\n Explanation: The two islands are considered the same because if we make a 180 degrees clockwise rotation on the first island, then two islands will have the same shapes.\n \n Example 2:\n \n \n >>> numDistinctIslands2(grid = [[1,1,0,0,0],[1,1,0,0,0],[0,0,0,1,1],[0,0,0,1,1]])\n >>> 1\n \"\"\"\n"}
{"task_id": "minimum-ascii-delete-sum-for-two-strings", "prompt": "def minimumDeleteSum(s1: str, s2: str) -> int:\n \"\"\"\n Given two strings s1 and\u00a0s2, return the lowest ASCII sum of deleted characters to make two strings equal.\n \n Example 1:\n \n >>> minimumDeleteSum(s1 = \"sea\", s2 = \"eat\")\n >>> 231\n Explanation: Deleting \"s\" from \"sea\" adds the ASCII value of \"s\" (115) to the sum.\n Deleting \"t\" from \"eat\" adds 116 to the sum.\n At the end, both strings are equal, and 115 + 116 = 231 is the minimum sum possible to achieve this.\n \n Example 2:\n \n >>> minimumDeleteSum(s1 = \"delete\", s2 = \"leet\")\n >>> 403\n Explanation: Deleting \"dee\" from \"delete\" to turn the string into \"let\",\n adds 100[d] + 101[e] + 101[e] to the sum.\n Deleting \"e\" from \"leet\" adds 101[e] to the sum.\n At the end, both strings are equal to \"let\", and the answer is 100+101+101+101 = 403.\n If instead we turned both strings into \"lee\" or \"eet\", we would get answers of 433 or 417, which are higher.\n \"\"\"\n"}
{"task_id": "subarray-product-less-than-k", "prompt": "def numSubarrayProductLessThanK(nums: List[int], k: int) -> int:\n \"\"\"\n Given an array of integers nums and an integer k, return the number of contiguous subarrays where the product of all the elements in the subarray is strictly less than k.\n \n Example 1:\n \n >>> numSubarrayProductLessThanK(nums = [10,5,2,6], k = 100)\n >>> 8\n Explanation: The 8 subarrays that have product less than 100 are:\n [10], [5], [2], [6], [10, 5], [5, 2], [2, 6], [5, 2, 6]\n Note that [10, 5, 2] is not included as the product of 100 is not strictly less than k.\n \n Example 2:\n \n >>> numSubarrayProductLessThanK(nums = [1,2,3], k = 0)\n >>> 0\n \"\"\"\n"}
{"task_id": "best-time-to-buy-and-sell-stock-with-transaction-fee", "prompt": "def maxProfit(prices: List[int], fee: int) -> int:\n \"\"\"\n You are given an array prices where prices[i] is the price of a given stock on the ith day, and an integer fee representing a transaction fee.\n Find the maximum profit you can achieve. You may complete as many transactions as you like, but you need to pay the transaction fee for each transaction.\n Note:\n \n You may not engage in multiple transactions simultaneously (i.e., you must sell the stock before you buy again).\n The transaction fee is only charged once for each stock purchase and sale.\n \n \n Example 1:\n \n >>> maxProfit(prices = [1,3,2,8,4,9], fee = 2)\n >>> 8\n Explanation: The maximum profit can be achieved by:\n - Buying at prices[0] = 1\n - Selling at prices[3] = 8\n - Buying at prices[4] = 4\n - Selling at prices[5] = 9\n The total profit is ((8 - 1) - 2) + ((9 - 4) - 2) = 8.\n \n Example 2:\n \n >>> maxProfit(prices = [1,3,7,5,10,3], fee = 3)\n >>> 6\n \"\"\"\n"}
{"task_id": "1-bit-and-2-bit-characters", "prompt": "def isOneBitCharacter(bits: List[int]) -> bool:\n \"\"\"\n We have two special characters:\n \n The first character can be represented by one bit 0.\n The second character can be represented by two bits (10 or 11).\n \n Given a binary array bits that ends with 0, return true if the last character must be a one-bit character.\n \n Example 1:\n \n >>> isOneBitCharacter(bits = [1,0,0])\n >>> true\n Explanation: The only way to decode it is two-bit character and one-bit character.\n So the last character is one-bit character.\n \n Example 2:\n \n >>> isOneBitCharacter(bits = [1,1,1,0])\n >>> false\n Explanation: The only way to decode it is two-bit character and two-bit character.\n So the last character is not one-bit character.\n \"\"\"\n"}
{"task_id": "maximum-length-of-repeated-subarray", "prompt": "def findLength(nums1: List[int], nums2: List[int]) -> int:\n \"\"\"\n Given two integer arrays nums1 and nums2, return the maximum length of a subarray that appears in both arrays.\n \n Example 1:\n \n >>> findLength(nums1 = [1,2,3,2,1], nums2 = [3,2,1,4,7])\n >>> 3\n Explanation: The repeated subarray with maximum length is [3,2,1].\n \n Example 2:\n \n >>> findLength(nums1 = [0,0,0,0,0], nums2 = [0,0,0,0,0])\n >>> 5\n Explanation: The repeated subarray with maximum length is [0,0,0,0,0].\n \"\"\"\n"}
{"task_id": "find-k-th-smallest-pair-distance", "prompt": "def smallestDistancePair(nums: List[int], k: int) -> int:\n \"\"\"\n The distance of a pair of integers a and b is defined as the absolute difference between a and b.\n Given an integer array nums and an integer k, return the kth smallest distance among all the pairs nums[i] and nums[j] where 0 <= i < j < nums.length.\n \n Example 1:\n \n >>> smallestDistancePair(nums = [1,3,1], k = 1)\n >>> 0\n Explanation: Here are all the pairs:\n (1,3) -> 2\n (1,1) -> 0\n (3,1) -> 2\n Then the 1st smallest distance pair is (1,1), and its distance is 0.\n \n Example 2:\n \n >>> smallestDistancePair(nums = [1,1,1], k = 2)\n >>> 0\n \n Example 3:\n \n >>> smallestDistancePair(nums = [1,6,1], k = 3)\n >>> 5\n \"\"\"\n"}
{"task_id": "longest-word-in-dictionary", "prompt": "def longestWord(words: List[str]) -> str:\n \"\"\"\n Given an array of strings words representing an English Dictionary, return the longest word in words that can be built one character at a time by other words in words.\n If there is more than one possible answer, return the longest word with the smallest lexicographical order. If there is no answer, return the empty string.\n Note that the word should be built from left to right with each additional character being added to the end of a previous word.\n \n Example 1:\n \n >>> longestWord(words = [\"w\",\"wo\",\"wor\",\"worl\",\"world\"])\n >>> \"world\"\n Explanation: The word \"world\" can be built one character at a time by \"w\", \"wo\", \"wor\", and \"worl\".\n \n Example 2:\n \n >>> longestWord(words = [\"a\",\"banana\",\"app\",\"appl\",\"ap\",\"apply\",\"apple\"])\n >>> \"apple\"\n Explanation: Both \"apply\" and \"apple\" can be built from other words in the dictionary. However, \"apple\" is lexicographically smaller than \"apply\".\n \"\"\"\n"}
{"task_id": "accounts-merge", "prompt": "def accountsMerge(accounts: List[List[str]]) -> List[List[str]]:\n \"\"\"\n Given a list of accounts where each element accounts[i] is a list of strings, where the first element accounts[i][0] is a name, and the rest of the elements are emails representing emails of the account.\n Now, we would like to merge these accounts. Two accounts definitely belong to the same person if there is some common email to both accounts. Note that even if two accounts have the same name, they may belong to different people as people could have the same name. A person can have any number of accounts initially, but all of their accounts definitely have the same name.\n After merging the accounts, return the accounts in the following format: the first element of each account is the name, and the rest of the elements are emails in sorted order. The accounts themselves can be returned in any order.\n \n Example 1:\n \n >>> accountsMerge(accounts = [[\"John\",\"johnsmith@mail.com\",\"john_newyork@mail.com\"],[\"John\",\"johnsmith@mail.com\",\"john00@mail.com\"],[\"Mary\",\"mary@mail.com\"],[\"John\",\"johnnybravo@mail.com\"]])\n >>> [[\"John\",\"john00@mail.com\",\"john_newyork@mail.com\",\"johnsmith@mail.com\"],[\"Mary\",\"mary@mail.com\"],[\"John\",\"johnnybravo@mail.com\"]]\n Explanation:\n The first and second John's are the same person as they have the common email \"johnsmith@mail.com\".\n The third John and Mary are different people as none of their email addresses are used by other accounts.\n We could return these lists in any order, for example the answer [['Mary', 'mary@mail.com'], ['John', 'johnnybravo@mail.com'],\n ['John', 'john00@mail.com', 'john_newyork@mail.com', 'johnsmith@mail.com']] would still be accepted.\n \n Example 2:\n \n >>> accountsMerge(accounts = [[\"Gabe\",\"Gabe0@m.co\",\"Gabe3@m.co\",\"Gabe1@m.co\"],[\"Kevin\",\"Kevin3@m.co\",\"Kevin5@m.co\",\"Kevin0@m.co\"],[\"Ethan\",\"Ethan5@m.co\",\"Ethan4@m.co\",\"Ethan0@m.co\"],[\"Hanzo\",\"Hanzo3@m.co\",\"Hanzo1@m.co\",\"Hanzo0@m.co\"],[\"Fern\",\"Fern5@m.co\",\"Fern1@m.co\",\"Fern0@m.co\"]])\n >>> [[\"Ethan\",\"Ethan0@m.co\",\"Ethan4@m.co\",\"Ethan5@m.co\"],[\"Gabe\",\"Gabe0@m.co\",\"Gabe1@m.co\",\"Gabe3@m.co\"],[\"Hanzo\",\"Hanzo0@m.co\",\"Hanzo1@m.co\",\"Hanzo3@m.co\"],[\"Kevin\",\"Kevin0@m.co\",\"Kevin3@m.co\",\"Kevin5@m.co\"],[\"Fern\",\"Fern0@m.co\",\"Fern1@m.co\",\"Fern5@m.co\"]]\n \"\"\"\n"}
{"task_id": "remove-comments", "prompt": "def removeComments(source: List[str]) -> List[str]:\n \"\"\"\n Given a C++ program, remove comments from it. The program source is an array of strings source where source[i] is the ith line of the source code. This represents the result of splitting the original source code string by the newline character '\\\n '.\n In C++, there are two types of comments, line comments, and block comments.\n \n The string \"//\" denotes a line comment, which represents that it and the rest of the characters to the right of it in the same line should be ignored.\n The string \"/*\" denotes a block comment, which represents that all characters until the next (non-overlapping) occurrence of \"*/\" should be ignored. (Here, occurrences happen in reading order: line by line from left to right.) To be clear, the string \"/*/\" does not yet end the block comment, as the ending would be overlapping the beginning.\n \n The first effective comment takes precedence over others.\n \n For example, if the string \"//\" occurs in a block comment, it is ignored.\n Similarly, if the string \"/*\" occurs in a line or block comment, it is also ignored.\n \n If a certain line of code is empty after removing comments, you must not output that line: each string in the answer list will be non-empty.\n There will be no control characters, single quote, or double quote characters.\n \n For example, source = \"string s = \"/* Not a comment. */\";\" will not be a test case.\n \n Also, nothing else such as defines or macros will interfere with the comments.\n It is guaranteed that every open block comment will eventually be closed, so \"/*\" outside of a line or block comment always starts a new comment.\n Finally, implicit newline characters can be deleted by block comments. Please see the examples below for details.\n After removing the comments from the source code, return the source code in the same format.\n \n Example 1:\n \n >>> removeComments(source = [\"/*Test program */\", \"int main()\", \"{ \", \" // variable declaration \", \"int a, b, c;\", \"/* This is a test\", \" multiline \", \" comment for \", \" testing */\", \"a = b + c;\", \"}\"])\n >>> [\"int main()\",\"{ \",\" \",\"int a, b, c;\",\"a = b + c;\",\"}\"]\n Explanation: The line by line code is visualized as below:\n /*Test program */\n int main()\n {\n // variable declaration\n int a, b, c;\n /* This is a test\n multiline\n comment for\n testing */\n a = b + c;\n }\n The string /* denotes a block comment, including line 1 and lines 6-9. The string // denotes line 4 as comments.\n The line by line output code is visualized as below:\n int main()\n {\n \n int a, b, c;\n a = b + c;\n }\n \n Example 2:\n \n >>> removeComments(source = [\"a/*comment\", \"line\", \"more_comment*/b\"])\n >>> [\"ab\"]\n Explanation: The original source string is \"a/*comment\\\n line\\\n more_comment*/b\", where we have bolded the newline characters. After deletion, the implicit newline characters are deleted, leaving the string \"ab\", which when delimited by newline characters becomes [\"ab\"].\n \"\"\"\n"}
{"task_id": "candy-crush", "prompt": "def candyCrush(board: List[List[int]]) -> List[List[int]]:\n \"\"\"\n This question is about implementing a basic elimination algorithm for Candy Crush.\n Given an m x n integer array board representing the grid of candy where board[i][j] represents the type of candy. A value of board[i][j] == 0 represents that the cell is empty.\n The given board represents the state of the game following the player's move. Now, you need to restore the board to a stable state by crushing candies according to the following rules:\n \n If three or more candies of the same type are adjacent vertically or horizontally, crush them all at the same time - these positions become empty.\n After crushing all candies simultaneously, if an empty space on the board has candies on top of itself, then these candies will drop until they hit a candy or bottom at the same time. No new candies will drop outside the top boundary.\n After the above steps, there may exist more candies that can be crushed. If so, you need to repeat the above steps.\n If there does not exist more candies that can be crushed (i.e., the board is stable), then return the current board.\n \n You need to perform the above rules until the board becomes stable, then return the stable board.\n \n Example 1:\n \n \n >>> candyCrush(board = [[110,5,112,113,114],[210,211,5,213,214],[310,311,3,313,314],[410,411,412,5,414],[5,1,512,3,3],[610,4,1,613,614],[710,1,2,713,714],[810,1,2,1,1],[1,1,2,2,2],[4,1,4,4,1014]])\n >>> [[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[110,0,0,0,114],[210,0,0,0,214],[310,0,0,113,314],[410,0,0,213,414],[610,211,112,313,614],[710,311,412,613,714],[810,411,512,713,1014]]\n \n Example 2:\n \n >>> candyCrush(board = [[1,3,5,5,2],[3,4,3,3,1],[3,2,4,5,2],[2,4,4,5,5],[1,4,4,1,1]])\n >>> [[1,3,0,0,0],[3,4,0,5,2],[3,2,0,3,1],[2,4,0,5,2],[1,4,3,1,1]]\n \"\"\"\n"}
{"task_id": "find-pivot-index", "prompt": "def pivotIndex(nums: List[int]) -> int:\n \"\"\"\n Given an array of integers nums, calculate the pivot index of this array.\n The pivot index is the index where the sum of all the numbers strictly to the left of the index is equal to the sum of all the numbers strictly to the index's right.\n If the index is on the left edge of the array, then the left sum is 0 because there are no elements to the left. This also applies to the right edge of the array.\n Return the leftmost pivot index. If no such index exists, return -1.\n \n Example 1:\n \n >>> pivotIndex(nums = [1,7,3,6,5,6])\n >>> 3\n Explanation:\n The pivot index is 3.\n Left sum = nums[0] + nums[1] + nums[2] = 1 + 7 + 3 = 11\n Right sum = nums[4] + nums[5] = 5 + 6 = 11\n \n Example 2:\n \n >>> pivotIndex(nums = [1,2,3])\n >>> -1\n Explanation:\n There is no index that satisfies the conditions in the problem statement.\n Example 3:\n \n >>> pivotIndex(nums = [2,1,-1])\n >>> 0\n Explanation:\n The pivot index is 0.\n Left sum = 0 (no elements to the left of index 0)\n Right sum = nums[1] + nums[2] = 1 + -1 = 0\n \"\"\"\n"}
{"task_id": "number-of-atoms", "prompt": "def countOfAtoms(formula: str) -> str:\n \"\"\"\n Given a string formula representing a chemical formula, return the count of each atom.\n The atomic element always starts with an uppercase character, then zero or more lowercase letters, representing the name.\n One or more digits representing that element's count may follow if the count is greater than 1. If the count is 1, no digits will follow.\n \n For example, \"H2O\" and \"H2O2\" are possible, but \"H1O2\" is impossible.\n \n Two formulas are concatenated together to produce another formula.\n \n For example, \"H2O2He3Mg4\" is also a formula.\n \n A formula placed in parentheses, and a count (optionally added) is also a formula.\n \n For example, \"(H2O2)\" and \"(H2O2)3\" are formulas.\n \n Return the count of all elements as a string in the following form: the first name (in sorted order), followed by its count (if that count is more than 1), followed by the second name (in sorted order), followed by its count (if that count is more than 1), and so on.\n The test cases are generated so that all the values in the output fit in a 32-bit integer.\n \n Example 1:\n \n >>> countOfAtoms(formula = \"H2O\")\n >>> \"H2O\"\n Explanation: The count of elements are {'H': 2, 'O': 1}.\n \n Example 2:\n \n >>> countOfAtoms(formula = \"Mg(OH)2\")\n >>> \"H2MgO2\"\n Explanation: The count of elements are {'H': 2, 'Mg': 1, 'O': 2}.\n \n Example 3:\n \n >>> countOfAtoms(formula = \"K4(ON(SO3)2)2\")\n >>> \"K4N2O14S4\"\n Explanation: The count of elements are {'K': 4, 'N': 2, 'O': 14, 'S': 4}.\n \"\"\"\n"}
{"task_id": "minimum-window-subsequence", "prompt": "def minWindow(s1: str, s2: str) -> str:\n \"\"\"\n Given strings s1 and s2, return the minimum contiguous\u00a0substring part of s1, so that s2 is a subsequence of the part.\n If there is no such window in s1 that covers all characters in s2, return the empty string \"\". If there are multiple such minimum-length windows, return the one with the left-most starting index.\n \n Example 1:\n \n >>> minWindow(s1 = \"abcdebdde\", s2 = \"bde\")\n >>> \"bcde\"\n Explanation:\n \"bcde\" is the answer because it occurs before \"bdde\" which has the same length.\n \"deb\" is not a smaller window because the elements of s2 in the window must occur in order.\n \n Example 2:\n \n >>> minWindow(s1 = \"jmeqksfrsdcmsiwvaovztaqenprpvnbstl\", s2 = \"u\")\n >>> \"\"\n \"\"\"\n"}
{"task_id": "self-dividing-numbers", "prompt": "def selfDividingNumbers(left: int, right: int) -> List[int]:\n \"\"\"\n A self-dividing number is a number that is divisible by every digit it contains.\n \n For example, 128 is a self-dividing number because 128 % 1 == 0, 128 % 2 == 0, and 128 % 8 == 0.\n \n A self-dividing number is not allowed to contain the digit zero.\n Given two integers left and right, return a list of all the self-dividing numbers in the range [left, right] (both inclusive).\n \n Example 1:\n >>> selfDividingNumbers(left = 1, right = 22)\n >>> [1,2,3,4,5,6,7,8,9,11,12,15,22]\n Example 2:\n >>> selfDividingNumbers(left = 47, right = 85)\n >>> [48,55,66,77]\n \"\"\"\n"}
{"task_id": "count-different-palindromic-subsequences", "prompt": "def countPalindromicSubsequences(s: str) -> int:\n \"\"\"\n Given a string s, return the number of different non-empty palindromic subsequences in s. Since the answer may be very large, return it modulo 109 + 7.\n A subsequence of a string is obtained by deleting zero or more characters from the string.\n A sequence is palindromic if it is equal to the sequence reversed.\n Two sequences a1, a2, ... and b1, b2, ... are different if there is some i for which ai != bi.\n \n Example 1:\n \n >>> countPalindromicSubsequences(s = \"bccb\")\n >>> 6\n Explanation: The 6 different non-empty palindromic subsequences are 'b', 'c', 'bb', 'cc', 'bcb', 'bccb'.\n Note that 'bcb' is counted only once, even though it occurs twice.\n \n Example 2:\n \n >>> countPalindromicSubsequences(s = \"abcdabcdabcdabcdabcdabcdabcdabcddcbadcbadcbadcbadcbadcbadcbadcba\")\n >>> 104860361\n Explanation: There are 3104860382 different non-empty palindromic subsequences, which is 104860361 modulo 109 + 7.\n \"\"\"\n"}
{"task_id": "flood-fill", "prompt": "def floodFill(image: List[List[int]], sr: int, sc: int, color: int) -> List[List[int]]:\n \"\"\"\n You are given an image represented by an m x n grid of integers image, where image[i][j] represents the pixel value of the image. You are also given three integers sr, sc, and color. Your task is to perform a flood fill on the image starting from the pixel image[sr][sc].\n To perform a flood fill:\n \n Begin with the starting pixel and change its color to color.\n Perform the same process for each pixel that is directly adjacent (pixels that share a side with the original pixel, either horizontally or vertically) and shares the same color as the starting pixel.\n Keep repeating this process by checking neighboring pixels of the updated pixels\u00a0and modifying their color if it matches the original color of the starting pixel.\n The process stops when there are no more adjacent pixels of the original color to update.\n \n Return the modified image after performing the flood fill.\n \n Example 1:\n \n >>> floodFill(image = [[1,1,1],[1,1,0],[1,0,1]], sr = 1, sc = 1, color = 2)\n >>> [[2,2,2],[2,2,0],[2,0,1]]\n Explanation:\n \n From the center of the image with position (sr, sc) = (1, 1) (i.e., the red pixel), all pixels connected by a path of the same color as the starting pixel (i.e., the blue pixels) are colored with the new color.\n Note the bottom corner is not colored 2, because it is not horizontally or vertically connected to the starting pixel.\n \n Example 2:\n \n >>> floodFill(image = [[0,0,0],[0,0,0]], sr = 0, sc = 0, color = 0)\n >>> [[0,0,0],[0,0,0]]\n Explanation:\n The starting pixel is already colored with 0, which is the same as the target color. Therefore, no changes are made to the image.\n \"\"\"\n"}
{"task_id": "sentence-similarity", "prompt": "def areSentencesSimilar(sentence1: List[str], sentence2: List[str], similarPairs: List[List[str]]) -> bool:\n \"\"\"\n We can represent a sentence as an array of words, for example, the sentence \"I am happy with leetcode\" can be represented as arr = [\"I\",\"am\",happy\",\"with\",\"leetcode\"].\n Given two sentences sentence1 and sentence2 each represented as a string array and given an array of string pairs similarPairs where similarPairs[i] = [xi, yi] indicates that the two words xi and yi are similar.\n Return true if sentence1 and sentence2 are similar, or false if they are not similar.\n Two sentences are similar if:\n \n They have the same length (i.e., the same number of words)\n sentence1[i] and sentence2[i] are similar.\n \n Notice that a word is always similar to itself, also notice that the similarity relation is not transitive. For example, if the words a and b are similar, and the words b and c are similar, a and c are not necessarily similar.\n \n Example 1:\n \n >>> areSentencesSimilar(sentence1 = [\"great\",\"acting\",\"skills\"], sentence2 = [\"fine\",\"drama\",\"talent\"], similarPairs = [[\"great\",\"fine\"],[\"drama\",\"acting\"],[\"skills\",\"talent\"]])\n >>> true\n Explanation: The two sentences have the same length and each word i of sentence1 is also similar to the corresponding word in sentence2.\n \n Example 2:\n \n >>> areSentencesSimilar(sentence1 = [\"great\"], sentence2 = [\"great\"], similarPairs = [])\n >>> true\n Explanation: A word is similar to itself.\n \n Example 3:\n \n >>> areSentencesSimilar(sentence1 = [\"great\"], sentence2 = [\"doubleplus\",\"good\"], similarPairs = [[\"great\",\"doubleplus\"]])\n >>> false\n Explanation: As they don't have the same length, we return false.\n \"\"\"\n"}
{"task_id": "asteroid-collision", "prompt": "def asteroidCollision(asteroids: List[int]) -> List[int]:\n \"\"\"\n We are given an array asteroids of integers representing asteroids in a row. The indices of the asteriod in the array represent their relative position in space.\n For each asteroid, the absolute value represents its size, and the sign represents its direction (positive meaning right, negative meaning left). Each asteroid moves at the same speed.\n Find out the state of the asteroids after all collisions. If two asteroids meet, the smaller one will explode. If both are the same size, both will explode. Two asteroids moving in the same direction will never meet.\n \n Example 1:\n \n >>> asteroidCollision(asteroids = [5,10,-5])\n >>> [5,10]\n Explanation: The 10 and -5 collide resulting in 10. The 5 and 10 never collide.\n \n Example 2:\n \n >>> asteroidCollision(asteroids = [8,-8])\n >>> []\n Explanation: The 8 and -8 collide exploding each other.\n \n Example 3:\n \n >>> asteroidCollision(asteroids = [10,2,-5])\n >>> [10]\n Explanation: The 2 and -5 collide resulting in -5. The 10 and -5 collide resulting in 10.\n \"\"\"\n"}
{"task_id": "parse-lisp-expression", "prompt": "def evaluate(expression: str) -> int:\n \"\"\"\n You are given a string expression representing a Lisp-like expression to return the integer value of.\n The syntax for these expressions is given as follows.\n \n An expression is either an integer, let expression, add expression, mult expression, or an assigned variable. Expressions always evaluate to a single integer.\n (An integer could be positive or negative.)\n A let expression takes the form \"(let v1 e1 v2 e2 ... vn en expr)\", where let is always the string \"let\", then there are one or more pairs of alternating variables and expressions, meaning that the first variable v1 is assigned the value of the expression e1, the second variable v2 is assigned the value of the expression e2, and so on sequentially; and then the value of this let expression is the value of the expression expr.\n An add expression takes the form \"(add e1 e2)\" where add is always the string \"add\", there are always two expressions e1, e2 and the result is the addition of the evaluation of e1 and the evaluation of e2.\n A mult expression takes the form \"(mult e1 e2)\" where mult is always the string \"mult\", there are always two expressions e1, e2 and the result is the multiplication of the evaluation of e1 and the evaluation of e2.\n For this question, we will use a smaller subset of variable names. A variable starts with a lowercase letter, then zero or more lowercase letters or digits. Additionally, for your convenience, the names \"add\", \"let\", and \"mult\" are protected and will never be used as variable names.\n Finally, there is the concept of scope. When an expression of a variable name is evaluated, within the context of that evaluation, the innermost scope (in terms of parentheses) is checked first for the value of that variable, and then outer scopes are checked sequentially. It is guaranteed that every expression is legal. Please see the examples for more details on the scope.\n \n \n Example 1:\n \n >>> evaluate(expression = \"(let x 2 (mult x (let x 3 y 4 (add x y))))\")\n >>> 14\n Explanation: In the expression (add x y), when checking for the value of the variable x,\n we check from the innermost scope to the outermost in the context of the variable we are trying to evaluate.\n Since x = 3 is found first, the value of x is 3.\n \n Example 2:\n \n >>> evaluate(expression = \"(let x 3 x 2 x)\")\n >>> 2\n Explanation: Assignment in let statements is processed sequentially.\n \n Example 3:\n \n >>> evaluate(expression = \"(let x 1 y 2 x (add x y) (add x y))\")\n >>> 5\n Explanation: The first (add x y) evaluates as 3, and is assigned to x.\n The second (add x y) evaluates as 3+2 = 5.\n \"\"\"\n"}
{"task_id": "sentence-similarity-ii", "prompt": "def areSentencesSimilarTwo(sentence1: List[str], sentence2: List[str], similarPairs: List[List[str]]) -> bool:\n \"\"\"\n We can represent a sentence as an array of words, for example, the sentence \"I am happy with leetcode\" can be represented as arr = [\"I\",\"am\",happy\",\"with\",\"leetcode\"].\n Given two sentences sentence1 and sentence2 each represented as a string array and given an array of string pairs similarPairs where similarPairs[i] = [xi, yi] indicates that the two words xi and yi are similar.\n Return true if sentence1 and sentence2 are similar, or false if they are not similar.\n Two sentences are similar if:\n \n They have the same length (i.e., the same number of words)\n sentence1[i] and sentence2[i] are similar.\n \n Notice that a word is always similar to itself, also notice that the similarity relation is transitive. For example, if the words a and b are similar, and the words b and c are similar, then\u00a0a and c are similar.\n \n Example 1:\n \n >>> areSentencesSimilarTwo(sentence1 = [\"great\",\"acting\",\"skills\"], sentence2 = [\"fine\",\"drama\",\"talent\"], similarPairs = [[\"great\",\"good\"],[\"fine\",\"good\"],[\"drama\",\"acting\"],[\"skills\",\"talent\"]])\n >>> true\n Explanation: The two sentences have the same length and each word i of sentence1 is also similar to the corresponding word in sentence2.\n \n Example 2:\n \n >>> areSentencesSimilarTwo(sentence1 = [\"I\",\"love\",\"leetcode\"], sentence2 = [\"I\",\"love\",\"onepiece\"], similarPairs = [[\"manga\",\"onepiece\"],[\"platform\",\"anime\"],[\"leetcode\",\"platform\"],[\"anime\",\"manga\"]])\n >>> true\n Explanation: \"leetcode\" --> \"platform\" --> \"anime\" --> \"manga\" --> \"onepiece\".\n Since \"leetcode is similar to \"onepiece\" and the first two words are the same, the two sentences are similar.\n Example 3:\n \n >>> areSentencesSimilarTwo(sentence1 = [\"I\",\"love\",\"leetcode\"], sentence2 = [\"I\",\"love\",\"onepiece\"], similarPairs = [[\"manga\",\"hunterXhunter\"],[\"platform\",\"anime\"],[\"leetcode\",\"platform\"],[\"anime\",\"manga\"]])\n >>> false\n Explanation: \"leetcode\" is not similar to \"onepiece\".\n \"\"\"\n"}
{"task_id": "monotone-increasing-digits", "prompt": "def monotoneIncreasingDigits(n: int) -> int:\n \"\"\"\n An integer has monotone increasing digits if and only if each pair of adjacent digits x and y satisfy x <= y.\n Given an integer n, return the largest number that is less than or equal to n with monotone increasing digits.\n \n Example 1:\n \n >>> monotoneIncreasingDigits(n = 10)\n >>> 9\n \n Example 2:\n \n >>> monotoneIncreasingDigits(n = 1234)\n >>> 1234\n \n Example 3:\n \n >>> monotoneIncreasingDigits(n = 332)\n >>> 299\n \"\"\"\n"}
{"task_id": "daily-temperatures", "prompt": "def dailyTemperatures(temperatures: List[int]) -> List[int]:\n \"\"\"\n Given an array of integers temperatures represents the daily temperatures, return an array answer such that answer[i] is the number of days you have to wait after the ith day to get a warmer temperature. If there is no future day for which this is possible, keep answer[i] == 0 instead.\n \n Example 1:\n >>> dailyTemperatures(temperatures = [73,74,75,71,69,72,76,73])\n >>> [1,1,4,2,1,1,0,0]\n Example 2:\n >>> dailyTemperatures(temperatures = [30,40,50,60])\n >>> [1,1,1,0]\n Example 3:\n >>> dailyTemperatures(temperatures = [30,60,90])\n >>> [1,1,0]\n \"\"\"\n"}
{"task_id": "delete-and-earn", "prompt": "def deleteAndEarn(nums: List[int]) -> int:\n \"\"\"\n You are given an integer array nums. You want to maximize the number of points you get by performing the following operation any number of times:\n \n Pick any nums[i] and delete it to earn nums[i] points. Afterwards, you must delete every element equal to nums[i] - 1 and every element equal to nums[i] + 1.\n \n Return the maximum number of points you can earn by applying the above operation some number of times.\n \n Example 1:\n \n >>> deleteAndEarn(nums = [3,4,2])\n >>> 6\n Explanation: You can perform the following operations:\n - Delete 4 to earn 4 points. Consequently, 3 is also deleted. nums = [2].\n - Delete 2 to earn 2 points. nums = [].\n You earn a total of 6 points.\n \n Example 2:\n \n >>> deleteAndEarn(nums = [2,2,3,3,3,4])\n >>> 9\n Explanation: You can perform the following operations:\n - Delete a 3 to earn 3 points. All 2's and 4's are also deleted. nums = [3,3].\n - Delete a 3 again to earn 3 points. nums = [3].\n - Delete a 3 once more to earn 3 points. nums = [].\n You earn a total of 9 points.\n \"\"\"\n"}
{"task_id": "cherry-pickup", "prompt": "def cherryPickup(grid: List[List[int]]) -> int:\n \"\"\"\n You are given an n x n grid representing a field of cherries, each cell is one of three possible integers.\n \n 0 means the cell is empty, so you can pass through,\n 1 means the cell contains a cherry that you can pick up and pass through, or\n -1 means the cell contains a thorn that blocks your way.\n \n Return the maximum number of cherries you can collect by following the rules below:\n \n Starting at the position (0, 0) and reaching (n - 1, n - 1) by moving right or down through valid path cells (cells with value 0 or 1).\n After reaching (n - 1, n - 1), returning to (0, 0) by moving left or up through valid path cells.\n When passing through a path cell containing a cherry, you pick it up, and the cell becomes an empty cell 0.\n If there is no valid path between (0, 0) and (n - 1, n - 1), then no cherries can be collected.\n \n \n Example 1:\n \n \n >>> cherryPickup(grid = [[0,1,-1],[1,0,-1],[1,1,1]])\n >>> 5\n Explanation: The player started at (0, 0) and went down, down, right right to reach (2, 2).\n 4 cherries were picked up during this single trip, and the matrix becomes [[0,1,-1],[0,0,-1],[0,0,0]].\n Then, the player went left, up, up, left to return home, picking up one more cherry.\n The total number of cherries picked up is 5, and this is the maximum possible.\n \n Example 2:\n \n >>> cherryPickup(grid = [[1,1,-1],[1,-1,1],[-1,1,1]])\n >>> 0\n \"\"\"\n"}
{"task_id": "closest-leaf-in-a-binary-tree", "prompt": "# class TreeNode:\n# def __init__(val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def findClosestLeaf(root: Optional[TreeNode], k: int) -> int:\n \"\"\"\n Given the root of a binary tree where every node has a unique value and a target integer k, return the value of the nearest leaf node to the target k in the tree.\n Nearest to a leaf means the least number of edges traveled on the binary tree to reach any leaf of the tree. Also, a node is called a leaf if it has no children.\n \n Example 1:\n \n \n >>> __init__(root = [1,3,2], k = 1)\n >>> 2\n Explanation: Either 2 or 3 is the nearest leaf node to the target of 1.\n \n Example 2:\n \n \n >>> __init__(root = [1], k = 1)\n >>> 1\n Explanation: The nearest leaf node is the root node itself.\n \n Example 3:\n \n \n >>> __init__(root = [1,2,3,4,null,null,null,5,null,6], k = 2)\n >>> 3\n Explanation: The leaf node with value 3 (and not the leaf node with value 6) is nearest to the node with value 2.\n \"\"\"\n"}
{"task_id": "network-delay-time", "prompt": "def networkDelayTime(times: List[List[int]], n: int, k: int) -> int:\n \"\"\"\n You are given a network of n nodes, labeled from 1 to n. You are also given times, a list of travel times as directed edges times[i] = (ui, vi, wi), where ui is the source node, vi is the target node, and wi is the time it takes for a signal to travel from source to target.\n We will send a signal from a given node k. Return the minimum time it takes for all the n nodes to receive the signal. If it is impossible for all the n nodes to receive the signal, return -1.\n \n Example 1:\n \n \n >>> networkDelayTime(times = [[2,1,1],[2,3,1],[3,4,1]], n = 4, k = 2)\n >>> 2\n \n Example 2:\n \n >>> networkDelayTime(times = [[1,2,1]], n = 2, k = 1)\n >>> 1\n \n Example 3:\n \n >>> networkDelayTime(times = [[1,2,1]], n = 2, k = 2)\n >>> -1\n \"\"\"\n"}
{"task_id": "find-smallest-letter-greater-than-target", "prompt": "def nextGreatestLetter(letters: List[str], target: str) -> str:\n \"\"\"\n You are given an array of characters letters that is sorted in non-decreasing order, and a character target. There are at least two different characters in letters.\n Return the smallest character in letters that is lexicographically greater than target. If such a character does not exist, return the first character in letters.\n \n Example 1:\n \n >>> nextGreatestLetter(letters = [\"c\",\"f\",\"j\"], target = \"a\")\n >>> \"c\"\n Explanation: The smallest character that is lexicographically greater than 'a' in letters is 'c'.\n \n Example 2:\n \n >>> nextGreatestLetter(letters = [\"c\",\"f\",\"j\"], target = \"c\")\n >>> \"f\"\n Explanation: The smallest character that is lexicographically greater than 'c' in letters is 'f'.\n \n Example 3:\n \n >>> nextGreatestLetter(letters = [\"x\",\"x\",\"y\",\"y\"], target = \"z\")\n >>> \"x\"\n Explanation: There are no characters in letters that is lexicographically greater than 'z' so we return letters[0].\n \"\"\"\n"}
{"task_id": "min-cost-climbing-stairs", "prompt": "def minCostClimbingStairs(cost: List[int]) -> int:\n \"\"\"\n You are given an integer array cost where cost[i] is the cost of ith step on a staircase. Once you pay the cost, you can either climb one or two steps.\n You can either start from the step with index 0, or the step with index 1.\n Return the minimum cost to reach the top of the floor.\n \n Example 1:\n \n >>> minCostClimbingStairs(cost = [10,15,20])\n >>> 15\n Explanation: You will start at index 1.\n - Pay 15 and climb two steps to reach the top.\n The total cost is 15.\n \n Example 2:\n \n >>> minCostClimbingStairs(cost = [1,100,1,1,1,100,1,1,100,1])\n >>> 6\n Explanation: You will start at index 0.\n - Pay 1 and climb two steps to reach index 2.\n - Pay 1 and climb two steps to reach index 4.\n - Pay 1 and climb two steps to reach index 6.\n - Pay 1 and climb one step to reach index 7.\n - Pay 1 and climb two steps to reach index 9.\n - Pay 1 and climb one step to reach the top.\n The total cost is 6.\n \"\"\"\n"}
{"task_id": "largest-number-at-least-twice-of-others", "prompt": "def dominantIndex(nums: List[int]) -> int:\n \"\"\"\n You are given an integer array nums where the largest integer is unique.\n Determine whether the largest element in the array is at least twice as much as every other number in the array. If it is, return the index of the largest element, or return -1 otherwise.\n \n Example 1:\n \n >>> dominantIndex(nums = [3,6,1,0])\n >>> 1\n Explanation: 6 is the largest integer.\n For every other number in the array x, 6 is at least twice as big as x.\n The index of value 6 is 1, so we return 1.\n \n Example 2:\n \n >>> dominantIndex(nums = [1,2,3,4])\n >>> -1\n Explanation: 4 is less than twice the value of 3, so we return -1.\n \"\"\"\n"}
{"task_id": "shortest-completing-word", "prompt": "def shortestCompletingWord(licensePlate: str, words: List[str]) -> str:\n \"\"\"\n Given a string licensePlate and an array of strings words, find the shortest completing word in words.\n A completing word is a word that contains all the letters in licensePlate. Ignore numbers and spaces in licensePlate, and treat letters as case insensitive. If a letter appears more than once in licensePlate, then it must appear in the word the same number of times or more.\n For example, if licensePlate = \"aBc 12c\", then it contains letters 'a', 'b' (ignoring case), and 'c' twice. Possible completing words are \"abccdef\", \"caaacab\", and \"cbca\".\n Return the shortest completing word in words. It is guaranteed an answer exists. If there are multiple shortest completing words, return the first one that occurs in words.\n \n Example 1:\n \n >>> shortestCompletingWord(licensePlate = \"1s3 PSt\", words = [\"step\",\"steps\",\"stripe\",\"stepple\"])\n >>> \"steps\"\n Explanation: licensePlate contains letters 's', 'p', 's' (ignoring case), and 't'.\n \"step\" contains 't' and 'p', but only contains 1 's'.\n \"steps\" contains 't', 'p', and both 's' characters.\n \"stripe\" is missing an 's'.\n \"stepple\" is missing an 's'.\n Since \"steps\" is the only word containing all the letters, that is the answer.\n \n Example 2:\n \n >>> shortestCompletingWord(licensePlate = \"1s3 456\", words = [\"looks\",\"pest\",\"stew\",\"show\"])\n >>> \"pest\"\n Explanation: licensePlate only contains the letter 's'. All the words contain 's', but among these \"pest\", \"stew\", and \"show\" are shortest. The answer is \"pest\" because it is the word that appears earliest of the 3.\n \"\"\"\n"}
{"task_id": "contain-virus", "prompt": "def containVirus(isInfected: List[List[int]]) -> int:\n \"\"\"\n A virus is spreading rapidly, and your task is to quarantine the infected area by installing walls.\n The world is modeled as an m x n binary grid isInfected, where isInfected[i][j] == 0 represents uninfected cells, and isInfected[i][j] == 1 represents cells contaminated with the virus. A wall (and only one wall) can be installed between any two 4-directionally adjacent cells, on the shared boundary.\n Every night, the virus spreads to all neighboring cells in all four directions unless blocked by a wall. Resources are limited. Each day, you can install walls around only one region (i.e., the affected area (continuous block of infected cells) that threatens the most uninfected cells the following night). There will never be a tie.\n Return the number of walls used to quarantine all the infected regions. If the world will become fully infected, return the number of walls used.\n \n Example 1:\n \n \n >>> containVirus(isInfected = [[0,1,0,0,0,0,0,1],[0,1,0,0,0,0,0,1],[0,0,0,0,0,0,0,1],[0,0,0,0,0,0,0,0]])\n >>> 10\n Explanation: There are 2 contaminated regions.\n On the first day, add 5 walls to quarantine the viral region on the left. The board after the virus spreads is:\n \n On the second day, add 5 walls to quarantine the viral region on the right. The virus is fully contained.\n \n \n Example 2:\n \n \n >>> containVirus(isInfected = [[1,1,1],[1,0,1],[1,1,1]])\n >>> 4\n Explanation: Even though there is only one cell saved, there are 4 walls built.\n Notice that walls are only built on the shared boundary of two different cells.\n \n Example 3:\n \n >>> containVirus(isInfected = [[1,1,1,0,0,0,0,0,0],[1,0,1,0,1,1,1,1,1],[1,1,1,0,0,0,0,0,0]])\n >>> 13\n Explanation: The region on the left only builds two new walls.\n \"\"\"\n"}
{"task_id": "number-of-corner-rectangles", "prompt": "def countCornerRectangles(grid: List[List[int]]) -> int:\n \"\"\"\n Given an m x n integer matrix grid where each entry is only 0 or 1, return the number of corner rectangles.\n A corner rectangle is four distinct 1's on the grid that forms an axis-aligned rectangle. Note that only the corners need to have the value 1. Also, all four 1's used must be distinct.\n \n Example 1:\n \n \n >>> countCornerRectangles(grid = [[1,0,0,1,0],[0,0,1,0,1],[0,0,0,1,0],[1,0,1,0,1]])\n >>> 1\n Explanation: There is only one corner rectangle, with corners grid[1][2], grid[1][4], grid[3][2], grid[3][4].\n \n Example 2:\n \n \n >>> countCornerRectangles(grid = [[1,1,1],[1,1,1],[1,1,1]])\n >>> 9\n Explanation: There are four 2x2 rectangles, four 2x3 and 3x2 rectangles, and one 3x3 rectangle.\n \n Example 3:\n \n \n >>> countCornerRectangles(grid = [[1,1,1,1]])\n >>> 0\n Explanation: Rectangles must have four distinct corners.\n \"\"\"\n"}
{"task_id": "ip-to-cidr", "prompt": "def ipToCIDR(ip: str, n: int) -> List[str]:\n \"\"\"\n An IP address is a formatted 32-bit unsigned integer where each group of 8 bits is printed as a decimal number and the dot character '.' splits the groups.\n \n For example, the binary number 00001111 10001000 11111111 01101011 (spaces added for clarity) formatted as an IP address would be \"15.136.255.107\".\n \n A CIDR block is a format used to denote a specific set of IP addresses. It is a string consisting of a base IP address, followed by a slash, followed by a prefix length k. The addresses it covers are all the IPs whose first k bits are the same as the base IP address.\n \n For example, \"123.45.67.89/20\" is a CIDR block with a prefix length of 20. Any IP address whose binary representation matches 01111011 00101101 0100xxxx xxxxxxxx, where x can be either 0 or 1, is in the set covered by the CIDR block.\n \n You are given a start IP address ip and the number of IP addresses we need to cover n. Your goal is to use as few CIDR blocks as possible to cover all the IP addresses in the inclusive range [ip, ip + n - 1] exactly. No other IP addresses outside of the range should be covered.\n Return the shortest list of CIDR blocks that covers the range of IP addresses. If there are multiple answers, return any of them.\n \n Example 1:\n \n >>> ipToCIDR(ip = \"255.0.0.7\", n = 10)\n >>> [\"255.0.0.7/32\",\"255.0.0.8/29\",\"255.0.0.16/32\"]\n Explanation:\n The IP addresses that need to be covered are:\n - 255.0.0.7 -> 11111111 00000000 00000000 00000111\n - 255.0.0.8 -> 11111111 00000000 00000000 00001000\n - 255.0.0.9 -> 11111111 00000000 00000000 00001001\n - 255.0.0.10 -> 11111111 00000000 00000000 00001010\n - 255.0.0.11 -> 11111111 00000000 00000000 00001011\n - 255.0.0.12 -> 11111111 00000000 00000000 00001100\n - 255.0.0.13 -> 11111111 00000000 00000000 00001101\n - 255.0.0.14 -> 11111111 00000000 00000000 00001110\n - 255.0.0.15 -> 11111111 00000000 00000000 00001111\n - 255.0.0.16 -> 11111111 00000000 00000000 00010000\n The CIDR block \"255.0.0.7/32\" covers the first address.\n The CIDR block \"255.0.0.8/29\" covers the middle 8 addresses (binary format of 11111111 00000000 00000000 00001xxx).\n The CIDR block \"255.0.0.16/32\" covers the last address.\n Note that while the CIDR block \"255.0.0.0/28\" does cover all the addresses, it also includes addresses outside of the range, so we cannot use it.\n \n Example 2:\n \n >>> ipToCIDR(ip = \"117.145.102.62\", n = 8)\n >>> [\"117.145.102.62/31\",\"117.145.102.64/30\",\"117.145.102.68/31\"]\n \"\"\"\n"}
{"task_id": "open-the-lock", "prompt": "def openLock(deadends: List[str], target: str) -> int:\n \"\"\"\n You have a lock in front of you with 4 circular wheels. Each wheel has 10 slots: '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'. The wheels can rotate freely and wrap around: for example we can turn '9' to be '0', or '0' to be '9'. Each move consists of turning one wheel one slot.\n The lock initially starts at '0000', a string representing the state of the 4 wheels.\n You are given a list of deadends dead ends, meaning if the lock displays any of these codes, the wheels of the lock will stop turning and you will be unable to open it.\n Given a target representing the value of the wheels that will unlock the lock, return the minimum total number of turns required to open the lock, or -1 if it is impossible.\n \n Example 1:\n \n >>> openLock(deadends = [\"0201\",\"0101\",\"0102\",\"1212\",\"2002\"], target = \"0202\")\n >>> 6\n Explanation:\n A sequence of valid moves would be \"0000\" -> \"1000\" -> \"1100\" -> \"1200\" -> \"1201\" -> \"1202\" -> \"0202\".\n Note that a sequence like \"0000\" -> \"0001\" -> \"0002\" -> \"0102\" -> \"0202\" would be invalid,\n because the wheels of the lock become stuck after the display becomes the dead end \"0102\".\n \n Example 2:\n \n >>> openLock(deadends = [\"8888\"], target = \"0009\")\n >>> 1\n Explanation: We can turn the last wheel in reverse to move from \"0000\" -> \"0009\".\n \n Example 3:\n \n >>> openLock(deadends = [\"8887\",\"8889\",\"8878\",\"8898\",\"8788\",\"8988\",\"7888\",\"9888\"], target = \"8888\")\n >>> -1\n Explanation: We cannot reach the target without getting stuck.\n \"\"\"\n"}
{"task_id": "cracking-the-safe", "prompt": "def crackSafe(n: int, k: int) -> str:\n \"\"\"\n There is a safe protected by a password. The password is a sequence of n digits where each digit can be in the range [0, k - 1].\n The safe has a peculiar way of checking the password. When you enter in a sequence, it checks the most recent n digits that were entered each time you type a digit.\n \n For example, the correct password is \"345\" and you enter in \"012345\":\n \n \n After typing 0, the most recent 3 digits is \"0\", which is incorrect.\n After typing 1, the most recent 3 digits is \"01\", which is incorrect.\n After typing 2, the most recent 3 digits is \"012\", which is incorrect.\n After typing 3, the most recent 3 digits is \"123\", which is incorrect.\n After typing 4, the most recent 3 digits is \"234\", which is incorrect.\n After typing 5, the most recent 3 digits is \"345\", which is correct and the safe unlocks.\n \n \n \n Return any string of minimum length that will unlock the safe at some point of entering it.\n \n Example 1:\n \n >>> crackSafe(n = 1, k = 2)\n >>> \"10\"\n Explanation: The password is a single digit, so enter each digit. \"01\" would also unlock the safe.\n \n Example 2:\n \n >>> crackSafe(n = 2, k = 2)\n >>> \"01100\"\n Explanation: For each possible password:\n - \"00\" is typed in starting from the 4th digit.\n - \"01\" is typed in starting from the 1st digit.\n - \"10\" is typed in starting from the 3rd digit.\n - \"11\" is typed in starting from the 2nd digit.\n Thus \"01100\" will unlock the safe. \"10011\", and \"11001\" would also unlock the safe.\n \"\"\"\n"}
{"task_id": "reach-a-number", "prompt": "def reachNumber(target: int) -> int:\n \"\"\"\n You are standing at position 0 on an infinite number line. There is a destination at position target.\n You can make some number of moves numMoves so that:\n \n On each move, you can either go left or right.\n During the ith move (starting from i == 1 to i == numMoves), you take i steps in the chosen direction.\n \n Given the integer target, return the minimum number of moves required (i.e., the minimum numMoves) to reach the destination.\n \n Example 1:\n \n >>> reachNumber(target = 2)\n >>> 3\n Explanation:\n On the 1st move, we step from 0 to 1 (1 step).\n On the 2nd move, we step from 1 to -1 (2 steps).\n On the 3rd move, we step from -1 to 2 (3 steps).\n \n Example 2:\n \n >>> reachNumber(target = 3)\n >>> 2\n Explanation:\n On the 1st move, we step from 0 to 1 (1 step).\n On the 2nd move, we step from 1 to 3 (2 steps).\n \"\"\"\n"}
{"task_id": "pour-water", "prompt": "def pourWater(heights: List[int], volume: int, k: int) -> List[int]:\n \"\"\"\n You are given an elevation map represents as an integer array heights where heights[i] representing the height of the terrain at index i. The width at each index is 1. You are also given two integers volume and k. volume units of water will fall at index k.\n Water first drops at the index k and rests on top of the highest terrain or water at that index. Then, it flows according to the following rules:\n \n If the droplet would eventually fall by moving left, then move left.\n Otherwise, if the droplet would eventually fall by moving right, then move right.\n Otherwise, rise to its current position.\n \n Here, \"eventually fall\" means that the droplet will eventually be at a lower level if it moves in that direction. Also, level means the height of the terrain plus any water in that column.\n We can assume there is infinitely high terrain on the two sides out of bounds of the array. Also, there could not be partial water being spread out evenly on more than one grid block, and each unit of water has to be in exactly one block.\n \n Example 1:\n \n \n >>> pourWater(heights = [2,1,1,2,1,2,2], volume = 4, k = 3)\n >>> [2,2,2,3,2,2,2]\n Explanation:\n The first drop of water lands at index k = 3. When moving left or right, the water can only move to the same level or a lower level. (By level, we mean the total height of the terrain plus any water in that column.)\n Since moving left will eventually make it fall, it moves left. (A droplet \"made to fall\" means go to a lower height than it was at previously.) Since moving left will not make it fall, it stays in place.\n \n The next droplet falls at index k = 3. Since the new droplet moving left will eventually make it fall, it moves left. Notice that the droplet still preferred to move left, even though it could move right (and moving right makes it fall quicker.)\n \n The third droplet falls at index k = 3. Since moving left would not eventually make it fall, it tries to move right. Since moving right would eventually make it fall, it moves right.\n \n Finally, the fourth droplet falls at index k = 3. Since moving left would not eventually make it fall, it tries to move right. Since moving right would not eventually make it fall, it stays in place.\n \n \n Example 2:\n \n >>> pourWater(heights = [1,2,3,4], volume = 2, k = 2)\n >>> [2,3,3,4]\n Explanation: The last droplet settles at index 1, since moving further left would not cause it to eventually fall to a lower height.\n \n Example 3:\n \n >>> pourWater(heights = [3,1,3], volume = 5, k = 1)\n >>> [4,4,4]\n \"\"\"\n"}
{"task_id": "pyramid-transition-matrix", "prompt": "def pyramidTransition(bottom: str, allowed: List[str]) -> bool:\n \"\"\"\n You are stacking blocks to form a pyramid. Each block has a color, which is represented by a single letter. Each row of blocks contains one less block than the row beneath it and is centered on top.\n To make the pyramid aesthetically pleasing, there are only specific triangular patterns that are allowed. A triangular pattern consists of a single block stacked on top of two blocks. The patterns are given\u00a0as a list of\u00a0three-letter strings allowed, where the first two characters of a pattern represent the left and right bottom blocks respectively, and the third character is the top block.\n \n For example, \"ABC\" represents a triangular pattern with a 'C' block stacked on top of an 'A' (left) and 'B' (right) block. Note that this is different from \"BAC\" where 'B' is on the left bottom and 'A' is on the right bottom.\n \n You start with a bottom row of blocks bottom, given as a single string, that you must use as the base of the pyramid.\n Given bottom and allowed, return true if you can build the pyramid all the way to the top such that every triangular pattern in the pyramid is in allowed, or false otherwise.\n \n Example 1:\n \n \n >>> pyramidTransition(bottom = \"BCD\", allowed = [\"BCC\",\"CDE\",\"CEA\",\"FFF\"])\n >>> true\n Explanation: The allowed triangular patterns are shown on the right.\n Starting from the bottom (level 3), we can build \"CE\" on level 2 and then build \"A\" on level 1.\n There are three triangular patterns in the pyramid, which are \"BCC\", \"CDE\", and \"CEA\". All are allowed.\n \n Example 2:\n \n \n >>> pyramidTransition(bottom = \"AAAA\", allowed = [\"AAB\",\"AAC\",\"BCD\",\"BBE\",\"DEF\"])\n >>> false\n Explanation: The allowed triangular patterns are shown on the right.\n Starting from the bottom (level 4), there are multiple ways to build level 3, but trying all the possibilites, you will get always stuck before building level 1.\n \"\"\"\n"}
{"task_id": "set-intersection-size-at-least-two", "prompt": "def intersectionSizeTwo(intervals: List[List[int]]) -> int:\n \"\"\"\n You are given a 2D integer array intervals where intervals[i] = [starti, endi] represents all the integers from starti to endi inclusively.\n A containing set is an array nums where each interval from intervals has at least two integers in nums.\n \n For example, if intervals = [[1,3], [3,7], [8,9]], then [1,2,4,7,8,9] and [2,3,4,8,9] are containing sets.\n \n Return the minimum possible size of a containing set.\n \n Example 1:\n \n >>> intersectionSizeTwo(intervals = [[1,3],[3,7],[8,9]])\n >>> 5\n Explanation: let nums = [2, 3, 4, 8, 9].\n It can be shown that there cannot be any containing array of size 4.\n \n Example 2:\n \n >>> intersectionSizeTwo(intervals = [[1,3],[1,4],[2,5],[3,5]])\n >>> 3\n Explanation: let nums = [2, 3, 4].\n It can be shown that there cannot be any containing array of size 2.\n \n Example 3:\n \n >>> intersectionSizeTwo(intervals = [[1,2],[2,3],[2,4],[4,5]])\n >>> 5\n Explanation: let nums = [1, 2, 3, 4, 5].\n It can be shown that there cannot be any containing array of size 4.\n \"\"\"\n"}
{"task_id": "bold-words-in-string", "prompt": "def boldWords(words: List[str], s: str) -> str:\n \"\"\"\n Given an array of keywords words and a string s, make all appearances of all keywords words[i] in s bold. Any letters between and tags become bold.\n Return s after adding the bold tags. The returned string should use the least number of tags possible, and the tags should form a valid combination.\n \n Example 1:\n \n >>> boldWords(words = [\"ab\",\"bc\"], s = \"aabcd\")\n >>> \"aabcd\"\n Explanation: Note that returning \"aabcd\" would use more tags, so it is incorrect.\n \n Example 2:\n \n >>> boldWords(words = [\"ab\",\"cb\"], s = \"aabcd\")\n >>> \"aabcd\"\n \"\"\"\n"}
{"task_id": "find-anagram-mappings", "prompt": "def anagramMappings(nums1: List[int], nums2: List[int]) -> List[int]:\n \"\"\"\n You are given two integer arrays nums1 and nums2 where nums2 is an anagram of nums1. Both arrays may contain duplicates.\n Return an index mapping array mapping from nums1 to nums2 where mapping[i] = j means the ith element in nums1 appears in nums2 at index j. If there are multiple answers, return any of them.\n An array a is an anagram of an array b means b is made by randomizing the order of the elements in a.\n \n Example 1:\n \n >>> anagramMappings(nums1 = [12,28,46,32,50], nums2 = [50,12,32,46,28])\n >>> [1,4,3,2,0]\n Explanation: As mapping[0] = 1 because the 0th element of nums1 appears at nums2[1], and mapping[1] = 4 because the 1st element of nums1 appears at nums2[4], and so on.\n \n Example 2:\n \n >>> anagramMappings(nums1 = [84,46], nums2 = [84,46])\n >>> [0,1]\n \"\"\"\n"}
{"task_id": "special-binary-string", "prompt": "def makeLargestSpecial(s: str) -> str:\n \"\"\"\n Special binary strings are binary strings with the following two properties:\n \n The number of 0's is equal to the number of 1's.\n Every prefix of the binary string has at least as many 1's as 0's.\n \n You are given a special binary string s.\n A move consists of choosing two consecutive, non-empty, special substrings of s, and swapping them. Two strings are consecutive if the last character of the first string is exactly one index before the first character of the second string.\n Return the lexicographically largest resulting string possible after applying the mentioned operations on the string.\n \n Example 1:\n \n >>> makeLargestSpecial(s = \"11011000\")\n >>> \"11100100\"\n Explanation: The strings \"10\" [occuring at s[1]] and \"1100\" [at s[3]] are swapped.\n This is the lexicographically largest string possible after some number of swaps.\n \n Example 2:\n \n >>> makeLargestSpecial(s = \"10\")\n >>> \"10\"\n \"\"\"\n"}
{"task_id": "prime-number-of-set-bits-in-binary-representation", "prompt": "def countPrimeSetBits(left: int, right: int) -> int:\n \"\"\"\n Given two integers left and right, return the count of numbers in the inclusive range [left, right] having a prime number of set bits in their binary representation.\n Recall that the number of set bits an integer has is the number of 1's present when written in binary.\n \n For example, 21 written in binary is 10101, which has 3 set bits.\n \n \n Example 1:\n \n >>> countPrimeSetBits(left = 6, right = 10)\n >>> 4\n Explanation:\n 6 -> 110 (2 set bits, 2 is prime)\n 7 -> 111 (3 set bits, 3 is prime)\n 8 -> 1000 (1 set bit, 1 is not prime)\n 9 -> 1001 (2 set bits, 2 is prime)\n 10 -> 1010 (2 set bits, 2 is prime)\n 4 numbers have a prime number of set bits.\n \n Example 2:\n \n >>> countPrimeSetBits(left = 10, right = 15)\n >>> 5\n Explanation:\n 10 -> 1010 (2 set bits, 2 is prime)\n 11 -> 1011 (3 set bits, 3 is prime)\n 12 -> 1100 (2 set bits, 2 is prime)\n 13 -> 1101 (3 set bits, 3 is prime)\n 14 -> 1110 (3 set bits, 3 is prime)\n 15 -> 1111 (4 set bits, 4 is not prime)\n 5 numbers have a prime number of set bits.\n \"\"\"\n"}
{"task_id": "partition-labels", "prompt": "def partitionLabels(s: str) -> List[int]:\n \"\"\"\n You are given a string s. We want to partition the string into as many parts as possible so that each letter appears in at most one part. For example, the string \"ababcc\" can be partitioned into [\"abab\", \"cc\"], but partitions such as [\"aba\", \"bcc\"] or [\"ab\", \"ab\", \"cc\"] are invalid.\n Note that the partition is done so that after concatenating all the parts in order, the resultant string should be s.\n Return a list of integers representing the size of these parts.\n \n Example 1:\n \n >>> partitionLabels(s = \"ababcbacadefegdehijhklij\")\n >>> [9,7,8]\n Explanation:\n The partition is \"ababcbaca\", \"defegde\", \"hijhklij\".\n This is a partition so that each letter appears in at most one part.\n A partition like \"ababcbacadefegde\", \"hijhklij\" is incorrect, because it splits s into less parts.\n \n Example 2:\n \n >>> partitionLabels(s = \"eccbbbbdec\")\n >>> [10]\n \"\"\"\n"}
{"task_id": "largest-plus-sign", "prompt": "def orderOfLargestPlusSign(n: int, mines: List[List[int]]) -> int:\n \"\"\"\n You are given an integer n. You have an n x n binary grid grid with all values initially 1's except for some indices given in the array mines. The ith element of the array mines is defined as mines[i] = [xi, yi] where grid[xi][yi] == 0.\n Return the order of the largest axis-aligned plus sign of 1's contained in grid. If there is none, return 0.\n An axis-aligned plus sign of 1's of order k has some center grid[r][c] == 1 along with four arms of length k - 1 going up, down, left, and right, and made of 1's. Note that there could be 0's or 1's beyond the arms of the plus sign, only the relevant area of the plus sign is checked for 1's.\n \n Example 1:\n \n \n >>> orderOfLargestPlusSign(n = 5, mines = [[4,2]])\n >>> 2\n Explanation: In the above grid, the largest plus sign can only be of order 2. One of them is shown.\n \n Example 2:\n \n \n >>> orderOfLargestPlusSign(n = 1, mines = [[0,0]])\n >>> 0\n Explanation: There is no plus sign, so return 0.\n \"\"\"\n"}
{"task_id": "couples-holding-hands", "prompt": "def minSwapsCouples(row: List[int]) -> int:\n \"\"\"\n There are n couples sitting in 2n seats arranged in a row and want to hold hands.\n The people and seats are represented by an integer array row where row[i] is the ID of the person sitting in the ith seat. The couples are numbered in order, the first couple being (0, 1), the second couple being (2, 3), and so on with the last couple being (2n - 2, 2n - 1).\n Return the minimum number of swaps so that every couple is sitting side by side. A swap consists of choosing any two people, then they stand up and switch seats.\n \n Example 1:\n \n >>> minSwapsCouples(row = [0,2,1,3])\n >>> 1\n Explanation: We only need to swap the second (row[1]) and third (row[2]) person.\n \n Example 2:\n \n >>> minSwapsCouples(row = [3,2,0,1])\n >>> 0\n Explanation: All couples are already seated side by side.\n \"\"\"\n"}
{"task_id": "toeplitz-matrix", "prompt": "def isToeplitzMatrix(matrix: List[List[int]]) -> bool:\n \"\"\"\n Given an m x n matrix, return\u00a0true\u00a0if the matrix is Toeplitz. Otherwise, return false.\n A matrix is Toeplitz if every diagonal from top-left to bottom-right has the same elements.\n \n Example 1:\n \n \n >>> isToeplitzMatrix(matrix = [[1,2,3,4],[5,1,2,3],[9,5,1,2]])\n >>> true\n Explanation:\n In the above grid, the\u00a0diagonals are:\n \"[9]\", \"[5, 5]\", \"[1, 1, 1]\", \"[2, 2, 2]\", \"[3, 3]\", \"[4]\".\n In each diagonal all elements are the same, so the answer is True.\n \n Example 2:\n \n \n >>> isToeplitzMatrix(matrix = [[1,2],[2,2]])\n >>> false\n Explanation:\n The diagonal \"[1, 2]\" has different elements.\n \"\"\"\n"}
{"task_id": "reorganize-string", "prompt": "def reorganizeString(s: str) -> str:\n \"\"\"\n Given a string s, rearrange the characters of s so that any two adjacent characters are not the same.\n Return any possible rearrangement of s or return \"\" if not possible.\n \n Example 1:\n >>> reorganizeString(s = \"aab\")\n >>> \"aba\"\n Example 2:\n >>> reorganizeString(s = \"aaab\")\n >>> \"\"\n \"\"\"\n"}
{"task_id": "max-chunks-to-make-sorted-ii", "prompt": "def maxChunksToSorted(arr: List[int]) -> int:\n \"\"\"\n You are given an integer array arr.\n We split arr into some number of chunks (i.e., partitions), and individually sort each chunk. After concatenating them, the result should equal the sorted array.\n Return the largest number of chunks we can make to sort the array.\n \n Example 1:\n \n >>> maxChunksToSorted(arr = [5,4,3,2,1])\n >>> 1\n Explanation:\n Splitting into two or more chunks will not return the required result.\n For example, splitting into [5, 4], [3, 2, 1] will result in [4, 5, 1, 2, 3], which isn't sorted.\n \n Example 2:\n \n >>> maxChunksToSorted(arr = [2,1,3,4,4])\n >>> 4\n Explanation:\n We can split into two chunks, such as [2, 1], [3, 4, 4].\n However, splitting into [2, 1], [3], [4], [4] is the highest number of chunks possible.\n \"\"\"\n"}
{"task_id": "max-chunks-to-make-sorted", "prompt": "def maxChunksToSorted(arr: List[int]) -> int:\n \"\"\"\n You are given an integer array arr of length n that represents a permutation of the integers in the range [0, n - 1].\n We split arr into some number of chunks (i.e., partitions), and individually sort each chunk. After concatenating them, the result should equal the sorted array.\n Return the largest number of chunks we can make to sort the array.\n \n Example 1:\n \n >>> maxChunksToSorted(arr = [4,3,2,1,0])\n >>> 1\n Explanation:\n Splitting into two or more chunks will not return the required result.\n For example, splitting into [4, 3], [2, 1, 0] will result in [3, 4, 0, 1, 2], which isn't sorted.\n \n Example 2:\n \n >>> maxChunksToSorted(arr = [1,0,2,3,4])\n >>> 4\n Explanation:\n We can split into two chunks, such as [1, 0], [2, 3, 4].\n However, splitting into [1, 0], [2], [3], [4] is the highest number of chunks possible.\n \"\"\"\n"}
{"task_id": "basic-calculator-iv", "prompt": "def basicCalculatorIV(expression: str, evalvars: List[str], evalints: List[int]) -> List[str]:\n \"\"\"\n Given an expression such as expression = \"e + 8 - a + 5\" and an evaluation map such as {\"e\": 1} (given in terms of evalvars = [\"e\"] and evalints = [1]), return a list of tokens representing the simplified expression, such as [\"-1*a\",\"14\"]\n \n An expression alternates chunks and symbols, with a space separating each chunk and symbol.\n A chunk is either an expression in parentheses, a variable, or a non-negative integer.\n A variable is a string of lowercase letters (not including digits.) Note that variables can be multiple letters, and note that variables never have a leading coefficient or unary operator like \"2x\" or \"-x\".\n \n Expressions are evaluated in the usual order: brackets first, then multiplication, then addition and subtraction.\n \n For example, expression = \"1 + 2 * 3\" has an answer of [\"7\"].\n \n The format of the output is as follows:\n \n For each term of free variables with a non-zero coefficient, we write the free variables within a term in sorted order lexicographically.\n \n For example, we would never write a term like \"b*a*c\", only \"a*b*c\".\n \n \n Terms have degrees equal to the number of free variables being multiplied, counting multiplicity. We write the largest degree terms of our answer first, breaking ties by lexicographic order ignoring the leading coefficient of the term.\n \n For example, \"a*a*b*c\" has degree 4.\n \n \n The leading coefficient of the term is placed directly to the left with an asterisk separating it from the variables (if they exist.) A leading coefficient of 1 is still printed.\n An example of a well-formatted answer is [\"-2*a*a*a\", \"3*a*a*b\", \"3*b*b\", \"4*a\", \"5*c\", \"-6\"].\n Terms (including constant terms) with coefficient 0 are not included.\n \n For example, an expression of \"0\" has an output of [].\n \n \n \n Note: You may assume that the given expression is always valid. All intermediate results will be in the range of [-231, 231 - 1].\n \n Example 1:\n \n >>> basicCalculatorIV(expression = \"e + 8 - a + 5\", evalvars = [\"e\"], evalints = [1])\n >>> [\"-1*a\",\"14\"]\n \n Example 2:\n \n >>> basicCalculatorIV(expression = \"e - 8 + temperature - pressure\", evalvars = [\"e\", \"temperature\"], evalints = [1, 12])\n >>> [\"-1*pressure\",\"5\"]\n \n Example 3:\n \n >>> basicCalculatorIV(expression = \"(e + 8) * (e - 8)\", evalvars = [], evalints = [])\n >>> [\"1*e*e\",\"-64\"]\n \"\"\"\n"}
{"task_id": "jewels-and-stones", "prompt": "def numJewelsInStones(jewels: str, stones: str) -> int:\n \"\"\"\n You're given strings jewels representing the types of stones that are jewels, and stones representing the stones you have. Each character in stones is a type of stone you have. You want to know how many of the stones you have are also jewels.\n Letters are case sensitive, so \"a\" is considered a different type of stone from \"A\".\n \n Example 1:\n >>> numJewelsInStones(jewels = \"aA\", stones = \"aAAbbbb\")\n >>> 3\n Example 2:\n >>> numJewelsInStones(jewels = \"z\", stones = \"ZZ\")\n >>> 0\n \"\"\"\n"}
{"task_id": "basic-calculator-iii", "prompt": "def calculate(s: str) -> int:\n \"\"\"\n Implement a basic calculator to evaluate a simple expression string.\n The expression string contains only non-negative integers, '+', '-', '*', '/' operators, and open '(' and closing parentheses ')'. The integer division should truncate toward zero.\n You may assume that the given expression is always valid. All intermediate results will be in the range of [-231, 231 - 1].\n Note: You are not allowed to use any built-in function which evaluates strings as mathematical expressions, such as eval().\n \n Example 1:\n \n >>> calculate(s = \"1+1\")\n >>> 2\n \n Example 2:\n \n >>> calculate(s = \"6-4/2\")\n >>> 4\n \n Example 3:\n \n >>> calculate(s = \"2*(5+5*2)/3+(6/2+8)\")\n >>> 21\n \"\"\"\n"}
{"task_id": "sliding-puzzle", "prompt": "def slidingPuzzle(board: List[List[int]]) -> int:\n \"\"\"\n On an 2 x 3 board, there are five tiles labeled from 1 to 5, and an empty square represented by 0. A move consists of choosing 0 and a 4-directionally adjacent number and swapping it.\n The state of the board is solved if and only if the board is [[1,2,3],[4,5,0]].\n Given the puzzle board board, return the least number of moves required so that the state of the board is solved. If it is impossible for the state of the board to be solved, return -1.\n \n Example 1:\n \n \n >>> slidingPuzzle(board = [[1,2,3],[4,0,5]])\n >>> 1\n Explanation: Swap the 0 and the 5 in one move.\n \n Example 2:\n \n \n >>> slidingPuzzle(board = [[1,2,3],[5,4,0]])\n >>> -1\n Explanation: No number of moves will make the board solved.\n \n Example 3:\n \n \n >>> slidingPuzzle(board = [[4,1,2],[5,0,3]])\n >>> 5\n Explanation: 5 is the smallest number of moves that solves the board.\n An example path:\n After move 0: [[4,1,2],[5,0,3]]\n After move 1: [[4,1,2],[0,5,3]]\n After move 2: [[0,1,2],[4,5,3]]\n After move 3: [[1,0,2],[4,5,3]]\n After move 4: [[1,2,0],[4,5,3]]\n After move 5: [[1,2,3],[4,5,0]]\n \"\"\"\n"}
{"task_id": "minimize-max-distance-to-gas-station", "prompt": "def minmaxGasDist(stations: List[int], k: int) -> float:\n \"\"\"\n You are given an integer array stations that represents the positions of the gas stations on the x-axis. You are also given an integer k.\n You should add k new gas stations. You can add the stations anywhere on the x-axis, and not necessarily on an integer position.\n Let penalty() be the maximum distance between adjacent gas stations after adding the k new stations.\n Return the smallest possible value of penalty(). Answers within 10-6 of the actual answer will be accepted.\n \n Example 1:\n >>> minmaxGasDist(stations = [1,2,3,4,5,6,7,8,9,10], k = 9)\n >>> 0.50000\n Example 2:\n >>> minmaxGasDist(stations = [23,24,36,39,46,56,57,65,84,98], k = 1)\n >>> 14.00000\n \"\"\"\n"}
{"task_id": "global-and-local-inversions", "prompt": "def isIdealPermutation(nums: List[int]) -> bool:\n \"\"\"\n You are given an integer array nums of length n which represents a permutation of all the integers in the range [0, n - 1].\n The number of global inversions is the number of the different pairs (i, j) where:\n \n 0 <= i < j < n\n nums[i] > nums[j]\n \n The number of local inversions is the number of indices i where:\n \n 0 <= i < n - 1\n nums[i] > nums[i + 1]\n \n Return true if the number of global inversions is equal to the number of local inversions.\n \n Example 1:\n \n >>> isIdealPermutation(nums = [1,0,2])\n >>> true\n Explanation: There is 1 global inversion and 1 local inversion.\n \n Example 2:\n \n >>> isIdealPermutation(nums = [1,2,0])\n >>> false\n Explanation: There are 2 global inversions and 1 local inversion.\n \"\"\"\n"}
{"task_id": "swap-adjacent-in-lr-string", "prompt": "def canTransform(start: str, result: str) -> bool:\n \"\"\"\n In a string composed of 'L', 'R', and 'X' characters, like \"RXXLRXRXL\", a move consists of either replacing one occurrence of \"XL\" with \"LX\", or replacing one occurrence of \"RX\" with \"XR\". Given the starting string start and the ending string result, return True if and only if there exists a sequence of moves to transform start to result.\n \n Example 1:\n \n >>> canTransform(start = \"RXXLRXRXL\", result = \"XRLXXRRLX\")\n >>> true\n Explanation: We can transform start to result following these steps:\n RXXLRXRXL ->\n XRXLRXRXL ->\n XRLXRXRXL ->\n XRLXXRRXL ->\n XRLXXRRLX\n \n Example 2:\n \n >>> canTransform(start = \"X\", result = \"L\")\n >>> false\n \"\"\"\n"}
{"task_id": "swim-in-rising-water", "prompt": "def swimInWater(grid: List[List[int]]) -> int:\n \"\"\"\n You are given an n x n integer matrix grid where each value grid[i][j] represents the elevation at that point (i, j).\n The rain starts to fall. At time t, the depth of the water everywhere is t. You can swim from a square to another 4-directionally adjacent square if and only if the elevation of both squares individually are at most t. You can swim infinite distances in zero time. Of course, you must stay within the boundaries of the grid during your swim.\n Return the least time until you can reach the bottom right square (n - 1, n - 1) if you start at the top left square (0, 0).\n \n Example 1:\n \n \n >>> swimInWater(grid = [[0,2],[1,3]])\n >>> 3\n Explanation:\n At time 0, you are in grid location (0, 0).\n You cannot go anywhere else because 4-directionally adjacent neighbors have a higher elevation than t = 0.\n You cannot reach point (1, 1) until time 3.\n When the depth of water is 3, we can swim anywhere inside the grid.\n \n Example 2:\n \n \n >>> swimInWater(grid = [[0,1,2,3,4],[24,23,22,21,5],[12,13,14,15,16],[11,17,18,19,20],[10,9,8,7,6]])\n >>> 16\n Explanation: The final route is shown.\n We need to wait until time 16 so that (0, 0) and (4, 4) are connected.\n \"\"\"\n"}
{"task_id": "k-th-symbol-in-grammar", "prompt": "def kthGrammar(n: int, k: int) -> int:\n \"\"\"\n We build a table of n rows (1-indexed). We start by writing 0 in the 1st row. Now in every subsequent row, we look at the previous row and replace each occurrence of 0 with 01, and each occurrence of 1 with 10.\n \n For example, for n = 3, the 1st row is 0, the 2nd row is 01, and the 3rd row is 0110.\n \n Given two integer n and k, return the kth (1-indexed) symbol in the nth row of a table of n rows.\n \n Example 1:\n \n >>> kthGrammar(n = 1, k = 1)\n >>> 0\n Explanation: row 1: 0\n \n Example 2:\n \n >>> kthGrammar(n = 2, k = 1)\n >>> 0\n Explanation:\n row 1: 0\n row 2: 01\n \n Example 3:\n \n >>> kthGrammar(n = 2, k = 2)\n >>> 1\n Explanation:\n row 1: 0\n row 2: 01\n \"\"\"\n"}
{"task_id": "reaching-points", "prompt": "def reachingPoints(sx: int, sy: int, tx: int, ty: int) -> bool:\n \"\"\"\n Given four integers sx, sy, tx, and ty, return true if it is possible to convert the point (sx, sy) to the point (tx, ty) through some operations, or false otherwise.\n The allowed operation on some point (x, y) is to convert it to either (x, x + y) or (x + y, y).\n \n Example 1:\n \n >>> reachingPoints(sx = 1, sy = 1, tx = 3, ty = 5)\n >>> true\n Explanation:\n One series of moves that transforms the starting point to the target is:\n (1, 1) -> (1, 2)\n (1, 2) -> (3, 2)\n (3, 2) -> (3, 5)\n \n Example 2:\n \n >>> reachingPoints(sx = 1, sy = 1, tx = 2, ty = 2)\n >>> false\n \n Example 3:\n \n >>> reachingPoints(sx = 1, sy = 1, tx = 1, ty = 1)\n >>> true\n \"\"\"\n"}
{"task_id": "rabbits-in-forest", "prompt": "def numRabbits(answers: List[int]) -> int:\n \"\"\"\n There is a forest with an unknown number of rabbits. We asked n rabbits \"How many rabbits have the same color as you?\" and collected the answers in an integer array answers where answers[i] is the answer of the ith rabbit.\n Given the array answers, return the minimum number of rabbits that could be in the forest.\n \n Example 1:\n \n >>> numRabbits(answers = [1,1,2])\n >>> 5\n Explanation:\n The two rabbits that answered \"1\" could both be the same color, say red.\n The rabbit that answered \"2\" can't be red or the answers would be inconsistent.\n Say the rabbit that answered \"2\" was blue.\n Then there should be 2 other blue rabbits in the forest that didn't answer into the array.\n The smallest possible number of rabbits in the forest is therefore 5: 3 that answered plus 2 that didn't.\n \n Example 2:\n \n >>> numRabbits(answers = [10,10,10])\n >>> 11\n \"\"\"\n"}
{"task_id": "transform-to-chessboard", "prompt": "def movesToChessboard(board: List[List[int]]) -> int:\n \"\"\"\n You are given an n x n binary grid board. In each move, you can swap any two rows with each other, or any two columns with each other.\n Return the minimum number of moves to transform the board into a chessboard board. If the task is impossible, return -1.\n A chessboard board is a board where no 0's and no 1's are 4-directionally adjacent.\n \n Example 1:\n \n \n >>> movesToChessboard(board = [[0,1,1,0],[0,1,1,0],[1,0,0,1],[1,0,0,1]])\n >>> 2\n Explanation: One potential sequence of moves is shown.\n The first move swaps the first and second column.\n The second move swaps the second and third row.\n \n Example 2:\n \n \n >>> movesToChessboard(board = [[0,1],[1,0]])\n >>> 0\n Explanation: Also note that the board with 0 in the top left corner, is also a valid chessboard.\n \n Example 3:\n \n \n >>> movesToChessboard(board = [[1,0],[1,0]])\n >>> -1\n Explanation: No matter what sequence of moves you make, you cannot end with a valid chessboard.\n \"\"\"\n"}
{"task_id": "minimum-distance-between-bst-nodes", "prompt": "# class TreeNode:\n# def __init__(val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def minDiffInBST(root: Optional[TreeNode]) -> int:\n \"\"\"\n Given the root of a Binary Search Tree (BST), return the minimum difference between the values of any two different nodes in the tree.\n \n Example 1:\n \n \n >>> __init__(root = [4,2,6,1,3])\n >>> 1\n \n Example 2:\n \n \n >>> __init__(root = [1,0,48,null,null,12,49])\n >>> 1\n \"\"\"\n"}
{"task_id": "letter-case-permutation", "prompt": "def letterCasePermutation(s: str) -> List[str]:\n \"\"\"\n Given a string s, you\u00a0can transform every letter individually to be lowercase or uppercase to create another string.\n Return a list of all possible strings we could create. Return the output in any order.\n \n Example 1:\n \n >>> letterCasePermutation(s = \"a1b2\")\n >>> [\"a1b2\",\"a1B2\",\"A1b2\",\"A1B2\"]\n \n Example 2:\n \n >>> letterCasePermutation(s = \"3z4\")\n >>> [\"3z4\",\"3Z4\"]\n \"\"\"\n"}
{"task_id": "is-graph-bipartite", "prompt": "def isBipartite(graph: List[List[int]]) -> bool:\n \"\"\"\n There is an undirected graph with n nodes, where each node is numbered between 0 and n - 1. You are given a 2D array graph, where graph[u] is an array of nodes that node u is adjacent to. More formally, for each v in graph[u], there is an undirected edge between node u and node v. The graph has the following properties:\n \n There are no self-edges (graph[u] does not contain u).\n There are no parallel edges (graph[u] does not contain duplicate values).\n If v is in graph[u], then u is in graph[v] (the graph is undirected).\n The graph may not be connected, meaning there may be two nodes u and v such that there is no path between them.\n \n A graph is bipartite if the nodes can be partitioned into two independent sets A and B such that every edge in the graph connects a node in set A and a node in set B.\n Return true if and only if it is bipartite.\n \n Example 1:\n \n \n >>> isBipartite(graph = [[1,2,3],[0,2],[0,1,3],[0,2]])\n >>> false\n Explanation: There is no way to partition the nodes into two independent sets such that every edge connects a node in one and a node in the other.\n Example 2:\n \n \n >>> isBipartite(graph = [[1,3],[0,2],[1,3],[0,2]])\n >>> true\n Explanation: We can partition the nodes into two sets: {0, 2} and {1, 3}.\n \"\"\"\n"}
{"task_id": "k-th-smallest-prime-fraction", "prompt": "def kthSmallestPrimeFraction(arr: List[int], k: int) -> List[int]:\n \"\"\"\n You are given a sorted integer array arr containing 1 and prime numbers, where all the integers of arr are unique. You are also given an integer k.\n For every i and j where 0 <= i < j < arr.length, we consider the fraction arr[i] / arr[j].\n Return the kth smallest fraction considered. Return your answer as an array of integers of size 2, where answer[0] == arr[i] and answer[1] == arr[j].\n \n Example 1:\n \n >>> kthSmallestPrimeFraction(arr = [1,2,3,5], k = 3)\n >>> [2,5]\n Explanation: The fractions to be considered in sorted order are:\n 1/5, 1/3, 2/5, 1/2, 3/5, and 2/3.\n The third fraction is 2/5.\n \n Example 2:\n \n >>> kthSmallestPrimeFraction(arr = [1,7], k = 1)\n >>> [1,7]\n \"\"\"\n"}
{"task_id": "cheapest-flights-within-k-stops", "prompt": "def findCheapestPrice(n: int, flights: List[List[int]], src: int, dst: int, k: int) -> int:\n \"\"\"\n There are n cities connected by some number of flights. You are given an array flights where flights[i] = [fromi, toi, pricei] indicates that there is a flight from city fromi to city toi with cost pricei.\n You are also given three integers src, dst, and k, return the cheapest price from src to dst with at most k stops. If there is no such route, return -1.\n \n Example 1:\n \n \n >>> findCheapestPrice(n = 4, flights = [[0,1,100],[1,2,100],[2,0,100],[1,3,600],[2,3,200]], src = 0, dst = 3, k = 1)\n >>> 700\n Explanation:\n The graph is shown above.\n The optimal path with at most 1 stop from city 0 to 3 is marked in red and has cost 100 + 600 = 700.\n Note that the path through cities [0,1,2,3] is cheaper but is invalid because it uses 2 stops.\n \n Example 2:\n \n \n >>> findCheapestPrice(n = 3, flights = [[0,1,100],[1,2,100],[0,2,500]], src = 0, dst = 2, k = 1)\n >>> 200\n Explanation:\n The graph is shown above.\n The optimal path with at most 1 stop from city 0 to 2 is marked in red and has cost 100 + 100 = 200.\n \n Example 3:\n \n \n >>> findCheapestPrice(n = 3, flights = [[0,1,100],[1,2,100],[0,2,500]], src = 0, dst = 2, k = 0)\n >>> 500\n Explanation:\n The graph is shown above.\n The optimal path with no stops from city 0 to 2 is marked in red and has cost 500.\n \"\"\"\n"}
{"task_id": "rotated-digits", "prompt": "def rotatedDigits(n: int) -> int:\n \"\"\"\n An integer x is a good if after rotating each digit individually by 180 degrees, we get a valid number that is different from x. Each digit must be rotated - we cannot choose to leave it alone.\n A number is valid if each digit remains a digit after rotation. For example:\n \n 0, 1, and 8 rotate to themselves,\n 2 and 5 rotate to each other (in this case they are rotated in a different direction, in other words, 2 or 5 gets mirrored),\n 6 and 9 rotate to each other, and\n the rest of the numbers do not rotate to any other number and become invalid.\n \n Given an integer n, return the number of good integers in the range [1, n].\n \n Example 1:\n \n >>> rotatedDigits(n = 10)\n >>> 4\n Explanation: There are four good numbers in the range [1, 10] : 2, 5, 6, 9.\n Note that 1 and 10 are not good numbers, since they remain unchanged after rotating.\n \n Example 2:\n \n >>> rotatedDigits(n = 1)\n >>> 0\n \n Example 3:\n \n >>> rotatedDigits(n = 2)\n >>> 1\n \"\"\"\n"}
{"task_id": "escape-the-ghosts", "prompt": "def escapeGhosts(ghosts: List[List[int]], target: List[int]) -> bool:\n \"\"\"\n You are playing a simplified PAC-MAN game on an infinite 2-D grid. You start at the point [0, 0], and you are given a destination point target = [xtarget, ytarget] that you are trying to get to. There are several ghosts on the map with their starting positions given as a 2D array ghosts, where ghosts[i] = [xi, yi] represents the starting position of the ith ghost. All inputs are integral coordinates.\n Each turn, you and all the ghosts may independently choose to either move 1 unit in any of the four cardinal directions: north, east, south, or west, or stay still. All actions happen simultaneously.\n You escape if and only if you can reach the target before any ghost reaches you. If you reach any square (including the target) at the same time as a ghost, it does not count as an escape.\n Return true if it is possible to escape regardless of how the ghosts move, otherwise return false.\n \n Example 1:\n \n >>> escapeGhosts(ghosts = [[1,0],[0,3]], target = [0,1])\n >>> true\n Explanation: You can reach the destination (0, 1) after 1 turn, while the ghosts located at (1, 0) and (0, 3) cannot catch up with you.\n \n Example 2:\n \n >>> escapeGhosts(ghosts = [[1,0]], target = [2,0])\n >>> false\n Explanation: You need to reach the destination (2, 0), but the ghost at (1, 0) lies between you and the destination.\n \n Example 3:\n \n >>> escapeGhosts(ghosts = [[2,0]], target = [1,0])\n >>> false\n Explanation: The ghost can reach the target at the same time as you.\n \"\"\"\n"}
{"task_id": "domino-and-tromino-tiling", "prompt": "def numTilings(n: int) -> int:\n \"\"\"\n You have two types of tiles: a 2 x 1 domino shape and a tromino shape. You may rotate these shapes.\n \n Given an integer n, return the number of ways to tile an 2 x n board. Since the answer may be very large, return it modulo 109 + 7.\n In a tiling, every square must be covered by a tile. Two tilings are different if and only if there are two 4-directionally adjacent cells on the board such that exactly one of the tilings has both squares occupied by a tile.\n \n Example 1:\n \n \n >>> numTilings(n = 3)\n >>> 5\n Explanation: The five different ways are show above.\n \n Example 2:\n \n >>> numTilings(n = 1)\n >>> 1\n \"\"\"\n"}
{"task_id": "custom-sort-string", "prompt": "def customSortString(order: str, s: str) -> str:\n \"\"\"\n You are given two strings order and s. All the characters of order are unique and were sorted in some custom order previously.\n Permute the characters of s so that they match the order that order was sorted. More specifically, if a character x occurs before a character y in order, then x should occur before y in the permuted string.\n Return any permutation of s that satisfies this property.\n \n Example 1:\n \n >>> customSortString(order = \"cba\", s = \"abcd\")\n >>> \"cbad\"\n Explanation: \"a\", \"b\", \"c\" appear in order, so the order of \"a\", \"b\", \"c\" should be \"c\", \"b\", and \"a\".\n Since \"d\" does not appear in order, it can be at any position in the returned string. \"dcba\", \"cdba\", \"cbda\" are also valid outputs.\n \n Example 2:\n \n >>> customSortString(order = \"bcafg\", s = \"abcd\")\n >>> \"bcad\"\n Explanation: The characters \"b\", \"c\", and \"a\" from order dictate the order for the characters in s. The character \"d\" in s does not appear in order, so its position is flexible.\n Following the order of appearance in order, \"b\", \"c\", and \"a\" from s should be arranged as \"b\", \"c\", \"a\". \"d\" can be placed at any position since it's not in order. The output \"bcad\" correctly follows this rule. Other arrangements like \"dbca\" or \"bcda\" would also be valid, as long as \"b\", \"c\", \"a\" maintain their order.\n \"\"\"\n"}
{"task_id": "number-of-matching-subsequences", "prompt": "def numMatchingSubseq(s: str, words: List[str]) -> int:\n \"\"\"\n Given a string s and an array of strings words, return the number of words[i] that is a subsequence of s.\n 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.\n \n For example, \"ace\" is a subsequence of \"abcde\".\n \n \n Example 1:\n \n >>> numMatchingSubseq(s = \"abcde\", words = [\"a\",\"bb\",\"acd\",\"ace\"])\n >>> 3\n Explanation: There are three strings in words that are a subsequence of s: \"a\", \"acd\", \"ace\".\n \n Example 2:\n \n >>> numMatchingSubseq(s = \"dsahjpjauf\", words = [\"ahjpjau\",\"ja\",\"ahbwzgqnuk\",\"tnmlanowax\"])\n >>> 2\n \"\"\"\n"}
{"task_id": "preimage-size-of-factorial-zeroes-function", "prompt": "def preimageSizeFZF(k: int) -> int:\n \"\"\"\n Let f(x) be the number of zeroes at the end of x!. Recall that x! = 1 * 2 * 3 * ... * x and by convention, 0! = 1.\n \n For example, f(3) = 0 because 3! = 6 has no zeroes at the end, while f(11) = 2 because 11! = 39916800 has two zeroes at the end.\n \n Given an integer k, return the number of non-negative integers x have the property that f(x) = k.\n \n Example 1:\n \n >>> preimageSizeFZF(k = 0)\n >>> 5\n Explanation: 0!, 1!, 2!, 3!, and 4! end with k = 0 zeroes.\n \n Example 2:\n \n >>> preimageSizeFZF(k = 5)\n >>> 0\n Explanation: There is no x such that x! ends in k = 5 zeroes.\n \n Example 3:\n \n >>> preimageSizeFZF(k = 3)\n >>> 5\n \"\"\"\n"}
{"task_id": "valid-tic-tac-toe-state", "prompt": "def validTicTacToe(board: List[str]) -> bool:\n \"\"\"\n Given a Tic-Tac-Toe board as a string array board, return true if and only if it is possible to reach this board position during the course of a valid tic-tac-toe game.\n The board is a 3 x 3 array that consists of characters ' ', 'X', and 'O'. The ' ' character represents an empty square.\n Here are the rules of Tic-Tac-Toe:\n \n Players take turns placing characters into empty squares ' '.\n The first player always places 'X' characters, while the second player always places 'O' characters.\n 'X' and 'O' characters are always placed into empty squares, never filled ones.\n The game ends when there are three of the same (non-empty) character filling any row, column, or diagonal.\n The game also ends if all squares are non-empty.\n No more moves can be played if the game is over.\n \n \n Example 1:\n \n \n >>> validTicTacToe(board = [\"O \",\" \",\" \"])\n >>> false\n Explanation: The first player always plays \"X\".\n \n Example 2:\n \n \n >>> validTicTacToe(board = [\"XOX\",\" X \",\" \"])\n >>> false\n Explanation: Players take turns making moves.\n \n Example 3:\n \n \n >>> validTicTacToe(board = [\"XOX\",\"O O\",\"XOX\"])\n >>> true\n \"\"\"\n"}
{"task_id": "number-of-subarrays-with-bounded-maximum", "prompt": "def numSubarrayBoundedMax(nums: List[int], left: int, right: int) -> int:\n \"\"\"\n Given an integer array nums and two integers left and right, return the number of contiguous non-empty subarrays such that the value of the maximum array element in that subarray is in the range [left, right].\n The test cases are generated so that the answer will fit in a 32-bit integer.\n \n Example 1:\n \n >>> numSubarrayBoundedMax(nums = [2,1,4,3], left = 2, right = 3)\n >>> 3\n Explanation: There are three subarrays that meet the requirements: [2], [2, 1], [3].\n \n Example 2:\n \n >>> numSubarrayBoundedMax(nums = [2,9,2,5,6], left = 2, right = 8)\n >>> 7\n \"\"\"\n"}
{"task_id": "rotate-string", "prompt": "def rotateString(s: str, goal: str) -> bool:\n \"\"\"\n Given two strings s and goal, return true if and only if s can become goal after some number of shifts on s.\n A shift on s consists of moving the leftmost character of s to the rightmost position.\n \n For example, if s = \"abcde\", then it will be \"bcdea\" after one shift.\n \n \n Example 1:\n >>> rotateString(s = \"abcde\", goal = \"cdeab\")\n >>> true\n Example 2:\n >>> rotateString(s = \"abcde\", goal = \"abced\")\n >>> false\n \"\"\"\n"}
{"task_id": "all-paths-from-source-to-target", "prompt": "def allPathsSourceTarget(graph: List[List[int]]) -> List[List[int]]:\n \"\"\"\n Given a directed acyclic graph (DAG) of n nodes labeled from 0 to n - 1, find all possible paths from node 0 to node n - 1 and return them in any order.\n The graph is given as follows: graph[i] is a list of all nodes you can visit from node i (i.e., there is a directed edge from node i to node graph[i][j]).\n \n Example 1:\n \n \n >>> allPathsSourceTarget(graph = [[1,2],[3],[3],[]])\n >>> [[0,1,3],[0,2,3]]\n Explanation: There are two paths: 0 -> 1 -> 3 and 0 -> 2 -> 3.\n \n Example 2:\n \n \n >>> allPathsSourceTarget(graph = [[4,3,1],[3,2,4],[3],[4],[]])\n >>> [[0,4],[0,3,4],[0,1,3,4],[0,1,2,3,4],[0,1,4]]\n \"\"\"\n"}
{"task_id": "smallest-rotation-with-highest-score", "prompt": "def bestRotation(nums: List[int]) -> int:\n \"\"\"\n You are given an array nums. You can rotate it by a non-negative integer k so that the array becomes [nums[k], nums[k + 1], ... nums[nums.length - 1], nums[0], nums[1], ..., nums[k-1]]. Afterward, any entries that are less than or equal to their index are worth one point.\n \n For example, if we have nums = [2,4,1,3,0], and we rotate by k = 2, it becomes [1,3,0,2,4]. This is worth 3 points because 1 > 0 [no points], 3 > 1 [no points], 0 <= 2 [one point], 2 <= 3 [one point], 4 <= 4 [one point].\n \n Return the rotation index k that corresponds to the highest score we can achieve if we rotated nums by it. If there are multiple answers, return the smallest such index k.\n \n Example 1:\n \n >>> bestRotation(nums = [2,3,1,4,0])\n >>> 3\n Explanation: Scores for each k are listed below:\n k = 0, nums = [2,3,1,4,0], score 2\n k = 1, nums = [3,1,4,0,2], score 3\n k = 2, nums = [1,4,0,2,3], score 3\n k = 3, nums = [4,0,2,3,1], score 4\n k = 4, nums = [0,2,3,1,4], score 3\n So we should choose k = 3, which has the highest score.\n \n Example 2:\n \n >>> bestRotation(nums = [1,3,0,2,4])\n >>> 0\n Explanation: nums will always have 3 points no matter how it shifts.\n So we will choose the smallest k, which is 0.\n \"\"\"\n"}
{"task_id": "champagne-tower", "prompt": "def champagneTower(poured: int, query_row: int, query_glass: int) -> float:\n \"\"\"\n We stack glasses in a pyramid, where the first row has 1 glass, the second row has 2 glasses, and so on until the 100th row.\u00a0 Each glass holds one cup\u00a0of champagne.\\r\n \\r\n Then, some champagne is poured into the first glass at the top.\u00a0 When the topmost glass is full, any excess liquid poured will fall equally to the glass immediately to the left and right of it.\u00a0 When those glasses become full, any excess champagne will fall equally to the left and right of those glasses, and so on.\u00a0 (A glass at the bottom row has its excess champagne fall on the floor.)\\r\n \\r\n For example, after one cup of champagne is poured, the top most glass is full.\u00a0 After two cups of champagne are poured, the two glasses on the second row are half full.\u00a0 After three cups of champagne are poured, those two cups become full - there are 3 full glasses total now.\u00a0 After four cups of champagne are poured, the third row has the middle glass half full, and the two outside glasses are a quarter full, as pictured below.\\r\n \\r\n \\r\n \\r\n Now after pouring some non-negative integer cups of champagne, return how full the jth glass in the ith row is (both i and j are 0-indexed.)\\r\n \\r\n \u00a0\\r\n Example 1:\\r\n \\r\n \\r\n >>> champagneTower(poured = 1, query_row = 1, query_glass = 1\\r)\n >>> 0.00000\\r\n Explanation: We poured 1 cup of champange to the top glass of the tower (which is indexed as (0, 0)). There will be no excess liquid so all the glasses under the top glass will remain empty.\\r\n \\r\n \\r\n Example 2:\\r\n \\r\n \\r\n >>> champagneTower(poured = 2, query_row = 1, query_glass = 1\\r)\n >>> 0.50000\\r\n Explanation: We poured 2 cups of champange to the top glass of the tower (which is indexed as (0, 0)). There is one cup of excess liquid. The glass indexed as (1, 0) and the glass indexed as (1, 1) will share the excess liquid equally, and each will get half cup of champange.\\r\n \\r\n \\r\n Example 3:\\r\n \\r\n \\r\n >>> champagneTower(poured = 100000009, query_row = 33, query_glass = 17\\r)\n >>> 1.00000\\r\n \\r\n \\r\n \u00a0\\r\n \"\"\"\n"}
{"task_id": "similar-rgb-color", "prompt": "def similarRGB(color: str) -> str:\n \"\"\"\n The red-green-blue color \"#AABBCC\" can be written as \"#ABC\" in shorthand.\n \n For example, \"#15c\" is shorthand for the color \"#1155cc\".\n \n The similarity between the two colors \"#ABCDEF\" and \"#UVWXYZ\" is -(AB - UV)2 - (CD - WX)2 - (EF - YZ)2.\n Given a string color that follows the format \"#ABCDEF\", return a string represents the color that is most similar to the given color and has a shorthand (i.e., it can be represented as some \"#XYZ\").\n Any answer which has the same highest similarity as the best answer will be accepted.\n \n Example 1:\n \n >>> similarRGB(color = \"#09f166\")\n >>> \"#11ee66\"\n Explanation:\n The similarity is -(0x09 - 0x11)2 -(0xf1 - 0xee)2 - (0x66 - 0x66)2 = -64 -9 -0 = -73.\n This is the highest among any shorthand color.\n \n Example 2:\n \n >>> similarRGB(color = \"#4e3fe1\")\n >>> \"#5544dd\"\n \"\"\"\n"}
{"task_id": "minimum-swaps-to-make-sequences-increasing", "prompt": "def minSwap(nums1: List[int], nums2: List[int]) -> int:\n \"\"\"\n You are given two integer arrays of the same length nums1 and nums2. In one operation, you are allowed to swap nums1[i] with nums2[i].\n \n For example, if nums1 = [1,2,3,8], and nums2 = [5,6,7,4], you can swap the element at i = 3 to obtain nums1 = [1,2,3,4] and nums2 = [5,6,7,8].\n \n Return the minimum number of needed operations to make nums1 and nums2 strictly increasing. The test cases are generated so that the given input always makes it possible.\n An array arr is strictly increasing if and only if arr[0] < arr[1] < arr[2] < ... < arr[arr.length - 1].\n \n Example 1:\n \n >>> minSwap(nums1 = [1,3,5,4], nums2 = [1,2,3,7])\n >>> 1\n Explanation:\n Swap nums1[3] and nums2[3]. Then the sequences are:\n nums1 = [1, 3, 5, 7] and nums2 = [1, 2, 3, 4]\n which are both strictly increasing.\n \n Example 2:\n \n >>> minSwap(nums1 = [0,3,5,8,9], nums2 = [2,1,4,6,9])\n >>> 1\n \"\"\"\n"}
{"task_id": "find-eventual-safe-states", "prompt": "def eventualSafeNodes(graph: List[List[int]]) -> List[int]:\n \"\"\"\n There is a directed graph of n nodes with each node labeled from 0 to n - 1. The graph is represented by a 0-indexed 2D integer array graph where graph[i] is an integer array of nodes adjacent to node i, meaning there is an edge from node i to each node in graph[i].\n A node is a terminal node if there are no outgoing edges. A node is a safe node if every possible path starting from that node leads to a terminal node (or another safe node).\n Return an array containing all the safe nodes of the graph. The answer should be sorted in ascending order.\n \n Example 1:\n \n \n >>> eventualSafeNodes(graph = [[1,2],[2,3],[5],[0],[5],[],[]])\n >>> [2,4,5,6]\n Explanation: The given graph is shown above.\n Nodes 5 and 6 are terminal nodes as there are no outgoing edges from either of them.\n Every path starting at nodes 2, 4, 5, and 6 all lead to either node 5 or 6.\n Example 2:\n \n >>> eventualSafeNodes(graph = [[1,2,3,4],[1,2],[3,4],[0,4],[]])\n >>> [4]\n Explanation:\n Only node 4 is a terminal node, and every path starting at node 4 leads to node 4.\n \"\"\"\n"}
{"task_id": "bricks-falling-when-hit", "prompt": "def hitBricks(grid: List[List[int]], hits: List[List[int]]) -> List[int]:\n \"\"\"\n You are given an m x n binary grid, where each 1 represents a brick and 0 represents an empty space. A brick is stable if:\n \n It is directly connected to the top of the grid, or\n At least one other brick in its four adjacent cells is stable.\n \n You are also given an array hits, which is a sequence of erasures we want to apply. Each time we want to erase the brick at the location hits[i] = (rowi, coli). The brick on that location\u00a0(if it exists) will disappear. Some other bricks may no longer be stable because of that erasure and will fall. Once a brick falls, it is immediately erased from the grid (i.e., it does not land on other stable bricks).\n Return an array result, where each result[i] is the number of bricks that will fall after the ith erasure is applied.\n Note that an erasure may refer to a location with no brick, and if it does, no bricks drop.\n \n Example 1:\n \n >>> hitBricks(grid = [[1,0,0,0],[1,1,1,0]], hits = [[1,0]])\n >>> [2]\n Explanation: Starting with the grid:\n [[1,0,0,0],\n [1,1,1,0]]\n We erase the underlined brick at (1,0), resulting in the grid:\n [[1,0,0,0],\n [0,1,1,0]]\n The two underlined bricks are no longer stable as they are no longer connected to the top nor adjacent to another stable brick, so they will fall. The resulting grid is:\n [[1,0,0,0],\n [0,0,0,0]]\n Hence the result is [2].\n \n Example 2:\n \n >>> hitBricks(grid = [[1,0,0,0],[1,1,0,0]], hits = [[1,1],[1,0]])\n >>> [0,0]\n Explanation: Starting with the grid:\n [[1,0,0,0],\n [1,1,0,0]]\n We erase the underlined brick at (1,1), resulting in the grid:\n [[1,0,0,0],\n [1,0,0,0]]\n All remaining bricks are still stable, so no bricks fall. The grid remains the same:\n [[1,0,0,0],\n [1,0,0,0]]\n Next, we erase the underlined brick at (1,0), resulting in the grid:\n [[1,0,0,0],\n [0,0,0,0]]\n Once again, all remaining bricks are still stable, so no bricks fall.\n Hence the result is [0,0].\n \"\"\"\n"}
{"task_id": "unique-morse-code-words", "prompt": "def uniqueMorseRepresentations(words: List[str]) -> int:\n \"\"\"\n International Morse Code defines a standard encoding where each letter is mapped to a series of dots and dashes, as follows:\n \n 'a' maps to \".-\",\n 'b' maps to \"-...\",\n 'c' maps to \"-.-.\", and so on.\n \n For convenience, the full table for the 26 letters of the English alphabet is given below:\n \n [\".-\",\"-...\",\"-.-.\",\"-..\",\".\",\"..-.\",\"--.\",\"....\",\"..\",\".---\",\"-.-\",\".-..\",\"--\",\"-.\",\"---\",\".--.\",\"--.-\",\".-.\",\"...\",\"-\",\"..-\",\"...-\",\".--\",\"-..-\",\"-.--\",\"--..\"]\n Given an array of strings words where each word can be written as a concatenation of the Morse code of each letter.\n \n For example, \"cab\" can be written as \"-.-..--...\", which is the concatenation of \"-.-.\", \".-\", and \"-...\". We will call such a concatenation the transformation of a word.\n \n Return the number of different transformations among all words we have.\n \n Example 1:\n \n >>> uniqueMorseRepresentations(words = [\"gin\",\"zen\",\"gig\",\"msg\"])\n >>> 2\n Explanation: The transformation of each word is:\n \"gin\" -> \"--...-.\"\n \"zen\" -> \"--...-.\"\n \"gig\" -> \"--...--.\"\n \"msg\" -> \"--...--.\"\n There are 2 different transformations: \"--...-.\" and \"--...--.\".\n \n Example 2:\n \n >>> uniqueMorseRepresentations(words = [\"a\"])\n >>> 1\n \"\"\"\n"}
{"task_id": "split-array-with-same-average", "prompt": "def splitArraySameAverage(nums: List[int]) -> bool:\n \"\"\"\n You are given an integer array nums.\n You should move each element of nums into one of the two arrays A and B such that A and B are non-empty, and average(A) == average(B).\n Return true if it is possible to achieve that and false otherwise.\n Note that for an array arr, average(arr) is the sum of all the elements of arr over the length of arr.\n \n Example 1:\n \n >>> splitArraySameAverage(nums = [1,2,3,4,5,6,7,8])\n >>> true\n Explanation: We can split the array into [1,4,5,8] and [2,3,6,7], and both of them have an average of 4.5.\n \n Example 2:\n \n >>> splitArraySameAverage(nums = [3,1])\n >>> false\n \"\"\"\n"}
{"task_id": "number-of-lines-to-write-string", "prompt": "def numberOfLines(widths: List[int], s: str) -> List[int]:\n \"\"\"\n You are given a string s of lowercase English letters and an array widths denoting how many pixels wide each lowercase English letter is. Specifically, widths[0] is the width of 'a', widths[1] is the width of 'b', and so on.\n You are trying to write s across several lines, where each line is no longer than 100 pixels. Starting at the beginning of s, write as many letters on the first line such that the total width does not exceed 100 pixels. Then, from where you stopped in s, continue writing as many letters as you can on the second line. Continue this process until you have written all of s.\n Return an array result of length 2 where:\n \n result[0] is the total number of lines.\n result[1] is the width of the last line in pixels.\n \n \n Example 1:\n \n >>> numberOfLines(widths = [10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10], s = \"abcdefghijklmnopqrstuvwxyz\")\n >>> [3,60]\n Explanation: You can write s as follows:\n abcdefghij // 100 pixels wide\n klmnopqrst // 100 pixels wide\n uvwxyz // 60 pixels wide\n There are a total of 3 lines, and the last line is 60 pixels wide.\n Example 2:\n \n >>> numberOfLines(widths = [4,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10], s = \"bbbcccdddaaa\")\n >>> [2,4]\n Explanation: You can write s as follows:\n bbbcccdddaa // 98 pixels wide\n a // 4 pixels wide\n There are a total of 2 lines, and the last line is 4 pixels wide.\n \"\"\"\n"}
{"task_id": "max-increase-to-keep-city-skyline", "prompt": "def maxIncreaseKeepingSkyline(grid: List[List[int]]) -> int:\n \"\"\"\n There is a city composed of n x n blocks, where each block contains a single building shaped like a vertical square prism. You are given a 0-indexed n x n integer matrix grid where grid[r][c] represents the height of the building located in the block at row r and column c.\n A city's skyline is the\u00a0outer contour formed by all the building when viewing the side of the city from a distance. The skyline from each cardinal direction north, east, south, and west may be different.\n We are allowed to increase the height of any number of buildings by any amount (the amount can be different per building). The height of a 0-height building can also be increased. However, increasing the height of a building should not affect the city's skyline from any cardinal direction.\n Return the maximum total sum that the height of the buildings can be increased by without changing the city's skyline from any cardinal direction.\n \n Example 1:\n \n \n >>> maxIncreaseKeepingSkyline(grid = [[3,0,8,4],[2,4,5,7],[9,2,6,3],[0,3,1,0]])\n >>> 35\n Explanation: The building heights are shown in the center of the above image.\n The skylines when viewed from each cardinal direction are drawn in red.\n The grid after increasing the height of buildings without affecting skylines is:\n gridNew = [ [8, 4, 8, 7],\n [7, 4, 7, 7],\n [9, 4, 8, 7],\n [3, 3, 3, 3] ]\n \n Example 2:\n \n >>> maxIncreaseKeepingSkyline(grid = [[0,0,0],[0,0,0],[0,0,0]])\n >>> 0\n Explanation: Increasing the height of any building will result in the skyline changing.\n \"\"\"\n"}
{"task_id": "soup-servings", "prompt": "def soupServings(n: int) -> float:\n \"\"\"\n There are two types of soup: type A and type B. Initially, we have n ml of each type of soup. There are four kinds of operations:\n \n Serve 100 ml of soup A and 0 ml of soup B,\n Serve 75 ml of soup A and 25 ml of soup B,\n Serve 50 ml of soup A and 50 ml of soup B, and\n Serve 25 ml of soup A and 75 ml of soup B.\n \n When we serve some soup, we give it to someone, and we no longer have it. Each turn, we will choose from the four operations with an equal probability 0.25. If the remaining volume of soup is not enough to complete the operation, we will serve as much as possible. We stop once we no longer have some quantity of both types of soup.\n Note that we do not have an operation where all 100 ml's of soup B are used first.\n Return the probability that soup A will be empty first, plus half the probability that A and B become empty at the same time. Answers within 10-5 of the actual answer will be accepted.\n \n Example 1:\n \n >>> soupServings(n = 50)\n >>> 0.62500\n Explanation: If we choose the first two operations, A will become empty first.\n For the third operation, A and B will become empty at the same time.\n For the fourth operation, B will become empty first.\n So the total probability of A becoming empty first plus half the probability that A and B become empty at the same time, is 0.25 * (1 + 1 + 0.5 + 0) = 0.625.\n \n Example 2:\n \n >>> soupServings(n = 100)\n >>> 0.71875\n \"\"\"\n"}
{"task_id": "expressive-words", "prompt": "def expressiveWords(s: str, words: List[str]) -> int:\n \"\"\"\n Sometimes people repeat letters to represent extra feeling. For example:\n \n \"hello\" -> \"heeellooo\"\n \"hi\" -> \"hiiii\"\n \n In these strings like \"heeellooo\", we have groups of adjacent letters that are all the same: \"h\", \"eee\", \"ll\", \"ooo\".\n You are given a string s and an array of query strings words. A query word is stretchy if it can be made to be equal to s by any number of applications of the following extension operation: choose a group consisting of characters c, and add some number of characters c to the group so that the size of the group is three or more.\n \n For example, starting with \"hello\", we could do an extension on the group \"o\" to get \"hellooo\", but we cannot get \"helloo\" since the group \"oo\" has a size less than three. Also, we could do another extension like \"ll\" -> \"lllll\" to get \"helllllooo\". If s = \"helllllooo\", then the query word \"hello\" would be stretchy because of these two extension operations: query = \"hello\" -> \"hellooo\" -> \"helllllooo\" = s.\n \n Return the number of query strings that are stretchy.\n \n Example 1:\n \n >>> expressiveWords(s = \"heeellooo\", words = [\"hello\", \"hi\", \"helo\"])\n >>> 1\n Explanation:\n We can extend \"e\" and \"o\" in the word \"hello\" to get \"heeellooo\".\n We can't extend \"helo\" to get \"heeellooo\" because the group \"ll\" is not size 3 or more.\n \n Example 2:\n \n >>> expressiveWords(s = \"zzzzzyyyyy\", words = [\"zzyy\",\"zy\",\"zyy\"])\n >>> 3\n \"\"\"\n"}
{"task_id": "chalkboard-xor-game", "prompt": "def xorGame(nums: List[int]) -> bool:\n \"\"\"\n You are given an array of integers nums represents the numbers written on a chalkboard.\n Alice and Bob take turns erasing exactly one number from the chalkboard, with Alice starting first. If erasing a number causes the bitwise XOR of all the elements of the chalkboard to become 0, then that player loses. The bitwise XOR of one element is that element itself, and the bitwise XOR of no elements is 0.\n Also, if any player starts their turn with the bitwise XOR of all the elements of the chalkboard equal to 0, then that player wins.\n Return true if and only if Alice wins the game, assuming both players play optimally.\n \n Example 1:\n \n >>> xorGame(nums = [1,1,2])\n >>> false\n Explanation:\n Alice has two choices: erase 1 or erase 2.\n If she erases 1, the nums array becomes [1, 2]. The bitwise XOR of all the elements of the chalkboard is 1 XOR 2 = 3. Now Bob can remove any element he wants, because Alice will be the one to erase the last element and she will lose.\n If Alice erases 2 first, now nums become [1, 1]. The bitwise XOR of all the elements of the chalkboard is 1 XOR 1 = 0. Alice will lose.\n \n Example 2:\n \n >>> xorGame(nums = [0,1])\n >>> true\n \n Example 3:\n \n >>> xorGame(nums = [1,2,3])\n >>> true\n \"\"\"\n"}
{"task_id": "subdomain-visit-count", "prompt": "def subdomainVisits(cpdomains: List[str]) -> List[str]:\n \"\"\"\n A website domain \"discuss.leetcode.com\" consists of various subdomains. At the top level, we have \"com\", at the next level, we have \"leetcode.com\"\u00a0and at the lowest level, \"discuss.leetcode.com\". When we visit a domain like \"discuss.leetcode.com\", we will also visit the parent domains \"leetcode.com\" and \"com\" implicitly.\n A count-paired domain is a domain that has one of the two formats \"rep d1.d2.d3\" or \"rep d1.d2\" where rep is the number of visits to the domain and d1.d2.d3 is the domain itself.\n \n For example, \"9001 discuss.leetcode.com\" is a count-paired domain that indicates that discuss.leetcode.com was visited 9001 times.\n \n Given an array of count-paired domains cpdomains, return an array of the count-paired domains of each subdomain in the input. You may return the answer in any order.\n \n Example 1:\n \n >>> subdomainVisits(cpdomains = [\"9001 discuss.leetcode.com\"])\n >>> [\"9001 leetcode.com\",\"9001 discuss.leetcode.com\",\"9001 com\"]\n Explanation: We only have one website domain: \"discuss.leetcode.com\".\n As discussed above, the subdomain \"leetcode.com\" and \"com\" will also be visited. So they will all be visited 9001 times.\n \n Example 2:\n \n >>> subdomainVisits(cpdomains = [\"900 google.mail.com\", \"50 yahoo.com\", \"1 intel.mail.com\", \"5 wiki.org\"])\n >>> [\"901 mail.com\",\"50 yahoo.com\",\"900 google.mail.com\",\"5 wiki.org\",\"5 org\",\"1 intel.mail.com\",\"951 com\"]\n Explanation: We will visit \"google.mail.com\" 900 times, \"yahoo.com\" 50 times, \"intel.mail.com\" once and \"wiki.org\" 5 times.\n For the subdomains, we will visit \"mail.com\" 900 + 1 = 901 times, \"com\" 900 + 50 + 1 = 951 times, and \"org\" 5 times.\n \"\"\"\n"}
{"task_id": "largest-triangle-area", "prompt": "def largestTriangleArea(points: List[List[int]]) -> float:\n \"\"\"\n Given an array of points on the X-Y plane points where points[i] = [xi, yi], return the area of the largest triangle that can be formed by any three different points. Answers within 10-5 of the actual answer will be accepted.\n \n Example 1:\n \n \n >>> largestTriangleArea(points = [[0,0],[0,1],[1,0],[0,2],[2,0]])\n >>> 2.00000\n Explanation: The five points are shown in the above figure. The red triangle is the largest.\n \n Example 2:\n \n >>> largestTriangleArea(points = [[1,0],[0,0],[0,1]])\n >>> 0.50000\n \"\"\"\n"}
{"task_id": "largest-sum-of-averages", "prompt": "def largestSumOfAverages(nums: List[int], k: int) -> float:\n \"\"\"\n You are given an integer array nums and an integer k. You can partition the array into at most k non-empty adjacent subarrays. The score of a partition is the sum of the averages of each subarray.\n Note that the partition must use every integer in nums, and that the score is not necessarily an integer.\n Return the maximum score you can achieve of all the possible partitions. Answers within 10-6 of the actual answer will be accepted.\n \n Example 1:\n \n >>> largestSumOfAverages(nums = [9,1,2,3,9], k = 3)\n >>> 20.00000\n Explanation:\n The best choice is to partition nums into [9], [1, 2, 3], [9]. The answer is 9 + (1 + 2 + 3) / 3 + 9 = 20.\n We could have also partitioned nums into [9, 1], [2], [3, 9], for example.\n That partition would lead to a score of 5 + 2 + 6 = 13, which is worse.\n \n Example 2:\n \n >>> largestSumOfAverages(nums = [1,2,3,4,5,6,7], k = 4)\n >>> 20.50000\n \"\"\"\n"}
{"task_id": "binary-tree-pruning", "prompt": "# class TreeNode:\n# def __init__(val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def pruneTree(root: Optional[TreeNode]) -> Optional[TreeNode]:\n \"\"\"\n Given the root of a binary tree, return the same tree where every subtree (of the given tree) not containing a 1 has been removed.\n A subtree of a node node is node plus every node that is a descendant of node.\n \n Example 1:\n \n \n >>> __init__(root = [1,null,0,0,1])\n >>> [1,null,0,null,1]\n Explanation:\n Only the red nodes satisfy the property \"every subtree not containing a 1\".\n The diagram on the right represents the answer.\n \n Example 2:\n \n \n >>> __init__(root = [1,0,1,0,0,0,1])\n >>> [1,null,1,null,1]\n \n Example 3:\n \n \n >>> __init__(root = [1,1,0,1,1,0,1,0])\n >>> [1,1,0,1,1,null,1]\n \"\"\"\n"}
{"task_id": "bus-routes", "prompt": "def numBusesToDestination(routes: List[List[int]], source: int, target: int) -> int:\n \"\"\"\n You are given an array routes representing bus routes where routes[i] is a bus route that the ith bus repeats forever.\n \n For example, if routes[0] = [1, 5, 7], this means that the 0th bus travels in the sequence 1 -> 5 -> 7 -> 1 -> 5 -> 7 -> 1 -> ... forever.\n \n You will start at the bus stop source (You are not on any bus initially), and you want to go to the bus stop target. You can travel between bus stops by buses only.\n Return the least number of buses you must take to travel from source to target. Return -1 if it is not possible.\n \n Example 1:\n \n >>> numBusesToDestination(routes = [[1,2,7],[3,6,7]], source = 1, target = 6)\n >>> 2\n Explanation: The best strategy is take the first bus to the bus stop 7, then take the second bus to the bus stop 6.\n \n Example 2:\n \n >>> numBusesToDestination(routes = [[7,12],[4,5,15],[6],[15,19],[9,12,13]], source = 15, target = 12)\n >>> -1\n \"\"\"\n"}
{"task_id": "ambiguous-coordinates", "prompt": "def ambiguousCoordinates(s: str) -> List[str]:\n \"\"\"\n We had some 2-dimensional coordinates, like \"(1, 3)\" or \"(2, 0.5)\". Then, we removed all commas, decimal points, and spaces and ended up with the string s.\n \n For example, \"(1, 3)\" becomes s = \"(13)\" and \"(2, 0.5)\" becomes s = \"(205)\".\n \n Return a list of strings representing all possibilities for what our original coordinates could have been.\n Our original representation never had extraneous zeroes, so we never started with numbers like \"00\", \"0.0\", \"0.00\", \"1.0\", \"001\", \"00.01\", or any other number that can be represented with fewer digits. Also, a decimal point within a number never occurs without at least one digit occurring before it, so we never started with numbers like \".1\".\n The final answer list can be returned in any order. All coordinates in the final answer have exactly one space between them (occurring after the comma.)\n \n Example 1:\n \n >>> ambiguousCoordinates(s = \"(123)\")\n >>> [\"(1, 2.3)\",\"(1, 23)\",\"(1.2, 3)\",\"(12, 3)\"]\n \n Example 2:\n \n >>> ambiguousCoordinates(s = \"(0123)\")\n >>> [\"(0, 1.23)\",\"(0, 12.3)\",\"(0, 123)\",\"(0.1, 2.3)\",\"(0.1, 23)\",\"(0.12, 3)\"]\n Explanation: 0.0, 00, 0001 or 00.01 are not allowed.\n \n Example 3:\n \n >>> ambiguousCoordinates(s = \"(00011)\")\n >>> [\"(0, 0.011)\",\"(0.001, 1)\"]\n \"\"\"\n"}
{"task_id": "linked-list-components", "prompt": "# class ListNode:\n# def __init__(val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution:\n def numComponents(head: Optional[ListNode], nums: List[int]) -> int:\n \"\"\"\n You are given the head of a linked list containing unique integer values and an integer array nums that is a subset of the linked list values.\n Return the number of connected components in nums where two values are connected if they appear consecutively in the linked list.\n \n Example 1:\n \n \n >>> __init__(head = [0,1,2,3], nums = [0,1,3])\n >>> 2\n Explanation: 0 and 1 are connected, so [0, 1] and [3] are the two connected components.\n \n Example 2:\n \n \n >>> __init__(head = [0,1,2,3,4], nums = [0,3,1,4])\n >>> 2\n Explanation: 0 and 1 are connected, 3 and 4 are connected, so [0, 1] and [3, 4] are the two connected components.\n \"\"\"\n"}
{"task_id": "race-car", "prompt": "def racecar(target: int) -> int:\n \"\"\"\n Your car starts at position 0 and speed +1 on an infinite number line. Your car can go into negative positions. Your car drives automatically according to a sequence of instructions 'A' (accelerate) and 'R' (reverse):\n \n When you get an instruction 'A', your car does the following:\n \n \n position += speed\n speed *= 2\n \n \n When you get an instruction 'R', your car does the following:\n \n If your speed is positive then speed = -1\n otherwise speed = 1\n \n \tYour position stays the same.\n \n For example, after commands \"AAR\", your car goes to positions 0 --> 1 --> 3 --> 3, and your speed goes to 1 --> 2 --> 4 --> -1.\n Given a target position target, return the length of the shortest sequence of instructions to get there.\n \n Example 1:\n \n >>> racecar(target = 3)\n >>> 2\n Explanation:\n The shortest instruction sequence is \"AA\".\n Your position goes from 0 --> 1 --> 3.\n \n Example 2:\n \n >>> racecar(target = 6)\n >>> 5\n Explanation:\n The shortest instruction sequence is \"AAARA\".\n Your position goes from 0 --> 1 --> 3 --> 7 --> 7 --> 6.\n \"\"\"\n"}
{"task_id": "short-encoding-of-words", "prompt": "def minimumLengthEncoding(words: List[str]) -> int:\n \"\"\"\n A valid encoding of an array of words is any reference string s and array of indices indices such that:\n \n words.length == indices.length\n The reference string s ends with the '#' character.\n For each index indices[i], the substring of s starting from indices[i] and up to (but not including) the next '#' character is equal to words[i].\n \n Given an array of words, return the length of the shortest reference string s possible of any valid encoding of words.\n \n Example 1:\n \n >>> minimumLengthEncoding(words = [\"time\", \"me\", \"bell\"])\n >>> 10\n Explanation: A valid encoding would be s = \"time#bell#\" and indices = [0, 2, 5].\n words[0] = \"time\", the substring of s starting from indices[0] = 0 to the next '#' is underlined in \"time#bell#\"\n words[1] = \"me\", the substring of s starting from indices[1] = 2 to the next '#' is underlined in \"time#bell#\"\n words[2] = \"bell\", the substring of s starting from indices[2] = 5 to the next '#' is underlined in \"time#bell#\"\n \n Example 2:\n \n >>> minimumLengthEncoding(words = [\"t\"])\n >>> 2\n Explanation: A valid encoding would be s = \"t#\" and indices = [0].\n \"\"\"\n"}
{"task_id": "shortest-distance-to-a-character", "prompt": "def shortestToChar(s: str, c: str) -> List[int]:\n \"\"\"\n Given a string s and a character c that occurs in s, return an array of integers answer where answer.length == s.length and answer[i] is the distance from index i to the closest occurrence of character c in s.\n The distance between two indices i and j is abs(i - j), where abs is the absolute value function.\n \n Example 1:\n \n >>> shortestToChar(s = \"loveleetcode\", c = \"e\")\n >>> [3,2,1,0,1,0,0,1,2,2,1,0]\n Explanation: The character 'e' appears at indices 3, 5, 6, and 11 (0-indexed).\n The closest occurrence of 'e' for index 0 is at index 3, so the distance is abs(0 - 3) = 3.\n The closest occurrence of 'e' for index 1 is at index 3, so the distance is abs(1 - 3) = 2.\n For index 4, there is a tie between the 'e' at index 3 and the 'e' at index 5, but the distance is still the same: abs(4 - 3) == abs(4 - 5) = 1.\n The closest occurrence of 'e' for index 8 is at index 6, so the distance is abs(8 - 6) = 2.\n \n Example 2:\n \n >>> shortestToChar(s = \"aaab\", c = \"b\")\n >>> [3,2,1,0]\n \"\"\"\n"}
{"task_id": "card-flipping-game", "prompt": "def flipgame(fronts: List[int], backs: List[int]) -> int:\n \"\"\"\n You are given two 0-indexed integer arrays fronts and backs of length n, where the ith card has the positive integer fronts[i] printed on the front and backs[i] printed on the back. Initially, each card is placed on a table such that the front number is facing up and the other is facing down. You may flip over any number of cards (possibly zero).\n After flipping the cards, an integer is considered good if it is facing down on some card and not facing up on any card.\n Return the minimum possible good integer after flipping the cards. If there are no good integers, return 0.\n \n Example 1:\n \n >>> flipgame(fronts = [1,2,4,4,7], backs = [1,3,4,1,3])\n >>> 2\n Explanation:\n If we flip the second card, the face up numbers are [1,3,4,4,7] and the face down are [1,2,4,1,3].\n 2 is the minimum good integer as it appears facing down but not facing up.\n It can be shown that 2 is the minimum possible good integer obtainable after flipping some cards.\n \n Example 2:\n \n >>> flipgame(fronts = [1], backs = [1])\n >>> 0\n Explanation:\n There are no good integers no matter how we flip the cards, so we return 0.\n \"\"\"\n"}
{"task_id": "binary-trees-with-factors", "prompt": "def numFactoredBinaryTrees(arr: List[int]) -> int:\n \"\"\"\n Given an array of unique integers, arr, where each integer arr[i] is strictly greater than 1.\n We make a binary tree using these integers, and each number may be used for any number of times. Each non-leaf node's value should be equal to the product of the values of its children.\n Return the number of binary trees we can make. The answer may be too large so return the answer modulo 109 + 7.\n \n Example 1:\n \n >>> numFactoredBinaryTrees(arr = [2,4])\n >>> 3\n Explanation: We can make these trees: [2], [4], [4, 2, 2]\n Example 2:\n \n >>> numFactoredBinaryTrees(arr = [2,4,5,10])\n >>> 7\n Explanation: We can make these trees: [2], [4], [5], [10], [4, 2, 2], [10, 2, 5], [10, 5, 2].\n \"\"\"\n"}
{"task_id": "goat-latin", "prompt": "def toGoatLatin(sentence: str) -> str:\n \"\"\"\n You are given a string sentence that consist of words separated by spaces. Each word consists of lowercase and uppercase letters only.\n We would like to convert the sentence to \"Goat Latin\" (a made-up language similar to Pig Latin.) The rules of Goat Latin are as follows:\n \n If a word begins with a vowel ('a', 'e', 'i', 'o', or 'u'), append \"ma\" to the end of the word.\n \n \n For example, the word \"apple\" becomes \"applema\".\n \n \n If a word begins with a consonant (i.e., not a vowel), remove the first letter and append it to the end, then add \"ma\".\n \n For example, the word \"goat\" becomes \"oatgma\".\n \n \n Add one letter 'a' to the end of each word per its word index in the sentence, starting with 1.\n \n For example, the first word gets \"a\" added to the end, the second word gets \"aa\" added to the end, and so on.\n \n \n \n Return the final sentence representing the conversion from sentence to Goat Latin.\n \n Example 1:\n >>> toGoatLatin(sentence = \"I speak Goat Latin\")\n >>> \"Imaa peaksmaaa oatGmaaaa atinLmaaaaa\"\n Example 2:\n >>> toGoatLatin(sentence = \"The quick brown fox jumped over the lazy dog\")\n >>> \"heTmaa uickqmaaa rownbmaaaa oxfmaaaaa umpedjmaaaaaa overmaaaaaaa hetmaaaaaaaa azylmaaaaaaaaa ogdmaaaaaaaaaa\"\n \"\"\"\n"}
{"task_id": "friends-of-appropriate-ages", "prompt": "def numFriendRequests(ages: List[int]) -> int:\n \"\"\"\n There are n persons on a social media website. You are given an integer array ages where ages[i] is the age of the ith person.\n A Person x will not send a friend request to a person y (x != y) if any of the following conditions is true:\n \n age[y] <= 0.5 * age[x] + 7\n age[y] > age[x]\n age[y] > 100 && age[x] < 100\n \n Otherwise, x will send a friend request to y.\n Note that if x sends a request to y, y will not necessarily send a request to x. Also, a person will not send a friend request to themself.\n Return the total number of friend requests made.\n \n Example 1:\n \n >>> numFriendRequests(ages = [16,16])\n >>> 2\n Explanation: 2 people friend request each other.\n \n Example 2:\n \n >>> numFriendRequests(ages = [16,17,18])\n >>> 2\n Explanation: Friend requests are made 17 -> 16, 18 -> 17.\n \n Example 3:\n \n >>> numFriendRequests(ages = [20,30,100,110,120])\n >>> 3\n Explanation: Friend requests are made 110 -> 100, 120 -> 110, 120 -> 100.\n \"\"\"\n"}
{"task_id": "most-profit-assigning-work", "prompt": "def maxProfitAssignment(difficulty: List[int], profit: List[int], worker: List[int]) -> int:\n \"\"\"\n You have n jobs and m workers. You are given three arrays: difficulty, profit, and worker where:\n \n difficulty[i] and profit[i] are the difficulty and the profit of the ith job, and\n worker[j] is the ability of jth worker (i.e., the jth worker can only complete a job with difficulty at most worker[j]).\n \n Every worker can be assigned at most one job, but one job can be completed multiple times.\n \n For example, if three workers attempt the same job that pays $1, then the total profit will be $3. If a worker cannot complete any job, their profit is $0.\n \n Return the maximum profit we can achieve after assigning the workers to the jobs.\n \n Example 1:\n \n >>> maxProfitAssignment(difficulty = [2,4,6,8,10], profit = [10,20,30,40,50], worker = [4,5,6,7])\n >>> 100\n Explanation: Workers are assigned jobs of difficulty [4,4,6,6] and they get a profit of [20,20,30,30] separately.\n \n Example 2:\n \n >>> maxProfitAssignment(difficulty = [85,47,57], profit = [24,66,99], worker = [40,25,25])\n >>> 0\n \"\"\"\n"}
{"task_id": "making-a-large-island", "prompt": "def largestIsland(grid: List[List[int]]) -> int:\n \"\"\"\n You are given an n x n binary matrix grid. You are allowed to change at most one 0 to be 1.\n Return the size of the largest island in grid after applying this operation.\n An island is a 4-directionally connected group of 1s.\n \n Example 1:\n \n >>> largestIsland(grid = [[1,0],[0,1]])\n >>> 3\n Explanation: Change one 0 to 1 and connect two 1s, then we get an island with area = 3.\n \n Example 2:\n \n >>> largestIsland(grid = [[1,1],[1,0]])\n >>> 4\n Explanation: Change the 0 to 1 and make the island bigger, only one island with area = 4.\n Example 3:\n \n >>> largestIsland(grid = [[1,1],[1,1]])\n >>> 4\n Explanation: Can't change any 0 to 1, only one island with area = 4.\n \"\"\"\n"}
{"task_id": "count-unique-characters-of-all-substrings-of-a-given-string", "prompt": "def uniqueLetterString(s: str) -> int:\n \"\"\"\n Let's define a function countUniqueChars(s) that returns the number of unique characters in\u00a0s.\n \n For example, calling countUniqueChars(s) if s = \"LEETCODE\" then \"L\", \"T\", \"C\", \"O\", \"D\" are the unique characters since they appear only once in s, therefore countUniqueChars(s) = 5.\n \n Given a string s, return the sum of countUniqueChars(t) where t is a substring of s. The test cases are generated such that the answer fits in a 32-bit integer.\n Notice that some substrings can be repeated so in this case you have to count the repeated ones too.\n \n Example 1:\n \n >>> uniqueLetterString(s = \"ABC\")\n >>> 10\n Explanation: All possible substrings are: \"A\",\"B\",\"C\",\"AB\",\"BC\" and \"ABC\".\n Every substring is composed with only unique letters.\n Sum of lengths of all substring is 1 + 1 + 1 + 2 + 2 + 3 = 10\n \n Example 2:\n \n >>> uniqueLetterString(s = \"ABA\")\n >>> 8\n Explanation: The same as example 1, except countUniqueChars(\"ABA\") = 1.\n \n Example 3:\n \n >>> uniqueLetterString(s = \"LEETCODE\")\n >>> 92\n \"\"\"\n"}
{"task_id": "consecutive-numbers-sum", "prompt": "def consecutiveNumbersSum(n: int) -> int:\n \"\"\"\n Given an integer n, return the number of ways you can write n as the sum of consecutive positive integers.\n \n Example 1:\n \n >>> consecutiveNumbersSum(n = 5)\n >>> 2\n Explanation: 5 = 2 + 3\n \n Example 2:\n \n >>> consecutiveNumbersSum(n = 9)\n >>> 3\n Explanation: 9 = 4 + 5 = 2 + 3 + 4\n \n Example 3:\n \n >>> consecutiveNumbersSum(n = 15)\n >>> 4\n Explanation: 15 = 8 + 7 = 4 + 5 + 6 = 1 + 2 + 3 + 4 + 5\n \"\"\"\n"}
{"task_id": "positions-of-large-groups", "prompt": "def largeGroupPositions(s: str) -> List[List[int]]:\n \"\"\"\n In a string s\u00a0of lowercase letters, these letters form consecutive groups of the same character.\n For example, a string like s = \"abbxxxxzyy\" has the groups \"a\", \"bb\", \"xxxx\", \"z\", and\u00a0\"yy\".\n A group is identified by an interval\u00a0[start, end], where\u00a0start\u00a0and\u00a0end\u00a0denote the start and end\u00a0indices (inclusive) of the group. In the above example,\u00a0\"xxxx\"\u00a0has the interval\u00a0[3,6].\n A group is considered\u00a0large\u00a0if it has 3 or more characters.\n Return\u00a0the intervals of every large group sorted in\u00a0increasing order by start index.\n \n Example 1:\n \n >>> largeGroupPositions(s = \"abbxxxxzzy\")\n >>> [[3,6]]\n Explanation: \"xxxx\" is the only large group with start index 3 and end index 6.\n \n Example 2:\n \n >>> largeGroupPositions(s = \"abc\")\n >>> []\n Explanation: We have groups \"a\", \"b\", and \"c\", none of which are large groups.\n \n Example 3:\n \n >>> largeGroupPositions(s = \"abcdddeeeeaabbbcd\")\n >>> [[3,5],[6,9],[12,14]]\n Explanation: The large groups are \"ddd\", \"eeee\", and \"bbb\".\n \"\"\"\n"}
{"task_id": "masking-personal-information", "prompt": "def maskPII(s: str) -> str:\n \"\"\"\n You are given a personal information string s, representing either an email address or a phone number. Return the masked personal information using the below rules.\n Email address:\n An email address is:\n \n A name consisting of uppercase and lowercase English letters, followed by\n The '@' symbol, followed by\n The domain consisting of uppercase and lowercase English letters with a dot '.' somewhere in the middle (not the first or last character).\n \n To mask an email:\n \n The uppercase letters in the name and domain must be converted to lowercase letters.\n The middle letters of the name (i.e., all but the first and last letters) must be replaced by 5 asterisks \"*****\".\n \n Phone number:\n A phone number is formatted as follows:\n \n The phone number contains 10-13 digits.\n The last 10 digits make up the local number.\n The remaining 0-3 digits, in the beginning, make up the country code.\n Separation characters from the set {'+', '-', '(', ')', ' '} separate the above digits in some way.\n \n To mask a phone number:\n \n Remove all separation characters.\n The masked phone number should have the form:\n \n \"***-***-XXXX\" if the country code has 0 digits.\n \"+*-***-***-XXXX\" if the country code has 1 digit.\n \"+**-***-***-XXXX\" if the country code has 2 digits.\n \"+***-***-***-XXXX\" if the country code has 3 digits.\n \n \n \"XXXX\" is the last 4 digits of the local number.\n \n \n Example 1:\n \n >>> maskPII(s = \"LeetCode@LeetCode.com\")\n >>> \"l*****e@leetcode.com\"\n Explanation: s is an email address.\n The name and domain are converted to lowercase, and the middle of the name is replaced by 5 asterisks.\n \n Example 2:\n \n >>> maskPII(s = \"AB@qq.com\")\n >>> \"a*****b@qq.com\"\n Explanation: s is an email address.\n The name and domain are converted to lowercase, and the middle of the name is replaced by 5 asterisks.\n Note that even though \"ab\" is 2 characters, it still must have 5 asterisks in the middle.\n \n Example 3:\n \n >>> maskPII(s = \"1(234)567-890\")\n >>> \"***-***-7890\"\n Explanation: s is a phone number.\n There are 10 digits, so the local number is 10 digits and the country code is 0 digits.\n Thus, the resulting masked number is \"***-***-7890\".\n \"\"\"\n"}
{"task_id": "flipping-an-image", "prompt": "def flipAndInvertImage(image: List[List[int]]) -> List[List[int]]:\n \"\"\"\n Given an n x n binary matrix image, flip the image horizontally, then invert it, and return the resulting image.\n To flip an image horizontally means that each row of the image is reversed.\n \n For example, flipping [1,1,0] horizontally results in [0,1,1].\n \n To invert an image means that each 0 is replaced by 1, and each 1 is replaced by 0.\n \n For example, inverting [0,1,1] results in [1,0,0].\n \n \n Example 1:\n \n >>> flipAndInvertImage(image = [[1,1,0],[1,0,1],[0,0,0]])\n >>> [[1,0,0],[0,1,0],[1,1,1]]\n Explanation: First reverse each row: [[0,1,1],[1,0,1],[0,0,0]].\n Then, invert the image: [[1,0,0],[0,1,0],[1,1,1]]\n \n Example 2:\n \n >>> flipAndInvertImage(image = [[1,1,0,0],[1,0,0,1],[0,1,1,1],[1,0,1,0]])\n >>> [[1,1,0,0],[0,1,1,0],[0,0,0,1],[1,0,1,0]]\n Explanation: First reverse each row: [[0,0,1,1],[1,0,0,1],[1,1,1,0],[0,1,0,1]].\n Then invert the image: [[1,1,0,0],[0,1,1,0],[0,0,0,1],[1,0,1,0]]\n \"\"\"\n"}
{"task_id": "find-and-replace-in-string", "prompt": "def findReplaceString(s: str, indices: List[int], sources: List[str], targets: List[str]) -> str:\n \"\"\"\n You are given a 0-indexed string s that you must perform k replacement operations on. The replacement operations are given as three 0-indexed parallel arrays, indices, sources, and targets, all of length k.\n To complete the ith replacement operation:\n \n Check if the substring sources[i] occurs at index indices[i] in the original string s.\n If it does not occur, do nothing.\n Otherwise if it does occur, replace that substring with targets[i].\n \n For example, if s = \"abcd\", indices[i] = 0, sources[i] = \"ab\", and targets[i] = \"eee\", then the result of this replacement will be \"eeecd\".\n All replacement operations must occur simultaneously, meaning the replacement operations should not affect the indexing of each other. The testcases will be generated such that the replacements will not overlap.\n \n For example, a testcase with s = \"abc\", indices = [0, 1], and sources = [\"ab\",\"bc\"] will not be generated because the \"ab\" and \"bc\" replacements overlap.\n \n Return the resulting string after performing all replacement operations on s.\n A substring is a contiguous sequence of characters in a string.\n \n Example 1:\n \n \n >>> findReplaceString(s = \"abcd\", indices = [0, 2], sources = [\"a\", \"cd\"], targets = [\"eee\", \"ffff\"])\n >>> \"eeebffff\"\n Explanation:\n \"a\" occurs at index 0 in s, so we replace it with \"eee\".\n \"cd\" occurs at index 2 in s, so we replace it with \"ffff\".\n \n Example 2:\n \n \n >>> findReplaceString(s = \"abcd\", indices = [0, 2], sources = [\"ab\",\"ec\"], targets = [\"eee\",\"ffff\"])\n >>> \"eeecd\"\n Explanation:\n \"ab\" occurs at index 0 in s, so we replace it with \"eee\".\n \"ec\" does not occur at index 2 in s, so we do nothing.\n \"\"\"\n"}
{"task_id": "sum-of-distances-in-tree", "prompt": "def sumOfDistancesInTree(n: int, edges: List[List[int]]) -> List[int]:\n \"\"\"\n There is an undirected connected tree with n nodes labeled from 0 to n - 1 and n - 1 edges.\n You are given the integer n and the array edges where edges[i] = [ai, bi] indicates that there is an edge between nodes ai and bi in the tree.\n Return an array answer of length n where answer[i] is the sum of the distances between the ith node in the tree and all other nodes.\n \n Example 1:\n \n \n >>> sumOfDistancesInTree(n = 6, edges = [[0,1],[0,2],[2,3],[2,4],[2,5]])\n >>> [8,12,6,10,10,10]\n Explanation: The tree is shown above.\n We can see that dist(0,1) + dist(0,2) + dist(0,3) + dist(0,4) + dist(0,5)\n equals 1 + 1 + 2 + 2 + 2 = 8.\n Hence, answer[0] = 8, and so on.\n \n Example 2:\n \n \n >>> sumOfDistancesInTree(n = 1, edges = [])\n >>> [0]\n \n Example 3:\n \n \n >>> sumOfDistancesInTree(n = 2, edges = [[1,0]])\n >>> [1,1]\n \"\"\"\n"}
{"task_id": "image-overlap", "prompt": "def largestOverlap(img1: List[List[int]], img2: List[List[int]]) -> int:\n \"\"\"\n You are given two images, img1 and img2, represented as binary, square matrices of size n x n. A binary matrix has only 0s and 1s as values.\n We translate one image however we choose by sliding all the 1 bits left, right, up, and/or down any number of units. We then place it on top of the other image. We can then calculate the overlap by counting the number of positions that have a 1 in both images.\n Note also that a translation does not include any kind of rotation. Any 1 bits that are translated outside of the matrix borders are erased.\n Return the largest possible overlap.\n \n Example 1:\n \n \n >>> largestOverlap(img1 = [[1,1,0],[0,1,0],[0,1,0]], img2 = [[0,0,0],[0,1,1],[0,0,1]])\n >>> 3\n Explanation: We translate img1 to right by 1 unit and down by 1 unit.\n \n The number of positions that have a 1 in both images is 3 (shown in red).\n \n \n Example 2:\n \n >>> largestOverlap(img1 = [[1]], img2 = [[1]])\n >>> 1\n \n Example 3:\n \n >>> largestOverlap(img1 = [[0]], img2 = [[0]])\n >>> 0\n \"\"\"\n"}
{"task_id": "rectangle-overlap", "prompt": "def isRectangleOverlap(rec1: List[int], rec2: List[int]) -> bool:\n \"\"\"\n An axis-aligned rectangle is represented as a list [x1, y1, x2, y2], where (x1, y1) is the coordinate of its bottom-left corner, and (x2, y2) is the coordinate of its top-right corner. Its top and bottom edges are parallel to the X-axis, and its left and right edges are parallel to the Y-axis.\n Two rectangles overlap if the area of their intersection is positive. To be clear, two rectangles that only touch at the corner or edges do not overlap.\n Given two axis-aligned rectangles rec1 and rec2, return true if they overlap, otherwise return false.\n \n Example 1:\n >>> isRectangleOverlap(rec1 = [0,0,2,2], rec2 = [1,1,3,3])\n >>> true\n Example 2:\n >>> isRectangleOverlap(rec1 = [0,0,1,1], rec2 = [1,0,2,1])\n >>> false\n Example 3:\n >>> isRectangleOverlap(rec1 = [0,0,1,1], rec2 = [2,2,3,3])\n >>> false\n \"\"\"\n"}
{"task_id": "new-21-game", "prompt": "def new21Game(n: int, k: int, maxPts: int) -> float:\n \"\"\"\n Alice plays the following game, loosely based on the card game \"21\".\n Alice starts with 0 points and draws numbers while she has less than k points. During each draw, she gains an integer number of points randomly from the range [1, maxPts], where maxPts is an integer. Each draw is independent and the outcomes have equal probabilities.\n Alice stops drawing numbers when she gets k or more points.\n Return the probability that Alice has n or fewer points.\n Answers within 10-5 of the actual answer are considered accepted.\n \n Example 1:\n \n >>> new21Game(n = 10, k = 1, maxPts = 10)\n >>> 1.00000\n Explanation: Alice gets a single card, then stops.\n \n Example 2:\n \n >>> new21Game(n = 6, k = 1, maxPts = 10)\n >>> 0.60000\n Explanation: Alice gets a single card, then stops.\n In 6 out of 10 possibilities, she is at or below 6 points.\n \n Example 3:\n \n >>> new21Game(n = 21, k = 17, maxPts = 10)\n >>> 0.73278\n \"\"\"\n"}
{"task_id": "push-dominoes", "prompt": "def pushDominoes(dominoes: str) -> str:\n \"\"\"\n There are n dominoes in a line, and we place each domino vertically upright. In the beginning, we simultaneously push some of the dominoes either to the left or to the right.\n After each second, each domino that is falling to the left pushes the adjacent domino on the left. Similarly, the dominoes falling to the right push their adjacent dominoes standing on the right.\n When a vertical domino has dominoes falling on it from both sides, it stays still due to the balance of the forces.\n For the purposes of this question, we will consider that a falling domino expends no additional force to a falling or already fallen domino.\n You are given a string dominoes representing the initial state where:\n \n dominoes[i] = 'L', if the ith domino has been pushed to the left,\n dominoes[i] = 'R', if the ith domino has been pushed to the right, and\n dominoes[i] = '.', if the ith domino has not been pushed.\n \n Return a string representing the final state.\n \n Example 1:\n \n >>> pushDominoes(dominoes = \"RR.L\")\n >>> \"RR.L\"\n Explanation: The first domino expends no additional force on the second domino.\n \n Example 2:\n \n \n >>> pushDominoes(dominoes = \".L.R...LR..L..\")\n >>> \"LL.RR.LLRRLL..\"\n \"\"\"\n"}
{"task_id": "similar-string-groups", "prompt": "def numSimilarGroups(strs: List[str]) -> int:\n \"\"\"\n Two strings, X and Y, are considered similar if either they are identical or we can make them equivalent by swapping at most two letters (in distinct positions) within the string X.\n For example, \"tars\"\u00a0and \"rats\"\u00a0are similar (swapping at positions 0 and 2), and \"rats\" and \"arts\" are similar, but \"star\" is not similar to \"tars\", \"rats\", or \"arts\".\n Together, these form two connected groups by similarity: {\"tars\", \"rats\", \"arts\"} and {\"star\"}.\u00a0 Notice that \"tars\" and \"arts\" are in the same group even though they are not similar.\u00a0 Formally, each group is such that a word is in the group if and only if it is similar to at least one other word in the group.\n We are given a list strs of strings where every string in strs is an anagram of every other string in strs. How many groups are there?\n \n Example 1:\n \n >>> numSimilarGroups(strs = [\"tars\",\"rats\",\"arts\",\"star\"])\n >>> 2\n \n Example 2:\n \n >>> numSimilarGroups(strs = [\"omv\",\"ovm\"])\n >>> 1\n \"\"\"\n"}
{"task_id": "magic-squares-in-grid", "prompt": "def numMagicSquaresInside(grid: List[List[int]]) -> int:\n \"\"\"\n A 3 x 3 magic square is a 3 x 3 grid filled with distinct numbers from 1 to 9 such that each row, column, and both diagonals all have the same sum.\n Given a row x col grid of integers, how many 3 x 3 magic square subgrids are there?\n Note: while a magic square can only contain numbers from 1 to 9, grid may contain numbers up to 15.\n \n Example 1:\n \n \n >>> numMagicSquaresInside(grid = [[4,3,8,4],[9,5,1,9],[2,7,6,2]])\n >>> 1\n Explanation:\n The following subgrid is a 3 x 3 magic square:\n \n while this one is not:\n \n In total, there is only one magic square inside the given grid.\n \n Example 2:\n \n >>> numMagicSquaresInside(grid = [[8]])\n >>> 0\n \"\"\"\n"}
{"task_id": "keys-and-rooms", "prompt": "def canVisitAllRooms(rooms: List[List[int]]) -> bool:\n \"\"\"\n There are n rooms labeled from 0 to n - 1\u00a0and all the rooms are locked except for room 0. Your goal is to visit all the rooms. However, you cannot enter a locked room without having its key.\n When you visit a room, you may find a set of distinct keys in it. Each key has a number on it, denoting which room it unlocks, and you can take all of them with you to unlock the other rooms.\n Given an array rooms where rooms[i] is the set of keys that you can obtain if you visited room i, return true if you can visit all the rooms, or false otherwise.\n \n Example 1:\n \n >>> canVisitAllRooms(rooms = [[1],[2],[3],[]])\n >>> true\n Explanation:\n We visit room 0 and pick up key 1.\n We then visit room 1 and pick up key 2.\n We then visit room 2 and pick up key 3.\n We then visit room 3.\n Since we were able to visit every room, we return true.\n \n Example 2:\n \n >>> canVisitAllRooms(rooms = [[1,3],[3,0,1],[2],[0]])\n >>> false\n Explanation: We can not enter room number 2 since the only key that unlocks it is in that room.\n \"\"\"\n"}
{"task_id": "split-array-into-fibonacci-sequence", "prompt": "def splitIntoFibonacci(num: str) -> List[int]:\n \"\"\"\n You are given a string of digits num, such as \"123456579\". We can split it into a Fibonacci-like sequence [123, 456, 579].\n Formally, a Fibonacci-like sequence is a list f of non-negative integers such that:\n \n 0 <= f[i] < 231, (that is, each integer fits in a 32-bit signed integer type),\n f.length >= 3, and\n f[i] + f[i + 1] == f[i + 2] for all 0 <= i < f.length - 2.\n \n Note that when splitting the string into pieces, each piece must not have extra leading zeroes, except if the piece is the number 0 itself.\n Return any Fibonacci-like sequence split from num, or return [] if it cannot be done.\n \n Example 1:\n \n >>> splitIntoFibonacci(num = \"1101111\")\n >>> [11,0,11,11]\n Explanation: The output [110, 1, 111] would also be accepted.\n \n Example 2:\n \n >>> splitIntoFibonacci(num = \"112358130\")\n >>> []\n Explanation: The task is impossible.\n \n Example 3:\n \n >>> splitIntoFibonacci(num = \"0123\")\n >>> []\n Explanation: Leading zeroes are not allowed, so \"01\", \"2\", \"3\" is not valid.\n \"\"\"\n"}
{"task_id": "backspace-string-compare", "prompt": "def backspaceCompare(s: str, t: str) -> bool:\n \"\"\"\n Given two strings s and t, return true if they are equal when both are typed into empty text editors. '#' means a backspace character.\n Note that after backspacing an empty text, the text will continue empty.\n \n Example 1:\n \n >>> backspaceCompare(s = \"ab#c\", t = \"ad#c\")\n >>> true\n Explanation: Both s and t become \"ac\".\n \n Example 2:\n \n >>> backspaceCompare(s = \"ab##\", t = \"c#d#\")\n >>> true\n Explanation: Both s and t become \"\".\n \n Example 3:\n \n >>> backspaceCompare(s = \"a#c\", t = \"b\")\n >>> false\n Explanation: s becomes \"c\" while t becomes \"b\".\n \"\"\"\n"}
{"task_id": "longest-mountain-in-array", "prompt": "def longestMountain(arr: List[int]) -> int:\n \"\"\"\n You may recall that an array arr is a mountain array if and only if:\n \n arr.length >= 3\n There exists some index i (0-indexed) with 0 < i < arr.length - 1 such that:\n \n arr[0] < arr[1] < ... < arr[i - 1] < arr[i]\n arr[i] > arr[i + 1] > ... > arr[arr.length - 1]\n \n \n \n Given an integer array arr, return the length of the longest subarray, which is a mountain. Return 0 if there is no mountain subarray.\n \n Example 1:\n \n >>> longestMountain(arr = [2,1,4,7,3,2,5])\n >>> 5\n Explanation: The largest mountain is [1,4,7,3,2] which has length 5.\n \n Example 2:\n \n >>> longestMountain(arr = [2,2,2])\n >>> 0\n Explanation: There is no mountain.\n \"\"\"\n"}
{"task_id": "hand-of-straights", "prompt": "def isNStraightHand(hand: List[int], groupSize: int) -> bool:\n \"\"\"\n Alice has some number of cards and she wants to rearrange the cards into groups so that each group is of size groupSize, and consists of groupSize consecutive cards.\n Given an integer array hand where hand[i] is the value written on the ith card and an integer groupSize, return true if she can rearrange the cards, or false otherwise.\n \n Example 1:\n \n >>> isNStraightHand(hand = [1,2,3,6,2,3,4,7,8], groupSize = 3)\n >>> true\n Explanation: Alice's hand can be rearranged as [1,2,3],[2,3,4],[6,7,8]\n \n Example 2:\n \n >>> isNStraightHand(hand = [1,2,3,4,5], groupSize = 4)\n >>> false\n Explanation: Alice's hand can not be rearranged into groups of 4.\n \"\"\"\n"}
{"task_id": "shortest-path-visiting-all-nodes", "prompt": "def shortestPathLength(graph: List[List[int]]) -> int:\n \"\"\"\n You have an undirected, connected graph of n nodes labeled from 0 to n - 1. You are given an array graph where graph[i] is a list of all the nodes connected with node i by an edge.\n Return the length of the shortest path that visits every node. You may start and stop at any node, you may revisit nodes multiple times, and you may reuse edges.\n \n Example 1:\n \n \n >>> shortestPathLength(graph = [[1,2,3],[0],[0],[0]])\n >>> 4\n Explanation: One possible path is [1,0,2,0,3]\n \n Example 2:\n \n \n >>> shortestPathLength(graph = [[1],[0,2,4],[1,3,4],[2],[1,2]])\n >>> 4\n Explanation: One possible path is [0,1,4,2,3]\n \"\"\"\n"}
{"task_id": "shifting-letters", "prompt": "def shiftingLetters(s: str, shifts: List[int]) -> str:\n \"\"\"\n You are given a string s of lowercase English letters and an integer array shifts of the same length.\n Call the shift() of a letter, the next letter in the alphabet, (wrapping around so that 'z' becomes 'a').\n \n For example, shift('a') = 'b', shift('t') = 'u', and shift('z') = 'a'.\n \n Now for each shifts[i] = x, we want to shift the first i + 1 letters of s, x times.\n Return the final string after all such shifts to s are applied.\n \n Example 1:\n \n >>> shiftingLetters(s = \"abc\", shifts = [3,5,9])\n >>> \"rpl\"\n Explanation: We start with \"abc\".\n After shifting the first 1 letters of s by 3, we have \"dbc\".\n After shifting the first 2 letters of s by 5, we have \"igc\".\n After shifting the first 3 letters of s by 9, we have \"rpl\", the answer.\n \n Example 2:\n \n >>> shiftingLetters(s = \"aaa\", shifts = [1,2,3])\n >>> \"gfd\"\n \"\"\"\n"}
{"task_id": "maximize-distance-to-closest-person", "prompt": "def maxDistToClosest(seats: List[int]) -> int:\n \"\"\"\n You are given an array representing a row of seats where seats[i] = 1 represents a person sitting in the ith seat, and seats[i] = 0 represents that the ith seat is empty (0-indexed).\n There is at least one empty seat, and at least one person sitting.\n Alex wants to sit in the seat such that the distance between him and the closest person to him is maximized.\n Return that maximum distance to the closest person.\n \n Example 1:\n \n \n >>> maxDistToClosest(seats = [1,0,0,0,1,0,1])\n >>> 2\n Explanation:\n If Alex sits in the second open seat (i.e. seats[2]), then the closest person has distance 2.\n If Alex sits in any other open seat, the closest person has distance 1.\n Thus, the maximum distance to the closest person is 2.\n \n Example 2:\n \n >>> maxDistToClosest(seats = [1,0,0,0])\n >>> 3\n Explanation:\n If Alex sits in the last seat (i.e. seats[3]), the closest person is 3 seats away.\n This is the maximum distance possible, so the answer is 3.\n \n Example 3:\n \n >>> maxDistToClosest(seats = [0,1])\n >>> 1\n \"\"\"\n"}
{"task_id": "rectangle-area-ii", "prompt": "def rectangleArea(rectangles: List[List[int]]) -> int:\n \"\"\"\n You are given a 2D array of axis-aligned rectangles. Each rectangle[i] = [xi1, yi1, xi2, yi2] denotes the ith rectangle where (xi1, yi1) are the coordinates of the bottom-left corner, and (xi2, yi2) are the coordinates of the top-right corner.\n Calculate the total area covered by all rectangles in the plane. Any area covered by two or more rectangles should only be counted once.\n Return the total area. Since the answer may be too large, return it modulo 109 + 7.\n \n Example 1:\n \n \n >>> rectangleArea(rectangles = [[0,0,2,2],[1,0,2,3],[1,0,3,1]])\n >>> 6\n Explanation: A total area of 6 is covered by all three rectangles, as illustrated in the picture.\n From (1,1) to (2,2), the green and red rectangles overlap.\n From (1,0) to (2,3), all three rectangles overlap.\n \n Example 2:\n \n >>> rectangleArea(rectangles = [[0,0,1000000000,1000000000]])\n >>> 49\n Explanation: The answer is 1018 modulo (109 + 7), which is 49.\n \"\"\"\n"}
{"task_id": "loud-and-rich", "prompt": "def loudAndRich(richer: List[List[int]], quiet: List[int]) -> List[int]:\n \"\"\"\n There is a group of n people labeled from 0 to n - 1 where each person has a different amount of money and a different level of quietness.\n You are given an array richer where richer[i] = [ai, bi] indicates that ai has more money than bi and an integer array quiet where quiet[i] is the quietness of the ith person. All the given data in richer are logically correct (i.e., the data will not lead you to a situation where x is richer than y and y is richer than x at the same time).\n Return an integer array answer where answer[x] = y if y is the least quiet person (that is, the person y with the smallest value of quiet[y]) among all people who definitely have equal to or more money than the person x.\n \n Example 1:\n \n >>> loudAndRich(richer = [[1,0],[2,1],[3,1],[3,7],[4,3],[5,3],[6,3]], quiet = [3,2,5,4,6,1,7,0])\n >>> [5,5,2,5,4,5,6,7]\n Explanation:\n answer[0] = 5.\n Person 5 has more money than 3, which has more money than 1, which has more money than 0.\n The only person who is quieter (has lower quiet[x]) is person 7, but it is not clear if they have more money than person 0.\n answer[7] = 7.\n Among all people that definitely have equal to or more money than person 7 (which could be persons 3, 4, 5, 6, or 7), the person who is the quietest (has lower quiet[x]) is person 7.\n The other answers can be filled out with similar reasoning.\n \n Example 2:\n \n >>> loudAndRich(richer = [], quiet = [0])\n >>> [0]\n \"\"\"\n"}
{"task_id": "peak-index-in-a-mountain-array", "prompt": "def peakIndexInMountainArray(arr: List[int]) -> int:\n \"\"\"\n You are given an integer mountain array arr of length n where the values increase to a peak element and then decrease.\n Return the index of the peak element.\n Your task is to solve it in O(log(n)) time complexity.\n \n Example 1:\n \n >>> peakIndexInMountainArray(arr = [0,1,0])\n >>> 1\n \n Example 2:\n \n >>> peakIndexInMountainArray(arr = [0,2,1,0])\n >>> 1\n \n Example 3:\n \n >>> peakIndexInMountainArray(arr = [0,10,5,2])\n >>> 1\n \"\"\"\n"}
{"task_id": "car-fleet", "prompt": "def carFleet(target: int, position: List[int], speed: List[int]) -> int:\n \"\"\"\n There are n cars at given miles away from the starting mile 0, traveling to reach the mile target.\n You are given two integer array position and speed, both of length n, where position[i] is the starting mile of the ith car and speed[i] is the speed of the ith car in miles per hour.\n A car cannot pass another car, but it can catch up and then travel next to it at the speed of the slower car.\n A car fleet is a car or cars driving next to each other. The speed of the car fleet is the minimum speed of any car in the fleet.\n If a car catches up to a car fleet at the mile target, it will still be considered as part of the car fleet.\n Return the number of car fleets that will arrive at the destination.\n \n Example 1:\n \n >>> carFleet(target = 12, position = [10,8,0,5,3], speed = [2,4,1,1,3])\n >>> 3\n Explanation:\n \n The cars starting at 10 (speed 2) and 8 (speed 4) become a fleet, meeting each other at 12. The fleet forms at target.\n The car starting at 0 (speed 1) does not catch up to any other car, so it is a fleet by itself.\n The cars starting at 5 (speed 1) and 3 (speed 3) become a fleet, meeting each other at 6. The fleet moves at speed 1 until it reaches target.\n \n \n Example 2:\n \n >>> carFleet(target = 10, position = [3], speed = [3])\n >>> 1\n Explanation:\n There is only one car, hence there is only one fleet.\n Example 3:\n \n >>> carFleet(target = 100, position = [0,2,4], speed = [4,2,1])\n >>> 1\n Explanation:\n \n The cars starting at 0 (speed 4) and 2 (speed 2) become a fleet, meeting each other at 4. The car starting at 4 (speed 1) travels to 5.\n Then, the fleet at 4 (speed 2) and the car at position 5 (speed 1) become one fleet, meeting each other at 6. The fleet moves at speed 1 until it reaches target.\n \"\"\"\n"}
{"task_id": "k-similar-strings", "prompt": "def kSimilarity(s1: str, s2: str) -> int:\n \"\"\"\n Strings s1 and s2 are k-similar (for some non-negative integer k) if we can swap the positions of two letters in s1 exactly k times so that the resulting string equals s2.\n Given two anagrams s1 and s2, return the smallest k for which s1 and s2 are k-similar.\n \n Example 1:\n \n >>> kSimilarity(s1 = \"ab\", s2 = \"ba\")\n >>> 1\n Explanation: The two string are 1-similar because we can use one swap to change s1 to s2: \"ab\" --> \"ba\".\n \n Example 2:\n \n >>> kSimilarity(s1 = \"abc\", s2 = \"bca\")\n >>> 2\n Explanation: The two strings are 2-similar because we can use two swaps to change s1 to s2: \"abc\" --> \"bac\" --> \"bca\".\n \"\"\"\n"}
{"task_id": "score-of-parentheses", "prompt": "def scoreOfParentheses(s: str) -> int:\n \"\"\"\n Given a balanced parentheses string s, return the score of the string.\n The score of a balanced parentheses string is based on the following rule:\n \n \"()\" has score 1.\n AB has score A + B, where A and B are balanced parentheses strings.\n (A) has score 2 * A, where A is a balanced parentheses string.\n \n \n Example 1:\n \n >>> scoreOfParentheses(s = \"()\")\n >>> 1\n \n Example 2:\n \n >>> scoreOfParentheses(s = \"(())\")\n >>> 2\n \n Example 3:\n \n >>> scoreOfParentheses(s = \"()()\")\n >>> 2\n \"\"\"\n"}
{"task_id": "minimum-cost-to-hire-k-workers", "prompt": "def mincostToHireWorkers(quality: List[int], wage: List[int], k: int) -> float:\n \"\"\"\n There are n workers. You are given two integer arrays quality and wage where quality[i] is the quality of the ith worker and wage[i] is the minimum wage expectation for the ith worker.\n We want to hire exactly k workers to form a paid group. To hire a group of k workers, we must pay them according to the following rules:\n \n Every worker in the paid group must be paid at least their minimum wage expectation.\n In the group, each worker's pay must be directly proportional to their quality. This means if a worker\u2019s quality is double that of another worker in the group, then they must be paid twice as much as the other worker.\n \n Given the integer k, return the least amount of money needed to form a paid group satisfying the above conditions. Answers within 10-5 of the actual answer will be accepted.\n \n Example 1:\n \n >>> mincostToHireWorkers(quality = [10,20,5], wage = [70,50,30], k = 2)\n >>> 105.00000\n Explanation: We pay 70 to 0th worker and 35 to 2nd worker.\n \n Example 2:\n \n >>> mincostToHireWorkers(quality = [3,1,10,10,1], wage = [4,8,2,2,7], k = 3)\n >>> 30.66667\n Explanation: We pay 4 to 0th worker, 13.33333 to 2nd and 3rd workers separately.\n \"\"\"\n"}
{"task_id": "mirror-reflection", "prompt": "def mirrorReflection(p: int, q: int) -> int:\n \"\"\"\n There is a special square room with mirrors on each of the four walls. Except for the southwest corner, there are receptors on each of the remaining corners, numbered 0, 1, and 2.\n The square room has walls of length p\u00a0and a laser ray from the southwest corner first meets the east wall at a distance q from the 0th receptor.\n Given the two integers p and q, return the number of the receptor that the ray meets first.\n The test cases are guaranteed so that the ray will meet a receptor eventually.\n \n Example 1:\n \n \n >>> mirrorReflection(p = 2, q = 1)\n >>> 2\n Explanation: The ray meets receptor 2 the first time it gets reflected back to the left wall.\n \n Example 2:\n \n >>> mirrorReflection(p = 3, q = 1)\n >>> 1\n \"\"\"\n"}
{"task_id": "buddy-strings", "prompt": "def buddyStrings(s: str, goal: str) -> bool:\n \"\"\"\n Given two strings s and goal, return true if you can swap two letters in s so the result is equal to goal, otherwise, return false.\n Swapping letters is defined as taking two indices i and j (0-indexed) such that i != j and swapping the characters at s[i] and s[j].\n \n For example, swapping at indices 0 and 2 in \"abcd\" results in \"cbad\".\n \n \n Example 1:\n \n >>> buddyStrings(s = \"ab\", goal = \"ba\")\n >>> true\n Explanation: You can swap s[0] = 'a' and s[1] = 'b' to get \"ba\", which is equal to goal.\n \n Example 2:\n \n >>> buddyStrings(s = \"ab\", goal = \"ab\")\n >>> false\n Explanation: The only letters you can swap are s[0] = 'a' and s[1] = 'b', which results in \"ba\" != goal.\n \n Example 3:\n \n >>> buddyStrings(s = \"aa\", goal = \"aa\")\n >>> true\n Explanation: You can swap s[0] = 'a' and s[1] = 'a' to get \"aa\", which is equal to goal.\n \"\"\"\n"}
{"task_id": "lemonade-change", "prompt": "def lemonadeChange(bills: List[int]) -> bool:\n \"\"\"\n At a lemonade stand, each lemonade costs $5. Customers are standing in a queue to buy from you and order one at a time (in the order specified by bills). Each customer will only buy one lemonade and pay with either a $5, $10, or $20 bill. You must provide the correct change to each customer so that the net transaction is that the customer pays $5.\n Note that you do not have any change in hand at first.\n Given an integer array bills where bills[i] is the bill the ith customer pays, return true if you can provide every customer with the correct change, or false otherwise.\n \n Example 1:\n \n >>> lemonadeChange(bills = [5,5,5,10,20])\n >>> true\n Explanation:\n From the first 3 customers, we collect three $5 bills in order.\n From the fourth customer, we collect a $10 bill and give back a $5.\n From the fifth customer, we give a $10 bill and a $5 bill.\n Since all customers got correct change, we output true.\n \n Example 2:\n \n >>> lemonadeChange(bills = [5,5,10,10,20])\n >>> false\n Explanation:\n From the first two customers in order, we collect two $5 bills.\n For the next two customers in order, we collect a $10 bill and give back a $5 bill.\n For the last customer, we can not give the change of $15 back because we only have two $10 bills.\n Since not every customer received the correct change, the answer is false.\n \"\"\"\n"}
{"task_id": "score-after-flipping-matrix", "prompt": "def matrixScore(grid: List[List[int]]) -> int:\n \"\"\"\n You are given an m x n binary matrix grid.\n A move consists of choosing any row or column and toggling each value in that row or column (i.e., changing all 0's to 1's, and all 1's to 0's).\n Every row of the matrix is interpreted as a binary number, and the score of the matrix is the sum of these numbers.\n Return the highest possible score after making any number of moves (including zero moves).\n \n Example 1:\n \n \n >>> matrixScore(grid = [[0,0,1,1],[1,0,1,0],[1,1,0,0]])\n >>> 39\n Explanation: 0b1111 + 0b1001 + 0b1111 = 15 + 9 + 15 = 39\n \n Example 2:\n \n >>> matrixScore(grid = [[0]])\n >>> 1\n \"\"\"\n"}
{"task_id": "shortest-subarray-with-sum-at-least-k", "prompt": "def shortestSubarray(nums: List[int], k: int) -> int:\n \"\"\"\n Given an integer array nums and an integer k, return the length of the shortest non-empty subarray of nums with a sum of at least k. If there is no such subarray, return -1.\n A subarray is a contiguous part of an array.\n \n Example 1:\n >>> shortestSubarray(nums = [1], k = 1)\n >>> 1\n Example 2:\n >>> shortestSubarray(nums = [1,2], k = 4)\n >>> -1\n Example 3:\n >>> shortestSubarray(nums = [2,-1,2], k = 3)\n >>> 3\n \"\"\"\n"}
{"task_id": "shortest-path-to-get-all-keys", "prompt": "def shortestPathAllKeys(grid: List[str]) -> int:\n \"\"\"\n You are given an m x n grid grid where:\n \n '.' is an empty cell.\n '#' is a wall.\n '@' is the starting point.\n Lowercase letters represent keys.\n Uppercase letters represent locks.\n \n You start at the starting point and one move consists of walking one space in one of the four cardinal directions. You cannot walk outside the grid, or walk into a wall.\n If you walk over a key, you can pick it up and you cannot walk over a lock unless you have its corresponding key.\n For some 1 <= k <= 6, there is exactly one lowercase and one uppercase letter of the first k letters of the English alphabet in the grid. This means that there is exactly one key for each lock, and one lock for each key; and also that the letters used to represent the keys and locks were chosen in the same order as the English alphabet.\n Return the lowest number of moves to acquire all keys. If it is impossible, return -1.\n \n Example 1:\n \n \n >>> shortestPathAllKeys(grid = [\"@.a..\",\"###.#\",\"b.A.B\"])\n >>> 8\n Explanation: Note that the goal is to obtain all the keys not to open all the locks.\n \n Example 2:\n \n \n >>> shortestPathAllKeys(grid = [\"@..aA\",\"..B#.\",\"....b\"])\n >>> 6\n \n Example 3:\n \n \n >>> shortestPathAllKeys(grid = [\"@Aa\"])\n >>> -1\n \"\"\"\n"}
{"task_id": "smallest-subtree-with-all-the-deepest-nodes", "prompt": "# class TreeNode:\n# def __init__(val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def subtreeWithAllDeepest(root: Optional[TreeNode]) -> Optional[TreeNode]:\n \"\"\"\n Given the root of a binary tree, the depth of each node is the shortest distance to the root.\n Return the smallest subtree such that it contains all the deepest nodes in the original tree.\n A node is called the deepest if it has the largest depth possible among any node in the entire tree.\n The subtree of a node is a tree consisting of that node, plus the set of all descendants of that node.\n \n Example 1:\n \n \n >>> __init__(root = [3,5,1,6,2,0,8,null,null,7,4])\n >>> [2,7,4]\n Explanation: We return the node with value 2, colored in yellow in the diagram.\n The nodes coloured in blue are the deepest nodes of the tree.\n Notice that nodes 5, 3 and 2 contain the deepest nodes in the tree but node 2 is the smallest subtree among them, so we return it.\n \n Example 2:\n \n >>> __init__(root = [1])\n >>> [1]\n Explanation: The root is the deepest node in the tree.\n \n Example 3:\n \n >>> __init__(root = [0,1,3,null,2])\n >>> [2]\n Explanation: The deepest node in the tree is 2, the valid subtrees are the subtrees of nodes 2, 1 and 0 but the subtree of node 2 is the smallest.\n \"\"\"\n"}
{"task_id": "prime-palindrome", "prompt": "def primePalindrome(n: int) -> int:\n \"\"\"\n Given an integer n, return the smallest prime palindrome greater than or equal to n.\n An integer is prime if it has exactly two divisors: 1 and itself. Note that 1 is not a prime number.\n \n For example, 2, 3, 5, 7, 11, and 13 are all primes.\n \n An integer is a palindrome if it reads the same from left to right as it does from right to left.\n \n For example, 101 and 12321 are palindromes.\n \n The test cases are generated so that the answer always exists and is in the range [2, 2 * 108].\n \n Example 1:\n >>> primePalindrome(n = 6)\n >>> 7\n Example 2:\n >>> primePalindrome(n = 8)\n >>> 11\n Example 3:\n >>> primePalindrome(n = 13)\n >>> 101\n \"\"\"\n"}
{"task_id": "transpose-matrix", "prompt": "def transpose(matrix: List[List[int]]) -> List[List[int]]:\n \"\"\"\n Given a 2D integer array matrix, return the transpose of matrix.\n The transpose of a matrix is the matrix flipped over its main diagonal, switching the matrix's row and column indices.\n \n \n Example 1:\n \n >>> transpose(matrix = [[1,2,3],[4,5,6],[7,8,9]])\n >>> [[1,4,7],[2,5,8],[3,6,9]]\n \n Example 2:\n \n >>> transpose(matrix = [[1,2,3],[4,5,6]])\n >>> [[1,4],[2,5],[3,6]]\n \"\"\"\n"}
{"task_id": "binary-gap", "prompt": "def binaryGap(n: int) -> int:\n \"\"\"\n Given a positive integer n, find and return the longest distance between any two adjacent 1's in the binary representation of n. If there are no two adjacent 1's, return 0.\n Two 1's are adjacent if there are only 0's separating them (possibly no 0's). The distance between two 1's is the absolute difference between their bit positions. For example, the two 1's in \"1001\" have a distance of 3.\n \n Example 1:\n \n >>> binaryGap(n = 22)\n >>> 2\n Explanation: 22 in binary is \"10110\".\n The first adjacent pair of 1's is \"10110\" with a distance of 2.\n The second adjacent pair of 1's is \"10110\" with a distance of 1.\n The answer is the largest of these two distances, which is 2.\n Note that \"10110\" is not a valid pair since there is a 1 separating the two 1's underlined.\n \n Example 2:\n \n >>> binaryGap(n = 8)\n >>> 0\n Explanation: 8 in binary is \"1000\".\n There are not any adjacent pairs of 1's in the binary representation of 8, so we return 0.\n \n Example 3:\n \n >>> binaryGap(n = 5)\n >>> 2\n Explanation: 5 in binary is \"101\".\n \"\"\"\n"}
{"task_id": "reordered-power-of-2", "prompt": "def reorderedPowerOf2(n: int) -> bool:\n \"\"\"\n You are given an integer n. We reorder the digits in any order (including the original order) such that the leading digit is not zero.\n Return true if and only if we can do this so that the resulting number is a power of two.\n \n Example 1:\n \n >>> reorderedPowerOf2(n = 1)\n >>> true\n \n Example 2:\n \n >>> reorderedPowerOf2(n = 10)\n >>> false\n \"\"\"\n"}
{"task_id": "advantage-shuffle", "prompt": "def advantageCount(nums1: List[int], nums2: List[int]) -> List[int]:\n \"\"\"\n You are given two integer arrays nums1 and nums2 both of the same length. The advantage of nums1 with respect to nums2 is the number of indices i for which nums1[i] > nums2[i].\n Return any permutation of nums1 that maximizes its advantage with respect to nums2.\n \n Example 1:\n >>> advantageCount(nums1 = [2,7,11,15], nums2 = [1,10,4,11])\n >>> [2,11,7,15]\n Example 2:\n >>> advantageCount(nums1 = [12,24,8,32], nums2 = [13,25,32,11])\n >>> [24,32,8,12]\n \"\"\"\n"}
{"task_id": "minimum-number-of-refueling-stops", "prompt": "def minRefuelStops(target: int, startFuel: int, stations: List[List[int]]) -> int:\n \"\"\"\n A car travels from a starting position to a destination which is target miles east of the starting position.\n There are gas stations along the way. The gas stations are represented as an array stations where stations[i] = [positioni, fueli] indicates that the ith gas station is positioni miles east of the starting position and has fueli liters of gas.\n The car starts with an infinite tank of gas, which initially has startFuel liters of fuel in it. It uses one liter of gas per one mile that it drives. When the car reaches a gas station, it may stop and refuel, transferring all the gas from the station into the car.\n Return the minimum number of refueling stops the car must make in order to reach its destination. If it cannot reach the destination, return -1.\n Note that if the car reaches a gas station with 0 fuel left, the car can still refuel there. If the car reaches the destination with 0 fuel left, it is still considered to have arrived.\n \n Example 1:\n \n >>> minRefuelStops(target = 1, startFuel = 1, stations = [])\n >>> 0\n Explanation: We can reach the target without refueling.\n \n Example 2:\n \n >>> minRefuelStops(target = 100, startFuel = 1, stations = [[10,100]])\n >>> -1\n Explanation: We can not reach the target (or even the first gas station).\n \n Example 3:\n \n >>> minRefuelStops(target = 100, startFuel = 10, stations = [[10,60],[20,30],[30,30],[60,40]])\n >>> 2\n Explanation: We start with 10 liters of fuel.\n We drive to position 10, expending 10 liters of fuel. We refuel from 0 liters to 60 liters of gas.\n Then, we drive from position 10 to position 60 (expending 50 liters of fuel),\n and refuel from 10 liters to 50 liters of gas. We then drive to and reach the target.\n We made 2 refueling stops along the way, so we return 2.\n \"\"\"\n"}
{"task_id": "leaf-similar-trees", "prompt": "# class TreeNode:\n# def __init__(val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def leafSimilar(root1: Optional[TreeNode], root2: Optional[TreeNode]) -> bool:\n \"\"\"\n Consider all the leaves of a binary tree, from\u00a0left to right order, the values of those\u00a0leaves form a leaf value sequence.\n \n For example, in the given tree above, the leaf value sequence is (6, 7, 4, 9, 8).\n Two binary trees are considered leaf-similar\u00a0if their leaf value sequence is the same.\n Return true if and only if the two given trees with head nodes root1 and root2 are leaf-similar.\n \n Example 1:\n \n \n >>> __init__(root1 = [3,5,1,6,2,9,8,null,null,7,4], root2 = [3,5,1,6,7,4,2,null,null,null,null,null,null,9,8])\n >>> true\n \n Example 2:\n \n \n >>> __init__(root1 = [1,2,3], root2 = [1,3,2])\n >>> false\n \"\"\"\n"}
{"task_id": "length-of-longest-fibonacci-subsequence", "prompt": "def lenLongestFibSubseq(arr: List[int]) -> int:\n \"\"\"\n A sequence x1, x2, ..., xn is Fibonacci-like if:\n \n n >= 3\n xi + xi+1 == xi+2 for all i + 2 <= n\n \n Given a strictly increasing array arr of positive integers forming a sequence, return the length of the longest Fibonacci-like subsequence of arr. If one does not exist, return 0.\n A subsequence is derived from another sequence arr by deleting any number of elements (including none) from arr, without changing the order of the remaining elements. For example, [3, 5, 8] is a subsequence of [3, 4, 5, 6, 7, 8].\n \n Example 1:\n \n >>> lenLongestFibSubseq(arr = [1,2,3,4,5,6,7,8])\n >>> 5\n Explanation: The longest subsequence that is fibonacci-like: [1,2,3,5,8].\n Example 2:\n \n >>> lenLongestFibSubseq(arr = [1,3,7,11,12,14,18])\n >>> 3\n Explanation: The longest subsequence that is fibonacci-like: [1,11,12], [3,11,14] or [7,11,18].\n \"\"\"\n"}
{"task_id": "walking-robot-simulation", "prompt": "def robotSim(commands: List[int], obstacles: List[List[int]]) -> int:\n \"\"\"\n A robot on an infinite XY-plane starts at point (0, 0) facing north. The robot receives an array of integers commands, which represents a sequence of moves that it needs to execute. There are only three possible types of instructions the robot can receive:\n \n -2: Turn left 90 degrees.\n -1: Turn right 90 degrees.\n 1 <= k <= 9: Move forward k units, one unit at a time.\n \n Some of the grid squares are obstacles. The ith obstacle is at grid point obstacles[i] = (xi, yi). If the robot runs into an obstacle, it will stay in its current location (on the block adjacent to the obstacle) and move onto the next command.\n Return the maximum squared Euclidean distance that the robot reaches at any point in its path (i.e. if the distance is 5, return 25).\n Note:\n \n There can be an obstacle at (0, 0). If this happens, the robot will ignore the obstacle until it has moved off the origin. However, it will be unable to return to (0, 0) due to the obstacle.\n North means +Y direction.\n East means +X direction.\n South means -Y direction.\n West means -X direction.\n \n \n Example 1:\n \n >>> robotSim(commands = [4,-1,3], obstacles = [])\n >>> 25\n Explanation:\n The robot starts at (0, 0):\n \n Move north 4 units to (0, 4).\n Turn right.\n Move east 3 units to (3, 4).\n \n The furthest point the robot ever gets from the origin is (3, 4), which squared is 32 + 42 = 25 units away.\n \n Example 2:\n \n >>> robotSim(commands = [4,-1,4,-2,4], obstacles = [[2,4]])\n >>> 65\n Explanation:\n The robot starts at (0, 0):\n \n Move north 4 units to (0, 4).\n Turn right.\n Move east 1 unit and get blocked by the obstacle at (2, 4), robot is at (1, 4).\n Turn left.\n Move north 4 units to (1, 8).\n \n The furthest point the robot ever gets from the origin is (1, 8), which squared is 12 + 82 = 65 units away.\n \n Example 3:\n \n >>> robotSim(commands = [6,-1,-1,6], obstacles = [[0,0]])\n >>> 36\n Explanation:\n The robot starts at (0, 0):\n \n Move north 6 units to (0, 6).\n Turn right.\n Turn right.\n Move south 5 units and get blocked by the obstacle at (0,0), robot is at (0, 1).\n \n The furthest point the robot ever gets from the origin is (0, 6), which squared is 62 = 36 units away.\n \"\"\"\n"}
{"task_id": "koko-eating-bananas", "prompt": "def minEatingSpeed(piles: List[int], h: int) -> int:\n \"\"\"\n Koko loves to eat bananas. There are n piles of bananas, the ith pile has piles[i] bananas. The guards have gone and will come back in h hours.\n Koko can decide her bananas-per-hour eating speed of k. Each hour, she chooses some pile of bananas and eats k bananas from that pile. If the pile has less than k bananas, she eats all of them instead and will not eat any more bananas during this hour.\n Koko likes to eat slowly but still wants to finish eating all the bananas before the guards return.\n Return the minimum integer k such that she can eat all the bananas within h hours.\n \n Example 1:\n \n >>> minEatingSpeed(piles = [3,6,7,11], h = 8)\n >>> 4\n \n Example 2:\n \n >>> minEatingSpeed(piles = [30,11,23,4,20], h = 5)\n >>> 30\n \n Example 3:\n \n >>> minEatingSpeed(piles = [30,11,23,4,20], h = 6)\n >>> 23\n \"\"\"\n"}
{"task_id": "middle-of-the-linked-list", "prompt": "# class ListNode:\n# def __init__(val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution:\n def middleNode(head: Optional[ListNode]) -> Optional[ListNode]:\n \"\"\"\n Given the head of a singly linked list, return the middle node of the linked list.\n If there are two middle nodes, return the second middle node.\n \n Example 1:\n \n \n >>> __init__(head = [1,2,3,4,5])\n >>> [3,4,5]\n Explanation: The middle node of the list is node 3.\n \n Example 2:\n \n \n >>> __init__(head = [1,2,3,4,5,6])\n >>> [4,5,6]\n Explanation: Since the list has two middle nodes with values 3 and 4, we return the second one.\n \"\"\"\n"}
{"task_id": "stone-game", "prompt": "def stoneGame(piles: List[int]) -> bool:\n \"\"\"\n Alice and Bob play a game with piles of stones. There are an even number of piles arranged in a row, and each pile has a positive integer number of stones piles[i].\n The objective of the game is to end with the most stones. The total number of stones across all the piles is odd, so there are no ties.\n Alice and Bob take turns, with Alice starting first. Each turn, a player takes the entire pile of stones either from the beginning or from the end of the row. This continues until there are no more piles left, at which point the person with the most stones wins.\n Assuming Alice and Bob play optimally, return true if Alice wins the game, or false if Bob wins.\n \n Example 1:\n \n >>> stoneGame(piles = [5,3,4,5])\n >>> true\n Explanation:\n Alice starts first, and can only take the first 5 or the last 5.\n Say she takes the first 5, so that the row becomes [3, 4, 5].\n If Bob takes 3, then the board is [4, 5], and Alice takes 5 to win with 10 points.\n If Bob takes the last 5, then the board is [3, 4], and Alice takes 4 to win with 9 points.\n This demonstrated that taking the first 5 was a winning move for Alice, so we return true.\n \n Example 2:\n \n >>> stoneGame(piles = [3,7,2,3])\n >>> true\n \"\"\"\n"}
{"task_id": "nth-magical-number", "prompt": "def nthMagicalNumber(n: int, a: int, b: int) -> int:\n \"\"\"\n A positive integer is magical if it is divisible by either a or b.\n Given the three integers n, a, and b, return the nth magical number. Since the answer may be very large, return it modulo 109 + 7.\n \n Example 1:\n \n >>> nthMagicalNumber(n = 1, a = 2, b = 3)\n >>> 2\n \n Example 2:\n \n >>> nthMagicalNumber(n = 4, a = 2, b = 3)\n >>> 6\n \"\"\"\n"}
{"task_id": "profitable-schemes", "prompt": "def profitableSchemes(n: int, minProfit: int, group: List[int], profit: List[int]) -> int:\n \"\"\"\n There is a group of n members, and a list of various crimes they could commit. The ith crime generates a profit[i] and requires group[i] members to participate in it. If a member participates in one crime, that member can't participate in another crime.\n Let's call a profitable scheme any subset of these crimes that generates at least minProfit profit, and the total number of members participating in that subset of crimes is at most n.\n Return the number of schemes that can be chosen. Since the answer may be very large, return it modulo 109 + 7.\n \n Example 1:\n \n >>> profitableSchemes(n = 5, minProfit = 3, group = [2,2], profit = [2,3])\n >>> 2\n Explanation: To make a profit of at least 3, the group could either commit crimes 0 and 1, or just crime 1.\n In total, there are 2 schemes.\n Example 2:\n \n >>> profitableSchemes(n = 10, minProfit = 5, group = [2,3,5], profit = [6,7,8])\n >>> 7\n Explanation: To make a profit of at least 5, the group could commit any crimes, as long as they commit one.\n There are 7 possible schemes: (0), (1), (2), (0,1), (0,2), (1,2), and (0,1,2).\n \"\"\"\n"}
{"task_id": "decoded-string-at-index", "prompt": "def decodeAtIndex(s: str, k: int) -> str:\n \"\"\"\n You are given an encoded string s. To decode the string to a tape, the encoded string is read one character at a time and the following steps are taken:\n \n If the character read is a letter, that letter is written onto the tape.\n If the character read is a digit d, the entire current tape is repeatedly written d - 1 more times in total.\n \n Given an integer k, return the kth letter (1-indexed) in the decoded string.\n \n Example 1:\n \n >>> decodeAtIndex(s = \"leet2code3\", k = 10)\n >>> \"o\"\n Explanation: The decoded string is \"leetleetcodeleetleetcodeleetleetcode\".\n The 10th letter in the string is \"o\".\n \n Example 2:\n \n >>> decodeAtIndex(s = \"ha22\", k = 5)\n >>> \"h\"\n Explanation: The decoded string is \"hahahaha\".\n The 5th letter is \"h\".\n \n Example 3:\n \n >>> decodeAtIndex(s = \"a2345678999999999999999\", k = 1)\n >>> \"a\"\n Explanation: The decoded string is \"a\" repeated 8301530446056247680 times.\n The 1st letter is \"a\".\n \"\"\"\n"}
{"task_id": "boats-to-save-people", "prompt": "def numRescueBoats(people: List[int], limit: int) -> int:\n \"\"\"\n You are given an array people where people[i] is the weight of the ith person, and an infinite number of boats where each boat can carry a maximum weight of limit. Each boat carries at most two people at the same time, provided the sum of the weight of those people is at most limit.\n Return the minimum number of boats to carry every given person.\n \n Example 1:\n \n >>> numRescueBoats(people = [1,2], limit = 3)\n >>> 1\n Explanation: 1 boat (1, 2)\n \n Example 2:\n \n >>> numRescueBoats(people = [3,2,2,1], limit = 3)\n >>> 3\n Explanation: 3 boats (1, 2), (2) and (3)\n \n Example 3:\n \n >>> numRescueBoats(people = [3,5,3,4], limit = 5)\n >>> 4\n Explanation: 4 boats (3), (3), (4), (5)\n \"\"\"\n"}
{"task_id": "reachable-nodes-in-subdivided-graph", "prompt": "def reachableNodes(edges: List[List[int]], maxMoves: int, n: int) -> int:\n \"\"\"\n You are given an undirected graph (the \"original graph\") with n nodes labeled from 0 to n - 1. You decide to subdivide each edge in the graph into a chain of nodes, with the number of new nodes varying between each edge.\n The graph is given as a 2D array of edges where edges[i] = [ui, vi, cnti] indicates that there is an edge between nodes ui and vi in the original graph, and cnti is the total number of new nodes that you will subdivide the edge into. Note that cnti == 0 means you will not subdivide the edge.\n To subdivide the edge [ui, vi], replace it with (cnti + 1) new edges and cnti new nodes. The new nodes are x1, x2, ..., xcnti, and the new edges are [ui, x1], [x1, x2], [x2, x3], ..., [xcnti-1, xcnti], [xcnti, vi].\n In this new graph, you want to know how many nodes are reachable from the node 0, where a node is reachable if the distance is maxMoves or less.\n Given the original graph and maxMoves, return the number of nodes that are reachable from node 0 in the new graph.\n \n Example 1:\n \n \n >>> reachableNodes(edges = [[0,1,10],[0,2,1],[1,2,2]], maxMoves = 6, n = 3)\n >>> 13\n Explanation: The edge subdivisions are shown in the image above.\n The nodes that are reachable are highlighted in yellow.\n \n Example 2:\n \n >>> reachableNodes(edges = [[0,1,4],[1,2,6],[0,2,8],[1,3,1]], maxMoves = 10, n = 4)\n >>> 23\n \n Example 3:\n \n >>> reachableNodes(edges = [[1,2,4],[1,4,5],[1,3,1],[2,3,4],[3,4,5]], maxMoves = 17, n = 5)\n >>> 1\n Explanation: Node 0 is disconnected from the rest of the graph, so only node 0 is reachable.\n \"\"\"\n"}
{"task_id": "projection-area-of-3d-shapes", "prompt": "def projectionArea(grid: List[List[int]]) -> int:\n \"\"\"\n You are given an n x n grid where we place some 1 x 1 x 1 cubes that are axis-aligned with the x, y, and z axes.\n Each value v = grid[i][j] represents a tower of v cubes placed on top of the cell (i, j).\n We view the projection of these cubes onto the xy, yz, and zx planes.\n A projection is like a shadow, that maps our 3-dimensional figure to a 2-dimensional plane. We are viewing the \"shadow\" when looking at the cubes from the top, the front, and the side.\n Return the total area of all three projections.\n \n Example 1:\n \n \n >>> projectionArea(grid = [[1,2],[3,4]])\n >>> 17\n Explanation: Here are the three projections (\"shadows\") of the shape made with each axis-aligned plane.\n \n Example 2:\n \n >>> projectionArea(grid = [[2]])\n >>> 5\n \n Example 3:\n \n >>> projectionArea(grid = [[1,0],[0,2]])\n >>> 8\n \"\"\"\n"}
{"task_id": "uncommon-words-from-two-sentences", "prompt": "def uncommonFromSentences(s1: str, s2: str) -> List[str]:\n \"\"\"\n A sentence is a string of single-space separated words where each word consists only of lowercase letters.\n A word is uncommon if it appears exactly once in one of the sentences, and does not appear in the other sentence.\n Given two sentences s1 and s2, return a list of all the uncommon words. You may return the answer in any order.\n \n Example 1:\n \n >>> uncommonFromSentences(s1 = \"this apple is sweet\", s2 = \"this apple is sour\")\n >>> [\"sweet\",\"sour\"]\n Explanation:\n The word \"sweet\" appears only in s1, while the word \"sour\" appears only in s2.\n \n Example 2:\n \n >>> uncommonFromSentences(s1 = \"apple apple\", s2 = \"banana\")\n >>> [\"banana\"]\n \"\"\"\n"}
{"task_id": "spiral-matrix-iii", "prompt": "def spiralMatrixIII(rows: int, cols: int, rStart: int, cStart: int) -> List[List[int]]:\n \"\"\"\n You start at the cell (rStart, cStart) of an rows x cols grid facing east. The northwest corner is at the first row and column in the grid, and the southeast corner is at the last row and column.\n You will walk in a clockwise spiral shape to visit every position in this grid. Whenever you move outside the grid's boundary, we continue our walk outside the grid (but may return to the grid boundary later.). Eventually, we reach all rows * cols spaces of the grid.\n Return an array of coordinates representing the positions of the grid in the order you visited them.\n \n Example 1:\n \n \n >>> spiralMatrixIII(rows = 1, cols = 4, rStart = 0, cStart = 0)\n >>> [[0,0],[0,1],[0,2],[0,3]]\n \n Example 2:\n \n \n >>> spiralMatrixIII(rows = 5, cols = 6, rStart = 1, cStart = 4)\n >>> [[1,4],[1,5],[2,5],[2,4],[2,3],[1,3],[0,3],[0,4],[0,5],[3,5],[3,4],[3,3],[3,2],[2,2],[1,2],[0,2],[4,5],[4,4],[4,3],[4,2],[4,1],[3,1],[2,1],[1,1],[0,1],[4,0],[3,0],[2,0],[1,0],[0,0]]\n \"\"\"\n"}
{"task_id": "possible-bipartition", "prompt": "def possibleBipartition(n: int, dislikes: List[List[int]]) -> bool:\n \"\"\"\n We want to split a group of n people (labeled from 1 to n) into two groups of any size. Each person may dislike some other people, and they should not go into the same group.\n Given the integer n and the array dislikes where dislikes[i] = [ai, bi] indicates that the person labeled ai does not like the person labeled bi, return true if it is possible to split everyone into two groups in this way.\n \n Example 1:\n \n >>> possibleBipartition(n = 4, dislikes = [[1,2],[1,3],[2,4]])\n >>> true\n Explanation: The first group has [1,4], and the second group has [2,3].\n \n Example 2:\n \n >>> possibleBipartition(n = 3, dislikes = [[1,2],[1,3],[2,3]])\n >>> false\n Explanation: We need at least 3 groups to divide them. We cannot put them in two groups.\n \"\"\"\n"}
{"task_id": "super-egg-drop", "prompt": "def superEggDrop(k: int, n: int) -> int:\n \"\"\"\n You are given k identical eggs and you have access to a building with n floors labeled from 1 to n.\n You know that there exists a floor f where 0 <= f <= n such that any egg dropped at a floor higher than f will break, and any egg dropped at or below floor f will not break.\n Each move, you may take an unbroken egg and drop it from any floor x (where 1 <= x <= n). If the egg breaks, you can no longer use it. However, if the egg does not break, you may reuse it in future moves.\n Return the minimum number of moves that you need to determine with certainty what the value of f is.\n \n Example 1:\n \n >>> superEggDrop(k = 1, n = 2)\n >>> 2\n Explanation:\n Drop the egg from floor 1. If it breaks, we know that f = 0.\n Otherwise, drop the egg from floor 2. If it breaks, we know that f = 1.\n If it does not break, then we know f = 2.\n Hence, we need at minimum 2 moves to determine with certainty what the value of f is.\n \n Example 2:\n \n >>> superEggDrop(k = 2, n = 6)\n >>> 3\n \n Example 3:\n \n >>> superEggDrop(k = 3, n = 14)\n >>> 4\n \"\"\"\n"}
{"task_id": "fair-candy-swap", "prompt": "def fairCandySwap(aliceSizes: List[int], bobSizes: List[int]) -> List[int]:\n \"\"\"\n Alice and Bob have a different total number of candies. You are given two integer arrays aliceSizes and bobSizes where aliceSizes[i] is the number of candies of the ith box of candy that Alice has and bobSizes[j] is the number of candies of the jth box of candy that Bob has.\n Since they are friends, they would like to exchange one candy box each so that after the exchange, they both have the same total amount of candy. The total amount of candy a person has is the sum of the number of candies in each box they have.\n Return an integer array answer where answer[0] is the number of candies in the box that Alice must exchange, and answer[1] is the number of candies in the box that Bob must exchange. If there are multiple answers, you may return any one of them. It is guaranteed that at least one answer exists.\n \n Example 1:\n \n >>> fairCandySwap(aliceSizes = [1,1], bobSizes = [2,2])\n >>> [1,2]\n \n Example 2:\n \n >>> fairCandySwap(aliceSizes = [1,2], bobSizes = [2,3])\n >>> [1,2]\n \n Example 3:\n \n >>> fairCandySwap(aliceSizes = [2], bobSizes = [1,3])\n >>> [2,3]\n \"\"\"\n"}
{"task_id": "construct-binary-tree-from-preorder-and-postorder-traversal", "prompt": "# class TreeNode:\n# def __init__(val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def constructFromPrePost(preorder: List[int], postorder: List[int]) -> Optional[TreeNode]:\n \"\"\"\n Given two integer arrays, preorder and postorder where preorder is the preorder traversal of a binary tree of distinct values and postorder is the postorder traversal of the same tree, reconstruct and return the binary tree.\n If there exist multiple answers, you can return any of them.\n \n Example 1:\n \n \n >>> __init__(preorder = [1,2,4,5,3,6,7], postorder = [4,5,2,6,7,3,1])\n >>> [1,2,3,4,5,6,7]\n \n Example 2:\n \n >>> __init__(preorder = [1], postorder = [1])\n >>> [1]\n \"\"\"\n"}
{"task_id": "find-and-replace-pattern", "prompt": "def findAndReplacePattern(words: List[str], pattern: str) -> List[str]:\n \"\"\"\n Given a list of strings words and a string pattern, return a list of words[i] that match pattern. You may return the answer in any order.\n A word matches the pattern if there exists a permutation of letters p so that after replacing every letter x in the pattern with p(x), we get the desired word.\n Recall that a permutation of letters is a bijection from letters to letters: every letter maps to another letter, and no two letters map to the same letter.\n \n Example 1:\n \n >>> findAndReplacePattern(words = [\"abc\",\"deq\",\"mee\",\"aqq\",\"dkd\",\"ccc\"], pattern = \"abb\")\n >>> [\"mee\",\"aqq\"]\n Explanation: \"mee\" matches the pattern because there is a permutation {a -> m, b -> e, ...}.\n \"ccc\" does not match the pattern because {a -> c, b -> c, ...} is not a permutation, since a and b map to the same letter.\n \n Example 2:\n \n >>> findAndReplacePattern(words = [\"a\",\"b\",\"c\"], pattern = \"a\")\n >>> [\"a\",\"b\",\"c\"]\n \"\"\"\n"}
{"task_id": "sum-of-subsequence-widths", "prompt": "def sumSubseqWidths(nums: List[int]) -> int:\n \"\"\"\n The width of a sequence is the difference between the maximum and minimum elements in the sequence.\n Given an array of integers nums, return the sum of the widths of all the non-empty subsequences of nums. Since the answer may be very large, return it modulo 109 + 7.\n A subsequence is a sequence that can be derived from an array by deleting some or no elements without changing the order of the remaining elements. For example, [3,6,2,7] is a subsequence of the array [0,3,1,6,2,2,7].\n \n Example 1:\n \n >>> sumSubseqWidths(nums = [2,1,3])\n >>> 6\n Explanation: The subsequences are [1], [2], [3], [2,1], [2,3], [1,3], [2,1,3].\n The corresponding widths are 0, 0, 0, 1, 1, 2, 2.\n The sum of these widths is 6.\n \n Example 2:\n \n >>> sumSubseqWidths(nums = [2])\n >>> 0\n \"\"\"\n"}
{"task_id": "surface-area-of-3d-shapes", "prompt": "def surfaceArea(grid: List[List[int]]) -> int:\n \"\"\"\n You are given an n x n grid where you have placed some 1 x 1 x 1 cubes. Each value v = grid[i][j] represents a tower of v cubes placed on top of cell (i, j).\n After placing these cubes, you have decided to glue any directly adjacent cubes to each other, forming several irregular 3D shapes.\n Return the total surface area of the resulting shapes.\n Note: The bottom face of each shape counts toward its surface area.\n \n Example 1:\n \n \n >>> surfaceArea(grid = [[1,2],[3,4]])\n >>> 34\n \n Example 2:\n \n \n >>> surfaceArea(grid = [[1,1,1],[1,0,1],[1,1,1]])\n >>> 32\n \n Example 3:\n \n \n >>> surfaceArea(grid = [[2,2,2],[2,1,2],[2,2,2]])\n >>> 46\n \"\"\"\n"}
{"task_id": "groups-of-special-equivalent-strings", "prompt": "def numSpecialEquivGroups(words: List[str]) -> int:\n \"\"\"\n You are given an array of strings of the same length words.\n In one move, you can swap any two even indexed characters or any two odd indexed characters of a string words[i].\n Two strings words[i] and words[j] are special-equivalent if after any number of moves, words[i] == words[j].\n \n For example, words[i] = \"zzxy\" and words[j] = \"xyzz\" are special-equivalent because we may make the moves \"zzxy\" -> \"xzzy\" -> \"xyzz\".\n \n A group of special-equivalent strings from words is a non-empty subset of words such that:\n \n Every pair of strings in the group are special equivalent, and\n The group is the largest size possible (i.e., there is not a string words[i] not in the group such that words[i] is special-equivalent to every string in the group).\n \n Return the number of groups of special-equivalent strings from words.\n \n Example 1:\n \n >>> numSpecialEquivGroups(words = [\"abcd\",\"cdab\",\"cbad\",\"xyzz\",\"zzxy\",\"zzyx\"])\n >>> 3\n Explanation:\n One group is [\"abcd\", \"cdab\", \"cbad\"], since they are all pairwise special equivalent, and none of the other strings is all pairwise special equivalent to these.\n The other two groups are [\"xyzz\", \"zzxy\"] and [\"zzyx\"].\n Note that in particular, \"zzxy\" is not special equivalent to \"zzyx\".\n \n Example 2:\n \n >>> numSpecialEquivGroups(words = [\"abc\",\"acb\",\"bac\",\"bca\",\"cab\",\"cba\"])\n >>> 3\n \"\"\"\n"}
{"task_id": "monotonic-array", "prompt": "def isMonotonic(nums: List[int]) -> bool:\n \"\"\"\n An array is monotonic if it is either monotone increasing or monotone decreasing.\n An array nums is monotone increasing if for all i <= j, nums[i] <= nums[j]. An array nums is monotone decreasing if for all i <= j, nums[i] >= nums[j].\n Given an integer array nums, return true if the given array is monotonic, or false otherwise.\n \n Example 1:\n \n >>> isMonotonic(nums = [1,2,2,3])\n >>> true\n \n Example 2:\n \n >>> isMonotonic(nums = [6,5,4,4])\n >>> true\n \n Example 3:\n \n >>> isMonotonic(nums = [1,3,2])\n >>> false\n \"\"\"\n"}
{"task_id": "increasing-order-search-tree", "prompt": "# class TreeNode:\n# def __init__(val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def increasingBST(root: Optional[TreeNode]) -> Optional[TreeNode]:\n \"\"\"\n Given the root of a binary search tree, rearrange the tree in in-order so that the leftmost node in the tree is now the root of the tree, and every node has no left child and only one right child.\n \n Example 1:\n \n \n >>> __init__(root = [5,3,6,2,4,null,8,1,null,null,null,7,9])\n >>> [1,null,2,null,3,null,4,null,5,null,6,null,7,null,8,null,9]\n \n Example 2:\n \n \n >>> __init__(root = [5,1,7])\n >>> [1,null,5,null,7]\n \"\"\"\n"}
{"task_id": "bitwise-ors-of-subarrays", "prompt": "def subarrayBitwiseORs(arr: List[int]) -> int:\n \"\"\"\n Given an integer array arr, return the number of distinct bitwise ORs of all the non-empty subarrays of arr.\n The bitwise OR of a subarray is the bitwise OR of each integer in the subarray. The bitwise OR of a subarray of one integer is that integer.\n A subarray is a contiguous non-empty sequence of elements within an array.\n \n Example 1:\n \n >>> subarrayBitwiseORs(arr = [0])\n >>> 1\n Explanation: There is only one possible result: 0.\n \n Example 2:\n \n >>> subarrayBitwiseORs(arr = [1,1,2])\n >>> 3\n Explanation: The possible subarrays are [1], [1], [2], [1, 1], [1, 2], [1, 1, 2].\n These yield the results 1, 1, 2, 1, 3, 3.\n There are 3 unique values, so the answer is 3.\n \n Example 3:\n \n >>> subarrayBitwiseORs(arr = [1,2,4])\n >>> 6\n Explanation: The possible results are 1, 2, 3, 4, 6, and 7.\n \"\"\"\n"}
{"task_id": "orderly-queue", "prompt": "def orderlyQueue(s: str, k: int) -> str:\n \"\"\"\n You are given a string s and an integer k. You can choose one of the first k letters of s and append it at the end of the string.\n Return the lexicographically smallest string you could have after applying the mentioned step any number of moves.\n \n Example 1:\n \n >>> orderlyQueue(s = \"cba\", k = 1)\n >>> \"acb\"\n Explanation:\n In the first move, we move the 1st character 'c' to the end, obtaining the string \"bac\".\n In the second move, we move the 1st character 'b' to the end, obtaining the final result \"acb\".\n \n Example 2:\n \n >>> orderlyQueue(s = \"baaca\", k = 3)\n >>> \"aaabc\"\n Explanation:\n In the first move, we move the 1st character 'b' to the end, obtaining the string \"aacab\".\n In the second move, we move the 3rd character 'c' to the end, obtaining the final result \"aaabc\".\n \"\"\"\n"}
{"task_id": "numbers-at-most-n-given-digit-set", "prompt": "def atMostNGivenDigitSet(digits: List[str], n: int) -> int:\n \"\"\"\n Given an array of digits which is sorted in non-decreasing order. You can write numbers using each digits[i] as many times as we want. For example, if digits = ['1','3','5'], we may write numbers such as '13', '551', and '1351315'.\n Return the number of positive integers that can be generated that are less than or equal to a given integer n.\n \n Example 1:\n \n >>> atMostNGivenDigitSet(digits = [\"1\",\"3\",\"5\",\"7\"], n = 100)\n >>> 20\n Explanation:\n The 20 numbers that can be written are:\n 1, 3, 5, 7, 11, 13, 15, 17, 31, 33, 35, 37, 51, 53, 55, 57, 71, 73, 75, 77.\n \n Example 2:\n \n >>> atMostNGivenDigitSet(digits = [\"1\",\"4\",\"9\"], n = 1000000000)\n >>> 29523\n Explanation:\n We can write 3 one digit numbers, 9 two digit numbers, 27 three digit numbers,\n 81 four digit numbers, 243 five digit numbers, 729 six digit numbers,\n 2187 seven digit numbers, 6561 eight digit numbers, and 19683 nine digit numbers.\n In total, this is 29523 integers that can be written using the digits array.\n \n Example 3:\n \n >>> atMostNGivenDigitSet(digits = [\"7\"], n = 8)\n >>> 1\n \"\"\"\n"}
{"task_id": "valid-permutations-for-di-sequence", "prompt": "def numPermsDISequence(s: str) -> int:\n \"\"\"\n You are given a string s of length n where s[i] is either:\n \n 'D' means decreasing, or\n 'I' means increasing.\n \n A permutation perm of n + 1 integers of all the integers in the range [0, n] is called a valid permutation if for all valid i:\n \n If s[i] == 'D', then perm[i] > perm[i + 1], and\n If s[i] == 'I', then perm[i] < perm[i + 1].\n \n Return the number of valid permutations perm. Since the answer may be large, return it modulo 109 + 7.\n \n Example 1:\n \n >>> numPermsDISequence(s = \"DID\")\n >>> 5\n Explanation: The 5 valid permutations of (0, 1, 2, 3) are:\n (1, 0, 3, 2)\n (2, 0, 3, 1)\n (2, 1, 3, 0)\n (3, 0, 2, 1)\n (3, 1, 2, 0)\n \n Example 2:\n \n >>> numPermsDISequence(s = \"D\")\n >>> 1\n \"\"\"\n"}
{"task_id": "fruit-into-baskets", "prompt": "def totalFruit(fruits: List[int]) -> int:\n \"\"\"\n You are visiting a farm that has a single row of fruit trees arranged from left to right. The trees are represented by an integer array fruits where fruits[i] is the type of fruit the ith tree produces.\n You want to collect as much fruit as possible. However, the owner has some strict rules that you must follow:\n \n You only have two baskets, and each basket can only hold a single type of fruit. There is no limit on the amount of fruit each basket can hold.\n Starting from any tree of your choice, you must pick exactly one fruit from every tree (including the start tree) while moving to the right. The picked fruits must fit in one of your baskets.\n Once you reach a tree with fruit that cannot fit in your baskets, you must stop.\n \n Given the integer array fruits, return the maximum number of fruits you can pick.\n \n Example 1:\n \n >>> totalFruit(fruits = [1,2,1])\n >>> 3\n Explanation: We can pick from all 3 trees.\n \n Example 2:\n \n >>> totalFruit(fruits = [0,1,2,2])\n >>> 3\n Explanation: We can pick from trees [1,2,2].\n If we had started at the first tree, we would only pick from trees [0,1].\n \n Example 3:\n \n >>> totalFruit(fruits = [1,2,3,2,2])\n >>> 4\n Explanation: We can pick from trees [2,3,2,2].\n If we had started at the first tree, we would only pick from trees [1,2].\n \"\"\"\n"}
{"task_id": "sort-array-by-parity", "prompt": "def sortArrayByParity(nums: List[int]) -> List[int]:\n \"\"\"\n Given an integer array nums, move all the even integers at the beginning of the array followed by all the odd integers.\n Return any array that satisfies this condition.\n \n Example 1:\n \n >>> sortArrayByParity(nums = [3,1,2,4])\n >>> [2,4,3,1]\n Explanation: The outputs [4,2,3,1], [2,4,1,3], and [4,2,1,3] would also be accepted.\n \n Example 2:\n \n >>> sortArrayByParity(nums = [0])\n >>> [0]\n \"\"\"\n"}
{"task_id": "super-palindromes", "prompt": "def superpalindromesInRange(left: str, right: str) -> int:\n \"\"\"\n Let's say a positive integer is a super-palindrome if it is a palindrome, and it is also the square of a palindrome.\n Given two positive integers left and right represented as strings, return the number of super-palindromes integers in the inclusive range [left, right].\n \n Example 1:\n \n >>> superpalindromesInRange(left = \"4\", right = \"1000\")\n >>> 4\n Explanation: 4, 9, 121, and 484 are superpalindromes.\n Note that 676 is not a superpalindrome: 26 * 26 = 676, but 26 is not a palindrome.\n \n Example 2:\n \n >>> superpalindromesInRange(left = \"1\", right = \"2\")\n >>> 1\n \"\"\"\n"}
{"task_id": "sum-of-subarray-minimums", "prompt": "def sumSubarrayMins(arr: List[int]) -> int:\n \"\"\"\n Given an array of integers arr, find the sum of min(b), where b ranges over every (contiguous) subarray of arr. Since the answer may be large, return the answer modulo 109 + 7.\n \n Example 1:\n \n >>> sumSubarrayMins(arr = [3,1,2,4])\n >>> 17\n Explanation:\n Subarrays are [3], [1], [2], [4], [3,1], [1,2], [2,4], [3,1,2], [1,2,4], [3,1,2,4].\n Minimums are 3, 1, 2, 4, 1, 1, 2, 1, 1, 1.\n Sum is 17.\n \n Example 2:\n \n >>> sumSubarrayMins(arr = [11,81,94,43,3])\n >>> 444\n \"\"\"\n"}
{"task_id": "smallest-range-i", "prompt": "def smallestRangeI(nums: List[int], k: int) -> int:\n \"\"\"\n You are given an integer array nums and an integer k.\n In one operation, you can choose any index i where 0 <= i < nums.length and change nums[i] to nums[i] + x where x is an integer from the range [-k, k]. You can apply this operation at most once for each index i.\n The score of nums is the difference between the maximum and minimum elements in nums.\n Return the minimum score of nums after applying the mentioned operation at most once for each index in it.\n \n Example 1:\n \n >>> smallestRangeI(nums = [1], k = 0)\n >>> 0\n Explanation: The score is max(nums) - min(nums) = 1 - 1 = 0.\n \n Example 2:\n \n >>> smallestRangeI(nums = [0,10], k = 2)\n >>> 6\n Explanation: Change nums to be [2, 8]. The score is max(nums) - min(nums) = 8 - 2 = 6.\n \n Example 3:\n \n >>> smallestRangeI(nums = [1,3,6], k = 3)\n >>> 0\n Explanation: Change nums to be [4, 4, 4]. The score is max(nums) - min(nums) = 4 - 4 = 0.\n \"\"\"\n"}
{"task_id": "snakes-and-ladders", "prompt": "def snakesAndLadders(board: List[List[int]]) -> int:\n \"\"\"\n You are given an n x n integer matrix board where the cells are labeled from 1 to n2 in a Boustrophedon style starting from the bottom left of the board (i.e. board[n - 1][0]) and alternating direction each row.\n You start on square 1 of the board. In each move, starting from square curr, do the following:\n \n Choose a destination square next with a label in the range [curr + 1, min(curr + 6, n2)].\n \n \n This choice simulates the result of a standard 6-sided die roll: i.e., there are always at most 6 destinations, regardless of the size of the board.\n \n \n If next has a snake or ladder, you must move to the destination of that snake or ladder. Otherwise, you move to next.\n The game ends when you reach the square n2.\n \n A board square on row r and column c has a snake or ladder if board[r][c] != -1. The destination of that snake or ladder is board[r][c]. Squares 1 and n2 are not the starting points of any snake or ladder.\n Note that you only take a snake or ladder at most once per dice roll. If the destination to a snake or ladder is the start of another snake or ladder, you do not follow the subsequent\u00a0snake or ladder.\n \n For example, suppose the board is [[-1,4],[-1,3]], and on the first move, your destination square is 2. You follow the ladder to square 3, but do not follow the subsequent ladder to 4.\n \n Return the least number of dice rolls required to reach the square n2. If it is not possible to reach the square, return -1.\n \n Example 1:\n \n \n >>> snakesAndLadders(board = [[-1,-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1],[-1,35,-1,-1,13,-1],[-1,-1,-1,-1,-1,-1],[-1,15,-1,-1,-1,-1]])\n >>> 4\n Explanation:\n In the beginning, you start at square 1 (at row 5, column 0).\n You decide to move to square 2 and must take the ladder to square 15.\n You then decide to move to square 17 and must take the snake to square 13.\n You then decide to move to square 14 and must take the ladder to square 35.\n You then decide to move to square 36, ending the game.\n This is the lowest possible number of moves to reach the last square, so return 4.\n \n Example 2:\n \n >>> snakesAndLadders(board = [[-1,-1],[-1,3]])\n >>> 1\n \"\"\"\n"}
{"task_id": "smallest-range-ii", "prompt": "def smallestRangeII(nums: List[int], k: int) -> int:\n \"\"\"\n You are given an integer array nums and an integer k.\n For each index i where 0 <= i < nums.length, change nums[i] to be either nums[i] + k or nums[i] - k.\n The score of nums is the difference between the maximum and minimum elements in nums.\n Return the minimum score of nums after changing the values at each index.\n \n Example 1:\n \n >>> smallestRangeII(nums = [1], k = 0)\n >>> 0\n Explanation: The score is max(nums) - min(nums) = 1 - 1 = 0.\n \n Example 2:\n \n >>> smallestRangeII(nums = [0,10], k = 2)\n >>> 6\n Explanation: Change nums to be [2, 8]. The score is max(nums) - min(nums) = 8 - 2 = 6.\n \n Example 3:\n \n >>> smallestRangeII(nums = [1,3,6], k = 3)\n >>> 3\n Explanation: Change nums to be [4, 6, 3]. The score is max(nums) - min(nums) = 6 - 3 = 3.\n \"\"\"\n"}
{"task_id": "sort-an-array", "prompt": "def sortArray(nums: List[int]) -> List[int]:\n \"\"\"\n Given an array of integers nums, sort the array in ascending order and return it.\n You must solve the problem without using any built-in functions in O(nlog(n)) time complexity and with the smallest space complexity possible.\n \n Example 1:\n \n >>> sortArray(nums = [5,2,3,1])\n >>> [1,2,3,5]\n Explanation: After sorting the array, the positions of some numbers are not changed (for example, 2 and 3), while the positions of other numbers are changed (for example, 1 and 5).\n \n Example 2:\n \n >>> sortArray(nums = [5,1,1,2,0,0])\n >>> [0,0,1,1,2,5]\n Explanation: Note that the values of nums are not necessairly unique.\n \"\"\"\n"}
{"task_id": "cat-and-mouse", "prompt": "def catMouseGame(graph: List[List[int]]) -> int:\n \"\"\"\n A game on an undirected graph is played by two players, Mouse and Cat, who alternate turns.\n The graph is given as follows: graph[a] is a list of all nodes b such that ab is an edge of the graph.\n The mouse starts at node 1 and goes first, the cat starts at node 2 and goes second, and there is a hole at node 0.\n During each player's turn, they must travel along one\u00a0edge of the graph that meets where they are.\u00a0 For example, if the Mouse is at node 1, it must travel to any node in graph[1].\n Additionally, it is not allowed for the Cat to travel to the Hole (node 0).\n Then, the game can end in three\u00a0ways:\n \n If ever the Cat occupies the same node as the Mouse, the Cat wins.\n If ever the Mouse reaches the Hole, the Mouse wins.\n If ever a position is repeated (i.e., the players are in the same position as a previous turn, and\u00a0it is the same player's turn to move), the game is a draw.\n \n Given a graph, and assuming both players play optimally, return\n \n 1\u00a0if the mouse wins the game,\n 2\u00a0if the cat wins the game, or\n 0\u00a0if the game is a draw.\n \n \n Example 1:\n \n \n >>> catMouseGame(graph = [[2,5],[3],[0,4,5],[1,4,5],[2,3],[0,2,3]])\n >>> 0\n \n Example 2:\n \n \n >>> catMouseGame(graph = [[1,3],[0],[3],[0,2]])\n >>> 1\n \"\"\"\n"}
{"task_id": "x-of-a-kind-in-a-deck-of-cards", "prompt": "def hasGroupsSizeX(deck: List[int]) -> bool:\n \"\"\"\n You are given an integer array deck where deck[i] represents the number written on the ith card.\n Partition the cards into one or more groups such that:\n \n Each group has exactly x cards where x > 1, and\n All the cards in one group have the same integer written on them.\n \n Return true if such partition is possible, or false otherwise.\n \n Example 1:\n \n >>> hasGroupsSizeX(deck = [1,2,3,4,4,3,2,1])\n >>> true\n Explanation: Possible partition [1,1],[2,2],[3,3],[4,4].\n \n Example 2:\n \n >>> hasGroupsSizeX(deck = [1,1,1,2,2,2,3,3])\n >>> false\n Explanation: No possible partition.\n \"\"\"\n"}
{"task_id": "partition-array-into-disjoint-intervals", "prompt": "def partitionDisjoint(nums: List[int]) -> int:\n \"\"\"\n Given an integer array nums, partition it into two (contiguous) subarrays left and right so that:\n \n Every element in left is less than or equal to every element in right.\n left and right are non-empty.\n left has the smallest possible size.\n \n Return the length of left after such a partitioning.\n Test cases are generated such that partitioning exists.\n \n Example 1:\n \n >>> partitionDisjoint(nums = [5,0,3,8,6])\n >>> 3\n Explanation: left = [5,0,3], right = [8,6]\n \n Example 2:\n \n >>> partitionDisjoint(nums = [1,1,1,0,6,12])\n >>> 4\n Explanation: left = [1,1,1,0], right = [6,12]\n \"\"\"\n"}
{"task_id": "word-subsets", "prompt": "def wordSubsets(words1: List[str], words2: List[str]) -> List[str]:\n \"\"\"\n You are given two string arrays words1 and words2.\n A string b is a subset of string a if every letter in b occurs in a including multiplicity.\n \n For example, \"wrr\" is a subset of \"warrior\" but is not a subset of \"world\".\n \n A string a from words1 is universal if for every string b in words2, b is a subset of a.\n Return an array of all the universal strings in words1. You may return the answer in any order.\n \n Example 1:\n \n >>> wordSubsets(words1 = [\"amazon\",\"apple\",\"facebook\",\"google\",\"leetcode\"], words2 = [\"e\",\"o\"])\n >>> [\"facebook\",\"google\",\"leetcode\"]\n \n Example 2:\n \n >>> wordSubsets(words1 = [\"amazon\",\"apple\",\"facebook\",\"google\",\"leetcode\"], words2 = [\"lc\",\"eo\"])\n >>> [\"leetcode\"]\n \n Example 3:\n \n >>> wordSubsets(words1 = [\"acaac\",\"cccbb\",\"aacbb\",\"caacc\",\"bcbbb\"], words2 = [\"c\",\"cc\",\"b\"])\n >>> [\"cccbb\"]\n \"\"\"\n"}
{"task_id": "reverse-only-letters", "prompt": "def reverseOnlyLetters(s: str) -> str:\n \"\"\"\n Given a string s, reverse the string according to the following rules:\n \n All the characters that are not English letters remain in the same position.\n All the English letters (lowercase or uppercase) should be reversed.\n \n Return s after reversing it.\n \n Example 1:\n >>> reverseOnlyLetters(s = \"ab-cd\")\n >>> \"dc-ba\"\n Example 2:\n >>> reverseOnlyLetters(s = \"a-bC-dEf-ghIj\")\n >>> \"j-Ih-gfE-dCba\"\n Example 3:\n >>> reverseOnlyLetters(s = \"Test1ng-Leet=code-Q!\")\n >>> \"Qedo1ct-eeLg=ntse-T!\"\n \"\"\"\n"}
{"task_id": "maximum-sum-circular-subarray", "prompt": "def maxSubarraySumCircular(nums: List[int]) -> int:\n \"\"\"\n Given a circular integer array nums of length n, return the maximum possible sum of a non-empty subarray of nums.\n A circular array means the end of the array connects to the beginning of the array. Formally, the next element of nums[i] is nums[(i + 1) % n] and the previous element of nums[i] is nums[(i - 1 + n) % n].\n A subarray may only include each element of the fixed buffer nums at most once. Formally, for a subarray nums[i], nums[i + 1], ..., nums[j], there does not exist i <= k1, k2 <= j with k1 % n == k2 % n.\n \n Example 1:\n \n >>> maxSubarraySumCircular(nums = [1,-2,3,-2])\n >>> 3\n Explanation: Subarray [3] has maximum sum 3.\n \n Example 2:\n \n >>> maxSubarraySumCircular(nums = [5,-3,5])\n >>> 10\n Explanation: Subarray [5,5] has maximum sum 5 + 5 = 10.\n \n Example 3:\n \n >>> maxSubarraySumCircular(nums = [-3,-2,-3])\n >>> -2\n Explanation: Subarray [-2] has maximum sum -2.\n \"\"\"\n"}
{"task_id": "number-of-music-playlists", "prompt": "def numMusicPlaylists(n: int, goal: int, k: int) -> int:\n \"\"\"\n Your music player contains n different songs. You want to listen to goal songs (not necessarily different) during your trip. To avoid boredom, you will create a playlist so that:\n \n Every song is played at least once.\n A song can only be played again only if k other songs have been played.\n \n Given n, goal, and k, return the number of possible playlists that you can create. Since the answer can be very large, return it modulo 109 + 7.\n \n Example 1:\n \n >>> numMusicPlaylists(n = 3, goal = 3, k = 1)\n >>> 6\n Explanation: There are 6 possible playlists: [1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], and [3, 2, 1].\n \n Example 2:\n \n >>> numMusicPlaylists(n = 2, goal = 3, k = 0)\n >>> 6\n Explanation: There are 6 possible playlists: [1, 1, 2], [1, 2, 1], [2, 1, 1], [2, 2, 1], [2, 1, 2], and [1, 2, 2].\n \n Example 3:\n \n >>> numMusicPlaylists(n = 2, goal = 3, k = 1)\n >>> 2\n Explanation: There are 2 possible playlists: [1, 2, 1] and [2, 1, 2].\n \"\"\"\n"}
{"task_id": "minimum-add-to-make-parentheses-valid", "prompt": "def minAddToMakeValid(s: str) -> int:\n \"\"\"\n A parentheses string is valid if and only if:\n \n It is the empty string,\n It can be written as AB (A concatenated with B), where A and B are valid strings, or\n It can be written as (A), where A is a valid string.\n \n You are given a parentheses string s. In one move, you can insert a parenthesis at any position of the string.\n \n For example, if s = \"()))\", you can insert an opening parenthesis to be \"(()))\" or a closing parenthesis to be \"())))\".\n \n Return the minimum number of moves required to make s valid.\n \n Example 1:\n \n >>> minAddToMakeValid(s = \"())\")\n >>> 1\n \n Example 2:\n \n >>> minAddToMakeValid(s = \"(((\")\n >>> 3\n \"\"\"\n"}
{"task_id": "sort-array-by-parity-ii", "prompt": "def sortArrayByParityII(nums: List[int]) -> List[int]:\n \"\"\"\n Given an array of integers nums, half of the integers in nums are odd, and the other half are even.\n Sort the array so that whenever nums[i] is odd, i is odd, and whenever nums[i] is even, i is even.\n Return any answer array that satisfies this condition.\n \n Example 1:\n \n >>> sortArrayByParityII(nums = [4,2,5,7])\n >>> [4,5,2,7]\n Explanation: [4,7,2,5], [2,5,4,7], [2,7,4,5] would also have been accepted.\n \n Example 2:\n \n >>> sortArrayByParityII(nums = [2,3])\n >>> [2,3]\n \"\"\"\n"}
{"task_id": "3sum-with-multiplicity", "prompt": "def threeSumMulti(arr: List[int], target: int) -> int:\n \"\"\"\n Given an integer array arr, and an integer target, return the number of tuples i, j, k such that i < j < k and arr[i] + arr[j] + arr[k] == target.\n As the answer can be very large, return it modulo 109 + 7.\n \n Example 1:\n \n >>> threeSumMulti(arr = [1,1,2,2,3,3,4,4,5,5], target = 8)\n >>> 20\n Explanation:\n Enumerating by the values (arr[i], arr[j], arr[k]):\n (1, 2, 5) occurs 8 times;\n (1, 3, 4) occurs 8 times;\n (2, 2, 4) occurs 2 times;\n (2, 3, 3) occurs 2 times.\n \n Example 2:\n \n >>> threeSumMulti(arr = [1,1,2,2,2,2], target = 5)\n >>> 12\n Explanation:\n arr[i] = 1, arr[j] = arr[k] = 2 occurs 12 times:\n We choose one 1 from [1,1] in 2 ways,\n and two 2s from [2,2,2,2] in 6 ways.\n \n Example 3:\n \n >>> threeSumMulti(arr = [2,1,3], target = 6)\n >>> 1\n Explanation: (1, 2, 3) occured one time in the array so we return 1.\n \"\"\"\n"}
{"task_id": "minimize-malware-spread", "prompt": "def minMalwareSpread(graph: List[List[int]], initial: List[int]) -> int:\n \"\"\"\n You are given a network of n nodes represented as an n x n adjacency matrix graph, where the ith node is directly connected to the jth node if graph[i][j] == 1.\n Some nodes initial are initially infected by malware. Whenever two nodes are directly connected, and at least one of those two nodes is infected by malware, both nodes will be infected by malware. This spread of malware will continue until no more nodes can be infected in this manner.\n Suppose M(initial) is the final number of nodes infected with malware in the entire network after the spread of malware stops. We will remove exactly one node from initial.\n Return the node that, if removed, would minimize M(initial). If multiple nodes could be removed to minimize M(initial), return such a node with the smallest index.\n Note that if a node was removed from the initial list of infected nodes, it might still be infected later due to the malware spread.\n \n Example 1:\n >>> minMalwareSpread(graph = [[1,1,0],[1,1,0],[0,0,1]], initial = [0,1])\n >>> 0\n Example 2:\n >>> minMalwareSpread(graph = [[1,0,0],[0,1,0],[0,0,1]], initial = [0,2])\n >>> 0\n Example 3:\n >>> minMalwareSpread(graph = [[1,1,1],[1,1,1],[1,1,1]], initial = [1,2])\n >>> 1\n \"\"\"\n"}
{"task_id": "long-pressed-name", "prompt": "def isLongPressedName(name: str, typed: str) -> bool:\n \"\"\"\n Your friend is typing his name into a keyboard. Sometimes, when typing a character c, the key might get long pressed, and the character will be typed 1 or more times.\n You examine the typed characters of the keyboard. Return True if it is possible that it was your friends name, with some characters (possibly none) being long pressed.\n \n Example 1:\n \n >>> isLongPressedName(name = \"alex\", typed = \"aaleex\")\n >>> true\n Explanation: 'a' and 'e' in 'alex' were long pressed.\n \n Example 2:\n \n >>> isLongPressedName(name = \"saeed\", typed = \"ssaaedd\")\n >>> false\n Explanation: 'e' must have been pressed twice, but it was not in the typed output.\n \"\"\"\n"}
{"task_id": "flip-string-to-monotone-increasing", "prompt": "def minFlipsMonoIncr(s: str) -> int:\n \"\"\"\n A binary string is monotone increasing if it consists of some number of 0's (possibly none), followed by some number of 1's (also possibly none).\n You are given a binary string s. You can flip s[i] changing it from 0 to 1 or from 1 to 0.\n Return the minimum number of flips to make s monotone increasing.\n \n Example 1:\n \n >>> minFlipsMonoIncr(s = \"00110\")\n >>> 1\n Explanation: We flip the last digit to get 00111.\n \n Example 2:\n \n >>> minFlipsMonoIncr(s = \"010110\")\n >>> 2\n Explanation: We flip to get 011111, or alternatively 000111.\n \n Example 3:\n \n >>> minFlipsMonoIncr(s = \"00011000\")\n >>> 2\n Explanation: We flip to get 00000000.\n \"\"\"\n"}
{"task_id": "three-equal-parts", "prompt": "def threeEqualParts(arr: List[int]) -> List[int]:\n \"\"\"\n You are given an array arr which consists of only zeros and ones, divide the array into three non-empty parts such that all of these parts represent the same binary value.\n If it is possible, return any [i, j] with i + 1 < j, such that:\n \n arr[0], arr[1], ..., arr[i] is the first part,\n arr[i + 1], arr[i + 2], ..., arr[j - 1] is the second part, and\n arr[j], arr[j + 1], ..., arr[arr.length - 1] is the third part.\n All three parts have equal binary values.\n \n If it is not possible, return [-1, -1].\n Note that the entire part is used when considering what binary value it represents. For example, [1,1,0] represents 6 in decimal, not 3. Also, leading zeros are allowed, so [0,1,1] and [1,1] represent the same value.\n \n Example 1:\n >>> threeEqualParts(arr = [1,0,1,0,1])\n >>> [0,3]\n Example 2:\n >>> threeEqualParts(arr = [1,1,0,1,1])\n >>> [-1,-1]\n Example 3:\n >>> threeEqualParts(arr = [1,1,0,0,1])\n >>> [0,2]\n \"\"\"\n"}
{"task_id": "minimize-malware-spread-ii", "prompt": "def minMalwareSpread(graph: List[List[int]], initial: List[int]) -> int:\n \"\"\"\n You are given a network of n nodes represented as an n x n adjacency matrix graph, where the ith node is directly connected to the jth node if graph[i][j] == 1.\n Some nodes initial are initially infected by malware. Whenever two nodes are directly connected, and at least one of those two nodes is infected by malware, both nodes will be infected by malware. This spread of malware will continue until no more nodes can be infected in this manner.\n Suppose M(initial) is the final number of nodes infected with malware in the entire network after the spread of malware stops.\n We will remove exactly one node from initial, completely removing it and any connections from this node to any other node.\n Return the node that, if removed, would minimize M(initial). If multiple nodes could be removed to minimize M(initial), return such a node with the smallest index.\n \n Example 1:\n >>> minMalwareSpread(graph = [[1,1,0],[1,1,0],[0,0,1]], initial = [0,1])\n >>> 0\n Example 2:\n >>> minMalwareSpread(graph = [[1,1,0],[1,1,1],[0,1,1]], initial = [0,1])\n >>> 1\n Example 3:\n >>> minMalwareSpread(graph = [[1,1,0,0],[1,1,1,0],[0,1,1,1],[0,0,1,1]], initial = [0,1])\n >>> 1\n \"\"\"\n"}
{"task_id": "unique-email-addresses", "prompt": "def numUniqueEmails(emails: List[str]) -> int:\n \"\"\"\n Every valid email consists of a local name and a domain name, separated by the '@' sign. Besides lowercase letters, the email may contain one or more '.' or '+'.\n \n For example, in \"alice@leetcode.com\", \"alice\" is the local name, and \"leetcode.com\" is the domain name.\n \n If you add periods '.' between some characters in the local name part of an email address, mail sent there will be forwarded to the same address without dots in the local name. Note that this rule does not apply to domain names.\n \n For example, \"alice.z@leetcode.com\" and \"alicez@leetcode.com\" forward to the same email address.\n \n If you add a plus '+' in the local name, everything after the first plus sign will be ignored. This allows certain emails to be filtered. Note that this rule does not apply to domain names.\n \n For example, \"m.y+name@email.com\" will be forwarded to \"my@email.com\".\n \n It is possible to use both of these rules at the same time.\n Given an array of strings emails where we send one email to each emails[i], return the number of different addresses that actually receive mails.\n \n Example 1:\n \n >>> numUniqueEmails(emails = [\"test.email+alex@leetcode.com\",\"test.e.mail+bob.cathy@leetcode.com\",\"testemail+david@lee.tcode.com\"])\n >>> 2\n Explanation: \"testemail@leetcode.com\" and \"testemail@lee.tcode.com\" actually receive mails.\n \n Example 2:\n \n >>> numUniqueEmails(emails = [\"a@leetcode.com\",\"b@leetcode.com\",\"c@leetcode.com\"])\n >>> 3\n \"\"\"\n"}
{"task_id": "binary-subarrays-with-sum", "prompt": "def numSubarraysWithSum(nums: List[int], goal: int) -> int:\n \"\"\"\n Given a binary array nums and an integer goal, return the number of non-empty subarrays with a sum goal.\n A subarray is a contiguous part of the array.\n \n Example 1:\n \n >>> numSubarraysWithSum(nums = [1,0,1,0,1], goal = 2)\n >>> 4\n Explanation: The 4 subarrays are bolded and underlined below:\n [1,0,1,0,1]\n [1,0,1,0,1]\n [1,0,1,0,1]\n [1,0,1,0,1]\n \n Example 2:\n \n >>> numSubarraysWithSum(nums = [0,0,0,0,0], goal = 0)\n >>> 15\n \"\"\"\n"}
{"task_id": "minimum-falling-path-sum", "prompt": "def minFallingPathSum(matrix: List[List[int]]) -> int:\n \"\"\"\n Given an n x n array of integers matrix, return the minimum sum of any falling path through matrix.\n A falling path starts at any element in the first row and chooses the element in the next row that is either directly below or diagonally left/right. Specifically, the next element from position (row, col) will be (row + 1, col - 1), (row + 1, col), or (row + 1, col + 1).\n \n Example 1:\n \n \n >>> minFallingPathSum(matrix = [[2,1,3],[6,5,4],[7,8,9]])\n >>> 13\n Explanation: There are two falling paths with a minimum sum as shown.\n \n Example 2:\n \n \n >>> minFallingPathSum(matrix = [[-19,57],[-40,-5]])\n >>> -59\n Explanation: The falling path with a minimum sum is shown.\n \"\"\"\n"}
{"task_id": "beautiful-array", "prompt": "def beautifulArray(n: int) -> List[int]:\n \"\"\"\n An array nums of length n is beautiful if:\n \n nums is a permutation of the integers in the range [1, n].\n For every 0 <= i < j < n, there is no index k with i < k < j where 2 * nums[k] == nums[i] + nums[j].\n \n Given the integer n, return any beautiful array nums of length n. There will be at least one valid answer for the given n.\n \n Example 1:\n >>> beautifulArray(n = 4)\n >>> [2,1,4,3]\n Example 2:\n >>> beautifulArray(n = 5)\n >>> [3,1,2,5,4]\n \"\"\"\n"}
{"task_id": "shortest-bridge", "prompt": "def shortestBridge(grid: List[List[int]]) -> int:\n \"\"\"\n You are given an n x n binary matrix grid where 1 represents land and 0 represents water.\n An island is a 4-directionally connected group of 1's not connected to any other 1's. There are exactly two islands in grid.\n You may change 0's to 1's to connect the two islands to form one island.\n Return the smallest number of 0's you must flip to connect the two islands.\n \n Example 1:\n \n >>> shortestBridge(grid = [[0,1],[1,0]])\n >>> 1\n \n Example 2:\n \n >>> shortestBridge(grid = [[0,1,0],[0,0,0],[0,0,1]])\n >>> 2\n \n Example 3:\n \n >>> shortestBridge(grid = [[1,1,1,1,1],[1,0,0,0,1],[1,0,1,0,1],[1,0,0,0,1],[1,1,1,1,1]])\n >>> 1\n \"\"\"\n"}
{"task_id": "knight-dialer", "prompt": "def knightDialer(n: int) -> int:\n \"\"\"\n The chess knight has a unique movement,\u00a0it may move two squares vertically and one square horizontally, or two squares horizontally and one square vertically (with both forming the shape of an L). The possible movements of chess knight are shown in this diagram:\n A chess knight can move as indicated in the chess diagram below:\n \n We have a chess knight and a phone pad as shown below, the knight can only stand on a numeric cell\u00a0(i.e. blue cell).\n \n Given an integer n, return how many distinct phone numbers of length n we can dial.\n You are allowed to place the knight on any numeric cell initially and then you should perform n - 1 jumps to dial a number of length n. All jumps should be valid knight jumps.\n As the answer may be very large, return the answer modulo 109 + 7.\n \n Example 1:\n \n >>> knightDialer(n = 1)\n >>> 10\n Explanation: We need to dial a number of length 1, so placing the knight over any numeric cell of the 10 cells is sufficient.\n \n Example 2:\n \n >>> knightDialer(n = 2)\n >>> 20\n Explanation: All the valid number we can dial are [04, 06, 16, 18, 27, 29, 34, 38, 40, 43, 49, 60, 61, 67, 72, 76, 81, 83, 92, 94]\n \n Example 3:\n \n >>> knightDialer(n = 3131)\n >>> 136006598\n Explanation: Please take care of the mod.\n \"\"\"\n"}
{"task_id": "stamping-the-sequence", "prompt": "def movesToStamp(stamp: str, target: str) -> List[int]:\n \"\"\"\n You are given two strings stamp and target. Initially, there is a string s of length target.length with all s[i] == '?'.\n In one turn, you can place stamp over s and replace every letter in the s with the corresponding letter from stamp.\n \n For example, if stamp = \"abc\" and target = \"abcba\", then s is \"?????\" initially. In one turn you can:\n \n \n place stamp at index 0 of s to obtain \"abc??\",\n place stamp at index 1 of s to obtain \"?abc?\", or\n place stamp at index 2 of s to obtain \"??abc\".\n \n \tNote that stamp must be fully contained in the boundaries of s in order to stamp (i.e., you cannot place stamp at index 3 of s).\n \n We want to convert s to target using at most 10 * target.length turns.\n Return an array of the index of the left-most letter being stamped at each turn. If we cannot obtain target from s within 10 * target.length turns, return an empty array.\n \n Example 1:\n \n >>> movesToStamp(stamp = \"abc\", target = \"ababc\")\n >>> [0,2]\n Explanation: Initially s = \"?????\".\n - Place stamp at index 0 to get \"abc??\".\n - Place stamp at index 2 to get \"ababc\".\n [1,0,2] would also be accepted as an answer, as well as some other answers.\n \n Example 2:\n \n >>> movesToStamp(stamp = \"abca\", target = \"aabcaca\")\n >>> [3,0,1]\n Explanation: Initially s = \"???????\".\n - Place stamp at index 3 to get \"???abca\".\n - Place stamp at index 0 to get \"abcabca\".\n - Place stamp at index 1 to get \"aabcaca\".\n \"\"\"\n"}
{"task_id": "reorder-data-in-log-files", "prompt": "def reorderLogFiles(logs: List[str]) -> List[str]:\n \"\"\"\n You are given an array of logs. Each log is a space-delimited string of words, where the first word is the identifier.\n There are two types of logs:\n \n Letter-logs: All words (except the identifier) consist of lowercase English letters.\n Digit-logs: All words (except the identifier) consist of digits.\n \n Reorder these logs so that:\n \n The letter-logs come before all digit-logs.\n The letter-logs are sorted lexicographically by their contents. If their contents are the same, then sort them lexicographically by their identifiers.\n The digit-logs maintain their relative ordering.\n \n Return the final order of the logs.\n \n Example 1:\n \n >>> reorderLogFiles(logs = [\"dig1 8 1 5 1\",\"let1 art can\",\"dig2 3 6\",\"let2 own kit dig\",\"let3 art zero\"])\n >>> [\"let1 art can\",\"let3 art zero\",\"let2 own kit dig\",\"dig1 8 1 5 1\",\"dig2 3 6\"]\n Explanation:\n The letter-log contents are all different, so their ordering is \"art can\", \"art zero\", \"own kit dig\".\n The digit-logs have a relative order of \"dig1 8 1 5 1\", \"dig2 3 6\".\n \n Example 2:\n \n >>> reorderLogFiles(logs = [\"a1 9 2 3 1\",\"g1 act car\",\"zo4 4 7\",\"ab1 off key dog\",\"a8 act zoo\"])\n >>> [\"g1 act car\",\"a8 act zoo\",\"ab1 off key dog\",\"a1 9 2 3 1\",\"zo4 4 7\"]\n \"\"\"\n"}
{"task_id": "range-sum-of-bst", "prompt": "# class TreeNode:\n# def __init__(val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def rangeSumBST(root: Optional[TreeNode], low: int, high: int) -> int:\n \"\"\"\n Given the root node of a binary search tree and two integers low and high, return the sum of values of all nodes with a value in the inclusive range [low, high].\n \n Example 1:\n \n \n >>> __init__(root = [10,5,15,3,7,null,18], low = 7, high = 15)\n >>> 32\n Explanation: Nodes 7, 10, and 15 are in the range [7, 15]. 7 + 10 + 15 = 32.\n \n Example 2:\n \n \n >>> __init__(root = [10,5,15,3,7,13,18,1,null,6], low = 6, high = 10)\n >>> 23\n Explanation: Nodes 6, 7, and 10 are in the range [6, 10]. 6 + 7 + 10 = 23.\n \"\"\"\n"}
{"task_id": "minimum-area-rectangle", "prompt": "def minAreaRect(points: List[List[int]]) -> int:\n \"\"\"\n You are given an array of points in the X-Y plane points where points[i] = [xi, yi].\n Return the minimum area of a rectangle formed from these points, with sides parallel to the X and Y axes. If there is not any such rectangle, return 0.\n \n Example 1:\n \n \n >>> minAreaRect(points = [[1,1],[1,3],[3,1],[3,3],[2,2]])\n >>> 4\n \n Example 2:\n \n \n >>> minAreaRect(points = [[1,1],[1,3],[3,1],[3,3],[4,1],[4,3]])\n >>> 2\n \"\"\"\n"}
{"task_id": "distinct-subsequences-ii", "prompt": "def distinctSubseqII(s: str) -> int:\n \"\"\"\n Given a string s, return the number of distinct non-empty subsequences of s. Since the answer may be very large, return it modulo 109 + 7.\n A subsequence of a string is a new string that is formed from the original string by deleting some (can be none) of the characters without disturbing the relative positions of the remaining characters. (i.e., \"ace\" is a subsequence of \"abcde\" while \"aec\" is not.\n \n Example 1:\n \n >>> distinctSubseqII(s = \"abc\")\n >>> 7\n Explanation: The 7 distinct subsequences are \"a\", \"b\", \"c\", \"ab\", \"ac\", \"bc\", and \"abc\".\n \n Example 2:\n \n >>> distinctSubseqII(s = \"aba\")\n >>> 6\n Explanation: The 6 distinct subsequences are \"a\", \"b\", \"ab\", \"aa\", \"ba\", and \"aba\".\n \n Example 3:\n \n >>> distinctSubseqII(s = \"aaa\")\n >>> 3\n Explanation: The 3 distinct subsequences are \"a\", \"aa\" and \"aaa\".\n \"\"\"\n"}
{"task_id": "valid-mountain-array", "prompt": "def validMountainArray(arr: List[int]) -> bool:\n \"\"\"\n Given an array of integers arr, return true if and only if it is a valid mountain array.\n Recall that arr is a mountain array if and only if:\n \n arr.length >= 3\n There exists some i with 0 < i < arr.length - 1 such that:\n \n arr[0] < arr[1] < ... < arr[i - 1] < arr[i]\n arr[i] > arr[i + 1] > ... > arr[arr.length - 1]\n \n \n \n \n \n Example 1:\n >>> validMountainArray(arr = [2,1])\n >>> false\n Example 2:\n >>> validMountainArray(arr = [3,5,5])\n >>> false\n Example 3:\n >>> validMountainArray(arr = [0,3,2,1])\n >>> true\n \"\"\"\n"}
{"task_id": "di-string-match", "prompt": "def diStringMatch(s: str) -> List[int]:\n \"\"\"\n A permutation perm of n + 1 integers of all the integers in the range [0, n] can be represented as a string s of length n where:\n \n s[i] == 'I' if perm[i] < perm[i + 1], and\n s[i] == 'D' if perm[i] > perm[i + 1].\n \n Given a string s, reconstruct the permutation perm and return it. If there are multiple valid permutations perm, return any of them.\n \n Example 1:\n >>> diStringMatch(s = \"IDID\")\n >>> [0,4,1,3,2]\n Example 2:\n >>> diStringMatch(s = \"III\")\n >>> [0,1,2,3]\n Example 3:\n >>> diStringMatch(s = \"DDI\")\n >>> [3,2,0,1]\n \"\"\"\n"}
{"task_id": "find-the-shortest-superstring", "prompt": "def shortestSuperstring(words: List[str]) -> str:\n \"\"\"\n Given an array of strings words, return the smallest string that contains each string in words as a substring. If there are multiple valid strings of the smallest length, return any of them.\n You may assume that no string in words is a substring of another string in words.\n \n Example 1:\n \n >>> shortestSuperstring(words = [\"alex\",\"loves\",\"leetcode\"])\n >>> \"alexlovesleetcode\"\n Explanation: All permutations of \"alex\",\"loves\",\"leetcode\" would also be accepted.\n \n Example 2:\n \n >>> shortestSuperstring(words = [\"catg\",\"ctaagt\",\"gcta\",\"ttca\",\"atgcatc\"])\n >>> \"gctaagttcatgcatc\"\n \"\"\"\n"}
{"task_id": "delete-columns-to-make-sorted", "prompt": "def minDeletionSize(strs: List[str]) -> int:\n \"\"\"\n You are given an array of n strings strs, all of the same length.\n The strings can be arranged such that there is one on each line, making a grid.\n \n For example, strs = [\"abc\", \"bce\", \"cae\"] can be arranged as follows:\n \n \n abc\n bce\n cae\n \n You want to delete the columns that are not sorted lexicographically. In the above example (0-indexed), columns 0 ('a', 'b', 'c') and 2 ('c', 'e', 'e') are sorted, while column 1 ('b', 'c', 'a') is not, so you would delete column 1.\n Return the number of columns that you will delete.\n \n Example 1:\n \n >>> minDeletionSize(strs = [\"cba\",\"daf\",\"ghi\"])\n >>> 1\n Explanation: The grid looks as follows:\n cba\n daf\n ghi\n Columns 0 and 2 are sorted, but column 1 is not, so you only need to delete 1 column.\n \n Example 2:\n \n >>> minDeletionSize(strs = [\"a\",\"b\"])\n >>> 0\n Explanation: The grid looks as follows:\n a\n b\n Column 0 is the only column and is sorted, so you will not delete any columns.\n \n Example 3:\n \n >>> minDeletionSize(strs = [\"zyx\",\"wvu\",\"tsr\"])\n >>> 3\n Explanation: The grid looks as follows:\n zyx\n wvu\n tsr\n All 3 columns are not sorted, so you will delete all 3.\n \"\"\"\n"}
{"task_id": "minimum-increment-to-make-array-unique", "prompt": "def minIncrementForUnique(nums: List[int]) -> int:\n \"\"\"\n You are given an integer array nums. In one move, you can pick an index i where 0 <= i < nums.length and increment nums[i] by 1.\n Return the minimum number of moves to make every value in nums unique.\n The test cases are generated so that the answer fits in a 32-bit integer.\n \n Example 1:\n \n >>> minIncrementForUnique(nums = [1,2,2])\n >>> 1\n Explanation: After 1 move, the array could be [1, 2, 3].\n \n Example 2:\n \n >>> minIncrementForUnique(nums = [3,2,1,2,1,7])\n >>> 6\n Explanation: After 6 moves, the array could be [3, 4, 1, 2, 5, 7].\n It can be shown that it is impossible for the array to have all unique values with 5 or less moves.\n \"\"\"\n"}
{"task_id": "validate-stack-sequences", "prompt": "def validateStackSequences(pushed: List[int], popped: List[int]) -> bool:\n \"\"\"\n Given two integer arrays pushed and popped each with distinct values, return true if this could have been the result of a sequence of push and pop operations on an initially empty stack, or false otherwise.\n \n Example 1:\n \n >>> validateStackSequences(pushed = [1,2,3,4,5], popped = [4,5,3,2,1])\n >>> true\n Explanation: We might do the following sequence:\n push(1), push(2), push(3), push(4),\n pop() -> 4,\n push(5),\n pop() -> 5, pop() -> 3, pop() -> 2, pop() -> 1\n \n Example 2:\n \n >>> validateStackSequences(pushed = [1,2,3,4,5], popped = [4,3,5,1,2])\n >>> false\n Explanation: 1 cannot be popped before 2.\n \"\"\"\n"}
{"task_id": "most-stones-removed-with-same-row-or-column", "prompt": "def removeStones(stones: List[List[int]]) -> int:\n \"\"\"\n On a 2D plane, we place n stones at some integer coordinate points. Each coordinate point may have at most one stone.\n A stone can be removed if it shares either the same row or the same column as another stone that has not been removed.\n Given an array stones of length n where stones[i] = [xi, yi] represents the location of the ith stone, return the largest possible number of stones that can be removed.\n \n Example 1:\n \n >>> removeStones(stones = [[0,0],[0,1],[1,0],[1,2],[2,1],[2,2]])\n >>> 5\n Explanation: One way to remove 5 stones is as follows:\n 1. Remove stone [2,2] because it shares the same row as [2,1].\n 2. Remove stone [2,1] because it shares the same column as [0,1].\n 3. Remove stone [1,2] because it shares the same row as [1,0].\n 4. Remove stone [1,0] because it shares the same column as [0,0].\n 5. Remove stone [0,1] because it shares the same row as [0,0].\n Stone [0,0] cannot be removed since it does not share a row/column with another stone still on the plane.\n \n Example 2:\n \n >>> removeStones(stones = [[0,0],[0,2],[1,1],[2,0],[2,2]])\n >>> 3\n Explanation: One way to make 3 moves is as follows:\n 1. Remove stone [2,2] because it shares the same row as [2,0].\n 2. Remove stone [2,0] because it shares the same column as [0,0].\n 3. Remove stone [0,2] because it shares the same row as [0,0].\n Stones [0,0] and [1,1] cannot be removed since they do not share a row/column with another stone still on the plane.\n \n Example 3:\n \n >>> removeStones(stones = [[0,0]])\n >>> 0\n Explanation: [0,0] is the only stone on the plane, so you cannot remove it.\n \"\"\"\n"}
{"task_id": "bag-of-tokens", "prompt": "def bagOfTokensScore(tokens: List[int], power: int) -> int:\n \"\"\"\n You start with an initial power of power, an initial score of 0, and a bag of tokens given as an integer array tokens, where each\u00a0tokens[i] denotes the value of tokeni.\n Your goal is to maximize the total score by strategically playing these tokens. In one move, you can play an unplayed token in one of the two ways (but not both for the same token):\n \n Face-up: If your current power is at least tokens[i], you may play tokeni, losing tokens[i] power and gaining 1 score.\n Face-down: If your current score is at least 1, you may play tokeni, gaining tokens[i] power and losing 1 score.\n \n Return the maximum possible score you can achieve after playing any number of tokens.\n \n Example 1:\n \n >>> bagOfTokensScore(tokens = [100], power = 50)\n >>> 0\n Explanation: Since your score is 0 initially, you cannot play the token face-down. You also cannot play it face-up since your power (50) is less than tokens[0]\u00a0(100).\n \n Example 2:\n \n >>> bagOfTokensScore(tokens = [200,100], power = 150)\n >>> 1\n Explanation: Play token1 (100) face-up, reducing your power to\u00a050 and increasing your score to\u00a01.\n There is no need to play token0, since you cannot play it face-up to add to your score. The maximum score achievable is 1.\n \n Example 3:\n \n >>> bagOfTokensScore(tokens = [100,200,300,400], power = 200)\n >>> 2\n Explanation: Play the tokens in this order to get a score of 2:\n \n Play token0 (100) face-up, reducing power to 100 and increasing score to 1.\n Play token3 (400) face-down, increasing power to 500 and reducing score to 0.\n Play token1 (200) face-up, reducing power to 300 and increasing score to 1.\n Play token2 (300) face-up, reducing power to 0 and increasing score to 2.\n \n The maximum score achievable is 2.\n \"\"\"\n"}
{"task_id": "largest-time-for-given-digits", "prompt": "def largestTimeFromDigits(arr: List[int]) -> str:\n \"\"\"\n Given an array arr of 4 digits, find the latest 24-hour time that can be made using each digit exactly once.\n 24-hour times are formatted as \"HH:MM\", where HH is between 00 and 23, and MM is between 00 and 59. The earliest 24-hour time is 00:00, and the latest is 23:59.\n Return the latest 24-hour time in \"HH:MM\" format. If no valid time can be made, return an empty string.\n \n Example 1:\n \n >>> largestTimeFromDigits(arr = [1,2,3,4])\n >>> \"23:41\"\n Explanation: The valid 24-hour times are \"12:34\", \"12:43\", \"13:24\", \"13:42\", \"14:23\", \"14:32\", \"21:34\", \"21:43\", \"23:14\", and \"23:41\". Of these times, \"23:41\" is the latest.\n \n Example 2:\n \n >>> largestTimeFromDigits(arr = [5,5,5,5])\n >>> \"\"\n Explanation: There are no valid 24-hour times as \"55:55\" is not valid.\n \"\"\"\n"}
{"task_id": "reveal-cards-in-increasing-order", "prompt": "def deckRevealedIncreasing(deck: List[int]) -> List[int]:\n \"\"\"\n You are given an integer array deck. There is a deck of cards where every card has a unique integer. The integer on the ith card is deck[i].\n You can order the deck in any order you want. Initially, all the cards start face down (unrevealed) in one deck.\n You will do the following steps repeatedly until all cards are revealed:\n \n Take the top card of the deck, reveal it, and take it out of the deck.\n If there are still cards in the deck then put the next top card of the deck at the bottom of the deck.\n If there are still unrevealed cards, go back to step 1. Otherwise, stop.\n \n Return an ordering of the deck that would reveal the cards in increasing order.\n Note that the first entry in the answer is considered to be the top of the deck.\n \n Example 1:\n \n >>> deckRevealedIncreasing(deck = [17,13,11,2,3,5,7])\n >>> [2,13,3,11,5,17,7]\n Explanation:\n We get the deck in the order [17,13,11,2,3,5,7] (this order does not matter), and reorder it.\n After reordering, the deck starts as [2,13,3,11,5,17,7], where 2 is the top of the deck.\n We reveal 2, and move 13 to the bottom. The deck is now [3,11,5,17,7,13].\n We reveal 3, and move 11 to the bottom. The deck is now [5,17,7,13,11].\n We reveal 5, and move 17 to the bottom. The deck is now [7,13,11,17].\n We reveal 7, and move 13 to the bottom. The deck is now [11,17,13].\n We reveal 11, and move 17 to the bottom. The deck is now [13,17].\n We reveal 13, and move 17 to the bottom. The deck is now [17].\n We reveal 17.\n Since all the cards revealed are in increasing order, the answer is correct.\n \n Example 2:\n \n >>> deckRevealedIncreasing(deck = [1,1000])\n >>> [1,1000]\n \"\"\"\n"}
{"task_id": "flip-equivalent-binary-trees", "prompt": "# class TreeNode:\n# def __init__(val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def flipEquiv(root1: Optional[TreeNode], root2: Optional[TreeNode]) -> bool:\n \"\"\"\n For a binary tree T, we can define a flip operation as follows: choose any node, and swap the left and right child subtrees.\n A binary tree X\u00a0is flip equivalent to a binary tree Y if and only if we can make X equal to Y after some number of flip operations.\n Given the roots of two binary trees root1 and root2, return true if the two trees are flip equivalent or false otherwise.\n \n Example 1:\n \n \n >>> __init__(root1 = [1,2,3,4,5,6,null,null,null,7,8], root2 = [1,3,2,null,6,4,5,null,null,null,null,8,7])\n >>> true\n Explanation: We flipped at nodes with values 1, 3, and 5.\n \n Example 2:\n \n >>> __init__(root1 = [], root2 = [])\n >>> true\n \n Example 3:\n \n >>> __init__(root1 = [], root2 = [1])\n >>> false\n \"\"\"\n"}
{"task_id": "largest-component-size-by-common-factor", "prompt": "def largestComponentSize(nums: List[int]) -> int:\n \"\"\"\n You are given an integer array of unique positive integers nums. Consider the following graph:\n \n There are nums.length nodes, labeled nums[0] to nums[nums.length - 1],\n There is an undirected edge between nums[i] and nums[j] if nums[i] and nums[j] share a common factor greater than 1.\n \n Return the size of the largest connected component in the graph.\n \n Example 1:\n \n \n >>> largestComponentSize(nums = [4,6,15,35])\n >>> 4\n \n Example 2:\n \n \n >>> largestComponentSize(nums = [20,50,9,63])\n >>> 2\n \n Example 3:\n \n \n >>> largestComponentSize(nums = [2,3,6,7,4,12,21,39])\n >>> 8\n \"\"\"\n"}
{"task_id": "verifying-an-alien-dictionary", "prompt": "def isAlienSorted(words: List[str], order: str) -> bool:\n \"\"\"\n In an alien language, surprisingly, they also use English lowercase letters, but possibly in a different order. The order of the alphabet is some permutation of lowercase letters.\n Given a sequence of words written in the alien language, and the order of the alphabet, return true if and only if the given words are sorted lexicographically in this alien language.\n \n Example 1:\n \n >>> isAlienSorted(words = [\"hello\",\"leetcode\"], order = \"hlabcdefgijkmnopqrstuvwxyz\")\n >>> true\n Explanation: As 'h' comes before 'l' in this language, then the sequence is sorted.\n \n Example 2:\n \n >>> isAlienSorted(words = [\"word\",\"world\",\"row\"], order = \"worldabcefghijkmnpqstuvxyz\")\n >>> false\n Explanation: As 'd' comes after 'l' in this language, then words[0] > words[1], hence the sequence is unsorted.\n \n Example 3:\n \n >>> isAlienSorted(words = [\"apple\",\"app\"], order = \"abcdefghijklmnopqrstuvwxyz\")\n >>> false\n Explanation: The first three characters \"app\" match, and the second string is shorter (in size.) According to lexicographical rules \"apple\" > \"app\", because 'l' > '\u2205', where '\u2205' is defined as the blank character which is less than any other character (More info).\n \"\"\"\n"}
{"task_id": "array-of-doubled-pairs", "prompt": "def canReorderDoubled(arr: List[int]) -> bool:\n \"\"\"\n Given an integer array of even length arr, return true if it is possible to reorder arr such that arr[2 * i + 1] = 2 * arr[2 * i] for every 0 <= i < len(arr) / 2, or false otherwise.\n \n Example 1:\n \n >>> canReorderDoubled(arr = [3,1,3,6])\n >>> false\n \n Example 2:\n \n >>> canReorderDoubled(arr = [2,1,2,6])\n >>> false\n \n Example 3:\n \n >>> canReorderDoubled(arr = [4,-2,2,-4])\n >>> true\n Explanation: We can take two groups, [-2,-4] and [2,4] to form [-2,-4,2,4] or [2,4,-2,-4].\n \"\"\"\n"}
{"task_id": "delete-columns-to-make-sorted-ii", "prompt": "def minDeletionSize(strs: List[str]) -> int:\n \"\"\"\n You are given an array of n strings strs, all of the same length.\n We may choose any deletion indices, and we delete all the characters in those indices for each string.\n For example, if we have strs = [\"abcdef\",\"uvwxyz\"] and deletion indices {0, 2, 3}, then the final array after deletions is [\"bef\", \"vyz\"].\n Suppose we chose a set of deletion indices answer such that after deletions, the final array has its elements in lexicographic order (i.e., strs[0] <= strs[1] <= strs[2] <= ... <= strs[n - 1]). Return the minimum possible value of answer.length.\n \n Example 1:\n \n >>> minDeletionSize(strs = [\"ca\",\"bb\",\"ac\"])\n >>> 1\n Explanation:\n After deleting the first column, strs = [\"a\", \"b\", \"c\"].\n Now strs is in lexicographic order (ie. strs[0] <= strs[1] <= strs[2]).\n We require at least 1 deletion since initially strs was not in lexicographic order, so the answer is 1.\n \n Example 2:\n \n >>> minDeletionSize(strs = [\"xc\",\"yb\",\"za\"])\n >>> 0\n Explanation:\n strs is already in lexicographic order, so we do not need to delete anything.\n Note that the rows of strs are not necessarily in lexicographic order:\n i.e., it is NOT necessarily true that (strs[0][0] <= strs[0][1] <= ...)\n \n Example 3:\n \n >>> minDeletionSize(strs = [\"zyx\",\"wvu\",\"tsr\"])\n >>> 3\n Explanation: We have to delete every column.\n \"\"\"\n"}
{"task_id": "tallest-billboard", "prompt": "def tallestBillboard(rods: List[int]) -> int:\n \"\"\"\n You are installing a billboard and want it to have the largest height. The billboard will have two steel supports, one on each side. Each steel support must be an equal height.\n You are given a collection of rods that can be welded together. For example, if you have rods of lengths 1, 2, and 3, you can weld them together to make a support of length 6.\n Return the largest possible height of your billboard installation. If you cannot support the billboard, return 0.\n \n Example 1:\n \n >>> tallestBillboard(rods = [1,2,3,6])\n >>> 6\n Explanation: We have two disjoint subsets {1,2,3} and {6}, which have the same sum = 6.\n \n Example 2:\n \n >>> tallestBillboard(rods = [1,2,3,4,5,6])\n >>> 10\n Explanation: We have two disjoint subsets {2,3,5} and {4,6}, which have the same sum = 10.\n \n Example 3:\n \n >>> tallestBillboard(rods = [1,2])\n >>> 0\n Explanation: The billboard cannot be supported, so we return 0.\n \"\"\"\n"}
{"task_id": "prison-cells-after-n-days", "prompt": "def prisonAfterNDays(cells: List[int], n: int) -> List[int]:\n \"\"\"\n There are 8 prison cells in a row and each cell is either occupied or vacant.\n Each day, whether the cell is occupied or vacant changes according to the following rules:\n \n If a cell has two adjacent neighbors that are both occupied or both vacant, then the cell becomes occupied.\n Otherwise, it becomes vacant.\n \n Note that because the prison is a row, the first and the last cells in the row can't have two adjacent neighbors.\n You are given an integer array cells where cells[i] == 1 if the ith cell is occupied and cells[i] == 0 if the ith cell is vacant, and you are given an integer n.\n Return the state of the prison after n days (i.e., n such changes described above).\n \n Example 1:\n \n >>> prisonAfterNDays(cells = [0,1,0,1,1,0,0,1], n = 7)\n >>> [0,0,1,1,0,0,0,0]\n Explanation: The following table summarizes the state of the prison on each day:\n Day 0: [0, 1, 0, 1, 1, 0, 0, 1]\n Day 1: [0, 1, 1, 0, 0, 0, 0, 0]\n Day 2: [0, 0, 0, 0, 1, 1, 1, 0]\n Day 3: [0, 1, 1, 0, 0, 1, 0, 0]\n Day 4: [0, 0, 0, 0, 0, 1, 0, 0]\n Day 5: [0, 1, 1, 1, 0, 1, 0, 0]\n Day 6: [0, 0, 1, 0, 1, 1, 0, 0]\n Day 7: [0, 0, 1, 1, 0, 0, 0, 0]\n \n Example 2:\n \n >>> prisonAfterNDays(cells = [1,0,0,1,0,0,1,0], n = 1000000000)\n >>> [0,0,1,1,1,1,1,0]\n \"\"\"\n"}
{"task_id": "check-completeness-of-a-binary-tree", "prompt": "# class TreeNode:\n# def __init__(val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def isCompleteTree(root: Optional[TreeNode]) -> bool:\n \"\"\"\n Given the root of a binary tree, determine if it is a complete binary tree.\n In a complete binary tree, every level, except possibly the last, is completely filled, and all nodes in the last level are as far left as possible. It can have between 1 and 2h nodes inclusive at the last level h.\n \n Example 1:\n \n \n >>> __init__(root = [1,2,3,4,5,6])\n >>> true\n Explanation: Every level before the last is full (ie. levels with node-values {1} and {2, 3}), and all nodes in the last level ({4, 5, 6}) are as far left as possible.\n \n Example 2:\n \n \n >>> __init__(root = [1,2,3,4,5,null,7])\n >>> false\n Explanation: The node with value 7 isn't as far left as possible.\n \"\"\"\n"}
{"task_id": "regions-cut-by-slashes", "prompt": "def regionsBySlashes(grid: List[str]) -> int:\n \"\"\"\n An n x n grid is composed of 1 x 1 squares where each 1 x 1 square consists of a '/', '\\', or blank space ' '. These characters divide the square into contiguous regions.\n Given the grid grid represented as a string array, return the number of regions.\n Note that backslash characters are escaped, so a '\\' is represented as '\\\\'.\n \n Example 1:\n \n \n >>> regionsBySlashes(grid = [\" /\",\"/ \"])\n >>> 2\n \n Example 2:\n \n \n >>> regionsBySlashes(grid = [\" /\",\" \"])\n >>> 1\n \n Example 3:\n \n \n >>> regionsBySlashes(grid = [\"/\\\\\",\"\\\\/\"])\n >>> 5\n Explanation: Recall that because \\ characters are escaped, \"\\\\/\" refers to \\/, and \"/\\\\\" refers to /\\.\n \"\"\"\n"}
{"task_id": "delete-columns-to-make-sorted-iii", "prompt": "def minDeletionSize(strs: List[str]) -> int:\n \"\"\"\n You are given an array of n strings strs, all of the same length.\n We may choose any deletion indices, and we delete all the characters in those indices for each string.\n For example, if we have strs = [\"abcdef\",\"uvwxyz\"] and deletion indices {0, 2, 3}, then the final array after deletions is [\"bef\", \"vyz\"].\n Suppose we chose a set of deletion indices answer such that after deletions, the final array has every string (row) in lexicographic order. (i.e., (strs[0][0] <= strs[0][1] <= ... <= strs[0][strs[0].length - 1]), and (strs[1][0] <= strs[1][1] <= ... <= strs[1][strs[1].length - 1]), and so on). Return the minimum possible value of answer.length.\n \n Example 1:\n \n >>> minDeletionSize(strs = [\"babca\",\"bbazb\"])\n >>> 3\n Explanation: After deleting columns 0, 1, and 4, the final array is strs = [\"bc\", \"az\"].\n Both these rows are individually in lexicographic order (ie. strs[0][0] <= strs[0][1] and strs[1][0] <= strs[1][1]).\n Note that strs[0] > strs[1] - the array strs is not necessarily in lexicographic order.\n Example 2:\n \n >>> minDeletionSize(strs = [\"edcba\"])\n >>> 4\n Explanation: If we delete less than 4 columns, the only row will not be lexicographically sorted.\n \n Example 3:\n \n >>> minDeletionSize(strs = [\"ghi\",\"def\",\"abc\"])\n >>> 0\n Explanation: All rows are already lexicographically sorted.\n \"\"\"\n"}
{"task_id": "n-repeated-element-in-size-2n-array", "prompt": "def repeatedNTimes(nums: List[int]) -> int:\n \"\"\"\n You are given an integer array nums with the following properties:\n \n nums.length == 2 * n.\n nums contains n + 1 unique elements.\n Exactly one element of nums is repeated n times.\n \n Return the element that is repeated n times.\n \n Example 1:\n >>> repeatedNTimes(nums = [1,2,3,3])\n >>> 3\n Example 2:\n >>> repeatedNTimes(nums = [2,1,2,5,3,2])\n >>> 2\n Example 3:\n >>> repeatedNTimes(nums = [5,1,5,2,5,3,5,4])\n >>> 5\n \"\"\"\n"}
{"task_id": "maximum-width-ramp", "prompt": "def maxWidthRamp(nums: List[int]) -> int:\n \"\"\"\n A ramp in an integer array nums is a pair (i, j) for which i < j and nums[i] <= nums[j]. The width of such a ramp is j - i.\n Given an integer array nums, return the maximum width of a ramp in nums. If there is no ramp in nums, return 0.\n \n Example 1:\n \n >>> maxWidthRamp(nums = [6,0,8,2,1,5])\n >>> 4\n Explanation: The maximum width ramp is achieved at (i, j) = (1, 5): nums[1] = 0 and nums[5] = 5.\n \n Example 2:\n \n >>> maxWidthRamp(nums = [9,8,1,0,1,9,4,0,4,1])\n >>> 7\n Explanation: The maximum width ramp is achieved at (i, j) = (2, 9): nums[2] = 1 and nums[9] = 1.\n \"\"\"\n"}
{"task_id": "minimum-area-rectangle-ii", "prompt": "def minAreaFreeRect(points: List[List[int]]) -> float:\n \"\"\"\n You are given an array of points in the X-Y plane points where points[i] = [xi, yi].\n Return the minimum area of any rectangle formed from these points, with sides not necessarily parallel to the X and Y axes. If there is not any such rectangle, return 0.\n Answers within 10-5 of the actual answer will be accepted.\n \n Example 1:\n \n \n >>> minAreaFreeRect(points = [[1,2],[2,1],[1,0],[0,1]])\n >>> 2.00000\n Explanation: The minimum area rectangle occurs at [1,2],[2,1],[1,0],[0,1], with an area of 2.\n \n Example 2:\n \n \n >>> minAreaFreeRect(points = [[0,1],[2,1],[1,1],[1,0],[2,0]])\n >>> 1.00000\n Explanation: The minimum area rectangle occurs at [1,0],[1,1],[2,1],[2,0], with an area of 1.\n \n Example 3:\n \n \n >>> minAreaFreeRect(points = [[0,3],[1,2],[3,1],[1,3],[2,1]])\n >>> 0\n Explanation: There is no possible rectangle to form from these points.\n \"\"\"\n"}
{"task_id": "least-operators-to-express-number", "prompt": "def leastOpsExpressTarget(x: int, target: int) -> int:\n \"\"\"\n Given a single positive integer x, we will write an expression of the form x (op1) x (op2) x (op3) x ... where each operator op1, op2, etc. is either addition, subtraction, multiplication, or division (+, -, *, or /). For example, with x = 3, we might write 3 * 3 / 3 + 3 - 3 which is a value of 3.\n When writing such an expression, we adhere to the following conventions:\n \n The division operator (/) returns rational numbers.\n There are no parentheses placed anywhere.\n We use the usual order of operations: multiplication and division happen before addition and subtraction.\n It is not allowed to use the unary negation operator (-). For example, \"x - x\" is a valid expression as it only uses subtraction, but \"-x + x\" is not because it uses negation.\n \n We would like to write an expression with the least number of operators such that the expression equals the given target. Return the least number of operators used.\n \n Example 1:\n \n >>> leastOpsExpressTarget(x = 3, target = 19)\n >>> 5\n Explanation: 3 * 3 + 3 * 3 + 3 / 3.\n The expression contains 5 operations.\n \n Example 2:\n \n >>> leastOpsExpressTarget(x = 5, target = 501)\n >>> 8\n Explanation: 5 * 5 * 5 * 5 - 5 * 5 * 5 + 5 / 5.\n The expression contains 8 operations.\n \n Example 3:\n \n >>> leastOpsExpressTarget(x = 100, target = 100000000)\n >>> 3\n Explanation: 100 * 100 * 100 * 100.\n The expression contains 3 operations.\n \"\"\"\n"}
{"task_id": "univalued-binary-tree", "prompt": "# class TreeNode:\n# def __init__(val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def isUnivalTree(root: Optional[TreeNode]) -> bool:\n \"\"\"\n A binary tree is uni-valued if every node in the tree has the same value.\n Given the root of a binary tree, return true if the given tree is uni-valued, or false otherwise.\n \n Example 1:\n \n \n >>> __init__(root = [1,1,1,1,1,null,1])\n >>> true\n \n Example 2:\n \n \n >>> __init__(root = [2,2,2,5,2])\n >>> false\n \"\"\"\n"}
{"task_id": "vowel-spellchecker", "prompt": "def spellchecker(wordlist: List[str], queries: List[str]) -> List[str]:\n \"\"\"\n Given a wordlist, we want to implement a spellchecker that converts a query word into a correct word.\n For a given query word, the spell checker handles two categories of spelling mistakes:\n \n Capitalization: If the query matches a word in the wordlist (case-insensitive), then the query word is returned with the same case as the case in the wordlist.\n \n \n Example: wordlist = [\"yellow\"], query = \"YellOw\": correct = \"yellow\"\n Example: wordlist = [\"Yellow\"], query = \"yellow\": correct = \"Yellow\"\n Example: wordlist = [\"yellow\"], query = \"yellow\": correct = \"yellow\"\n \n \n Vowel Errors: If after replacing the vowels ('a', 'e', 'i', 'o', 'u') of the query word with any vowel individually, it matches a word in the wordlist (case-insensitive), then the query word is returned with the same case as the match in the wordlist.\n \n Example: wordlist = [\"YellOw\"], query = \"yollow\": correct = \"YellOw\"\n Example: wordlist = [\"YellOw\"], query = \"yeellow\": correct = \"\" (no match)\n Example: wordlist = [\"YellOw\"], query = \"yllw\": correct = \"\" (no match)\n \n \n \n In addition, the spell checker operates under the following precedence rules:\n \n When the query exactly matches a word in the wordlist (case-sensitive), you should return the same word back.\n When the query matches a word up to capitlization, you should return the first such match in the wordlist.\n When the query matches a word up to vowel errors, you should return the first such match in the wordlist.\n If the query has no matches in the wordlist, you should return the empty string.\n \n Given some queries, return a list of words answer, where answer[i] is the correct word for query = queries[i].\n \n Example 1:\n >>> spellchecker(wordlist = [\"KiTe\",\"kite\",\"hare\",\"Hare\"], queries = [\"kite\",\"Kite\",\"KiTe\",\"Hare\",\"HARE\",\"Hear\",\"hear\",\"keti\",\"keet\",\"keto\"])\n >>> [\"kite\",\"KiTe\",\"KiTe\",\"Hare\",\"hare\",\"\",\"\",\"KiTe\",\"\",\"KiTe\"]\n Example 2:\n >>> spellchecker(wordlist = [\"yellow\"], queries = [\"YellOw\"])\n >>> [\"yellow\"]\n \"\"\"\n"}
{"task_id": "numbers-with-same-consecutive-differences", "prompt": "def numsSameConsecDiff(n: int, k: int) -> List[int]:\n \"\"\"\n Given two integers n and k, return an array of all the integers of length n where the difference between every two consecutive digits is k. You may return the answer in any order.\n Note that the integers should not have leading zeros. Integers as 02 and 043 are not allowed.\n \n Example 1:\n \n >>> numsSameConsecDiff(n = 3, k = 7)\n >>> [181,292,707,818,929]\n Explanation: Note that 070 is not a valid number, because it has leading zeroes.\n \n Example 2:\n \n >>> numsSameConsecDiff(n = 2, k = 1)\n >>> [10,12,21,23,32,34,43,45,54,56,65,67,76,78,87,89,98]\n \"\"\"\n"}
{"task_id": "binary-tree-cameras", "prompt": "# class TreeNode:\n# def __init__(val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def minCameraCover(root: Optional[TreeNode]) -> int:\n \"\"\"\n You are given the root of a binary tree. We install cameras on the tree nodes where each camera at a node can monitor its parent, itself, and its immediate children.\n Return the minimum number of cameras needed to monitor all nodes of the tree.\n \n Example 1:\n \n \n >>> __init__(root = [0,0,null,0,0])\n >>> 1\n Explanation: One camera is enough to monitor all nodes if placed as shown.\n \n Example 2:\n \n \n >>> __init__(root = [0,0,null,0,null,0,null,null,0])\n >>> 2\n Explanation: At least two cameras are needed to monitor all nodes of the tree. The above image shows one of the valid configurations of camera placement.\n \"\"\"\n"}
{"task_id": "pancake-sorting", "prompt": "def pancakeSort(arr: List[int]) -> List[int]:\n \"\"\"\n Given an array of integers arr, sort the array by performing a series of pancake flips.\n In one pancake flip we do the following steps:\n \n Choose an integer k where 1 <= k <= arr.length.\n Reverse the sub-array arr[0...k-1] (0-indexed).\n \n For example, if arr = [3,2,1,4] and we performed a pancake flip choosing k = 3, we reverse the sub-array [3,2,1], so arr = [1,2,3,4] after the pancake flip at k = 3.\n Return an array of the k-values corresponding to a sequence of pancake flips that sort arr. Any valid answer that sorts the array within 10 * arr.length flips will be judged as correct.\n \n Example 1:\n \n >>> pancakeSort(arr = [3,2,4,1])\n >>> [4,2,4,3]\n Explanation:\n We perform 4 pancake flips, with k values 4, 2, 4, and 3.\n Starting state: arr = [3, 2, 4, 1]\n After 1st flip (k = 4): arr = [1, 4, 2, 3]\n After 2nd flip (k = 2): arr = [4, 1, 2, 3]\n After 3rd flip (k = 4): arr = [3, 2, 1, 4]\n After 4th flip (k = 3): arr = [1, 2, 3, 4], which is sorted.\n \n Example 2:\n \n >>> pancakeSort(arr = [1,2,3])\n >>> []\n Explanation: The input is already sorted, so there is no need to flip anything.\n Note that other answers, such as [3, 3], would also be accepted.\n \"\"\"\n"}
{"task_id": "powerful-integers", "prompt": "def powerfulIntegers(x: int, y: int, bound: int) -> List[int]:\n \"\"\"\n Given three integers x, y, and bound, return a list of all the powerful integers that have a value less than or equal to bound.\n An integer is powerful if it can be represented as xi + yj for some integers i >= 0 and j >= 0.\n You may return the answer in any order. In your answer, each value should occur at most once.\n \n Example 1:\n \n >>> powerfulIntegers(x = 2, y = 3, bound = 10)\n >>> [2,3,4,5,7,9,10]\n Explanation:\n 2 = 20 + 30\n 3 = 21 + 30\n 4 = 20 + 31\n 5 = 21 + 31\n 7 = 22 + 31\n 9 = 23 + 30\n 10 = 20 + 32\n \n Example 2:\n \n >>> powerfulIntegers(x = 3, y = 5, bound = 15)\n >>> [2,4,6,8,10,14]\n \"\"\"\n"}
{"task_id": "flip-binary-tree-to-match-preorder-traversal", "prompt": "# class TreeNode:\n# def __init__(val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def flipMatchVoyage(root: Optional[TreeNode], voyage: List[int]) -> List[int]:\n \"\"\"\n You are given the root of a binary tree with n nodes, where each node is uniquely assigned a value from 1 to n. You are also given a sequence of n values voyage, which is the desired pre-order traversal of the binary tree.\n Any node in the binary tree can be flipped by swapping its left and right subtrees. For example, flipping node 1 will have the following effect:\n \n Flip the smallest number of nodes so that the pre-order traversal of the tree matches voyage.\n Return a list of the values of all flipped nodes. You may return the answer in any order. If it is impossible to flip the nodes in the tree to make the pre-order traversal match voyage, return the list [-1].\n \n Example 1:\n \n \n >>> __init__(root = [1,2], voyage = [2,1])\n >>> [-1]\n Explanation: It is impossible to flip the nodes such that the pre-order traversal matches voyage.\n \n Example 2:\n \n \n >>> __init__(root = [1,2,3], voyage = [1,3,2])\n >>> [1]\n Explanation: Flipping node 1 swaps nodes 2 and 3, so the pre-order traversal matches voyage.\n Example 3:\n \n \n >>> __init__(root = [1,2,3], voyage = [1,2,3])\n >>> []\n Explanation: The tree's pre-order traversal already matches voyage, so no nodes need to be flipped.\n \"\"\"\n"}
{"task_id": "equal-rational-numbers", "prompt": "def isRationalEqual(s: str, t: str) -> bool:\n \"\"\"\n Given two strings s and t, each of which represents a non-negative rational number, return true if and only if they represent the same number. The strings may use parentheses to denote the repeating part of the rational number.\n A rational number can be represented using up to three parts: , , and a . The number will be represented in one of the following three ways:\n \n \n \n For example, 12, 0, and 123.\n \n \n <.>\n \n For example, 0.5, 1., 2.12, and 123.0001.\n \n \n <.><(><)>\n \n For example, 0.1(6), 1.(9), 123.00(1212).\n \n \n \n The repeating portion of a decimal expansion is conventionally denoted within a pair of round brackets. For example:\n \n 1/6 = 0.16666666... = 0.1(6) = 0.1666(6) = 0.166(66).\n \n \n Example 1:\n \n >>> isRationalEqual(s = \"0.(52)\", t = \"0.5(25)\")\n >>> true\n Explanation: Because \"0.(52)\" represents 0.52525252..., and \"0.5(25)\" represents 0.52525252525..... , the strings represent the same number.\n \n Example 2:\n \n >>> isRationalEqual(s = \"0.1666(6)\", t = \"0.166(66)\")\n >>> true\n \n Example 3:\n \n >>> isRationalEqual(s = \"0.9(9)\", t = \"1.\")\n >>> true\n Explanation: \"0.9(9)\" represents 0.999999999... repeated forever, which equals 1. [See this link for an explanation.]\n \"1.\" represents the number 1, which is formed correctly: (IntegerPart) = \"1\" and (NonRepeatingPart) = \"\".\n \"\"\"\n"}
{"task_id": "k-closest-points-to-origin", "prompt": "def kClosest(points: List[List[int]], k: int) -> List[List[int]]:\n \"\"\"\n Given an array of points where points[i] = [xi, yi] represents a point on the X-Y plane and an integer k, return the k closest points to the origin (0, 0).\n The distance between two points on the X-Y plane is the Euclidean distance (i.e., \u221a(x1 - x2)2 + (y1 - y2)2).\n You may return the answer in any order. The answer is guaranteed to be unique (except for the order that it is in).\n \n Example 1:\n \n \n >>> kClosest(points = [[1,3],[-2,2]], k = 1)\n >>> [[-2,2]]\n Explanation:\n The distance between (1, 3) and the origin is sqrt(10).\n The distance between (-2, 2) and the origin is sqrt(8).\n Since sqrt(8) < sqrt(10), (-2, 2) is closer to the origin.\n We only want the closest k = 1 points from the origin, so the answer is just [[-2,2]].\n \n Example 2:\n \n >>> kClosest(points = [[3,3],[5,-1],[-2,4]], k = 2)\n >>> [[3,3],[-2,4]]\n Explanation: The answer [[-2,4],[3,3]] would also be accepted.\n \"\"\"\n"}
{"task_id": "subarray-sums-divisible-by-k", "prompt": "def subarraysDivByK(nums: List[int], k: int) -> int:\n \"\"\"\n Given an integer array nums and an integer k, return the number of non-empty subarrays that have a sum divisible by k.\n A subarray is a contiguous part of an array.\n \n Example 1:\n \n >>> subarraysDivByK(nums = [4,5,0,-2,-3,1], k = 5)\n >>> 7\n Explanation: There are 7 subarrays with a sum divisible by k = 5:\n [4, 5, 0, -2, -3, 1], [5], [5, 0], [5, 0, -2, -3], [0], [0, -2, -3], [-2, -3]\n \n Example 2:\n \n >>> subarraysDivByK(nums = [5], k = 9)\n >>> 0\n \"\"\"\n"}
{"task_id": "odd-even-jump", "prompt": "def oddEvenJumps(arr: List[int]) -> int:\n \"\"\"\n You are given an integer array arr. From some starting index, you can make a series of jumps. The (1st, 3rd, 5th, ...) jumps in the series are called odd-numbered jumps, and the (2nd, 4th, 6th, ...) jumps in the series are called even-numbered jumps. Note that the jumps are numbered, not the indices.\n You may jump forward from index i to index j (with i < j) in the following way:\n \n During odd-numbered jumps (i.e., jumps 1, 3, 5, ...), you jump to the index j such that arr[i] <= arr[j] and arr[j] is the smallest possible value. If there are multiple such indices j, you can only jump to the smallest such index j.\n During even-numbered jumps (i.e., jumps 2, 4, 6, ...), you jump to the index j such that arr[i] >= arr[j] and arr[j] is the largest possible value. If there are multiple such indices j, you can only jump to the smallest such index j.\n It may be the case that for some index i, there are no legal jumps.\n \n A starting index is good if, starting from that index, you can reach the end of the array (index arr.length - 1) by jumping some number of times (possibly 0 or more than once).\n Return the number of good starting indices.\n \n Example 1:\n \n >>> oddEvenJumps(arr = [10,13,12,14,15])\n >>> 2\n Explanation:\n From starting index i = 0, we can make our 1st jump to i = 2 (since arr[2] is the smallest among arr[1], arr[2], arr[3], arr[4] that is greater or equal to arr[0]), then we cannot jump any more.\n From starting index i = 1 and i = 2, we can make our 1st jump to i = 3, then we cannot jump any more.\n From starting index i = 3, we can make our 1st jump to i = 4, so we have reached the end.\n From starting index i = 4, we have reached the end already.\n In total, there are 2 different starting indices i = 3 and i = 4, where we can reach the end with some number of\n jumps.\n \n Example 2:\n \n >>> oddEvenJumps(arr = [2,3,1,1,4])\n >>> 3\n Explanation:\n From starting index i = 0, we make jumps to i = 1, i = 2, i = 3:\n During our 1st jump (odd-numbered), we first jump to i = 1 because arr[1] is the smallest value in [arr[1], arr[2], arr[3], arr[4]] that is greater than or equal to arr[0].\n During our 2nd jump (even-numbered), we jump from i = 1 to i = 2 because arr[2] is the largest value in [arr[2], arr[3], arr[4]] that is less than or equal to arr[1]. arr[3] is also the largest value, but 2 is a smaller index, so we can only jump to i = 2 and not i = 3\n During our 3rd jump (odd-numbered), we jump from i = 2 to i = 3 because arr[3] is the smallest value in [arr[3], arr[4]] that is greater than or equal to arr[2].\n We can't jump from i = 3 to i = 4, so the starting index i = 0 is not good.\n In a similar manner, we can deduce that:\n From starting index i = 1, we jump to i = 4, so we reach the end.\n From starting index i = 2, we jump to i = 3, and then we can't jump anymore.\n From starting index i = 3, we jump to i = 4, so we reach the end.\n From starting index i = 4, we are already at the end.\n In total, there are 3 different starting indices i = 1, i = 3, and i = 4, where we can reach the end with some\n number of jumps.\n \n Example 3:\n \n >>> oddEvenJumps(arr = [5,1,3,4,2])\n >>> 3\n Explanation: We can reach the end from starting indices 1, 2, and 4.\n \"\"\"\n"}
{"task_id": "largest-perimeter-triangle", "prompt": "def largestPerimeter(nums: List[int]) -> int:\n \"\"\"\n Given an integer array nums, return the largest perimeter of a triangle with a non-zero area, formed from three of these lengths. If it is impossible to form any triangle of a non-zero area, return 0.\n \n Example 1:\n \n >>> largestPerimeter(nums = [2,1,2])\n >>> 5\n Explanation: You can form a triangle with three side lengths: 1, 2, and 2.\n \n Example 2:\n \n >>> largestPerimeter(nums = [1,2,1,10])\n >>> 0\n Explanation:\n You cannot use the side lengths 1, 1, and 2 to form a triangle.\n You cannot use the side lengths 1, 1, and 10 to form a triangle.\n You cannot use the side lengths 1, 2, and 10 to form a triangle.\n As we cannot use any three side lengths to form a triangle of non-zero area, we return 0.\n \"\"\"\n"}
{"task_id": "squares-of-a-sorted-array", "prompt": "def sortedSquares(nums: List[int]) -> List[int]:\n \"\"\"\n Given an integer array nums sorted in non-decreasing order, return an array of the squares of each number sorted in non-decreasing order.\n \n Example 1:\n \n >>> sortedSquares(nums = [-4,-1,0,3,10])\n >>> [0,1,9,16,100]\n Explanation: After squaring, the array becomes [16,1,0,9,100].\n After sorting, it becomes [0,1,9,16,100].\n \n Example 2:\n \n >>> sortedSquares(nums = [-7,-3,2,3,11])\n >>> [4,9,9,49,121]\n \"\"\"\n"}
{"task_id": "longest-turbulent-subarray", "prompt": "def maxTurbulenceSize(arr: List[int]) -> int:\n \"\"\"\n Given an integer array arr, return the length of a maximum size turbulent subarray of arr.\n A subarray is turbulent if the comparison sign flips between each adjacent pair of elements in the subarray.\n More formally, a subarray [arr[i], arr[i + 1], ..., arr[j]] of arr is said to be turbulent if and only if:\n \n For i <= k < j:\n \n \n arr[k] > arr[k + 1] when k is odd, and\n arr[k] < arr[k + 1] when k is even.\n \n \n Or, for i <= k < j:\n \n arr[k] > arr[k + 1] when k is even, and\n arr[k] < arr[k + 1] when k is odd.\n \n \n \n \n Example 1:\n \n >>> maxTurbulenceSize(arr = [9,4,2,10,7,8,8,1,9])\n >>> 5\n Explanation: arr[1] > arr[2] < arr[3] > arr[4] < arr[5]\n \n Example 2:\n \n >>> maxTurbulenceSize(arr = [4,8,12,16])\n >>> 2\n \n Example 3:\n \n >>> maxTurbulenceSize(arr = [100])\n >>> 1\n \"\"\"\n"}
{"task_id": "distribute-coins-in-binary-tree", "prompt": "# class TreeNode:\n# def __init__(val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def distributeCoins(root: Optional[TreeNode]) -> int:\n \"\"\"\n You are given the root of a binary tree with n nodes where each node in the tree has node.val coins. There are n coins in total throughout the whole tree.\n In one move, we may choose two adjacent nodes and move one coin from one node to another. A move may be from parent to child, or from child to parent.\n Return the minimum number of moves required to make every node have exactly one coin.\n \n Example 1:\n \n \n >>> __init__(root = [3,0,0])\n >>> 2\n Explanation: From the root of the tree, we move one coin to its left child, and one coin to its right child.\n \n Example 2:\n \n \n >>> __init__(root = [0,3,0])\n >>> 3\n Explanation: From the left child of the root, we move two coins to the root [taking two moves]. Then, we move one coin from the root of the tree to the right child.\n \"\"\"\n"}
{"task_id": "unique-paths-iii", "prompt": "def uniquePathsIII(grid: List[List[int]]) -> int:\n \"\"\"\n You are given an m x n integer array grid where grid[i][j] could be:\n \n 1 representing the starting square. There is exactly one starting square.\n 2 representing the ending square. There is exactly one ending square.\n 0 representing empty squares we can walk over.\n -1 representing obstacles that we cannot walk over.\n \n Return the number of 4-directional walks from the starting square to the ending square, that walk over every non-obstacle square exactly once.\n \n Example 1:\n \n \n >>> uniquePathsIII(grid = [[1,0,0,0],[0,0,0,0],[0,0,2,-1]])\n >>> 2\n Explanation: We have the following two paths:\n 1. (0,0),(0,1),(0,2),(0,3),(1,3),(1,2),(1,1),(1,0),(2,0),(2,1),(2,2)\n 2. (0,0),(1,0),(2,0),(2,1),(1,1),(0,1),(0,2),(0,3),(1,3),(1,2),(2,2)\n \n Example 2:\n \n \n >>> uniquePathsIII(grid = [[1,0,0,0],[0,0,0,0],[0,0,0,2]])\n >>> 4\n Explanation: We have the following four paths:\n 1. (0,0),(0,1),(0,2),(0,3),(1,3),(1,2),(1,1),(1,0),(2,0),(2,1),(2,2),(2,3)\n 2. (0,0),(0,1),(1,1),(1,0),(2,0),(2,1),(2,2),(1,2),(0,2),(0,3),(1,3),(2,3)\n 3. (0,0),(1,0),(2,0),(2,1),(2,2),(1,2),(1,1),(0,1),(0,2),(0,3),(1,3),(2,3)\n 4. (0,0),(1,0),(2,0),(2,1),(1,1),(0,1),(0,2),(0,3),(1,3),(1,2),(2,2),(2,3)\n \n Example 3:\n \n \n >>> uniquePathsIII(grid = [[0,1],[2,0]])\n >>> 0\n Explanation: There is no path that walks over every empty square exactly once.\n Note that the starting and ending square can be anywhere in the grid.\n \"\"\"\n"}
{"task_id": "triples-with-bitwise-and-equal-to-zero", "prompt": "def countTriplets(nums: List[int]) -> int:\n \"\"\"\n Given an integer array nums, return the number of AND triples.\n An AND triple is a triple of indices (i, j, k) such that:\n \n 0 <= i < nums.length\n 0 <= j < nums.length\n 0 <= k < nums.length\n nums[i] & nums[j] & nums[k] == 0, where & represents the bitwise-AND operator.\n \n \n Example 1:\n \n >>> countTriplets(nums = [2,1,3])\n >>> 12\n Explanation: We could choose the following i, j, k triples:\n (i=0, j=0, k=1) : 2 & 2 & 1\n (i=0, j=1, k=0) : 2 & 1 & 2\n (i=0, j=1, k=1) : 2 & 1 & 1\n (i=0, j=1, k=2) : 2 & 1 & 3\n (i=0, j=2, k=1) : 2 & 3 & 1\n (i=1, j=0, k=0) : 1 & 2 & 2\n (i=1, j=0, k=1) : 1 & 2 & 1\n (i=1, j=0, k=2) : 1 & 2 & 3\n (i=1, j=1, k=0) : 1 & 1 & 2\n (i=1, j=2, k=0) : 1 & 3 & 2\n (i=2, j=0, k=1) : 3 & 2 & 1\n (i=2, j=1, k=0) : 3 & 1 & 2\n \n Example 2:\n \n >>> countTriplets(nums = [0,0,0])\n >>> 27\n \"\"\"\n"}
{"task_id": "minimum-cost-for-tickets", "prompt": "def mincostTickets(days: List[int], costs: List[int]) -> int:\n \"\"\"\n You have planned some train traveling one year in advance. The days of the year in which you will travel are given as an integer array days. Each day is an integer from 1 to 365.\n Train tickets are sold in three different ways:\n \n a 1-day pass is sold for costs[0] dollars,\n a 7-day pass is sold for costs[1] dollars, and\n a 30-day pass is sold for costs[2] dollars.\n \n The passes allow that many days of consecutive travel.\n \n For example, if we get a 7-day pass on day 2, then we can travel for 7 days: 2, 3, 4, 5, 6, 7, and 8.\n \n Return the minimum number of dollars you need to travel every day in the given list of days.\n \n Example 1:\n \n >>> mincostTickets(days = [1,4,6,7,8,20], costs = [2,7,15])\n >>> 11\n Explanation: For example, here is one way to buy passes that lets you travel your travel plan:\n On day 1, you bought a 1-day pass for costs[0] = $2, which covered day 1.\n On day 3, you bought a 7-day pass for costs[1] = $7, which covered days 3, 4, ..., 9.\n On day 20, you bought a 1-day pass for costs[0] = $2, which covered day 20.\n In total, you spent $11 and covered all the days of your travel.\n \n Example 2:\n \n >>> mincostTickets(days = [1,2,3,4,5,6,7,8,9,10,30,31], costs = [2,7,15])\n >>> 17\n Explanation: For example, here is one way to buy passes that lets you travel your travel plan:\n On day 1, you bought a 30-day pass for costs[2] = $15 which covered days 1, 2, ..., 30.\n On day 31, you bought a 1-day pass for costs[0] = $2 which covered day 31.\n In total, you spent $17 and covered all the days of your travel.\n \"\"\"\n"}
{"task_id": "string-without-aaa-or-bbb", "prompt": "def strWithout3a3b(a: int, b: int) -> str:\n \"\"\"\n Given two integers a and b, return any string s such that:\n \n s has length a + b and contains exactly a 'a' letters, and exactly b 'b' letters,\n The substring 'aaa' does not occur in s, and\n The substring 'bbb' does not occur in s.\n \n \n Example 1:\n \n >>> strWithout3a3b(a = 1, b = 2)\n >>> \"abb\"\n Explanation: \"abb\", \"bab\" and \"bba\" are all correct answers.\n \n Example 2:\n \n >>> strWithout3a3b(a = 4, b = 1)\n >>> \"aabaa\"\n \"\"\"\n"}
{"task_id": "sum-of-even-numbers-after-queries", "prompt": "def sumEvenAfterQueries(nums: List[int], queries: List[List[int]]) -> List[int]:\n \"\"\"\n You are given an integer array nums and an array queries where queries[i] = [vali, indexi].\n For each query i, first, apply nums[indexi] = nums[indexi] + vali, then print the sum of the even values of nums.\n Return an integer array answer where answer[i] is the answer to the ith query.\n \n Example 1:\n \n >>> sumEvenAfterQueries(nums = [1,2,3,4], queries = [[1,0],[-3,1],[-4,0],[2,3]])\n >>> [8,6,2,4]\n Explanation: At the beginning, the array is [1,2,3,4].\n After adding 1 to nums[0], the array is [2,2,3,4], and the sum of even values is 2 + 2 + 4 = 8.\n After adding -3 to nums[1], the array is [2,-1,3,4], and the sum of even values is 2 + 4 = 6.\n After adding -4 to nums[0], the array is [-2,-1,3,4], and the sum of even values is -2 + 4 = 2.\n After adding 2 to nums[3], the array is [-2,-1,3,6], and the sum of even values is -2 + 6 = 4.\n \n Example 2:\n \n >>> sumEvenAfterQueries(nums = [1], queries = [[4,0]])\n >>> [0]\n \"\"\"\n"}
{"task_id": "interval-list-intersections", "prompt": "def intervalIntersection(firstList: List[List[int]], secondList: List[List[int]]) -> List[List[int]]:\n \"\"\"\n You are given two lists of closed intervals, firstList and secondList, where firstList[i] = [starti, endi] and secondList[j] = [startj, endj]. Each list of intervals is pairwise disjoint and in sorted order.\n Return the intersection of these two interval lists.\n A closed interval [a, b] (with a <= b) denotes the set of real numbers x with a <= x <= b.\n The intersection of two closed intervals is a set of real numbers that are either empty or represented as a closed interval. For example, the intersection of [1, 3] and [2, 4] is [2, 3].\n \n Example 1:\n \n \n >>> intervalIntersection(firstList = [[0,2],[5,10],[13,23],[24,25]], secondList = [[1,5],[8,12],[15,24],[25,26]])\n >>> [[1,2],[5,5],[8,10],[15,23],[24,24],[25,25]]\n \n Example 2:\n \n >>> intervalIntersection(firstList = [[1,3],[5,9]], secondList = [])\n >>> []\n \"\"\"\n"}
{"task_id": "vertical-order-traversal-of-a-binary-tree", "prompt": "# class TreeNode:\n# def __init__(val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def verticalTraversal(root: Optional[TreeNode]) -> List[List[int]]:\n \"\"\"\n Given the root of a binary tree, calculate the vertical order traversal of the binary tree.\n For each node at position (row, col), its left and right children will be at positions (row + 1, col - 1) and (row + 1, col + 1) respectively. The root of the tree is at (0, 0).\n The vertical order traversal of a binary tree is a list of top-to-bottom orderings for each column index starting from the leftmost column and ending on the rightmost column. There may be multiple nodes in the same row and same column. In such a case, sort these nodes by their values.\n Return the vertical order traversal of the binary tree.\n \n Example 1:\n \n \n >>> __init__(root = [3,9,20,null,null,15,7])\n >>> [[9],[3,15],[20],[7]]\n Explanation:\n Column -1: Only node 9 is in this column.\n Column 0: Nodes 3 and 15 are in this column in that order from top to bottom.\n Column 1: Only node 20 is in this column.\n Column 2: Only node 7 is in this column.\n Example 2:\n \n \n >>> __init__(root = [1,2,3,4,5,6,7])\n >>> [[4],[2],[1,5,6],[3],[7]]\n Explanation:\n Column -2: Only node 4 is in this column.\n Column -1: Only node 2 is in this column.\n Column 0: Nodes 1, 5, and 6 are in this column.\n 1 is at the top, so it comes first.\n 5 and 6 are at the same position (2, 0), so we order them by their value, 5 before 6.\n Column 1: Only node 3 is in this column.\n Column 2: Only node 7 is in this column.\n \n Example 3:\n \n \n >>> __init__(root = [1,2,3,4,6,5,7])\n >>> [[4],[2],[1,5,6],[3],[7]]\n Explanation:\n This case is the exact same as example 2, but with nodes 5 and 6 swapped.\n Note that the solution remains the same since 5 and 6 are in the same location and should be ordered by their values.\n \"\"\"\n"}
{"task_id": "smallest-string-starting-from-leaf", "prompt": "# class TreeNode:\n# def __init__(val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def smallestFromLeaf(root: Optional[TreeNode]) -> str:\n \"\"\"\n You are given the root of a binary tree where each node has a value in the range [0, 25] representing the letters 'a' to 'z'.\n Return the lexicographically smallest string that starts at a leaf of this tree and ends at the root.\n As a reminder, any shorter prefix of a string is lexicographically smaller.\n \n For example, \"ab\" is lexicographically smaller than \"aba\".\n \n A leaf of a node is a node that has no children.\n \n Example 1:\n \n \n >>> __init__(root = [0,1,2,3,4,3,4])\n >>> \"dba\"\n \n Example 2:\n \n \n >>> __init__(root = [25,1,3,1,3,0,2])\n >>> \"adz\"\n \n Example 3:\n \n \n >>> __init__(root = [2,2,1,null,1,0,null,0])\n >>> \"abc\"\n \"\"\"\n"}
{"task_id": "add-to-array-form-of-integer", "prompt": "def addToArrayForm(num: List[int], k: int) -> List[int]:\n \"\"\"\n The array-form of an integer num is an array representing its digits in left to right order.\n \n For example, for num = 1321, the array form is [1,3,2,1].\n \n Given num, the array-form of an integer, and an integer k, return the array-form of the integer num + k.\n \n Example 1:\n \n >>> addToArrayForm(num = [1,2,0,0], k = 34)\n >>> [1,2,3,4]\n Explanation: 1200 + 34 = 1234\n \n Example 2:\n \n >>> addToArrayForm(num = [2,7,4], k = 181)\n >>> [4,5,5]\n Explanation: 274 + 181 = 455\n \n Example 3:\n \n >>> addToArrayForm(num = [2,1,5], k = 806)\n >>> [1,0,2,1]\n Explanation: 215 + 806 = 1021\n \"\"\"\n"}
{"task_id": "satisfiability-of-equality-equations", "prompt": "def equationsPossible(equations: List[str]) -> bool:\n \"\"\"\n You are given an array of strings equations that represent relationships between variables where each string equations[i] is of length 4 and takes one of two different forms: \"xi==yi\" or \"xi!=yi\".Here, xi and yi are lowercase letters (not necessarily different) that represent one-letter variable names.\n Return true if it is possible to assign integers to variable names so as to satisfy all the given equations, or false otherwise.\n \n Example 1:\n \n >>> equationsPossible(equations = [\"a==b\",\"b!=a\"])\n >>> false\n Explanation: If we assign say, a = 1 and b = 1, then the first equation is satisfied, but not the second.\n There is no way to assign the variables to satisfy both equations.\n \n Example 2:\n \n >>> equationsPossible(equations = [\"b==a\",\"a==b\"])\n >>> true\n Explanation: We could assign a = 1 and b = 1 to satisfy both equations.\n \"\"\"\n"}
{"task_id": "broken-calculator", "prompt": "def brokenCalc(startValue: int, target: int) -> int:\n \"\"\"\n There is a broken calculator that has the integer startValue on its display initially. In one operation, you can:\n \n multiply the number on display by 2, or\n subtract 1 from the number on display.\n \n Given two integers startValue and target, return the minimum number of operations needed to display target on the calculator.\n \n Example 1:\n \n >>> brokenCalc(startValue = 2, target = 3)\n >>> 2\n Explanation: Use double operation and then decrement operation {2 -> 4 -> 3}.\n \n Example 2:\n \n >>> brokenCalc(startValue = 5, target = 8)\n >>> 2\n Explanation: Use decrement and then double {5 -> 4 -> 8}.\n \n Example 3:\n \n >>> brokenCalc(startValue = 3, target = 10)\n >>> 3\n Explanation: Use double, decrement and double {3 -> 6 -> 5 -> 10}.\n \"\"\"\n"}
{"task_id": "subarrays-with-k-different-integers", "prompt": "def subarraysWithKDistinct(nums: List[int], k: int) -> int:\n \"\"\"\n Given an integer array nums and an integer k, return the number of good subarrays of nums.\n A good array is an array where the number of different integers in that array is exactly k.\n \n For example, [1,2,3,1,2] has 3 different integers: 1, 2, and 3.\n \n A subarray is a contiguous part of an array.\n \n Example 1:\n \n >>> subarraysWithKDistinct(nums = [1,2,1,2,3], k = 2)\n >>> 7\n Explanation: Subarrays formed with exactly 2 different integers: [1,2], [2,1], [1,2], [2,3], [1,2,1], [2,1,2], [1,2,1,2]\n \n Example 2:\n \n >>> subarraysWithKDistinct(nums = [1,2,1,3,4], k = 3)\n >>> 3\n Explanation: Subarrays formed with exactly 3 different integers: [1,2,1,3], [2,1,3], [1,3,4].\n \"\"\"\n"}
{"task_id": "cousins-in-binary-tree", "prompt": "# class TreeNode:\n# def __init__(val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def isCousins(root: Optional[TreeNode], x: int, y: int) -> bool:\n \"\"\"\n Given the root of a binary tree with unique values and the values of two different nodes of the tree x and y, return true if the nodes corresponding to the values x and y in the tree are cousins, or false otherwise.\n Two nodes of a binary tree are cousins if they have the same depth with different parents.\n Note that in a binary tree, the root node is at the depth 0, and children of each depth k node are at the depth k + 1.\n \n Example 1:\n \n \n >>> __init__(root = [1,2,3,4], x = 4, y = 3)\n >>> false\n \n Example 2:\n \n \n >>> __init__(root = [1,2,3,null,4,null,5], x = 5, y = 4)\n >>> true\n \n Example 3:\n \n \n >>> __init__(root = [1,2,3,null,4], x = 2, y = 3)\n >>> false\n \"\"\"\n"}
{"task_id": "rotting-oranges", "prompt": "def orangesRotting(grid: List[List[int]]) -> int:\n \"\"\"\n You are given an m x n grid where each cell can have one of three values:\n \n 0 representing an empty cell,\n 1 representing a fresh orange, or\n 2 representing a rotten orange.\n \n Every minute, any fresh orange that is 4-directionally adjacent to a rotten orange becomes rotten.\n Return the minimum number of minutes that must elapse until no cell has a fresh orange. If this is impossible, return -1.\n \n Example 1:\n \n \n >>> orangesRotting(grid = [[2,1,1],[1,1,0],[0,1,1]])\n >>> 4\n \n Example 2:\n \n >>> orangesRotting(grid = [[2,1,1],[0,1,1],[1,0,1]])\n >>> -1\n Explanation: The orange in the bottom left corner (row 2, column 0) is never rotten, because rotting only happens 4-directionally.\n \n Example 3:\n \n >>> orangesRotting(grid = [[0,2]])\n >>> 0\n Explanation: Since there are already no fresh oranges at minute 0, the answer is just 0.\n \"\"\"\n"}
{"task_id": "minimum-number-of-k-consecutive-bit-flips", "prompt": "def minKBitFlips(nums: List[int], k: int) -> int:\n \"\"\"\n You are given a binary array nums and an integer k.\n A k-bit flip is choosing a subarray of length k from nums and simultaneously changing every 0 in the subarray to 1, and every 1 in the subarray to 0.\n Return the minimum number of k-bit flips required so that there is no 0 in the array. If it is not possible, return -1.\n A subarray is a contiguous part of an array.\n \n Example 1:\n \n >>> minKBitFlips(nums = [0,1,0], k = 1)\n >>> 2\n Explanation: Flip nums[0], then flip nums[2].\n \n Example 2:\n \n >>> minKBitFlips(nums = [1,1,0], k = 2)\n >>> -1\n Explanation: No matter how we flip subarrays of size 2, we cannot make the array become [1,1,1].\n \n Example 3:\n \n >>> minKBitFlips(nums = [0,0,0,1,0,1,1,0], k = 3)\n >>> 3\n Explanation:\n Flip nums[0],nums[1],nums[2]: nums becomes [1,1,1,1,0,1,1,0]\n Flip nums[4],nums[5],nums[6]: nums becomes [1,1,1,1,1,0,0,0]\n Flip nums[5],nums[6],nums[7]: nums becomes [1,1,1,1,1,1,1,1]\n \"\"\"\n"}
{"task_id": "number-of-squareful-arrays", "prompt": "def numSquarefulPerms(nums: List[int]) -> int:\n \"\"\"\n An array is squareful if the sum of every pair of adjacent elements is a perfect square.\n Given an integer array nums, return the number of permutations of nums that are squareful.\n Two permutations perm1 and perm2 are different if there is some index i such that perm1[i] != perm2[i].\n \n Example 1:\n \n >>> numSquarefulPerms(nums = [1,17,8])\n >>> 2\n Explanation: [1,8,17] and [17,8,1] are the valid permutations.\n \n Example 2:\n \n >>> numSquarefulPerms(nums = [2,2,2])\n >>> 1\n \"\"\"\n"}
{"task_id": "find-the-town-judge", "prompt": "def findJudge(n: int, trust: List[List[int]]) -> int:\n \"\"\"\n In a town, there are n people labeled from 1 to n. There is a rumor that one of these people is secretly the town judge.\n If the town judge exists, then:\n \n The town judge trusts nobody.\n Everybody (except for the town judge) trusts the town judge.\n There is exactly one person that satisfies properties 1 and 2.\n \n You are given an array trust where trust[i] = [ai, bi] representing that the person labeled ai trusts the person labeled bi. If a trust relationship does not exist in trust array, then such a trust relationship does not exist.\n Return the label of the town judge if the town judge exists and can be identified, or return -1 otherwise.\n \n Example 1:\n \n >>> findJudge(n = 2, trust = [[1,2]])\n >>> 2\n \n Example 2:\n \n >>> findJudge(n = 3, trust = [[1,3],[2,3]])\n >>> 3\n \n Example 3:\n \n >>> findJudge(n = 3, trust = [[1,3],[2,3],[3,1]])\n >>> -1\n \"\"\"\n"}
{"task_id": "maximum-binary-tree-ii", "prompt": "# class TreeNode:\n# def __init__(val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def insertIntoMaxTree(root: Optional[TreeNode], val: int) -> Optional[TreeNode]:\n \"\"\"\n A maximum tree is a tree where every node has a value greater than any other value in its subtree.\n You are given the root of a maximum binary tree and an integer val.\n Just as in the previous problem, the given tree was constructed from a list a (root = Construct(a)) recursively with the following Construct(a) routine:\n \n If a is empty, return null.\n Otherwise, let a[i] be the largest element of a. Create a root node with the value a[i].\n The left child of root will be Construct([a[0], a[1], ..., a[i - 1]]).\n The right child of root will be Construct([a[i + 1], a[i + 2], ..., a[a.length - 1]]).\n Return root.\n \n Note that we were not given a directly, only a root node root = Construct(a).\n Suppose b is a copy of a with the value val appended to it. It is guaranteed that b has unique values.\n Return Construct(b).\n \n Example 1:\n \n \n >>> __init__(root = [4,1,3,null,null,2], val = 5)\n >>> [5,4,null,1,3,null,null,2]\n Explanation: a = [1,4,2,3], b = [1,4,2,3,5]\n \n Example 2:\n \n \n >>> __init__(root = [5,2,4,null,1], val = 3)\n >>> [5,2,4,null,1,null,3]\n Explanation: a = [2,1,5,4], b = [2,1,5,4,3]\n \n Example 3:\n \n \n >>> __init__(root = [5,2,3,null,1], val = 4)\n >>> [5,2,4,null,1,3]\n Explanation: a = [2,1,5,3], b = [2,1,5,3,4]\n \"\"\"\n"}
{"task_id": "available-captures-for-rook", "prompt": "def numRookCaptures(board: List[List[str]]) -> int:\n \"\"\"\n You are given an 8 x 8 matrix representing a chessboard. There is exactly one white rook represented by 'R', some number of white bishops 'B', and some number of black pawns 'p'. Empty squares are represented by '.'.\n A rook can move any number of squares horizontally or vertically (up, down, left, right) until it reaches another piece or the edge of the board. A rook is attacking a pawn if it can move to the pawn's square in one move.\n Note: A rook cannot move through other pieces, such as bishops or pawns. This means a rook cannot attack a pawn if there is another piece blocking the path.\n Return the number of pawns the white rook is attacking.\n \n Example 1:\n \n \n >>> numRookCaptures(board = [[\".\",\".\",\".\",\".\",\".\",\".\",\".\",\".\"],[\".\",\".\",\".\",\"p\",\".\",\".\",\".\",\".\"],[\".\",\".\",\".\",\"R\",\".\",\".\",\".\",\"p\"],[\".\",\".\",\".\",\".\",\".\",\".\",\".\",\".\"],[\".\",\".\",\".\",\".\",\".\",\".\",\".\",\".\"],[\".\",\".\",\".\",\"p\",\".\",\".\",\".\",\".\"],[\".\",\".\",\".\",\".\",\".\",\".\",\".\",\".\"],[\".\",\".\",\".\",\".\",\".\",\".\",\".\",\".\"]])\n >>> 3\n Explanation:\n In this example, the rook is attacking all the pawns.\n \n Example 2:\n \n \n >>> numRookCaptures(board = [[\".\",\".\",\".\",\".\",\".\",\".\",\".\"],[\".\",\"p\",\"p\",\"p\",\"p\",\"p\",\".\",\".\"],[\".\",\"p\",\"p\",\"B\",\"p\",\"p\",\".\",\".\"],[\".\",\"p\",\"B\",\"R\",\"B\",\"p\",\".\",\".\"],[\".\",\"p\",\"p\",\"B\",\"p\",\"p\",\".\",\".\"],[\".\",\"p\",\"p\",\"p\",\"p\",\"p\",\".\",\".\"],[\".\",\".\",\".\",\".\",\".\",\".\",\".\",\".\"],[\".\",\".\",\".\",\".\",\".\",\".\",\".\",\".\"]])\n >>> 0\n Explanation:\n The bishops are blocking the rook from attacking any of the pawns.\n \n Example 3:\n \n \n >>> numRookCaptures(board = [[\".\",\".\",\".\",\".\",\".\",\".\",\".\",\".\"],[\".\",\".\",\".\",\"p\",\".\",\".\",\".\",\".\"],[\".\",\".\",\".\",\"p\",\".\",\".\",\".\",\".\"],[\"p\",\"p\",\".\",\"R\",\".\",\"p\",\"B\",\".\"],[\".\",\".\",\".\",\".\",\".\",\".\",\".\",\".\"],[\".\",\".\",\".\",\"B\",\".\",\".\",\".\",\".\"],[\".\",\".\",\".\",\"p\",\".\",\".\",\".\",\".\"],[\".\",\".\",\".\",\".\",\".\",\".\",\".\",\".\"]])\n >>> 3\n Explanation:\n The rook is attacking the pawns at positions b5, d6, and f5.\n \"\"\"\n"}
{"task_id": "minimum-cost-to-merge-stones", "prompt": "def mergeStones(stones: List[int], k: int) -> int:\n \"\"\"\n There are n piles of stones arranged in a row. The ith pile has stones[i] stones.\n A move consists of merging exactly k consecutive piles into one pile, and the cost of this move is equal to the total number of stones in these k piles.\n Return the minimum cost to merge all piles of stones into one pile. If it is impossible, return -1.\n \n Example 1:\n \n >>> mergeStones(stones = [3,2,4,1], k = 2)\n >>> 20\n Explanation: We start with [3, 2, 4, 1].\n We merge [3, 2] for a cost of 5, and we are left with [5, 4, 1].\n We merge [4, 1] for a cost of 5, and we are left with [5, 5].\n We merge [5, 5] for a cost of 10, and we are left with [10].\n The total cost was 20, and this is the minimum possible.\n \n Example 2:\n \n >>> mergeStones(stones = [3,2,4,1], k = 3)\n >>> -1\n Explanation: After any merge operation, there are 2 piles left, and we can't merge anymore. So the task is impossible.\n \n Example 3:\n \n >>> mergeStones(stones = [3,5,1,2,6], k = 3)\n >>> 25\n Explanation: We start with [3, 5, 1, 2, 6].\n We merge [5, 1, 2] for a cost of 8, and we are left with [3, 8, 6].\n We merge [3, 8, 6] for a cost of 17, and we are left with [17].\n The total cost was 25, and this is the minimum possible.\n \"\"\"\n"}
{"task_id": "grid-illumination", "prompt": "def gridIllumination(n: int, lamps: List[List[int]], queries: List[List[int]]) -> List[int]:\n \"\"\"\n There is a 2D grid of size n x n where each cell of this grid has a lamp that is initially turned off.\n You are given a 2D array of lamp positions lamps, where lamps[i] = [rowi, coli] indicates that the lamp at grid[rowi][coli] is turned on. Even if the same lamp is listed more than once, it is turned on.\n When a lamp is turned on, it illuminates its cell and all other cells in the same row, column, or diagonal.\n You are also given another 2D array queries, where queries[j] = [rowj, colj]. For the jth query, determine whether grid[rowj][colj] is illuminated or not. After answering the jth query, turn off the lamp at grid[rowj][colj] and its 8 adjacent lamps if they exist. A lamp is adjacent if its cell shares either a side or corner with grid[rowj][colj].\n Return an array of integers ans, where ans[j] should be 1 if the cell in the jth query was illuminated, or 0 if the lamp was not.\n \n Example 1:\n \n \n >>> gridIllumination(n = 5, lamps = [[0,0],[4,4]], queries = [[1,1],[1,0]])\n >>> [1,0]\n Explanation: We have the initial grid with all lamps turned off. In the above picture we see the grid after turning on the lamp at grid[0][0] then turning on the lamp at grid[4][4].\n The 0th\u00a0query asks if the lamp at grid[1][1] is illuminated or not (the blue square). It is illuminated, so set ans[0] = 1. Then, we turn off all lamps in the red square.\n \n The 1st\u00a0query asks if the lamp at grid[1][0] is illuminated or not (the blue square). It is not illuminated, so set ans[1] = 0. Then, we turn off all lamps in the red rectangle.\n \n \n Example 2:\n \n >>> gridIllumination(n = 5, lamps = [[0,0],[4,4]], queries = [[1,1],[1,1]])\n >>> [1,1]\n \n Example 3:\n \n >>> gridIllumination(n = 5, lamps = [[0,0],[0,4]], queries = [[0,4],[0,1],[1,4]])\n >>> [1,1,0]\n \"\"\"\n"}
{"task_id": "find-common-characters", "prompt": "def commonChars(words: List[str]) -> List[str]:\n \"\"\"\n Given a string array words, return an array of all characters that show up in all strings within the words (including duplicates). You may return the answer in any order.\n \n Example 1:\n >>> commonChars(words = [\"bella\",\"label\",\"roller\"])\n >>> [\"e\",\"l\",\"l\"]\n Example 2:\n >>> commonChars(words = [\"cool\",\"lock\",\"cook\"])\n >>> [\"c\",\"o\"]\n \"\"\"\n"}
{"task_id": "check-if-word-is-valid-after-substitutions", "prompt": "def isValid(s: str) -> bool:\n \"\"\"\n Given a string s, determine if it is valid.\n A string s is valid if, starting with an empty string t = \"\", you can transform t into s after performing the following operation any number of times:\n \n Insert string \"abc\" into any position in t. More formally, t becomes tleft + \"abc\" + tright, where t == tleft + tright. Note that tleft and tright may be empty.\n \n Return true if s is a valid string, otherwise, return false.\n \n Example 1:\n \n >>> isValid(s = \"aabcbc\")\n >>> true\n Explanation:\n \"\" -> \"abc\" -> \"aabcbc\"\n Thus, \"aabcbc\" is valid.\n Example 2:\n \n >>> isValid(s = \"abcabcababcc\")\n >>> true\n Explanation:\n \"\" -> \"abc\" -> \"abcabc\" -> \"abcabcabc\" -> \"abcabcababcc\"\n Thus, \"abcabcababcc\" is valid.\n \n Example 3:\n \n >>> isValid(s = \"abccba\")\n >>> false\n Explanation: It is impossible to get \"abccba\" using the operation.\n \"\"\"\n"}
{"task_id": "max-consecutive-ones-iii", "prompt": "def longestOnes(nums: List[int], k: int) -> int:\n \"\"\"\n Given a binary array nums and an integer k, return the maximum number of consecutive 1's in the array if you can flip at most k 0's.\n \n Example 1:\n \n >>> longestOnes(nums = [1,1,1,0,0,0,1,1,1,1,0], k = 2)\n >>> 6\n Explanation: [1,1,1,0,0,1,1,1,1,1,1]\n Bolded numbers were flipped from 0 to 1. The longest subarray is underlined.\n Example 2:\n \n >>> longestOnes(nums = [0,0,1,1,0,0,1,1,1,0,1,1,0,0,0,1,1,1,1], k = 3)\n >>> 10\n Explanation: [0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,1,1,1,1]\n Bolded numbers were flipped from 0 to 1. The longest subarray is underlined.\n \"\"\"\n"}
{"task_id": "maximize-sum-of-array-after-k-negations", "prompt": "def largestSumAfterKNegations(nums: List[int], k: int) -> int:\n \"\"\"\n Given an integer array nums and an integer k, modify the array in the following way:\n \n choose an index i and replace nums[i] with -nums[i].\n \n You should apply this process exactly k times. You may choose the same index i multiple times.\n Return the largest possible sum of the array after modifying it in this way.\n \n Example 1:\n \n >>> largestSumAfterKNegations(nums = [4,2,3], k = 1)\n >>> 5\n Explanation: Choose index 1 and nums becomes [4,-2,3].\n \n Example 2:\n \n >>> largestSumAfterKNegations(nums = [3,-1,0,2], k = 3)\n >>> 6\n Explanation: Choose indices (1, 2, 2) and nums becomes [3,1,0,2].\n \n Example 3:\n \n >>> largestSumAfterKNegations(nums = [2,-3,-1,5,-4], k = 2)\n >>> 13\n Explanation: Choose indices (1, 4) and nums becomes [2,3,-1,5,4].\n \"\"\"\n"}
{"task_id": "clumsy-factorial", "prompt": "def clumsy(n: int) -> int:\n \"\"\"\n The factorial of a positive integer n is the product of all positive integers less than or equal to n.\n \n For example, factorial(10) = 10 * 9 * 8 * 7 * 6 * 5 * 4 * 3 * 2 * 1.\n \n We make a clumsy factorial using the integers in decreasing order by swapping out the multiply operations for a fixed rotation of operations with multiply '*', divide '/', add '+', and subtract '-' in this order.\n \n For example, clumsy(10) = 10 * 9 / 8 + 7 - 6 * 5 / 4 + 3 - 2 * 1.\n \n However, these operations are still applied using the usual order of operations of arithmetic. We do all multiplication and division steps before any addition or subtraction steps, and multiplication and division steps are processed left to right.\n Additionally, the division that we use is floor division such that 10 * 9 / 8 = 90 / 8 = 11.\n Given an integer n, return the clumsy factorial of n.\n \n Example 1:\n \n >>> clumsy(n = 4)\n >>> 7\n Explanation: 7 = 4 * 3 / 2 + 1\n \n Example 2:\n \n >>> clumsy(n = 10)\n >>> 12\n Explanation: 12 = 10 * 9 / 8 + 7 - 6 * 5 / 4 + 3 - 2 * 1\n \"\"\"\n"}
{"task_id": "minimum-domino-rotations-for-equal-row", "prompt": "def minDominoRotations(tops: List[int], bottoms: List[int]) -> int:\n \"\"\"\n In a row of dominoes, tops[i] and bottoms[i] represent the top and bottom halves of the ith domino. (A domino is a tile with two numbers from 1 to 6 - one on each half of the tile.)\n We may rotate the ith domino, so that tops[i] and bottoms[i] swap values.\n Return the minimum number of rotations so that all the values in tops are the same, or all the values in bottoms are the same.\n If it cannot be done, return -1.\n \n Example 1:\n \n \n >>> minDominoRotations(tops = [2,1,2,4,2,2], bottoms = [5,2,6,2,3,2])\n >>> 2\n Explanation:\n The first figure represents the dominoes as given by tops and bottoms: before we do any rotations.\n If we rotate the second and fourth dominoes, we can make every value in the top row equal to 2, as indicated by the second figure.\n \n Example 2:\n \n >>> minDominoRotations(tops = [3,5,1,2,3], bottoms = [3,6,3,3,4])\n >>> -1\n Explanation:\n In this case, it is not possible to rotate the dominoes to make one row of values equal.\n \"\"\"\n"}
{"task_id": "construct-binary-search-tree-from-preorder-traversal", "prompt": "# class TreeNode:\n# def __init__(val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def bstFromPreorder(preorder: List[int]) -> Optional[TreeNode]:\n \"\"\"\n Given an array of integers preorder, which represents the preorder traversal of a BST (i.e., binary search tree), construct the tree and return its root.\n It is guaranteed that there is always possible to find a binary search tree with the given requirements for the given test cases.\n A binary search tree is a binary tree where for every node, any descendant of Node.left has a value strictly less than Node.val, and any descendant of Node.right has a value strictly greater than Node.val.\n A preorder traversal of a binary tree displays the value of the node first, then traverses Node.left, then traverses Node.right.\n \n Example 1:\n \n \n >>> __init__(preorder = [8,5,1,7,10,12])\n >>> [8,5,10,1,7,null,12]\n \n Example 2:\n \n >>> __init__(preorder = [1,3])\n >>> [1,null,3]\n \"\"\"\n"}
{"task_id": "complement-of-base-10-integer", "prompt": "def bitwiseComplement(n: int) -> int:\n \"\"\"\n The complement of an integer is the integer you get when you flip all the 0's to 1's and all the 1's to 0's in its binary representation.\n \n For example, The integer 5 is \"101\" in binary and its complement is \"010\" which is the integer 2.\n \n Given an integer n, return its complement.\n \n Example 1:\n \n >>> bitwiseComplement(n = 5)\n >>> 2\n Explanation: 5 is \"101\" in binary, with complement \"010\" in binary, which is 2 in base-10.\n \n Example 2:\n \n >>> bitwiseComplement(n = 7)\n >>> 0\n Explanation: 7 is \"111\" in binary, with complement \"000\" in binary, which is 0 in base-10.\n \n Example 3:\n \n >>> bitwiseComplement(n = 10)\n >>> 5\n Explanation: 10 is \"1010\" in binary, with complement \"0101\" in binary, which is 5 in base-10.\n \"\"\"\n"}
{"task_id": "pairs-of-songs-with-total-durations-divisible-by-60", "prompt": "def numPairsDivisibleBy60(time: List[int]) -> int:\n \"\"\"\n You are given a list of songs where the ith song has a duration of time[i] seconds.\n Return the number of pairs of songs for which their total duration in seconds is divisible by 60. Formally, we want the number of indices i, j such that i < j with (time[i] + time[j]) % 60 == 0.\n \n Example 1:\n \n >>> numPairsDivisibleBy60(time = [30,20,150,100,40])\n >>> 3\n Explanation: Three pairs have a total duration divisible by 60:\n (time[0] = 30, time[2] = 150): total duration 180\n (time[1] = 20, time[3] = 100): total duration 120\n (time[1] = 20, time[4] = 40): total duration 60\n \n Example 2:\n \n >>> numPairsDivisibleBy60(time = [60,60,60])\n >>> 3\n Explanation: All three pairs have a total duration of 120, which is divisible by 60.\n \"\"\"\n"}
{"task_id": "capacity-to-ship-packages-within-d-days", "prompt": "def shipWithinDays(weights: List[int], days: int) -> int:\n \"\"\"\n A conveyor belt has packages that must be shipped from one port to another within days days.\n The ith package on the conveyor belt has a weight of weights[i]. Each day, we load the ship with packages on the conveyor belt (in the order given by weights). We may not load more weight than the maximum weight capacity of the ship.\n Return the least weight capacity of the ship that will result in all the packages on the conveyor belt being shipped within days days.\n \n Example 1:\n \n >>> shipWithinDays(weights = [1,2,3,4,5,6,7,8,9,10], days = 5)\n >>> 15\n Explanation: A ship capacity of 15 is the minimum to ship all the packages in 5 days like this:\n 1st day: 1, 2, 3, 4, 5\n 2nd day: 6, 7\n 3rd day: 8\n 4th day: 9\n 5th day: 10\n \n Note that the cargo must be shipped in the order given, so using a ship of capacity 14 and splitting the packages into parts like (2, 3, 4, 5), (1, 6, 7), (8), (9), (10) is not allowed.\n \n Example 2:\n \n >>> shipWithinDays(weights = [3,2,2,4,1,4], days = 3)\n >>> 6\n Explanation: A ship capacity of 6 is the minimum to ship all the packages in 3 days like this:\n 1st day: 3, 2\n 2nd day: 2, 4\n 3rd day: 1, 4\n \n Example 3:\n \n >>> shipWithinDays(weights = [1,2,3,1,1], days = 4)\n >>> 3\n Explanation:\n 1st day: 1\n 2nd day: 2\n 3rd day: 3\n 4th day: 1, 1\n \"\"\"\n"}
{"task_id": "numbers-with-repeated-digits", "prompt": "def numDupDigitsAtMostN(n: int) -> int:\n \"\"\"\n Given an integer n, return the number of positive integers in the range [1, n] that have at least one repeated digit.\n \n Example 1:\n \n >>> numDupDigitsAtMostN(n = 20)\n >>> 1\n Explanation: The only positive number (<= 20) with at least 1 repeated digit is 11.\n \n Example 2:\n \n >>> numDupDigitsAtMostN(n = 100)\n >>> 10\n Explanation: The positive numbers (<= 100) with atleast 1 repeated digit are 11, 22, 33, 44, 55, 66, 77, 88, 99, and 100.\n \n Example 3:\n \n >>> numDupDigitsAtMostN(n = 1000)\n >>> 262\n \"\"\"\n"}
{"task_id": "partition-array-into-three-parts-with-equal-sum", "prompt": "def canThreePartsEqualSum(arr: List[int]) -> bool:\n \"\"\"\n Given an array of integers arr, return true if we can partition the array into three non-empty parts with equal sums.\n Formally, we can partition the array if we can find indexes i + 1 < j with (arr[0] + arr[1] + ... + arr[i] == arr[i + 1] + arr[i + 2] + ... + arr[j - 1] == arr[j] + arr[j + 1] + ... + arr[arr.length - 1])\n \n Example 1:\n \n >>> canThreePartsEqualSum(arr = [0,2,1,-6,6,-7,9,1,2,0,1])\n >>> true\n Explanation: 0 + 2 + 1 = -6 + 6 - 7 + 9 + 1 = 2 + 0 + 1\n \n Example 2:\n \n >>> canThreePartsEqualSum(arr = [0,2,1,-6,6,7,9,-1,2,0,1])\n >>> false\n \n Example 3:\n \n >>> canThreePartsEqualSum(arr = [3,3,6,5,-2,2,5,1,-9,4])\n >>> true\n Explanation: 3 + 3 = 6 = 5 - 2 + 2 + 5 + 1 - 9 + 4\n \"\"\"\n"}
{"task_id": "best-sightseeing-pair", "prompt": "def maxScoreSightseeingPair(values: List[int]) -> int:\n \"\"\"\n You are given an integer array values where values[i] represents the value of the ith sightseeing spot. Two sightseeing spots i and j have a distance j - i between them.\n The score of a pair (i < j) of sightseeing spots is values[i] + values[j] + i - j: the sum of the values of the sightseeing spots, minus the distance between them.\n Return the maximum score of a pair of sightseeing spots.\n \n Example 1:\n \n >>> maxScoreSightseeingPair(values = [8,1,5,2,6])\n >>> 11\n Explanation: i = 0, j = 2, values[i] + values[j] + i - j = 8 + 5 + 0 - 2 = 11\n \n Example 2:\n \n >>> maxScoreSightseeingPair(values = [1,2])\n >>> 2\n \"\"\"\n"}
{"task_id": "smallest-integer-divisible-by-k", "prompt": "def smallestRepunitDivByK(k: int) -> int:\n \"\"\"\n Given a positive integer k, you need to find the length of the smallest positive integer n such that n is divisible by k, and n only contains the digit 1.\n Return the length of n. If there is no such n, return -1.\n Note: n may not fit in a 64-bit signed integer.\n \n Example 1:\n \n >>> smallestRepunitDivByK(k = 1)\n >>> 1\n Explanation: The smallest answer is n = 1, which has length 1.\n \n Example 2:\n \n >>> smallestRepunitDivByK(k = 2)\n >>> -1\n Explanation: There is no such positive integer n divisible by 2.\n \n Example 3:\n \n >>> smallestRepunitDivByK(k = 3)\n >>> 3\n Explanation: The smallest answer is n = 111, which has length 3.\n \"\"\"\n"}
{"task_id": "binary-string-with-substrings-representing-1-to-n", "prompt": "def queryString(s: str, n: int) -> bool:\n \"\"\"\n Given a binary string s and a positive integer n, return true if the binary representation of all the integers in the range [1, n] are substrings of s, or false otherwise.\n A substring is a contiguous sequence of characters within a string.\n \n Example 1:\n >>> queryString(s = \"0110\", n = 3)\n >>> true\n Example 2:\n >>> queryString(s = \"0110\", n = 4)\n >>> false\n \"\"\"\n"}
{"task_id": "convert-to-base-2", "prompt": "def baseNeg2(n: int) -> str:\n \"\"\"\n Given an integer n, return a binary string representing its representation in base -2.\n Note that the returned string should not have leading zeros unless the string is \"0\".\n \n Example 1:\n \n >>> baseNeg2(n = 2)\n >>> \"110\"\n Explantion: (-2)2 + (-2)1 = 2\n \n Example 2:\n \n >>> baseNeg2(n = 3)\n >>> \"111\"\n Explantion: (-2)2 + (-2)1 + (-2)0 = 3\n \n Example 3:\n \n >>> baseNeg2(n = 4)\n >>> \"100\"\n Explantion: (-2)2 = 4\n \"\"\"\n"}
{"task_id": "binary-prefix-divisible-by-5", "prompt": "def prefixesDivBy5(nums: List[int]) -> List[bool]:\n \"\"\"\n You are given a binary array nums (0-indexed).\n We define xi as the number whose binary representation is the subarray nums[0..i] (from most-significant-bit to least-significant-bit).\n \n For example, if nums = [1,0,1], then x0 = 1, x1 = 2, and x2 = 5.\n \n Return an array of booleans answer where answer[i] is true if xi is divisible by 5.\n \n Example 1:\n \n >>> prefixesDivBy5(nums = [0,1,1])\n >>> [true,false,false]\n Explanation: The input numbers in binary are 0, 01, 011; which are 0, 1, and 3 in base-10.\n Only the first number is divisible by 5, so answer[0] is true.\n \n Example 2:\n \n >>> prefixesDivBy5(nums = [1,1,1])\n >>> [false,false,false]\n \"\"\"\n"}
{"task_id": "next-greater-node-in-linked-list", "prompt": "# class ListNode:\n# def __init__(val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution:\n def nextLargerNodes(head: Optional[ListNode]) -> List[int]:\n \"\"\"\n You are given the head of a linked list with n nodes.\n For each node in the list, find the value of the next greater node. That is, for each node, find the value of the first node that is next to it and has a strictly larger value than it.\n Return an integer array answer where answer[i] is the value of the next greater node of the ith node (1-indexed). If the ith node does not have a next greater node, set answer[i] = 0.\n \n Example 1:\n \n \n >>> __init__(head = [2,1,5])\n >>> [5,5,0]\n \n Example 2:\n \n \n >>> __init__(head = [2,7,4,3,5])\n >>> [7,0,5,5,0]\n \"\"\"\n"}
{"task_id": "number-of-enclaves", "prompt": "def numEnclaves(grid: List[List[int]]) -> int:\n \"\"\"\n You are given an m x n binary matrix grid, where 0 represents a sea cell and 1 represents a land cell.\n A move consists of walking from one land cell to another adjacent (4-directionally) land cell or walking off the boundary of the grid.\n Return the number of land cells in grid for which we cannot walk off the boundary of the grid in any number of moves.\n \n Example 1:\n \n \n >>> numEnclaves(grid = [[0,0,0,0],[1,0,1,0],[0,1,1,0],[0,0,0,0]])\n >>> 3\n Explanation: There are three 1s that are enclosed by 0s, and one 1 that is not enclosed because its on the boundary.\n \n Example 2:\n \n \n >>> numEnclaves(grid = [[0,1,1,0],[0,0,1,0],[0,0,1,0],[0,0,0,0]])\n >>> 0\n Explanation: All 1s are either on the boundary or can reach the boundary.\n \"\"\"\n"}
{"task_id": "remove-outermost-parentheses", "prompt": "def removeOuterParentheses(s: str) -> str:\n \"\"\"\n A valid parentheses string is either empty \"\", \"(\" + A + \")\", or A + B, where A and B are valid parentheses strings, and + represents string concatenation.\n \n For example, \"\", \"()\", \"(())()\", and \"(()(()))\" are all valid parentheses strings.\n \n A valid parentheses string s is primitive if it is nonempty, and there does not exist a way to split it into s = A + B, with A and B nonempty valid parentheses strings.\n Given a valid parentheses string s, consider its primitive decomposition: s = P1 + P2 + ... + Pk, where Pi are primitive valid parentheses strings.\n Return s after removing the outermost parentheses of every primitive string in the primitive decomposition of s.\n \n Example 1:\n \n >>> removeOuterParentheses(s = \"(()())(())\")\n >>> \"()()()\"\n Explanation:\n The input string is \"(()())(())\", with primitive decomposition \"(()())\" + \"(())\".\n After removing outer parentheses of each part, this is \"()()\" + \"()\" = \"()()()\".\n \n Example 2:\n \n >>> removeOuterParentheses(s = \"(()())(())(()(()))\")\n >>> \"()()()()(())\"\n Explanation:\n The input string is \"(()())(())(()(()))\", with primitive decomposition \"(()())\" + \"(())\" + \"(()(()))\".\n After removing outer parentheses of each part, this is \"()()\" + \"()\" + \"()(())\" = \"()()()()(())\".\n \n Example 3:\n \n >>> removeOuterParentheses(s = \"()()\")\n >>> \"\"\n Explanation:\n The input string is \"()()\", with primitive decomposition \"()\" + \"()\".\n After removing outer parentheses of each part, this is \"\" + \"\" = \"\".\n \"\"\"\n"}
{"task_id": "sum-of-root-to-leaf-binary-numbers", "prompt": "# class TreeNode:\n# def __init__(val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def sumRootToLeaf(root: Optional[TreeNode]) -> int:\n \"\"\"\n You are given the root of a binary tree where each node has a value 0 or 1. Each root-to-leaf path represents a binary number starting with the most significant bit.\n \n For example, if the path is 0 -> 1 -> 1 -> 0 -> 1, then this could represent 01101 in binary, which is 13.\n \n For all leaves in the tree, consider the numbers represented by the path from the root to that leaf. Return the sum of these numbers.\n The test cases are generated so that the answer fits in a 32-bits integer.\n \n Example 1:\n \n \n >>> __init__(root = [1,0,1,0,1,0,1])\n >>> 22\n Explanation: (100) + (101) + (110) + (111) = 4 + 5 + 6 + 7 = 22\n \n Example 2:\n \n >>> __init__(root = [0])\n >>> 0\n \"\"\"\n"}
{"task_id": "camelcase-matching", "prompt": "def camelMatch(queries: List[str], pattern: str) -> List[bool]:\n \"\"\"\n Given an array of strings queries and a string pattern, return a boolean array answer where answer[i] is true if queries[i] matches pattern, and false otherwise.\n A query word queries[i] matches pattern if you can insert lowercase English letters into the pattern so that it equals the query. You may insert a character at any position in pattern or you may choose not to insert any characters at all.\n \n Example 1:\n \n >>> camelMatch(queries = [\"FooBar\",\"FooBarTest\",\"FootBall\",\"FrameBuffer\",\"ForceFeedBack\"], pattern = \"FB\")\n >>> [true,false,true,true,false]\n Explanation: \"FooBar\" can be generated like this \"F\" + \"oo\" + \"B\" + \"ar\".\n \"FootBall\" can be generated like this \"F\" + \"oot\" + \"B\" + \"all\".\n \"FrameBuffer\" can be generated like this \"F\" + \"rame\" + \"B\" + \"uffer\".\n \n Example 2:\n \n >>> camelMatch(queries = [\"FooBar\",\"FooBarTest\",\"FootBall\",\"FrameBuffer\",\"ForceFeedBack\"], pattern = \"FoBa\")\n >>> [true,false,true,false,false]\n Explanation: \"FooBar\" can be generated like this \"Fo\" + \"o\" + \"Ba\" + \"r\".\n \"FootBall\" can be generated like this \"Fo\" + \"ot\" + \"Ba\" + \"ll\".\n \n Example 3:\n \n >>> camelMatch(queries = [\"FooBar\",\"FooBarTest\",\"FootBall\",\"FrameBuffer\",\"ForceFeedBack\"], pattern = \"FoBaT\")\n >>> [false,true,false,false,false]\n Explanation: \"FooBarTest\" can be generated like this \"Fo\" + \"o\" + \"Ba\" + \"r\" + \"T\" + \"est\".\n \"\"\"\n"}
{"task_id": "video-stitching", "prompt": "def videoStitching(clips: List[List[int]], time: int) -> int:\n \"\"\"\n You are given a series of video clips from a sporting event that lasted time seconds. These video clips can be overlapping with each other and have varying lengths.\n Each video clip is described by an array clips where clips[i] = [starti, endi] indicates that the ith clip started at starti and ended at endi.\n We can cut these clips into segments freely.\n \n For example, a clip [0, 7] can be cut into segments [0, 1] + [1, 3] + [3, 7].\n \n Return the minimum number of clips needed so that we can cut the clips into segments that cover the entire sporting event [0, time]. If the task is impossible, return -1.\n \n Example 1:\n \n >>> videoStitching(clips = [[0,2],[4,6],[8,10],[1,9],[1,5],[5,9]], time = 10)\n >>> 3\n Explanation: We take the clips [0,2], [8,10], [1,9]; a total of 3 clips.\n Then, we can reconstruct the sporting event as follows:\n We cut [1,9] into segments [1,2] + [2,8] + [8,9].\n Now we have segments [0,2] + [2,8] + [8,10] which cover the sporting event [0, 10].\n \n Example 2:\n \n >>> videoStitching(clips = [[0,1],[1,2]], time = 5)\n >>> -1\n Explanation: We cannot cover [0,5] with only [0,1] and [1,2].\n \n Example 3:\n \n >>> videoStitching(clips = [[0,1],[6,8],[0,2],[5,6],[0,4],[0,3],[6,7],[1,3],[4,7],[1,4],[2,5],[2,6],[3,4],[4,5],[5,7],[6,9]], time = 9)\n >>> 3\n Explanation: We can take clips [0,4], [4,7], and [6,9].\n \"\"\"\n"}
{"task_id": "divisor-game", "prompt": "def divisorGame(n: int) -> bool:\n \"\"\"\n Alice and Bob take turns playing a game, with Alice starting first.\n Initially, there is a number n on the chalkboard. On each player's turn, that player makes a move consisting of:\n \n Choosing any x with 0 < x < n and n % x == 0.\n Replacing the number n on the chalkboard with n - x.\n \n Also, if a player cannot make a move, they lose the game.\n Return true if and only if Alice wins the game, assuming both players play optimally.\n \n Example 1:\n \n >>> divisorGame(n = 2)\n >>> true\n Explanation: Alice chooses 1, and Bob has no more moves.\n \n Example 2:\n \n >>> divisorGame(n = 3)\n >>> false\n Explanation: Alice chooses 1, Bob chooses 1, and Alice has no more moves.\n \"\"\"\n"}
{"task_id": "maximum-difference-between-node-and-ancestor", "prompt": "# class TreeNode:\n# def __init__(val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def maxAncestorDiff(root: Optional[TreeNode]) -> int:\n \"\"\"\n Given the root of a binary tree, find the maximum value v for which there exist different nodes a and b where v = |a.val - b.val| and a is an ancestor of b.\n A node a is an ancestor of b if either: any child of a is equal to b\u00a0or any child of a is an ancestor of b.\n \n Example 1:\n \n \n >>> __init__(root = [8,3,10,1,6,null,14,null,null,4,7,13])\n >>> 7\n Explanation: We have various ancestor-node differences, some of which are given below :\n |8 - 3| = 5\n |3 - 7| = 4\n |8 - 1| = 7\n |10 - 13| = 3\n Among all possible differences, the maximum value of 7 is obtained by |8 - 1| = 7.\n Example 2:\n \n \n >>> __init__(root = [1,null,2,null,0,3])\n >>> 3\n \"\"\"\n"}
{"task_id": "longest-arithmetic-subsequence", "prompt": "def longestArithSeqLength(nums: List[int]) -> int:\n \"\"\"\n Given an array nums of integers, return the length of the longest arithmetic subsequence in nums.\n Note that:\n \n 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.\n A sequence seq is arithmetic if seq[i + 1] - seq[i] are all the same value (for 0 <= i < seq.length - 1).\n \n \n Example 1:\n \n >>> longestArithSeqLength(nums = [3,6,9,12])\n >>> 4\n Explanation: The whole array is an arithmetic sequence with steps of length = 3.\n \n Example 2:\n \n >>> longestArithSeqLength(nums = [9,4,7,2,10])\n >>> 3\n Explanation: The longest arithmetic subsequence is [4,7,10].\n \n Example 3:\n \n >>> longestArithSeqLength(nums = [20,1,15,3,10,5,8])\n >>> 4\n Explanation: The longest arithmetic subsequence is [20,15,10,5].\n \"\"\"\n"}
{"task_id": "recover-a-tree-from-preorder-traversal", "prompt": "# class TreeNode:\n# def __init__(val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def recoverFromPreorder(traversal: str) -> Optional[TreeNode]:\n \"\"\"\n We run a\u00a0preorder\u00a0depth-first search (DFS) on the root of a binary tree.\n At each node in this traversal, we output D dashes (where D is the depth of this node), then we output the value of this node.\u00a0 If the depth of a node is D, the depth of its immediate child is D + 1.\u00a0 The depth of the root node is 0.\n If a node has only one child, that child is guaranteed to be the left child.\n Given the output traversal of this traversal, recover the tree and return its root.\n \n Example 1:\n \n \n >>> __init__(traversal = \"1-2--3--4-5--6--7\")\n >>> [1,2,5,3,4,6,7]\n \n Example 2:\n \n \n >>> __init__(traversal = \"1-2--3---4-5--6---7\")\n >>> [1,2,5,3,null,6,null,4,null,7]\n \n Example 3:\n \n \n >>> __init__(traversal = \"1-401--349---90--88\")\n >>> [1,401,null,349,88,90]\n \"\"\"\n"}
{"task_id": "two-city-scheduling", "prompt": "def twoCitySchedCost(costs: List[List[int]]) -> int:\n \"\"\"\n A company is planning to interview 2n people. Given the array costs where costs[i] = [aCosti, bCosti],\u00a0the cost of flying the ith person to city a is aCosti, and the cost of flying the ith person to city b is bCosti.\n Return the minimum cost to fly every person to a city such that exactly n people arrive in each city.\n \n Example 1:\n \n >>> twoCitySchedCost(costs = [[10,20],[30,200],[400,50],[30,20]])\n >>> 110\n Explanation:\n The first person goes to city A for a cost of 10.\n The second person goes to city A for a cost of 30.\n The third person goes to city B for a cost of 50.\n The fourth person goes to city B for a cost of 20.\n \n The total minimum cost is 10 + 30 + 50 + 20 = 110 to have half the people interviewing in each city.\n \n Example 2:\n \n >>> twoCitySchedCost(costs = [[259,770],[448,54],[926,667],[184,139],[840,118],[577,469]])\n >>> 1859\n \n Example 3:\n \n >>> twoCitySchedCost(costs = [[515,563],[451,713],[537,709],[343,819],[855,779],[457,60],[650,359],[631,42]])\n >>> 3086\n \"\"\"\n"}
{"task_id": "matrix-cells-in-distance-order", "prompt": "def allCellsDistOrder(rows: int, cols: int, rCenter: int, cCenter: int) -> List[List[int]]:\n \"\"\"\n You are given four integers row, cols, rCenter, and cCenter. There is a rows x cols matrix and you are on the cell with the coordinates (rCenter, cCenter).\n Return the coordinates of all cells in the matrix, sorted by their distance from (rCenter, cCenter) from the smallest distance to the largest distance. You may return the answer in any order that satisfies this condition.\n The distance between two cells (r1, c1) and (r2, c2) is |r1 - r2| + |c1 - c2|.\n \n Example 1:\n \n >>> allCellsDistOrder(rows = 1, cols = 2, rCenter = 0, cCenter = 0)\n >>> [[0,0],[0,1]]\n Explanation: The distances from (0, 0) to other cells are: [0,1]\n \n Example 2:\n \n >>> allCellsDistOrder(rows = 2, cols = 2, rCenter = 0, cCenter = 1)\n >>> [[0,1],[0,0],[1,1],[1,0]]\n Explanation: The distances from (0, 1) to other cells are: [0,1,1,2]\n The answer [[0,1],[1,1],[0,0],[1,0]] would also be accepted as correct.\n \n Example 3:\n \n >>> allCellsDistOrder(rows = 2, cols = 3, rCenter = 1, cCenter = 2)\n >>> [[1,2],[0,2],[1,1],[0,1],[1,0],[0,0]]\n Explanation: The distances from (1, 2) to other cells are: [0,1,1,2,2,3]\n There are other answers that would also be accepted as correct, such as [[1,2],[1,1],[0,2],[1,0],[0,1],[0,0]].\n \"\"\"\n"}
{"task_id": "maximum-sum-of-two-non-overlapping-subarrays", "prompt": "def maxSumTwoNoOverlap(nums: List[int], firstLen: int, secondLen: int) -> int:\n \"\"\"\n Given an integer array nums and two integers firstLen and secondLen, return the maximum sum of elements in two non-overlapping subarrays with lengths firstLen and secondLen.\n The array with length firstLen could occur before or after the array with length secondLen, but they have to be non-overlapping.\n A subarray is a contiguous part of an array.\n \n Example 1:\n \n >>> maxSumTwoNoOverlap(nums = [0,6,5,2,2,5,1,9,4], firstLen = 1, secondLen = 2)\n >>> 20\n Explanation: One choice of subarrays is [9] with length 1, and [6,5] with length 2.\n \n Example 2:\n \n >>> maxSumTwoNoOverlap(nums = [3,8,1,3,2,1,8,9,0], firstLen = 3, secondLen = 2)\n >>> 29\n Explanation: One choice of subarrays is [3,8,1] with length 3, and [8,9] with length 2.\n \n Example 3:\n \n >>> maxSumTwoNoOverlap(nums = [2,1,5,6,0,9,5,0,3,8], firstLen = 4, secondLen = 3)\n >>> 31\n Explanation: One choice of subarrays is [5,6,0,9] with length 4, and [0,3,8] with length 3.\n \"\"\"\n"}
{"task_id": "moving-stones-until-consecutive", "prompt": "def numMovesStones(a: int, b: int, c: int) -> List[int]:\n \"\"\"\n There are three stones in different positions on the X-axis. You are given three integers a, b, and c, the positions of the stones.\n In one move, you pick up a stone at an endpoint (i.e., either the lowest or highest position stone), and move it to an unoccupied position between those endpoints. Formally, let's say the stones are currently at positions x, y, and z with x < y < z. You pick up the stone at either position x or position z, and move that stone to an integer position k, with x < k < z and k != y.\n The game ends when you cannot make any more moves (i.e., the stones are in three consecutive positions).\n Return an integer array answer of length 2 where:\n \n answer[0] is the minimum number of moves you can play, and\n answer[1] is the maximum number of moves you can play.\n \n \n Example 1:\n \n >>> numMovesStones(a = 1, b = 2, c = 5)\n >>> [1,2]\n Explanation: Move the stone from 5 to 3, or move the stone from 5 to 4 to 3.\n \n Example 2:\n \n >>> numMovesStones(a = 4, b = 3, c = 2)\n >>> [0,0]\n Explanation: We cannot make any moves.\n \n Example 3:\n \n >>> numMovesStones(a = 3, b = 5, c = 1)\n >>> [1,2]\n Explanation: Move the stone from 1 to 4; or move the stone from 1 to 2 to 4.\n \"\"\"\n"}
{"task_id": "coloring-a-border", "prompt": "def colorBorder(grid: List[List[int]], row: int, col: int, color: int) -> List[List[int]]:\n \"\"\"\n You are given an m x n integer matrix grid, and three integers row, col, and color. Each value in the grid represents the color of the grid square at that location.\n Two squares are called adjacent if they are next to each other in any of the 4 directions.\n Two squares belong to the same connected component if they have the same color and they are adjacent.\n The border of a connected component is all the squares in the connected component that are either adjacent to (at least) a square not in the component, or on the boundary of the grid (the first or last row or column).\n You should color the border of the connected component that contains the square grid[row][col] with color.\n Return the final grid.\n \n Example 1:\n >>> colorBorder(grid = [[1,1],[1,2]], row = 0, col = 0, color = 3)\n >>> [[3,3],[3,2]]\n Example 2:\n >>> colorBorder(grid = [[1,2,2],[2,3,2]], row = 0, col = 1, color = 3)\n >>> [[1,3,3],[2,3,3]]\n Example 3:\n >>> colorBorder(grid = [[1,1,1],[1,1,1],[1,1,1]], row = 1, col = 1, color = 2)\n >>> [[2,2,2],[2,1,2],[2,2,2]]\n \"\"\"\n"}
{"task_id": "uncrossed-lines", "prompt": "def maxUncrossedLines(nums1: List[int], nums2: List[int]) -> int:\n \"\"\"\n You are given two integer arrays nums1 and nums2. We write the integers of nums1 and nums2 (in the order they are given) on two separate horizontal lines.\n We may draw connecting lines: a straight line connecting two numbers nums1[i] and nums2[j] such that:\n \n nums1[i] == nums2[j], and\n the line we draw does not intersect any other connecting (non-horizontal) line.\n \n Note that a connecting line cannot intersect even at the endpoints (i.e., each number can only belong to one connecting line).\n Return the maximum number of connecting lines we can draw in this way.\n \n Example 1:\n \n \n >>> maxUncrossedLines(nums1 = [1,4,2], nums2 = [1,2,4])\n >>> 2\n Explanation: We can draw 2 uncrossed lines as in the diagram.\n We cannot draw 3 uncrossed lines, because the line from nums1[1] = 4 to nums2[2] = 4 will intersect the line from nums1[2]=2 to nums2[1]=2.\n \n Example 2:\n \n >>> maxUncrossedLines(nums1 = [2,5,1,2,5], nums2 = [10,5,2,1,5,2])\n >>> 3\n \n Example 3:\n \n >>> maxUncrossedLines(nums1 = [1,3,7,1,7,5], nums2 = [1,9,2,5,1])\n >>> 2\n \"\"\"\n"}
{"task_id": "escape-a-large-maze", "prompt": "def isEscapePossible(blocked: List[List[int]], source: List[int], target: List[int]) -> bool:\n \"\"\"\n There is a 1 million by 1 million grid on an XY-plane, and the coordinates of each grid square are (x, y).\n We start at the source = [sx, sy] square and want to reach the target = [tx, ty] square. There is also an array of blocked squares, where each blocked[i] = [xi, yi] represents a blocked square with coordinates (xi, yi).\n Each move, we can walk one square north, east, south, or west if the square is not in the array of blocked squares. We are also not allowed to walk outside of the grid.\n Return true if and only if it is possible to reach the target square from the source square through a sequence of valid moves.\n \n Example 1:\n \n >>> isEscapePossible(blocked = [[0,1],[1,0]], source = [0,0], target = [0,2])\n >>> false\n Explanation: The target square is inaccessible starting from the source square because we cannot move.\n We cannot move north or east because those squares are blocked.\n We cannot move south or west because we cannot go outside of the grid.\n \n Example 2:\n \n >>> isEscapePossible(blocked = [], source = [0,0], target = [999999,999999])\n >>> true\n Explanation: Because there are no blocked cells, it is possible to reach the target square.\n \"\"\"\n"}
{"task_id": "valid-boomerang", "prompt": "def isBoomerang(points: List[List[int]]) -> bool:\n \"\"\"\n Given an array points where points[i] = [xi, yi] represents a point on the X-Y plane, return true if these points are a boomerang.\n A boomerang is a set of three points that are all distinct and not in a straight line.\n \n Example 1:\n >>> isBoomerang(points = [[1,1],[2,3],[3,2]])\n >>> true\n Example 2:\n >>> isBoomerang(points = [[1,1],[2,2],[3,3]])\n >>> false\n \"\"\"\n"}
{"task_id": "binary-search-tree-to-greater-sum-tree", "prompt": "# class TreeNode:\n# def __init__(val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def bstToGst(root: Optional[TreeNode]) -> Optional[TreeNode]:\n \"\"\"\n Given the root of a Binary Search Tree (BST), convert it to a Greater Tree such that every key of the original BST is changed to the original key plus the sum of all keys greater than the original key in BST.\n As a reminder, a binary search tree is a tree that satisfies these constraints:\n \n The left subtree of a node contains only nodes with keys less than the node's key.\n The right subtree of a node contains only nodes with keys greater than the node's key.\n Both the left and right subtrees must also be binary search trees.\n \n \n Example 1:\n \n \n >>> __init__(root = [4,1,6,0,2,5,7,null,null,null,3,null,null,null,8])\n >>> [30,36,21,36,35,26,15,null,null,null,33,null,null,null,8]\n \n Example 2:\n \n >>> __init__(root = [0,null,1])\n >>> [1,null,1]\n \"\"\"\n"}
{"task_id": "minimum-score-triangulation-of-polygon", "prompt": "def minScoreTriangulation(values: List[int]) -> int:\n \"\"\"\n You have a convex n-sided polygon where each vertex has an integer value. You are given an integer array values where values[i] is the value of the ith vertex in clockwise order.\n Polygon triangulation is a process where you divide a polygon into a set of triangles and the vertices of each triangle must also be vertices of the original polygon. Note that no other shapes other than triangles are allowed in the division. This process will result in n - 2 triangles.\n You will triangulate the polygon. For each triangle, the weight of that triangle is the product of the values at its vertices. The total score of the triangulation is the sum of these weights over all n - 2 triangles.\n Return the minimum possible score that you can achieve with some triangulation of the polygon.\n \n Example 1:\n \n \n >>> minScoreTriangulation(values = [1,2,3])\n >>> 6\n Explanation: The polygon is already triangulated, and the score of the only triangle is 6.\n \n Example 2:\n \n \n >>> minScoreTriangulation(values = [3,7,4,5])\n >>> 144\n Explanation: There are two triangulations, with possible scores: 3*7*5 + 4*5*7 = 245, or 3*4*5 + 3*4*7 = 144.\n The minimum score is 144.\n \n Example 3:\n \n \n >>> minScoreTriangulation(values = [1,3,1,4,1,5])\n >>> 13\n Explanation: The minimum score triangulation is 1*1*3 + 1*1*4 + 1*1*5 + 1*1*1 = 13.\n \"\"\"\n"}
{"task_id": "moving-stones-until-consecutive-ii", "prompt": "def numMovesStonesII(stones: List[int]) -> List[int]:\n \"\"\"\n There are some stones in different positions on the X-axis. You are given an integer array stones, the positions of the stones.\n Call a stone an endpoint stone if it has the smallest or largest position. In one move, you pick up an endpoint stone and move it to an unoccupied position so that it is no longer an endpoint stone.\n \n In particular, if the stones are at say, stones = [1,2,5], you cannot move the endpoint stone at position 5, since moving it to any position (such as 0, or 3) will still keep that stone as an endpoint stone.\n \n The game ends when you cannot make any more moves (i.e., the stones are in three consecutive positions).\n Return an integer array answer of length 2 where:\n \n answer[0] is the minimum number of moves you can play, and\n answer[1] is the maximum number of moves you can play.\n \n \n Example 1:\n \n >>> numMovesStonesII(stones = [7,4,9])\n >>> [1,2]\n Explanation: We can move 4 -> 8 for one move to finish the game.\n Or, we can move 9 -> 5, 4 -> 6 for two moves to finish the game.\n \n Example 2:\n \n >>> numMovesStonesII(stones = [6,5,4,3,10])\n >>> [2,3]\n Explanation: We can move 3 -> 8 then 10 -> 7 to finish the game.\n Or, we can move 3 -> 7, 4 -> 8, 5 -> 9 to finish the game.\n Notice we cannot move 10 -> 2 to finish the game, because that would be an illegal move.\n \"\"\"\n"}
{"task_id": "robot-bounded-in-circle", "prompt": "def isRobotBounded(instructions: str) -> bool:\n \"\"\"\n On an infinite plane, a robot initially stands at (0, 0) and faces north. Note that:\n \n The north direction is the positive direction of the y-axis.\n The south direction is the negative direction of the y-axis.\n The east direction is the positive direction of the x-axis.\n The west direction is the negative direction of the x-axis.\n \n The robot can receive one of three instructions:\n \n \"G\": go straight 1 unit.\n \"L\": turn 90 degrees to the left (i.e., anti-clockwise direction).\n \"R\": turn 90 degrees to the right (i.e., clockwise direction).\n \n The robot performs the instructions given in order, and repeats them forever.\n Return true if and only if there exists a circle in the plane such that the robot never leaves the circle.\n \n Example 1:\n \n >>> isRobotBounded(instructions = \"GGLLGG\")\n >>> true\n Explanation: The robot is initially at (0, 0) facing the north direction.\n \"G\": move one step. Position: (0, 1). Direction: North.\n \"G\": move one step. Position: (0, 2). Direction: North.\n \"L\": turn 90 degrees anti-clockwise. Position: (0, 2). Direction: West.\n \"L\": turn 90 degrees anti-clockwise. Position: (0, 2). Direction: South.\n \"G\": move one step. Position: (0, 1). Direction: South.\n \"G\": move one step. Position: (0, 0). Direction: South.\n Repeating the instructions, the robot goes into the cycle: (0, 0) --> (0, 1) --> (0, 2) --> (0, 1) --> (0, 0).\n Based on that, we return true.\n \n Example 2:\n \n >>> isRobotBounded(instructions = \"GG\")\n >>> false\n Explanation: The robot is initially at (0, 0) facing the north direction.\n \"G\": move one step. Position: (0, 1). Direction: North.\n \"G\": move one step. Position: (0, 2). Direction: North.\n Repeating the instructions, keeps advancing in the north direction and does not go into cycles.\n Based on that, we return false.\n \n Example 3:\n \n >>> isRobotBounded(instructions = \"GL\")\n >>> true\n Explanation: The robot is initially at (0, 0) facing the north direction.\n \"G\": move one step. Position: (0, 1). Direction: North.\n \"L\": turn 90 degrees anti-clockwise. Position: (0, 1). Direction: West.\n \"G\": move one step. Position: (-1, 1). Direction: West.\n \"L\": turn 90 degrees anti-clockwise. Position: (-1, 1). Direction: South.\n \"G\": move one step. Position: (-1, 0). Direction: South.\n \"L\": turn 90 degrees anti-clockwise. Position: (-1, 0). Direction: East.\n \"G\": move one step. Position: (0, 0). Direction: East.\n \"L\": turn 90 degrees anti-clockwise. Position: (0, 0). Direction: North.\n Repeating the instructions, the robot goes into the cycle: (0, 0) --> (0, 1) --> (-1, 1) --> (-1, 0) --> (0, 0).\n Based on that, we return true.\n \"\"\"\n"}
{"task_id": "flower-planting-with-no-adjacent", "prompt": "def gardenNoAdj(n: int, paths: List[List[int]]) -> List[int]:\n \"\"\"\n You have n gardens, labeled from 1 to n, and an array paths where paths[i] = [xi, yi] describes a bidirectional path between garden xi to garden yi. In each garden, you want to plant one of 4 types of flowers.\n All gardens have at most 3 paths coming into or leaving it.\n Your task is to choose a flower type for each garden such that, for any two gardens connected by a path, they have different types of flowers.\n Return any such a choice as an array answer, where answer[i] is the type of flower planted in the (i+1)th garden. The flower types are denoted 1, 2, 3, or 4. It is guaranteed an answer exists.\n \n Example 1:\n \n >>> gardenNoAdj(n = 3, paths = [[1,2],[2,3],[3,1]])\n >>> [1,2,3]\n Explanation:\n Gardens 1 and 2 have different types.\n Gardens 2 and 3 have different types.\n Gardens 3 and 1 have different types.\n Hence, [1,2,3] is a valid answer. Other valid answers include [1,2,4], [1,4,2], and [3,2,1].\n \n Example 2:\n \n >>> gardenNoAdj(n = 4, paths = [[1,2],[3,4]])\n >>> [1,2,1,2]\n \n Example 3:\n \n >>> gardenNoAdj(n = 4, paths = [[1,2],[2,3],[3,4],[4,1],[1,3],[2,4]])\n >>> [1,2,3,4]\n \"\"\"\n"}
{"task_id": "partition-array-for-maximum-sum", "prompt": "def maxSumAfterPartitioning(arr: List[int], k: int) -> int:\n \"\"\"\n Given an integer array arr, partition the array into (contiguous) subarrays of length at most k. After partitioning, each subarray has their values changed to become the maximum value of that subarray.\n Return the largest sum of the given array after partitioning. Test cases are generated so that the answer fits in a 32-bit integer.\n \n Example 1:\n \n >>> maxSumAfterPartitioning(arr = [1,15,7,9,2,5,10], k = 3)\n >>> 84\n Explanation: arr becomes [15,15,15,9,10,10,10]\n \n Example 2:\n \n >>> maxSumAfterPartitioning(arr = [1,4,1,5,7,3,6,1,9,9,3], k = 4)\n >>> 83\n \n Example 3:\n \n >>> maxSumAfterPartitioning(arr = [1], k = 1)\n >>> 1\n \"\"\"\n"}
{"task_id": "longest-duplicate-substring", "prompt": "def longestDupSubstring(s: str) -> str:\n \"\"\"\n Given a string s, consider all duplicated substrings: (contiguous) substrings of s that occur 2 or more times.\u00a0The occurrences\u00a0may overlap.\n Return any duplicated\u00a0substring that has the longest possible length.\u00a0If s does not have a duplicated substring, the answer is \"\".\n \n Example 1:\n >>> longestDupSubstring(s = \"banana\")\n >>> \"ana\"\n Example 2:\n >>> longestDupSubstring(s = \"abcd\")\n >>> \"\"\n \"\"\"\n"}
{"task_id": "last-stone-weight", "prompt": "def lastStoneWeight(stones: List[int]) -> int:\n \"\"\"\n You are given an array of integers stones where stones[i] is the weight of the ith stone.\n We are playing a game with the stones. On each turn, we choose the heaviest two stones and smash them together. Suppose the heaviest two stones have weights x and y with x <= y. The result of this smash is:\n \n If x == y, both stones are destroyed, and\n If x != y, the stone of weight x is destroyed, and the stone of weight y has new weight y - x.\n \n At the end of the game, there is at most one stone left.\n Return the weight of the last remaining stone. If there are no stones left, return 0.\n \n Example 1:\n \n >>> lastStoneWeight(stones = [2,7,4,1,8,1])\n >>> 1\n Explanation:\n We combine 7 and 8 to get 1 so the array converts to [2,4,1,1,1] then,\n we combine 2 and 4 to get 2 so the array converts to [2,1,1,1] then,\n we combine 2 and 1 to get 1 so the array converts to [1,1,1] then,\n we combine 1 and 1 to get 0 so the array converts to [1] then that's the value of the last stone.\n \n Example 2:\n \n >>> lastStoneWeight(stones = [1])\n >>> 1\n \"\"\"\n"}
{"task_id": "remove-all-adjacent-duplicates-in-string", "prompt": "def removeDuplicates(s: str) -> str:\n \"\"\"\n You are given a string s consisting of lowercase English letters. A duplicate removal consists of choosing two adjacent and equal letters and removing them.\n We repeatedly make duplicate removals on s until we no longer can.\n Return the final string after all such duplicate removals have been made. It can be proven that the answer is unique.\n \n Example 1:\n \n >>> removeDuplicates(s = \"abbaca\")\n >>> \"ca\"\n Explanation:\n For example, in \"abbaca\" we could remove \"bb\" since the letters are adjacent and equal, and this is the only possible move. The result of this move is that the string is \"aaca\", of which only \"aa\" is possible, so the final string is \"ca\".\n \n Example 2:\n \n >>> removeDuplicates(s = \"azxxzy\")\n >>> \"ay\"\n \"\"\"\n"}
{"task_id": "longest-string-chain", "prompt": "def longestStrChain(words: List[str]) -> int:\n \"\"\"\n You are given an array of words where each word consists of lowercase English letters.\n wordA is a predecessor of wordB if and only if we can insert exactly one letter anywhere in wordA without changing the order of the other characters to make it equal to wordB.\n \n For example, \"abc\" is a predecessor of \"abac\", while \"cba\" is not a predecessor of \"bcad\".\n \n A word chain is a sequence of words [word1, word2, ..., wordk] with k >= 1, where word1 is a predecessor of word2, word2 is a predecessor of word3, and so on. A single word is trivially a word chain with k == 1.\n Return the length of the longest possible word chain with words chosen from the given list of words.\n \n Example 1:\n \n >>> longestStrChain(words = [\"a\",\"b\",\"ba\",\"bca\",\"bda\",\"bdca\"])\n >>> 4\n Explanation: One of the longest word chains is [\"a\",\"ba\",\"bda\",\"bdca\"].\n \n Example 2:\n \n >>> longestStrChain(words = [\"xbc\",\"pcxbcf\",\"xb\",\"cxbc\",\"pcxbc\"])\n >>> 5\n Explanation: All the words can be put in a word chain [\"xb\", \"xbc\", \"cxbc\", \"pcxbc\", \"pcxbcf\"].\n \n Example 3:\n \n >>> longestStrChain(words = [\"abcd\",\"dbqca\"])\n >>> 1\n Explanation: The trivial word chain [\"abcd\"] is one of the longest word chains.\n [\"abcd\",\"dbqca\"] is not a valid word chain because the ordering of the letters is changed.\n \"\"\"\n"}
{"task_id": "last-stone-weight-ii", "prompt": "def lastStoneWeightII(stones: List[int]) -> int:\n \"\"\"\n You are given an array of integers stones where stones[i] is the weight of the ith stone.\n We are playing a game with the stones. On each turn, we choose any two stones and smash them together. Suppose the stones have weights x and y with x <= y. The result of this smash is:\n \n If x == y, both stones are destroyed, and\n If x != y, the stone of weight x is destroyed, and the stone of weight y has new weight y - x.\n \n At the end of the game, there is at most one stone left.\n Return the smallest possible weight of the left stone. If there are no stones left, return 0.\n \n Example 1:\n \n >>> lastStoneWeightII(stones = [2,7,4,1,8,1])\n >>> 1\n Explanation:\n We can combine 2 and 4 to get 2, so the array converts to [2,7,1,8,1] then,\n we can combine 7 and 8 to get 1, so the array converts to [2,1,1,1] then,\n we can combine 2 and 1 to get 1, so the array converts to [1,1,1] then,\n we can combine 1 and 1 to get 0, so the array converts to [1], then that's the optimal value.\n \n Example 2:\n \n >>> lastStoneWeightII(stones = [31,26,33,21,40])\n >>> 5\n \"\"\"\n"}
{"task_id": "height-checker", "prompt": "def heightChecker(heights: List[int]) -> int:\n \"\"\"\n A school is trying to take an annual photo of all the students. The students are asked to stand in a single file line in non-decreasing order by height. Let this ordering be represented by the integer array expected where expected[i] is the expected height of the ith student in line.\n You are given an integer array heights representing the current order that the students are standing in. Each heights[i] is the height of the ith student in line (0-indexed).\n Return the number of indices where heights[i] != expected[i].\n \n Example 1:\n \n >>> heightChecker(heights = [1,1,4,2,1,3])\n >>> 3\n Explanation:\n heights: [1,1,4,2,1,3]\n expected: [1,1,1,2,3,4]\n Indices 2, 4, and 5 do not match.\n \n Example 2:\n \n >>> heightChecker(heights = [5,1,2,3,4])\n >>> 5\n Explanation:\n heights: [5,1,2,3,4]\n expected: [1,2,3,4,5]\n All indices do not match.\n \n Example 3:\n \n >>> heightChecker(heights = [1,2,3,4,5])\n >>> 0\n Explanation:\n heights: [1,2,3,4,5]\n expected: [1,2,3,4,5]\n All indices match.\n \"\"\"\n"}
{"task_id": "grumpy-bookstore-owner", "prompt": "def maxSatisfied(customers: List[int], grumpy: List[int], minutes: int) -> int:\n \"\"\"\n There is a bookstore owner that has a store open for n minutes. You are given an integer array customers of length n where customers[i] is the number of the customers that enter the store at the start of the ith minute and all those customers leave after the end of that minute.\n During certain minutes, the bookstore owner is grumpy. You are given a binary array grumpy where grumpy[i] is 1 if the bookstore owner is grumpy during the ith minute, and is 0 otherwise.\n When the bookstore owner is grumpy, the customers entering during that minute are not satisfied. Otherwise, they are satisfied.\n The bookstore owner knows a secret technique to remain not grumpy for minutes consecutive minutes, but this technique can only be used once.\n Return the maximum number of customers that can be satisfied throughout the day.\n \n Example 1:\n \n >>> maxSatisfied(customers = [1,0,1,2,1,1,7,5], grumpy = [0,1,0,1,0,1,0,1], minutes = 3)\n >>> 16\n Explanation:\n The bookstore owner keeps themselves not grumpy for the last 3 minutes.\n The maximum number of customers that can be satisfied = 1 + 1 + 1 + 1 + 7 + 5 = 16.\n \n Example 2:\n \n >>> maxSatisfied(customers = [1], grumpy = [0], minutes = 1)\n >>> 1\n \"\"\"\n"}
{"task_id": "previous-permutation-with-one-swap", "prompt": "def prevPermOpt1(arr: List[int]) -> List[int]:\n \"\"\"\n Given an array of positive integers arr (not necessarily distinct), return the lexicographically largest permutation that is smaller than arr, that can be made with exactly one swap. If it cannot be done, then return the same array.\n Note that a swap exchanges the positions of two numbers arr[i] and arr[j]\n \n Example 1:\n \n >>> prevPermOpt1(arr = [3,2,1])\n >>> [3,1,2]\n Explanation: Swapping 2 and 1.\n \n Example 2:\n \n >>> prevPermOpt1(arr = [1,1,5])\n >>> [1,1,5]\n Explanation: This is already the smallest permutation.\n \n Example 3:\n \n >>> prevPermOpt1(arr = [1,9,4,6,7])\n >>> [1,7,4,6,9]\n Explanation: Swapping 9 and 7.\n \"\"\"\n"}
{"task_id": "distant-barcodes", "prompt": "def rearrangeBarcodes(barcodes: List[int]) -> List[int]:\n \"\"\"\n In a warehouse, there is a row of barcodes, where the ith barcode is barcodes[i].\n Rearrange the barcodes so that no two adjacent barcodes are equal. You may return any answer, and it is guaranteed an answer exists.\n \n Example 1:\n >>> rearrangeBarcodes(barcodes = [1,1,1,2,2,2])\n >>> [2,1,2,1,2,1]\n Example 2:\n >>> rearrangeBarcodes(barcodes = [1,1,1,1,2,2,3,3])\n >>> [1,3,1,3,1,2,1,2]\n \"\"\"\n"}
{"task_id": "shortest-way-to-form-string", "prompt": "def shortestWay(source: str, target: str) -> int:\n \"\"\"\n A subsequence of a string is a new string that is formed from the original string by deleting some (can be none) of the characters without disturbing the relative positions of the remaining characters. (i.e., \"ace\" is a subsequence of \"abcde\" while \"aec\" is not).\n Given two strings source and target, return the minimum number of subsequences of source such that their concatenation equals target. If the task is impossible, return -1.\n \n Example 1:\n \n >>> shortestWay(source = \"abc\", target = \"abcbc\")\n >>> 2\n Explanation: The target \"abcbc\" can be formed by \"abc\" and \"bc\", which are subsequences of source \"abc\".\n \n Example 2:\n \n >>> shortestWay(source = \"abc\", target = \"acdbc\")\n >>> -1\n Explanation: The target string cannot be constructed from the subsequences of source string due to the character \"d\" in target string.\n \n Example 3:\n \n >>> shortestWay(source = \"xyz\", target = \"xzyxz\")\n >>> 3\n Explanation: The target string can be constructed as follows \"xz\" + \"y\" + \"xz\".\n \"\"\"\n"}
{"task_id": "confusing-number", "prompt": "def confusingNumber(n: int) -> bool:\n \"\"\"\n A confusing number is a number that when rotated 180 degrees becomes a different number with each digit valid.\n We can rotate digits of a number by 180 degrees to form new digits.\n \n When 0, 1, 6, 8, and 9 are rotated 180 degrees, they become 0, 1, 9, 8, and 6 respectively.\n When 2, 3, 4, 5, and 7 are rotated 180 degrees, they become invalid.\n \n Note that after rotating a number, we can ignore leading zeros.\n \n For example, after rotating 8000, we have 0008 which is considered as just 8.\n \n Given an integer n, return true if it is a confusing number, or false otherwise.\n \n Example 1:\n \n \n >>> confusingNumber(n = 6)\n >>> true\n Explanation: We get 9 after rotating 6, 9 is a valid number, and 9 != 6.\n \n Example 2:\n \n \n >>> confusingNumber(n = 89)\n >>> true\n Explanation: We get 68 after rotating 89, 68 is a valid number and 68 != 89.\n \n Example 3:\n \n \n >>> confusingNumber(n = 11)\n >>> false\n Explanation: We get 11 after rotating 11, 11 is a valid number but the value remains the same, thus 11 is not a confusing number\n \"\"\"\n"}
{"task_id": "campus-bikes", "prompt": "def assignBikes(workers: List[List[int]], bikes: List[List[int]]) -> List[int]:\n \"\"\"\n On a campus represented on the X-Y plane, there are n workers and m bikes, with n <= m.\n You are given an array workers of length n where workers[i] = [xi, yi] is the position of the ith worker. You are also given an array bikes of length m where bikes[j] = [xj, yj] is the position of the jth bike. All the given positions are unique.\n Assign a bike to each worker. Among the available bikes and workers, we choose the (workeri, bikej) pair with the shortest Manhattan distance between each other and assign the bike to that worker.\n If there are multiple (workeri, bikej) pairs with the same shortest Manhattan distance, we choose the pair with the smallest worker index. If there are multiple ways to do that, we choose the pair with the smallest bike index. Repeat this process until there are no available workers.\n Return an array answer of length n, where answer[i] is the index (0-indexed) of the bike that the ith worker is assigned to.\n The Manhattan distance between two points p1 and p2 is Manhattan(p1, p2) = |p1.x - p2.x| + |p1.y - p2.y|.\n \n Example 1:\n \n \n >>> assignBikes(workers = [[0,0],[2,1]], bikes = [[1,2],[3,3]])\n >>> [1,0]\n Explanation: Worker 1 grabs Bike 0 as they are closest (without ties), and Worker 0 is assigned Bike 1. So the output is [1, 0].\n \n Example 2:\n \n \n >>> assignBikes(workers = [[0,0],[1,1],[2,0]], bikes = [[1,0],[2,2],[2,1]])\n >>> [0,2,1]\n Explanation: Worker 0 grabs Bike 0 at first. Worker 1 and Worker 2 share the same distance to Bike 2, thus Worker 1 is assigned to Bike 2, and Worker 2 will take Bike 1. So the output is [0,2,1].\n \"\"\"\n"}
{"task_id": "minimize-rounding-error-to-meet-target", "prompt": "def minimizeError(prices: List[str], target: int) -> str:\n \"\"\"\n Given an array of prices [p1,p2...,pn] and a target, round each price pi to Roundi(pi) so that the rounded array [Round1(p1),Round2(p2)...,Roundn(pn)] sums to the given target. Each operation Roundi(pi) could be either Floor(pi) or Ceil(pi).\n Return the string \"-1\" if the rounded array is impossible to sum to target. Otherwise, return the smallest rounding error, which is defined as \u03a3 |Roundi(pi) - (pi)| for i from 1 to n, as a string with three places after the decimal.\n \n Example 1:\n \n >>> minimizeError(prices = [\"0.700\",\"2.800\",\"4.900\"], target = 8)\n >>> \"1.000\"\n Explanation:\n Use Floor, Ceil and Ceil operations to get (0.7 - 0) + (3 - 2.8) + (5 - 4.9) = 0.7 + 0.2 + 0.1 = 1.0 .\n \n Example 2:\n \n >>> minimizeError(prices = [\"1.500\",\"2.500\",\"3.500\"], target = 10)\n >>> \"-1\"\n Explanation: It is impossible to meet the target.\n \n Example 3:\n \n >>> minimizeError(prices = [\"1.500\",\"2.500\",\"3.500\"], target = 9)\n >>> \"1.500\"\n \"\"\"\n"}
{"task_id": "all-paths-from-source-lead-to-destination", "prompt": "def leadsToDestination(n: int, edges: List[List[int]], source: int, destination: int) -> bool:\n \"\"\"\n Given the edges of a directed graph where edges[i] = [ai, bi] indicates there is an edge between nodes ai and bi, and two nodes source and destination of this graph, determine whether or not all paths starting from source eventually, end at destination, that is:\n \n At least one path exists from the source node to the destination node\n If a path exists from the source node to a node with no outgoing edges, then that node is equal to destination.\n The number of possible paths from source to destination is a finite number.\n \n Return true if and only if all roads from source lead to destination.\n \n Example 1:\n \n \n >>> leadsToDestination(n = 3, edges = [[0,1],[0,2]], source = 0, destination = 2)\n >>> false\n Explanation: It is possible to reach and get stuck on both node 1 and node 2.\n \n Example 2:\n \n \n >>> leadsToDestination(n = 4, edges = [[0,1],[0,3],[1,2],[2,1]], source = 0, destination = 3)\n >>> false\n Explanation: We have two possibilities: to end at node 3, or to loop over node 1 and node 2 indefinitely.\n \n Example 3:\n \n \n >>> leadsToDestination(n = 4, edges = [[0,1],[0,2],[1,3],[2,3]], source = 0, destination = 3)\n >>> true\n \"\"\"\n"}
{"task_id": "missing-element-in-sorted-array", "prompt": "def missingElement(nums: List[int], k: int) -> int:\n \"\"\"\n Given an integer array nums which is sorted in ascending order and all of its elements are unique and given also an integer k, return the kth missing number starting from the leftmost number of the array.\n \n Example 1:\n \n >>> missingElement(nums = [4,7,9,10], k = 1)\n >>> 5\n Explanation: The first missing number is 5.\n \n Example 2:\n \n >>> missingElement(nums = [4,7,9,10], k = 3)\n >>> 8\n Explanation: The missing numbers are [5,6,8,...], hence the third missing number is 8.\n \n Example 3:\n \n >>> missingElement(nums = [1,2,4], k = 3)\n >>> 6\n Explanation: The missing numbers are [3,5,6,7,...], hence the third missing number is 6.\n \"\"\"\n"}
{"task_id": "lexicographically-smallest-equivalent-string", "prompt": "def smallestEquivalentString(s1: str, s2: str, baseStr: str) -> str:\n \"\"\"\n You are given two strings of the same length s1 and s2 and a string baseStr.\n We say s1[i] and s2[i] are equivalent characters.\n \n For example, if s1 = \"abc\" and s2 = \"cde\", then we have 'a' == 'c', 'b' == 'd', and 'c' == 'e'.\n \n Equivalent characters follow the usual rules of any equivalence relation:\n \n Reflexivity: 'a' == 'a'.\n Symmetry: 'a' == 'b' implies 'b' == 'a'.\n Transitivity: 'a' == 'b' and 'b' == 'c' implies 'a' == 'c'.\n \n For example, given the equivalency information from s1 = \"abc\" and s2 = \"cde\", \"acd\" and \"aab\" are equivalent strings of baseStr = \"eed\", and \"aab\" is the lexicographically smallest equivalent string of baseStr.\n Return the lexicographically smallest equivalent string of baseStr by using the equivalency information from s1 and s2.\n \n Example 1:\n \n >>> smallestEquivalentString(s1 = \"parker\", s2 = \"morris\", baseStr = \"parser\")\n >>> \"makkek\"\n Explanation: Based on the equivalency information in s1 and s2, we can group their characters as [m,p], [a,o], [k,r,s], [e,i].\n The characters in each group are equivalent and sorted in lexicographical order.\n So the answer is \"makkek\".\n \n Example 2:\n \n >>> smallestEquivalentString(s1 = \"hello\", s2 = \"world\", baseStr = \"hold\")\n >>> \"hdld\"\n Explanation: Based on the equivalency information in s1 and s2, we can group their characters as [h,w], [d,e,o], [l,r].\n So only the second letter 'o' in baseStr is changed to 'd', the answer is \"hdld\".\n \n Example 3:\n \n >>> smallestEquivalentString(s1 = \"leetcode\", s2 = \"programs\", baseStr = \"sourcecode\")\n >>> \"aauaaaaada\"\n Explanation: We group the equivalent characters in s1 and s2 as [a,o,e,r,s,c], [l,p], [g,t] and [d,m], thus all letters in baseStr except 'u' and 'd' are transformed to 'a', the answer is \"aauaaaaada\".\n \"\"\"\n"}
{"task_id": "longest-repeating-substring", "prompt": "def longestRepeatingSubstring(s: str) -> int:\n \"\"\"\n Given a string s, return the length of the longest repeating substrings. If no repeating substring exists, return 0.\n \n Example 1:\n \n >>> longestRepeatingSubstring(s = \"abcd\")\n >>> 0\n Explanation: There is no repeating substring.\n \n Example 2:\n \n >>> longestRepeatingSubstring(s = \"abbaba\")\n >>> 2\n Explanation: The longest repeating substrings are \"ab\" and \"ba\", each of which occurs twice.\n \n Example 3:\n \n >>> longestRepeatingSubstring(s = \"aabcaabdaab\")\n >>> 3\n Explanation: The longest repeating substring is \"aab\", which occurs 3 times.\n \"\"\"\n"}
{"task_id": "number-of-valid-subarrays", "prompt": "def validSubarrays(nums: List[int]) -> int:\n \"\"\"\n Given an integer array nums, return the number of non-empty subarrays with the leftmost element of the subarray\u00a0not larger than other elements in the subarray.\n A subarray is a contiguous part of an array.\n \n Example 1:\n \n >>> validSubarrays(nums = [1,4,2,5,3])\n >>> 11\n Explanation: There are 11 valid subarrays: [1],[4],[2],[5],[3],[1,4],[2,5],[1,4,2],[2,5,3],[1,4,2,5],[1,4,2,5,3].\n \n Example 2:\n \n >>> validSubarrays(nums = [3,2,1])\n >>> 3\n Explanation: The 3 valid subarrays are: [3],[2],[1].\n \n Example 3:\n \n >>> validSubarrays(nums = [2,2,2])\n >>> 6\n Explanation: There are 6 valid subarrays: [2],[2],[2],[2,2],[2,2],[2,2,2].\n \"\"\"\n"}
{"task_id": "fixed-point", "prompt": "def fixedPoint(arr: List[int]) -> int:\n \"\"\"\n Given an array of distinct integers arr, where arr is sorted in ascending order, return the smallest index i that satisfies arr[i] == i. If there is no such index, return -1.\n \n Example 1:\n \n >>> fixedPoint(arr = [-10,-5,0,3,7])\n >>> 3\n Explanation: For the given array, arr[0] = -10, arr[1] = -5, arr[2] = 0, arr[3] = 3, thus the output is 3.\n Example 2:\n \n >>> fixedPoint(arr = [0,2,5,8,17])\n >>> 0\n Explanation: arr[0] = 0, thus the output is 0.\n Example 3:\n \n >>> fixedPoint(arr = [-10,-5,3,4,7,9])\n >>> -1\n Explanation: There is no such i that arr[i] == i, thus the output is -1.\n \"\"\"\n"}
{"task_id": "index-pairs-of-a-string", "prompt": "def indexPairs(text: str, words: List[str]) -> List[List[int]]:\n \"\"\"\n Given a string text and an array of strings words, return an array of all index pairs [i, j] so that the substring text[i...j] is in words.\n Return the pairs [i, j] in sorted order (i.e., sort them by their first coordinate, and in case of ties sort them by their second coordinate).\n \n Example 1:\n \n >>> indexPairs(text = \"thestoryofleetcodeandme\", words = [\"story\",\"fleet\",\"leetcode\"])\n >>> [[3,7],[9,13],[10,17]]\n \n Example 2:\n \n >>> indexPairs(text = \"ababa\", words = [\"aba\",\"ab\"])\n >>> [[0,1],[0,2],[2,3],[2,4]]\n Explanation: Notice that matches can overlap, see \"aba\" is found in [0,2] and [2,4].\n \"\"\"\n"}
{"task_id": "campus-bikes-ii", "prompt": "def assignBikes(workers: List[List[int]], bikes: List[List[int]]) -> int:\n \"\"\"\n On a campus represented as a 2D grid, there are n workers and m bikes, with n <= m. Each worker and bike is a 2D coordinate on this grid.\n We assign one unique bike to each worker so that the sum of the Manhattan distances between each worker and their assigned bike is minimized.\n Return the minimum possible sum of Manhattan distances between each worker and their assigned bike.\n The Manhattan distance between two points p1 and p2 is Manhattan(p1, p2) = |p1.x - p2.x| + |p1.y - p2.y|.\n \n Example 1:\n \n \n >>> assignBikes(workers = [[0,0],[2,1]], bikes = [[1,2],[3,3]])\n >>> 6\n Explanation:\n We assign bike 0 to worker 0, bike 1 to worker 1. The Manhattan distance of both assignments is 3, so the output is 6.\n \n Example 2:\n \n \n >>> assignBikes(workers = [[0,0],[1,1],[2,0]], bikes = [[1,0],[2,2],[2,1]])\n >>> 4\n Explanation:\n We first assign bike 0 to worker 0, then assign bike 1 to worker 1 or worker 2, bike 2 to worker 2 or worker 1. Both assignments lead to sum of the Manhattan distances as 4.\n \n Example 3:\n \n >>> assignBikes(workers = [[0,0],[1,0],[2,0],[3,0],[4,0]], bikes = [[0,999],[1,999],[2,999],[3,999],[4,999]])\n >>> 4995\n \"\"\"\n"}
{"task_id": "digit-count-in-range", "prompt": "def digitsCount(d: int, low: int, high: int) -> int:\n \"\"\"\n Given a single-digit integer d and two integers low and high, return the number of times that d occurs as a digit in all integers in the inclusive range [low, high].\n \n Example 1:\n \n >>> digitsCount(d = 1, low = 1, high = 13)\n >>> 6\n Explanation: The digit d = 1 occurs 6 times in 1, 10, 11, 12, 13.\n Note that the digit d = 1 occurs twice in the number 11.\n \n Example 2:\n \n >>> digitsCount(d = 3, low = 100, high = 250)\n >>> 35\n Explanation: The digit d = 3 occurs 35 times in 103,113,123,130,131,...,238,239,243.\n \"\"\"\n"}
{"task_id": "greatest-common-divisor-of-strings", "prompt": "def gcdOfStrings(str1: str, str2: str) -> str:\n \"\"\"\n For two strings s and t, we say \"t divides s\" if and only if s = t + t + t + ... + t + t (i.e., t is concatenated with itself one or more times).\n Given two strings str1 and str2, return the largest string x such that x divides both str1 and str2.\n \n Example 1:\n \n >>> gcdOfStrings(str1 = \"ABCABC\", str2 = \"ABC\")\n >>> \"ABC\"\n \n Example 2:\n \n >>> gcdOfStrings(str1 = \"ABABAB\", str2 = \"ABAB\")\n >>> \"AB\"\n \n Example 3:\n \n >>> gcdOfStrings(str1 = \"LEET\", str2 = \"CODE\")\n >>> \"\"\n \"\"\"\n"}
{"task_id": "flip-columns-for-maximum-number-of-equal-rows", "prompt": "def maxEqualRowsAfterFlips(matrix: List[List[int]]) -> int:\n \"\"\"\n You are given an m x n binary matrix matrix.\n You can choose any number of columns in the matrix and flip every cell in that column (i.e., Change the value of the cell from 0 to 1 or vice versa).\n Return the maximum number of rows that have all values equal after some number of flips.\n \n Example 1:\n \n >>> maxEqualRowsAfterFlips(matrix = [[0,1],[1,1]])\n >>> 1\n Explanation: After flipping no values, 1 row has all values equal.\n \n Example 2:\n \n >>> maxEqualRowsAfterFlips(matrix = [[0,1],[1,0]])\n >>> 2\n Explanation: After flipping values in the first column, both rows have equal values.\n \n Example 3:\n \n >>> maxEqualRowsAfterFlips(matrix = [[0,0,0],[0,0,1],[1,1,0]])\n >>> 2\n Explanation: After flipping values in the first two columns, the last two rows have equal values.\n \"\"\"\n"}
{"task_id": "adding-two-negabinary-numbers", "prompt": "def addNegabinary(arr1: List[int], arr2: List[int]) -> List[int]:\n \"\"\"\n Given two numbers arr1 and arr2 in base -2, return the result of adding them together.\n Each number is given in array format:\u00a0 as an array of 0s and 1s, from most significant bit to least significant bit.\u00a0 For example, arr = [1,1,0,1] represents the number (-2)^3\u00a0+ (-2)^2 + (-2)^0 = -3.\u00a0 A number arr in array, format is also guaranteed to have no leading zeros: either\u00a0arr == [0] or arr[0] == 1.\n Return the result of adding arr1 and arr2 in the same format: as an array of 0s and 1s with no leading zeros.\n \n Example 1:\n \n >>> addNegabinary(arr1 = [1,1,1,1,1], arr2 = [1,0,1])\n >>> [1,0,0,0,0]\n Explanation: arr1 represents 11, arr2 represents 5, the output represents 16.\n \n Example 2:\n \n >>> addNegabinary(arr1 = [0], arr2 = [0])\n >>> [0]\n \n Example 3:\n \n >>> addNegabinary(arr1 = [0], arr2 = [1])\n >>> [1]\n \"\"\"\n"}
{"task_id": "number-of-submatrices-that-sum-to-target", "prompt": "def numSubmatrixSumTarget(matrix: List[List[int]], target: int) -> int:\n \"\"\"\n Given a matrix\u00a0and a target, return the number of non-empty submatrices that sum to target.\n A submatrix x1, y1, x2, y2 is the set of all cells matrix[x][y] with x1 <= x <= x2 and y1 <= y <= y2.\n Two submatrices (x1, y1, x2, y2) and (x1', y1', x2', y2') are different if they have some coordinate\u00a0that is different: for example, if x1 != x1'.\n \n Example 1:\n \n \n >>> numSubmatrixSumTarget(matrix = [[0,1,0],[1,1,1],[0,1,0]], target = 0)\n >>> 4\n Explanation: The four 1x1 submatrices that only contain 0.\n \n Example 2:\n \n >>> numSubmatrixSumTarget(matrix = [[1,-1],[-1,1]], target = 0)\n >>> 5\n Explanation: The two 1x2 submatrices, plus the two 2x1 submatrices, plus the 2x2 submatrix.\n \n Example 3:\n \n >>> numSubmatrixSumTarget(matrix = [[904]], target = 0)\n >>> 0\n \"\"\"\n"}
{"task_id": "occurrences-after-bigram", "prompt": "def findOcurrences(text: str, first: str, second: str) -> List[str]:\n \"\"\"\n Given two strings first and second, consider occurrences in some text of the form \"first second third\", where second comes immediately after first, and third comes immediately after second.\n Return an array of all the words third for each occurrence of \"first second third\".\n \n Example 1:\n >>> findOcurrences(text = \"alice is a good girl she is a good student\", first = \"a\", second = \"good\")\n >>> [\"girl\",\"student\"]\n Example 2:\n >>> findOcurrences(text = \"we will we will rock you\", first = \"we\", second = \"will\")\n >>> [\"we\",\"rock\"]\n \"\"\"\n"}
{"task_id": "letter-tile-possibilities", "prompt": "def numTilePossibilities(tiles: str) -> int:\n \"\"\"\n You have n\u00a0\u00a0tiles, where each tile has one letter tiles[i] printed on it.\n Return the number of possible non-empty sequences of letters you can make using the letters printed on those tiles.\n \n Example 1:\n \n >>> numTilePossibilities(tiles = \"AAB\")\n >>> 8\n Explanation: The possible sequences are \"A\", \"B\", \"AA\", \"AB\", \"BA\", \"AAB\", \"ABA\", \"BAA\".\n \n Example 2:\n \n >>> numTilePossibilities(tiles = \"AAABBC\")\n >>> 188\n \n Example 3:\n \n >>> numTilePossibilities(tiles = \"V\")\n >>> 1\n \"\"\"\n"}
{"task_id": "insufficient-nodes-in-root-to-leaf-paths", "prompt": "# class TreeNode:\n# def __init__(val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def sufficientSubset(root: Optional[TreeNode], limit: int) -> Optional[TreeNode]:\n \"\"\"\n Given the root of a binary tree and an integer limit, delete all insufficient nodes in the tree simultaneously, and return the root of the resulting binary tree.\n A node is insufficient if every root to leaf path intersecting this node has a sum strictly less than limit.\n A leaf is a node with no children.\n \n Example 1:\n \n \n >>> __init__(root = [1,2,3,4,-99,-99,7,8,9,-99,-99,12,13,-99,14], limit = 1)\n >>> [1,2,3,4,null,null,7,8,9,null,14]\n \n Example 2:\n \n \n >>> __init__(root = [5,4,8,11,null,17,4,7,1,null,null,5,3], limit = 22)\n >>> [5,4,8,11,null,17,4,7,null,null,null,5]\n \n Example 3:\n \n \n >>> __init__(root = [1,2,-3,-5,null,4,null], limit = -1)\n >>> [1,null,-3,4]\n \"\"\"\n"}
{"task_id": "smallest-subsequence-of-distinct-characters", "prompt": "def smallestSubsequence(s: str) -> str:\n \"\"\"\n Given a string s, return the lexicographically smallest subsequence of s that contains all the distinct characters of s exactly once.\n \n Example 1:\n \n >>> smallestSubsequence(s = \"bcabc\")\n >>> \"abc\"\n \n Example 2:\n \n >>> smallestSubsequence(s = \"cbacdcbc\")\n >>> \"acdb\"\n \"\"\"\n"}
{"task_id": "sum-of-digits-in-the-minimum-number", "prompt": "def sumOfDigits(nums: List[int]) -> int:\n \"\"\"\n Given an integer array nums, return 0 if the sum of the digits of the minimum integer in nums is odd, or 1 otherwise.\n \n Example 1:\n \n >>> sumOfDigits(nums = [34,23,1,24,75,33,54,8])\n >>> 0\n Explanation: The minimal element is 1, and the sum of those digits is 1 which is odd, so the answer is 0.\n \n Example 2:\n \n >>> sumOfDigits(nums = [99,77,33,66,55])\n >>> 1\n Explanation: The minimal element is 33, and the sum of those digits is 3 + 3 = 6 which is even, so the answer is 1.\n \"\"\"\n"}
{"task_id": "high-five", "prompt": "def highFive(items: List[List[int]]) -> List[List[int]]:\n \"\"\"\n Given a list of the scores of different students, items, where items[i] = [IDi, scorei] represents one score from a student with IDi, calculate each student's top five average.\n Return the answer as an array of pairs result, where result[j] = [IDj, topFiveAveragej] represents the student with IDj and their top five average. Sort result by IDj in increasing order.\n A student's top five average is calculated by taking the sum of their top five scores and dividing it by 5 using integer division.\n \n Example 1:\n \n >>> highFive(items = [[1,91],[1,92],[2,93],[2,97],[1,60],[2,77],[1,65],[1,87],[1,100],[2,100],[2,76]])\n >>> [[1,87],[2,88]]\n Explanation:\n The student with ID = 1 got scores 91, 92, 60, 65, 87, and 100. Their top five average is (100 + 92 + 91 + 87 + 65) / 5 = 87.\n The student with ID = 2 got scores 93, 97, 77, 100, and 76. Their top five average is (100 + 97 + 93 + 77 + 76) / 5 = 88.6, but with integer division their average converts to 88.\n \n Example 2:\n \n >>> highFive(items = [[1,100],[7,100],[1,100],[7,100],[1,100],[7,100],[1,100],[7,100],[1,100],[7,100]])\n >>> [[1,100],[7,100]]\n \"\"\"\n"}
{"task_id": "brace-expansion", "prompt": "def expand(s: str) -> List[str]:\n \"\"\"\n You are given a string s representing a list of words. Each letter in the word has one or more options.\n \n If there is one option, the letter is represented as is.\n If there is more than one option, then curly braces delimit the options. For example, \"{a,b,c}\" represents options [\"a\", \"b\", \"c\"].\n \n For example, if s = \"a{b,c}\", the first character is always 'a', but the second character can be 'b' or 'c'. The original list is [\"ab\", \"ac\"].\n Return all words that can be formed in this manner, sorted in lexicographical order.\n \n Example 1:\n >>> expand(s = \"{a,b}c{d,e}f\")\n >>> [\"acdf\",\"acef\",\"bcdf\",\"bcef\"]\n Example 2:\n >>> expand(s = \"abcd\")\n >>> [\"abcd\"]\n \"\"\"\n"}
{"task_id": "confusing-number-ii", "prompt": "def confusingNumberII(n: int) -> int:\n \"\"\"\n A confusing number is a number that when rotated 180 degrees becomes a different number with each digit valid.\n We can rotate digits of a number by 180 degrees to form new digits.\n \n When 0, 1, 6, 8, and 9 are rotated 180 degrees, they become 0, 1, 9, 8, and 6 respectively.\n When 2, 3, 4, 5, and 7 are rotated 180 degrees, they become invalid.\n \n Note that after rotating a number, we can ignore leading zeros.\n \n For example, after rotating 8000, we have 0008 which is considered as just 8.\n \n Given an integer n, return the number of confusing numbers in the inclusive range [1, n].\n \n Example 1:\n \n >>> confusingNumberII(n = 20)\n >>> 6\n Explanation: The confusing numbers are [6,9,10,16,18,19].\n 6 converts to 9.\n 9 converts to 6.\n 10 converts to 01 which is just 1.\n 16 converts to 91.\n 18 converts to 81.\n 19 converts to 61.\n \n Example 2:\n \n >>> confusingNumberII(n = 100)\n >>> 19\n Explanation: The confusing numbers are [6,9,10,16,18,19,60,61,66,68,80,81,86,89,90,91,98,99,100].\n \"\"\"\n"}
{"task_id": "duplicate-zeros", "prompt": "def duplicateZeros(arr: List[int]) -> None:\n \"\"\"\n Do not return anything, modify arr in-place instead.\n \"\"\"\n \"\"\"\n Given a fixed-length integer array arr, duplicate each occurrence of zero, shifting the remaining elements to the right.\n Note that elements beyond the length of the original array are not written. Do the above modifications to the input array in place and do not return anything.\n \n Example 1:\n \n >>> duplicateZeros(arr = [1,0,2,3,0,4,5,0])\n >>> [1,0,0,2,3,0,0,4]\n Explanation: After calling your function, the input array is modified to: [1,0,0,2,3,0,0,4]\n \n Example 2:\n \n >>> duplicateZeros(arr = [1,2,3])\n >>> [1,2,3]\n Explanation: After calling your function, the input array is modified to: [1,2,3]\n \"\"\"\n"}
{"task_id": "largest-values-from-labels", "prompt": "def largestValsFromLabels(values: List[int], labels: List[int], numWanted: int, useLimit: int) -> int:\n \"\"\"\n You are given n item's value and label as two integer arrays values and labels. You are also given two integers numWanted and useLimit.\n Your task is to find a subset of items with the maximum sum of their values such that:\n \n The number of items is at most numWanted.\n The number of items with the same label is at most useLimit.\n \n Return the maximum sum.\n \n Example 1:\n \n >>> largestValsFromLabels(values = [5,4,3,2,1], labels = [1,1,2,2,3], numWanted = 3, useLimit = 1)\n >>> 9\n Explanation:\n The subset chosen is the first, third, and fifth items with the sum of values 5 + 3 + 1.\n \n Example 2:\n \n >>> largestValsFromLabels(values = [5,4,3,2,1], labels = [1,3,3,3,2], numWanted = 3, useLimit = 2)\n >>> 12\n Explanation:\n The subset chosen is the first, second, and third items with the sum of values 5 + 4 + 3.\n \n Example 3:\n \n >>> largestValsFromLabels(values = [9,8,8,7,6], labels = [0,0,0,1,1], numWanted = 3, useLimit = 1)\n >>> 16\n Explanation:\n The subset chosen is the first and fourth items with the sum of values 9 + 7.\n \"\"\"\n"}
{"task_id": "shortest-path-in-binary-matrix", "prompt": "def shortestPathBinaryMatrix(grid: List[List[int]]) -> int:\n \"\"\"\n Given an n x n binary matrix grid, return the length of the shortest clear path in the matrix. If there is no clear path, return -1.\n A clear path in a binary matrix is a path from the top-left cell (i.e., (0, 0)) to the bottom-right cell (i.e., (n - 1, n - 1)) such that:\n \n All the visited cells of the path are 0.\n All the adjacent cells of the path are 8-directionally connected (i.e., they are different and they share an edge or a corner).\n \n The length of a clear path is the number of visited cells of this path.\n \n Example 1:\n \n \n >>> shortestPathBinaryMatrix(grid = [[0,1],[1,0]])\n >>> 2\n \n Example 2:\n \n \n >>> shortestPathBinaryMatrix(grid = [[0,0,0],[1,1,0],[1,1,0]])\n >>> 4\n \n Example 3:\n \n >>> shortestPathBinaryMatrix(grid = [[1,0,0],[1,1,0],[1,1,0]])\n >>> -1\n \"\"\"\n"}
{"task_id": "shortest-common-supersequence", "prompt": "def shortestCommonSupersequence(str1: str, str2: str) -> str:\n \"\"\"\n Given two strings str1 and str2, return the shortest string that has both str1 and str2 as subsequences. If there are multiple valid strings, return any of them.\n A string s is a subsequence of string t if deleting some number of characters from t (possibly 0) results in the string s.\n \n Example 1:\n \n >>> shortestCommonSupersequence(str1 = \"abac\", str2 = \"cab\")\n >>> \"cabac\"\n Explanation:\n str1 = \"abac\" is a subsequence of \"cabac\" because we can delete the first \"c\".\n str2 = \"cab\" is a subsequence of \"cabac\" because we can delete the last \"ac\".\n The answer provided is the shortest such string that satisfies these properties.\n \n Example 2:\n \n >>> shortestCommonSupersequence(str1 = \"aaaaaaaa\", str2 = \"aaaaaaaa\")\n >>> \"aaaaaaaa\"\n \"\"\"\n"}
{"task_id": "statistics-from-a-large-sample", "prompt": "def sampleStats(count: List[int]) -> List[float]:\n \"\"\"\n You are given a large sample of integers in the range [0, 255]. Since the sample is so large, it is represented by an array count\u00a0where count[k] is the number of times that k appears in the sample.\n Calculate the following statistics:\n \n minimum: The minimum element in the sample.\n maximum: The maximum element in the sample.\n mean: The average of the sample, calculated as the total sum of all elements divided by the total number of elements.\n median:\n \n If the sample has an odd number of elements, then the median is the middle element once the sample is sorted.\n If the sample has an even number of elements, then the median is the average of the two middle elements once the sample is sorted.\n \n \n mode: The number that appears the most in the sample. It is guaranteed to be unique.\n \n Return the statistics of the sample as an array of floating-point numbers [minimum, maximum, mean, median, mode]. Answers within 10-5 of the actual answer will be accepted.\n \n Example 1:\n \n >>> sampleStats(count = [0,1,3,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0])\n >>> [1.00000,3.00000,2.37500,2.50000,3.00000]\n Explanation: The sample represented by count is [1,2,2,2,3,3,3,3].\n The minimum and maximum are 1 and 3 respectively.\n The mean is (1+2+2+2+3+3+3+3) / 8 = 19 / 8 = 2.375.\n Since the size of the sample is even, the median is the average of the two middle elements 2 and 3, which is 2.5.\n The mode is 3 as it appears the most in the sample.\n \n Example 2:\n \n >>> sampleStats(count = [0,4,3,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0])\n >>> [1.00000,4.00000,2.18182,2.00000,1.00000]\n Explanation: The sample represented by count is [1,1,1,1,2,2,2,3,3,4,4].\n The minimum and maximum are 1 and 4 respectively.\n The mean is (1+1+1+1+2+2+2+3+3+4+4) / 11 = 24 / 11 = 2.18181818... (for display purposes, the output shows the rounded number 2.18182).\n Since the size of the sample is odd, the median is the middle element 2.\n The mode is 1 as it appears the most in the sample.\n \"\"\"\n"}
{"task_id": "car-pooling", "prompt": "def carPooling(trips: List[List[int]], capacity: int) -> bool:\n \"\"\"\n There is a car with capacity empty seats. The vehicle only drives east (i.e., it cannot turn around and drive west).\n You are given the integer capacity and an array trips where trips[i] = [numPassengersi, fromi, toi] indicates that the ith trip has numPassengersi passengers and the locations to pick them up and drop them off are fromi and toi respectively. The locations are given as the number of kilometers due east from the car's initial location.\n Return true if it is possible to pick up and drop off all passengers for all the given trips, or false otherwise.\n \n Example 1:\n \n >>> carPooling(trips = [[2,1,5],[3,3,7]], capacity = 4)\n >>> false\n \n Example 2:\n \n >>> carPooling(trips = [[2,1,5],[3,3,7]], capacity = 5)\n >>> true\n \"\"\"\n"}
{"task_id": "brace-expansion-ii", "prompt": "def braceExpansionII(expression: str) -> List[str]:\n \"\"\"\n Under the grammar given below, strings can represent a set of lowercase words. Let\u00a0R(expr)\u00a0denote the set of words the expression represents.\n The grammar can best be understood through simple examples:\n \n Single letters represent a singleton set containing that word.\n \n R(\"a\") = {\"a\"}\n R(\"w\") = {\"w\"}\n \n \n When we take a comma-delimited list of two or more expressions, we take the union of possibilities.\n \n R(\"{a,b,c}\") = {\"a\",\"b\",\"c\"}\n R(\"{{a,b},{b,c}}\") = {\"a\",\"b\",\"c\"} (notice the final set only contains each word at most once)\n \n \n When we concatenate two expressions, we take the set of possible concatenations between two words where the first word comes from the first expression and the second word comes from the second expression.\n \n R(\"{a,b}{c,d}\") = {\"ac\",\"ad\",\"bc\",\"bd\"}\n R(\"a{b,c}{d,e}f{g,h}\") = {\"abdfg\", \"abdfh\", \"abefg\", \"abefh\", \"acdfg\", \"acdfh\", \"acefg\", \"acefh\"}\n \n \n \n Formally, the three rules for our grammar:\n \n For every lowercase letter x, we have R(x) = {x}.\n For expressions e1, e2, ... , ek with k >= 2, we have R({e1, e2, ...}) = R(e1) \u222a R(e2) \u222a ...\n For expressions e1 and e2, we have R(e1 + e2) = {a + b for (a, b) in R(e1) \u00d7 R(e2)}, where + denotes concatenation, and \u00d7 denotes the cartesian product.\n \n Given an expression representing a set of words under the given grammar, return the sorted list of words that the expression represents.\n \n Example 1:\n \n >>> braceExpansionII(expression = \"{a,b}{c,{d,e}}\")\n >>> [\"ac\",\"ad\",\"ae\",\"bc\",\"bd\",\"be\"]\n \n Example 2:\n \n >>> braceExpansionII(expression = \"{{a,z},a{b,c},{ab,z}}\")\n >>> [\"a\",\"ab\",\"ac\",\"z\"]\n Explanation: Each distinct word is written only once in the final answer.\n \"\"\"\n"}
{"task_id": "two-sum-less-than-k", "prompt": "def twoSumLessThanK(nums: List[int], k: int) -> int:\n \"\"\"\n Given an array nums of integers and\u00a0integer k, return the maximum sum such that there exists i < j with nums[i] + nums[j] = sum and sum < k. If no i, j exist satisfying this equation, return -1.\n \n Example 1:\n \n >>> twoSumLessThanK(nums = [34,23,1,24,75,33,54,8], k = 60)\n >>> 58\n Explanation: We can use 34 and 24 to sum 58 which is less than 60.\n \n Example 2:\n \n >>> twoSumLessThanK(nums = [10,20,30], k = 15)\n >>> -1\n Explanation: In this case it is not possible to get a pair sum less that 15.\n \"\"\"\n"}
{"task_id": "find-k-length-substrings-with-no-repeated-characters", "prompt": "def numKLenSubstrNoRepeats(s: str, k: int) -> int:\n \"\"\"\n Given a string s and an integer k, return the number of substrings in s of length k with no repeated characters.\n \n Example 1:\n \n >>> numKLenSubstrNoRepeats(s = \"havefunonleetcode\", k = 5)\n >>> 6\n Explanation: There are 6 substrings they are: 'havef','avefu','vefun','efuno','etcod','tcode'.\n \n Example 2:\n \n >>> numKLenSubstrNoRepeats(s = \"home\", k = 5)\n >>> 0\n Explanation: Notice k can be larger than the length of s. In this case, it is not possible to find any substring.\n \"\"\"\n"}
{"task_id": "the-earliest-moment-when-everyone-become-friends", "prompt": "def earliestAcq(logs: List[List[int]], n: int) -> int:\n \"\"\"\n There are n people in a social group labeled from 0 to n - 1. You are given an array logs where logs[i] = [timestampi, xi, yi] indicates that xi and yi will be friends at the time timestampi.\n Friendship is symmetric. That means if a is friends with b, then b is friends with a. Also, person a is acquainted with a person b if a is friends with b, or a is a friend of someone acquainted with b.\n Return the earliest time for which every person became acquainted with every other person. If there is no such earliest time, return -1.\n \n Example 1:\n \n >>> earliestAcq(logs = [[20190101,0,1],[20190104,3,4],[20190107,2,3],[20190211,1,5],[20190224,2,4],[20190301,0,3],[20190312,1,2],[20190322,4,5]], n = 6)\n >>> 20190301\n Explanation:\n The first event occurs at timestamp = 20190101, and after 0 and 1 become friends, we have the following friendship groups [0,1], [2], [3], [4], [5].\n The second event occurs at timestamp = 20190104, and after 3 and 4 become friends, we have the following friendship groups [0,1], [2], [3,4], [5].\n The third event occurs at timestamp = 20190107, and after 2 and 3 become friends, we have the following friendship groups [0,1], [2,3,4], [5].\n The fourth event occurs at timestamp = 20190211, and after 1 and 5 become friends, we have the following friendship groups [0,1,5], [2,3,4].\n The fifth event occurs at timestamp = 20190224, and as 2 and 4 are already friends, nothing happens.\n The sixth event occurs at timestamp = 20190301, and after 0 and 3 become friends, we all become friends.\n \n Example 2:\n \n >>> earliestAcq(logs = [[0,2,0],[1,0,1],[3,0,3],[4,1,2],[7,3,1]], n = 4)\n >>> 3\n Explanation: At timestamp = 3, all the persons (i.e., 0, 1, 2, and 3) become friends.\n \"\"\"\n"}
{"task_id": "path-with-maximum-minimum-value", "prompt": "def maximumMinimumPath(grid: List[List[int]]) -> int:\n \"\"\"\n Given an m x n integer matrix grid, return the maximum score of a path starting at (0, 0) and ending at (m - 1, n - 1) moving in the 4 cardinal directions.\n The score of a path is the minimum value in that path.\n \n For example, the score of the path 8 \u2192 4 \u2192 5 \u2192 9 is 4.\n \n \n Example 1:\n \n \n >>> maximumMinimumPath(grid = [[5,4,5],[1,2,6],[7,4,6]])\n >>> 4\n Explanation: The path with the maximum score is highlighted in yellow.\n \n Example 2:\n \n \n >>> maximumMinimumPath(grid = [[2,2,1,2,2,2],[1,2,2,2,1,2]])\n >>> 2\n \n Example 3:\n \n \n >>> maximumMinimumPath(grid = [[3,4,6,3,4],[0,2,1,1,7],[8,8,3,2,7],[3,2,4,9,8],[4,1,2,0,0],[4,6,5,4,3]])\n >>> 3\n \"\"\"\n"}
{"task_id": "distribute-candies-to-people", "prompt": "def distributeCandies(candies: int, num_people: int) -> List[int]:\n \"\"\"\n We distribute some\u00a0number of candies, to a row of n =\u00a0num_people\u00a0people in the following way:\n We then give 1 candy to the first person, 2 candies to the second person, and so on until we give n\u00a0candies to the last person.\n Then, we go back to the start of the row, giving n\u00a0+ 1 candies to the first person, n\u00a0+ 2 candies to the second person, and so on until we give 2 * n\u00a0candies to the last person.\n This process repeats (with us giving one more candy each time, and moving to the start of the row after we reach the end) until we run out of candies.\u00a0 The last person will receive all of our remaining candies (not necessarily one more than the previous gift).\n Return an array (of length num_people\u00a0and sum candies) that represents the final distribution of candies.\n \n Example 1:\n \n >>> distributeCandies(candies = 7, num_people = 4)\n >>> [1,2,3,1]\n Explanation:\n On the first turn, ans[0] += 1, and the array is [1,0,0,0].\n On the second turn, ans[1] += 2, and the array is [1,2,0,0].\n On the third turn, ans[2] += 3, and the array is [1,2,3,0].\n On the fourth turn, ans[3] += 1 (because there is only one candy left), and the final array is [1,2,3,1].\n \n Example 2:\n \n >>> distributeCandies(candies = 10, num_people = 3)\n >>> [5,2,3]\n Explanation:\n On the first turn, ans[0] += 1, and the array is [1,0,0].\n On the second turn, ans[1] += 2, and the array is [1,2,0].\n On the third turn, ans[2] += 3, and the array is [1,2,3].\n On the fourth turn, ans[0] += 4, and the final array is [5,2,3].\n \"\"\"\n"}
{"task_id": "path-in-zigzag-labelled-binary-tree", "prompt": "def pathInZigZagTree(label: int) -> List[int]:\n \"\"\"\n In an infinite binary tree where every node has two children, the nodes are labelled in row order.\n In the odd numbered rows (ie., the first, third, fifth,...), the labelling is left to right, while in the even numbered rows (second, fourth, sixth,...), the labelling is right to left.\n \n Given the label of a node in this tree, return the labels in the path from the root of the tree to the\u00a0node with that label.\n \n Example 1:\n \n >>> pathInZigZagTree(label = 14)\n >>> [1,3,4,14]\n \n Example 2:\n \n >>> pathInZigZagTree(label = 26)\n >>> [1,2,6,10,26]\n \"\"\"\n"}
{"task_id": "filling-bookcase-shelves", "prompt": "def minHeightShelves(books: List[List[int]], shelfWidth: int) -> int:\n \"\"\"\n You are given an array books where books[i] = [thicknessi, heighti] indicates the thickness and height of the ith book. You are also given an integer shelfWidth.\n We want to place these books in order onto bookcase shelves that have a total width shelfWidth.\n We choose some of the books to place on this shelf such that the sum of their thickness is less than or equal to shelfWidth, then build another level of the shelf of the bookcase so that the total height of the bookcase has increased by the maximum height of the books we just put down. We repeat this process until there are no more books to place.\n Note that at each step of the above process, the order of the books we place is the same order as the given sequence of books.\n \n For example, if we have an ordered list of 5 books, we might place the first and second book onto the first shelf, the third book on the second shelf, and the fourth and fifth book on the last shelf.\n \n Return the minimum possible height that the total bookshelf can be after placing shelves in this manner.\n \n Example 1:\n \n \n >>> minHeightShelves(books = [[1,1],[2,3],[2,3],[1,1],[1,1],[1,1],[1,2]], shelfWidth = 4)\n >>> 6\n Explanation:\n The sum of the heights of the 3 shelves is 1 + 3 + 2 = 6.\n Notice that book number 2 does not have to be on the first shelf.\n \n Example 2:\n \n >>> minHeightShelves(books = [[1,3],[2,4],[3,2]], shelfWidth = 6)\n >>> 4\n \"\"\"\n"}
{"task_id": "parsing-a-boolean-expression", "prompt": "def parseBoolExpr(expression: str) -> bool:\n \"\"\"\n A boolean expression is an expression that evaluates to either true or false. It can be in one of the following shapes:\n \n 't' that evaluates to true.\n 'f' that evaluates to false.\n '!(subExpr)' that evaluates to the logical NOT of the inner expression subExpr.\n '&(subExpr1, subExpr2, ..., subExprn)' that evaluates to the logical AND of the inner expressions subExpr1, subExpr2, ..., subExprn where n >= 1.\n '|(subExpr1, subExpr2, ..., subExprn)' that evaluates to the logical OR of the inner expressions subExpr1, subExpr2, ..., subExprn where n >= 1.\n \n Given a string expression that represents a boolean expression, return the evaluation of that expression.\n It is guaranteed that the given expression is valid and follows the given rules.\n \n Example 1:\n \n >>> parseBoolExpr(expression = \"&(|(f))\")\n >>> false\n Explanation:\n First, evaluate |(f) --> f. The expression is now \"&(f)\".\n Then, evaluate &(f) --> f. The expression is now \"f\".\n Finally, return false.\n \n Example 2:\n \n >>> parseBoolExpr(expression = \"|(f,f,f,t)\")\n >>> true\n Explanation: The evaluation of (false OR false OR false OR true) is true.\n \n Example 3:\n \n >>> parseBoolExpr(expression = \"!(&(f,t))\")\n >>> true\n Explanation:\n First, evaluate &(f,t) --> (false AND true) --> false --> f. The expression is now \"!(f)\".\n Then, evaluate !(f) --> NOT false --> true. We return true.\n \"\"\"\n"}
{"task_id": "defanging-an-ip-address", "prompt": "def defangIPaddr(address: str) -> str:\n \"\"\"\n Given a valid (IPv4) IP address, return a defanged version of that IP address.\\r\n \\r\n A defanged\u00a0IP address\u00a0replaces every period \".\" with \"[.]\".\\r\n \\r\n \u00a0\\r\n Example 1:\\r\n >>> defangIPaddr(address = \"1.1.1.1\"\\r)\n >>> \"1[.]1[.]1[.]1\"\\r\n Example 2:\\r\n >>> defangIPaddr(address = \"255.100.50.0\"\\r)\n >>> \"255[.]100[.]50[.]0\"\\r\n \\r\n \u00a0\\r\n \"\"\"\n"}
{"task_id": "corporate-flight-bookings", "prompt": "def corpFlightBookings(bookings: List[List[int]], n: int) -> List[int]:\n \"\"\"\n There are n flights that are labeled from 1 to n.\n You are given an array of flight bookings bookings, where bookings[i] = [firsti, lasti, seatsi] represents a booking for flights firsti through lasti (inclusive) with seatsi seats reserved for each flight in the range.\n Return an array answer of length n, where answer[i] is the total number of seats reserved for flight i.\n \n Example 1:\n \n >>> corpFlightBookings(bookings = [[1,2,10],[2,3,20],[2,5,25]], n = 5)\n >>> [10,55,45,25,25]\n Explanation:\n Flight labels: 1 2 3 4 5\n Booking 1 reserved: 10 10\n Booking 2 reserved: 20 20\n Booking 3 reserved: 25 25 25 25\n Total seats: 10 55 45 25 25\n Hence, answer = [10,55,45,25,25]\n \n Example 2:\n \n >>> corpFlightBookings(bookings = [[1,2,10],[2,2,15]], n = 2)\n >>> [10,25]\n Explanation:\n Flight labels: 1 2\n Booking 1 reserved: 10 10\n Booking 2 reserved: 15\n Total seats: 10 25\n Hence, answer = [10,25]\n \"\"\"\n"}
{"task_id": "maximum-nesting-depth-of-two-valid-parentheses-strings", "prompt": "def maxDepthAfterSplit(seq: str) -> List[int]:\n \"\"\"\n A string is a valid parentheses string\u00a0(denoted VPS) if and only if it consists of \"(\" and \")\" characters only, and:\\r\n \\r\n \\r\n \tIt is the empty string, or\\r\n \tIt can be written as\u00a0AB\u00a0(A\u00a0concatenated with\u00a0B), where\u00a0A\u00a0and\u00a0B\u00a0are VPS's, or\\r\n \tIt can be written as\u00a0(A), where\u00a0A\u00a0is a VPS.\\r\n \\r\n \\r\n We can\u00a0similarly define the nesting depth depth(S) of any VPS S as follows:\\r\n \\r\n \\r\n \tdepth(\"\") = 0\\r\n \tdepth(A + B) = max(depth(A), depth(B)), where A and B are VPS's\\r\n \tdepth(\"(\" + A + \")\") = 1 + depth(A), where A is a VPS.\\r\n \\r\n \\r\n For example,\u00a0 \"\",\u00a0\"()()\", and\u00a0\"()(()())\"\u00a0are VPS's (with nesting depths 0, 1, and 2), and \")(\" and \"(()\" are not VPS's.\\r\n \\r\n \u00a0\\r\n \\r\n Given a VPS seq, split it into two disjoint subsequences A and B, such that\u00a0A and B are VPS's (and\u00a0A.length + B.length = seq.length).\\r\n \\r\n Now choose any such A and B such that\u00a0max(depth(A), depth(B)) is the minimum possible value.\\r\n \\r\n Return an answer array (of length seq.length) that encodes such a\u00a0choice of A and B:\u00a0 answer[i] = 0 if seq[i] is part of A, else answer[i] = 1.\u00a0 Note that even though multiple answers may exist, you may return any of them.\\r\n \n \n Example 1:\n \n >>> maxDepthAfterSplit(seq = \"(()())\")\n >>> [0,1,1,1,1,0]\n \n Example 2:\n \n >>> maxDepthAfterSplit(seq = \"()(())()\")\n >>> [0,0,0,1,1,0,1,1]\n \"\"\"\n"}
{"task_id": "number-of-days-in-a-month", "prompt": "def numberOfDays(year: int, month: int) -> int:\n \"\"\"\n Given a year year and a month month, return the number of days of that month.\n \n Example 1:\n >>> numberOfDays(year = 1992, month = 7)\n >>> 31\n Example 2:\n >>> numberOfDays(year = 2000, month = 2)\n >>> 29\n Example 3:\n >>> numberOfDays(year = 1900, month = 2)\n >>> 28\n \"\"\"\n"}
{"task_id": "remove-vowels-from-a-string", "prompt": "def removeVowels(s: str) -> str:\n \"\"\"\n Given a string s, remove the vowels 'a', 'e', 'i', 'o', and 'u' from it, and return the new string.\n \n Example 1:\n \n >>> removeVowels(s = \"leetcodeisacommunityforcoders\")\n >>> \"ltcdscmmntyfrcdrs\"\n \n Example 2:\n \n >>> removeVowels(s = \"aeiou\")\n >>> \"\"\n \"\"\"\n"}
{"task_id": "maximum-average-subtree", "prompt": "# class TreeNode:\n# def __init__(val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def maximumAverageSubtree(root: Optional[TreeNode]) -> float:\n \"\"\"\n Given the root of a binary tree, return the maximum average value of a subtree of that tree. Answers within 10-5 of the actual answer will be accepted.\n A subtree of a tree is any node of that tree plus all its descendants.\n The average value of a tree is the sum of its values, divided by the number of nodes.\n \n Example 1:\n \n \n >>> __init__(root = [5,6,1])\n >>> 6.00000\n Explanation:\n For the node with value = 5 we have an average of (5 + 6 + 1) / 3 = 4.\n For the node with value = 6 we have an average of 6 / 1 = 6.\n For the node with value = 1 we have an average of 1 / 1 = 1.\n So the answer is 6 which is the maximum.\n \n Example 2:\n \n >>> __init__(root = [0,null,1])\n >>> 1.00000\n \"\"\"\n"}
{"task_id": "divide-array-into-increasing-sequences", "prompt": "def canDivideIntoSubsequences(nums: List[int], k: int) -> bool:\n \"\"\"\n Given an integer array nums sorted in non-decreasing order and an integer k, return true if this array can be divided into one or more disjoint increasing subsequences of length at least k, or false otherwise.\n \n Example 1:\n \n >>> canDivideIntoSubsequences(nums = [1,2,2,3,3,4,4], k = 3)\n >>> true\n Explanation: The array can be divided into two subsequences [1,2,3,4] and [2,3,4] with lengths at least 3 each.\n \n Example 2:\n \n >>> canDivideIntoSubsequences(nums = [5,6,6,7,8], k = 3)\n >>> false\n Explanation: There is no way to divide the array using the conditions required.\n \"\"\"\n"}
{"task_id": "relative-sort-array", "prompt": "def relativeSortArray(arr1: List[int], arr2: List[int]) -> List[int]:\n \"\"\"\n Given two arrays arr1 and arr2, the elements of arr2 are distinct, and all elements in arr2 are also in arr1.\n Sort the elements of arr1 such that the relative ordering of items in arr1 are the same as in arr2. Elements that do not appear in arr2 should be placed at the end of arr1 in ascending order.\n \n Example 1:\n \n >>> relativeSortArray(arr1 = [2,3,1,3,2,4,6,7,9,2,19], arr2 = [2,1,4,3,9,6])\n >>> [2,2,2,1,4,3,3,9,6,7,19]\n \n Example 2:\n \n >>> relativeSortArray(arr1 = [28,6,22,8,44,17], arr2 = [22,28,8,6])\n >>> [22,28,8,6,17,44]\n \"\"\"\n"}
{"task_id": "lowest-common-ancestor-of-deepest-leaves", "prompt": "# class TreeNode:\n# def __init__(val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def lcaDeepestLeaves(root: Optional[TreeNode]) -> Optional[TreeNode]:\n \"\"\"\n Given the root of a binary tree, return the lowest common ancestor of its deepest leaves.\n Recall that:\n \n The node of a binary tree is a leaf if and only if it has no children\n The depth of the root of the tree is 0. if the depth of a node is d, the depth of each of its children is d + 1.\n The lowest common ancestor of a set S of nodes, is the node A with the largest depth such that every node in S is in the subtree with root A.\n \n \n Example 1:\n \n \n >>> __init__(root = [3,5,1,6,2,0,8,null,null,7,4])\n >>> [2,7,4]\n Explanation: We return the node with value 2, colored in yellow in the diagram.\n The nodes coloured in blue are the deepest leaf-nodes of the tree.\n Note that nodes 6, 0, and 8 are also leaf nodes, but the depth of them is 2, but the depth of nodes 7 and 4 is 3.\n Example 2:\n \n >>> __init__(root = [1])\n >>> [1]\n Explanation: The root is the deepest node in the tree, and it's the lca of itself.\n \n Example 3:\n \n >>> __init__(root = [0,1,3,null,2])\n >>> [2]\n Explanation: The deepest leaf node in the tree is 2, the lca of one node is itself.\n \"\"\"\n"}
{"task_id": "longest-well-performing-interval", "prompt": "def longestWPI(hours: List[int]) -> int:\n \"\"\"\n We are given hours, a list of the number of hours worked per day for a given employee.\n A day is considered to be a tiring day if and only if the number of hours worked is (strictly) greater than 8.\n A well-performing interval is an interval of days for which the number of tiring days is strictly larger than the number of non-tiring days.\n Return the length of the longest well-performing interval.\n \n Example 1:\n \n >>> longestWPI(hours = [9,9,6,0,6,6,9])\n >>> 3\n Explanation: The longest well-performing interval is [9,9,6].\n \n Example 2:\n \n >>> longestWPI(hours = [6,6,6])\n >>> 0\n \"\"\"\n"}
{"task_id": "smallest-sufficient-team", "prompt": "def smallestSufficientTeam(req_skills: List[str], people: List[List[str]]) -> List[int]:\n \"\"\"\n In a project, you have a list of required skills req_skills, and a list of people. The ith person people[i] contains a list of skills that the person has.\n Consider a sufficient team: a set of people such that for every required skill in req_skills, there is at least one person in the team who has that skill. We can represent these teams by the index of each person.\n \n For example, team = [0, 1, 3] represents the people with skills people[0], people[1], and people[3].\n \n Return any sufficient team of the smallest possible size, represented by the index of each person. You may return the answer in any order.\n It is guaranteed an answer exists.\n \n Example 1:\n >>> smallestSufficientTeam(req_skills = [\"java\",\"nodejs\",\"reactjs\"], people = [[\"java\"],[\"nodejs\"],[\"nodejs\",\"reactjs\"]])\n >>> [0,2]\n Example 2:\n >>> smallestSufficientTeam(req_skills = [\"algorithms\",\"math\",\"java\",\"reactjs\",\"csharp\",\"aws\"], people = [[\"algorithms\",\"math\",\"java\"],[\"algorithms\",\"math\",\"reactjs\"],[\"java\",\"csharp\",\"aws\"],[\"reactjs\",\"csharp\"],[\"csharp\",\"math\"],[\"aws\",\"java\"]])\n >>> [1,2]\n \"\"\"\n"}
{"task_id": "number-of-equivalent-domino-pairs", "prompt": "def numEquivDominoPairs(dominoes: List[List[int]]) -> int:\n \"\"\"\n Given a list of dominoes, dominoes[i] = [a, b] is equivalent to dominoes[j] = [c, d] if and only if either (a == c and b == d), or (a == d and b == c) - that is, one domino can be rotated to be equal to another domino.\n Return the number of pairs (i, j) for which 0 <= i < j < dominoes.length, and dominoes[i] is equivalent to dominoes[j].\n \n Example 1:\n \n >>> numEquivDominoPairs(dominoes = [[1,2],[2,1],[3,4],[5,6]])\n >>> 1\n \n Example 2:\n \n >>> numEquivDominoPairs(dominoes = [[1,2],[1,2],[1,1],[1,2],[2,2]])\n >>> 3\n \"\"\"\n"}
{"task_id": "shortest-path-with-alternating-colors", "prompt": "def shortestAlternatingPaths(n: int, redEdges: List[List[int]], blueEdges: List[List[int]]) -> List[int]:\n \"\"\"\n You are given an integer n, the number of nodes in a directed graph where the nodes are labeled from 0 to n - 1. Each edge is red or blue in this graph, and there could be self-edges and parallel edges.\n You are given two arrays redEdges and blueEdges where:\n \n redEdges[i] = [ai, bi] indicates that there is a directed red edge from node ai to node bi in the graph, and\n blueEdges[j] = [uj, vj] indicates that there is a directed blue edge from node uj to node vj in the graph.\n \n Return an array answer of length n, where each answer[x] is the length of the shortest path from node 0 to node x such that the edge colors alternate along the path, or -1 if such a path does not exist.\n \n Example 1:\n \n >>> shortestAlternatingPaths(n = 3, redEdges = [[0,1],[1,2]], blueEdges = [])\n >>> [0,1,-1]\n \n Example 2:\n \n >>> shortestAlternatingPaths(n = 3, redEdges = [[0,1]], blueEdges = [[2,1]])\n >>> [0,1,-1]\n \"\"\"\n"}
{"task_id": "minimum-cost-tree-from-leaf-values", "prompt": "def mctFromLeafValues(arr: List[int]) -> int:\n \"\"\"\n Given an array arr of positive integers, consider all binary trees such that:\n \n Each node has either 0 or 2 children;\n The values of arr correspond to the values of each leaf in an in-order traversal of the tree.\n The value of each non-leaf node is equal to the product of the largest leaf value in its left and right subtree, respectively.\n \n 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.\n A node is a leaf if and only if it has zero children.\n \n Example 1:\n \n \n >>> mctFromLeafValues(arr = [6,2,4])\n >>> 32\n Explanation: There are two possible trees shown.\n The first has a non-leaf node sum 36, and the second has non-leaf node sum 32.\n \n Example 2:\n \n \n >>> mctFromLeafValues(arr = [4,11])\n >>> 44\n \"\"\"\n"}
{"task_id": "maximum-of-absolute-value-expression", "prompt": "def maxAbsValExpr(arr1: List[int], arr2: List[int]) -> int:\n \"\"\"\n Given two arrays of integers with equal lengths, return the maximum value of:\\r\n \\r\n |arr1[i] - arr1[j]| + |arr2[i] - arr2[j]| + |i - j|\\r\n \\r\n where the maximum is taken over all 0 <= i, j < arr1.length.\\r\n \n \n Example 1:\n \n >>> maxAbsValExpr(arr1 = [1,2,3,4], arr2 = [-1,4,5,6])\n >>> 13\n \n Example 2:\n \n >>> maxAbsValExpr(arr1 = [1,-2,-5,0,10], arr2 = [0,-2,-1,-7,-4])\n >>> 20\n \"\"\"\n"}
{"task_id": "largest-unique-number", "prompt": "def largestUniqueNumber(nums: List[int]) -> int:\n \"\"\"\n Given an integer array nums, return the largest integer that only occurs once. If no integer occurs once, return -1.\n \n Example 1:\n \n >>> largestUniqueNumber(nums = [5,7,3,9,4,9,8,3,1])\n >>> 8\n Explanation: The maximum integer in the array is 9 but it is repeated. The number 8 occurs only once, so it is the answer.\n Example 2:\n \n >>> largestUniqueNumber(nums = [9,9,8,8])\n >>> -1\n Explanation: There is no number that occurs only once.\n \"\"\"\n"}
{"task_id": "armstrong-number", "prompt": "def isArmstrong(n: int) -> bool:\n \"\"\"\n Given an integer n, return true if and only if it is an Armstrong number.\n The k-digit number n is an Armstrong number if and only if the kth power of each digit sums to n.\n \n Example 1:\n \n >>> isArmstrong(n = 153)\n >>> true\n Explanation: 153 is a 3-digit number, and 153 = 13 + 53 + 33.\n \n Example 2:\n \n >>> isArmstrong(n = 123)\n >>> false\n Explanation: 123 is a 3-digit number, and 123 != 13 + 23 + 33 = 36.\n \"\"\"\n"}
{"task_id": "connecting-cities-with-minimum-cost", "prompt": "def minimumCost(n: int, connections: List[List[int]]) -> int:\n \"\"\"\n 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.\n 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,\n The cost is the sum of the connections' costs used.\n \n Example 1:\n \n \n >>> minimumCost(n = 3, connections = [[1,2,5],[1,3,6],[2,3,1]])\n >>> 6\n Explanation: Choosing any 2 edges will connect all cities so we choose the minimum 2.\n \n Example 2:\n \n \n >>> minimumCost(n = 4, connections = [[1,2,3],[3,4,4]])\n >>> -1\n Explanation: There is no way to connect all cities even if all edges are used.\n \"\"\"\n"}
{"task_id": "parallel-courses", "prompt": "def minimumSemesters(n: int, relations: List[List[int]]) -> int:\n \"\"\"\n 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.\n 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.\n Return the minimum number of semesters needed to take all courses. If there is no way to take all the courses, return -1.\n \n Example 1:\n \n \n >>> minimumSemesters(n = 3, relations = [[1,3],[2,3]])\n >>> 2\n Explanation: The figure above represents the given graph.\n In the first semester, you can take courses 1 and 2.\n In the second semester, you can take course 3.\n \n Example 2:\n \n \n >>> minimumSemesters(n = 3, relations = [[1,2],[2,3],[3,1]])\n >>> -1\n Explanation: No course can be studied because they are prerequisites of each other.\n \"\"\"\n"}
{"task_id": "n-th-tribonacci-number", "prompt": "def tribonacci(n: int) -> int:\n \"\"\"\n The Tribonacci sequence Tn is defined as follows:\n T0 = 0, T1 = 1, T2 = 1, and Tn+3 = Tn + Tn+1 + Tn+2 for n >= 0.\n Given n, return the value of Tn.\n \n Example 1:\n \n >>> tribonacci(n = 4)\n >>> 4\n Explanation:\n T_3 = 0 + 1 + 1 = 2\n T_4 = 1 + 1 + 2 = 4\n \n Example 2:\n \n >>> tribonacci(n = 25)\n >>> 1389537\n \"\"\"\n"}
{"task_id": "alphabet-board-path", "prompt": "def alphabetBoardPath(target: str) -> str:\n \"\"\"\n On an alphabet board, we start at position (0, 0), corresponding to character\u00a0board[0][0].\\r\n \\r\n Here, board = [\"abcde\", \"fghij\", \"klmno\", \"pqrst\", \"uvwxy\", \"z\"], as shown in the diagram below.\\r\n \\r\n \\r\n \\r\n We may make the following moves:\\r\n \\r\n \\r\n \t'U' moves our position up one row, if the position exists on the board;\\r\n \t'D' moves our position down one row, if the position exists on the board;\\r\n \t'L' moves our position left one column, if the position exists on the board;\\r\n \t'R' moves our position right one column, if the position exists on the board;\\r\n \t'!'\u00a0adds the character board[r][c] at our current position (r, c)\u00a0to the\u00a0answer.\\r\n \\r\n \\r\n (Here, the only positions that exist on the board are positions with letters on them.)\\r\n \\r\n Return a sequence of moves that makes our answer equal to target\u00a0in the minimum number of moves.\u00a0 You may return any path that does so.\\r\n \\r\n \u00a0\\r\n Example 1:\\r\n >>> alphabetBoardPath(target = \"leet\"\\r)\n >>> \"DDR!UURRR!!DDD!\"\\r\n Example 2:\\r\n >>> alphabetBoardPath(target = \"code\"\\r)\n >>> \"RR!DDRR!UUL!R!\"\\r\n \\r\n \u00a0\\r\n \"\"\"\n"}
{"task_id": "largest-1-bordered-square", "prompt": "def largest1BorderedSquare(grid: List[List[int]]) -> int:\n \"\"\"\n Given a 2D grid of 0s and 1s, return the number of elements in\u00a0the largest square\u00a0subgrid that has all 1s on its border, or 0 if such a subgrid\u00a0doesn't exist in the grid.\\r\n \\r\n \u00a0\\r\n Example 1:\\r\n \\r\n \\r\n >>> largest1BorderedSquare(grid = [[1,1,1],[1,0,1],[1,1,1]]\\r)\n >>> 9\\r\n \\r\n \\r\n Example 2:\\r\n \\r\n \\r\n >>> largest1BorderedSquare(grid = [[1,1,0,0]]\\r)\n >>> 1\\r\n \\r\n \\r\n \u00a0\\r\n \"\"\"\n"}
{"task_id": "stone-game-ii", "prompt": "def stoneGameII(piles: List[int]) -> int:\n \"\"\"\n 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.\n Alice and Bob take turns, with Alice starting first.\n 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.\n The game continues until all the stones have been taken.\n Assuming Alice and Bob play optimally, return the maximum number of stones Alice can get.\n \n Example 1:\n \n >>> stoneGameII(piles = [2,7,9,4,4])\n >>> 10\n Explanation:\n \n 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.\n 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.\n \n So we return 10 since it's larger.\n \n Example 2:\n \n >>> stoneGameII(piles = [1,2,3,4,5,100])\n >>> 104\n \"\"\"\n"}
{"task_id": "longest-common-subsequence", "prompt": "def longestCommonSubsequence(text1: str, text2: str) -> int:\n \"\"\"\n Given two strings text1 and text2, return the length of their longest common subsequence. If there is no common subsequence, return 0.\n 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.\n \n For example, \"ace\" is a subsequence of \"abcde\".\n \n A common subsequence of two strings is a subsequence that is common to both strings.\n \n Example 1:\n \n >>> longestCommonSubsequence(text1 = \"abcde\", text2 = \"ace\")\n >>> 3\n Explanation: The longest common subsequence is \"ace\" and its length is 3.\n \n Example 2:\n \n >>> longestCommonSubsequence(text1 = \"abc\", text2 = \"abc\")\n >>> 3\n Explanation: The longest common subsequence is \"abc\" and its length is 3.\n \n Example 3:\n \n >>> longestCommonSubsequence(text1 = \"abc\", text2 = \"def\")\n >>> 0\n Explanation: There is no such common subsequence, so the result is 0.\n \"\"\"\n"}
{"task_id": "decrease-elements-to-make-array-zigzag", "prompt": "def movesToMakeZigzag(nums: List[int]) -> int:\n \"\"\"\n Given an array nums of integers, a move\u00a0consists of choosing any element and decreasing it by 1.\n An array A is a\u00a0zigzag array\u00a0if either:\n \n Every even-indexed element is greater than adjacent elements, ie.\u00a0A[0] > A[1] < A[2] > A[3] < A[4] > ...\n OR, every odd-indexed element is greater than adjacent elements, ie.\u00a0A[0] < A[1] > A[2] < A[3] > A[4] < ...\n \n Return the minimum number of moves to transform the given array nums into a zigzag array.\n \n Example 1:\n \n >>> movesToMakeZigzag(nums = [1,2,3])\n >>> 2\n Explanation: We can decrease 2 to 0 or 3 to 1.\n \n Example 2:\n \n >>> movesToMakeZigzag(nums = [9,6,1,6,2])\n >>> 4\n \"\"\"\n"}
{"task_id": "binary-tree-coloring-game", "prompt": "# class TreeNode:\n# def __init__(val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def btreeGameWinningMove(root: Optional[TreeNode], n: int, x: int) -> bool:\n \"\"\"\n 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.\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.\n 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.)\n 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.\n 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.\n \n Example 1:\n \n \n >>> __init__(root = [1,2,3,4,5,6,7,8,9,10,11], n = 11, x = 3)\n >>> true\n Explanation: The second player can choose the node with value 2.\n \n Example 2:\n \n >>> __init__(root = [1,2,3], n = 3, x = 1)\n >>> false\n \"\"\"\n"}
{"task_id": "longest-chunked-palindrome-decomposition", "prompt": "def longestDecomposition(text: str) -> int:\n \"\"\"\n You are given a string text. You should split it to k substrings (subtext1, subtext2, ..., subtextk) such that:\n \n subtexti is a non-empty string.\n The concatenation of all the substrings is equal to text (i.e., subtext1 + subtext2 + ... + subtextk == text).\n subtexti == subtextk - i + 1 for all valid values of i (i.e., 1 <= i <= k).\n \n Return the largest possible value of k.\n \n Example 1:\n \n >>> longestDecomposition(text = \"ghiabcdefhelloadamhelloabcdefghi\")\n >>> 7\n Explanation: We can split the string on \"(ghi)(abcdef)(hello)(adam)(hello)(abcdef)(ghi)\".\n \n Example 2:\n \n >>> longestDecomposition(text = \"merchant\")\n >>> 1\n Explanation: We can split the string on \"(merchant)\".\n \n Example 3:\n \n >>> longestDecomposition(text = \"antaprezatepzapreanta\")\n >>> 11\n Explanation: We can split the string on \"(a)(nt)(a)(pre)(za)(tep)(za)(pre)(a)(nt)(a)\".\n \"\"\"\n"}
{"task_id": "check-if-a-number-is-majority-element-in-a-sorted-array", "prompt": "def isMajorityElement(nums: List[int], target: int) -> bool:\n \"\"\"\n 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.\n A majority element in an array nums is an element that appears more than nums.length / 2 times in the array.\n \n Example 1:\n \n >>> isMajorityElement(nums = [2,4,5,5,5,5,5,6,6], target = 5)\n >>> true\n Explanation: The value 5 appears 5 times and the length of the array is 9.\n Thus, 5 is a majority element because 5 > 9/2 is true.\n \n Example 2:\n \n >>> isMajorityElement(nums = [10,100,101,101], target = 101)\n >>> false\n Explanation: The value 101 appears 2 times and the length of the array is 4.\n Thus, 101 is not a majority element because 2 > 4/2 is false.\n \"\"\"\n"}
{"task_id": "minimum-swaps-to-group-all-1s-together", "prompt": "def minSwaps(data: List[int]) -> int:\n \"\"\"\n Given a\u00a0binary array data, return\u00a0the minimum number of swaps required to group all 1\u2019s present in the array together in any place in the array.\n \n Example 1:\n \n >>> minSwaps(data = [1,0,1,0,1])\n >>> 1\n Explanation: There are 3 ways to group all 1's together:\n [1,1,1,0,0] using 1 swap.\n [0,1,1,1,0] using 2 swaps.\n [0,0,1,1,1] using 1 swap.\n The minimum is 1.\n \n Example 2:\n \n >>> minSwaps(data = [0,0,0,1,0])\n >>> 0\n Explanation: Since there is only one 1 in the array, no swaps are needed.\n \n Example 3:\n \n >>> minSwaps(data = [1,0,1,0,1,0,0,1,1,0,1])\n >>> 3\n Explanation: One possible solution that uses 3 swaps is [0,0,0,0,0,1,1,1,1,1,1].\n \"\"\"\n"}
{"task_id": "analyze-user-website-visit-pattern", "prompt": "def mostVisitedPattern(username: List[str], timestamp: List[int], website: List[str]) -> List[str]:\n \"\"\"\n 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].\n A pattern is a list of three websites (not necessarily distinct).\n \n For example, [\"home\", \"away\", \"love\"], [\"leetcode\", \"love\", \"leetcode\"], and [\"luffy\", \"luffy\", \"luffy\"] are all patterns.\n \n 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.\n \n 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.\n 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.\n 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.\n \n 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.\n 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.\n \n Example 1:\n \n >>> 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\"])\n >>> [\"home\",\"about\",\"career\"]\n Explanation: The tuples in this example are:\n [\"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].\n The pattern (\"home\", \"about\", \"career\") has score 2 (joe and mary).\n The pattern (\"home\", \"cart\", \"maps\") has score 1 (james).\n The pattern (\"home\", \"cart\", \"home\") has score 1 (james).\n The pattern (\"home\", \"maps\", \"home\") has score 1 (james).\n The pattern (\"cart\", \"maps\", \"home\") has score 1 (james).\n The pattern (\"home\", \"home\", \"home\") has score 0 (no user visited home 3 times).\n \n Example 2:\n \n >>> mostVisitedPattern(username = [\"ua\",\"ua\",\"ua\",\"ub\",\"ub\",\"ub\"], timestamp = [1,2,3,4,5,6], website = [\"a\",\"b\",\"a\",\"a\",\"b\",\"c\"])\n >>> [\"a\",\"b\",\"a\"]\n \"\"\"\n"}
{"task_id": "string-transforms-into-another-string", "prompt": "def canConvert(str1: str, str2: str) -> bool:\n \"\"\"\n Given two strings str1 and str2 of the same length, determine whether you can transform str1 into str2 by doing zero or more conversions.\n In one conversion you can convert all occurrences of one character in str1 to any other lowercase English character.\n Return true if and only if you can transform str1 into str2.\n \n Example 1:\n \n >>> canConvert(str1 = \"aabcc\", str2 = \"ccdee\")\n >>> true\n Explanation: Convert 'c' to 'e' then 'b' to 'd' then 'a' to 'c'. Note that the order of conversions matter.\n \n Example 2:\n \n >>> canConvert(str1 = \"leetcode\", str2 = \"codeleet\")\n >>> false\n Explanation: There is no way to transform str1 to str2.\n \"\"\"\n"}
{"task_id": "day-of-the-year", "prompt": "def dayOfYear(date: str) -> int:\n \"\"\"\n Given a string date representing a Gregorian calendar date formatted as YYYY-MM-DD, return the day number of the year.\n \n Example 1:\n \n >>> dayOfYear(date = \"2019-01-09\")\n >>> 9\n Explanation: Given date is the 9th day of the year in 2019.\n \n Example 2:\n \n >>> dayOfYear(date = \"2019-02-10\")\n >>> 41\n \"\"\"\n"}
{"task_id": "number-of-dice-rolls-with-target-sum", "prompt": "def numRollsToTarget(n: int, k: int, target: int) -> int:\n \"\"\"\n You have n dice, and each dice has k faces numbered from 1 to k.\n 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.\n \n Example 1:\n \n >>> numRollsToTarget(n = 1, k = 6, target = 3)\n >>> 1\n Explanation: You throw one die with 6 faces.\n There is only one way to get a sum of 3.\n \n Example 2:\n \n >>> numRollsToTarget(n = 2, k = 6, target = 7)\n >>> 6\n Explanation: You throw two dice, each with 6 faces.\n There are 6 ways to get a sum of 7: 1+6, 2+5, 3+4, 4+3, 5+2, 6+1.\n \n Example 3:\n \n >>> numRollsToTarget(n = 30, k = 30, target = 500)\n >>> 222616187\n Explanation: The answer must be returned modulo 109 + 7.\n \"\"\"\n"}
{"task_id": "swap-for-longest-repeated-character-substring", "prompt": "def maxRepOpt1(text: str) -> int:\n \"\"\"\n You are given a string text. You can swap two of the characters in the text.\n Return the length of the longest substring with repeated characters.\n \n Example 1:\n \n >>> maxRepOpt1(text = \"ababa\")\n >>> 3\n 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.\n \n Example 2:\n \n >>> maxRepOpt1(text = \"aaabaaa\")\n >>> 6\n Explanation: Swap 'b' with the last 'a' (or the first 'a'), and we get longest repeated character substring \"aaaaaa\" with length 6.\n \n Example 3:\n \n >>> maxRepOpt1(text = \"aaaaa\")\n >>> 5\n Explanation: No need to swap, longest repeated character substring is \"aaaaa\" with length is 5.\n \"\"\"\n"}
{"task_id": "find-words-that-can-be-formed-by-characters", "prompt": "def countCharacters(words: List[str], chars: str) -> int:\n \"\"\"\n You are given an array of strings words and a string chars.\n A string is good if it can be formed by characters from chars (each character can only be used once).\n Return the sum of lengths of all good strings in words.\n \n Example 1:\n \n >>> countCharacters(words = [\"cat\",\"bt\",\"hat\",\"tree\"], chars = \"atach\")\n >>> 6\n Explanation: The strings that can be formed are \"cat\" and \"hat\" so the answer is 3 + 3 = 6.\n \n Example 2:\n \n >>> countCharacters(words = [\"hello\",\"world\",\"leetcode\"], chars = \"welldonehoneyr\")\n >>> 10\n Explanation: The strings that can be formed are \"hello\" and \"world\" so the answer is 5 + 5 = 10.\n \"\"\"\n"}
{"task_id": "maximum-level-sum-of-a-binary-tree", "prompt": "# class TreeNode:\n# def __init__(val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def maxLevelSum(root: Optional[TreeNode]) -> int:\n \"\"\"\n Given the root of a binary tree, the level of its root is 1, the level of its children is 2, and so on.\n Return the smallest level x such that the sum of all the values of nodes at level x is maximal.\n \n Example 1:\n \n \n >>> __init__(root = [1,7,0,7,-8,null,null])\n >>> 2\n Explanation:\n Level 1 sum = 1.\n Level 2 sum = 7 + 0 = 7.\n Level 3 sum = 7 + -8 = -1.\n So we return the level with the maximum sum which is level 2.\n \n Example 2:\n \n >>> __init__(root = [989,null,10250,98693,-89388,null,null,null,-32127])\n >>> 2\n \"\"\"\n"}
{"task_id": "as-far-from-land-as-possible", "prompt": "def maxDistance(grid: List[List[int]]) -> int:\n \"\"\"\n Given an n x n grid\u00a0containing only values 0 and 1, where\u00a00 represents water\u00a0and 1 represents land, find a water cell such that its distance to the nearest land cell is maximized, and return the distance.\u00a0If no land or water exists in the grid, return -1.\n The distance used in this problem is the Manhattan distance:\u00a0the distance between two cells (x0, y0) and (x1, y1) is |x0 - x1| + |y0 - y1|.\n \n Example 1:\n \n \n >>> maxDistance(grid = [[1,0,1],[0,0,0],[1,0,1]])\n >>> 2\n Explanation: The cell (1, 1) is as far as possible from all the land with distance 2.\n \n Example 2:\n \n \n >>> maxDistance(grid = [[1,0,0],[0,0,0],[0,0,0]])\n >>> 4\n Explanation: The cell (2, 2) is as far as possible from all the land with distance 4.\n \"\"\"\n"}
{"task_id": "last-substring-in-lexicographical-order", "prompt": "def lastSubstring(s: str) -> str:\n \"\"\"\n Given a string s, return the last substring of s in lexicographical order.\n \n Example 1:\n \n >>> lastSubstring(s = \"abab\")\n >>> \"bab\"\n Explanation: The substrings are [\"a\", \"ab\", \"aba\", \"abab\", \"b\", \"ba\", \"bab\"]. The lexicographically maximum substring is \"bab\".\n \n Example 2:\n \n >>> lastSubstring(s = \"leetcode\")\n >>> \"tcode\"\n \"\"\"\n"}
{"task_id": "single-row-keyboard", "prompt": "def calculateTime(keyboard: str, word: str) -> int:\n \"\"\"\n There is a special keyboard with all keys in a single row.\n 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|.\n You want to type a string word. Write a function to calculate how much time it takes to type it with one finger.\n \n Example 1:\n \n >>> calculateTime(keyboard = \"abcdefghijklmnopqrstuvwxyz\", word = \"cba\")\n >>> 4\n Explanation: The index moves from 0 to 2 to write 'c' then to 1 to write 'b' then to 0 again to write 'a'.\n Total time = 2 + 1 + 1 = 4.\n \n Example 2:\n \n >>> calculateTime(keyboard = \"pqrstuvwxyzabcdefghijklmno\", word = \"leetcode\")\n >>> 73\n \"\"\"\n"}
{"task_id": "minimum-cost-to-connect-sticks", "prompt": "def connectSticks(sticks: List[int]) -> int:\n \"\"\"\n You have some number of sticks with positive integer lengths. These lengths are given as an array\u00a0sticks, where\u00a0sticks[i]\u00a0is the length of the\u00a0ith\u00a0stick.\n You can connect any two sticks of lengths x and y into one stick\u00a0by paying a cost of x + y. You must connect\u00a0all the sticks until there is only one stick remaining.\n Return\u00a0the minimum cost of connecting all the given sticks into one stick in this way.\n \n Example 1:\n \n >>> connectSticks(sticks = [2,4,3])\n >>> 14\n Explanation:\u00a0You start with sticks = [2,4,3].\n 1. Combine sticks 2 and 3 for a cost of 2 + 3 = 5. Now you have sticks = [5,4].\n 2. Combine sticks 5 and 4 for a cost of 5 + 4 = 9. Now you have sticks = [9].\n There is only one stick left, so you are done. The total cost is 5 + 9 = 14.\n \n Example 2:\n \n >>> connectSticks(sticks = [1,8,3,5])\n >>> 30\n Explanation: You start with sticks = [1,8,3,5].\n 1. Combine sticks 1 and 3 for a cost of 1 + 3 = 4. Now you have sticks = [4,8,5].\n 2. Combine sticks 4 and 5 for a cost of 4 + 5 = 9. Now you have sticks = [9,8].\n 3. Combine sticks 9 and 8 for a cost of 9 + 8 = 17. Now you have sticks = [17].\n There is only one stick left, so you are done. The total cost is 4 + 9 + 17 = 30.\n \n Example 3:\n \n >>> connectSticks(sticks = [5])\n >>> 0\n Explanation: There is only one stick, so you don't need to do anything. The total cost is 0.\n \"\"\"\n"}
{"task_id": "optimize-water-distribution-in-a-village", "prompt": "def minCostToSupplyWater(n: int, wells: List[int], pipes: List[List[int]]) -> int:\n \"\"\"\n There are n houses in a village. We want to supply water for all the houses by building wells and laying pipes.\n 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.\n Return the minimum total cost to supply water to all houses.\n \n Example 1:\n \n \n >>> minCostToSupplyWater(n = 3, wells = [1,2,2], pipes = [[1,2,1],[2,3,1]])\n >>> 3\n Explanation: The image shows the costs of connecting houses using pipes.\n 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.\n \n Example 2:\n \n >>> minCostToSupplyWater(n = 2, wells = [1,1], pipes = [[1,2,1],[1,2,2]])\n >>> 2\n Explanation: We can supply water with cost two using one of the three options:\n Option 1:\n - Build a well inside house 1 with cost 1.\n - Build a well inside house 2 with cost 1.\n The total cost will be 2.\n Option 2:\n - Build a well inside house 1 with cost 1.\n - Connect house 2 with house 1 with cost 1.\n The total cost will be 2.\n Option 3:\n - Build a well inside house 2 with cost 1.\n - Connect house 1 with house 2 with cost 1.\n The total cost will be 2.\n Note that we can connect houses 1 and 2 with cost 1 or with cost 2 but we will always choose the cheapest option.\n \"\"\"\n"}
{"task_id": "invalid-transactions", "prompt": "def invalidTransactions(transactions: List[str]) -> List[str]:\n \"\"\"\n A transaction is possibly invalid if:\n \n the amount exceeds $1000, or;\n if it occurs within (and including) 60 minutes of another transaction with the same name in a different city.\n \n 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.\n Return a list of transactions that are possibly invalid. You may return the answer in any order.\n \n Example 1:\n \n >>> invalidTransactions(transactions = [\"alice,20,800,mtv\",\"alice,50,100,beijing\"])\n >>> [\"alice,20,800,mtv\",\"alice,50,100,beijing\"]\n 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.\n Example 2:\n \n >>> invalidTransactions(transactions = [\"alice,20,800,mtv\",\"alice,50,1200,mtv\"])\n >>> [\"alice,50,1200,mtv\"]\n \n Example 3:\n \n >>> invalidTransactions(transactions = [\"alice,20,800,mtv\",\"bob,50,1200,mtv\"])\n >>> [\"bob,50,1200,mtv\"]\n \"\"\"\n"}
{"task_id": "compare-strings-by-frequency-of-the-smallest-character", "prompt": "def numSmallerByFrequency(queries: List[str], words: List[str]) -> List[int]:\n \"\"\"\n 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.\n 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.\n Return an integer array answer, where each answer[i] is the answer to the ith query.\n \n Example 1:\n \n >>> numSmallerByFrequency(queries = [\"cbd\"], words = [\"zaaaz\"])\n >>> [1]\n Explanation: On the first query we have f(\"cbd\") = 1, f(\"zaaaz\") = 3 so f(\"cbd\") < f(\"zaaaz\").\n \n Example 2:\n \n >>> numSmallerByFrequency(queries = [\"bbb\",\"cc\"], words = [\"a\",\"aa\",\"aaa\",\"aaaa\"])\n >>> [1,2]\n Explanation: On the first query only f(\"bbb\") < f(\"aaaa\"). On the second query both f(\"aaa\") and f(\"aaaa\") are both > f(\"cc\").\n \"\"\"\n"}
{"task_id": "remove-zero-sum-consecutive-nodes-from-linked-list", "prompt": "# class ListNode:\n# def __init__(val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution:\n def removeZeroSumSublists(head: Optional[ListNode]) -> Optional[ListNode]:\n \"\"\"\n 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\n \\r\n After doing so, return the head of the final linked list.\u00a0 You may return any such answer.\\r\n \n \n (Note that in the examples below, all sequences are serializations of ListNode objects.)\n Example 1:\n \n >>> __init__(head = [1,2,-3,3,1])\n >>> [3,1]\n Note: The answer [1,2,1] would also be accepted.\n \n Example 2:\n \n >>> __init__(head = [1,2,3,-3,4])\n >>> [1,2,4]\n \n Example 3:\n \n >>> __init__(head = [1,2,3,-3,-2])\n >>> [1]\n \"\"\"\n"}
{"task_id": "prime-arrangements", "prompt": "def numPrimeArrangements(n: int) -> int:\n \"\"\"\n Return the number of permutations of 1 to n so that prime numbers are at prime indices (1-indexed.)\n (Recall that an integer\u00a0is prime if and only if it is greater than 1, and cannot be written as a product of two positive integers\u00a0both smaller than it.)\n Since the answer may be large, return the answer modulo 10^9 + 7.\n \n Example 1:\n \n >>> numPrimeArrangements(n = 5)\n >>> 12\n 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.\n \n Example 2:\n \n >>> numPrimeArrangements(n = 100)\n >>> 682289015\n \"\"\"\n"}
{"task_id": "diet-plan-performance", "prompt": "def dietPlanPerformance(calories: List[int], k: int, lower: int, upper: int) -> int:\n \"\"\"\n A dieter consumes\u00a0calories[i]\u00a0calories on the i-th day.\n Given an integer k, for every consecutive sequence of k days (calories[i], calories[i+1], ..., calories[i+k-1]\u00a0for 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]):\n \n If T < lower, they performed poorly on their diet and lose 1 point;\n If T > upper, they performed well on their diet and gain 1 point;\n Otherwise, they performed normally and there is no change in points.\n \n Initially, the dieter has zero points. Return the total number of points the dieter has after dieting for calories.length\u00a0days.\n Note that the total points can be negative.\n \n Example 1:\n \n >>> dietPlanPerformance(calories = [1,2,3,4,5], k = 1, lower = 3, upper = 3)\n >>> 0\n Explanation: Since k = 1, we consider each element of the array separately and compare it to lower and upper.\n calories[0] and calories[1] are less than lower so 2 points are lost.\n calories[3] and calories[4] are greater than upper so 2 points are gained.\n \n Example 2:\n \n >>> dietPlanPerformance(calories = [3,2], k = 2, lower = 0, upper = 1)\n >>> 1\n Explanation: Since k = 2, we consider subarrays of length 2.\n calories[0] + calories[1] > upper so 1 point is gained.\n \n Example 3:\n \n >>> dietPlanPerformance(calories = [6,5,0,0], k = 2, lower = 1, upper = 5)\n >>> 0\n Explanation:\n calories[0] + calories[1] > upper so 1 point is gained.\n lower <= calories[1] + calories[2] <= upper so no change in points.\n calories[2] + calories[3] < lower so 1 point is lost.\n \"\"\"\n"}
{"task_id": "can-make-palindrome-from-substring", "prompt": "def canMakePaliQueries(s: str, queries: List[List[int]]) -> List[bool]:\n \"\"\"\n 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.\n 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.\n Return a boolean array answer where answer[i] is the result of the ith query queries[i].\n 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.\n \n Example :\n \n >>> canMakePaliQueries(s = \"abcda\", queries = [[3,3,0],[1,2,0],[0,3,1],[0,3,2],[0,4,1]])\n >>> [true,false,false,true,true]\n Explanation:\n queries[0]: substring = \"d\", is palidrome.\n queries[1]: substring = \"bc\", is not palidrome.\n queries[2]: substring = \"abcd\", is not palidrome after replacing only 1 character.\n 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\".\n queries[4]: substring = \"abcda\", could be changed to \"abcba\" which is palidrome.\n \n Example 2:\n \n >>> canMakePaliQueries(s = \"lyb\", queries = [[0,1,0],[2,2,1]])\n >>> [false,true]\n \"\"\"\n"}
{"task_id": "number-of-valid-words-for-each-puzzle", "prompt": "def findNumOfValidWords(words: List[str], puzzles: List[str]) -> List[int]:\n \"\"\"\n With respect to a given puzzle string, a word is valid if both the following conditions are satisfied:\n \n word contains the first letter of puzzle.\n For each letter in word, that letter is in puzzle.\n \n For example, if the puzzle is \"abcdefg\", then valid words are \"faced\", \"cabbage\", and \"baggage\", while\n invalid words are \"beefed\" (does not include 'a') and \"based\" (includes 's' which is not in the puzzle).\n \n \n \n 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].\n \n Example 1:\n \n >>> findNumOfValidWords(words = [\"aaaa\",\"asas\",\"able\",\"ability\",\"actt\",\"actor\",\"access\"], puzzles = [\"aboveyz\",\"abrodyz\",\"abslute\",\"absoryz\",\"actresz\",\"gaswxyz\"])\n >>> [1,1,3,2,4,0]\n Explanation:\n 1 valid word for \"aboveyz\" : \"aaaa\"\n 1 valid word for \"abrodyz\" : \"aaaa\"\n 3 valid words for \"abslute\" : \"aaaa\", \"asas\", \"able\"\n 2 valid words for \"absoryz\" : \"aaaa\", \"asas\"\n 4 valid words for \"actresz\" : \"aaaa\", \"asas\", \"actt\", \"access\"\n There are no valid words for \"gaswxyz\" cause none of the words in the list contains letter 'g'.\n \n Example 2:\n \n >>> findNumOfValidWords(words = [\"apple\",\"pleas\",\"please\"], puzzles = [\"aelwxyz\",\"aelpxyz\",\"aelpsxy\",\"saelpxy\",\"xaelpsy\"])\n >>> [0,1,3,2,0]\n \"\"\"\n"}
{"task_id": "count-substrings-with-only-one-distinct-letter", "prompt": "def countLetters(s: str) -> int:\n \"\"\"\n Given a string s, return the number of substrings that have only one distinct letter.\n \n Example 1:\n \n >>> countLetters(s = \"aaaba\")\n >>> 8\n Explanation: The substrings with one distinct letter are \"aaa\", \"aa\", \"a\", \"b\".\n \"aaa\" occurs 1 time.\n \"aa\" occurs 2 times.\n \"a\" occurs 4 times.\n \"b\" occurs 1 time.\n So the answer is 1 + 2 + 4 + 1 = 8.\n \n Example 2:\n \n >>> countLetters(s = \"aaaaaaaaaa\")\n >>> 55\n \"\"\"\n"}
{"task_id": "before-and-after-puzzle", "prompt": "def beforeAndAfterPuzzles(phrases: List[str]) -> List[str]:\n \"\"\"\n Given a list of phrases, generate a list of\u00a0Before and After puzzles.\n 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\u00a0no consecutive spaces\u00a0in a phrase.\n Before and After\u00a0puzzles are phrases that are formed by merging\u00a0two phrases where the last\u00a0word of the first\u00a0phrase is the same as the first word of the second phrase.\n Return the\u00a0Before and After\u00a0puzzles that can be formed by every two phrases\u00a0phrases[i]\u00a0and\u00a0phrases[j]\u00a0where\u00a0i != j. Note that the order of matching two phrases matters, we want to consider both orders.\n You should return a list of\u00a0distinct\u00a0strings sorted\u00a0lexicographically.\n \n Example 1:\n \n >>> beforeAndAfterPuzzles(phrases = [\"writing code\",\"code rocks\"])\n >>> [\"writing code rocks\"]\n \n Example 2:\n \n \"a quick bite to eat\",\n \u00a0 \"a chip off the old block\",\n \u00a0 \"chocolate bar\",\n \u00a0 \"mission impossible\",\n \u00a0 \"a man on a mission\",\n \u00a0 \"block party\",\n \u00a0 \"eat my words\",\n \u00a0 \"bar of soap\"]\n >>> beforeAndAfterPuzzles(phrases = [\"mission statement\",)\n >>> [\"a chip off the old block party\",\n \u00a0 \"a man on a mission impossible\",\n \u00a0 \"a man on a mission statement\",\n \u00a0 \"a quick bite to eat my words\",\n \"chocolate bar of soap\"]\n \n Example 3:\n \n >>> beforeAndAfterPuzzles(phrases = [\"a\",\"b\",\"a\"])\n >>> [\"a\"]\n \"\"\"\n"}
{"task_id": "shortest-distance-to-target-color", "prompt": "def shortestDistanceColor(colors: List[int], queries: List[List[int]]) -> List[int]:\n \"\"\"\n You are given an array colors, in which there are three colors: 1, 2 and\u00a03.\n You are also given some queries. Each query consists of two integers i\u00a0and c, return\u00a0the shortest distance between the given index\u00a0i and the target color c. If there is no solution return -1.\n \n Example 1:\n \n >>> shortestDistanceColor(colors = [1,1,2,1,3,2,2,3,3], queries = [[1,3],[2,2],[6,1]])\n >>> [3,0,3]\n Explanation:\n The nearest 3 from index 1 is at index 4 (3 steps away).\n The nearest 2 from index 2 is at index 2 itself (0 steps away).\n The nearest 1 from index 6 is at index 3 (3 steps away).\n \n Example 2:\n \n >>> shortestDistanceColor(colors = [1,2], queries = [[0,3]])\n >>> [-1]\n Explanation: There is no 3 in the array.\n \"\"\"\n"}
{"task_id": "maximum-number-of-ones", "prompt": "def maximumNumberOfOnes(width: int, height: int, sideLength: int, maxOnes: int) -> int:\n \"\"\"\n Consider a matrix M with dimensions width * height, such that every cell has value 0\u00a0or 1, and any square\u00a0sub-matrix of M of size sideLength * sideLength\u00a0has at most maxOnes\u00a0ones.\n Return the maximum possible number of ones that the matrix M can have.\n \n Example 1:\n \n >>> maximumNumberOfOnes(width = 3, height = 3, sideLength = 2, maxOnes = 1)\n >>> 4\n Explanation:\n In a 3*3 matrix, no 2*2 sub-matrix can have more than 1 one.\n The best solution that has 4 ones is:\n [1,0,1]\n [0,0,0]\n [1,0,1]\n \n Example 2:\n \n >>> maximumNumberOfOnes(width = 3, height = 3, sideLength = 2, maxOnes = 2)\n >>> 6\n Explanation:\n [1,0,1]\n [1,0,1]\n [1,0,1]\n \"\"\"\n"}
{"task_id": "distance-between-bus-stops", "prompt": "def distanceBetweenBusStops(distance: List[int], start: int, destination: int) -> int:\n \"\"\"\n A bus\u00a0has n stops numbered from 0 to n - 1 that form\u00a0a circle. We know the distance between all pairs of neighboring stops where distance[i] is the distance between the stops number\u00a0i and (i + 1) % n.\\r\n \\r\n The bus goes along both directions\u00a0i.e. clockwise and counterclockwise.\\r\n \\r\n Return the shortest distance between the given\u00a0start\u00a0and destination\u00a0stops.\\r\n \\r\n \u00a0\\r\n Example 1:\\r\n \\r\n \\r\n \\r\n \\r\n >>> distanceBetweenBusStops(distance = [1,2,3,4], start = 0, destination = 1\\r)\n >>> 1\\r\n Explanation: Distance between 0 and 1 is 1 or 9, minimum is 1.\\r\n \\r\n \u00a0\\r\n \\r\n Example 2:\\r\n \\r\n \\r\n \\r\n \\r\n >>> distanceBetweenBusStops(distance = [1,2,3,4], start = 0, destination = 2\\r)\n >>> 3\\r\n Explanation: Distance between 0 and 2 is 3 or 7, minimum is 3.\\r\n \\r\n \\r\n \u00a0\\r\n \\r\n Example 3:\\r\n \\r\n \\r\n \\r\n \\r\n >>> distanceBetweenBusStops(distance = [1,2,3,4], start = 0, destination = 3\\r)\n >>> 4\\r\n Explanation: Distance between 0 and 3 is 6 or 4, minimum is 4.\\r\n \\r\n \\r\n \u00a0\\r\n \"\"\"\n"}
{"task_id": "day-of-the-week", "prompt": "def dayOfTheWeek(day: int, month: int, year: int) -> str:\n \"\"\"\n Given a date, return the corresponding day of the week for that date.\n The input is given as three integers representing the day, month and year respectively.\n Return the answer as one of the following values\u00a0{\"Sunday\", \"Monday\", \"Tuesday\", \"Wednesday\", \"Thursday\", \"Friday\", \"Saturday\"}.\n \n Example 1:\n \n >>> dayOfTheWeek(day = 31, month = 8, year = 2019)\n >>> \"Saturday\"\n \n Example 2:\n \n >>> dayOfTheWeek(day = 18, month = 7, year = 1999)\n >>> \"Sunday\"\n \n Example 3:\n \n >>> dayOfTheWeek(day = 15, month = 8, year = 1993)\n >>> \"Sunday\"\n \"\"\"\n"}
{"task_id": "maximum-subarray-sum-with-one-deletion", "prompt": "def maximumSum(arr: List[int]) -> int:\n \"\"\"\n Given an array of integers, return the maximum sum for a non-empty\u00a0subarray (contiguous elements) with at most one element deletion.\u00a0In 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\u00a0sum of the remaining elements is maximum possible.\n Note that the subarray needs to be non-empty after deleting one element.\n \n Example 1:\n \n >>> maximumSum(arr = [1,-2,0,3])\n >>> 4\n Explanation: Because we can choose [1, -2, 0, 3] and drop -2, thus the subarray [1, 0, 3] becomes the maximum value.\n Example 2:\n \n >>> maximumSum(arr = [1,-2,-2,3])\n >>> 3\n Explanation: We just choose [3] and it's the maximum sum.\n \n Example 3:\n \n >>> maximumSum(arr = [-1,-1,-1,-1])\n >>> -1\n Explanation:\u00a0The 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.\n \"\"\"\n"}
{"task_id": "make-array-strictly-increasing", "prompt": "def makeArrayIncreasing(arr1: List[int], arr2: List[int]) -> int:\n \"\"\"\n Given two integer arrays\u00a0arr1 and arr2, return the minimum number of operations (possibly zero) needed\u00a0to make arr1 strictly increasing.\n In one operation, you can choose two indices\u00a00 <=\u00a0i < arr1.length\u00a0and\u00a00 <= j < arr2.length\u00a0and do the assignment\u00a0arr1[i] = arr2[j].\n If there is no way to make\u00a0arr1\u00a0strictly increasing,\u00a0return\u00a0-1.\n \n Example 1:\n \n >>> makeArrayIncreasing(arr1 = [1,5,3,6,7], arr2 = [1,3,2,4])\n >>> 1\n Explanation: Replace 5 with 2, then arr1 = [1, 2, 3, 6, 7].\n \n Example 2:\n \n >>> makeArrayIncreasing(arr1 = [1,5,3,6,7], arr2 = [4,3,1])\n >>> 2\n Explanation: Replace 5 with 3 and then replace 3 with 4. arr1 = [1, 3, 4, 6, 7].\n \n Example 3:\n \n >>> makeArrayIncreasing(arr1 = [1,5,3,6,7], arr2 = [1,6,3,3])\n >>> -1\n Explanation: You can't make arr1 strictly increasing.\n \"\"\"\n"}
{"task_id": "maximum-number-of-balloons", "prompt": "def maxNumberOfBalloons(text: str) -> int:\n \"\"\"\n Given a string text, you want to use the characters of text to form as many instances of the word \"balloon\" as possible.\n You can use each character in text at most once. Return the maximum number of instances that can be formed.\n \n Example 1:\n \n \n >>> maxNumberOfBalloons(text = \"nlaebolko\")\n >>> 1\n \n Example 2:\n \n \n >>> maxNumberOfBalloons(text = \"loonbalxballpoon\")\n >>> 2\n \n Example 3:\n \n >>> maxNumberOfBalloons(text = \"leetcode\")\n >>> 0\n \"\"\"\n"}
{"task_id": "reverse-substrings-between-each-pair-of-parentheses", "prompt": "def reverseParentheses(s: str) -> str:\n \"\"\"\n You are given a string s that consists of lower case English letters and brackets.\n Reverse the strings in each pair of matching parentheses, starting from the innermost one.\n Your result should not contain any brackets.\n \n Example 1:\n \n >>> reverseParentheses(s = \"(abcd)\")\n >>> \"dcba\"\n \n Example 2:\n \n >>> reverseParentheses(s = \"(u(love)i)\")\n >>> \"iloveu\"\n Explanation: The substring \"love\" is reversed first, then the whole string is reversed.\n \n Example 3:\n \n >>> reverseParentheses(s = \"(ed(et(oc))el)\")\n >>> \"leetcode\"\n Explanation: First, we reverse the substring \"oc\", then \"etco\", and finally, the whole string.\n \"\"\"\n"}
{"task_id": "k-concatenation-maximum-sum", "prompt": "def kConcatenationMaxSum(arr: List[int], k: int) -> int:\n \"\"\"\n Given an integer array arr and an integer k, modify the array by repeating it k times.\n For example, if arr = [1, 2] and k = 3 then the modified array will be [1, 2, 1, 2, 1, 2].\n 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.\n As the answer can be very large, return the answer modulo 109 + 7.\n \n Example 1:\n \n >>> kConcatenationMaxSum(arr = [1,2], k = 3)\n >>> 9\n \n Example 2:\n \n >>> kConcatenationMaxSum(arr = [1,-2,1], k = 5)\n >>> 2\n \n Example 3:\n \n >>> kConcatenationMaxSum(arr = [-1,-2], k = 7)\n >>> 0\n \"\"\"\n"}
{"task_id": "critical-connections-in-a-network", "prompt": "def criticalConnections(n: int, connections: List[List[int]]) -> List[List[int]]:\n \"\"\"\n 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.\n A critical connection is a connection that, if removed, will make some servers unable to reach some other server.\n Return all critical connections in the network in any order.\n \n Example 1:\n \n \n >>> criticalConnections(n = 4, connections = [[0,1],[1,2],[2,0],[1,3]])\n >>> [[1,3]]\n Explanation: [[3,1]] is also accepted.\n \n Example 2:\n \n >>> criticalConnections(n = 2, connections = [[0,1]])\n >>> [[0,1]]\n \"\"\"\n"}
{"task_id": "how-many-apples-can-you-put-into-the-basket", "prompt": "def maxNumberOfApples(weight: List[int]) -> int:\n \"\"\"\n You have some apples and a basket that can carry up to 5000 units of weight.\n 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.\n \n Example 1:\n \n >>> maxNumberOfApples(weight = [100,200,150,1000])\n >>> 4\n Explanation: All 4 apples can be carried by the basket since their sum of weights is 1450.\n \n Example 2:\n \n >>> maxNumberOfApples(weight = [900,950,800,1000,700,800])\n >>> 5\n Explanation: The sum of weights of the 6 apples exceeds 5000 so we choose any 5 of them.\n \"\"\"\n"}
{"task_id": "minimum-knight-moves", "prompt": "def minKnightMoves(x: int, y: int) -> int:\n \"\"\"\n In an infinite chess board with coordinates from -infinity to +infinity, you have a knight at square [0, 0].\n 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.\n \n Return the minimum number of steps needed to move the knight to the square [x, y]. It is guaranteed the answer exists.\n \n Example 1:\n \n >>> minKnightMoves(x = 2, y = 1)\n >>> 1\n Explanation: [0, 0] \u2192 [2, 1]\n \n Example 2:\n \n >>> minKnightMoves(x = 5, y = 5)\n >>> 4\n Explanation: [0, 0] \u2192 [2, 1] \u2192 [4, 2] \u2192 [3, 4] \u2192 [5, 5]\n \"\"\"\n"}
{"task_id": "find-smallest-common-element-in-all-rows", "prompt": "def smallestCommonElement(mat: List[List[int]]) -> int:\n \"\"\"\n Given an m x n matrix mat where every row is sorted in strictly increasing order, return the smallest common element in all rows.\n If there is no common element, return -1.\n \n Example 1:\n \n >>> smallestCommonElement(mat = [[1,2,3,4,5],[2,4,5,8,10],[3,5,7,9,11],[1,3,5,7,9]])\n >>> 5\n \n Example 2:\n \n >>> smallestCommonElement(mat = [[1,2,3],[2,3,4],[2,3,5]])\n >>> 2\n \"\"\"\n"}
{"task_id": "minimum-time-to-build-blocks", "prompt": "def minBuildTime(blocks: List[int], split: int) -> int:\n \"\"\"\n You are given a list of blocks, where blocks[i] = t means that the\u00a0i-th block needs\u00a0t\u00a0units of time to be built. A block can only be built by exactly one worker.\n 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.\n The time cost of spliting one worker into two workers is\u00a0given as an integer split. Note that if two workers split at the same time, they split in parallel so the cost would be\u00a0split.\n Output the minimum time needed to build all blocks.\n Initially, there is only one worker.\n \n Example 1:\n \n >>> minBuildTime(blocks = [1], split = 1)\n >>> 1\n Explanation: We use 1 worker to build 1 block in 1 time unit.\n \n Example 2:\n \n >>> minBuildTime(blocks = [1,2], split = 5)\n >>> 7\n 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.\n \n Example 3:\n \n >>> minBuildTime(blocks = [1,2,3], split = 1)\n >>> 4\n Explanation: Split 1 worker into 2, then assign the first worker to the last block and split the second worker into 2.\n Then, use the two unassigned workers to build the first two blocks.\n The cost is 1 + max(3, 1 + max(1, 2)) = 4.\n \"\"\"\n"}
{"task_id": "minimum-absolute-difference", "prompt": "def minimumAbsDifference(arr: List[int]) -> List[List[int]]:\n \"\"\"\n Given an array of distinct integers arr, find all pairs of elements with the minimum absolute difference of any two elements.\n Return a list of pairs in ascending order(with respect to pairs), each pair [a, b] follows\n \n a, b are from arr\n a < b\n b - a equals to the minimum absolute difference of any two elements in arr\n \n \n Example 1:\n \n >>> minimumAbsDifference(arr = [4,2,1,3])\n >>> [[1,2],[2,3],[3,4]]\n Explanation: The minimum absolute difference is 1. List all pairs with difference equal to 1 in ascending order.\n Example 2:\n \n >>> minimumAbsDifference(arr = [1,3,6,10,15])\n >>> [[1,3]]\n \n Example 3:\n \n >>> minimumAbsDifference(arr = [3,8,-10,23,19,-4,-14,27])\n >>> [[-14,-10],[19,23],[23,27]]\n \"\"\"\n"}
{"task_id": "ugly-number-iii", "prompt": "def nthUglyNumber(n: int, a: int, b: int, c: int) -> int:\n \"\"\"\n An ugly number is a positive integer that is divisible by a, b, or c.\n Given four integers n, a, b, and c, return the nth ugly number.\n \n Example 1:\n \n >>> nthUglyNumber(n = 3, a = 2, b = 3, c = 5)\n >>> 4\n Explanation: The ugly numbers are 2, 3, 4, 5, 6, 8, 9, 10... The 3rd is 4.\n \n Example 2:\n \n >>> nthUglyNumber(n = 4, a = 2, b = 3, c = 4)\n >>> 6\n Explanation: The ugly numbers are 2, 3, 4, 6, 8, 9, 10, 12... The 4th is 6.\n \n Example 3:\n \n >>> nthUglyNumber(n = 5, a = 2, b = 11, c = 13)\n >>> 10\n Explanation: The ugly numbers are 2, 4, 6, 8, 10, 11, 12, 13... The 5th is 10.\n \"\"\"\n"}
{"task_id": "smallest-string-with-swaps", "prompt": "def smallestStringWithSwaps(s: str, pairs: List[List[int]]) -> str:\n \"\"\"\n You are given a string s, and an array of pairs of indices in the string\u00a0pairs\u00a0where\u00a0pairs[i] =\u00a0[a, b]\u00a0indicates 2 indices(0-indexed) of the string.\n You can\u00a0swap the characters at any pair of indices in the given\u00a0pairs\u00a0any number of times.\n Return the\u00a0lexicographically smallest string that s\u00a0can be changed to after using the swaps.\n \n Example 1:\n \n >>> smallestStringWithSwaps(s = \"dcab\", pairs = [[0,3],[1,2]])\n >>> \"bacd\"\n Explaination:\n Swap s[0] and s[3], s = \"bcad\"\n Swap s[1] and s[2], s = \"bacd\"\n \n Example 2:\n \n >>> smallestStringWithSwaps(s = \"dcab\", pairs = [[0,3],[1,2],[0,2]])\n >>> \"abcd\"\n Explaination:\n Swap s[0] and s[3], s = \"bcad\"\n Swap s[0] and s[2], s = \"acbd\"\n Swap s[1] and s[2], s = \"abcd\"\n Example 3:\n \n >>> smallestStringWithSwaps(s = \"cba\", pairs = [[0,1],[1,2]])\n >>> \"abc\"\n Explaination:\n Swap s[0] and s[1], s = \"bca\"\n Swap s[1] and s[2], s = \"bac\"\n Swap s[0] and s[1], s = \"abc\"\n \"\"\"\n"}
{"task_id": "sort-items-by-groups-respecting-dependencies", "prompt": "def sortItems(n: int, m: int, group: List[int], beforeItems: List[List[int]]) -> List[int]:\n \"\"\"\n There are\u00a0n\u00a0items each\u00a0belonging to zero or one of\u00a0m\u00a0groups where group[i]\u00a0is the group that the i-th item belongs to and it's equal to -1\u00a0if 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.\n Return a sorted list of the items such that:\n \n The items that belong to the same group are next to each other in the sorted list.\n There are some\u00a0relations\u00a0between these items where\u00a0beforeItems[i]\u00a0is a list containing all the items that should come before the\u00a0i-th item in the sorted array (to the left of the\u00a0i-th item).\n \n Return any solution if there is more than one solution and return an empty list\u00a0if there is no solution.\n \n Example 1:\n \n \n >>> sortItems(n = 8, m = 2, group = [-1,-1,1,0,0,1,0,-1], beforeItems = [[],[6],[5],[6],[3,6],[],[],[]])\n >>> [6,3,4,1,5,2,0,7]\n \n Example 2:\n \n >>> sortItems(n = 8, m = 2, group = [-1,-1,1,0,0,1,0,-1], beforeItems = [[],[6],[5],[6],[3],[],[4],[]])\n >>> []\n Explanation:\u00a0This is the same as example 1 except that 4 needs to be before 6 in the sorted list.\n \"\"\"\n"}
{"task_id": "unique-number-of-occurrences", "prompt": "def uniqueOccurrences(arr: List[int]) -> bool:\n \"\"\"\n Given an array of integers arr, return true if the number of occurrences of each value in the array is unique or false otherwise.\n \n Example 1:\n \n >>> uniqueOccurrences(arr = [1,2,2,1,1,3])\n >>> true\n Explanation:\u00a0The value 1 has 3 occurrences, 2 has 2 and 3 has 1. No two values have the same number of occurrences.\n Example 2:\n \n >>> uniqueOccurrences(arr = [1,2])\n >>> false\n \n Example 3:\n \n >>> uniqueOccurrences(arr = [-3,0,1,-3,1,1,1,-3,10,0])\n >>> true\n \"\"\"\n"}
{"task_id": "get-equal-substrings-within-budget", "prompt": "def equalSubstring(s: str, t: str, maxCost: int) -> int:\n \"\"\"\n You are given two strings s and t of the same length and an integer maxCost.\n 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).\n 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.\n \n Example 1:\n \n >>> equalSubstring(s = \"abcd\", t = \"bcdf\", maxCost = 3)\n >>> 3\n Explanation: \"abc\" of s can change to \"bcd\".\n That costs 3, so the maximum length is 3.\n \n Example 2:\n \n >>> equalSubstring(s = \"abcd\", t = \"cdef\", maxCost = 3)\n >>> 1\n Explanation: Each character in s costs 2 to change to character in t, so the maximum length is 1.\n \n Example 3:\n \n >>> equalSubstring(s = \"abcd\", t = \"acde\", maxCost = 0)\n >>> 1\n Explanation: You cannot make any change, so the maximum length is 1.\n \"\"\"\n"}
{"task_id": "remove-all-adjacent-duplicates-in-string-ii", "prompt": "def removeDuplicates(s: str, k: int) -> str:\n \"\"\"\n 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.\n We repeatedly make k duplicate removals on s until we no longer can.\n Return the final string after all such duplicate removals have been made. It is guaranteed that the answer is unique.\n \n Example 1:\n \n >>> removeDuplicates(s = \"abcd\", k = 2)\n >>> \"abcd\"\n Explanation: There's nothing to delete.\n Example 2:\n \n >>> removeDuplicates(s = \"deeedbbcccbdaa\", k = 3)\n >>> \"aa\"\n Explanation:\n First delete \"eee\" and \"ccc\", get \"ddbbbdaa\"\n Then delete \"bbb\", get \"dddaa\"\n Finally delete \"ddd\", get \"aa\"\n Example 3:\n \n >>> removeDuplicates(s = \"pbbcggttciiippooaais\", k = 2)\n >>> \"ps\"\n \"\"\"\n"}
{"task_id": "minimum-moves-to-reach-target-with-rotations", "prompt": "def minimumMoves(grid: List[List[int]]) -> int:\n \"\"\"\n In an\u00a0n*n\u00a0grid, 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\u00a0(n-1, n-2)\u00a0and\u00a0(n-1, n-1).\n In one move the snake can:\n \n Move one cell to the right\u00a0if there are no blocked cells there. This move keeps the horizontal/vertical position of the snake as it is.\n Move down one cell\u00a0if there are no blocked cells there. This move keeps the horizontal/vertical position of the snake as it is.\n 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\u00a0(r, c)\u00a0and\u00a0(r, c+1)\u00a0to\u00a0(r, c)\u00a0and\u00a0(r+1, c).\n \n Rotate counterclockwise\u00a0if it's in a vertical position and the two cells to its right are both empty. In that case the snake moves from\u00a0(r, c)\u00a0and\u00a0(r+1, c)\u00a0to\u00a0(r, c)\u00a0and\u00a0(r, c+1).\n \n \n Return the minimum number of moves to reach the target.\n If there is no way to reach the target, return\u00a0-1.\n \n Example 1:\n \n \n [1,1,0,0,1,0],\n \u00a0 [0,0,0,0,1,1],\n \u00a0 [0,0,1,0,1,0],\n \u00a0 [0,1,1,0,0,0],\n \u00a0 [0,1,1,0,0,0]]\n >>> minimumMoves(grid = [[0,0,0,0,0,1],)\n >>> 11\n Explanation:\n One possible solution is [right, right, rotate clockwise, right, down, down, down, down, rotate counterclockwise, right, down].\n \n Example 2:\n \n \u00a0 [0,0,0,0,1,1],\n \u00a0 [1,1,0,0,0,1],\n \u00a0 [1,1,1,0,0,1],\n \u00a0 [1,1,1,0,0,1],\n \u00a0 [1,1,1,0,0,0]]\n >>> minimumMoves(grid = [[0,0,1,1,1,1],)\n >>> 9\n \"\"\"\n"}
{"task_id": "intersection-of-three-sorted-arrays", "prompt": "def arraysIntersection(arr1: List[int], arr2: List[int], arr3: List[int]) -> List[int]:\n \"\"\"\n Given three integer arrays arr1, arr2 and arr3\u00a0sorted in strictly increasing order, return a sorted array of only\u00a0the\u00a0integers that appeared in all three arrays.\n \n Example 1:\n \n >>> arraysIntersection(arr1 = [1,2,3,4,5], arr2 = [1,2,5,7,9], arr3 = [1,3,4,5,8])\n >>> [1,5]\n Explanation: Only 1 and 5 appeared in the three arrays.\n \n Example 2:\n \n >>> arraysIntersection(arr1 = [197,418,523,876,1356], arr2 = [501,880,1593,1710,1870], arr3 = [521,682,1337,1395,1764])\n >>> []\n \"\"\"\n"}
{"task_id": "two-sum-bsts", "prompt": "# class TreeNode:\n# def __init__(val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def twoSumBSTs(root1: Optional[TreeNode], root2: Optional[TreeNode], target: int) -> bool:\n \"\"\"\n 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.\n \n Example 1:\n \n \n >>> __init__(root1 = [2,1,4], root2 = [1,0,3], target = 5)\n >>> true\n Explanation: 2 and 3 sum up to 5.\n \n Example 2:\n \n \n >>> __init__(root1 = [0,-10,10], root2 = [5,1,7,0,2], target = 18)\n >>> false\n \"\"\"\n"}
{"task_id": "stepping-numbers", "prompt": "def countSteppingNumbers(low: int, high: int) -> List[int]:\n \"\"\"\n A stepping number is an integer such that all of its adjacent digits have an absolute difference of exactly 1.\n \n For example, 321 is a stepping number while 421 is not.\n \n Given two integers low and high, return a sorted list of all the stepping numbers in the inclusive range [low, high].\n \n Example 1:\n \n >>> countSteppingNumbers(low = 0, high = 21)\n >>> [0,1,2,3,4,5,6,7,8,9,10,12,21]\n \n Example 2:\n \n >>> countSteppingNumbers(low = 10, high = 15)\n >>> [10,12]\n \"\"\"\n"}
{"task_id": "valid-palindrome-iii", "prompt": "def isValidPalindrome(s: str, k: int) -> bool:\n \"\"\"\n Given a string s and an integer k, return true if s is a k-palindrome.\n A string is k-palindrome if it can be transformed into a palindrome by removing at most k characters from it.\n \n Example 1:\n \n >>> isValidPalindrome(s = \"abcdeca\", k = 2)\n >>> true\n Explanation: Remove 'b' and 'e' characters.\n \n Example 2:\n \n >>> isValidPalindrome(s = \"abbababa\", k = 1)\n >>> true\n \"\"\"\n"}
{"task_id": "minimum-cost-to-move-chips-to-the-same-position", "prompt": "def minCostToMoveChips(position: List[int]) -> int:\n \"\"\"\n We have n chips, where the position of the ith chip is position[i].\n 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:\n \n position[i] + 2 or position[i] - 2 with cost = 0.\n position[i] + 1 or position[i] - 1 with cost = 1.\n \n Return the minimum cost needed to move all the chips to the same position.\n \n Example 1:\n \n \n >>> minCostToMoveChips(position = [1,2,3])\n >>> 1\n Explanation: First step: Move the chip at position 3 to position 1 with cost = 0.\n Second step: Move the chip at position 2 to position 1 with cost = 1.\n Total cost is 1.\n \n Example 2:\n \n \n >>> minCostToMoveChips(position = [2,2,2,3,3])\n >>> 2\n Explanation: We can move the two chips at position 3 to position 2. Each move has cost = 1. The total cost = 2.\n \n Example 3:\n \n >>> minCostToMoveChips(position = [1,1000000000])\n >>> 1\n \"\"\"\n"}
{"task_id": "longest-arithmetic-subsequence-of-given-difference", "prompt": "def longestSubsequence(arr: List[int], difference: int) -> int:\n \"\"\"\n 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.\n 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.\n \n Example 1:\n \n >>> longestSubsequence(arr = [1,2,3,4], difference = 1)\n >>> 4\n Explanation: The longest arithmetic subsequence is [1,2,3,4].\n Example 2:\n \n >>> longestSubsequence(arr = [1,3,5,7], difference = 1)\n >>> 1\n Explanation: The longest arithmetic subsequence is any single element.\n \n Example 3:\n \n >>> longestSubsequence(arr = [1,5,7,8,5,3,4,2,1], difference = -2)\n >>> 4\n Explanation: The longest arithmetic subsequence is [7,5,3,1].\n \"\"\"\n"}
{"task_id": "path-with-maximum-gold", "prompt": "def getMaximumGold(grid: List[List[int]]) -> int:\n \"\"\"\n 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.\n Return the maximum amount of gold you can collect under the conditions:\n \n Every time you are located in a cell you will collect all the gold in that cell.\n From your position, you can walk one step to the left, right, up, or down.\n You can't visit the same cell more than once.\n Never visit a cell with 0 gold.\n You can start and stop collecting gold from any position in the grid that has some gold.\n \n \n Example 1:\n \n >>> getMaximumGold(grid = [[0,6,0],[5,8,7],[0,9,0]])\n >>> 24\n Explanation:\n [[0,6,0],\n [5,8,7],\n [0,9,0]]\n Path to get the maximum gold, 9 -> 8 -> 7.\n \n Example 2:\n \n >>> getMaximumGold(grid = [[1,0,7],[2,0,6],[3,4,5],[0,3,0],[9,0,20]])\n >>> 28\n Explanation:\n [[1,0,7],\n [2,0,6],\n [3,4,5],\n [0,3,0],\n [9,0,20]]\n Path to get the maximum gold, 1 -> 2 -> 3 -> 4 -> 5 -> 6 -> 7.\n \"\"\"\n"}
{"task_id": "count-vowels-permutation", "prompt": "def countVowelPermutation(n: int) -> int:\n \"\"\"\n Given an integer n, your task is to count how many strings of length n can be formed under the following rules:\n \n Each character is a lower case vowel\u00a0('a', 'e', 'i', 'o', 'u')\n Each vowel\u00a0'a' may only be followed by an 'e'.\n Each vowel\u00a0'e' may only be followed by an 'a'\u00a0or an 'i'.\n Each vowel\u00a0'i' may not be followed by another 'i'.\n Each vowel\u00a0'o' may only be followed by an 'i' or a\u00a0'u'.\n Each vowel\u00a0'u' may only be followed by an 'a'.\n \n Since the answer\u00a0may be too large,\u00a0return it modulo\u00a010^9 + 7.\n \n Example 1:\n \n >>> countVowelPermutation(n = 1)\n >>> 5\n Explanation: All possible strings are: \"a\", \"e\", \"i\" , \"o\" and \"u\".\n \n Example 2:\n \n >>> countVowelPermutation(n = 2)\n >>> 10\n Explanation: All possible strings are: \"ae\", \"ea\", \"ei\", \"ia\", \"ie\", \"io\", \"iu\", \"oi\", \"ou\" and \"ua\".\n \n Example 3:\n \n >>> countVowelPermutation(n = 5)\n >>> 68\n \"\"\"\n"}
{"task_id": "split-a-string-in-balanced-strings", "prompt": "def balancedStringSplit(s: str) -> int:\n \"\"\"\n Balanced strings are those that have an equal quantity of 'L' and 'R' characters.\n Given a balanced string s, split it into some number of substrings such that:\n \n Each substring is balanced.\n \n Return the maximum number of balanced strings you can obtain.\n \n Example 1:\n \n >>> balancedStringSplit(s = \"RLRRLLRLRL\")\n >>> 4\n Explanation: s can be split into \"RL\", \"RRLL\", \"RL\", \"RL\", each substring contains same number of 'L' and 'R'.\n \n Example 2:\n \n >>> balancedStringSplit(s = \"RLRRRLLRLL\")\n >>> 2\n Explanation: s can be split into \"RL\", \"RRRLLRLL\", each substring contains same number of 'L' and 'R'.\n Note that s cannot be split into \"RL\", \"RR\", \"RL\", \"LR\", \"LL\", because the 2nd and 5th substrings are not balanced.\n Example 3:\n \n >>> balancedStringSplit(s = \"LLLLRRRR\")\n >>> 1\n Explanation: s can be split into \"LLLLRRRR\".\n \"\"\"\n"}
{"task_id": "queens-that-can-attack-the-king", "prompt": "def queensAttacktheKing(queens: List[List[int]], king: List[int]) -> List[List[int]]:\n \"\"\"\n On a 0-indexed 8 x 8 chessboard, there can be multiple black queens and one white king.\n 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.\n Return the coordinates of the black queens that can directly attack the king. You may return the answer in any order.\n \n Example 1:\n \n \n >>> queensAttacktheKing(queens = [[0,1],[1,0],[4,0],[0,4],[3,3],[2,4]], king = [0,0])\n >>> [[0,1],[1,0],[3,3]]\n 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).\n \n Example 2:\n \n \n >>> queensAttacktheKing(queens = [[0,0],[1,1],[2,2],[3,4],[3,5],[4,4],[4,5]], king = [3,3])\n >>> [[2,2],[3,4],[4,4]]\n 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).\n \"\"\"\n"}
{"task_id": "dice-roll-simulation", "prompt": "def dieSimulator(n: int, rollMax: List[int]) -> int:\n \"\"\"\n 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.\n 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.\n Two sequences are considered different if at least one element differs from each other.\n \n Example 1:\n \n >>> dieSimulator(n = 2, rollMax = [1,1,2,2,2,3])\n >>> 34\n 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.\n \n Example 2:\n \n >>> dieSimulator(n = 2, rollMax = [1,1,1,1,1,1])\n >>> 30\n \n Example 3:\n \n >>> dieSimulator(n = 3, rollMax = [1,1,1,2,2,3])\n >>> 181\n \"\"\"\n"}
{"task_id": "maximum-equal-frequency", "prompt": "def maxEqualFreq(nums: List[int]) -> int:\n \"\"\"\n 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.\n 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).\n \n Example 1:\n \n >>> maxEqualFreq(nums = [2,2,1,1,5,3,3,5])\n >>> 7\n 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.\n \n Example 2:\n \n >>> maxEqualFreq(nums = [1,1,1,2,2,2,3,3,3,4,4,4,5])\n >>> 13\n \"\"\"\n"}
{"task_id": "airplane-seat-assignment-probability", "prompt": "def nthPersonGetsNthSeat(n: int) -> float:\n \"\"\"\n 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:\n \n Take their own seat if it is still available, and\n Pick other seats randomly when they find their seat occupied\n \n Return the probability that the nth person gets his own seat.\n \n Example 1:\n \n >>> nthPersonGetsNthSeat(n = 1)\n >>> 1.00000\n Explanation: The first person can only get the first seat.\n Example 2:\n \n >>> nthPersonGetsNthSeat(n = 2)\n >>> 0.50000\n Explanation: The second person has a probability of 0.5 to get the second seat (when first person gets the first seat).\n \"\"\"\n"}
{"task_id": "missing-number-in-arithmetic-progression", "prompt": "def missingNumber(arr: List[int]) -> int:\n \"\"\"\n 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.\n A value from arr was removed that was not the first or last value in the array.\n Given arr, return the removed value.\n \n Example 1:\n \n >>> missingNumber(arr = [5,7,11,13])\n >>> 9\n Explanation: The previous array was [5,7,9,11,13].\n \n Example 2:\n \n >>> missingNumber(arr = [15,13,12])\n >>> 14\n Explanation: The previous array was [15,14,13,12].\n \"\"\"\n"}
{"task_id": "meeting-scheduler", "prompt": "def minAvailableDuration(slots1: List[List[int]], slots2: List[List[int]], duration: int) -> List[int]:\n \"\"\"\n 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.\n If there is no common time slot that satisfies the requirements, return an empty array.\n The format of a time slot is an array of two elements [start, end] representing an inclusive time range from start to end.\n 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.\n \n Example 1:\n \n >>> minAvailableDuration(slots1 = [[10,50],[60,120],[140,210]], slots2 = [[0,15],[60,70]], duration = 8)\n >>> [60,68]\n \n Example 2:\n \n >>> minAvailableDuration(slots1 = [[10,50],[60,120],[140,210]], slots2 = [[0,15],[60,70]], duration = 12)\n >>> []\n \"\"\"\n"}
{"task_id": "toss-strange-coins", "prompt": "def probabilityOfHeads(prob: List[float], target: int) -> float:\n \"\"\"\n You have some coins.\u00a0 The i-th\u00a0coin has a probability\u00a0prob[i] of facing heads when tossed.\n Return the probability that the number of coins facing heads equals target if you toss every coin exactly once.\n \n Example 1:\n >>> probabilityOfHeads(prob = [0.4], target = 1)\n >>> 0.40000\n Example 2:\n >>> probabilityOfHeads(prob = [0.5,0.5,0.5,0.5,0.5], target = 0)\n >>> 0.03125\n \"\"\"\n"}
{"task_id": "divide-chocolate", "prompt": "def maximizeSweetness(sweetness: List[int], k: int) -> int:\n \"\"\"\n You have one chocolate bar that consists of some chunks. Each chunk has its own sweetness given by the array\u00a0sweetness.\n You want to share the chocolate with your k\u00a0friends so you start cutting the chocolate bar into k + 1\u00a0pieces using\u00a0k\u00a0cuts, each piece consists of some consecutive chunks.\n Being generous, you will eat the piece with the minimum total sweetness and give the other pieces to your friends.\n Find the maximum total sweetness of the\u00a0piece you can get by cutting the chocolate bar optimally.\n \n Example 1:\n \n >>> maximizeSweetness(sweetness = [1,2,3,4,5,6,7,8,9], k = 5)\n >>> 6\n Explanation: You can divide the chocolate to [1,2,3], [4,5], [6], [7], [8], [9]\n \n Example 2:\n \n >>> maximizeSweetness(sweetness = [5,6,7,8,9,1,2,3,4], k = 8)\n >>> 1\n Explanation: There is only one way to cut the bar into 9 pieces.\n \n Example 3:\n \n >>> maximizeSweetness(sweetness = [1,2,2,1,2,2,1,2,2], k = 2)\n >>> 5\n Explanation: You can divide the chocolate to [1,2,2], [1,2,2], [1,2,2]\n \"\"\"\n"}
{"task_id": "check-if-it-is-a-straight-line", "prompt": "def checkStraightLine(coordinates: List[List[int]]) -> bool:\n \"\"\"\n You are given an array\u00a0coordinates, coordinates[i] = [x, y], where [x, y] represents the coordinate of a point. Check if these points\u00a0make a straight line in the XY plane.\n \n \n Example 1:\n \n \n >>> checkStraightLine(coordinates = [[1,2],[2,3],[3,4],[4,5],[5,6],[6,7]])\n >>> true\n \n Example 2:\n \n \n >>> checkStraightLine(coordinates = [[1,1],[2,2],[3,4],[4,5],[5,6],[7,7]])\n >>> false\n \"\"\"\n"}
{"task_id": "remove-sub-folders-from-the-filesystem", "prompt": "def removeSubfolders(folder: List[str]) -> List[str]:\n \"\"\"\n 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.\n 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\".\n The format of a path is one or more concatenated strings of the form: '/' followed by one or more lowercase English letters.\n \n For example, \"/leetcode\" and \"/leetcode/problems\" are valid paths while an empty string and \"/\" are not.\n \n \n Example 1:\n \n >>> removeSubfolders(folder = [\"/a\",\"/a/b\",\"/c/d\",\"/c/d/e\",\"/c/f\"])\n >>> [\"/a\",\"/c/d\",\"/c/f\"]\n Explanation: Folders \"/a/b\" is a subfolder of \"/a\" and \"/c/d/e\" is inside of folder \"/c/d\" in our filesystem.\n \n Example 2:\n \n >>> removeSubfolders(folder = [\"/a\",\"/a/b/c\",\"/a/b/d\"])\n >>> [\"/a\"]\n Explanation: Folders \"/a/b/c\" and \"/a/b/d\" will be removed because they are subfolders of \"/a\".\n \n Example 3:\n \n >>> removeSubfolders(folder = [\"/a/b/c\",\"/a/b/ca\",\"/a/b/d\"])\n >>> [\"/a/b/c\",\"/a/b/ca\",\"/a/b/d\"]\n \"\"\"\n"}
{"task_id": "replace-the-substring-for-balanced-string", "prompt": "def balancedString(s: str) -> int:\n \"\"\"\n You are given a string s of length n containing only four kinds of characters: 'Q', 'W', 'E', and 'R'.\n A string is said to be balanced if each of its characters appears n / 4 times where n is the length of the string.\n 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.\n \n Example 1:\n \n >>> balancedString(s = \"QWER\")\n >>> 0\n Explanation: s is already balanced.\n \n Example 2:\n \n >>> balancedString(s = \"QQWE\")\n >>> 1\n Explanation: We need to replace a 'Q' to 'R', so that \"RQWE\" (or \"QRWE\") is balanced.\n \n Example 3:\n \n >>> balancedString(s = \"QQQW\")\n >>> 2\n Explanation: We can replace the first \"QQ\" to \"ER\".\n \"\"\"\n"}
{"task_id": "maximum-profit-in-job-scheduling", "prompt": "def jobScheduling(startTime: List[int], endTime: List[int], profit: List[int]) -> int:\n \"\"\"\n We have n jobs, where every job is scheduled to be done from startTime[i] to endTime[i], obtaining a profit of profit[i].\n 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.\n If you choose a job that ends at time X you will be able to start another job that starts at time X.\n \n Example 1:\n \n \n >>> jobScheduling(startTime = [1,2,3,3], endTime = [3,4,5,6], profit = [50,10,40,70])\n >>> 120\n Explanation: The subset chosen is the first and fourth job.\n Time range [1-3]+[3-6] , we get profit of 120 = 50 + 70.\n \n Example 2:\n \n \n >>> jobScheduling(startTime = [1,2,3,4,6], endTime = [3,5,10,6,9], profit = [20,20,100,70,60])\n >>> 150\n Explanation: The subset chosen is the first, fourth and fifth job.\n Profit obtained 150 = 20 + 70 + 60.\n \n Example 3:\n \n \n >>> jobScheduling(startTime = [1,1,1], endTime = [2,3,4], profit = [5,6,4])\n >>> 6\n \"\"\"\n"}
{"task_id": "circular-permutation-in-binary-representation", "prompt": "def circularPermutation(n: int, start: int) -> List[int]:\n \"\"\"\n Given 2 integers n and start. Your task is return any permutation p\u00a0of (0,1,2.....,2^n -1) such that :\\r\n \\r\n \\r\n \tp[0] = start\\r\n \tp[i] and p[i+1]\u00a0differ by only one bit in their binary representation.\\r\n \tp[0] and p[2^n -1]\u00a0must also differ by only one bit in their binary representation.\\r\n \\r\n \\r\n \u00a0\\r\n Example 1:\\r\n \\r\n \\r\n >>> circularPermutation(n = 2, start = 3\\r)\n >>> [3,2,0,1]\\r\n Explanation: The binary representation of the permutation is (11,10,00,01). \\r\n All the adjacent element differ by one bit. Another valid permutation is [3,1,0,2]\\r\n \\r\n \\r\n Example 2:\\r\n \\r\n \\r\n >>> circularPermutation(n = 3, start = 2\\r)\n >>> [2,6,7,5,4,0,1,3]\\r\n Explanation: The binary representation of the permutation is (010,110,111,101,100,000,001,011).\\r\n \\r\n \\r\n \u00a0\\r\n \"\"\"\n"}
{"task_id": "maximum-length-of-a-concatenated-string-with-unique-characters", "prompt": "def maxLength(arr: List[str]) -> int:\n \"\"\"\n 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.\n Return the maximum possible length of s.\n 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.\n \n Example 1:\n \n >>> maxLength(arr = [\"un\",\"iq\",\"ue\"])\n >>> 4\n Explanation: All the valid concatenations are:\n - \"\"\n - \"un\"\n - \"iq\"\n - \"ue\"\n - \"uniq\" (\"un\" + \"iq\")\n - \"ique\" (\"iq\" + \"ue\")\n Maximum length is 4.\n \n Example 2:\n \n >>> maxLength(arr = [\"cha\",\"r\",\"act\",\"ers\"])\n >>> 6\n Explanation: Possible longest valid concatenations are \"chaers\" (\"cha\" + \"ers\") and \"acters\" (\"act\" + \"ers\").\n \n Example 3:\n \n >>> maxLength(arr = [\"abcdefghijklmnopqrstuvwxyz\"])\n >>> 26\n Explanation: The only string in arr has all 26 characters.\n \"\"\"\n"}
{"task_id": "tiling-a-rectangle-with-the-fewest-squares", "prompt": "def tilingRectangle(n: int, m: int) -> int:\n \"\"\"\n Given a rectangle of size n x m, return the minimum number of integer-sided squares that tile the rectangle.\n \n Example 1:\n \n \n >>> tilingRectangle(n = 2, m = 3)\n >>> 3\n Explanation: 3 squares are necessary to cover the rectangle.\n 2 (squares of 1x1)\n 1 (square of 2x2)\n Example 2:\n \n \n >>> tilingRectangle(n = 5, m = 8)\n >>> 5\n \n Example 3:\n \n \n >>> tilingRectangle(n = 11, m = 13)\n >>> 6\n \"\"\"\n"}
{"task_id": "web-crawler-multithreaded", "prompt": "# This is HtmlParser's API interface.\n# You should not implement it, or speculate about its implementation\n# \"\"\"\n#class HtmlParser(object):\n# def getUrls(url):\n# \"\"\"\n# :type url: str\n# :rtype List[str]\n# \"\"\"\n\nclass Solution:\n def crawl(startUrl: str, htmlParser: 'HtmlParser') -> List[str]:\n \"\"\"\n 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.\n Return all URLs obtained by your web crawler in any order.\n Your crawler should:\n \n Start from the page: startUrl\n Call HtmlParser.getUrls(url) to get all URLs from a webpage of a given URL.\n Do not crawl the same link twice.\n Explore only the links that are under the same hostname as startUrl.\n \n \n 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.\n The HtmlParser interface is defined as such:\n \n interface HtmlParser {\n // Return a list of all urls from a webpage of given url.\n // This is a blocking call, that means it will do HTTP request and return when this request is finished.\n public List getUrls(String url);\n }\n \n 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?\n 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.\n \n Example 1:\n \n \n urls = [\n \u00a0 \"http://news.yahoo.com\",\n \u00a0 \"http://news.yahoo.com/news\",\n \u00a0 \"http://news.yahoo.com/news/topics/\",\n \u00a0 \"http://news.google.com\",\n \u00a0 \"http://news.yahoo.com/us\"\n ]\n edges = [[2,0],[2,1],[3,2],[3,1],[0,4]]\n startUrl = \"http://news.yahoo.com/news/topics/\"\n >>> getUrls()\n >>> [\n \u00a0 \"http://news.yahoo.com\",\n \u00a0 \"http://news.yahoo.com/news\",\n \u00a0 \"http://news.yahoo.com/news/topics/\",\n \u00a0 \"http://news.yahoo.com/us\"\n ]\n \n Example 2:\n \n \n urls = [\n \u00a0 \"http://news.yahoo.com\",\n \u00a0 \"http://news.yahoo.com/news\",\n \u00a0 \"http://news.yahoo.com/news/topics/\",\n \u00a0 \"http://news.google.com\"\n ]\n edges = [[0,2],[2,1],[3,2],[3,1],[3,0]]\n startUrl = \"http://news.google.com\"\n >>> getUrls()\n >>> [\"http://news.google.com\"]\n Explanation: The startUrl links to all other pages that do not share the same hostname.\n \"\"\"\n"}
{"task_id": "array-transformation", "prompt": "def transformArray(arr: List[int]) -> List[int]:\n \"\"\"\n Given an initial array arr, every day you produce a new array using the array of the previous day.\n On the i-th day, you do the following operations on the array of day\u00a0i-1\u00a0to produce the array of day i:\n \n If an element is smaller than both its left neighbor and its right neighbor, then this element is incremented.\n If an element is bigger than both its left neighbor and its right neighbor, then this element is decremented.\n The first\u00a0and last elements never change.\n \n After some days, the array does not change. Return that final array.\n \n Example 1:\n \n >>> transformArray(arr = [6,2,3,4])\n >>> [6,3,3,4]\n Explanation:\n On the first day, the array is changed from [6,2,3,4] to [6,3,3,4].\n No more operations can be done to this array.\n \n Example 2:\n \n >>> transformArray(arr = [1,6,3,4,3,5])\n >>> [1,4,4,4,4,5]\n Explanation:\n On the first day, the array is changed from [1,6,3,4,3,5] to [1,5,4,3,4,5].\n On the second day, the array is changed from [1,5,4,3,4,5] to [1,4,4,4,4,5].\n No more operations can be done to this array.\n \"\"\"\n"}
{"task_id": "tree-diameter", "prompt": "def treeDiameter(edges: List[List[int]]) -> int:\n \"\"\"\n The diameter of a tree is the number of edges in the longest path in that tree.\n 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.\n Return the diameter of the tree.\n \n Example 1:\n \n \n >>> treeDiameter(edges = [[0,1],[0,2]])\n >>> 2\n Explanation: The longest path of the tree is the path 1 - 0 - 2.\n \n Example 2:\n \n \n >>> treeDiameter(edges = [[0,1],[1,2],[2,3],[1,4],[4,5]])\n >>> 4\n Explanation: The longest path of the tree is the path 3 - 2 - 1 - 4 - 5.\n \"\"\"\n"}
{"task_id": "palindrome-removal", "prompt": "def minimumMoves(arr: List[int]) -> int:\n \"\"\"\n You are given an integer array arr.\n 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.\n Return the minimum number of moves needed to remove all numbers from the array.\n \n Example 1:\n \n >>> minimumMoves(arr = [1,2])\n >>> 2\n \n Example 2:\n \n >>> minimumMoves(arr = [1,3,4,1,5])\n >>> 3\n Explanation: Remove [4] then remove [1,3,1] then remove [5].\n \"\"\"\n"}
{"task_id": "minimum-swaps-to-make-strings-equal", "prompt": "def minimumSwap(s1: str, s2: str) -> int:\n \"\"\"\n 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].\n Return the minimum number of swaps required to make s1 and s2 equal, or return -1 if it is impossible to do so.\n \n Example 1:\n \n >>> minimumSwap(s1 = \"xx\", s2 = \"yy\")\n >>> 1\n Explanation: Swap s1[0] and s2[1], s1 = \"yx\", s2 = \"yx\".\n \n Example 2:\n \n >>> minimumSwap(s1 = \"xy\", s2 = \"yx\")\n >>> 2\n Explanation: Swap s1[0] and s2[0], s1 = \"yy\", s2 = \"xx\".\n Swap s1[0] and s2[1], s1 = \"xy\", s2 = \"xy\".\n 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.\n \n Example 3:\n \n >>> minimumSwap(s1 = \"xx\", s2 = \"xy\")\n >>> -1\n \"\"\"\n"}
{"task_id": "count-number-of-nice-subarrays", "prompt": "def numberOfSubarrays(nums: List[int], k: int) -> int:\n \"\"\"\n Given an array of integers nums and an integer k. A continuous subarray is called nice if there are k odd numbers on it.\n Return the number of nice sub-arrays.\n \n Example 1:\n \n >>> numberOfSubarrays(nums = [1,1,2,1,1], k = 3)\n >>> 2\n Explanation: The only sub-arrays with 3 odd numbers are [1,1,2,1] and [1,2,1,1].\n \n Example 2:\n \n >>> numberOfSubarrays(nums = [2,4,6], k = 1)\n >>> 0\n Explanation: There are no odd numbers in the array.\n \n Example 3:\n \n >>> numberOfSubarrays(nums = [2,2,2,1,2,2,1,2,2,2], k = 2)\n >>> 16\n \"\"\"\n"}
{"task_id": "minimum-remove-to-make-valid-parentheses", "prompt": "def minRemoveToMakeValid(s: str) -> str:\n \"\"\"\n Given a string s of '(' , ')' and lowercase English characters.\n 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.\n Formally, a parentheses string is valid if and only if:\n \n It is the empty string, contains only lowercase characters, or\n It can be written as AB (A concatenated with B), where A and B are valid strings, or\n It can be written as (A), where A is a valid string.\n \n \n Example 1:\n \n >>> minRemoveToMakeValid(s = \"lee(t(c)o)de)\")\n >>> \"lee(t(c)o)de\"\n Explanation: \"lee(t(co)de)\" , \"lee(t(c)ode)\" would also be accepted.\n \n Example 2:\n \n >>> minRemoveToMakeValid(s = \"a)b(c)d\")\n >>> \"ab(c)d\"\n \n Example 3:\n \n >>> minRemoveToMakeValid(s = \"))((\")\n >>> \"\"\n Explanation: An empty string is also valid.\n \"\"\"\n"}
{"task_id": "check-if-it-is-a-good-array", "prompt": "def isGoodArray(nums: List[int]) -> bool:\n \"\"\"\n Given an array nums of\u00a0positive integers. Your task is to select some subset of nums, multiply each element by an integer and add all these numbers.\u00a0The array is said to be\u00a0good\u00a0if you can obtain a sum of\u00a01\u00a0from the array by any possible subset and multiplicand.\n Return\u00a0True\u00a0if the array is good\u00a0otherwise\u00a0return\u00a0False.\n \n Example 1:\n \n >>> isGoodArray(nums = [12,5,7,23])\n >>> true\n Explanation: Pick numbers 5 and 7.\n 5*3 + 7*(-2) = 1\n \n Example 2:\n \n >>> isGoodArray(nums = [29,6,10])\n >>> true\n Explanation: Pick numbers 29, 6 and 10.\n 29*1 + 6*(-3) + 10*(-1) = 1\n \n Example 3:\n \n >>> isGoodArray(nums = [3,6])\n >>> false\n \"\"\"\n"}
{"task_id": "cells-with-odd-values-in-a-matrix", "prompt": "def oddCells(m: int, n: int, indices: List[List[int]]) -> int:\n \"\"\"\n 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.\n For each location indices[i], do both of the following:\n \n Increment all the cells on row ri.\n Increment all the cells on column ci.\n \n Given m, n, and indices, return the number of odd-valued cells in the matrix after applying the increment to all locations in indices.\n \n Example 1:\n \n \n >>> oddCells(m = 2, n = 3, indices = [[0,1],[1,1]])\n >>> 6\n Explanation: Initial matrix = [[0,0,0],[0,0,0]].\n After applying first increment it becomes [[1,2,1],[0,1,0]].\n The final matrix is [[1,3,1],[1,3,1]], which contains 6 odd numbers.\n \n Example 2:\n \n \n >>> oddCells(m = 2, n = 2, indices = [[1,1],[0,0]])\n >>> 0\n Explanation: Final matrix = [[2,2],[2,2]]. There are no odd numbers in the final matrix.\n \"\"\"\n"}
{"task_id": "reconstruct-a-2-row-binary-matrix", "prompt": "def reconstructMatrix(upper: int, lower: int, colsum: List[int]) -> List[List[int]]:\n \"\"\"\n Given the following details of a matrix with n columns and 2 rows :\n \n The matrix is a binary matrix, which means each element in the matrix can be 0 or 1.\n The sum of elements of the 0-th(upper) row is given as upper.\n The sum of elements of the 1-st(lower) row is given as lower.\n 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.\n \n Your task is to reconstruct the matrix with upper, lower and colsum.\n Return it as a 2-D integer array.\n If there are more than one valid solution, any of them will be accepted.\n If no valid solution exists, return an empty 2-D array.\n \n Example 1:\n \n >>> reconstructMatrix(upper = 2, lower = 1, colsum = [1,1,1])\n >>> [[1,1,0],[0,0,1]]\n Explanation: [[1,0,1],[0,1,0]], and [[0,1,1],[1,0,0]] are also correct answers.\n \n Example 2:\n \n >>> reconstructMatrix(upper = 2, lower = 3, colsum = [2,2,1,1])\n >>> []\n \n Example 3:\n \n >>> reconstructMatrix(upper = 5, lower = 5, colsum = [2,1,2,0,1,0,1,2,0,1])\n >>> [[1,1,1,0,1,0,0,1,0,0],[1,0,1,0,0,0,1,1,0,1]]\n \"\"\"\n"}
{"task_id": "number-of-closed-islands", "prompt": "def closedIsland(grid: List[List[int]]) -> int:\n \"\"\"\n Given a 2D\u00a0grid consists of 0s (land)\u00a0and 1s (water).\u00a0 An island is a maximal 4-directionally connected group of 0s and a closed island\u00a0is an island totally\u00a0(all left, top, right, bottom) surrounded by 1s.\n Return the number of closed islands.\n \n Example 1:\n \n \n >>> 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]])\n >>> 2\n Explanation:\n Islands in gray are closed because they are completely surrounded by water (group of 1s).\n Example 2:\n \n \n >>> closedIsland(grid = [[0,0,1,0,0],[0,1,0,1,0],[0,1,1,1,0]])\n >>> 1\n \n Example 3:\n \n \u00a0 [1,0,0,0,0,0,1],\n \u00a0 [1,0,1,1,1,0,1],\n \u00a0 [1,0,1,0,1,0,1],\n \u00a0 [1,0,1,1,1,0,1],\n \u00a0 [1,0,0,0,0,0,1],\n [1,1,1,1,1,1,1]]\n >>> closedIsland(grid = [[1,1,1,1,1,1,1],)\n >>> 2\n \"\"\"\n"}
{"task_id": "maximum-score-words-formed-by-letters", "prompt": "def maxScoreWords(words: List[str], letters: List[str], score: List[int]) -> int:\n \"\"\"\n Given a list of words, list of\u00a0 single\u00a0letters (might be repeating)\u00a0and score\u00a0of every character.\n Return the maximum score of any valid set of words formed by using the given letters (words[i] cannot be used two\u00a0or more times).\n It is not necessary to use all characters in letters and each letter can only be used once. Score of letters\u00a0'a', 'b', 'c', ... ,'z' is given by\u00a0score[0], score[1], ... , score[25] respectively.\n \n Example 1:\n \n >>> 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])\n >>> 23\n Explanation:\n Score a=1, c=9, d=5, g=3, o=2\n Given letters, we can form the words \"dad\" (5+1+5) and \"good\" (3+2+2+5) with a score of 23.\n Words \"dad\" and \"dog\" only get a score of 21.\n Example 2:\n \n >>> 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])\n >>> 27\n Explanation:\n Score a=4, b=4, c=4, x=5, z=10\n Given letters, we can form the words \"ax\" (4+5), \"bx\" (4+5) and \"cx\" (4+5) with a score of 27.\n Word \"xxxz\" only get a score of 25.\n Example 3:\n \n >>> 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])\n >>> 0\n Explanation:\n Letter \"e\" can only be used once.\n \"\"\"\n"}
{"task_id": "encode-number", "prompt": "def encode(num: int) -> str:\n \"\"\"\n Given a non-negative integer num, Return its encoding string.\\r\n \\r\n The encoding is done by converting the integer to a string using a secret function that you should deduce from the following table:\\r\n \\r\n \\r\n \\r\n \u00a0\\r\n Example 1:\\r\n \\r\n \\r\n >>> encode(num = 23\\r)\n >>> \"1000\"\\r\n \\r\n \\r\n Example 2:\\r\n \\r\n \\r\n >>> encode(num = 107\\r)\n >>> \"101100\"\\r\n \\r\n \\r\n \u00a0\\r\n \"\"\"\n"}
{"task_id": "smallest-common-region", "prompt": "def findSmallestRegion(regions: List[List[str]], region1: str, region2: str) -> str:\n \"\"\"\n You are given some lists of regions where the first region of each list includes all other regions in that list.\n Naturally, if a region x contains another region y then x is bigger than y. Also, by definition, a region x contains itself.\n Given two regions: region1 and region2, return the smallest region that contains both of them.\n 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.\n It is guaranteed the smallest region exists.\n \n Example 1:\n \n regions = [[\"Earth\",\"North America\",\"South America\"],\n [\"North America\",\"United States\",\"Canada\"],\n [\"United States\",\"New York\",\"Boston\"],\n [\"Canada\",\"Ontario\",\"Quebec\"],\n [\"South America\",\"Brazil\"]],\n region1 = \"Quebec\",\n region2 = \"New York\"\n >>> findSmallestRegion()\n >>> \"North America\"\n \n Example 2:\n \n >>> 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\")\n >>> \"Earth\"\n \"\"\"\n"}
{"task_id": "synonymous-sentences", "prompt": "def generateSentences(synonyms: List[List[str]], text: str) -> List[str]:\n \"\"\"\n 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.\n Return all possible synonymous sentences sorted lexicographically.\n \n Example 1:\n \n >>> generateSentences(synonyms = [[\"happy\",\"joy\"],[\"sad\",\"sorrow\"],[\"joy\",\"cheerful\"]], text = \"I am happy today but was sad yesterday\")\n >>> [\"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\"]\n \n Example 2:\n \n >>> generateSentences(synonyms = [[\"happy\",\"joy\"],[\"cheerful\",\"glad\"]], text = \"I am happy today but was sad yesterday\")\n >>> [\"I am happy today but was sad yesterday\",\"I am joy today but was sad yesterday\"]\n \"\"\"\n"}
{"task_id": "handshakes-that-dont-cross", "prompt": "def numberOfWays(numPeople: int) -> int:\n \"\"\"\n 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.\n Return the number of ways these handshakes could occur such that none of the handshakes cross.\n Since the answer could be very large, return it modulo 109 + 7.\n \n Example 1:\n \n \n >>> numberOfWays(numPeople = 4)\n >>> 2\n 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)].\n \n Example 2:\n \n \n >>> numberOfWays(numPeople = 6)\n >>> 5\n \"\"\"\n"}
{"task_id": "shift-2d-grid", "prompt": "def shiftGrid(grid: List[List[int]], k: int) -> List[List[int]]:\n \"\"\"\n Given a 2D grid of size m x n\u00a0and an integer k. You need to shift the grid\u00a0k times.\n In one shift operation:\n \n Element at grid[i][j] moves to grid[i][j + 1].\n Element at grid[i][n - 1] moves to grid[i + 1][0].\n Element at grid[m\u00a0- 1][n - 1] moves to grid[0][0].\n \n Return the 2D grid after applying shift operation k times.\n \n Example 1:\n \n \n >>> shiftGrid(grid = [[1,2,3],[4,5,6],[7,8,9]], k = 1)\n >>> [[9,1,2],[3,4,5],[6,7,8]]\n \n Example 2:\n \n \n >>> shiftGrid(grid = [[3,8,1,9],[19,7,2,5],[4,6,11,10],[12,0,21,13]], k = 4)\n >>> [[12,0,21,13],[3,8,1,9],[19,7,2,5],[4,6,11,10]]\n \n Example 3:\n \n >>> shiftGrid(grid = [[1,2,3],[4,5,6],[7,8,9]], k = 9)\n >>> [[1,2,3],[4,5,6],[7,8,9]]\n \"\"\"\n"}
{"task_id": "greatest-sum-divisible-by-three", "prompt": "def maxSumDivThree(nums: List[int]) -> int:\n \"\"\"\n Given an integer array nums, return the maximum possible sum of elements of the array such that it is divisible by three.\n \n Example 1:\n \n >>> maxSumDivThree(nums = [3,6,5,1,8])\n >>> 18\n Explanation: Pick numbers 3, 6, 1 and 8 their sum is 18 (maximum sum divisible by 3).\n Example 2:\n \n >>> maxSumDivThree(nums = [4])\n >>> 0\n Explanation: Since 4 is not divisible by 3, do not pick any number.\n \n Example 3:\n \n >>> maxSumDivThree(nums = [1,2,3,4,4])\n >>> 12\n Explanation: Pick numbers 1, 3, 4 and 4 their sum is 12 (maximum sum divisible by 3).\n \"\"\"\n"}
{"task_id": "minimum-moves-to-move-a-box-to-their-target-location", "prompt": "def minPushBox(grid: List[List[str]]) -> int:\n \"\"\"\n A storekeeper is a game in which the player pushes boxes around in a warehouse trying to get them to target locations.\n The game is represented by an m x n grid of characters grid where each element is a wall, floor, or box.\n Your task is to move the box 'B' to the target position 'T' under the following rules:\n \n The character 'S' represents the player. The player can move up, down, left, right in grid if it is a floor (empty cell).\n The character '.' represents the floor which means a free cell to walk.\n The character\u00a0'#'\u00a0represents the wall which means an obstacle (impossible to walk there).\n There is only one box 'B' and one target cell 'T' in the grid.\n 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.\n The player cannot walk through the box.\n \n Return the minimum number of pushes to move the box to the target. If there is no way to reach the target, return -1.\n \n Example 1:\n \n \n [\"#\",\"T\",\"#\",\"#\",\"#\",\"#\"],\n [\"#\",\".\",\".\",\"B\",\".\",\"#\"],\n [\"#\",\".\",\"#\",\"#\",\".\",\"#\"],\n [\"#\",\".\",\".\",\".\",\"S\",\"#\"],\n [\"#\",\"#\",\"#\",\"#\",\"#\",\"#\"]]\n >>> minPushBox(grid = [[\"#\",\"#\",\"#\",\"#\",\"#\",\"#\"],)\n >>> 3\n Explanation: We return only the number of times the box is pushed.\n Example 2:\n \n [\"#\",\"T\",\"#\",\"#\",\"#\",\"#\"],\n [\"#\",\".\",\".\",\"B\",\".\",\"#\"],\n [\"#\",\"#\",\"#\",\"#\",\".\",\"#\"],\n [\"#\",\".\",\".\",\".\",\"S\",\"#\"],\n [\"#\",\"#\",\"#\",\"#\",\"#\",\"#\"]]\n >>> minPushBox(grid = [[\"#\",\"#\",\"#\",\"#\",\"#\",\"#\"],)\n >>> -1\n \n Example 3:\n \n [\"#\",\"T\",\".\",\".\",\"#\",\"#\"],\n [\"#\",\".\",\"#\",\"B\",\".\",\"#\"],\n [\"#\",\".\",\".\",\".\",\".\",\"#\"],\n [\"#\",\".\",\".\",\".\",\"S\",\"#\"],\n [\"#\",\"#\",\"#\",\"#\",\"#\",\"#\"]]\n >>> minPushBox(grid = [[\"#\",\"#\",\"#\",\"#\",\"#\",\"#\"],)\n >>> 5\n Explanation: push the box down, left, left, up and up.\n \"\"\"\n"}
{"task_id": "minimum-time-visiting-all-points", "prompt": "def minTimeToVisitAllPoints(points: List[List[int]]) -> int:\n \"\"\"\n 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.\n You can move according to these rules:\n \n In 1 second, you can either:\n \n \n move vertically by one\u00a0unit,\n move horizontally by one unit, or\n move diagonally sqrt(2) units (in other words, move one unit vertically then one unit horizontally in 1 second).\n \n \n You have to visit the points in the same order as they appear in the array.\n You are allowed to pass through points that appear later in the order, but these do not count as visits.\n \n \n Example 1:\n \n \n >>> minTimeToVisitAllPoints(points = [[1,1],[3,4],[-1,0]])\n >>> 7\n Explanation: One optimal path is [1,1] -> [2,2] -> [3,3] -> [3,4] -> [2,3] -> [1,2] -> [0,1] -> [-1,0]\n Time from [1,1] to [3,4] = 3 seconds\n Time from [3,4] to [-1,0] = 4 seconds\n Total time = 7 seconds\n Example 2:\n \n >>> minTimeToVisitAllPoints(points = [[3,2],[-2,2]])\n >>> 5\n \"\"\"\n"}
{"task_id": "count-servers-that-communicate", "prompt": "def countServers(grid: List[List[int]]) -> int:\n \"\"\"\n You are given a map of a server center, represented as a m * n integer matrix\u00a0grid, 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.\n \n Return the number of servers\u00a0that communicate with any other server.\n \n Example 1:\n \n \n >>> countServers(grid = [[1,0],[0,1]])\n >>> 0\n Explanation:\u00a0No servers can communicate with others.\n Example 2:\n \n \n >>> countServers(grid = [[1,0],[1,1]])\n >>> 3\n Explanation:\u00a0All three servers can communicate with at least one other server.\n \n Example 3:\n \n \n >>> countServers(grid = [[1,1,0,0],[0,0,1,0],[0,0,1,0],[0,0,0,1]])\n >>> 4\n Explanation:\u00a0The 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.\n \"\"\"\n"}
{"task_id": "search-suggestions-system", "prompt": "def suggestedProducts(products: List[str], searchWord: str) -> List[List[str]]:\n \"\"\"\n You are given an array of strings products and a string searchWord.\n Design a system that suggests at most three product names from products after each character of searchWord is typed. Suggested products should have common prefix with searchWord. If there are more than three products with a common prefix return the three lexicographically minimums products.\n Return a list of lists of the suggested products after each character of searchWord is typed.\n \n Example 1:\n \n >>> suggestedProducts(products = [\"mobile\",\"mouse\",\"moneypot\",\"monitor\",\"mousepad\"], searchWord = \"mouse\")\n >>> [[\"mobile\",\"moneypot\",\"monitor\"],[\"mobile\",\"moneypot\",\"monitor\"],[\"mouse\",\"mousepad\"],[\"mouse\",\"mousepad\"],[\"mouse\",\"mousepad\"]]\n Explanation: products sorted lexicographically = [\"mobile\",\"moneypot\",\"monitor\",\"mouse\",\"mousepad\"].\n After typing m and mo all products match and we show user [\"mobile\",\"moneypot\",\"monitor\"].\n After typing mou, mous and mouse the system suggests [\"mouse\",\"mousepad\"].\n \n Example 2:\n \n >>> suggestedProducts(products = [\"havana\"], searchWord = \"havana\")\n >>> [[\"havana\"],[\"havana\"],[\"havana\"],[\"havana\"],[\"havana\"],[\"havana\"]]\n Explanation: The only word \"havana\" will be always suggested while typing the search word.\n \"\"\"\n"}
{"task_id": "number-of-ways-to-stay-in-the-same-place-after-some-steps", "prompt": "def numWays(steps: int, arrLen: int) -> int:\n \"\"\"\n You have a pointer at index 0 in an array of size arrLen. At each step, you can move 1 position to the left, 1 position to the right in the array, or stay in the same place (The pointer should not be placed outside the array at any time).\n Given two integers steps and arrLen, return the number of ways such that your pointer is still at index 0 after exactly steps steps. Since the answer may be too large, return it modulo 109 + 7.\n \n Example 1:\n \n >>> numWays(steps = 3, arrLen = 2)\n >>> 4\n Explanation: There are 4 differents ways to stay at index 0 after 3 steps.\n Right, Left, Stay\n Stay, Right, Left\n Right, Stay, Left\n Stay, Stay, Stay\n \n Example 2:\n \n >>> numWays(steps = 2, arrLen = 4)\n >>> 2\n Explanation: There are 2 differents ways to stay at index 0 after 2 steps\n Right, Left\n Stay, Stay\n \n Example 3:\n \n >>> numWays(steps = 4, arrLen = 2)\n >>> 8\n \"\"\"\n"}
{"task_id": "hexspeak", "prompt": "def toHexspeak(num: str) -> str:\n \"\"\"\n A decimal number can be converted to its Hexspeak representation by first converting it to an uppercase hexadecimal string, then replacing all occurrences of the digit '0' with the letter 'O', and the digit '1' with the letter 'I'. Such a representation is valid if and only if it consists only of the letters in the set {'A', 'B', 'C', 'D', 'E', 'F', 'I', 'O'}.\n Given a string num representing a decimal integer n, return the Hexspeak representation of n if it is valid, otherwise return \"ERROR\".\n \n Example 1:\n \n >>> toHexspeak(num = \"257\")\n >>> \"IOI\"\n Explanation: 257 is 101 in hexadecimal.\n \n Example 2:\n \n >>> toHexspeak(num = \"3\")\n >>> \"ERROR\"\n \"\"\"\n"}
{"task_id": "remove-interval", "prompt": "def removeInterval(intervals: List[List[int]], toBeRemoved: List[int]) -> List[List[int]]:\n \"\"\"\n A set of real numbers can be represented as the union of several disjoint intervals, where each interval is in the form [a, b). A real number x is in the set if one of its intervals [a, b) contains x (i.e. a <= x < b).\n You are given a sorted list of disjoint intervals intervals representing a set of real numbers as described above, where intervals[i] = [ai, bi] represents the interval [ai, bi). You are also given another interval toBeRemoved.\n Return the set of real numbers with the interval toBeRemoved removed from intervals. In other words, return the set of real numbers such that every x in the set is in intervals but not in toBeRemoved. Your answer should be a sorted list of disjoint intervals as described above.\n \n Example 1:\n \n \n >>> removeInterval(intervals = [[0,2],[3,4],[5,7]], toBeRemoved = [1,6])\n >>> [[0,1],[6,7]]\n \n Example 2:\n \n \n >>> removeInterval(intervals = [[0,5]], toBeRemoved = [2,3])\n >>> [[0,2],[3,5]]\n \n Example 3:\n \n >>> removeInterval(intervals = [[-5,-4],[-3,-2],[1,2],[3,5],[8,9]], toBeRemoved = [-1,4])\n >>> [[-5,-4],[-3,-2],[4,5],[8,9]]\n \"\"\"\n"}
{"task_id": "delete-tree-nodes", "prompt": "def deleteTreeNodes(nodes: int, parent: List[int], value: List[int]) -> int:\n \"\"\"\n A tree rooted at node 0 is given as follows:\n \n The number of nodes is nodes;\n The value of the ith node is value[i];\n The parent of the ith node is parent[i].\n \n Remove every subtree whose sum of values of nodes is zero.\n Return the number of the remaining nodes in the tree.\n \n Example 1:\n \n \n >>> deleteTreeNodes(nodes = 7, parent = [-1,0,0,1,2,2,2], value = [1,-2,4,0,-2,-1,-1])\n >>> 2\n \n Example 2:\n \n >>> deleteTreeNodes(nodes = 7, parent = [-1,0,0,1,2,2,2], value = [1,-2,4,0,-2,-1,-2])\n >>> 6\n \"\"\"\n"}
{"task_id": "find-winner-on-a-tic-tac-toe-game", "prompt": "def tictactoe(moves: List[List[int]]) -> str:\n \"\"\"\n Tic-tac-toe is played by two players A and B on a 3 x 3 grid. The rules of Tic-Tac-Toe are:\n \n Players take turns placing characters into empty squares ' '.\n The first player A always places 'X' characters, while the second player B always places 'O' characters.\n 'X' and 'O' characters are always placed into empty squares, never on filled ones.\n The game ends when there are three of the same (non-empty) character filling any row, column, or diagonal.\n The game also ends if all squares are non-empty.\n No more moves can be played if the game is over.\n \n Given a 2D integer array moves where moves[i] = [rowi, coli] indicates that the ith move will be played on grid[rowi][coli]. return the winner of the game if it exists (A or B). In case the game ends in a draw return \"Draw\". If there are still movements to play return \"Pending\".\n You can assume that moves is valid (i.e., it follows the rules of Tic-Tac-Toe), the grid is initially empty, and A will play first.\n \n Example 1:\n \n \n >>> tictactoe(moves = [[0,0],[2,0],[1,1],[2,1],[2,2]])\n >>> \"A\"\n Explanation: A wins, they always play first.\n \n Example 2:\n \n \n >>> tictactoe(moves = [[0,0],[1,1],[0,1],[0,2],[1,0],[2,0]])\n >>> \"B\"\n Explanation: B wins.\n \n Example 3:\n \n \n >>> tictactoe(moves = [[0,0],[1,1],[2,0],[1,0],[1,2],[2,1],[0,1],[0,2],[2,2]])\n >>> \"Draw\"\n Explanation: The game ends in a draw since there are no moves to make.\n \"\"\"\n"}
{"task_id": "number-of-burgers-with-no-waste-of-ingredients", "prompt": "def numOfBurgers(tomatoSlices: int, cheeseSlices: int) -> List[int]:\n \"\"\"\n Given two integers tomatoSlices and cheeseSlices. The ingredients of different burgers are as follows:\n \n Jumbo Burger: 4 tomato slices and 1 cheese slice.\n Small Burger: 2 Tomato slices and 1 cheese slice.\n \n Return [total_jumbo, total_small] so that the number of remaining tomatoSlices equal to 0 and the number of remaining cheeseSlices equal to 0. If it is not possible to make the remaining tomatoSlices and cheeseSlices equal to 0 return [].\n \n Example 1:\n \n >>> numOfBurgers(tomatoSlices = 16, cheeseSlices = 7)\n >>> [1,6]\n Explantion: To make one jumbo burger and 6 small burgers we need 4*1 + 2*6 = 16 tomato and 1 + 6 = 7 cheese.\n There will be no remaining ingredients.\n \n Example 2:\n \n >>> numOfBurgers(tomatoSlices = 17, cheeseSlices = 4)\n >>> []\n Explantion: There will be no way to use all ingredients to make small and jumbo burgers.\n \n Example 3:\n \n >>> numOfBurgers(tomatoSlices = 4, cheeseSlices = 17)\n >>> []\n Explantion: Making 1 jumbo burger there will be 16 cheese remaining and making 2 small burgers there will be 15 cheese remaining.\n \"\"\"\n"}
{"task_id": "count-square-submatrices-with-all-ones", "prompt": "def countSquares(matrix: List[List[int]]) -> int:\n \"\"\"\n Given a m * n matrix of ones and zeros, return how many square submatrices have all ones.\n \n Example 1:\n \n [\n \u00a0 [0,1,1,1],\n \u00a0 [1,1,1,1],\n \u00a0 [0,1,1,1]\n ]\n >>> countSquares(matrix =)\n >>> 15\n Explanation:\n There are 10 squares of side 1.\n There are 4 squares of side 2.\n There is 1 square of side 3.\n Total number of squares = 10 + 4 + 1 = 15.\n \n Example 2:\n \n [\n [1,0,1],\n [1,1,0],\n [1,1,0]\n ]\n >>> countSquares(matrix =)\n >>> 7\n Explanation:\n There are 6 squares of side 1.\n There is 1 square of side 2.\n Total number of squares = 6 + 1 = 7.\n \"\"\"\n"}
{"task_id": "palindrome-partitioning-iii", "prompt": "def palindromePartition(s: str, k: int) -> int:\n \"\"\"\n You are given a string s containing lowercase letters and an integer k. You need to :\n \n First, change some characters of s to other lowercase English letters.\n Then divide s into k non-empty disjoint substrings such that each substring is a palindrome.\n \n Return the minimal number of characters that you need to change to divide the string.\n \n Example 1:\n \n >>> palindromePartition(s = \"abc\", k = 2)\n >>> 1\n Explanation:\u00a0You can split the string into \"ab\" and \"c\", and change 1 character in \"ab\" to make it palindrome.\n \n Example 2:\n \n >>> palindromePartition(s = \"aabbc\", k = 3)\n >>> 0\n Explanation:\u00a0You can split the string into \"aa\", \"bb\" and \"c\", all of them are palindrome.\n Example 3:\n \n >>> palindromePartition(s = \"leetcode\", k = 8)\n >>> 0\n \"\"\"\n"}
{"task_id": "subtract-the-product-and-sum-of-digits-of-an-integer", "prompt": "def subtractProductAndSum(n: int) -> int:\n \"\"\"\n Given an integer number n, return the difference between the product of its digits and the sum of its digits.\n \n Example 1:\n \n >>> subtractProductAndSum(n = 234)\n >>> 15\n Explanation:\n Product of digits = 2 * 3 * 4 = 24\n Sum of digits = 2 + 3 + 4 = 9\n Result = 24 - 9 = 15\n \n Example 2:\n \n >>> subtractProductAndSum(n = 4421)\n >>> 21\n Explanation:\n Product of digits = 4 * 4 * 2 * 1 = 32\n Sum of digits = 4 + 4 + 2 + 1 = 11\n Result = 32 - 11 = 21\n \"\"\"\n"}
{"task_id": "group-the-people-given-the-group-size-they-belong-to", "prompt": "def groupThePeople(groupSizes: List[int]) -> List[List[int]]:\n \"\"\"\n There are n people\u00a0that are split into some unknown number of groups. Each person is labeled with a\u00a0unique ID\u00a0from\u00a00\u00a0to\u00a0n - 1.\n You are given an integer array\u00a0groupSizes, where groupSizes[i]\u00a0is the size of the group that person\u00a0i\u00a0is in. For example, if\u00a0groupSizes[1] = 3, then\u00a0person\u00a01\u00a0must be in a\u00a0group of size\u00a03.\n Return\u00a0a list of groups\u00a0such that\u00a0each person\u00a0i\u00a0is in a group of size\u00a0groupSizes[i].\n Each person should\u00a0appear in\u00a0exactly one group,\u00a0and every person must be in a group. If there are\u00a0multiple answers, return any of them. It is guaranteed that there will be at least one valid solution for the given input.\n \n Example 1:\n \n >>> groupThePeople(groupSizes = [3,3,3,3,3,1,3])\n >>> [[5],[0,1,2],[3,4,6]]\n Explanation:\n The first group is [5]. The size is 1, and groupSizes[5] = 1.\n The second group is [0,1,2]. The size is 3, and groupSizes[0] = groupSizes[1] = groupSizes[2] = 3.\n The third group is [3,4,6]. The size is 3, and groupSizes[3] = groupSizes[4] = groupSizes[6] = 3.\n Other possible solutions are [[2,1,6],[5],[0,4,3]] and [[5],[0,6,2],[4,3,1]].\n \n Example 2:\n \n >>> groupThePeople(groupSizes = [2,1,3,3,3,2])\n >>> [[1],[0,5],[2,3,4]]\n \"\"\"\n"}
{"task_id": "find-the-smallest-divisor-given-a-threshold", "prompt": "def smallestDivisor(nums: List[int], threshold: int) -> int:\n \"\"\"\n Given an array of integers nums and an integer threshold, we will choose a positive integer divisor, divide all the array by it, and sum the division's result. Find the smallest divisor such that the result mentioned above is less than or equal to threshold.\n Each result of the division is rounded to the nearest integer greater than or equal to that element. (For example: 7/3 = 3 and 10/2 = 5).\n The test cases are generated so\u00a0that there will be an answer.\n \n Example 1:\n \n >>> smallestDivisor(nums = [1,2,5,9], threshold = 6)\n >>> 5\n Explanation: We can get a sum to 17 (1+2+5+9) if the divisor is 1.\n If the divisor is 4 we can get a sum of 7 (1+1+2+3) and if the divisor is 5 the sum will be 5 (1+1+1+2).\n \n Example 2:\n \n >>> smallestDivisor(nums = [44,22,33,11,1], threshold = 5)\n >>> 44\n \"\"\"\n"}
{"task_id": "minimum-number-of-flips-to-convert-binary-matrix-to-zero-matrix", "prompt": "def minFlips(mat: List[List[int]]) -> int:\n \"\"\"\n Given a m x n binary matrix mat. In one step, you can choose one cell and flip it and all the four neighbors of it if they exist (Flip is changing 1 to 0 and 0 to 1). A pair of cells are called neighbors if they share one edge.\n Return the minimum number of steps required to convert mat to a zero matrix or -1 if you cannot.\n A binary matrix is a matrix with all cells equal to 0 or 1 only.\n A zero matrix is a matrix with all cells equal to 0.\n \n Example 1:\n \n \n >>> minFlips(mat = [[0,0],[0,1]])\n >>> 3\n Explanation: One possible solution is to flip (1, 0) then (0, 1) and finally (1, 1) as shown.\n \n Example 2:\n \n >>> minFlips(mat = [[0]])\n >>> 0\n Explanation: Given matrix is a zero matrix. We do not need to change it.\n \n Example 3:\n \n >>> minFlips(mat = [[1,0,0],[1,0,0]])\n >>> -1\n Explanation: Given matrix cannot be a zero matrix.\n \"\"\"\n"}
{"task_id": "element-appearing-more-than-25-in-sorted-array", "prompt": "def findSpecialInteger(arr: List[int]) -> int:\n \"\"\"\n Given an integer array sorted in non-decreasing order, there is exactly one integer in the array that occurs more than 25% of the time, return that integer.\n \n Example 1:\n \n >>> findSpecialInteger(arr = [1,2,2,6,6,6,6,7,10])\n >>> 6\n \n Example 2:\n \n >>> findSpecialInteger(arr = [1,1])\n >>> 1\n \"\"\"\n"}
{"task_id": "remove-covered-intervals", "prompt": "def removeCoveredIntervals(intervals: List[List[int]]) -> int:\n \"\"\"\n Given an array intervals where intervals[i] = [li, ri] represent the interval [li, ri), remove all intervals that are covered by another interval in the list.\n The interval [a, b) is covered by the interval [c, d) if and only if c <= a and b <= d.\n Return the number of remaining intervals.\n \n Example 1:\n \n >>> removeCoveredIntervals(intervals = [[1,4],[3,6],[2,8]])\n >>> 2\n Explanation: Interval [3,6] is covered by [2,8], therefore it is removed.\n \n Example 2:\n \n >>> removeCoveredIntervals(intervals = [[1,4],[2,3]])\n >>> 1\n \"\"\"\n"}
{"task_id": "minimum-falling-path-sum-ii", "prompt": "def minFallingPathSum(grid: List[List[int]]) -> int:\n \"\"\"\n Given an n x n integer matrix grid, return the minimum sum of a falling path with non-zero shifts.\n A falling path with non-zero shifts is a choice of exactly one element from each row of grid such that no two elements chosen in adjacent rows are in the same column.\n \n Example 1:\n \n \n >>> minFallingPathSum(grid = [[1,2,3],[4,5,6],[7,8,9]])\n >>> 13\n Explanation:\n The possible falling paths are:\n [1,5,9], [1,5,7], [1,6,7], [1,6,8],\n [2,4,8], [2,4,9], [2,6,7], [2,6,8],\n [3,4,8], [3,4,9], [3,5,7], [3,5,9]\n The falling path with the smallest sum is\u00a0[1,5,7], so the answer is\u00a013.\n \n Example 2:\n \n >>> minFallingPathSum(grid = [[7]])\n >>> 7\n \"\"\"\n"}
{"task_id": "convert-binary-number-in-a-linked-list-to-integer", "prompt": "# class ListNode:\n# def __init__(val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution:\n def getDecimalValue(head: Optional[ListNode]) -> int:\n \"\"\"\n Given head which is a reference node to a singly-linked list. The value of each node in the linked list is either 0 or 1. The linked list holds the binary representation of a number.\n Return the decimal value of the number in the linked list.\n The most significant bit is at the head of the linked list.\n \n Example 1:\n \n \n >>> __init__(head = [1,0,1])\n >>> 5\n Explanation: (101) in base 2 = (5) in base 10\n \n Example 2:\n \n >>> __init__(head = [0])\n >>> 0\n \"\"\"\n"}
{"task_id": "sequential-digits", "prompt": "def sequentialDigits(low: int, high: int) -> List[int]:\n \"\"\"\n An\u00a0integer has sequential digits if and only if each digit in the number is one more than the previous digit.\n Return a sorted list of all the integers\u00a0in the range [low, high]\u00a0inclusive that have sequential digits.\n \n Example 1:\n >>> sequentialDigits(low = 100, high = 300)\n >>> [123,234]\n Example 2:\n >>> sequentialDigits(low = 1000, high = 13000)\n >>> [1234,2345,3456,4567,5678,6789,12345]\n \"\"\"\n"}
{"task_id": "maximum-side-length-of-a-square-with-sum-less-than-or-equal-to-threshold", "prompt": "def maxSideLength(mat: List[List[int]], threshold: int) -> int:\n \"\"\"\n Given a m x n matrix mat and an integer threshold, return the maximum side-length of a square with a sum less than or equal to threshold or return 0 if there is no such square.\n \n Example 1:\n \n \n >>> maxSideLength(mat = [[1,1,3,2,4,3,2],[1,1,3,2,4,3,2],[1,1,3,2,4,3,2]], threshold = 4)\n >>> 2\n Explanation: The maximum side length of square with sum less than 4 is 2 as shown.\n \n Example 2:\n \n >>> maxSideLength(mat = [[2,2,2,2,2],[2,2,2,2,2],[2,2,2,2,2],[2,2,2,2,2],[2,2,2,2,2]], threshold = 1)\n >>> 0\n \"\"\"\n"}
{"task_id": "shortest-path-in-a-grid-with-obstacles-elimination", "prompt": "def shortestPath(grid: List[List[int]], k: int) -> int:\n \"\"\"\n You are given an m x n integer matrix grid where each cell is either 0 (empty) or 1 (obstacle). You can move up, down, left, or right from and to an empty cell in one step.\n Return the minimum number of steps to walk from the upper left corner (0, 0) to the lower right corner (m - 1, n - 1) given that you can eliminate at most k obstacles. If it is not possible to find such walk return -1.\n \n Example 1:\n \n \n >>> shortestPath(grid = [[0,0,0],[1,1,0],[0,0,0],[0,1,1],[0,0,0]], k = 1)\n >>> 6\n Explanation:\n The shortest path without eliminating any obstacle is 10.\n The shortest path with one obstacle elimination at position (3,2) is 6. Such path is (0,0) -> (0,1) -> (0,2) -> (1,2) -> (2,2) -> (3,2) -> (4,2).\n \n Example 2:\n \n \n >>> shortestPath(grid = [[0,1,1],[1,1,1],[1,0,0]], k = 1)\n >>> -1\n Explanation: We need to eliminate at least two obstacles to find such a walk.\n \"\"\"\n"}
{"task_id": "find-numbers-with-even-number-of-digits", "prompt": "def findNumbers(nums: List[int]) -> int:\n \"\"\"\n Given an array nums of integers, return how many of them contain an even number of digits.\n \n Example 1:\n \n >>> findNumbers(nums = [12,345,2,6,7896])\n >>> 2\n Explanation:\n 12 contains 2 digits (even number of digits).\n 345 contains 3 digits (odd number of digits).\n 2 contains 1 digit (odd number of digits).\n 6 contains 1 digit (odd number of digits).\n 7896 contains 4 digits (even number of digits).\n Therefore only 12 and 7896 contain an even number of digits.\n \n Example 2:\n \n >>> findNumbers(nums = [555,901,482,1771])\n >>> 1\n Explanation:\n Only 1771 contains an even number of digits.\n \"\"\"\n"}
{"task_id": "divide-array-in-sets-of-k-consecutive-numbers", "prompt": "def isPossibleDivide(nums: List[int], k: int) -> bool:\n \"\"\"\n Given an array of integers nums and a positive integer k, check whether it is possible to divide this array into sets of k consecutive numbers.\n Return true if it is possible. Otherwise, return false.\n \n Example 1:\n \n >>> isPossibleDivide(nums = [1,2,3,3,4,4,5,6], k = 4)\n >>> true\n Explanation: Array can be divided into [1,2,3,4] and [3,4,5,6].\n \n Example 2:\n \n >>> isPossibleDivide(nums = [3,2,1,2,3,4,3,4,5,9,10,11], k = 3)\n >>> true\n Explanation: Array can be divided into [1,2,3] , [2,3,4] , [3,4,5] and [9,10,11].\n \n Example 3:\n \n >>> isPossibleDivide(nums = [1,2,3,4], k = 3)\n >>> false\n Explanation: Each array should be divided in subarrays of size 3.\n \"\"\"\n"}
{"task_id": "maximum-number-of-occurrences-of-a-substring", "prompt": "def maxFreq(s: str, maxLetters: int, minSize: int, maxSize: int) -> int:\n \"\"\"\n Given a string s, return the maximum number of occurrences of any substring under the following rules:\n \n The number of unique characters in the substring must be less than or equal to maxLetters.\n The substring size must be between minSize and maxSize inclusive.\n \n \n Example 1:\n \n >>> maxFreq(s = \"aababcaab\", maxLetters = 2, minSize = 3, maxSize = 4)\n >>> 2\n Explanation: Substring \"aab\" has 2 occurrences in the original string.\n It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize).\n \n Example 2:\n \n >>> maxFreq(s = \"aaaa\", maxLetters = 1, minSize = 3, maxSize = 3)\n >>> 2\n Explanation: Substring \"aaa\" occur 2 times in the string. It can overlap.\n \"\"\"\n"}
{"task_id": "maximum-candies-you-can-get-from-boxes", "prompt": "def maxCandies(status: List[int], candies: List[int], keys: List[List[int]], containedBoxes: List[List[int]], initialBoxes: List[int]) -> int:\n \"\"\"\n You have n boxes labeled from 0 to n - 1. You are given four arrays: status, candies, keys, and containedBoxes where:\n \n status[i] is 1 if the ith box is open and 0 if the ith box is closed,\n candies[i] is the number of candies in the ith box,\n keys[i] is a list of the labels of the boxes you can open after opening the ith box.\n containedBoxes[i] is a list of the boxes you found inside the ith box.\n \n You are given an integer array initialBoxes that contains the labels of the boxes you initially have. You can take all the candies in any open box and you can use the keys in it to open new boxes and you also can use the boxes you find in it.\n Return the maximum number of candies you can get following the rules above.\n \n Example 1:\n \n >>> maxCandies(status = [1,0,1,0], candies = [7,5,4,100], keys = [[],[],[1],[]], containedBoxes = [[1,2],[3],[],[]], initialBoxes = [0])\n >>> 16\n Explanation: You will be initially given box 0. You will find 7 candies in it and boxes 1 and 2.\n Box 1 is closed and you do not have a key for it so you will open box 2. You will find 4 candies and a key to box 1 in box 2.\n In box 1, you will find 5 candies and box 3 but you will not find a key to box 3 so box 3 will remain closed.\n Total number of candies collected = 7 + 4 + 5 = 16 candy.\n \n Example 2:\n \n >>> maxCandies(status = [1,0,0,0,0,0], candies = [1,1,1,1,1,1], keys = [[1,2,3,4,5],[],[],[],[],[]], containedBoxes = [[1,2,3,4,5],[],[],[],[],[]], initialBoxes = [0])\n >>> 6\n Explanation: You have initially box 0. Opening it you can find boxes 1,2,3,4 and 5 and their keys.\n The total number of candies will be 6.\n \"\"\"\n"}
{"task_id": "replace-elements-with-greatest-element-on-right-side", "prompt": "def replaceElements(arr: List[int]) -> List[int]:\n \"\"\"\n Given an array arr,\u00a0replace every element in that array with the greatest element among the elements to its\u00a0right, and replace the last element with -1.\n After doing so, return the array.\n \n Example 1:\n \n >>> replaceElements(arr = [17,18,5,4,6,1])\n >>> [18,6,6,6,1,-1]\n Explanation:\n - index 0 --> the greatest element to the right of index 0 is index 1 (18).\n - index 1 --> the greatest element to the right of index 1 is index 4 (6).\n - index 2 --> the greatest element to the right of index 2 is index 4 (6).\n - index 3 --> the greatest element to the right of index 3 is index 4 (6).\n - index 4 --> the greatest element to the right of index 4 is index 5 (1).\n - index 5 --> there are no elements to the right of index 5, so we put -1.\n \n Example 2:\n \n >>> replaceElements(arr = [400])\n >>> [-1]\n Explanation: There are no elements to the right of index 0.\n \"\"\"\n"}
{"task_id": "sum-of-mutated-array-closest-to-target", "prompt": "def findBestValue(arr: List[int], target: int) -> int:\n \"\"\"\n Given an integer array arr and a target value target, return the integer value such that when we change all the integers larger than value in the given array to be equal to value, the sum of the array gets as close as possible (in absolute difference) to target.\n In case of a tie, return the minimum such integer.\n Notice that the answer is not neccesarilly a number from arr.\n \n Example 1:\n \n >>> findBestValue(arr = [4,9,3], target = 10)\n >>> 3\n Explanation: When using 3 arr converts to [3, 3, 3] which sums 9 and that's the optimal answer.\n \n Example 2:\n \n >>> findBestValue(arr = [2,3,5], target = 10)\n >>> 5\n \n Example 3:\n \n >>> findBestValue(arr = [60864,25176,27249,21296,20204], target = 56803)\n >>> 11361\n \"\"\"\n"}
{"task_id": "number-of-paths-with-max-score", "prompt": "def pathsWithMaxScore(board: List[str]) -> List[int]:\n \"\"\"\n You are given a square board\u00a0of characters. You can move on the board starting at the bottom right square marked with the character\u00a0'S'.\\r\n \\r\n You need\u00a0to reach the top left square marked with the character 'E'. The rest of the squares are labeled either with a numeric character\u00a01, 2, ..., 9 or with an obstacle 'X'. In one move you can go up, left or up-left (diagonally) only if there is no obstacle there.\\r\n \\r\n Return a list of two integers: the first integer is the maximum sum of numeric characters you can collect, and the second is the number of such paths that you can take to get that maximum sum, taken modulo 10^9 + 7.\\r\n \\r\n In case there is no path, return\u00a0[0, 0].\\r\n \\r\n \u00a0\\r\n Example 1:\\r\n >>> pathsWithMaxScore(board = [\"E23\",\"2X2\",\"12S\"]\\r)\n >>> [7,1]\\r\n Example 2:\\r\n >>> pathsWithMaxScore(board = [\"E12\",\"1X1\",\"21S\"]\\r)\n >>> [4,2]\\r\n Example 3:\\r\n >>> pathsWithMaxScore(board = [\"E11\",\"XXX\",\"11S\"]\\r)\n >>> [0,0]\\r\n \\r\n \u00a0\\r\n \"\"\"\n"}
{"task_id": "deepest-leaves-sum", "prompt": "# class TreeNode:\n# def __init__(val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def deepestLeavesSum(root: Optional[TreeNode]) -> int:\n \"\"\"\n Given the root of a binary tree, return the sum of values of its deepest leaves.\n \n Example 1:\n \n \n >>> __init__(root = [1,2,3,4,5,null,6,7,null,null,null,null,8])\n >>> 15\n \n Example 2:\n \n >>> __init__(root = [6,7,8,2,7,1,3,9,null,1,4,null,null,null,5])\n >>> 19\n \"\"\"\n"}
{"task_id": "find-n-unique-integers-sum-up-to-zero", "prompt": "def sumZero(n: int) -> List[int]:\n \"\"\"\n Given an integer n, return any array containing n unique integers such that they add up to 0.\n \n Example 1:\n \n >>> sumZero(n = 5)\n >>> [-7,-1,1,3,4]\n Explanation: These arrays also are accepted [-5,-1,1,2,3] , [-3,-1,2,-2,4].\n \n Example 2:\n \n >>> sumZero(n = 3)\n >>> [-1,0,1]\n \n Example 3:\n \n >>> sumZero(n = 1)\n >>> [0]\n \"\"\"\n"}
{"task_id": "all-elements-in-two-binary-search-trees", "prompt": "# class TreeNode:\n# def __init__(val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def getAllElements(root1: Optional[TreeNode], root2: Optional[TreeNode]) -> List[int]:\n \"\"\"\n Given two binary search trees root1 and root2, return a list containing all the integers from both trees sorted in ascending order.\n \n Example 1:\n \n \n >>> __init__(root1 = [2,1,4], root2 = [1,0,3])\n >>> [0,1,1,2,3,4]\n \n Example 2:\n \n \n >>> __init__(root1 = [1,null,8], root2 = [8,1])\n >>> [1,1,8,8]\n \"\"\"\n"}
{"task_id": "jump-game-iii", "prompt": "def canReach(arr: List[int], start: int) -> bool:\n \"\"\"\n Given an array of non-negative integers arr, you are initially positioned at start\u00a0index of the array. When you are at index i, you can jump\u00a0to i + arr[i] or i - arr[i], check if you can reach\u00a0any index with value 0.\n Notice that you can not jump outside of the array at any time.\n \n Example 1:\n \n >>> canReach(arr = [4,2,3,0,3,1,2], start = 5)\n >>> true\n Explanation:\n All possible ways to reach at index 3 with value 0 are:\n index 5 -> index 4 -> index 1 -> index 3\n index 5 -> index 6 -> index 4 -> index 1 -> index 3\n \n Example 2:\n \n >>> canReach(arr = [4,2,3,0,3,1,2], start = 0)\n >>> true\n Explanation:\n One possible way to reach at index 3 with value 0 is:\n index 0 -> index 4 -> index 1 -> index 3\n \n Example 3:\n \n >>> canReach(arr = [3,0,2,1,2], start = 2)\n >>> false\n Explanation: There is no way to reach at index 1 with value 0.\n \"\"\"\n"}
{"task_id": "verbal-arithmetic-puzzle", "prompt": "def isSolvable(words: List[str], result: str) -> bool:\n \"\"\"\n Given an equation, represented by words on the left side and the result on the right side.\n You need to check if the equation is solvable under the following rules:\n \n Each character is decoded as one digit (0 - 9).\n No two characters can map to the same digit.\n Each words[i] and result are decoded as one number without leading zeros.\n Sum of numbers on the left side (words) will equal to the number on the right side (result).\n \n Return true if the equation is solvable, otherwise return false.\n \n Example 1:\n \n >>> isSolvable(words = [\"SEND\",\"MORE\"], result = \"MONEY\")\n >>> true\n Explanation: Map 'S'-> 9, 'E'->5, 'N'->6, 'D'->7, 'M'->1, 'O'->0, 'R'->8, 'Y'->'2'\n Such that: \"SEND\" + \"MORE\" = \"MONEY\" , 9567 + 1085 = 10652\n Example 2:\n \n >>> isSolvable(words = [\"SIX\",\"SEVEN\",\"SEVEN\"], result = \"TWENTY\")\n >>> true\n Explanation: Map 'S'-> 6, 'I'->5, 'X'->0, 'E'->8, 'V'->7, 'N'->2, 'T'->1, 'W'->'3', 'Y'->4\n Such that: \"SIX\" + \"SEVEN\" + \"SEVEN\" = \"TWENTY\" , 650 + 68782 + 68782 = 138214\n Example 3:\n \n >>> isSolvable(words = [\"LEET\",\"CODE\"], result = \"POINT\")\n >>> false\n Explanation: There is no possible mapping to satisfy the equation, so we return false.\n Note that two different characters cannot map to the same digit.\n \"\"\"\n"}
{"task_id": "decrypt-string-from-alphabet-to-integer-mapping", "prompt": "def freqAlphabets(s: str) -> str:\n \"\"\"\n You are given a string s formed by digits and '#'. We want to map s to English lowercase characters as follows:\n \n Characters ('a' to 'i') are represented by ('1' to '9') respectively.\n Characters ('j' to 'z') are represented by ('10#' to '26#') respectively.\n \n Return the string formed after mapping.\n The test cases are generated so that a unique mapping will always exist.\n \n Example 1:\n \n >>> freqAlphabets(s = \"10#11#12\")\n >>> \"jkab\"\n Explanation: \"j\" -> \"10#\" , \"k\" -> \"11#\" , \"a\" -> \"1\" , \"b\" -> \"2\".\n \n Example 2:\n \n >>> freqAlphabets(s = \"1326#\")\n >>> \"acz\"\n \"\"\"\n"}
{"task_id": "xor-queries-of-a-subarray", "prompt": "def xorQueries(arr: List[int], queries: List[List[int]]) -> List[int]:\n \"\"\"\n You are given an array arr of positive integers. You are also given the array queries where queries[i] = [lefti, righti].\n For each query i compute the XOR of elements from lefti to righti (that is, arr[lefti] XOR arr[lefti + 1] XOR ... XOR arr[righti] ).\n Return an array answer where answer[i] is the answer to the ith query.\n \n Example 1:\n \n >>> xorQueries(arr = [1,3,4,8], queries = [[0,1],[1,2],[0,3],[3,3]])\n >>> [2,7,14,8]\n Explanation:\n The binary representation of the elements in the array are:\n 1 = 0001\n 3 = 0011\n 4 = 0100\n 8 = 1000\n The XOR values for queries are:\n [0,1] = 1 xor 3 = 2\n [1,2] = 3 xor 4 = 7\n [0,3] = 1 xor 3 xor 4 xor 8 = 14\n [3,3] = 8\n \n Example 2:\n \n >>> xorQueries(arr = [4,8,2,10], queries = [[2,3],[1,3],[0,0],[0,3]])\n >>> [8,0,4,4]\n \"\"\"\n"}
{"task_id": "get-watched-videos-by-your-friends", "prompt": "def watchedVideosByFriends(watchedVideos: List[List[str]], friends: List[List[int]], id: int, level: int) -> List[str]:\n \"\"\"\n There are n people, each person has a unique id between 0 and n-1. Given the arrays watchedVideos and friends, where watchedVideos[i] and friends[i] contain the list of watched videos and the list of friends respectively for the person with id = i.\n Level 1 of videos are all watched videos by your\u00a0friends, level 2 of videos are all watched videos by the friends of your\u00a0friends and so on. In general, the level k of videos are all\u00a0watched videos by people\u00a0with the shortest path exactly equal\u00a0to\u00a0k with you. Given your\u00a0id and the level of videos, return the list of videos ordered by their frequencies (increasing). For videos with the same frequency order them alphabetically from least to greatest.\n \n Example 1:\n \n \n >>> watchedVideosByFriends(watchedVideos = [[\"A\",\"B\"],[\"C\"],[\"B\",\"C\"],[\"D\"]], friends = [[1,2],[0,3],[0,3],[1,2]], id = 0, level = 1)\n >>> [\"B\",\"C\"]\n Explanation:\n You have id = 0 (green color in the figure) and your friends are (yellow color in the figure):\n Person with id = 1 -> watchedVideos = [\"C\"]\n Person with id = 2 -> watchedVideos = [\"B\",\"C\"]\n The frequencies of watchedVideos by your friends are:\n B -> 1\n C -> 2\n \n Example 2:\n \n \n >>> watchedVideosByFriends(watchedVideos = [[\"A\",\"B\"],[\"C\"],[\"B\",\"C\"],[\"D\"]], friends = [[1,2],[0,3],[0,3],[1,2]], id = 0, level = 2)\n >>> [\"D\"]\n Explanation:\n You have id = 0 (green color in the figure) and the only friend of your friends is the person with id = 3 (yellow color in the figure).\n \"\"\"\n"}
{"task_id": "minimum-insertion-steps-to-make-a-string-palindrome", "prompt": "def minInsertions(s: str) -> int:\n \"\"\"\n Given a string s. In one step you can insert any character at any index of the string.\n Return the minimum number of steps to make s\u00a0palindrome.\n A\u00a0Palindrome String\u00a0is one that reads the same backward as well as forward.\n \n Example 1:\n \n >>> minInsertions(s = \"zzazz\")\n >>> 0\n Explanation: The string \"zzazz\" is already palindrome we do not need any insertions.\n \n Example 2:\n \n >>> minInsertions(s = \"mbadm\")\n >>> 2\n Explanation: String can be \"mbdadbm\" or \"mdbabdm\".\n \n Example 3:\n \n >>> minInsertions(s = \"leetcode\")\n >>> 5\n Explanation: Inserting 5 characters the string becomes \"leetcodocteel\".\n \"\"\"\n"}
{"task_id": "decompress-run-length-encoded-list", "prompt": "def decompressRLElist(nums: List[int]) -> List[int]:\n \"\"\"\n We are given a list nums of integers representing a list compressed with run-length encoding.\n Consider each adjacent pair\u00a0of elements [freq, val] = [nums[2*i], nums[2*i+1]]\u00a0(with i >= 0).\u00a0 For each such pair, there are freq elements with value val concatenated in a sublist. Concatenate all the sublists from left to right to generate the decompressed list.\n Return the decompressed list.\n \n Example 1:\n \n >>> decompressRLElist(nums = [1,2,3,4])\n >>> [2,4,4,4]\n Explanation: The first pair [1,2] means we have freq = 1 and val = 2 so we generate the array [2].\n The second pair [3,4] means we have freq = 3 and val = 4 so we generate [4,4,4].\n At the end the concatenation [2] + [4,4,4] is [2,4,4,4].\n \n Example 2:\n \n >>> decompressRLElist(nums = [1,1,2,3])\n >>> [1,3,3]\n \"\"\"\n"}
{"task_id": "matrix-block-sum", "prompt": "def matrixBlockSum(mat: List[List[int]], k: int) -> List[List[int]]:\n \"\"\"\n Given a m x n matrix mat and an integer k, return a matrix answer where each answer[i][j] is the sum of all elements mat[r][c] for:\n \n i - k <= r <= i + k,\n j - k <= c <= j + k, and\n (r, c) is a valid position in the matrix.\n \n \n Example 1:\n \n >>> matrixBlockSum(mat = [[1,2,3],[4,5,6],[7,8,9]], k = 1)\n >>> [[12,21,16],[27,45,33],[24,39,28]]\n \n Example 2:\n \n >>> matrixBlockSum(mat = [[1,2,3],[4,5,6],[7,8,9]], k = 2)\n >>> [[45,45,45],[45,45,45],[45,45,45]]\n \"\"\"\n"}
{"task_id": "sum-of-nodes-with-even-valued-grandparent", "prompt": "# class TreeNode:\n# def __init__(val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def sumEvenGrandparent(root: Optional[TreeNode]) -> int:\n \"\"\"\n Given the root of a binary tree, return the sum of values of nodes with an even-valued grandparent. If there are no nodes with an even-valued grandparent, return 0.\n A grandparent of a node is the parent of its parent if it exists.\n \n Example 1:\n \n \n >>> __init__(root = [6,7,8,2,7,1,3,9,null,1,4,null,null,null,5])\n >>> 18\n Explanation: The red nodes are the nodes with even-value grandparent while the blue nodes are the even-value grandparents.\n \n Example 2:\n \n \n >>> __init__(root = [1])\n >>> 0\n \"\"\"\n"}
{"task_id": "distinct-echo-substrings", "prompt": "def distinctEchoSubstrings(text: str) -> int:\n \"\"\"\n Return the number of distinct non-empty substrings of text\u00a0that can be written as the concatenation of some string with itself (i.e. it can be written as a + a\u00a0where a is some string).\n \n Example 1:\n \n >>> distinctEchoSubstrings(text = \"abcabcabc\")\n >>> 3\n Explanation: The 3 substrings are \"abcabc\", \"bcabca\" and \"cabcab\".\n \n Example 2:\n \n >>> distinctEchoSubstrings(text = \"leetcodeleetcode\")\n >>> 2\n Explanation: The 2 substrings are \"ee\" and \"leetcodeleetcode\".\n \"\"\"\n"}
{"task_id": "convert-integer-to-the-sum-of-two-no-zero-integers", "prompt": "def getNoZeroIntegers(n: int) -> List[int]:\n \"\"\"\n No-Zero integer is a positive integer that does not contain any 0 in its decimal representation.\n Given an integer n, return a list of two integers [a, b] where:\n \n a and b are No-Zero integers.\n a + b = n\n \n The test cases are generated so that there is at least one valid solution. If there are many valid solutions, you can return any of them.\n \n Example 1:\n \n >>> getNoZeroIntegers(n = 2)\n >>> [1,1]\n Explanation: Let a = 1 and b = 1.\n Both a and b are no-zero integers, and a + b = 2 = n.\n \n Example 2:\n \n >>> getNoZeroIntegers(n = 11)\n >>> [2,9]\n Explanation: Let a = 2 and b = 9.\n Both a and b are no-zero integers, and a + b = 11 = n.\n Note that there are other valid answers as [8, 3] that can be accepted.\n \"\"\"\n"}
{"task_id": "minimum-flips-to-make-a-or-b-equal-to-c", "prompt": "def minFlips(a: int, b: int, c: int) -> int:\n \"\"\"\n Given 3 positives numbers a, b and c. Return the minimum flips required in some bits of a and b to make (\u00a0a OR b == c\u00a0). (bitwise OR operation).\\r\n Flip operation\u00a0consists of change\u00a0any\u00a0single bit 1 to 0 or change the bit 0 to 1\u00a0in their binary representation.\\r\n \\r\n \u00a0\\r\n Example 1:\\r\n \\r\n \\r\n \\r\n \\r\n >>> minFlips(a = 2, b = 6, c = 5\\r)\n >>> 3\\r\n Explanation: After flips a = 1 , b = 4 , c = 5 such that (a OR b == c)\\r\n \\r\n Example 2:\\r\n \\r\n \\r\n >>> minFlips(a = 4, b = 2, c = 7\\r)\n >>> 1\\r\n \\r\n \\r\n Example 3:\\r\n \\r\n \\r\n >>> minFlips(a = 1, b = 2, c = 3\\r)\n >>> 0\\r\n \\r\n \\r\n \u00a0\\r\n \"\"\"\n"}
{"task_id": "number-of-operations-to-make-network-connected", "prompt": "def makeConnected(n: int, connections: List[List[int]]) -> int:\n \"\"\"\n There are n computers numbered from 0 to n - 1 connected by ethernet cables connections forming a network where connections[i] = [ai, bi] represents a connection between computers ai and bi. Any computer can reach any other computer directly or indirectly through the network.\n You are given an initial computer network connections. You can extract certain cables between two directly connected computers, and place them between any pair of disconnected computers to make them directly connected.\n Return the minimum number of times you need to do this in order to make all the computers connected. If it is not possible, return -1.\n \n Example 1:\n \n \n >>> makeConnected(n = 4, connections = [[0,1],[0,2],[1,2]])\n >>> 1\n Explanation: Remove cable between computer 1 and 2 and place between computers 1 and 3.\n \n Example 2:\n \n \n >>> makeConnected(n = 6, connections = [[0,1],[0,2],[0,3],[1,2],[1,3]])\n >>> 2\n \n Example 3:\n \n >>> makeConnected(n = 6, connections = [[0,1],[0,2],[0,3],[1,2]])\n >>> -1\n Explanation: There are not enough cables.\n \"\"\"\n"}
{"task_id": "minimum-distance-to-type-a-word-using-two-fingers", "prompt": "def minimumDistance(word: str) -> int:\n \"\"\"\n You have a keyboard layout as shown above in the X-Y plane, where each English uppercase letter is located at some coordinate.\n \n For example, the letter 'A' is located at coordinate (0, 0), the letter 'B' is located at coordinate (0, 1), the letter 'P' is located at coordinate (2, 3) and the letter 'Z' is located at coordinate (4, 1).\n \n Given the string word, return the minimum total distance to type such string using only two fingers.\n The distance between coordinates (x1, y1) and (x2, y2) is |x1 - x2| + |y1 - y2|.\n Note that the initial positions of your two fingers are considered free so do not count towards your total distance, also your two fingers do not have to start at the first letter or the first two letters.\n \n Example 1:\n \n >>> minimumDistance(word = \"CAKE\")\n >>> 3\n Explanation: Using two fingers, one optimal way to type \"CAKE\" is:\n Finger 1 on letter 'C' -> cost = 0\n Finger 1 on letter 'A' -> cost = Distance from letter 'C' to letter 'A' = 2\n Finger 2 on letter 'K' -> cost = 0\n Finger 2 on letter 'E' -> cost = Distance from letter 'K' to letter 'E' = 1\n Total distance = 3\n \n Example 2:\n \n >>> minimumDistance(word = \"HAPPY\")\n >>> 6\n Explanation: Using two fingers, one optimal way to type \"HAPPY\" is:\n Finger 1 on letter 'H' -> cost = 0\n Finger 1 on letter 'A' -> cost = Distance from letter 'H' to letter 'A' = 2\n Finger 2 on letter 'P' -> cost = 0\n Finger 2 on letter 'P' -> cost = Distance from letter 'P' to letter 'P' = 0\n Finger 1 on letter 'Y' -> cost = Distance from letter 'A' to letter 'Y' = 4\n Total distance = 6\n \"\"\"\n"}
{"task_id": "print-words-vertically", "prompt": "def printVertically(s: str) -> List[str]:\n \"\"\"\n Given a string s.\u00a0Return\u00a0all the words vertically in the same order in which they appear in s.\\r\n Words are returned as a list of strings, complete with\u00a0spaces when is necessary. (Trailing spaces are not allowed).\\r\n Each word would be put on only one column and that in one column there will be only one word.\\r\n \\r\n \u00a0\\r\n Example 1:\\r\n \\r\n \\r\n >>> printVertically(s = \"HOW ARE YOU\"\\r)\n >>> [\"HAY\",\"ORO\",\"WEU\"]\\r\n Explanation: Each word is printed vertically. \\r\n \"HAY\"\\r\n \u00a0\"ORO\"\\r\n \u00a0\"WEU\"\\r\n \\r\n \\r\n Example 2:\\r\n \\r\n \\r\n >>> printVertically(s = \"TO BE OR NOT TO BE\"\\r)\n >>> [\"TBONTB\",\"OEROOE\",\" T\"]\\r\n Explanation: Trailing spaces is not allowed. \\r\n \"TBONTB\"\\r\n \"OEROOE\"\\r\n \" T\"\\r\n \\r\n \\r\n Example 3:\\r\n \\r\n \\r\n >>> printVertically(s = \"CONTEST IS COMING\"\\r)\n >>> [\"CIC\",\"OSO\",\"N M\",\"T I\",\"E N\",\"S G\",\"T\"]\\r\n \\r\n \\r\n \u00a0\\r\n \"\"\"\n"}
{"task_id": "delete-leaves-with-a-given-value", "prompt": "# class TreeNode:\n# def __init__(val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def removeLeafNodes(root: Optional[TreeNode], target: int) -> Optional[TreeNode]:\n \"\"\"\n Given a binary tree root and an integer target, delete all the leaf nodes with value target.\n Note that once you delete a leaf node with value target, if its parent node becomes a leaf node and has the value target, it should also be deleted (you need to continue doing that until you cannot).\n \n Example 1:\n \n \n >>> __init__(root = [1,2,3,2,null,2,4], target = 2)\n >>> [1,null,3,null,4]\n Explanation: Leaf nodes in green with value (target = 2) are removed (Picture in left).\n After removing, new nodes become leaf nodes with value (target = 2) (Picture in center).\n \n Example 2:\n \n \n >>> __init__(root = [1,3,3,3,2], target = 3)\n >>> [1,3,null,null,2]\n \n Example 3:\n \n \n >>> __init__(root = [1,2,null,2,null,2], target = 2)\n >>> [1]\n Explanation: Leaf nodes in green with value (target = 2) are removed at each step.\n \"\"\"\n"}
{"task_id": "minimum-number-of-taps-to-open-to-water-a-garden", "prompt": "def minTaps(n: int, ranges: List[int]) -> int:\n \"\"\"\n There is a one-dimensional garden on the x-axis. The garden starts at the point 0 and ends at the point n. (i.e., the\u00a0length of the garden is n).\n There are n + 1 taps located at points [0, 1, ..., n] in the garden.\n Given an integer n and an integer array ranges of length n + 1 where ranges[i] (0-indexed) means the i-th tap can water the area [i - ranges[i], i + ranges[i]] if it was open.\n Return the minimum number of taps that should be open to water the whole garden, If the garden cannot be watered return -1.\n \n Example 1:\n \n \n >>> minTaps(n = 5, ranges = [3,4,1,1,0,0])\n >>> 1\n Explanation: The tap at point 0 can cover the interval [-3,3]\n The tap at point 1 can cover the interval [-3,5]\n The tap at point 2 can cover the interval [1,3]\n The tap at point 3 can cover the interval [2,4]\n The tap at point 4 can cover the interval [4,4]\n The tap at point 5 can cover the interval [5,5]\n Opening Only the second tap will water the whole garden [0,5]\n \n Example 2:\n \n >>> minTaps(n = 3, ranges = [0,0,0,0])\n >>> -1\n Explanation: Even if you activate all the four taps you cannot water the whole garden.\n \"\"\"\n"}
{"task_id": "break-a-palindrome", "prompt": "def breakPalindrome(palindrome: str) -> str:\n \"\"\"\n Given a palindromic string of lowercase English letters palindrome, replace exactly one character with any lowercase English letter so that the resulting string is not a palindrome and that it is the lexicographically smallest one possible.\n Return the resulting string. If there is no way to replace a character to make it not a palindrome, return an empty string.\n A string a is lexicographically smaller than a string b (of the same length) if in the first position where a and b differ, a has a character strictly smaller than the corresponding character in b. For example, \"abcc\" is lexicographically smaller than \"abcd\" because the first position they differ is at the fourth character, and 'c' is smaller than 'd'.\n \n Example 1:\n \n >>> breakPalindrome(palindrome = \"abccba\")\n >>> \"aaccba\"\n Explanation: There are many ways to make \"abccba\" not a palindrome, such as \"zbccba\", \"aaccba\", and \"abacba\".\n Of all the ways, \"aaccba\" is the lexicographically smallest.\n \n Example 2:\n \n >>> breakPalindrome(palindrome = \"a\")\n >>> \"\"\n Explanation: There is no way to replace a single character to make \"a\" not a palindrome, so return an empty string.\n \"\"\"\n"}
{"task_id": "sort-the-matrix-diagonally", "prompt": "def diagonalSort(mat: List[List[int]]) -> List[List[int]]:\n \"\"\"\n A matrix diagonal is a diagonal line of cells starting from some cell in either the topmost row or leftmost column and going in the bottom-right direction until reaching the matrix's end. For example, the matrix diagonal starting from mat[2][0], where mat is a 6 x 3 matrix, includes cells mat[2][0], mat[3][1], and mat[4][2].\n Given an m x n matrix mat of integers, sort each matrix diagonal in ascending order and return the resulting matrix.\n \n Example 1:\n \n \n >>> diagonalSort(mat = [[3,3,1,1],[2,2,1,2],[1,1,1,2]])\n >>> [[1,1,1,1],[1,2,2,2],[1,2,3,3]]\n \n Example 2:\n \n >>> diagonalSort(mat = [[11,25,66,1,69,7],[23,55,17,45,15,52],[75,31,36,44,58,8],[22,27,33,25,68,4],[84,28,14,11,5,50]])\n >>> [[5,17,4,1,52,7],[11,11,25,45,8,69],[14,23,25,44,58,15],[22,27,31,36,50,66],[84,28,75,33,55,68]]\n \"\"\"\n"}
{"task_id": "reverse-subarray-to-maximize-array-value", "prompt": "def maxValueAfterReverse(nums: List[int]) -> int:\n \"\"\"\n You are given an integer array nums. The value of this array is defined as the sum of |nums[i] - nums[i + 1]| for all 0 <= i < nums.length - 1.\n You are allowed to select any subarray of the given array and reverse it. You can perform this operation only once.\n Find maximum possible value of the final array.\n \n Example 1:\n \n >>> maxValueAfterReverse(nums = [2,3,1,5,4])\n >>> 10\n Explanation: By reversing the subarray [3,1,5] the array becomes [2,5,1,3,4] whose value is 10.\n \n Example 2:\n \n >>> maxValueAfterReverse(nums = [2,4,9,24,2,1,10])\n >>> 68\n \"\"\"\n"}
{"task_id": "rank-transform-of-an-array", "prompt": "def arrayRankTransform(arr: List[int]) -> List[int]:\n \"\"\"\n Given an array of integers\u00a0arr, replace each element with its rank.\n The rank represents how large the element is. The rank has the following rules:\n \n Rank is an integer starting from 1.\n The larger the element, the larger the rank. If two elements are equal, their rank must be the same.\n Rank should be as small as possible.\n \n \n Example 1:\n \n >>> arrayRankTransform(arr = [40,10,20,30])\n >>> [4,1,2,3]\n Explanation: 40 is the largest element. 10 is the smallest. 20 is the second smallest. 30 is the third smallest.\n Example 2:\n \n >>> arrayRankTransform(arr = [100,100,100])\n >>> [1,1,1]\n Explanation: Same elements share the same rank.\n \n Example 3:\n \n >>> arrayRankTransform(arr = [37,12,28,9,100,56,80,5,12])\n >>> [5,3,4,2,8,6,7,1,3]\n \"\"\"\n"}
{"task_id": "remove-palindromic-subsequences", "prompt": "def removePalindromeSub(s: str) -> int:\n \"\"\"\n You are given a string s consisting only of letters 'a' and 'b'. In a single step you can remove one palindromic subsequence from s.\n Return the minimum number of steps to make the given string empty.\n A string is a subsequence of a given string if it is generated by deleting some characters of a given string without changing its order. Note that a subsequence does not necessarily need to be contiguous.\n A string is called palindrome if is one that reads the same backward as well as forward.\n \n Example 1:\n \n >>> removePalindromeSub(s = \"ababa\")\n >>> 1\n Explanation: s is already a palindrome, so its entirety can be removed in a single step.\n \n Example 2:\n \n >>> removePalindromeSub(s = \"abb\")\n >>> 2\n Explanation: \"abb\" -> \"bb\" -> \"\".\n Remove palindromic subsequence \"a\" then \"bb\".\n \n Example 3:\n \n >>> removePalindromeSub(s = \"baabb\")\n >>> 2\n Explanation: \"baabb\" -> \"b\" -> \"\".\n Remove palindromic subsequence \"baab\" then \"b\".\n \"\"\"\n"}
{"task_id": "filter-restaurants-by-vegan-friendly-price-and-distance", "prompt": "def filterRestaurants(restaurants: List[List[int]], veganFriendly: int, maxPrice: int, maxDistance: int) -> List[int]:\n \"\"\"\n Given the array restaurants where \u00a0restaurants[i] = [idi, ratingi, veganFriendlyi, pricei, distancei]. You have to filter the restaurants using three filters.\n The veganFriendly filter will be either true (meaning you should only include restaurants with veganFriendlyi set to true)\u00a0or false\u00a0(meaning you can include any restaurant). In addition, you have the filters\u00a0maxPrice and maxDistance\u00a0which\u00a0are the maximum value for price and distance of restaurants you should consider respectively.\n Return the array of restaurant IDs after filtering, ordered by rating from highest to lowest. For restaurants with the same rating, order them by id from highest to lowest. For simplicity veganFriendlyi and veganFriendly take value 1 when it is true, and 0 when it is false.\n \n Example 1:\n \n >>> filterRestaurants(restaurants = [[1,4,1,40,10],[2,8,0,50,5],[3,8,1,30,4],[4,10,0,10,3],[5,1,1,15,1]], veganFriendly = 1, maxPrice = 50, maxDistance = 10)\n >>> [3,1,5]\n Explanation:\n The restaurants are:\n Restaurant 1 [id=1, rating=4, veganFriendly=1, price=40, distance=10]\n Restaurant 2 [id=2, rating=8, veganFriendly=0, price=50, distance=5]\n Restaurant 3 [id=3, rating=8, veganFriendly=1, price=30, distance=4]\n Restaurant 4 [id=4, rating=10, veganFriendly=0, price=10, distance=3]\n Restaurant 5 [id=5, rating=1, veganFriendly=1, price=15, distance=1]\n After filter restaurants with veganFriendly = 1, maxPrice = 50 and maxDistance = 10 we have restaurant 3, restaurant 1 and restaurant 5 (ordered by rating from highest to lowest).\n \n Example 2:\n \n >>> filterRestaurants(restaurants = [[1,4,1,40,10],[2,8,0,50,5],[3,8,1,30,4],[4,10,0,10,3],[5,1,1,15,1]], veganFriendly = 0, maxPrice = 50, maxDistance = 10)\n >>> [4,3,2,1,5]\n Explanation: The restaurants are the same as in example 1, but in this case the filter veganFriendly = 0, therefore all restaurants are considered.\n \n Example 3:\n \n >>> filterRestaurants(restaurants = [[1,4,1,40,10],[2,8,0,50,5],[3,8,1,30,4],[4,10,0,10,3],[5,1,1,15,1]], veganFriendly = 0, maxPrice = 30, maxDistance = 3)\n >>> [4,5]\n \"\"\"\n"}
{"task_id": "find-the-city-with-the-smallest-number-of-neighbors-at-a-threshold-distance", "prompt": "def findTheCity(n: int, edges: List[List[int]], distanceThreshold: int) -> int:\n \"\"\"\n There are n cities numbered from 0 to n-1. Given the array edges where edges[i] = [fromi, toi, weighti] represents a bidirectional and weighted edge between cities fromi and toi, and given the integer distanceThreshold.\n Return the city with the smallest number of cities that are reachable through some path and whose distance is at most distanceThreshold, If there are multiple such cities, return the city with the greatest number.\n Notice that the distance of a path connecting cities i and j is equal to the sum of the edges' weights along that path.\n \n Example 1:\n \n \n >>> findTheCity(n = 4, edges = [[0,1,3],[1,2,1],[1,3,4],[2,3,1]], distanceThreshold = 4)\n >>> 3\n Explanation: The figure above describes the graph.\n The neighboring cities at a distanceThreshold = 4 for each city are:\n City 0 -> [City 1, City 2]\n City 1 -> [City 0, City 2, City 3]\n City 2 -> [City 0, City 1, City 3]\n City 3 -> [City 1, City 2]\n Cities 0 and 3 have 2 neighboring cities at a distanceThreshold = 4, but we have to return city 3 since it has the greatest number.\n \n Example 2:\n \n \n >>> findTheCity(n = 5, edges = [[0,1,2],[0,4,8],[1,2,3],[1,4,2],[2,3,1],[3,4,1]], distanceThreshold = 2)\n >>> 0\n Explanation: The figure above describes the graph.\n The neighboring cities at a distanceThreshold = 2 for each city are:\n City 0 -> [City 1]\n City 1 -> [City 0, City 4]\n City 2 -> [City 3, City 4]\n City 3 -> [City 2, City 4]\n City 4 -> [City 1, City 2, City 3]\n The city 0 has 1 neighboring city at a distanceThreshold = 2.\n \"\"\"\n"}
{"task_id": "minimum-difficulty-of-a-job-schedule", "prompt": "def minDifficulty(jobDifficulty: List[int], d: int) -> int:\n \"\"\"\n You want to schedule a list of jobs in d days. Jobs are dependent (i.e To work on the ith job, you have to finish all the jobs j where 0 <= j < i).\n You have to finish at least one task every day. The difficulty of a job schedule is the sum of difficulties of each day of the d days. The difficulty of a day is the maximum difficulty of a job done on that day.\n You are given an integer array jobDifficulty and an integer d. The difficulty of the ith job is jobDifficulty[i].\n Return the minimum difficulty of a job schedule. If you cannot find a schedule for the jobs return -1.\n \n Example 1:\n \n \n >>> minDifficulty(jobDifficulty = [6,5,4,3,2,1], d = 2)\n >>> 7\n Explanation: First day you can finish the first 5 jobs, total difficulty = 6.\n Second day you can finish the last job, total difficulty = 1.\n The difficulty of the schedule = 6 + 1 = 7\n \n Example 2:\n \n >>> minDifficulty(jobDifficulty = [9,9,9], d = 4)\n >>> -1\n Explanation: If you finish a job per day you will still have a free day. you cannot find a schedule for the given jobs.\n \n Example 3:\n \n >>> minDifficulty(jobDifficulty = [1,1,1], d = 3)\n >>> 3\n Explanation: The schedule is one job per day. total difficulty will be 3.\n \"\"\"\n"}
{"task_id": "the-k-weakest-rows-in-a-matrix", "prompt": "def kWeakestRows(mat: List[List[int]], k: int) -> List[int]:\n \"\"\"\n You are given an m x n binary matrix mat of 1's (representing soldiers) and 0's (representing civilians). The soldiers are positioned in front of the civilians. That is, all the 1's will appear to the left of all the 0's in each row.\n A row i is weaker than a row j if one of the following is true:\n \n The number of soldiers in row i is less than the number of soldiers in row j.\n Both rows have the same number of soldiers and i < j.\n \n Return the indices of the k weakest rows in the matrix ordered from weakest to strongest.\n \n Example 1:\n \n [[1,1,0,0,0],\n [1,1,1,1,0],\n [1,0,0,0,0],\n [1,1,0,0,0],\n [1,1,1,1,1]],\n k = 3\n >>> kWeakestRows(mat =)\n >>> [2,0,3]\n Explanation:\n The number of soldiers in each row is:\n - Row 0: 2\n - Row 1: 4\n - Row 2: 1\n - Row 3: 2\n - Row 4: 5\n The rows ordered from weakest to strongest are [2,0,3,1,4].\n \n Example 2:\n \n [[1,0,0,0],\n [1,1,1,1],\n [1,0,0,0],\n [1,0,0,0]],\n k = 2\n >>> kWeakestRows(mat =)\n >>> [0,2]\n Explanation:\n The number of soldiers in each row is:\n - Row 0: 1\n - Row 1: 4\n - Row 2: 1\n - Row 3: 1\n The rows ordered from weakest to strongest are [0,2,3,1].\n \"\"\"\n"}
{"task_id": "reduce-array-size-to-the-half", "prompt": "def minSetSize(arr: List[int]) -> int:\n \"\"\"\n You are given an integer array arr. You can choose a set of integers and remove all the occurrences of these integers in the array.\n Return the minimum size of the set so that at least half of the integers of the array are removed.\n \n Example 1:\n \n >>> minSetSize(arr = [3,3,3,3,5,5,5,2,2,7])\n >>> 2\n Explanation: Choosing {3,7} will make the new array [5,5,5,2,2] which has size 5 (i.e equal to half of the size of the old array).\n Possible sets of size 2 are {3,5},{3,2},{5,2}.\n Choosing set {2,7} is not possible as it will make the new array [3,3,3,3,5,5,5] which has a size greater than half of the size of the old array.\n \n Example 2:\n \n >>> minSetSize(arr = [7,7,7,7,7,7])\n >>> 1\n Explanation: The only possible set you can choose is {7}. This will make the new array empty.\n \"\"\"\n"}
{"task_id": "maximum-product-of-splitted-binary-tree", "prompt": "# class TreeNode:\n# def __init__(val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def maxProduct(root: Optional[TreeNode]) -> int:\n \"\"\"\n Given the root of a binary tree, split the binary tree into two subtrees by removing one edge such that the product of the sums of the subtrees is maximized.\n Return the maximum product of the sums of the two subtrees. Since the answer may be too large, return it modulo 109 + 7.\n Note that you need to maximize the answer before taking the mod and not after taking it.\n \n Example 1:\n \n \n >>> __init__(root = [1,2,3,4,5,6])\n >>> 110\n Explanation: Remove the red edge and get 2 binary trees with sum 11 and 10. Their product is 110 (11*10)\n \n Example 2:\n \n \n >>> __init__(root = [1,null,2,3,4,null,null,5,6])\n >>> 90\n Explanation: Remove the red edge and get 2 binary trees with sum 15 and 6.Their product is 90 (15*6)\n \"\"\"\n"}
{"task_id": "jump-game-v", "prompt": "def maxJumps(arr: List[int], d: int) -> int:\n \"\"\"\n Given an array of\u00a0integers arr and an integer d. In one step you can jump from index i to index:\n \n i + x where:\u00a0i + x < arr.length and 0 <\u00a0x <= d.\n i - x where:\u00a0i - x >= 0 and 0 <\u00a0x <= d.\n \n In addition, you can only jump from index i to index j\u00a0if arr[i] > arr[j] and arr[i] > arr[k] for all indices k between i and j (More formally min(i,\u00a0j) < k < max(i, j)).\n You can choose any index of the array and start jumping. Return the maximum number of indices\u00a0you can visit.\n Notice that you can not jump outside of the array at any time.\n \n Example 1:\n \n \n >>> maxJumps(arr = [6,4,14,6,8,13,9,7,10,6,12], d = 2)\n >>> 4\n Explanation: You can start at index 10. You can jump 10 --> 8 --> 6 --> 7 as shown.\n Note that if you start at index 6 you can only jump to index 7. You cannot jump to index 5 because 13 > 9. You cannot jump to index 4 because index 5 is between index 4 and 6 and 13 > 9.\n Similarly You cannot jump from index 3 to index 2 or index 1.\n \n Example 2:\n \n >>> maxJumps(arr = [3,3,3,3,3], d = 3)\n >>> 1\n Explanation: You can start at any index. You always cannot jump to any index.\n \n Example 3:\n \n >>> maxJumps(arr = [7,6,5,4,3,2,1], d = 1)\n >>> 7\n Explanation: Start at index 0. You can visit all the indicies.\n \"\"\"\n"}
{"task_id": "number-of-steps-to-reduce-a-number-to-zero", "prompt": "def numberOfSteps(num: int) -> int:\n \"\"\"\n Given an integer num, return the number of steps to reduce it to zero.\n In one step, if the current number is even, you have to divide it by 2, otherwise, you have to subtract 1 from it.\n \n Example 1:\n \n >>> numberOfSteps(num = 14)\n >>> 6\n Explanation:\n Step 1) 14 is even; divide by 2 and obtain 7.\n Step 2) 7 is odd; subtract 1 and obtain 6.\n Step 3) 6 is even; divide by 2 and obtain 3.\n Step 4) 3 is odd; subtract 1 and obtain 2.\n Step 5) 2 is even; divide by 2 and obtain 1.\n Step 6) 1 is odd; subtract 1 and obtain 0.\n \n Example 2:\n \n >>> numberOfSteps(num = 8)\n >>> 4\n Explanation:\n Step 1) 8 is even; divide by 2 and obtain 4.\n Step 2) 4 is even; divide by 2 and obtain 2.\n Step 3) 2 is even; divide by 2 and obtain 1.\n Step 4) 1 is odd; subtract 1 and obtain 0.\n \n Example 3:\n \n >>> numberOfSteps(num = 123)\n >>> 12\n \"\"\"\n"}
{"task_id": "number-of-sub-arrays-of-size-k-and-average-greater-than-or-equal-to-threshold", "prompt": "def numOfSubarrays(arr: List[int], k: int, threshold: int) -> int:\n \"\"\"\n Given an array of integers arr and two integers k and threshold, return the number of sub-arrays of size k and average greater than or equal to threshold.\n \n Example 1:\n \n >>> numOfSubarrays(arr = [2,2,2,2,5,5,5,8], k = 3, threshold = 4)\n >>> 3\n Explanation: Sub-arrays [2,5,5],[5,5,5] and [5,5,8] have averages 4, 5 and 6 respectively. All other sub-arrays of size 3 have averages less than 4 (the threshold).\n \n Example 2:\n \n >>> numOfSubarrays(arr = [11,13,17,23,29,31,7,5,2,3], k = 3, threshold = 5)\n >>> 6\n Explanation: The first 6 sub-arrays of size 3 have averages greater than 5. Note that averages are not integers.\n \"\"\"\n"}
{"task_id": "angle-between-hands-of-a-clock", "prompt": "def angleClock(hour: int, minutes: int) -> float:\n \"\"\"\n Given two numbers, hour and minutes, return the smaller angle (in degrees) formed between the hour and the minute hand.\n Answers within 10-5 of the actual value will be accepted as correct.\n \n Example 1:\n \n \n >>> angleClock(hour = 12, minutes = 30)\n >>> 165\n \n Example 2:\n \n \n >>> angleClock(hour = 3, minutes = 30)\n >>> 75\n \n Example 3:\n \n \n >>> angleClock(hour = 3, minutes = 15)\n >>> 7.5\n \"\"\"\n"}
{"task_id": "jump-game-iv", "prompt": "def minJumps(arr: List[int]) -> int:\n \"\"\"\n Given an array of\u00a0integers arr, you are initially positioned at the first index of the array.\n In one step you can jump from index i to index:\n \n i + 1 where:\u00a0i + 1 < arr.length.\n i - 1 where:\u00a0i - 1 >= 0.\n j where: arr[i] == arr[j] and i != j.\n \n Return the minimum number of steps to reach the last index of the array.\n Notice that you can not jump outside of the array at any time.\n \n Example 1:\n \n >>> minJumps(arr = [100,-23,-23,404,100,23,23,23,3,404])\n >>> 3\n Explanation: You need three jumps from index 0 --> 4 --> 3 --> 9. Note that index 9 is the last index of the array.\n \n Example 2:\n \n >>> minJumps(arr = [7])\n >>> 0\n Explanation: Start index is the last index. You do not need to jump.\n \n Example 3:\n \n >>> minJumps(arr = [7,6,9,6,9,6,9,7])\n >>> 1\n Explanation: You can jump directly from index 0 to index 7 which is last index of the array.\n \"\"\"\n"}
{"task_id": "check-if-n-and-its-double-exist", "prompt": "def checkIfExist(arr: List[int]) -> bool:\n \"\"\"\n Given an array arr of integers, check if there exist two indices i and j such that :\n \n i != j\n 0 <= i, j < arr.length\n arr[i] == 2 * arr[j]\n \n \n Example 1:\n \n >>> checkIfExist(arr = [10,2,5,3])\n >>> true\n Explanation: For i = 0 and j = 2, arr[i] == 10 == 2 * 5 == 2 * arr[j]\n \n Example 2:\n \n >>> checkIfExist(arr = [3,1,7,11])\n >>> false\n Explanation: There is no i and j that satisfy the conditions.\n \"\"\"\n"}
{"task_id": "minimum-number-of-steps-to-make-two-strings-anagram", "prompt": "def minSteps(s: str, t: str) -> int:\n \"\"\"\n You are given two strings of the same length s and t. In one step you can choose any character of t and replace it with another character.\n Return the minimum number of steps to make t an anagram of s.\n An Anagram of a string is a string that contains the same characters with a different (or the same) ordering.\n \n Example 1:\n \n >>> minSteps(s = \"bab\", t = \"aba\")\n >>> 1\n Explanation: Replace the first 'a' in t with b, t = \"bba\" which is anagram of s.\n \n Example 2:\n \n >>> minSteps(s = \"leetcode\", t = \"practice\")\n >>> 5\n Explanation: Replace 'p', 'r', 'a', 'i' and 'c' from t with proper characters to make t anagram of s.\n \n Example 3:\n \n >>> minSteps(s = \"anagram\", t = \"mangaar\")\n >>> 0\n Explanation: \"anagram\" and \"mangaar\" are anagrams.\n \"\"\"\n"}
{"task_id": "maximum-students-taking-exam", "prompt": "def maxStudents(seats: List[List[str]]) -> int:\n \"\"\"\n Given a m\u00a0* n\u00a0matrix seats\u00a0\u00a0that represent seats distributions\u00a0in a classroom.\u00a0If a seat\u00a0is\u00a0broken, it is denoted by '#' character otherwise it is denoted by a '.' character.\n Students can see the answers of those sitting next to the left, right, upper left and upper right, but he cannot see the answers of the student sitting\u00a0directly in front or behind him. Return the maximum number of students that can take the exam together\u00a0without any cheating being possible.\n Students must be placed in seats in good condition.\n \n Example 1:\n \n \n \u00a0 [\".\",\"#\",\"#\",\"#\",\"#\",\".\"],\n \u00a0 [\"#\",\".\",\"#\",\"#\",\".\",\"#\"]]\n >>> maxStudents(seats = [[\"#\",\".\",\"#\",\"#\",\".\",\"#\"],)\n >>> 4\n Explanation: Teacher can place 4 students in available seats so they don't cheat on the exam.\n \n Example 2:\n \n \u00a0 [\"#\",\"#\"],\n \u00a0 [\"#\",\".\"],\n \u00a0 [\"#\",\"#\"],\n \u00a0 [\".\",\"#\"]]\n >>> maxStudents(seats = [[\".\",\"#\"],)\n >>> 3\n Explanation: Place all students in available seats.\n \n \n Example 3:\n \n \u00a0 [\".\",\"#\",\".\",\"#\",\".\"],\n \u00a0 [\".\",\".\",\"#\",\".\",\".\"],\n \u00a0 [\".\",\"#\",\".\",\"#\",\".\"],\n \u00a0 [\"#\",\".\",\".\",\".\",\"#\"]]\n >>> maxStudents(seats = [[\"#\",\".\",\".\",\".\",\"#\"],)\n >>> 10\n Explanation: Place students in available seats in column 1, 3 and 5.\n \"\"\"\n"}
{"task_id": "count-negative-numbers-in-a-sorted-matrix", "prompt": "def countNegatives(grid: List[List[int]]) -> int:\n \"\"\"\n Given a m x n matrix grid which is sorted in non-increasing order both row-wise and column-wise, return the number of negative numbers in grid.\n \n Example 1:\n \n >>> countNegatives(grid = [[4,3,2,-1],[3,2,1,-1],[1,1,-1,-2],[-1,-1,-2,-3]])\n >>> 8\n Explanation: There are 8 negatives number in the matrix.\n \n Example 2:\n \n >>> countNegatives(grid = [[3,2],[1,0]])\n >>> 0\n \"\"\"\n"}
{"task_id": "maximum-number-of-events-that-can-be-attended", "prompt": "def maxEvents(events: List[List[int]]) -> int:\n \"\"\"\n You are given an array of events where events[i] = [startDayi, endDayi]. Every event i starts at startDayi and ends at endDayi.\n You can attend an event i at any day d where startTimei <= d <= endTimei. You can only attend one event at any time d.\n Return the maximum number of events you can attend.\n \n Example 1:\n \n \n >>> maxEvents(events = [[1,2],[2,3],[3,4]])\n >>> 3\n Explanation: You can attend all the three events.\n One way to attend them all is as shown.\n Attend the first event on day 1.\n Attend the second event on day 2.\n Attend the third event on day 3.\n \n Example 2:\n \n >>> maxEvents(events= [[1,2],[2,3],[3,4],[1,2]])\n >>> 4\n \"\"\"\n"}
{"task_id": "construct-target-array-with-multiple-sums", "prompt": "def isPossible(target: List[int]) -> bool:\n \"\"\"\n You are given an array target of n integers. From a starting array arr consisting of n 1's, you may perform the following procedure :\n \n let x be the sum of all elements currently in your array.\n choose index i, such that 0 <= i < n and set the value of arr at index i to x.\n You may repeat this procedure as many times as needed.\n \n Return true if it is possible to construct the target array from arr, otherwise, return false.\n \n Example 1:\n \n >>> isPossible(target = [9,3,5])\n >>> true\n Explanation: Start with arr = [1, 1, 1]\n [1, 1, 1], sum = 3 choose index 1\n [1, 3, 1], sum = 5 choose index 2\n [1, 3, 5], sum = 9 choose index 0\n [9, 3, 5] Done\n \n Example 2:\n \n >>> isPossible(target = [1,1,1,2])\n >>> false\n Explanation: Impossible to create target array from [1,1,1,1].\n \n Example 3:\n \n >>> isPossible(target = [8,5])\n >>> true\n \"\"\"\n"}
{"task_id": "sort-integers-by-the-number-of-1-bits", "prompt": "def sortByBits(arr: List[int]) -> List[int]:\n \"\"\"\n You are given an integer array arr. Sort the integers in the array\u00a0in ascending order by the number of 1's\u00a0in their binary representation and in case of two or more integers have the same number of 1's you have to sort them in ascending order.\n Return the array after sorting it.\n \n Example 1:\n \n >>> sortByBits(arr = [0,1,2,3,4,5,6,7,8])\n >>> [0,1,2,4,8,3,5,6,7]\n Explantion: [0] is the only integer with 0 bits.\n [1,2,4,8] all have 1 bit.\n [3,5,6] have 2 bits.\n [7] has 3 bits.\n The sorted array by bits is [0,1,2,4,8,3,5,6,7]\n \n Example 2:\n \n >>> sortByBits(arr = [1024,512,256,128,64,32,16,8,4,2,1])\n >>> [1,2,4,8,16,32,64,128,256,512,1024]\n Explantion: All integers have 1 bit in the binary representation, you should just sort them in ascending order.\n \"\"\"\n"}
{"task_id": "number-of-substrings-containing-all-three-characters", "prompt": "def numberOfSubstrings(s: str) -> int:\n \"\"\"\n Given a string s\u00a0consisting only of characters a, b and c.\n Return the number of substrings containing at least\u00a0one occurrence of all these characters a, b and c.\n \n Example 1:\n \n >>> numberOfSubstrings(s = \"abcabc\")\n >>> 10\n Explanation: The substrings containing\u00a0at least\u00a0one occurrence of the characters\u00a0a,\u00a0b\u00a0and\u00a0c are \"abc\", \"abca\", \"abcab\", \"abcabc\", \"bca\", \"bcab\", \"bcabc\", \"cab\", \"cabc\" and \"abc\" (again).\n \n Example 2:\n \n >>> numberOfSubstrings(s = \"aaacb\")\n >>> 3\n Explanation: The substrings containing\u00a0at least\u00a0one occurrence of the characters\u00a0a,\u00a0b\u00a0and\u00a0c are \"aaacb\", \"aacb\" and \"acb\".\n \n Example 3:\n \n >>> numberOfSubstrings(s = \"abc\")\n >>> 1\n \"\"\"\n"}
{"task_id": "count-all-valid-pickup-and-delivery-options", "prompt": "def countOrders(n: int) -> int:\n \"\"\"\n Given n orders, each order consists of a pickup and a delivery service.\n Count all valid pickup/delivery possible sequences such that delivery(i) is always after of\u00a0pickup(i).\n Since the answer\u00a0may be too large,\u00a0return it modulo\u00a010^9 + 7.\n \n Example 1:\n \n >>> countOrders(n = 1)\n >>> 1\n Explanation: Unique order (P1, D1), Delivery 1 always is after of Pickup 1.\n \n Example 2:\n \n >>> countOrders(n = 2)\n >>> 6\n Explanation: All possible orders:\n (P1,P2,D1,D2), (P1,P2,D2,D1), (P1,D1,P2,D2), (P2,P1,D1,D2), (P2,P1,D2,D1) and (P2,D2,P1,D1).\n This is an invalid order (P1,D2,P2,D1) because Pickup 2 is after of Delivery 2.\n \n Example 3:\n \n >>> countOrders(n = 3)\n >>> 90\n \"\"\"\n"}
{"task_id": "number-of-days-between-two-dates", "prompt": "def daysBetweenDates(date1: str, date2: str) -> int:\n \"\"\"\n Write a program to count the number of days between two dates.\n The two dates are given as strings, their format is YYYY-MM-DD\u00a0as shown in the examples.\n \n Example 1:\n >>> daysBetweenDates(date1 = \"2019-06-29\", date2 = \"2019-06-30\")\n >>> 1\n Example 2:\n >>> daysBetweenDates(date1 = \"2020-01-15\", date2 = \"2019-12-31\")\n >>> 15\n \"\"\"\n"}
{"task_id": "validate-binary-tree-nodes", "prompt": "def validateBinaryTreeNodes(n: int, leftChild: List[int], rightChild: List[int]) -> bool:\n \"\"\"\n You have n binary tree nodes numbered from 0 to n - 1 where node i has two children leftChild[i] and rightChild[i], return true if and only if all the given nodes form exactly one valid binary tree.\n If node i has no left child then leftChild[i] will equal -1, similarly for the right child.\n Note that the nodes have no values and that we only use the node numbers in this problem.\n \n Example 1:\n \n \n >>> validateBinaryTreeNodes(n = 4, leftChild = [1,-1,3,-1], rightChild = [2,-1,-1,-1])\n >>> true\n \n Example 2:\n \n \n >>> validateBinaryTreeNodes(n = 4, leftChild = [1,-1,3,-1], rightChild = [2,3,-1,-1])\n >>> false\n \n Example 3:\n \n \n >>> validateBinaryTreeNodes(n = 2, leftChild = [1,0], rightChild = [-1,-1])\n >>> false\n \"\"\"\n"}
{"task_id": "closest-divisors", "prompt": "def closestDivisors(num: int) -> List[int]:\n \"\"\"\n Given an integer num, find the closest two integers in absolute difference whose product equals\u00a0num + 1\u00a0or num + 2.\n Return the two integers in any order.\n \n Example 1:\n \n >>> closestDivisors(num = 8)\n >>> [3,3]\n Explanation: For num + 1 = 9, the closest divisors are 3 & 3, for num + 2 = 10, the closest divisors are 2 & 5, hence 3 & 3 is chosen.\n \n Example 2:\n \n >>> closestDivisors(num = 123)\n >>> [5,25]\n \n Example 3:\n \n >>> closestDivisors(num = 999)\n >>> [40,25]\n \"\"\"\n"}
{"task_id": "largest-multiple-of-three", "prompt": "def largestMultipleOfThree(digits: List[int]) -> str:\n \"\"\"\n Given an array of digits digits, return the largest multiple of three that can be formed by concatenating some of the given digits in any order. If there is no answer return an empty string.\n Since the answer may not fit in an integer data type, return the answer as a string. Note that the returning answer must not contain unnecessary leading zeros.\n \n Example 1:\n \n >>> largestMultipleOfThree(digits = [8,1,9])\n >>> \"981\"\n \n Example 2:\n \n >>> largestMultipleOfThree(digits = [8,6,7,1,0])\n >>> \"8760\"\n \n Example 3:\n \n >>> largestMultipleOfThree(digits = [1])\n >>> \"\"\n \"\"\"\n"}
{"task_id": "how-many-numbers-are-smaller-than-the-current-number", "prompt": "def smallerNumbersThanCurrent(nums: List[int]) -> List[int]:\n \"\"\"\n Given the array nums, for each nums[i] find out how many numbers in the array are smaller than it. That is, for each nums[i] you have to count the number of valid j's\u00a0such that\u00a0j != i and nums[j] < nums[i].\n Return the answer in an array.\n \n Example 1:\n \n >>> smallerNumbersThanCurrent(nums = [8,1,2,2,3])\n >>> [4,0,1,1,3]\n Explanation:\n For nums[0]=8 there exist four smaller numbers than it (1, 2, 2 and 3).\n For nums[1]=1 does not exist any smaller number than it.\n For nums[2]=2 there exist one smaller number than it (1).\n For nums[3]=2 there exist one smaller number than it (1).\n For nums[4]=3 there exist three smaller numbers than it (1, 2 and 2).\n \n Example 2:\n \n >>> smallerNumbersThanCurrent(nums = [6,5,4,8])\n >>> [2,1,0,3]\n \n Example 3:\n \n >>> smallerNumbersThanCurrent(nums = [7,7,7,7])\n >>> [0,0,0,0]\n \"\"\"\n"}
{"task_id": "rank-teams-by-votes", "prompt": "def rankTeams(votes: List[str]) -> str:\n \"\"\"\n In a special ranking system, each voter gives a rank from highest to lowest to all teams participating in the competition.\n The ordering of teams is decided by who received the most position-one votes. If two or more teams tie in the first position, we consider the second position to resolve the conflict, if they tie again, we continue this process until the ties are resolved. If two or more teams are still tied after considering all positions, we rank them alphabetically based on their team letter.\n You are given an array of strings votes which is the votes of all voters in the ranking systems. Sort all teams according to the ranking system described above.\n Return a string of all teams sorted by the ranking system.\n \n Example 1:\n \n >>> rankTeams(votes = [\"ABC\",\"ACB\",\"ABC\",\"ACB\",\"ACB\"])\n >>> \"ACB\"\n Explanation:\n Team A was ranked first place by 5 voters. No other team was voted as first place, so team A is the first team.\n Team B was ranked second by 2 voters and ranked third by 3 voters.\n Team C was ranked second by 3 voters and ranked third by 2 voters.\n As most of the voters ranked C second, team C is the second team, and team B is the third.\n \n Example 2:\n \n >>> rankTeams(votes = [\"WXYZ\",\"XYZW\"])\n >>> \"XWYZ\"\n Explanation:\n X is the winner due to the tie-breaking rule. X has the same votes as W for the first position, but X has one vote in the second position, while W does not have any votes in the second position.\n \n Example 3:\n \n >>> rankTeams(votes = [\"ZMNAGUEDSJYLBOPHRQICWFXTVK\"])\n >>> \"ZMNAGUEDSJYLBOPHRQICWFXTVK\"\n Explanation: Only one voter, so their votes are used for the ranking.\n \"\"\"\n"}
{"task_id": "linked-list-in-binary-tree", "prompt": "# class ListNode:\n# def __init__(val=0, next=None):\n# self.val = val\n# self.next = next\n# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def isSubPath(head: Optional[ListNode], root: Optional[TreeNode]) -> bool:\n \"\"\"\n Given a binary tree root and a\u00a0linked list with\u00a0head\u00a0as the first node.\n Return True if all the elements in the linked list starting from the head correspond to some downward path connected in the binary tree\u00a0otherwise return False.\n In this context downward path means a path that starts at some node and goes downwards.\n \n Example 1:\n \n \n >>> __init__(head = [4,2,8], root = [1,4,4,null,2,2,null,1,null,6,8,null,null,null,null,1,3])\n >>> true\n Explanation: Nodes in blue form a subpath in the binary Tree.\n \n Example 2:\n \n \n >>> __init__(head = [1,4,2,6], root = [1,4,4,null,2,2,null,1,null,6,8,null,null,null,null,1,3])\n >>> true\n \n Example 3:\n \n >>> __init__(head = [1,4,2,6,8], root = [1,4,4,null,2,2,null,1,null,6,8,null,null,null,null,1,3])\n >>> false\n Explanation: There is no path in the binary tree that contains all the elements of the linked list from head.\n \"\"\"\n"}
{"task_id": "minimum-cost-to-make-at-least-one-valid-path-in-a-grid", "prompt": "def minCost(grid: List[List[int]]) -> int:\n \"\"\"\n Given an m x n grid. Each cell of the grid has a sign pointing to the next cell you should visit if you are currently in this cell. The sign of grid[i][j] can be:\n \n 1 which means go to the cell to the right. (i.e go from grid[i][j] to grid[i][j + 1])\n 2 which means go to the cell to the left. (i.e go from grid[i][j] to grid[i][j - 1])\n 3 which means go to the lower cell. (i.e go from grid[i][j] to grid[i + 1][j])\n 4 which means go to the upper cell. (i.e go from grid[i][j] to grid[i - 1][j])\n \n Notice that there could be some signs on the cells of the grid that point outside the grid.\n You will initially start at the upper left cell (0, 0). A valid path in the grid is a path that starts from the upper left cell (0, 0) and ends at the bottom-right cell (m - 1, n - 1) following the signs on the grid. The valid path does not have to be the shortest.\n You can modify the sign on a cell with cost = 1. You can modify the sign on a cell one time only.\n Return the minimum cost to make the grid have at least one valid path.\n \n Example 1:\n \n \n >>> minCost(grid = [[1,1,1,1],[2,2,2,2],[1,1,1,1],[2,2,2,2]])\n >>> 3\n Explanation: You will start at point (0, 0).\n The path to (3, 3) is as follows. (0, 0) --> (0, 1) --> (0, 2) --> (0, 3) change the arrow to down with cost = 1 --> (1, 3) --> (1, 2) --> (1, 1) --> (1, 0) change the arrow to down with cost = 1 --> (2, 0) --> (2, 1) --> (2, 2) --> (2, 3) change the arrow to down with cost = 1 --> (3, 3)\n The total cost = 3.\n \n Example 2:\n \n \n >>> minCost(grid = [[1,1,3],[3,2,2],[1,1,4]])\n >>> 0\n Explanation: You can follow the path from (0, 0) to (2, 2).\n \n Example 3:\n \n \n >>> minCost(grid = [[1,2],[4,3]])\n >>> 1\n \"\"\"\n"}
{"task_id": "increasing-decreasing-string", "prompt": "def sortString(s: str) -> str:\n \"\"\"\n You are given a string s. Reorder the string using the following algorithm:\n \n Remove the smallest character from s and append it to the result.\n Remove the smallest character from s that is greater than the last appended character, and append it to the result.\n Repeat step 2 until no more characters can be removed.\n Remove the largest character from s and append it to the result.\n Remove the largest character from s that is smaller than the last appended character, and append it to the result.\n Repeat step 5 until no more characters can be removed.\n Repeat steps 1 through 6 until all characters from s have been removed.\n \n If the smallest or largest character appears more than once, you may choose any occurrence to append to the result.\n Return the resulting string after reordering s using this algorithm.\n \n Example 1:\n \n >>> sortString(s = \"aaaabbbbcccc\")\n >>> \"abccbaabccba\"\n Explanation: After steps 1, 2 and 3 of the first iteration, result = \"abc\"\n After steps 4, 5 and 6 of the first iteration, result = \"abccba\"\n First iteration is done. Now s = \"aabbcc\" and we go back to step 1\n After steps 1, 2 and 3 of the second iteration, result = \"abccbaabc\"\n After steps 4, 5 and 6 of the second iteration, result = \"abccbaabccba\"\n \n Example 2:\n \n >>> sortString(s = \"rat\")\n >>> \"art\"\n Explanation: The word \"rat\" becomes \"art\" after re-ordering it with the mentioned algorithm.\n \"\"\"\n"}
{"task_id": "find-the-longest-substring-containing-vowels-in-even-counts", "prompt": "def findTheLongestSubstring(s: str) -> int:\n \"\"\"\n Given the string s, return the size of the longest substring containing each vowel an even number of times. That is, 'a', 'e', 'i', 'o', and 'u' must appear an even number of times.\n \n Example 1:\n \n >>> findTheLongestSubstring(s = \"eleetminicoworoep\")\n >>> 13\n Explanation: The longest substring is \"leetminicowor\" which contains two each of the vowels: e, i and o and zero of the vowels: a and u.\n \n Example 2:\n \n >>> findTheLongestSubstring(s = \"leetcodeisgreat\")\n >>> 5\n Explanation: The longest substring is \"leetc\" which contains two e's.\n \n Example 3:\n \n >>> findTheLongestSubstring(s = \"bcbcbc\")\n >>> 6\n Explanation: In this case, the given string \"bcbcbc\" is the longest because all vowels: a, e, i, o and u appear zero times.\n \"\"\"\n"}
{"task_id": "longest-zigzag-path-in-a-binary-tree", "prompt": "# class TreeNode:\n# def __init__(val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def longestZigZag(root: Optional[TreeNode]) -> int:\n \"\"\"\n You are given the root of a binary tree.\n A ZigZag path for a binary tree is defined as follow:\n \n Choose any node in the binary tree and a direction (right or left).\n If the current direction is right, move to the right child of the current node; otherwise, move to the left child.\n Change the direction from right to left or from left to right.\n Repeat the second and third steps until you can't move in the tree.\n \n Zigzag length is defined as the number of nodes visited - 1. (A single node has a length of 0).\n Return the longest ZigZag path contained in that tree.\n \n Example 1:\n \n \n >>> __init__(root = [1,null,1,1,1,null,null,1,1,null,1,null,null,null,1])\n >>> 3\n Explanation: Longest ZigZag path in blue nodes (right -> left -> right).\n \n Example 2:\n \n \n >>> __init__(root = [1,1,1,null,1,null,null,1,1,null,1])\n >>> 4\n Explanation: Longest ZigZag path in blue nodes (left -> right -> left -> right).\n \n Example 3:\n \n >>> __init__(root = [1])\n >>> 0\n \"\"\"\n"}
{"task_id": "maximum-sum-bst-in-binary-tree", "prompt": "# class TreeNode:\n# def __init__(val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def maxSumBST(root: Optional[TreeNode]) -> int:\n \"\"\"\n Given a binary tree root, return the maximum sum of all keys of any sub-tree which is also a Binary Search Tree (BST).\n Assume a BST is defined as follows:\n \n The left subtree of a node contains only nodes with keys less than the node's key.\n The right subtree of a node contains only nodes with keys greater than the node's key.\n Both the left and right subtrees must also be binary search trees.\n \n \n Example 1:\n \n \n >>> __init__(root = [1,4,3,2,4,2,5,null,null,null,null,null,null,4,6])\n >>> 20\n Explanation: Maximum sum in a valid Binary search tree is obtained in root node with key equal to 3.\n \n Example 2:\n \n \n >>> __init__(root = [4,3,null,1,2])\n >>> 2\n Explanation: Maximum sum in a valid Binary search tree is obtained in a single root node with key equal to 2.\n \n Example 3:\n \n >>> __init__(root = [-4,-2,-5])\n >>> 0\n Explanation: All values are negatives. Return an empty BST.\n \"\"\"\n"}
{"task_id": "generate-a-string-with-characters-that-have-odd-counts", "prompt": "def generateTheString(n: int) -> str:\n \"\"\"\n Given an\u00a0integer n, return a string with n\u00a0characters such that each character in such string occurs an odd number of times.\n The returned string must contain only lowercase English letters. If there are multiples valid strings, return any of them.\n \n Example 1:\n \n >>> generateTheString(n = 4)\n >>> \"pppz\"\n Explanation: \"pppz\" is a valid string since the character 'p' occurs three times and the character 'z' occurs once. Note that there are many other valid strings such as \"ohhh\" and \"love\".\n \n Example 2:\n \n >>> generateTheString(n = 2)\n >>> \"xy\"\n Explanation: \"xy\" is a valid string since the characters 'x' and 'y' occur once. Note that there are many other valid strings such as \"ag\" and \"ur\".\n \n Example 3:\n \n >>> generateTheString(n = 7)\n >>> \"holasss\"\n \"\"\"\n"}
{"task_id": "number-of-times-binary-string-is-prefix-aligned", "prompt": "def numTimesAllBlue(flips: List[int]) -> int:\n \"\"\"\n You have a 1-indexed binary string of length n where all the bits are 0 initially. We will flip all the bits of this binary string (i.e., change them from 0 to 1) one by one. You are given a 1-indexed integer array flips where flips[i] indicates that the bit at index i will be flipped in the ith step.\n A binary string is prefix-aligned if, after the ith step, all the bits in the inclusive range [1, i] are ones and all the other bits are zeros.\n Return the number of times the binary string is prefix-aligned during the flipping process.\n \n Example 1:\n \n >>> numTimesAllBlue(flips = [3,2,4,1,5])\n >>> 2\n Explanation: The binary string is initially \"00000\".\n After applying step 1: The string becomes \"00100\", which is not prefix-aligned.\n After applying step 2: The string becomes \"01100\", which is not prefix-aligned.\n After applying step 3: The string becomes \"01110\", which is not prefix-aligned.\n After applying step 4: The string becomes \"11110\", which is prefix-aligned.\n After applying step 5: The string becomes \"11111\", which is prefix-aligned.\n We can see that the string was prefix-aligned 2 times, so we return 2.\n \n Example 2:\n \n >>> numTimesAllBlue(flips = [4,1,2,3])\n >>> 1\n Explanation: The binary string is initially \"0000\".\n After applying step 1: The string becomes \"0001\", which is not prefix-aligned.\n After applying step 2: The string becomes \"1001\", which is not prefix-aligned.\n After applying step 3: The string becomes \"1101\", which is not prefix-aligned.\n After applying step 4: The string becomes \"1111\", which is prefix-aligned.\n We can see that the string was prefix-aligned 1 time, so we return 1.\n \"\"\"\n"}
{"task_id": "time-needed-to-inform-all-employees", "prompt": "def numOfMinutes(n: int, headID: int, manager: List[int], informTime: List[int]) -> int:\n \"\"\"\n A company has n employees with a unique ID for each employee from 0 to n - 1. The head of the company is the one with headID.\n Each employee has one direct manager given in the manager array where manager[i] is the direct manager of the i-th employee, manager[headID] = -1. Also, it is guaranteed that the subordination relationships have a tree structure.\n The head of the company wants to inform all the company employees of an urgent piece of news. He will inform his direct subordinates, and they will inform their subordinates, and so on until all employees know about the urgent news.\n The i-th employee needs informTime[i] minutes to inform all of his direct subordinates (i.e., After informTime[i] minutes, all his direct subordinates can start spreading the news).\n Return the number of minutes needed to inform all the employees about the urgent news.\n \n Example 1:\n \n >>> numOfMinutes(n = 1, headID = 0, manager = [-1], informTime = [0])\n >>> 0\n Explanation: The head of the company is the only employee in the company.\n \n Example 2:\n \n \n >>> numOfMinutes(n = 6, headID = 2, manager = [2,2,-1,2,2,2], informTime = [0,0,1,0,0,0])\n >>> 1\n Explanation: The head of the company with id = 2 is the direct manager of all the employees in the company and needs 1 minute to inform them all.\n The tree structure of the employees in the company is shown.\n \"\"\"\n"}
{"task_id": "frog-position-after-t-seconds", "prompt": "def frogPosition(n: int, edges: List[List[int]], t: int, target: int) -> float:\n \"\"\"\n Given an undirected tree consisting of n vertices numbered from 1 to n. A frog starts jumping from vertex 1. In one second, the frog jumps from its current vertex to another unvisited vertex if they are directly connected. The frog can not jump back to a visited vertex. In case the frog can jump to several vertices, it jumps randomly to one of them with the same probability. Otherwise, when the frog can not jump to any unvisited vertex, it jumps forever on the same vertex.\n The edges of the undirected tree are given in the array edges, where edges[i] = [ai, bi] means that exists an edge connecting the vertices ai and bi.\n Return the probability that after t seconds the frog is on the vertex target. Answers within 10-5 of the actual answer will be accepted.\n \n Example 1:\n \n \n >>> frogPosition(n = 7, edges = [[1,2],[1,3],[1,7],[2,4],[2,6],[3,5]], t = 2, target = 4)\n >>> 0.16666666666666666\n Explanation: The figure above shows the given graph. The frog starts at vertex 1, jumping with 1/3 probability to the vertex 2 after second 1 and then jumping with 1/2 probability to vertex 4 after second 2. Thus the probability for the frog is on the vertex 4 after 2 seconds is 1/3 * 1/2 = 1/6 = 0.16666666666666666.\n \n Example 2:\n \n \n >>> frogPosition(n = 7, edges = [[1,2],[1,3],[1,7],[2,4],[2,6],[3,5]], t = 1, target = 7)\n >>> 0.3333333333333333\n Explanation: The figure above shows the given graph. The frog starts at vertex 1, jumping with 1/3 = 0.3333333333333333 probability to the vertex 7 after second 1.\n \"\"\"\n"}
{"task_id": "find-a-corresponding-node-of-a-binary-tree-in-a-clone-of-that-tree", "prompt": "# class TreeNode:\n# def __init__(x):\n# self.val = x\n# self.left = None\n# self.right = None\n\nclass Solution:\n def getTargetCopy(original: TreeNode, cloned: TreeNode, target: TreeNode) -> TreeNode:\n \"\"\"\n Given two binary trees original and cloned and given a reference to a node target in the original tree.\n The cloned tree is a copy of the original tree.\n Return a reference to the same node in the cloned tree.\n Note that you are not allowed to change any of the two trees or the target node and the answer must be a reference to a node in the cloned tree.\n \n Example 1:\n \n \n >>> __init__(tree = [7,4,3,null,null,6,19], target = 3)\n >>> 3\n Explanation: In all examples the original and cloned trees are shown. The target node is a green node from the original tree. The answer is the yellow node from the cloned tree.\n \n Example 2:\n \n \n >>> __init__(tree = [7], target = 7)\n >>> 7\n \n Example 3:\n \n \n >>> __init__(tree = [8,null,6,null,5,null,4,null,3,null,2,null,1], target = 4)\n >>> 4\n \"\"\"\n"}
{"task_id": "lucky-numbers-in-a-matrix", "prompt": "def luckyNumbers(matrix: List[List[int]]) -> List[int]:\n \"\"\"\n Given an m x n matrix of distinct numbers, return all lucky numbers in the matrix in any order.\n A lucky number is an element of the matrix such that it is the minimum element in its row and maximum in its column.\n \n Example 1:\n \n >>> luckyNumbers(matrix = [[3,7,8],[9,11,13],[15,16,17]])\n >>> [15]\n Explanation: 15 is the only lucky number since it is the minimum in its row and the maximum in its column.\n \n Example 2:\n \n >>> luckyNumbers(matrix = [[1,10,4,2],[9,3,8,7],[15,16,17,12]])\n >>> [12]\n Explanation: 12 is the only lucky number since it is the minimum in its row and the maximum in its column.\n \n Example 3:\n \n >>> luckyNumbers(matrix = [[7,8],[1,2]])\n >>> [7]\n Explanation: 7 is the only lucky number since it is the minimum in its row and the maximum in its column.\n \"\"\"\n"}
{"task_id": "balance-a-binary-search-tree", "prompt": "# class TreeNode:\n# def __init__(val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def balanceBST(root: Optional[TreeNode]) -> Optional[TreeNode]:\n \"\"\"\n Given the root of a binary search tree, return a balanced binary search tree with the same node values. If there is more than one answer, return any of them.\n A binary search tree is balanced if the depth of the two subtrees of every node never differs by more than 1.\n \n Example 1:\n \n \n >>> __init__(root = [1,null,2,null,3,null,4,null,null])\n >>> [2,1,3,null,null,null,4]\n Explanation: This is not the only correct answer, [3,1,4,null,2] is also correct.\n \n Example 2:\n \n \n >>> __init__(root = [2,1,3])\n >>> [2,1,3]\n \"\"\"\n"}
{"task_id": "maximum-performance-of-a-team", "prompt": "def maxPerformance(n: int, speed: List[int], efficiency: List[int], k: int) -> int:\n \"\"\"\n You are given two integers n and k and two integer arrays speed and efficiency both of length n. There are n engineers numbered from 1 to n. speed[i] and efficiency[i] represent the speed and efficiency of the ith engineer respectively.\n Choose at most k different engineers out of the n engineers to form a team with the maximum performance.\n The performance of a team is the sum of its engineers' speeds multiplied by the minimum efficiency among its engineers.\n Return the maximum performance of this team. Since the answer can be a huge number, return it modulo 109 + 7.\n \n Example 1:\n \n >>> maxPerformance(n = 6, speed = [2,10,3,1,5,8], efficiency = [5,4,3,9,7,2], k = 2)\n >>> 60\n Explanation:\n We have the maximum performance of the team by selecting engineer 2 (with speed=10 and efficiency=4) and engineer 5 (with speed=5 and efficiency=7). That is, performance = (10 + 5) * min(4, 7) = 60.\n \n Example 2:\n \n >>> maxPerformance(n = 6, speed = [2,10,3,1,5,8], efficiency = [5,4,3,9,7,2], k = 3)\n >>> 68\n Explanation:\n This is the same example as the first but k = 3. We can select engineer 1, engineer 2 and engineer 5 to get the maximum performance of the team. That is, performance = (2 + 10 + 5) * min(5, 4, 7) = 68.\n \n Example 3:\n \n >>> maxPerformance(n = 6, speed = [2,10,3,1,5,8], efficiency = [5,4,3,9,7,2], k = 4)\n >>> 72\n \"\"\"\n"}
{"task_id": "find-the-distance-value-between-two-arrays", "prompt": "def findTheDistanceValue(arr1: List[int], arr2: List[int], d: int) -> int:\n \"\"\"\n Given two integer arrays arr1 and arr2, and the integer d, return the distance value between the two arrays.\n The distance value is defined as the number of elements arr1[i] such that there is not any element arr2[j] where |arr1[i]-arr2[j]| <= d.\n \n Example 1:\n \n >>> findTheDistanceValue(arr1 = [4,5,8], arr2 = [10,9,1,8], d = 2)\n >>> 2\n Explanation:\n For arr1[0]=4 we have:\n |4-10|=6 > d=2\n |4-9|=5 > d=2\n |4-1|=3 > d=2\n |4-8|=4 > d=2\n For arr1[1]=5 we have:\n |5-10|=5 > d=2\n |5-9|=4 > d=2\n |5-1|=4 > d=2\n |5-8|=3 > d=2\n For arr1[2]=8 we have:\n |8-10|=2 <= d=2\n |8-9|=1 <= d=2\n |8-1|=7 > d=2\n |8-8|=0 <= d=2\n \n Example 2:\n \n >>> findTheDistanceValue(arr1 = [1,4,2,3], arr2 = [-4,-3,6,10,20,30], d = 3)\n >>> 2\n \n Example 3:\n \n >>> findTheDistanceValue(arr1 = [2,1,100,3], arr2 = [-5,-2,10,-3,7], d = 6)\n >>> 1\n \"\"\"\n"}
{"task_id": "cinema-seat-allocation", "prompt": "def maxNumberOfFamilies(n: int, reservedSeats: List[List[int]]) -> int:\n \"\"\"\n A cinema\u00a0has n\u00a0rows of seats, numbered from 1 to n\u00a0and there are ten\u00a0seats in each row, labelled from 1\u00a0to 10\u00a0as shown in the figure above.\n Given the array reservedSeats containing the numbers of seats already reserved, for example, reservedSeats[i] = [3,8]\u00a0means the seat located in row 3 and labelled with 8\u00a0is already reserved.\n Return the maximum number of four-person groups\u00a0you can assign on the cinema\u00a0seats. A four-person group\u00a0occupies four\u00a0adjacent seats in one single row. Seats across an aisle (such as [3,3]\u00a0and [3,4]) are not considered to be adjacent, but there is an exceptional case\u00a0on which an aisle split\u00a0a four-person group, in that case, the aisle split\u00a0a four-person group in the middle,\u00a0which means to have two people on each side.\n \n Example 1:\n \n \n >>> maxNumberOfFamilies(n = 3, reservedSeats = [[1,2],[1,3],[1,8],[2,6],[3,1],[3,10]])\n >>> 4\n Explanation: The figure above shows the optimal allocation for four groups, where seats mark with blue are already reserved and contiguous seats mark with orange are for one group.\n \n Example 2:\n \n >>> maxNumberOfFamilies(n = 2, reservedSeats = [[2,1],[1,8],[2,6]])\n >>> 2\n \n Example 3:\n \n >>> maxNumberOfFamilies(n = 4, reservedSeats = [[4,3],[1,4],[4,6],[1,7]])\n >>> 4\n \"\"\"\n"}
{"task_id": "sort-integers-by-the-power-value", "prompt": "def getKth(lo: int, hi: int, k: int) -> int:\n \"\"\"\n The power of an integer x is defined as the number of steps needed to transform x into 1 using the following steps:\n \n if x is even then x = x / 2\n if x is odd then x = 3 * x + 1\n \n For example, the power of x = 3 is 7 because 3 needs 7 steps to become 1 (3 --> 10 --> 5 --> 16 --> 8 --> 4 --> 2 --> 1).\n Given three integers lo, hi and k. The task is to sort all integers in the interval [lo, hi] by the power value in ascending order, if two or more integers have the same power value sort them by ascending order.\n Return the kth integer in the range [lo, hi] sorted by the power value.\n Notice that for any integer x (lo <= x <= hi) it is guaranteed that x will transform into 1 using these steps and that the power of x is will fit in a 32-bit signed integer.\n \n Example 1:\n \n >>> getKth(lo = 12, hi = 15, k = 2)\n >>> 13\n Explanation: The power of 12 is 9 (12 --> 6 --> 3 --> 10 --> 5 --> 16 --> 8 --> 4 --> 2 --> 1)\n The power of 13 is 9\n The power of 14 is 17\n The power of 15 is 17\n The interval sorted by the power value [12,13,14,15]. For k = 2 answer is the second element which is 13.\n Notice that 12 and 13 have the same power value and we sorted them in ascending order. Same for 14 and 15.\n \n Example 2:\n \n >>> getKth(lo = 7, hi = 11, k = 4)\n >>> 7\n Explanation: The power array corresponding to the interval [7, 8, 9, 10, 11] is [16, 3, 19, 6, 14].\n The interval sorted by power is [8, 10, 11, 7, 9].\n The fourth number in the sorted array is 7.\n \"\"\"\n"}
{"task_id": "pizza-with-3n-slices", "prompt": "def maxSizeSlices(slices: List[int]) -> int:\n \"\"\"\n There is a pizza with 3n slices of varying size, you and your friends will take slices of pizza as follows:\n \n You will pick any pizza slice.\n Your friend Alice will pick the next slice in the anti-clockwise direction of your pick.\n Your friend Bob will pick the next slice in the clockwise direction of your pick.\n Repeat until there are no more slices of pizzas.\n \n Given an integer array slices that represent the sizes of the pizza slices in a clockwise direction, return the maximum possible sum of slice sizes that you can pick.\n \n Example 1:\n \n \n >>> maxSizeSlices(slices = [1,2,3,4,5,6])\n >>> 10\n Explanation: Pick pizza slice of size 4, Alice and Bob will pick slices with size 3 and 5 respectively. Then Pick slices with size 6, finally Alice and Bob will pick slice of size 2 and 1 respectively. Total = 4 + 6.\n \n Example 2:\n \n \n >>> maxSizeSlices(slices = [8,9,8,6,1,1])\n >>> 16\n Explanation: Pick pizza slice of size 8 in each turn. If you pick slice with size 9 your partners will pick slices of size 8.\n \"\"\"\n"}
{"task_id": "create-target-array-in-the-given-order", "prompt": "def createTargetArray(nums: List[int], index: List[int]) -> List[int]:\n \"\"\"\n Given two arrays of integers\u00a0nums and index. Your task is to create target array under the following rules:\n \n Initially target array is empty.\n From left to right read nums[i] and index[i], insert at index index[i]\u00a0the value nums[i]\u00a0in\u00a0target array.\n Repeat the previous step until there are no elements to read in nums and index.\n \n Return the target array.\n It is guaranteed that the insertion operations will be valid.\n \n Example 1:\n \n >>> createTargetArray(nums = [0,1,2,3,4], index = [0,1,2,2,1])\n >>> [0,4,1,3,2]\n Explanation:\n nums index target\n 0 0 [0]\n 1 1 [0,1]\n 2 2 [0,1,2]\n 3 2 [0,1,3,2]\n 4 1 [0,4,1,3,2]\n \n Example 2:\n \n >>> createTargetArray(nums = [1,2,3,4,0], index = [0,1,2,3,0])\n >>> [0,1,2,3,4]\n Explanation:\n nums index target\n 1 0 [1]\n 2 1 [1,2]\n 3 2 [1,2,3]\n 4 3 [1,2,3,4]\n 0 0 [0,1,2,3,4]\n \n Example 3:\n \n >>> createTargetArray(nums = [1], index = [0])\n >>> [1]\n \"\"\"\n"}
{"task_id": "four-divisors", "prompt": "def sumFourDivisors(nums: List[int]) -> int:\n \"\"\"\n Given an integer array nums, return the sum of divisors of the integers in that array that have exactly four divisors. If there is no such integer in the array, return 0.\n \n Example 1:\n \n >>> sumFourDivisors(nums = [21,4,7])\n >>> 32\n Explanation:\n 21 has 4 divisors: 1, 3, 7, 21\n 4 has 3 divisors: 1, 2, 4\n 7 has 2 divisors: 1, 7\n The answer is the sum of divisors of 21 only.\n \n Example 2:\n \n >>> sumFourDivisors(nums = [21,21])\n >>> 64\n \n Example 3:\n \n >>> sumFourDivisors(nums = [1,2,3,4,5])\n >>> 0\n \"\"\"\n"}
{"task_id": "check-if-there-is-a-valid-path-in-a-grid", "prompt": "def hasValidPath(grid: List[List[int]]) -> bool:\n \"\"\"\n You are given an m x n grid. Each cell of grid represents a street. The street of grid[i][j] can be:\n \n 1 which means a street connecting the left cell and the right cell.\n 2 which means a street connecting the upper cell and the lower cell.\n 3 which means a street connecting the left cell and the lower cell.\n 4 which means a street connecting the right cell and the lower cell.\n 5 which means a street connecting the left cell and the upper cell.\n 6 which means a street connecting the right cell and the upper cell.\n \n \n You will initially start at the street of the upper-left cell (0, 0). A valid path in the grid is a path that starts from the upper left cell (0, 0) and ends at the bottom-right cell (m - 1, n - 1). The path should only follow the streets.\n Notice that you are not allowed to change any street.\n Return true if there is a valid path in the grid or false otherwise.\n \n Example 1:\n \n \n >>> hasValidPath(grid = [[2,4,3],[6,5,2]])\n >>> true\n Explanation: As shown you can start at cell (0, 0) and visit all the cells of the grid to reach (m - 1, n - 1).\n \n Example 2:\n \n \n >>> hasValidPath(grid = [[1,2,1],[1,2,1]])\n >>> false\n Explanation: As shown you the street at cell (0, 0) is not connected with any street of any other cell and you will get stuck at cell (0, 0)\n \n Example 3:\n \n >>> hasValidPath(grid = [[1,1,2]])\n >>> false\n Explanation: You will get stuck at cell (0, 1) and you cannot reach cell (0, 2).\n \"\"\"\n"}
{"task_id": "longest-happy-prefix", "prompt": "def longestPrefix(s: str) -> str:\n \"\"\"\n A string is called a happy prefix if is a non-empty prefix which is also a suffix (excluding itself).\n Given a string s, return the longest happy prefix of s. Return an empty string \"\" if no such prefix exists.\n \n Example 1:\n \n >>> longestPrefix(s = \"level\")\n >>> \"l\"\n Explanation: s contains 4 prefix excluding itself (\"l\", \"le\", \"lev\", \"leve\"), and suffix (\"l\", \"el\", \"vel\", \"evel\"). The largest prefix which is also suffix is given by \"l\".\n \n Example 2:\n \n >>> longestPrefix(s = \"ababab\")\n >>> \"abab\"\n Explanation: \"abab\" is the largest prefix which is also suffix. They can overlap in the original string.\n \"\"\"\n"}
{"task_id": "find-lucky-integer-in-an-array", "prompt": "def findLucky(arr: List[int]) -> int:\n \"\"\"\n Given an array of integers arr, a lucky integer is an integer that has a frequency in the array equal to its value.\n Return the largest lucky integer in the array. If there is no lucky integer return -1.\n \n Example 1:\n \n >>> findLucky(arr = [2,2,3,4])\n >>> 2\n Explanation: The only lucky number in the array is 2 because frequency[2] == 2.\n \n Example 2:\n \n >>> findLucky(arr = [1,2,2,3,3,3])\n >>> 3\n Explanation: 1, 2 and 3 are all lucky numbers, return the largest of them.\n \n Example 3:\n \n >>> findLucky(arr = [2,2,2,3,3])\n >>> -1\n Explanation: There are no lucky numbers in the array.\n \"\"\"\n"}
{"task_id": "count-number-of-teams", "prompt": "def numTeams(rating: List[int]) -> int:\n \"\"\"\n There are n soldiers standing in a line. Each soldier is assigned a unique rating value.\n You have to form a team of 3 soldiers amongst them under the following rules:\n \n Choose 3 soldiers with index (i, j, k) with rating (rating[i], rating[j], rating[k]).\n A team is valid if: (rating[i] < rating[j] < rating[k]) or (rating[i] > rating[j] > rating[k]) where (0 <= i < j < k < n).\n \n Return the number of teams you can form given the conditions. (soldiers can be part of multiple teams).\n \n Example 1:\n \n >>> numTeams(rating = [2,5,3,4,1])\n >>> 3\n Explanation: We can form three teams given the conditions. (2,3,4), (5,4,1), (5,3,1).\n \n Example 2:\n \n >>> numTeams(rating = [2,1,3])\n >>> 0\n Explanation: We can't form any team given the conditions.\n \n Example 3:\n \n >>> numTeams(rating = [1,2,3,4])\n >>> 4\n \"\"\"\n"}
{"task_id": "find-all-good-strings", "prompt": "def findGoodStrings(n: int, s1: str, s2: str, evil: str) -> int:\n \"\"\"\n Given the strings s1 and s2 of size n and the string evil, return the number of good strings.\n A good string has size n, it is alphabetically greater than or equal to s1, it is alphabetically smaller than or equal to s2, and it does not contain the string evil as a substring. Since the answer can be a huge number, return this modulo 109 + 7.\n \n Example 1:\n \n >>> findGoodStrings(n = 2, s1 = \"aa\", s2 = \"da\", evil = \"b\")\n >>> 51\n Explanation: There are 25 good strings starting with 'a': \"aa\",\"ac\",\"ad\",...,\"az\". Then there are 25 good strings starting with 'c': \"ca\",\"cc\",\"cd\",...,\"cz\" and finally there is one good string starting with 'd': \"da\".\n \n Example 2:\n \n >>> findGoodStrings(n = 8, s1 = \"leetcode\", s2 = \"leetgoes\", evil = \"leet\")\n >>> 0\n Explanation: All strings greater than or equal to s1 and smaller than or equal to s2 start with the prefix \"leet\", therefore, there is not any good string.\n \n Example 3:\n \n >>> findGoodStrings(n = 2, s1 = \"gx\", s2 = \"gz\", evil = \"x\")\n >>> 2\n \"\"\"\n"}
{"task_id": "count-largest-group", "prompt": "def countLargestGroup(n: int) -> int:\n \"\"\"\n You are given an integer n.\n Each number from 1 to n is grouped according to the sum of its digits.\n Return the number of groups that have the largest size.\n \n Example 1:\n \n >>> countLargestGroup(n = 13)\n >>> 4\n Explanation: There are 9 groups in total, they are grouped according sum of its digits of numbers from 1 to 13:\n [1,10], [2,11], [3,12], [4,13], [5], [6], [7], [8], [9].\n There are 4 groups with largest size.\n \n Example 2:\n \n >>> countLargestGroup(n = 2)\n >>> 2\n Explanation: There are 2 groups [1], [2] of size 1.\n \"\"\"\n"}
{"task_id": "construct-k-palindrome-strings", "prompt": "def canConstruct(s: str, k: int) -> bool:\n \"\"\"\n Given a string s and an integer k, return true if you can use all the characters in s to construct non-empty k palindrome strings or false otherwise.\n \n Example 1:\n \n >>> canConstruct(s = \"annabelle\", k = 2)\n >>> true\n Explanation: You can construct two palindromes using all characters in s.\n Some possible constructions \"anna\" + \"elble\", \"anbna\" + \"elle\", \"anellena\" + \"b\"\n \n Example 2:\n \n >>> canConstruct(s = \"leetcode\", k = 3)\n >>> false\n Explanation: It is impossible to construct 3 palindromes using all the characters of s.\n \n Example 3:\n \n >>> canConstruct(s = \"true\", k = 4)\n >>> true\n Explanation: The only possible solution is to put each character in a separate string.\n \"\"\"\n"}
{"task_id": "circle-and-rectangle-overlapping", "prompt": "def checkOverlap(radius: int, xCenter: int, yCenter: int, x1: int, y1: int, x2: int, y2: int) -> bool:\n \"\"\"\n You are given a circle represented as (radius, xCenter, yCenter) and an axis-aligned rectangle represented as (x1, y1, x2, y2), where (x1, y1) are the coordinates of the bottom-left corner, and (x2, y2) are the coordinates of the top-right corner of the rectangle.\n Return true if the circle and rectangle are overlapped otherwise return false. In other words, check if there is any point (xi, yi) that belongs to the circle and the rectangle at the same time.\n \n Example 1:\n \n \n >>> checkOverlap(radius = 1, xCenter = 0, yCenter = 0, x1 = 1, y1 = -1, x2 = 3, y2 = 1)\n >>> true\n Explanation: Circle and rectangle share the point (1,0).\n \n Example 2:\n \n >>> checkOverlap(radius = 1, xCenter = 1, yCenter = 1, x1 = 1, y1 = -3, x2 = 2, y2 = -1)\n >>> false\n \n Example 3:\n \n \n >>> checkOverlap(radius = 1, xCenter = 0, yCenter = 0, x1 = -1, y1 = 0, x2 = 0, y2 = 1)\n >>> true\n \"\"\"\n"}
{"task_id": "reducing-dishes", "prompt": "def maxSatisfaction(satisfaction: List[int]) -> int:\n \"\"\"\n A chef has collected data on the satisfaction level of his n dishes. Chef can cook any dish in 1 unit of time.\n Like-time coefficient of a dish is defined as the time taken to cook that dish including previous dishes multiplied by its satisfaction level i.e. time[i] * satisfaction[i].\n Return the maximum sum of like-time coefficient that the chef can obtain after preparing some amount of dishes.\n Dishes can be prepared in any order and the chef can discard some dishes to get this maximum value.\n \n Example 1:\n \n >>> maxSatisfaction(satisfaction = [-1,-8,0,5,-9])\n >>> 14\n Explanation: After Removing the second and last dish, the maximum total like-time coefficient will be equal to (-1*1 + 0*2 + 5*3 = 14).\n Each dish is prepared in one unit of time.\n Example 2:\n \n >>> maxSatisfaction(satisfaction = [4,3,2])\n >>> 20\n Explanation: Dishes can be prepared in any order, (2*1 + 3*2 + 4*3 = 20)\n \n Example 3:\n \n >>> maxSatisfaction(satisfaction = [-1,-4,-5])\n >>> 0\n Explanation: People do not like the dishes. No dish is prepared.\n \"\"\"\n"}
{"task_id": "minimum-subsequence-in-non-increasing-order", "prompt": "def minSubsequence(nums: List[int]) -> List[int]:\n \"\"\"\n Given the array nums, obtain a subsequence of the array whose sum of elements is strictly greater than the sum of the non\u00a0included elements in such subsequence.\n If there are multiple solutions, return the subsequence with minimum size and if there still exist multiple solutions, return the subsequence with the maximum total sum of all its elements. A subsequence of an array can be obtained by erasing some (possibly zero) elements from the array.\n Note that the solution with the given constraints is guaranteed to be\u00a0unique. Also return the answer sorted in non-increasing order.\n \n Example 1:\n \n >>> minSubsequence(nums = [4,3,10,9,8])\n >>> [10,9]\n Explanation: The subsequences [10,9] and [10,8] are minimal such that the sum of their elements is strictly greater than the sum of elements not included. However, the subsequence [10,9] has the maximum total sum of its elements.\n \n Example 2:\n \n >>> minSubsequence(nums = [4,4,7,6,7])\n >>> [7,7,6]\n Explanation: The subsequence [7,7] has the sum of its elements equal to 14 which is not strictly greater than the sum of elements not included (14 = 4 + 4 + 6). Therefore, the subsequence [7,6,7] is the minimal satisfying the conditions. Note the subsequence has to be returned in non-increasing order.\n \"\"\"\n"}
{"task_id": "number-of-steps-to-reduce-a-number-in-binary-representation-to-one", "prompt": "def numSteps(s: str) -> int:\n \"\"\"\n Given the binary representation of an integer as a string s, return the number of steps to reduce it to 1 under the following rules:\n \n \n If the current number is even, you have to divide it by 2.\n \n \n If the current number is odd, you have to add 1 to it.\n \n \n It is guaranteed that you can always reach one for all test cases.\n \n Example 1:\n \n >>> numSteps(s = \"1101\")\n >>> 6\n Explanation: \"1101\" corressponds to number 13 in their decimal representation.\n Step 1) 13 is odd, add 1 and obtain 14.\n Step 2) 14 is even, divide by 2 and obtain 7.\n Step 3) 7 is odd, add 1 and obtain 8.\n Step 4) 8 is even, divide by 2 and obtain 4.\n Step 5) 4 is even, divide by 2 and obtain 2.\n Step 6) 2 is even, divide by 2 and obtain 1.\n \n Example 2:\n \n >>> numSteps(s = \"10\")\n >>> 1\n Explanation: \"10\" corresponds to number 2 in their decimal representation.\n Step 1) 2 is even, divide by 2 and obtain 1.\n \n Example 3:\n \n >>> numSteps(s = \"1\")\n >>> 0\n \"\"\"\n"}
{"task_id": "longest-happy-string", "prompt": "def longestDiverseString(a: int, b: int, c: int) -> str:\n \"\"\"\n A string s is called happy if it satisfies the following conditions:\n \n s only contains the letters 'a', 'b', and 'c'.\n s does not contain any of \"aaa\", \"bbb\", or \"ccc\" as a substring.\n s contains at most a occurrences of the letter 'a'.\n s contains at most b occurrences of the letter 'b'.\n s contains at most c occurrences of the letter 'c'.\n \n Given three integers a, b, and c, return the longest possible happy string. If there are multiple longest happy strings, return any of them. If there is no such string, return the empty string \"\".\n A substring is a contiguous sequence of characters within a string.\n \n Example 1:\n \n >>> longestDiverseString(a = 1, b = 1, c = 7)\n >>> \"ccaccbcc\"\n Explanation: \"ccbccacc\" would also be a correct answer.\n \n Example 2:\n \n >>> longestDiverseString(a = 7, b = 1, c = 0)\n >>> \"aabaa\"\n Explanation: It is the only correct answer in this case.\n \"\"\"\n"}
{"task_id": "stone-game-iii", "prompt": "def stoneGameIII(stoneValue: List[int]) -> str:\n \"\"\"\n Alice and Bob continue their games with piles of stones. There are several stones arranged in a row, and each stone has an associated value which is an integer given in the array stoneValue.\n Alice and Bob take turns, with Alice starting first. On each player's turn, that player can take 1, 2, or 3 stones from the first remaining stones in the row.\n The score of each player is the sum of the values of the stones taken. The score of each player is 0 initially.\n The objective of the game is to end with the highest score, and the winner is the player with the highest score and there could be a tie. The game continues until all the stones have been taken.\n Assume Alice and Bob play optimally.\n Return \"Alice\" if Alice will win, \"Bob\" if Bob will win, or \"Tie\" if they will end the game with the same score.\n \n Example 1:\n \n >>> stoneGameIII(stoneValue = [1,2,3,7])\n >>> \"Bob\"\n Explanation: Alice will always lose. Her best move will be to take three piles and the score become 6. Now the score of Bob is 7 and Bob wins.\n \n Example 2:\n \n >>> stoneGameIII(stoneValue = [1,2,3,-9])\n >>> \"Alice\"\n Explanation: Alice must choose all the three piles at the first move to win and leave Bob with negative score.\n If Alice chooses one pile her score will be 1 and the next move Bob's score becomes 5. In the next move, Alice will take the pile with value = -9 and lose.\n If Alice chooses two piles her score will be 3 and the next move Bob's score becomes 3. In the next move, Alice will take the pile with value = -9 and also lose.\n Remember that both play optimally so here Alice will choose the scenario that makes her win.\n \n Example 3:\n \n >>> stoneGameIII(stoneValue = [1,2,3,6])\n >>> \"Tie\"\n Explanation: Alice cannot win this game. She can end the game in a draw if she decided to choose all the first three piles, otherwise she will lose.\n \"\"\"\n"}
{"task_id": "string-matching-in-an-array", "prompt": "def stringMatching(words: List[str]) -> List[str]:\n \"\"\"\n Given an array of string words, return all strings in words that are a substring of another word. You can return the answer in any order.\n \n Example 1:\n \n >>> stringMatching(words = [\"mass\",\"as\",\"hero\",\"superhero\"])\n >>> [\"as\",\"hero\"]\n Explanation: \"as\" is substring of \"mass\" and \"hero\" is substring of \"superhero\".\n [\"hero\",\"as\"] is also a valid answer.\n \n Example 2:\n \n >>> stringMatching(words = [\"leetcode\",\"et\",\"code\"])\n >>> [\"et\",\"code\"]\n Explanation: \"et\", \"code\" are substring of \"leetcode\".\n \n Example 3:\n \n >>> stringMatching(words = [\"blue\",\"green\",\"bu\"])\n >>> []\n Explanation: No string of words is substring of another string.\n \"\"\"\n"}
{"task_id": "queries-on-a-permutation-with-key", "prompt": "def processQueries(queries: List[int], m: int) -> List[int]:\n \"\"\"\n Given the array queries of positive integers between 1 and m, you have to process all queries[i] (from i=0 to i=queries.length-1) according to the following rules:\n \n In the beginning, you have the permutation P=[1,2,3,...,m].\n For the current i, find the position of queries[i] in the permutation P (indexing from 0) and then move this at the beginning of the permutation P. Notice that the position of queries[i] in P is the result for queries[i].\n \n Return an array containing the result for the given queries.\n \n Example 1:\n \n >>> processQueries(queries = [3,1,2,1], m = 5)\n >>> [2,1,2,1]\n Explanation: The queries are processed as follow:\n For i=0: queries[i]=3, P=[1,2,3,4,5], position of 3 in P is 2, then we move 3 to the beginning of P resulting in P=[3,1,2,4,5].\n For i=1: queries[i]=1, P=[3,1,2,4,5], position of 1 in P is 1, then we move 1 to the beginning of P resulting in P=[1,3,2,4,5].\n For i=2: queries[i]=2, P=[1,3,2,4,5], position of 2 in P is 2, then we move 2 to the beginning of P resulting in P=[2,1,3,4,5].\n For i=3: queries[i]=1, P=[2,1,3,4,5], position of 1 in P is 1, then we move 1 to the beginning of P resulting in P=[1,2,3,4,5].\n Therefore, the array containing the result is [2,1,2,1].\n \n Example 2:\n \n >>> processQueries(queries = [4,1,2,2], m = 4)\n >>> [3,1,2,0]\n \n Example 3:\n \n >>> processQueries(queries = [7,5,5,8,3], m = 8)\n >>> [6,5,0,7,5]\n \"\"\"\n"}
{"task_id": "html-entity-parser", "prompt": "def entityParser(text: str) -> str:\n \"\"\"\n HTML entity parser is the parser that takes HTML code as input and replace all the entities of the special characters by the characters itself.\n The special characters and their entities for HTML are:\n \n Quotation Mark: the entity is " and symbol character is \".\n Single Quote Mark: the entity is ' and symbol character is '.\n Ampersand: the entity is & and symbol character is &.\n Greater Than Sign: the entity is > and symbol character is >.\n Less Than Sign: the entity is < and symbol character is <.\n Slash: the entity is ⁄ and symbol character is /.\n \n Given the input text string to the HTML parser, you have to implement the entity parser.\n Return the text after replacing the entities by the special characters.\n \n Example 1:\n \n >>> entityParser(text = \"& is an HTML entity but &ambassador; is not.\")\n >>> \"& is an HTML entity but &ambassador; is not.\"\n Explanation: The parser will replace the & entity by &\n \n Example 2:\n \n >>> entityParser(text = \"and I quote: "..."\")\n >>> \"and I quote: \\\"...\\\"\"\n \"\"\"\n"}
{"task_id": "number-of-ways-to-paint-n-3-grid", "prompt": "def numOfWays(n: int) -> int:\n \"\"\"\n You have a grid of size n x 3 and you want to paint each cell of the grid with exactly one of the three colors: Red, Yellow, or Green while making sure that no two adjacent cells have the same color (i.e., no two cells that share vertical or horizontal sides have the same color).\n Given n the number of rows of the grid, return the number of ways you can paint this grid. As the answer may grow large, the answer must be computed modulo 109 + 7.\n \n Example 1:\n \n \n >>> numOfWays(n = 1)\n >>> 12\n Explanation: There are 12 possible way to paint the grid as shown.\n \n Example 2:\n \n >>> numOfWays(n = 5000)\n >>> 30228214\n \"\"\"\n"}
{"task_id": "minimum-value-to-get-positive-step-by-step-sum", "prompt": "def minStartValue(nums: List[int]) -> int:\n \"\"\"\n Given an array of integers\u00a0nums, you start with an initial positive value startValue.\n In each iteration, you calculate the step by step sum of startValue\u00a0plus\u00a0elements in nums\u00a0(from left to right).\n Return the minimum positive value of\u00a0startValue such that the step by step sum is never less than 1.\n \n Example 1:\n \n >>> minStartValue(nums = [-3,2,-3,4,2])\n >>> 5\n Explanation: If you choose startValue = 4, in the third iteration your step by step sum is less than 1.\n step by step sum\n startValue = 4 | startValue = 5 | nums\n (4 -3 ) = 1 | (5 -3 ) = 2 | -3\n (1 +2 ) = 3 | (2 +2 ) = 4 | 2\n (3 -3 ) = 0 | (4 -3 ) = 1 | -3\n (0 +4 ) = 4 | (1 +4 ) = 5 | 4\n (4 +2 ) = 6 | (5 +2 ) = 7 | 2\n \n Example 2:\n \n >>> minStartValue(nums = [1,2])\n >>> 1\n Explanation: Minimum start value should be positive.\n \n Example 3:\n \n >>> minStartValue(nums = [1,-2,-3])\n >>> 5\n \"\"\"\n"}
{"task_id": "find-the-minimum-number-of-fibonacci-numbers-whose-sum-is-k", "prompt": "def findMinFibonacciNumbers(k: int) -> int:\n \"\"\"\n Given an integer\u00a0k, return the minimum number of Fibonacci numbers whose sum is equal to k. The same Fibonacci number can be used multiple times.\n The Fibonacci numbers are defined as:\n \n F1 = 1\n F2 = 1\n Fn = Fn-1 + Fn-2 for n > 2.\n \n It is guaranteed that for the given constraints we can always find such Fibonacci numbers that sum up to k.\n \n Example 1:\n \n >>> findMinFibonacciNumbers(k = 7)\n >>> 2\n Explanation: The Fibonacci numbers are: 1, 1, 2, 3, 5, 8, 13, ...\n For k = 7 we can use 2 + 5 = 7.\n Example 2:\n \n >>> findMinFibonacciNumbers(k = 10)\n >>> 2\n Explanation: For k = 10 we can use 2 + 8 = 10.\n \n Example 3:\n \n >>> findMinFibonacciNumbers(k = 19)\n >>> 3\n Explanation: For k = 19 we can use 1 + 5 + 13 = 19.\n \"\"\"\n"}
{"task_id": "the-k-th-lexicographical-string-of-all-happy-strings-of-length-n", "prompt": "def getHappyString(n: int, k: int) -> str:\n \"\"\"\n A happy string is a string that:\n \n consists only of letters of the set ['a', 'b', 'c'].\n s[i] != s[i + 1] for all values of i from 1 to s.length - 1 (string is 1-indexed).\n \n For example, strings \"abc\", \"ac\", \"b\" and \"abcbabcbcb\" are all happy strings and strings \"aa\", \"baa\" and \"ababbc\" are not happy strings.\n Given two integers n and k, consider a list of all happy strings of length n sorted in lexicographical order.\n Return the kth string of this list or return an empty string if there are less than k happy strings of length n.\n \n Example 1:\n \n >>> getHappyString(n = 1, k = 3)\n >>> \"c\"\n Explanation: The list [\"a\", \"b\", \"c\"] contains all happy strings of length 1. The third string is \"c\".\n \n Example 2:\n \n >>> getHappyString(n = 1, k = 4)\n >>> \"\"\n Explanation: There are only 3 happy strings of length 1.\n \n Example 3:\n \n >>> getHappyString(n = 3, k = 9)\n >>> \"cab\"\n Explanation: There are 12 different happy string of length 3 [\"aba\", \"abc\", \"aca\", \"acb\", \"bab\", \"bac\", \"bca\", \"bcb\", \"cab\", \"cac\", \"cba\", \"cbc\"]. You will find the 9th string = \"cab\"\n \"\"\"\n"}
{"task_id": "restore-the-array", "prompt": "def numberOfArrays(s: str, k: int) -> int:\n \"\"\"\n A program was supposed to print an array of integers. The program forgot to print whitespaces and the array is printed as a string of digits s and all we know is that all integers in the array were in the range [1, k] and there are no leading zeros in the array.\n Given the string s and the integer k, return the number of the possible arrays that can be printed as s using the mentioned program. Since the answer may be very large, return it modulo 109 + 7.\n \n Example 1:\n \n >>> numberOfArrays(s = \"1000\", k = 10000)\n >>> 1\n Explanation: The only possible array is [1000]\n \n Example 2:\n \n >>> numberOfArrays(s = \"1000\", k = 10)\n >>> 0\n Explanation: There cannot be an array that was printed this way and has all integer >= 1 and <= 10.\n \n Example 3:\n \n >>> numberOfArrays(s = \"1317\", k = 2000)\n >>> 8\n Explanation: Possible arrays are [1317],[131,7],[13,17],[1,317],[13,1,7],[1,31,7],[1,3,17],[1,3,1,7]\n \"\"\"\n"}
{"task_id": "reformat-the-string", "prompt": "def reformat(s: str) -> str:\n \"\"\"\n You are given an alphanumeric string s. (Alphanumeric string is a string consisting of lowercase English letters and digits).\n You have to find a permutation of the string where no letter is followed by another letter and no digit is followed by another digit. That is, no two adjacent characters have the same type.\n Return the reformatted string or return an empty string if it is impossible to reformat the string.\n \n Example 1:\n \n >>> reformat(s = \"a0b1c2\")\n >>> \"0a1b2c\"\n Explanation: No two adjacent characters have the same type in \"0a1b2c\". \"a0b1c2\", \"0a1b2c\", \"0c2a1b\" are also valid permutations.\n \n Example 2:\n \n >>> reformat(s = \"leetcode\")\n >>> \"\"\n Explanation: \"leetcode\" has only characters so we cannot separate them by digits.\n \n Example 3:\n \n >>> reformat(s = \"1229857369\")\n >>> \"\"\n Explanation: \"1229857369\" has only digits so we cannot separate them by characters.\n \"\"\"\n"}
{"task_id": "display-table-of-food-orders-in-a-restaurant", "prompt": "def displayTable(orders: List[List[str]]) -> List[List[str]]:\n \"\"\"\n Given\u00a0the array orders, which represents the orders that customers have done in a restaurant. More specifically\u00a0orders[i]=[customerNamei,tableNumberi,foodItemi] where customerNamei is the name of the customer, tableNumberi\u00a0is the table customer sit at, and foodItemi\u00a0is the item customer orders.\\r\n \\r\n Return the restaurant's \u201cdisplay table\u201d. The \u201cdisplay table\u201d is a table whose row entries denote how many of each food item each table ordered. The first column is the table number and the remaining columns correspond to each food item in alphabetical order. The first row should be a header whose first column is \u201cTable\u201d, followed by the names of the food items. Note that the customer names are not part of the table. Additionally, the rows should be sorted in numerically increasing order.\\r\n \\r\n \u00a0\\r\n Example 1:\\r\n \\r\n \\r\n >>> displayTable(orders = [[\"David\",\"3\",\"Ceviche\"],[\"Corina\",\"10\",\"Beef Burrito\"],[\"David\",\"3\",\"Fried Chicken\"],[\"Carla\",\"5\",\"Water\"],[\"Carla\",\"5\",\"Ceviche\"],[\"Rous\",\"3\",\"Ceviche\"]]\\r)\n >>> [[\"Table\",\"Beef Burrito\",\"Ceviche\",\"Fried Chicken\",\"Water\"],[\"3\",\"0\",\"2\",\"1\",\"0\"],[\"5\",\"0\",\"1\",\"0\",\"1\"],[\"10\",\"1\",\"0\",\"0\",\"0\"]] \\r\n Explanation:\\r\n The displaying table looks like:\\r\n Table,Beef Burrito,Ceviche,Fried Chicken,Water\\r\n 3 ,0 ,2 ,1 ,0\\r\n 5 ,0 ,1 ,0 ,1\\r\n 10 ,1 ,0 ,0 ,0\\r\n For the table 3: David orders \"Ceviche\" and \"Fried Chicken\", and Rous orders \"Ceviche\".\\r\n For the table 5: Carla orders \"Water\" and \"Ceviche\".\\r\n For the table 10: Corina orders \"Beef Burrito\". \\r\n \\r\n \\r\n Example 2:\\r\n \\r\n \\r\n >>> displayTable(orders = [[\"James\",\"12\",\"Fried Chicken\"],[\"Ratesh\",\"12\",\"Fried Chicken\"],[\"Amadeus\",\"12\",\"Fried Chicken\"],[\"Adam\",\"1\",\"Canadian Waffles\"],[\"Brianna\",\"1\",\"Canadian Waffles\"]]\\r)\n >>> [[\"Table\",\"Canadian Waffles\",\"Fried Chicken\"],[\"1\",\"2\",\"0\"],[\"12\",\"0\",\"3\"]] \\r\n Explanation: \\r\n For the table 1: Adam and Brianna order \"Canadian Waffles\".\\r\n For the table 12: James, Ratesh and Amadeus order \"Fried Chicken\".\\r\n \\r\n \\r\n Example 3:\\r\n \\r\n \\r\n >>> displayTable(orders = [[\"Laura\",\"2\",\"Bean Burrito\"],[\"Jhon\",\"2\",\"Beef Burrito\"],[\"Melissa\",\"2\",\"Soda\"]]\\r)\n >>> [[\"Table\",\"Bean Burrito\",\"Beef Burrito\",\"Soda\"],[\"2\",\"1\",\"1\",\"1\"]]\\r\n \\r\n \\r\n \u00a0\\r\n \"\"\"\n"}
{"task_id": "minimum-number-of-frogs-croaking", "prompt": "def minNumberOfFrogs(croakOfFrogs: str) -> int:\n \"\"\"\n You are given the string croakOfFrogs, which represents a combination of the string \"croak\" from different frogs, that is, multiple frogs can croak at the same time, so multiple \"croak\" are mixed.\n Return the minimum number of different frogs to finish all the croaks in the given string.\n A valid \"croak\" means a frog is printing five letters 'c', 'r', 'o', 'a', and 'k' sequentially. The frogs have to print all five letters to finish a croak. If the given string is not a combination of a valid \"croak\" return -1.\n \n Example 1:\n \n >>> minNumberOfFrogs(croakOfFrogs = \"croakcroak\")\n >>> 1\n Explanation: One frog yelling \"croak\" twice.\n \n Example 2:\n \n >>> minNumberOfFrogs(croakOfFrogs = \"crcoakroak\")\n >>> 2\n Explanation: The minimum number of frogs is two.\n The first frog could yell \"crcoakroak\".\n The second frog could yell later \"crcoakroak\".\n \n Example 3:\n \n >>> minNumberOfFrogs(croakOfFrogs = \"croakcrook\")\n >>> -1\n Explanation: The given string is an invalid combination of \"croak\" from different frogs.\n \"\"\"\n"}
{"task_id": "build-array-where-you-can-find-the-maximum-exactly-k-comparisons", "prompt": "def numOfArrays(n: int, m: int, k: int) -> int:\n \"\"\"\n You are given three integers n, m and k. Consider the following algorithm to find the maximum element of an array of positive integers:\n \n You should build the array arr which has the following properties:\n \n arr has exactly n integers.\n 1 <= arr[i] <= m where (0 <= i < n).\n After applying the mentioned algorithm to arr, the value search_cost is equal to k.\n \n Return the number of ways to build the array arr under the mentioned conditions. As the answer may grow large, the answer must be computed modulo 109 + 7.\n \n Example 1:\n \n >>> numOfArrays(n = 2, m = 3, k = 1)\n >>> 6\n Explanation: The possible arrays are [1, 1], [2, 1], [2, 2], [3, 1], [3, 2] [3, 3]\n \n Example 2:\n \n >>> numOfArrays(n = 5, m = 2, k = 3)\n >>> 0\n Explanation: There are no possible arrays that satisfy the mentioned conditions.\n \n Example 3:\n \n >>> numOfArrays(n = 9, m = 1, k = 1)\n >>> 1\n Explanation: The only possible array is [1, 1, 1, 1, 1, 1, 1, 1, 1]\n \"\"\"\n"}
{"task_id": "maximum-score-after-splitting-a-string", "prompt": "def maxScore(s: str) -> int:\n \"\"\"\n Given a\u00a0string s\u00a0of zeros and ones, return the maximum score after splitting the string into two non-empty substrings (i.e. left substring and right substring).\n The score after splitting a string is the number of zeros in the left substring plus the number of ones in the right substring.\n \n Example 1:\n \n >>> maxScore(s = \"011101\")\n >>> 5\n Explanation:\n All possible ways of splitting s into two non-empty substrings are:\n left = \"0\" and right = \"11101\", score = 1 + 4 = 5\n left = \"01\" and right = \"1101\", score = 1 + 3 = 4\n left = \"011\" and right = \"101\", score = 1 + 2 = 3\n left = \"0111\" and right = \"01\", score = 1 + 1 = 2\n left = \"01110\" and right = \"1\", score = 2 + 1 = 3\n \n Example 2:\n \n >>> maxScore(s = \"00111\")\n >>> 5\n Explanation: When left = \"00\" and right = \"111\", we get the maximum score = 2 + 3 = 5\n \n Example 3:\n \n >>> maxScore(s = \"1111\")\n >>> 3\n \"\"\"\n"}
{"task_id": "maximum-points-you-can-obtain-from-cards", "prompt": "def maxScore(cardPoints: List[int], k: int) -> int:\n \"\"\"\n There are several cards arranged in a row, and each card has an associated number of points. The points are given in the integer array cardPoints.\n In one step, you can take one card from the beginning or from the end of the row. You have to take exactly k cards.\n Your score is the sum of the points of the cards you have taken.\n Given the integer array cardPoints and the integer k, return the maximum score you can obtain.\n \n Example 1:\n \n >>> maxScore(cardPoints = [1,2,3,4,5,6,1], k = 3)\n >>> 12\n Explanation: After the first step, your score will always be 1. However, choosing the rightmost card first will maximize your total score. The optimal strategy is to take the three cards on the right, giving a final score of 1 + 6 + 5 = 12.\n \n Example 2:\n \n >>> maxScore(cardPoints = [2,2,2], k = 2)\n >>> 4\n Explanation: Regardless of which two cards you take, your score will always be 4.\n \n Example 3:\n \n >>> maxScore(cardPoints = [9,7,7,9,7,7,9], k = 7)\n >>> 55\n Explanation: You have to take all the cards. Your score is the sum of points of all cards.\n \"\"\"\n"}
{"task_id": "diagonal-traverse-ii", "prompt": "def findDiagonalOrder(nums: List[List[int]]) -> List[int]:\n \"\"\"\n Given a 2D integer array nums, return all elements of nums in diagonal order as shown in the below images.\n \n Example 1:\n \n \n >>> findDiagonalOrder(nums = [[1,2,3],[4,5,6],[7,8,9]])\n >>> [1,4,2,7,5,3,8,6,9]\n \n Example 2:\n \n \n >>> findDiagonalOrder(nums = [[1,2,3,4,5],[6,7],[8],[9,10,11],[12,13,14,15,16]])\n >>> [1,6,2,8,7,3,9,4,12,10,5,13,11,14,15,16]\n \"\"\"\n"}
{"task_id": "constrained-subsequence-sum", "prompt": "def constrainedSubsetSum(nums: List[int], k: int) -> int:\n \"\"\"\n Given an integer array nums and an integer k, return the maximum sum of a non-empty subsequence of that array such that for every two consecutive integers in the subsequence, nums[i] and nums[j], where i < j, the condition j - i <= k is satisfied.\n A subsequence of an array is obtained by deleting some number of elements (can be zero) from the array, leaving the remaining elements in their original order.\n \n Example 1:\n \n >>> constrainedSubsetSum(nums = [10,2,-10,5,20], k = 2)\n >>> 37\n Explanation: The subsequence is [10, 2, 5, 20].\n \n Example 2:\n \n >>> constrainedSubsetSum(nums = [-1,-2,-3], k = 1)\n >>> -1\n Explanation: The subsequence must be non-empty, so we choose the largest number.\n \n Example 3:\n \n >>> constrainedSubsetSum(nums = [10,-2,-10,-5,20], k = 2)\n >>> 23\n Explanation: The subsequence is [10, -2, -5, 20].\n \"\"\"\n"}
{"task_id": "counting-elements", "prompt": "def countElements(arr: List[int]) -> int:\n \"\"\"\n Given an integer array arr, count how many elements x there are, such that x + 1 is also in arr. If there are duplicates in arr, count them separately.\n \n Example 1:\n \n >>> countElements(arr = [1,2,3])\n >>> 2\n Explanation: 1 and 2 are counted cause 2 and 3 are in arr.\n \n Example 2:\n \n >>> countElements(arr = [1,1,3,3,5,5,7,7])\n >>> 0\n Explanation: No numbers are counted, cause there is no 2, 4, 6, or 8 in arr.\n \"\"\"\n"}
{"task_id": "perform-string-shifts", "prompt": "def stringShift(s: str, shift: List[List[int]]) -> str:\n \"\"\"\n You are given a string s containing lowercase English letters, and a matrix shift, where shift[i] = [directioni, amounti]:\n \n directioni can be 0 (for left shift) or 1 (for right shift).\n amounti is the amount by which string s is to be shifted.\n A left shift by 1 means remove the first character of s and append it to the end.\n Similarly, a right shift by 1 means remove the last character of s and add it to the beginning.\n \n Return the final string after all operations.\n \n Example 1:\n \n >>> stringShift(s = \"abc\", shift = [[0,1],[1,2]])\n >>> \"cab\"\n Explanation:\n [0,1] means shift to left by 1. \"abc\" -> \"bca\"\n [1,2] means shift to right by 2. \"bca\" -> \"cab\"\n Example 2:\n \n >>> stringShift(s = \"abcdefg\", shift = [[1,1],[1,1],[0,2],[1,3]])\n >>> \"efgabcd\"\n Explanation:\n [1,1] means shift to right by 1. \"abcdefg\" -> \"gabcdef\"\n [1,1] means shift to right by 1. \"gabcdef\" -> \"fgabcde\"\n [0,2] means shift to left by 2. \"fgabcde\" -> \"abcdefg\"\n [1,3] means shift to right by 3. \"abcdefg\" -> \"efgabcd\"\n \"\"\"\n"}
{"task_id": "check-if-a-string-is-a-valid-sequence-from-root-to-leaves-path-in-a-binary-tree", "prompt": "# class TreeNode:\n# def __init__(val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def isValidSequence(root: Optional[TreeNode], arr: List[int]) -> bool:\n \"\"\"\n Given a binary tree where each path going from the root to any leaf form a valid sequence, check if a given string\u00a0is a valid sequence in such binary tree.\n We get the given string from the concatenation of an array of integers arr and the concatenation of all\u00a0values of the nodes along a path results in a sequence in the given binary tree.\n \n Example 1:\n \n \n >>> __init__(root = [0,1,0,0,1,0,null,null,1,0,0], arr = [0,1,0,1])\n >>> true\n Explanation:\n The path 0 -> 1 -> 0 -> 1 is a valid sequence (green color in the figure).\n Other valid sequences are:\n 0 -> 1 -> 1 -> 0\n 0 -> 0 -> 0\n \n Example 2:\n \n \n >>> __init__(root = [0,1,0,0,1,0,null,null,1,0,0], arr = [0,0,1])\n >>> false\n Explanation: The path 0 -> 0 -> 1 does not exist, therefore it is not even a sequence.\n \n Example 3:\n \n \n >>> __init__(root = [0,1,0,0,1,0,null,null,1,0,0], arr = [0,1,1])\n >>> false\n Explanation: The path 0 -> 1 -> 1 is a sequence, but it is not a valid sequence.\n \"\"\"\n"}
{"task_id": "kids-with-the-greatest-number-of-candies", "prompt": "def kidsWithCandies(candies: List[int], extraCandies: int) -> List[bool]:\n \"\"\"\n There are n kids with candies. You are given an integer array candies, where each candies[i] represents the number of candies the ith kid has, and an integer extraCandies, denoting the number of extra candies that you have.\n Return a boolean array result of length n, where result[i] is true if, after giving the ith kid all the extraCandies, they will have the greatest number of candies among all the kids, or false otherwise.\n Note that multiple kids can have the greatest number of candies.\n \n Example 1:\n \n >>> kidsWithCandies(candies = [2,3,5,1,3], extraCandies = 3)\n >>> [true,true,true,false,true]\n Explanation: If you give all extraCandies to:\n - Kid 1, they will have 2 + 3 = 5 candies, which is the greatest among the kids.\n - Kid 2, they will have 3 + 3 = 6 candies, which is the greatest among the kids.\n - Kid 3, they will have 5 + 3 = 8 candies, which is the greatest among the kids.\n - Kid 4, they will have 1 + 3 = 4 candies, which is not the greatest among the kids.\n - Kid 5, they will have 3 + 3 = 6 candies, which is the greatest among the kids.\n \n Example 2:\n \n >>> kidsWithCandies(candies = [4,2,1,1,2], extraCandies = 1)\n >>> [true,false,false,false,false]\n Explanation: There is only 1 extra candy.\n Kid 1 will always have the greatest number of candies, even if a different kid is given the extra candy.\n \n Example 3:\n \n >>> kidsWithCandies(candies = [12,1,12], extraCandies = 10)\n >>> [true,false,true]\n \"\"\"\n"}
{"task_id": "max-difference-you-can-get-from-changing-an-integer", "prompt": "def maxDiff(num: int) -> int:\n \"\"\"\n You are given an integer num. You will apply the following steps exactly two times:\n \n Pick a digit x (0 <= x <= 9).\n Pick another digit y (0 <= y <= 9). The digit y can be equal to x.\n Replace all the occurrences of x in the decimal representation of num by y.\n The new integer cannot have any leading zeros, also the new integer cannot be 0.\n \n Let a and b be the results of applying the operations to num the first and second times, respectively.\n Return the max difference between a and b.\n \n Example 1:\n \n >>> maxDiff(num = 555)\n >>> 888\n Explanation: The first time pick x = 5 and y = 9 and store the new integer in a.\n The second time pick x = 5 and y = 1 and store the new integer in b.\n We have now a = 999 and b = 111 and max difference = 888\n \n Example 2:\n \n >>> maxDiff(num = 9)\n >>> 8\n Explanation: The first time pick x = 9 and y = 9 and store the new integer in a.\n The second time pick x = 9 and y = 1 and store the new integer in b.\n We have now a = 9 and b = 1 and max difference = 8\n \"\"\"\n"}
{"task_id": "check-if-a-string-can-break-another-string", "prompt": "def checkIfCanBreak(s1: str, s2: str) -> bool:\n \"\"\"\n Given two strings: s1 and s2 with the same\u00a0size, check if some\u00a0permutation of string s1 can break\u00a0some\u00a0permutation of string s2 or vice-versa. In other words s2 can break s1\u00a0or vice-versa.\n A string x\u00a0can break\u00a0string y\u00a0(both of size n) if x[i] >= y[i]\u00a0(in alphabetical order)\u00a0for all i\u00a0between 0 and n-1.\n \n Example 1:\n \n >>> checkIfCanBreak(s1 = \"abc\", s2 = \"xya\")\n >>> true\n Explanation: \"ayx\" is a permutation of s2=\"xya\" which can break to string \"abc\" which is a permutation of s1=\"abc\".\n \n Example 2:\n \n >>> checkIfCanBreak(s1 = \"abe\", s2 = \"acd\")\n >>> false\n Explanation: All permutations for s1=\"abe\" are: \"abe\", \"aeb\", \"bae\", \"bea\", \"eab\" and \"eba\" and all permutation for s2=\"acd\" are: \"acd\", \"adc\", \"cad\", \"cda\", \"dac\" and \"dca\". However, there is not any permutation from s1 which can break some permutation from s2 and vice-versa.\n \n Example 3:\n \n >>> checkIfCanBreak(s1 = \"leetcodee\", s2 = \"interview\")\n >>> true\n \"\"\"\n"}
{"task_id": "number-of-ways-to-wear-different-hats-to-each-other", "prompt": "def numberWays(hats: List[List[int]]) -> int:\n \"\"\"\n There are n people and 40 types of hats labeled from 1 to 40.\n Given a 2D integer array hats, where hats[i] is a list of all hats preferred by the ith person.\n Return the number of ways that n people can wear different hats from each other.\n Since the answer may be too large, return it modulo 109 + 7.\n \n Example 1:\n \n >>> numberWays(hats = [[3,4],[4,5],[5]])\n >>> 1\n Explanation: There is only one way to choose hats given the conditions.\n First person choose hat 3, Second person choose hat 4 and last one hat 5.\n \n Example 2:\n \n >>> numberWays(hats = [[3,5,1],[3,5]])\n >>> 4\n Explanation: There are 4 ways to choose hats:\n (3,5), (5,3), (1,3) and (1,5)\n \n Example 3:\n \n >>> numberWays(hats = [[1,2,3,4],[1,2,3,4],[1,2,3,4],[1,2,3,4]])\n >>> 24\n Explanation: Each person can choose hats labeled from 1 to 4.\n Number of Permutations of (1,2,3,4) = 24.\n \"\"\"\n"}
{"task_id": "destination-city", "prompt": "def destCity(paths: List[List[str]]) -> str:\n \"\"\"\n You are given the array paths, where paths[i] = [cityAi, cityBi] means there exists a direct path going from cityAi to cityBi. Return the destination city, that is, the city without any path outgoing to another city.\n It is guaranteed that the graph of paths forms a line without any loop, therefore, there will be exactly one destination city.\n \n Example 1:\n \n >>> destCity(paths = [[\"London\",\"New York\"],[\"New York\",\"Lima\"],[\"Lima\",\"Sao Paulo\"]])\n >>> \"Sao Paulo\"\n Explanation: Starting at \"London\" city you will reach \"Sao Paulo\" city which is the destination city. Your trip consist of: \"London\" -> \"New York\" -> \"Lima\" -> \"Sao Paulo\".\n \n Example 2:\n \n >>> destCity(paths = [[\"B\",\"C\"],[\"D\",\"B\"],[\"C\",\"A\"]])\n >>> \"A\"\n Explanation: All possible trips are:\n \"D\" -> \"B\" -> \"C\" -> \"A\".\n \"B\" -> \"C\" -> \"A\".\n \"C\" -> \"A\".\n \"A\".\n Clearly the destination city is \"A\".\n \n Example 3:\n \n >>> destCity(paths = [[\"A\",\"Z\"]])\n >>> \"Z\"\n \"\"\"\n"}
{"task_id": "check-if-all-1s-are-at-least-length-k-places-away", "prompt": "def kLengthApart(nums: List[int], k: int) -> bool:\n \"\"\"\n Given an binary array nums and an integer k, return true if all 1's are at least k places away from each other, otherwise return false.\n \n Example 1:\n \n \n >>> kLengthApart(nums = [1,0,0,0,1,0,0,1], k = 2)\n >>> true\n Explanation: Each of the 1s are at least 2 places away from each other.\n \n Example 2:\n \n \n >>> kLengthApart(nums = [1,0,0,1,0,1], k = 2)\n >>> false\n Explanation: The second 1 and third 1 are only one apart from each other.\n \"\"\"\n"}
{"task_id": "longest-continuous-subarray-with-absolute-diff-less-than-or-equal-to-limit", "prompt": "def longestSubarray(nums: List[int], limit: int) -> int:\n \"\"\"\n Given an array of integers nums and an integer limit, return the size of the longest non-empty subarray such that the absolute difference between any two elements of this subarray is less than or equal to limit.\n \n Example 1:\n \n >>> longestSubarray(nums = [8,2,4,7], limit = 4)\n >>> 2\n Explanation: All subarrays are:\n [8] with maximum absolute diff |8-8| = 0 <= 4.\n [8,2] with maximum absolute diff |8-2| = 6 > 4.\n [8,2,4] with maximum absolute diff |8-2| = 6 > 4.\n [8,2,4,7] with maximum absolute diff |8-2| = 6 > 4.\n [2] with maximum absolute diff |2-2| = 0 <= 4.\n [2,4] with maximum absolute diff |2-4| = 2 <= 4.\n [2,4,7] with maximum absolute diff |2-7| = 5 > 4.\n [4] with maximum absolute diff |4-4| = 0 <= 4.\n [4,7] with maximum absolute diff |4-7| = 3 <= 4.\n [7] with maximum absolute diff |7-7| = 0 <= 4.\n Therefore, the size of the longest subarray is 2.\n \n Example 2:\n \n >>> longestSubarray(nums = [10,1,2,4,7,2], limit = 5)\n >>> 4\n Explanation: The subarray [2,4,7,2] is the longest since the maximum absolute diff is |2-7| = 5 <= 5.\n \n Example 3:\n \n >>> longestSubarray(nums = [4,2,2,2,4,4,2,2], limit = 0)\n >>> 3\n \"\"\"\n"}
{"task_id": "find-the-kth-smallest-sum-of-a-matrix-with-sorted-rows", "prompt": "def kthSmallest(mat: List[List[int]], k: int) -> int:\n \"\"\"\n You are given an m x n matrix mat that has its rows sorted in non-decreasing order and an integer k.\n You are allowed to choose exactly one element from each row to form an array.\n Return the kth smallest array sum among all possible arrays.\n \n Example 1:\n \n >>> kthSmallest(mat = [[1,3,11],[2,4,6]], k = 5)\n >>> 7\n Explanation: Choosing one element from each row, the first k smallest sum are:\n [1,2], [1,4], [3,2], [3,4], [1,6]. Where the 5th sum is 7.\n \n Example 2:\n \n >>> kthSmallest(mat = [[1,3,11],[2,4,6]], k = 9)\n >>> 17\n \n Example 3:\n \n >>> kthSmallest(mat = [[1,10,10],[1,4,5],[2,3,6]], k = 7)\n >>> 9\n Explanation: Choosing one element from each row, the first k smallest sum are:\n [1,1,2], [1,1,3], [1,4,2], [1,4,3], [1,1,6], [1,5,2], [1,5,3]. Where the 7th sum is 9.\n \"\"\"\n"}
{"task_id": "build-an-array-with-stack-operations", "prompt": "def buildArray(target: List[int], n: int) -> List[str]:\n \"\"\"\n You are given an integer array target and an integer n.\n You have an empty stack with the two following operations:\n \n \"Push\": pushes an integer to the top of the stack.\n \"Pop\": removes the integer on the top of the stack.\n \n You also have a stream of the integers in the range [1, n].\n Use the two stack operations to make the numbers in the stack (from the bottom to the top) equal to target. You should follow the following rules:\n \n If the stream of the integers is not empty, pick the next integer from the stream and push it to the top of the stack.\n If the stack is not empty, pop the integer at the top of the stack.\n If, at any moment, the elements in the stack (from the bottom to the top) are equal to target, do not read new integers from the stream and do not do more operations on the stack.\n \n Return the stack operations needed to build target following the mentioned rules. If there are multiple valid answers, return any of them.\n \n Example 1:\n \n >>> buildArray(target = [1,3], n = 3)\n >>> [\"Push\",\"Push\",\"Pop\",\"Push\"]\n Explanation: Initially the stack s is empty. The last element is the top of the stack.\n Read 1 from the stream and push it to the stack. s = [1].\n Read 2 from the stream and push it to the stack. s = [1,2].\n Pop the integer on the top of the stack. s = [1].\n Read 3 from the stream and push it to the stack. s = [1,3].\n \n Example 2:\n \n >>> buildArray(target = [1,2,3], n = 3)\n >>> [\"Push\",\"Push\",\"Push\"]\n Explanation: Initially the stack s is empty. The last element is the top of the stack.\n Read 1 from the stream and push it to the stack. s = [1].\n Read 2 from the stream and push it to the stack. s = [1,2].\n Read 3 from the stream and push it to the stack. s = [1,2,3].\n \n Example 3:\n \n >>> buildArray(target = [1,2], n = 4)\n >>> [\"Push\",\"Push\"]\n Explanation: Initially the stack s is empty. The last element is the top of the stack.\n Read 1 from the stream and push it to the stack. s = [1].\n Read 2 from the stream and push it to the stack. s = [1,2].\n Since the stack (from the bottom to the top) is equal to target, we stop the stack operations.\n The answers that read integer 3 from the stream are not accepted.\n \"\"\"\n"}
{"task_id": "count-triplets-that-can-form-two-arrays-of-equal-xor", "prompt": "def countTriplets(arr: List[int]) -> int:\n \"\"\"\n Given an array of integers arr.\n We want to select three indices i, j and k where (0 <= i < j <= k < arr.length).\n Let's define a and b as follows:\n \n a = arr[i] ^ arr[i + 1] ^ ... ^ arr[j - 1]\n b = arr[j] ^ arr[j + 1] ^ ... ^ arr[k]\n \n Note that ^ denotes the bitwise-xor operation.\n Return the number of triplets (i, j and k) Where a == b.\n \n Example 1:\n \n >>> countTriplets(arr = [2,3,1,6,7])\n >>> 4\n Explanation: The triplets are (0,1,2), (0,2,2), (2,3,4) and (2,4,4)\n \n Example 2:\n \n >>> countTriplets(arr = [1,1,1,1,1])\n >>> 10\n \"\"\"\n"}
{"task_id": "number-of-ways-of-cutting-a-pizza", "prompt": "def ways(pizza: List[str], k: int) -> int:\n \"\"\"\n Given a rectangular pizza represented as a rows x cols\u00a0matrix containing the following characters: 'A' (an apple) and '.' (empty cell) and given the integer k. You have to cut the pizza into k pieces using k-1 cuts.\n For each cut you choose the direction: vertical or horizontal, then you choose a cut position at the cell boundary and cut the pizza into two pieces. If you cut the pizza vertically, give the left part of the pizza to a person. If you cut the pizza horizontally, give the upper part of the pizza to a person. Give the last piece of pizza to the last person.\n Return the number of ways of cutting the pizza such that each piece contains at least one apple.\u00a0Since the answer can be a huge number, return this modulo 10^9 + 7.\n \n Example 1:\n \n \n >>> ways(pizza = [\"A..\",\"AAA\",\"...\"], k = 3)\n >>> 3\n Explanation: The figure above shows the three ways to cut the pizza. Note that pieces must contain at least one apple.\n \n Example 2:\n \n >>> ways(pizza = [\"A..\",\"AA.\",\"...\"], k = 3)\n >>> 1\n \n Example 3:\n \n >>> ways(pizza = [\"A..\",\"A..\",\"...\"], k = 1)\n >>> 1\n \"\"\"\n"}
{"task_id": "consecutive-characters", "prompt": "def maxPower(s: str) -> int:\n \"\"\"\n The power of the string is the maximum length of a non-empty substring that contains only one unique character.\n Given a string s, return the power of s.\n \n Example 1:\n \n >>> maxPower(s = \"leetcode\")\n >>> 2\n Explanation: The substring \"ee\" is of length 2 with the character 'e' only.\n \n Example 2:\n \n >>> maxPower(s = \"abbcccddddeeeeedcba\")\n >>> 5\n Explanation: The substring \"eeeee\" is of length 5 with the character 'e' only.\n \"\"\"\n"}
{"task_id": "simplified-fractions", "prompt": "def simplifiedFractions(n: int) -> List[str]:\n \"\"\"\n Given an integer n, return a list of all simplified fractions between 0 and 1 (exclusive) such that the denominator is less-than-or-equal-to n. You can return the answer in any order.\n \n Example 1:\n \n >>> simplifiedFractions(n = 2)\n >>> [\"1/2\"]\n Explanation: \"1/2\" is the only unique fraction with a denominator less-than-or-equal-to 2.\n \n Example 2:\n \n >>> simplifiedFractions(n = 3)\n >>> [\"1/2\",\"1/3\",\"2/3\"]\n \n Example 3:\n \n >>> simplifiedFractions(n = 4)\n >>> [\"1/2\",\"1/3\",\"1/4\",\"2/3\",\"3/4\"]\n Explanation: \"2/4\" is not a simplified fraction because it can be simplified to \"1/2\".\n \"\"\"\n"}
{"task_id": "count-good-nodes-in-binary-tree", "prompt": "# class TreeNode:\n# def __init__(val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def goodNodes(root: Optional[TreeNode]) -> int:\n \"\"\"\n Given a binary tree root, a node X in the tree is named\u00a0good if in the path from root to X there are no nodes with a value greater than X.\\r\n \\r\n Return the number of good nodes in the binary tree.\\r\n \\r\n \u00a0\\r\n Example 1:\\r\n \\r\n \\r\n \\r\n \\r\n >>> __init__(root = [3,1,4,3,null,1,5]\\r)\n >>> 4\\r\n Explanation: Nodes in blue are good.\\r\n Root Node (3) is always a good node.\\r\n Node 4 -> (3,4) is the maximum value in the path starting from the root.\\r\n Node 5 -> (3,4,5) is the maximum value in the path\\r\n Node 3 -> (3,1,3) is the maximum value in the path.\\r\n \\r\n Example 2:\\r\n \\r\n \\r\n \\r\n \\r\n >>> __init__(root = [3,3,null,4,2]\\r)\n >>> 3\\r\n Explanation: Node 2 -> (3, 3, 2) is not good, because \"3\" is higher than it.\\r\n \\r\n Example 3:\\r\n \\r\n \\r\n >>> __init__(root = [1]\\r)\n >>> 1\\r\n Explanation: Root is considered as good.\\r\n \\r\n \u00a0\\r\n \"\"\"\n"}
{"task_id": "form-largest-integer-with-digits-that-add-up-to-target", "prompt": "def largestNumber(cost: List[int], target: int) -> str:\n \"\"\"\n Given an array of integers cost and an integer target, return the maximum integer you can paint under the following rules:\n \n The cost of painting a digit (i + 1) is given by cost[i] (0-indexed).\n The total cost used must be equal to target.\n The integer does not have 0 digits.\n \n Since the answer may be very large, return it as a string. If there is no way to paint any integer given the condition, return \"0\".\n \n Example 1:\n \n >>> largestNumber(cost = [4,3,2,5,6,7,2,5,5], target = 9)\n >>> \"7772\"\n Explanation: The cost to paint the digit '7' is 2, and the digit '2' is 3. Then cost(\"7772\") = 2*3+ 3*1 = 9. You could also paint \"977\", but \"7772\" is the largest number.\n Digit cost\n 1 -> 4\n 2 -> 3\n 3 -> 2\n 4 -> 5\n 5 -> 6\n 6 -> 7\n 7 -> 2\n 8 -> 5\n 9 -> 5\n \n Example 2:\n \n >>> largestNumber(cost = [7,6,5,5,5,6,8,7,8], target = 12)\n >>> \"85\"\n Explanation: The cost to paint the digit '8' is 7, and the digit '5' is 5. Then cost(\"85\") = 7 + 5 = 12.\n \n Example 3:\n \n >>> largestNumber(cost = [2,4,6,2,4,6,4,4,4], target = 5)\n >>> \"0\"\n Explanation: It is impossible to paint any integer with total cost equal to target.\n \"\"\"\n"}
{"task_id": "number-of-students-doing-homework-at-a-given-time", "prompt": "def busyStudent(startTime: List[int], endTime: List[int], queryTime: int) -> int:\n \"\"\"\n Given two integer arrays startTime and endTime and given an integer queryTime.\n The ith student started doing their homework at the time startTime[i] and finished it at time endTime[i].\n Return the number of students doing their homework at time queryTime. More formally, return the number of students where queryTime lays in the interval [startTime[i], endTime[i]] inclusive.\n \n Example 1:\n \n >>> busyStudent(startTime = [1,2,3], endTime = [3,2,7], queryTime = 4)\n >>> 1\n Explanation: We have 3 students where:\n The first student started doing homework at time 1 and finished at time 3 and wasn't doing anything at time 4.\n The second student started doing homework at time 2 and finished at time 2 and also wasn't doing anything at time 4.\n The third student started doing homework at time 3 and finished at time 7 and was the only student doing homework at time 4.\n \n Example 2:\n \n >>> busyStudent(startTime = [4], endTime = [4], queryTime = 4)\n >>> 1\n Explanation: The only student was doing their homework at the queryTime.\n \"\"\"\n"}
{"task_id": "rearrange-words-in-a-sentence", "prompt": "def arrangeWords(text: str) -> str:\n \"\"\"\n Given a sentence\u00a0text (A\u00a0sentence\u00a0is a string of space-separated words) in the following format:\n \n First letter is in upper case.\n Each word in text are separated by a single space.\n \n Your task is to rearrange the words in text such that\u00a0all words are rearranged in an increasing order of their lengths. If two words have the same length, arrange them in their original order.\n Return the new text\u00a0following the format shown above.\n \n Example 1:\n \n >>> arrangeWords(text = \"Leetcode is cool\")\n >>> \"Is cool leetcode\"\n Explanation: There are 3 words, \"Leetcode\" of length 8, \"is\" of length 2 and \"cool\" of length 4.\n Output is ordered by length and the new first word starts with capital letter.\n \n Example 2:\n \n >>> arrangeWords(text = \"Keep calm and code on\")\n >>> \"On and keep calm code\"\n Explanation: Output is ordered as follows:\n \"On\" 2 letters.\n \"and\" 3 letters.\n \"keep\" 4 letters in case of tie order by position in original text.\n \"calm\" 4 letters.\n \"code\" 4 letters.\n \n Example 3:\n \n >>> arrangeWords(text = \"To be or not to be\")\n >>> \"To be or to be not\"\n \"\"\"\n"}
{"task_id": "people-whose-list-of-favorite-companies-is-not-a-subset-of-another-list", "prompt": "def peopleIndexes(favoriteCompanies: List[List[str]]) -> List[int]:\n \"\"\"\n Given the array favoriteCompanies where favoriteCompanies[i] is the list of favorites companies for the ith person (indexed from 0).\n Return the indices of people whose list of favorite companies is not a subset of any other list of favorites companies. You must return the indices in increasing order.\n \n Example 1:\n \n >>> peopleIndexes(favoriteCompanies = [[\"leetcode\",\"google\",\"facebook\"],[\"google\",\"microsoft\"],[\"google\",\"facebook\"],[\"google\"],[\"amazon\"]])\n >>> [0,1,4]\n Explanation:\n Person with index=2 has favoriteCompanies[2]=[\"google\",\"facebook\"] which is a subset of favoriteCompanies[0]=[\"leetcode\",\"google\",\"facebook\"] corresponding to the person with index 0.\n Person with index=3 has favoriteCompanies[3]=[\"google\"] which is a subset of favoriteCompanies[0]=[\"leetcode\",\"google\",\"facebook\"] and favoriteCompanies[1]=[\"google\",\"microsoft\"].\n Other lists of favorite companies are not a subset of another list, therefore, the answer is [0,1,4].\n \n Example 2:\n \n >>> peopleIndexes(favoriteCompanies = [[\"leetcode\",\"google\",\"facebook\"],[\"leetcode\",\"amazon\"],[\"facebook\",\"google\"]])\n >>> [0,1]\n Explanation: In this case favoriteCompanies[2]=[\"facebook\",\"google\"] is a subset of favoriteCompanies[0]=[\"leetcode\",\"google\",\"facebook\"], therefore, the answer is [0,1].\n \n Example 3:\n \n >>> peopleIndexes(favoriteCompanies = [[\"leetcode\"],[\"google\"],[\"facebook\"],[\"amazon\"]])\n >>> [0,1,2,3]\n \"\"\"\n"}
{"task_id": "maximum-number-of-darts-inside-of-a-circular-dartboard", "prompt": "def numPoints(darts: List[List[int]], r: int) -> int:\n \"\"\"\n Alice is throwing n darts on a very large wall. You are given an array darts where darts[i] = [xi, yi] is the position of the ith dart that Alice threw on the wall.\n Bob knows the positions of the n darts on the wall. He wants to place a dartboard of radius r on the wall so that the maximum number of darts that Alice throws lie\u00a0on the dartboard.\n Given the integer r, return the maximum number of darts that can lie on the dartboard.\n \n Example 1:\n \n \n >>> numPoints(darts = [[-2,0],[2,0],[0,2],[0,-2]], r = 2)\n >>> 4\n Explanation: Circle dartboard with center in (0,0) and radius = 2 contain all points.\n \n Example 2:\n \n \n >>> numPoints(darts = [[-3,0],[3,0],[2,6],[5,4],[0,9],[7,8]], r = 5)\n >>> 5\n Explanation: Circle dartboard with center in (0,4) and radius = 5 contain all points except the point (7,8).\n \"\"\"\n"}
{"task_id": "check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence", "prompt": "def isPrefixOfWord(sentence: str, searchWord: str) -> int:\n \"\"\"\n Given a sentence that consists of some words separated by a single space, and a searchWord, check if searchWord is a prefix of any word in sentence.\n Return the index of the word in sentence (1-indexed) where searchWord is a prefix of this word. If searchWord is a prefix of more than one word, return the index of the first word (minimum index). If there is no such word return -1.\n A prefix of a string s is any leading contiguous substring of s.\n \n Example 1:\n \n >>> isPrefixOfWord(sentence = \"i love eating burger\", searchWord = \"burg\")\n >>> 4\n Explanation: \"burg\" is prefix of \"burger\" which is the 4th word in the sentence.\n \n Example 2:\n \n >>> isPrefixOfWord(sentence = \"this problem is an easy problem\", searchWord = \"pro\")\n >>> 2\n Explanation: \"pro\" is prefix of \"problem\" which is the 2nd and the 6th word in the sentence, but we return 2 as it's the minimal index.\n \n Example 3:\n \n >>> isPrefixOfWord(sentence = \"i am tired\", searchWord = \"you\")\n >>> -1\n Explanation: \"you\" is not a prefix of any word in the sentence.\n \"\"\"\n"}
{"task_id": "maximum-number-of-vowels-in-a-substring-of-given-length", "prompt": "def maxVowels(s: str, k: int) -> int:\n \"\"\"\n Given a string s and an integer k, return the maximum number of vowel letters in any substring of s with length k.\n Vowel letters in English are 'a', 'e', 'i', 'o', and 'u'.\n \n Example 1:\n \n >>> maxVowels(s = \"abciiidef\", k = 3)\n >>> 3\n Explanation: The substring \"iii\" contains 3 vowel letters.\n \n Example 2:\n \n >>> maxVowels(s = \"aeiou\", k = 2)\n >>> 2\n Explanation: Any substring of length 2 contains 2 vowels.\n \n Example 3:\n \n >>> maxVowels(s = \"leetcode\", k = 3)\n >>> 2\n Explanation: \"lee\", \"eet\" and \"ode\" contain 2 vowels.\n \"\"\"\n"}
{"task_id": "max-dot-product-of-two-subsequences", "prompt": "def maxDotProduct(nums1: List[int], nums2: List[int]) -> int:\n \"\"\"\n Given two arrays nums1\u00a0and nums2.\n Return the maximum dot product\u00a0between\u00a0non-empty subsequences of nums1 and nums2 with the same length.\n A subsequence of a array is a new array which is formed from the original array by deleting some (can be none) of the characters without disturbing the relative positions of the remaining characters. (ie,\u00a0[2,3,5]\u00a0is a subsequence of\u00a0[1,2,3,4,5]\u00a0while [1,5,3]\u00a0is not).\n \n Example 1:\n \n >>> maxDotProduct(nums1 = [2,1,-2,5], nums2 = [3,0,-6])\n >>> 18\n Explanation: Take subsequence [2,-2] from nums1 and subsequence [3,-6] from nums2.\n Their dot product is (2*3 + (-2)*(-6)) = 18.\n Example 2:\n \n >>> maxDotProduct(nums1 = [3,-2], nums2 = [2,-6,7])\n >>> 21\n Explanation: Take subsequence [3] from nums1 and subsequence [7] from nums2.\n Their dot product is (3*7) = 21.\n Example 3:\n \n >>> maxDotProduct(nums1 = [-1,-1], nums2 = [1,1])\n >>> -1\n Explanation: Take subsequence [-1] from nums1 and subsequence [1] from nums2.\n Their dot product is -1.\n \"\"\"\n"}
{"task_id": "make-two-arrays-equal-by-reversing-subarrays", "prompt": "def canBeEqual(target: List[int], arr: List[int]) -> bool:\n \"\"\"\n You are given two integer arrays of equal length target and arr. In one step, you can select any non-empty subarray of arr and reverse it. You are allowed to make any number of steps.\n Return true if you can make arr equal to target\u00a0or false otherwise.\n \n Example 1:\n \n >>> canBeEqual(target = [1,2,3,4], arr = [2,4,1,3])\n >>> true\n Explanation: You can follow the next steps to convert arr to target:\n 1- Reverse subarray [2,4,1], arr becomes [1,4,2,3]\n 2- Reverse subarray [4,2], arr becomes [1,2,4,3]\n 3- Reverse subarray [4,3], arr becomes [1,2,3,4]\n There are multiple ways to convert arr to target, this is not the only way to do so.\n \n Example 2:\n \n >>> canBeEqual(target = [7], arr = [7])\n >>> true\n Explanation: arr is equal to target without any reverses.\n \n Example 3:\n \n >>> canBeEqual(target = [3,7,9], arr = [3,7,11])\n >>> false\n Explanation: arr does not have value 9 and it can never be converted to target.\n \"\"\"\n"}
{"task_id": "check-if-a-string-contains-all-binary-codes-of-size-k", "prompt": "def hasAllCodes(s: str, k: int) -> bool:\n \"\"\"\n Given a binary string s and an integer k, return true if every binary code of length k is a substring of s. Otherwise, return false.\n \n Example 1:\n \n >>> hasAllCodes(s = \"00110110\", k = 2)\n >>> true\n Explanation: The binary codes of length 2 are \"00\", \"01\", \"10\" and \"11\". They can be all found as substrings at indices 0, 1, 3 and 2 respectively.\n \n Example 2:\n \n >>> hasAllCodes(s = \"0110\", k = 1)\n >>> true\n Explanation: The binary codes of length 1 are \"0\" and \"1\", it is clear that both exist as a substring.\n \n Example 3:\n \n >>> hasAllCodes(s = \"0110\", k = 2)\n >>> false\n Explanation: The binary code \"00\" is of length 2 and does not exist in the array.\n \"\"\"\n"}
{"task_id": "course-schedule-iv", "prompt": "def checkIfPrerequisite(numCourses: int, prerequisites: List[List[int]], queries: List[List[int]]) -> List[bool]:\n \"\"\"\n There are a total of numCourses courses you have to take, labeled from 0 to numCourses - 1. You are given an array prerequisites where prerequisites[i] = [ai, bi] indicates that you must take course ai first if you want to take course bi.\n \n For example, the pair [0, 1] indicates that you have to take course 0 before you can take course 1.\n \n Prerequisites can also be indirect. If course a is a prerequisite of course b, and course b is a prerequisite of course c, then course a is a prerequisite of course c.\n You are also given an array queries where queries[j] = [uj, vj]. For the jth query, you should answer whether course uj is a prerequisite of course vj or not.\n Return a boolean array answer, where answer[j] is the answer to the jth query.\n \n Example 1:\n \n \n >>> checkIfPrerequisite(numCourses = 2, prerequisites = [[1,0]], queries = [[0,1],[1,0]])\n >>> [false,true]\n Explanation: The pair [1, 0] indicates that you have to take course 1 before you can take course 0.\n Course 0 is not a prerequisite of course 1, but the opposite is true.\n \n Example 2:\n \n >>> checkIfPrerequisite(numCourses = 2, prerequisites = [], queries = [[1,0],[0,1]])\n >>> [false,false]\n Explanation: There are no prerequisites, and each course is independent.\n \n Example 3:\n \n \n >>> checkIfPrerequisite(numCourses = 3, prerequisites = [[1,2],[1,0],[2,0]], queries = [[1,0],[1,2]])\n >>> [true,true]\n \"\"\"\n"}
{"task_id": "cherry-pickup-ii", "prompt": "def cherryPickup(grid: List[List[int]]) -> int:\n \"\"\"\n You are given a rows x cols matrix grid representing a field of cherries where grid[i][j] represents the number of cherries that you can collect from the (i, j) cell.\n You have two robots that can collect cherries for you:\n \n Robot #1 is located at the top-left corner (0, 0), and\n Robot #2 is located at the top-right corner (0, cols - 1).\n \n Return the maximum number of cherries collection using both robots by following the rules below:\n \n From a cell (i, j), robots can move to cell (i + 1, j - 1), (i + 1, j), or (i + 1, j + 1).\n When any robot passes through a cell, It picks up all cherries, and the cell becomes an empty cell.\n When both robots stay in the same cell, only one takes the cherries.\n Both robots cannot move outside of the grid at any moment.\n Both robots should reach the bottom row in grid.\n \n \n Example 1:\n \n \n >>> cherryPickup(grid = [[3,1,1],[2,5,1],[1,5,5],[2,1,1]])\n >>> 24\n Explanation: Path of robot #1 and #2 are described in color green and blue respectively.\n Cherries taken by Robot #1, (3 + 2 + 5 + 2) = 12.\n Cherries taken by Robot #2, (1 + 5 + 5 + 1) = 12.\n Total of cherries: 12 + 12 = 24.\n \n Example 2:\n \n \n >>> cherryPickup(grid = [[1,0,0,0,0,0,1],[2,0,0,0,0,3,0],[2,0,9,0,0,0,0],[0,3,0,5,4,0,0],[1,0,2,3,0,0,6]])\n >>> 28\n Explanation: Path of robot #1 and #2 are described in color green and blue respectively.\n Cherries taken by Robot #1, (1 + 9 + 5 + 2) = 17.\n Cherries taken by Robot #2, (1 + 3 + 4 + 3) = 11.\n Total of cherries: 17 + 11 = 28.\n \"\"\"\n"}
{"task_id": "maximum-product-of-two-elements-in-an-array", "prompt": "def maxProduct(nums: List[int]) -> int:\n \"\"\"\n Given the array of integers nums, you will choose two different indices i and j of that array. Return the maximum value of (nums[i]-1)*(nums[j]-1).\n \n Example 1:\n \n >>> maxProduct(nums = [3,4,5,2])\n >>> 12\n Explanation: If you choose the indices i=1 and j=2 (indexed from 0), you will get the maximum value, that is, (nums[1]-1)*(nums[2]-1) = (4-1)*(5-1) = 3*4 = 12.\n \n Example 2:\n \n >>> maxProduct(nums = [1,5,4,5])\n >>> 16\n Explanation: Choosing the indices i=1 and j=3 (indexed from 0), you will get the maximum value of (5-1)*(5-1) = 16.\n \n Example 3:\n \n >>> maxProduct(nums = [3,7])\n >>> 12\n \"\"\"\n"}
{"task_id": "maximum-area-of-a-piece-of-cake-after-horizontal-and-vertical-cuts", "prompt": "def maxArea(h: int, w: int, horizontalCuts: List[int], verticalCuts: List[int]) -> int:\n \"\"\"\n You are given a rectangular cake of size h x w and two arrays of integers horizontalCuts and verticalCuts where:\n \n horizontalCuts[i] is the distance from the top of the rectangular cake to the ith horizontal cut and similarly, and\n verticalCuts[j] is the distance from the left of the rectangular cake to the jth vertical cut.\n \n Return the maximum area of a piece of cake after you cut at each horizontal and vertical position provided in the arrays horizontalCuts and verticalCuts. Since the answer can be a large number, return this modulo 109 + 7.\n \n Example 1:\n \n \n >>> maxArea(h = 5, w = 4, horizontalCuts = [1,2,4], verticalCuts = [1,3])\n >>> 4\n Explanation: The figure above represents the given rectangular cake. Red lines are the horizontal and vertical cuts. After you cut the cake, the green piece of cake has the maximum area.\n \n Example 2:\n \n \n >>> maxArea(h = 5, w = 4, horizontalCuts = [3,1], verticalCuts = [1])\n >>> 6\n Explanation: The figure above represents the given rectangular cake. Red lines are the horizontal and vertical cuts. After you cut the cake, the green and yellow pieces of cake have the maximum area.\n \n Example 3:\n \n >>> maxArea(h = 5, w = 4, horizontalCuts = [3], verticalCuts = [3])\n >>> 9\n \"\"\"\n"}
{"task_id": "reorder-routes-to-make-all-paths-lead-to-the-city-zero", "prompt": "def minReorder(n: int, connections: List[List[int]]) -> int:\n \"\"\"\n There are n cities numbered from 0 to n - 1 and n - 1 roads such that there is only one way to travel between two different cities (this network form a tree). Last year, The ministry of transport decided to orient the roads in one direction because they are too narrow.\n Roads are represented by connections where connections[i] = [ai, bi] represents a road from city ai to city bi.\n This year, there will be a big event in the capital (city 0), and many people want to travel to this city.\n Your task consists of reorienting some roads such that each city can visit the city 0. Return the minimum number of edges changed.\n It's guaranteed that each city can reach city 0 after reorder.\n \n Example 1:\n \n \n >>> minReorder(n = 6, connections = [[0,1],[1,3],[2,3],[4,0],[4,5]])\n >>> 3\n Explanation: Change the direction of edges show in red such that each node can reach the node 0 (capital).\n \n Example 2:\n \n \n >>> minReorder(n = 5, connections = [[1,0],[1,2],[3,2],[3,4]])\n >>> 2\n Explanation: Change the direction of edges show in red such that each node can reach the node 0 (capital).\n \n Example 3:\n \n >>> minReorder(n = 3, connections = [[1,0],[2,0]])\n >>> 0\n \"\"\"\n"}
{"task_id": "probability-of-a-two-boxes-having-the-same-number-of-distinct-balls", "prompt": "def getProbability(balls: List[int]) -> float:\n \"\"\"\n Given 2n balls of k distinct colors. You will be given an integer array balls of size k where balls[i] is the number of balls of color i.\n All the balls will be shuffled uniformly at random, then we will distribute the first n balls to the first box and the remaining n balls to the other box (Please read the explanation of the second example carefully).\n Please note that the two boxes are considered different. For example, if we have two balls of colors a and b, and two boxes [] and (), then the distribution [a] (b) is considered different than the distribution [b] (a) (Please read the explanation of the first example carefully).\n Return the probability that the two boxes have the same number of distinct balls. Answers within 10-5 of the actual value will be accepted as correct.\n \n Example 1:\n \n >>> getProbability(balls = [1,1])\n >>> 1.00000\n Explanation: Only 2 ways to divide the balls equally:\n - A ball of color 1 to box 1 and a ball of color 2 to box 2\n - A ball of color 2 to box 1 and a ball of color 1 to box 2\n In both ways, the number of distinct colors in each box is equal. The probability is 2/2 = 1\n \n Example 2:\n \n >>> getProbability(balls = [2,1,1])\n >>> 0.66667\n Explanation: We have the set of balls [1, 1, 2, 3]\n This set of balls will be shuffled randomly and we may have one of the 12 distinct shuffles with equal probability (i.e. 1/12):\n [1,1 / 2,3], [1,1 / 3,2], [1,2 / 1,3], [1,2 / 3,1], [1,3 / 1,2], [1,3 / 2,1], [2,1 / 1,3], [2,1 / 3,1], [2,3 / 1,1], [3,1 / 1,2], [3,1 / 2,1], [3,2 / 1,1]\n After that, we add the first two balls to the first box and the second two balls to the second box.\n We can see that 8 of these 12 possible random distributions have the same number of distinct colors of balls in each box.\n Probability is 8/12 = 0.66667\n \n Example 3:\n \n >>> getProbability(balls = [1,2,1,2])\n >>> 0.60000\n Explanation: The set of balls is [1, 2, 2, 3, 4, 4]. It is hard to display all the 180 possible random shuffles of this set but it is easy to check that 108 of them will have the same number of distinct colors in each box.\n Probability = 108 / 180 = 0.6\n \"\"\"\n"}
{"task_id": "find-all-the-lonely-nodes", "prompt": "# class TreeNode:\n# def __init__(val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def getLonelyNodes(root: Optional[TreeNode]) -> List[int]:\n \"\"\"\n In a binary tree, a lonely node is a node that is the only child of its parent node. The root of the tree is not lonely because it does not have a parent node.\n Given the root of a binary tree, return an array containing the values of all lonely nodes in the tree. Return the list in any order.\n \n Example 1:\n \n \n >>> __init__(root = [1,2,3,null,4])\n >>> [4]\n Explanation: Light blue node is the only lonely node.\n Node 1 is the root and is not lonely.\n Nodes 2 and 3 have the same parent and are not lonely.\n \n Example 2:\n \n \n >>> __init__(root = [7,1,4,6,null,5,3,null,null,null,null,null,2])\n >>> [6,2]\n Explanation: Light blue nodes are lonely nodes.\n Please remember that order doesn't matter, [2,6] is also an acceptable answer.\n \n Example 3:\n \n \n \n >>> __init__(root = [11,99,88,77,null,null,66,55,null,null,44,33,null,null,22])\n >>> [77,55,33,66,44,22]\n Explanation: Nodes 99 and 88 share the same parent. Node 11 is the root.\n All other nodes are lonely.\n \"\"\"\n"}
{"task_id": "shuffle-the-array", "prompt": "def shuffle(nums: List[int], n: int) -> List[int]:\n \"\"\"\n Given the array nums consisting of 2n elements in the form [x1,x2,...,xn,y1,y2,...,yn].\\r\n \\r\n Return the array in the form [x1,y1,x2,y2,...,xn,yn].\\r\n \\r\n \u00a0\\r\n Example 1:\\r\n \\r\n \\r\n >>> shuffle(nums = [2,5,1,3,4,7], n = 3\\r)\n >>> [2,3,5,4,1,7] \\r\n Explanation: Since x1=2, x2=5, x3=1, y1=3, y2=4, y3=7 then the answer is [2,3,5,4,1,7].\\r\n \\r\n \\r\n Example 2:\\r\n \\r\n \\r\n >>> shuffle(nums = [1,2,3,4,4,3,2,1], n = 4\\r)\n >>> [1,4,2,3,3,2,4,1]\\r\n \\r\n \\r\n Example 3:\\r\n \\r\n \\r\n >>> shuffle(nums = [1,1,2,2], n = 2\\r)\n >>> [1,2,1,2]\\r\n \\r\n \\r\n \u00a0\\r\n \"\"\"\n"}
{"task_id": "the-k-strongest-values-in-an-array", "prompt": "def getStrongest(arr: List[int], k: int) -> List[int]:\n \"\"\"\n Given an array of integers arr and an integer k.\n A value arr[i] is said to be stronger than a value arr[j] if |arr[i] - m| > |arr[j] - m| where m is the centre of the array.\n If |arr[i] - m| == |arr[j] - m|, then arr[i] is said to be stronger than arr[j] if arr[i] > arr[j].\n Return a list of the strongest k values in the array. return the answer in any arbitrary order.\n The centre is the middle value in an ordered integer list. More formally, if the length of the list is n, the centre is the element in position ((n - 1) / 2) in the sorted list (0-indexed).\n \n For arr = [6, -3, 7, 2, 11], n = 5 and the centre is obtained by sorting the array arr = [-3, 2, 6, 7, 11] and the centre is arr[m] where m = ((5 - 1) / 2) = 2. The centre is 6.\n For arr = [-7, 22, 17,\u20093], n = 4 and the centre is obtained by sorting the array arr = [-7, 3, 17, 22] and the centre is arr[m] where m = ((4 - 1) / 2) = 1. The centre is 3.\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n Example 1:\n \n >>> getStrongest(arr = [1,2,3,4,5], k = 2)\n >>> [5,1]\n Explanation: Centre is 3, the elements of the array sorted by the strongest are [5,1,4,2,3]. The strongest 2 elements are [5, 1]. [1, 5] is also accepted answer.\n Please note that although |5 - 3| == |1 - 3| but 5 is stronger than 1 because 5 > 1.\n \n Example 2:\n \n >>> getStrongest(arr = [1,1,3,5,5], k = 2)\n >>> [5,5]\n Explanation: Centre is 3, the elements of the array sorted by the strongest are [5,5,1,1,3]. The strongest 2 elements are [5, 5].\n \n Example 3:\n \n >>> getStrongest(arr = [6,7,11,7,6,8], k = 5)\n >>> [11,8,6,6,7]\n Explanation: Centre is 7, the elements of the array sorted by the strongest are [11,8,6,6,7,7].\n Any permutation of [11,8,6,6,7] is accepted.\n \"\"\"\n"}
{"task_id": "paint-house-iii", "prompt": "def minCost(houses: List[int], cost: List[List[int]], m: int, n: int, target: int) -> int:\n \"\"\"\n There is a row of m houses in a small city, each house must be painted with one of the n colors (labeled from 1 to n), some houses that have been painted last summer should not be painted again.\n A neighborhood is a maximal group of continuous houses that are painted with the same color.\n \n For example: houses = [1,2,2,3,3,2,1,1] contains 5 neighborhoods [{1}, {2,2}, {3,3}, {2}, {1,1}].\n \n Given an array houses, an m x n matrix cost and an integer target where:\n \n houses[i]: is the color of the house i, and 0 if the house is not painted yet.\n cost[i][j]: is the cost of paint the house i with the color j + 1.\n \n Return the minimum cost of painting all the remaining houses in such a way that there are exactly target neighborhoods. If it is not possible, return -1.\n \n Example 1:\n \n >>> minCost(houses = [0,0,0,0,0], cost = [[1,10],[10,1],[10,1],[1,10],[5,1]], m = 5, n = 2, target = 3)\n >>> 9\n Explanation: Paint houses of this way [1,2,2,1,1]\n This array contains target = 3 neighborhoods, [{1}, {2,2}, {1,1}].\n Cost of paint all houses (1 + 1 + 1 + 1 + 5) = 9.\n \n Example 2:\n \n >>> minCost(houses = [0,2,1,2,0], cost = [[1,10],[10,1],[10,1],[1,10],[5,1]], m = 5, n = 2, target = 3)\n >>> 11\n Explanation: Some houses are already painted, Paint the houses of this way [2,2,1,2,2]\n This array contains target = 3 neighborhoods, [{2,2}, {1}, {2,2}].\n Cost of paint the first and last house (10 + 1) = 11.\n \n Example 3:\n \n >>> minCost(houses = [3,1,2,3], cost = [[1,1,1],[1,1,1],[1,1,1],[1,1,1]], m = 4, n = 3, target = 3)\n >>> -1\n Explanation: Houses are already painted with a total of 4 neighborhoods [{3},{1},{2},{3}] different of target = 3.\n \"\"\"\n"}
{"task_id": "delete-n-nodes-after-m-nodes-of-a-linked-list", "prompt": "# class ListNode:\n# def __init__(val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution:\n def deleteNodes(head: Optional[ListNode], m: int, n: int) -> Optional[ListNode]:\n \"\"\"\n You are given the head of a linked list and two integers m and n.\n Traverse the linked list and remove some nodes in the following way:\n \n Start with the head as the current node.\n Keep the first m nodes starting with the current node.\n Remove the next n nodes\n Keep repeating steps 2 and 3 until you reach the end of the list.\n \n Return the head of the modified list after removing the mentioned nodes.\n \n Example 1:\n \n \n >>> __init__(head = [1,2,3,4,5,6,7,8,9,10,11,12,13], m = 2, n = 3)\n >>> [1,2,6,7,11,12]\n Explanation: Keep the first (m = 2) nodes starting from the head of the linked List (1 ->2) show in black nodes.\n Delete the next (n = 3) nodes (3 -> 4 -> 5) show in read nodes.\n Continue with the same procedure until reaching the tail of the Linked List.\n Head of the linked list after removing nodes is returned.\n \n Example 2:\n \n \n >>> __init__(head = [1,2,3,4,5,6,7,8,9,10,11], m = 1, n = 3)\n >>> [1,5,9]\n Explanation: Head of linked list after removing nodes is returned.\n \"\"\"\n"}
{"task_id": "final-prices-with-a-special-discount-in-a-shop", "prompt": "def finalPrices(prices: List[int]) -> List[int]:\n \"\"\"\n You are given an integer array prices where prices[i] is the price of the ith item in a shop.\n There is a special discount for items in the shop. If you buy the ith item, then you will receive a discount equivalent to prices[j] where j is the minimum index such that j > i and prices[j] <= prices[i]. Otherwise, you will not receive any discount at all.\n Return an integer array answer where answer[i] is the final price you will pay for the ith item of the shop, considering the special discount.\n \n Example 1:\n \n >>> finalPrices(prices = [8,4,6,2,3])\n >>> [4,2,4,2,3]\n Explanation:\n For item 0 with price[0]=8 you will receive a discount equivalent to prices[1]=4, therefore, the final price you will pay is 8 - 4 = 4.\n For item 1 with price[1]=4 you will receive a discount equivalent to prices[3]=2, therefore, the final price you will pay is 4 - 2 = 2.\n For item 2 with price[2]=6 you will receive a discount equivalent to prices[3]=2, therefore, the final price you will pay is 6 - 2 = 4.\n For items 3 and 4 you will not receive any discount at all.\n \n Example 2:\n \n >>> finalPrices(prices = [1,2,3,4,5])\n >>> [1,2,3,4,5]\n Explanation: In this case, for all items, you will not receive any discount at all.\n \n Example 3:\n \n >>> finalPrices(prices = [10,1,1,6])\n >>> [9,0,1,6]\n \"\"\"\n"}
{"task_id": "find-two-non-overlapping-sub-arrays-each-with-target-sum", "prompt": "def minSumOfLengths(arr: List[int], target: int) -> int:\n \"\"\"\n You are given an array of integers arr and an integer target.\n You have to find two non-overlapping sub-arrays of arr each with a sum equal target. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays is minimum.\n Return the minimum sum of the lengths of the two required sub-arrays, or return -1 if you cannot find such two sub-arrays.\n \n Example 1:\n \n >>> minSumOfLengths(arr = [3,2,2,4,3], target = 3)\n >>> 2\n Explanation: Only two sub-arrays have sum = 3 ([3] and [3]). The sum of their lengths is 2.\n \n Example 2:\n \n >>> minSumOfLengths(arr = [7,3,4,7], target = 7)\n >>> 2\n Explanation: Although we have three non-overlapping sub-arrays of sum = 7 ([7], [3,4] and [7]), but we will choose the first and third sub-arrays as the sum of their lengths is 2.\n \n Example 3:\n \n >>> minSumOfLengths(arr = [4,3,2,6,2,3,4], target = 6)\n >>> -1\n Explanation: We have only one sub-array of sum = 6.\n \"\"\"\n"}
{"task_id": "allocate-mailboxes", "prompt": "def minDistance(houses: List[int], k: int) -> int:\n \"\"\"\n Given the array houses where houses[i] is the location of the ith house along a street and an integer k, allocate k mailboxes in the street.\n Return the minimum total distance between each house and its nearest mailbox.\n The test cases are generated so that the answer fits in a 32-bit integer.\n \n Example 1:\n \n \n >>> minDistance(houses = [1,4,8,10,20], k = 3)\n >>> 5\n Explanation: Allocate mailboxes in position 3, 9 and 20.\n Minimum total distance from each houses to nearest mailboxes is |3-1| + |4-3| + |9-8| + |10-9| + |20-20| = 5\n \n Example 2:\n \n \n >>> minDistance(houses = [2,3,5,12,18], k = 2)\n >>> 9\n Explanation: Allocate mailboxes in position 3 and 14.\n Minimum total distance from each houses to nearest mailboxes is |2-3| + |3-3| + |5-3| + |12-14| + |18-14| = 9.\n \"\"\"\n"}
{"task_id": "running-sum-of-1d-array", "prompt": "def runningSum(nums: List[int]) -> List[int]:\n \"\"\"\n Given an array nums. We define a running sum of an array as\u00a0runningSum[i] = sum(nums[0]\u2026nums[i]).\n Return the running sum of nums.\n \n Example 1:\n \n >>> runningSum(nums = [1,2,3,4])\n >>> [1,3,6,10]\n Explanation: Running sum is obtained as follows: [1, 1+2, 1+2+3, 1+2+3+4].\n Example 2:\n \n >>> runningSum(nums = [1,1,1,1,1])\n >>> [1,2,3,4,5]\n Explanation: Running sum is obtained as follows: [1, 1+1, 1+1+1, 1+1+1+1, 1+1+1+1+1].\n Example 3:\n \n >>> runningSum(nums = [3,1,2,10,1])\n >>> [3,4,6,16,17]\n \"\"\"\n"}
{"task_id": "least-number-of-unique-integers-after-k-removals", "prompt": "def findLeastNumOfUniqueInts(arr: List[int], k: int) -> int:\n \"\"\"\n Given an array of integers\u00a0arr\u00a0and an integer k.\u00a0Find the least number of unique integers\u00a0after removing exactly k elements.\\r\n \\r\n \\r\n \\r\n \\r\n \u00a0\\r\n Example 1:\\r\n \\r\n \\r\n >>> findLeastNumOfUniqueInts(arr = [5,5,4], k = 1\\r)\n >>> 1\\r\n Explanation: Remove the single 4, only 5 is left.\\r\n \\r\n Example 2:\\r\n \\r\n \\r\n >>> findLeastNumOfUniqueInts(arr = [4,3,1,1,3,3,2], k = 3\\r)\n >>> 2\\r\n Explanation: Remove 4, 2 and either one of the two 1s or three 3s. 1 and 3 will be left.\\r\n \\r\n \u00a0\\r\n \"\"\"\n"}
{"task_id": "minimum-number-of-days-to-make-m-bouquets", "prompt": "def minDays(bloomDay: List[int], m: int, k: int) -> int:\n \"\"\"\n You are given an integer array bloomDay, an integer m and an integer k.\n You want to make m bouquets. To make a bouquet, you need to use k adjacent flowers from the garden.\n The garden consists of n flowers, the ith flower will bloom in the bloomDay[i] and then can be used in exactly one bouquet.\n Return the minimum number of days you need to wait to be able to make m bouquets from the garden. If it is impossible to make m bouquets return -1.\n \n Example 1:\n \n >>> minDays(bloomDay = [1,10,3,10,2], m = 3, k = 1)\n >>> 3\n Explanation: Let us see what happened in the first three days. x means flower bloomed and _ means flower did not bloom in the garden.\n We need 3 bouquets each should contain 1 flower.\n After day 1: [x, _, _, _, _] // we can only make one bouquet.\n After day 2: [x, _, _, _, x] // we can only make two bouquets.\n After day 3: [x, _, x, _, x] // we can make 3 bouquets. The answer is 3.\n \n Example 2:\n \n >>> minDays(bloomDay = [1,10,3,10,2], m = 3, k = 2)\n >>> -1\n Explanation: We need 3 bouquets each has 2 flowers, that means we need 6 flowers. We only have 5 flowers so it is impossible to get the needed bouquets and we return -1.\n \n Example 3:\n \n >>> minDays(bloomDay = [7,7,7,7,12,7,7], m = 2, k = 3)\n >>> 12\n Explanation: We need 2 bouquets each should have 3 flowers.\n Here is the garden after the 7 and 12 days:\n After day 7: [x, x, x, x, _, x, x]\n We can make one bouquet of the first three flowers that bloomed. We cannot make another bouquet from the last three flowers that bloomed because they are not adjacent.\n After day 12: [x, x, x, x, x, x, x]\n It is obvious that we can make two bouquets in different ways.\n \"\"\"\n"}
{"task_id": "clone-binary-tree-with-random-pointer", "prompt": "# class Node:\n# def __init__(val=0, left=None, right=None, random=None):\n# self.val = val\n# self.left = left\n# self.right = right\n# self.random = random\n\nclass Solution:\n def copyRandomBinaryTree(root: 'Optional[Node]') -> 'Optional[NodeCopy]':\n \"\"\"\n A binary tree is given such that each node contains an additional random pointer which could point to any node in the tree or null.\n Return a deep copy of the tree.\n The tree is represented in the same input/output way as normal binary trees where each node is represented as a pair of [val, random_index] where:\n \n val: an integer representing Node.val\n random_index: the index of the node (in the input) where the random pointer points to, or null if it does not point to any node.\n \n You will be given the tree in class Node and you should return the cloned tree in class NodeCopy. NodeCopy class is just a clone of Node class with the same attributes and constructors.\n \n Example 1:\n \n \n >>> __init__(root = [[1,null],null,[4,3],[7,0]])\n >>> [[1,null],null,[4,3],[7,0]]\n Explanation: The original binary tree is [1,null,4,7].\n The random pointer of node one is null, so it is represented as [1, null].\n The random pointer of node 4 is node 7, so it is represented as [4, 3] where 3 is the index of node 7 in the array representing the tree.\n The random pointer of node 7 is node 1, so it is represented as [7, 0] where 0 is the index of node 1 in the array representing the tree.\n \n Example 2:\n \n \n >>> __init__(root = [[1,4],null,[1,0],null,[1,5],[1,5]])\n >>> [[1,4],null,[1,0],null,[1,5],[1,5]]\n Explanation: The random pointer of a node can be the node itself.\n \n Example 3:\n \n \n >>> __init__(root = [[1,6],[2,5],[3,4],[4,3],[5,2],[6,1],[7,0]])\n >>> [[1,6],[2,5],[3,4],[4,3],[5,2],[6,1],[7,0]]\n \"\"\"\n"}
{"task_id": "xor-operation-in-an-array", "prompt": "def xorOperation(n: int, start: int) -> int:\n \"\"\"\n You are given an integer n and an integer start.\n Define an array nums where nums[i] = start + 2 * i (0-indexed) and n == nums.length.\n Return the bitwise XOR of all elements of nums.\n \n Example 1:\n \n >>> xorOperation(n = 5, start = 0)\n >>> 8\n Explanation: Array nums is equal to [0, 2, 4, 6, 8] where (0 ^ 2 ^ 4 ^ 6 ^ 8) = 8.\n Where \"^\" corresponds to bitwise XOR operator.\n \n Example 2:\n \n >>> xorOperation(n = 4, start = 3)\n >>> 8\n Explanation: Array nums is equal to [3, 5, 7, 9] where (3 ^ 5 ^ 7 ^ 9) = 8.\n \"\"\"\n"}
{"task_id": "making-file-names-unique", "prompt": "def getFolderNames(names: List[str]) -> List[str]:\n \"\"\"\n Given an array of strings names of size n. You will create n folders in your file system such that, at the ith minute, you will create a folder with the name names[i].\n Since two files cannot have the same name, if you enter a folder name that was previously used, the system will have a suffix addition to its name in the form of (k), where, k is the smallest positive integer such that the obtained name remains unique.\n Return an array of strings of length n where ans[i] is the actual name the system will assign to the ith folder when you create it.\n \n Example 1:\n \n >>> getFolderNames(names = [\"pes\",\"fifa\",\"gta\",\"pes(2019)\"])\n >>> [\"pes\",\"fifa\",\"gta\",\"pes(2019)\"]\n Explanation: Let's see how the file system creates folder names:\n \"pes\" --> not assigned before, remains \"pes\"\n \"fifa\" --> not assigned before, remains \"fifa\"\n \"gta\" --> not assigned before, remains \"gta\"\n \"pes(2019)\" --> not assigned before, remains \"pes(2019)\"\n \n Example 2:\n \n >>> getFolderNames(names = [\"gta\",\"gta(1)\",\"gta\",\"avalon\"])\n >>> [\"gta\",\"gta(1)\",\"gta(2)\",\"avalon\"]\n Explanation: Let's see how the file system creates folder names:\n \"gta\" --> not assigned before, remains \"gta\"\n \"gta(1)\" --> not assigned before, remains \"gta(1)\"\n \"gta\" --> the name is reserved, system adds (k), since \"gta(1)\" is also reserved, systems put k = 2. it becomes \"gta(2)\"\n \"avalon\" --> not assigned before, remains \"avalon\"\n \n Example 3:\n \n >>> getFolderNames(names = [\"onepiece\",\"onepiece(1)\",\"onepiece(2)\",\"onepiece(3)\",\"onepiece\"])\n >>> [\"onepiece\",\"onepiece(1)\",\"onepiece(2)\",\"onepiece(3)\",\"onepiece(4)\"]\n Explanation: When the last folder is created, the smallest positive valid k is 4, and it becomes \"onepiece(4)\".\n \"\"\"\n"}
{"task_id": "avoid-flood-in-the-city", "prompt": "def avoidFlood(rains: List[int]) -> List[int]:\n \"\"\"\n Your country has an infinite number of lakes. Initially, all the lakes are empty, but when it rains over the nth lake, the nth lake becomes full of water. If it rains over a lake that is full of water, there will be a flood. Your goal is to avoid floods in any lake.\n Given an integer array rains where:\n \n rains[i] > 0 means there will be rains over the rains[i] lake.\n rains[i] == 0 means there are no rains this day and you can choose one lake this day and dry it.\n \n Return an array ans where:\n \n ans.length == rains.length\n ans[i] == -1 if rains[i] > 0.\n ans[i] is the lake you choose to dry in the ith day if rains[i] == 0.\n \n If there are multiple valid answers return any of them. If it is impossible to avoid flood return an empty array.\n Notice that if you chose to dry a full lake, it becomes empty, but if you chose to dry an empty lake, nothing changes.\n \n Example 1:\n \n >>> avoidFlood(rains = [1,2,3,4])\n >>> [-1,-1,-1,-1]\n Explanation: After the first day full lakes are [1]\n After the second day full lakes are [1,2]\n After the third day full lakes are [1,2,3]\n After the fourth day full lakes are [1,2,3,4]\n There's no day to dry any lake and there is no flood in any lake.\n \n Example 2:\n \n >>> avoidFlood(rains = [1,2,0,0,2,1])\n >>> [-1,-1,2,1,-1,-1]\n Explanation: After the first day full lakes are [1]\n After the second day full lakes are [1,2]\n After the third day, we dry lake 2. Full lakes are [1]\n After the fourth day, we dry lake 1. There is no full lakes.\n After the fifth day, full lakes are [2].\n After the sixth day, full lakes are [1,2].\n It is easy that this scenario is flood-free. [-1,-1,1,2,-1,-1] is another acceptable scenario.\n \n Example 3:\n \n >>> avoidFlood(rains = [1,2,0,1,2])\n >>> []\n Explanation: After the second day, full lakes are [1,2]. We have to dry one lake in the third day.\n After that, it will rain over lakes [1,2]. It's easy to prove that no matter which lake you choose to dry in the 3rd day, the other one will flood.\n \"\"\"\n"}
{"task_id": "find-critical-and-pseudo-critical-edges-in-minimum-spanning-tree", "prompt": "def findCriticalAndPseudoCriticalEdges(n: int, edges: List[List[int]]) -> List[List[int]]:\n \"\"\"\n Given a weighted undirected connected graph with n\u00a0vertices numbered from 0 to n - 1,\u00a0and an array edges\u00a0where edges[i] = [ai, bi, weighti] represents a bidirectional and weighted edge between nodes\u00a0ai\u00a0and bi. A minimum spanning tree (MST) is a subset of the graph's edges that connects all vertices without cycles\u00a0and with the minimum possible total edge weight.\n Find all the critical and pseudo-critical edges in the given graph's minimum spanning tree (MST). An MST edge whose deletion from the graph would cause the MST weight to increase is called a\u00a0critical edge. On\u00a0the other hand, a pseudo-critical edge is that which can appear in some MSTs but not all.\n Note that you can return the indices of the edges in any order.\n \n Example 1:\n \n \n >>> findCriticalAndPseudoCriticalEdges(n = 5, edges = [[0,1,1],[1,2,1],[2,3,2],[0,3,2],[0,4,3],[3,4,3],[1,4,6]])\n >>> [[0,1],[2,3,4,5]]\n Explanation: The figure above describes the graph.\n The following figure shows all the possible MSTs:\n \n Notice that the two edges 0 and 1 appear in all MSTs, therefore they are critical edges, so we return them in the first list of the output.\n The edges 2, 3, 4, and 5 are only part of some MSTs, therefore they are considered pseudo-critical edges. We add them to the second list of the output.\n \n Example 2:\n \n \n >>> findCriticalAndPseudoCriticalEdges(n = 4, edges = [[0,1,1],[1,2,1],[2,3,1],[0,3,1]])\n >>> [[],[0,1,2,3]]\n Explanation: We can observe that since all 4 edges have equal weight, choosing any 3 edges from the given 4 will yield an MST. Therefore all 4 edges are pseudo-critical.\n \"\"\"\n"}
{"task_id": "average-salary-excluding-the-minimum-and-maximum-salary", "prompt": "def average(salary: List[int]) -> float:\n \"\"\"\n You are given an array of unique integers salary where salary[i] is the salary of the ith employee.\n Return the average salary of employees excluding the minimum and maximum salary. Answers within 10-5 of the actual answer will be accepted.\n \n Example 1:\n \n >>> average(salary = [4000,3000,1000,2000])\n >>> 2500.00000\n Explanation: Minimum salary and maximum salary are 1000 and 4000 respectively.\n Average salary excluding minimum and maximum salary is (2000+3000) / 2 = 2500\n \n Example 2:\n \n >>> average(salary = [1000,2000,3000])\n >>> 2000.00000\n Explanation: Minimum salary and maximum salary are 1000 and 3000 respectively.\n Average salary excluding minimum and maximum salary is (2000) / 1 = 2000\n \"\"\"\n"}
{"task_id": "the-kth-factor-of-n", "prompt": "def kthFactor(n: int, k: int) -> int:\n \"\"\"\n You are given two positive integers n and k. A factor of an integer n is defined as an integer i where n % i == 0.\n Consider a list of all factors of n sorted in ascending order, return the kth factor in this list or return -1 if n has less than k factors.\n \n Example 1:\n \n >>> kthFactor(n = 12, k = 3)\n >>> 3\n Explanation: Factors list is [1, 2, 3, 4, 6, 12], the 3rd factor is 3.\n \n Example 2:\n \n >>> kthFactor(n = 7, k = 2)\n >>> 7\n Explanation: Factors list is [1, 7], the 2nd factor is 7.\n \n Example 3:\n \n >>> kthFactor(n = 4, k = 4)\n >>> -1\n Explanation: Factors list is [1, 2, 4], there is only 3 factors. We should return -1.\n \"\"\"\n"}
{"task_id": "longest-subarray-of-1s-after-deleting-one-element", "prompt": "def longestSubarray(nums: List[int]) -> int:\n \"\"\"\n Given a binary array nums, you should delete one element from it.\n Return the size of the longest non-empty subarray containing only 1's in the resulting array. Return 0 if there is no such subarray.\n \n Example 1:\n \n >>> longestSubarray(nums = [1,1,0,1])\n >>> 3\n Explanation: After deleting the number in position 2, [1,1,1] contains 3 numbers with value of 1's.\n \n Example 2:\n \n >>> longestSubarray(nums = [0,1,1,1,0,1,1,0,1])\n >>> 5\n Explanation: After deleting the number in position 4, [0,1,1,1,1,1,0,1] longest subarray with value of 1's is [1,1,1,1,1].\n \n Example 3:\n \n >>> longestSubarray(nums = [1,1,1])\n >>> 2\n Explanation: You must delete one element.\n \"\"\"\n"}
{"task_id": "parallel-courses-ii", "prompt": "def minNumberOfSemesters(n: int, relations: List[List[int]], k: int) -> int:\n \"\"\"\n 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. Also, you are given the integer k.\n In one semester, you can take at most k courses as long as you have taken all the prerequisites in the previous semesters for the courses you are taking.\n Return the minimum number of semesters needed to take all courses. The testcases will be generated such that it is possible to take every course.\n \n Example 1:\n \n \n >>> minNumberOfSemesters(n = 4, relations = [[2,1],[3,1],[1,4]], k = 2)\n >>> 3\n Explanation: The figure above represents the given graph.\n In the first semester, you can take courses 2 and 3.\n In the second semester, you can take course 1.\n In the third semester, you can take course 4.\n \n Example 2:\n \n \n >>> minNumberOfSemesters(n = 5, relations = [[2,1],[3,1],[4,1],[1,5]], k = 2)\n >>> 4\n Explanation: The figure above represents the given graph.\n In the first semester, you can only take courses 2 and 3 since you cannot take more than two per semester.\n In the second semester, you can take course 4.\n In the third semester, you can take course 1.\n In the fourth semester, you can take course 5.\n \"\"\"\n"}
{"task_id": "path-crossing", "prompt": "def isPathCrossing(path: str) -> bool:\n \"\"\"\n Given a string path, where path[i] = 'N', 'S', 'E' or 'W', each representing moving one unit north, south, east, or west, respectively. You start at the origin (0, 0) on a 2D plane and walk on the path specified by path.\n Return true if the path crosses itself at any point, that is, if at any time you are on a location you have previously visited. Return false otherwise.\n \n Example 1:\n \n \n >>> isPathCrossing(path = \"NES\")\n >>> false\n Explanation: Notice that the path doesn't cross any point more than once.\n \n Example 2:\n \n \n >>> isPathCrossing(path = \"NESWW\")\n >>> true\n Explanation: Notice that the path visits the origin twice.\n \"\"\"\n"}
{"task_id": "check-if-array-pairs-are-divisible-by-k", "prompt": "def canArrange(arr: List[int], k: int) -> bool:\n \"\"\"\n Given an array of integers arr of even length n and an integer k.\n We want to divide the array into exactly n / 2 pairs such that the sum of each pair is divisible by k.\n Return true If you can find a way to do that or false otherwise.\n \n Example 1:\n \n >>> canArrange(arr = [1,2,3,4,5,10,6,7,8,9], k = 5)\n >>> true\n Explanation: Pairs are (1,9),(2,8),(3,7),(4,6) and (5,10).\n \n Example 2:\n \n >>> canArrange(arr = [1,2,3,4,5,6], k = 7)\n >>> true\n Explanation: Pairs are (1,6),(2,5) and(3,4).\n \n Example 3:\n \n >>> canArrange(arr = [1,2,3,4,5,6], k = 10)\n >>> false\n Explanation: You can try all possible pairs to see that there is no way to divide arr into 3 pairs each with sum divisible by 10.\n \"\"\"\n"}
{"task_id": "number-of-subsequences-that-satisfy-the-given-sum-condition", "prompt": "def numSubseq(nums: List[int], target: int) -> int:\n \"\"\"\n You are given an array of integers nums and an integer target.\n Return the number of non-empty subsequences of nums such that the sum of the minimum and maximum element on it is less or equal to target. Since the answer may be too large, return it modulo 109 + 7.\n \n Example 1:\n \n >>> numSubseq(nums = [3,5,6,7], target = 9)\n >>> 4\n Explanation: There are 4 subsequences that satisfy the condition.\n [3] -> Min value + max value <= target (3 + 3 <= 9)\n [3,5] -> (3 + 5 <= 9)\n [3,5,6] -> (3 + 6 <= 9)\n [3,6] -> (3 + 6 <= 9)\n \n Example 2:\n \n >>> numSubseq(nums = [3,3,6,8], target = 10)\n >>> 6\n Explanation: There are 6 subsequences that satisfy the condition. (nums can have repeated numbers).\n [3] , [3] , [3,3], [3,6] , [3,6] , [3,3,6]\n \n Example 3:\n \n >>> numSubseq(nums = [2,3,3,4,6,7], target = 12)\n >>> 61\n Explanation: There are 63 non-empty subsequences, two of them do not satisfy the condition ([6,7], [7]).\n Number of valid subsequences (63 - 2 = 61).\n \"\"\"\n"}
{"task_id": "max-value-of-equation", "prompt": "def findMaxValueOfEquation(points: List[List[int]], k: int) -> int:\n \"\"\"\n You are given an array points containing the coordinates of points on a 2D plane, sorted by the x-values, where points[i] = [xi, yi] such that xi < xj for all 1 <= i < j <= points.length. You are also given an integer k.\n Return the maximum value of the equation yi + yj + |xi - xj| where |xi - xj| <= k and 1 <= i < j <= points.length.\n It is guaranteed that there exists at least one pair of points that satisfy the constraint |xi - xj| <= k.\n \n Example 1:\n \n >>> findMaxValueOfEquation(points = [[1,3],[2,0],[5,10],[6,-10]], k = 1)\n >>> 4\n Explanation: The first two points satisfy the condition |xi - xj| <= 1 and if we calculate the equation we get 3 + 0 + |1 - 2| = 4. Third and fourth points also satisfy the condition and give a value of 10 + -10 + |5 - 6| = 1.\n No other pairs satisfy the condition, so we return the max of 4 and 1.\n \n Example 2:\n \n >>> findMaxValueOfEquation(points = [[0,0],[3,0],[9,2]], k = 3)\n >>> 3\n Explanation: Only the first two points have an absolute difference of 3 or less in the x-values, and give the value of 0 + 0 + |0 - 3| = 3.\n \"\"\"\n"}
{"task_id": "can-make-arithmetic-progression-from-sequence", "prompt": "def canMakeArithmeticProgression(arr: List[int]) -> bool:\n \"\"\"\n A sequence of numbers is called an arithmetic progression if the difference between any two consecutive elements is the same.\n Given an array of numbers arr, return true if the array can be rearranged to form an arithmetic progression. Otherwise, return false.\n \n Example 1:\n \n >>> canMakeArithmeticProgression(arr = [3,5,1])\n >>> true\n Explanation: We can reorder the elements as [1,3,5] or [5,3,1] with differences 2 and -2 respectively, between each consecutive elements.\n \n Example 2:\n \n >>> canMakeArithmeticProgression(arr = [1,2,4])\n >>> false\n Explanation: There is no way to reorder the elements to obtain an arithmetic progression.\n \"\"\"\n"}
{"task_id": "last-moment-before-all-ants-fall-out-of-a-plank", "prompt": "def getLastMoment(n: int, left: List[int], right: List[int]) -> int:\n \"\"\"\n We have a wooden plank of the length n units. Some ants are walking on the plank, each ant moves with a speed of 1 unit per second. Some of the ants move to the left, the other move to the right.\n When two ants moving in two different directions meet at some point, they change their directions and continue moving again. Assume changing directions does not take any additional time.\n When an ant reaches one end of the plank at a time t, it falls out of the plank immediately.\n Given an integer n and two integer arrays left and right, the positions of the ants moving to the left and the right, return the moment when the last ant(s) fall out of the plank.\n \n Example 1:\n \n \n >>> getLastMoment(n = 4, left = [4,3], right = [0,1])\n >>> 4\n Explanation: In the image above:\n -The ant at index 0 is named A and going to the right.\n -The ant at index 1 is named B and going to the right.\n -The ant at index 3 is named C and going to the left.\n -The ant at index 4 is named D and going to the left.\n The last moment when an ant was on the plank is t = 4 seconds. After that, it falls immediately out of the plank. (i.e., We can say that at t = 4.0000000001, there are no ants on the plank).\n \n Example 2:\n \n \n >>> getLastMoment(n = 7, left = [], right = [0,1,2,3,4,5,6,7])\n >>> 7\n Explanation: All ants are going to the right, the ant at index 0 needs 7 seconds to fall.\n \n Example 3:\n \n \n >>> getLastMoment(n = 7, left = [0,1,2,3,4,5,6,7], right = [])\n >>> 7\n Explanation: All ants are going to the left, the ant at index 7 needs 7 seconds to fall.\n \"\"\"\n"}
{"task_id": "count-submatrices-with-all-ones", "prompt": "def numSubmat(mat: List[List[int]]) -> int:\n \"\"\"\n Given an m x n binary matrix mat, return the number of submatrices that have all ones.\n \n Example 1:\n \n \n >>> numSubmat(mat = [[1,0,1],[1,1,0],[1,1,0]])\n >>> 13\n Explanation:\n There are 6 rectangles of side 1x1.\n There are 2 rectangles of side 1x2.\n There are 3 rectangles of side 2x1.\n There is 1 rectangle of side 2x2.\n There is 1 rectangle of side 3x1.\n Total number of rectangles = 6 + 2 + 3 + 1 + 1 = 13.\n \n Example 2:\n \n \n >>> numSubmat(mat = [[0,1,1,0],[0,1,1,1],[1,1,1,0]])\n >>> 24\n Explanation:\n There are 8 rectangles of side 1x1.\n There are 5 rectangles of side 1x2.\n There are 2 rectangles of side 1x3.\n There are 4 rectangles of side 2x1.\n There are 2 rectangles of side 2x2.\n There are 2 rectangles of side 3x1.\n There is 1 rectangle of side 3x2.\n Total number of rectangles = 8 + 5 + 2 + 4 + 2 + 2 + 1 = 24.\n \"\"\"\n"}
{"task_id": "minimum-possible-integer-after-at-most-k-adjacent-swaps-on-digits", "prompt": "def minInteger(num: str, k: int) -> str:\n \"\"\"\n You are given a string num representing the digits of a very large integer and an integer k. You are allowed to swap any two adjacent digits of the integer at most k times.\n Return the minimum integer you can obtain also as a string.\n \n Example 1:\n \n \n >>> minInteger(num = \"4321\", k = 4)\n >>> \"1342\"\n Explanation: The steps to obtain the minimum integer from 4321 with 4 adjacent swaps are shown.\n \n Example 2:\n \n >>> minInteger(num = \"100\", k = 1)\n >>> \"010\"\n Explanation: It's ok for the output to have leading zeros, but the input is guaranteed not to have any leading zeros.\n \n Example 3:\n \n >>> minInteger(num = \"36789\", k = 1000)\n >>> \"36789\"\n Explanation: We can keep the number without any swaps.\n \"\"\"\n"}
{"task_id": "reformat-date", "prompt": "def reformatDate(date: str) -> str:\n \"\"\"\n Given a date string in the form\u00a0Day Month Year, where:\n \n Day\u00a0is in the set {\"1st\", \"2nd\", \"3rd\", \"4th\", ..., \"30th\", \"31st\"}.\n Month\u00a0is in the set {\"Jan\", \"Feb\", \"Mar\", \"Apr\", \"May\", \"Jun\", \"Jul\", \"Aug\", \"Sep\", \"Oct\", \"Nov\", \"Dec\"}.\n Year\u00a0is in the range [1900, 2100].\n \n Convert the date string to the format YYYY-MM-DD, where:\n \n YYYY denotes the 4 digit year.\n MM denotes the 2 digit month.\n DD denotes the 2 digit day.\n \n \n Example 1:\n \n >>> reformatDate(date = \"20th Oct 2052\")\n >>> \"2052-10-20\"\n \n Example 2:\n \n >>> reformatDate(date = \"6th Jun 1933\")\n >>> \"1933-06-06\"\n \n Example 3:\n \n >>> reformatDate(date = \"26th May 1960\")\n >>> \"1960-05-26\"\n \"\"\"\n"}
{"task_id": "range-sum-of-sorted-subarray-sums", "prompt": "def rangeSum(nums: List[int], n: int, left: int, right: int) -> int:\n \"\"\"\n You are given the array nums consisting of n positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of n * (n + 1) / 2 numbers.\n Return the sum of the numbers from index left to index right (indexed from 1), inclusive, in the new array. Since the answer can be a huge number return it modulo 109 + 7.\n \n Example 1:\n \n >>> rangeSum(nums = [1,2,3,4], n = 4, left = 1, right = 5)\n >>> 13\n Explanation: All subarray sums are 1, 3, 6, 10, 2, 5, 9, 3, 7, 4. After sorting them in non-decreasing order we have the new array [1, 2, 3, 3, 4, 5, 6, 7, 9, 10]. The sum of the numbers from index le = 1 to ri = 5 is 1 + 2 + 3 + 3 + 4 = 13.\n \n Example 2:\n \n >>> rangeSum(nums = [1,2,3,4], n = 4, left = 3, right = 4)\n >>> 6\n Explanation: The given array is the same as example 1. We have the new array [1, 2, 3, 3, 4, 5, 6, 7, 9, 10]. The sum of the numbers from index le = 3 to ri = 4 is 3 + 3 = 6.\n \n Example 3:\n \n >>> rangeSum(nums = [1,2,3,4], n = 4, left = 1, right = 10)\n >>> 50\n \"\"\"\n"}
{"task_id": "minimum-difference-between-largest-and-smallest-value-in-three-moves", "prompt": "def minDifference(nums: List[int]) -> int:\n \"\"\"\n You are given an integer array nums.\n In one move, you can choose one element of nums and change it to any value.\n Return the minimum difference between the largest and smallest value of nums after performing at most three moves.\n \n Example 1:\n \n >>> minDifference(nums = [5,3,2,4])\n >>> 0\n Explanation: We can make at most 3 moves.\n In the first move, change 2 to 3. nums becomes [5,3,3,4].\n In the second move, change 4 to 3. nums becomes [5,3,3,3].\n In the third move, change 5 to 3. nums becomes [3,3,3,3].\n After performing 3 moves, the difference between the minimum and maximum is 3 - 3 = 0.\n \n Example 2:\n \n >>> minDifference(nums = [1,5,0,10,14])\n >>> 1\n Explanation: We can make at most 3 moves.\n In the first move, change 5 to 0. nums becomes [1,0,0,10,14].\n In the second move, change 10 to 0. nums becomes [1,0,0,0,14].\n In the third move, change 14 to 1. nums becomes [1,0,0,0,1].\n After performing 3 moves, the difference between the minimum and maximum is 1 - 0 = 1.\n It can be shown that there is no way to make the difference 0 in 3 moves.\n Example 3:\n \n >>> minDifference(nums = [3,100,20])\n >>> 0\n Explanation: We can make at most 3 moves.\n In the first move, change 100 to 7. nums becomes [3,7,20].\n In the second move, change 20 to 7. nums becomes [3,7,7].\n In the third move, change 3 to 7. nums becomes [7,7,7].\n After performing 3 moves, the difference between the minimum and maximum is 7 - 7 = 0.\n \"\"\"\n"}
{"task_id": "stone-game-iv", "prompt": "def winnerSquareGame(n: int) -> bool:\n \"\"\"\n Alice and Bob take turns playing a game, with Alice starting first.\n Initially, there are n stones in a pile. On each player's turn, that player makes a move consisting of removing any non-zero square number of stones in the pile.\n Also, if a player cannot make a move, he/she loses the game.\n Given a positive integer n, return true if and only if Alice wins the game otherwise return false, assuming both players play optimally.\n \n Example 1:\n \n >>> winnerSquareGame(n = 1)\n >>> true\n Explanation: Alice can remove 1 stone winning the game because Bob doesn't have any moves.\n Example 2:\n \n >>> winnerSquareGame(n = 2)\n >>> false\n Explanation: Alice can only remove 1 stone, after that Bob removes the last one winning the game (2 -> 1 -> 0).\n \n Example 3:\n \n >>> winnerSquareGame(n = 4)\n >>> true\n Explanation: n is already a perfect square, Alice can win with one move, removing 4 stones (4 -> 0).\n \"\"\"\n"}
{"task_id": "number-of-good-pairs", "prompt": "def numIdenticalPairs(nums: List[int]) -> int:\n \"\"\"\n Given an array of integers nums, return the number of good pairs.\n A pair (i, j) is called good if nums[i] == nums[j] and i < j.\n \n Example 1:\n \n >>> numIdenticalPairs(nums = [1,2,3,1,1,3])\n >>> 4\n Explanation: There are 4 good pairs (0,3), (0,4), (3,4), (2,5) 0-indexed.\n \n Example 2:\n \n >>> numIdenticalPairs(nums = [1,1,1,1])\n >>> 6\n Explanation: Each pair in the array are good.\n \n Example 3:\n \n >>> numIdenticalPairs(nums = [1,2,3])\n >>> 0\n \"\"\"\n"}
{"task_id": "number-of-substrings-with-only-1s", "prompt": "def numSub(s: str) -> int:\n \"\"\"\n Given a binary string s, return the number of substrings with all characters 1's. Since the answer may be too large, return it modulo 109 + 7.\n \n Example 1:\n \n >>> numSub(s = \"0110111\")\n >>> 9\n Explanation: There are 9 substring in total with only 1's characters.\n \"1\" -> 5 times.\n \"11\" -> 3 times.\n \"111\" -> 1 time.\n Example 2:\n \n >>> numSub(s = \"101\")\n >>> 2\n Explanation: Substring \"1\" is shown 2 times in s.\n \n Example 3:\n \n >>> numSub(s = \"111111\")\n >>> 21\n Explanation: Each substring contains only 1's characters.\n \"\"\"\n"}
{"task_id": "path-with-maximum-probability", "prompt": "def maxProbability(n: int, edges: List[List[int]], succProb: List[float], start_node: int, end_node: int) -> float:\n \"\"\"\n You are given an undirected weighted graph of\u00a0n\u00a0nodes (0-indexed), represented by an edge list where\u00a0edges[i] = [a, b]\u00a0is an undirected edge connecting the nodes\u00a0a\u00a0and\u00a0b\u00a0with a probability of success of traversing that edge\u00a0succProb[i].\n Given two nodes\u00a0start\u00a0and\u00a0end, find the path with the maximum probability of success to go from\u00a0start\u00a0to\u00a0end\u00a0and return its success probability.\n If there is no path from\u00a0start\u00a0to\u00a0end, return\u00a00. Your answer will be accepted if it differs from the correct answer by at most 1e-5.\n \n Example 1:\n \n \n >>> maxProbability(n = 3, edges = [[0,1],[1,2],[0,2]], succProb = [0.5,0.5,0.2], start = 0, end = 2)\n >>> 0.25000\n Explanation:\u00a0There are two paths from start to end, one having a probability of success = 0.2 and the other has 0.5 * 0.5 = 0.25.\n \n Example 2:\n \n \n >>> maxProbability(n = 3, edges = [[0,1],[1,2],[0,2]], succProb = [0.5,0.5,0.3], start = 0, end = 2)\n >>> 0.30000\n \n Example 3:\n \n \n >>> maxProbability(n = 3, edges = [[0,1]], succProb = [0.5], start = 0, end = 2)\n >>> 0.00000\n Explanation:\u00a0There is no path between 0 and 2.\n \"\"\"\n"}
{"task_id": "best-position-for-a-service-centre", "prompt": "def getMinDistSum(positions: List[List[int]]) -> float:\n \"\"\"\n A delivery company wants to build a new service center in a new city. The company knows the positions of all the customers in this city on a 2D-Map and wants to build the new center in a position such that the sum of the euclidean distances to all customers is minimum.\n Given an array positions where positions[i] = [xi, yi] is the position of the ith customer on the map, return the minimum sum of the euclidean distances to all customers.\n In other words, you need to choose the position of the service center [xcentre, ycentre] such that the following formula is minimized:\n \n Answers within 10-5 of the actual value will be accepted.\n \n Example 1:\n \n \n >>> getMinDistSum(positions = [[0,1],[1,0],[1,2],[2,1]])\n >>> 4.00000\n Explanation: As shown, you can see that choosing [xcentre, ycentre] = [1, 1] will make the distance to each customer = 1, the sum of all distances is 4 which is the minimum possible we can achieve.\n \n Example 2:\n \n \n >>> getMinDistSum(positions = [[1,1],[3,3]])\n >>> 2.82843\n Explanation: The minimum possible sum of distances = sqrt(2) + sqrt(2) = 2.82843\n \"\"\"\n"}
{"task_id": "water-bottles", "prompt": "def numWaterBottles(numBottles: int, numExchange: int) -> int:\n \"\"\"\n There are numBottles water bottles that are initially full of water. You can exchange numExchange empty water bottles from the market with one full water bottle.\n The operation of drinking a full water bottle turns it into an empty bottle.\n Given the two integers numBottles and numExchange, return the maximum number of water bottles you can drink.\n \n Example 1:\n \n \n >>> numWaterBottles(numBottles = 9, numExchange = 3)\n >>> 13\n Explanation: You can exchange 3 empty bottles to get 1 full water bottle.\n Number of water bottles you can drink: 9 + 3 + 1 = 13.\n \n Example 2:\n \n \n >>> numWaterBottles(numBottles = 15, numExchange = 4)\n >>> 19\n Explanation: You can exchange 4 empty bottles to get 1 full water bottle.\n Number of water bottles you can drink: 15 + 3 + 1 = 19.\n \"\"\"\n"}
{"task_id": "number-of-nodes-in-the-sub-tree-with-the-same-label", "prompt": "def countSubTrees(n: int, edges: List[List[int]], labels: str) -> List[int]:\n \"\"\"\n You are given a tree (i.e. a connected, undirected graph that has no cycles) consisting of n nodes numbered from 0 to n - 1 and exactly n - 1 edges. The root of the tree is the node 0, and each node of the tree has a label which is a lower-case character given in the string labels (i.e. The node with the number i has the label labels[i]).\n The edges array is given on the form edges[i] = [ai, bi], which means there is an edge between nodes ai and bi in the tree.\n Return an array of size n where ans[i] is the number of nodes in the subtree of the ith node which have the same label as node i.\n A subtree of a tree T is the tree consisting of a node in T and all of its descendant nodes.\n \n Example 1:\n \n \n >>> countSubTrees(n = 7, edges = [[0,1],[0,2],[1,4],[1,5],[2,3],[2,6]], labels = \"abaedcd\")\n >>> [2,1,1,1,1,1,1]\n Explanation: Node 0 has label 'a' and its sub-tree has node 2 with label 'a' as well, thus the answer is 2. Notice that any node is part of its sub-tree.\n Node 1 has a label 'b'. The sub-tree of node 1 contains nodes 1,4 and 5, as nodes 4 and 5 have different labels than node 1, the answer is just 1 (the node itself).\n \n Example 2:\n \n \n >>> countSubTrees(n = 4, edges = [[0,1],[1,2],[0,3]], labels = \"bbbb\")\n >>> [4,2,1,1]\n Explanation: The sub-tree of node 2 contains only node 2, so the answer is 1.\n The sub-tree of node 3 contains only node 3, so the answer is 1.\n The sub-tree of node 1 contains nodes 1 and 2, both have label 'b', thus the answer is 2.\n The sub-tree of node 0 contains nodes 0, 1, 2 and 3, all with label 'b', thus the answer is 4.\n \n Example 3:\n \n \n >>> countSubTrees(n = 5, edges = [[0,1],[0,2],[1,3],[0,4]], labels = \"aabab\")\n >>> [3,2,1,1,1]\n \"\"\"\n"}
{"task_id": "maximum-number-of-non-overlapping-substrings", "prompt": "def maxNumOfSubstrings(s: str) -> List[str]:\n \"\"\"\n Given a string s of lowercase letters, you need to find the maximum number of non-empty substrings of s that meet the following conditions:\n \n The substrings do not overlap, that is for any two substrings s[i..j] and s[x..y], either j < x or i > y is true.\n A substring that contains a certain character c must also contain all occurrences of c.\n \n Find the maximum number of substrings that meet the above conditions. If there are multiple solutions with the same number of substrings, return the one with minimum total length. It can be shown that there exists a unique solution of minimum total length.\n Notice that you can return the substrings in any order.\n \n Example 1:\n \n >>> maxNumOfSubstrings(s = \"adefaddaccc\")\n >>> [\"e\",\"f\",\"ccc\"]\n Explanation:\u00a0The following are all the possible substrings that meet the conditions:\n [\n \u00a0 \"adefaddaccc\"\n \u00a0 \"adefadda\",\n \u00a0 \"ef\",\n \u00a0 \"e\",\n \"f\",\n \u00a0 \"ccc\",\n ]\n If we choose the first string, we cannot choose anything else and we'd get only 1. If we choose \"adefadda\", we are left with \"ccc\" which is the only one that doesn't overlap, thus obtaining 2 substrings. Notice also, that it's not optimal to choose \"ef\" since it can be split into two. Therefore, the optimal way is to choose [\"e\",\"f\",\"ccc\"] which gives us 3 substrings. No other solution of the same number of substrings exist.\n \n Example 2:\n \n >>> maxNumOfSubstrings(s = \"abbaccd\")\n >>> [\"d\",\"bb\",\"cc\"]\n Explanation: Notice that while the set of substrings [\"d\",\"abba\",\"cc\"] also has length 3, it's considered incorrect since it has larger total length.\n \"\"\"\n"}
{"task_id": "find-a-value-of-a-mysterious-function-closest-to-target", "prompt": "def closestToTarget(arr: List[int], target: int) -> int:\n \"\"\"\n Winston was given the above mysterious function func. He has an integer array arr and an integer target and he wants to find the values l and r that make the value |func(arr, l, r) - target| minimum possible.\n Return the minimum possible value of |func(arr, l, r) - target|.\n Notice that func should be called with the values l and r where 0 <= l, r < arr.length.\n \n Example 1:\n \n >>> closestToTarget(arr = [9,12,3,7,15], target = 5)\n >>> 2\n Explanation: Calling func with all the pairs of [l,r] = [[0,0],[1,1],[2,2],[3,3],[4,4],[0,1],[1,2],[2,3],[3,4],[0,2],[1,3],[2,4],[0,3],[1,4],[0,4]], Winston got the following results [9,12,3,7,15,8,0,3,7,0,0,3,0,0,0]. The value closest to 5 is 7 and 3, thus the minimum difference is 2.\n \n Example 2:\n \n >>> closestToTarget(arr = [1000000,1000000,1000000], target = 1)\n >>> 999999\n Explanation: Winston called the func with all possible values of [l,r] and he always got 1000000, thus the min difference is 999999.\n \n Example 3:\n \n >>> closestToTarget(arr = [1,2,4,8,16], target = 0)\n >>> 0\n \"\"\"\n"}
{"task_id": "count-odd-numbers-in-an-interval-range", "prompt": "def countOdds(low: int, high: int) -> int:\n \"\"\"\n Given two non-negative integers low and high. Return the count of odd numbers between low and high\u00a0(inclusive).\\r\n \\r\n \u00a0\\r\n Example 1:\\r\n \\r\n \\r\n >>> countOdds(low = 3, high = 7\\r)\n >>> 3\\r\n Explanation: The odd numbers between 3 and 7 are [3,5,7].\\r\n \\r\n Example 2:\\r\n \\r\n \\r\n >>> countOdds(low = 8, high = 10\\r)\n >>> 1\\r\n Explanation: The odd numbers between 8 and 10 are [9].\\r\n \\r\n \u00a0\\r\n \"\"\"\n"}
{"task_id": "number-of-sub-arrays-with-odd-sum", "prompt": "def numOfSubarrays(arr: List[int]) -> int:\n \"\"\"\n Given an array of integers arr, return the number of subarrays with an odd sum.\n Since the answer can be very large, return it modulo 109 + 7.\n \n Example 1:\n \n >>> numOfSubarrays(arr = [1,3,5])\n >>> 4\n Explanation: All subarrays are [[1],[1,3],[1,3,5],[3],[3,5],[5]]\n All sub-arrays sum are [1,4,9,3,8,5].\n Odd sums are [1,9,3,5] so the answer is 4.\n \n Example 2:\n \n >>> numOfSubarrays(arr = [2,4,6])\n >>> 0\n Explanation: All subarrays are [[2],[2,4],[2,4,6],[4],[4,6],[6]]\n All sub-arrays sum are [2,6,12,4,10,6].\n All sub-arrays have even sum and the answer is 0.\n \n Example 3:\n \n >>> numOfSubarrays(arr = [1,2,3,4,5,6,7])\n >>> 16\n \"\"\"\n"}
{"task_id": "number-of-good-ways-to-split-a-string", "prompt": "def numSplits(s: str) -> int:\n \"\"\"\n You are given a string s.\n A split is called good if you can split s into two non-empty strings sleft and sright where their concatenation is equal to s (i.e., sleft + sright = s) and the number of distinct letters in sleft and sright is the same.\n Return the number of good splits you can make in s.\n \n Example 1:\n \n >>> numSplits(s = \"aacaba\")\n >>> 2\n Explanation: There are 5 ways to split \"aacaba\" and 2 of them are good.\n (\"a\", \"acaba\") Left string and right string contains 1 and 3 different letters respectively.\n (\"aa\", \"caba\") Left string and right string contains 1 and 3 different letters respectively.\n (\"aac\", \"aba\") Left string and right string contains 2 and 2 different letters respectively (good split).\n (\"aaca\", \"ba\") Left string and right string contains 2 and 2 different letters respectively (good split).\n (\"aacab\", \"a\") Left string and right string contains 3 and 1 different letters respectively.\n \n Example 2:\n \n >>> numSplits(s = \"abcd\")\n >>> 1\n Explanation: Split the string as follows (\"ab\", \"cd\").\n \"\"\"\n"}
{"task_id": "minimum-number-of-increments-on-subarrays-to-form-a-target-array", "prompt": "def minNumberOperations(target: List[int]) -> int:\n \"\"\"\n You are given an integer array target. You have an integer array initial of the same size as target with all elements initially zeros.\n In one operation you can choose any subarray from initial and increment each value by one.\n Return the minimum number of operations to form a target array from initial.\n The test cases are generated so that the answer fits in a 32-bit integer.\n \n Example 1:\n \n >>> minNumberOperations(target = [1,2,3,2,1])\n >>> 3\n Explanation: We need at least 3 operations to form the target array from the initial array.\n [0,0,0,0,0] increment 1 from index 0 to 4 (inclusive).\n [1,1,1,1,1] increment 1 from index 1 to 3 (inclusive).\n [1,2,2,2,1] increment 1 at index 2.\n [1,2,3,2,1] target array is formed.\n \n Example 2:\n \n >>> minNumberOperations(target = [3,1,1,2])\n >>> 4\n Explanation: [0,0,0,0] -> [1,1,1,1] -> [1,1,1,2] -> [2,1,1,2] -> [3,1,1,2]\n \n Example 3:\n \n >>> minNumberOperations(target = [3,1,5,4,2])\n >>> 7\n Explanation: [0,0,0,0,0] -> [1,1,1,1,1] -> [2,1,1,1,1] -> [3,1,1,1,1] -> [3,1,2,2,2] -> [3,1,3,3,2] -> [3,1,4,4,2] -> [3,1,5,4,2].\n \"\"\"\n"}
{"task_id": "shuffle-string", "prompt": "def restoreString(s: str, indices: List[int]) -> str:\n \"\"\"\n You are given a string s and an integer array indices of the same length. The string s will be shuffled such that the character at the ith position moves to indices[i] in the shuffled string.\n Return the shuffled string.\n \n Example 1:\n \n \n >>> restoreString(s = \"codeleet\", indices = [4,5,6,7,0,2,1,3])\n >>> \"leetcode\"\n Explanation: As shown, \"codeleet\" becomes \"leetcode\" after shuffling.\n \n Example 2:\n \n >>> restoreString(s = \"abc\", indices = [0,1,2])\n >>> \"abc\"\n Explanation: After shuffling, each character remains in its position.\n \"\"\"\n"}
{"task_id": "minimum-suffix-flips", "prompt": "def minFlips(target: str) -> int:\n \"\"\"\n You are given a 0-indexed binary string target of length n. You have another binary string s of length n that is initially set to all zeros. You want to make s equal to target.\n In one operation, you can pick an index i where 0 <= i < n and flip all bits in the inclusive range [i, n - 1]. Flip means changing '0' to '1' and '1' to '0'.\n Return the minimum number of operations needed to make s equal to target.\n \n Example 1:\n \n >>> minFlips(target = \"10111\")\n >>> 3\n Explanation: Initially, s = \"00000\".\n Choose index i = 2: \"00000\" -> \"00111\"\n Choose index i = 0: \"00111\" -> \"11000\"\n Choose index i = 1: \"11000\" -> \"10111\"\n We need at least 3 flip operations to form target.\n \n Example 2:\n \n >>> minFlips(target = \"101\")\n >>> 3\n Explanation: Initially, s = \"000\".\n Choose index i = 0: \"000\" -> \"111\"\n Choose index i = 1: \"111\" -> \"100\"\n Choose index i = 2: \"100\" -> \"101\"\n We need at least 3 flip operations to form target.\n \n Example 3:\n \n >>> minFlips(target = \"00000\")\n >>> 0\n Explanation: We do not need any operations since the initial s already equals target.\n \"\"\"\n"}
{"task_id": "number-of-good-leaf-nodes-pairs", "prompt": "# class TreeNode:\n# def __init__(val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def countPairs(root: Optional[TreeNode], distance: int) -> int:\n \"\"\"\n You are given the root of a binary tree and an integer distance. A pair of two different leaf nodes of a binary tree is said to be good if the length of the shortest path between them is less than or equal to distance.\n Return the number of good leaf node pairs in the tree.\n \n Example 1:\n \n \n >>> __init__(root = [1,2,3,null,4], distance = 3)\n >>> 1\n Explanation: The leaf nodes of the tree are 3 and 4 and the length of the shortest path between them is 3. This is the only good pair.\n \n Example 2:\n \n \n >>> __init__(root = [1,2,3,4,5,6,7], distance = 3)\n >>> 2\n Explanation: The good pairs are [4,5] and [6,7] with shortest path = 2. The pair [4,6] is not good because the length of ther shortest path between them is 4.\n \n Example 3:\n \n >>> __init__(root = [7,1,4,6,null,5,3,null,null,null,null,null,2], distance = 3)\n >>> 1\n Explanation: The only good pair is [2,5].\n \"\"\"\n"}
{"task_id": "string-compression-ii", "prompt": "def getLengthOfOptimalCompression(s: str, k: int) -> int:\n \"\"\"\n Run-length encoding is a string compression method that works by\u00a0replacing consecutive identical characters (repeated 2 or more times) with the concatenation of the character and the number marking the count of the characters (length of the run). For example, to compress the string\u00a0\"aabccc\"\u00a0we replace \"aa\"\u00a0by\u00a0\"a2\"\u00a0and replace \"ccc\"\u00a0by\u00a0\"c3\". Thus the compressed string becomes \"a2bc3\".\n Notice that in this problem, we are not adding\u00a0'1'\u00a0after single characters.\n Given a\u00a0string s\u00a0and an integer k. You need to delete at most\u00a0k characters from\u00a0s\u00a0such that the run-length encoded version of s\u00a0has minimum length.\n Find the minimum length of the run-length encoded\u00a0version of s after deleting at most k characters.\n \n Example 1:\n \n >>> getLengthOfOptimalCompression(s = \"aaabcccd\", k = 2)\n >>> 4\n Explanation: Compressing s without deleting anything will give us \"a3bc3d\" of length 6. Deleting any of the characters 'a' or 'c' would at most decrease the length of the compressed string to 5, for instance delete 2 'a' then we will have s = \"abcccd\" which compressed is abc3d. Therefore, the optimal way is to delete 'b' and 'd', then the compressed version of s will be \"a3c3\" of length 4.\n Example 2:\n \n >>> getLengthOfOptimalCompression(s = \"aabbaa\", k = 2)\n >>> 2\n Explanation: If we delete both 'b' characters, the resulting compressed string would be \"a4\" of length 2.\n \n Example 3:\n \n >>> getLengthOfOptimalCompression(s = \"aaaaaaaaaaa\", k = 0)\n >>> 3\n Explanation: Since k is zero, we cannot delete anything. The compressed string is \"a11\" of length 3.\n \"\"\"\n"}
{"task_id": "count-good-triplets", "prompt": "def countGoodTriplets(arr: List[int], a: int, b: int, c: int) -> int:\n \"\"\"\n Given an array of integers arr, and three integers\u00a0a,\u00a0b\u00a0and\u00a0c. You need to find the number of good triplets.\\r\n \\r\n A triplet (arr[i], arr[j], arr[k])\u00a0is good if the following conditions are true:\\r\n \\r\n \\r\n \t0 <= i < j < k <\u00a0arr.length\\r\n \t|arr[i] - arr[j]| <= a\\r\n \t|arr[j] - arr[k]| <= b\\r\n \t|arr[i] - arr[k]| <= c\\r\n \\r\n \\r\n Where |x| denotes the absolute value of x.\\r\n \\r\n Return the number of good triplets.\\r\n \\r\n \u00a0\\r\n Example 1:\\r\n \\r\n \\r\n >>> countGoodTriplets(arr = [3,0,1,1,9,7], a = 7, b = 2, c = 3\\r)\n >>> 4\\r\n Explanation:\u00a0There are 4 good triplets: [(3,0,1), (3,0,1), (3,1,1), (0,1,1)].\\r\n \\r\n \\r\n Example 2:\\r\n \\r\n \\r\n >>> countGoodTriplets(arr = [1,1,2,2,3], a = 0, b = 0, c = 1\\r)\n >>> 0\\r\n Explanation: No triplet satisfies all conditions.\\r\n \\r\n \\r\n \u00a0\\r\n \"\"\"\n"}
{"task_id": "find-the-winner-of-an-array-game", "prompt": "def getWinner(arr: List[int], k: int) -> int:\n \"\"\"\n Given an integer array arr of distinct integers and an integer k.\n A game will be played between the first two elements of the array (i.e. arr[0] and arr[1]). In each round of the game, we compare arr[0] with arr[1], the larger integer wins and remains at position 0, and the smaller integer moves to the end of the array. The game ends when an integer wins k consecutive rounds.\n Return the integer which will win the game.\n It is guaranteed that there will be a winner of the game.\n \n Example 1:\n \n >>> getWinner(arr = [2,1,3,5,4,6,7], k = 2)\n >>> 5\n Explanation: Let's see the rounds of the game:\n Round | arr | winner | win_count\n 1 | [2,1,3,5,4,6,7] | 2 | 1\n 2 | [2,3,5,4,6,7,1] | 3 | 1\n 3 | [3,5,4,6,7,1,2] | 5 | 1\n 4 | [5,4,6,7,1,2,3] | 5 | 2\n So we can see that 4 rounds will be played and 5 is the winner because it wins 2 consecutive games.\n \n Example 2:\n \n >>> getWinner(arr = [3,2,1], k = 10)\n >>> 3\n Explanation: 3 will win the first 10 rounds consecutively.\n \"\"\"\n"}
{"task_id": "minimum-swaps-to-arrange-a-binary-grid", "prompt": "def minSwaps(grid: List[List[int]]) -> int:\n \"\"\"\n Given an n x n binary grid, in one step you can choose two adjacent rows of the grid and swap them.\n A grid is said to be valid if all the cells above the main diagonal are zeros.\n Return the minimum number of steps needed to make the grid valid, or -1 if the grid cannot be valid.\n The main diagonal of a grid is the diagonal that starts at cell (1, 1) and ends at cell (n, n).\n \n Example 1:\n \n \n >>> minSwaps(grid = [[0,0,1],[1,1,0],[1,0,0]])\n >>> 3\n \n Example 2:\n \n \n >>> minSwaps(grid = [[0,1,1,0],[0,1,1,0],[0,1,1,0],[0,1,1,0]])\n >>> -1\n Explanation: All rows are similar, swaps have no effect on the grid.\n \n Example 3:\n \n \n >>> minSwaps(grid = [[1,0,0],[1,1,0],[1,1,1]])\n >>> 0\n \"\"\"\n"}
{"task_id": "get-the-maximum-score", "prompt": "def maxSum(nums1: List[int], nums2: List[int]) -> int:\n \"\"\"\n You are given two sorted arrays of distinct integers nums1 and nums2.\n A valid path is defined as follows:\n \n Choose array nums1 or nums2 to traverse (from index-0).\n Traverse the current array from left to right.\n If you are reading any value that is present in nums1 and nums2 you are allowed to change your path to the other array. (Only one repeated value is considered in the valid path).\n \n The score is defined as the sum of unique values in a valid path.\n Return the maximum score you can obtain of all possible valid paths. Since the answer may be too large, return it modulo 109 + 7.\n \n Example 1:\n \n \n >>> maxSum(nums1 = [2,4,5,8,10], nums2 = [4,6,8,9])\n >>> 30\n Explanation: Valid paths:\n [2,4,5,8,10], [2,4,5,8,9], [2,4,6,8,9], [2,4,6,8,10], (starting from nums1)\n [4,6,8,9], [4,5,8,10], [4,5,8,9], [4,6,8,10] (starting from nums2)\n The maximum is obtained with the path in green [2,4,6,8,10].\n \n Example 2:\n \n >>> maxSum(nums1 = [1,3,5,7,9], nums2 = [3,5,100])\n >>> 109\n Explanation: Maximum sum is obtained with the path [1,3,5,100].\n \n Example 3:\n \n >>> maxSum(nums1 = [1,2,3,4,5], nums2 = [6,7,8,9,10])\n >>> 40\n Explanation: There are no common elements between nums1 and nums2.\n Maximum sum is obtained with the path [6,7,8,9,10].\n \"\"\"\n"}
{"task_id": "kth-missing-positive-number", "prompt": "def findKthPositive(arr: List[int], k: int) -> int:\n \"\"\"\n Given an array arr of positive integers sorted in a strictly increasing order, and an integer k.\n Return the kth positive integer that is missing from this array.\n \n Example 1:\n \n >>> findKthPositive(arr = [2,3,4,7,11], k = 5)\n >>> 9\n Explanation: The missing positive integers are [1,5,6,8,9,10,12,13,...]. The 5th\u00a0missing positive integer is 9.\n \n Example 2:\n \n >>> findKthPositive(arr = [1,2,3,4], k = 2)\n >>> 6\n Explanation: The missing positive integers are [5,6,7,...]. The 2nd missing positive integer is 6.\n \"\"\"\n"}
{"task_id": "can-convert-string-in-k-moves", "prompt": "def canConvertString(s: str, t: str, k: int) -> bool:\n \"\"\"\n Given two strings\u00a0s\u00a0and\u00a0t, your goal is to convert\u00a0s\u00a0into\u00a0t\u00a0in\u00a0k\u00a0moves or less.\n During the\u00a0ith\u00a0(1 <= i <= k)\u00a0move you can:\n \n Choose any index\u00a0j\u00a0(1-indexed) from\u00a0s, such that\u00a01 <= j <= s.length\u00a0and j\u00a0has not been chosen in any previous move,\u00a0and shift the character at that index\u00a0i\u00a0times.\n Do nothing.\n \n Shifting a character means replacing it by the next letter in the alphabet\u00a0(wrapping around so that\u00a0'z'\u00a0becomes\u00a0'a'). Shifting a character by\u00a0i\u00a0means applying the shift operations\u00a0i\u00a0times.\n Remember that any index\u00a0j\u00a0can be picked at most once.\n Return\u00a0true\u00a0if it's possible to convert\u00a0s\u00a0into\u00a0t\u00a0in no more than\u00a0k\u00a0moves, otherwise return\u00a0false.\n \n Example 1:\n \n >>> canConvertString(s = \"input\", t = \"ouput\", k = 9)\n >>> true\n Explanation: In the 6th move, we shift 'i' 6 times to get 'o'. And in the 7th move we shift 'n' to get 'u'.\n \n Example 2:\n \n >>> canConvertString(s = \"abc\", t = \"bcd\", k = 10)\n >>> false\n Explanation: We need to shift each character in s one time to convert it into t. We can shift 'a' to 'b' during the 1st move. However, there is no way to shift the other characters in the remaining moves to obtain t from s.\n \n Example 3:\n \n >>> canConvertString(s = \"aab\", t = \"bbb\", k = 27)\n >>> true\n Explanation: In the 1st move, we shift the first 'a' 1 time to get 'b'. In the 27th move, we shift the second 'a' 27 times to get 'b'.\n \"\"\"\n"}
{"task_id": "minimum-insertions-to-balance-a-parentheses-string", "prompt": "def minInsertions(s: str) -> int:\n \"\"\"\n Given a parentheses string s containing only the characters '(' and ')'. A parentheses string is balanced if:\n \n Any left parenthesis '(' must have a corresponding two consecutive right parenthesis '))'.\n Left parenthesis '(' must go before the corresponding two consecutive right parenthesis '))'.\n \n In other words, we treat '(' as an opening parenthesis and '))' as a closing parenthesis.\n \n For example, \"())\", \"())(())))\" and \"(())())))\" are balanced, \")()\", \"()))\" and \"(()))\" are not balanced.\n \n You can insert the characters '(' and ')' at any position of the string to balance it if needed.\n Return the minimum number of insertions needed to make s balanced.\n \n Example 1:\n \n >>> minInsertions(s = \"(()))\")\n >>> 1\n Explanation: The second '(' has two matching '))', but the first '(' has only ')' matching. We need to add one more ')' at the end of the string to be \"(())))\" which is balanced.\n \n Example 2:\n \n >>> minInsertions(s = \"())\")\n >>> 0\n Explanation: The string is already balanced.\n \n Example 3:\n \n >>> minInsertions(s = \"))())(\")\n >>> 3\n Explanation: Add '(' to match the first '))', Add '))' to match the last '('.\n \"\"\"\n"}
{"task_id": "find-longest-awesome-substring", "prompt": "def longestAwesome(s: str) -> int:\n \"\"\"\n You are given a string s. An awesome substring is a non-empty substring of s such that we can make any number of swaps in order to make it a palindrome.\n Return the length of the maximum length awesome substring of s.\n \n Example 1:\n \n >>> longestAwesome(s = \"3242415\")\n >>> 5\n Explanation: \"24241\" is the longest awesome substring, we can form the palindrome \"24142\" with some swaps.\n \n Example 2:\n \n >>> longestAwesome(s = \"12345678\")\n >>> 1\n \n Example 3:\n \n >>> longestAwesome(s = \"213123\")\n >>> 6\n Explanation: \"213123\" is the longest awesome substring, we can form the palindrome \"231132\" with some swaps.\n \"\"\"\n"}
{"task_id": "make-the-string-great", "prompt": "def makeGood(s: str) -> str:\n \"\"\"\n Given a string s of lower and upper case English letters.\n A good string is a string which doesn't have two adjacent characters s[i] and s[i + 1] where:\n \n 0 <= i <= s.length - 2\n s[i] is a lower-case letter and s[i + 1] is the same letter but in upper-case or vice-versa.\n \n To make the string good, you can choose two adjacent characters that make the string bad and remove them. You can keep doing this until the string becomes good.\n Return the string after making it good. The answer is guaranteed to be unique under the given constraints.\n Notice that an empty string is also good.\n \n Example 1:\n \n >>> makeGood(s = \"leEeetcode\")\n >>> \"leetcode\"\n Explanation: In the first step, either you choose i = 1 or i = 2, both will result \"leEeetcode\" to be reduced to \"leetcode\".\n \n Example 2:\n \n >>> makeGood(s = \"abBAcC\")\n >>> \"\"\n Explanation: We have many possible scenarios, and all lead to the same answer. For example:\n \"abBAcC\" --> \"aAcC\" --> \"cC\" --> \"\"\n \"abBAcC\" --> \"abBA\" --> \"aA\" --> \"\"\n \n Example 3:\n \n >>> makeGood(s = \"s\")\n >>> \"s\"\n \"\"\"\n"}
{"task_id": "find-kth-bit-in-nth-binary-string", "prompt": "def findKthBit(n: int, k: int) -> str:\n \"\"\"\n Given two positive integers n and k, the binary string Sn is formed as follows:\n \n S1 = \"0\"\n Si = Si - 1 + \"1\" + reverse(invert(Si - 1)) for i > 1\n \n Where + denotes the concatenation operation, reverse(x) returns the reversed string x, and invert(x) inverts all the bits in x (0 changes to 1 and 1 changes to 0).\n For example, the first four strings in the above sequence are:\n \n S1 = \"0\"\n S2 = \"011\"\n S3 = \"0111001\"\n S4 = \"011100110110001\"\n \n Return the kth bit in Sn. It is guaranteed that k is valid for the given n.\n \n Example 1:\n \n >>> findKthBit(n = 3, k = 1)\n >>> \"0\"\n Explanation: S3 is \"0111001\".\n The 1st bit is \"0\".\n \n Example 2:\n \n >>> findKthBit(n = 4, k = 11)\n >>> \"1\"\n Explanation: S4 is \"011100110110001\".\n The 11th bit is \"1\".\n \"\"\"\n"}
{"task_id": "maximum-number-of-non-overlapping-subarrays-with-sum-equals-target", "prompt": "def maxNonOverlapping(nums: List[int], target: int) -> int:\n \"\"\"\n Given an array nums and an integer target, return the maximum number of non-empty non-overlapping subarrays such that the sum of values in each subarray is equal to target.\n \n Example 1:\n \n >>> maxNonOverlapping(nums = [1,1,1,1,1], target = 2)\n >>> 2\n Explanation: There are 2 non-overlapping subarrays [1,1,1,1,1] with sum equals to target(2).\n \n Example 2:\n \n >>> maxNonOverlapping(nums = [-1,3,5,1,4,2,-9], target = 6)\n >>> 2\n Explanation: There are 3 subarrays with sum equal to 6.\n ([5,1], [4,2], [3,5,1,4,2,-9]) but only the first 2 are non-overlapping.\n \"\"\"\n"}
{"task_id": "minimum-cost-to-cut-a-stick", "prompt": "def minCost(n: int, cuts: List[int]) -> int:\n \"\"\"\n Given a wooden stick of length n units. The stick is labelled from 0 to n. For example, a stick of length 6 is labelled as follows:\n \n Given an integer array cuts where cuts[i] denotes a position you should perform a cut at.\n You should perform the cuts in order, you can change the order of the cuts as you wish.\n The cost of one cut is the length of the stick to be cut, the total cost is the sum of costs of all cuts. When you cut a stick, it will be split into two smaller sticks (i.e. the sum of their lengths is the length of the stick before the cut). Please refer to the first example for a better explanation.\n Return the minimum total cost of the cuts.\n \n Example 1:\n \n \n >>> minCost(n = 7, cuts = [1,3,4,5])\n >>> 16\n Explanation: Using cuts order = [1, 3, 4, 5] as in the input leads to the following scenario:\n \n The first cut is done to a rod of length 7 so the cost is 7. The second cut is done to a rod of length 6 (i.e. the second part of the first cut), the third is done to a rod of length 4 and the last cut is to a rod of length 3. The total cost is 7 + 6 + 4 + 3 = 20.\n Rearranging the cuts to be [3, 5, 1, 4] for example will lead to a scenario with total cost = 16 (as shown in the example photo 7 + 4 + 3 + 2 = 16).\n Example 2:\n \n >>> minCost(n = 9, cuts = [5,6,1,4,2])\n >>> 22\n Explanation: If you try the given cuts ordering the cost will be 25.\n There are much ordering with total cost <= 25, for example, the order [4, 6, 5, 2, 1] has total cost = 22 which is the minimum possible.\n \"\"\"\n"}
{"task_id": "the-most-similar-path-in-a-graph", "prompt": "def mostSimilar(n: int, roads: List[List[int]], names: List[str], targetPath: List[str]) -> List[int]:\n \"\"\"\n We have n cities and m bi-directional roads where roads[i] = [ai, bi] connects city ai with city bi. Each city has a name consisting of exactly three upper-case English letters given in the string array names. Starting at any city x, you can reach any city y where y != x (i.e., the cities and the roads are forming an undirected connected graph).\n You will be given a string array targetPath. You should find a path in the graph of the same length and with the minimum edit distance to targetPath.\n You need to return the order of the nodes in the path with the minimum edit distance. The\u00a0path should be of the same length of targetPath and should be valid (i.e., there should be a direct road between ans[i] and ans[i + 1]). If there are multiple answers return any one of them.\n The edit distance is defined as follows:\n \n \n Example 1:\n \n \n >>> mostSimilar(n = 5, roads = [[0,2],[0,3],[1,2],[1,3],[1,4],[2,4]], names = [\"ATL\",\"PEK\",\"LAX\",\"DXB\",\"HND\"], targetPath = [\"ATL\",\"DXB\",\"HND\",\"LAX\"])\n >>> [0,2,4,2]\n Explanation: [0,2,4,2], [0,3,0,2] and [0,3,1,2] are accepted answers.\n [0,2,4,2] is equivalent to [\"ATL\",\"LAX\",\"HND\",\"LAX\"] which has edit distance = 1 with targetPath.\n [0,3,0,2] is equivalent to [\"ATL\",\"DXB\",\"ATL\",\"LAX\"] which has edit distance = 1 with targetPath.\n [0,3,1,2] is equivalent to [\"ATL\",\"DXB\",\"PEK\",\"LAX\"] which has edit distance = 1 with targetPath.\n \n Example 2:\n \n \n >>> mostSimilar(n = 4, roads = [[1,0],[2,0],[3,0],[2,1],[3,1],[3,2]], names = [\"ATL\",\"PEK\",\"LAX\",\"DXB\"], targetPath = [\"ABC\",\"DEF\",\"GHI\",\"JKL\",\"MNO\",\"PQR\",\"STU\",\"VWX\"])\n >>> [0,1,0,1,0,1,0,1]\n Explanation: Any path in this graph has edit distance = 8 with targetPath.\n \n Example 3:\n \n \n >>> mostSimilar(n = 6, roads = [[0,1],[1,2],[2,3],[3,4],[4,5]], names = [\"ATL\",\"PEK\",\"LAX\",\"ATL\",\"DXB\",\"HND\"], targetPath = [\"ATL\",\"DXB\",\"HND\",\"DXB\",\"ATL\",\"LAX\",\"PEK\"])\n >>> [3,4,5,4,3,2,1]\n Explanation: [3,4,5,4,3,2,1] is the only path with edit distance = 0 with targetPath.\n It's equivalent to [\"ATL\",\"DXB\",\"HND\",\"DXB\",\"ATL\",\"LAX\",\"PEK\"]\n \"\"\"\n"}
{"task_id": "three-consecutive-odds", "prompt": "def threeConsecutiveOdds(arr: List[int]) -> bool:\n \"\"\"\n Given an integer array arr, return true\u00a0if there are three consecutive odd numbers in the array. Otherwise, return\u00a0false.\n \n Example 1:\n \n >>> threeConsecutiveOdds(arr = [2,6,4,1])\n >>> false\n Explanation: There are no three consecutive odds.\n \n Example 2:\n \n >>> threeConsecutiveOdds(arr = [1,2,34,3,4,5,7,23,12])\n >>> true\n Explanation: [5,7,23] are three consecutive odds.\n \"\"\"\n"}
{"task_id": "minimum-operations-to-make-array-equal", "prompt": "def minOperations(n: int) -> int:\n \"\"\"\n You have an array arr of length n where arr[i] = (2 * i) + 1 for all valid values of i (i.e.,\u00a00 <= i < n).\n In one operation, you can select two indices x and y where 0 <= x, y < n and subtract 1 from arr[x] and add 1 to arr[y] (i.e., perform arr[x] -=1 and arr[y] += 1). The goal is to make all the elements of the array equal. It is guaranteed that all the elements of the array can be made equal using some operations.\n Given an integer n, the length of the array, return the minimum number of operations needed to make all the elements of arr equal.\n \n Example 1:\n \n >>> minOperations(n = 3)\n >>> 2\n Explanation: arr = [1, 3, 5]\n First operation choose x = 2 and y = 0, this leads arr to be [2, 3, 4]\n In the second operation choose x = 2 and y = 0 again, thus arr = [3, 3, 3].\n \n Example 2:\n \n >>> minOperations(n = 6)\n >>> 9\n \"\"\"\n"}
{"task_id": "magnetic-force-between-two-balls", "prompt": "def maxDistance(position: List[int], m: int) -> int:\n \"\"\"\n In the universe Earth C-137, Rick discovered a special form of magnetic force between two balls if they are put in his new invented basket. Rick has n empty baskets, the ith basket is at position[i], Morty has m balls and needs to distribute the balls into the baskets such that the minimum magnetic force between any two balls is maximum.\n Rick stated that magnetic force between two different balls at positions x and y is |x - y|.\n Given the integer array position and the integer m. Return the required force.\n \n Example 1:\n \n \n >>> maxDistance(position = [1,2,3,4,7], m = 3)\n >>> 3\n Explanation: Distributing the 3 balls into baskets 1, 4 and 7 will make the magnetic force between ball pairs [3, 3, 6]. The minimum magnetic force is 3. We cannot achieve a larger minimum magnetic force than 3.\n \n Example 2:\n \n >>> maxDistance(position = [5,4,3,2,1,1000000000], m = 2)\n >>> 999999999\n Explanation: We can use baskets 1 and 1000000000.\n \"\"\"\n"}
{"task_id": "minimum-number-of-days-to-eat-n-oranges", "prompt": "def minDays(n: int) -> int:\n \"\"\"\n There are n oranges in the kitchen and you decided to eat some of these oranges every day as follows:\n \n Eat one orange.\n If the number of remaining oranges n is divisible by 2 then you can eat n / 2 oranges.\n If the number of remaining oranges n is divisible by 3 then you can eat 2 * (n / 3) oranges.\n \n You can only choose one of the actions per day.\n Given the integer n, return the minimum number of days to eat n oranges.\n \n Example 1:\n \n >>> minDays(n = 10)\n >>> 4\n Explanation: You have 10 oranges.\n Day 1: Eat 1 orange, 10 - 1 = 9.\n Day 2: Eat 6 oranges, 9 - 2*(9/3) = 9 - 6 = 3. (Since 9 is divisible by 3)\n Day 3: Eat 2 oranges, 3 - 2*(3/3) = 3 - 2 = 1.\n Day 4: Eat the last orange 1 - 1 = 0.\n You need at least 4 days to eat the 10 oranges.\n \n Example 2:\n \n >>> minDays(n = 6)\n >>> 3\n Explanation: You have 6 oranges.\n Day 1: Eat 3 oranges, 6 - 6/2 = 6 - 3 = 3. (Since 6 is divisible by 2).\n Day 2: Eat 2 oranges, 3 - 2*(3/3) = 3 - 2 = 1. (Since 3 is divisible by 3)\n Day 3: Eat the last orange 1 - 1 = 0.\n You need at least 3 days to eat the 6 oranges.\n \"\"\"\n"}
{"task_id": "strings-differ-by-one-character", "prompt": "def differByOne(dict: List[str]) -> bool:\n \"\"\"\n Given a list of strings dict where all the strings are of the same length.\n Return true if there are 2 strings that only differ by 1 character in the same index, otherwise return false.\n \n Example 1:\n \n >>> differByOne(dict = [\"abcd\",\"acbd\", \"aacd\"])\n >>> true\n Explanation: Strings \"abcd\" and \"aacd\" differ only by one character in the index 1.\n \n Example 2:\n \n >>> differByOne(dict = [\"ab\",\"cd\",\"yz\"])\n >>> false\n \n Example 3:\n \n >>> differByOne(dict = [\"abcd\",\"cccc\",\"abyd\",\"abab\"])\n >>> true\n \"\"\"\n"}
{"task_id": "thousand-separator", "prompt": "def thousandSeparator(n: int) -> str:\n \"\"\"\n Given an integer n, add a dot (\".\") as the thousands separator and return it in string format.\n \n Example 1:\n \n >>> thousandSeparator(n = 987)\n >>> \"987\"\n \n Example 2:\n \n >>> thousandSeparator(n = 1234)\n >>> \"1.234\"\n \"\"\"\n"}
{"task_id": "minimum-number-of-vertices-to-reach-all-nodes", "prompt": "def findSmallestSetOfVertices(n: int, edges: List[List[int]]) -> List[int]:\n \"\"\"\n Given a\u00a0directed acyclic graph,\u00a0with\u00a0n\u00a0vertices numbered from\u00a00\u00a0to\u00a0n-1,\u00a0and an array\u00a0edges\u00a0where\u00a0edges[i] = [fromi, toi]\u00a0represents a directed edge from node\u00a0fromi\u00a0to node\u00a0toi.\n Find the smallest set of vertices from which all nodes in the graph are reachable. It's guaranteed that a unique solution exists.\n Notice that you can return the vertices in any order.\n \n Example 1:\n \n \n >>> findSmallestSetOfVertices(n = 6, edges = [[0,1],[0,2],[2,5],[3,4],[4,2]])\n >>> [0,3]\n Explanation: It's not possible to reach all the nodes from a single vertex. From 0 we can reach [0,1,2,5]. From 3 we can reach [3,4,2,5]. So we output [0,3].\n Example 2:\n \n \n >>> findSmallestSetOfVertices(n = 5, edges = [[0,1],[2,1],[3,1],[1,4],[2,4]])\n >>> [0,2,3]\n Explanation: Notice that vertices 0, 3 and 2 are not reachable from any other node, so we must include them. Also any of these vertices can reach nodes 1 and 4.\n \"\"\"\n"}
{"task_id": "minimum-numbers-of-function-calls-to-make-target-array", "prompt": "def minOperations(nums: List[int]) -> int:\n \"\"\"\n You are given an integer array nums. You have an integer array arr of the same length with all values set to 0 initially. You also have the following modify function:\n \n You want to use the modify function to convert arr to nums using the minimum number of calls.\n Return the minimum number of function calls to make nums from arr.\n The test cases are generated so that the answer fits in a 32-bit signed integer.\n \n Example 1:\n \n >>> minOperations(nums = [1,5])\n >>> 5\n Explanation: Increment by 1 (second element): [0, 0] to get [0, 1] (1 operation).\n Double all the elements: [0, 1] -> [0, 2] -> [0, 4] (2 operations).\n Increment by 1 (both elements) [0, 4] -> [1, 4] -> [1, 5] (2 operations).\n Total of operations: 1 + 2 + 2 = 5.\n \n Example 2:\n \n >>> minOperations(nums = [2,2])\n >>> 3\n Explanation: Increment by 1 (both elements) [0, 0] -> [0, 1] -> [1, 1] (2 operations).\n Double all the elements: [1, 1] -> [2, 2] (1 operation).\n Total of operations: 2 + 1 = 3.\n \n Example 3:\n \n >>> minOperations(nums = [4,2,5])\n >>> 6\n Explanation: (initial)[0,0,0] -> [1,0,0] -> [1,0,1] -> [2,0,2] -> [2,1,2] -> [4,2,4] -> [4,2,5](nums).\n \"\"\"\n"}
{"task_id": "detect-cycles-in-2d-grid", "prompt": "def containsCycle(grid: List[List[str]]) -> bool:\n \"\"\"\n Given a 2D array of characters grid of size m x n, you need to find if there exists any cycle consisting of the same value in grid.\n A cycle is a path of length 4 or more in the grid that starts and ends at the same cell. From a given cell, you can move to one of the cells adjacent to it - in one of the four directions (up, down, left, or right), if it has the same value of the current cell.\n Also, you cannot move to the cell that you visited in your last move. For example, the cycle (1, 1) -> (1, 2) -> (1, 1) is invalid because from (1, 2) we visited (1, 1) which was the last visited cell.\n Return true if any cycle of the same value exists in grid, otherwise, return false.\n \n Example 1:\n \n \n >>> containsCycle(grid = [[\"a\",\"a\",\"a\",\"a\"],[\"a\",\"b\",\"b\",\"a\"],[\"a\",\"b\",\"b\",\"a\"],[\"a\",\"a\",\"a\",\"a\"]])\n >>> true\n Explanation: There are two valid cycles shown in different colors in the image below:\n \n \n Example 2:\n \n \n >>> containsCycle(grid = [[\"c\",\"c\",\"c\",\"a\"],[\"c\",\"d\",\"c\",\"c\"],[\"c\",\"c\",\"e\",\"c\"],[\"f\",\"c\",\"c\",\"c\"]])\n >>> true\n Explanation: There is only one valid cycle highlighted in the image below:\n \n \n Example 3:\n \n \n >>> containsCycle(grid = [[\"a\",\"b\",\"b\"],[\"b\",\"z\",\"b\"],[\"b\",\"b\",\"a\"]])\n >>> false\n \"\"\"\n"}
{"task_id": "most-visited-sector-in-a-circular-track", "prompt": "def mostVisited(n: int, rounds: List[int]) -> List[int]:\n \"\"\"\n Given an integer n and an integer array rounds. We have a circular track which consists of n sectors labeled from 1 to n. A marathon will be held on this track, the marathon consists of m rounds. The ith round starts at sector rounds[i - 1] and ends at sector rounds[i]. For example, round 1 starts at sector rounds[0] and ends at sector rounds[1]\n Return an array of the most visited sectors sorted in ascending order.\n Notice that you circulate the track in ascending order of sector numbers in the counter-clockwise direction (See the first example).\n \n Example 1:\n \n \n >>> mostVisited(n = 4, rounds = [1,3,1,2])\n >>> [1,2]\n Explanation: The marathon starts at sector 1. The order of the visited sectors is as follows:\n 1 --> 2 --> 3 (end of round 1) --> 4 --> 1 (end of round 2) --> 2 (end of round 3 and the marathon)\n We can see that both sectors 1 and 2 are visited twice and they are the most visited sectors. Sectors 3 and 4 are visited only once.\n Example 2:\n \n >>> mostVisited(n = 2, rounds = [2,1,2,1,2,1,2,1,2])\n >>> [2]\n \n Example 3:\n \n >>> mostVisited(n = 7, rounds = [1,3,5,7])\n >>> [1,2,3,4,5,6,7]\n \"\"\"\n"}
{"task_id": "maximum-number-of-coins-you-can-get", "prompt": "def maxCoins(piles: List[int]) -> int:\n \"\"\"\n There are 3n piles of coins of varying size, you and your friends will take piles of coins as follows:\n \n In each step, you will choose any 3 piles of coins (not necessarily consecutive).\n Of your choice, Alice will pick the pile with the maximum number of coins.\n You will pick the next pile with the maximum number of coins.\n Your friend Bob will pick the last pile.\n Repeat until there are no more piles of coins.\n \n Given an array of integers piles where piles[i] is the number of coins in the ith pile.\n Return the maximum number of coins that you can have.\n \n Example 1:\n \n >>> maxCoins(piles = [2,4,1,2,7,8])\n >>> 9\n Explanation: Choose the triplet (2, 7, 8), Alice Pick the pile with 8 coins, you the pile with 7 coins and Bob the last one.\n Choose the triplet (1, 2, 4), Alice Pick the pile with 4 coins, you the pile with 2 coins and Bob the last one.\n The maximum number of coins which you can have are: 7 + 2 = 9.\n On the other hand if we choose this arrangement (1, 2, 8), (2, 4, 7) you only get 2 + 4 = 6 coins which is not optimal.\n \n Example 2:\n \n >>> maxCoins(piles = [2,4,5])\n >>> 4\n \n Example 3:\n \n >>> maxCoins(piles = [9,8,7,6,5,1,2,3,4])\n >>> 18\n \"\"\"\n"}
{"task_id": "find-latest-group-of-size-m", "prompt": "def findLatestStep(arr: List[int], m: int) -> int:\n \"\"\"\n Given an array arr that represents a permutation of numbers from 1 to n.\n You have a binary string of size n that initially has all its bits set to zero. At each step i (assuming both the binary string and arr are 1-indexed) from 1 to n, the bit at position arr[i] is set to 1.\n You are also given an integer m. Find the latest step at which there exists a group of ones of length m. A group of ones is a contiguous substring of 1's such that it cannot be extended in either direction.\n Return the latest step at which there exists a group of ones of length exactly m. If no such group exists, return -1.\n \n Example 1:\n \n >>> findLatestStep(arr = [3,5,1,2,4], m = 1)\n >>> 4\n Explanation:\n Step 1: \"00100\", groups: [\"1\"]\n Step 2: \"00101\", groups: [\"1\", \"1\"]\n Step 3: \"10101\", groups: [\"1\", \"1\", \"1\"]\n Step 4: \"11101\", groups: [\"111\", \"1\"]\n Step 5: \"11111\", groups: [\"11111\"]\n The latest step at which there exists a group of size 1 is step 4.\n \n Example 2:\n \n >>> findLatestStep(arr = [3,1,5,4,2], m = 2)\n >>> -1\n Explanation:\n Step 1: \"00100\", groups: [\"1\"]\n Step 2: \"10100\", groups: [\"1\", \"1\"]\n Step 3: \"10101\", groups: [\"1\", \"1\", \"1\"]\n Step 4: \"10111\", groups: [\"1\", \"111\"]\n Step 5: \"11111\", groups: [\"11111\"]\n No group of size 2 exists during any step.\n \"\"\"\n"}
{"task_id": "stone-game-v", "prompt": "def stoneGameV(stoneValue: List[int]) -> int:\n \"\"\"\n There are several stones arranged in a row, and each stone has an associated value which is an integer given in the array stoneValue.\n In each round of the game, Alice divides the row into two non-empty rows (i.e. left row and right row), then Bob calculates the value of each row which is the sum of the values of all the stones in this row. Bob throws away the row which has the maximum value, and Alice's score increases by the value of the remaining row. If the value of the two rows are equal, Bob lets Alice decide which row will be thrown away. The next round starts with the remaining row.\n The game ends when there is only one stone remaining. Alice's is initially zero.\n Return the maximum score that Alice can obtain.\n \n Example 1:\n \n >>> stoneGameV(stoneValue = [6,2,3,4,5,5])\n >>> 18\n Explanation: In the first round, Alice divides the row to [6,2,3], [4,5,5]. The left row has the value 11 and the right row has value 14. Bob throws away the right row and Alice's score is now 11.\n In the second round Alice divides the row to [6], [2,3]. This time Bob throws away the left row and Alice's score becomes 16 (11 + 5).\n The last round Alice has only one choice to divide the row which is [2], [3]. Bob throws away the right row and Alice's score is now 18 (16 + 2). The game ends because only one stone is remaining in the row.\n \n Example 2:\n \n >>> stoneGameV(stoneValue = [7,7,7,7,7,7,7])\n >>> 28\n \n Example 3:\n \n >>> stoneGameV(stoneValue = [4])\n >>> 0\n \"\"\"\n"}
{"task_id": "put-boxes-into-the-warehouse-i", "prompt": "def maxBoxesInWarehouse(boxes: List[int], warehouse: List[int]) -> int:\n \"\"\"\n You are given two arrays of positive integers, boxes and warehouse, representing the heights of some boxes of unit width and the heights of n rooms in a warehouse respectively. The warehouse's rooms are labelled from 0 to n - 1 from left to right where warehouse[i] (0-indexed) is the height of the ith room.\n Boxes are put into the warehouse by the following rules:\n \n Boxes cannot be stacked.\n You can rearrange the insertion order of the boxes.\n Boxes can only be pushed into the warehouse from left to right only.\n If the height of some room in the warehouse is less than the height of a box, then that box and all other boxes behind it will be stopped before that room.\n \n Return the maximum number of boxes you can put into the warehouse.\n \n Example 1:\n \n \n >>> maxBoxesInWarehouse(boxes = [4,3,4,1], warehouse = [5,3,3,4,1])\n >>> 3\n Explanation:\n \n We can first put the box of height 1 in room 4. Then we can put the box of height 3 in either of the 3 rooms 1, 2, or 3. Lastly, we can put one box of height 4 in room 0.\n There is no way we can fit all 4 boxes in the warehouse.\n \n Example 2:\n \n \n >>> maxBoxesInWarehouse(boxes = [1,2,2,3,4], warehouse = [3,4,1,2])\n >>> 3\n Explanation:\n \n Notice that it's not possible to put the box of height 4 into the warehouse since it cannot pass the first room of height 3.\n Also, for the last two rooms, 2 and 3, only boxes of height 1 can fit.\n We can fit 3 boxes maximum as shown above. The yellow box can also be put in room 2 instead.\n Swapping the orange and green boxes is also valid, or swapping one of them with the red box.\n \n Example 3:\n \n >>> maxBoxesInWarehouse(boxes = [1,2,3], warehouse = [1,2,3,4])\n >>> 1\n Explanation: Since the first room in the warehouse is of height 1, we can only put boxes of height 1.\n \"\"\"\n"}
{"task_id": "detect-pattern-of-length-m-repeated-k-or-more-times", "prompt": "def containsPattern(arr: List[int], m: int, k: int) -> bool:\n \"\"\"\n Given an array of positive integers arr, find a pattern of length m that is repeated k or more times.\n A pattern is a subarray (consecutive sub-sequence) that consists of one or more values, repeated multiple times consecutively without overlapping. A pattern is defined by its length and the number of repetitions.\n Return true if there exists a pattern of length m that is repeated k or more times, otherwise return false.\n \n Example 1:\n \n >>> containsPattern(arr = [1,2,4,4,4,4], m = 1, k = 3)\n >>> true\n Explanation: The pattern (4) of length 1 is repeated 4 consecutive times. Notice that pattern can be repeated k or more times but not less.\n \n Example 2:\n \n >>> containsPattern(arr = [1,2,1,2,1,1,1,3], m = 2, k = 2)\n >>> true\n Explanation: The pattern (1,2) of length 2 is repeated 2 consecutive times. Another valid pattern (2,1) is also repeated 2 times.\n \n Example 3:\n \n >>> containsPattern(arr = [1,2,1,2,1,3], m = 2, k = 3)\n >>> false\n Explanation: The pattern (1,2) is of length 2 but is repeated only 2 times. There is no pattern of length 2 that is repeated 3 or more times.\n \"\"\"\n"}
{"task_id": "maximum-length-of-subarray-with-positive-product", "prompt": "def getMaxLen(nums: List[int]) -> int:\n \"\"\"\n Given an array of integers nums, find the maximum length of a subarray where the product of all its elements is positive.\n A subarray of an array is a consecutive sequence of zero or more values taken out of that array.\n Return the maximum length of a subarray with positive product.\n \n Example 1:\n \n >>> getMaxLen(nums = [1,-2,-3,4])\n >>> 4\n Explanation: The array nums already has a positive product of 24.\n \n Example 2:\n \n >>> getMaxLen(nums = [0,1,-2,-3,-4])\n >>> 3\n Explanation: The longest subarray with positive product is [1,-2,-3] which has a product of 6.\n Notice that we cannot include 0 in the subarray since that'll make the product 0 which is not positive.\n Example 3:\n \n >>> getMaxLen(nums = [-1,-2,-3,0,1])\n >>> 2\n Explanation: The longest subarray with positive product is [-1,-2] or [-2,-3].\n \"\"\"\n"}
{"task_id": "minimum-number-of-days-to-disconnect-island", "prompt": "def minDays(grid: List[List[int]]) -> int:\n \"\"\"\n You are given an m x n binary grid grid where 1 represents land and 0 represents water. An island is a maximal 4-directionally (horizontal or vertical) connected group of 1's.\n The grid is said to be connected if we have exactly one island, otherwise is said disconnected.\n In one day, we are allowed to change any single land cell (1) into a water cell (0).\n Return the minimum number of days to disconnect the grid.\n \n Example 1:\n \n \n \n >>> minDays(grid = [[0,1,1,0],[0,1,1,0],[0,0,0,0]])\n >>> 2\n Explanation: We need at least 2 days to get a disconnected grid.\n Change land grid[1][1] and grid[0][2] to water and get 2 disconnected island.\n \n Example 2:\n \n \n >>> minDays(grid = [[1,1]])\n >>> 2\n Explanation: Grid of full water is also disconnected ([[1,1]] -> [[0,0]]), 0 islands.\n \"\"\"\n"}
{"task_id": "number-of-ways-to-reorder-array-to-get-same-bst", "prompt": "def numOfWays(nums: List[int]) -> int:\n \"\"\"\n Given an array nums that represents a permutation of integers from 1 to n. We are going to construct a binary search tree (BST) by inserting the elements of nums in order into an initially empty BST. Find the number of different ways to reorder nums so that the constructed BST is identical to that formed from the original array nums.\n \n For example, given nums = [2,1,3], we will have 2 as the root, 1 as a left child, and 3 as a right child. The array [2,3,1] also yields the same BST but [3,2,1] yields a different BST.\n \n Return the number of ways to reorder nums such that the BST formed is identical to the original BST formed from nums.\n Since the answer may be very large, return it modulo 109 + 7.\n \n Example 1:\n \n \n >>> numOfWays(nums = [2,1,3])\n >>> 1\n Explanation: We can reorder nums to be [2,3,1] which will yield the same BST. There are no other ways to reorder nums which will yield the same BST.\n \n Example 2:\n \n \n >>> numOfWays(nums = [3,4,5,1,2])\n >>> 5\n Explanation: The following 5 arrays will yield the same BST:\n [3,1,2,4,5]\n [3,1,4,2,5]\n [3,1,4,5,2]\n [3,4,1,2,5]\n [3,4,1,5,2]\n \n Example 3:\n \n \n >>> numOfWays(nums = [1,2,3])\n >>> 0\n Explanation: There are no other orderings of nums that will yield the same BST.\n \"\"\"\n"}
{"task_id": "matrix-diagonal-sum", "prompt": "def diagonalSum(mat: List[List[int]]) -> int:\n \"\"\"\n Given a\u00a0square\u00a0matrix\u00a0mat, return the sum of the matrix diagonals.\n Only include the sum of all the elements on the primary diagonal and all the elements on the secondary diagonal that are not part of the primary diagonal.\n \n Example 1:\n \n \n \u00a0 [4,5,6],\n \u00a0 [7,8,9]]\n >>> diagonalSum(mat = [[1,2,3],)\n >>> 25\n Explanation: Diagonals sum: 1 + 5 + 9 + 3 + 7 = 25\n Notice that element mat[1][1] = 5 is counted only once.\n \n Example 2:\n \n \u00a0 [1,1,1,1],\n \u00a0 [1,1,1,1],\n \u00a0 [1,1,1,1]]\n >>> diagonalSum(mat = [[1,1,1,1],)\n >>> 8\n \n Example 3:\n \n >>> diagonalSum(mat = [[5]])\n >>> 5\n \"\"\"\n"}
{"task_id": "number-of-ways-to-split-a-string", "prompt": "def numWays(s: str) -> int:\n \"\"\"\n Given a binary string s, you can split s into 3 non-empty strings s1, s2, and s3 where s1 + s2 + s3 = s.\n Return the number of ways s can be split such that the number of ones is the same in s1, s2, and s3. Since the answer may be too large, return it modulo 109 + 7.\n \n Example 1:\n \n >>> numWays(s = \"10101\")\n >>> 4\n Explanation: There are four ways to split s in 3 parts where each part contain the same number of letters '1'.\n \"1|010|1\"\n \"1|01|01\"\n \"10|10|1\"\n \"10|1|01\"\n \n Example 2:\n \n >>> numWays(s = \"1001\")\n >>> 0\n \n Example 3:\n \n >>> numWays(s = \"0000\")\n >>> 3\n Explanation: There are three ways to split s in 3 parts.\n \"0|0|00\"\n \"0|00|0\"\n \"00|0|0\"\n \"\"\"\n"}
{"task_id": "shortest-subarray-to-be-removed-to-make-array-sorted", "prompt": "def findLengthOfShortestSubarray(arr: List[int]) -> int:\n \"\"\"\n Given an integer array arr, remove a subarray (can be empty) from arr such that the remaining elements in arr are non-decreasing.\n Return the length of the shortest subarray to remove.\n A subarray is a contiguous subsequence of the array.\n \n Example 1:\n \n >>> findLengthOfShortestSubarray(arr = [1,2,3,10,4,2,3,5])\n >>> 3\n Explanation: The shortest subarray we can remove is [10,4,2] of length 3. The remaining elements after that will be [1,2,3,3,5] which are sorted.\n Another correct solution is to remove the subarray [3,10,4].\n \n Example 2:\n \n >>> findLengthOfShortestSubarray(arr = [5,4,3,2,1])\n >>> 4\n Explanation: Since the array is strictly decreasing, we can only keep a single element. Therefore we need to remove a subarray of length 4, either [5,4,3,2] or [4,3,2,1].\n \n Example 3:\n \n >>> findLengthOfShortestSubarray(arr = [1,2,3])\n >>> 0\n Explanation: The array is already non-decreasing. We do not need to remove any elements.\n \"\"\"\n"}
{"task_id": "count-all-possible-routes", "prompt": "def countRoutes(locations: List[int], start: int, finish: int, fuel: int) -> int:\n \"\"\"\n You are given an array of distinct positive integers locations where locations[i] represents the position of city i. You are also given integers start, finish and fuel representing the starting city, ending city, and the initial amount of fuel you have, respectively.\n At each step, if you are at city i, you can pick any city j such that j != i and 0 <= j < locations.length and move to city j. Moving from city i to city j reduces the amount of fuel you have by |locations[i] - locations[j]|. Please notice that |x| denotes the absolute value of x.\n Notice that fuel cannot become negative at any point in time, and that you are allowed to visit any city more than once (including start and finish).\n Return the count of all possible routes from start to finish. Since the answer may be too large, return it modulo 109 + 7.\n \n Example 1:\n \n >>> countRoutes(locations = [2,3,6,8,4], start = 1, finish = 3, fuel = 5)\n >>> 4\n Explanation: The following are all possible routes, each uses 5 units of fuel:\n 1 -> 3\n 1 -> 2 -> 3\n 1 -> 4 -> 3\n 1 -> 4 -> 2 -> 3\n \n Example 2:\n \n >>> countRoutes(locations = [4,3,1], start = 1, finish = 0, fuel = 6)\n >>> 5\n Explanation: The following are all possible routes:\n 1 -> 0, used fuel = 1\n 1 -> 2 -> 0, used fuel = 5\n 1 -> 2 -> 1 -> 0, used fuel = 5\n 1 -> 0 -> 1 -> 0, used fuel = 3\n 1 -> 0 -> 1 -> 0 -> 1 -> 0, used fuel = 5\n \n Example 3:\n \n >>> countRoutes(locations = [5,2,1], start = 0, finish = 2, fuel = 3)\n >>> 0\n Explanation: It is impossible to get from 0 to 2 using only 3 units of fuel since the shortest route needs 4 units of fuel.\n \"\"\"\n"}
{"task_id": "replace-all-s-to-avoid-consecutive-repeating-characters", "prompt": "def modifyString(s: str) -> str:\n \"\"\"\n Given a string s containing only lowercase English letters and the '?' character, convert all the '?' characters into lowercase letters such that the final string does not contain any consecutive repeating characters. You cannot modify the non '?' characters.\n It is guaranteed that there are no consecutive repeating characters in the given string except for '?'.\n Return the final string after all the conversions (possibly zero) have been made. If there is more than one solution, return any of them. It can be shown that an answer is always possible with the given constraints.\n \n Example 1:\n \n >>> modifyString(s = \"?zs\")\n >>> \"azs\"\n Explanation: There are 25 solutions for this problem. From \"azs\" to \"yzs\", all are valid. Only \"z\" is an invalid modification as the string will consist of consecutive repeating characters in \"zzs\".\n \n Example 2:\n \n >>> modifyString(s = \"ubv?w\")\n >>> \"ubvaw\"\n Explanation: There are 24 solutions for this problem. Only \"v\" and \"w\" are invalid modifications as the strings will consist of consecutive repeating characters in \"ubvvw\" and \"ubvww\".\n \"\"\"\n"}
{"task_id": "number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers", "prompt": "def numTriplets(nums1: List[int], nums2: List[int]) -> int:\n \"\"\"\n Given two arrays of integers nums1 and nums2, return the number of triplets formed (type 1 and type 2) under the following rules:\n \n Type 1: Triplet (i, j, k) if nums1[i]2 == nums2[j] * nums2[k] where 0 <= i < nums1.length and 0 <= j < k < nums2.length.\n Type 2: Triplet (i, j, k) if nums2[i]2 == nums1[j] * nums1[k] where 0 <= i < nums2.length and 0 <= j < k < nums1.length.\n \n \n Example 1:\n \n >>> numTriplets(nums1 = [7,4], nums2 = [5,2,8,9])\n >>> 1\n Explanation: Type 1: (1, 1, 2), nums1[1]2 = nums2[1] * nums2[2]. (42 = 2 * 8).\n \n Example 2:\n \n >>> numTriplets(nums1 = [1,1], nums2 = [1,1,1])\n >>> 9\n Explanation: All Triplets are valid, because 12 = 1 * 1.\n Type 1: (0,0,1), (0,0,2), (0,1,2), (1,0,1), (1,0,2), (1,1,2). nums1[i]2 = nums2[j] * nums2[k].\n Type 2: (0,0,1), (1,0,1), (2,0,1). nums2[i]2 = nums1[j] * nums1[k].\n \n Example 3:\n \n >>> numTriplets(nums1 = [7,7,8,3], nums2 = [1,2,9,7])\n >>> 2\n Explanation: There are 2 valid triplets.\n Type 1: (3,0,2). nums1[3]2 = nums2[0] * nums2[2].\n Type 2: (3,0,1). nums2[3]2 = nums1[0] * nums1[1].\n \"\"\"\n"}
{"task_id": "minimum-time-to-make-rope-colorful", "prompt": "def minCost(colors: str, neededTime: List[int]) -> int:\n \"\"\"\n Alice has n balloons arranged on a rope. You are given a 0-indexed string colors where colors[i] is the color of the ith balloon.\n Alice wants the rope to be colorful. She does not want two consecutive balloons to be of the same color, so she asks Bob for help. Bob can remove some balloons from the rope to make it colorful. You are given a 0-indexed integer array neededTime where neededTime[i] is the time (in seconds) that Bob needs to remove the ith balloon from the rope.\n Return the minimum time Bob needs to make the rope colorful.\n \n Example 1:\n \n \n >>> minCost(colors = \"abaac\", neededTime = [1,2,3,4,5])\n >>> 3\n Explanation: In the above image, 'a' is blue, 'b' is red, and 'c' is green.\n Bob can remove the blue balloon at index 2. This takes 3 seconds.\n There are no longer two consecutive balloons of the same color. Total time = 3.\n Example 2:\n \n \n >>> minCost(colors = \"abc\", neededTime = [1,2,3])\n >>> 0\n Explanation: The rope is already colorful. Bob does not need to remove any balloons from the rope.\n \n Example 3:\n \n \n >>> minCost(colors = \"aabaa\", neededTime = [1,2,3,4,1])\n >>> 2\n Explanation: Bob will remove the balloons at indices 0 and 4. Each balloons takes 1 second to remove.\n There are no longer two consecutive balloons of the same color. Total time = 1 + 1 = 2.\n \"\"\"\n"}
{"task_id": "remove-max-number-of-edges-to-keep-graph-fully-traversable", "prompt": "def maxNumEdgesToRemove(n: int, edges: List[List[int]]) -> int:\n \"\"\"\n Alice and Bob have an undirected graph of n nodes and three types of edges:\n \n Type 1: Can be traversed by Alice only.\n Type 2: Can be traversed by Bob only.\n Type 3: Can be traversed by both Alice and Bob.\n \n Given an array edges where edges[i] = [typei, ui, vi] represents a bidirectional edge of type typei between nodes ui and vi, find the maximum number of edges you can remove so that after removing the edges, the graph can still be fully traversed by both Alice and Bob. The graph is fully traversed by Alice and Bob if starting from any node, they can reach all other nodes.\n Return the maximum number of edges you can remove, or return -1 if Alice and Bob cannot fully traverse the graph.\n \n Example 1:\n \n \n >>> maxNumEdgesToRemove(n = 4, edges = [[3,1,2],[3,2,3],[1,1,3],[1,2,4],[1,1,2],[2,3,4]])\n >>> 2\n Explanation: If we remove the 2 edges [1,1,2] and [1,1,3]. The graph will still be fully traversable by Alice and Bob. Removing any additional edge will not make it so. So the maximum number of edges we can remove is 2.\n \n Example 2:\n \n \n >>> maxNumEdgesToRemove(n = 4, edges = [[3,1,2],[3,2,3],[1,1,4],[2,1,4]])\n >>> 0\n Explanation: Notice that removing any edge will not make the graph fully traversable by Alice and Bob.\n \n Example 3:\n \n \n >>> maxNumEdgesToRemove(n = 4, edges = [[3,2,3],[1,1,2],[2,3,4]])\n >>> -1\n Explanation: In the current graph, Alice cannot reach node 4 from the other nodes. Likewise, Bob cannot reach 1. Therefore it's impossible to make the graph fully traversable.\n \"\"\"\n"}
{"task_id": "put-boxes-into-the-warehouse-ii", "prompt": "def maxBoxesInWarehouse(boxes: List[int], warehouse: List[int]) -> int:\n \"\"\"\n You are given two arrays of positive integers, boxes and warehouse, representing the heights of some boxes of unit width and the heights of n rooms in a warehouse respectively. The warehouse's rooms are labeled from 0 to n - 1 from left to right where warehouse[i] (0-indexed) is the height of the ith room.\n Boxes are put into the warehouse by the following rules:\n \n Boxes cannot be stacked.\n You can rearrange the insertion order of the boxes.\n Boxes can be pushed into the warehouse from either side (left or right)\n If the height of some room in the warehouse is less than the height of a box, then that box and all other boxes behind it will be stopped before that room.\n \n Return the maximum number of boxes you can put into the warehouse.\n \n Example 1:\n \n \n >>> maxBoxesInWarehouse(boxes = [1,2,2,3,4], warehouse = [3,4,1,2])\n >>> 4\n Explanation:\n \n We can store the boxes in the following order:\n 1- Put the yellow box in room 2 from either the left or right side.\n 2- Put the orange box in room 3 from the right side.\n 3- Put the green box in room 1 from the left side.\n 4- Put the red box in room 0 from the left side.\n Notice that there are other valid ways to put 4 boxes such as swapping the red and green boxes or the red and orange boxes.\n \n Example 2:\n \n \n >>> maxBoxesInWarehouse(boxes = [3,5,5,2], warehouse = [2,1,3,4,5])\n >>> 3\n Explanation:\n \n It is not possible to put the two boxes of height 5 in the warehouse since there's only 1 room of height >= 5.\n Other valid solutions are to put the green box in room 2 or to put the orange box first in room 2 before putting the green and red boxes.\n \"\"\"\n"}
{"task_id": "special-positions-in-a-binary-matrix", "prompt": "def numSpecial(mat: List[List[int]]) -> int:\n \"\"\"\n Given an m x n binary matrix mat, return the number of special positions in mat.\n A position (i, j) is called special if mat[i][j] == 1 and all other elements in row i and column j are 0 (rows and columns are 0-indexed).\n \n Example 1:\n \n \n >>> numSpecial(mat = [[1,0,0],[0,0,1],[1,0,0]])\n >>> 1\n Explanation: (1, 2) is a special position because mat[1][2] == 1 and all other elements in row 1 and column 2 are 0.\n \n Example 2:\n \n \n >>> numSpecial(mat = [[1,0,0],[0,1,0],[0,0,1]])\n >>> 3\n Explanation: (0, 0), (1, 1) and (2, 2) are special positions.\n \"\"\"\n"}
{"task_id": "count-unhappy-friends", "prompt": "def unhappyFriends(n: int, preferences: List[List[int]], pairs: List[List[int]]) -> int:\n \"\"\"\n You are given a list of\u00a0preferences\u00a0for\u00a0n\u00a0friends, where n is always even.\n For each person i,\u00a0preferences[i]\u00a0contains\u00a0a list of friends\u00a0sorted in the order of preference. In other words, a friend earlier in the list is more preferred than a friend later in the list.\u00a0Friends in\u00a0each list are\u00a0denoted by integers from 0 to n-1.\n All the friends are divided into pairs.\u00a0The pairings are\u00a0given in a list\u00a0pairs,\u00a0where pairs[i] = [xi, yi] denotes xi\u00a0is paired with yi and yi is paired with xi.\n However, this pairing may cause some of the friends to be unhappy.\u00a0A friend x\u00a0is unhappy if x\u00a0is paired with y\u00a0and there exists a friend u\u00a0who\u00a0is paired with v\u00a0but:\n \n x\u00a0prefers u\u00a0over y,\u00a0and\n u\u00a0prefers x\u00a0over v.\n \n Return the number of unhappy friends.\n \n Example 1:\n \n >>> unhappyFriends(n = 4, preferences = [[1, 2, 3], [3, 2, 0], [3, 1, 0], [1, 2, 0]], pairs = [[0, 1], [2, 3]])\n >>> 2\n Explanation:\n Friend 1 is unhappy because:\n - 1 is paired with 0 but prefers 3 over 0, and\n - 3 prefers 1 over 2.\n Friend 3 is unhappy because:\n - 3 is paired with 2 but prefers 1 over 2, and\n - 1 prefers 3 over 0.\n Friends 0 and 2 are happy.\n \n Example 2:\n \n >>> unhappyFriends(n = 2, preferences = [[1], [0]], pairs = [[1, 0]])\n >>> 0\n Explanation: Both friends 0 and 1 are happy.\n \n Example 3:\n \n >>> unhappyFriends(n = 4, preferences = [[1, 3, 2], [2, 3, 0], [1, 3, 0], [0, 2, 1]], pairs = [[1, 3], [0, 2]])\n >>> 4\n \"\"\"\n"}
{"task_id": "min-cost-to-connect-all-points", "prompt": "def minCostConnectPoints(points: List[List[int]]) -> int:\n \"\"\"\n You are given an array points representing integer coordinates of some points on a 2D-plane, where points[i] = [xi, yi].\n The cost of connecting two points [xi, yi] and [xj, yj] is the manhattan distance between them: |xi - xj| + |yi - yj|, where |val| denotes the absolute value of val.\n Return the minimum cost to make all points connected. All points are connected if there is exactly one simple path between any two points.\n \n Example 1:\n \n \n >>> minCostConnectPoints(points = [[0,0],[2,2],[3,10],[5,2],[7,0]])\n >>> 20\n Explanation:\n \n We can connect the points as shown above to get the minimum cost of 20.\n Notice that there is a unique path between every pair of points.\n \n Example 2:\n \n >>> minCostConnectPoints(points = [[3,12],[-2,5],[-4,1]])\n >>> 18\n \"\"\"\n"}
{"task_id": "check-if-string-is-transformable-with-substring-sort-operations", "prompt": "def isTransformable(s: str, t: str) -> bool:\n \"\"\"\n Given two strings s and t, transform string s into string t using the following operation any number of times:\n \n Choose a non-empty substring in s and sort it in place so the characters are in ascending order.\n \n \n For example, applying the operation on the underlined substring in \"14234\" results in \"12344\".\n \n \n \n Return true if it is possible to transform s into t. Otherwise, return false.\n A substring is a contiguous sequence of characters within a string.\n \n Example 1:\n \n >>> isTransformable(s = \"84532\", t = \"34852\")\n >>> true\n Explanation: You can transform s into t using the following sort operations:\n \"84532\" (from index 2 to 3) -> \"84352\"\n \"84352\" (from index 0 to 2) -> \"34852\"\n \n Example 2:\n \n >>> isTransformable(s = \"34521\", t = \"23415\")\n >>> true\n Explanation: You can transform s into t using the following sort operations:\n \"34521\" -> \"23451\"\n \"23451\" -> \"23415\"\n \n Example 3:\n \n >>> isTransformable(s = \"12345\", t = \"12435\")\n >>> false\n \"\"\"\n"}
{"task_id": "sum-of-all-odd-length-subarrays", "prompt": "def sumOddLengthSubarrays(arr: List[int]) -> int:\n \"\"\"\n Given an array of positive integers arr, return the sum of all possible odd-length subarrays of arr.\n A subarray is a contiguous subsequence of the array.\n \n Example 1:\n \n >>> sumOddLengthSubarrays(arr = [1,4,2,5,3])\n >>> 58\n Explanation: The odd-length subarrays of arr and their sums are:\n [1] = 1\n [4] = 4\n [2] = 2\n [5] = 5\n [3] = 3\n [1,4,2] = 7\n [4,2,5] = 11\n [2,5,3] = 10\n [1,4,2,5,3] = 15\n If we add all these together we get 1 + 4 + 2 + 5 + 3 + 7 + 11 + 10 + 15 = 58\n Example 2:\n \n >>> sumOddLengthSubarrays(arr = [1,2])\n >>> 3\n Explanation: There are only 2 subarrays of odd length, [1] and [2]. Their sum is 3.\n Example 3:\n \n >>> sumOddLengthSubarrays(arr = [10,11,12])\n >>> 66\n \"\"\"\n"}
{"task_id": "maximum-sum-obtained-of-any-permutation", "prompt": "def maxSumRangeQuery(nums: List[int], requests: List[List[int]]) -> int:\n \"\"\"\n We have an array of integers, nums, and an array of requests where requests[i] = [starti, endi]. The ith request asks for the sum of nums[starti] + nums[starti + 1] + ... + nums[endi - 1] + nums[endi]. Both starti and endi are 0-indexed.\n Return the maximum total sum of all requests among all permutations of nums.\n Since the answer may be too large, return it modulo 109 + 7.\n \n Example 1:\n \n >>> maxSumRangeQuery(nums = [1,2,3,4,5], requests = [[1,3],[0,1]])\n >>> 19\n Explanation: One permutation of nums is [2,1,3,4,5] with the following result:\n requests[0] -> nums[1] + nums[2] + nums[3] = 1 + 3 + 4 = 8\n requests[1] -> nums[0] + nums[1] = 2 + 1 = 3\n Total sum: 8 + 3 = 11.\n A permutation with a higher total sum is [3,5,4,2,1] with the following result:\n requests[0] -> nums[1] + nums[2] + nums[3] = 5 + 4 + 2 = 11\n requests[1] -> nums[0] + nums[1] = 3 + 5 = 8\n Total sum: 11 + 8 = 19, which is the best that you can do.\n \n Example 2:\n \n >>> maxSumRangeQuery(nums = [1,2,3,4,5,6], requests = [[0,1]])\n >>> 11\n Explanation: A permutation with the max total sum is [6,5,4,3,2,1] with request sums [11].\n Example 3:\n \n >>> maxSumRangeQuery(nums = [1,2,3,4,5,10], requests = [[0,2],[1,3],[1,1]])\n >>> 47\n Explanation: A permutation with the max total sum is [4,10,5,3,2,1] with request sums [19,18,10].\n \"\"\"\n"}
{"task_id": "make-sum-divisible-by-p", "prompt": "def minSubarray(nums: List[int], p: int) -> int:\n \"\"\"\n Given an array of positive integers nums, remove the smallest subarray (possibly empty) such that the sum of the remaining elements is divisible by p. It is not allowed to remove the whole array.\n Return the length of the smallest subarray that you need to remove, or -1 if it's impossible.\n A subarray is defined as a contiguous block of elements in the array.\n \n Example 1:\n \n >>> minSubarray(nums = [3,1,4,2], p = 6)\n >>> 1\n Explanation: The sum of the elements in nums is 10, which is not divisible by 6. We can remove the subarray [4], and the sum of the remaining elements is 6, which is divisible by 6.\n \n Example 2:\n \n >>> minSubarray(nums = [6,3,5,2], p = 9)\n >>> 2\n Explanation: We cannot remove a single element to get a sum divisible by 9. The best way is to remove the subarray [5,2], leaving us with [6,3] with sum 9.\n \n Example 3:\n \n >>> minSubarray(nums = [1,2,3], p = 3)\n >>> 0\n Explanation: Here the sum is 6. which is already divisible by 3. Thus we do not need to remove anything.\n \"\"\"\n"}
{"task_id": "strange-printer-ii", "prompt": "def isPrintable(targetGrid: List[List[int]]) -> bool:\n \"\"\"\n There is a strange printer with the following two special requirements:\n \n On each turn, the printer will print a solid rectangular pattern of a single color on the grid. This will cover up the existing colors in the rectangle.\n Once the printer has used a color for the above operation, the same color cannot be used again.\n \n You are given a m x n matrix targetGrid, where targetGrid[row][col] is the color in the position (row, col) of the grid.\n Return true if it is possible to print the matrix targetGrid, otherwise, return false.\n \n Example 1:\n \n \n >>> isPrintable(targetGrid = [[1,1,1,1],[1,2,2,1],[1,2,2,1],[1,1,1,1]])\n >>> true\n \n Example 2:\n \n \n >>> isPrintable(targetGrid = [[1,1,1,1],[1,1,3,3],[1,1,3,4],[5,5,1,4]])\n >>> true\n \n Example 3:\n \n >>> isPrintable(targetGrid = [[1,2,1],[2,1,2],[1,2,1]])\n >>> false\n Explanation: It is impossible to form targetGrid because it is not allowed to print the same color in different turns.\n \"\"\"\n"}
{"task_id": "rearrange-spaces-between-words", "prompt": "def reorderSpaces(text: str) -> str:\n \"\"\"\n You are given a string text of words that are placed among some number of spaces. Each word consists of one or more lowercase English letters and are separated by at least one space. It's guaranteed that text contains at least one word.\n Rearrange the spaces so that there is an equal number of spaces between every pair of adjacent words and that number is maximized. If you cannot redistribute all the spaces equally, place the extra spaces at the end, meaning the returned string should be the same length as text.\n Return the string after rearranging the spaces.\n \n Example 1:\n \n >>> reorderSpaces(text = \" this is a sentence \")\n >>> \"this is a sentence\"\n Explanation: There are a total of 9 spaces and 4 words. We can evenly divide the 9 spaces between the words: 9 / (4-1) = 3 spaces.\n \n Example 2:\n \n >>> reorderSpaces(text = \" practice makes perfect\")\n >>> \"practice makes perfect \"\n Explanation: There are a total of 7 spaces and 3 words. 7 / (3-1) = 3 spaces plus 1 extra space. We place this extra space at the end of the string.\n \"\"\"\n"}
{"task_id": "split-a-string-into-the-max-number-of-unique-substrings", "prompt": "def maxUniqueSplit(s: str) -> int:\n \"\"\"\n Given a string\u00a0s,\u00a0return the maximum\u00a0number of unique substrings that the given string can be split into.\n You can split string\u00a0s into any list of\u00a0non-empty substrings, where the concatenation of the substrings forms the original string.\u00a0However, you must split the substrings such that all of them are unique.\n A substring is a contiguous sequence of characters within a string.\n \n Example 1:\n \n >>> maxUniqueSplit(s = \"ababccc\")\n >>> 5\n Explanation: One way to split maximally is ['a', 'b', 'ab', 'c', 'cc']. Splitting like ['a', 'b', 'a', 'b', 'c', 'cc'] is not valid as you have 'a' and 'b' multiple times.\n \n Example 2:\n \n >>> maxUniqueSplit(s = \"aba\")\n >>> 2\n Explanation: One way to split maximally is ['a', 'ba'].\n \n Example 3:\n \n >>> maxUniqueSplit(s = \"aa\")\n >>> 1\n Explanation: It is impossible to split the string any further.\n \"\"\"\n"}
{"task_id": "maximum-non-negative-product-in-a-matrix", "prompt": "def maxProductPath(grid: List[List[int]]) -> int:\n \"\"\"\n You are given a m x n matrix grid. Initially, you are located at the top-left corner (0, 0), and in each step, you can only move right or down in the matrix.\n Among all possible paths starting from the top-left corner (0, 0) and ending in the bottom-right corner (m - 1, n - 1), find the path with the maximum non-negative product. The product of a path is the product of all integers in the grid cells visited along the path.\n Return the maximum non-negative product modulo 109 + 7. If the maximum product is negative, return -1.\n Notice that the modulo is performed after getting the maximum product.\n \n Example 1:\n \n \n >>> maxProductPath(grid = [[-1,-2,-3],[-2,-3,-3],[-3,-3,-2]])\n >>> -1\n Explanation: It is not possible to get non-negative product in the path from (0, 0) to (2, 2), so return -1.\n \n Example 2:\n \n \n >>> maxProductPath(grid = [[1,-2,1],[1,-2,1],[3,-4,1]])\n >>> 8\n Explanation: Maximum non-negative product is shown (1 * 1 * -2 * -4 * 1 = 8).\n \n Example 3:\n \n \n >>> maxProductPath(grid = [[1,3],[0,-4]])\n >>> 0\n Explanation: Maximum non-negative product is shown (1 * 0 * -4 = 0).\n \"\"\"\n"}
{"task_id": "minimum-cost-to-connect-two-groups-of-points", "prompt": "def connectTwoGroups(cost: List[List[int]]) -> int:\n \"\"\"\n You are given two groups of points where the first group has size1 points, the second group has size2 points, and size1 >= size2.\n The cost of the connection between any two points are given in an size1 x size2 matrix where cost[i][j] is the cost of connecting point i of the first group and point j of the second group. The groups are connected if each point in both groups is connected to one or more points in the opposite group. In other words, each point in the first group must be connected to at least one point in the second group, and each point in the second group must be connected to at least one point in the first group.\n Return the minimum cost it takes to connect the two groups.\n \n Example 1:\n \n \n >>> connectTwoGroups(cost = [[15, 96], [36, 2]])\n >>> 17\n Explanation: The optimal way of connecting the groups is:\n 1--A\n 2--B\n This results in a total cost of 17.\n \n Example 2:\n \n \n >>> connectTwoGroups(cost = [[1, 3, 5], [4, 1, 1], [1, 5, 3]])\n >>> 4\n Explanation: The optimal way of connecting the groups is:\n 1--A\n 2--B\n 2--C\n 3--A\n This results in a total cost of 4.\n Note that there are multiple points connected to point 2 in the first group and point A in the second group. This does not matter as there is no limit to the number of points that can be connected. We only care about the minimum total cost.\n \n Example 3:\n \n >>> connectTwoGroups(cost = [[2, 5, 1], [3, 4, 7], [8, 1, 2], [6, 2, 4], [3, 8, 8]])\n >>> 10\n \"\"\"\n"}
{"task_id": "crawler-log-folder", "prompt": "def minOperations(logs: List[str]) -> int:\n \"\"\"\n The Leetcode file system keeps a log each time some user performs a change folder operation.\n The operations are described below:\n \n \"../\" : Move to the parent folder of the current folder. (If you are already in the main folder, remain in the same folder).\n \"./\" : Remain in the same folder.\n \"x/\" : Move to the child folder named x (This folder is guaranteed to always exist).\n \n You are given a list of strings logs where logs[i] is the operation performed by the user at the ith step.\n The file system starts in the main folder, then the operations in logs are performed.\n Return the minimum number of operations needed to go back to the main folder after the change folder operations.\n \n Example 1:\n \n \n >>> minOperations(logs = [\"d1/\",\"d2/\",\"../\",\"d21/\",\"./\"])\n >>> 2\n Explanation: Use this change folder operation \"../\" 2 times and go back to the main folder.\n \n Example 2:\n \n \n >>> minOperations(logs = [\"d1/\",\"d2/\",\"./\",\"d3/\",\"../\",\"d31/\"])\n >>> 3\n \n Example 3:\n \n >>> minOperations(logs = [\"d1/\",\"../\",\"../\",\"../\"])\n >>> 0\n \"\"\"\n"}
{"task_id": "maximum-profit-of-operating-a-centennial-wheel", "prompt": "def minOperationsMaxProfit(customers: List[int], boardingCost: int, runningCost: int) -> int:\n \"\"\"\n You are the operator of a Centennial Wheel that has four gondolas, and each gondola has room for up to four people. You have the ability to rotate the gondolas counterclockwise, which costs you runningCost dollars.\n You are given an array customers of length n where customers[i] is the number of new customers arriving just before the ith rotation (0-indexed). This means you must rotate the wheel i times before the customers[i] customers arrive. You cannot make customers wait if there is room in the gondola. Each customer pays boardingCost dollars when they board on the gondola closest to the ground and will exit once that gondola reaches the ground again.\n You can stop the wheel at any time, including before serving all customers. If you decide to stop serving customers, all subsequent rotations are free in order to get all the customers down safely. Note that if there are currently more than four customers waiting at the wheel, only four will board the gondola, and the rest will wait for the next rotation.\n Return the minimum number of rotations you need to perform to maximize your profit. If there is no scenario where the profit is positive, return -1.\n \n Example 1:\n \n \n >>> minOperationsMaxProfit(customers = [8,3], boardingCost = 5, runningCost = 6)\n >>> 3\n Explanation: The numbers written on the gondolas are the number of people currently there.\n 1. 8 customers arrive, 4 board and 4 wait for the next gondola, the wheel rotates. Current profit is 4 * $5 - 1 * $6 = $14.\n 2. 3 customers arrive, the 4 waiting board the wheel and the other 3 wait, the wheel rotates. Current profit is 8 * $5 - 2 * $6 = $28.\n 3. The final 3 customers board the gondola, the wheel rotates. Current profit is 11 * $5 - 3 * $6 = $37.\n The highest profit was $37 after rotating the wheel 3 times.\n \n Example 2:\n \n >>> minOperationsMaxProfit(customers = [10,9,6], boardingCost = 6, runningCost = 4)\n >>> 7\n Explanation:\n 1. 10 customers arrive, 4 board and 6 wait for the next gondola, the wheel rotates. Current profit is 4 * $6 - 1 * $4 = $20.\n 2. 9 customers arrive, 4 board and 11 wait (2 originally waiting, 9 newly waiting), the wheel rotates. Current profit is 8 * $6 - 2 * $4 = $40.\n 3. The final 6 customers arrive, 4 board and 13 wait, the wheel rotates. Current profit is 12 * $6 - 3 * $4 = $60.\n 4. 4 board and 9 wait, the wheel rotates. Current profit is 16 * $6 - 4 * $4 = $80.\n 5. 4 board and 5 wait, the wheel rotates. Current profit is 20 * $6 - 5 * $4 = $100.\n 6. 4 board and 1 waits, the wheel rotates. Current profit is 24 * $6 - 6 * $4 = $120.\n 7. 1 boards, the wheel rotates. Current profit is 25 * $6 - 7 * $4 = $122.\n The highest profit was $122 after rotating the wheel 7 times.\n \n Example 3:\n \n >>> minOperationsMaxProfit(customers = [3,4,0,5,1], boardingCost = 1, runningCost = 92)\n >>> -1\n Explanation:\n 1. 3 customers arrive, 3 board and 0 wait, the wheel rotates. Current profit is 3 * $1 - 1 * $92 = -$89.\n 2. 4 customers arrive, 4 board and 0 wait, the wheel rotates. Current profit is 7 * $1 - 2 * $92 = -$177.\n 3. 0 customers arrive, 0 board and 0 wait, the wheel rotates. Current profit is 7 * $1 - 3 * $92 = -$269.\n 4. 5 customers arrive, 4 board and 1 waits, the wheel rotates. Current profit is 11 * $1 - 4 * $92 = -$357.\n 5. 1 customer arrives, 2 board and 0 wait, the wheel rotates. Current profit is 13 * $1 - 5 * $92 = -$447.\n The profit was never positive, so return -1.\n \"\"\"\n"}
{"task_id": "maximum-number-of-achievable-transfer-requests", "prompt": "def maximumRequests(n: int, requests: List[List[int]]) -> int:\n \"\"\"\n We have n buildings numbered from 0 to n - 1. Each building has a number of employees. It's transfer season, and some employees want to change the building they reside in.\n You are given an array requests where requests[i] = [fromi, toi] represents an employee's request to transfer from building fromi to building toi.\n All buildings are full, so a list of requests is achievable only if for each building, the net change in employee transfers is zero. This means the number of employees leaving is equal to the number of employees moving in. For example if n = 3 and two employees are leaving building 0, one is leaving building 1, and one is leaving building 2, there should be two employees moving to building 0, one employee moving to building 1, and one employee moving to building 2.\n Return the maximum number of achievable requests.\n \n Example 1:\n \n \n >>> maximumRequests(n = 5, requests = [[0,1],[1,0],[0,1],[1,2],[2,0],[3,4]])\n >>> 5\n Explantion: Let's see the requests:\n From building 0 we have employees x and y and both want to move to building 1.\n From building 1 we have employees a and b and they want to move to buildings 2 and 0 respectively.\n From building 2 we have employee z and they want to move to building 0.\n From building 3 we have employee c and they want to move to building 4.\n From building 4 we don't have any requests.\n We can achieve the requests of users x and b by swapping their places.\n We can achieve the requests of users y, a and z by swapping the places in the 3 buildings.\n \n Example 2:\n \n \n >>> maximumRequests(n = 3, requests = [[0,0],[1,2],[2,1]])\n >>> 3\n Explantion: Let's see the requests:\n From building 0 we have employee x and they want to stay in the same building 0.\n From building 1 we have employee y and they want to move to building 2.\n From building 2 we have employee z and they want to move to building 1.\n We can achieve all the requests.\n Example 3:\n \n >>> maximumRequests(n = 4, requests = [[0,3],[3,1],[1,2],[2,0]])\n >>> 4\n \"\"\"\n"}
{"task_id": "find-nearest-right-node-in-binary-tree", "prompt": "# class TreeNode:\n# def __init__(val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def findNearestRightNode(root: TreeNode, u: TreeNode) -> Optional[TreeNode]:\n \"\"\"\n Given the root of a binary tree and a node u in the tree, return the nearest node on the same level that is to the right of u, or return null if u is the rightmost node in its level.\n \n Example 1:\n \n \n >>> __init__(root = [1,2,3,null,4,5,6], u = 4)\n >>> 5\n Explanation: The nearest node on the same level to the right of node 4 is node 5.\n \n Example 2:\n \n \n >>> __init__(root = [3,null,4,2], u = 2)\n >>> null\n Explanation: There are no nodes to the right of 2.\n \"\"\"\n"}
{"task_id": "alert-using-same-key-card-three-or-more-times-in-a-one-hour-period", "prompt": "def alertNames(keyName: List[str], keyTime: List[str]) -> List[str]:\n \"\"\"\n LeetCode company workers use key-cards to unlock office doors. Each time a worker uses their key-card, the security system saves the worker's name and the time when it was used. The system emits an alert if any worker uses the key-card three or more times in a one-hour period.\n You are given a list of strings keyName and keyTime where [keyName[i], keyTime[i]] corresponds to a person's name and the time when their key-card was used in a single day.\n Access times are given in the 24-hour time format \"HH:MM\", such as \"23:51\" and \"09:49\".\n Return a list of unique worker names who received an alert for frequent keycard use. Sort the names in ascending order alphabetically.\n Notice that \"10:00\" - \"11:00\" is considered to be within a one-hour period, while \"22:51\" - \"23:52\" is not considered to be within a one-hour period.\n \n Example 1:\n \n >>> alertNames(keyName = [\"daniel\",\"daniel\",\"daniel\",\"luis\",\"luis\",\"luis\",\"luis\"], keyTime = [\"10:00\",\"10:40\",\"11:00\",\"09:00\",\"11:00\",\"13:00\",\"15:00\"])\n >>> [\"daniel\"]\n Explanation: \"daniel\" used the keycard 3 times in a one-hour period (\"10:00\",\"10:40\", \"11:00\").\n \n Example 2:\n \n >>> alertNames(keyName = [\"alice\",\"alice\",\"alice\",\"bob\",\"bob\",\"bob\",\"bob\"], keyTime = [\"12:01\",\"12:00\",\"18:00\",\"21:00\",\"21:20\",\"21:30\",\"23:00\"])\n >>> [\"bob\"]\n Explanation: \"bob\" used the keycard 3 times in a one-hour period (\"21:00\",\"21:20\", \"21:30\").\n \"\"\"\n"}
{"task_id": "find-valid-matrix-given-row-and-column-sums", "prompt": "def restoreMatrix(rowSum: List[int], colSum: List[int]) -> List[List[int]]:\n \"\"\"\n You are given two arrays rowSum and colSum of non-negative integers where rowSum[i] is the sum of the elements in the ith row and colSum[j] is the sum of the elements of the jth column of a 2D matrix. In other words, you do not know the elements of the matrix, but you do know the sums of each row and column.\n Find any matrix of non-negative integers of size rowSum.length x colSum.length that satisfies the rowSum and colSum requirements.\n Return a 2D array representing any matrix that fulfills the requirements. It's guaranteed that at least one matrix that fulfills the requirements exists.\n \n Example 1:\n \n >>> restoreMatrix(rowSum = [3,8], colSum = [4,7])\n >>> [[3,0],\n [1,7]]\n Explanation:\n 0th row: 3 + 0 = 3 == rowSum[0]\n 1st row: 1 + 7 = 8 == rowSum[1]\n 0th column: 3 + 1 = 4 == colSum[0]\n 1st column: 0 + 7 = 7 == colSum[1]\n The row and column sums match, and all matrix elements are non-negative.\n Another possible matrix is: [[1,2],\n [3,5]]\n \n Example 2:\n \n >>> restoreMatrix(rowSum = [5,7,10], colSum = [8,6,8])\n >>> [[0,5,0],\n [6,1,0],\n [2,0,8]]\n \"\"\"\n"}
{"task_id": "find-servers-that-handled-most-number-of-requests", "prompt": "def busiestServers(k: int, arrival: List[int], load: List[int]) -> List[int]:\n \"\"\"\n You have k servers numbered from 0 to k-1 that are being used to handle multiple requests simultaneously. Each server has infinite computational capacity but cannot handle more than one request at a time. The requests are assigned to servers according to a specific algorithm:\n \n The ith (0-indexed) request arrives.\n If all servers are busy, the request is dropped (not handled at all).\n If the (i % k)th server is available, assign the request to that server.\n Otherwise, assign the request to the next available server (wrapping around the list of servers and starting from 0 if necessary). For example, if the ith server is busy, try to assign the request to the (i+1)th server, then the (i+2)th server, and so on.\n \n You are given a strictly increasing array arrival of positive integers, where arrival[i] represents the arrival time of the ith request, and another array load, where load[i] represents the load of the ith request (the time it takes to complete). Your goal is to find the busiest server(s). A server is considered busiest if it handled the most number of requests successfully among all the servers.\n Return a list containing the IDs (0-indexed) of the busiest server(s). You may return the IDs in any order.\n \n Example 1:\n \n \n >>> busiestServers(k = 3, arrival = [1,2,3,4,5], load = [5,2,3,3,3])\n >>> [1]\n Explanation:\n All of the servers start out available.\n The first 3 requests are handled by the first 3 servers in order.\n Request 3 comes in. Server 0 is busy, so it's assigned to the next available server, which is 1.\n Request 4 comes in. It cannot be handled since all servers are busy, so it is dropped.\n Servers 0 and 2 handled one request each, while server 1 handled two requests. Hence server 1 is the busiest server.\n \n Example 2:\n \n >>> busiestServers(k = 3, arrival = [1,2,3,4], load = [1,2,1,2])\n >>> [0]\n Explanation:\n The first 3 requests are handled by first 3 servers.\n Request 3 comes in. It is handled by server 0 since the server is available.\n Server 0 handled two requests, while servers 1 and 2 handled one request each. Hence server 0 is the busiest server.\n \n Example 3:\n \n >>> busiestServers(k = 3, arrival = [1,2,3], load = [10,12,11])\n >>> [0,1,2]\n Explanation: Each server handles a single request, so they are all considered the busiest.\n \"\"\"\n"}
{"task_id": "special-array-with-x-elements-greater-than-or-equal-x", "prompt": "def specialArray(nums: List[int]) -> int:\n \"\"\"\n You are given an array nums of non-negative integers. nums is considered special if there exists a number x such that there are exactly x numbers in nums that are greater than or equal to x.\n Notice that x does not have to be an element in nums.\n Return x if the array is special, otherwise, return -1. It can be proven that if nums is special, the value for x is unique.\n \n Example 1:\n \n >>> specialArray(nums = [3,5])\n >>> 2\n Explanation: There are 2 values (3 and 5) that are greater than or equal to 2.\n \n Example 2:\n \n >>> specialArray(nums = [0,0])\n >>> -1\n Explanation: No numbers fit the criteria for x.\n If x = 0, there should be 0 numbers >= x, but there are 2.\n If x = 1, there should be 1 number >= x, but there are 0.\n If x = 2, there should be 2 numbers >= x, but there are 0.\n x cannot be greater since there are only 2 numbers in nums.\n \n Example 3:\n \n >>> specialArray(nums = [0,4,3,0,4])\n >>> 3\n Explanation: There are 3 values that are greater than or equal to 3.\n \"\"\"\n"}
{"task_id": "even-odd-tree", "prompt": "# class TreeNode:\n# def __init__(val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def isEvenOddTree(root: Optional[TreeNode]) -> bool:\n \"\"\"\n A binary tree is named Even-Odd if it meets the following conditions:\n \n The root of the binary tree is at level index 0, its children are at level index 1, their children are at level index 2, etc.\n For every even-indexed level, all nodes at the level have odd integer values in strictly increasing order (from left to right).\n For every odd-indexed level, all nodes at the level have even integer values in strictly decreasing order (from left to right).\n \n Given the root of a binary tree, return true if the binary tree is Even-Odd, otherwise return false.\n \n Example 1:\n \n \n >>> __init__(root = [1,10,4,3,null,7,9,12,8,6,null,null,2])\n >>> true\n Explanation: The node values on each level are:\n Level 0: [1]\n Level 1: [10,4]\n Level 2: [3,7,9]\n Level 3: [12,8,6,2]\n Since levels 0 and 2 are all odd and increasing and levels 1 and 3 are all even and decreasing, the tree is Even-Odd.\n \n Example 2:\n \n \n >>> __init__(root = [5,4,2,3,3,7])\n >>> false\n Explanation: The node values on each level are:\n Level 0: [5]\n Level 1: [4,2]\n Level 2: [3,3,7]\n Node values in level 2 must be in strictly increasing order, so the tree is not Even-Odd.\n \n Example 3:\n \n \n >>> __init__(root = [5,9,1,3,5,7])\n >>> false\n Explanation: Node values in the level 1 should be even integers.\n \"\"\"\n"}
{"task_id": "maximum-number-of-visible-points", "prompt": "def visiblePoints(points: List[List[int]], angle: int, location: List[int]) -> int:\n \"\"\"\n You are given an array points, an integer angle, and your location, where location = [posx, posy] and points[i] = [xi, yi] both denote integral coordinates on the X-Y plane.\n Initially, you are facing directly east from your position. You cannot move from your position, but you can rotate. In other words, posx and posy cannot be changed. Your field of view in degrees is represented by angle, determining how wide you can see from any given view direction. Let d be the amount in degrees that you rotate counterclockwise. Then, your field of view is the inclusive range of angles [d - angle/2, d + angle/2].\n \n Your browser does not support the video tag or this video format.\n \n You can see some set of points if, for each point, the angle formed by the point, your position, and the immediate east direction from your position is in your field of view.\n There can be multiple points at one coordinate. There may be points at your location, and you can always see these points regardless of your rotation. Points do not obstruct your vision to other points.\n Return the maximum number of points you can see.\n \n Example 1:\n \n \n >>> visiblePoints(points = [[2,1],[2,2],[3,3]], angle = 90, location = [1,1])\n >>> 3\n Explanation: The shaded region represents your field of view. All points can be made visible in your field of view, including [3,3] even though [2,2] is in front and in the same line of sight.\n \n Example 2:\n \n >>> visiblePoints(points = [[2,1],[2,2],[3,4],[1,1]], angle = 90, location = [1,1])\n >>> 4\n Explanation: All points can be made visible in your field of view, including the one at your location.\n \n Example 3:\n \n \n >>> visiblePoints(points = [[1,0],[2,1]], angle = 13, location = [1,1])\n >>> 1\n Explanation: You can only see one of the two points, as shown above.\n \"\"\"\n"}
{"task_id": "minimum-one-bit-operations-to-make-integers-zero", "prompt": "def minimumOneBitOperations(n: int) -> int:\n \"\"\"\n Given an integer n, you must transform it into 0 using the following operations any number of times:\n \n Change the rightmost (0th) bit in the binary representation of n.\n Change the ith bit in the binary representation of n if the (i-1)th bit is set to 1 and the (i-2)th through 0th bits are set to 0.\n \n Return the minimum number of operations to transform n into 0.\n \n Example 1:\n \n >>> minimumOneBitOperations(n = 3)\n >>> 2\n Explanation: The binary representation of 3 is \"11\".\n \"11\" -> \"01\" with the 2nd operation since the 0th bit is 1.\n \"01\" -> \"00\" with the 1st operation.\n \n Example 2:\n \n >>> minimumOneBitOperations(n = 6)\n >>> 4\n Explanation: The binary representation of 6 is \"110\".\n \"110\" -> \"010\" with the 2nd operation since the 1st bit is 1 and 0th through 0th bits are 0.\n \"010\" -> \"011\" with the 1st operation.\n \"011\" -> \"001\" with the 2nd operation since the 0th bit is 1.\n \"001\" -> \"000\" with the 1st operation.\n \"\"\"\n"}
{"task_id": "maximum-nesting-depth-of-the-parentheses", "prompt": "def maxDepth(s: str) -> int:\n \"\"\"\n Given a valid parentheses string s, return the nesting depth of s. The nesting depth is the maximum number of nested parentheses.\n \n Example 1:\n \n >>> maxDepth(s = \"(1+(2*3)+((8)/4))+1\")\n >>> 3\n Explanation:\n Digit 8 is inside of 3 nested parentheses in the string.\n \n Example 2:\n \n >>> maxDepth(s = \"(1)+((2))+(((3)))\")\n >>> 3\n Explanation:\n Digit 3 is inside of 3 nested parentheses in the string.\n \n Example 3:\n \n >>> maxDepth(s = \"()(())((()()))\")\n >>> 3\n \"\"\"\n"}
{"task_id": "maximal-network-rank", "prompt": "def maximalNetworkRank(n: int, roads: List[List[int]]) -> int:\n \"\"\"\n There is an infrastructure of n cities with some number of roads connecting these cities. Each roads[i] = [ai, bi] indicates that there is a bidirectional road between cities ai and bi.\n The network rank of two different cities is defined as the total number of\u00a0directly connected roads to either city. If a road is directly connected to both cities, it is only counted once.\n The maximal network rank of the infrastructure is the maximum network rank of all pairs of different cities.\n Given the integer n and the array roads, return the maximal network rank of the entire infrastructure.\n \n Example 1:\n \n \n >>> maximalNetworkRank(n = 4, roads = [[0,1],[0,3],[1,2],[1,3]])\n >>> 4\n Explanation: The network rank of cities 0 and 1 is 4 as there are 4 roads that are connected to either 0 or 1. The road between 0 and 1 is only counted once.\n \n Example 2:\n \n \n >>> maximalNetworkRank(n = 5, roads = [[0,1],[0,3],[1,2],[1,3],[2,3],[2,4]])\n >>> 5\n Explanation: There are 5 roads that are connected to cities 1 or 2.\n \n Example 3:\n \n >>> maximalNetworkRank(n = 8, roads = [[0,1],[1,2],[2,3],[2,4],[5,6],[5,7]])\n >>> 5\n Explanation: The network rank of 2 and 5 is 5. Notice that all the cities do not have to be connected.\n \"\"\"\n"}
{"task_id": "split-two-strings-to-make-palindrome", "prompt": "def checkPalindromeFormation(a: str, b: str) -> bool:\n \"\"\"\n You are given two strings a and b of the same length. Choose an index and split both strings at the same index, splitting a into two strings: aprefix and asuffix where a = aprefix + asuffix, and splitting b into two strings: bprefix and bsuffix where b = bprefix + bsuffix. Check if aprefix + bsuffix or bprefix + asuffix forms a palindrome.\n When you split a string s into sprefix and ssuffix, either ssuffix or sprefix is allowed to be empty. For example, if s = \"abc\", then \"\" + \"abc\", \"a\" + \"bc\", \"ab\" + \"c\" , and \"abc\" + \"\" are valid splits.\n Return true if it is possible to form a palindrome string, otherwise return false.\n Notice that\u00a0x + y denotes the concatenation of strings x and y.\n \n Example 1:\n \n >>> checkPalindromeFormation(a = \"x\", b = \"y\")\n >>> true\n Explaination: If either a or b are palindromes the answer is true since you can split in the following way:\n aprefix = \"\", asuffix = \"x\"\n bprefix = \"\", bsuffix = \"y\"\n Then, aprefix + bsuffix = \"\" + \"y\" = \"y\", which is a palindrome.\n \n Example 2:\n \n >>> checkPalindromeFormation(a = \"xbdef\", b = \"xecab\")\n >>> false\n \n Example 3:\n \n >>> checkPalindromeFormation(a = \"ulacfd\", b = \"jizalu\")\n >>> true\n Explaination: Split them at index 3:\n aprefix = \"ula\", asuffix = \"cfd\"\n bprefix = \"jiz\", bsuffix = \"alu\"\n Then, aprefix + bsuffix = \"ula\" + \"alu\" = \"ulaalu\", which is a palindrome.\n \"\"\"\n"}
{"task_id": "count-subtrees-with-max-distance-between-cities", "prompt": "def countSubgraphsForEachDiameter(n: int, edges: List[List[int]]) -> List[int]:\n \"\"\"\n There are n cities numbered from 1 to n. You are given an array edges of size n-1, where edges[i] = [ui, vi] represents a bidirectional edge between cities ui and vi. There exists a unique path between each pair of cities. In other words, the cities form a tree.\\r\n \\r\n A subtree is a subset of cities where every city is reachable from every other city in the subset, where the path between each pair passes through only the cities from the subset. Two subtrees are different if there is a city in one subtree that is not present in the other.\\r\n \\r\n For each d from 1 to n-1, find the number of subtrees in which the maximum distance between any two cities in the subtree is equal to d.\\r\n \\r\n Return an array of size n-1 where the dth element (1-indexed) is the number of subtrees in which the maximum distance between any two cities is equal to d.\\r\n \\r\n Notice\u00a0that\u00a0the distance between the two cities is the number of edges in the path between them.\\r\n \\r\n \u00a0\\r\n Example 1:\\r\n \\r\n \\r\n \\r\n \\r\n >>> countSubgraphsForEachDiameter(n = 4, edges = [[1,2],[2,3],[2,4]]\\r)\n >>> [3,4,0]\\r\n Explanation:\\r\n The subtrees with subsets {1,2}, {2,3} and {2,4} have a max distance of 1.\\r\n The subtrees with subsets {1,2,3}, {1,2,4}, {2,3,4} and {1,2,3,4} have a max distance of 2.\\r\n No subtree has two nodes where the max distance between them is 3.\\r\n \\r\n \\r\n Example 2:\\r\n \\r\n \\r\n >>> countSubgraphsForEachDiameter(n = 2, edges = [[1,2]]\\r)\n >>> [1]\\r\n \\r\n \\r\n Example 3:\\r\n \\r\n \\r\n >>> countSubgraphsForEachDiameter(n = 3, edges = [[1,2],[2,3]]\\r)\n >>> [2,1]\\r\n \\r\n \\r\n \u00a0\\r\n \"\"\"\n"}
{"task_id": "mean-of-array-after-removing-some-elements", "prompt": "def trimMean(arr: List[int]) -> float:\n \"\"\"\n Given an integer array arr, return the mean of the remaining integers after removing the smallest 5% and the largest 5% of the elements.\n Answers within 10-5 of the actual answer will be considered accepted.\n \n Example 1:\n \n >>> trimMean(arr = [1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3])\n >>> 2.00000\n Explanation: After erasing the minimum and the maximum values of this array, all elements are equal to 2, so the mean is 2.\n \n Example 2:\n \n >>> trimMean(arr = [6,2,7,5,1,2,0,3,10,2,5,0,5,5,0,8,7,6,8,0])\n >>> 4.00000\n \n Example 3:\n \n >>> trimMean(arr = [6,0,7,0,7,5,7,8,3,4,0,7,8,1,6,8,1,1,2,4,8,1,9,5,4,3,8,5,10,8,6,6,1,0,6,10,8,2,3,4])\n >>> 4.77778\n \"\"\"\n"}
{"task_id": "coordinate-with-maximum-network-quality", "prompt": "def bestCoordinate(towers: List[List[int]], radius: int) -> List[int]:\n \"\"\"\n You are given an array of network towers towers, where towers[i] = [xi, yi, qi] denotes the ith network tower with location (xi, yi) and quality factor qi. All the coordinates are integral coordinates on the X-Y plane, and the distance between the two coordinates is the Euclidean distance.\n You are also given an integer radius where a tower is reachable if the distance is less than or equal to radius. Outside that distance, the signal becomes garbled, and the tower is not reachable.\n The signal quality of the ith tower at a coordinate (x, y) is calculated with the formula \u230aqi / (1 + d)\u230b, where d is the distance between the tower and the coordinate. The network quality at a coordinate is the sum of the signal qualities from all the reachable towers.\n Return the array [cx, cy] representing the integral coordinate (cx, cy) where the network quality is maximum. If there are multiple coordinates with the same network quality, return the lexicographically minimum non-negative coordinate.\n Note:\n \n A coordinate (x1, y1) is lexicographically smaller than (x2, y2) if either:\n \n \n x1 < x2, or\n x1 == x2 and y1 < y2.\n \n \n \u230aval\u230b is the greatest integer less than or equal to val (the floor function).\n \n \n Example 1:\n \n \n >>> bestCoordinate(towers = [[1,2,5],[2,1,7],[3,1,9]], radius = 2)\n >>> [2,1]\n Explanation: At coordinate (2, 1) the total quality is 13.\n - Quality of 7 from (2, 1) results in \u230a7 / (1 + sqrt(0)\u230b = \u230a7\u230b = 7\n - Quality of 5 from (1, 2) results in \u230a5 / (1 + sqrt(2)\u230b = \u230a2.07\u230b = 2\n - Quality of 9 from (3, 1) results in \u230a9 / (1 + sqrt(1)\u230b = \u230a4.5\u230b = 4\n No other coordinate has a higher network quality.\n Example 2:\n \n >>> bestCoordinate(towers = [[23,11,21]], radius = 9)\n >>> [23,11]\n Explanation: Since there is only one tower, the network quality is highest right at the tower's location.\n \n Example 3:\n \n >>> bestCoordinate(towers = [[1,2,13],[2,1,7],[0,1,9]], radius = 2)\n >>> [1,2]\n Explanation: Coordinate (1, 2) has the highest network quality.\n \"\"\"\n"}
{"task_id": "number-of-sets-of-k-non-overlapping-line-segments", "prompt": "def numberOfSets(n: int, k: int) -> int:\n \"\"\"\n Given n points on a 1-D plane, where the ith point (from 0 to n-1) is at x = i, find the number of ways we can draw exactly k non-overlapping line segments such that each segment covers two or more points. The endpoints of each segment must have integral coordinates. The k line segments do not have to cover all n points, and they are allowed to share endpoints.\n Return the number of ways we can draw k non-overlapping line segments. Since this number can be huge, return it modulo 109 + 7.\n \n Example 1:\n \n \n >>> numberOfSets(n = 4, k = 2)\n >>> 5\n Explanation: The two line segments are shown in red and blue.\n The image above shows the 5 different ways {(0,2),(2,3)}, {(0,1),(1,3)}, {(0,1),(2,3)}, {(1,2),(2,3)}, {(0,1),(1,2)}.\n \n Example 2:\n \n >>> numberOfSets(n = 3, k = 1)\n >>> 3\n Explanation: The 3 ways are {(0,1)}, {(0,2)}, {(1,2)}.\n \n Example 3:\n \n >>> numberOfSets(n = 30, k = 7)\n >>> 796297179\n Explanation: The total number of possible ways to draw 7 line segments is 3796297200. Taking this number modulo 109 + 7 gives us 796297179.\n \"\"\"\n"}
{"task_id": "largest-substring-between-two-equal-characters", "prompt": "def maxLengthBetweenEqualCharacters(s: str) -> int:\n \"\"\"\n Given a string s, return the length of the longest substring between two equal characters, excluding the two characters. If there is no such substring return -1.\n A substring is a contiguous sequence of characters within a string.\n \n Example 1:\n \n >>> maxLengthBetweenEqualCharacters(s = \"aa\")\n >>> 0\n Explanation: The optimal substring here is an empty substring between the two 'a's.\n Example 2:\n \n >>> maxLengthBetweenEqualCharacters(s = \"abca\")\n >>> 2\n Explanation: The optimal substring here is \"bc\".\n \n Example 3:\n \n >>> maxLengthBetweenEqualCharacters(s = \"cbzxy\")\n >>> -1\n Explanation: There are no characters that appear twice in s.\n \"\"\"\n"}
{"task_id": "lexicographically-smallest-string-after-applying-operations", "prompt": "def findLexSmallestString(s: str, a: int, b: int) -> str:\n \"\"\"\n You are given a string s of even length consisting of digits from 0 to 9, and two integers a and b.\n You can apply either of the following two operations any number of times and in any order on s:\n \n Add a to all odd indices of s (0-indexed). Digits post 9 are cycled back to 0. For example, if s = \"3456\" and a = 5, s becomes \"3951\".\n Rotate s to the right by b positions. For example, if s = \"3456\" and b = 1, s becomes \"6345\".\n \n Return the lexicographically smallest string you can obtain by applying the above operations any number of times on s.\n A string a is lexicographically smaller than a string b (of the same length) if in the first position where a and b differ, string a has a letter that appears earlier in the alphabet than the corresponding letter in b. For example, \"0158\" is lexicographically smaller than \"0190\" because the first position they differ is at the third letter, and '5' comes before '9'.\n \n Example 1:\n \n >>> findLexSmallestString(s = \"5525\", a = 9, b = 2)\n >>> \"2050\"\n Explanation: We can apply the following operations:\n Start: \"5525\"\n Rotate: \"2555\"\n Add: \"2454\"\n Add: \"2353\"\n Rotate: \"5323\"\n Add: \"5222\"\n Add: \"5121\"\n Rotate: \"2151\"\n Add: \"2050\"\u200b\u200b\u200b\u200b\u200b\n There is no way to obtain a string that is lexicographically smaller than \"2050\".\n \n Example 2:\n \n >>> findLexSmallestString(s = \"74\", a = 5, b = 1)\n >>> \"24\"\n Explanation: We can apply the following operations:\n Start: \"74\"\n Rotate: \"47\"\n \u200b\u200b\u200b\u200b\u200b\u200b\u200bAdd: \"42\"\n \u200b\u200b\u200b\u200b\u200b\u200b\u200bRotate: \"24\"\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\n There is no way to obtain a string that is lexicographically smaller than \"24\".\n \n Example 3:\n \n >>> findLexSmallestString(s = \"0011\", a = 4, b = 2)\n >>> \"0011\"\n Explanation: There are no sequence of operations that will give us a lexicographically smaller string than \"0011\".\n \"\"\"\n"}
{"task_id": "best-team-with-no-conflicts", "prompt": "def bestTeamScore(scores: List[int], ages: List[int]) -> int:\n \"\"\"\n You are the manager of a basketball team. For the upcoming tournament, you want to choose the team with the highest overall score. The score of the team is the sum of scores of all the players in the team.\n However, the basketball team is not allowed to have conflicts. A conflict exists if a younger player has a strictly higher score than an older player. A conflict does not occur between players of the same age.\n Given two lists, scores and ages, where each scores[i] and ages[i] represents the score and age of the ith player, respectively, return the highest overall score of all possible basketball teams.\n \n Example 1:\n \n >>> bestTeamScore(scores = [1,3,5,10,15], ages = [1,2,3,4,5])\n >>> 34\n Explanation:\u00a0You can choose all the players.\n \n Example 2:\n \n >>> bestTeamScore(scores = [4,5,6,5], ages = [2,1,2,1])\n >>> 16\n Explanation:\u00a0It is best to choose the last 3 players. Notice that you are allowed to choose multiple people of the same age.\n \n Example 3:\n \n >>> bestTeamScore(scores = [1,2,3,5], ages = [8,9,10,1])\n >>> 6\n Explanation:\u00a0It is best to choose the first 3 players.\n \"\"\"\n"}
{"task_id": "graph-connectivity-with-threshold", "prompt": "def areConnected(n: int, threshold: int, queries: List[List[int]]) -> List[bool]:\n \"\"\"\n We have n cities labeled from 1 to n. Two different cities with labels x and y are directly connected by a bidirectional road if and only if x and y share a common divisor strictly greater than some threshold. More formally, cities with labels x and y have a road between them if there exists an integer z such that all of the following are true:\n \n x % z == 0,\n y % z == 0, and\n z > threshold.\n \n Given the two integers, n and threshold, and an array of queries, you must determine for each queries[i] = [ai, bi] if cities ai and bi are connected directly or indirectly.\u00a0(i.e. there is some path between them).\n Return an array answer, where answer.length == queries.length and answer[i] is true if for the ith query, there is a path between ai and bi, or answer[i] is false if there is no path.\n \n Example 1:\n \n \n >>> areConnected(n = 6, threshold = 2, queries = [[1,4],[2,5],[3,6]])\n >>> [false,false,true]\n Explanation: The divisors for each number:\n 1: 1\n 2: 1, 2\n 3: 1, 3\n 4: 1, 2, 4\n 5: 1, 5\n 6: 1, 2, 3, 6\n Using the underlined divisors above the threshold, only cities 3 and 6 share a common divisor, so they are the\n only ones directly connected. The result of each query:\n [1,4] 1 is not connected to 4\n [2,5] 2 is not connected to 5\n [3,6] 3 is connected to 6 through path 3--6\n \n Example 2:\n \n \n >>> areConnected(n = 6, threshold = 0, queries = [[4,5],[3,4],[3,2],[2,6],[1,3]])\n >>> [true,true,true,true,true]\n Explanation: The divisors for each number are the same as the previous example. However, since the threshold is 0,\n all divisors can be used. Since all numbers share 1 as a divisor, all cities are connected.\n \n Example 3:\n \n \n >>> areConnected(n = 5, threshold = 1, queries = [[4,5],[4,5],[3,2],[2,3],[3,4]])\n >>> [false,false,false,false,false]\n Explanation: Only cities 2 and 4 share a common divisor 2 which is strictly greater than the threshold 1, so they are the only ones directly connected.\n Please notice that there can be multiple queries for the same pair of nodes [x, y], and that the query [x, y] is equivalent to the query [y, x].\n \"\"\"\n"}
{"task_id": "slowest-key", "prompt": "def slowestKey(releaseTimes: List[int], keysPressed: str) -> str:\n \"\"\"\n A newly designed keypad was tested, where a tester pressed a sequence of n keys, one at a time.\n You are given a string keysPressed of length n, where keysPressed[i] was the ith key pressed in the testing sequence, and a sorted list releaseTimes, where releaseTimes[i] was the time the ith key was released. Both arrays are 0-indexed. The 0th key was pressed at the time 0,\u00a0and every subsequent key was pressed at the exact time the previous key was released.\n The tester wants to know the key of the keypress that had the longest duration. The ith keypress had a duration of releaseTimes[i] - releaseTimes[i - 1], and the 0th keypress had a duration of releaseTimes[0].\n Note that the same key could have been pressed multiple times during the test, and these multiple presses of the same key may not have had the same duration.\n Return the key of the keypress that had the longest duration. If there are multiple such keypresses, return the lexicographically largest key of the keypresses.\n \n Example 1:\n \n >>> slowestKey(releaseTimes = [9,29,49,50], keysPressed = \"cbcd\")\n >>> \"c\"\n Explanation: The keypresses were as follows:\n Keypress for 'c' had a duration of 9 (pressed at time 0 and released at time 9).\n Keypress for 'b' had a duration of 29 - 9 = 20 (pressed at time 9 right after the release of the previous character and released at time 29).\n Keypress for 'c' had a duration of 49 - 29 = 20 (pressed at time 29 right after the release of the previous character and released at time 49).\n Keypress for 'd' had a duration of 50 - 49 = 1 (pressed at time 49 right after the release of the previous character and released at time 50).\n The longest of these was the keypress for 'b' and the second keypress for 'c', both with duration 20.\n 'c' is lexicographically larger than 'b', so the answer is 'c'.\n \n Example 2:\n \n >>> slowestKey(releaseTimes = [12,23,36,46,62], keysPressed = \"spuda\")\n >>> \"a\"\n Explanation: The keypresses were as follows:\n Keypress for 's' had a duration of 12.\n Keypress for 'p' had a duration of 23 - 12 = 11.\n Keypress for 'u' had a duration of 36 - 23 = 13.\n Keypress for 'd' had a duration of 46 - 36 = 10.\n Keypress for 'a' had a duration of 62 - 46 = 16.\n The longest of these was the keypress for 'a' with duration 16.\n \"\"\"\n"}
{"task_id": "arithmetic-subarrays", "prompt": "def checkArithmeticSubarrays(nums: List[int], l: List[int], r: List[int]) -> List[bool]:\n \"\"\"\n A sequence of numbers is called arithmetic if it consists of at least two elements, and the difference between every two consecutive elements is the same. More formally, a sequence s is arithmetic if and only if s[i+1] - s[i] == s[1] - s[0] for all valid i.\n For example, these are arithmetic sequences:\n \n 1, 3, 5, 7, 9\n 7, 7, 7, 7\n 3, -1, -5, -9\n The following sequence is not arithmetic:\n \n 1, 1, 2, 5, 7\n You are given an array of n integers, nums, and two arrays of m integers each, l and r, representing the m range queries, where the ith query is the range [l[i], r[i]]. All the arrays are 0-indexed.\n Return a list of boolean elements answer, where answer[i] is true if the subarray nums[l[i]], nums[l[i]+1], ... , nums[r[i]] can be rearranged to form an arithmetic sequence, and false otherwise.\n \n Example 1:\n \n >>> checkArithmeticSubarrays(nums = [4,6,5,9,3,7], l = [0,0,2], r = [2,3,5])\n >>> [true,false,true]\n Explanation:\n In the 0th query, the subarray is [4,6,5]. This can be rearranged as [6,5,4], which is an arithmetic sequence.\n In the 1st query, the subarray is [4,6,5,9]. This cannot be rearranged as an arithmetic sequence.\n In the 2nd query, the subarray is [5,9,3,7]. This can be rearranged as [3,5,7,9], which is an arithmetic sequence.\n Example 2:\n \n >>> checkArithmeticSubarrays(nums = [-12,-9,-3,-12,-6,15,20,-25,-20,-15,-10], l = [0,1,6,4,8,7], r = [4,4,9,7,9,10])\n >>> [false,true,false,false,true,true]\n \"\"\"\n"}
{"task_id": "path-with-minimum-effort", "prompt": "def minimumEffortPath(heights: List[List[int]]) -> int:\n \"\"\"\n You are a hiker preparing for an upcoming hike. You are given heights, a 2D array of size rows x columns, where heights[row][col] represents the height of cell (row, col). You are situated in the top-left cell, (0, 0), and you hope to travel to the bottom-right cell, (rows-1, columns-1) (i.e.,\u00a00-indexed). You can move up, down, left, or right, and you wish to find a route that requires the minimum effort.\n A route's effort is the maximum absolute difference in heights between two consecutive cells of the route.\n Return the minimum effort required to travel from the top-left cell to the bottom-right cell.\n \n Example 1:\n \n \n >>> minimumEffortPath(heights = [[1,2,2],[3,8,2],[5,3,5]])\n >>> 2\n Explanation: The route of [1,3,5,3,5] has a maximum absolute difference of 2 in consecutive cells.\n This is better than the route of [1,2,2,2,5], where the maximum absolute difference is 3.\n \n Example 2:\n \n \n >>> minimumEffortPath(heights = [[1,2,3],[3,8,4],[5,3,5]])\n >>> 1\n Explanation: The route of [1,2,3,4,5] has a maximum absolute difference of 1 in consecutive cells, which is better than route [1,3,5,3,5].\n \n Example 3:\n \n \n >>> minimumEffortPath(heights = [[1,2,1,1,1],[1,2,1,2,1],[1,2,1,2,1],[1,2,1,2,1],[1,1,1,2,1]])\n >>> 0\n Explanation: This route does not require any effort.\n \"\"\"\n"}
{"task_id": "rank-transform-of-a-matrix", "prompt": "def matrixRankTransform(matrix: List[List[int]]) -> List[List[int]]:\n \"\"\"\n Given an m x n matrix, return a new matrix answer where answer[row][col] is the rank of matrix[row][col].\n The rank is an integer that represents how large an element is compared to other elements. It is calculated using the following rules:\n \n The rank is an integer starting from 1.\n If two elements p and q are in the same row or column, then:\n \n If p < q then rank(p) < rank(q)\n If p == q then rank(p) == rank(q)\n If p > q then rank(p) > rank(q)\n \n \n The rank should be as small as possible.\n \n The test cases are generated so that answer is unique under the given rules.\n \n Example 1:\n \n \n >>> matrixRankTransform(matrix = [[1,2],[3,4]])\n >>> [[1,2],[2,3]]\n Explanation:\n The rank of matrix[0][0] is 1 because it is the smallest integer in its row and column.\n The rank of matrix[0][1] is 2 because matrix[0][1] > matrix[0][0] and matrix[0][0] is rank 1.\n The rank of matrix[1][0] is 2 because matrix[1][0] > matrix[0][0] and matrix[0][0] is rank 1.\n The rank of matrix[1][1] is 3 because matrix[1][1] > matrix[0][1], matrix[1][1] > matrix[1][0], and both matrix[0][1] and matrix[1][0] are rank 2.\n \n Example 2:\n \n \n >>> matrixRankTransform(matrix = [[7,7],[7,7]])\n >>> [[1,1],[1,1]]\n \n Example 3:\n \n \n >>> matrixRankTransform(matrix = [[20,-21,14],[-19,4,19],[22,-47,24],[-19,4,19]])\n >>> [[4,2,3],[1,3,4],[5,1,6],[1,3,4]]\n \"\"\"\n"}
{"task_id": "sort-array-by-increasing-frequency", "prompt": "def frequencySort(nums: List[int]) -> List[int]:\n \"\"\"\n Given an array of integers nums, sort the array in increasing order based on the frequency of the values. If multiple values have the same frequency, sort them in decreasing order.\n Return the sorted array.\n \n Example 1:\n \n >>> frequencySort(nums = [1,1,2,2,2,3])\n >>> [3,1,1,2,2,2]\n Explanation: '3' has a frequency of 1, '1' has a frequency of 2, and '2' has a frequency of 3.\n \n Example 2:\n \n >>> frequencySort(nums = [2,3,1,3,2])\n >>> [1,3,3,2,2]\n Explanation: '2' and '3' both have a frequency of 2, so they are sorted in decreasing order.\n \n Example 3:\n \n >>> frequencySort(nums = [-1,1,-6,4,5,-6,1,4,1])\n >>> [5,-1,4,4,-6,-6,1,1,1]\n \"\"\"\n"}
{"task_id": "widest-vertical-area-between-two-points-containing-no-points", "prompt": "def maxWidthOfVerticalArea(points: List[List[int]]) -> int:\n \"\"\"\n Given n points on a 2D plane where points[i] = [xi, yi], Return\u00a0the widest vertical area between two points such that no points are inside the area.\n A vertical area is an area of fixed-width extending infinitely along the y-axis (i.e., infinite height). The widest vertical area is the one with the maximum width.\n Note that points on the edge of a vertical area are not considered included in the area.\n \n Example 1:\n \u200b\n \n >>> maxWidthOfVerticalArea(points = [[8,7],[9,9],[7,4],[9,7]])\n >>> 1\n Explanation: Both the red and the blue area are optimal.\n \n Example 2:\n \n >>> maxWidthOfVerticalArea(points = [[3,1],[9,0],[1,0],[1,4],[5,3],[8,8]])\n >>> 3\n \"\"\"\n"}
{"task_id": "count-substrings-that-differ-by-one-character", "prompt": "def countSubstrings(s: str, t: str) -> int:\n \"\"\"\n Given two strings s and t, find the number of ways you can choose a non-empty substring of s and replace a single character by a different character such that the resulting substring is a substring of t. In other words, find the number of substrings in s that differ from some substring in t by exactly one character.\n For example, the underlined substrings in \"computer\" and \"computation\" only differ by the 'e'/'a', so this is a valid way.\n Return the number of substrings that satisfy the condition above.\n A substring is a contiguous sequence of characters within a string.\n \n Example 1:\n \n >>> countSubstrings(s = \"aba\", t = \"baba\")\n >>> 6\n Explanation: The following are the pairs of substrings from s and t that differ by exactly 1 character:\n (\"aba\", \"baba\")\n (\"aba\", \"baba\")\n (\"aba\", \"baba\")\n (\"aba\", \"baba\")\n (\"aba\", \"baba\")\n (\"aba\", \"baba\")\n The underlined portions are the substrings that are chosen from s and t.\n \n \u200b\u200bExample 2:\n \n >>> countSubstrings(s = \"ab\", t = \"bb\")\n >>> 3\n Explanation: The following are the pairs of substrings from s and t that differ by 1 character:\n (\"ab\", \"bb\")\n (\"ab\", \"bb\")\n (\"ab\", \"bb\")\n \u200b\u200b\u200b\u200bThe underlined portions are the substrings that are chosen from s and t.\n \"\"\"\n"}
{"task_id": "number-of-ways-to-form-a-target-string-given-a-dictionary", "prompt": "def numWays(words: List[str], target: str) -> int:\n \"\"\"\n You are given a list of strings of the same length words and a string target.\n Your task is to form target using the given words under the following rules:\n \n target should be formed from left to right.\n To form the ith character (0-indexed) of target, you can choose the kth character of the jth string in words if target[i] = words[j][k].\n Once you use the kth character of the jth string of words, you can no longer use the xth character of any string in words where x <= k. In other words, all characters to the left of or at index k become unusuable for every string.\n Repeat the process until you form the string target.\n \n Notice that you can use multiple characters from the same string in words provided the conditions above are met.\n Return the number of ways to form target from words. Since the answer may be too large, return it modulo 109 + 7.\n \n Example 1:\n \n >>> numWays(words = [\"acca\",\"bbbb\",\"caca\"], target = \"aba\")\n >>> 6\n Explanation: There are 6 ways to form target.\n \"aba\" -> index 0 (\"acca\"), index 1 (\"bbbb\"), index 3 (\"caca\")\n \"aba\" -> index 0 (\"acca\"), index 2 (\"bbbb\"), index 3 (\"caca\")\n \"aba\" -> index 0 (\"acca\"), index 1 (\"bbbb\"), index 3 (\"acca\")\n \"aba\" -> index 0 (\"acca\"), index 2 (\"bbbb\"), index 3 (\"acca\")\n \"aba\" -> index 1 (\"caca\"), index 2 (\"bbbb\"), index 3 (\"acca\")\n \"aba\" -> index 1 (\"caca\"), index 2 (\"bbbb\"), index 3 (\"caca\")\n \n Example 2:\n \n >>> numWays(words = [\"abba\",\"baab\"], target = \"bab\")\n >>> 4\n Explanation: There are 4 ways to form target.\n \"bab\" -> index 0 (\"baab\"), index 1 (\"baab\"), index 2 (\"abba\")\n \"bab\" -> index 0 (\"baab\"), index 1 (\"baab\"), index 3 (\"baab\")\n \"bab\" -> index 0 (\"baab\"), index 2 (\"baab\"), index 3 (\"baab\")\n \"bab\" -> index 1 (\"abba\"), index 2 (\"baab\"), index 3 (\"baab\")\n \"\"\"\n"}
{"task_id": "check-array-formation-through-concatenation", "prompt": "def canFormArray(arr: List[int], pieces: List[List[int]]) -> bool:\n \"\"\"\n You are given an array of distinct integers arr and an array of integer arrays pieces, where the integers in pieces are distinct. Your goal is to form arr by concatenating the arrays in pieces in any order. However, you are not allowed to reorder the integers in each array pieces[i].\n Return true if it is possible to form the array arr from pieces. Otherwise, return false.\n \n Example 1:\n \n >>> canFormArray(arr = [15,88], pieces = [[88],[15]])\n >>> true\n Explanation: Concatenate [15] then [88]\n \n Example 2:\n \n >>> canFormArray(arr = [49,18,16], pieces = [[16,18,49]])\n >>> false\n Explanation: Even though the numbers match, we cannot reorder pieces[0].\n \n Example 3:\n \n >>> canFormArray(arr = [91,4,64,78], pieces = [[78],[4,64],[91]])\n >>> true\n Explanation: Concatenate [91] then [4,64] then [78]\n \"\"\"\n"}
{"task_id": "count-sorted-vowel-strings", "prompt": "def countVowelStrings(n: int) -> int:\n \"\"\"\n Given an integer n, return the number of strings of length n that consist only of vowels (a, e, i, o, u) and are lexicographically sorted.\n A string s is lexicographically sorted if for all valid i, s[i] is the same as or comes before s[i+1] in the alphabet.\n \n Example 1:\n \n >>> countVowelStrings(n = 1)\n >>> 5\n Explanation: The 5 sorted strings that consist of vowels only are [\"a\",\"e\",\"i\",\"o\",\"u\"].\n \n Example 2:\n \n >>> countVowelStrings(n = 2)\n >>> 15\n Explanation: The 15 sorted strings that consist of vowels only are\n [\"aa\",\"ae\",\"ai\",\"ao\",\"au\",\"ee\",\"ei\",\"eo\",\"eu\",\"ii\",\"io\",\"iu\",\"oo\",\"ou\",\"uu\"].\n Note that \"ea\" is not a valid string since 'e' comes after 'a' in the alphabet.\n \n Example 3:\n \n >>> countVowelStrings(n = 33)\n >>> 66045\n \"\"\"\n"}
{"task_id": "furthest-building-you-can-reach", "prompt": "def furthestBuilding(heights: List[int], bricks: int, ladders: int) -> int:\n \"\"\"\n You are given an integer array heights representing the heights of buildings, some bricks, and some ladders.\n You start your journey from building 0 and move to the next building by possibly using bricks or ladders.\n While moving from building i to building i+1 (0-indexed),\n \n If the current building's height is greater than or equal to the next building's height, you do not need a ladder or bricks.\n If the current building's height is less than the next building's height, you can either use one ladder or (h[i+1] - h[i]) bricks.\n \n Return the furthest building index (0-indexed) you can reach if you use the given ladders and bricks optimally.\n \n Example 1:\n \n \n >>> furthestBuilding(heights = [4,2,7,6,9,14,12], bricks = 5, ladders = 1)\n >>> 4\n Explanation: Starting at building 0, you can follow these steps:\n - Go to building 1 without using ladders nor bricks since 4 >= 2.\n - Go to building 2 using 5 bricks. You must use either bricks or ladders because 2 < 7.\n - Go to building 3 without using ladders nor bricks since 7 >= 6.\n - Go to building 4 using your only ladder. You must use either bricks or ladders because 6 < 9.\n It is impossible to go beyond building 4 because you do not have any more bricks or ladders.\n \n Example 2:\n \n >>> furthestBuilding(heights = [4,12,2,7,3,18,20,3,19], bricks = 10, ladders = 2)\n >>> 7\n \n Example 3:\n \n >>> furthestBuilding(heights = [14,3,19,3], bricks = 17, ladders = 0)\n >>> 3\n \"\"\"\n"}
{"task_id": "kth-smallest-instructions", "prompt": "def kthSmallestPath(destination: List[int], k: int) -> str:\n \"\"\"\n Bob is standing at cell (0, 0), and he wants to reach destination: (row, column). He can only travel right and down. You are going to help Bob by providing instructions for him to reach destination.\n The instructions are represented as a string, where each character is either:\n \n 'H', meaning move horizontally (go right), or\n 'V', meaning move vertically (go down).\n \n Multiple instructions will lead Bob to destination. For example, if destination is (2, 3), both \"HHHVV\" and \"HVHVH\" are valid instructions.\n However, Bob is very picky. Bob has a lucky number k, and he wants the kth lexicographically smallest instructions that will lead him to destination. k is 1-indexed.\n Given an integer array destination and an integer k, return the kth lexicographically smallest instructions that will take Bob to destination.\n \n Example 1:\n \n \n >>> kthSmallestPath(destination = [2,3], k = 1)\n >>> \"HHHVV\"\n Explanation: All the instructions that reach (2, 3) in lexicographic order are as follows:\n [\"HHHVV\", \"HHVHV\", \"HHVVH\", \"HVHHV\", \"HVHVH\", \"HVVHH\", \"VHHHV\", \"VHHVH\", \"VHVHH\", \"VVHHH\"].\n \n Example 2:\n \n \n >>> kthSmallestPath(destination = [2,3], k = 2)\n >>> \"HHVHV\"\n \n Example 3:\n \n \n >>> kthSmallestPath(destination = [2,3], k = 3)\n >>> \"HHVVH\"\n \"\"\"\n"}
{"task_id": "lowest-common-ancestor-of-a-binary-tree-ii", "prompt": "# class TreeNode:\n# def __init__(x):\n# self.val = x\n# self.left = None\n# self.right = None\n\nclass Solution:\n def lowestCommonAncestor(root: 'TreeNode', p: 'TreeNode', q: 'TreeNode') -> 'TreeNode':\n \"\"\"\n Given the root of a binary tree, return the lowest common ancestor (LCA) of two given nodes, p and q. If either node p or q does not exist in the tree, return null. All values of the nodes in the tree are unique.\n According to the definition of LCA on Wikipedia: \"The lowest common ancestor of two nodes p and q in a binary tree T is the lowest node that has both p and q as descendants (where we allow a node to be a descendant of itself)\". A descendant of a node x is a node y that is on the path from node x to some leaf node.\n \n Example 1:\n \n \n >>> __init__(root = [3,5,1,6,2,0,8,null,null,7,4], p = 5, q = 1)\n >>> 3\n Explanation: The LCA of nodes 5 and 1 is 3.\n Example 2:\n \n \n >>> __init__(root = [3,5,1,6,2,0,8,null,null,7,4], p = 5, q = 4)\n >>> 5\n Explanation: The LCA of nodes 5 and 4 is 5. A node can be a descendant of itself according to the definition of LCA.\n Example 3:\n \n \n >>> __init__(root = [3,5,1,6,2,0,8,null,null,7,4], p = 5, q = 10)\n >>> null\n Explanation: Node 10 does not exist in the tree, so return null.\n \"\"\"\n"}
{"task_id": "get-maximum-in-generated-array", "prompt": "def getMaximumGenerated(n: int) -> int:\n \"\"\"\n You are given an integer n. A 0-indexed integer array nums of length n + 1 is generated in the following way:\n \n nums[0] = 0\n nums[1] = 1\n nums[2 * i] = nums[i] when 2 <= 2 * i <= n\n nums[2 * i + 1] = nums[i] + nums[i + 1] when 2 <= 2 * i + 1 <= n\n \n Return the maximum integer in the array nums\u200b\u200b\u200b.\n \n Example 1:\n \n >>> getMaximumGenerated(n = 7)\n >>> 3\n Explanation: According to the given rules:\n nums[0] = 0\n nums[1] = 1\n nums[(1 * 2) = 2] = nums[1] = 1\n nums[(1 * 2) + 1 = 3] = nums[1] + nums[2] = 1 + 1 = 2\n nums[(2 * 2) = 4] = nums[2] = 1\n nums[(2 * 2) + 1 = 5] = nums[2] + nums[3] = 1 + 2 = 3\n nums[(3 * 2) = 6] = nums[3] = 2\n nums[(3 * 2) + 1 = 7] = nums[3] + nums[4] = 2 + 1 = 3\n Hence, nums = [0,1,1,2,1,3,2,3], and the maximum is max(0,1,1,2,1,3,2,3) = 3.\n \n Example 2:\n \n >>> getMaximumGenerated(n = 2)\n >>> 1\n Explanation: According to the given rules, nums = [0,1,1]. The maximum is max(0,1,1) = 1.\n \n Example 3:\n \n >>> getMaximumGenerated(n = 3)\n >>> 2\n Explanation: According to the given rules, nums = [0,1,1,2]. The maximum is max(0,1,1,2) = 2.\n \"\"\"\n"}
{"task_id": "minimum-deletions-to-make-character-frequencies-unique", "prompt": "def minDeletions(s: str) -> int:\n \"\"\"\n A string s is called good if there are no two different characters in s that have the same frequency.\n Given a string s, return the minimum number of characters you need to delete to make s good.\n The frequency of a character in a string is the number of times it appears in the string. For example, in the string \"aab\", the frequency of 'a' is 2, while the frequency of 'b' is 1.\n \n Example 1:\n \n >>> minDeletions(s = \"aab\")\n >>> 0\n Explanation: s is already good.\n \n Example 2:\n \n >>> minDeletions(s = \"aaabbbcc\")\n >>> 2\n Explanation: You can delete two 'b's resulting in the good string \"aaabcc\".\n Another way it to delete one 'b' and one 'c' resulting in the good string \"aaabbc\".\n Example 3:\n \n >>> minDeletions(s = \"ceabaacb\")\n >>> 2\n Explanation: You can delete both 'c's resulting in the good string \"eabaab\".\n Note that we only care about characters that are still in the string at the end (i.e. frequency of 0 is ignored).\n \"\"\"\n"}
{"task_id": "sell-diminishing-valued-colored-balls", "prompt": "def maxProfit(inventory: List[int], orders: int) -> int:\n \"\"\"\n You have an inventory of different colored balls, and there is a customer that wants orders balls of any color.\n The customer weirdly values the colored balls. Each colored ball's value is the number of balls of that color\u00a0you currently have in your inventory. For example, if you own 6 yellow balls, the customer would pay 6 for the first yellow ball. After the transaction, there are only 5 yellow balls left, so the next yellow ball is then valued at 5 (i.e., the value of the balls decreases as you sell more to the customer).\n You are given an integer array, inventory, where inventory[i] represents the number of balls of the ith color that you initially own. You are also given an integer orders, which represents the total number of balls that the customer wants. You can sell the balls in any order.\n Return the maximum total value that you can attain after selling orders colored balls. As the answer may be too large, return it modulo 109 + 7.\n \n Example 1:\n \n \n >>> maxProfit(inventory = [2,5], orders = 4)\n >>> 14\n Explanation: Sell the 1st color 1 time (2) and the 2nd color 3 times (5 + 4 + 3).\n The maximum total value is 2 + 5 + 4 + 3 = 14.\n \n Example 2:\n \n >>> maxProfit(inventory = [3,5], orders = 6)\n >>> 19\n Explanation: Sell the 1st color 2 times (3 + 2) and the 2nd color 4 times (5 + 4 + 3 + 2).\n The maximum total value is 3 + 2 + 5 + 4 + 3 + 2 = 19.\n \"\"\"\n"}
{"task_id": "create-sorted-array-through-instructions", "prompt": "def createSortedArray(instructions: List[int]) -> int:\n \"\"\"\n Given an integer array instructions, you are asked to create a sorted array from the elements in instructions. You start with an empty container nums. For each element from left to right in instructions, insert it into nums. The cost of each insertion is the minimum of the following:\\r\n \\r\n \\r\n \tThe number of elements currently in nums that are strictly less than instructions[i].\\r\n \tThe number of elements currently in nums that are strictly greater than instructions[i].\\r\n \\r\n \\r\n For example, if inserting element 3 into nums = [1,2,3,5], the cost of insertion is min(2, 1) (elements 1 and 2 are less than 3, element 5 is greater than 3) and nums will become [1,2,3,3,5].\\r\n \\r\n Return the total cost to insert all elements from instructions into nums. Since the answer may be large, return it modulo 109 + 7\\r\n \\r\n \u00a0\\r\n Example 1:\\r\n \\r\n \\r\n >>> createSortedArray(instructions = [1,5,6,2]\\r)\n >>> 1\\r\n Explanation: Begin with nums = [].\\r\n Insert 1 with cost min(0, 0) = 0, now nums = [1].\\r\n Insert 5 with cost min(1, 0) = 0, now nums = [1,5].\\r\n Insert 6 with cost min(2, 0) = 0, now nums = [1,5,6].\\r\n Insert 2 with cost min(1, 2) = 1, now nums = [1,2,5,6].\\r\n The total cost is 0 + 0 + 0 + 1 = 1.\\r\n \\r\n Example 2:\\r\n \\r\n \\r\n >>> createSortedArray(instructions = [1,2,3,6,5,4]\\r)\n >>> 3\\r\n Explanation: Begin with nums = [].\\r\n Insert 1 with cost min(0, 0) = 0, now nums = [1].\\r\n Insert 2 with cost min(1, 0) = 0, now nums = [1,2].\\r\n Insert 3 with cost min(2, 0) = 0, now nums = [1,2,3].\\r\n Insert 6 with cost min(3, 0) = 0, now nums = [1,2,3,6].\\r\n Insert 5 with cost min(3, 1) = 1, now nums = [1,2,3,5,6].\\r\n Insert 4 with cost min(3, 2) = 2, now nums = [1,2,3,4,5,6].\\r\n The total cost is 0 + 0 + 0 + 0 + 1 + 2 = 3.\\r\n \\r\n \\r\n Example 3:\\r\n \\r\n \\r\n >>> createSortedArray(instructions = [1,3,3,3,2,4,2,1,2]\\r)\n >>> 4\\r\n Explanation: Begin with nums = [].\\r\n Insert 1 with cost min(0, 0) = 0, now nums = [1].\\r\n Insert 3 with cost min(1, 0) = 0, now nums = [1,3].\\r\n Insert 3 with cost min(1, 0) = 0, now nums = [1,3,3].\\r\n Insert 3 with cost min(1, 0) = 0, now nums = [1,3,3,3].\\r\n Insert 2 with cost min(1, 3) = 1, now nums = [1,2,3,3,3].\\r\n Insert 4 with cost min(5, 0) = 0, now nums = [1,2,3,3,3,4].\\r\n \u200b\u200b\u200b\u200b\u200b\u200b\u200bInsert 2 with cost min(1, 4) = 1, now nums = [1,2,2,3,3,3,4].\\r\n \u200b\u200b\u200b\u200b\u200b\u200b\u200bInsert 1 with cost min(0, 6) = 0, now nums = [1,1,2,2,3,3,3,4].\\r\n \u200b\u200b\u200b\u200b\u200b\u200b\u200bInsert 2 with cost min(2, 4) = 2, now nums = [1,1,2,2,2,3,3,3,4].\\r\n The total cost is 0 + 0 + 0 + 0 + 1 + 0 + 1 + 0 + 2 = 4.\\r\n \\r\n \\r\n \u00a0\\r\n \"\"\"\n"}
{"task_id": "defuse-the-bomb", "prompt": "def decrypt(code: List[int], k: int) -> List[int]:\n \"\"\"\n You have a bomb to defuse, and your time is running out! Your informer will provide you with a circular array code\u00a0of length of n\u00a0and a key k.\n To decrypt the code, you must replace every number. All the numbers are replaced simultaneously.\n \n If k > 0, replace the ith number with the sum of the next k numbers.\n If k < 0, replace the ith number with the sum of the previous k numbers.\n If k == 0, replace the ith number with 0.\n \n As code is circular, the next element of code[n-1] is code[0], and the previous element of code[0] is code[n-1].\n Given the circular array code and an integer key k, return the decrypted code to defuse the bomb!\n \n Example 1:\n \n >>> decrypt(code = [5,7,1,4], k = 3)\n >>> [12,10,16,13]\n Explanation: Each number is replaced by the sum of the next 3 numbers. The decrypted code is [7+1+4, 1+4+5, 4+5+7, 5+7+1]. Notice that the numbers wrap around.\n \n Example 2:\n \n >>> decrypt(code = [1,2,3,4], k = 0)\n >>> [0,0,0,0]\n Explanation: When k is zero, the numbers are replaced by 0.\n \n Example 3:\n \n >>> decrypt(code = [2,4,9,3], k = -2)\n >>> [12,5,6,13]\n Explanation: The decrypted code is [3+9, 2+3, 4+2, 9+4]. Notice that the numbers wrap around again. If k is negative, the sum is of the previous numbers.\n \"\"\"\n"}
{"task_id": "minimum-deletions-to-make-string-balanced", "prompt": "def minimumDeletions(s: str) -> int:\n \"\"\"\n You are given a string s consisting only of characters 'a' and 'b'\u200b\u200b\u200b\u200b.\n You can delete any number of characters in s to make s balanced. s is balanced if there is no pair of indices (i,j) such that i < j and s[i] = 'b' and s[j]= 'a'.\n Return the minimum number of deletions needed to make s balanced.\n \n Example 1:\n \n >>> minimumDeletions(s = \"aababbab\")\n >>> 2\n Explanation: You can either:\n Delete the characters at 0-indexed positions 2 and 6 (\"aababbab\" -> \"aaabbb\"), or\n Delete the characters at 0-indexed positions 3 and 6 (\"aababbab\" -> \"aabbbb\").\n \n Example 2:\n \n >>> minimumDeletions(s = \"bbaaaaabb\")\n >>> 2\n Explanation: The only solution is to delete the first two characters.\n \"\"\"\n"}
{"task_id": "minimum-jumps-to-reach-home", "prompt": "def minimumJumps(forbidden: List[int], a: int, b: int, x: int) -> int:\n \"\"\"\n A certain bug's home is on the x-axis at position x. Help them get there from position 0.\n The bug jumps according to the following rules:\n \n It can jump exactly a positions forward (to the right).\n It can jump exactly b positions backward (to the left).\n It cannot jump backward twice in a row.\n It cannot jump to any forbidden positions.\n \n The bug may jump forward beyond its home, but it cannot jump to positions numbered with negative integers.\n Given an array of integers forbidden, where forbidden[i] means that the bug cannot jump to the position forbidden[i], and integers a, b, and x, return the minimum number of jumps needed for the bug to reach its home. If there is no possible sequence of jumps that lands the bug on position x, return -1.\n \n Example 1:\n \n >>> minimumJumps(forbidden = [14,4,18,1,15], a = 3, b = 15, x = 9)\n >>> 3\n Explanation: 3 jumps forward (0 -> 3 -> 6 -> 9) will get the bug home.\n \n Example 2:\n \n >>> minimumJumps(forbidden = [8,3,16,6,12,20], a = 15, b = 13, x = 11)\n >>> -1\n \n Example 3:\n \n >>> minimumJumps(forbidden = [1,6,2,14,5,17,4], a = 16, b = 9, x = 7)\n >>> 2\n Explanation: One jump forward (0 -> 16) then one jump backward (16 -> 7) will get the bug home.\n \"\"\"\n"}
{"task_id": "distribute-repeating-integers", "prompt": "def canDistribute(nums: List[int], quantity: List[int]) -> bool:\n \"\"\"\n You are given an array of n integers, nums, where there are at most 50 unique values in the array. You are also given an array of m customer order quantities, quantity, where quantity[i] is the amount of integers the ith customer ordered. Determine if it is possible to distribute nums such that:\n \n The ith customer gets exactly quantity[i] integers,\n The integers the ith customer gets are all equal, and\n Every customer is satisfied.\n \n Return true if it is possible to distribute nums according to the above conditions.\n \n Example 1:\n \n >>> canDistribute(nums = [1,2,3,4], quantity = [2])\n >>> false\n Explanation: The 0th customer cannot be given two different integers.\n \n Example 2:\n \n >>> canDistribute(nums = [1,2,3,3], quantity = [2])\n >>> true\n Explanation: The 0th customer is given [3,3]. The integers [1,2] are not used.\n \n Example 3:\n \n >>> canDistribute(nums = [1,1,2,2], quantity = [2,2])\n >>> true\n Explanation: The 0th customer is given [1,1], and the 1st customer is given [2,2].\n \"\"\"\n"}
{"task_id": "determine-if-two-strings-are-close", "prompt": "def closeStrings(word1: str, word2: str) -> bool:\n \"\"\"\n Two strings are considered close if you can attain one from the other using the following operations:\n \n Operation 1: Swap any two existing characters.\n \n \n For example, abcde -> aecdb\n \n \n Operation 2: Transform every occurrence of one existing character into another existing character, and do the same with the other character.\n \n For example, aacabb -> bbcbaa (all a's turn into b's, and all b's turn into a's)\n \n \n \n You can use the operations on either string as many times as necessary.\n Given two strings, word1 and word2, return true if word1 and word2 are close, and false otherwise.\n \n Example 1:\n \n >>> closeStrings(word1 = \"abc\", word2 = \"bca\")\n >>> true\n Explanation: You can attain word2 from word1 in 2 operations.\n Apply Operation 1: \"abc\" -> \"acb\"\n Apply Operation 1: \"acb\" -> \"bca\"\n \n Example 2:\n \n >>> closeStrings(word1 = \"a\", word2 = \"aa\")\n >>> false\n Explanation: It is impossible to attain word2 from word1, or vice versa, in any number of operations.\n \n Example 3:\n \n >>> closeStrings(word1 = \"cabbba\", word2 = \"abbccc\")\n >>> true\n Explanation: You can attain word2 from word1 in 3 operations.\n Apply Operation 1: \"cabbba\" -> \"caabbb\"\n Apply Operation 2: \"caabbb\" -> \"baaccc\"\n Apply Operation 2: \"baaccc\" -> \"abbccc\"\n \"\"\"\n"}
{"task_id": "minimum-operations-to-reduce-x-to-zero", "prompt": "def minOperations(nums: List[int], x: int) -> int:\n \"\"\"\n You are given an integer array nums and an integer x. In one operation, you can either remove the leftmost or the rightmost element from the array nums and subtract its value from x. Note that this modifies the array for future operations.\n Return the minimum number of operations to reduce x to exactly 0 if it is possible, otherwise, return -1.\n \n Example 1:\n \n >>> minOperations(nums = [1,1,4,2,3], x = 5)\n >>> 2\n Explanation: The optimal solution is to remove the last two elements to reduce x to zero.\n \n Example 2:\n \n >>> minOperations(nums = [5,6,7,8,9], x = 4)\n >>> -1\n \n Example 3:\n \n >>> minOperations(nums = [3,2,20,1,1,3], x = 10)\n >>> 5\n Explanation: The optimal solution is to remove the last three elements and the first two elements (5 operations in total) to reduce x to zero.\n \"\"\"\n"}
{"task_id": "maximize-grid-happiness", "prompt": "def getMaxGridHappiness(m: int, n: int, introvertsCount: int, extrovertsCount: int) -> int:\n \"\"\"\n You are given four integers, m, n, introvertsCount, and extrovertsCount. You have an m x n grid, and there are two types of people: introverts and extroverts. There are introvertsCount introverts and extrovertsCount extroverts.\n You should decide how many people you want to live in the grid and assign each of them one grid cell. Note that you do not have to have all the people living in the grid.\n The happiness of each person is calculated as follows:\n \n Introverts start with 120 happiness and lose 30 happiness for each neighbor (introvert or extrovert).\n Extroverts start with 40 happiness and gain 20 happiness for each neighbor (introvert or extrovert).\n \n Neighbors live in the directly adjacent cells north, east, south, and west of a person's cell.\n The grid happiness is the sum of each person's happiness. Return the maximum possible grid happiness.\n \n Example 1:\n \n \n >>> getMaxGridHappiness(m = 2, n = 3, introvertsCount = 1, extrovertsCount = 2)\n >>> 240\n Explanation: Assume the grid is 1-indexed with coordinates (row, column).\n We can put the introvert in cell (1,1) and put the extroverts in cells (1,3) and (2,3).\n - Introvert at (1,1) happiness: 120 (starting happiness) - (0 * 30) (0 neighbors) = 120\n - Extrovert at (1,3) happiness: 40 (starting happiness) + (1 * 20) (1 neighbor) = 60\n - Extrovert at (2,3) happiness: 40 (starting happiness) + (1 * 20) (1 neighbor) = 60\n The grid happiness is 120 + 60 + 60 = 240.\n The above figure shows the grid in this example with each person's happiness. The introvert stays in the light green cell while the extroverts live on the light purple cells.\n \n Example 2:\n \n >>> getMaxGridHappiness(m = 3, n = 1, introvertsCount = 2, extrovertsCount = 1)\n >>> 260\n Explanation: Place the two introverts in (1,1) and (3,1) and the extrovert at (2,1).\n - Introvert at (1,1) happiness: 120 (starting happiness) - (1 * 30) (1 neighbor) = 90\n - Extrovert at (2,1) happiness: 40 (starting happiness) + (2 * 20) (2 neighbors) = 80\n - Introvert at (3,1) happiness: 120 (starting happiness) - (1 * 30) (1 neighbor) = 90\n The grid happiness is 90 + 80 + 90 = 260.\n \n Example 3:\n \n >>> getMaxGridHappiness(m = 2, n = 2, introvertsCount = 4, extrovertsCount = 0)\n >>> 240\n \"\"\"\n"}
{"task_id": "check-if-two-string-arrays-are-equivalent", "prompt": "def arrayStringsAreEqual(word1: List[str], word2: List[str]) -> bool:\n \"\"\"\n Given two string arrays word1 and word2, return true if the two arrays represent the same string, and false otherwise.\n A string is represented by an array if the array elements concatenated in order forms the string.\n \n Example 1:\n \n >>> arrayStringsAreEqual(word1 = [\"ab\", \"c\"], word2 = [\"a\", \"bc\"])\n >>> true\n Explanation:\n word1 represents string \"ab\" + \"c\" -> \"abc\"\n word2 represents string \"a\" + \"bc\" -> \"abc\"\n The strings are the same, so return true.\n Example 2:\n \n >>> arrayStringsAreEqual(word1 = [\"a\", \"cb\"], word2 = [\"ab\", \"c\"])\n >>> false\n \n Example 3:\n \n >>> arrayStringsAreEqual(word1 = [\"abc\", \"d\", \"defg\"], word2 = [\"abcddefg\"])\n >>> true\n \"\"\"\n"}
{"task_id": "smallest-string-with-a-given-numeric-value", "prompt": "def getSmallestString(n: int, k: int) -> str:\n \"\"\"\n The numeric value of a lowercase character is defined as its position (1-indexed) in the alphabet, so the numeric value of a is 1, the numeric value of b is 2, the numeric value of c is 3, and so on.\n The numeric value of a string consisting of lowercase characters is defined as the sum of its characters' numeric values. For example, the numeric value of the string \"abe\" is equal to 1 + 2 + 5 = 8.\n You are given two integers n and k. Return the lexicographically smallest string with length equal to n and numeric value equal to k.\n Note that a string x is lexicographically smaller than string y if x comes before y in dictionary order, that is, either x is a prefix of y, or if i is the first position such that x[i] != y[i], then x[i] comes before y[i] in alphabetic order.\n \n Example 1:\n \n >>> getSmallestString(n = 3, k = 27)\n >>> \"aay\"\n Explanation: The numeric value of the string is 1 + 1 + 25 = 27, and it is the smallest string with such a value and length equal to 3.\n \n Example 2:\n \n >>> getSmallestString(n = 5, k = 73)\n >>> \"aaszz\"\n \"\"\"\n"}
{"task_id": "ways-to-make-a-fair-array", "prompt": "def waysToMakeFair(nums: List[int]) -> int:\n \"\"\"\n You are given an integer array\u00a0nums. You can choose exactly one index (0-indexed) and remove the element. Notice that the index of the elements may change after the removal.\n For example, if nums = [6,1,7,4,1]:\n \n Choosing to remove index 1 results in nums = [6,7,4,1].\n Choosing to remove index 2 results in nums = [6,1,4,1].\n Choosing to remove index 4 results in nums = [6,1,7,4].\n \n An array is fair if the sum of the odd-indexed values equals the sum of the even-indexed values.\n Return the number of indices that you could choose such that after the removal, nums is fair.\n \n Example 1:\n \n >>> waysToMakeFair(nums = [2,1,6,4])\n >>> 1\n Explanation:\n Remove index 0: [1,6,4] -> Even sum: 1 + 4 = 5. Odd sum: 6. Not fair.\n Remove index 1: [2,6,4] -> Even sum: 2 + 4 = 6. Odd sum: 6. Fair.\n Remove index 2: [2,1,4] -> Even sum: 2 + 4 = 6. Odd sum: 1. Not fair.\n Remove index 3: [2,1,6] -> Even sum: 2 + 6 = 8. Odd sum: 1. Not fair.\n There is 1 index that you can remove to make nums fair.\n \n Example 2:\n \n >>> waysToMakeFair(nums = [1,1,1])\n >>> 3\n Explanation:\u00a0You can remove any index and the remaining array is fair.\n \n Example 3:\n \n >>> waysToMakeFair(nums = [1,2,3])\n >>> 0\n Explanation:\u00a0You cannot make a fair array after removing any index.\n \"\"\"\n"}
{"task_id": "minimum-initial-energy-to-finish-tasks", "prompt": "def minimumEffort(tasks: List[List[int]]) -> int:\n \"\"\"\n You are given an array tasks where tasks[i] = [actuali, minimumi]:\n \n actuali is the actual amount of energy you spend to finish the ith task.\n minimumi is the minimum amount of energy you require to begin the ith task.\n \n For example, if the task is [10, 12] and your current energy is 11, you cannot start this task. However, if your current energy is 13, you can complete this task, and your energy will be 3 after finishing it.\n You can finish the tasks in any order you like.\n Return the minimum initial amount of energy you will need to finish all the tasks.\n \n Example 1:\n \n >>> minimumEffort(tasks = [[1,2],[2,4],[4,8]])\n >>> 8\n Explanation:\n Starting with 8 energy, we finish the tasks in the following order:\n - 3rd task. Now energy = 8 - 4 = 4.\n - 2nd task. Now energy = 4 - 2 = 2.\n - 1st task. Now energy = 2 - 1 = 1.\n Notice that even though we have leftover energy, starting with 7 energy does not work because we cannot do the 3rd task.\n Example 2:\n \n >>> minimumEffort(tasks = [[1,3],[2,4],[10,11],[10,12],[8,9]])\n >>> 32\n Explanation:\n Starting with 32 energy, we finish the tasks in the following order:\n - 1st task. Now energy = 32 - 1 = 31.\n - 2nd task. Now energy = 31 - 2 = 29.\n - 3rd task. Now energy = 29 - 10 = 19.\n - 4th task. Now energy = 19 - 10 = 9.\n - 5th task. Now energy = 9 - 8 = 1.\n Example 3:\n \n >>> minimumEffort(tasks = [[1,7],[2,8],[3,9],[4,10],[5,11],[6,12]])\n >>> 27\n Explanation:\n Starting with 27 energy, we finish the tasks in the following order:\n - 5th task. Now energy = 27 - 5 = 22.\n - 2nd task. Now energy = 22 - 2 = 20.\n - 3rd task. Now energy = 20 - 3 = 17.\n - 1st task. Now energy = 17 - 1 = 16.\n - 4th task. Now energy = 16 - 4 = 12.\n - 6th task. Now energy = 12 - 6 = 6.\n \"\"\"\n"}
{"task_id": "maximum-repeating-substring", "prompt": "def maxRepeating(sequence: str, word: str) -> int:\n \"\"\"\n For a string sequence, a string word is k-repeating if word concatenated k times is a substring of sequence. The word's maximum k-repeating value is the highest value k where word is k-repeating in sequence. If word is not a substring of sequence, word's maximum k-repeating value is 0.\n Given strings sequence and word, return the maximum k-repeating value of word in sequence.\n \n Example 1:\n \n >>> maxRepeating(sequence = \"ababc\", word = \"ab\")\n >>> 2\n Explanation: \"abab\" is a substring in \"ababc\".\n \n Example 2:\n \n >>> maxRepeating(sequence = \"ababc\", word = \"ba\")\n >>> 1\n Explanation: \"ba\" is a substring in \"ababc\". \"baba\" is not a substring in \"ababc\".\n \n Example 3:\n \n >>> maxRepeating(sequence = \"ababc\", word = \"ac\")\n >>> 0\n Explanation: \"ac\" is not a substring in \"ababc\".\n \"\"\"\n"}
{"task_id": "merge-in-between-linked-lists", "prompt": "# class ListNode:\n# def __init__(val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution:\n def mergeInBetween(list1: ListNode, a: int, b: int, list2: ListNode) -> ListNode:\n \"\"\"\n You are given two linked lists: list1 and list2 of sizes n and m respectively.\n Remove list1's nodes from the ath node to the bth node, and put list2 in their place.\n The blue edges and nodes in the following figure indicate the result:\n \n Build the result list and return its head.\n \n Example 1:\n \n \n >>> __init__(list1 = [10,1,13,6,9,5], a = 3, b = 4, list2 = [1000000,1000001,1000002])\n >>> [10,1,13,1000000,1000001,1000002,5]\n Explanation: We remove the nodes 3 and 4 and put the entire list2 in their place. The blue edges and nodes in the above figure indicate the result.\n \n Example 2:\n \n \n >>> __init__(list1 = [0,1,2,3,4,5,6], a = 2, b = 5, list2 = [1000000,1000001,1000002,1000003,1000004])\n >>> [0,1,1000000,1000001,1000002,1000003,1000004,6]\n Explanation: The blue edges and nodes in the above figure indicate the result.\n \"\"\"\n"}
{"task_id": "minimum-number-of-removals-to-make-mountain-array", "prompt": "def minimumMountainRemovals(nums: List[int]) -> int:\n \"\"\"\n You may recall that an array arr is a mountain array if and only if:\n \n arr.length >= 3\n There exists some index i (0-indexed) with 0 < i < arr.length - 1 such that:\n \n arr[0] < arr[1] < ... < arr[i - 1] < arr[i]\n arr[i] > arr[i + 1] > ... > arr[arr.length - 1]\n \n \n \n Given an integer array nums\u200b\u200b\u200b, return the minimum number of elements to remove to make nums\u200b\u200b\u200b a mountain array.\n \n Example 1:\n \n >>> minimumMountainRemovals(nums = [1,3,1])\n >>> 0\n Explanation: The array itself is a mountain array so we do not need to remove any elements.\n \n Example 2:\n \n >>> minimumMountainRemovals(nums = [2,1,1,5,6,2,3,1])\n >>> 3\n Explanation: One solution is to remove the elements at indices 0, 1, and 5, making the array nums = [1,5,6,3,1].\n \"\"\"\n"}
{"task_id": "richest-customer-wealth", "prompt": "def maximumWealth(accounts: List[List[int]]) -> int:\n \"\"\"\n You are given an m x n integer grid accounts where accounts[i][j] is the amount of money the i\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200bth\u200b\u200b\u200b\u200b customer has in the j\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200bth\u200b\u200b\u200b\u200b bank. Return the wealth that the richest customer has.\n A customer's wealth is the amount of money they have in all their bank accounts. The richest customer is the customer that has the maximum wealth.\n \n Example 1:\n \n >>> maximumWealth(accounts = [[1,2,3],[3,2,1]])\n >>> 6\n Explanation:\n 1st customer has wealth = 1 + 2 + 3 = 6\n 2nd customer has wealth = 3 + 2 + 1 = 6\n Both customers are considered the richest with a wealth of 6 each, so return 6.\n \n Example 2:\n \n >>> maximumWealth(accounts = [[1,5],[7,3],[3,5]])\n >>> 10\n Explanation:\n 1st customer has wealth = 6\n 2nd customer has wealth = 10\n 3rd customer has wealth = 8\n The 2nd customer is the richest with a wealth of 10.\n Example 3:\n \n >>> maximumWealth(accounts = [[2,8,7],[7,1,3],[1,9,5]])\n >>> 17\n \"\"\"\n"}
{"task_id": "find-the-most-competitive-subsequence", "prompt": "def mostCompetitive(nums: List[int], k: int) -> List[int]:\n \"\"\"\n Given an integer array nums and a positive integer k, return the most competitive subsequence of nums of size k.\n An array's subsequence is a resulting sequence obtained by erasing some (possibly zero) elements from the array.\n We define that a subsequence a is more competitive than a subsequence b (of the same length) if in the first position where a and b differ, subsequence a has a number less than the corresponding number in b. For example, [1,3,4] is more competitive than [1,3,5] because the first position they differ is at the final number, and 4 is less than 5.\n \n Example 1:\n \n >>> mostCompetitive(nums = [3,5,2,6], k = 2)\n >>> [2,6]\n Explanation: Among the set of every possible subsequence: {[3,5], [3,2], [3,6], [5,2], [5,6], [2,6]}, [2,6] is the most competitive.\n \n Example 2:\n \n >>> mostCompetitive(nums = [2,4,3,3,5,4,9,6], k = 4)\n >>> [2,3,3,4]\n \"\"\"\n"}
{"task_id": "minimum-moves-to-make-array-complementary", "prompt": "def minMoves(nums: List[int], limit: int) -> int:\n \"\"\"\n You are given an integer array nums of even length n and an integer limit. In one move, you can replace any integer from nums with another integer between 1 and limit, inclusive.\n The array nums is complementary if for all indices i (0-indexed), nums[i] + nums[n - 1 - i] equals the same number. For example, the array [1,2,3,4] is complementary because for all indices i, nums[i] + nums[n - 1 - i] = 5.\n Return the minimum number of moves required to make nums complementary.\n \n Example 1:\n \n >>> minMoves(nums = [1,2,4,3], limit = 4)\n >>> 1\n Explanation: In 1 move, you can change nums to [1,2,2,3] (underlined elements are changed).\n nums[0] + nums[3] = 1 + 3 = 4.\n nums[1] + nums[2] = 2 + 2 = 4.\n nums[2] + nums[1] = 2 + 2 = 4.\n nums[3] + nums[0] = 3 + 1 = 4.\n Therefore, nums[i] + nums[n-1-i] = 4 for every i, so nums is complementary.\n \n Example 2:\n \n >>> minMoves(nums = [1,2,2,1], limit = 2)\n >>> 2\n Explanation: In 2 moves, you can change nums to [2,2,2,2]. You cannot change any number to 3 since 3 > limit.\n \n Example 3:\n \n >>> minMoves(nums = [1,2,1,2], limit = 2)\n >>> 0\n Explanation: nums is already complementary.\n \"\"\"\n"}
{"task_id": "minimize-deviation-in-array", "prompt": "def minimumDeviation(nums: List[int]) -> int:\n \"\"\"\n You are given an array nums of n positive integers.\n You can perform two types of operations on any element of the array any number of times:\n \n If the element is even, divide it by 2.\n \n \n For example, if the array is [1,2,3,4], then you can do this operation on the last element, and the array will be [1,2,3,2].\n \n \n If the element is odd, multiply it by 2.\n \n For example, if the array is [1,2,3,4], then you can do this operation on the first element, and the array will be [2,2,3,4].\n \n \n \n The deviation of the array is the maximum difference between any two elements in the array.\n Return the minimum deviation the array can have after performing some number of operations.\n \n Example 1:\n \n >>> minimumDeviation(nums = [1,2,3,4])\n >>> 1\n Explanation: You can transform the array to [1,2,3,2], then to [2,2,3,2], then the deviation will be 3 - 2 = 1.\n \n Example 2:\n \n >>> minimumDeviation(nums = [4,1,5,20,3])\n >>> 3\n Explanation: You can transform the array after two operations to [4,2,5,5,3], then the deviation will be 5 - 2 = 3.\n \n Example 3:\n \n >>> minimumDeviation(nums = [2,10,8])\n >>> 3\n \"\"\"\n"}
{"task_id": "goal-parser-interpretation", "prompt": "def interpret(command: str) -> str:\n \"\"\"\n You own a Goal Parser that can interpret a string command. The command consists of an alphabet of \"G\", \"()\" and/or \"(al)\" in some order. The Goal Parser will interpret \"G\" as the string \"G\", \"()\" as the string \"o\", and \"(al)\" as the string \"al\". The interpreted strings are then concatenated in the original order.\n Given the string command, return the Goal Parser's interpretation of command.\n \n Example 1:\n \n >>> interpret(command = \"G()(al)\")\n >>> \"Goal\"\n Explanation:\u00a0The Goal Parser interprets the command as follows:\n G -> G\n () -> o\n (al) -> al\n The final concatenated result is \"Goal\".\n \n Example 2:\n \n >>> interpret(command = \"G()()()()(al)\")\n >>> \"Gooooal\"\n \n Example 3:\n \n >>> interpret(command = \"(al)G(al)()()G\")\n >>> \"alGalooG\"\n \"\"\"\n"}
{"task_id": "max-number-of-k-sum-pairs", "prompt": "def maxOperations(nums: List[int], k: int) -> int:\n \"\"\"\n You are given an integer array nums and an integer k.\n In one operation, you can pick two numbers from the array whose sum equals k and remove them from the array.\n Return the maximum number of operations you can perform on the array.\n \n Example 1:\n \n >>> maxOperations(nums = [1,2,3,4], k = 5)\n >>> 2\n Explanation: Starting with nums = [1,2,3,4]:\n - Remove numbers 1 and 4, then nums = [2,3]\n - Remove numbers 2 and 3, then nums = []\n There are no more pairs that sum up to 5, hence a total of 2 operations.\n Example 2:\n \n >>> maxOperations(nums = [3,1,3,4,3], k = 6)\n >>> 1\n Explanation: Starting with nums = [3,1,3,4,3]:\n - Remove the first two 3's, then nums = [1,4,3]\n There are no more pairs that sum up to 6, hence a total of 1 operation.\n \"\"\"\n"}
{"task_id": "concatenation-of-consecutive-binary-numbers", "prompt": "def concatenatedBinary(n: int) -> int:\n \"\"\"\n Given an integer n, return the decimal value of the binary string formed by concatenating the binary representations of 1 to n in order, modulo 109 + 7.\n \n Example 1:\n \n >>> concatenatedBinary(n = 1)\n >>> 1\n Explanation: \"1\" in binary corresponds to the decimal value 1.\n \n Example 2:\n \n >>> concatenatedBinary(n = 3)\n >>> 27\n Explanation: In binary, 1, 2, and 3 corresponds to \"1\", \"10\", and \"11\".\n After concatenating them, we have \"11011\", which corresponds to the decimal value 27.\n \n Example 3:\n \n >>> concatenatedBinary(n = 12)\n >>> 505379714\n Explanation: The concatenation results in \"1101110010111011110001001101010111100\".\n The decimal value of that is 118505380540.\n After modulo 109 + 7, the result is 505379714.\n \"\"\"\n"}
{"task_id": "minimum-incompatibility", "prompt": "def minimumIncompatibility(nums: List[int], k: int) -> int:\n \"\"\"\n You are given an integer array nums\u200b\u200b\u200b and an integer k. You are asked to distribute this array into k subsets of equal size such that there are no two equal elements in the same subset.\n A subset's incompatibility is the difference between the maximum and minimum elements in that array.\n Return the minimum possible sum of incompatibilities of the k subsets after distributing the array optimally, or return -1 if it is not possible.\n A subset is a group integers that appear in the array with no particular order.\n \n Example 1:\n \n >>> minimumIncompatibility(nums = [1,2,1,4], k = 2)\n >>> 4\n Explanation: The optimal distribution of subsets is [1,2] and [1,4].\n The incompatibility is (2-1) + (4-1) = 4.\n Note that [1,1] and [2,4] would result in a smaller sum, but the first subset contains 2 equal elements.\n Example 2:\n \n >>> minimumIncompatibility(nums = [6,3,8,1,3,1,2,2], k = 4)\n >>> 6\n Explanation: The optimal distribution of subsets is [1,2], [2,3], [6,8], and [1,3].\n The incompatibility is (2-1) + (3-2) + (8-6) + (3-1) = 6.\n \n Example 3:\n \n >>> minimumIncompatibility(nums = [5,3,3,6,3,3], k = 3)\n >>> -1\n Explanation: It is impossible to distribute nums into 3 subsets where no two elements are equal in the same subset.\n \"\"\"\n"}
{"task_id": "longest-palindromic-subsequence-ii", "prompt": "def longestPalindromeSubseq(s: str) -> int:\n \"\"\"\n A subsequence of a string s is considered a good palindromic subsequence if:\n \n It is a subsequence of s.\n It is a palindrome (has the same value if reversed).\n It has an even length.\n No two consecutive characters are equal, except the two middle ones.\n \n For example, if s = \"abcabcabb\", then \"abba\" is considered a good palindromic subsequence, while \"bcb\" (not even length) and \"bbbb\" (has equal consecutive characters) are not.\n Given a string s, return the length of the longest good palindromic subsequence in s.\n \n Example 1:\n \n >>> longestPalindromeSubseq(s = \"bbabab\")\n >>> 4\n Explanation: The longest good palindromic subsequence of s is \"baab\".\n \n Example 2:\n \n >>> longestPalindromeSubseq(s = \"dcbccacdb\")\n >>> 4\n Explanation: The longest good palindromic subsequence of s is \"dccd\".\n \"\"\"\n"}
{"task_id": "count-the-number-of-consistent-strings", "prompt": "def countConsistentStrings(allowed: str, words: List[str]) -> int:\n \"\"\"\n You are given a string allowed consisting of distinct characters and an array of strings words. A string is consistent if all characters in the string appear in the string allowed.\n Return the number of consistent strings in the array words.\n \n Example 1:\n \n >>> countConsistentStrings(allowed = \"ab\", words = [\"ad\",\"bd\",\"aaab\",\"baa\",\"badab\"])\n >>> 2\n Explanation: Strings \"aaab\" and \"baa\" are consistent since they only contain characters 'a' and 'b'.\n \n Example 2:\n \n >>> countConsistentStrings(allowed = \"abc\", words = [\"a\",\"b\",\"c\",\"ab\",\"ac\",\"bc\",\"abc\"])\n >>> 7\n Explanation: All strings are consistent.\n \n Example 3:\n \n >>> countConsistentStrings(allowed = \"cad\", words = [\"cc\",\"acd\",\"b\",\"ba\",\"bac\",\"bad\",\"ac\",\"d\"])\n >>> 4\n Explanation: Strings \"cc\", \"acd\", \"ac\", and \"d\" are consistent.\n \"\"\"\n"}
{"task_id": "sum-of-absolute-differences-in-a-sorted-array", "prompt": "def getSumAbsoluteDifferences(nums: List[int]) -> List[int]:\n \"\"\"\n You are given an integer array nums sorted in non-decreasing order.\n Build and return an integer array result with the same length as nums such that result[i] is equal to the summation of absolute differences between nums[i] and all the other elements in the array.\n In other words, result[i] is equal to sum(|nums[i]-nums[j]|) where 0 <= j < nums.length and j != i (0-indexed).\n \n Example 1:\n \n >>> getSumAbsoluteDifferences(nums = [2,3,5])\n >>> [4,3,5]\n Explanation: Assuming the arrays are 0-indexed, then\n result[0] = |2-2| + |2-3| + |2-5| = 0 + 1 + 3 = 4,\n result[1] = |3-2| + |3-3| + |3-5| = 1 + 0 + 2 = 3,\n result[2] = |5-2| + |5-3| + |5-5| = 3 + 2 + 0 = 5.\n \n Example 2:\n \n >>> getSumAbsoluteDifferences(nums = [1,4,6,8,10])\n >>> [24,15,13,15,21]\n \"\"\"\n"}
{"task_id": "stone-game-vi", "prompt": "def stoneGameVI(aliceValues: List[int], bobValues: List[int]) -> int:\n \"\"\"\n Alice and Bob take turns playing a game, with Alice starting first.\n There are n stones in a pile. On each player's turn, they can remove a stone from the pile and receive points based on the stone's value. Alice and Bob may value the stones differently.\n You are given two integer arrays of length n, aliceValues and bobValues. Each aliceValues[i] and bobValues[i] represents how Alice and Bob, respectively, value the ith stone.\n The winner is the person with the most points after all the stones are chosen. If both players have the same amount of points, the game results in a draw. Both players will play optimally.\u00a0Both players know the other's values.\n Determine the result of the game, and:\n \n If Alice wins, return 1.\n If Bob wins, return -1.\n If the game results in a draw, return 0.\n \n \n Example 1:\n \n >>> stoneGameVI(aliceValues = [1,3], bobValues = [2,1])\n >>> 1\n Explanation:\n If Alice takes stone 1 (0-indexed) first, Alice will receive 3 points.\n Bob can only choose stone 0, and will only receive 2 points.\n Alice wins.\n \n Example 2:\n \n >>> stoneGameVI(aliceValues = [1,2], bobValues = [3,1])\n >>> 0\n Explanation:\n If Alice takes stone 0, and Bob takes stone 1, they will both have 1 point.\n Draw.\n \n Example 3:\n \n >>> stoneGameVI(aliceValues = [2,4,3], bobValues = [1,6,7])\n >>> -1\n Explanation:\n Regardless of how Alice plays, Bob will be able to have more points than Alice.\n For example, if Alice takes stone 1, Bob can take stone 2, and Alice takes stone 0, Alice will have 6 points to Bob's 7.\n Bob wins.\n \"\"\"\n"}
{"task_id": "delivering-boxes-from-storage-to-ports", "prompt": "def boxDelivering(boxes: List[List[int]], portsCount: int, maxBoxes: int, maxWeight: int) -> int:\n \"\"\"\n You have the task of delivering some boxes from storage to their ports using only one ship. However, this ship has a limit on the number of boxes and the total weight that it can carry.\n You are given an array boxes, where boxes[i] = [ports\u200b\u200bi\u200b, weighti], and three integers portsCount, maxBoxes, and maxWeight.\n \n ports\u200b\u200bi is the port where you need to deliver the ith box and weightsi is the weight of the ith box.\n portsCount is the number of ports.\n maxBoxes and maxWeight are the respective box and weight limits of the ship.\n \n The boxes need to be delivered in the order they are given. The ship will follow these steps:\n \n The ship will take some number of boxes from the boxes queue, not violating the maxBoxes and maxWeight constraints.\n For each loaded box in order, the ship will make a trip to the port the box needs to be delivered to and deliver it. If the ship is already at the correct port, no trip is needed, and the box can immediately be delivered.\n The ship then makes a return trip to storage to take more boxes from the queue.\n \n The ship must end at storage after all the boxes have been delivered.\n Return the minimum number of trips the ship needs to make to deliver all boxes to their respective ports.\n \n Example 1:\n \n >>> boxDelivering(boxes = [[1,1],[2,1],[1,1]], portsCount = 2, maxBoxes = 3, maxWeight = 3)\n >>> 4\n Explanation: The optimal strategy is as follows:\n - The ship takes all the boxes in the queue, goes to port 1, then port 2, then port 1 again, then returns to storage. 4 trips.\n So the total number of trips is 4.\n Note that the first and third boxes cannot be delivered together because the boxes need to be delivered in order (i.e. the second box needs to be delivered at port 2 before the third box).\n \n Example 2:\n \n >>> boxDelivering(boxes = [[1,2],[3,3],[3,1],[3,1],[2,4]], portsCount = 3, maxBoxes = 3, maxWeight = 6)\n >>> 6\n Explanation: The optimal strategy is as follows:\n - The ship takes the first box, goes to port 1, then returns to storage. 2 trips.\n - The ship takes the second, third and fourth boxes, goes to port 3, then returns to storage. 2 trips.\n - The ship takes the fifth box, goes to port 2, then returns to storage. 2 trips.\n So the total number of trips is 2 + 2 + 2 = 6.\n \n Example 3:\n \n >>> boxDelivering(boxes = [[1,4],[1,2],[2,1],[2,1],[3,2],[3,4]], portsCount = 3, maxBoxes = 6, maxWeight = 7)\n >>> 6\n Explanation: The optimal strategy is as follows:\n - The ship takes the first and second boxes, goes to port 1, then returns to storage. 2 trips.\n - The ship takes the third and fourth boxes, goes to port 2, then returns to storage. 2 trips.\n - The ship takes the fifth and sixth boxes, goes to port 3, then returns to storage. 2 trips.\n So the total number of trips is 2 + 2 + 2 = 6.\n \"\"\"\n"}
{"task_id": "count-of-matches-in-tournament", "prompt": "def numberOfMatches(n: int) -> int:\n \"\"\"\n You are given an integer n, the number of teams in a tournament that has strange rules:\n \n If the current number of teams is even, each team gets paired with another team. A total of n / 2 matches are played, and n / 2 teams advance to the next round.\n If the current number of teams is odd, one team randomly advances in the tournament, and the rest gets paired. A total of (n - 1) / 2 matches are played, and (n - 1) / 2 + 1 teams advance to the next round.\n \n Return the number of matches played in the tournament until a winner is decided.\n \n Example 1:\n \n >>> numberOfMatches(n = 7)\n >>> 6\n Explanation: Details of the tournament:\n - 1st Round: Teams = 7, Matches = 3, and 4 teams advance.\n - 2nd Round: Teams = 4, Matches = 2, and 2 teams advance.\n - 3rd Round: Teams = 2, Matches = 1, and 1 team is declared the winner.\n Total number of matches = 3 + 2 + 1 = 6.\n \n Example 2:\n \n >>> numberOfMatches(n = 14)\n >>> 13\n Explanation: Details of the tournament:\n - 1st Round: Teams = 14, Matches = 7, and 7 teams advance.\n - 2nd Round: Teams = 7, Matches = 3, and 4 teams advance.\n - 3rd Round: Teams = 4, Matches = 2, and 2 teams advance.\n - 4th Round: Teams = 2, Matches = 1, and 1 team is declared the winner.\n Total number of matches = 7 + 3 + 2 + 1 = 13.\n \"\"\"\n"}
{"task_id": "partitioning-into-minimum-number-of-deci-binary-numbers", "prompt": "def minPartitions(n: str) -> int:\n \"\"\"\n A decimal number is called deci-binary if each of its digits is either 0 or 1 without any leading zeros. For example, 101 and 1100 are deci-binary, while 112 and 3001 are not.\n Given a string n that represents a positive decimal integer, return the minimum number of positive deci-binary numbers needed so that they sum up to n.\n \n Example 1:\n \n >>> minPartitions(n = \"32\")\n >>> 3\n Explanation: 10 + 11 + 11 = 32\n \n Example 2:\n \n >>> minPartitions(n = \"82734\")\n >>> 8\n \n Example 3:\n \n >>> minPartitions(n = \"27346209830709182346\")\n >>> 9\n \"\"\"\n"}
{"task_id": "stone-game-vii", "prompt": "def stoneGameVII(stones: List[int]) -> int:\n \"\"\"\n Alice and Bob take turns playing a game, with Alice starting first.\n There are n stones arranged in a row. On each player's turn, they can remove either the leftmost stone or the rightmost stone from the row and receive points equal to the sum of the remaining stones' values in the row. The winner is the one with the higher score when there are no stones left to remove.\n Bob found that he will always lose this game (poor Bob, he always loses), so he decided to minimize the score's difference. Alice's goal is to maximize the difference in the score.\n Given an array of integers stones where stones[i] represents the value of the ith stone from the left, return the difference in Alice and Bob's score if they both play optimally.\n \n Example 1:\n \n >>> stoneGameVII(stones = [5,3,1,4,2])\n >>> 6\n Explanation:\n - Alice removes 2 and gets 5 + 3 + 1 + 4 = 13 points. Alice = 13, Bob = 0, stones = [5,3,1,4].\n - Bob removes 5 and gets 3 + 1 + 4 = 8 points. Alice = 13, Bob = 8, stones = [3,1,4].\n - Alice removes 3 and gets 1 + 4 = 5 points. Alice = 18, Bob = 8, stones = [1,4].\n - Bob removes 1 and gets 4 points. Alice = 18, Bob = 12, stones = [4].\n - Alice removes 4 and gets 0 points. Alice = 18, Bob = 12, stones = [].\n The score difference is 18 - 12 = 6.\n \n Example 2:\n \n >>> stoneGameVII(stones = [7,90,5,1,100,10,10,2])\n >>> 122\n \"\"\"\n"}
{"task_id": "maximum-height-by-stacking-cuboids", "prompt": "def maxHeight(cuboids: List[List[int]]) -> int:\n \"\"\"\n Given n cuboids where the dimensions of the ith cuboid is cuboids[i] = [widthi, lengthi, heighti] (0-indexed). Choose a subset of cuboids and place them on each other.\n You can place cuboid i on cuboid j if widthi <= widthj and lengthi <= lengthj and heighti <= heightj. You can rearrange any cuboid's dimensions by rotating it to put it on another cuboid.\n Return the maximum height of the stacked cuboids.\n \n Example 1:\n \n \n >>> maxHeight(cuboids = [[50,45,20],[95,37,53],[45,23,12]])\n >>> 190\n Explanation:\n Cuboid 1 is placed on the bottom with the 53x37 side facing down with height 95.\n Cuboid 0 is placed next with the 45x20 side facing down with height 50.\n Cuboid 2 is placed next with the 23x12 side facing down with height 45.\n The total height is 95 + 50 + 45 = 190.\n \n Example 2:\n \n >>> maxHeight(cuboids = [[38,25,45],[76,35,3]])\n >>> 76\n Explanation:\n You can't place any of the cuboids on the other.\n We choose cuboid 1 and rotate it so that the 35x3 side is facing down and its height is 76.\n \n Example 3:\n \n >>> maxHeight(cuboids = [[7,11,17],[7,17,11],[11,7,17],[11,17,7],[17,7,11],[17,11,7]])\n >>> 102\n Explanation:\n After rearranging the cuboids, you can see that all cuboids have the same dimension.\n You can place the 11x7 side down on all cuboids so their heights are 17.\n The maximum height of stacked cuboids is 6 * 17 = 102.\n \"\"\"\n"}
{"task_id": "count-ways-to-distribute-candies", "prompt": "def waysToDistribute(n: int, k: int) -> int:\n \"\"\"\n There are n unique candies (labeled 1 through n) and k bags. You are asked to distribute all the candies into the bags such that every bag has at least one candy.\n There can be multiple ways to distribute the candies. Two ways are considered different if the candies in one bag in the first way are not all in the same bag in the second way. The order of the bags and the order of the candies within each bag do not matter.\n For example, (1), (2,3) and (2), (1,3) are considered different because candies 2 and 3 in the bag (2,3) in the first way are not in the same bag in the second way (they are split between the bags (2) and (1,3)). However, (1), (2,3) and (3,2), (1) are considered the same because the candies in each bag are all in the same bags in both ways.\n Given two integers, n and k, return the number of different ways to distribute the candies. As the answer may be too large, return it modulo 109 + 7.\n \n Example 1:\n \n \n >>> waysToDistribute(n = 3, k = 2)\n >>> 3\n Explanation: You can distribute 3 candies into 2 bags in 3 ways:\n (1), (2,3)\n (1,2), (3)\n (1,3), (2)\n \n Example 2:\n \n >>> waysToDistribute(n = 4, k = 2)\n >>> 7\n Explanation: You can distribute 4 candies into 2 bags in 7 ways:\n (1), (2,3,4)\n (1,2), (3,4)\n (1,3), (2,4)\n (1,4), (2,3)\n (1,2,3), (4)\n (1,2,4), (3)\n (1,3,4), (2)\n \n Example 3:\n \n >>> waysToDistribute(n = 20, k = 5)\n >>> 206085257\n Explanation: You can distribute 20 candies into 5 bags in 1881780996 ways. 1881780996 modulo 109 + 7 = 206085257.\n \"\"\"\n"}
{"task_id": "reformat-phone-number", "prompt": "def reformatNumber(number: str) -> str:\n \"\"\"\n You are given a phone number as a string number. number consists of digits, spaces ' ', and/or dashes '-'.\n You would like to reformat the phone number in a certain manner. Firstly, remove all spaces and dashes. Then, group the digits from left to right into blocks of length 3 until there are 4 or fewer digits. The final digits are then grouped as follows:\n \n 2 digits: A single block of length 2.\n 3 digits: A single block of length 3.\n 4 digits: Two blocks of length 2 each.\n \n The blocks are then joined by dashes. Notice that the reformatting process should never produce any blocks of length 1 and produce at most two blocks of length 2.\n Return the phone number after formatting.\n \n Example 1:\n \n >>> reformatNumber(number = \"1-23-45 6\")\n >>> \"123-456\"\n Explanation: The digits are \"123456\".\n Step 1: There are more than 4 digits, so group the next 3 digits. The 1st block is \"123\".\n Step 2: There are 3 digits remaining, so put them in a single block of length 3. The 2nd block is \"456\".\n Joining the blocks gives \"123-456\".\n \n Example 2:\n \n >>> reformatNumber(number = \"123 4-567\")\n >>> \"123-45-67\"\n Explanation: The digits are \"1234567\".\n Step 1: There are more than 4 digits, so group the next 3 digits. The 1st block is \"123\".\n Step 2: There are 4 digits left, so split them into two blocks of length 2. The blocks are \"45\" and \"67\".\n Joining the blocks gives \"123-45-67\".\n \n Example 3:\n \n >>> reformatNumber(number = \"123 4-5678\")\n >>> \"123-456-78\"\n Explanation: The digits are \"12345678\".\n Step 1: The 1st block is \"123\".\n Step 2: The 2nd block is \"456\".\n Step 3: There are 2 digits left, so put them in a single block of length 2. The 3rd block is \"78\".\n Joining the blocks gives \"123-456-78\".\n \"\"\"\n"}
{"task_id": "maximum-erasure-value", "prompt": "def maximumUniqueSubarray(nums: List[int]) -> int:\n \"\"\"\n You are given an array of positive integers nums and want to erase a subarray containing\u00a0unique elements. The score you get by erasing the subarray is equal to the sum of its elements.\n Return the maximum score you can get by erasing exactly one subarray.\n An array b is called to be a subarray of a if it forms a contiguous subsequence of a, that is, if it is equal to a[l],a[l+1],...,a[r] for some (l,r).\n \n Example 1:\n \n >>> maximumUniqueSubarray(nums = [4,2,4,5,6])\n >>> 17\n Explanation: The optimal subarray here is [2,4,5,6].\n \n Example 2:\n \n >>> maximumUniqueSubarray(nums = [5,2,1,2,5,2,1,2,5])\n >>> 8\n Explanation: The optimal subarray here is [5,2,1] or [1,2,5].\n \"\"\"\n"}
{"task_id": "jump-game-vi", "prompt": "def maxResult(nums: List[int], k: int) -> int:\n \"\"\"\n You are given a 0-indexed integer array nums and an integer k.\n You are initially standing at index 0. In one move, you can jump at most k steps forward without going outside the boundaries of the array. That is, you can jump from index i to any index in the range [i + 1, min(n - 1, i + k)] inclusive.\n You want to reach the last index of the array (index n - 1). Your score is the sum of all nums[j] for each index j you visited in the array.\n Return the maximum score you can get.\n \n Example 1:\n \n >>> maxResult(nums = [1,-1,-2,4,-7,3], k = 2)\n >>> 7\n Explanation: You can choose your jumps forming the subsequence [1,-1,4,3] (underlined above). The sum is 7.\n \n Example 2:\n \n >>> maxResult(nums = [10,-5,-2,4,0,3], k = 3)\n >>> 17\n Explanation: You can choose your jumps forming the subsequence [10,4,3] (underlined above). The sum is 17.\n \n Example 3:\n \n >>> maxResult(nums = [1,-5,-20,4,-1,3,-6,-3], k = 2)\n >>> 0\n \"\"\"\n"}
{"task_id": "checking-existence-of-edge-length-limited-paths", "prompt": "def distanceLimitedPathsExist(n: int, edgeList: List[List[int]], queries: List[List[int]]) -> List[bool]:\n \"\"\"\n An undirected graph of n nodes is defined by edgeList, where edgeList[i] = [ui, vi, disi] denotes an edge between nodes ui and vi with distance disi. Note that there may be multiple edges between two nodes.\n Given an array queries, where queries[j] = [pj, qj, limitj], your task is to determine for each queries[j] whether there is a path between pj and qj such that each edge on the path has a distance strictly less than limitj .\n Return a boolean array answer, where answer.length == queries.length and the jth value of answer is true if there is a path for queries[j] is true, and false otherwise.\n \n Example 1:\n \n \n >>> distanceLimitedPathsExist(n = 3, edgeList = [[0,1,2],[1,2,4],[2,0,8],[1,0,16]], queries = [[0,1,2],[0,2,5]])\n >>> [false,true]\n Explanation: The above figure shows the given graph. Note that there are two overlapping edges between 0 and 1 with distances 2 and 16.\n For the first query, between 0 and 1 there is no path where each distance is less than 2, thus we return false for this query.\n For the second query, there is a path (0 -> 1 -> 2) of two edges with distances less than 5, thus we return true for this query.\n \n Example 2:\n \n \n >>> distanceLimitedPathsExist(n = 5, edgeList = [[0,1,10],[1,2,5],[2,3,9],[3,4,13]], queries = [[0,4,14],[1,4,13]])\n >>> [true,false]\n Explanation: The above figure shows the given graph.\n \"\"\"\n"}
{"task_id": "number-of-distinct-substrings-in-a-string", "prompt": "def countDistinct(s: str) -> int:\n \"\"\"\n Given a string s, return the number of distinct substrings of\u00a0s.\n A substring of a string is obtained by deleting any number of characters (possibly zero) from the front of the string and any number (possibly zero) from the back of the string.\n \n Example 1:\n \n >>> countDistinct(s = \"aabbaba\")\n >>> 21\n Explanation: The set of distinct strings is [\"a\",\"b\",\"aa\",\"bb\",\"ab\",\"ba\",\"aab\",\"abb\",\"bab\",\"bba\",\"aba\",\"aabb\",\"abba\",\"bbab\",\"baba\",\"aabba\",\"abbab\",\"bbaba\",\"aabbab\",\"abbaba\",\"aabbaba\"]\n \n Example 2:\n \n >>> countDistinct(s = \"abcdefg\")\n >>> 28\n \"\"\"\n"}
{"task_id": "number-of-students-unable-to-eat-lunch", "prompt": "def countStudents(students: List[int], sandwiches: List[int]) -> int:\n \"\"\"\n The school cafeteria offers circular and square sandwiches at lunch break, referred to by numbers 0 and 1 respectively. All students stand in a queue. Each student either prefers square or circular sandwiches.\n The number of sandwiches in the cafeteria is equal to the number of students. The sandwiches are placed in a stack. At each step:\n \n If the student at the front of the queue prefers the sandwich on the top of the stack, they will take it and leave the queue.\n Otherwise, they will leave it and go to the queue's end.\n \n This continues until none of the queue students want to take the top sandwich and are thus unable to eat.\n You are given two integer arrays students and sandwiches where sandwiches[i] is the type of the i\u200b\u200b\u200b\u200b\u200b\u200bth sandwich in the stack (i = 0 is the top of the stack) and students[j] is the preference of the j\u200b\u200b\u200b\u200b\u200b\u200bth student in the initial queue (j = 0 is the front of the queue). Return the number of students that are unable to eat.\n \n Example 1:\n \n >>> countStudents(students = [1,1,0,0], sandwiches = [0,1,0,1])\n >>> 0\n Explanation:\n - Front student leaves the top sandwich and returns to the end of the line making students = [1,0,0,1].\n - Front student leaves the top sandwich and returns to the end of the line making students = [0,0,1,1].\n - Front student takes the top sandwich and leaves the line making students = [0,1,1] and sandwiches = [1,0,1].\n - Front student leaves the top sandwich and returns to the end of the line making students = [1,1,0].\n - Front student takes the top sandwich and leaves the line making students = [1,0] and sandwiches = [0,1].\n - Front student leaves the top sandwich and returns to the end of the line making students = [0,1].\n - Front student takes the top sandwich and leaves the line making students = [1] and sandwiches = [1].\n - Front student takes the top sandwich and leaves the line making students = [] and sandwiches = [].\n Hence all students are able to eat.\n \n Example 2:\n \n >>> countStudents(students = [1,1,1,0,0,1], sandwiches = [1,0,0,0,1,1])\n >>> 3\n \"\"\"\n"}
{"task_id": "average-waiting-time", "prompt": "def averageWaitingTime(customers: List[List[int]]) -> float:\n \"\"\"\n There is a restaurant with a single chef. You are given an array customers, where customers[i] = [arrivali, timei]:\n \n arrivali is the arrival time of the ith customer. The arrival times are sorted in non-decreasing order.\n timei is the time needed to prepare the order of the ith customer.\n \n When a customer arrives, he gives the chef his order, and the chef starts preparing it once he is idle. The customer waits till the chef finishes preparing his order. The chef does not prepare food for more than one customer at a time. The chef prepares food for customers in the order they were given in the input.\n Return the average waiting time of all customers. Solutions within 10-5 from the actual answer are considered accepted.\n \n Example 1:\n \n >>> averageWaitingTime(customers = [[1,2],[2,5],[4,3]])\n >>> 5.00000\n Explanation:\n 1) The first customer arrives at time 1, the chef takes his order and starts preparing it immediately at time 1, and finishes at time 3, so the waiting time of the first customer is 3 - 1 = 2.\n 2) The second customer arrives at time 2, the chef takes his order and starts preparing it at time 3, and finishes at time 8, so the waiting time of the second customer is 8 - 2 = 6.\n 3) The third customer arrives at time 4, the chef takes his order and starts preparing it at time 8, and finishes at time 11, so the waiting time of the third customer is 11 - 4 = 7.\n So the average waiting time = (2 + 6 + 7) / 3 = 5.\n \n Example 2:\n \n >>> averageWaitingTime(customers = [[5,2],[5,4],[10,3],[20,1]])\n >>> 3.25000\n Explanation:\n 1) The first customer arrives at time 5, the chef takes his order and starts preparing it immediately at time 5, and finishes at time 7, so the waiting time of the first customer is 7 - 5 = 2.\n 2) The second customer arrives at time 5, the chef takes his order and starts preparing it at time 7, and finishes at time 11, so the waiting time of the second customer is 11 - 5 = 6.\n 3) The third customer arrives at time 10, the chef takes his order and starts preparing it at time 11, and finishes at time 14, so the waiting time of the third customer is 14 - 10 = 4.\n 4) The fourth customer arrives at time 20, the chef takes his order and starts preparing it immediately at time 20, and finishes at time 21, so the waiting time of the fourth customer is 21 - 20 = 1.\n So the average waiting time = (2 + 6 + 4 + 1) / 4 = 3.25.\n \"\"\"\n"}
{"task_id": "maximum-binary-string-after-change", "prompt": "def maximumBinaryString(binary: str) -> str:\n \"\"\"\n You are given a binary string binary consisting of only 0's or 1's. You can apply each of the following operations any number of times:\n \n Operation 1: If the number contains the substring \"00\", you can replace it with \"10\".\n \n \n For example, \"00010\" -> \"10010\"\n \n \n Operation 2: If the number contains the substring \"10\", you can replace it with \"01\".\n \n For example, \"00010\" -> \"00001\"\n \n \n \n Return the maximum binary string you can obtain after any number of operations. Binary string x is greater than binary string y if x's decimal representation is greater than y's decimal representation.\n \n Example 1:\n \n >>> maximumBinaryString(binary = \"000110\")\n >>> \"111011\"\n Explanation: A valid transformation sequence can be:\n \"000110\" -> \"000101\"\n \"000101\" -> \"100101\"\n \"100101\" -> \"110101\"\n \"110101\" -> \"110011\"\n \"110011\" -> \"111011\"\n \n Example 2:\n \n >>> maximumBinaryString(binary = \"01\")\n >>> \"01\"\n Explanation:\u00a0\"01\" cannot be transformed any further.\n \"\"\"\n"}
{"task_id": "minimum-adjacent-swaps-for-k-consecutive-ones", "prompt": "def minMoves(nums: List[int], k: int) -> int:\n \"\"\"\n You are given an integer array, nums, and an integer k. nums comprises of only 0's and 1's. In one move, you can choose two adjacent indices and swap their values.\n Return the minimum number of moves required so that nums has k consecutive 1's.\n \n Example 1:\n \n >>> minMoves(nums = [1,0,0,1,0,1], k = 2)\n >>> 1\n Explanation: In 1 move, nums could be [1,0,0,0,1,1] and have 2 consecutive 1's.\n \n Example 2:\n \n >>> minMoves(nums = [1,0,0,0,0,0,1,1], k = 3)\n >>> 5\n Explanation: In 5 moves, the leftmost 1 can be shifted right until nums = [0,0,0,0,0,1,1,1].\n \n Example 3:\n \n >>> minMoves(nums = [1,1,0,1], k = 2)\n >>> 0\n Explanation: nums already has 2 consecutive 1's.\n \"\"\"\n"}
{"task_id": "determine-if-string-halves-are-alike", "prompt": "def halvesAreAlike(s: str) -> bool:\n \"\"\"\n You are given a string s of even length. Split this string into two halves of equal lengths, and let a be the first half and b be the second half.\n Two strings are alike if they have the same number of vowels ('a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'). Notice that s contains uppercase and lowercase letters.\n Return true if a and b are alike. Otherwise, return false.\n \n Example 1:\n \n >>> halvesAreAlike(s = \"book\")\n >>> true\n Explanation: a = \"bo\" and b = \"ok\". a has 1 vowel and b has 1 vowel. Therefore, they are alike.\n \n Example 2:\n \n >>> halvesAreAlike(s = \"textbook\")\n >>> false\n Explanation: a = \"text\" and b = \"book\". a has 1 vowel whereas b has 2. Therefore, they are not alike.\n Notice that the vowel o is counted twice.\n \"\"\"\n"}
{"task_id": "maximum-number-of-eaten-apples", "prompt": "def eatenApples(apples: List[int], days: List[int]) -> int:\n \"\"\"\n There is a special kind of apple tree that grows apples every day for n days. On the ith day, the tree grows apples[i] apples that will rot after days[i] days, that is on day i + days[i] the apples will be rotten and cannot be eaten. On some days, the apple tree does not grow any apples, which are denoted by apples[i] == 0 and days[i] == 0.\n You decided to eat at most one apple a day (to keep the doctors away). Note that you can keep eating after the first n days.\n Given two integer arrays days and apples of length n, return the maximum number of apples you can eat.\n \n Example 1:\n \n >>> eatenApples(apples = [1,2,3,5,2], days = [3,2,1,4,2])\n >>> 7\n Explanation: You can eat 7 apples:\n - On the first day, you eat an apple that grew on the first day.\n - On the second day, you eat an apple that grew on the second day.\n - On the third day, you eat an apple that grew on the second day. After this day, the apples that grew on the third day rot.\n - On the fourth to the seventh days, you eat apples that grew on the fourth day.\n \n Example 2:\n \n >>> eatenApples(apples = [3,0,0,0,0,2], days = [3,0,0,0,0,2])\n >>> 5\n Explanation: You can eat 5 apples:\n - On the first to the third day you eat apples that grew on the first day.\n - Do nothing on the fouth and fifth days.\n - On the sixth and seventh days you eat apples that grew on the sixth day.\n \"\"\"\n"}
{"task_id": "where-will-the-ball-fall", "prompt": "def findBall(grid: List[List[int]]) -> List[int]:\n \"\"\"\n You have a 2-D grid of size m x n representing a box, and you have n balls. The box is open on the top and bottom sides.\n Each cell in the box has a diagonal board spanning two corners of the cell that can redirect a ball to the right or to the left.\n \n A board that redirects the ball to the right spans the top-left corner to the bottom-right corner and is represented in the grid as 1.\n A board that redirects the ball to the left spans the top-right corner to the bottom-left corner and is represented in the grid as -1.\n \n We drop one ball at the top of each column of the box. Each ball can get stuck in the box or fall out of the bottom. A ball gets stuck if it hits a \"V\" shaped pattern between two boards or if a board redirects the ball into either wall of the box.\n Return an array answer of size n where answer[i] is the column that the ball falls out of at the bottom after dropping the ball from the ith column at the top, or -1 if the ball gets stuck in the box.\n \n Example 1:\n \n \n >>> findBall(grid = [[1,1,1,-1,-1],[1,1,1,-1,-1],[-1,-1,-1,1,1],[1,1,1,1,-1],[-1,-1,-1,-1,-1]])\n >>> [1,-1,-1,-1,-1]\n Explanation: This example is shown in the photo.\n Ball b0 is dropped at column 0 and falls out of the box at column 1.\n Ball b1 is dropped at column 1 and will get stuck in the box between column 2 and 3 and row 1.\n Ball b2 is dropped at column 2 and will get stuck on the box between column 2 and 3 and row 0.\n Ball b3 is dropped at column 3 and will get stuck on the box between column 2 and 3 and row 0.\n Ball b4 is dropped at column 4 and will get stuck on the box between column 2 and 3 and row 1.\n \n Example 2:\n \n >>> findBall(grid = [[-1]])\n >>> [-1]\n Explanation: The ball gets stuck against the left wall.\n \n Example 3:\n \n >>> findBall(grid = [[1,1,1,1,1,1],[-1,-1,-1,-1,-1,-1],[1,1,1,1,1,1],[-1,-1,-1,-1,-1,-1]])\n >>> [0,1,2,3,4,-1]\n \"\"\"\n"}
{"task_id": "maximum-xor-with-an-element-from-array", "prompt": "def maximizeXor(nums: List[int], queries: List[List[int]]) -> List[int]:\n \"\"\"\n You are given an array nums consisting of non-negative integers. You are also given a queries array, where queries[i] = [xi, mi].\n The answer to the ith query is the maximum bitwise XOR value of xi and any element of nums that does not exceed mi. In other words, the answer is max(nums[j] XOR xi) for all j such that nums[j] <= mi. If all elements in nums are larger than mi, then the answer is -1.\n Return an integer array answer where answer.length == queries.length and answer[i] is the answer to the ith query.\n \n Example 1:\n \n >>> maximizeXor(nums = [0,1,2,3,4], queries = [[3,1],[1,3],[5,6]])\n >>> [3,3,7]\n Explanation:\n 1) 0 and 1 are the only two integers not greater than 1. 0 XOR 3 = 3 and 1 XOR 3 = 2. The larger of the two is 3.\n 2) 1 XOR 2 = 3.\n 3) 5 XOR 2 = 7.\n \n Example 2:\n \n >>> maximizeXor(nums = [5,2,4,6,6,3], queries = [[12,4],[8,1],[6,3]])\n >>> [15,-1,5]\n \"\"\"\n"}
{"task_id": "largest-subarray-length-k", "prompt": "def largestSubarray(nums: List[int], k: int) -> List[int]:\n \"\"\"\n An array A is larger than some array B if for the first index i where A[i] != B[i], A[i] > B[i].\n For example, consider 0-indexing:\n \n [1,3,2,4] > [1,2,2,4], since at index 1, 3 > 2.\n [1,4,4,4] < [2,1,1,1], since at index 0, 1 < 2.\n \n A subarray is a contiguous subsequence of the array.\n Given an integer array nums of distinct integers, return the largest subarray of nums of length k.\n \n Example 1:\n \n >>> largestSubarray(nums = [1,4,5,2,3], k = 3)\n >>> [5,2,3]\n Explanation: The subarrays of size 3 are: [1,4,5], [4,5,2], and [5,2,3].\n Of these, [5,2,3] is the largest.\n Example 2:\n \n >>> largestSubarray(nums = [1,4,5,2,3], k = 4)\n >>> [4,5,2,3]\n Explanation: The subarrays of size 4 are: [1,4,5,2], and [4,5,2,3].\n Of these, [4,5,2,3] is the largest.\n Example 3:\n \n >>> largestSubarray(nums = [1,4,5,2,3], k = 1)\n >>> [5]\n \"\"\"\n"}
{"task_id": "maximum-units-on-a-truck", "prompt": "def maximumUnits(boxTypes: List[List[int]], truckSize: int) -> int:\n \"\"\"\n You are assigned to put some amount of boxes onto one truck. You are given a 2D array boxTypes, where boxTypes[i] = [numberOfBoxesi, numberOfUnitsPerBoxi]:\n \n numberOfBoxesi is the number of boxes of type i.\n numberOfUnitsPerBoxi is the number of units in each box of the type i.\n \n You are also given an integer truckSize, which is the maximum number of boxes that can be put on the truck. You can choose any boxes to put on the truck as long as the number\u00a0of boxes does not exceed truckSize.\n Return the maximum total number of units that can be put on the truck.\n \n Example 1:\n \n >>> maximumUnits(boxTypes = [[1,3],[2,2],[3,1]], truckSize = 4)\n >>> 8\n Explanation: There are:\n - 1 box of the first type that contains 3 units.\n - 2 boxes of the second type that contain 2 units each.\n - 3 boxes of the third type that contain 1 unit each.\n You can take all the boxes of the first and second types, and one box of the third type.\n The total number of units will be = (1 * 3) + (2 * 2) + (1 * 1) = 8.\n \n Example 2:\n \n >>> maximumUnits(boxTypes = [[5,10],[2,5],[4,7],[3,9]], truckSize = 10)\n >>> 91\n \"\"\"\n"}
{"task_id": "count-good-meals", "prompt": "def countPairs(deliciousness: List[int]) -> int:\n \"\"\"\n A good meal is a meal that contains exactly two different food items with a sum of deliciousness equal to a power of two.\n You can pick any two different foods to make a good meal.\n Given an array of integers deliciousness where deliciousness[i] is the deliciousness of the i\u200b\u200b\u200b\u200b\u200b\u200bth\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b item of food, return the number of different good meals you can make from this list modulo 109 + 7.\n Note that items with different indices are considered different even if they have the same deliciousness value.\n \n Example 1:\n \n >>> countPairs(deliciousness = [1,3,5,7,9])\n >>> 4\n Explanation: The good meals are (1,3), (1,7), (3,5) and, (7,9).\n Their respective sums are 4, 8, 8, and 16, all of which are powers of 2.\n \n Example 2:\n \n >>> countPairs(deliciousness = [1,1,1,3,3,3,7])\n >>> 15\n Explanation: The good meals are (1,1) with 3 ways, (1,3) with 9 ways, and (1,7) with 3 ways.\n \"\"\"\n"}
{"task_id": "ways-to-split-array-into-three-subarrays", "prompt": "def waysToSplit(nums: List[int]) -> int:\n \"\"\"\n A split of an integer array is good if:\n \n The array is split into three non-empty contiguous subarrays - named left, mid, right respectively from left to right.\n The sum of the elements in left is less than or equal to the sum of the elements in mid, and the sum of the elements in mid is less than or equal to the sum of the elements in right.\n \n Given nums, an array of non-negative integers, return the number of good ways to split nums. As the number may be too large, return it modulo 109 + 7.\n \n Example 1:\n \n >>> waysToSplit(nums = [1,1,1])\n >>> 1\n Explanation: The only good way to split nums is [1] [1] [1].\n Example 2:\n \n >>> waysToSplit(nums = [1,2,2,2,5,0])\n >>> 3\n Explanation: There are three good ways of splitting nums:\n [1] [2] [2,2,5,0]\n [1] [2,2] [2,5,0]\n [1,2] [2,2] [5,0]\n \n Example 3:\n \n >>> waysToSplit(nums = [3,2,1])\n >>> 0\n Explanation: There is no good way to split nums.\n \"\"\"\n"}
{"task_id": "minimum-operations-to-make-a-subsequence", "prompt": "def minOperations(target: List[int], arr: List[int]) -> int:\n \"\"\"\n You are given an array target that consists of distinct integers and another integer array arr that can have duplicates.\n In one operation, you can insert any integer at any position in arr. For example, if arr = [1,4,1,2], you can add 3 in the middle and make it [1,4,3,1,2]. Note that you can insert the integer at the very beginning or end of the array.\n Return the minimum number of operations needed to make target a subsequence of arr.\n A subsequence of an array is a new array generated from the original array by deleting some elements (possibly none) without changing the remaining elements' relative order. For example, [2,7,4] is a subsequence of [4,2,3,7,2,1,4] (the underlined elements), while [2,4,2] is not.\n \n Example 1:\n \n >>> minOperations(target = [5,1,3], arr = [9,4,2,3,4])\n >>> 2\n Explanation: You can add 5 and 1 in such a way that makes arr = [5,9,4,1,2,3,4], then target will be a subsequence of arr.\n \n Example 2:\n \n >>> minOperations(target = [6,4,8,1,3,2], arr = [4,7,6,2,3,8,6,1])\n >>> 3\n \"\"\"\n"}
{"task_id": "sum-of-special-evenly-spaced-elements-in-array", "prompt": "def solve(nums: List[int], queries: List[List[int]]) -> List[int]:\n \"\"\"\n You are given a 0-indexed integer array nums consisting of n non-negative integers.\n You are also given an array queries, where queries[i] = [xi, yi]. The answer to the ith query is the sum of all nums[j] where xi <= j < n and (j - xi) is divisible by yi.\n Return an array answer where answer.length == queries.length and answer[i] is the answer to the ith query modulo 109 + 7.\n \n Example 1:\n \n >>> solve(nums = [0,1,2,3,4,5,6,7], queries = [[0,3],[5,1],[4,2]])\n >>> [9,18,10]\n Explanation: The answers of the queries are as follows:\n 1) The j indices that satisfy this query are 0, 3, and 6. nums[0] + nums[3] + nums[6] = 9\n 2) The j indices that satisfy this query are 5, 6, and 7. nums[5] + nums[6] + nums[7] = 18\n 3) The j indices that satisfy this query are 4 and 6. nums[4] + nums[6] = 10\n \n Example 2:\n \n >>> solve(nums = [100,200,101,201,102,202,103,203], queries = [[0,7]])\n >>> [303]\n \"\"\"\n"}
{"task_id": "calculate-money-in-leetcode-bank", "prompt": "def totalMoney(n: int) -> int:\n \"\"\"\n Hercy wants to save money for his first car. He puts money in the Leetcode\u00a0bank every day.\n He starts by putting in $1 on Monday, the first day. Every day from Tuesday to Sunday, he will put in $1 more than the day before. On every subsequent Monday, he will put in $1 more than the previous Monday.\n Given n, return the total amount of money he will have in the Leetcode bank at the end of the nth day.\n \n Example 1:\n \n >>> totalMoney(n = 4)\n >>> 10\n Explanation:\u00a0After the 4th day, the total is 1 + 2 + 3 + 4 = 10.\n \n Example 2:\n \n >>> totalMoney(n = 10)\n >>> 37\n Explanation:\u00a0After the 10th day, the total is (1 + 2 + 3 + 4 + 5 + 6 + 7) + (2 + 3 + 4) = 37. Notice that on the 2nd Monday, Hercy only puts in $2.\n \n Example 3:\n \n >>> totalMoney(n = 20)\n >>> 96\n Explanation:\u00a0After the 20th day, the total is (1 + 2 + 3 + 4 + 5 + 6 + 7) + (2 + 3 + 4 + 5 + 6 + 7 + 8) + (3 + 4 + 5 + 6 + 7 + 8) = 96.\n \"\"\"\n"}
{"task_id": "maximum-score-from-removing-substrings", "prompt": "def maximumGain(s: str, x: int, y: int) -> int:\n \"\"\"\n You are given a string s and two integers x and y. You can perform two types of operations any number of times.\n \n Remove substring \"ab\" and gain x points.\n \n \n For example, when removing \"ab\" from \"cabxbae\" it becomes \"cxbae\".\n \n \n Remove substring \"ba\" and gain y points.\n \n For example, when removing \"ba\" from \"cabxbae\" it becomes \"cabxe\".\n \n \n \n Return the maximum points you can gain after applying the above operations on s.\n \n Example 1:\n \n >>> maximumGain(s = \"cdbcbbaaabab\", x = 4, y = 5)\n >>> 19\n Explanation:\n - Remove the \"ba\" underlined in \"cdbcbbaaabab\". Now, s = \"cdbcbbaaab\" and 5 points are added to the score.\n - Remove the \"ab\" underlined in \"cdbcbbaaab\". Now, s = \"cdbcbbaa\" and 4 points are added to the score.\n - Remove the \"ba\" underlined in \"cdbcbbaa\". Now, s = \"cdbcba\" and 5 points are added to the score.\n - Remove the \"ba\" underlined in \"cdbcba\". Now, s = \"cdbc\" and 5 points are added to the score.\n Total score = 5 + 4 + 5 + 5 = 19.\n Example 2:\n \n >>> maximumGain(s = \"aabbaaxybbaabb\", x = 5, y = 4)\n >>> 20\n \"\"\"\n"}
{"task_id": "construct-the-lexicographically-largest-valid-sequence", "prompt": "def constructDistancedSequence(n: int) -> List[int]:\n \"\"\"\n Given an integer n, find a sequence with elements in the range [1, n] that satisfies all of the following:\n \n The integer 1 occurs once in the sequence.\n Each integer between 2 and n occurs twice in the sequence.\n For every integer i between 2 and n, the distance between the two occurrences of i is exactly i.\n \n The distance between two numbers on the sequence, a[i] and a[j], is the absolute difference of their indices, |j - i|.\n Return the lexicographically largest sequence. It is guaranteed that under the given constraints, there is always a solution.\n A sequence a is lexicographically larger than a sequence b (of the same length) if in the first position where a and b differ, sequence a has a number greater than the corresponding number in b. For example, [0,1,9,0] is lexicographically larger than [0,1,5,6] because the first position they differ is at the third number, and 9 is greater than 5.\n \n Example 1:\n \n >>> constructDistancedSequence(n = 3)\n >>> [3,1,2,3,2]\n Explanation: [2,3,2,1,3] is also a valid sequence, but [3,1,2,3,2] is the lexicographically largest valid sequence.\n \n Example 2:\n \n >>> constructDistancedSequence(n = 5)\n >>> [5,3,1,4,3,5,2,4,2]\n \"\"\"\n"}
{"task_id": "number-of-ways-to-reconstruct-a-tree", "prompt": "def checkWays(pairs: List[List[int]]) -> int:\n \"\"\"\n You are given an array pairs, where pairs[i] = [xi, yi], and:\n \n There are no duplicates.\n xi < yi\n \n Let ways be the number of rooted trees that satisfy the following conditions:\n \n The tree consists of nodes whose values appeared in pairs.\n A pair [xi, yi] exists in pairs if and only if xi is an ancestor of yi or yi is an ancestor of xi.\n Note: the tree does not have to be a binary tree.\n \n Two ways are considered to be different if there is at least one node that has different parents in both ways.\n Return:\n \n 0 if ways == 0\n 1 if ways == 1\n 2 if ways > 1\n \n A rooted tree is a tree that has a single root node, and all edges are oriented to be outgoing from the root.\n An ancestor of a node is any node on the path from the root to that node (excluding the node itself). The root has no ancestors.\n \n Example 1:\n \n \n >>> checkWays(pairs = [[1,2],[2,3]])\n >>> 1\n Explanation: There is exactly one valid rooted tree, which is shown in the above figure.\n \n Example 2:\n \n \n >>> checkWays(pairs = [[1,2],[2,3],[1,3]])\n >>> 2\n Explanation: There are multiple valid rooted trees. Three of them are shown in the above figures.\n \n Example 3:\n \n >>> checkWays(pairs = [[1,2],[2,3],[2,4],[1,5]])\n >>> 0\n Explanation: There are no valid rooted trees.\n \"\"\"\n"}
{"task_id": "decode-xored-array", "prompt": "def decode(encoded: List[int], first: int) -> List[int]:\n \"\"\"\n There is a hidden integer array arr that consists of n non-negative integers.\n It was encoded into another integer array encoded of length n - 1, such that encoded[i] = arr[i] XOR arr[i + 1]. For example, if arr = [1,0,2,1], then encoded = [1,2,3].\n You are given the encoded array. You are also given an integer first, that is the first element of arr, i.e. arr[0].\n Return the original array arr. It can be proved that the answer exists and is unique.\n \n Example 1:\n \n >>> decode(encoded = [1,2,3], first = 1)\n >>> [1,0,2,1]\n Explanation: If arr = [1,0,2,1], then first = 1 and encoded = [1 XOR 0, 0 XOR 2, 2 XOR 1] = [1,2,3]\n \n Example 2:\n \n >>> decode(encoded = [6,2,7,3], first = 4)\n >>> [4,2,0,7,4]\n \"\"\"\n"}
{"task_id": "swapping-nodes-in-a-linked-list", "prompt": "# class ListNode:\n# def __init__(val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution:\n def swapNodes(head: Optional[ListNode], k: int) -> Optional[ListNode]:\n \"\"\"\n You are given the head of a linked list, and an integer k.\n Return the head of the linked list after swapping the values of the kth node from the beginning and the kth node from the end (the list is 1-indexed).\n \n Example 1:\n \n \n >>> __init__(head = [1,2,3,4,5], k = 2)\n >>> [1,4,3,2,5]\n \n Example 2:\n \n >>> __init__(head = [7,9,6,6,7,8,3,0,9,5], k = 5)\n >>> [7,9,6,6,8,7,3,0,9,5]\n \"\"\"\n"}
{"task_id": "minimize-hamming-distance-after-swap-operations", "prompt": "def minimumHammingDistance(source: List[int], target: List[int], allowedSwaps: List[List[int]]) -> int:\n \"\"\"\n You are given two integer arrays, source and target, both of length n. You are also given an array allowedSwaps where each allowedSwaps[i] = [ai, bi] indicates that you are allowed to swap the elements at index ai and index bi (0-indexed) of array source. Note that you can swap elements at a specific pair of indices multiple times and in any order.\n The Hamming distance of two arrays of the same length, source and target, is the number of positions where the elements are different. Formally, it is the number of indices i for 0 <= i <= n-1 where source[i] != target[i] (0-indexed).\n Return the minimum Hamming distance of source and target after performing any amount of swap operations on array source.\n \n Example 1:\n \n >>> minimumHammingDistance(source = [1,2,3,4], target = [2,1,4,5], allowedSwaps = [[0,1],[2,3]])\n >>> 1\n Explanation: source can be transformed the following way:\n - Swap indices 0 and 1: source = [2,1,3,4]\n - Swap indices 2 and 3: source = [2,1,4,3]\n The Hamming distance of source and target is 1 as they differ in 1 position: index 3.\n \n Example 2:\n \n >>> minimumHammingDistance(source = [1,2,3,4], target = [1,3,2,4], allowedSwaps = [])\n >>> 2\n Explanation: There are no allowed swaps.\n The Hamming distance of source and target is 2 as they differ in 2 positions: index 1 and index 2.\n \n Example 3:\n \n >>> minimumHammingDistance(source = [5,1,2,4,3], target = [1,5,4,2,3], allowedSwaps = [[0,4],[4,2],[1,3],[1,4]])\n >>> 0\n \"\"\"\n"}
{"task_id": "find-minimum-time-to-finish-all-jobs", "prompt": "def minimumTimeRequired(jobs: List[int], k: int) -> int:\n \"\"\"\n You are given an integer array jobs, where jobs[i] is the amount of time it takes to complete the ith job.\n There are k workers that you can assign jobs to. Each job should be assigned to exactly one worker. The working time of a worker is the sum of the time it takes to complete all jobs assigned to them. Your goal is to devise an optimal assignment such that the maximum working time of any worker is minimized.\n Return the minimum possible maximum working time of any assignment.\n \n Example 1:\n \n >>> minimumTimeRequired(jobs = [3,2,3], k = 3)\n >>> 3\n Explanation: By assigning each person one job, the maximum time is 3.\n \n Example 2:\n \n >>> minimumTimeRequired(jobs = [1,2,4,7,8], k = 2)\n >>> 11\n Explanation: Assign the jobs the following way:\n Worker 1: 1, 2, 8 (working time = 1 + 2 + 8 = 11)\n Worker 2: 4, 7 (working time = 4 + 7 = 11)\n The maximum working time is 11.\n \"\"\"\n"}
{"task_id": "number-of-rectangles-that-can-form-the-largest-square", "prompt": "def countGoodRectangles(rectangles: List[List[int]]) -> int:\n \"\"\"\n You are given an array rectangles where rectangles[i] = [li, wi] represents the ith rectangle of length li and width wi.\\r\n \\r\n You can cut the ith rectangle to form a square with a side length of k if both k <= li and k <= wi. For example, if you have a rectangle [4,6], you can cut it to get a square with a side length of at most 4.\\r\n \\r\n Let maxLen be the side length of the largest square you can obtain from any of the given rectangles.\\r\n \\r\n Return the number of rectangles that can make a square with a side length of maxLen.\\r\n \\r\n \u00a0\\r\n Example 1:\\r\n \\r\n \\r\n >>> countGoodRectangles(rectangles = [[5,8],[3,9],[5,12],[16,5]]\\r)\n >>> 3\\r\n Explanation: The largest squares you can get from each rectangle are of lengths [5,3,5,5].\\r\n The largest possible square is of length 5, and you can get it out of 3 rectangles.\\r\n \\r\n \\r\n Example 2:\\r\n \\r\n \\r\n >>> countGoodRectangles(rectangles = [[2,3],[3,7],[4,3],[3,7]]\\r)\n >>> 3\\r\n \\r\n \\r\n \u00a0\\r\n \"\"\"\n"}
{"task_id": "tuple-with-same-product", "prompt": "def tupleSameProduct(nums: List[int]) -> int:\n \"\"\"\n Given an array nums of distinct positive integers, return the number of tuples (a, b, c, d) such that a * b = c * d where a, b, c, and d are elements of nums, and a != b != c != d.\n \n Example 1:\n \n >>> tupleSameProduct(nums = [2,3,4,6])\n >>> 8\n Explanation: There are 8 valid tuples:\n (2,6,3,4) , (2,6,4,3) , (6,2,3,4) , (6,2,4,3)\n (3,4,2,6) , (4,3,2,6) , (3,4,6,2) , (4,3,6,2)\n \n Example 2:\n \n >>> tupleSameProduct(nums = [1,2,4,5,10])\n >>> 16\n Explanation: There are 16 valid tuples:\n (1,10,2,5) , (1,10,5,2) , (10,1,2,5) , (10,1,5,2)\n (2,5,1,10) , (2,5,10,1) , (5,2,1,10) , (5,2,10,1)\n (2,10,4,5) , (2,10,5,4) , (10,2,4,5) , (10,2,5,4)\n (4,5,2,10) , (4,5,10,2) , (5,4,2,10) , (5,4,10,2)\n \"\"\"\n"}
{"task_id": "largest-submatrix-with-rearrangements", "prompt": "def largestSubmatrix(matrix: List[List[int]]) -> int:\n \"\"\"\n You are given a binary matrix matrix of size m x n, and you are allowed to rearrange the columns of the matrix in any order.\n Return the area of the largest submatrix within matrix where every element of the submatrix is 1 after reordering the columns optimally.\n \n Example 1:\n \n \n >>> largestSubmatrix(matrix = [[0,0,1],[1,1,1],[1,0,1]])\n >>> 4\n Explanation: You can rearrange the columns as shown above.\n The largest submatrix of 1s, in bold, has an area of 4.\n \n Example 2:\n \n \n >>> largestSubmatrix(matrix = [[1,0,1,0,1]])\n >>> 3\n Explanation: You can rearrange the columns as shown above.\n The largest submatrix of 1s, in bold, has an area of 3.\n \n Example 3:\n \n >>> largestSubmatrix(matrix = [[1,1,0],[1,0,1]])\n >>> 2\n Explanation: Notice that you must rearrange entire columns, and there is no way to make a submatrix of 1s larger than an area of 2.\n \"\"\"\n"}
{"task_id": "cat-and-mouse-ii", "prompt": "def canMouseWin(grid: List[str], catJump: int, mouseJump: int) -> bool:\n \"\"\"\n A game is played by a cat and a mouse named Cat and Mouse.\n The environment is represented by a grid of size rows x cols, where each element is a wall, floor, player (Cat, Mouse), or food.\n \n Players are represented by the characters 'C'(Cat),'M'(Mouse).\n Floors are represented by the character '.' and can be walked on.\n Walls are represented by the character '#' and cannot be walked on.\n Food is represented by the character 'F' and can be walked on.\n There is only one of each character 'C', 'M', and 'F' in grid.\n \n Mouse and Cat play according to the following rules:\n \n Mouse moves first, then they take turns to move.\n During each turn, Cat and Mouse can jump in one of the four directions (left, right, up, down). They cannot jump over the wall nor outside of the grid.\n catJump, mouseJump are the maximum lengths Cat and Mouse can jump at a time, respectively. Cat and Mouse can jump less than the maximum length.\n Staying in the same position is allowed.\n Mouse can jump over Cat.\n \n The game can end in 4 ways:\n \n If Cat occupies the same position as Mouse, Cat wins.\n If Cat reaches the food first, Cat wins.\n If Mouse reaches the food first, Mouse wins.\n If Mouse cannot get to the food within 1000 turns, Cat wins.\n \n Given a rows x cols matrix grid and two integers catJump and mouseJump, return true if Mouse can win the game if both Cat and Mouse play optimally, otherwise return false.\n \n Example 1:\n \n \n >>> canMouseWin(grid = [\"####F\",\"#C...\",\"M....\"], catJump = 1, mouseJump = 2)\n >>> true\n Explanation: Cat cannot catch Mouse on its turn nor can it get the food before Mouse.\n \n Example 2:\n \n \n >>> canMouseWin(grid = [\"M.C...F\"], catJump = 1, mouseJump = 4)\n >>> true\n \n Example 3:\n \n >>> canMouseWin(grid = [\"M.C...F\"], catJump = 1, mouseJump = 3)\n >>> false\n \"\"\"\n"}
{"task_id": "shortest-path-to-get-food", "prompt": "def getFood(grid: List[List[str]]) -> int:\n \"\"\"\n You are starving and you want to eat food as quickly as possible. You want to find the shortest path to arrive at any food cell.\n You are given an m x n character matrix, grid, of these different types of cells:\n \n '*' is your location. There is exactly one '*' cell.\n '#' is a food cell. There may be multiple food cells.\n 'O' is free space, and you can travel through these cells.\n 'X' is an obstacle, and you cannot travel through these cells.\n \n You can travel to any adjacent cell north, east, south, or west of your current location if there is not an obstacle.\n Return the length of the shortest path for you to reach any food cell. If there is no path for you to reach food, return -1.\n \n Example 1:\n \n \n >>> getFood(grid = [[\"X\",\"X\",\"X\",\"X\",\"X\",\"X\"],[\"X\",\"*\",\"O\",\"O\",\"O\",\"X\"],[\"X\",\"O\",\"O\",\"#\",\"O\",\"X\"],[\"X\",\"X\",\"X\",\"X\",\"X\",\"X\"]])\n >>> 3\n Explanation: It takes 3 steps to reach the food.\n \n Example 2:\n \n \n >>> getFood(grid = [[\"X\",\"X\",\"X\",\"X\",\"X\"],[\"X\",\"*\",\"X\",\"O\",\"X\"],[\"X\",\"O\",\"X\",\"#\",\"X\"],[\"X\",\"X\",\"X\",\"X\",\"X\"]])\n >>> -1\n Explanation: It is not possible to reach the food.\n \n Example 3:\n \n \n >>> getFood(grid = [[\"X\",\"X\",\"X\",\"X\",\"X\",\"X\",\"X\",\"X\"],[\"X\",\"*\",\"O\",\"X\",\"O\",\"#\",\"O\",\"X\"],[\"X\",\"O\",\"O\",\"X\",\"O\",\"O\",\"X\",\"X\"],[\"X\",\"O\",\"O\",\"O\",\"O\",\"#\",\"O\",\"X\"],[\"X\",\"X\",\"X\",\"X\",\"X\",\"X\",\"X\",\"X\"]])\n >>> 6\n Explanation: There can be multiple food cells. It only takes 6 steps to reach the bottom food.\n Example 4:\n \n >>> getFood(grid = [[\"X\",\"X\",\"X\",\"X\",\"X\",\"X\",\"X\",\"X\"],[\"X\",\"*\",\"O\",\"X\",\"O\",\"#\",\"O\",\"X\"],[\"X\",\"O\",\"O\",\"X\",\"O\",\"O\",\"X\",\"X\"],[\"X\",\"O\",\"O\",\"O\",\"O\",\"#\",\"O\",\"X\"],[\"O\",\"O\",\"O\",\"O\",\"O\",\"O\",\"O\",\"O\"]])\n >>> 5\n \"\"\"\n"}
{"task_id": "find-the-highest-altitude", "prompt": "def largestAltitude(gain: List[int]) -> int:\n \"\"\"\n There is a biker going on a road trip. The road trip consists of n + 1 points at different altitudes. The biker starts his trip on point 0 with altitude equal 0.\n You are given an integer array gain of length n where gain[i] is the net gain in altitude between points i\u200b\u200b\u200b\u200b\u200b\u200b and i + 1 for all (0 <= i < n). Return the highest altitude of a point.\n \n Example 1:\n \n >>> largestAltitude(gain = [-5,1,5,0,-7])\n >>> 1\n Explanation: The altitudes are [0,-5,-4,1,1,-6]. The highest is 1.\n \n Example 2:\n \n >>> largestAltitude(gain = [-4,-3,-2,-1,4,3,2])\n >>> 0\n Explanation: The altitudes are [0,-4,-7,-9,-10,-6,-3,-1]. The highest is 0.\n \"\"\"\n"}
{"task_id": "minimum-number-of-people-to-teach", "prompt": "def minimumTeachings(n: int, languages: List[List[int]], friendships: List[List[int]]) -> int:\n \"\"\"\n On a social network consisting of m users and some friendships between users, two users can communicate with each other if they know a common language.\n You are given an integer n, an array languages, and an array friendships where:\n \n There are n languages numbered 1 through n,\n languages[i] is the set of languages the i\u200b\u200b\u200b\u200b\u200b\u200bth\u200b\u200b\u200b\u200b user knows, and\n friendships[i] = [u\u200b\u200b\u200b\u200b\u200b\u200bi\u200b\u200b\u200b, v\u200b\u200b\u200b\u200b\u200b\u200bi] denotes a friendship between the users u\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200bi\u200b\u200b\u200b\u200b\u200b and vi.\n \n You can choose one language and teach it to some users so that all friends can communicate with each other. Return the minimum number of users you need to teach.\n Note that friendships are not transitive, meaning if x is a friend of y and y is a friend of z, this doesn't guarantee that x is a friend of z.\n \n Example 1:\n \n >>> minimumTeachings(n = 2, languages = [[1],[2],[1,2]], friendships = [[1,2],[1,3],[2,3]])\n >>> 1\n Explanation: You can either teach user 1 the second language or user 2 the first language.\n \n Example 2:\n \n >>> minimumTeachings(n = 3, languages = [[2],[1,3],[1,2],[3]], friendships = [[1,4],[1,2],[3,4],[2,3]])\n >>> 2\n Explanation: Teach the third language to users 1 and 3, yielding two users to teach.\n \"\"\"\n"}
{"task_id": "decode-xored-permutation", "prompt": "def decode(encoded: List[int]) -> List[int]:\n \"\"\"\n There is an integer array perm that is a permutation of the first n positive integers, where n is always odd.\n It was encoded into another integer array encoded of length n - 1, such that encoded[i] = perm[i] XOR perm[i + 1]. For example, if perm = [1,3,2], then encoded = [2,1].\n Given the encoded array, return the original array perm. It is guaranteed that the answer exists and is unique.\n \n Example 1:\n \n >>> decode(encoded = [3,1])\n >>> [1,2,3]\n Explanation: If perm = [1,2,3], then encoded = [1 XOR 2,2 XOR 3] = [3,1]\n \n Example 2:\n \n >>> decode(encoded = [6,5,4,6])\n >>> [2,4,1,5,3]\n \"\"\"\n"}
{"task_id": "latest-time-by-replacing-hidden-digits", "prompt": "def maximumTime(time: str) -> str:\n \"\"\"\n You are given a string time in the form of hh:mm, where some of the digits in the string are hidden (represented by ?).\n The valid times are those inclusively between 00:00 and 23:59.\n Return the latest valid time you can get from time by replacing the hidden digits.\n \n Example 1:\n \n >>> maximumTime(time = \"2?:?0\")\n >>> \"23:50\"\n Explanation: The latest hour beginning with the digit '2' is 23 and the latest minute ending with the digit '0' is 50.\n \n Example 2:\n \n >>> maximumTime(time = \"0?:3?\")\n >>> \"09:39\"\n \n Example 3:\n \n >>> maximumTime(time = \"1?:22\")\n >>> \"19:22\"\n \"\"\"\n"}
{"task_id": "change-minimum-characters-to-satisfy-one-of-three-conditions", "prompt": "def minCharacters(a: str, b: str) -> int:\n \"\"\"\n You are given two strings a and b that consist of lowercase letters. In one operation, you can change any character in a or b to any lowercase letter.\n Your goal is to satisfy one of the following three conditions:\n \n Every letter in a is strictly less than every letter in b in the alphabet.\n Every letter in b is strictly less than every letter in a in the alphabet.\n Both a and b consist of only one distinct letter.\n \n Return the minimum number of operations needed to achieve your goal.\n \n Example 1:\n \n >>> minCharacters(a = \"aba\", b = \"caa\")\n >>> 2\n Explanation: Consider the best way to make each condition true:\n 1) Change b to \"ccc\" in 2 operations, then every letter in a is less than every letter in b.\n 2) Change a to \"bbb\" and b to \"aaa\" in 3 operations, then every letter in b is less than every letter in a.\n 3) Change a to \"aaa\" and b to \"aaa\" in 2 operations, then a and b consist of one distinct letter.\n The best way was done in 2 operations (either condition 1 or condition 3).\n \n Example 2:\n \n >>> minCharacters(a = \"dabadd\", b = \"cda\")\n >>> 3\n Explanation: The best way is to make condition 1 true by changing b to \"eee\".\n \"\"\"\n"}
{"task_id": "find-kth-largest-xor-coordinate-value", "prompt": "def kthLargestValue(matrix: List[List[int]], k: int) -> int:\n \"\"\"\n You are given a 2D matrix of size m x n, consisting of non-negative integers. You are also given an integer k.\n The value of coordinate (a, b) of the matrix is the XOR of all matrix[i][j] where 0 <= i <= a < m and 0 <= j <= b < n (0-indexed).\n Find the kth largest value (1-indexed) of all the coordinates of matrix.\n \n Example 1:\n \n >>> kthLargestValue(matrix = [[5,2],[1,6]], k = 1)\n >>> 7\n Explanation: The value of coordinate (0,1) is 5 XOR 2 = 7, which is the largest value.\n \n Example 2:\n \n >>> kthLargestValue(matrix = [[5,2],[1,6]], k = 2)\n >>> 5\n Explanation: The value of coordinate (0,0) is 5 = 5, which is the 2nd largest value.\n \n Example 3:\n \n >>> kthLargestValue(matrix = [[5,2],[1,6]], k = 3)\n >>> 4\n Explanation: The value of coordinate (1,0) is 5 XOR 1 = 4, which is the 3rd largest value.\n \"\"\"\n"}
{"task_id": "building-boxes", "prompt": "def minimumBoxes(n: int) -> int:\n \"\"\"\n You have a cubic storeroom where the width, length, and height of the room are all equal to n units. You are asked to place n boxes in this room where each box is a cube of unit side length. There are however some rules to placing the boxes:\n \n You can place the boxes anywhere on the floor.\n If box x is placed on top of the box y, then each side of the four vertical sides of the box y must either be adjacent to another box or to a wall.\n \n Given an integer n, return the minimum possible number of boxes touching the floor.\n \n Example 1:\n \n \n >>> minimumBoxes(n = 3)\n >>> 3\n Explanation: The figure above is for the placement of the three boxes.\n These boxes are placed in the corner of the room, where the corner is on the left side.\n \n Example 2:\n \n \n >>> minimumBoxes(n = 4)\n >>> 3\n Explanation: The figure above is for the placement of the four boxes.\n These boxes are placed in the corner of the room, where the corner is on the left side.\n \n Example 3:\n \n \n >>> minimumBoxes(n = 10)\n >>> 6\n Explanation: The figure above is for the placement of the ten boxes.\n These boxes are placed in the corner of the room, where the corner is on the back side.\n \"\"\"\n"}
{"task_id": "find-distance-in-a-binary-tree", "prompt": "# class TreeNode:\n# def __init__(val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def findDistance(root: Optional[TreeNode], p: int, q: int) -> int:\n \"\"\"\n Given the root of a binary tree and two integers p and q, return the distance between the nodes of value p and value q in the tree.\n The distance between two nodes is the number of edges on the path from one to the other.\n \n Example 1:\n \n \n >>> __init__(root = [3,5,1,6,2,0,8,null,null,7,4], p = 5, q = 0)\n >>> 3\n Explanation: There are 3 edges between 5 and 0: 5-3-1-0.\n Example 2:\n \n \n >>> __init__(root = [3,5,1,6,2,0,8,null,null,7,4], p = 5, q = 7)\n >>> 2\n Explanation: There are 2 edges between 5 and 7: 5-2-7.\n Example 3:\n \n \n >>> __init__(root = [3,5,1,6,2,0,8,null,null,7,4], p = 5, q = 5)\n >>> 0\n Explanation: The distance between a node and itself is 0.\n \"\"\"\n"}
{"task_id": "maximum-number-of-balls-in-a-box", "prompt": "def countBalls(lowLimit: int, highLimit: int) -> int:\n \"\"\"\n You are working in a ball factory where you have n balls numbered from lowLimit up to highLimit inclusive (i.e., n == highLimit - lowLimit + 1), and an infinite number of boxes numbered from 1 to infinity.\n Your job at this factory is to put each ball in the box with a number equal to the sum of digits of the ball's number. For example, the ball number 321 will be put in the box number 3 + 2 + 1 = 6 and the ball number 10 will be put in the box number 1 + 0 = 1.\n Given two integers lowLimit and highLimit, return the number of balls in the box with the most balls.\n \n Example 1:\n \n >>> countBalls(lowLimit = 1, highLimit = 10)\n >>> 2\n Explanation:\n Box Number: 1 2 3 4 5 6 7 8 9 10 11 ...\n Ball Count: 2 1 1 1 1 1 1 1 1 0 0 ...\n Box 1 has the most number of balls with 2 balls.\n Example 2:\n \n >>> countBalls(lowLimit = 5, highLimit = 15)\n >>> 2\n Explanation:\n Box Number: 1 2 3 4 5 6 7 8 9 10 11 ...\n Ball Count: 1 1 1 1 2 2 1 1 1 0 0 ...\n Boxes 5 and 6 have the most number of balls with 2 balls in each.\n \n Example 3:\n \n >>> countBalls(lowLimit = 19, highLimit = 28)\n >>> 2\n Explanation:\n Box Number: 1 2 3 4 5 6 7 8 9 10 11 12 ...\n Ball Count: 0 1 1 1 1 1 1 1 1 2 0 0 ...\n Box 10 has the most number of balls with 2 balls.\n \"\"\"\n"}
{"task_id": "restore-the-array-from-adjacent-pairs", "prompt": "def restoreArray(adjacentPairs: List[List[int]]) -> List[int]:\n \"\"\"\n There is an integer array nums that consists of n unique elements, but you have forgotten it. However, you do remember every pair of adjacent elements in nums.\n You are given a 2D integer array adjacentPairs of size n - 1 where each adjacentPairs[i] = [ui, vi] indicates that the elements ui and vi are adjacent in nums.\n It is guaranteed that every adjacent pair of elements nums[i] and nums[i+1] will exist in adjacentPairs, either as [nums[i], nums[i+1]] or [nums[i+1], nums[i]]. The pairs can appear in any order.\n Return the original array nums. If there are multiple solutions, return any of them.\n \n Example 1:\n \n >>> restoreArray(adjacentPairs = [[2,1],[3,4],[3,2]])\n >>> [1,2,3,4]\n Explanation: This array has all its adjacent pairs in adjacentPairs.\n Notice that adjacentPairs[i] may not be in left-to-right order.\n \n Example 2:\n \n >>> restoreArray(adjacentPairs = [[4,-2],[1,4],[-3,1]])\n >>> [-2,4,1,-3]\n Explanation: There can be negative numbers.\n Another solution is [-3,1,4,-2], which would also be accepted.\n \n Example 3:\n \n >>> restoreArray(adjacentPairs = [[100000,-100000]])\n >>> [100000,-100000]\n \"\"\"\n"}
{"task_id": "can-you-eat-your-favorite-candy-on-your-favorite-day", "prompt": "def canEat(candiesCount: List[int], queries: List[List[int]]) -> List[bool]:\n \"\"\"\n You are given a (0-indexed) array of positive integers candiesCount where candiesCount[i] represents the number of candies of the\u00a0ith\u00a0type you have. You are also given a 2D array queries where queries[i] = [favoriteTypei, favoriteDayi, dailyCapi].\n You play a game with the following rules:\n \n You start eating candies on day 0.\n You cannot eat any candy of type i unless you have eaten all candies of type i - 1.\n You must eat at least one candy per day until you have eaten all the candies.\n \n Construct a boolean array answer such that answer.length == queries.length and answer[i] is true if you can eat a candy of type favoriteTypei on day favoriteDayi without eating more than dailyCapi candies on any day, and false otherwise. Note that you can eat different types of candy on the same day, provided that you follow rule 2.\n Return the constructed array answer.\n \n Example 1:\n \n >>> canEat(candiesCount = [7,4,5,3,8], queries = [[0,2,2],[4,2,4],[2,13,1000000000]])\n >>> [true,false,true]\n Explanation:\n 1- If you eat 2 candies (type 0) on day 0 and 2 candies (type 0) on day 1, you will eat a candy of type 0 on day 2.\n 2- You can eat at most 4 candies each day.\n If you eat 4 candies every day, you will eat 4 candies (type 0) on day 0 and 4 candies (type 0 and type 1) on day 1.\n On day 2, you can only eat 4 candies (type 1 and type 2), so you cannot eat a candy of type 4 on day 2.\n 3- If you eat 1 candy each day, you will eat a candy of type 2 on day 13.\n \n Example 2:\n \n >>> canEat(candiesCount = [5,2,6,4,1], queries = [[3,1,2],[4,10,3],[3,10,100],[4,100,30],[1,3,1]])\n >>> [false,true,true,false,false]\n \"\"\"\n"}
{"task_id": "palindrome-partitioning-iv", "prompt": "def checkPartitioning(s: str) -> bool:\n \"\"\"\n Given a string s, return true if it is possible to split the string s into three non-empty palindromic substrings. Otherwise, return false.\u200b\u200b\u200b\u200b\u200b\n A string is said to be palindrome if it the same string when reversed.\n \n Example 1:\n \n >>> checkPartitioning(s = \"abcbdd\")\n >>> true\n Explanation: \"abcbdd\" = \"a\" + \"bcb\" + \"dd\", and all three substrings are palindromes.\n \n Example 2:\n \n >>> checkPartitioning(s = \"bcbddxy\")\n >>> false\n Explanation: s cannot be split into 3 palindromes.\n \"\"\"\n"}
{"task_id": "maximum-subarray-sum-after-one-operation", "prompt": "def maxSumAfterOperation(nums: List[int]) -> int:\n \"\"\"\n You are given an integer array nums. You must perform exactly one operation\u00a0where you can replace one\u00a0element nums[i] with nums[i] * nums[i].\u00a0\\r\n \\r\n Return the maximum possible subarray sum after exactly\u00a0one operation. The subarray must be non-empty.\\r\n \\r\n \u00a0\\r\n Example 1:\\r\n \\r\n \\r\n >>> maxSumAfterOperation(nums = [2,-1,-4,-3]\\r)\n >>> 17\\r\n Explanation: You can perform the operation on index 2 (0-indexed) to make nums = [2,-1,16,-3]. Now, the maximum subarray sum is 2 + -1 + 16 = 17.\\r\n \\r\n Example 2:\\r\n \\r\n \\r\n >>> maxSumAfterOperation(nums = [1,-1,1,1,-1,-1,1]\\r)\n >>> 4\\r\n Explanation: You can perform the operation on index 1 (0-indexed) to make nums = [1,1,1,1,-1,-1,1]. Now, the maximum subarray sum is 1 + 1 + 1 + 1 = 4.\\r\n \\r\n \u00a0\\r\n \"\"\"\n"}
{"task_id": "sum-of-unique-elements", "prompt": "def sumOfUnique(nums: List[int]) -> int:\n \"\"\"\n You are given an integer array nums. The unique elements of an array are the elements that appear exactly once in the array.\n Return the sum of all the unique elements of nums.\n \n Example 1:\n \n >>> sumOfUnique(nums = [1,2,3,2])\n >>> 4\n Explanation: The unique elements are [1,3], and the sum is 4.\n \n Example 2:\n \n >>> sumOfUnique(nums = [1,1,1,1,1])\n >>> 0\n Explanation: There are no unique elements, and the sum is 0.\n \n Example 3:\n \n >>> sumOfUnique(nums = [1,2,3,4,5])\n >>> 15\n Explanation: The unique elements are [1,2,3,4,5], and the sum is 15.\n \"\"\"\n"}
{"task_id": "maximum-absolute-sum-of-any-subarray", "prompt": "def maxAbsoluteSum(nums: List[int]) -> int:\n \"\"\"\n You are given an integer array nums. The absolute sum of a subarray [numsl, numsl+1, ..., numsr-1, numsr] is abs(numsl + numsl+1 + ... + numsr-1 + numsr).\n Return the maximum absolute sum of any (possibly empty) subarray of nums.\n Note that abs(x) is defined as follows:\n \n If x is a negative integer, then abs(x) = -x.\n If x is a non-negative integer, then abs(x) = x.\n \n \n Example 1:\n \n >>> maxAbsoluteSum(nums = [1,-3,2,3,-4])\n >>> 5\n Explanation: The subarray [2,3] has absolute sum = abs(2+3) = abs(5) = 5.\n \n Example 2:\n \n >>> maxAbsoluteSum(nums = [2,-5,1,-4,3,-2])\n >>> 8\n Explanation: The subarray [-5,1,-4] has absolute sum = abs(-5+1-4) = abs(-8) = 8.\n \"\"\"\n"}
{"task_id": "minimum-length-of-string-after-deleting-similar-ends", "prompt": "def minimumLength(s: str) -> int:\n \"\"\"\n Given a string s consisting only of characters 'a', 'b', and 'c'. You are asked to apply the following algorithm on the string any number of times:\n \n Pick a non-empty prefix from the string s where all the characters in the prefix are equal.\n Pick a non-empty suffix from the string s where all the characters in this suffix are equal.\n The prefix and the suffix should not intersect at any index.\n The characters from the prefix and suffix must be the same.\n Delete both the prefix and the suffix.\n \n Return the minimum length of s after performing the above operation any number of times (possibly zero times).\n \n Example 1:\n \n >>> minimumLength(s = \"ca\")\n >>> 2\n Explanation: You can't remove any characters, so the string stays as is.\n \n Example 2:\n \n >>> minimumLength(s = \"cabaabac\")\n >>> 0\n Explanation: An optimal sequence of operations is:\n - Take prefix = \"c\" and suffix = \"c\" and remove them, s = \"abaaba\".\n - Take prefix = \"a\" and suffix = \"a\" and remove them, s = \"baab\".\n - Take prefix = \"b\" and suffix = \"b\" and remove them, s = \"aa\".\n - Take prefix = \"a\" and suffix = \"a\" and remove them, s = \"\".\n Example 3:\n \n >>> minimumLength(s = \"aabccabba\")\n >>> 3\n Explanation: An optimal sequence of operations is:\n - Take prefix = \"aa\" and suffix = \"a\" and remove them, s = \"bccabb\".\n - Take prefix = \"b\" and suffix = \"bb\" and remove them, s = \"cca\".\n \"\"\"\n"}
{"task_id": "maximum-number-of-events-that-can-be-attended-ii", "prompt": "def maxValue(events: List[List[int]], k: int) -> int:\n \"\"\"\n You are given an array of events where events[i] = [startDayi, endDayi, valuei]. The ith event starts at startDayi and ends at endDayi, and if you attend this event, you will receive a value of valuei. You are also given an integer k which represents the maximum number of events you can attend.\n You can only attend one event at a time. If you choose to attend an event, you must attend the entire event. Note that the end day is inclusive: that is, you cannot attend two events where one of them starts and the other ends on the same day.\n Return the maximum sum of values that you can receive by attending events.\n \n Example 1:\n \n \n >>> maxValue(events = [[1,2,4],[3,4,3],[2,3,1]], k = 2)\n >>> 7\n Explanation: Choose the green events, 0 and 1 (0-indexed) for a total value of 4 + 3 = 7.\n Example 2:\n \n \n >>> maxValue(events = [[1,2,4],[3,4,3],[2,3,10]], k = 2)\n >>> 10\n Explanation: Choose event 2 for a total value of 10.\n Notice that you cannot attend any other event as they overlap, and that you do not have to attend k events.\n Example 3:\n \n \n >>> maxValue(events = [[1,1,1],[2,2,2],[3,3,3],[4,4,4]], k = 3)\n >>> 9\n Explanation: Although the events do not overlap, you can only attend 3 events. Pick the highest valued three.\n \"\"\"\n"}
{"task_id": "check-if-array-is-sorted-and-rotated", "prompt": "def check(nums: List[int]) -> bool:\n \"\"\"\n Given an array nums, return true if the array was originally sorted in non-decreasing order, then rotated some number of positions (including zero). Otherwise, return false.\n There may be duplicates in the original array.\n Note: An array A rotated by x positions results in an array B of the same length such that B[i] == A[(i+x) % A.length] for every valid index i.\n \n Example 1:\n \n >>> check(nums = [3,4,5,1,2])\n >>> true\n Explanation: [1,2,3,4,5] is the original sorted array.\n You can rotate the array by x = 3 positions to begin on the element of value 3: [3,4,5,1,2].\n \n Example 2:\n \n >>> check(nums = [2,1,3,4])\n >>> false\n Explanation: There is no sorted array once rotated that can make nums.\n \n Example 3:\n \n >>> check(nums = [1,2,3])\n >>> true\n Explanation: [1,2,3] is the original sorted array.\n You can rotate the array by x = 0 positions (i.e. no rotation) to make nums.\n \"\"\"\n"}
{"task_id": "maximum-score-from-removing-stones", "prompt": "def maximumScore(a: int, b: int, c: int) -> int:\n \"\"\"\n You are playing a solitaire game with three piles of stones of sizes a\u200b\u200b\u200b\u200b\u200b\u200b, b,\u200b\u200b\u200b\u200b\u200b\u200b and c\u200b\u200b\u200b\u200b\u200b\u200b respectively. Each turn you choose two different non-empty piles, take one stone from each, and add 1 point to your score. The game stops when there are fewer than two non-empty piles (meaning there are no more available moves).\n Given three integers a\u200b\u200b\u200b\u200b\u200b, b,\u200b\u200b\u200b\u200b\u200b and c\u200b\u200b\u200b\u200b\u200b, return the maximum score you can get.\n \n Example 1:\n \n >>> maximumScore(a = 2, b = 4, c = 6)\n >>> 6\n Explanation: The starting state is (2, 4, 6). One optimal set of moves is:\n - Take from 1st and 3rd piles, state is now (1, 4, 5)\n - Take from 1st and 3rd piles, state is now (0, 4, 4)\n - Take from 2nd and 3rd piles, state is now (0, 3, 3)\n - Take from 2nd and 3rd piles, state is now (0, 2, 2)\n - Take from 2nd and 3rd piles, state is now (0, 1, 1)\n - Take from 2nd and 3rd piles, state is now (0, 0, 0)\n There are fewer than two non-empty piles, so the game ends. Total: 6 points.\n \n Example 2:\n \n >>> maximumScore(a = 4, b = 4, c = 6)\n >>> 7\n Explanation: The starting state is (4, 4, 6). One optimal set of moves is:\n - Take from 1st and 2nd piles, state is now (3, 3, 6)\n - Take from 1st and 3rd piles, state is now (2, 3, 5)\n - Take from 1st and 3rd piles, state is now (1, 3, 4)\n - Take from 1st and 3rd piles, state is now (0, 3, 3)\n - Take from 2nd and 3rd piles, state is now (0, 2, 2)\n - Take from 2nd and 3rd piles, state is now (0, 1, 1)\n - Take from 2nd and 3rd piles, state is now (0, 0, 0)\n There are fewer than two non-empty piles, so the game ends. Total: 7 points.\n \n Example 3:\n \n >>> maximumScore(a = 1, b = 8, c = 8)\n >>> 8\n Explanation: One optimal set of moves is to take from the 2nd and 3rd piles for 8 turns until they are empty.\n After that, there are fewer than two non-empty piles, so the game ends.\n \"\"\"\n"}
{"task_id": "largest-merge-of-two-strings", "prompt": "def largestMerge(word1: str, word2: str) -> str:\n \"\"\"\n You are given two strings word1 and word2. You want to construct a string merge in the following way: while either word1 or word2 are non-empty, choose one of the following options:\n \n If word1 is non-empty, append the first character in word1 to merge and delete it from word1.\n \n \n For example, if word1 = \"abc\" and merge = \"dv\", then after choosing this operation, word1 = \"bc\" and merge = \"dva\".\n \n \n If word2 is non-empty, append the first character in word2 to merge and delete it from word2.\n \n For example, if word2 = \"abc\" and merge = \"\", then after choosing this operation, word2 = \"bc\" and merge = \"a\".\n \n \n \n Return the lexicographically largest merge you can construct.\n A string a is lexicographically larger than a string b (of the same length) if in the first position where a and b differ, a has a character strictly larger than the corresponding character in b. For example, \"abcd\" is lexicographically larger than \"abcc\" because the first position they differ is at the fourth character, and d is greater than c.\n \n Example 1:\n \n >>> largestMerge(word1 = \"cabaa\", word2 = \"bcaaa\")\n >>> \"cbcabaaaaa\"\n Explanation: One way to get the lexicographically largest merge is:\n - Take from word1: merge = \"c\", word1 = \"abaa\", word2 = \"bcaaa\"\n - Take from word2: merge = \"cb\", word1 = \"abaa\", word2 = \"caaa\"\n - Take from word2: merge = \"cbc\", word1 = \"abaa\", word2 = \"aaa\"\n - Take from word1: merge = \"cbca\", word1 = \"baa\", word2 = \"aaa\"\n - Take from word1: merge = \"cbcab\", word1 = \"aa\", word2 = \"aaa\"\n - Append the remaining 5 a's from word1 and word2 at the end of merge.\n \n Example 2:\n \n >>> largestMerge(word1 = \"abcabc\", word2 = \"abdcaba\")\n >>> \"abdcabcabcaba\"\n \"\"\"\n"}
{"task_id": "closest-subsequence-sum", "prompt": "def minAbsDifference(nums: List[int], goal: int) -> int:\n \"\"\"\n You are given an integer array nums and an integer goal.\n You want to choose a subsequence of nums such that the sum of its elements is the closest possible to goal. That is, if the sum of the subsequence's elements is sum, then you want to minimize the absolute difference abs(sum - goal).\n Return the minimum possible value of abs(sum - goal).\n Note that a subsequence of an array is an array formed by removing some elements (possibly all or none) of the original array.\n \n Example 1:\n \n >>> minAbsDifference(nums = [5,-7,3,5], goal = 6)\n >>> 0\n Explanation: Choose the whole array as a subsequence, with a sum of 6.\n This is equal to the goal, so the absolute difference is 0.\n \n Example 2:\n \n >>> minAbsDifference(nums = [7,-9,15,-2], goal = -5)\n >>> 1\n Explanation: Choose the subsequence [7,-9,-2], with a sum of -4.\n The absolute difference is abs(-4 - (-5)) = abs(1) = 1, which is the minimum.\n \n Example 3:\n \n >>> minAbsDifference(nums = [1,2,3], goal = -7)\n >>> 7\n \"\"\"\n"}
{"task_id": "minimum-changes-to-make-alternating-binary-string", "prompt": "def minOperations(s: str) -> int:\n \"\"\"\n You are given a string s consisting only of the characters '0' and '1'. In one operation, you can change any '0' to '1' or vice versa.\n The string is called alternating if no two adjacent characters are equal. For example, the string \"010\" is alternating, while the string \"0100\" is not.\n Return the minimum number of operations needed to make s alternating.\n \n Example 1:\n \n >>> minOperations(s = \"0100\")\n >>> 1\n Explanation: If you change the last character to '1', s will be \"0101\", which is alternating.\n \n Example 2:\n \n >>> minOperations(s = \"10\")\n >>> 0\n Explanation: s is already alternating.\n \n Example 3:\n \n >>> minOperations(s = \"1111\")\n >>> 2\n Explanation: You need two operations to reach \"0101\" or \"1010\".\n \"\"\"\n"}
{"task_id": "count-number-of-homogenous-substrings", "prompt": "def countHomogenous(s: str) -> int:\n \"\"\"\n Given a string s, return the number of homogenous substrings of s. Since the answer may be too large, return it modulo 109 + 7.\n A string is homogenous if all the characters of the string are the same.\n A substring is a contiguous sequence of characters within a string.\n \n Example 1:\n \n >>> countHomogenous(s = \"abbcccaa\")\n >>> 13\n Explanation: The homogenous substrings are listed as below:\n \"a\" appears 3 times.\n \"aa\" appears 1 time.\n \"b\" appears 2 times.\n \"bb\" appears 1 time.\n \"c\" appears 3 times.\n \"cc\" appears 2 times.\n \"ccc\" appears 1 time.\n 3 + 1 + 2 + 1 + 3 + 2 + 1 = 13.\n Example 2:\n \n >>> countHomogenous(s = \"xy\")\n >>> 2\n Explanation: The homogenous substrings are \"x\" and \"y\".\n Example 3:\n \n >>> countHomogenous(s = \"zzzzz\")\n >>> 15\n \"\"\"\n"}
{"task_id": "minimum-limit-of-balls-in-a-bag", "prompt": "def minimumSize(nums: List[int], maxOperations: int) -> int:\n \"\"\"\n You are given an integer array nums where the ith bag contains nums[i] balls. You are also given an integer maxOperations.\n You can perform the following operation at most maxOperations times:\n \n Take any bag of balls and divide it into two new bags with a positive number of balls.\n \n \n For example, a bag of 5 balls can become two new bags of 1 and 4 balls, or two new bags of 2 and 3 balls.\n \n \n \n Your penalty is the maximum number of balls in a bag. You want to minimize your penalty after the operations.\n Return the minimum possible penalty after performing the operations.\n \n Example 1:\n \n >>> minimumSize(nums = [9], maxOperations = 2)\n >>> 3\n Explanation:\n - Divide the bag with 9 balls into two bags of sizes 6 and 3. [9] -> [6,3].\n - Divide the bag with 6 balls into two bags of sizes 3 and 3. [6,3] -> [3,3,3].\n The bag with the most number of balls has 3 balls, so your penalty is 3 and you should return 3.\n \n Example 2:\n \n >>> minimumSize(nums = [2,4,8,2], maxOperations = 4)\n >>> 2\n Explanation:\n - Divide the bag with 8 balls into two bags of sizes 4 and 4. [2,4,8,2] -> [2,4,4,4,2].\n - Divide the bag with 4 balls into two bags of sizes 2 and 2. [2,4,4,4,2] -> [2,2,2,4,4,2].\n - Divide the bag with 4 balls into two bags of sizes 2 and 2. [2,2,2,4,4,2] -> [2,2,2,2,2,4,2].\n - Divide the bag with 4 balls into two bags of sizes 2 and 2. [2,2,2,2,2,4,2] -> [2,2,2,2,2,2,2,2].\n The bag with the most number of balls has 2 balls, so your penalty is 2, and you should return 2.\n \"\"\"\n"}
{"task_id": "minimum-degree-of-a-connected-trio-in-a-graph", "prompt": "def minTrioDegree(n: int, edges: List[List[int]]) -> int:\n \"\"\"\n You are given an undirected graph. You are given an integer n which is the number of nodes in the graph and an array edges, where each edges[i] = [ui, vi] indicates that there is an undirected edge between ui and vi.\n A connected trio is a set of three nodes where there is an edge between every pair of them.\n The degree of a connected trio is the number of edges where one endpoint is in the trio, and the other is not.\n Return the minimum degree of a connected trio in the graph, or -1 if the graph has no connected trios.\n \n Example 1:\n \n \n >>> minTrioDegree(n = 6, edges = [[1,2],[1,3],[3,2],[4,1],[5,2],[3,6]])\n >>> 3\n Explanation: There is exactly one trio, which is [1,2,3]. The edges that form its degree are bolded in the figure above.\n \n Example 2:\n \n \n >>> minTrioDegree(n = 7, edges = [[1,3],[4,1],[4,3],[2,5],[5,6],[6,7],[7,5],[2,6]])\n >>> 0\n Explanation: There are exactly three trios:\n 1) [1,4,3] with degree 0.\n 2) [2,5,6] with degree 2.\n 3) [5,6,7] with degree 2.\n \"\"\"\n"}
{"task_id": "buildings-with-an-ocean-view", "prompt": "def findBuildings(heights: List[int]) -> List[int]:\n \"\"\"\n There are n buildings in a line. You are given an integer array heights of size n that represents the heights of the buildings in the line.\n The ocean is to the right of the buildings. A building has an ocean view if the building can see the ocean without obstructions. Formally, a building has an ocean view if all the buildings to its right have a smaller height.\n Return a list of indices (0-indexed) of buildings that have an ocean view, sorted in increasing order.\n \n Example 1:\n \n >>> findBuildings(heights = [4,2,3,1])\n >>> [0,2,3]\n Explanation: Building 1 (0-indexed) does not have an ocean view because building 2 is taller.\n \n Example 2:\n \n >>> findBuildings(heights = [4,3,2,1])\n >>> [0,1,2,3]\n Explanation: All the buildings have an ocean view.\n \n Example 3:\n \n >>> findBuildings(heights = [1,3,2,4])\n >>> [3]\n Explanation: Only building 3 has an ocean view.\n \"\"\"\n"}
{"task_id": "longest-nice-substring", "prompt": "def longestNiceSubstring(s: str) -> str:\n \"\"\"\n A string s is nice if, for every letter of the alphabet that s contains, it appears both in uppercase and lowercase. For example, \"abABB\" is nice because 'A' and 'a' appear, and 'B' and 'b' appear. However, \"abA\" is not because 'b' appears, but 'B' does not.\n Given a string s, return the longest substring of s that is nice. If there are multiple, return the substring of the earliest occurrence. If there are none, return an empty string.\n \n Example 1:\n \n >>> longestNiceSubstring(s = \"YazaAay\")\n >>> \"aAa\"\n Explanation: \"aAa\" is a nice string because 'A/a' is the only letter of the alphabet in s, and both 'A' and 'a' appear.\n \"aAa\" is the longest nice substring.\n \n Example 2:\n \n >>> longestNiceSubstring(s = \"Bb\")\n >>> \"Bb\"\n Explanation: \"Bb\" is a nice string because both 'B' and 'b' appear. The whole string is a substring.\n \n Example 3:\n \n >>> longestNiceSubstring(s = \"c\")\n >>> \"\"\n Explanation: There are no nice substrings.\n \"\"\"\n"}
{"task_id": "form-array-by-concatenating-subarrays-of-another-array", "prompt": "def canChoose(groups: List[List[int]], nums: List[int]) -> bool:\n \"\"\"\n You are given a 2D integer array groups of length n. You are also given an integer array nums.\n You are asked if you can choose n disjoint subarrays from the array nums such that the ith subarray is equal to groups[i] (0-indexed), and if i > 0, the (i-1)th subarray appears before the ith subarray in nums (i.e. the subarrays must be in the same order as groups).\n Return true if you can do this task, and false otherwise.\n Note that the subarrays are disjoint if and only if there is no index k such that nums[k] belongs to more than one subarray. A subarray is a contiguous sequence of elements within an array.\n \n Example 1:\n \n >>> canChoose(groups = [[1,-1,-1],[3,-2,0]], nums = [1,-1,0,1,-1,-1,3,-2,0])\n >>> true\n Explanation: You can choose the 0th subarray as [1,-1,0,1,-1,-1,3,-2,0] and the 1st one as [1,-1,0,1,-1,-1,3,-2,0].\n These subarrays are disjoint as they share no common nums[k] element.\n \n Example 2:\n \n >>> canChoose(groups = [[10,-2],[1,2,3,4]], nums = [1,2,3,4,10,-2])\n >>> false\n Explanation: Note that choosing the subarrays [1,2,3,4,10,-2] and [1,2,3,4,10,-2] is incorrect because they are not in the same order as in groups.\n [10,-2] must come before [1,2,3,4].\n \n Example 3:\n \n >>> canChoose(groups = [[1,2,3],[3,4]], nums = [7,7,1,2,3,4,7,7])\n >>> false\n Explanation: Note that choosing the subarrays [7,7,1,2,3,4,7,7] and [7,7,1,2,3,4,7,7] is invalid because they are not disjoint.\n They share a common elements nums[4] (0-indexed).\n \"\"\"\n"}
{"task_id": "map-of-highest-peak", "prompt": "def highestPeak(isWater: List[List[int]]) -> List[List[int]]:\n \"\"\"\n You are given an integer matrix isWater of size m x n that represents a map of land and water cells.\n \n If isWater[i][j] == 0, cell (i, j) is a land cell.\n If isWater[i][j] == 1, cell (i, j) is a water cell.\n \n You must assign each cell a height in a way that follows these rules:\n \n The height of each cell must be non-negative.\n If the cell is a water cell, its height must be 0.\n Any two adjacent cells must have an absolute height difference of at most 1. A cell is adjacent to another cell if the former is directly north, east, south, or west of the latter (i.e., their sides are touching).\n \n Find an assignment of heights such that the maximum height in the matrix is maximized.\n Return an integer matrix height of size m x n where height[i][j] is cell (i, j)'s height. If there are multiple solutions, return any of them.\n \n Example 1:\n \n \n >>> highestPeak(isWater = [[0,1],[0,0]])\n >>> [[1,0],[2,1]]\n Explanation: The image shows the assigned heights of each cell.\n The blue cell is the water cell, and the green cells are the land cells.\n \n Example 2:\n \n \n >>> highestPeak(isWater = [[0,0,1],[1,0,0],[0,0,0]])\n >>> [[1,1,0],[0,1,1],[1,2,2]]\n Explanation: A height of 2 is the maximum possible height of any assignment.\n Any height assignment that has a maximum height of 2 while still meeting the rules will also be accepted.\n \"\"\"\n"}
{"task_id": "tree-of-coprimes", "prompt": "def getCoprimes(nums: List[int], edges: List[List[int]]) -> List[int]:\n \"\"\"\n There is a tree (i.e.,\u00a0a connected, undirected graph that has no cycles) consisting of n nodes numbered from 0 to n - 1 and exactly n - 1 edges. Each node has a value associated with it, and the root of the tree is node 0.\n To represent this tree, you are given an integer array nums and a 2D array edges. Each nums[i] represents the ith node's value, and each edges[j] = [uj, vj] represents an edge between nodes uj and vj in the tree.\n Two values x and y are coprime if gcd(x, y) == 1 where gcd(x, y) is the greatest common divisor of x and y.\n An ancestor of a node i is any other node on the shortest path from node i to the root. A node is not considered an ancestor of itself.\n Return an array ans of size n, where ans[i] is the closest ancestor to node i such that nums[i] and nums[ans[i]] are coprime, or -1 if there is no such ancestor.\n \n Example 1:\n \n \n >>> getCoprimes(nums = [2,3,3,2], edges = [[0,1],[1,2],[1,3]])\n >>> [-1,0,0,1]\n Explanation: In the above figure, each node's value is in parentheses.\n - Node 0 has no coprime ancestors.\n - Node 1 has only one ancestor, node 0. Their values are coprime (gcd(2,3) == 1).\n - Node 2 has two ancestors, nodes 1 and 0. Node 1's value is not coprime (gcd(3,3) == 3), but node 0's\n value is (gcd(2,3) == 1), so node 0 is the closest valid ancestor.\n - Node 3 has two ancestors, nodes 1 and 0. It is coprime with node 1 (gcd(3,2) == 1), so node 1 is its\n closest valid ancestor.\n \n Example 2:\n \n \n >>> getCoprimes(nums = [5,6,10,2,3,6,15], edges = [[0,1],[0,2],[1,3],[1,4],[2,5],[2,6]])\n >>> [-1,0,-1,0,0,0,-1]\n \"\"\"\n"}
{"task_id": "merge-strings-alternately", "prompt": "def mergeAlternately(word1: str, word2: str) -> str:\n \"\"\"\n You are given two strings word1 and word2. Merge the strings by adding letters in alternating order, starting with word1. If a string is longer than the other, append the additional letters onto the end of the merged string.\\r\n \\r\n Return the merged string.\\r\n \\r\n \u00a0\\r\n Example 1:\\r\n \\r\n \\r\n >>> mergeAlternately(word1 = \"abc\", word2 = \"pqr\"\\r)\n >>> \"apbqcr\"\\r\n Explanation:\u00a0The merged string will be merged as so:\\r\n word1: a b c\\r\n word2: p q r\\r\n merged: a p b q c r\\r\n \\r\n \\r\n Example 2:\\r\n \\r\n \\r\n >>> mergeAlternately(word1 = \"ab\", word2 = \"pqrs\"\\r)\n >>> \"apbqrs\"\\r\n Explanation:\u00a0Notice that as word2 is longer, \"rs\" is appended to the end.\\r\n word1: a b \\r\n word2: p q r s\\r\n merged: a p b q r s\\r\n \\r\n \\r\n Example 3:\\r\n \\r\n \\r\n >>> mergeAlternately(word1 = \"abcd\", word2 = \"pq\"\\r)\n >>> \"apbqcd\"\\r\n Explanation:\u00a0Notice that as word1 is longer, \"cd\" is appended to the end.\\r\n word1: a b c d\\r\n word2: p q \\r\n merged: a p b q c d\\r\n \\r\n \\r\n \u00a0\\r\n \"\"\"\n"}
{"task_id": "minimum-number-of-operations-to-move-all-balls-to-each-box", "prompt": "def minOperations(boxes: str) -> List[int]:\n \"\"\"\n You have n boxes. You are given a binary string boxes of length n, where boxes[i] is '0' if the ith box is empty, and '1' if it contains one ball.\n In one operation, you can move one ball from a box to an adjacent box. Box i is adjacent to box j if abs(i - j) == 1. Note that after doing so, there may be more than one ball in some boxes.\n Return an array answer of size n, where answer[i] is the minimum number of operations needed to move all the balls to the ith box.\n Each answer[i] is calculated considering the initial state of the boxes.\n \n Example 1:\n \n >>> minOperations(boxes = \"110\")\n >>> [1,1,3]\n Explanation: The answer for each box is as follows:\n 1) First box: you will have to move one ball from the second box to the first box in one operation.\n 2) Second box: you will have to move one ball from the first box to the second box in one operation.\n 3) Third box: you will have to move one ball from the first box to the third box in two operations, and move one ball from the second box to the third box in one operation.\n \n Example 2:\n \n >>> minOperations(boxes = \"001011\")\n >>> [11,8,5,4,3,4]\n \"\"\"\n"}
{"task_id": "maximum-score-from-performing-multiplication-operations", "prompt": "def maximumScore(nums: List[int], multipliers: List[int]) -> int:\n \"\"\"\n You are given two 0-indexed integer arrays nums and multipliers of size n and m respectively, where n >= m.\n You begin with a score of 0. You want to perform exactly m operations. On the ith operation (0-indexed) you will:\n \n Choose one integer x from either the start or the end of the array nums.\n Add multipliers[i] * x to your score.\n \n Note that multipliers[0] corresponds to the first operation, multipliers[1] to the second operation, and so on.\n \n \n Remove x from nums.\n \n Return the maximum score after performing m operations.\n \n Example 1:\n \n >>> maximumScore(nums = [1,2,3], multipliers = [3,2,1])\n >>> 14\n Explanation:\u00a0An optimal solution is as follows:\n - Choose from the end, [1,2,3], adding 3 * 3 = 9 to the score.\n - Choose from the end, [1,2], adding 2 * 2 = 4 to the score.\n - Choose from the end, [1], adding 1 * 1 = 1 to the score.\n The total score is 9 + 4 + 1 = 14.\n Example 2:\n \n >>> maximumScore(nums = [-5,-3,-3,-2,7,1], multipliers = [-10,-5,3,4,6])\n >>> 102\n Explanation: An optimal solution is as follows:\n - Choose from the start, [-5,-3,-3,-2,7,1], adding -5 * -10 = 50 to the score.\n - Choose from the start, [-3,-3,-2,7,1], adding -3 * -5 = 15 to the score.\n - Choose from the start, [-3,-2,7,1], adding -3 * 3 = -9 to the score.\n - Choose from the end, [-2,7,1], adding 1 * 4 = 4 to the score.\n - Choose from the end, [-2,7], adding 7 * 6 = 42 to the score.\n The total score is 50 + 15 - 9 + 4 + 42 = 102.\n \"\"\"\n"}
{"task_id": "maximize-palindrome-length-from-subsequences", "prompt": "def longestPalindrome(word1: str, word2: str) -> int:\n \"\"\"\n You are given two strings, word1 and word2. You want to construct a string in the following manner:\n \n Choose some non-empty subsequence subsequence1 from word1.\n Choose some non-empty subsequence subsequence2 from word2.\n Concatenate the subsequences: subsequence1 + subsequence2, to make the string.\n \n Return the length of the longest palindrome that can be constructed in the described manner. If no palindromes can be constructed, return 0.\n A subsequence of a string s is a string that can be made by deleting some (possibly none) characters from s without changing the order of the remaining characters.\n A palindrome is a string that reads the same forward\u00a0as well as backward.\n \n Example 1:\n \n >>> longestPalindrome(word1 = \"cacb\", word2 = \"cbba\")\n >>> 5\n Explanation: Choose \"ab\" from word1 and \"cba\" from word2 to make \"abcba\", which is a palindrome.\n Example 2:\n \n >>> longestPalindrome(word1 = \"ab\", word2 = \"ab\")\n >>> 3\n Explanation: Choose \"ab\" from word1 and \"a\" from word2 to make \"aba\", which is a palindrome.\n Example 3:\n \n >>> longestPalindrome(word1 = \"aa\", word2 = \"bb\")\n >>> 0\n Explanation: You cannot construct a palindrome from the described method, so return 0.\n \"\"\"\n"}
{"task_id": "sort-features-by-popularity", "prompt": "def sortFeatures(features: List[str], responses: List[str]) -> List[str]:\n \"\"\"\n You are given a string array features where features[i] is a single word that represents the name of a feature of the latest product you are working on. You have made a survey where users have reported which features they like. You are given a string array responses, where each responses[i] is a string containing space-separated words.\n The popularity of a feature is the number of responses[i] that contain the feature. You want to sort the features in non-increasing order by their popularity. If two features have the same popularity, order them by their original index in features. Notice that one response could contain the same feature multiple times; this feature is only counted once in its popularity.\n Return the features in sorted order.\n \n Example 1:\n \n >>> sortFeatures(features = [\"cooler\",\"lock\",\"touch\"], responses = [\"i like cooler cooler\",\"lock touch cool\",\"locker like touch\"])\n >>> [\"touch\",\"cooler\",\"lock\"]\n Explanation: appearances(\"cooler\") = 1, appearances(\"lock\") = 1, appearances(\"touch\") = 2. Since \"cooler\" and \"lock\" both had 1 appearance, \"cooler\" comes first because \"cooler\" came first in the features array.\n \n Example 2:\n \n >>> sortFeatures(features = [\"a\",\"aa\",\"b\",\"c\"], responses = [\"a\",\"a aa\",\"a a a a a\",\"b a\"])\n >>> [\"a\",\"aa\",\"b\",\"c\"]\n \"\"\"\n"}
{"task_id": "count-items-matching-a-rule", "prompt": "def countMatches(items: List[List[str]], ruleKey: str, ruleValue: str) -> int:\n \"\"\"\n You are given an array items, where each items[i] = [typei, colori, namei] describes the type, color, and name of the ith item. You are also given a rule represented by two strings, ruleKey and ruleValue.\n The ith item is said to match the rule if one of the following is true:\n \n ruleKey == \"type\" and ruleValue == typei.\n ruleKey == \"color\" and ruleValue == colori.\n ruleKey == \"name\" and ruleValue == namei.\n \n Return the number of items that match the given rule.\n \n Example 1:\n \n >>> countMatches(items = [[\"phone\",\"blue\",\"pixel\"],[\"computer\",\"silver\",\"lenovo\"],[\"phone\",\"gold\",\"iphone\"]], ruleKey = \"color\", ruleValue = \"silver\")\n >>> 1\n Explanation: There is only one item matching the given rule, which is [\"computer\",\"silver\",\"lenovo\"].\n \n Example 2:\n \n >>> countMatches(items = [[\"phone\",\"blue\",\"pixel\"],[\"computer\",\"silver\",\"phone\"],[\"phone\",\"gold\",\"iphone\"]], ruleKey = \"type\", ruleValue = \"phone\")\n >>> 2\n Explanation: There are only two items matching the given rule, which are [\"phone\",\"blue\",\"pixel\"] and [\"phone\",\"gold\",\"iphone\"]. Note that the item [\"computer\",\"silver\",\"phone\"] does not match.\n \"\"\"\n"}
{"task_id": "closest-dessert-cost", "prompt": "def closestCost(baseCosts: List[int], toppingCosts: List[int], target: int) -> int:\n \"\"\"\n You would like to make dessert and are preparing to buy the ingredients. You have n ice cream base flavors and m types of toppings to choose from. You must follow these rules when making your dessert:\n \n There must be exactly one ice cream base.\n You can add one or more types of topping or have no toppings at all.\n There are at most two of each type of topping.\n \n You are given three inputs:\n \n baseCosts, an integer array of length n, where each baseCosts[i] represents the price of the ith ice cream base flavor.\n toppingCosts, an integer array of length m, where each toppingCosts[i] is the price of one of the ith topping.\n target, an integer representing your target price for dessert.\n \n You want to make a dessert with a total cost as close to target as possible.\n Return the closest possible cost of the dessert to target. If there are multiple, return the lower one.\n \n Example 1:\n \n >>> closestCost(baseCosts = [1,7], toppingCosts = [3,4], target = 10)\n >>> 10\n Explanation: Consider the following combination (all 0-indexed):\n - Choose base 1: cost 7\n - Take 1 of topping 0: cost 1 x 3 = 3\n - Take 0 of topping 1: cost 0 x 4 = 0\n Total: 7 + 3 + 0 = 10.\n \n Example 2:\n \n >>> closestCost(baseCosts = [2,3], toppingCosts = [4,5,100], target = 18)\n >>> 17\n Explanation: Consider the following combination (all 0-indexed):\n - Choose base 1: cost 3\n - Take 1 of topping 0: cost 1 x 4 = 4\n - Take 2 of topping 1: cost 2 x 5 = 10\n - Take 0 of topping 2: cost 0 x 100 = 0\n Total: 3 + 4 + 10 + 0 = 17. You cannot make a dessert with a total cost of 18.\n \n Example 3:\n \n >>> closestCost(baseCosts = [3,10], toppingCosts = [2,5], target = 9)\n >>> 8\n Explanation: It is possible to make desserts with cost 8 and 10. Return 8 as it is the lower cost.\n \"\"\"\n"}
{"task_id": "equal-sum-arrays-with-minimum-number-of-operations", "prompt": "def minOperations(nums1: List[int], nums2: List[int]) -> int:\n \"\"\"\n You are given two arrays of integers nums1 and nums2, possibly of different lengths. The values in the arrays are between 1 and 6, inclusive.\n In one operation, you can change any integer's value in any of the arrays to any value between 1 and 6, inclusive.\n Return the minimum number of operations required to make the sum of values in nums1 equal to the sum of values in nums2. Return -1\u200b\u200b\u200b\u200b\u200b if it is not possible to make the sum of the two arrays equal.\n \n Example 1:\n \n >>> minOperations(nums1 = [1,2,3,4,5,6], nums2 = [1,1,2,2,2,2])\n >>> 3\n Explanation: You can make the sums of nums1 and nums2 equal with 3 operations. All indices are 0-indexed.\n - Change nums2[0] to 6. nums1 = [1,2,3,4,5,6], nums2 = [6,1,2,2,2,2].\n - Change nums1[5] to 1. nums1 = [1,2,3,4,5,1], nums2 = [6,1,2,2,2,2].\n - Change nums1[2] to 2. nums1 = [1,2,2,4,5,1], nums2 = [6,1,2,2,2,2].\n \n Example 2:\n \n >>> minOperations(nums1 = [1,1,1,1,1,1,1], nums2 = [6])\n >>> -1\n Explanation: There is no way to decrease the sum of nums1 or to increase the sum of nums2 to make them equal.\n \n Example 3:\n \n >>> minOperations(nums1 = [6,6], nums2 = [1])\n >>> 3\n Explanation: You can make the sums of nums1 and nums2 equal with 3 operations. All indices are 0-indexed.\n - Change nums1[0] to 2. nums1 = [2,6], nums2 = [1].\n - Change nums1[1] to 2. nums1 = [2,2], nums2 = [1].\n - Change nums2[0] to 4. nums1 = [2,2], nums2 = [4].\n \"\"\"\n"}
{"task_id": "car-fleet-ii", "prompt": "def getCollisionTimes(cars: List[List[int]]) -> List[float]:\n \"\"\"\n There are n cars traveling at different speeds in the same direction along a one-lane road. You are given an array cars of length n, where cars[i] = [positioni, speedi] represents:\n \n positioni is the distance between the ith car and the beginning of the road in meters. It is guaranteed that positioni < positioni+1.\n speedi is the initial speed of the ith car in meters per second.\n \n For simplicity, cars can be considered as points moving along the number line. Two cars collide when they occupy the same position. Once a car collides with another car, they unite and form a single car fleet. The cars in the formed fleet will have the same position and the same speed, which is the initial speed of the slowest car in the fleet.\n Return an array answer, where answer[i] is the time, in seconds, at which the ith car collides with the next car, or -1 if the car does not collide with the next car. Answers within 10-5 of the actual answers are accepted.\n \n Example 1:\n \n >>> getCollisionTimes(cars = [[1,2],[2,1],[4,3],[7,2]])\n >>> [1.00000,-1.00000,3.00000,-1.00000]\n Explanation: After exactly one second, the first car will collide with the second car, and form a car fleet with speed 1 m/s. After exactly 3 seconds, the third car will collide with the fourth car, and form a car fleet with speed 2 m/s.\n \n Example 2:\n \n >>> getCollisionTimes(cars = [[3,4],[5,4],[6,3],[9,1]])\n >>> [2.00000,1.00000,1.50000,-1.00000]\n \"\"\"\n"}
{"task_id": "find-nearest-point-that-has-the-same-x-or-y-coordinate", "prompt": "def nearestValidPoint(x: int, y: int, points: List[List[int]]) -> int:\n \"\"\"\n You are given two integers, x and y, which represent your current location on a Cartesian grid: (x, y). You are also given an array points where each points[i] = [ai, bi] represents that a point exists at (ai, bi). A point is valid if it shares the same x-coordinate or the same y-coordinate as your location.\n Return the index (0-indexed) of the valid point with the smallest Manhattan distance from your current location. If there are multiple, return the valid point with the smallest index. If there are no valid points, return -1.\n The Manhattan distance between two points (x1, y1) and (x2, y2) is abs(x1 - x2) + abs(y1 - y2).\n \n Example 1:\n \n >>> nearestValidPoint(x = 3, y = 4, points = [[1,2],[3,1],[2,4],[2,3],[4,4]])\n >>> 2\n Explanation: Of all the points, only [3,1], [2,4] and [4,4] are valid. Of the valid points, [2,4] and [4,4] have the smallest Manhattan distance from your current location, with a distance of 1. [2,4] has the smallest index, so return 2.\n Example 2:\n \n >>> nearestValidPoint(x = 3, y = 4, points = [[3,4]])\n >>> 0\n Explanation: The answer is allowed to be on the same location as your current location.\n Example 3:\n \n >>> nearestValidPoint(x = 3, y = 4, points = [[2,3]])\n >>> -1\n Explanation: There are no valid points.\n \"\"\"\n"}
{"task_id": "check-if-number-is-a-sum-of-powers-of-three", "prompt": "def checkPowersOfThree(n: int) -> bool:\n \"\"\"\n Given an integer n, return true if it is possible to represent n as the sum of distinct powers of three. Otherwise, return false.\n An integer y is a power of three if there exists an integer x such that y == 3x.\n \n Example 1:\n \n >>> checkPowersOfThree(n = 12)\n >>> true\n Explanation: 12 = 31 + 32\n \n Example 2:\n \n >>> checkPowersOfThree(n = 91)\n >>> true\n Explanation: 91 = 30 + 32 + 34\n \n Example 3:\n \n >>> checkPowersOfThree(n = 21)\n >>> false\n \"\"\"\n"}
{"task_id": "sum-of-beauty-of-all-substrings", "prompt": "def beautySum(s: str) -> int:\n \"\"\"\n The beauty of a string is the difference in frequencies between the most frequent and least frequent characters.\n \n For example, the beauty of \"abaacc\" is 3 - 1 = 2.\n \n Given a string s, return the sum of beauty of all of its substrings.\n \n Example 1:\n \n >>> beautySum(s = \"aabcb\")\n >>> 5\n Explanation: The substrings with non-zero beauty are [\"aab\",\"aabc\",\"aabcb\",\"abcb\",\"bcb\"], each with beauty equal to 1.\n Example 2:\n \n >>> beautySum(s = \"aabcbaa\")\n >>> 17\n \"\"\"\n"}
{"task_id": "count-pairs-of-nodes", "prompt": "def countPairs(n: int, edges: List[List[int]], queries: List[int]) -> List[int]:\n \"\"\"\n You are given an undirected graph defined by an integer n, the number of nodes, and a 2D integer array edges, the edges in the graph, where edges[i] = [ui, vi] indicates that there is an undirected edge between ui and vi. You are also given an integer array queries.\n Let incident(a, b) be defined as the number of edges that are connected to either node a or b.\n The answer to the jth query is the number of pairs of nodes (a, b) that satisfy both of the following conditions:\n \n a < b\n incident(a, b) > queries[j]\n \n Return an array answers such that answers.length == queries.length and answers[j] is the answer of the jth query.\n Note that there can be multiple edges between the same two nodes.\n \n Example 1:\n \n \n >>> countPairs(n = 4, edges = [[1,2],[2,4],[1,3],[2,3],[2,1]], queries = [2,3])\n >>> [6,5]\n Explanation: The calculations for incident(a, b) are shown in the table above.\n The answers for each of the queries are as follows:\n - answers[0] = 6. All the pairs have an incident(a, b) value greater than 2.\n - answers[1] = 5. All the pairs except (3, 4) have an incident(a, b) value greater than 3.\n \n Example 2:\n \n >>> countPairs(n = 5, edges = [[1,5],[1,5],[3,4],[2,5],[1,3],[5,1],[2,3],[2,5]], queries = [1,2,3,4,5])\n >>> [10,10,9,8,6]\n \"\"\"\n"}
{"task_id": "check-if-binary-string-has-at-most-one-segment-of-ones", "prompt": "def checkOnesSegment(s: str) -> bool:\n \"\"\"\n Given a binary string s \u200b\u200b\u200b\u200b\u200bwithout leading zeros, return true\u200b\u200b\u200b if s contains at most one contiguous segment of ones. Otherwise, return false.\n \n Example 1:\n \n >>> checkOnesSegment(s = \"1001\")\n >>> false\n Explanation: The ones do not form a contiguous segment.\n \n Example 2:\n \n >>> checkOnesSegment(s = \"110\")\n >>> true\n \"\"\"\n"}
{"task_id": "minimum-elements-to-add-to-form-a-given-sum", "prompt": "def minElements(nums: List[int], limit: int, goal: int) -> int:\n \"\"\"\n You are given an integer array nums and two integers limit and goal. The array nums has an interesting property that abs(nums[i]) <= limit.\n Return the minimum number of elements you need to add to make the sum of the array equal to goal. The array must maintain its property that abs(nums[i]) <= limit.\n Note that abs(x) equals x if x >= 0, and -x otherwise.\n \n Example 1:\n \n >>> minElements(nums = [1,-1,1], limit = 3, goal = -4)\n >>> 2\n Explanation: You can add -2 and -3, then the sum of the array will be 1 - 1 + 1 - 2 - 3 = -4.\n \n Example 2:\n \n >>> minElements(nums = [1,-10,9,1], limit = 100, goal = 0)\n >>> 1\n \"\"\"\n"}
{"task_id": "number-of-restricted-paths-from-first-to-last-node", "prompt": "def countRestrictedPaths(n: int, edges: List[List[int]]) -> int:\n \"\"\"\n There is an undirected weighted connected graph. You are given a positive integer n which denotes that the graph has n nodes labeled from 1 to n, and an array edges where each edges[i] = [ui, vi, weighti] denotes that there is an edge between nodes ui and vi with weight equal to weighti.\n A path from node start to node end is a sequence of nodes [z0, z1, z2, ..., zk] such that z0 = start and zk = end and there is an edge between zi and zi+1 where 0 <= i <= k-1.\n The distance of a path is the sum of the weights on the edges of the path. Let distanceToLastNode(x) denote the shortest distance of a path between node n and node x. A restricted path is a path that also satisfies that distanceToLastNode(zi) > distanceToLastNode(zi+1) where 0 <= i <= k-1.\n Return the number of restricted paths from node 1 to node n. Since that number may be too large, return it modulo 109 + 7.\n \n Example 1:\n \n \n >>> countRestrictedPaths(n = 5, edges = [[1,2,3],[1,3,3],[2,3,1],[1,4,2],[5,2,2],[3,5,1],[5,4,10]])\n >>> 3\n Explanation: Each circle contains the node number in black and its distanceToLastNode value in blue. The three restricted paths are:\n 1) 1 --> 2 --> 5\n 2) 1 --> 2 --> 3 --> 5\n 3) 1 --> 3 --> 5\n \n Example 2:\n \n \n >>> countRestrictedPaths(n = 7, edges = [[1,3,1],[4,1,2],[7,3,4],[2,5,3],[5,6,1],[6,7,2],[7,5,3],[2,6,4]])\n >>> 1\n Explanation: Each circle contains the node number in black and its distanceToLastNode value in blue. The only restricted path is 1 --> 3 --> 7.\n \"\"\"\n"}
{"task_id": "make-the-xor-of-all-segments-equal-to-zero", "prompt": "def minChanges(nums: List[int], k: int) -> int:\n \"\"\"\n You are given an array nums\u200b\u200b\u200b and an integer k\u200b\u200b\u200b\u200b\u200b. The XOR of a segment [left, right] where left <= right is the XOR of all the elements with indices between left and right, inclusive: nums[left] XOR nums[left+1] XOR ... XOR nums[right].\n Return the minimum number of elements to change in the array such that the XOR of all segments of size k\u200b\u200b\u200b\u200b\u200b\u200b is equal to zero.\n \n Example 1:\n \n >>> minChanges(nums = [1,2,0,3,0], k = 1)\n >>> 3\n Explanation: Modify the array from [1,2,0,3,0] to from [0,0,0,0,0].\n \n Example 2:\n \n >>> minChanges(nums = [3,4,5,2,1,7,3,4,7], k = 3)\n >>> 3\n Explanation: Modify the array from [3,4,5,2,1,7,3,4,7] to [3,4,7,3,4,7,3,4,7].\n \n Example 3:\n \n >>> minChanges(nums = [1,2,4,1,2,5,1,2,6], k = 3)\n >>> 3\n Explanation: Modify the array from [1,2,4,1,2,5,1,2,6] to [1,2,3,1,2,3,1,2,3].\n \"\"\"\n"}
{"task_id": "maximize-the-beauty-of-the-garden", "prompt": "def maximumBeauty(flowers: List[int]) -> int:\n \"\"\"\n There is a garden of n flowers, and each flower has an integer beauty value. The flowers are arranged in a line. You are given an integer array flowers of size n and each flowers[i] represents the beauty of the ith flower.\\r\n \\r\n A garden is valid if it meets these conditions:\\r\n \\r\n \\r\n \tThe garden has at least two flowers.\\r\n \tThe first and the last flower of the garden have the same beauty value.\\r\n \\r\n \\r\n As the appointed gardener, you have the ability to remove any (possibly none) flowers from the garden. You want to remove flowers in a way that makes the remaining garden valid. The beauty of the garden is the sum of the beauty of all the remaining flowers.\\r\n \\r\n Return the maximum possible beauty of some valid garden after you have removed any (possibly none) flowers.\\r\n \\r\n \u00a0\\r\n Example 1:\\r\n \\r\n \\r\n >>> maximumBeauty(flowers = [1,2,3,1,2]\\r)\n >>> 8\\r\n Explanation: You can produce the valid garden [2,3,1,2] to have a total beauty of 2 + 3 + 1 + 2 = 8.\\r\n \\r\n Example 2:\\r\n \\r\n \\r\n >>> maximumBeauty(flowers = [100,1,1,-3,1]\\r)\n >>> 3\\r\n Explanation: You can produce the valid garden [1,1,1] to have a total beauty of 1 + 1 + 1 = 3.\\r\n \\r\n \\r\n Example 3:\\r\n \\r\n \\r\n >>> maximumBeauty(flowers = [-1,-2,0,-1]\\r)\n >>> -2\\r\n Explanation: You can produce the valid garden [-1,-1] to have a total beauty of -1 + -1 = -2.\\r\n \\r\n \\r\n \u00a0\\r\n \"\"\"\n"}
{"task_id": "check-if-one-string-swap-can-make-strings-equal", "prompt": "def areAlmostEqual(s1: str, s2: str) -> bool:\n \"\"\"\n You are given two strings s1 and s2 of equal length. A string swap is an operation where you choose two indices in a string (not necessarily different) and swap the characters at these indices.\n Return true if it is possible to make both strings equal by performing at most one string swap on exactly one of the strings. Otherwise, return false.\n \n Example 1:\n \n >>> areAlmostEqual(s1 = \"bank\", s2 = \"kanb\")\n >>> true\n Explanation: For example, swap the first character with the last character of s2 to make \"bank\".\n \n Example 2:\n \n >>> areAlmostEqual(s1 = \"attack\", s2 = \"defend\")\n >>> false\n Explanation: It is impossible to make them equal with one string swap.\n \n Example 3:\n \n >>> areAlmostEqual(s1 = \"kelb\", s2 = \"kelb\")\n >>> true\n Explanation: The two strings are already equal, so no string swap operation is required.\n \"\"\"\n"}
{"task_id": "find-center-of-star-graph", "prompt": "def findCenter(edges: List[List[int]]) -> int:\n \"\"\"\n There is an undirected star graph consisting of n nodes labeled from 1 to n. A star graph is a graph where there is one center node and exactly n - 1 edges that connect the center node with every other node.\n You are given a 2D integer array edges where each edges[i] = [ui, vi] indicates that there is an edge between the nodes ui and vi. Return the center of the given star graph.\n \n Example 1:\n \n \n >>> findCenter(edges = [[1,2],[2,3],[4,2]])\n >>> 2\n Explanation: As shown in the figure above, node 2 is connected to every other node, so 2 is the center.\n \n Example 2:\n \n >>> findCenter(edges = [[1,2],[5,1],[1,3],[1,4]])\n >>> 1\n \"\"\"\n"}
{"task_id": "maximum-average-pass-ratio", "prompt": "def maxAverageRatio(classes: List[List[int]], extraStudents: int) -> float:\n \"\"\"\n There is a school that has classes of students and each class will be having a final exam. You are given a 2D integer array classes, where classes[i] = [passi, totali]. You know beforehand that in the ith class, there are totali total students, but only passi number of students will pass the exam.\n You are also given an integer extraStudents. There are another extraStudents brilliant students that are guaranteed to pass the exam of any class they are assigned to. You want to assign each of the extraStudents students to a class in a way that maximizes the average pass ratio across all the classes.\n The pass ratio of a class is equal to the number of students of the class that will pass the exam divided by the total number of students of the class. The average pass ratio is the sum of pass ratios of all the classes divided by the number of the classes.\n Return the maximum possible average pass ratio after assigning the extraStudents students. Answers within 10-5 of the actual answer will be accepted.\n \n Example 1:\n \n >>> maxAverageRatio(classes = [[1,2],[3,5],[2,2]], extraStudents = 2)\n >>> 0.78333\n Explanation: You can assign the two extra students to the first class. The average pass ratio will be equal to (3/4 + 3/5 + 2/2) / 3 = 0.78333.\n \n Example 2:\n \n >>> maxAverageRatio(classes = [[2,4],[3,9],[4,5],[2,10]], extraStudents = 4)\n >>> 0.53485\n \"\"\"\n"}
{"task_id": "maximum-score-of-a-good-subarray", "prompt": "def maximumScore(nums: List[int], k: int) -> int:\n \"\"\"\n You are given an array of integers nums (0-indexed) and an integer k.\n The score of a subarray (i, j) is defined as min(nums[i], nums[i+1], ..., nums[j]) * (j - i + 1). A good subarray is a subarray where i <= k <= j.\n Return the maximum possible score of a good subarray.\n \n Example 1:\n \n >>> maximumScore(nums = [1,4,3,7,4,5], k = 3)\n >>> 15\n Explanation: The optimal subarray is (1, 5) with a score of min(4,3,7,4,5) * (5-1+1) = 3 * 5 = 15.\n \n Example 2:\n \n >>> maximumScore(nums = [5,5,4,5,4,1,1,1], k = 0)\n >>> 20\n Explanation: The optimal subarray is (0, 4) with a score of min(5,5,4,5,4) * (4-0+1) = 4 * 5 = 20.\n \"\"\"\n"}
{"task_id": "count-pairs-of-equal-substrings-with-minimum-difference", "prompt": "def countQuadruples(firstString: str, secondString: str) -> int:\n \"\"\"\n You are given two strings firstString and secondString that are 0-indexed and consist only of lowercase English letters. Count the number of index quadruples (i,j,a,b) that satisfy the following conditions:\n \n 0 <= i <= j < firstString.length\n 0 <= a <= b < secondString.length\n The substring of firstString that starts at the ith character and ends at the jth character (inclusive) is equal to the substring of secondString that starts at the ath character and ends at the bth character (inclusive).\n j - a is the minimum possible value among all quadruples that satisfy the previous conditions.\n \n Return the number of such quadruples.\n \n Example 1:\n \n >>> countQuadruples(firstString = \"abcd\", secondString = \"bccda\")\n >>> 1\n Explanation: The quadruple (0,0,4,4) is the only one that satisfies all the conditions and minimizes j - a.\n \n Example 2:\n \n >>> countQuadruples(firstString = \"ab\", secondString = \"cd\")\n >>> 0\n Explanation: There are no quadruples satisfying all the conditions.\n \"\"\"\n"}
{"task_id": "second-largest-digit-in-a-string", "prompt": "def secondHighest(s: str) -> int:\n \"\"\"\n Given an alphanumeric string s, return the second largest numerical digit that appears in s, or -1 if it does not exist.\n An alphanumeric string is a string consisting of lowercase English letters and digits.\n \n Example 1:\n \n >>> secondHighest(s = \"dfa12321afd\")\n >>> 2\n Explanation: The digits that appear in s are [1, 2, 3]. The second largest digit is 2.\n \n Example 2:\n \n >>> secondHighest(s = \"abc1111\")\n >>> -1\n Explanation: The digits that appear in s are [1]. There is no second largest digit.\n \"\"\"\n"}
{"task_id": "maximum-number-of-consecutive-values-you-can-make", "prompt": "def getMaximumConsecutive(coins: List[int]) -> int:\n \"\"\"\n You are given an integer array coins of length n which represents the n coins that you own. The value of the ith coin is coins[i]. You can make some value x if you can choose some of your n coins such that their values sum up to x.\n Return the maximum number of consecutive integer values that you can make with your coins starting from and including 0.\n Note that you may have multiple coins of the same value.\n \n Example 1:\n \n >>> getMaximumConsecutive(coins = [1,3])\n >>> 2\n Explanation: You can make the following values:\n - 0: take []\n - 1: take [1]\n You can make 2 consecutive integer values starting from 0.\n Example 2:\n \n >>> getMaximumConsecutive(coins = [1,1,1,4])\n >>> 8\n Explanation: You can make the following values:\n - 0: take []\n - 1: take [1]\n - 2: take [1,1]\n - 3: take [1,1,1]\n - 4: take [4]\n - 5: take [4,1]\n - 6: take [4,1,1]\n - 7: take [4,1,1,1]\n You can make 8 consecutive integer values starting from 0.\n Example 3:\n \n >>> getMaximumConsecutive(coins = [1,4,10,3,1])\n >>> 20\n \"\"\"\n"}
{"task_id": "maximum-ascending-subarray-sum", "prompt": "def maxAscendingSum(nums: List[int]) -> int:\n \"\"\"\n Given an array of positive integers nums, return the maximum possible sum of an strictly increasing subarray in nums.\n A subarray is defined as a contiguous sequence of numbers in an array.\n \n Example 1:\n \n >>> maxAscendingSum(nums = [10,20,30,5,10,50])\n >>> 65\n Explanation: [5,10,50] is the ascending subarray with the maximum sum of 65.\n \n Example 2:\n \n >>> maxAscendingSum(nums = [10,20,30,40,50])\n >>> 150\n Explanation: [10,20,30,40,50] is the ascending subarray with the maximum sum of 150.\n \n Example 3:\n \n >>> maxAscendingSum(nums = [12,17,15,13,10,11,12])\n >>> 33\n Explanation: [10,11,12] is the ascending subarray with the maximum sum of 33.\n \"\"\"\n"}
{"task_id": "number-of-orders-in-the-backlog", "prompt": "def getNumberOfBacklogOrders(orders: List[List[int]]) -> int:\n \"\"\"\n You are given a 2D integer array orders, where each orders[i] = [pricei, amounti, orderTypei] denotes that amounti orders have been placed of type orderTypei at the price pricei. The orderTypei is:\\r\n \\r\n \\r\n \t0 if it is a batch of buy orders, or\\r\n \t1 if it is a batch of sell orders.\\r\n \\r\n \\r\n Note that orders[i] represents a batch of amounti independent orders with the same price and order type. All orders represented by orders[i] will be placed before all orders represented by orders[i+1] for all valid i.\\r\n \\r\n There is a backlog that consists of orders that have not been executed. The backlog is initially empty. When an order is placed, the following happens:\\r\n \\r\n \\r\n \tIf the order is a buy order, you look at the sell order with the smallest price in the backlog. If that sell order's price is smaller than or equal to the current buy order's price, they will match and be executed, and that sell order will be removed from the backlog. Else, the buy order is added to the backlog.\\r\n \tVice versa, if the order is a sell order, you look at the buy order with the largest price in the backlog. If that buy order's price is larger than or equal to the current sell order's price, they will match and be executed, and that buy order will be removed from the backlog. Else, the sell order is added to the backlog.\\r\n \\r\n \\r\n Return the total amount of orders in the backlog after placing all the orders from the input. Since this number can be large, return it modulo 109 + 7.\\r\n \\r\n \u00a0\\r\n Example 1:\\r\n \\r\n \\r\n >>> getNumberOfBacklogOrders(orders = [[10,5,0],[15,2,1],[25,1,1],[30,4,0]]\\r)\n >>> 6\\r\n Explanation: Here is what happens with the orders:\\r\n - 5 orders of type buy with price 10 are placed. There are no sell orders, so the 5 orders are added to the backlog.\\r\n - 2 orders of type sell with price 15 are placed. There are no buy orders with prices larger than or equal to 15, so the 2 orders are added to the backlog.\\r\n - 1 order of type sell with price 25 is placed. There are no buy orders with prices larger than or equal to 25 in the backlog, so this order is added to the backlog.\\r\n - 4 orders of type buy with price 30 are placed. The first 2 orders are matched with the 2 sell orders of the least price, which is 15 and these 2 sell orders are removed from the backlog. The 3rd order is matched with the sell order of the least price, which is 25 and this sell order is removed from the backlog. Then, there are no more sell orders in the backlog, so the 4th order is added to the backlog.\\r\n Finally, the backlog has 5 buy orders with price 10, and 1 buy order with price 30. So the total number of orders in the backlog is 6.\\r\n \\r\n \\r\n Example 2:\\r\n \\r\n \\r\n >>> getNumberOfBacklogOrders(orders = [[7,1000000000,1],[15,3,0],[5,999999995,0],[5,1,1]]\\r)\n >>> 999999984\\r\n Explanation: Here is what happens with the orders:\\r\n - 109 orders of type sell with price 7 are placed. There are no buy orders, so the 109 orders are added to the backlog.\\r\n - 3 orders of type buy with price 15 are placed. They are matched with the 3 sell orders with the least price which is 7, and those 3 sell orders are removed from the backlog.\\r\n - 999999995 orders of type buy with price 5 are placed. The least price of a sell order is 7, so the 999999995 orders are added to the backlog.\\r\n - 1 order of type sell with price 5 is placed. It is matched with the buy order of the highest price, which is 5, and that buy order is removed from the backlog.\\r\n Finally, the backlog has (1000000000-3) sell orders with price 7, and (999999995-1) buy orders with price 5. So the total number of orders = 1999999991, which is equal to 999999984 % (109 + 7).\\r\n \\r\n \\r\n \u00a0\\r\n \"\"\"\n"}
{"task_id": "maximum-value-at-a-given-index-in-a-bounded-array", "prompt": "def maxValue(n: int, index: int, maxSum: int) -> int:\n \"\"\"\n You are given three positive integers:\u00a0n, index, and maxSum. You want to construct an array nums (0-indexed) that satisfies the following conditions:\n \n nums.length == n\n nums[i] is a positive integer where 0 <= i < n.\n abs(nums[i] - nums[i+1]) <= 1 where 0 <= i < n-1.\n The sum of all the elements of nums does not exceed maxSum.\n nums[index] is maximized.\n \n Return nums[index] of the constructed array.\n Note that abs(x) equals x if x >= 0, and -x otherwise.\n \n Example 1:\n \n >>> maxValue(n = 4, index = 2, maxSum = 6)\n >>> 2\n Explanation: nums = [1,2,2,1] is one array that satisfies all the conditions.\n There are no arrays that satisfy all the conditions and have nums[2] == 3, so 2 is the maximum nums[2].\n \n Example 2:\n \n >>> maxValue(n = 6, index = 1, maxSum = 10)\n >>> 3\n \"\"\"\n"}
{"task_id": "count-pairs-with-xor-in-a-range", "prompt": "def countPairs(nums: List[int], low: int, high: int) -> int:\n \"\"\"\n Given a (0-indexed) integer array nums and two integers low and high, return the number of nice pairs.\\r\n \\r\n A nice pair is a pair (i, j) where 0 <= i < j < nums.length and low <= (nums[i] XOR nums[j]) <= high.\\r\n \\r\n \u00a0\\r\n Example 1:\\r\n \\r\n \\r\n >>> countPairs(nums = [1,4,2,7], low = 2, high = 6\\r)\n >>> 6\\r\n Explanation: All nice pairs (i, j) are as follows:\\r\n - (0, 1): nums[0] XOR nums[1] = 5 \\r\n - (0, 2): nums[0] XOR nums[2] = 3\\r\n - (0, 3): nums[0] XOR nums[3] = 6\\r\n - (1, 2): nums[1] XOR nums[2] = 6\\r\n - (1, 3): nums[1] XOR nums[3] = 3\\r\n - (2, 3): nums[2] XOR nums[3] = 5\\r\n \\r\n \\r\n Example 2:\\r\n \\r\n \\r\n >>> countPairs(nums = [9,8,4,2,1], low = 5, high = 14\\r)\n >>> 8\\r\n Explanation: All nice pairs (i, j) are as follows:\\r\n \u200b\u200b\u200b\u200b\u200b - (0, 2): nums[0] XOR nums[2] = 13\\r\n \u00a0 - (0, 3): nums[0] XOR nums[3] = 11\\r\n \u00a0 - (0, 4): nums[0] XOR nums[4] = 8\\r\n \u00a0 - (1, 2): nums[1] XOR nums[2] = 12\\r\n \u00a0 - (1, 3): nums[1] XOR nums[3] = 10\\r\n \u00a0 - (1, 4): nums[1] XOR nums[4] = 9\\r\n \u00a0 - (2, 3): nums[2] XOR nums[3] = 6\\r\n \u00a0 - (2, 4): nums[2] XOR nums[4] = 5\\r\n \\r\n \u00a0\\r\n \"\"\"\n"}
{"task_id": "number-of-different-integers-in-a-string", "prompt": "def numDifferentIntegers(word: str) -> int:\n \"\"\"\n You are given a string word that consists of digits and lowercase English letters.\n You will replace every non-digit character with a space. For example, \"a123bc34d8ef34\" will become \" 123\u00a0 34 8\u00a0 34\". Notice that you are left with some integers that are separated by at least one space: \"123\", \"34\", \"8\", and \"34\".\n Return the number of different integers after performing the replacement operations on word.\n Two integers are considered different if their decimal representations without any leading zeros are different.\n \n Example 1:\n \n >>> numDifferentIntegers(word = \"a123bc34d8ef34\")\n >>> 3\n Explanation: The three different integers are \"123\", \"34\", and \"8\". Notice that \"34\" is only counted once.\n \n Example 2:\n \n >>> numDifferentIntegers(word = \"leet1234code234\")\n >>> 2\n \n Example 3:\n \n >>> numDifferentIntegers(word = \"a1b01c001\")\n >>> 1\n Explanation: The three integers \"1\", \"01\", and \"001\" all represent the same integer because\n the leading zeros are ignored when comparing their decimal values.\n \"\"\"\n"}
{"task_id": "minimum-number-of-operations-to-reinitialize-a-permutation", "prompt": "def reinitializePermutation(n: int) -> int:\n \"\"\"\n You are given an even integer n\u200b\u200b\u200b\u200b\u200b\u200b. You initially have a permutation perm of size n\u200b\u200b where perm[i] == i\u200b (0-indexed)\u200b\u200b\u200b\u200b.\n In one operation, you will create a new array arr, and for each i:\n \n If i % 2 == 0, then arr[i] = perm[i / 2].\n If i % 2 == 1, then arr[i] = perm[n / 2 + (i - 1) / 2].\n \n You will then assign arr\u200b\u200b\u200b\u200b to perm.\n Return the minimum non-zero number of operations you need to perform on perm to return the permutation to its initial value.\n \n Example 1:\n \n >>> reinitializePermutation(n = 2)\n >>> 1\n Explanation: perm = [0,1] initially.\n After the 1st operation, perm = [0,1]\n So it takes only 1 operation.\n \n Example 2:\n \n >>> reinitializePermutation(n = 4)\n >>> 2\n Explanation: perm = [0,1,2,3] initially.\n After the 1st operation, perm = [0,2,1,3]\n After the 2nd operation, perm = [0,1,2,3]\n So it takes only 2 operations.\n \n Example 3:\n \n >>> reinitializePermutation(n = 6)\n >>> 4\n \"\"\"\n"}
{"task_id": "evaluate-the-bracket-pairs-of-a-string", "prompt": "def evaluate(s: str, knowledge: List[List[str]]) -> str:\n \"\"\"\n You are given a string s that contains some bracket pairs, with each pair containing a non-empty key.\n \n For example, in the string \"(name)is(age)yearsold\", there are two bracket pairs that contain the keys \"name\" and \"age\".\n \n You know the values of a wide range of keys. This is represented by a 2D string array knowledge where each knowledge[i] = [keyi, valuei] indicates that key keyi has a value of valuei.\n You are tasked to evaluate all of the bracket pairs. When you evaluate a bracket pair that contains some key keyi, you will:\n \n Replace keyi and the bracket pair with the key's corresponding valuei.\n If you do not know the value of the key, you will replace keyi and the bracket pair with a question mark \"?\" (without the quotation marks).\n \n Each key will appear at most once in your knowledge. There will not be any nested brackets in s.\n Return the resulting string after evaluating all of the bracket pairs.\n \n Example 1:\n \n >>> evaluate(s = \"(name)is(age)yearsold\", knowledge = [[\"name\",\"bob\"],[\"age\",\"two\"]])\n >>> \"bobistwoyearsold\"\n Explanation:\n The key \"name\" has a value of \"bob\", so replace \"(name)\" with \"bob\".\n The key \"age\" has a value of \"two\", so replace \"(age)\" with \"two\".\n \n Example 2:\n \n >>> evaluate(s = \"hi(name)\", knowledge = [[\"a\",\"b\"]])\n >>> \"hi?\"\n Explanation: As you do not know the value of the key \"name\", replace \"(name)\" with \"?\".\n \n Example 3:\n \n >>> evaluate(s = \"(a)(a)(a)aaa\", knowledge = [[\"a\",\"yes\"]])\n >>> \"yesyesyesaaa\"\n Explanation: The same key can appear multiple times.\n The key \"a\" has a value of \"yes\", so replace all occurrences of \"(a)\" with \"yes\".\n Notice that the \"a\"s not in a bracket pair are not evaluated.\n \"\"\"\n"}
{"task_id": "maximize-number-of-nice-divisors", "prompt": "def maxNiceDivisors(primeFactors: int) -> int:\n \"\"\"\n You are given a positive integer primeFactors. You are asked to construct a positive integer n that satisfies the following conditions:\\r\n \\r\n \\r\n The number of prime factors of n (not necessarily distinct) is at most primeFactors.\\r\n The number of nice divisors of n is maximized. Note that a divisor of n is nice if it is divisible by every prime factor of n. For example, if n = 12, then its prime factors are [2,2,3], then 6 and 12 are nice divisors, while 3 and 4 are not.\\r\n \\r\n \\r\n Return the number of nice divisors of n. Since that number can be too large, return it modulo 109 + 7.\\r\n \\r\n Note that a prime number is a natural number greater than 1 that is not a product of two smaller natural numbers. The prime factors of a number n is a list of prime numbers such that their product equals n.\\r\n \\r\n \u00a0\\r\n Example 1:\\r\n \\r\n \\r\n >>> maxNiceDivisors(primeFactors = 5\\r)\n >>> 6\\r\n Explanation: 200 is a valid value of n.\\r\n It has 5 prime factors: [2,2,2,5,5], and it has 6 nice divisors: [10,20,40,50,100,200].\\r\n There is not other value of n that has at most 5 prime factors and more nice divisors.\\r\n \\r\n \\r\n Example 2:\\r\n \\r\n \\r\n >>> maxNiceDivisors(primeFactors = 8\\r)\n >>> 18\\r\n \\r\n \\r\n \u00a0\\r\n \"\"\"\n"}
{"task_id": "determine-color-of-a-chessboard-square", "prompt": "def squareIsWhite(coordinates: str) -> bool:\n \"\"\"\n You are given coordinates, a string that represents the coordinates of a square of the chessboard. Below is a chessboard for your reference.\n \n Return true if the square is white, and false if the square is black.\n The coordinate will always represent a valid chessboard square. The coordinate will always have the letter first, and the number second.\n \n Example 1:\n \n >>> squareIsWhite(coordinates = \"a1\")\n >>> false\n Explanation: From the chessboard above, the square with coordinates \"a1\" is black, so return false.\n \n Example 2:\n \n >>> squareIsWhite(coordinates = \"h3\")\n >>> true\n Explanation: From the chessboard above, the square with coordinates \"h3\" is white, so return true.\n \n Example 3:\n \n >>> squareIsWhite(coordinates = \"c7\")\n >>> false\n \"\"\"\n"}
{"task_id": "sentence-similarity-iii", "prompt": "def areSentencesSimilar(sentence1: str, sentence2: str) -> bool:\n \"\"\"\n You are given two strings sentence1 and sentence2, each representing a sentence composed of words. A sentence is a list of words that are separated by a single space with no leading or trailing spaces. Each word consists of only uppercase and lowercase English characters.\n Two sentences s1 and s2 are considered similar if it is possible to insert an arbitrary sentence (possibly empty) inside one of these sentences such that the two sentences become equal. Note that the inserted sentence must be separated from existing words by spaces.\n For example,\n \n s1 = \"Hello Jane\" and s2 = \"Hello my name is Jane\" can be made equal by inserting \"my name is\" between \"Hello\" and \"Jane\" in s1.\n s1 = \"Frog cool\" and s2 = \"Frogs are cool\" are not similar, since although there is a sentence \"s are\" inserted into s1, it is not separated from \"Frog\" by a space.\n \n Given two sentences sentence1 and sentence2, return true if sentence1 and sentence2 are similar. Otherwise, return false.\n \n Example 1:\n \n >>> areSentencesSimilar(sentence1 = \"My name is Haley\", sentence2 = \"My Haley\")\n >>> true\n Explanation:\n sentence2 can be turned to sentence1 by inserting \"name is\" between \"My\" and \"Haley\".\n \n Example 2:\n \n >>> areSentencesSimilar(sentence1 = \"of\", sentence2 = \"A lot of words\")\n >>> false\n Explanation:\n No single sentence can be inserted inside one of the sentences to make it equal to the other.\n \n Example 3:\n \n >>> areSentencesSimilar(sentence1 = \"Eating right now\", sentence2 = \"Eating\")\n >>> true\n Explanation:\n sentence2 can be turned to sentence1 by inserting \"right now\" at the end of the sentence.\n \"\"\"\n"}
{"task_id": "count-nice-pairs-in-an-array", "prompt": "def countNicePairs(nums: List[int]) -> int:\n \"\"\"\n You are given an array nums that consists of non-negative integers. Let us define rev(x) as the reverse of the non-negative integer x. For example, rev(123) = 321, and rev(120) = 21. A pair of indices (i, j) is nice if it satisfies all of the following conditions:\n \n 0 <= i < j < nums.length\n nums[i] + rev(nums[j]) == nums[j] + rev(nums[i])\n \n Return the number of nice pairs of indices. Since that number can be too large, return it modulo 109 + 7.\n \n Example 1:\n \n >>> countNicePairs(nums = [42,11,1,97])\n >>> 2\n Explanation: The two pairs are:\n - (0,3) : 42 + rev(97) = 42 + 79 = 121, 97 + rev(42) = 97 + 24 = 121.\n - (1,2) : 11 + rev(1) = 11 + 1 = 12, 1 + rev(11) = 1 + 11 = 12.\n \n Example 2:\n \n >>> countNicePairs(nums = [13,10,35,24,76])\n >>> 4\n \"\"\"\n"}
{"task_id": "maximum-number-of-groups-getting-fresh-donuts", "prompt": "def maxHappyGroups(batchSize: int, groups: List[int]) -> int:\n \"\"\"\n There is a donuts shop that bakes donuts in batches of batchSize. They have a rule where they must serve all of the donuts of a batch before serving any donuts of the next batch. You are given an integer batchSize and an integer array groups, where groups[i] denotes that there is a group of groups[i] customers that will visit the shop. Each customer will get exactly one donut.\n When a group visits the shop, all customers of the group must be served before serving any of the following groups. A group will be happy if they all get fresh donuts. That is, the first customer of the group does not receive a donut that was left over from the previous group.\n You can freely rearrange the ordering of the groups. Return the maximum possible number of happy groups after rearranging the groups.\n \n Example 1:\n \n >>> maxHappyGroups(batchSize = 3, groups = [1,2,3,4,5,6])\n >>> 4\n Explanation: You can arrange the groups as [6,2,4,5,1,3]. Then the 1st, 2nd, 4th, and 6th groups will be happy.\n \n Example 2:\n \n >>> maxHappyGroups(batchSize = 4, groups = [1,3,2,5,2,2,1,6])\n >>> 4\n \"\"\"\n"}
{"task_id": "truncate-sentence", "prompt": "def truncateSentence(s: str, k: int) -> str:\n \"\"\"\n A sentence is a list of words that are separated by a single space with no leading or trailing spaces. Each of the words consists of only uppercase and lowercase English letters (no punctuation).\n \n For example, \"Hello World\", \"HELLO\", and \"hello world hello world\" are all sentences.\n \n You are given a sentence s\u200b\u200b\u200b\u200b\u200b\u200b and an integer k\u200b\u200b\u200b\u200b\u200b\u200b. You want to truncate s\u200b\u200b\u200b\u200b\u200b\u200b such that it contains only the first k\u200b\u200b\u200b\u200b\u200b\u200b words. Return s\u200b\u200b\u200b\u200b\u200b\u200b after truncating it.\n \n Example 1:\n \n >>> truncateSentence(s = \"Hello how are you Contestant\", k = 4)\n >>> \"Hello how are you\"\n Explanation:\n The words in s are [\"Hello\", \"how\" \"are\", \"you\", \"Contestant\"].\n The first 4 words are [\"Hello\", \"how\", \"are\", \"you\"].\n Hence, you should return \"Hello how are you\".\n \n Example 2:\n \n >>> truncateSentence(s = \"What is the solution to this problem\", k = 4)\n >>> \"What is the solution\"\n Explanation:\n The words in s are [\"What\", \"is\" \"the\", \"solution\", \"to\", \"this\", \"problem\"].\n The first 4 words are [\"What\", \"is\", \"the\", \"solution\"].\n Hence, you should return \"What is the solution\".\n Example 3:\n \n >>> truncateSentence(s = \"chopper is not a tanuki\", k = 5)\n >>> \"chopper is not a tanuki\"\n \"\"\"\n"}
{"task_id": "finding-the-users-active-minutes", "prompt": "def findingUsersActiveMinutes(logs: List[List[int]], k: int) -> List[int]:\n \"\"\"\n You are given the logs for users' actions on LeetCode, and an integer k. The logs are represented by a 2D integer array logs where each logs[i] = [IDi, timei] indicates that the user with IDi performed an action at the minute timei.\n Multiple users can perform actions simultaneously, and a single user can perform multiple actions in the same minute.\n The user active minutes (UAM) for a given user is defined as the number of unique minutes in which the user performed an action on LeetCode. A minute can only be counted once, even if multiple actions occur during it.\n You are to calculate a 1-indexed array answer of size k such that, for each j (1 <= j <= k), answer[j] is the number of users whose UAM equals j.\n Return the array answer as described above.\n \n Example 1:\n \n >>> findingUsersActiveMinutes(logs = [[0,5],[1,2],[0,2],[0,5],[1,3]], k = 5)\n >>> [0,2,0,0,0]\n Explanation:\n The user with ID=0 performed actions at minutes 5, 2, and 5 again. Hence, they have a UAM of 2 (minute 5 is only counted once).\n The user with ID=1 performed actions at minutes 2 and 3. Hence, they have a UAM of 2.\n Since both users have a UAM of 2, answer[2] is 2, and the remaining answer[j] values are 0.\n \n Example 2:\n \n >>> findingUsersActiveMinutes(logs = [[1,1],[2,2],[2,3]], k = 4)\n >>> [1,1,0,0]\n Explanation:\n The user with ID=1 performed a single action at minute 1. Hence, they have a UAM of 1.\n The user with ID=2 performed actions at minutes 2 and 3. Hence, they have a UAM of 2.\n There is one user with a UAM of 1 and one with a UAM of 2.\n Hence, answer[1] = 1, answer[2] = 1, and the remaining values are 0.\n \"\"\"\n"}
{"task_id": "minimum-absolute-sum-difference", "prompt": "def minAbsoluteSumDiff(nums1: List[int], nums2: List[int]) -> int:\n \"\"\"\n You are given two positive integer arrays nums1 and nums2, both of length n.\n The absolute sum difference of arrays nums1 and nums2 is defined as the sum of |nums1[i] - nums2[i]| for each 0 <= i < n (0-indexed).\n You can replace at most one element of nums1 with any other element in nums1 to minimize the absolute sum difference.\n Return the minimum absolute sum difference after replacing at most one element in the array nums1. Since the answer may be large, return it modulo 109 + 7.\n |x| is defined as:\n \n x if x >= 0, or\n -x if x < 0.\n \n \n Example 1:\n \n >>> minAbsoluteSumDiff(nums1 = [1,7,5], nums2 = [2,3,5])\n >>> 3\n Explanation: There are two possible optimal solutions:\n - Replace the second element with the first: [1,7,5] => [1,1,5], or\n - Replace the second element with the third: [1,7,5] => [1,5,5].\n Both will yield an absolute sum difference of |1-2| + (|1-3| or |5-3|) + |5-5| = 3.\n \n Example 2:\n \n >>> minAbsoluteSumDiff(nums1 = [2,4,6,8,10], nums2 = [2,4,6,8,10])\n >>> 0\n Explanation: nums1 is equal to nums2 so no replacement is needed. This will result in an\n absolute sum difference of 0.\n \n Example 3:\n \n >>> minAbsoluteSumDiff(nums1 = [1,10,4,4,2,7], nums2 = [9,3,5,1,7,4])\n >>> 20\n Explanation: Replace the first element with the second: [1,10,4,4,2,7] => [10,10,4,4,2,7].\n This yields an absolute sum difference of |10-9| + |10-3| + |4-5| + |4-1| + |2-7| + |7-4| = 20\n \"\"\"\n"}
{"task_id": "number-of-different-subsequences-gcds", "prompt": "def countDifferentSubsequenceGCDs(nums: List[int]) -> int:\n \"\"\"\n You are given an array nums that consists of positive integers.\n The GCD of a sequence of numbers is defined as the greatest integer that divides all the numbers in the sequence evenly.\n \n For example, the GCD of the sequence [4,6,16] is 2.\n \n A subsequence of an array is a sequence that can be formed by removing some elements (possibly none) of the array.\n \n For example, [2,5,10] is a subsequence of [1,2,1,2,4,1,5,10].\n \n Return the number of different GCDs among all non-empty subsequences of nums.\n \n Example 1:\n \n \n >>> countDifferentSubsequenceGCDs(nums = [6,10,3])\n >>> 5\n Explanation: The figure shows all the non-empty subsequences and their GCDs.\n The different GCDs are 6, 10, 3, 2, and 1.\n \n Example 2:\n \n >>> countDifferentSubsequenceGCDs(nums = [5,15,40,5,6])\n >>> 7\n \"\"\"\n"}
{"task_id": "maximum-number-of-accepted-invitations", "prompt": "def maximumInvitations(grid: List[List[int]]) -> int:\n \"\"\"\n There are m boys and n girls in a class attending an upcoming party.\n You are given an m x n integer matrix grid, where grid[i][j] equals 0 or 1. If grid[i][j] == 1, then that means the ith boy can invite the jth girl to the party. A boy can invite at most one girl, and a girl can accept at most one invitation from a boy.\n Return the maximum possible number of accepted invitations.\n \n Example 1:\n \n [1,0,1],\n [0,0,1]]\n >>> maximumInvitations(grid = [[1,1,1],)\n >>> 3\n Explanation: The invitations are sent as follows:\n - The 1st boy invites the 2nd girl.\n - The 2nd boy invites the 1st girl.\n - The 3rd boy invites the 3rd girl.\n Example 2:\n \n [1,0,0,0],\n [0,0,1,0],\n [1,1,1,0]]\n >>> maximumInvitations(grid = [[1,0,1,0],)\n >>> 3\n Explanation: The invitations are sent as follows:\n -The 1st boy invites the 3rd girl.\n -The 2nd boy invites the 1st girl.\n -The 3rd boy invites no one.\n -The 4th boy invites the 2nd girl.\n \"\"\"\n"}
{"task_id": "sign-of-the-product-of-an-array", "prompt": "def arraySign(nums: List[int]) -> int:\n \"\"\"\n Implement a function signFunc(x) that returns:\n \n 1 if x is positive.\n -1 if x is negative.\n 0 if x is equal to 0.\n \n You are given an integer array nums. Let product be the product of all values in the array nums.\n Return signFunc(product).\n \n Example 1:\n \n >>> arraySign(nums = [-1,-2,-3,-4,3,2,1])\n >>> 1\n Explanation: The product of all values in the array is 144, and signFunc(144) = 1\n \n Example 2:\n \n >>> arraySign(nums = [1,5,0,2,-3])\n >>> 0\n Explanation: The product of all values in the array is 0, and signFunc(0) = 0\n \n Example 3:\n \n >>> arraySign(nums = [-1,1,-1,1,-1])\n >>> -1\n Explanation: The product of all values in the array is -1, and signFunc(-1) = -1\n \"\"\"\n"}
{"task_id": "find-the-winner-of-the-circular-game", "prompt": "def findTheWinner(n: int, k: int) -> int:\n \"\"\"\n There are n friends that are playing a game. The friends are sitting in a circle and are numbered from 1 to n in clockwise order. More formally, moving clockwise from the ith friend brings you to the (i+1)th friend for 1 <= i < n, and moving clockwise from the nth friend brings you to the 1st friend.\n The rules of the game are as follows:\n \n Start at the 1st friend.\n Count the next k friends in the clockwise direction including the friend you started at. The counting wraps around the circle and may count some friends more than once.\n The last friend you counted leaves the circle and loses the game.\n If there is still more than one friend in the circle, go back to step 2 starting from the friend immediately clockwise of the friend who just lost and repeat.\n Else, the last friend in the circle wins the game.\n \n Given the number of friends, n, and an integer k, return the winner of the game.\n \n Example 1:\n \n \n >>> findTheWinner(n = 5, k = 2)\n >>> 3\n Explanation: Here are the steps of the game:\n 1) Start at friend 1.\n 2) Count 2 friends clockwise, which are friends 1 and 2.\n 3) Friend 2 leaves the circle. Next start is friend 3.\n 4) Count 2 friends clockwise, which are friends 3 and 4.\n 5) Friend 4 leaves the circle. Next start is friend 5.\n 6) Count 2 friends clockwise, which are friends 5 and 1.\n 7) Friend 1 leaves the circle. Next start is friend 3.\n 8) Count 2 friends clockwise, which are friends 3 and 5.\n 9) Friend 5 leaves the circle. Only friend 3 is left, so they are the winner.\n Example 2:\n \n >>> findTheWinner(n = 6, k = 5)\n >>> 1\n Explanation: The friends leave in this order: 5, 4, 6, 2, 3. The winner is friend 1.\n \"\"\"\n"}
{"task_id": "minimum-sideway-jumps", "prompt": "def minSideJumps(obstacles: List[int]) -> int:\n \"\"\"\n There is a 3 lane road of length n that consists of n + 1 points labeled from 0 to n. A frog starts at point 0 in the second lane and wants to jump to point n. However, there could be obstacles along the way.\n You are given an array obstacles of length n + 1 where each obstacles[i] (ranging from 0 to 3) describes an obstacle on the lane obstacles[i] at point i. If obstacles[i] == 0, there are no obstacles at point i. There will be at most one obstacle in the 3 lanes at each point.\n \n For example, if obstacles[2] == 1, then there is an obstacle on lane 1 at point 2.\n \n The frog can only travel from point i to point i + 1 on the same lane if there is not an obstacle on the lane at point i + 1. To avoid obstacles, the frog can also perform a side jump to jump to another lane (even if they are not adjacent) at the same point if there is no obstacle on the new lane.\n \n For example, the frog can jump from lane 3 at point 3 to lane 1 at point 3.\n \n Return the minimum number of side jumps the frog needs to reach any lane at point n starting from lane 2 at point 0.\n Note: There will be no obstacles on points 0 and n.\n \n Example 1:\n \n \n >>> minSideJumps(obstacles = [0,1,2,3,0])\n >>> 2\n Explanation: The optimal solution is shown by the arrows above. There are 2 side jumps (red arrows).\n Note that the frog can jump over obstacles only when making side jumps (as shown at point 2).\n \n Example 2:\n \n \n >>> minSideJumps(obstacles = [0,1,1,3,3,0])\n >>> 0\n Explanation: There are no obstacles on lane 2. No side jumps are required.\n \n Example 3:\n \n \n >>> minSideJumps(obstacles = [0,2,1,0,3,0])\n >>> 2\n Explanation: The optimal solution is shown by the arrows above. There are 2 side jumps.\n \"\"\"\n"}
{"task_id": "faulty-sensor", "prompt": "def badSensor(sensor1: List[int], sensor2: List[int]) -> int:\n \"\"\"\n An experiment is being conducted in a lab. To ensure accuracy, there are two sensors collecting data simultaneously. You are given two arrays sensor1 and sensor2, where sensor1[i] and sensor2[i] are the ith data points collected by the two sensors.\n However, this type of sensor has a chance of being defective, which causes exactly one data point to be dropped. After the data is dropped, all the data points to the right of the dropped data are shifted one place to the left, and the last data point is replaced with some random value. It is guaranteed that this random value will not be equal to the dropped value.\n \n For example, if the correct data is [1,2,3,4,5] and 3 is dropped, the sensor could return [1,2,4,5,7] (the last position can be any value, not just 7).\n \n We know that there is a defect in at most one of the sensors. Return the sensor number (1 or 2) with the defect. If there is no defect in either sensor or if it is impossible to determine the defective sensor, return -1.\n \n Example 1:\n \n >>> badSensor(sensor1 = [2,3,4,5], sensor2 = [2,1,3,4])\n >>> 1\n Explanation: Sensor 2 has the correct values.\n The second data point from sensor 2 is dropped, and the last value of sensor 1 is replaced by a 5.\n \n Example 2:\n \n >>> badSensor(sensor1 = [2,2,2,2,2], sensor2 = [2,2,2,2,5])\n >>> -1\n Explanation: It is impossible to determine which sensor has a defect.\n Dropping the last value for either sensor could produce the output for the other sensor.\n \n Example 3:\n \n >>> badSensor(sensor1 = [2,3,2,2,3,2], sensor2 = [2,3,2,3,2,7])\n >>> 2\n Explanation: Sensor 1 has the correct values.\n The fourth data point from sensor 1 is dropped, and the last value of sensor 1 is replaced by a 7.\n \"\"\"\n"}
{"task_id": "minimum-operations-to-make-the-array-increasing", "prompt": "def minOperations(nums: List[int]) -> int:\n \"\"\"\n You are given an integer array nums (0-indexed). In one operation, you can choose an element of the array and increment it by 1.\\r\n \\r\n \\r\n \tFor example, if nums = [1,2,3], you can choose to increment nums[1] to make nums = [1,3,3].\\r\n \\r\n \\r\n Return the minimum number of operations needed to make nums strictly increasing.\\r\n \\r\n An array nums is strictly increasing if nums[i] < nums[i+1] for all 0 <= i < nums.length - 1. An array of length 1 is trivially strictly increasing.\\r\n \\r\n \u00a0\\r\n Example 1:\\r\n \\r\n \\r\n >>> minOperations(nums = [1,1,1]\\r)\n >>> 3\\r\n Explanation: You can do the following operations:\\r\n 1) Increment nums[2], so nums becomes [1,1,2].\\r\n 2) Increment nums[1], so nums becomes [1,2,2].\\r\n 3) Increment nums[2], so nums becomes [1,2,3].\\r\n \\r\n \\r\n Example 2:\\r\n \\r\n \\r\n >>> minOperations(nums = [1,5,2,4,1]\\r)\n >>> 14\\r\n \\r\n \\r\n Example 3:\\r\n \\r\n \\r\n >>> minOperations(nums = [8]\\r)\n >>> 0\\r\n \\r\n \\r\n \u00a0\\r\n \"\"\"\n"}
{"task_id": "queries-on-number-of-points-inside-a-circle", "prompt": "def countPoints(points: List[List[int]], queries: List[List[int]]) -> List[int]:\n \"\"\"\n You are given an array points where points[i] = [xi, yi] is the coordinates of the ith point on a 2D plane. Multiple points can have the same coordinates.\n You are also given an array queries where queries[j] = [xj, yj, rj] describes a circle centered at (xj, yj) with a radius of rj.\n For each query queries[j], compute the number of points inside the jth circle. Points on the border of the circle are considered inside.\n Return an array answer, where answer[j] is the answer to the jth query.\n \n Example 1:\n \n \n >>> countPoints(points = [[1,3],[3,3],[5,3],[2,2]], queries = [[2,3,1],[4,3,1],[1,1,2]])\n >>> [3,2,2]\n Explanation: The points and circles are shown above.\n queries[0] is the green circle, queries[1] is the red circle, and queries[2] is the blue circle.\n \n Example 2:\n \n \n >>> countPoints(points = [[1,1],[2,2],[3,3],[4,4],[5,5]], queries = [[1,2,2],[2,2,2],[4,3,2],[4,3,3]])\n >>> [2,3,2,4]\n Explanation: The points and circles are shown above.\n queries[0] is green, queries[1] is red, queries[2] is blue, and queries[3] is purple.\n \"\"\"\n"}
{"task_id": "maximum-xor-for-each-query", "prompt": "def getMaximumXor(nums: List[int], maximumBit: int) -> List[int]:\n \"\"\"\n You are given a sorted array nums of n non-negative integers and an integer maximumBit. You want to perform the following query n times:\n \n Find a non-negative integer k < 2maximumBit such that nums[0] XOR nums[1] XOR ... XOR nums[nums.length-1] XOR k is maximized. k is the answer to the ith query.\n Remove the last element from the current array nums.\n \n Return an array answer, where answer[i] is the answer to the ith query.\n \n Example 1:\n \n >>> getMaximumXor(nums = [0,1,1,3], maximumBit = 2)\n >>> [0,3,2,3]\n Explanation: The queries are answered as follows:\n 1st query: nums = [0,1,1,3], k = 0 since 0 XOR 1 XOR 1 XOR 3 XOR 0 = 3.\n 2nd query: nums = [0,1,1], k = 3 since 0 XOR 1 XOR 1 XOR 3 = 3.\n 3rd query: nums = [0,1], k = 2 since 0 XOR 1 XOR 2 = 3.\n 4th query: nums = [0], k = 3 since 0 XOR 3 = 3.\n \n Example 2:\n \n >>> getMaximumXor(nums = [2,3,4,7], maximumBit = 3)\n >>> [5,2,6,5]\n Explanation: The queries are answered as follows:\n 1st query: nums = [2,3,4,7], k = 5 since 2 XOR 3 XOR 4 XOR 7 XOR 5 = 7.\n 2nd query: nums = [2,3,4], k = 2 since 2 XOR 3 XOR 4 XOR 2 = 7.\n 3rd query: nums = [2,3], k = 6 since 2 XOR 3 XOR 6 = 7.\n 4th query: nums = [2], k = 5 since 2 XOR 5 = 7.\n \n Example 3:\n \n >>> getMaximumXor(nums = [0,1,2,2,5,7], maximumBit = 3)\n >>> [4,3,6,4,6,7]\n \"\"\"\n"}
{"task_id": "check-if-the-sentence-is-pangram", "prompt": "def checkIfPangram(sentence: str) -> bool:\n \"\"\"\n A pangram is a sentence where every letter of the English alphabet appears at least once.\n Given a string sentence containing only lowercase English letters, return true if sentence is a pangram, or false otherwise.\n \n Example 1:\n \n >>> checkIfPangram(sentence = \"thequickbrownfoxjumpsoverthelazydog\")\n >>> true\n Explanation: sentence contains at least one of every letter of the English alphabet.\n \n Example 2:\n \n >>> checkIfPangram(sentence = \"leetcode\")\n >>> false\n \"\"\"\n"}
{"task_id": "maximum-ice-cream-bars", "prompt": "def maxIceCream(costs: List[int], coins: int) -> int:\n \"\"\"\n It is a sweltering summer day, and a boy wants to buy some ice cream bars.\n At the store, there are n ice cream bars. You are given an array costs of length n, where costs[i] is the price of the ith ice cream bar in coins. The boy initially has coins coins to spend, and he wants to buy as many ice cream bars as possible.\n Note: The boy can buy the ice cream bars in any order.\n Return the maximum number of ice cream bars the boy can buy with coins coins.\n You must solve the problem by counting sort.\n \n Example 1:\n \n >>> maxIceCream(costs = [1,3,2,4,1], coins = 7)\n >>> 4\n Explanation: The boy can buy ice cream bars at indices 0,1,2,4 for a total price of 1 + 3 + 2 + 1 = 7.\n \n Example 2:\n \n >>> maxIceCream(costs = [10,6,8,7,7,8], coins = 5)\n >>> 0\n Explanation: The boy cannot afford any of the ice cream bars.\n \n Example 3:\n \n >>> maxIceCream(costs = [1,6,3,1,2,5], coins = 20)\n >>> 6\n Explanation: The boy can buy all the ice cream bars for a total price of 1 + 6 + 3 + 1 + 2 + 5 = 18.\n \"\"\"\n"}
{"task_id": "single-threaded-cpu", "prompt": "def getOrder(tasks: List[List[int]]) -> List[int]:\n \"\"\"\n You are given n\u200b\u200b\u200b\u200b\u200b\u200b tasks labeled from 0 to n - 1 represented by a 2D integer array tasks, where tasks[i] = [enqueueTimei, processingTimei] means that the i\u200b\u200b\u200b\u200b\u200b\u200bth\u200b\u200b\u200b\u200b task will be available to process at enqueueTimei and will take processingTimei to finish processing.\n You have a single-threaded CPU that can process at most one task at a time and will act in the following way:\n \n If the CPU is idle and there are no available tasks to process, the CPU remains idle.\n If the CPU is idle and there are available tasks, the CPU will choose the one with the shortest processing time. If multiple tasks have the same shortest processing time, it will choose the task with the smallest index.\n Once a task is started, the CPU will process the entire task without stopping.\n The CPU can finish a task then start a new one instantly.\n \n Return the order in which the CPU will process the tasks.\n \n Example 1:\n \n >>> getOrder(tasks = [[1,2],[2,4],[3,2],[4,1]])\n >>> [0,2,3,1]\n Explanation: The events go as follows:\n - At time = 1, task 0 is available to process. Available tasks = {0}.\n - Also at time = 1, the idle CPU starts processing task 0. Available tasks = {}.\n - At time = 2, task 1 is available to process. Available tasks = {1}.\n - At time = 3, task 2 is available to process. Available tasks = {1, 2}.\n - Also at time = 3, the CPU finishes task 0 and starts processing task 2 as it is the shortest. Available tasks = {1}.\n - At time = 4, task 3 is available to process. Available tasks = {1, 3}.\n - At time = 5, the CPU finishes task 2 and starts processing task 3 as it is the shortest. Available tasks = {1}.\n - At time = 6, the CPU finishes task 3 and starts processing task 1. Available tasks = {}.\n - At time = 10, the CPU finishes task 1 and becomes idle.\n \n Example 2:\n \n >>> getOrder(tasks = [[7,10],[7,12],[7,5],[7,4],[7,2]])\n >>> [4,3,2,0,1]\n Explanation: The events go as follows:\n - At time = 7, all the tasks become available. Available tasks = {0,1,2,3,4}.\n - Also at time = 7, the idle CPU starts processing task 4. Available tasks = {0,1,2,3}.\n - At time = 9, the CPU finishes task 4 and starts processing task 3. Available tasks = {0,1,2}.\n - At time = 13, the CPU finishes task 3 and starts processing task 2. Available tasks = {0,1}.\n - At time = 18, the CPU finishes task 2 and starts processing task 0. Available tasks = {1}.\n - At time = 28, the CPU finishes task 0 and starts processing task 1. Available tasks = {}.\n - At time = 40, the CPU finishes task 1 and becomes idle.\n \"\"\"\n"}
{"task_id": "find-xor-sum-of-all-pairs-bitwise-and", "prompt": "def getXORSum(arr1: List[int], arr2: List[int]) -> int:\n \"\"\"\n The XOR sum of a list is the bitwise XOR of all its elements. If the list only contains one element, then its XOR sum will be equal to this element.\n \n For example, the XOR sum of [1,2,3,4] is equal to 1 XOR 2 XOR 3 XOR 4 = 4, and the XOR sum of [3] is equal to 3.\n \n You are given two 0-indexed arrays arr1 and arr2 that consist only of non-negative integers.\n Consider the list containing the result of arr1[i] AND arr2[j] (bitwise AND) for every (i, j) pair where 0 <= i < arr1.length and 0 <= j < arr2.length.\n Return the XOR sum of the aforementioned list.\n \n Example 1:\n \n >>> getXORSum(arr1 = [1,2,3], arr2 = [6,5])\n >>> 0\n Explanation: The list = [1 AND 6, 1 AND 5, 2 AND 6, 2 AND 5, 3 AND 6, 3 AND 5] = [0,1,2,0,2,1].\n The XOR sum = 0 XOR 1 XOR 2 XOR 0 XOR 2 XOR 1 = 0.\n \n Example 2:\n \n >>> getXORSum(arr1 = [12], arr2 = [4])\n >>> 4\n Explanation: The list = [12 AND 4] = [4]. The XOR sum = 4.\n \"\"\"\n"}
{"task_id": "remove-duplicates-from-an-unsorted-linked-list", "prompt": "# class ListNode:\n# def __init__(val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution:\n def deleteDuplicatesUnsorted(head: Optional[ListNode]) -> Optional[ListNode]:\n \"\"\"\n Given the head of a linked list, find all the values that appear more than once in the list and delete the nodes that have any of those values.\\r\n \\r\n Return the linked list after the deletions.\\r\n \\r\n \u00a0\\r\n Example 1:\\r\n \\r\n \\r\n >>> __init__(head = [1,2,3,2]\\r)\n >>> [1,3]\\r\n Explanation: 2 appears twice in the linked list, so all 2's should be deleted. After deleting all 2's, we are left with [1,3].\\r\n \\r\n \\r\n Example 2:\\r\n \\r\n \\r\n >>> __init__(head = [2,1,1,2]\\r)\n >>> []\\r\n Explanation: 2 and 1 both appear twice. All the elements should be deleted.\\r\n \\r\n \\r\n Example 3:\\r\n \\r\n \\r\n >>> __init__(head = [3,2,2,1,3,2,4]\\r)\n >>> [1,4]\\r\n Explanation: 3 appears twice and 2 appears three times. After deleting all 3's and 2's, we are left with [1,4].\\r\n \\r\n \\r\n \u00a0\\r\n \"\"\"\n"}
{"task_id": "sum-of-digits-in-base-k", "prompt": "def sumBase(n: int, k: int) -> int:\n \"\"\"\n Given an integer n (in base 10) and a base k, return the sum of the digits of n after converting n from base 10 to base k.\n After converting, each digit should be interpreted as a base 10 number, and the sum should be returned in base 10.\n \n Example 1:\n \n >>> sumBase(n = 34, k = 6)\n >>> 9\n Explanation: 34 (base 10) expressed in base 6 is 54. 5 + 4 = 9.\n \n Example 2:\n \n >>> sumBase(n = 10, k = 10)\n >>> 1\n Explanation: n is already in base 10. 1 + 0 = 1.\n \"\"\"\n"}
{"task_id": "frequency-of-the-most-frequent-element", "prompt": "def maxFrequency(nums: List[int], k: int) -> int:\n \"\"\"\n The frequency of an element is the number of times it occurs in an array.\n You are given an integer array nums and an integer k. In one operation, you can choose an index of nums and increment the element at that index by 1.\n Return the maximum possible frequency of an element after performing at most k operations.\n \n Example 1:\n \n >>> maxFrequency(nums = [1,2,4], k = 5)\n >>> 3\n Explanation: Increment the first element three times and the second element two times to make nums = [4,4,4].\n 4 has a frequency of 3.\n Example 2:\n \n >>> maxFrequency(nums = [1,4,8,13], k = 5)\n >>> 2\n Explanation: There are multiple optimal solutions:\n - Increment the first element three times to make nums = [4,4,8,13]. 4 has a frequency of 2.\n - Increment the second element four times to make nums = [1,8,8,13]. 8 has a frequency of 2.\n - Increment the third element five times to make nums = [1,4,13,13]. 13 has a frequency of 2.\n \n Example 3:\n \n >>> maxFrequency(nums = [3,9,6], k = 2)\n >>> 1\n \"\"\"\n"}
{"task_id": "longest-substring-of-all-vowels-in-order", "prompt": "def longestBeautifulSubstring(word: str) -> int:\n \"\"\"\n A string is considered beautiful if it satisfies the following conditions:\n \n Each of the 5 English vowels ('a', 'e', 'i', 'o', 'u') must appear at least once in it.\n The letters must be sorted in alphabetical order (i.e. all 'a's before 'e's, all 'e's before 'i's, etc.).\n \n For example, strings \"aeiou\" and \"aaaaaaeiiiioou\" are considered beautiful, but \"uaeio\", \"aeoiu\", and \"aaaeeeooo\" are not beautiful.\n Given a string word consisting of English vowels, return the length of the longest beautiful substring of word. If no such substring exists, return 0.\n A substring is a contiguous sequence of characters in a string.\n \n Example 1:\n \n >>> longestBeautifulSubstring(word = \"aeiaaioaaaaeiiiiouuuooaauuaeiu\")\n >>> 13\n Explanation: The longest beautiful substring in word is \"aaaaeiiiiouuu\" of length 13.\n Example 2:\n \n >>> longestBeautifulSubstring(word = \"aeeeiiiioooauuuaeiou\")\n >>> 5\n Explanation: The longest beautiful substring in word is \"aeiou\" of length 5.\n \n Example 3:\n \n >>> longestBeautifulSubstring(word = \"a\")\n >>> 0\n Explanation: There is no beautiful substring, so return 0.\n \"\"\"\n"}
{"task_id": "maximum-building-height", "prompt": "def maxBuilding(n: int, restrictions: List[List[int]]) -> int:\n \"\"\"\n You want to build n new buildings in a city. The new buildings will be built in a line and are labeled from 1 to n.\n However, there are city restrictions on the heights of the new buildings:\n \n The height of each building must be a non-negative integer.\n The height of the first building must be 0.\n The height difference between any two adjacent buildings cannot exceed 1.\n \n Additionally, there are city restrictions on the maximum height of specific buildings. These restrictions are given as a 2D integer array restrictions where restrictions[i] = [idi, maxHeighti] indicates that building idi must have a height less than or equal to maxHeighti.\n It is guaranteed that each building will appear at most once in restrictions, and building 1 will not be in restrictions.\n Return the maximum possible height of the tallest building.\n \n Example 1:\n \n \n >>> maxBuilding(n = 5, restrictions = [[2,1],[4,1]])\n >>> 2\n Explanation: The green area in the image indicates the maximum allowed height for each building.\n We can build the buildings with heights [0,1,2,1,2], and the tallest building has a height of 2.\n Example 2:\n \n \n >>> maxBuilding(n = 6, restrictions = [])\n >>> 5\n Explanation: The green area in the image indicates the maximum allowed height for each building.\n We can build the buildings with heights [0,1,2,3,4,5], and the tallest building has a height of 5.\n \n Example 3:\n \n \n >>> maxBuilding(n = 10, restrictions = [[5,3],[2,5],[7,4],[10,3]])\n >>> 5\n Explanation: The green area in the image indicates the maximum allowed height for each building.\n We can build the buildings with heights [0,1,2,3,3,4,4,5,4,3], and the tallest building has a height of 5.\n \"\"\"\n"}
{"task_id": "next-palindrome-using-same-digits", "prompt": "def nextPalindrome(num: str) -> str:\n \"\"\"\n You are given a numeric string num, representing a very large palindrome.\n Return the smallest palindrome larger than num that can be created by rearranging its digits. If no such palindrome exists, return an empty string \"\".\n A palindrome is a number that reads the same backward as forward.\n \n Example 1:\n \n >>> nextPalindrome(num = \"1221\")\n >>> \"2112\"\n Explanation:\u00a0The next palindrome larger than \"1221\" is \"2112\".\n \n Example 2:\n \n >>> nextPalindrome(num = \"32123\")\n >>> \"\"\n Explanation:\u00a0No palindromes larger than \"32123\" can be made by rearranging the digits.\n \n Example 3:\n \n >>> nextPalindrome(num = \"45544554\")\n >>> \"54455445\"\n Explanation: The next palindrome larger than \"45544554\" is \"54455445\".\n \"\"\"\n"}
{"task_id": "replace-all-digits-with-characters", "prompt": "def replaceDigits(s: str) -> str:\n \"\"\"\n You are given a 0-indexed string s that has lowercase English letters in its even indices and digits in its odd indices.\n You must perform an operation shift(c, x), where c is a character and x is a digit, that returns the xth character after c.\n \n For example, shift('a', 5) = 'f' and shift('x', 0) = 'x'.\n \n For every odd index i, you want to replace the digit s[i] with the result of the shift(s[i-1], s[i]) operation.\n Return s after replacing all digits. It is guaranteed that shift(s[i-1], s[i]) will never exceed 'z'.\n Note that shift(c, x) is not a preloaded function, but an operation to be implemented as part of the solution.\n \n Example 1:\n \n >>> replaceDigits(s = \"a1c1e1\")\n >>> \"abcdef\"\n Explanation: The digits are replaced as follows:\n - s[1] -> shift('a',1) = 'b'\n - s[3] -> shift('c',1) = 'd'\n - s[5] -> shift('e',1) = 'f'\n Example 2:\n \n >>> replaceDigits(s = \"a1b2c3d4e\")\n >>> \"abbdcfdhe\"\n Explanation: The digits are replaced as follows:\n - s[1] -> shift('a',1) = 'b'\n - s[3] -> shift('b',2) = 'd'\n - s[5] -> shift('c',3) = 'f'\n - s[7] -> shift('d',4) = 'h'\n \"\"\"\n"}
{"task_id": "maximum-element-after-decreasing-and-rearranging", "prompt": "def maximumElementAfterDecrementingAndRearranging(arr: List[int]) -> int:\n \"\"\"\n You are given an array of positive integers arr. Perform some operations (possibly none) on arr so that it satisfies these conditions:\n \n The value of the first element in arr must be 1.\n The absolute difference between any 2 adjacent elements must be less than or equal to 1. In other words, abs(arr[i] - arr[i - 1]) <= 1 for each i where 1 <= i < arr.length (0-indexed). abs(x) is the absolute value of x.\n \n There are 2 types of operations that you can perform any number of times:\n \n Decrease the value of any element of arr to a smaller positive integer.\n Rearrange the elements of arr to be in any order.\n \n Return the maximum possible value of an element in arr after performing the operations to satisfy the conditions.\n \n Example 1:\n \n >>> maximumElementAfterDecrementingAndRearranging(arr = [2,2,1,2,1])\n >>> 2\n Explanation:\n We can satisfy the conditions by rearranging arr so it becomes [1,2,2,2,1].\n The largest element in arr is 2.\n \n Example 2:\n \n >>> maximumElementAfterDecrementingAndRearranging(arr = [100,1,1000])\n >>> 3\n Explanation:\n One possible way to satisfy the conditions is by doing the following:\n 1. Rearrange arr so it becomes [1,100,1000].\n 2. Decrease the value of the second element to 2.\n 3. Decrease the value of the third element to 3.\n Now arr = [1,2,3], which satisfies the conditions.\n The largest element in arr is 3.\n \n Example 3:\n \n >>> maximumElementAfterDecrementingAndRearranging(arr = [1,2,3,4,5])\n >>> 5\n Explanation: The array already satisfies the conditions, and the largest element is 5.\n \"\"\"\n"}
{"task_id": "closest-room", "prompt": "def closestRoom(rooms: List[List[int]], queries: List[List[int]]) -> List[int]:\n \"\"\"\n There is a hotel with n rooms. The rooms are represented by a 2D integer array rooms where rooms[i] = [roomIdi, sizei] denotes that there is a room with room number roomIdi and size equal to sizei. Each roomIdi is guaranteed to be unique.\n You are also given k queries in a 2D array queries where queries[j] = [preferredj, minSizej]. The answer to the jth query is the room number id of a room such that:\n \n The room has a size of at least minSizej, and\n abs(id - preferredj) is minimized, where abs(x) is the absolute value of x.\n \n If there is a tie in the absolute difference, then use the room with the smallest such id. If there is no such room, the answer is -1.\n Return an array answer of length k where answer[j] contains the answer to the jth query.\n \n Example 1:\n \n >>> closestRoom(rooms = [[2,2],[1,2],[3,2]], queries = [[3,1],[3,3],[5,2]])\n >>> [3,-1,3]\n Explanation: The answers to the queries are as follows:\n Query = [3,1]: Room number 3 is the closest as abs(3 - 3) = 0, and its size of 2 is at least 1. The answer is 3.\n Query = [3,3]: There are no rooms with a size of at least 3, so the answer is -1.\n Query = [5,2]: Room number 3 is the closest as abs(3 - 5) = 2, and its size of 2 is at least 2. The answer is 3.\n Example 2:\n \n >>> closestRoom(rooms = [[1,4],[2,3],[3,5],[4,1],[5,2]], queries = [[2,3],[2,4],[2,5]])\n >>> [2,1,3]\n Explanation: The answers to the queries are as follows:\n Query = [2,3]: Room number 2 is the closest as abs(2 - 2) = 0, and its size of 3 is at least 3. The answer is 2.\n Query = [2,4]: Room numbers 1 and 3 both have sizes of at least 4. The answer is 1 since it is smaller.\n Query = [2,5]: Room number 3 is the only room with a size of at least 5. The answer is 3.\n \"\"\"\n"}
{"task_id": "minimum-distance-to-the-target-element", "prompt": "def getMinDistance(nums: List[int], target: int, start: int) -> int:\n \"\"\"\n Given an integer array nums (0-indexed) and two integers target and start, find an index i such that nums[i] == target and abs(i - start) is minimized. Note that\u00a0abs(x)\u00a0is the absolute value of x.\n Return abs(i - start).\n It is guaranteed that target exists in nums.\n \n Example 1:\n \n >>> getMinDistance(nums = [1,2,3,4,5], target = 5, start = 3)\n >>> 1\n Explanation: nums[4] = 5 is the only value equal to target, so the answer is abs(4 - 3) = 1.\n \n Example 2:\n \n >>> getMinDistance(nums = [1], target = 1, start = 0)\n >>> 0\n Explanation: nums[0] = 1 is the only value equal to target, so the answer is abs(0 - 0) = 0.\n \n Example 3:\n \n >>> getMinDistance(nums = [1,1,1,1,1,1,1,1,1,1], target = 1, start = 0)\n >>> 0\n Explanation: Every value of nums is 1, but nums[0] minimizes abs(i - start), which is abs(0 - 0) = 0.\n \"\"\"\n"}
{"task_id": "splitting-a-string-into-descending-consecutive-values", "prompt": "def splitString(s: str) -> bool:\n \"\"\"\n You are given a string s that consists of only digits.\n Check if we can split s into two or more non-empty substrings such that the numerical values of the substrings are in descending order and the difference between numerical values of every two adjacent substrings is equal to 1.\n \n For example, the string s = \"0090089\" can be split into [\"0090\", \"089\"] with numerical values [90,89]. The values are in descending order and adjacent values differ by 1, so this way is valid.\n Another example, the string s = \"001\" can be split into [\"0\", \"01\"], [\"00\", \"1\"], or [\"0\", \"0\", \"1\"]. However all the ways are invalid because they have numerical values [0,1], [0,1], and [0,0,1] respectively, all of which are not in descending order.\n \n Return true if it is possible to split s\u200b\u200b\u200b\u200b\u200b\u200b as described above, or false otherwise.\n A substring is a contiguous sequence of characters in a string.\n \n Example 1:\n \n >>> splitString(s = \"1234\")\n >>> false\n Explanation: There is no valid way to split s.\n \n Example 2:\n \n >>> splitString(s = \"050043\")\n >>> true\n Explanation: s can be split into [\"05\", \"004\", \"3\"] with numerical values [5,4,3].\n The values are in descending order with adjacent values differing by 1.\n \n Example 3:\n \n >>> splitString(s = \"9080701\")\n >>> false\n Explanation: There is no valid way to split s.\n \"\"\"\n"}
{"task_id": "minimum-adjacent-swaps-to-reach-the-kth-smallest-number", "prompt": "def getMinSwaps(num: str, k: int) -> int:\n \"\"\"\n You are given a string num, representing a large integer, and an integer k.\n We call some integer wonderful if it is a permutation of the digits in num and is greater in value than num. There can be many wonderful integers. However, we only care about the smallest-valued ones.\n \n For example, when num = \"5489355142\":\n \n \n The 1st smallest wonderful integer is \"5489355214\".\n The 2nd smallest wonderful integer is \"5489355241\".\n The 3rd smallest wonderful integer is \"5489355412\".\n The 4th smallest wonderful integer is \"5489355421\".\n \n \n \n Return the minimum number of adjacent digit swaps that needs to be applied to num to reach the kth smallest wonderful integer.\n The tests are generated in such a way that kth\u00a0smallest wonderful integer exists.\n \n Example 1:\n \n >>> getMinSwaps(num = \"5489355142\", k = 4)\n >>> 2\n Explanation: The 4th smallest wonderful number is \"5489355421\". To get this number:\n - Swap index 7 with index 8: \"5489355142\" -> \"5489355412\"\n - Swap index 8 with index 9: \"5489355412\" -> \"5489355421\"\n \n Example 2:\n \n >>> getMinSwaps(num = \"11112\", k = 4)\n >>> 4\n Explanation: The 4th smallest wonderful number is \"21111\". To get this number:\n - Swap index 3 with index 4: \"11112\" -> \"11121\"\n - Swap index 2 with index 3: \"11121\" -> \"11211\"\n - Swap index 1 with index 2: \"11211\" -> \"12111\"\n - Swap index 0 with index 1: \"12111\" -> \"21111\"\n \n Example 3:\n \n >>> getMinSwaps(num = \"00123\", k = 1)\n >>> 1\n Explanation: The 1st smallest wonderful number is \"00132\". To get this number:\n - Swap index 3 with index 4: \"00123\" -> \"00132\"\n \"\"\"\n"}
{"task_id": "minimum-interval-to-include-each-query", "prompt": "def minInterval(intervals: List[List[int]], queries: List[int]) -> List[int]:\n \"\"\"\n You are given a 2D integer array intervals, where intervals[i] = [lefti, righti] describes the ith interval starting at lefti and ending at righti (inclusive). The size of an interval is defined as the number of integers it contains, or more formally righti - lefti + 1.\n You are also given an integer array queries. The answer to the jth query is the size of the smallest interval i such that lefti <= queries[j] <= righti. If no such interval exists, the answer is -1.\n Return an array containing the answers to the queries.\n \n Example 1:\n \n >>> minInterval(intervals = [[1,4],[2,4],[3,6],[4,4]], queries = [2,3,4,5])\n >>> [3,3,1,4]\n Explanation: The queries are processed as follows:\n - Query = 2: The interval [2,4] is the smallest interval containing 2. The answer is 4 - 2 + 1 = 3.\n - Query = 3: The interval [2,4] is the smallest interval containing 3. The answer is 4 - 2 + 1 = 3.\n - Query = 4: The interval [4,4] is the smallest interval containing 4. The answer is 4 - 4 + 1 = 1.\n - Query = 5: The interval [3,6] is the smallest interval containing 5. The answer is 6 - 3 + 1 = 4.\n \n Example 2:\n \n >>> minInterval(intervals = [[2,3],[2,5],[1,8],[20,25]], queries = [2,19,5,22])\n >>> [2,-1,4,6]\n Explanation: The queries are processed as follows:\n - Query = 2: The interval [2,3] is the smallest interval containing 2. The answer is 3 - 2 + 1 = 2.\n - Query = 19: None of the intervals contain 19. The answer is -1.\n - Query = 5: The interval [2,5] is the smallest interval containing 5. The answer is 5 - 2 + 1 = 4.\n - Query = 22: The interval [20,25] is the smallest interval containing 22. The answer is 25 - 20 + 1 = 6.\n \"\"\"\n"}
{"task_id": "distinct-numbers-in-each-subarray", "prompt": "def distinctNumbers(nums: List[int], k: int) -> List[int]:\n \"\"\"\n You are given an integer array nums of length n and an integer k. Your task is to find the number of distinct elements in every subarray of size k within nums.\n Return an array ans such that ans[i] is the count of distinct elements in nums[i..(i + k - 1)] for each index 0 <= i < n - k.\n \n Example 1:\n \n >>> distinctNumbers(nums = [1,2,3,2,2,1,3], k = 3)\n >>> [3,2,2,2,3]\n Explanation: The number of distinct elements in each subarray goes as follows:\n - nums[0..2] = [1,2,3] so ans[0] = 3\n - nums[1..3] = [2,3,2] so ans[1] = 2\n - nums[2..4] = [3,2,2] so ans[2] = 2\n - nums[3..5] = [2,2,1] so ans[3] = 2\n - nums[4..6] = [2,1,3] so ans[4] = 3\n \n Example 2:\n \n >>> distinctNumbers(nums = [1,1,1,1,2,3,4], k = 4)\n >>> [1,2,3,4]\n Explanation: The number of distinct elements in each subarray goes as follows:\n - nums[0..3] = [1,1,1,1] so ans[0] = 1\n - nums[1..4] = [1,1,1,2] so ans[1] = 2\n - nums[2..5] = [1,1,2,3] so ans[2] = 3\n - nums[3..6] = [1,2,3,4] so ans[3] = 4\n \"\"\"\n"}
{"task_id": "maximum-population-year", "prompt": "def maximumPopulation(logs: List[List[int]]) -> int:\n \"\"\"\n You are given a 2D integer array logs where each logs[i] = [birthi, deathi] indicates the birth and death years of the ith person.\n The population of some year x is the number of people alive during that year. The ith person is counted in year x's population if x is in the inclusive range [birthi, deathi - 1]. Note that the person is not counted in the year that they die.\n Return the earliest year with the maximum population.\n \n Example 1:\n \n >>> maximumPopulation(logs = [[1993,1999],[2000,2010]])\n >>> 1993\n Explanation: The maximum population is 1, and 1993 is the earliest year with this population.\n \n Example 2:\n \n >>> maximumPopulation(logs = [[1950,1961],[1960,1971],[1970,1981]])\n >>> 1960\n Explanation:\n The maximum population is 2, and it had happened in years 1960 and 1970.\n The earlier year between them is 1960.\n \"\"\"\n"}
{"task_id": "maximum-distance-between-a-pair-of-values", "prompt": "def maxDistance(nums1: List[int], nums2: List[int]) -> int:\n \"\"\"\n You are given two non-increasing 0-indexed integer arrays nums1\u200b\u200b\u200b\u200b\u200b\u200b and nums2\u200b\u200b\u200b\u200b\u200b\u200b.\n A pair of indices (i, j), where 0 <= i < nums1.length and 0 <= j < nums2.length, is valid if both i <= j and nums1[i] <= nums2[j]. The distance of the pair is j - i\u200b\u200b\u200b\u200b.\n Return the maximum distance of any valid pair (i, j). If there are no valid pairs, return 0.\n An array arr is non-increasing if arr[i-1] >= arr[i] for every 1 <= i < arr.length.\n \n Example 1:\n \n >>> maxDistance(nums1 = [55,30,5,4,2], nums2 = [100,20,10,10,5])\n >>> 2\n Explanation: The valid pairs are (0,0), (2,2), (2,3), (2,4), (3,3), (3,4), and (4,4).\n The maximum distance is 2 with pair (2,4).\n \n Example 2:\n \n >>> maxDistance(nums1 = [2,2,2], nums2 = [10,10,1])\n >>> 1\n Explanation: The valid pairs are (0,0), (0,1), and (1,1).\n The maximum distance is 1 with pair (0,1).\n \n Example 3:\n \n >>> maxDistance(nums1 = [30,29,19,5], nums2 = [25,25,25,25,25])\n >>> 2\n Explanation: The valid pairs are (2,2), (2,3), (2,4), (3,3), and (3,4).\n The maximum distance is 2 with pair (2,4).\n \"\"\"\n"}
{"task_id": "maximum-subarray-min-product", "prompt": "def maxSumMinProduct(nums: List[int]) -> int:\n \"\"\"\n The min-product of an array is equal to the minimum value in the array multiplied by the array's sum.\n \n For example, the array [3,2,5] (minimum value is 2) has a min-product of 2 * (3+2+5) = 2 * 10 = 20.\n \n Given an array of integers nums, return the maximum min-product of any non-empty subarray of nums. Since the answer may be large, return it modulo 109 + 7.\n Note that the min-product should be maximized before performing the modulo operation. Testcases are generated such that the maximum min-product without modulo will fit in a 64-bit signed integer.\n A subarray is a contiguous part of an array.\n \n Example 1:\n \n >>> maxSumMinProduct(nums = [1,2,3,2])\n >>> 14\n Explanation: The maximum min-product is achieved with the subarray [2,3,2] (minimum value is 2).\n 2 * (2+3+2) = 2 * 7 = 14.\n \n Example 2:\n \n >>> maxSumMinProduct(nums = [2,3,3,1,2])\n >>> 18\n Explanation: The maximum min-product is achieved with the subarray [3,3] (minimum value is 3).\n 3 * (3+3) = 3 * 6 = 18.\n \n Example 3:\n \n >>> maxSumMinProduct(nums = [3,1,5,6,4,2])\n >>> 60\n Explanation: The maximum min-product is achieved with the subarray [5,6,4] (minimum value is 4).\n 4 * (5+6+4) = 4 * 15 = 60.\n \"\"\"\n"}
{"task_id": "largest-color-value-in-a-directed-graph", "prompt": "def largestPathValue(colors: str, edges: List[List[int]]) -> int:\n \"\"\"\n There is a directed graph of n colored nodes and m edges. The nodes are numbered from 0 to n - 1.\\r\n \\r\n You are given a string colors where colors[i] is a lowercase English letter representing the color of the ith node in this graph (0-indexed). You are also given a 2D array edges where edges[j] = [aj, bj] indicates that there is a directed edge from node aj to node bj.\\r\n \\r\n A valid path in the graph is a sequence of nodes x1 -> x2 -> x3 -> ... -> xk such that there is a directed edge from xi to xi+1 for every 1 <= i < k. The color value of the path is the number of nodes that are colored the most frequently occurring color along that path.\\r\n \\r\n Return the largest color value of any valid path in the given graph, or -1 if the graph contains a cycle.\\r\n \\r\n \u00a0\\r\n Example 1:\\r\n \\r\n \\r\n \\r\n \\r\n >>> largestPathValue(colors = \"abaca\", edges = [[0,1],[0,2],[2,3],[3,4]]\\r)\n >>> 3\\r\n Explanation: The path 0 -> 2 -> 3 -> 4 contains 3 nodes that are colored \"a\" (red in the above image).\\r\n \\r\n \\r\n Example 2:\\r\n \\r\n \\r\n \\r\n \\r\n >>> largestPathValue(colors = \"a\", edges = [[0,0]]\\r)\n >>> -1\\r\n Explanation: There is a cycle from 0 to 0.\\r\n \\r\n \\r\n \u00a0\\r\n \"\"\"\n"}
{"task_id": "longest-word-with-all-prefixes", "prompt": "def longestWord(words: List[str]) -> str:\n \"\"\"\n Given an array of strings words, find the longest string in words such that every prefix of it is also in words.\n \n For example, let words = [\"a\", \"app\", \"ap\"]. The string \"app\" has prefixes \"ap\" and \"a\", all of which are in words.\n \n Return the string described above. If there is more than one string with the same length, return the lexicographically smallest one, and if no string exists, return \"\".\n \n Example 1:\n \n >>> longestWord(words = [\"k\",\"ki\",\"kir\",\"kira\", \"kiran\"])\n >>> \"kiran\"\n Explanation: \"kiran\" has prefixes \"kira\", \"kir\", \"ki\", and \"k\", and all of them appear in words.\n \n Example 2:\n \n >>> longestWord(words = [\"a\", \"banana\", \"app\", \"appl\", \"ap\", \"apply\", \"apple\"])\n >>> \"apple\"\n Explanation: Both \"apple\" and \"apply\" have all their prefixes in words.\n However, \"apple\" is lexicographically smaller, so we return that.\n \n Example 3:\n \n >>> longestWord(words = [\"abc\", \"bc\", \"ab\", \"qwe\"])\n >>> \"\"\n \"\"\"\n"}
{"task_id": "sorting-the-sentence", "prompt": "def sortSentence(s: str) -> str:\n \"\"\"\n A sentence is a list of words that are separated by a single space with no leading or trailing spaces. Each word consists of lowercase and uppercase English letters.\n A sentence can be shuffled by appending the 1-indexed word position to each word then rearranging the words in the sentence.\n \n For example, the sentence \"This is a sentence\" can be shuffled as \"sentence4 a3 is2 This1\" or \"is2 sentence4 This1 a3\".\n \n Given a shuffled sentence s containing no more than 9 words, reconstruct and return the original sentence.\n \n Example 1:\n \n >>> sortSentence(s = \"is2 sentence4 This1 a3\")\n >>> \"This is a sentence\"\n Explanation: Sort the words in s to their original positions \"This1 is2 a3 sentence4\", then remove the numbers.\n \n Example 2:\n \n >>> sortSentence(s = \"Myself2 Me1 I4 and3\")\n >>> \"Me Myself and I\"\n Explanation: Sort the words in s to their original positions \"Me1 Myself2 and3 I4\", then remove the numbers.\n \"\"\"\n"}
{"task_id": "incremental-memory-leak", "prompt": "def memLeak(memory1: int, memory2: int) -> List[int]:\n \"\"\"\n You are given two integers memory1 and memory2 representing the available memory in bits on two memory sticks. There is currently a faulty program running that consumes an increasing amount of memory every second.\n At the ith second (starting from 1), i bits of memory are allocated to the stick with more available memory (or from the first memory stick if both have the same available memory). If neither stick has at least i bits of available memory, the program crashes.\n Return an array containing [crashTime, memory1crash, memory2crash], where crashTime is the time (in seconds) when the program crashed and memory1crash and memory2crash are the available bits of memory in the first and second sticks respectively.\n \n Example 1:\n \n >>> memLeak(memory1 = 2, memory2 = 2)\n >>> [3,1,0]\n Explanation: The memory is allocated as follows:\n - At the 1st second, 1 bit of memory is allocated to stick 1. The first stick now has 1 bit of available memory.\n - At the 2nd second, 2 bits of memory are allocated to stick 2. The second stick now has 0 bits of available memory.\n - At the 3rd second, the program crashes. The sticks have 1 and 0 bits available respectively.\n \n Example 2:\n \n >>> memLeak(memory1 = 8, memory2 = 11)\n >>> [6,0,4]\n Explanation: The memory is allocated as follows:\n - At the 1st second, 1 bit of memory is allocated to stick 2. The second stick now has 10 bit of available memory.\n - At the 2nd second, 2 bits of memory are allocated to stick 2. The second stick now has 8 bits of available memory.\n - At the 3rd second, 3 bits of memory are allocated to stick 1. The first stick now has 5 bits of available memory.\n - At the 4th second, 4 bits of memory are allocated to stick 2. The second stick now has 4 bits of available memory.\n - At the 5th second, 5 bits of memory are allocated to stick 1. The first stick now has 0 bits of available memory.\n - At the 6th second, the program crashes. The sticks have 0 and 4 bits available respectively.\n \"\"\"\n"}
{"task_id": "rotating-the-box", "prompt": "def rotateTheBox(boxGrid: List[List[str]]) -> List[List[str]]:\n \"\"\"\n You are given an m x n matrix of characters boxGrid representing a side-view of a box. Each cell of the box is one of the following:\n \n A stone '#'\n A stationary obstacle '*'\n Empty '.'\n \n The box is rotated 90 degrees clockwise, causing some of the stones to fall due to gravity. Each stone falls down until it lands on an obstacle, another stone, or the bottom of the box. Gravity does not affect the obstacles' positions, and the inertia from the box's rotation does not affect the stones' horizontal positions.\n It is guaranteed that each stone in boxGrid rests on an obstacle, another stone, or the bottom of the box.\n Return an n x m matrix representing the box after the rotation described above.\n \n Example 1:\n \n \n >>> rotateTheBox(boxGrid = [[\"#\",\".\",\"#\"]])\n >>> [[\".\"],\n \u00a0 [\"#\"],\n \u00a0 [\"#\"]]\n \n Example 2:\n \n \n \u00a0 [\"#\",\"#\",\"*\",\".\"]]\n >>> rotateTheBox(boxGrid = [[\"#\",\".\",\"*\",\".\"],)\n >>> [[\"#\",\".\"],\n \u00a0 [\"#\",\"#\"],\n \u00a0 [\"*\",\"*\"],\n \u00a0 [\".\",\".\"]]\n \n Example 3:\n \n \n \u00a0 [\"#\",\"#\",\"#\",\"*\",\".\",\".\"],\n \u00a0 [\"#\",\"#\",\"#\",\".\",\"#\",\".\"]]\n >>> rotateTheBox(boxGrid = [[\"#\",\"#\",\"*\",\".\",\"*\",\".\"],)\n >>> [[\".\",\"#\",\"#\"],\n \u00a0 [\".\",\"#\",\"#\"],\n \u00a0 [\"#\",\"#\",\"*\"],\n \u00a0 [\"#\",\"*\",\".\"],\n \u00a0 [\"#\",\".\",\"*\"],\n \u00a0 [\"#\",\".\",\".\"]]\n \"\"\"\n"}
{"task_id": "sum-of-floored-pairs", "prompt": "def sumOfFlooredPairs(nums: List[int]) -> int:\n \"\"\"\n Given an integer array nums, return the sum of floor(nums[i] / nums[j]) for all pairs of indices 0 <= i, j < nums.length in the array. Since the answer may be too large, return it modulo 109 + 7.\n The floor() function returns the integer part of the division.\n \n Example 1:\n \n >>> sumOfFlooredPairs(nums = [2,5,9])\n >>> 10\n Explanation:\n floor(2 / 5) = floor(2 / 9) = floor(5 / 9) = 0\n floor(2 / 2) = floor(5 / 5) = floor(9 / 9) = 1\n floor(5 / 2) = 2\n floor(9 / 2) = 4\n floor(9 / 5) = 1\n We calculate the floor of the division for every pair of indices in the array then sum them up.\n \n Example 2:\n \n >>> sumOfFlooredPairs(nums = [7,7,7,7,7,7,7])\n >>> 49\n \"\"\"\n"}
{"task_id": "sum-of-all-subset-xor-totals", "prompt": "def subsetXORSum(nums: List[int]) -> int:\n \"\"\"\n The XOR total of an array is defined as the bitwise XOR of all its elements, or 0 if the array is empty.\n \n For example, the XOR total of the array [2,5,6] is 2 XOR 5 XOR 6 = 1.\n \n Given an array nums, return the sum of all XOR totals for every subset of nums.\n Note: Subsets with the same elements should be counted multiple times.\n An array a is a subset of an array b if a can be obtained from b by deleting some (possibly zero) elements of b.\n \n Example 1:\n \n >>> subsetXORSum(nums = [1,3])\n >>> 6\n Explanation: The 4 subsets of [1,3] are:\n - The empty subset has an XOR total of 0.\n - [1] has an XOR total of 1.\n - [3] has an XOR total of 3.\n - [1,3] has an XOR total of 1 XOR 3 = 2.\n 0 + 1 + 3 + 2 = 6\n \n Example 2:\n \n >>> subsetXORSum(nums = [5,1,6])\n >>> 28\n Explanation: The 8 subsets of [5,1,6] are:\n - The empty subset has an XOR total of 0.\n - [5] has an XOR total of 5.\n - [1] has an XOR total of 1.\n - [6] has an XOR total of 6.\n - [5,1] has an XOR total of 5 XOR 1 = 4.\n - [5,6] has an XOR total of 5 XOR 6 = 3.\n - [1,6] has an XOR total of 1 XOR 6 = 7.\n - [5,1,6] has an XOR total of 5 XOR 1 XOR 6 = 2.\n 0 + 5 + 1 + 6 + 4 + 3 + 7 + 2 = 28\n \n Example 3:\n \n >>> subsetXORSum(nums = [3,4,5,6,7,8])\n >>> 480\n Explanation: The sum of all XOR totals for every subset is 480.\n \"\"\"\n"}
{"task_id": "minimum-number-of-swaps-to-make-the-binary-string-alternating", "prompt": "def minSwaps(s: str) -> int:\n \"\"\"\n Given a binary string s, return the minimum number of character swaps to make it alternating, or -1 if it is impossible.\n The string is called alternating if no two adjacent characters are equal. For example, the strings \"010\" and \"1010\" are alternating, while the string \"0100\" is not.\n Any two characters may be swapped, even if they are\u00a0not adjacent.\n \n Example 1:\n \n >>> minSwaps(s = \"111000\")\n >>> 1\n Explanation: Swap positions 1 and 4: \"111000\" -> \"101010\"\n The string is now alternating.\n \n Example 2:\n \n >>> minSwaps(s = \"010\")\n >>> 0\n Explanation: The string is already alternating, no swaps are needed.\n \n Example 3:\n \n >>> minSwaps(s = \"1110\")\n >>> -1\n \"\"\"\n"}
{"task_id": "number-of-ways-to-rearrange-sticks-with-k-sticks-visible", "prompt": "def rearrangeSticks(n: int, k: int) -> int:\n \"\"\"\n There are n uniquely-sized sticks whose lengths are integers from 1 to n. You want to arrange the sticks such that exactly k\u00a0sticks are visible from the left. A stick\u00a0is visible from the left if there are no longer\u00a0sticks to the left of it.\n \n For example, if the sticks are arranged [1,3,2,5,4], then the sticks with lengths 1, 3, and 5 are visible from the left.\n \n Given n and k, return the number of such arrangements. Since the answer may be large, return it modulo 109 + 7.\n \n Example 1:\n \n >>> rearrangeSticks(n = 3, k = 2)\n >>> 3\n Explanation: [1,3,2], [2,3,1], and [2,1,3] are the only arrangements such that exactly 2 sticks are visible.\n The visible sticks are underlined.\n \n Example 2:\n \n >>> rearrangeSticks(n = 5, k = 5)\n >>> 1\n Explanation: [1,2,3,4,5] is the only arrangement such that all 5 sticks are visible.\n The visible sticks are underlined.\n \n Example 3:\n \n >>> rearrangeSticks(n = 20, k = 11)\n >>> 647427950\n Explanation: There are 647427950 (mod 109 + 7) ways to rearrange the sticks such that exactly 11 sticks are visible.\n \"\"\"\n"}
{"task_id": "product-of-two-run-length-encoded-arrays", "prompt": "def findRLEArray(encoded1: List[List[int]], encoded2: List[List[int]]) -> List[List[int]]:\n \"\"\"\n Run-length encoding is a compression algorithm that allows for an integer array nums with many segments of consecutive repeated numbers to be represented by a (generally smaller) 2D array encoded. Each encoded[i] = [vali, freqi] describes the ith segment of repeated numbers in nums where vali is the value that is repeated freqi times.\n \n For example, nums = [1,1,1,2,2,2,2,2] is represented by the run-length encoded array encoded = [[1,3],[2,5]]. Another way to read this is \"three 1's followed by five 2's\".\n \n The product of two run-length encoded arrays encoded1 and encoded2 can be calculated using the following steps:\n \n Expand both encoded1 and encoded2 into the full arrays nums1 and nums2 respectively.\n Create a new array prodNums of length nums1.length and set prodNums[i] = nums1[i] * nums2[i].\n Compress prodNums into a run-length encoded array and return it.\n \n You are given two run-length encoded arrays encoded1 and encoded2 representing full arrays nums1 and nums2 respectively. Both nums1 and nums2 have the same length. Each encoded1[i] = [vali, freqi] describes the ith segment of nums1, and each encoded2[j] = [valj, freqj] describes the jth segment of nums2.\n Return the product of encoded1 and encoded2.\n Note: Compression should be done such that the run-length encoded array has the minimum possible length.\n \n Example 1:\n \n >>> findRLEArray(encoded1 = [[1,3],[2,3]], encoded2 = [[6,3],[3,3]])\n >>> [[6,6]]\n Explanation: encoded1 expands to [1,1,1,2,2,2] and encoded2 expands to [6,6,6,3,3,3].\n prodNums = [6,6,6,6,6,6], which is compressed into the run-length encoded array [[6,6]].\n \n Example 2:\n \n >>> findRLEArray(encoded1 = [[1,3],[2,1],[3,2]], encoded2 = [[2,3],[3,3]])\n >>> [[2,3],[6,1],[9,2]]\n Explanation: encoded1 expands to [1,1,1,2,3,3] and encoded2 expands to [2,2,2,3,3,3].\n prodNums = [2,2,2,6,9,9], which is compressed into the run-length encoded array [[2,3],[6,1],[9,2]].\n \"\"\"\n"}
{"task_id": "longer-contiguous-segments-of-ones-than-zeros", "prompt": "def checkZeroOnes(s: str) -> bool:\n \"\"\"\n Given a binary string s, return true if the longest contiguous segment of 1's is strictly longer than the longest contiguous segment of 0's in s, or return false otherwise.\n \n For example, in s = \"110100010\" the longest continuous segment of 1s has length 2, and the longest continuous segment of 0s has length 3.\n \n Note that if there are no 0's, then the longest continuous segment of 0's is considered to have a length 0. The same applies if there is no 1's.\n \n Example 1:\n \n >>> checkZeroOnes(s = \"1101\")\n >>> true\n Explanation:\n The longest contiguous segment of 1s has length 2: \"1101\"\n The longest contiguous segment of 0s has length 1: \"1101\"\n The segment of 1s is longer, so return true.\n \n Example 2:\n \n >>> checkZeroOnes(s = \"111000\")\n >>> false\n Explanation:\n The longest contiguous segment of 1s has length 3: \"111000\"\n The longest contiguous segment of 0s has length 3: \"111000\"\n The segment of 1s is not longer, so return false.\n \n Example 3:\n \n >>> checkZeroOnes(s = \"110100010\")\n >>> false\n Explanation:\n The longest contiguous segment of 1s has length 2: \"110100010\"\n The longest contiguous segment of 0s has length 3: \"110100010\"\n The segment of 1s is not longer, so return false.\n \"\"\"\n"}
{"task_id": "minimum-speed-to-arrive-on-time", "prompt": "def minSpeedOnTime(dist: List[int], hour: float) -> int:\n \"\"\"\n You are given a floating-point number hour, representing the amount of time you have to reach the office. To commute to the office, you must take n trains in sequential order. You are also given an integer array dist of length n, where dist[i] describes the distance (in kilometers) of the ith train ride.\n Each train can only depart at an integer hour, so you may need to wait in between each train ride.\n \n For example, if the 1st train ride takes 1.5 hours, you must wait for an additional 0.5 hours before you can depart on the 2nd train ride at the 2 hour mark.\n \n Return the minimum positive integer speed (in kilometers per hour) that all the trains must travel at for you to reach the office on time, or -1 if it is impossible to be on time.\n Tests are generated such that the answer will not exceed 107 and hour will have at most two digits after the decimal point.\n \n Example 1:\n \n >>> minSpeedOnTime(dist = [1,3,2], hour = 6)\n >>> 1\n Explanation: At speed 1:\n - The first train ride takes 1/1 = 1 hour.\n - Since we are already at an integer hour, we depart immediately at the 1 hour mark. The second train takes 3/1 = 3 hours.\n - Since we are already at an integer hour, we depart immediately at the 4 hour mark. The third train takes 2/1 = 2 hours.\n - You will arrive at exactly the 6 hour mark.\n \n Example 2:\n \n >>> minSpeedOnTime(dist = [1,3,2], hour = 2.7)\n >>> 3\n Explanation: At speed 3:\n - The first train ride takes 1/3 = 0.33333 hours.\n - Since we are not at an integer hour, we wait until the 1 hour mark to depart. The second train ride takes 3/3 = 1 hour.\n - Since we are already at an integer hour, we depart immediately at the 2 hour mark. The third train takes 2/3 = 0.66667 hours.\n - You will arrive at the 2.66667 hour mark.\n \n Example 3:\n \n >>> minSpeedOnTime(dist = [1,3,2], hour = 1.9)\n >>> -1\n Explanation: It is impossible because the earliest the third train can depart is at the 2 hour mark.\n \"\"\"\n"}
{"task_id": "jump-game-vii", "prompt": "def canReach(s: str, minJump: int, maxJump: int) -> bool:\n \"\"\"\n You are given a 0-indexed binary string s and two integers minJump and maxJump. In the beginning, you are standing at index 0, which is equal to '0'. You can move from index i to index j if the following conditions are fulfilled:\n \n i + minJump <= j <= min(i + maxJump, s.length - 1), and\n s[j] == '0'.\n \n Return true if you can reach index s.length - 1 in s, or false otherwise.\n \n Example 1:\n \n >>> canReach(s = \"011010\", minJump = 2, maxJump = 3)\n >>> true\n Explanation:\n In the first step, move from index 0 to index 3.\n In the second step, move from index 3 to index 5.\n \n Example 2:\n \n >>> canReach(s = \"01101110\", minJump = 2, maxJump = 3)\n >>> false\n \"\"\"\n"}
{"task_id": "stone-game-viii", "prompt": "def stoneGameVIII(stones: List[int]) -> int:\n \"\"\"\n Alice and Bob take turns playing a game, with Alice starting first.\\r\n \\r\n There are n stones arranged in a row. On each player's turn, while the number of stones is more than one, they will do the following:\\r\n \\r\n \\r\n \tChoose an integer x > 1, and remove the leftmost x stones from the row.\\r\n \tAdd the sum of the removed stones' values to the player's score.\\r\n \tPlace a new stone, whose value is equal to that sum, on the left side of the row.\\r\n \\r\n \\r\n The game stops when only one stone is left in the row.\\r\n \\r\n The score difference between Alice and Bob is (Alice's score - Bob's score). Alice's goal is to maximize the score difference, and Bob's goal is the minimize the score difference.\\r\n \\r\n Given an integer array stones of length n where stones[i] represents the value of the ith stone from the left, return the score difference between Alice and Bob if they both play optimally.\\r\n \\r\n \u00a0\\r\n Example 1:\\r\n \\r\n \\r\n >>> stoneGameVIII(stones = [-1,2,-3,4,-5]\\r)\n >>> 5\\r\n Explanation:\\r\n - Alice removes the first 4 stones, adds (-1) + 2 + (-3) + 4 = 2 to her score, and places a stone of\\r\n value 2 on the left. stones = [2,-5].\\r\n - Bob removes the first 2 stones, adds 2 + (-5) = -3 to his score, and places a stone of value -3 on\\r\n the left. stones = [-3].\\r\n The difference between their scores is 2 - (-3) = 5.\\r\n \\r\n \\r\n Example 2:\\r\n \\r\n \\r\n >>> stoneGameVIII(stones = [7,-6,5,10,5,-2,-6]\\r)\n >>> 13\\r\n Explanation:\\r\n - Alice removes all stones, adds 7 + (-6) + 5 + 10 + 5 + (-2) + (-6) = 13 to her score, and places a\\r\n stone of value 13 on the left. stones = [13].\\r\n The difference between their scores is 13 - 0 = 13.\\r\n \\r\n \\r\n Example 3:\\r\n \\r\n \\r\n >>> stoneGameVIII(stones = [-10,-12]\\r)\n >>> -22\\r\n Explanation:\\r\n - Alice can only make one move, which is to remove both stones. She adds (-10) + (-12) = -22 to her\\r\n score and places a stone of value -22 on the left. stones = [-22].\\r\n The difference between their scores is (-22) - 0 = -22.\\r\n \\r\n \\r\n \u00a0\\r\n \"\"\"\n"}
{"task_id": "minimize-product-sum-of-two-arrays", "prompt": "def minProductSum(nums1: List[int], nums2: List[int]) -> int:\n \"\"\"\n The product sum of two equal-length arrays a and b is equal to the sum of a[i] * b[i] for all 0 <= i < a.length (0-indexed).\\r\n \\r\n \\r\n \tFor example, if a = [1,2,3,4] and b = [5,2,3,1], the product sum would be 1*5 + 2*2 + 3*3 + 4*1 = 22.\\r\n \\r\n \\r\n Given two arrays nums1 and nums2 of length n, return the minimum product sum if you are allowed to rearrange the order of the elements in nums1.\u00a0\\r\n \\r\n \u00a0\\r\n Example 1:\\r\n \\r\n \\r\n >>> minProductSum(nums1 = [5,3,4,2], nums2 = [4,2,2,5]\\r)\n >>> 40\\r\n Explanation:\u00a0We can rearrange nums1 to become [3,5,4,2]. The product sum of [3,5,4,2] and [4,2,2,5] is 3*4 + 5*2 + 4*2 + 2*5 = 40.\\r\n \\r\n \\r\n Example 2:\\r\n \\r\n \\r\n >>> minProductSum(nums1 = [2,1,4,5,7], nums2 = [3,2,4,8,6]\\r)\n >>> 65\\r\n Explanation: We can rearrange nums1 to become [5,7,4,1,2]. The product sum of [5,7,4,1,2] and [3,2,4,8,6] is 5*3 + 7*2 + 4*4 + 1*8 + 2*6 = 65.\\r\n \\r\n \\r\n \u00a0\\r\n \"\"\"\n"}
{"task_id": "substrings-of-size-three-with-distinct-characters", "prompt": "def countGoodSubstrings(s: str) -> int:\n \"\"\"\n A string is good if there are no repeated characters.\n Given a string s\u200b\u200b\u200b\u200b\u200b, return the number of good substrings of length three in s\u200b\u200b\u200b\u200b\u200b\u200b.\n Note that if there are multiple occurrences of the same substring, every occurrence should be counted.\n A substring is a contiguous sequence of characters in a string.\n \n Example 1:\n \n >>> countGoodSubstrings(s = \"xyzzaz\")\n >>> 1\n Explanation: There are 4 substrings of size 3: \"xyz\", \"yzz\", \"zza\", and \"zaz\".\n The only good substring of length 3 is \"xyz\".\n \n Example 2:\n \n >>> countGoodSubstrings(s = \"aababcabc\")\n >>> 4\n Explanation: There are 7 substrings of size 3: \"aab\", \"aba\", \"bab\", \"abc\", \"bca\", \"cab\", and \"abc\".\n The good substrings are \"abc\", \"bca\", \"cab\", and \"abc\".\n \"\"\"\n"}
{"task_id": "minimize-maximum-pair-sum-in-array", "prompt": "def minPairSum(nums: List[int]) -> int:\n \"\"\"\n The pair sum of a pair (a,b) is equal to a + b. The maximum pair sum is the largest pair sum in a list of pairs.\\r\n \\r\n \\r\n \tFor example, if we have pairs (1,5), (2,3), and (4,4), the maximum pair sum would be max(1+5, 2+3, 4+4) = max(6, 5, 8) = 8.\\r\n \\r\n \\r\n Given an array nums of even length n, pair up the elements of nums into n / 2 pairs such that:\\r\n \\r\n \\r\n \tEach element of nums is in exactly one pair, and\\r\n \tThe maximum pair sum is minimized.\\r\n \\r\n \\r\n Return the minimized maximum pair sum after optimally pairing up the elements.\\r\n \\r\n \u00a0\\r\n Example 1:\\r\n \\r\n \\r\n >>> minPairSum(nums = [3,5,2,3]\\r)\n >>> 7\\r\n Explanation: The elements can be paired up into pairs (3,3) and (5,2).\\r\n The maximum pair sum is max(3+3, 5+2) = max(6, 7) = 7.\\r\n \\r\n \\r\n Example 2:\\r\n \\r\n \\r\n >>> minPairSum(nums = [3,5,4,2,4,6]\\r)\n >>> 8\\r\n Explanation: The elements can be paired up into pairs (3,5), (4,4), and (6,2).\\r\n The maximum pair sum is max(3+5, 4+4, 6+2) = max(8, 8, 8) = 8.\\r\n \\r\n \\r\n \u00a0\\r\n \"\"\"\n"}
{"task_id": "get-biggest-three-rhombus-sums-in-a-grid", "prompt": "def getBiggestThree(grid: List[List[int]]) -> List[int]:\n \"\"\"\n You are given an m x n integer matrix grid\u200b\u200b\u200b.\n A rhombus sum is the sum of the elements that form the border of a regular rhombus shape in grid\u200b\u200b\u200b. The rhombus must have the shape of a square rotated 45 degrees with each of the corners centered in a grid cell. Below is an image of four valid rhombus shapes with the corresponding colored cells that should be included in each rhombus sum:\n \n Note that the rhombus can have an area of 0, which is depicted by the purple rhombus in the bottom right corner.\n Return the biggest three distinct rhombus sums in the grid in descending order. If there are less than three distinct values, return all of them.\n \n Example 1:\n \n \n >>> getBiggestThree(grid = [[3,4,5,1,3],[3,3,4,2,3],[20,30,200,40,10],[1,5,5,4,1],[4,3,2,2,5]])\n >>> [228,216,211]\n Explanation: The rhombus shapes for the three biggest distinct rhombus sums are depicted above.\n - Blue: 20 + 3 + 200 + 5 = 228\n - Red: 200 + 2 + 10 + 4 = 216\n - Green: 5 + 200 + 4 + 2 = 211\n \n Example 2:\n \n \n >>> getBiggestThree(grid = [[1,2,3],[4,5,6],[7,8,9]])\n >>> [20,9,8]\n Explanation: The rhombus shapes for the three biggest distinct rhombus sums are depicted above.\n - Blue: 4 + 2 + 6 + 8 = 20\n - Red: 9 (area 0 rhombus in the bottom right corner)\n - Green: 8 (area 0 rhombus in the bottom middle)\n \n Example 3:\n \n >>> getBiggestThree(grid = [[7,7,7]])\n >>> [7]\n Explanation: All three possible rhombus sums are the same, so return [7].\n \"\"\"\n"}
{"task_id": "minimum-xor-sum-of-two-arrays", "prompt": "def minimumXORSum(nums1: List[int], nums2: List[int]) -> int:\n \"\"\"\n You are given two integer arrays nums1 and nums2 of length n.\n The XOR sum of the two integer arrays is (nums1[0] XOR nums2[0]) + (nums1[1] XOR nums2[1]) + ... + (nums1[n - 1] XOR nums2[n - 1]) (0-indexed).\n \n For example, the XOR sum of [1,2,3] and [3,2,1] is equal to (1 XOR 3) + (2 XOR 2) + (3 XOR 1) = 2 + 0 + 2 = 4.\n \n Rearrange the elements of nums2 such that the resulting XOR sum is minimized.\n Return the XOR sum after the rearrangement.\n \n Example 1:\n \n >>> minimumXORSum(nums1 = [1,2], nums2 = [2,3])\n >>> 2\n Explanation: Rearrange nums2 so that it becomes [3,2].\n The XOR sum is (1 XOR 3) + (2 XOR 2) = 2 + 0 = 2.\n Example 2:\n \n >>> minimumXORSum(nums1 = [1,0,3], nums2 = [5,3,4])\n >>> 8\n Explanation: Rearrange nums2 so that it becomes [5,4,3].\n The XOR sum is (1 XOR 5) + (0 XOR 4) + (3 XOR 3) = 4 + 4 + 0 = 8.\n \"\"\"\n"}
{"task_id": "check-if-word-equals-summation-of-two-words", "prompt": "def isSumEqual(firstWord: str, secondWord: str, targetWord: str) -> bool:\n \"\"\"\n The letter value of a letter is its position in the alphabet starting from 0 (i.e. 'a' -> 0, 'b' -> 1, 'c' -> 2, etc.).\n The numerical value of some string of lowercase English letters s is the concatenation of the letter values of each letter in s, which is then converted into an integer.\n \n For example, if s = \"acb\", we concatenate each letter's letter value, resulting in \"021\". After converting it, we get 21.\n \n You are given three strings firstWord, secondWord, and targetWord, each consisting of lowercase English letters 'a' through 'j' inclusive.\n Return true if the summation of the numerical values of firstWord and secondWord equals the numerical value of targetWord, or false otherwise.\n \n Example 1:\n \n >>> isSumEqual(firstWord = \"acb\", secondWord = \"cba\", targetWord = \"cdb\")\n >>> true\n Explanation:\n The numerical value of firstWord is \"acb\" -> \"021\" -> 21.\n The numerical value of secondWord is \"cba\" -> \"210\" -> 210.\n The numerical value of targetWord is \"cdb\" -> \"231\" -> 231.\n We return true because 21 + 210 == 231.\n \n Example 2:\n \n >>> isSumEqual(firstWord = \"aaa\", secondWord = \"a\", targetWord = \"aab\")\n >>> false\n Explanation:\n The numerical value of firstWord is \"aaa\" -> \"000\" -> 0.\n The numerical value of secondWord is \"a\" -> \"0\" -> 0.\n The numerical value of targetWord is \"aab\" -> \"001\" -> 1.\n We return false because 0 + 0 != 1.\n \n Example 3:\n \n >>> isSumEqual(firstWord = \"aaa\", secondWord = \"a\", targetWord = \"aaaa\")\n >>> true\n Explanation:\n The numerical value of firstWord is \"aaa\" -> \"000\" -> 0.\n The numerical value of secondWord is \"a\" -> \"0\" -> 0.\n The numerical value of targetWord is \"aaaa\" -> \"0000\" -> 0.\n We return true because 0 + 0 == 0.\n \"\"\"\n"}
{"task_id": "maximum-value-after-insertion", "prompt": "def maxValue(n: str, x: int) -> str:\n \"\"\"\n You are given a very large integer n, represented as a string,\u200b\u200b\u200b\u200b\u200b\u200b and an integer digit x. The digits in n and the digit x are in the inclusive range [1, 9], and n may represent a negative number.\n You want to maximize n's numerical value by inserting x anywhere in the decimal representation of n\u200b\u200b\u200b\u200b\u200b\u200b. You cannot insert x to the left of the negative sign.\n \n For example, if n = 73 and x = 6, it would be best to insert it between 7 and 3, making n = 763.\n If n = -55 and x = 2, it would be best to insert it before the first 5, making n = -255.\n \n Return a string representing the maximum value of n\u200b\u200b\u200b\u200b\u200b\u200b after the insertion.\n \n Example 1:\n \n >>> maxValue(n = \"99\", x = 9)\n >>> \"999\"\n Explanation: The result is the same regardless of where you insert 9.\n \n Example 2:\n \n >>> maxValue(n = \"-13\", x = 2)\n >>> \"-123\"\n Explanation: You can make n one of {-213, -123, -132}, and the largest of those three is -123.\n \"\"\"\n"}
{"task_id": "process-tasks-using-servers", "prompt": "def assignTasks(servers: List[int], tasks: List[int]) -> List[int]:\n \"\"\"\n You are given two 0-indexed integer arrays servers and tasks of lengths n\u200b\u200b\u200b\u200b\u200b\u200b and m\u200b\u200b\u200b\u200b\u200b\u200b respectively. servers[i] is the weight of the i\u200b\u200b\u200b\u200b\u200b\u200bth\u200b\u200b\u200b\u200b server, and tasks[j] is the time needed to process the j\u200b\u200b\u200b\u200b\u200b\u200bth\u200b\u200b\u200b\u200b task in seconds.\n Tasks are assigned to the servers using a task queue. Initially, all servers are free, and the queue is empty.\n At second j, the jth task is inserted into the queue (starting with the 0th task being inserted at second 0). As long as there are free servers and the queue is not empty, the task in the front of the queue will be assigned to a free server with the smallest weight, and in case of a tie, it is assigned to a free server with the smallest index.\n If there are no free servers and the queue is not empty, we wait until a server becomes free and immediately assign the next task. If multiple servers become free at the same time, then multiple tasks from the queue will be assigned in order of insertion following the weight and index priorities above.\n A server that is assigned task j at second t will be free again at second t + tasks[j].\n Build an array ans\u200b\u200b\u200b\u200b of length m, where ans[j] is the index of the server the j\u200b\u200b\u200b\u200b\u200b\u200bth task will be assigned to.\n Return the array ans\u200b\u200b\u200b\u200b.\n \n Example 1:\n \n >>> assignTasks(servers = [3,3,2], tasks = [1,2,3,2,1,2])\n >>> [2,2,0,2,1,2]\n Explanation: Events in chronological order go as follows:\n - At second 0, task 0 is added and processed using server 2 until second 1.\n - At second 1, server 2 becomes free. Task 1 is added and processed using server 2 until second 3.\n - At second 2, task 2 is added and processed using server 0 until second 5.\n - At second 3, server 2 becomes free. Task 3 is added and processed using server 2 until second 5.\n - At second 4, task 4 is added and processed using server 1 until second 5.\n - At second 5, all servers become free. Task 5 is added and processed using server 2 until second 7.\n Example 2:\n \n >>> assignTasks(servers = [5,1,4,3,2], tasks = [2,1,2,4,5,2,1])\n >>> [1,4,1,4,1,3,2]\n Explanation: Events in chronological order go as follows:\n - At second 0, task 0 is added and processed using server 1 until second 2.\n - At second 1, task 1 is added and processed using server 4 until second 2.\n - At second 2, servers 1 and 4 become free. Task 2 is added and processed using server 1 until second 4.\n - At second 3, task 3 is added and processed using server 4 until second 7.\n - At second 4, server 1 becomes free. Task 4 is added and processed using server 1 until second 9.\n - At second 5, task 5 is added and processed using server 3 until second 7.\n - At second 6, task 6 is added and processed using server 2 until second 7.\n \"\"\"\n"}
{"task_id": "minimum-skips-to-arrive-at-meeting-on-time", "prompt": "def minSkips(dist: List[int], speed: int, hoursBefore: int) -> int:\n \"\"\"\n You are given an integer hoursBefore, the number of hours you have to travel to your meeting. To arrive at your meeting, you have to travel through n roads. The road lengths are given as an integer array dist of length n, where dist[i] describes the length of the ith road in kilometers. In addition, you are given an integer speed, which is the speed (in km/h) you will travel at.\n After you travel road i, you must rest and wait for the next integer hour before you can begin traveling on the next road. Note that you do not have to rest after traveling the last road because you are already at the meeting.\n \n For example, if traveling a road takes 1.4 hours, you must wait until the 2 hour mark before traveling the next road. If traveling a road takes exactly\u00a02\u00a0hours, you do not need to wait.\n \n However, you are allowed to skip some rests to be able to arrive on time, meaning you do not need to wait for the next integer hour. Note that this means you may finish traveling future roads at different hour marks.\n \n For example, suppose traveling the first road takes 1.4 hours and traveling the second road takes 0.6 hours. Skipping the rest after the first road will mean you finish traveling the second road right at the 2 hour mark, letting you start traveling the third road immediately.\n \n Return the minimum number of skips required to arrive at the meeting on time, or -1 if it is impossible.\n \n Example 1:\n \n >>> minSkips(dist = [1,3,2], speed = 4, hoursBefore = 2)\n >>> 1\n Explanation:\n Without skipping any rests, you will arrive in (1/4 + 3/4) + (3/4 + 1/4) + (2/4) = 2.5 hours.\n You can skip the first rest to arrive in ((1/4 + 0) + (3/4 + 0)) + (2/4) = 1.5 hours.\n Note that the second rest is shortened because you finish traveling the second road at an integer hour due to skipping the first rest.\n \n Example 2:\n \n >>> minSkips(dist = [7,3,5,5], speed = 2, hoursBefore = 10)\n >>> 2\n Explanation:\n Without skipping any rests, you will arrive in (7/2 + 1/2) + (3/2 + 1/2) + (5/2 + 1/2) + (5/2) = 11.5 hours.\n You can skip the first and third rest to arrive in ((7/2 + 0) + (3/2 + 0)) + ((5/2 + 0) + (5/2)) = 10 hours.\n \n Example 3:\n \n >>> minSkips(dist = [7,3,5,5], speed = 1, hoursBefore = 10)\n >>> -1\n Explanation: It is impossible to arrive at the meeting on time even if you skip all the rests.\n \"\"\"\n"}
{"task_id": "egg-drop-with-2-eggs-and-n-floors", "prompt": "def twoEggDrop(n: int) -> int:\n \"\"\"\n You are given two identical eggs and you have access to a building with n floors labeled from 1 to n.\n You know that there exists a floor f where 0 <= f <= n such that any egg dropped at a floor higher than f will break, and any egg dropped at or below floor f will not break.\n In each move, you may take an unbroken egg and drop it from any floor x (where 1 <= x <= n). If the egg breaks, you can no longer use it. However, if the egg does not break, you may reuse it in future moves.\n Return the minimum number of moves that you need to determine with certainty what the value of f is.\n \n Example 1:\n \n >>> twoEggDrop(n = 2)\n >>> 2\n Explanation: We can drop the first egg from floor 1 and the second egg from floor 2.\n If the first egg breaks, we know that f = 0.\n If the second egg breaks but the first egg didn't, we know that f = 1.\n Otherwise, if both eggs survive, we know that f = 2.\n \n Example 2:\n \n >>> twoEggDrop(n = 100)\n >>> 14\n Explanation: One optimal strategy is:\n - Drop the 1st egg at floor 9. If it breaks, we know f is between 0 and 8. Drop the 2nd egg starting from floor 1 and going up one at a time to find f within 8 more drops. Total drops is 1 + 8 = 9.\n - If the 1st egg does not break, drop the 1st egg again at floor 22. If it breaks, we know f is between 9 and 21. Drop the 2nd egg starting from floor 10 and going up one at a time to find f within 12 more drops. Total drops is 2 + 12 = 14.\n - If the 1st egg does not break again, follow a similar process dropping the 1st egg from floors 34, 45, 55, 64, 72, 79, 85, 90, 94, 97, 99, and 100.\n Regardless of the outcome, it takes at most 14 drops to determine f.\n \"\"\"\n"}
{"task_id": "count-pairs-in-two-arrays", "prompt": "def countPairs(nums1: List[int], nums2: List[int]) -> int:\n \"\"\"\n Given two integer arrays nums1 and nums2 of length n, count the pairs of indices (i, j) such that i < j and nums1[i] + nums1[j] > nums2[i] + nums2[j].\n Return the number of pairs satisfying the condition.\n \n Example 1:\n \n >>> countPairs(nums1 = [2,1,2,1], nums2 = [1,2,1,2])\n >>> 1\n Explanation: The pairs satisfying the condition are:\n - (0, 2) where 2 + 2 > 1 + 1.\n Example 2:\n \n >>> countPairs(nums1 = [1,10,6,2], nums2 = [1,4,1,5])\n >>> 5\n Explanation: The pairs satisfying the condition are:\n - (0, 1) where 1 + 10 > 1 + 4.\n - (0, 2) where 1 + 6 > 1 + 1.\n - (1, 2) where 10 + 6 > 4 + 1.\n - (1, 3) where 10 + 2 > 4 + 5.\n - (2, 3) where 6 + 2 > 1 + 5.\n \"\"\"\n"}
{"task_id": "determine-whether-matrix-can-be-obtained-by-rotation", "prompt": "def findRotation(mat: List[List[int]], target: List[List[int]]) -> bool:\n \"\"\"\n Given two n x n binary matrices mat and target, return true if it is possible to make mat equal to target by rotating mat in 90-degree increments, or false otherwise.\n \n Example 1:\n \n \n >>> findRotation(mat = [[0,1],[1,0]], target = [[1,0],[0,1]])\n >>> true\n Explanation: We can rotate mat 90 degrees clockwise to make mat equal target.\n \n Example 2:\n \n \n >>> findRotation(mat = [[0,1],[1,1]], target = [[1,0],[0,1]])\n >>> false\n Explanation: It is impossible to make mat equal to target by rotating mat.\n \n Example 3:\n \n \n >>> findRotation(mat = [[0,0,0],[0,1,0],[1,1,1]], target = [[1,1,1],[0,1,0],[0,0,0]])\n >>> true\n Explanation: We can rotate mat 90 degrees clockwise two times to make mat equal target.\n \"\"\"\n"}
{"task_id": "reduction-operations-to-make-the-array-elements-equal", "prompt": "def reductionOperations(nums: List[int]) -> int:\n \"\"\"\n Given an integer array nums, your goal is to make all elements in nums equal. To complete one operation, follow these steps:\n \n Find the largest value in nums. Let its index be i (0-indexed) and its value be largest. If there are multiple elements with the largest value, pick the smallest i.\n Find the next largest value in nums strictly smaller than largest. Let its value be nextLargest.\n Reduce nums[i] to nextLargest.\n \n Return the number of operations to make all elements in nums equal.\n \n Example 1:\n \n >>> reductionOperations(nums = [5,1,3])\n >>> 3\n Explanation:\u00a0It takes 3 operations to make all elements in nums equal:\n 1. largest = 5 at index 0. nextLargest = 3. Reduce nums[0] to 3. nums = [3,1,3].\n 2. largest = 3 at index 0. nextLargest = 1. Reduce nums[0] to 1. nums = [1,1,3].\n 3. largest = 3 at index 2. nextLargest = 1. Reduce nums[2] to 1. nums = [1,1,1].\n \n Example 2:\n \n >>> reductionOperations(nums = [1,1,1])\n >>> 0\n Explanation:\u00a0All elements in nums are already equal.\n \n Example 3:\n \n >>> reductionOperations(nums = [1,1,2,2,3])\n >>> 4\n Explanation:\u00a0It takes 4 operations to make all elements in nums equal:\n 1. largest = 3 at index 4. nextLargest = 2. Reduce nums[4] to 2. nums = [1,1,2,2,2].\n 2. largest = 2 at index 2. nextLargest = 1. Reduce nums[2] to 1. nums = [1,1,1,2,2].\n 3. largest = 2 at index 3. nextLargest = 1. Reduce nums[3] to 1. nums = [1,1,1,1,2].\n 4. largest = 2 at index 4. nextLargest = 1. Reduce nums[4] to 1. nums = [1,1,1,1,1].\n \"\"\"\n"}
{"task_id": "minimum-number-of-flips-to-make-the-binary-string-alternating", "prompt": "def minFlips(s: str) -> int:\n \"\"\"\n You are given a binary string s. You are allowed to perform two types of operations on the string in any sequence:\n \n Type-1: Remove the character at the start of the string s and append it to the end of the string.\n Type-2: Pick any character in s and flip its value, i.e., if its value is '0' it becomes '1' and vice-versa.\n \n Return the minimum number of type-2 operations you need to perform such that s becomes alternating.\n The string is called alternating if no two adjacent characters are equal.\n \n For example, the strings \"010\" and \"1010\" are alternating, while the string \"0100\" is not.\n \n \n Example 1:\n \n >>> minFlips(s = \"111000\")\n >>> 2\n Explanation: Use the first operation two times to make s = \"100011\".\n Then, use the second operation on the third and sixth elements to make s = \"101010\".\n \n Example 2:\n \n >>> minFlips(s = \"010\")\n >>> 0\n Explanation: The string is already alternating.\n \n Example 3:\n \n >>> minFlips(s = \"1110\")\n >>> 1\n Explanation: Use the second operation on the second element to make s = \"1010\".\n \"\"\"\n"}
{"task_id": "minimum-space-wasted-from-packaging", "prompt": "def minWastedSpace(packages: List[int], boxes: List[List[int]]) -> int:\n \"\"\"\n You have n packages that you are trying to place in boxes, one package in each box. There are m suppliers that each produce boxes of different sizes (with infinite supply). A package can be placed in a box if the size of the package is less than or equal to the size of the box.\n The package sizes are given as an integer array packages, where packages[i] is the size of the ith package. The suppliers are given as a 2D integer array boxes, where boxes[j] is an array of box sizes that the jth supplier produces.\n You want to choose a single supplier and use boxes from them such that the total wasted space is minimized. For each package in a box, we define the space wasted to be size of the box - size of the package. The total wasted space is the sum of the space wasted in all the boxes.\n \n For example, if you have to fit packages with sizes [2,3,5] and the supplier offers boxes of sizes [4,8], you can fit the packages of size-2 and size-3 into two boxes of size-4 and the package with size-5 into a box of size-8. This would result in a waste of (4-2) + (4-3) + (8-5) = 6.\n \n Return the minimum total wasted space by choosing the box supplier optimally, or -1 if it is impossible to fit all the packages inside boxes. Since the answer may be large, return it modulo 109 + 7.\n \n Example 1:\n \n >>> minWastedSpace(packages = [2,3,5], boxes = [[4,8],[2,8]])\n >>> 6\n Explanation: It is optimal to choose the first supplier, using two size-4 boxes and one size-8 box.\n The total waste is (4-2) + (4-3) + (8-5) = 6.\n \n Example 2:\n \n >>> minWastedSpace(packages = [2,3,5], boxes = [[1,4],[2,3],[3,4]])\n >>> -1\n Explanation: There is no box that the package of size 5 can fit in.\n \n Example 3:\n \n >>> minWastedSpace(packages = [3,5,8,10,11,12], boxes = [[12],[11,9],[10,5,14]])\n >>> 9\n Explanation: It is optimal to choose the third supplier, using two size-5 boxes, two size-10 boxes, and two size-14 boxes.\n The total waste is (5-3) + (5-5) + (10-8) + (10-10) + (14-11) + (14-12) = 9.\n \"\"\"\n"}
{"task_id": "cutting-ribbons", "prompt": "def maxLength(ribbons: List[int], k: int) -> int:\n \"\"\"\n You are given an integer array ribbons, where ribbons[i] represents the length of the ith ribbon, and an integer k. You may cut any of the ribbons into any number of segments of positive integer lengths, or perform no cuts at all.\n \n For example, if you have a ribbon of length 4, you can:\n \n \n Keep the ribbon of length 4,\n Cut it into one ribbon of length 3 and one ribbon of length 1,\n Cut it into two ribbons of length 2,\n Cut it into one ribbon of length 2 and two ribbons of length 1, or\n Cut it into four ribbons of length 1.\n \n \n \n Your task is to determine the maximum length of ribbon, x, that allows you to cut at least k ribbons, each of length x. You can discard any leftover ribbon from the cuts. If it is impossible to cut k ribbons of the same length, return 0.\n \n Example 1:\n \n >>> maxLength(ribbons = [9,7,5], k = 3)\n >>> 5\n Explanation:\n - Cut the first ribbon to two ribbons, one of length 5 and one of length 4.\n - Cut the second ribbon to two ribbons, one of length 5 and one of length 2.\n - Keep the third ribbon as it is.\n Now you have 3 ribbons of length 5.\n Example 2:\n \n >>> maxLength(ribbons = [7,5,9], k = 4)\n >>> 4\n Explanation:\n - Cut the first ribbon to two ribbons, one of length 4 and one of length 3.\n - Cut the second ribbon to two ribbons, one of length 4 and one of length 1.\n - Cut the third ribbon to three ribbons, two of length 4 and one of length 1.\n Now you have 4 ribbons of length 4.\n \n Example 3:\n \n >>> maxLength(ribbons = [5,7,9], k = 22)\n >>> 0\n Explanation: You cannot obtain k ribbons of the same positive integer length.\n \"\"\"\n"}
{"task_id": "check-if-all-the-integers-in-a-range-are-covered", "prompt": "def isCovered(ranges: List[List[int]], left: int, right: int) -> bool:\n \"\"\"\n You are given a 2D integer array ranges and two integers left and right. Each ranges[i] = [starti, endi] represents an inclusive interval between starti and endi.\n Return true if each integer in the inclusive range [left, right] is covered by at least one interval in ranges. Return false otherwise.\n An integer x is covered by an interval ranges[i] = [starti, endi] if starti <= x <= endi.\n \n Example 1:\n \n >>> isCovered(ranges = [[1,2],[3,4],[5,6]], left = 2, right = 5)\n >>> true\n Explanation: Every integer between 2 and 5 is covered:\n - 2 is covered by the first range.\n - 3 and 4 are covered by the second range.\n - 5 is covered by the third range.\n \n Example 2:\n \n >>> isCovered(ranges = [[1,10],[10,20]], left = 21, right = 21)\n >>> false\n Explanation: 21 is not covered by any range.\n \"\"\"\n"}
{"task_id": "find-the-student-that-will-replace-the-chalk", "prompt": "def chalkReplacer(chalk: List[int], k: int) -> int:\n \"\"\"\n There are n students in a class numbered from 0 to n - 1. The teacher will give each student a problem starting with the student number 0, then the student number 1, and so on until the teacher reaches the student number n - 1. After that, the teacher will restart the process, starting with the student number 0 again.\n You are given a 0-indexed integer array chalk and an integer k. There are initially k pieces of chalk. When the student number i is given a problem to solve, they will use chalk[i] pieces of chalk to solve that problem. However, if the current number of chalk pieces is strictly less than chalk[i], then the student number i will be asked to replace the chalk.\n Return the index of the student that will replace the chalk pieces.\n \n Example 1:\n \n >>> chalkReplacer(chalk = [5,1,5], k = 22)\n >>> 0\n Explanation: The students go in turns as follows:\n - Student number 0 uses 5 chalk, so k = 17.\n - Student number 1 uses 1 chalk, so k = 16.\n - Student number 2 uses 5 chalk, so k = 11.\n - Student number 0 uses 5 chalk, so k = 6.\n - Student number 1 uses 1 chalk, so k = 5.\n - Student number 2 uses 5 chalk, so k = 0.\n Student number 0 does not have enough chalk, so they will have to replace it.\n Example 2:\n \n >>> chalkReplacer(chalk = [3,4,1,2], k = 25)\n >>> 1\n Explanation: The students go in turns as follows:\n - Student number 0 uses 3 chalk so k = 22.\n - Student number 1 uses 4 chalk so k = 18.\n - Student number 2 uses 1 chalk so k = 17.\n - Student number 3 uses 2 chalk so k = 15.\n - Student number 0 uses 3 chalk so k = 12.\n - Student number 1 uses 4 chalk so k = 8.\n - Student number 2 uses 1 chalk so k = 7.\n - Student number 3 uses 2 chalk so k = 5.\n - Student number 0 uses 3 chalk so k = 2.\n Student number 1 does not have enough chalk, so they will have to replace it.\n \"\"\"\n"}
{"task_id": "largest-magic-square", "prompt": "def largestMagicSquare(grid: List[List[int]]) -> int:\n \"\"\"\n A k x k magic square is a k x k grid filled with integers such that every row sum, every column sum, and both diagonal sums are all equal. The integers in the magic square do not have to be distinct. Every 1 x 1 grid is trivially a magic square.\n Given an m x n integer grid, return the size (i.e., the side length k) of the largest magic square that can be found within this grid.\n \n Example 1:\n \n \n >>> largestMagicSquare(grid = [[7,1,4,5,6],[2,5,1,6,4],[1,5,4,3,2],[1,2,7,3,4]])\n >>> 3\n Explanation: The largest magic square has a size of 3.\n Every row sum, column sum, and diagonal sum of this magic square is equal to 12.\n - Row sums: 5+1+6 = 5+4+3 = 2+7+3 = 12\n - Column sums: 5+5+2 = 1+4+7 = 6+3+3 = 12\n - Diagonal sums: 5+4+3 = 6+4+2 = 12\n \n Example 2:\n \n \n >>> largestMagicSquare(grid = [[5,1,3,1],[9,3,3,1],[1,3,3,8]])\n >>> 2\n \"\"\"\n"}
{"task_id": "minimum-cost-to-change-the-final-value-of-expression", "prompt": "def minOperationsToFlip(expression: str) -> int:\n \"\"\"\n You are given a valid boolean expression as a string expression consisting of the characters '1','0','&' (bitwise AND operator),'|' (bitwise OR operator),'(', and ')'.\n \n For example, \"()1|1\" and \"(1)&()\" are not valid while \"1\", \"(((1))|(0))\", and \"1|(0&(1))\" are valid expressions.\n \n Return the minimum cost to change the final value of the expression.\n \n For example, if expression = \"1|1|(0&0)&1\", its value is 1|1|(0&0)&1 = 1|1|0&1 = 1|0&1 = 1&1 = 1. We want to apply operations so that the new expression evaluates to 0.\n \n The cost of changing the final value of an expression is the number of operations performed on the expression. The types of operations are described as follows:\n \n Turn a '1' into a '0'.\n Turn a '0' into a '1'.\n Turn a '&' into a '|'.\n Turn a '|' into a '&'.\n \n Note: '&' does not take precedence over '|' in the order of calculation. Evaluate parentheses first, then in left-to-right order.\n \n Example 1:\n \n >>> minOperationsToFlip(expression = \"1&(0|1)\")\n >>> 1\n Explanation: We can turn \"1&(0|1)\" into \"1&(0&1)\" by changing the '|' to a '&' using 1 operation.\n The new expression evaluates to 0.\n \n Example 2:\n \n >>> minOperationsToFlip(expression = \"(0&0)&(0&0&0)\")\n >>> 3\n Explanation: We can turn \"(0&0)&(0&0&0)\" into \"(0|1)|(0&0&0)\" using 3 operations.\n The new expression evaluates to 1.\n \n Example 3:\n \n >>> minOperationsToFlip(expression = \"(0|(1|0&1))\")\n >>> 1\n Explanation: We can turn \"(0|(1|0&1))\" into \"(0|(0|0&1))\" using 1 operation.\n The new expression evaluates to 0.\n \"\"\"\n"}
{"task_id": "redistribute-characters-to-make-all-strings-equal", "prompt": "def makeEqual(words: List[str]) -> bool:\n \"\"\"\n You are given an array of strings words (0-indexed).\n In one operation, pick two distinct indices i and j, where words[i] is a non-empty string, and move any character from words[i] to any position in words[j].\n Return true if you can make every string in words equal using any number of operations, and false otherwise.\n \n Example 1:\n \n >>> makeEqual(words = [\"abc\",\"aabc\",\"bc\"])\n >>> true\n Explanation: Move the first 'a' in words[1] to the front of words[2],\n to make words[1] = \"abc\" and words[2] = \"abc\".\n All the strings are now equal to \"abc\", so return true.\n \n Example 2:\n \n >>> makeEqual(words = [\"ab\",\"a\"])\n >>> false\n Explanation: It is impossible to make all the strings equal using the operation.\n \"\"\"\n"}
{"task_id": "maximum-number-of-removable-characters", "prompt": "def maximumRemovals(s: str, p: str, removable: List[int]) -> int:\n \"\"\"\n You are given two strings s and p where p is a subsequence of s. You are also given a distinct 0-indexed integer array removable containing a subset of indices of s (s is also 0-indexed).\n You want to choose an integer k (0 <= k <= removable.length) such that, after removing k characters from s using the first k indices in removable, p is still a subsequence of s. More formally, you will mark the character at s[removable[i]] for each 0 <= i < k, then remove all marked characters and check if p is still a subsequence.\n Return the maximum k you can choose such that p is still a subsequence of s after the removals.\n 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.\n \n Example 1:\n \n >>> maximumRemovals(s = \"abcacb\", p = \"ab\", removable = [3,1,0])\n >>> 2\n Explanation: After removing the characters at indices 3 and 1, \"abcacb\" becomes \"accb\".\n \"ab\" is a subsequence of \"accb\".\n If we remove the characters at indices 3, 1, and 0, \"abcacb\" becomes \"ccb\", and \"ab\" is no longer a subsequence.\n Hence, the maximum k is 2.\n \n Example 2:\n \n >>> maximumRemovals(s = \"abcbddddd\", p = \"abcd\", removable = [3,2,1,4,5,6])\n >>> 1\n Explanation: After removing the character at index 3, \"abcbddddd\" becomes \"abcddddd\".\n \"abcd\" is a subsequence of \"abcddddd\".\n \n Example 3:\n \n >>> maximumRemovals(s = \"abcab\", p = \"abc\", removable = [0,1,2,3,4])\n >>> 0\n Explanation: If you remove the first index in the array removable, \"abc\" is no longer a subsequence.\n \"\"\"\n"}
{"task_id": "merge-triplets-to-form-target-triplet", "prompt": "def mergeTriplets(triplets: List[List[int]], target: List[int]) -> bool:\n \"\"\"\n A triplet is an array of three integers. You are given a 2D integer array triplets, where triplets[i] = [ai, bi, ci] describes the ith triplet. You are also given an integer array target = [x, y, z] that describes the triplet you want to obtain.\n To obtain target, you may apply the following operation on triplets any number of times (possibly zero):\n \n Choose two indices (0-indexed) i and j (i != j) and update triplets[j] to become [max(ai, aj), max(bi, bj), max(ci, cj)].\n \n \n For example, if triplets[i] = [2, 5, 3] and triplets[j] = [1, 7, 5], triplets[j] will be updated to [max(2, 1), max(5, 7), max(3, 5)] = [2, 7, 5].\n \n \n \n Return true if it is possible to obtain the target triplet [x, y, z] as an element of triplets, or false otherwise.\n \n Example 1:\n \n >>> mergeTriplets(triplets = [[2,5,3],[1,8,4],[1,7,5]], target = [2,7,5])\n >>> true\n Explanation: Perform the following operations:\n - Choose the first and last triplets [[2,5,3],[1,8,4],[1,7,5]]. Update the last triplet to be [max(2,1), max(5,7), max(3,5)] = [2,7,5]. triplets = [[2,5,3],[1,8,4],[2,7,5]]\n The target triplet [2,7,5] is now an element of triplets.\n \n Example 2:\n \n >>> mergeTriplets(triplets = [[3,4,5],[4,5,6]], target = [3,2,5])\n >>> false\n Explanation: It is impossible to have [3,2,5] as an element because there is no 2 in any of the triplets.\n \n Example 3:\n \n >>> mergeTriplets(triplets = [[2,5,3],[2,3,4],[1,2,5],[5,2,3]], target = [5,5,5])\n >>> true\n Explanation: Perform the following operations:\n - Choose the first and third triplets [[2,5,3],[2,3,4],[1,2,5],[5,2,3]]. Update the third triplet to be [max(2,1), max(5,2), max(3,5)] = [2,5,5]. triplets = [[2,5,3],[2,3,4],[2,5,5],[5,2,3]].\n - Choose the third and fourth triplets [[2,5,3],[2,3,4],[2,5,5],[5,2,3]]. Update the fourth triplet to be [max(2,5), max(5,2), max(5,3)] = [5,5,5]. triplets = [[2,5,3],[2,3,4],[2,5,5],[5,5,5]].\n The target triplet [5,5,5] is now an element of triplets.\n \"\"\"\n"}
{"task_id": "the-earliest-and-latest-rounds-where-players-compete", "prompt": "def earliestAndLatest(n: int, firstPlayer: int, secondPlayer: int) -> List[int]:\n \"\"\"\n There is a tournament where n players are participating. The players are standing in a single row and are numbered from 1 to n based on their initial standing position (player 1 is the first player in the row, player 2 is the second player in the row, etc.).\n The tournament consists of multiple rounds (starting from round number 1). In each round, the ith player from the front of the row competes against the ith player from the end of the row, and the winner advances to the next round. When the number of players is odd for the current round, the player in the middle automatically advances to the next round.\n \n For example, if the row consists of players 1, 2, 4, 6, 7\n \n Player 1 competes against player 7.\n Player 2 competes against player 6.\n Player 4 automatically advances to the next round.\n \n \n \n After each round is over, the winners are lined back up in the row based on the original ordering assigned to them initially (ascending order).\n The players numbered firstPlayer and secondPlayer are the best in the tournament. They can win against any other player before they compete against each other. If any two other players compete against each other, either of them might win, and thus you may choose the outcome of this round.\n Given the integers n, firstPlayer, and secondPlayer, return an integer array containing two values, the earliest possible round number and the\u00a0latest possible round number in which these two players will compete against each other, respectively.\n \n Example 1:\n \n >>> earliestAndLatest(n = 11, firstPlayer = 2, secondPlayer = 4)\n >>> [3,4]\n Explanation:\n One possible scenario which leads to the earliest round number:\n First round: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11\n Second round: 2, 3, 4, 5, 6, 11\n Third round: 2, 3, 4\n One possible scenario which leads to the latest round number:\n First round: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11\n Second round: 1, 2, 3, 4, 5, 6\n Third round: 1, 2, 4\n Fourth round: 2, 4\n \n Example 2:\n \n >>> earliestAndLatest(n = 5, firstPlayer = 1, secondPlayer = 5)\n >>> [1,1]\n Explanation: The players numbered 1 and 5 compete in the first round.\n There is no way to make them compete in any other round.\n \"\"\"\n"}
{"task_id": "find-a-peak-element-ii", "prompt": "def findPeakGrid(mat: List[List[int]]) -> List[int]:\n \"\"\"\n A peak element in a 2D grid is an element that is strictly greater than all of its adjacent neighbors to the left, right, top, and bottom.\n Given a 0-indexed m x n matrix mat where no two adjacent cells are equal, find any peak element mat[i][j] and return the length 2 array [i,j].\n You may assume that the entire matrix is surrounded by an outer perimeter with the value -1 in each cell.\n You must write an algorithm that runs in O(m log(n)) or O(n log(m)) time.\n \n Example 1:\n \n \n >>> findPeakGrid(mat = [[1,4],[3,2]])\n >>> [0,1]\n Explanation:\u00a0Both 3 and 4 are peak elements so [1,0] and [0,1] are both acceptable answers.\n \n Example 2:\n \n \n >>> findPeakGrid(mat = [[10,20,15],[21,30,14],[7,16,32]])\n >>> [1,1]\n Explanation:\u00a0Both 30 and 32 are peak elements so [1,1] and [2,2] are both acceptable answers.\n \"\"\"\n"}
{"task_id": "depth-of-bst-given-insertion-order", "prompt": "def maxDepthBST(order: List[int]) -> int:\n \"\"\"\n You are given a 0-indexed integer array order of length n, a permutation of integers from 1 to n representing the order of insertion into a binary search tree.\n A binary search tree is defined as follows:\n \n The left subtree of a node contains only nodes with keys less than the node's key.\n The right subtree of a node contains only nodes with keys greater than the node's key.\n Both the left and right subtrees must also be binary search trees.\n \n The binary search tree is constructed as follows:\n \n order[0] will be the root of the binary search tree.\n All subsequent elements are inserted as the child of any existing node such that the binary search tree properties hold.\n \n Return the depth of the binary search tree.\n A binary tree's depth is the number of nodes along the longest path from the root node down to the farthest leaf node.\n \n Example 1:\n \n \n >>> maxDepthBST(order = [2,1,4,3])\n >>> 3\n Explanation: The binary search tree has a depth of 3 with path 2->3->4.\n \n Example 2:\n \n \n >>> maxDepthBST(order = [2,1,3,4])\n >>> 3\n Explanation: The binary search tree has a depth of 3 with path 2->3->4.\n \n Example 3:\n \n \n >>> maxDepthBST(order = [1,2,3,4])\n >>> 4\n Explanation: The binary search tree has a depth of 4 with path 1->2->3->4.\n \"\"\"\n"}
{"task_id": "largest-odd-number-in-string", "prompt": "def largestOddNumber(num: str) -> str:\n \"\"\"\n You are given a string num, representing a large integer. Return the largest-valued odd integer (as a string) that is a non-empty substring of num, or an empty string \"\" if no odd integer exists.\n A substring is a contiguous sequence of characters within a string.\n \n Example 1:\n \n >>> largestOddNumber(num = \"52\")\n >>> \"5\"\n Explanation: The only non-empty substrings are \"5\", \"2\", and \"52\". \"5\" is the only odd number.\n \n Example 2:\n \n >>> largestOddNumber(num = \"4206\")\n >>> \"\"\n Explanation: There are no odd numbers in \"4206\".\n \n Example 3:\n \n >>> largestOddNumber(num = \"35427\")\n >>> \"35427\"\n Explanation: \"35427\" is already an odd number.\n \"\"\"\n"}
{"task_id": "the-number-of-full-rounds-you-have-played", "prompt": "def numberOfRounds(loginTime: str, logoutTime: str) -> int:\n \"\"\"\n You are participating in an online chess tournament. There is a chess round that starts every 15 minutes. The first round of the day starts at 00:00, and after every 15 minutes, a new round starts.\n \n For example, the second round starts at 00:15, the fourth round starts at 00:45, and the seventh round starts at 01:30.\n \n You are given two strings loginTime and logoutTime where:\n \n loginTime is the time you will login to the game, and\n logoutTime is the time you will logout from the game.\n \n If logoutTime is earlier than loginTime, this means you have played from loginTime to midnight and from midnight to logoutTime.\n Return the number of full chess rounds you have played in the tournament.\n Note:\u00a0All the given times follow the 24-hour clock. That means the first round of the day starts at 00:00 and the last round of the day starts at 23:45.\n \n Example 1:\n \n >>> numberOfRounds(loginTime = \"09:31\", logoutTime = \"10:14\")\n >>> 1\n Explanation: You played one full round from 09:45 to 10:00.\n You did not play the full round from 09:30 to 09:45 because you logged in at 09:31 after it began.\n You did not play the full round from 10:00 to 10:15 because you logged out at 10:14 before it ended.\n \n Example 2:\n \n >>> numberOfRounds(loginTime = \"21:30\", logoutTime = \"03:00\")\n >>> 22\n Explanation: You played 10 full rounds from 21:30 to 00:00 and 12 full rounds from 00:00 to 03:00.\n 10 + 12 = 22.\n \"\"\"\n"}
{"task_id": "count-sub-islands", "prompt": "def countSubIslands(grid1: List[List[int]], grid2: List[List[int]]) -> int:\n \"\"\"\n You are given two m x n binary matrices grid1 and grid2 containing only 0's (representing water) and 1's (representing land). An island is a group of 1's connected 4-directionally (horizontal or vertical). Any cells outside of the grid are considered water cells.\n An island in grid2 is considered a sub-island if there is an island in grid1 that contains all the cells that make up this island in grid2.\n Return the number of islands in grid2 that are considered sub-islands.\n \n Example 1:\n \n \n >>> countSubIslands(grid1 = [[1,1,1,0,0],[0,1,1,1,1],[0,0,0,0,0],[1,0,0,0,0],[1,1,0,1,1]], grid2 = [[1,1,1,0,0],[0,0,1,1,1],[0,1,0,0,0],[1,0,1,1,0],[0,1,0,1,0]])\n >>> 3\n Explanation: In the picture above, the grid on the left is grid1 and the grid on the right is grid2.\n The 1s colored red in grid2 are those considered to be part of a sub-island. There are three sub-islands.\n \n Example 2:\n \n \n >>> countSubIslands(grid1 = [[1,0,1,0,1],[1,1,1,1,1],[0,0,0,0,0],[1,1,1,1,1],[1,0,1,0,1]], grid2 = [[0,0,0,0,0],[1,1,1,1,1],[0,1,0,1,0],[0,1,0,1,0],[1,0,0,0,1]])\n >>> 2\n Explanation: In the picture above, the grid on the left is grid1 and the grid on the right is grid2.\n The 1s colored red in grid2 are those considered to be part of a sub-island. There are two sub-islands.\n \"\"\"\n"}
{"task_id": "minimum-absolute-difference-queries", "prompt": "def minDifference(nums: List[int], queries: List[List[int]]) -> List[int]:\n \"\"\"\n The minimum absolute difference of an array a is defined as the minimum value of |a[i] - a[j]|, where 0 <= i < j < a.length and a[i] != a[j]. If all elements of a are the same, the minimum absolute difference is -1.\n \n For example, the minimum absolute difference of the array [5,2,3,7,2] is |2 - 3| = 1. Note that it is not 0 because a[i] and a[j] must be different.\n \n You are given an integer array nums and the array queries where queries[i] = [li, ri]. For each query i, compute the minimum absolute difference of the subarray nums[li...ri] containing the elements of nums between the 0-based indices li and ri (inclusive).\n Return an array ans where ans[i] is the answer to the ith query.\n A subarray is a contiguous sequence of elements in an array.\n The value of |x| is defined as:\n \n x if x >= 0.\n -x if x < 0.\n \n \n Example 1:\n \n >>> minDifference(nums = [1,3,4,8], queries = [[0,1],[1,2],[2,3],[0,3]])\n >>> [2,1,4,1]\n Explanation: The queries are processed as follows:\n - queries[0] = [0,1]: The subarray is [1,3] and the minimum absolute difference is |1-3| = 2.\n - queries[1] = [1,2]: The subarray is [3,4] and the minimum absolute difference is |3-4| = 1.\n - queries[2] = [2,3]: The subarray is [4,8] and the minimum absolute difference is |4-8| = 4.\n - queries[3] = [0,3]: The subarray is [1,3,4,8] and the minimum absolute difference is |3-4| = 1.\n \n Example 2:\n \n >>> minDifference(nums = [4,5,2,2,7,10], queries = [[2,3],[0,2],[0,5],[3,5]])\n >>> [-1,1,1,3]\n Explanation: The queries are processed as follows:\n - queries[0] = [2,3]: The subarray is [2,2] and the minimum absolute difference is -1 because all the\n elements are the same.\n - queries[1] = [0,2]: The subarray is [4,5,2] and the minimum absolute difference is |4-5| = 1.\n - queries[2] = [0,5]: The subarray is [4,5,2,2,7,10] and the minimum absolute difference is |4-5| = 1.\n - queries[3] = [3,5]: The subarray is [2,7,10] and the minimum absolute difference is |7-10| = 3.\n \"\"\"\n"}
{"task_id": "game-of-nim", "prompt": "def nimGame(piles: List[int]) -> bool:\n \"\"\"\n Alice and Bob take turns playing a game with Alice starting first.\n In this game, there are n piles of stones. On each player's turn, the player should remove any positive number of stones from a non-empty pile of his or her choice. The first player who cannot make a move loses, and the other player wins.\n Given an integer array piles, where piles[i] is the number of stones in the ith pile, return true if Alice wins, or false if Bob wins.\n Both Alice and Bob play optimally.\n \n Example 1:\n \n >>> nimGame(piles = [1])\n >>> true\n Explanation: There is only one possible scenario:\n - On the first turn, Alice removes one stone from the first pile. piles = [0].\n - On the second turn, there are no stones left for Bob to remove. Alice wins.\n \n Example 2:\n \n >>> nimGame(piles = [1,1])\n >>> false\n Explanation: It can be proven that Bob will always win. One possible scenario is:\n - On the first turn, Alice removes one stone from the first pile. piles = [0,1].\n - On the second turn, Bob removes one stone from the second pile. piles = [0,0].\n - On the third turn, there are no stones left for Alice to remove. Bob wins.\n \n Example 3:\n \n >>> nimGame(piles = [1,2,3])\n >>> false\n Explanation: It can be proven that Bob will always win. One possible scenario is:\n - On the first turn, Alice removes three stones from the third pile. piles = [1,2,0].\n - On the second turn, Bob removes one stone from the second pile. piles = [1,1,0].\n - On the third turn, Alice removes one stone from the first pile. piles = [0,1,0].\n - On the fourth turn, Bob removes one stone from the second pile. piles = [0,0,0].\n - On the fifth turn, there are no stones left for Alice to remove. Bob wins.\n \"\"\"\n"}
{"task_id": "remove-one-element-to-make-the-array-strictly-increasing", "prompt": "def canBeIncreasing(nums: List[int]) -> bool:\n \"\"\"\n Given a 0-indexed integer array nums, return true if it can be made strictly increasing after removing exactly one element, or false otherwise. If the array is already strictly increasing, return true.\n The array nums is strictly increasing if nums[i - 1] < nums[i] for each index (1 <= i < nums.length).\n \n Example 1:\n \n >>> canBeIncreasing(nums = [1,2,10,5,7])\n >>> true\n Explanation: By removing 10 at index 2 from nums, it becomes [1,2,5,7].\n [1,2,5,7] is strictly increasing, so return true.\n \n Example 2:\n \n >>> canBeIncreasing(nums = [2,3,1,2])\n >>> false\n Explanation:\n [3,1,2] is the result of removing the element at index 0.\n [2,1,2] is the result of removing the element at index 1.\n [2,3,2] is the result of removing the element at index 2.\n [2,3,1] is the result of removing the element at index 3.\n No resulting array is strictly increasing, so return false.\n Example 3:\n \n >>> canBeIncreasing(nums = [1,1,1])\n >>> false\n Explanation: The result of removing any element is [1,1].\n [1,1] is not strictly increasing, so return false.\n \"\"\"\n"}
{"task_id": "remove-all-occurrences-of-a-substring", "prompt": "def removeOccurrences(s: str, part: str) -> str:\n \"\"\"\n Given two strings s and part, perform the following operation on s until all occurrences of the substring part are removed:\n \n Find the leftmost occurrence of the substring part and remove it from s.\n \n Return s after removing all occurrences of part.\n A substring is a contiguous sequence of characters in a string.\n \n Example 1:\n \n >>> removeOccurrences(s = \"daabcbaabcbc\", part = \"abc\")\n >>> \"dab\"\n Explanation: The following operations are done:\n - s = \"daabcbaabcbc\", remove \"abc\" starting at index 2, so s = \"dabaabcbc\".\n - s = \"dabaabcbc\", remove \"abc\" starting at index 4, so s = \"dababc\".\n - s = \"dababc\", remove \"abc\" starting at index 3, so s = \"dab\".\n Now s has no occurrences of \"abc\".\n \n Example 2:\n \n >>> removeOccurrences(s = \"axxxxyyyyb\", part = \"xy\")\n >>> \"ab\"\n Explanation: The following operations are done:\n - s = \"axxxxyyyyb\", remove \"xy\" starting at index 4 so s = \"axxxyyyb\".\n - s = \"axxxyyyb\", remove \"xy\" starting at index 3 so s = \"axxyyb\".\n - s = \"axxyyb\", remove \"xy\" starting at index 2 so s = \"axyb\".\n - s = \"axyb\", remove \"xy\" starting at index 1 so s = \"ab\".\n Now s has no occurrences of \"xy\".\n \"\"\"\n"}
{"task_id": "maximum-alternating-subsequence-sum", "prompt": "def maxAlternatingSum(nums: List[int]) -> int:\n \"\"\"\n The alternating sum of a 0-indexed array is defined as the sum of the elements at even indices minus the sum of the elements at odd indices.\\r\n \\r\n \\r\n \tFor example, the alternating sum of [4,2,5,3] is (4 + 5) - (2 + 3) = 4.\\r\n \\r\n \\r\n Given an array nums, return the maximum alternating sum of any subsequence of nums (after reindexing the elements of the subsequence).\\r\n \\r\n \\r\n \\r\n \\r\n A subsequence of an array is a new array generated from the original array by deleting some elements (possibly none) without changing the remaining elements' relative order. For example, [2,7,4] is a subsequence of [4,2,3,7,2,1,4] (the underlined elements), while [2,4,2] is not.\\r\n \\r\n \u00a0\\r\n Example 1:\\r\n \\r\n \\r\n >>> maxAlternatingSum(nums = [4,2,5,3]\\r)\n >>> 7\\r\n Explanation: It is optimal to choose the subsequence [4,2,5] with alternating sum (4 + 5) - 2 = 7.\\r\n \\r\n \\r\n Example 2:\\r\n \\r\n \\r\n >>> maxAlternatingSum(nums = [5,6,7,8]\\r)\n >>> 8\\r\n Explanation: It is optimal to choose the subsequence [8] with alternating sum 8.\\r\n \\r\n \\r\n Example 3:\\r\n \\r\n \\r\n >>> maxAlternatingSum(nums = [6,2,1,2,4,5]\\r)\n >>> 10\\r\n Explanation: It is optimal to choose the subsequence [6,1,5] with alternating sum (6 + 5) - 1 = 10.\\r\n \\r\n \\r\n \u00a0\\r\n \"\"\"\n"}
{"task_id": "maximum-product-difference-between-two-pairs", "prompt": "def maxProductDifference(nums: List[int]) -> int:\n \"\"\"\n The product difference between two pairs (a, b) and (c, d) is defined as (a * b) - (c * d).\\r\n \\r\n \\r\n \tFor example, the product difference between (5, 6) and (2, 7) is (5 * 6) - (2 * 7) = 16.\\r\n \\r\n \\r\n Given an integer array nums, choose four distinct indices w, x, y, and z such that the product difference between pairs (nums[w], nums[x]) and (nums[y], nums[z]) is maximized.\\r\n \\r\n Return the maximum such product difference.\\r\n \\r\n \u00a0\\r\n Example 1:\\r\n \\r\n \\r\n >>> maxProductDifference(nums = [5,6,2,7,4]\\r)\n >>> 34\\r\n Explanation: We can choose indices 1 and 3 for the first pair (6, 7) and indices 2 and 4 for the second pair (2, 4).\\r\n The product difference is (6 * 7) - (2 * 4) = 34.\\r\n \\r\n \\r\n Example 2:\\r\n \\r\n \\r\n >>> maxProductDifference(nums = [4,2,5,9,7,4,8]\\r)\n >>> 64\\r\n Explanation: We can choose indices 3 and 6 for the first pair (9, 8) and indices 1 and 5 for the second pair (2, 4).\\r\n The product difference is (9 * 8) - (2 * 4) = 64.\\r\n \\r\n \\r\n \u00a0\\r\n \"\"\"\n"}
{"task_id": "cyclically-rotating-a-grid", "prompt": "def rotateGrid(grid: List[List[int]], k: int) -> List[List[int]]:\n \"\"\"\n You are given an m x n integer matrix grid\u200b\u200b\u200b, where m and n are both even integers, and an integer k.\\r\n \\r\n The matrix is composed of several layers, which is shown in the below image, where each color is its own layer:\\r\n \\r\n \\r\n \\r\n A cyclic rotation of the matrix is done by cyclically rotating each layer in the matrix. To cyclically rotate a layer once, each element in the layer will take the place of the adjacent element in the counter-clockwise direction. An example rotation is shown below:\\r\n \\r\n Return the matrix after applying k cyclic rotations to it.\\r\n \\r\n \u00a0\\r\n Example 1:\\r\n \\r\n \\r\n >>> rotateGrid(grid = [[40,10],[30,20]], k = 1\\r)\n >>> [[10,20],[40,30]]\\r\n Explanation: The figures above represent the grid at every state.\\r\n \\r\n \\r\n Example 2:\\r\n \\r\n \\r\n \\r\n >>> rotateGrid(grid = [[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]], k = 2\\r)\n >>> [[3,4,8,12],[2,11,10,16],[1,7,6,15],[5,9,13,14]]\\r\n Explanation: The figures above represent the grid at every state.\\r\n \\r\n \\r\n \u00a0\\r\n \"\"\"\n"}
{"task_id": "number-of-wonderful-substrings", "prompt": "def wonderfulSubstrings(word: str) -> int:\n \"\"\"\n A wonderful string is a string where at most one letter appears an odd number of times.\\r\n \\r\n \\r\n \tFor example, \"ccjjc\" and \"abab\" are wonderful, but \"ab\" is not.\\r\n \\r\n \\r\n Given a string word that consists of the first ten lowercase English letters ('a' through 'j'), return the number of wonderful non-empty substrings in word. If the same substring appears multiple times in word, then count each occurrence separately.\\r\n \\r\n A substring is a contiguous sequence of characters in a string.\\r\n \\r\n \u00a0\\r\n Example 1:\\r\n \\r\n \\r\n >>> wonderfulSubstrings(word = \"aba\"\\r)\n >>> 4\\r\n Explanation: The four wonderful substrings are underlined below:\\r\n - \"aba\" -> \"a\"\\r\n - \"aba\" -> \"b\"\\r\n - \"aba\" -> \"a\"\\r\n - \"aba\" -> \"aba\"\\r\n \\r\n \\r\n Example 2:\\r\n \\r\n \\r\n >>> wonderfulSubstrings(word = \"aabb\"\\r)\n >>> 9\\r\n Explanation: The nine wonderful substrings are underlined below:\\r\n - \"aabb\" -> \"a\"\\r\n - \"aabb\" -> \"aa\"\\r\n - \"aabb\" -> \"aab\"\\r\n - \"aabb\" -> \"aabb\"\\r\n - \"aabb\" -> \"a\"\\r\n - \"aabb\" -> \"abb\"\\r\n - \"aabb\" -> \"b\"\\r\n - \"aabb\" -> \"bb\"\\r\n - \"aabb\" -> \"b\"\\r\n \\r\n \\r\n Example 3:\\r\n \\r\n \\r\n >>> wonderfulSubstrings(word = \"he\"\\r)\n >>> 2\\r\n Explanation: The two wonderful substrings are underlined below:\\r\n - \"he\" -> \"h\"\\r\n - \"he\" -> \"e\"\\r\n \\r\n \\r\n \u00a0\\r\n \"\"\"\n"}
{"task_id": "count-ways-to-build-rooms-in-an-ant-colony", "prompt": "def waysToBuildRooms(prevRoom: List[int]) -> int:\n \"\"\"\n You are an ant tasked with adding n new rooms numbered 0 to n-1 to your colony. You are given the expansion plan as a 0-indexed integer array of length n, prevRoom, where prevRoom[i] indicates that you must build room prevRoom[i] before building room i, and these two rooms must be connected directly. Room 0 is already built, so prevRoom[0] = -1. The expansion\u00a0plan is given such that once all the rooms are built, every room will be reachable from room 0.\\r\n \\r\n You can only build one room at a time, and you can travel freely between rooms you have already built only if they are connected.\u00a0You can choose to build any room as long as its previous room\u00a0is already built.\\r\n \\r\n Return the number of different orders you can build all the rooms in. Since the answer may be large, return it modulo 109 + 7.\\r\n \\r\n \u00a0\\r\n Example 1:\\r\n \\r\n \\r\n >>> waysToBuildRooms(prevRoom = [-1,0,1]\\r)\n >>> 1\\r\n Explanation:\u00a0There is only one way to build the additional rooms: 0 \u2192 1 \u2192 2\\r\n \\r\n \\r\n Example 2:\\r\n \\r\n \\r\n \\r\n >>> waysToBuildRooms(prevRoom = [-1,0,0,1,2]\\r)\n >>> 6\\r\n Explanation:\\r\n The 6 ways are:\\r\n 0 \u2192 1 \u2192 3 \u2192 2 \u2192 4\\r\n 0 \u2192 2 \u2192 4 \u2192 1 \u2192 3\\r\n 0 \u2192 1 \u2192 2 \u2192 3 \u2192 4\\r\n 0 \u2192 1 \u2192 2 \u2192 4 \u2192 3\\r\n 0 \u2192 2 \u2192 1 \u2192 3 \u2192 4\\r\n 0 \u2192 2 \u2192 1 \u2192 4 \u2192 3\\r\n \\r\n \\r\n \u00a0\\r\n \"\"\"\n"}
{"task_id": "kth-smallest-subarray-sum", "prompt": "def kthSmallestSubarraySum(nums: List[int], k: int) -> int:\n \"\"\"\n Given an integer array nums of length n and an integer k, return the kth smallest subarray sum.\n A subarray is defined as a non-empty contiguous sequence of elements in an array. A subarray sum is the sum of all elements in the subarray.\n \n Example 1:\n \n >>> kthSmallestSubarraySum(nums = [2,1,3], k = 4)\n >>> 3\n Explanation: The subarrays of [2,1,3] are:\n - [2] with sum 2\n - [1] with sum 1\n - [3] with sum 3\n - [2,1] with sum 3\n - [1,3] with sum 4\n - [2,1,3] with sum 6\n Ordering the sums from smallest to largest gives 1, 2, 3, 3, 4, 6. The 4th smallest is 3.\n \n Example 2:\n \n >>> kthSmallestSubarraySum(nums = [3,3,5,5], k = 7)\n >>> 10\n Explanation: The subarrays of [3,3,5,5] are:\n - [3] with sum 3\n - [3] with sum 3\n - [5] with sum 5\n - [5] with sum 5\n - [3,3] with sum 6\n - [3,5] with sum 8\n - [5,5] with sum 10\n - [3,3,5], with sum 11\n - [3,5,5] with sum 13\n - [3,3,5,5] with sum 16\n Ordering the sums from smallest to largest gives 3, 3, 5, 5, 6, 8, 10, 11, 13, 16. The 7th smallest is 10.\n \"\"\"\n"}
{"task_id": "build-array-from-permutation", "prompt": "def buildArray(nums: List[int]) -> List[int]:\n \"\"\"\n Given a zero-based permutation nums (0-indexed), build an array ans of the same length where ans[i] = nums[nums[i]] for each 0 <= i < nums.length and return it.\n A zero-based permutation nums is an array of distinct integers from 0 to nums.length - 1 (inclusive).\n \n Example 1:\n \n >>> buildArray(nums = [0,2,1,5,3,4])\n >>> [0,1,2,4,5,3]\n Explanation: The array ans is built as follows:\n ans = [nums[nums[0]], nums[nums[1]], nums[nums[2]], nums[nums[3]], nums[nums[4]], nums[nums[5]]]\n = [nums[0], nums[2], nums[1], nums[5], nums[3], nums[4]]\n = [0,1,2,4,5,3]\n Example 2:\n \n >>> buildArray(nums = [5,0,1,2,3,4])\n >>> [4,5,0,1,2,3]\n Explanation: The array ans is built as follows:\n ans = [nums[nums[0]], nums[nums[1]], nums[nums[2]], nums[nums[3]], nums[nums[4]], nums[nums[5]]]\n = [nums[5], nums[0], nums[1], nums[2], nums[3], nums[4]]\n = [4,5,0,1,2,3]\n \"\"\"\n"}
{"task_id": "eliminate-maximum-number-of-monsters", "prompt": "def eliminateMaximum(dist: List[int], speed: List[int]) -> int:\n \"\"\"\n You are playing a video game where you are defending your city from a group of n monsters. You are given a 0-indexed integer array dist of size n, where dist[i] is the initial distance in kilometers of the ith monster from the city.\n The monsters walk toward the city at a constant speed. The speed of each monster is given to you in an integer array speed of size n, where speed[i] is the speed of the ith monster in kilometers per minute.\n You have a weapon that, once fully charged, can eliminate a single monster. However, the weapon takes one minute to charge. The weapon is fully charged at the very start.\n You lose when any monster reaches your city. If a monster reaches the city at the exact moment the weapon is fully charged, it counts as a loss, and the game ends before you can use your weapon.\n Return the maximum number of monsters that you can eliminate before you lose, or n if you can eliminate all the monsters before they reach the city.\n \n Example 1:\n \n >>> eliminateMaximum(dist = [1,3,4], speed = [1,1,1])\n >>> 3\n Explanation:\n In the beginning, the distances of the monsters are [1,3,4]. You eliminate the first monster.\n After a minute, the distances of the monsters are [X,2,3]. You eliminate the second monster.\n After a minute, the distances of the monsters are [X,X,2]. You eliminate the third monster.\n All 3 monsters can be eliminated.\n Example 2:\n \n >>> eliminateMaximum(dist = [1,1,2,3], speed = [1,1,1,1])\n >>> 1\n Explanation:\n In the beginning, the distances of the monsters are [1,1,2,3]. You eliminate the first monster.\n After a minute, the distances of the monsters are [X,0,1,2], so you lose.\n You can only eliminate 1 monster.\n \n Example 3:\n \n >>> eliminateMaximum(dist = [3,2,4], speed = [5,3,2])\n >>> 1\n Explanation:\n In the beginning, the distances of the monsters are [3,2,4]. You eliminate the first monster.\n After a minute, the distances of the monsters are [X,0,2], so you lose.\n You can only eliminate 1 monster.\n \"\"\"\n"}
{"task_id": "count-good-numbers", "prompt": "def countGoodNumbers(n: int) -> int:\n \"\"\"\n A digit string is good if the digits (0-indexed) at even indices are even and the digits at odd indices are prime (2, 3, 5, or 7).\n \n For example, \"2582\" is good because the digits (2 and 8) at even positions are even and the digits (5 and 2) at odd positions are prime. However, \"3245\" is not good because 3 is at an even index but is not even.\n \n Given an integer n, return the total number of good digit strings of length n. Since the answer may be large, return it modulo 109 + 7.\n A digit string is a string consisting of digits 0 through 9 that may contain leading zeros.\n \n Example 1:\n \n >>> countGoodNumbers(n = 1)\n >>> 5\n Explanation: The good numbers of length 1 are \"0\", \"2\", \"4\", \"6\", \"8\".\n \n Example 2:\n \n >>> countGoodNumbers(n = 4)\n >>> 400\n \n Example 3:\n \n >>> countGoodNumbers(n = 50)\n >>> 564908303\n \"\"\"\n"}
{"task_id": "longest-common-subpath", "prompt": "def longestCommonSubpath(n: int, paths: List[List[int]]) -> int:\n \"\"\"\n There is a country of n cities numbered from 0 to n - 1. In this country, there is a road connecting every pair of cities.\n There are m friends numbered from 0 to m - 1 who are traveling through the country. Each one of them will take a path consisting of some cities. Each path is represented by an integer array that contains the visited cities in order. The path may contain a city more than once, but the same city will not be listed consecutively.\n Given an integer n and a 2D integer array paths where paths[i] is an integer array representing the path of the ith friend, return the length of the longest common subpath that is shared by every friend's path, or 0 if there is no common subpath at all.\n A subpath of a path is a contiguous sequence of cities within that path.\n \n Example 1:\n \n [2,3,4],\n [4,0,1,2,3]]\n >>> longestCommonSubpath(n = 5, paths = [[0,1,2,3,4],)\n >>> 2\n Explanation: The longest common subpath is [2,3].\n \n Example 2:\n \n >>> longestCommonSubpath(n = 3, paths = [[0],[1],[2]])\n >>> 0\n Explanation: There is no common subpath shared by the three paths.\n \n Example 3:\n \n [4,3,2,1,0]]\n >>> longestCommonSubpath(n = 5, paths = [[0,1,2,3,4],)\n >>> 1\n Explanation: The possible longest common subpaths are [0], [1], [2], [3], and [4]. All have a length of 1.\n \"\"\"\n"}
{"task_id": "erect-the-fence-ii", "prompt": "def outerTrees(trees: List[List[int]]) -> List[float]:\n \"\"\"\n You are given a 2D integer array trees where trees[i] = [xi, yi] represents the location of the ith tree in the garden.\n You are asked to fence the entire garden using the minimum length of rope possible. The garden is well-fenced only if all the trees are enclosed and the rope used forms a perfect circle. A tree is considered enclosed if it is inside or on the border of the circle.\n More formally, you must form a circle using the rope with a center (x, y) and radius r where all trees lie inside or on the circle and r is minimum.\n Return the center and radius of the circle as a length 3 array [x, y, r].\u00a0Answers within 10-5 of the actual answer will be accepted.\n \n Example 1:\n \n \n >>> outerTrees(trees = [[1,1],[2,2],[2,0],[2,4],[3,3],[4,2]])\n >>> [2.00000,2.00000,2.00000]\n Explanation: The fence will have center = (2, 2) and radius = 2\n \n Example 2:\n \n \n >>> outerTrees(trees = [[1,2],[2,2],[4,2]])\n >>> [2.50000,2.00000,1.50000]\n Explanation: The fence will have center = (2.5, 2) and radius = 1.5\n \"\"\"\n"}
{"task_id": "count-square-sum-triples", "prompt": "def countTriples(n: int) -> int:\n \"\"\"\n A square triple (a,b,c) is a triple where a, b, and c are integers and a2 + b2 = c2.\n Given an integer n, return the number of square triples such that 1 <= a, b, c <= n.\n \n Example 1:\n \n >>> countTriples(n = 5)\n >>> 2\n Explanation: The square triples are (3,4,5) and (4,3,5).\n \n Example 2:\n \n >>> countTriples(n = 10)\n >>> 4\n Explanation: The square triples are (3,4,5), (4,3,5), (6,8,10), and (8,6,10).\n \"\"\"\n"}
{"task_id": "nearest-exit-from-entrance-in-maze", "prompt": "def nearestExit(maze: List[List[str]], entrance: List[int]) -> int:\n \"\"\"\n You are given an m x n matrix maze (0-indexed) with empty cells (represented as '.') and walls (represented as '+'). You are also given the entrance of the maze, where entrance = [entrancerow, entrancecol] denotes the row and column of the cell you are initially standing at.\n In one step, you can move one cell up, down, left, or right. You cannot step into a cell with a wall, and you cannot step outside the maze. Your goal is to find the nearest exit from the entrance. An exit is defined as an empty cell that is at the border of the maze. The entrance does not count as an exit.\n Return the number of steps in the shortest path from the entrance to the nearest exit, or -1 if no such path exists.\n \n Example 1:\n \n \n >>> nearestExit(maze = [[\"+\",\"+\",\".\",\"+\"],[\".\",\".\",\".\",\"+\"],[\"+\",\"+\",\"+\",\".\"]], entrance = [1,2])\n >>> 1\n Explanation: There are 3 exits in this maze at [1,0], [0,2], and [2,3].\n Initially, you are at the entrance cell [1,2].\n - You can reach [1,0] by moving 2 steps left.\n - You can reach [0,2] by moving 1 step up.\n It is impossible to reach [2,3] from the entrance.\n Thus, the nearest exit is [0,2], which is 1 step away.\n \n Example 2:\n \n \n >>> nearestExit(maze = [[\"+\",\"+\",\"+\"],[\".\",\".\",\".\"],[\"+\",\"+\",\"+\"]], entrance = [1,0])\n >>> 2\n Explanation: There is 1 exit in this maze at [1,2].\n [1,0] does not count as an exit since it is the entrance cell.\n Initially, you are at the entrance cell [1,0].\n - You can reach [1,2] by moving 2 steps right.\n Thus, the nearest exit is [1,2], which is 2 steps away.\n \n Example 3:\n \n \n >>> nearestExit(maze = [[\".\",\"+\"]], entrance = [0,0])\n >>> -1\n Explanation: There are no exits in this maze.\n \"\"\"\n"}
{"task_id": "sum-game", "prompt": "def sumGame(num: str) -> bool:\n \"\"\"\n Alice and Bob take turns playing a game, with Alice\u00a0starting first.\n You are given a string num of even length consisting of digits and '?' characters. On each turn, a player will do the following if there is still at least one '?' in num:\n \n Choose an index i where num[i] == '?'.\n Replace num[i] with any digit between '0' and '9'.\n \n The game ends when there are no more '?' characters in num.\n For Bob\u00a0to win, the sum of the digits in the first half of num must be equal to the sum of the digits in the second half. For Alice\u00a0to win, the sums must not be equal.\n \n For example, if the game ended with num = \"243801\", then Bob\u00a0wins because 2+4+3 = 8+0+1. If the game ended with num = \"243803\", then Alice\u00a0wins because 2+4+3 != 8+0+3.\n \n Assuming Alice and Bob play optimally, return true if Alice will win and false if Bob will win.\n \n Example 1:\n \n >>> sumGame(num = \"5023\")\n >>> false\n Explanation: There are no moves to be made.\n The sum of the first half is equal to the sum of the second half: 5 + 0 = 2 + 3.\n \n Example 2:\n \n >>> sumGame(num = \"25??\")\n >>> true\n Explanation: Alice can replace one of the '?'s with '9' and it will be impossible for Bob to make the sums equal.\n \n Example 3:\n \n >>> sumGame(num = \"?3295???\")\n >>> false\n Explanation: It can be proven that Bob will always win. One possible outcome is:\n - Alice replaces the first '?' with '9'. num = \"93295???\".\n - Bob replaces one of the '?' in the right half with '9'. num = \"932959??\".\n - Alice replaces one of the '?' in the right half with '2'. num = \"9329592?\".\n - Bob replaces the last '?' in the right half with '7'. num = \"93295927\".\n Bob wins because 9 + 3 + 2 + 9 = 5 + 9 + 2 + 7.\n \"\"\"\n"}
{"task_id": "minimum-cost-to-reach-destination-in-time", "prompt": "def minCost(maxTime: int, edges: List[List[int]], passingFees: List[int]) -> int:\n \"\"\"\n There is a country of n cities numbered from 0 to n - 1 where all the cities are connected by bi-directional roads. The roads are represented as a 2D integer array edges where edges[i] = [xi, yi, timei] denotes a road between cities xi and yi that takes timei minutes to travel. There may be multiple roads of differing travel times connecting the same two cities, but no road connects a city to itself.\n Each time you pass through a city, you must pay a passing fee. This is represented as a 0-indexed integer array passingFees of length n where passingFees[j] is the amount of dollars you must pay when you pass through city j.\n In the beginning, you are at city 0 and want to reach city n - 1 in maxTime minutes or less. The cost of your journey is the summation of passing fees for each city that you passed through at some moment of your journey (including the source and destination cities).\n Given maxTime, edges, and passingFees, return the minimum cost to complete your journey, or -1 if you cannot complete it within maxTime minutes.\n \n Example 1:\n \n \n >>> minCost(maxTime = 30, edges = [[0,1,10],[1,2,10],[2,5,10],[0,3,1],[3,4,10],[4,5,15]], passingFees = [5,1,2,20,20,3])\n >>> 11\n Explanation: The path to take is 0 -> 1 -> 2 -> 5, which takes 30 minutes and has $11 worth of passing fees.\n \n Example 2:\n \n \n >>> minCost(maxTime = 29, edges = [[0,1,10],[1,2,10],[2,5,10],[0,3,1],[3,4,10],[4,5,15]], passingFees = [5,1,2,20,20,3])\n >>> 48\n Explanation: The path to take is 0 -> 3 -> 4 -> 5, which takes 26 minutes and has $48 worth of passing fees.\n You cannot take path 0 -> 1 -> 2 -> 5 since it would take too long.\n \n Example 3:\n \n >>> minCost(maxTime = 25, edges = [[0,1,10],[1,2,10],[2,5,10],[0,3,1],[3,4,10],[4,5,15]], passingFees = [5,1,2,20,20,3])\n >>> -1\n Explanation: There is no way to reach city 5 from city 0 within 25 minutes.\n \"\"\"\n"}
{"task_id": "concatenation-of-array", "prompt": "def getConcatenation(nums: List[int]) -> List[int]:\n \"\"\"\n Given an integer array nums of length n, you want to create an array ans of length 2n where ans[i] == nums[i] and ans[i + n] == nums[i] for 0 <= i < n (0-indexed).\n Specifically, ans is the concatenation of two nums arrays.\n Return the array ans.\n \n Example 1:\n \n >>> getConcatenation(nums = [1,2,1])\n >>> [1,2,1,1,2,1]\n Explanation: The array ans is formed as follows:\n - ans = [nums[0],nums[1],nums[2],nums[0],nums[1],nums[2]]\n - ans = [1,2,1,1,2,1]\n Example 2:\n \n >>> getConcatenation(nums = [1,3,2,1])\n >>> [1,3,2,1,1,3,2,1]\n Explanation: The array ans is formed as follows:\n - ans = [nums[0],nums[1],nums[2],nums[3],nums[0],nums[1],nums[2],nums[3]]\n - ans = [1,3,2,1,1,3,2,1]\n \"\"\"\n"}
{"task_id": "unique-length-3-palindromic-subsequences", "prompt": "def countPalindromicSubsequence(s: str) -> int:\n \"\"\"\n Given a string s, return the number of unique palindromes of length three that are a subsequence of s.\n Note that even if there are multiple ways to obtain the same subsequence, it is still only counted once.\n A palindrome is a string that reads the same forwards and backwards.\n 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.\n \n For example, \"ace\" is a subsequence of \"abcde\".\n \n \n Example 1:\n \n >>> countPalindromicSubsequence(s = \"aabca\")\n >>> 3\n Explanation: The 3 palindromic subsequences of length 3 are:\n - \"aba\" (subsequence of \"aabca\")\n - \"aaa\" (subsequence of \"aabca\")\n - \"aca\" (subsequence of \"aabca\")\n \n Example 2:\n \n >>> countPalindromicSubsequence(s = \"adc\")\n >>> 0\n Explanation: There are no palindromic subsequences of length 3 in \"adc\".\n \n Example 3:\n \n >>> countPalindromicSubsequence(s = \"bbcbaba\")\n >>> 4\n Explanation: The 4 palindromic subsequences of length 3 are:\n - \"bbb\" (subsequence of \"bbcbaba\")\n - \"bcb\" (subsequence of \"bbcbaba\")\n - \"bab\" (subsequence of \"bbcbaba\")\n - \"aba\" (subsequence of \"bbcbaba\")\n \"\"\"\n"}
{"task_id": "painting-a-grid-with-three-different-colors", "prompt": "def colorTheGrid(m: int, n: int) -> int:\n \"\"\"\n You are given two integers m and n. Consider an m x n grid where each cell is initially white. You can paint each cell red, green, or blue. All cells must be painted.\n Return the number of ways to color the grid with no two adjacent cells having the same color. Since the answer can be very large, return it modulo 109 + 7.\n \n Example 1:\n \n \n >>> colorTheGrid(m = 1, n = 1)\n >>> 3\n Explanation: The three possible colorings are shown in the image above.\n \n Example 2:\n \n \n >>> colorTheGrid(m = 1, n = 2)\n >>> 6\n Explanation: The six possible colorings are shown in the image above.\n \n Example 3:\n \n >>> colorTheGrid(m = 5, n = 5)\n >>> 580986\n \"\"\"\n"}
{"task_id": "check-if-string-is-decomposable-into-value-equal-substrings", "prompt": "def isDecomposable(s: str) -> bool:\n \"\"\"\n A value-equal string is a string where all characters are the same.\n \n For example, \"1111\" and \"33\" are value-equal strings.\n In contrast, \"123\" is not a value-equal string.\n \n Given a digit string s, decompose the string into some number of consecutive value-equal substrings where exactly one substring has a length of 2 and the remaining substrings have a length of 3.\n Return true if you can decompose s according to the above rules. Otherwise, return false.\n A substring is a contiguous sequence of characters in a string.\n \n Example 1:\n \n >>> isDecomposable(s = \"000111000\")\n >>> false\n Explanation: s cannot be decomposed according to the rules because [\"000\", \"111\", \"000\"] does not have a substring of length 2.\n \n Example 2:\n \n >>> isDecomposable(s = \"00011111222\")\n >>> true\n Explanation: s can be decomposed into [\"000\", \"111\", \"11\", \"222\"].\n \n Example 3:\n \n >>> isDecomposable(s = \"011100022233\")\n >>> false\n Explanation: s cannot be decomposed according to the rules because of the first '0'.\n \"\"\"\n"}
{"task_id": "maximum-number-of-words-you-can-type", "prompt": "def canBeTypedWords(text: str, brokenLetters: str) -> int:\n \"\"\"\n There is a malfunctioning keyboard where some letter keys do not work. All other keys on the keyboard work properly.\n Given a string text of words separated by a single space (no leading or trailing spaces) and a string brokenLetters of all distinct letter keys that are broken, return the number of words in text you can fully type using this keyboard.\n \n Example 1:\n \n >>> canBeTypedWords(text = \"hello world\", brokenLetters = \"ad\")\n >>> 1\n Explanation: We cannot type \"world\" because the 'd' key is broken.\n \n Example 2:\n \n >>> canBeTypedWords(text = \"leet code\", brokenLetters = \"lt\")\n >>> 1\n Explanation: We cannot type \"leet\" because the 'l' and 't' keys are broken.\n \n Example 3:\n \n >>> canBeTypedWords(text = \"leet code\", brokenLetters = \"e\")\n >>> 0\n Explanation: We cannot type either word because the 'e' key is broken.\n \"\"\"\n"}
{"task_id": "add-minimum-number-of-rungs", "prompt": "def addRungs(rungs: List[int], dist: int) -> int:\n \"\"\"\n You are given a strictly increasing integer array rungs that represents the height of rungs on a ladder. You are currently on the floor at height 0, and you want to reach the last rung.\n You are also given an integer dist. You can only climb to the next highest rung if the distance between where you are currently at (the floor or on a rung) and the next rung is at most dist. You are able to insert rungs at any positive integer height if a rung is not already there.\n Return the minimum number of rungs that must be added to the ladder in order for you to climb to the last rung.\n \n Example 1:\n \n >>> addRungs(rungs = [1,3,5,10], dist = 2)\n >>> 2\n Explanation:\n You currently cannot reach the last rung.\n Add rungs at heights 7 and 8 to climb this ladder.\n The ladder will now have rungs at [1,3,5,7,8,10].\n \n Example 2:\n \n >>> addRungs(rungs = [3,6,8,10], dist = 3)\n >>> 0\n Explanation:\n This ladder can be climbed without adding additional rungs.\n \n Example 3:\n \n >>> addRungs(rungs = [3,4,6,7], dist = 2)\n >>> 1\n Explanation:\n You currently cannot reach the first rung from the ground.\n Add a rung at height 1 to climb this ladder.\n The ladder will now have rungs at [1,3,4,6,7].\n \"\"\"\n"}
{"task_id": "maximum-number-of-points-with-cost", "prompt": "def maxPoints(points: List[List[int]]) -> int:\n \"\"\"\n You are given an m x n integer matrix points (0-indexed). Starting with 0 points, you want to maximize the number of points you can get from the matrix.\n To gain points, you must pick one cell in each row. Picking the cell at coordinates (r, c) will add points[r][c] to your score.\n However, you will lose points if you pick a cell too far from the cell that you picked in the previous row. For every two adjacent rows r and r + 1 (where 0 <= r < m - 1), picking cells at coordinates (r, c1) and (r + 1, c2) will subtract abs(c1 - c2) from your score.\n Return the maximum number of points you can achieve.\n abs(x) is defined as:\n \n x for x >= 0.\n -x for x < 0.\n \n \n Example 1:\n \n \n >>> maxPoints(points = [[1,2,3],[1,5,1],[3,1,1]])\n >>> 9\n Explanation:\n The blue cells denote the optimal cells to pick, which have coordinates (0, 2), (1, 1), and (2, 0).\n You add 3 + 5 + 3 = 11 to your score.\n However, you must subtract abs(2 - 1) + abs(1 - 0) = 2 from your score.\n Your final score is 11 - 2 = 9.\n \n Example 2:\n \n \n >>> maxPoints(points = [[1,5],[2,3],[4,2]])\n >>> 11\n Explanation:\n The blue cells denote the optimal cells to pick, which have coordinates (0, 1), (1, 1), and (2, 0).\n You add 5 + 3 + 4 = 12 to your score.\n However, you must subtract abs(1 - 1) + abs(1 - 0) = 1 from your score.\n Your final score is 12 - 1 = 11.\n \"\"\"\n"}
{"task_id": "maximum-genetic-difference-query", "prompt": "def maxGeneticDifference(parents: List[int], queries: List[List[int]]) -> List[int]:\n \"\"\"\n There is a rooted tree consisting of n nodes numbered 0 to n - 1. Each node's number denotes its unique genetic value (i.e. the genetic value of node x is x). The genetic difference between two genetic values is defined as the bitwise-XOR of their values. You are given the integer array parents, where parents[i] is the parent for node i. If node x is the root of the tree, then parents[x] == -1.\n You are also given the array queries where queries[i] = [nodei, vali]. For each query i, find the maximum genetic difference between vali and pi, where pi is the genetic value of any node that is on the path between nodei and the root (including nodei and the root). More formally, you want to maximize vali XOR pi.\n Return an array ans where ans[i] is the answer to the ith query.\n \n Example 1:\n \n \n >>> maxGeneticDifference(parents = [-1,0,1,1], queries = [[0,2],[3,2],[2,5]])\n >>> [2,3,7]\n Explanation: The queries are processed as follows:\n - [0,2]: The node with the maximum genetic difference is 0, with a difference of 2 XOR 0 = 2.\n - [3,2]: The node with the maximum genetic difference is 1, with a difference of 2 XOR 1 = 3.\n - [2,5]: The node with the maximum genetic difference is 2, with a difference of 5 XOR 2 = 7.\n \n Example 2:\n \n \n >>> maxGeneticDifference(parents = [3,7,-1,2,0,7,0,2], queries = [[4,6],[1,15],[0,5]])\n >>> [6,14,7]\n Explanation: The queries are processed as follows:\n - [4,6]: The node with the maximum genetic difference is 0, with a difference of 6 XOR 0 = 6.\n - [1,15]: The node with the maximum genetic difference is 1, with a difference of 15 XOR 1 = 14.\n - [0,5]: The node with the maximum genetic difference is 2, with a difference of 5 XOR 2 = 7.\n \"\"\"\n"}
{"task_id": "longest-common-subsequence-between-sorted-arrays", "prompt": "def longestCommonSubsequence(arrays: List[List[int]]) -> List[int]:\n \"\"\"\n Given an array of integer arrays arrays where each arrays[i] is sorted in strictly increasing order, return an integer array representing the longest common subsequence among\u00a0all the arrays.\n A subsequence is a sequence that can be derived from another sequence by deleting some elements (possibly none) without changing the order of the remaining elements.\n \n Example 1:\n \n [1,4,7,9]]\n >>> longestCommonSubsequence(arrays = [[1,3,4],)\n >>> [1,4]\n Explanation: The longest common subsequence in the two arrays is [1,4].\n \n Example 2:\n \n [1,2,3,5,6,7,10],\n [2,3,4,6,9]]\n >>> longestCommonSubsequence(arrays = [[2,3,6,8],)\n >>> [2,3,6]\n Explanation: The longest common subsequence in all three arrays is [2,3,6].\n \n Example 3:\n \n [6,7,8]]\n >>> longestCommonSubsequence(arrays = [[1,2,3,4,5],)\n >>> []\n Explanation: There is no common subsequence between the two arrays.\n \"\"\"\n"}
{"task_id": "check-if-all-characters-have-equal-number-of-occurrences", "prompt": "def areOccurrencesEqual(s: str) -> bool:\n \"\"\"\n Given a string s, return true if s is a good string, or false otherwise.\n A string s is good if all the characters that appear in s have the same number of occurrences (i.e., the same frequency).\n \n Example 1:\n \n >>> areOccurrencesEqual(s = \"abacbc\")\n >>> true\n Explanation: The characters that appear in s are 'a', 'b', and 'c'. All characters occur 2 times in s.\n \n Example 2:\n \n >>> areOccurrencesEqual(s = \"aaabb\")\n >>> false\n Explanation: The characters that appear in s are 'a' and 'b'.\n 'a' occurs 3 times while 'b' occurs 2 times, which is not the same number of times.\n \"\"\"\n"}
{"task_id": "the-number-of-the-smallest-unoccupied-chair", "prompt": "def smallestChair(times: List[List[int]], targetFriend: int) -> int:\n \"\"\"\n There is a party where n friends numbered from 0 to n - 1 are attending. There is an infinite number of chairs in this party that are numbered from 0 to infinity. When a friend arrives at the party, they sit on the unoccupied chair with the smallest number.\n \n For example, if chairs 0, 1, and 5 are occupied when a friend comes, they will sit on chair number 2.\n \n When a friend leaves the party, their chair becomes unoccupied at the moment they leave. If another friend arrives at that same moment, they can sit in that chair.\n You are given a 0-indexed 2D integer array times where times[i] = [arrivali, leavingi], indicating the arrival and leaving times of the ith friend respectively, and an integer targetFriend. All arrival times are distinct.\n Return the chair number that the friend numbered targetFriend will sit on.\n \n Example 1:\n \n >>> smallestChair(times = [[1,4],[2,3],[4,6]], targetFriend = 1)\n >>> 1\n Explanation:\n - Friend 0 arrives at time 1 and sits on chair 0.\n - Friend 1 arrives at time 2 and sits on chair 1.\n - Friend 1 leaves at time 3 and chair 1 becomes empty.\n - Friend 0 leaves at time 4 and chair 0 becomes empty.\n - Friend 2 arrives at time 4 and sits on chair 0.\n Since friend 1 sat on chair 1, we return 1.\n \n Example 2:\n \n >>> smallestChair(times = [[3,10],[1,5],[2,6]], targetFriend = 0)\n >>> 2\n Explanation:\n - Friend 1 arrives at time 1 and sits on chair 0.\n - Friend 2 arrives at time 2 and sits on chair 1.\n - Friend 0 arrives at time 3 and sits on chair 2.\n - Friend 1 leaves at time 5 and chair 0 becomes empty.\n - Friend 2 leaves at time 6 and chair 1 becomes empty.\n - Friend 0 leaves at time 10 and chair 2 becomes empty.\n Since friend 0 sat on chair 2, we return 2.\n \"\"\"\n"}
{"task_id": "describe-the-painting", "prompt": "def splitPainting(segments: List[List[int]]) -> List[List[int]]:\n \"\"\"\n There is a long and thin painting that can be represented by a number line. The painting was painted with multiple overlapping segments where each segment was painted with a unique color. You are given a 2D integer array segments, where segments[i] = [starti, endi, colori] represents the half-closed segment [starti, endi) with colori as the color.\n The colors in the overlapping segments of the painting were mixed when it was painted. When two or more colors mix, they form a new color that can be represented as a set of mixed colors.\n \n For example, if colors 2, 4, and 6 are mixed, then the resulting mixed color is {2,4,6}.\n \n For the sake of simplicity, you should only output the sum of the elements in the set rather than the full set.\n You want to describe the painting with the minimum number of non-overlapping half-closed segments of these mixed colors. These segments can be represented by the 2D array painting where painting[j] = [leftj, rightj, mixj] describes a half-closed segment [leftj, rightj) with the mixed color sum of mixj.\n \n For example, the painting created with segments = [[1,4,5],[1,7,7]] can be described by painting = [[1,4,12],[4,7,7]] because:\n \n \n [1,4) is colored {5,7} (with a sum of 12) from both the first and second segments.\n [4,7) is colored {7} from only the second segment.\n \n \n \n Return the 2D array painting describing the finished painting (excluding any parts that are not painted). You may return the segments in any order.\n A half-closed segment [a, b) is the section of the number line between points a and b including point a and not including point b.\n \n Example 1:\n \n \n >>> splitPainting(segments = [[1,4,5],[4,7,7],[1,7,9]])\n >>> [[1,4,14],[4,7,16]]\n Explanation: The painting can be described as follows:\n - [1,4) is colored {5,9} (with a sum of 14) from the first and third segments.\n - [4,7) is colored {7,9} (with a sum of 16) from the second and third segments.\n \n Example 2:\n \n \n >>> splitPainting(segments = [[1,7,9],[6,8,15],[8,10,7]])\n >>> [[1,6,9],[6,7,24],[7,8,15],[8,10,7]]\n Explanation: The painting can be described as follows:\n - [1,6) is colored 9 from the first segment.\n - [6,7) is colored {9,15} (with a sum of 24) from the first and second segments.\n - [7,8) is colored 15 from the second segment.\n - [8,10) is colored 7 from the third segment.\n \n Example 3:\n \n \n >>> splitPainting(segments = [[1,4,5],[1,4,7],[4,7,1],[4,7,11]])\n >>> [[1,4,12],[4,7,12]]\n Explanation: The painting can be described as follows:\n - [1,4) is colored {5,7} (with a sum of 12) from the first and second segments.\n - [4,7) is colored {1,11} (with a sum of 12) from the third and fourth segments.\n Note that returning a single segment [1,7) is incorrect because the mixed color sets are different.\n \"\"\"\n"}
{"task_id": "number-of-visible-people-in-a-queue", "prompt": "def canSeePersonsCount(heights: List[int]) -> List[int]:\n \"\"\"\n There are n people standing in a queue, and they numbered from 0 to n - 1 in left to right order. You are given an array heights of distinct integers where heights[i] represents the height of the ith person.\n A person can see another person to their right in the queue if everybody in between is shorter than both of them. More formally, the ith person can see the jth person if i < j and min(heights[i], heights[j]) > max(heights[i+1], heights[i+2], ..., heights[j-1]).\n Return an array answer of length n where answer[i] is the number of people the ith person can see to their right in the queue.\n \n Example 1:\n \n \n >>> canSeePersonsCount(heights = [10,6,8,5,11,9])\n >>> [3,1,2,1,1,0]\n Explanation:\n Person 0 can see person 1, 2, and 4.\n Person 1 can see person 2.\n Person 2 can see person 3 and 4.\n Person 3 can see person 4.\n Person 4 can see person 5.\n Person 5 can see no one since nobody is to the right of them.\n \n Example 2:\n \n >>> canSeePersonsCount(heights = [5,1,2,3,10])\n >>> [4,1,1,1,0]\n \"\"\"\n"}
{"task_id": "sum-of-digits-of-string-after-convert", "prompt": "def getLucky(s: str, k: int) -> int:\n \"\"\"\n You are given a string s consisting of lowercase English letters, and an integer k. Your task is to convert the string into an integer by a special process, and then transform it by summing its digits repeatedly k times. More specifically, perform the following steps:\n \n Convert s into an integer by replacing each letter with its position in the alphabet (i.e.\u00a0replace 'a' with 1, 'b' with 2, ..., 'z' with 26).\n Transform the integer by replacing it with the sum of its digits.\n Repeat the transform operation (step 2) k times in total.\n \n For example, if s = \"zbax\" and k = 2, then the resulting integer would be 8 by the following operations:\n \n Convert: \"zbax\" \u279d \"(26)(2)(1)(24)\" \u279d \"262124\" \u279d 262124\n Transform #1: 262124 \u279d 2 + 6 + 2 + 1 + 2 + 4 \u279d 17\n Transform #2: 17 \u279d 1 + 7 \u279d 8\n \n Return the resulting integer after performing the operations described above.\n \n Example 1:\n \n >>> getLucky(s = \"iiii\", k = 1)\n >>> 36\n Explanation:\n The operations are as follows:\n - Convert: \"iiii\" \u279d \"(9)(9)(9)(9)\" \u279d \"9999\" \u279d 9999\n - Transform #1: 9999 \u279d 9 + 9 + 9 + 9 \u279d 36\n Thus the resulting integer is 36.\n \n Example 2:\n \n >>> getLucky(s = \"leetcode\", k = 2)\n >>> 6\n Explanation:\n The operations are as follows:\n - Convert: \"leetcode\" \u279d \"(12)(5)(5)(20)(3)(15)(4)(5)\" \u279d \"12552031545\" \u279d 12552031545\n - Transform #1: 12552031545 \u279d 1 + 2 + 5 + 5 + 2 + 0 + 3 + 1 + 5 + 4 + 5 \u279d 33\n - Transform #2: 33 \u279d 3 + 3 \u279d 6\n Thus the resulting integer is 6.\n \n Example 3:\n \n >>> getLucky(s = \"zbax\", k = 2)\n >>> 8\n \"\"\"\n"}
{"task_id": "largest-number-after-mutating-substring", "prompt": "def maximumNumber(num: str, change: List[int]) -> str:\n \"\"\"\n You are given a string num, which represents a large integer. You are also given a 0-indexed integer array change of length 10 that maps each digit 0-9 to another digit. More formally, digit d maps to digit change[d].\n You may choose to mutate a single substring of num. To mutate a substring, replace each digit num[i] with the digit it maps to in change (i.e. replace num[i] with change[num[i]]).\n Return a string representing the largest possible integer after mutating (or choosing not to) a single substring of num.\n A substring is a contiguous sequence of characters within the string.\n \n Example 1:\n \n >>> maximumNumber(num = \"132\", change = [9,8,5,0,3,6,4,2,6,8])\n >>> \"832\"\n Explanation: Replace the substring \"1\":\n - 1 maps to change[1] = 8.\n Thus, \"132\" becomes \"832\".\n \"832\" is the largest number that can be created, so return it.\n \n Example 2:\n \n >>> maximumNumber(num = \"021\", change = [9,4,3,5,7,2,1,9,0,6])\n >>> \"934\"\n Explanation: Replace the substring \"021\":\n - 0 maps to change[0] = 9.\n - 2 maps to change[2] = 3.\n - 1 maps to change[1] = 4.\n Thus, \"021\" becomes \"934\".\n \"934\" is the largest number that can be created, so return it.\n \n Example 3:\n \n >>> maximumNumber(num = \"5\", change = [1,4,7,5,3,2,5,6,9,4])\n >>> \"5\"\n Explanation: \"5\" is already the largest number that can be created, so return it.\n \"\"\"\n"}
{"task_id": "maximum-compatibility-score-sum", "prompt": "def maxCompatibilitySum(students: List[List[int]], mentors: List[List[int]]) -> int:\n \"\"\"\n There is a survey that consists of n questions where each question's answer is either 0 (no) or 1 (yes).\n The survey was given to m students numbered from 0 to m - 1 and m mentors numbered from 0 to m - 1. The answers of the students are represented by a 2D integer array students where students[i] is an integer array that contains the answers of the ith student (0-indexed). The answers of the mentors are represented by a 2D integer array mentors where mentors[j] is an integer array that contains the answers of the jth mentor (0-indexed).\n Each student will be assigned to one mentor, and each mentor will have one student assigned to them. The compatibility score of a student-mentor pair is the number of answers that are the same for both the student and the mentor.\n \n For example, if the student's answers were [1, 0, 1] and the mentor's answers were [0, 0, 1], then their compatibility score is 2 because only the second and the third answers are the same.\n \n You are tasked with finding the optimal student-mentor pairings to maximize the sum of the compatibility scores.\n Given students and mentors, return the maximum compatibility score sum that can be achieved.\n \n Example 1:\n \n >>> maxCompatibilitySum(students = [[1,1,0],[1,0,1],[0,0,1]], mentors = [[1,0,0],[0,0,1],[1,1,0]])\n >>> 8\n Explanation:\u00a0We assign students to mentors in the following way:\n - student 0 to mentor 2 with a compatibility score of 3.\n - student 1 to mentor 0 with a compatibility score of 2.\n - student 2 to mentor 1 with a compatibility score of 3.\n The compatibility score sum is 3 + 2 + 3 = 8.\n \n Example 2:\n \n >>> maxCompatibilitySum(students = [[0,0],[0,0],[0,0]], mentors = [[1,1],[1,1],[1,1]])\n >>> 0\n Explanation: The compatibility score of any student-mentor pair is 0.\n \"\"\"\n"}
{"task_id": "delete-duplicate-folders-in-system", "prompt": "def deleteDuplicateFolder(paths: List[List[str]]) -> List[List[str]]:\n \"\"\"\n Due to a bug, there are many duplicate folders in a file system. You are given a 2D array paths, where paths[i] is an array representing an absolute path to the ith folder in the file system.\n \n For example, [\"one\", \"two\", \"three\"] represents the path \"/one/two/three\".\n \n Two folders (not necessarily on the same level) are identical if they contain the same non-empty set of identical subfolders and underlying subfolder structure. The folders do not need to be at the root level to be identical. If two or more folders are identical, then mark the folders as well as all their subfolders.\n \n For example, folders \"/a\" and \"/b\" in the file structure below are identical. They (as well as their subfolders) should all be marked:\n \n \n /a\n /a/x\n /a/x/y\n /a/z\n /b\n /b/x\n /b/x/y\n /b/z\n \n \n However, if the file structure also included the path \"/b/w\", then the folders \"/a\" and \"/b\" would not be identical. Note that \"/a/x\" and \"/b/x\" would still be considered identical even with the added folder.\n \n Once all the identical folders and their subfolders have been marked, the file system will delete all of them. The file system only runs the deletion once, so any folders that become identical after the initial deletion are not deleted.\n Return the 2D array ans containing the paths of the remaining folders after deleting all the marked folders. The paths may be returned in any order.\n \n Example 1:\n \n \n >>> deleteDuplicateFolder(paths = [[\"a\"],[\"c\"],[\"d\"],[\"a\",\"b\"],[\"c\",\"b\"],[\"d\",\"a\"]])\n >>> [[\"d\"],[\"d\",\"a\"]]\n Explanation: The file structure is as shown.\n Folders \"/a\" and \"/c\" (and their subfolders) are marked for deletion because they both contain an empty\n folder named \"b\".\n \n Example 2:\n \n \n >>> deleteDuplicateFolder(paths = [[\"a\"],[\"c\"],[\"a\",\"b\"],[\"c\",\"b\"],[\"a\",\"b\",\"x\"],[\"a\",\"b\",\"x\",\"y\"],[\"w\"],[\"w\",\"y\"]])\n >>> [[\"c\"],[\"c\",\"b\"],[\"a\"],[\"a\",\"b\"]]\n Explanation: The file structure is as shown.\n Folders \"/a/b/x\" and \"/w\" (and their subfolders) are marked for deletion because they both contain an empty folder named \"y\".\n Note that folders \"/a\" and \"/c\" are identical after the deletion, but they are not deleted because they were not marked beforehand.\n \n Example 3:\n \n \n >>> deleteDuplicateFolder(paths = [[\"a\",\"b\"],[\"c\",\"d\"],[\"c\"],[\"a\"]])\n >>> [[\"c\"],[\"c\",\"d\"],[\"a\"],[\"a\",\"b\"]]\n Explanation: All folders are unique in the file system.\n Note that the returned array can be in a different order as the order does not matter.\n \"\"\"\n"}
{"task_id": "maximum-of-minimum-values-in-all-subarrays", "prompt": "def findMaximums(nums: List[int]) -> List[int]:\n \"\"\"\n You are given an integer array nums of size n. You are asked to solve n queries for each integer i in the range 0 <= i < n.\n To solve the ith query:\n \n Find the minimum value in each possible subarray of size i + 1 of the array nums.\n Find the maximum of those minimum values. This maximum is the answer to the query.\n \n Return a 0-indexed integer array ans of size n such that ans[i] is the answer to the ith query.\n A subarray is a contiguous sequence of elements in an array.\n \n Example 1:\n \n >>> findMaximums(nums = [0,1,2,4])\n >>> [4,2,1,0]\n Explanation:\n i=0:\n - The subarrays of size 1 are [0], [1], [2], [4]. The minimum values are 0, 1, 2, 4.\n - The maximum of the minimum values is 4.\n i=1:\n - The subarrays of size 2 are [0,1], [1,2], [2,4]. The minimum values are 0, 1, 2.\n - The maximum of the minimum values is 2.\n i=2:\n - The subarrays of size 3 are [0,1,2], [1,2,4]. The minimum values are 0, 1.\n - The maximum of the minimum values is 1.\n i=3:\n - There is one subarray of size 4, which is [0,1,2,4]. The minimum value is 0.\n - There is only one value, so the maximum is 0.\n \n Example 2:\n \n >>> findMaximums(nums = [10,20,50,10])\n >>> [50,20,10,10]\n Explanation:\n i=0:\n - The subarrays of size 1 are [10], [20], [50], [10]. The minimum values are 10, 20, 50, 10.\n - The maximum of the minimum values is 50.\n i=1:\n - The subarrays of size 2 are [10,20], [20,50], [50,10]. The minimum values are 10, 20, 10.\n - The maximum of the minimum values is 20.\n i=2:\n - The subarrays of size 3 are [10,20,50], [20,50,10]. The minimum values are 10, 10.\n - The maximum of the minimum values is 10.\n i=3:\n - There is one subarray of size 4, which is [10,20,50,10]. The minimum value is 10.\n - There is only one value, so the maximum is 10.\n \"\"\"\n"}
{"task_id": "three-divisors", "prompt": "def isThree(n: int) -> bool:\n \"\"\"\n Given an integer n, return true if n has exactly three positive divisors. Otherwise, return false.\n An integer m is a divisor of n if there exists an integer k such that n = k * m.\n \n Example 1:\n \n >>> isThree(n = 2)\n >>> false\n Explantion: 2 has only two divisors: 1 and 2.\n \n Example 2:\n \n >>> isThree(n = 4)\n >>> true\n Explantion: 4 has three divisors: 1, 2, and 4.\n \"\"\"\n"}
{"task_id": "maximum-number-of-weeks-for-which-you-can-work", "prompt": "def numberOfWeeks(milestones: List[int]) -> int:\n \"\"\"\n There are n projects numbered from 0 to n - 1. You are given an integer array milestones where each milestones[i] denotes the number of milestones the ith project has.\n You can work on the projects following these two rules:\n \n Every week, you will finish exactly one milestone of one project. You\u00a0must\u00a0work every week.\n You cannot work on two milestones from the same project for two consecutive weeks.\n \n Once all the milestones of all the projects are finished, or if the only milestones that you can work on will cause you to violate the above rules, you will stop working. Note that you may not be able to finish every project's milestones due to these constraints.\n Return the maximum number of weeks you would be able to work on the projects without violating the rules mentioned above.\n \n Example 1:\n \n >>> numberOfWeeks(milestones = [1,2,3])\n >>> 6\n Explanation: One possible scenario is:\n \u200b\u200b\u200b\u200b- During the 1st week, you will work on a milestone of project 0.\n - During the 2nd week, you will work on a milestone of project 2.\n - During the 3rd week, you will work on a milestone of project 1.\n - During the 4th week, you will work on a milestone of project 2.\n - During the 5th week, you will work on a milestone of project 1.\n - During the 6th week, you will work on a milestone of project 2.\n The total number of weeks is 6.\n \n Example 2:\n \n >>> numberOfWeeks(milestones = [5,2,1])\n >>> 7\n Explanation: One possible scenario is:\n - During the 1st week, you will work on a milestone of project 0.\n - During the 2nd week, you will work on a milestone of project 1.\n - During the 3rd week, you will work on a milestone of project 0.\n - During the 4th week, you will work on a milestone of project 1.\n - During the 5th week, you will work on a milestone of project 0.\n - During the 6th week, you will work on a milestone of project 2.\n - During the 7th week, you will work on a milestone of project 0.\n The total number of weeks is 7.\n Note that you cannot work on the last milestone of project 0 on 8th week because it would violate the rules.\n Thus, one milestone in project 0 will remain unfinished.\n \"\"\"\n"}
{"task_id": "minimum-garden-perimeter-to-collect-enough-apples", "prompt": "def minimumPerimeter(neededApples: int) -> int:\n \"\"\"\n In a garden represented as an infinite 2D grid, there is an apple tree planted at every integer coordinate. The apple tree planted at an integer coordinate (i, j) has |i| + |j| apples growing on it.\n You will buy an axis-aligned square plot of land that is centered at (0, 0).\n Given an integer neededApples, return the minimum perimeter of a plot such that at least neededApples apples are inside or on the perimeter of that plot.\n The value of |x| is defined as:\n \n x if x >= 0\n -x if x < 0\n \n \n Example 1:\n \n \n >>> minimumPerimeter(neededApples = 1)\n >>> 8\n Explanation: A square plot of side length 1 does not contain any apples.\n However, a square plot of side length 2 has 12 apples inside (as depicted in the image above).\n The perimeter is 2 * 4 = 8.\n \n Example 2:\n \n >>> minimumPerimeter(neededApples = 13)\n >>> 16\n \n Example 3:\n \n >>> minimumPerimeter(neededApples = 1000000000)\n >>> 5040\n \"\"\"\n"}
{"task_id": "count-number-of-special-subsequences", "prompt": "def countSpecialSubsequences(nums: List[int]) -> int:\n \"\"\"\n A sequence is special if it consists of a positive number of 0s, followed by a positive number of 1s, then a positive number of 2s.\n \n For example, [0,1,2] and [0,0,1,1,1,2] are special.\n In contrast, [2,1,0], [1], and [0,1,2,0] are not special.\n \n Given an array nums (consisting of only integers 0, 1, and 2), return the number of different subsequences that are special. Since the answer may be very large, return it modulo 109 + 7.\n A subsequence of an array is a sequence that can be derived from the array by deleting some or no elements without changing the order of the remaining elements. Two subsequences are different if the set of indices chosen are different.\n \n Example 1:\n \n >>> countSpecialSubsequences(nums = [0,1,2,2])\n >>> 3\n Explanation: The special subsequences are bolded [0,1,2,2], [0,1,2,2], and [0,1,2,2].\n \n Example 2:\n \n >>> countSpecialSubsequences(nums = [2,2,0,0])\n >>> 0\n Explanation: There are no special subsequences in [2,2,0,0].\n \n Example 3:\n \n >>> countSpecialSubsequences(nums = [0,1,2,0,1,2])\n >>> 7\n Explanation: The special subsequences are bolded:\n - [0,1,2,0,1,2]\n - [0,1,2,0,1,2]\n - [0,1,2,0,1,2]\n - [0,1,2,0,1,2]\n - [0,1,2,0,1,2]\n - [0,1,2,0,1,2]\n - [0,1,2,0,1,2]\n \"\"\"\n"}
{"task_id": "minimum-time-for-k-virus-variants-to-spread", "prompt": "def minDayskVariants(points: List[List[int]], k: int) -> int:\n \"\"\"\n There are n unique virus variants in an infinite 2D grid. You are given a 2D array points, where points[i] = [xi, yi] represents a virus originating at (xi, yi) on day 0. Note that it is possible for multiple virus variants to originate at the same point.\n Every day, each cell infected with a virus variant will spread the virus to all neighboring points in the four cardinal directions (i.e. up, down, left, and right). If a cell has multiple variants, all the variants will spread without interfering with each other.\n Given an integer k, return the minimum integer number of days for any point to contain at least k of the unique virus variants.\n \n Example 1:\n \n \n >>> minDayskVariants(points = [[1,1],[6,1]], k = 2)\n >>> 3\n Explanation: On day 3, points (3,1) and (4,1) will contain both virus variants. Note that these are not the only points that will contain both virus variants.\n \n Example 2:\n \n \n >>> minDayskVariants(points = [[3,3],[1,2],[9,2]], k = 2)\n >>> 2\n Explanation: On day 2, points (1,3), (2,3), (2,2), and (3,2) will contain the first two viruses. Note that these are not the only points that will contain both virus variants.\n \n Example 3:\n \n \n >>> minDayskVariants(points = [[3,3],[1,2],[9,2]], k = 3)\n >>> 4\n Explanation: On day 4, the point (5,2) will contain all 3 viruses. Note that this is not the only point that will contain all 3 virus variants.\n \"\"\"\n"}
{"task_id": "delete-characters-to-make-fancy-string", "prompt": "def makeFancyString(s: str) -> str:\n \"\"\"\n A fancy string is a string where no three consecutive characters are equal.\n Given a string s, delete the minimum possible number of characters from s to make it fancy.\n Return the final string after the deletion. It can be shown that the answer will always be unique.\n \n Example 1:\n \n >>> makeFancyString(s = \"leeetcode\")\n >>> \"leetcode\"\n Explanation:\n Remove an 'e' from the first group of 'e's to create \"leetcode\".\n No three consecutive characters are equal, so return \"leetcode\".\n \n Example 2:\n \n >>> makeFancyString(s = \"aaabaaaa\")\n >>> \"aabaa\"\n Explanation:\n Remove an 'a' from the first group of 'a's to create \"aabaaaa\".\n Remove two 'a's from the second group of 'a's to create \"aabaa\".\n No three consecutive characters are equal, so return \"aabaa\".\n \n Example 3:\n \n >>> makeFancyString(s = \"aab\")\n >>> \"aab\"\n Explanation: No three consecutive characters are equal, so return \"aab\".\n \"\"\"\n"}
{"task_id": "check-if-move-is-legal", "prompt": "def checkMove(board: List[List[str]], rMove: int, cMove: int, color: str) -> bool:\n \"\"\"\n You are given a 0-indexed 8 x 8 grid board, where board[r][c] represents the cell (r, c) on a game board. On the board, free cells are represented by '.', white cells are represented by 'W', and black cells are represented by 'B'.\n Each move in this game consists of choosing a free cell and changing it to the color you are playing as (either white or black). However, a move is only legal if, after changing it, the cell becomes the endpoint of a good line (horizontal, vertical, or diagonal).\n A good line is a line of three or more cells (including the endpoints) where the endpoints of the line are one color, and the remaining cells in the middle are the opposite color (no cells in the line are free). You can find examples for good lines in the figure below:\n \n Given two integers rMove and cMove and a character color representing the color you are playing as (white or black), return true if changing cell (rMove, cMove) to color color is a legal move, or false if it is not legal.\n \n Example 1:\n \n \n >>> checkMove(board = [[\".\",\".\",\".\",\"B\",\".\",\".\",\".\",\".\"],[\".\",\".\",\".\",\"W\",\".\",\".\",\".\",\".\"],[\".\",\".\",\".\",\"W\",\".\",\".\",\".\",\".\"],[\".\",\".\",\".\",\"W\",\".\",\".\",\".\",\".\"],[\"W\",\"B\",\"B\",\".\",\"W\",\"W\",\"W\",\"B\"],[\".\",\".\",\".\",\"B\",\".\",\".\",\".\",\".\"],[\".\",\".\",\".\",\"B\",\".\",\".\",\".\",\".\"],[\".\",\".\",\".\",\"W\",\".\",\".\",\".\",\".\"]], rMove = 4, cMove = 3, color = \"B\")\n >>> true\n Explanation: '.', 'W', and 'B' are represented by the colors blue, white, and black respectively, and cell (rMove, cMove) is marked with an 'X'.\n The two good lines with the chosen cell as an endpoint are annotated above with the red rectangles.\n \n Example 2:\n \n \n >>> checkMove(board = [[\".\",\".\",\".\",\".\",\".\",\".\",\".\",\".\"],[\".\",\"B\",\".\",\".\",\"W\",\".\",\".\",\".\"],[\".\",\".\",\"W\",\".\",\".\",\".\",\".\",\".\"],[\".\",\".\",\".\",\"W\",\"B\",\".\",\".\",\".\"],[\".\",\".\",\".\",\".\",\".\",\".\",\".\",\".\"],[\".\",\".\",\".\",\".\",\"B\",\"W\",\".\",\".\"],[\".\",\".\",\".\",\".\",\".\",\".\",\"W\",\".\"],[\".\",\".\",\".\",\".\",\".\",\".\",\".\",\"B\"]], rMove = 4, cMove = 4, color = \"W\")\n >>> false\n Explanation: While there are good lines with the chosen cell as a middle cell, there are no good lines with the chosen cell as an endpoint.\n \"\"\"\n"}
{"task_id": "minimum-total-space-wasted-with-k-resizing-operations", "prompt": "def minSpaceWastedKResizing(nums: List[int], k: int) -> int:\n \"\"\"\n You are currently designing a dynamic array. You are given a 0-indexed integer array nums, where nums[i] is the number of elements that will be in the array at time i. In addition, you are given an integer k, the maximum number of times you can resize the array (to any size).\n The size of the array at time t, sizet, must be at least nums[t] because there needs to be enough space in the array to hold all the elements. The space wasted at\u00a0time t is defined as sizet - nums[t], and the total space wasted is the sum of the space wasted across every time t where 0 <= t < nums.length.\n Return the minimum total space wasted if you can resize the array at most k times.\n Note: The array can have any size at the start and does not count towards the number of resizing operations.\n \n Example 1:\n \n >>> minSpaceWastedKResizing(nums = [10,20], k = 0)\n >>> 10\n Explanation: size = [20,20].\n We can set the initial size to be 20.\n The total wasted space is (20 - 10) + (20 - 20) = 10.\n \n Example 2:\n \n >>> minSpaceWastedKResizing(nums = [10,20,30], k = 1)\n >>> 10\n Explanation: size = [20,20,30].\n We can set the initial size to be 20 and resize to 30 at time 2.\n The total wasted space is (20 - 10) + (20 - 20) + (30 - 30) = 10.\n \n Example 3:\n \n >>> minSpaceWastedKResizing(nums = [10,20,15,30,20], k = 2)\n >>> 15\n Explanation: size = [10,20,20,30,30].\n We can set the initial size to 10, resize to 20 at time 1, and resize to 30 at time 3.\n The total wasted space is (10 - 10) + (20 - 20) + (20 - 15) + (30 - 30) + (30 - 20) = 15.\n \"\"\"\n"}
{"task_id": "maximum-product-of-the-length-of-two-palindromic-substrings", "prompt": "def maxProduct(s: str) -> int:\n \"\"\"\n You are given a 0-indexed string s and are tasked with finding two non-intersecting palindromic substrings of odd length such that the product of their lengths is maximized.\n More formally, you want to choose four integers i, j, k, l such that 0 <= i <= j < k <= l < s.length and both the substrings s[i...j] and s[k...l] are palindromes and have odd lengths. s[i...j] denotes a substring from index i to index j inclusive.\n Return the maximum possible product of the lengths of the two non-intersecting palindromic substrings.\n A palindrome is a string that is the same forward and backward. A substring is a contiguous sequence of characters in a string.\n \n Example 1:\n \n >>> maxProduct(s = \"ababbb\")\n >>> 9\n Explanation: Substrings \"aba\" and \"bbb\" are palindromes with odd length. product = 3 * 3 = 9.\n \n Example 2:\n \n >>> maxProduct(s = \"zaaaxbbby\")\n >>> 9\n Explanation: Substrings \"aaa\" and \"bbb\" are palindromes with odd length. product = 3 * 3 = 9.\n \"\"\"\n"}
{"task_id": "check-if-string-is-a-prefix-of-array", "prompt": "def isPrefixString(s: str, words: List[str]) -> bool:\n \"\"\"\n Given a string s and an array of strings words, determine whether s is a prefix string of words.\n A string s is a prefix string of words if s can be made by concatenating the first k strings in words for some positive k no larger than words.length.\n Return true if s is a prefix string of words, or false otherwise.\n \n Example 1:\n \n >>> isPrefixString(s = \"iloveleetcode\", words = [\"i\",\"love\",\"leetcode\",\"apples\"])\n >>> true\n Explanation:\n s can be made by concatenating \"i\", \"love\", and \"leetcode\" together.\n \n Example 2:\n \n >>> isPrefixString(s = \"iloveleetcode\", words = [\"apples\",\"i\",\"love\",\"leetcode\"])\n >>> false\n Explanation:\n It is impossible to make s using a prefix of arr.\n \"\"\"\n"}
{"task_id": "remove-stones-to-minimize-the-total", "prompt": "def minStoneSum(piles: List[int], k: int) -> int:\n \"\"\"\n You are given a 0-indexed integer array piles, where piles[i] represents the number of stones in the ith pile, and an integer k. You should apply the following operation exactly k times:\n \n Choose any piles[i] and remove floor(piles[i] / 2) stones from it.\n \n Notice that you can apply the operation on the same pile more than once.\n Return the minimum possible total number of stones remaining after applying the k operations.\n floor(x) is the greatest integer that is smaller than or equal to x (i.e., rounds x down).\n \n Example 1:\n \n >>> minStoneSum(piles = [5,4,9], k = 2)\n >>> 12\n Explanation:\u00a0Steps of a possible scenario are:\n - Apply the operation on pile 2. The resulting piles are [5,4,5].\n - Apply the operation on pile 0. The resulting piles are [3,4,5].\n The total number of stones in [3,4,5] is 12.\n \n Example 2:\n \n >>> minStoneSum(piles = [4,3,6,7], k = 3)\n >>> 12\n Explanation:\u00a0Steps of a possible scenario are:\n - Apply the operation on pile 2. The resulting piles are [4,3,3,7].\n - Apply the operation on pile 3. The resulting piles are [4,3,3,4].\n - Apply the operation on pile 0. The resulting piles are [2,3,3,4].\n The total number of stones in [2,3,3,4] is 12.\n \"\"\"\n"}
{"task_id": "minimum-number-of-swaps-to-make-the-string-balanced", "prompt": "def minSwaps(s: str) -> int:\n \"\"\"\n You are given a 0-indexed string s of even length n. The string consists of exactly n / 2 opening brackets '[' and n / 2 closing brackets ']'.\n A string is called balanced if and only if:\n \n It is the empty string, or\n It can be written as AB, where both A and B are balanced strings, or\n It can be written as [C], where C is a balanced string.\n \n You may swap the brackets at any two indices any number of times.\n Return the minimum number of swaps to make s balanced.\n \n Example 1:\n \n >>> minSwaps(s = \"][][\")\n >>> 1\n Explanation: You can make the string balanced by swapping index 0 with index 3.\n The resulting string is \"[[]]\".\n \n Example 2:\n \n >>> minSwaps(s = \"]]][[[\")\n >>> 2\n Explanation: You can do the following to make the string balanced:\n - Swap index 0 with index 4. s = \"[]][][\".\n - Swap index 1 with index 5. s = \"[[][]]\".\n The resulting string is \"[[][]]\".\n \n Example 3:\n \n >>> minSwaps(s = \"[]\")\n >>> 0\n Explanation: The string is already balanced.\n \"\"\"\n"}
{"task_id": "find-the-longest-valid-obstacle-course-at-each-position", "prompt": "def longestObstacleCourseAtEachPosition(obstacles: List[int]) -> List[int]:\n \"\"\"\n You want to build some obstacle courses. You are given a 0-indexed integer array obstacles of length n, where obstacles[i] describes the height of the ith obstacle.\n For every index i between 0 and n - 1 (inclusive), find the length of the longest obstacle course in obstacles such that:\n \n You choose any number of obstacles between 0 and i inclusive.\n You must include the ith obstacle in the course.\n You must put the chosen obstacles in the same order as they appear in obstacles.\n Every obstacle (except the first) is taller than or the same height as the obstacle immediately before it.\n \n Return an array ans of length n, where ans[i] is the length of the longest obstacle course for index i as described above.\n \n Example 1:\n \n >>> longestObstacleCourseAtEachPosition(obstacles = [1,2,3,2])\n >>> [1,2,3,3]\n Explanation: The longest valid obstacle course at each position is:\n - i = 0: [1], [1] has length 1.\n - i = 1: [1,2], [1,2] has length 2.\n - i = 2: [1,2,3], [1,2,3] has length 3.\n - i = 3: [1,2,3,2], [1,2,2] has length 3.\n \n Example 2:\n \n >>> longestObstacleCourseAtEachPosition(obstacles = [2,2,1])\n >>> [1,2,1]\n Explanation: The longest valid obstacle course at each position is:\n - i = 0: [2], [2] has length 1.\n - i = 1: [2,2], [2,2] has length 2.\n - i = 2: [2,2,1], [1] has length 1.\n \n Example 3:\n \n >>> longestObstacleCourseAtEachPosition(obstacles = [3,1,5,6,4,2])\n >>> [1,1,2,3,2,2]\n Explanation: The longest valid obstacle course at each position is:\n - i = 0: [3], [3] has length 1.\n - i = 1: [3,1], [1] has length 1.\n - i = 2: [3,1,5], [3,5] has length 2. [1,5] is also valid.\n - i = 3: [3,1,5,6], [3,5,6] has length 3. [1,5,6] is also valid.\n - i = 4: [3,1,5,6,4], [3,4] has length 2. [1,4] is also valid.\n - i = 5: [3,1,5,6,4,2], [1,2] has length 2.\n \"\"\"\n"}
{"task_id": "binary-searchable-numbers-in-an-unsorted-array", "prompt": "def binarySearchableNumbers(nums: List[int]) -> int:\n \"\"\"\n Consider a function that implements an algorithm similar to Binary Search. The function has two input parameters: sequence is a sequence of integers, and target is an integer value. The purpose of the function is to find if the target exists in the sequence.\n The pseudocode of the function is as follows:\n \n func(sequence, target)\n while sequence is not empty\n randomly choose an element from sequence as the pivot\n if pivot = target, return true\n else if pivot < target, remove pivot and all elements to its left from the sequence\n else, remove pivot and all elements to its right from the sequence\n end while\n return false\n \n When the sequence is sorted, the function works correctly for all values. When the sequence is not sorted, the function does not work for all values, but may still work for some values.\n Given an integer array nums, representing the sequence, that contains unique numbers and may or may not be sorted, return the number of values that are guaranteed to be found using the function, for every possible pivot selection.\n \n Example 1:\n \n >>> binarySearchableNumbers(nums = [7])\n >>> 1\n Explanation:\n Searching for value 7 is guaranteed to be found.\n Since the sequence has only one element, 7 will be chosen as the pivot. Because the pivot equals the target, the function will return true.\n \n Example 2:\n \n >>> binarySearchableNumbers(nums = [-1,5,2])\n >>> 1\n Explanation:\n Searching for value -1 is guaranteed to be found.\n If -1 was chosen as the pivot, the function would return true.\n If 5 was chosen as the pivot, 5 and 2 would be removed. In the next loop, the sequence would have only -1 and the function would return true.\n If 2 was chosen as the pivot, 2 would be removed. In the next loop, the sequence would have -1 and 5. No matter which number was chosen as the next pivot, the function would find -1 and return true.\n \n Searching for value 5 is NOT guaranteed to be found.\n If 2 was chosen as the pivot, -1, 5 and 2 would be removed. The sequence would be empty and the function would return false.\n \n Searching for value 2 is NOT guaranteed to be found.\n If 5 was chosen as the pivot, 5 and 2 would be removed. In the next loop, the sequence would have only -1 and the function would return false.\n \n Because only -1 is guaranteed to be found, you should return 1.\n \"\"\"\n"}
{"task_id": "number-of-strings-that-appear-as-substrings-in-word", "prompt": "def numOfStrings(patterns: List[str], word: str) -> int:\n \"\"\"\n Given an array of strings patterns and a string word, return the number of strings in patterns that exist as a substring in word.\n A substring is a contiguous sequence of characters within a string.\n \n Example 1:\n \n >>> numOfStrings(patterns = [\"a\",\"abc\",\"bc\",\"d\"], word = \"abc\")\n >>> 3\n Explanation:\n - \"a\" appears as a substring in \"abc\".\n - \"abc\" appears as a substring in \"abc\".\n - \"bc\" appears as a substring in \"abc\".\n - \"d\" does not appear as a substring in \"abc\".\n 3 of the strings in patterns appear as a substring in word.\n \n Example 2:\n \n >>> numOfStrings(patterns = [\"a\",\"b\",\"c\"], word = \"aaaaabbbbb\")\n >>> 2\n Explanation:\n - \"a\" appears as a substring in \"aaaaabbbbb\".\n - \"b\" appears as a substring in \"aaaaabbbbb\".\n - \"c\" does not appear as a substring in \"aaaaabbbbb\".\n 2 of the strings in patterns appear as a substring in word.\n \n Example 3:\n \n >>> numOfStrings(patterns = [\"a\",\"a\",\"a\"], word = \"ab\")\n >>> 3\n Explanation: Each of the patterns appears as a substring in word \"ab\".\n \"\"\"\n"}
{"task_id": "array-with-elements-not-equal-to-average-of-neighbors", "prompt": "def rearrangeArray(nums: List[int]) -> List[int]:\n \"\"\"\n You are given a 0-indexed array nums of distinct integers. You want to rearrange the elements in the array such that every element in the rearranged array is not equal to the average of its neighbors.\n More formally, the rearranged array should have the property such that for every i in the range 1 <= i < nums.length - 1, (nums[i-1] + nums[i+1]) / 2 is not equal to nums[i].\n Return any rearrangement of nums that meets the requirements.\n \n Example 1:\n \n >>> rearrangeArray(nums = [1,2,3,4,5])\n >>> [1,2,4,5,3]\n Explanation:\n When i=1, nums[i] = 2, and the average of its neighbors is (1+4) / 2 = 2.5.\n When i=2, nums[i] = 4, and the average of its neighbors is (2+5) / 2 = 3.5.\n When i=3, nums[i] = 5, and the average of its neighbors is (4+3) / 2 = 3.5.\n \n Example 2:\n \n >>> rearrangeArray(nums = [6,2,0,9,7])\n >>> [9,7,6,2,0]\n Explanation:\n When i=1, nums[i] = 7, and the average of its neighbors is (9+6) / 2 = 7.5.\n When i=2, nums[i] = 6, and the average of its neighbors is (7+2) / 2 = 4.5.\n When i=3, nums[i] = 2, and the average of its neighbors is (6+0) / 2 = 3.\n Note that the original array [6,2,0,9,7] also satisfies the conditions.\n \"\"\"\n"}
{"task_id": "last-day-where-you-can-still-cross", "prompt": "def latestDayToCross(row: int, col: int, cells: List[List[int]]) -> int:\n \"\"\"\n There is a 1-based binary matrix where 0 represents land and 1 represents water. You are given integers row and col representing the number of rows and columns in the matrix, respectively.\n Initially on day 0, the entire matrix is land. However, each day a new cell becomes flooded with water. You are given a 1-based 2D array cells, where cells[i] = [ri, ci] represents that on the ith day, the cell on the rith row and cith column (1-based coordinates) will be covered with water (i.e., changed to 1).\n You want to find the last day that it is possible to walk from the top to the bottom by only walking on land cells. You can start from any cell in the top row and end at any cell in the bottom row. You can only travel in the four cardinal directions (left, right, up, and down).\n Return the last day where it is possible to walk from the top to the bottom by only walking on land cells.\n \n Example 1:\n \n \n >>> latestDayToCross(row = 2, col = 2, cells = [[1,1],[2,1],[1,2],[2,2]])\n >>> 2\n Explanation: The above image depicts how the matrix changes each day starting from day 0.\n The last day where it is possible to cross from top to bottom is on day 2.\n \n Example 2:\n \n \n >>> latestDayToCross(row = 2, col = 2, cells = [[1,1],[1,2],[2,1],[2,2]])\n >>> 1\n Explanation: The above image depicts how the matrix changes each day starting from day 0.\n The last day where it is possible to cross from top to bottom is on day 1.\n \n Example 3:\n \n \n >>> latestDayToCross(row = 3, col = 3, cells = [[1,2],[2,1],[3,3],[2,2],[1,1],[1,3],[2,3],[3,2],[3,1]])\n >>> 3\n Explanation: The above image depicts how the matrix changes each day starting from day 0.\n The last day where it is possible to cross from top to bottom is on day 3.\n \"\"\"\n"}
{"task_id": "find-if-path-exists-in-graph", "prompt": "def validPath(n: int, edges: List[List[int]], source: int, destination: int) -> bool:\n \"\"\"\n There is a bi-directional graph with n vertices, where each vertex is labeled from 0 to n - 1 (inclusive). The edges in the graph are represented as a 2D integer array edges, where each edges[i] = [ui, vi] denotes a bi-directional edge between vertex ui and vertex vi. Every vertex pair is connected by at most one edge, and no vertex has an edge to itself.\n You want to determine if there is a valid path that exists from vertex source to vertex destination.\n Given edges and the integers n, source, and destination, return true if there is a valid path from source to destination, or false otherwise.\n \n Example 1:\n \n \n >>> validPath(n = 3, edges = [[0,1],[1,2],[2,0]], source = 0, destination = 2)\n >>> true\n Explanation: There are two paths from vertex 0 to vertex 2:\n - 0 \u2192 1 \u2192 2\n - 0 \u2192 2\n \n Example 2:\n \n \n >>> validPath(n = 6, edges = [[0,1],[0,2],[3,5],[5,4],[4,3]], source = 0, destination = 5)\n >>> false\n Explanation: There is no path from vertex 0 to vertex 5.\n \"\"\"\n"}
{"task_id": "count-nodes-equal-to-sum-of-descendants", "prompt": "# class TreeNode:\n# def __init__(val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def equalToDescendants(root: Optional[TreeNode]) -> int:\n \"\"\"\n Given the root of a binary tree, return the number of nodes where the value of the node is equal to the sum of the values of its descendants.\n A descendant of a node x is any node that is on the path from node x to some leaf node. The sum is considered to be 0 if the node has no descendants.\n \n Example 1:\n \n \n >>> __init__(root = [10,3,4,2,1])\n >>> 2\n Explanation:\n For the node with value 10: The sum of its descendants is 3+4+2+1 = 10.\n For the node with value 3: The sum of its descendants is 2+1 = 3.\n \n Example 2:\n \n \n >>> __init__(root = [2,3,null,2,null])\n >>> 0\n Explanation:\n No node has a value that is equal to the sum of its descendants.\n \n Example 3:\n \n \n >>> __init__(root = [0])\n >>> 1\n For the node with value 0: The sum of its descendants is 0 since it has no descendants.\n \"\"\"\n"}
{"task_id": "minimum-time-to-type-word-using-special-typewriter", "prompt": "def minTimeToType(word: str) -> int:\n \"\"\"\n There is a special typewriter with lowercase English letters 'a' to 'z' arranged in a circle with a pointer. A character can only be typed if the pointer is pointing to that character. The pointer is initially pointing to the character 'a'.\n \n Each second, you may perform one of the following operations:\n \n Move the pointer one character counterclockwise or clockwise.\n Type the character the pointer is currently on.\n \n Given a string word, return the minimum number of seconds to type out the characters in word.\n \n Example 1:\n \n >>> minTimeToType(word = \"abc\")\n >>> 5\n Explanation:\n The characters are printed as follows:\n - Type the character 'a' in 1 second since the pointer is initially on 'a'.\n - Move the pointer clockwise to 'b' in 1 second.\n - Type the character 'b' in 1 second.\n - Move the pointer clockwise to 'c' in 1 second.\n - Type the character 'c' in 1 second.\n \n Example 2:\n \n >>> minTimeToType(word = \"bza\")\n >>> 7\n Explanation:\n The characters are printed as follows:\n - Move the pointer clockwise to 'b' in 1 second.\n - Type the character 'b' in 1 second.\n - Move the pointer counterclockwise to 'z' in 2 seconds.\n - Type the character 'z' in 1 second.\n - Move the pointer clockwise to 'a' in 1 second.\n - Type the character 'a' in 1 second.\n \n Example 3:\n \n >>> minTimeToType(word = \"zjpc\")\n >>> 34\n Explanation:\n The characters are printed as follows:\n - Move the pointer counterclockwise to 'z' in 1 second.\n - Type the character 'z' in 1 second.\n - Move the pointer clockwise to 'j' in 10 seconds.\n - Type the character 'j' in 1 second.\n - Move the pointer clockwise to 'p' in 6 seconds.\n - Type the character 'p' in 1 second.\n - Move the pointer counterclockwise to 'c' in 13 seconds.\n - Type the character 'c' in 1 second.\n \"\"\"\n"}
{"task_id": "maximum-matrix-sum", "prompt": "def maxMatrixSum(matrix: List[List[int]]) -> int:\n \"\"\"\n You are given an n x n integer matrix. You can do the following operation any number of times:\n \n Choose any two adjacent elements of matrix and multiply each of them by -1.\n \n Two elements are considered adjacent if and only if they share a border.\n Your goal is to maximize the summation of the matrix's elements. Return the maximum sum of the matrix's elements using the operation mentioned above.\n \n Example 1:\n \n \n >>> maxMatrixSum(matrix = [[1,-1],[-1,1]])\n >>> 4\n Explanation: We can follow the following steps to reach sum equals 4:\n - Multiply the 2 elements in the first row by -1.\n - Multiply the 2 elements in the first column by -1.\n \n Example 2:\n \n \n >>> maxMatrixSum(matrix = [[1,2,3],[-1,-2,-3],[1,2,3]])\n >>> 16\n Explanation: We can follow the following step to reach sum equals 16:\n - Multiply the 2 last elements in the second row by -1.\n \"\"\"\n"}
{"task_id": "number-of-ways-to-arrive-at-destination", "prompt": "def countPaths(n: int, roads: List[List[int]]) -> int:\n \"\"\"\n You are in a city that consists of n intersections numbered from 0 to n - 1 with bi-directional roads between some intersections. The inputs are generated such that you can reach any intersection from any other intersection and that there is at most one road between any two intersections.\n You are given an integer n and a 2D integer array roads where roads[i] = [ui, vi, timei] means that there is a road between intersections ui and vi that takes timei minutes to travel. You want to know in how many ways you can travel from intersection 0 to intersection n - 1 in the shortest amount of time.\n Return the number of ways you can arrive at your destination in the shortest amount of time. Since the answer may be large, return it modulo 109 + 7.\n \n Example 1:\n \n \n >>> countPaths(n = 7, roads = [[0,6,7],[0,1,2],[1,2,3],[1,3,3],[6,3,3],[3,5,1],[6,5,1],[2,5,1],[0,4,5],[4,6,2]])\n >>> 4\n Explanation: The shortest amount of time it takes to go from intersection 0 to intersection 6 is 7 minutes.\n The four ways to get there in 7 minutes are:\n - 0 \u279d 6\n - 0 \u279d 4 \u279d 6\n - 0 \u279d 1 \u279d 2 \u279d 5 \u279d 6\n - 0 \u279d 1 \u279d 3 \u279d 5 \u279d 6\n \n Example 2:\n \n >>> countPaths(n = 2, roads = [[1,0,10]])\n >>> 1\n Explanation: There is only one way to go from intersection 0 to intersection 1, and it takes 10 minutes.\n \"\"\"\n"}
{"task_id": "number-of-ways-to-separate-numbers", "prompt": "def numberOfCombinations(num: str) -> int:\n \"\"\"\n You wrote down many positive integers in a string called num. However, you realized that you forgot to add commas to seperate the different numbers. You remember that the list of integers was non-decreasing and that no integer had leading zeros.\n Return the number of possible lists of integers that you could have written down to get the string num. Since the answer may be large, return it modulo 109 + 7.\n \n Example 1:\n \n >>> numberOfCombinations(num = \"327\")\n >>> 2\n Explanation: You could have written down the numbers:\n 3, 27\n 327\n \n Example 2:\n \n >>> numberOfCombinations(num = \"094\")\n >>> 0\n Explanation: No numbers can have leading zeros and all numbers must be positive.\n \n Example 3:\n \n >>> numberOfCombinations(num = \"0\")\n >>> 0\n Explanation: No numbers can have leading zeros and all numbers must be positive.\n \"\"\"\n"}
{"task_id": "find-greatest-common-divisor-of-array", "prompt": "def findGCD(nums: List[int]) -> int:\n \"\"\"\n Given an integer array nums, return the greatest common divisor of the smallest number and largest number in nums.\n The greatest common divisor of two numbers is the largest positive integer that evenly divides both numbers.\n \n Example 1:\n \n >>> findGCD(nums = [2,5,6,9,10])\n >>> 2\n Explanation:\n The smallest number in nums is 2.\n The largest number in nums is 10.\n The greatest common divisor of 2 and 10 is 2.\n \n Example 2:\n \n >>> findGCD(nums = [7,5,6,8,3])\n >>> 1\n Explanation:\n The smallest number in nums is 3.\n The largest number in nums is 8.\n The greatest common divisor of 3 and 8 is 1.\n \n Example 3:\n \n >>> findGCD(nums = [3,3])\n >>> 3\n Explanation:\n The smallest number in nums is 3.\n The largest number in nums is 3.\n The greatest common divisor of 3 and 3 is 3.\n \"\"\"\n"}
{"task_id": "find-unique-binary-string", "prompt": "def findDifferentBinaryString(nums: List[str]) -> str:\n \"\"\"\n Given an array of strings nums containing n unique binary strings each of length n, return a binary string of length n that does not appear in nums. If there are multiple answers, you may return any of them.\n \n Example 1:\n \n >>> findDifferentBinaryString(nums = [\"01\",\"10\"])\n >>> \"11\"\n Explanation: \"11\" does not appear in nums. \"00\" would also be correct.\n \n Example 2:\n \n >>> findDifferentBinaryString(nums = [\"00\",\"01\"])\n >>> \"11\"\n Explanation: \"11\" does not appear in nums. \"10\" would also be correct.\n \n Example 3:\n \n >>> findDifferentBinaryString(nums = [\"111\",\"011\",\"001\"])\n >>> \"101\"\n Explanation: \"101\" does not appear in nums. \"000\", \"010\", \"100\", and \"110\" would also be correct.\n \"\"\"\n"}
{"task_id": "minimize-the-difference-between-target-and-chosen-elements", "prompt": "def minimizeTheDifference(mat: List[List[int]], target: int) -> int:\n \"\"\"\n You are given an m x n integer matrix mat and an integer target.\n Choose one integer from each row in the matrix such that the absolute difference between target and the sum of the chosen elements is minimized.\n Return the minimum absolute difference.\n The absolute difference between two numbers a and b is the absolute value of a - b.\n \n Example 1:\n \n \n >>> minimizeTheDifference(mat = [[1,2,3],[4,5,6],[7,8,9]], target = 13)\n >>> 0\n Explanation: One possible choice is to:\n - Choose 1 from the first row.\n - Choose 5 from the second row.\n - Choose 7 from the third row.\n The sum of the chosen elements is 13, which equals the target, so the absolute difference is 0.\n \n Example 2:\n \n \n >>> minimizeTheDifference(mat = [[1],[2],[3]], target = 100)\n >>> 94\n Explanation: The best possible choice is to:\n - Choose 1 from the first row.\n - Choose 2 from the second row.\n - Choose 3 from the third row.\n The sum of the chosen elements is 6, and the absolute difference is 94.\n \n Example 3:\n \n \n >>> minimizeTheDifference(mat = [[1,2,9,8,7]], target = 6)\n >>> 1\n Explanation: The best choice is to choose 7 from the first row.\n The absolute difference is 1.\n \"\"\"\n"}
{"task_id": "find-array-given-subset-sums", "prompt": "def recoverArray(n: int, sums: List[int]) -> List[int]:\n \"\"\"\n You are given an integer n representing the length of an unknown array that you are trying to recover. You are also given an array sums containing the values of all 2n subset sums of the unknown array (in no particular order).\n Return the array ans of length n representing the unknown array. If multiple answers exist, return any of them.\n An array sub is a subset of an array arr if sub can be obtained from arr by deleting some (possibly zero or all) elements of arr. The sum of the elements in sub is one possible subset sum of arr. The sum of an empty array is considered to be 0.\n Note: Test cases are generated such that there will always be at least one correct answer.\n \n Example 1:\n \n >>> recoverArray(n = 3, sums = [-3,-2,-1,0,0,1,2,3])\n >>> [1,2,-3]\n Explanation: [1,2,-3] is able to achieve the given subset sums:\n - []: sum is 0\n - [1]: sum is 1\n - [2]: sum is 2\n - [1,2]: sum is 3\n - [-3]: sum is -3\n - [1,-3]: sum is -2\n - [2,-3]: sum is -1\n - [1,2,-3]: sum is 0\n Note that any permutation of [1,2,-3] and also any permutation of [-1,-2,3] will also be accepted.\n \n Example 2:\n \n >>> recoverArray(n = 2, sums = [0,0,0,0])\n >>> [0,0]\n Explanation: The only correct answer is [0,0].\n \n Example 3:\n \n >>> recoverArray(n = 4, sums = [0,0,5,5,4,-1,4,9,9,-1,4,3,4,8,3,8])\n >>> [0,-1,4,5]\n Explanation: [0,-1,4,5] is able to achieve the given subset sums.\n \"\"\"\n"}
{"task_id": "widest-pair-of-indices-with-equal-range-sum", "prompt": "def widestPairOfIndices(nums1: List[int], nums2: List[int]) -> int:\n \"\"\"\n You are given two 0-indexed binary arrays nums1 and nums2. Find the widest pair of indices (i, j) such that i <= j and nums1[i] + nums1[i+1] + ... + nums1[j] == nums2[i] + nums2[i+1] + ... + nums2[j].\n The widest pair of indices is the pair with the largest distance between i and j. The distance between a pair of indices is defined as j - i + 1.\n Return the distance of the widest pair of indices. If no pair of indices meets the conditions, return 0.\n \n Example 1:\n \n >>> widestPairOfIndices(nums1 = [1,1,0,1], nums2 = [0,1,1,0])\n >>> 3\n Explanation:\n If i = 1 and j = 3:\n nums1[1] + nums1[2] + nums1[3] = 1 + 0 + 1 = 2.\n nums2[1] + nums2[2] + nums2[3] = 1 + 1 + 0 = 2.\n The distance between i and j is j - i + 1 = 3 - 1 + 1 = 3.\n \n Example 2:\n \n >>> widestPairOfIndices(nums1 = [0,1], nums2 = [1,1])\n >>> 1\n Explanation:\n If i = 1 and j = 1:\n nums1[1] = 1.\n nums2[1] = 1.\n The distance between i and j is j - i + 1 = 1 - 1 + 1 = 1.\n \n Example 3:\n \n >>> widestPairOfIndices(nums1 = [0], nums2 = [1])\n >>> 0\n Explanation:\n There are no pairs of indices that meet the requirements.\n \"\"\"\n"}
{"task_id": "minimum-difference-between-highest-and-lowest-of-k-scores", "prompt": "def minimumDifference(nums: List[int], k: int) -> int:\n \"\"\"\n You are given a 0-indexed integer array nums, where nums[i] represents the score of the ith student. You are also given an integer k.\n Pick the scores of any k students from the array so that the difference between the highest and the lowest of the k scores is minimized.\n Return the minimum possible difference.\n \n Example 1:\n \n >>> minimumDifference(nums = [90], k = 1)\n >>> 0\n Explanation: There is one way to pick score(s) of one student:\n - [90]. The difference between the highest and lowest score is 90 - 90 = 0.\n The minimum possible difference is 0.\n \n Example 2:\n \n >>> minimumDifference(nums = [9,4,1,7], k = 2)\n >>> 2\n Explanation: There are six ways to pick score(s) of two students:\n - [9,4,1,7]. The difference between the highest and lowest score is 9 - 4 = 5.\n - [9,4,1,7]. The difference between the highest and lowest score is 9 - 1 = 8.\n - [9,4,1,7]. The difference between the highest and lowest score is 9 - 7 = 2.\n - [9,4,1,7]. The difference between the highest and lowest score is 4 - 1 = 3.\n - [9,4,1,7]. The difference between the highest and lowest score is 7 - 4 = 3.\n - [9,4,1,7]. The difference between the highest and lowest score is 7 - 1 = 6.\n The minimum possible difference is 2.\n \"\"\"\n"}
{"task_id": "find-the-kth-largest-integer-in-the-array", "prompt": "def kthLargestNumber(nums: List[str], k: int) -> str:\n \"\"\"\n You are given an array of strings nums and an integer k. Each string in nums represents an integer without leading zeros.\n Return the string that represents the kth largest integer in nums.\n Note: Duplicate numbers should be counted distinctly. For example, if nums is [\"1\",\"2\",\"2\"], \"2\" is the first largest integer, \"2\" is the second-largest integer, and \"1\" is the third-largest integer.\n \n Example 1:\n \n >>> kthLargestNumber(nums = [\"3\",\"6\",\"7\",\"10\"], k = 4)\n >>> \"3\"\n Explanation:\n The numbers in nums sorted in non-decreasing order are [\"3\",\"6\",\"7\",\"10\"].\n The 4th largest integer in nums is \"3\".\n \n Example 2:\n \n >>> kthLargestNumber(nums = [\"2\",\"21\",\"12\",\"1\"], k = 3)\n >>> \"2\"\n Explanation:\n The numbers in nums sorted in non-decreasing order are [\"1\",\"2\",\"12\",\"21\"].\n The 3rd largest integer in nums is \"2\".\n \n Example 3:\n \n >>> kthLargestNumber(nums = [\"0\",\"0\"], k = 2)\n >>> \"0\"\n Explanation:\n The numbers in nums sorted in non-decreasing order are [\"0\",\"0\"].\n The 2nd largest integer in nums is \"0\".\n \"\"\"\n"}
{"task_id": "minimum-number-of-work-sessions-to-finish-the-tasks", "prompt": "def minSessions(tasks: List[int], sessionTime: int) -> int:\n \"\"\"\n There are n tasks assigned to you. The task times are represented as an integer array tasks of length n, where the ith task takes tasks[i] hours to finish. A work session is when you work for at most sessionTime consecutive hours and then take a break.\n You should finish the given tasks in a way that satisfies the following conditions:\n \n If you start a task in a work session, you must complete it in the same work session.\n You can start a new task immediately after finishing the previous one.\n You may complete the tasks in any order.\n \n Given tasks and sessionTime, return the minimum number of work sessions needed to finish all the tasks following the conditions above.\n The tests are generated such that sessionTime is greater than or equal to the maximum element in tasks[i].\n \n Example 1:\n \n >>> minSessions(tasks = [1,2,3], sessionTime = 3)\n >>> 2\n Explanation: You can finish the tasks in two work sessions.\n - First work session: finish the first and the second tasks in 1 + 2 = 3 hours.\n - Second work session: finish the third task in 3 hours.\n \n Example 2:\n \n >>> minSessions(tasks = [3,1,3,1,1], sessionTime = 8)\n >>> 2\n Explanation: You can finish the tasks in two work sessions.\n - First work session: finish all the tasks except the last one in 3 + 1 + 3 + 1 = 8 hours.\n - Second work session: finish the last task in 1 hour.\n \n Example 3:\n \n >>> minSessions(tasks = [1,2,3,4,5], sessionTime = 15)\n >>> 1\n Explanation: You can finish all the tasks in one work session.\n \"\"\"\n"}
{"task_id": "number-of-unique-good-subsequences", "prompt": "def numberOfUniqueGoodSubsequences(binary: str) -> int:\n \"\"\"\n You are given a binary string binary. A subsequence of binary is considered good if it is not empty and has no leading zeros (with the exception of \"0\").\n Find the number of unique good subsequences of binary.\n \n For example, if binary = \"001\", then all the good subsequences are [\"0\", \"0\", \"1\"], so the unique good subsequences are \"0\" and \"1\". Note that subsequences \"00\", \"01\", and \"001\" are not good because they have leading zeros.\n \n Return the number of unique good subsequences of binary. Since the answer may be very large, return it modulo 109 + 7.\n A subsequence is a sequence that can be derived from another sequence by deleting some or no elements without changing the order of the remaining elements.\n \n Example 1:\n \n >>> numberOfUniqueGoodSubsequences(binary = \"001\")\n >>> 2\n Explanation: The good subsequences of binary are [\"0\", \"0\", \"1\"].\n The unique good subsequences are \"0\" and \"1\".\n \n Example 2:\n \n >>> numberOfUniqueGoodSubsequences(binary = \"11\")\n >>> 2\n Explanation: The good subsequences of binary are [\"1\", \"1\", \"11\"].\n The unique good subsequences are \"1\" and \"11\".\n Example 3:\n \n >>> numberOfUniqueGoodSubsequences(binary = \"101\")\n >>> 5\n Explanation: The good subsequences of binary are [\"1\", \"0\", \"1\", \"10\", \"11\", \"101\"].\n The unique good subsequences are \"0\", \"1\", \"10\", \"11\", and \"101\".\n \"\"\"\n"}
{"task_id": "maximum-number-of-people-that-can-be-caught-in-tag", "prompt": "def catchMaximumAmountofPeople(team: List[int], dist: int) -> int:\n \"\"\"\n You are playing a game of tag with your friends. In tag, people are divided into two teams: people who are \"it\", and people who are not \"it\". The people who are \"it\" want to catch as many people as possible who are not \"it\".\n You are given a 0-indexed integer array team containing only zeros (denoting people who are not \"it\") and ones (denoting people who are \"it\"), and an integer dist. A person who is \"it\" at index i can catch any one person whose index is in the range [i - dist, i + dist] (inclusive) and is not \"it\".\n Return the maximum number of people that the people who are \"it\" can catch.\n \n Example 1:\n \n >>> catchMaximumAmountofPeople(team = [0,1,0,1,0], dist = 3)\n >>> 2\n Explanation:\n The person who is \"it\" at index 1 can catch people in the range [i-dist, i+dist] = [1-3, 1+3] = [-2, 4].\n They can catch the person who is not \"it\" at index 2.\n The person who is \"it\" at index 3 can catch people in the range [i-dist, i+dist] = [3-3, 3+3] = [0, 6].\n They can catch the person who is not \"it\" at index 0.\n The person who is not \"it\" at index 4 will not be caught because the people at indices 1 and 3 are already catching one person.\n Example 2:\n \n >>> catchMaximumAmountofPeople(team = [1], dist = 1)\n >>> 0\n Explanation:\n There are no people who are not \"it\" to catch.\n \n Example 3:\n \n >>> catchMaximumAmountofPeople(team = [0], dist = 1)\n >>> 0\n Explanation:\n There are no people who are \"it\" to catch people.\n \"\"\"\n"}
{"task_id": "find-the-middle-index-in-array", "prompt": "def findMiddleIndex(nums: List[int]) -> int:\n \"\"\"\n Given a 0-indexed integer array nums, find the leftmost middleIndex (i.e., the smallest amongst all the possible ones).\n A middleIndex is an index where nums[0] + nums[1] + ... + nums[middleIndex-1] == nums[middleIndex+1] + nums[middleIndex+2] + ... + nums[nums.length-1].\n If middleIndex == 0, the left side sum is considered to be 0. Similarly, if middleIndex == nums.length - 1, the right side sum is considered to be 0.\n Return the leftmost middleIndex that satisfies the condition, or -1 if there is no such index.\n \n Example 1:\n \n >>> findMiddleIndex(nums = [2,3,-1,8,4])\n >>> 3\n Explanation: The sum of the numbers before index 3 is: 2 + 3 + -1 = 4\n The sum of the numbers after index 3 is: 4 = 4\n \n Example 2:\n \n >>> findMiddleIndex(nums = [1,-1,4])\n >>> 2\n Explanation: The sum of the numbers before index 2 is: 1 + -1 = 0\n The sum of the numbers after index 2 is: 0\n \n Example 3:\n \n >>> findMiddleIndex(nums = [2,5])\n >>> -1\n Explanation: There is no valid middleIndex.\n \"\"\"\n"}
{"task_id": "find-all-groups-of-farmland", "prompt": "def findFarmland(land: List[List[int]]) -> List[List[int]]:\n \"\"\"\n You are given a 0-indexed m x n binary matrix land where a 0 represents a hectare of forested land and a 1 represents a hectare of farmland.\n To keep the land organized, there are designated rectangular areas of hectares that consist entirely of farmland. These rectangular areas are called groups. No two groups are adjacent, meaning farmland in one group is not four-directionally adjacent to another farmland in a different group.\n land can be represented by a coordinate system where the top left corner of land is (0, 0) and the bottom right corner of land is (m-1, n-1). Find the coordinates of the top left and bottom right corner of each group of farmland. A group of farmland with a top left corner at (r1, c1) and a bottom right corner at (r2, c2) is represented by the 4-length array [r1, c1, r2, c2].\n Return a 2D array containing the 4-length arrays described above for each group of farmland in land. If there are no groups of farmland, return an empty array. You may return the answer in any order.\n \n Example 1:\n \n \n >>> findFarmland(land = [[1,0,0],[0,1,1],[0,1,1]])\n >>> [[0,0,0,0],[1,1,2,2]]\n Explanation:\n The first group has a top left corner at land[0][0] and a bottom right corner at land[0][0].\n The second group has a top left corner at land[1][1] and a bottom right corner at land[2][2].\n \n Example 2:\n \n \n >>> findFarmland(land = [[1,1],[1,1]])\n >>> [[0,0,1,1]]\n Explanation:\n The first group has a top left corner at land[0][0] and a bottom right corner at land[1][1].\n \n Example 3:\n \n \n >>> findFarmland(land = [[0]])\n >>> []\n Explanation:\n There are no groups of farmland.\n \"\"\"\n"}
{"task_id": "the-number-of-good-subsets", "prompt": "def numberOfGoodSubsets(nums: List[int]) -> int:\n \"\"\"\n You are given an integer array nums. We call a subset of nums good if its product can be represented as a product of one or more distinct prime numbers.\n \n For example, if nums = [1, 2, 3, 4]:\n \n \n [2, 3], [1, 2, 3], and [1, 3] are good subsets with products 6 = 2*3, 6 = 2*3, and 3 = 3 respectively.\n [1, 4] and [4] are not good subsets with products 4 = 2*2 and 4 = 2*2 respectively.\n \n \n \n Return the number of different good subsets in nums modulo 109 + 7.\n A subset of nums is any array that can be obtained by deleting some (possibly none or all) elements from nums. Two subsets are different if and only if the chosen indices to delete are different.\n \n Example 1:\n \n >>> numberOfGoodSubsets(nums = [1,2,3,4])\n >>> 6\n Explanation: The good subsets are:\n - [1,2]: product is 2, which is the product of distinct prime 2.\n - [1,2,3]: product is 6, which is the product of distinct primes 2 and 3.\n - [1,3]: product is 3, which is the product of distinct prime 3.\n - [2]: product is 2, which is the product of distinct prime 2.\n - [2,3]: product is 6, which is the product of distinct primes 2 and 3.\n - [3]: product is 3, which is the product of distinct prime 3.\n \n Example 2:\n \n >>> numberOfGoodSubsets(nums = [4,2,3,15])\n >>> 5\n Explanation: The good subsets are:\n - [2]: product is 2, which is the product of distinct prime 2.\n - [2,3]: product is 6, which is the product of distinct primes 2 and 3.\n - [2,15]: product is 30, which is the product of distinct primes 2, 3, and 5.\n - [3]: product is 3, which is the product of distinct prime 3.\n - [15]: product is 15, which is the product of distinct primes 3 and 5.\n \"\"\"\n"}
{"task_id": "count-special-quadruplets", "prompt": "def countQuadruplets(nums: List[int]) -> int:\n \"\"\"\n Given a 0-indexed integer array nums, return the number of distinct quadruplets (a, b, c, d) such that:\n \n nums[a] + nums[b] + nums[c] == nums[d], and\n a < b < c < d\n \n \n Example 1:\n \n >>> countQuadruplets(nums = [1,2,3,6])\n >>> 1\n Explanation: The only quadruplet that satisfies the requirement is (0, 1, 2, 3) because 1 + 2 + 3 == 6.\n \n Example 2:\n \n >>> countQuadruplets(nums = [3,3,6,4,5])\n >>> 0\n Explanation: There are no such quadruplets in [3,3,6,4,5].\n \n Example 3:\n \n >>> countQuadruplets(nums = [1,1,1,3,5])\n >>> 4\n Explanation: The 4 quadruplets that satisfy the requirement are:\n - (0, 1, 2, 3): 1 + 1 + 1 == 3\n - (0, 1, 3, 4): 1 + 1 + 3 == 5\n - (0, 2, 3, 4): 1 + 1 + 3 == 5\n - (1, 2, 3, 4): 1 + 1 + 3 == 5\n \"\"\"\n"}
{"task_id": "the-number-of-weak-characters-in-the-game", "prompt": "def numberOfWeakCharacters(properties: List[List[int]]) -> int:\n \"\"\"\n You are playing a game that contains multiple characters, and each of the characters has two main properties: attack and defense. You are given a 2D integer array properties where properties[i] = [attacki, defensei] represents the properties of the ith character in the game.\n A character is said to be weak if any other character has both attack and defense levels strictly greater than this character's attack and defense levels. More formally, a character i is said to be weak if there exists another character j where attackj > attacki and defensej > defensei.\n Return the number of weak characters.\n \n Example 1:\n \n >>> numberOfWeakCharacters(properties = [[5,5],[6,3],[3,6]])\n >>> 0\n Explanation: No character has strictly greater attack and defense than the other.\n \n Example 2:\n \n >>> numberOfWeakCharacters(properties = [[2,2],[3,3]])\n >>> 1\n Explanation: The first character is weak because the second character has a strictly greater attack and defense.\n \n Example 3:\n \n >>> numberOfWeakCharacters(properties = [[1,5],[10,4],[4,3]])\n >>> 1\n Explanation: The third character is weak because the second character has a strictly greater attack and defense.\n \"\"\"\n"}
{"task_id": "first-day-where-you-have-been-in-all-the-rooms", "prompt": "def firstDayBeenInAllRooms(nextVisit: List[int]) -> int:\n \"\"\"\n There are n rooms you need to visit, labeled from 0 to n - 1. Each day is labeled, starting from 0. You will go in and visit one room a day.\n Initially on day 0, you visit room 0. The order you visit the rooms for the coming days is determined by the following rules and a given 0-indexed array nextVisit of length n:\n \n Assuming that on a day, you visit room i,\n if you have been in room i an odd number of times (including the current visit), on the next day you will visit a room with a lower or equal room number specified by nextVisit[i] where 0 <= nextVisit[i] <= i;\n if you have been in room i an even number of times (including the current visit), on the next day you will visit room (i + 1) mod n.\n \n Return the label of the first day where you have been in all the rooms. It can be shown that such a day exists. Since the answer may be very large, return it modulo 109 + 7.\n \n Example 1:\n \n >>> firstDayBeenInAllRooms(nextVisit = [0,0])\n >>> 2\n Explanation:\n - On day 0, you visit room 0. The total times you have been in room 0 is 1, which is odd.\n \u00a0 On the next day you will visit room nextVisit[0] = 0\n - On day 1, you visit room 0, The total times you have been in room 0 is 2, which is even.\n \u00a0 On the next day you will visit room (0 + 1) mod 2 = 1\n - On day 2, you visit room 1. This is the first day where you have been in all the rooms.\n \n Example 2:\n \n >>> firstDayBeenInAllRooms(nextVisit = [0,0,2])\n >>> 6\n Explanation:\n Your room visiting order for each day is: [0,0,1,0,0,1,2,...].\n Day 6 is the first day where you have been in all the rooms.\n \n Example 3:\n \n >>> firstDayBeenInAllRooms(nextVisit = [0,1,2,0])\n >>> 6\n Explanation:\n Your room visiting order for each day is: [0,0,1,1,2,2,3,...].\n Day 6 is the first day where you have been in all the rooms.\n \"\"\"\n"}
{"task_id": "gcd-sort-of-an-array", "prompt": "def gcdSort(nums: List[int]) -> bool:\n \"\"\"\n You are given an integer array nums, and you can perform the following operation any number of times on nums:\n \n Swap the positions of two elements nums[i] and nums[j] if gcd(nums[i], nums[j]) > 1 where gcd(nums[i], nums[j]) is the greatest common divisor of nums[i] and nums[j].\n \n Return true if it is possible to sort nums in non-decreasing order using the above swap method, or false otherwise.\n \n Example 1:\n \n >>> gcdSort(nums = [7,21,3])\n >>> true\n Explanation: We can sort [7,21,3] by performing the following operations:\n - Swap 7 and 21 because gcd(7,21) = 7. nums = [21,7,3]\n - Swap 21 and 3 because gcd(21,3) = 3. nums = [3,7,21]\n \n Example 2:\n \n >>> gcdSort(nums = [5,2,6,2])\n >>> false\n Explanation: It is impossible to sort the array because 5 cannot be swapped with any other element.\n \n Example 3:\n \n >>> gcdSort(nums = [10,5,9,3,15])\n >>> true\n We can sort [10,5,9,3,15] by performing the following operations:\n - Swap 10 and 15 because gcd(10,15) = 5. nums = [15,5,9,3,10]\n - Swap 15 and 3 because gcd(15,3) = 3. nums = [3,5,9,15,10]\n - Swap 10 and 15 because gcd(10,15) = 5. nums = [3,5,9,10,15]\n \"\"\"\n"}
{"task_id": "smallest-greater-multiple-made-of-two-digits", "prompt": "def findInteger(k: int, digit1: int, digit2: int) -> int:\n \"\"\"\n Given three integers, k, digit1, and digit2, you want to find the smallest integer that is:\n \n Larger than k,\n A multiple of k, and\n Comprised of only the digits digit1 and/or digit2.\n \n Return the smallest such integer. If no such integer exists or the integer exceeds the limit of a signed 32-bit integer (231 - 1), return -1.\n \n Example 1:\n \n >>> findInteger(k = 2, digit1 = 0, digit2 = 2)\n >>> 20\n Explanation:\n 20 is the first integer larger than 2, a multiple of 2, and comprised of only the digits 0 and/or 2.\n \n Example 2:\n \n >>> findInteger(k = 3, digit1 = 4, digit2 = 2)\n >>> 24\n Explanation:\n 24 is the first integer larger than 3, a multiple of 3, and comprised of only the digits 4 and/or 2.\n \n Example 3:\n \n >>> findInteger(k = 2, digit1 = 0, digit2 = 0)\n >>> -1\n Explanation:\n No integer meets the requirements so return -1.\n \"\"\"\n"}
{"task_id": "reverse-prefix-of-word", "prompt": "def reversePrefix(word: str, ch: str) -> str:\n \"\"\"\n Given a 0-indexed string word and a character ch, reverse the segment of word that starts at index 0 and ends at the index of the first occurrence of ch (inclusive). If the character ch does not exist in word, do nothing.\n \n For example, if word = \"abcdefd\" and ch = \"d\", then you should reverse the segment that starts at 0 and ends at 3 (inclusive). The resulting string will be \"dcbaefd\".\n \n Return the resulting string.\n \n Example 1:\n \n >>> reversePrefix(word = \"abcdefd\", ch = \"d\")\n >>> \"dcbaefd\"\n Explanation:\u00a0The first occurrence of \"d\" is at index 3.\n Reverse the part of word from 0 to 3 (inclusive), the resulting string is \"dcbaefd\".\n \n Example 2:\n \n >>> reversePrefix(word = \"xyxzxe\", ch = \"z\")\n >>> \"zxyxxe\"\n Explanation:\u00a0The first and only occurrence of \"z\" is at index 3.\n Reverse the part of word from 0 to 3 (inclusive), the resulting string is \"zxyxxe\".\n \n Example 3:\n \n >>> reversePrefix(word = \"abcd\", ch = \"z\")\n >>> \"abcd\"\n Explanation:\u00a0\"z\" does not exist in word.\n You should not do any reverse operation, the resulting string is \"abcd\".\n \"\"\"\n"}
{"task_id": "number-of-pairs-of-interchangeable-rectangles", "prompt": "def interchangeableRectangles(rectangles: List[List[int]]) -> int:\n \"\"\"\n You are given n rectangles represented by a 0-indexed 2D integer array rectangles, where rectangles[i] = [widthi, heighti] denotes the width and height of the ith rectangle.\n Two rectangles i and j (i < j) are considered interchangeable if they have the same width-to-height ratio. More formally, two rectangles are interchangeable if widthi/heighti == widthj/heightj (using decimal division, not integer division).\n Return the number of pairs of interchangeable rectangles in rectangles.\n \n Example 1:\n \n >>> interchangeableRectangles(rectangles = [[4,8],[3,6],[10,20],[15,30]])\n >>> 6\n Explanation: The following are the interchangeable pairs of rectangles by index (0-indexed):\n - Rectangle 0 with rectangle 1: 4/8 == 3/6.\n - Rectangle 0 with rectangle 2: 4/8 == 10/20.\n - Rectangle 0 with rectangle 3: 4/8 == 15/30.\n - Rectangle 1 with rectangle 2: 3/6 == 10/20.\n - Rectangle 1 with rectangle 3: 3/6 == 15/30.\n - Rectangle 2 with rectangle 3: 10/20 == 15/30.\n \n Example 2:\n \n >>> interchangeableRectangles(rectangles = [[4,5],[7,8]])\n >>> 0\n Explanation: There are no interchangeable pairs of rectangles.\n \"\"\"\n"}
{"task_id": "maximum-product-of-the-length-of-two-palindromic-subsequences", "prompt": "def maxProduct(s: str) -> int:\n \"\"\"\n Given a string s, find two disjoint palindromic subsequences of s such that the product of their lengths is maximized. The two subsequences are disjoint if they do not both pick a character at the same index.\n Return the maximum possible product of the lengths of the two palindromic subsequences.\n A subsequence is a string that can be derived from another string by deleting some or no characters without changing the order of the remaining characters. A string is palindromic if it reads the same forward and backward.\n \n Example 1:\n \n \n >>> maxProduct(s = \"leetcodecom\")\n >>> 9\n Explanation: An optimal solution is to choose \"ete\" for the 1st subsequence and \"cdc\" for the 2nd subsequence.\n The product of their lengths is: 3 * 3 = 9.\n \n Example 2:\n \n >>> maxProduct(s = \"bb\")\n >>> 1\n Explanation: An optimal solution is to choose \"b\" (the first character) for the 1st subsequence and \"b\" (the second character) for the 2nd subsequence.\n The product of their lengths is: 1 * 1 = 1.\n \n Example 3:\n \n >>> maxProduct(s = \"accbcaxxcxx\")\n >>> 25\n Explanation: An optimal solution is to choose \"accca\" for the 1st subsequence and \"xxcxx\" for the 2nd subsequence.\n The product of their lengths is: 5 * 5 = 25.\n \"\"\"\n"}
{"task_id": "smallest-missing-genetic-value-in-each-subtree", "prompt": "def smallestMissingValueSubtree(parents: List[int], nums: List[int]) -> List[int]:\n \"\"\"\n There is a family tree rooted at 0 consisting of n nodes numbered 0 to n - 1. You are given a 0-indexed integer array parents, where parents[i] is the parent for node i. Since node 0 is the root, parents[0] == -1.\n There are 105 genetic values, each represented by an integer in the inclusive range [1, 105]. You are given a 0-indexed integer array nums, where nums[i] is a distinct genetic value for node i.\n Return an array ans of length n where ans[i] is the smallest genetic value that is missing from the subtree rooted at node i.\n The subtree rooted at a node x contains node x and all of its descendant nodes.\n \n Example 1:\n \n \n >>> smallestMissingValueSubtree(parents = [-1,0,0,2], nums = [1,2,3,4])\n >>> [5,1,1,1]\n Explanation: The answer for each subtree is calculated as follows:\n - 0: The subtree contains nodes [0,1,2,3] with values [1,2,3,4]. 5 is the smallest missing value.\n - 1: The subtree contains only node 1 with value 2. 1 is the smallest missing value.\n - 2: The subtree contains nodes [2,3] with values [3,4]. 1 is the smallest missing value.\n - 3: The subtree contains only node 3 with value 4. 1 is the smallest missing value.\n \n Example 2:\n \n \n >>> smallestMissingValueSubtree(parents = [-1,0,1,0,3,3], nums = [5,4,6,2,1,3])\n >>> [7,1,1,4,2,1]\n Explanation: The answer for each subtree is calculated as follows:\n - 0: The subtree contains nodes [0,1,2,3,4,5] with values [5,4,6,2,1,3]. 7 is the smallest missing value.\n - 1: The subtree contains nodes [1,2] with values [4,6]. 1 is the smallest missing value.\n - 2: The subtree contains only node 2 with value 6. 1 is the smallest missing value.\n - 3: The subtree contains nodes [3,4,5] with values [2,1,3]. 4 is the smallest missing value.\n - 4: The subtree contains only node 4 with value 1. 2 is the smallest missing value.\n - 5: The subtree contains only node 5 with value 3. 1 is the smallest missing value.\n \n Example 3:\n \n >>> smallestMissingValueSubtree(parents = [-1,2,3,0,2,4,1], nums = [2,3,4,5,6,7,8])\n >>> [1,1,1,1,1,1,1]\n Explanation: The value 1 is missing from all the subtrees.\n \"\"\"\n"}
{"task_id": "subtree-removal-game-with-fibonacci-tree", "prompt": "def findGameWinner(n: int) -> bool:\n \"\"\"\n A Fibonacci tree is a binary tree created using the order function order(n):\n \n order(0) is the empty tree.\n order(1) is a binary tree with only one node.\n order(n) is a binary tree that consists of a root node with the left subtree as order(n - 2) and the right subtree as order(n - 1).\n \n Alice and Bob are playing a game with a Fibonacci tree with Alice staring first. On each turn, a player selects a node and removes that node and its subtree. The player that is forced to delete root loses.\n Given the integer n, return true if Alice wins the game or false if Bob wins, assuming both players play optimally.\n A subtree of a binary tree tree is a tree that consists of a node in tree and all of this node's descendants. The tree tree could also be considered as a subtree of itself.\n \n Example 1:\n \n \n >>> findGameWinner(n = 3)\n >>> true\n Explanation:\n Alice takes the node 1 in the right subtree.\n Bob takes either the 1 in the left subtree or the 2 in the right subtree.\n Alice takes whichever node Bob doesn't take.\n Bob is forced to take the root node 3, so Bob will lose.\n Return true because Alice wins.\n \n Example 2:\n \n \n >>> findGameWinner(n = 1)\n >>> false\n Explanation:\n Alice is forced to take the root node 1, so Alice will lose.\n Return false because Alice loses.\n \n Example 3:\n \n \n >>> findGameWinner(n = 2)\n >>> true\n Explanation:\n Alice takes the node 1.\n Bob is forced to take the root node 2, so Bob will lose.\n Return true because Alice wins.\n \"\"\"\n"}
{"task_id": "count-number-of-pairs-with-absolute-difference-k", "prompt": "def countKDifference(nums: List[int], k: int) -> int:\n \"\"\"\n Given an integer array nums and an integer k, return the number of pairs (i, j) where i < j such that |nums[i] - nums[j]| == k.\n The value of |x| is defined as:\n \n x if x >= 0.\n -x if x < 0.\n \n \n Example 1:\n \n >>> countKDifference(nums = [1,2,2,1], k = 1)\n >>> 4\n Explanation: The pairs with an absolute difference of 1 are:\n - [1,2,2,1]\n - [1,2,2,1]\n - [1,2,2,1]\n - [1,2,2,1]\n \n Example 2:\n \n >>> countKDifference(nums = [1,3], k = 3)\n >>> 0\n Explanation: There are no pairs with an absolute difference of 3.\n \n Example 3:\n \n >>> countKDifference(nums = [3,2,1,5,4], k = 2)\n >>> 3\n Explanation: The pairs with an absolute difference of 2 are:\n - [3,2,1,5,4]\n - [3,2,1,5,4]\n - [3,2,1,5,4]\n \"\"\"\n"}
{"task_id": "find-original-array-from-doubled-array", "prompt": "def findOriginalArray(changed: List[int]) -> List[int]:\n \"\"\"\n An integer array original is transformed into a doubled array changed by appending twice the value of every element in original, and then randomly shuffling the resulting array.\n Given an array changed, return original if changed is a doubled array. If changed is not a doubled array, return an empty array. The elements in original may be returned in any order.\n \n Example 1:\n \n >>> findOriginalArray(changed = [1,3,4,2,6,8])\n >>> [1,3,4]\n Explanation: One possible original array could be [1,3,4]:\n - Twice the value of 1 is 1 * 2 = 2.\n - Twice the value of 3 is 3 * 2 = 6.\n - Twice the value of 4 is 4 * 2 = 8.\n Other original arrays could be [4,3,1] or [3,1,4].\n \n Example 2:\n \n >>> findOriginalArray(changed = [6,3,0,1])\n >>> []\n Explanation: changed is not a doubled array.\n \n Example 3:\n \n >>> findOriginalArray(changed = [1])\n >>> []\n Explanation: changed is not a doubled array.\n \"\"\"\n"}
{"task_id": "maximum-earnings-from-taxi", "prompt": "def maxTaxiEarnings(n: int, rides: List[List[int]]) -> int:\n \"\"\"\n There are n points on a road you are driving your taxi on. The n points on the road are labeled from 1 to n in the direction you are going, and you want to drive from point 1 to point n to make money by picking up passengers. You cannot change the direction of the taxi.\n The passengers are represented by a 0-indexed 2D integer array rides, where rides[i] = [starti, endi, tipi] denotes the ith passenger requesting a ride from point starti to point endi who is willing to give a tipi dollar tip.\n For each passenger i you pick up, you earn endi - starti + tipi dollars. You may only drive at most one passenger at a time.\n Given n and rides, return the maximum number of dollars you can earn by picking up the passengers optimally.\n Note: You may drop off a passenger and pick up a different passenger at the same point.\n \n Example 1:\n \n >>> maxTaxiEarnings(n = 5, rides = [[2,5,4],[1,5,1]])\n >>> 7\n Explanation: We can pick up passenger 0 to earn 5 - 2 + 4 = 7 dollars.\n \n Example 2:\n \n >>> maxTaxiEarnings(n = 20, rides = [[1,6,1],[3,10,2],[10,12,3],[11,12,2],[12,15,2],[13,18,1]])\n >>> 20\n Explanation: We will pick up the following passengers:\n - Drive passenger 1 from point 3 to point 10 for a profit of 10 - 3 + 2 = 9 dollars.\n - Drive passenger 2 from point 10 to point 12 for a profit of 12 - 10 + 3 = 5 dollars.\n - Drive passenger 5 from point 13 to point 18 for a profit of 18 - 13 + 1 = 6 dollars.\n We earn 9 + 5 + 6 = 20 dollars in total.\n \"\"\"\n"}
{"task_id": "minimum-number-of-operations-to-make-array-continuous", "prompt": "def minOperations(nums: List[int]) -> int:\n \"\"\"\n You are given an integer array nums. In one operation, you can replace any element in nums with any integer.\n nums is considered continuous if both of the following conditions are fulfilled:\n \n All elements in nums are unique.\n The difference between the maximum element and the minimum element in nums equals nums.length - 1.\n \n For example, nums = [4, 2, 5, 3] is continuous, but nums = [1, 2, 3, 5, 6] is not continuous.\n Return the minimum number of operations to make nums continuous.\n \n Example 1:\n \n >>> minOperations(nums = [4,2,5,3])\n >>> 0\n Explanation:\u00a0nums is already continuous.\n \n Example 2:\n \n >>> minOperations(nums = [1,2,3,5,6])\n >>> 1\n Explanation:\u00a0One possible solution is to change the last element to 4.\n The resulting array is [1,2,3,5,4], which is continuous.\n \n Example 3:\n \n >>> minOperations(nums = [1,10,100,1000])\n >>> 3\n Explanation:\u00a0One possible solution is to:\n - Change the second element to 2.\n - Change the third element to 3.\n - Change the fourth element to 4.\n The resulting array is [1,2,3,4], which is continuous.\n \"\"\"\n"}
{"task_id": "final-value-of-variable-after-performing-operations", "prompt": "def finalValueAfterOperations(operations: List[str]) -> int:\n \"\"\"\n There is a programming language with only four operations and one variable X:\n \n ++X and X++ increments the value of the variable X by 1.\n --X and X-- decrements the value of the variable X by 1.\n \n Initially, the value of X is 0.\n Given an array of strings operations containing a list of operations, return the final value of X after performing all the operations.\n \n Example 1:\n \n >>> finalValueAfterOperations(operations = [\"--X\",\"X++\",\"X++\"])\n >>> 1\n Explanation:\u00a0The operations are performed as follows:\n Initially, X = 0.\n --X: X is decremented by 1, X = 0 - 1 = -1.\n X++: X is incremented by 1, X = -1 + 1 = 0.\n X++: X is incremented by 1, X = 0 + 1 = 1.\n \n Example 2:\n \n >>> finalValueAfterOperations(operations = [\"++X\",\"++X\",\"X++\"])\n >>> 3\n Explanation: The operations are performed as follows:\n Initially, X = 0.\n ++X: X is incremented by 1, X = 0 + 1 = 1.\n ++X: X is incremented by 1, X = 1 + 1 = 2.\n X++: X is incremented by 1, X = 2 + 1 = 3.\n \n Example 3:\n \n >>> finalValueAfterOperations(operations = [\"X++\",\"++X\",\"--X\",\"X--\"])\n >>> 0\n Explanation:\u00a0The operations are performed as follows:\n Initially, X = 0.\n X++: X is incremented by 1, X = 0 + 1 = 1.\n ++X: X is incremented by 1, X = 1 + 1 = 2.\n --X: X is decremented by 1, X = 2 - 1 = 1.\n X--: X is decremented by 1, X = 1 - 1 = 0.\n \"\"\"\n"}
{"task_id": "sum-of-beauty-in-the-array", "prompt": "def sumOfBeauties(nums: List[int]) -> int:\n \"\"\"\n You are given a 0-indexed integer array nums. For each index i (1 <= i <= nums.length - 2) the beauty of nums[i] equals:\n \n 2, if nums[j] < nums[i] < nums[k], for all 0 <= j < i and for all i < k <= nums.length - 1.\n 1, if nums[i - 1] < nums[i] < nums[i + 1], and the previous condition is not satisfied.\n 0, if none of the previous conditions holds.\n \n Return the sum of beauty of all nums[i] where 1 <= i <= nums.length - 2.\n \n Example 1:\n \n >>> sumOfBeauties(nums = [1,2,3])\n >>> 2\n Explanation: For each index i in the range 1 <= i <= 1:\n - The beauty of nums[1] equals 2.\n \n Example 2:\n \n >>> sumOfBeauties(nums = [2,4,6,4])\n >>> 1\n Explanation: For each index i in the range 1 <= i <= 2:\n - The beauty of nums[1] equals 1.\n - The beauty of nums[2] equals 0.\n \n Example 3:\n \n >>> sumOfBeauties(nums = [3,2,1])\n >>> 0\n Explanation: For each index i in the range 1 <= i <= 1:\n - The beauty of nums[1] equals 0.\n \"\"\"\n"}
{"task_id": "longest-subsequence-repeated-k-times", "prompt": "def longestSubsequenceRepeatedK(s: str, k: int) -> str:\n \"\"\"\n You are given a string s of length n, and an integer k. You are tasked to find the longest subsequence repeated k times in string s.\n A subsequence is a string that can be derived from another string by deleting some or no characters without changing the order of the remaining characters.\n A subsequence seq is repeated k times in the string s if seq * k is a subsequence of s, where seq * k represents a string constructed by concatenating seq k times.\n \n For example, \"bba\" is repeated 2 times in the string \"bababcba\", because the string \"bbabba\", constructed by concatenating \"bba\" 2 times, is a subsequence of the string \"bababcba\".\n \n Return the longest subsequence repeated k times in string s. If multiple such subsequences are found, return the lexicographically largest one. If there is no such subsequence, return an empty string.\n \n Example 1:\n \n \n >>> longestSubsequenceRepeatedK(s = \"letsleetcode\", k = 2)\n >>> \"let\"\n Explanation: There are two longest subsequences repeated 2 times: \"let\" and \"ete\".\n \"let\" is the lexicographically largest one.\n \n Example 2:\n \n >>> longestSubsequenceRepeatedK(s = \"bb\", k = 2)\n >>> \"b\"\n Explanation: The longest subsequence repeated 2 times is \"b\".\n \n Example 3:\n \n >>> longestSubsequenceRepeatedK(s = \"ab\", k = 2)\n >>> \"\"\n Explanation: There is no subsequence repeated 2 times. Empty string is returned.\n \"\"\"\n"}
{"task_id": "average-height-of-buildings-in-each-segment", "prompt": "def averageHeightOfBuildings(buildings: List[List[int]]) -> List[List[int]]:\n \"\"\"\n A perfectly straight street is represented by a number line. The street has building(s) on it and is represented by a 2D integer array buildings, where buildings[i] = [starti, endi, heighti]. This means that there is a building with heighti in the half-closed segment [starti, endi).\n You want to describe the heights of the buildings on the street with the minimum number of non-overlapping segments. The street can be represented by the 2D integer array street where street[j] = [leftj, rightj, averagej] describes a half-closed segment [leftj, rightj) of the road where the average heights of the buildings in the segment is averagej.\n \n For example, if buildings = [[1,5,2],[3,10,4]], the street could be represented by street = [[1,3,2],[3,5,3],[5,10,4]] because:\n \n \n From 1 to 3, there is only the first building with an average height of 2 / 1 = 2.\n From 3 to 5, both the first and the second building are there with an average height of (2+4) / 2 = 3.\n From 5 to 10, there is only the second building with an average height of 4 / 1 = 4.\n \n \n \n Given buildings, return the 2D integer array street as described above (excluding any areas of the street where there are no buldings). You may return the array in any order.\n The average of n elements is the sum of the n elements divided (integer division) by n.\n A half-closed segment [a, b) is the section of the number line between points a and b including point a and not including point b.\n \n Example 1:\n \n \n >>> averageHeightOfBuildings(buildings = [[1,4,2],[3,9,4]])\n >>> [[1,3,2],[3,4,3],[4,9,4]]\n Explanation:\n From 1 to 3, there is only the first building with an average height of 2 / 1 = 2.\n From 3 to 4, both the first and the second building are there with an average height of (2+4) / 2 = 3.\n From 4 to 9, there is only the second building with an average height of 4 / 1 = 4.\n \n Example 2:\n \n >>> averageHeightOfBuildings(buildings = [[1,3,2],[2,5,3],[2,8,3]])\n >>> [[1,3,2],[3,8,3]]\n Explanation:\n From 1 to 2, there is only the first building with an average height of 2 / 1 = 2.\n From 2 to 3, all three buildings are there with an average height of (2+3+3) / 3 = 2.\n From 3 to 5, both the second and the third building are there with an average height of (3+3) / 2 = 3.\n From 5 to 8, there is only the last building with an average height of 3 / 1 = 3.\n The average height from 1 to 3 is the same so we can group them into one segment.\n The average height from 3 to 8 is the same so we can group them into one segment.\n \n Example 3:\n \n >>> averageHeightOfBuildings(buildings = [[1,2,1],[5,6,1]])\n >>> [[1,2,1],[5,6,1]]\n Explanation:\n From 1 to 2, there is only the first building with an average height of 1 / 1 = 1.\n From 2 to 5, there are no buildings, so it is not included in the output.\n From 5 to 6, there is only the second building with an average height of 1 / 1 = 1.\n We cannot group the segments together because an empty space with no buildings seperates the segments.\n \"\"\"\n"}
{"task_id": "maximum-difference-between-increasing-elements", "prompt": "def maximumDifference(nums: List[int]) -> int:\n \"\"\"\n Given a 0-indexed integer array nums of size n, find the maximum difference between nums[i] and nums[j] (i.e., nums[j] - nums[i]), such that 0 <= i < j < n and nums[i] < nums[j].\n Return the maximum difference. If no such i and j exists, return -1.\n \n Example 1:\n \n >>> maximumDifference(nums = [7,1,5,4])\n >>> 4\n Explanation:\n The maximum difference occurs with i = 1 and j = 2, nums[j] - nums[i] = 5 - 1 = 4.\n Note that with i = 1 and j = 0, the difference nums[j] - nums[i] = 7 - 1 = 6, but i > j, so it is not valid.\n \n Example 2:\n \n >>> maximumDifference(nums = [9,4,3,2])\n >>> -1\n Explanation:\n There is no i and j such that i < j and nums[i] < nums[j].\n \n Example 3:\n \n >>> maximumDifference(nums = [1,5,2,10])\n >>> 9\n Explanation:\n The maximum difference occurs with i = 0 and j = 3, nums[j] - nums[i] = 10 - 1 = 9.\n \"\"\"\n"}
{"task_id": "grid-game", "prompt": "def gridGame(grid: List[List[int]]) -> int:\n \"\"\"\n You are given a 0-indexed 2D array grid of size 2 x n, where grid[r][c] represents the number of points at position (r, c) on the matrix. Two robots are playing a game on this matrix.\n Both robots initially start at (0, 0) and want to reach (1, n-1). Each robot may only move to the right ((r, c) to (r, c + 1)) or down ((r, c) to (r + 1, c)).\n At the start of the game, the first robot moves from (0, 0) to (1, n-1), collecting all the points from the cells on its path. For all cells (r, c) traversed on the path, grid[r][c] is set to 0. Then, the second robot moves from (0, 0) to (1, n-1), collecting the points on its path. Note that their paths may intersect with one another.\n The first robot wants to minimize the number of points collected by the second robot. In contrast, the second robot wants to maximize the number of points it collects. If both robots play optimally, return the number of points collected by the second robot.\n \n Example 1:\n \n \n >>> gridGame(grid = [[2,5,4],[1,5,1]])\n >>> 4\n Explanation: The optimal path taken by the first robot is shown in red, and the optimal path taken by the second robot is shown in blue.\n The cells visited by the first robot are set to 0.\n The second robot will collect 0 + 0 + 4 + 0 = 4 points.\n \n Example 2:\n \n \n >>> gridGame(grid = [[3,3,1],[8,5,2]])\n >>> 4\n Explanation: The optimal path taken by the first robot is shown in red, and the optimal path taken by the second robot is shown in blue.\n The cells visited by the first robot are set to 0.\n The second robot will collect 0 + 3 + 1 + 0 = 4 points.\n \n Example 3:\n \n \n >>> gridGame(grid = [[1,3,1,15],[1,3,3,1]])\n >>> 7\n Explanation: The optimal path taken by the first robot is shown in red, and the optimal path taken by the second robot is shown in blue.\n The cells visited by the first robot are set to 0.\n The second robot will collect 0 + 1 + 3 + 3 + 0 = 7 points.\n \"\"\"\n"}
{"task_id": "check-if-word-can-be-placed-in-crossword", "prompt": "def placeWordInCrossword(board: List[List[str]], word: str) -> bool:\n \"\"\"\n You are given an m x n matrix board, representing the current state of a crossword puzzle. The crossword contains lowercase English letters (from solved words), ' ' to represent any empty cells, and '#' to represent any blocked cells.\n A word can be placed horizontally (left to right or right to left) or vertically (top to bottom or bottom to top) in the board if:\n \n It does not occupy a cell containing the character '#'.\n The cell each letter is placed in must either be ' ' (empty) or match the letter already on the board.\n There must not be any empty cells ' ' or other lowercase letters directly left or right of the word if the word was placed horizontally.\n There must not be any empty cells ' ' or other lowercase letters directly above or below the word if the word was placed vertically.\n \n Given a string word, return true if word can be placed in board, or false otherwise.\n \n Example 1:\n \n \n >>> placeWordInCrossword(board = [[\"#\", \" \", \"#\"], [\" \", \" \", \"#\"], [\"#\", \"c\", \" \"]], word = \"abc\")\n >>> true\n Explanation: The word \"abc\" can be placed as shown above (top to bottom).\n \n Example 2:\n \n \n >>> placeWordInCrossword(board = [[\" \", \"#\", \"a\"], [\" \", \"#\", \"c\"], [\" \", \"#\", \"a\"]], word = \"ac\")\n >>> false\n Explanation: It is impossible to place the word because there will always be a space/letter above or below it.\n Example 3:\n \n \n >>> placeWordInCrossword(board = [[\"#\", \" \", \"#\"], [\" \", \" \", \"#\"], [\"#\", \" \", \"c\"]], word = \"ca\")\n >>> true\n Explanation: The word \"ca\" can be placed as shown above (right to left).\n \"\"\"\n"}
{"task_id": "the-score-of-students-solving-math-expression", "prompt": "def scoreOfStudents(s: str, answers: List[int]) -> int:\n \"\"\"\n You are given a string s that contains digits 0-9, addition symbols '+', and multiplication symbols '*' only, representing a valid math expression of single digit numbers (e.g., 3+5*2). This expression was given to n elementary school students. The students were instructed to get the answer of the expression by following this order of operations:\n \n Compute multiplication, reading from left to right; Then,\n Compute addition, reading from left to right.\n \n You are given an integer array answers of length n, which are the submitted answers of the students in no particular order. You are asked to grade the answers, by following these rules:\n \n If an answer equals the correct answer of the expression, this student will be rewarded 5 points;\n Otherwise, if the answer could be interpreted as if the student applied the operators in the wrong order but had correct arithmetic, this student will be rewarded 2 points;\n Otherwise, this student will be rewarded 0 points.\n \n Return the sum of the points of the students.\n \n Example 1:\n \n \n >>> scoreOfStudents(s = \"7+3*1*2\", answers = [20,13,42])\n >>> 7\n Explanation: As illustrated above, the correct answer of the expression is 13, therefore one student is rewarded 5 points: [20,13,42]\n A student might have applied the operators in this wrong order: ((7+3)*1)*2 = 20. Therefore one student is rewarded 2 points: [20,13,42]\n The points for the students are: [2,5,0]. The sum of the points is 2+5+0=7.\n \n Example 2:\n \n >>> scoreOfStudents(s = \"3+5*2\", answers = [13,0,10,13,13,16,16])\n >>> 19\n Explanation: The correct answer of the expression is 13, therefore three students are rewarded 5 points each: [13,0,10,13,13,16,16]\n A student might have applied the operators in this wrong order: ((3+5)*2 = 16. Therefore two students are rewarded 2 points: [13,0,10,13,13,16,16]\n The points for the students are: [5,0,0,5,5,2,2]. The sum of the points is 5+0+0+5+5+2+2=19.\n \n Example 3:\n \n >>> scoreOfStudents(s = \"6+0*1\", answers = [12,9,6,4,8,6])\n >>> 10\n Explanation: The correct answer of the expression is 6.\n If a student had incorrectly done (6+0)*1, the answer would also be 6.\n By the rules of grading, the students will still be rewarded 5 points (as they got the correct answer), not 2 points.\n The points for the students are: [0,0,5,0,0,5]. The sum of the points is 10.\n \"\"\"\n"}
{"task_id": "brightest-position-on-street", "prompt": "def brightestPosition(lights: List[List[int]]) -> int:\n \"\"\"\n A perfectly straight street is represented by a number line. The street has street lamp(s) on it and is represented by a 2D integer array lights. Each lights[i] = [positioni, rangei] indicates that there is a street lamp at position positioni that lights up the area from [positioni - rangei, positioni + rangei] (inclusive).\n The brightness of a position p is defined as the number of street lamp that light up the position p.\n Given lights, return the brightest position on the street. If there are multiple brightest positions, return the smallest one.\n \n Example 1:\n \n \n >>> brightestPosition(lights = [[-3,2],[1,2],[3,3]])\n >>> -1\n Explanation:\n The first street lamp lights up the area from [(-3) - 2, (-3) + 2] = [-5, -1].\n The second street lamp lights up the area from [1 - 2, 1 + 2] = [-1, 3].\n The third street lamp lights up the area from [3 - 3, 3 + 3] = [0, 6].\n \n Position -1 has a brightness of 2, illuminated by the first and second street light.\n Positions 0, 1, 2, and 3 have a brightness of 2, illuminated by the second and third street light.\n Out of all these positions, -1 is the smallest, so return it.\n \n Example 2:\n \n >>> brightestPosition(lights = [[1,0],[0,1]])\n >>> 1\n Explanation:\n The first street lamp lights up the area from [1 - 0, 1 + 0] = [1, 1].\n The second street lamp lights up the area from [0 - 1, 0 + 1] = [-1, 1].\n \n Position 1 has a brightness of 2, illuminated by the first and second street light.\n Return 1 because it is the brightest position on the street.\n \n Example 3:\n \n >>> brightestPosition(lights = [[1,2]])\n >>> -1\n Explanation:\n The first street lamp lights up the area from [1 - 2, 1 + 2] = [-1, 3].\n \n Positions -1, 0, 1, 2, and 3 have a brightness of 1, illuminated by the first street light.\n Out of all these positions, -1 is the smallest, so return it.\n \"\"\"\n"}
{"task_id": "convert-1d-array-into-2d-array", "prompt": "def construct2DArray(original: List[int], m: int, n: int) -> List[List[int]]:\n \"\"\"\n You are given a 0-indexed 1-dimensional (1D) integer array original, and two integers, m and n. You are tasked with creating a 2-dimensional (2D) array with m rows and n columns using all the elements from original.\n The elements from indices 0 to n - 1 (inclusive) of original should form the first row of the constructed 2D array, the elements from indices n to 2 * n - 1 (inclusive) should form the second row of the constructed 2D array, and so on.\n Return an m x n 2D array constructed according to the above procedure, or an empty 2D array if it is impossible.\n \n Example 1:\n \n \n >>> construct2DArray(original = [1,2,3,4], m = 2, n = 2)\n >>> [[1,2],[3,4]]\n Explanation: The constructed 2D array should contain 2 rows and 2 columns.\n The first group of n=2 elements in original, [1,2], becomes the first row in the constructed 2D array.\n The second group of n=2 elements in original, [3,4], becomes the second row in the constructed 2D array.\n \n Example 2:\n \n >>> construct2DArray(original = [1,2,3], m = 1, n = 3)\n >>> [[1,2,3]]\n Explanation: The constructed 2D array should contain 1 row and 3 columns.\n Put all three elements in original into the first row of the constructed 2D array.\n \n Example 3:\n \n >>> construct2DArray(original = [1,2], m = 1, n = 1)\n >>> []\n Explanation: There are 2 elements in original.\n It is impossible to fit 2 elements in a 1x1 2D array, so return an empty 2D array.\n \"\"\"\n"}
{"task_id": "number-of-pairs-of-strings-with-concatenation-equal-to-target", "prompt": "def numOfPairs(nums: List[str], target: str) -> int:\n \"\"\"\n Given an array of digit strings nums and a digit string target, return the number of pairs of indices (i, j) (where i != j) such that the concatenation of nums[i] + nums[j] equals target.\n \n Example 1:\n \n >>> numOfPairs(nums = [\"777\",\"7\",\"77\",\"77\"], target = \"7777\")\n >>> 4\n Explanation: Valid pairs are:\n - (0, 1): \"777\" + \"7\"\n - (1, 0): \"7\" + \"777\"\n - (2, 3): \"77\" + \"77\"\n - (3, 2): \"77\" + \"77\"\n \n Example 2:\n \n >>> numOfPairs(nums = [\"123\",\"4\",\"12\",\"34\"], target = \"1234\")\n >>> 2\n Explanation: Valid pairs are:\n - (0, 1): \"123\" + \"4\"\n - (2, 3): \"12\" + \"34\"\n \n Example 3:\n \n >>> numOfPairs(nums = [\"1\",\"1\",\"1\"], target = \"11\")\n >>> 6\n Explanation: Valid pairs are:\n - (0, 1): \"1\" + \"1\"\n - (1, 0): \"1\" + \"1\"\n - (0, 2): \"1\" + \"1\"\n - (2, 0): \"1\" + \"1\"\n - (1, 2): \"1\" + \"1\"\n - (2, 1): \"1\" + \"1\"\n \"\"\"\n"}
{"task_id": "maximize-the-confusion-of-an-exam", "prompt": "def maxConsecutiveAnswers(answerKey: str, k: int) -> int:\n \"\"\"\n A teacher is writing a test with n true/false questions, with 'T' denoting true and 'F' denoting false. He wants to confuse the students by maximizing the number of consecutive questions with the same answer (multiple trues or multiple falses in a row).\n You are given a string answerKey, where answerKey[i] is the original answer to the ith question. In addition, you are given an integer k, the maximum number of times you may perform the following operation:\n \n Change the answer key for any question to 'T' or 'F' (i.e., set answerKey[i] to 'T' or 'F').\n \n Return the maximum number of consecutive 'T's or 'F's in the answer key after performing the operation at most k times.\n \n Example 1:\n \n >>> maxConsecutiveAnswers(answerKey = \"TTFF\", k = 2)\n >>> 4\n Explanation: We can replace both the 'F's with 'T's to make answerKey = \"TTTT\".\n There are four consecutive 'T's.\n \n Example 2:\n \n >>> maxConsecutiveAnswers(answerKey = \"TFFT\", k = 1)\n >>> 3\n Explanation: We can replace the first 'T' with an 'F' to make answerKey = \"FFFT\".\n Alternatively, we can replace the second 'T' with an 'F' to make answerKey = \"TFFF\".\n In both cases, there are three consecutive 'F's.\n \n Example 3:\n \n >>> maxConsecutiveAnswers(answerKey = \"TTFTTFTT\", k = 1)\n >>> 5\n Explanation: We can replace the first 'F' to make answerKey = \"TTTTTFTT\"\n Alternatively, we can replace the second 'F' to make answerKey = \"TTFTTTTT\".\n In both cases, there are five consecutive 'T's.\n \"\"\"\n"}
{"task_id": "maximum-number-of-ways-to-partition-an-array", "prompt": "def waysToPartition(nums: List[int], k: int) -> int:\n \"\"\"\n You are given a 0-indexed integer array nums of length n. The number of ways to partition nums is the number of pivot indices that satisfy both conditions:\n \n 1 <= pivot < n\n nums[0] + nums[1] + ... + nums[pivot - 1] == nums[pivot] + nums[pivot + 1] + ... + nums[n - 1]\n \n You are also given an integer k. You can choose to change the value of one element of nums to k, or to leave the array unchanged.\n Return the maximum possible number of ways to partition nums to satisfy both conditions after changing at most one element.\n \n Example 1:\n \n >>> waysToPartition(nums = [2,-1,2], k = 3)\n >>> 1\n Explanation: One optimal approach is to change nums[0] to k. The array becomes [3,-1,2].\n There is one way to partition the array:\n - For pivot = 2, we have the partition [3,-1 | 2]: 3 + -1 == 2.\n \n Example 2:\n \n >>> waysToPartition(nums = [0,0,0], k = 1)\n >>> 2\n Explanation: The optimal approach is to leave the array unchanged.\n There are two ways to partition the array:\n - For pivot = 1, we have the partition [0 | 0,0]: 0 == 0 + 0.\n - For pivot = 2, we have the partition [0,0 | 0]: 0 + 0 == 0.\n \n Example 3:\n \n >>> waysToPartition(nums = [22,4,-25,-20,-15,15,-16,7,19,-10,0,-13,-14], k = -33)\n >>> 4\n Explanation: One optimal approach is to change nums[2] to k. The array becomes [22,4,-33,-20,-15,15,-16,7,19,-10,0,-13,-14].\n There are four ways to partition the array.\n \"\"\"\n"}
{"task_id": "minimum-moves-to-convert-string", "prompt": "def minimumMoves(s: str) -> int:\n \"\"\"\n You are given a string s consisting of n characters which are either 'X' or 'O'.\n A move is defined as selecting three consecutive characters of s and converting them to 'O'. Note that if a move is applied to the character 'O', it will stay the same.\n Return the minimum number of moves required so that all the characters of s are converted to 'O'.\n \n Example 1:\n \n >>> minimumMoves(s = \"XXX\")\n >>> 1\n Explanation: XXX -> OOO\n We select all the 3 characters and convert them in one move.\n \n Example 2:\n \n >>> minimumMoves(s = \"XXOX\")\n >>> 2\n Explanation: XXOX -> OOOX -> OOOO\n We select the first 3 characters in the first move, and convert them to 'O'.\n Then we select the last 3 characters and convert them so that the final string contains all 'O's.\n Example 3:\n \n >>> minimumMoves(s = \"OOOO\")\n >>> 0\n Explanation: There are no 'X's in s to convert.\n \"\"\"\n"}
{"task_id": "find-missing-observations", "prompt": "def missingRolls(rolls: List[int], mean: int, n: int) -> List[int]:\n \"\"\"\n You have observations of n + m 6-sided dice rolls with each face numbered from 1 to 6. n of the observations went missing, and you only have the observations of m rolls. Fortunately, you have also calculated the average value of the n + m rolls.\n You are given an integer array rolls of length m where rolls[i] is the value of the ith observation. You are also given the two integers mean and n.\n Return an array of length n containing the missing observations such that the average value of the n + m rolls is exactly mean. If there are multiple valid answers, return any of them. If no such array exists, return an empty array.\n The average value of a set of k numbers is the sum of the numbers divided by k.\n Note that mean is an integer, so the sum of the n + m rolls should be divisible by n + m.\n \n Example 1:\n \n >>> missingRolls(rolls = [3,2,4,3], mean = 4, n = 2)\n >>> [6,6]\n Explanation: The mean of all n + m rolls is (3 + 2 + 4 + 3 + 6 + 6) / 6 = 4.\n \n Example 2:\n \n >>> missingRolls(rolls = [1,5,6], mean = 3, n = 4)\n >>> [2,3,2,2]\n Explanation: The mean of all n + m rolls is (1 + 5 + 6 + 2 + 3 + 2 + 2) / 7 = 3.\n \n Example 3:\n \n >>> missingRolls(rolls = [1,2,3,4], mean = 6, n = 4)\n >>> []\n Explanation: It is impossible for the mean to be 6 no matter what the 4 missing rolls are.\n \"\"\"\n"}
{"task_id": "stone-game-ix", "prompt": "def stoneGameIX(stones: List[int]) -> bool:\n \"\"\"\n Alice and Bob continue their games with stones. There is a row of n stones, and each stone has an associated value. You are given an integer array stones, where stones[i] is the value of the ith stone.\n Alice and Bob take turns, with Alice starting first. On each turn, the player may remove any stone from stones. The player who removes a stone loses if the sum of the values of all removed stones is divisible by 3. Bob will win automatically if there are no remaining stones (even if it is Alice's turn).\n Assuming both players play optimally, return true if Alice wins and false if Bob wins.\n \n Example 1:\n \n >>> stoneGameIX(stones = [2,1])\n >>> true\n Explanation:\u00a0The game will be played as follows:\n - Turn 1: Alice can remove either stone.\n - Turn 2: Bob removes the remaining stone.\n The sum of the removed stones is 1 + 2 = 3 and is divisible by 3. Therefore, Bob loses and Alice wins the game.\n \n Example 2:\n \n >>> stoneGameIX(stones = [2])\n >>> false\n Explanation:\u00a0Alice will remove the only stone, and the sum of the values on the removed stones is 2.\n Since all the stones are removed and the sum of values is not divisible by 3, Bob wins the game.\n \n Example 3:\n \n >>> stoneGameIX(stones = [5,1,2,4,3])\n >>> false\n Explanation: Bob will always win. One possible way for Bob to win is shown below:\n - Turn 1: Alice can remove the second stone with value 1. Sum of removed stones = 1.\n - Turn 2: Bob removes the fifth stone with value 3. Sum of removed stones = 1 + 3 = 4.\n - Turn 3: Alices removes the fourth stone with value 4. Sum of removed stones = 1 + 3 + 4 = 8.\n - Turn 4: Bob removes the third stone with value 2. Sum of removed stones = 1 + 3 + 4 + 2 = 10.\n - Turn 5: Alice removes the first stone with value 5. Sum of removed stones = 1 + 3 + 4 + 2 + 5 = 15.\n Alice loses the game because the sum of the removed stones (15) is divisible by 3. Bob wins the game.\n \"\"\"\n"}
{"task_id": "smallest-k-length-subsequence-with-occurrences-of-a-letter", "prompt": "def smallestSubsequence(s: str, k: int, letter: str, repetition: int) -> str:\n \"\"\"\n You are given a string s, an integer k, a letter letter, and an integer repetition.\n Return the lexicographically smallest subsequence of s of length k that has the letter letter appear at least repetition times. The test cases are generated so that the letter appears in s at least repetition times.\n A subsequence is a string that can be derived from another string by deleting some or no characters without changing the order of the remaining characters.\n A string a is lexicographically smaller than a string b if in the first position where a and b differ, string a has a letter that appears earlier in the alphabet than the corresponding letter in b.\n \n Example 1:\n \n >>> smallestSubsequence(s = \"leet\", k = 3, letter = \"e\", repetition = 1)\n >>> \"eet\"\n Explanation: There are four subsequences of length 3 that have the letter 'e' appear at least 1 time:\n - \"lee\" (from \"leet\")\n - \"let\" (from \"leet\")\n - \"let\" (from \"leet\")\n - \"eet\" (from \"leet\")\n The lexicographically smallest subsequence among them is \"eet\".\n \n Example 2:\n \n \n >>> smallestSubsequence(s = \"leetcode\", k = 4, letter = \"e\", repetition = 2)\n >>> \"ecde\"\n Explanation: \"ecde\" is the lexicographically smallest subsequence of length 4 that has the letter \"e\" appear at least 2 times.\n \n Example 3:\n \n >>> smallestSubsequence(s = \"bb\", k = 2, letter = \"b\", repetition = 2)\n >>> \"bb\"\n Explanation: \"bb\" is the only subsequence of length 2 that has the letter \"b\" appear at least 2 times.\n \"\"\"\n"}
{"task_id": "count-subarrays-with-more-ones-than-zeros", "prompt": "def subarraysWithMoreZerosThanOnes(nums: List[int]) -> int:\n \"\"\"\n You are given a binary array nums containing only the integers 0 and 1. Return the number of subarrays in nums that have more 1's than 0's. Since the answer may be very large, return it modulo 109 + 7.\n A subarray is a contiguous sequence of elements within an array.\n \n Example 1:\n \n >>> subarraysWithMoreZerosThanOnes(nums = [0,1,1,0,1])\n >>> 9\n Explanation:\n The subarrays of size 1 that have more ones than zeros are: [1], [1], [1]\n The subarrays of size 2 that have more ones than zeros are: [1,1]\n The subarrays of size 3 that have more ones than zeros are: [0,1,1], [1,1,0], [1,0,1]\n The subarrays of size 4 that have more ones than zeros are: [1,1,0,1]\n The subarrays of size 5 that have more ones than zeros are: [0,1,1,0,1]\n \n Example 2:\n \n >>> subarraysWithMoreZerosThanOnes(nums = [0])\n >>> 0\n Explanation:\n No subarrays have more ones than zeros.\n \n Example 3:\n \n >>> subarraysWithMoreZerosThanOnes(nums = [1])\n >>> 1\n Explanation:\n The subarrays of size 1 that have more ones than zeros are: [1]\n \"\"\"\n"}
{"task_id": "two-out-of-three", "prompt": "def twoOutOfThree(nums1: List[int], nums2: List[int], nums3: List[int]) -> List[int]:\n \"\"\"\n Given three integer arrays nums1, nums2, and nums3, return a distinct array containing all the values that are present in at least two out of the three arrays. You may return the values in any order.\n \n Example 1:\n \n >>> twoOutOfThree(nums1 = [1,1,3,2], nums2 = [2,3], nums3 = [3])\n >>> [3,2]\n Explanation: The values that are present in at least two arrays are:\n - 3, in all three arrays.\n - 2, in nums1 and nums2.\n \n Example 2:\n \n >>> twoOutOfThree(nums1 = [3,1], nums2 = [2,3], nums3 = [1,2])\n >>> [2,3,1]\n Explanation: The values that are present in at least two arrays are:\n - 2, in nums2 and nums3.\n - 3, in nums1 and nums2.\n - 1, in nums1 and nums3.\n \n Example 3:\n \n >>> twoOutOfThree(nums1 = [1,2,2], nums2 = [4,3,3], nums3 = [5])\n >>> []\n Explanation: No value is present in at least two arrays.\n \"\"\"\n"}
{"task_id": "minimum-operations-to-make-a-uni-value-grid", "prompt": "def minOperations(grid: List[List[int]], x: int) -> int:\n \"\"\"\n You are given a 2D integer grid of size m x n and an integer x. In one operation, you can add x to or subtract x from any element in the grid.\n A uni-value grid is a grid where all the elements of it are equal.\n Return the minimum number of operations to make the grid uni-value. If it is not possible, return -1.\n \n Example 1:\n \n \n >>> minOperations(grid = [[2,4],[6,8]], x = 2)\n >>> 4\n Explanation: We can make every element equal to 4 by doing the following:\n - Add x to 2 once.\n - Subtract x from 6 once.\n - Subtract x from 8 twice.\n A total of 4 operations were used.\n \n Example 2:\n \n \n >>> minOperations(grid = [[1,5],[2,3]], x = 1)\n >>> 5\n Explanation: We can make every element equal to 3.\n \n Example 3:\n \n \n >>> minOperations(grid = [[1,2],[3,4]], x = 2)\n >>> -1\n Explanation: It is impossible to make every element equal.\n \"\"\"\n"}
{"task_id": "partition-array-into-two-arrays-to-minimize-sum-difference", "prompt": "def minimumDifference(nums: List[int]) -> int:\n \"\"\"\n You are given an integer array nums of 2 * n integers. You need to partition nums into two arrays of length n to minimize the absolute difference of the sums of the arrays. To partition nums, put each element of nums into one of the two arrays.\n Return the minimum possible absolute difference.\n \n Example 1:\n \n \n >>> minimumDifference(nums = [3,9,7,3])\n >>> 2\n Explanation: One optimal partition is: [3,9] and [7,3].\n The absolute difference between the sums of the arrays is abs((3 + 9) - (7 + 3)) = 2.\n \n Example 2:\n \n >>> minimumDifference(nums = [-36,36])\n >>> 72\n Explanation: One optimal partition is: [-36] and [36].\n The absolute difference between the sums of the arrays is abs((-36) - (36)) = 72.\n \n Example 3:\n \n \n >>> minimumDifference(nums = [2,-1,0,4,-2,-9])\n >>> 0\n Explanation: One optimal partition is: [2,4,-9] and [-1,0,-2].\n The absolute difference between the sums of the arrays is abs((2 + 4 + -9) - (-1 + 0 + -2)) = 0.\n \"\"\"\n"}
{"task_id": "maximum-alternating-subarray-sum", "prompt": "def maximumAlternatingSubarraySum(nums: List[int]) -> int:\n \"\"\"\n A subarray of a 0-indexed integer array is a contiguous non-empty sequence of elements within an array.\n The alternating subarray sum of a subarray that ranges from index i to j (inclusive, 0 <= i <= j < nums.length) is nums[i] - nums[i+1] + nums[i+2] - ... +/- nums[j].\n Given a 0-indexed integer array nums, return the maximum alternating subarray sum of any subarray of nums.\n \n Example 1:\n \n >>> maximumAlternatingSubarraySum(nums = [3,-1,1,2])\n >>> 5\n Explanation:\n The subarray [3,-1,1] has the largest alternating subarray sum.\n The alternating subarray sum is 3 - (-1) + 1 = 5.\n \n Example 2:\n \n >>> maximumAlternatingSubarraySum(nums = [2,2,2,2,2])\n >>> 2\n Explanation:\n The subarrays [2], [2,2,2], and [2,2,2,2,2] have the largest alternating subarray sum.\n The alternating subarray sum of [2] is 2.\n The alternating subarray sum of [2,2,2] is 2 - 2 + 2 = 2.\n The alternating subarray sum of [2,2,2,2,2] is 2 - 2 + 2 - 2 + 2 = 2.\n \n Example 3:\n \n >>> maximumAlternatingSubarraySum(nums = [1])\n >>> 1\n Explanation:\n There is only one non-empty subarray, which is [1].\n The alternating subarray sum is 1.\n \"\"\"\n"}
{"task_id": "minimum-number-of-moves-to-seat-everyone", "prompt": "def minMovesToSeat(seats: List[int], students: List[int]) -> int:\n \"\"\"\n There are n availabe seats and n students standing in a room. You are given an array seats of length n, where seats[i] is the position of the ith seat. You are also given the array students of length n, where students[j] is the position of the jth student.\n You may perform the following move any number of times:\n \n Increase or decrease the position of the ith student by 1 (i.e., moving the ith student from position\u00a0x\u00a0to x + 1 or x - 1)\n \n Return the minimum number of moves required to move each student to a seat such that no two students are in the same seat.\n Note that there may be multiple seats or students in the same position at the beginning.\n \n Example 1:\n \n >>> minMovesToSeat(seats = [3,1,5], students = [2,7,4])\n >>> 4\n Explanation: The students are moved as follows:\n - The first student is moved from position 2 to position 1 using 1 move.\n - The second student is moved from position 7 to position 5 using 2 moves.\n - The third student is moved from position 4 to position 3 using 1 move.\n In total, 1 + 2 + 1 = 4 moves were used.\n \n Example 2:\n \n >>> minMovesToSeat(seats = [4,1,5,9], students = [1,3,2,6])\n >>> 7\n Explanation: The students are moved as follows:\n - The first student is not moved.\n - The second student is moved from position 3 to position 4 using 1 move.\n - The third student is moved from position 2 to position 5 using 3 moves.\n - The fourth student is moved from position 6 to position 9 using 3 moves.\n In total, 0 + 1 + 3 + 3 = 7 moves were used.\n \n Example 3:\n \n >>> minMovesToSeat(seats = [2,2,6,6], students = [1,3,2,6])\n >>> 4\n Explanation: Note that there are two seats at position 2 and two seats at position 6.\n The students are moved as follows:\n - The first student is moved from position 1 to position 2 using 1 move.\n - The second student is moved from position 3 to position 6 using 3 moves.\n - The third student is not moved.\n - The fourth student is not moved.\n In total, 1 + 3 + 0 + 0 = 4 moves were used.\n \"\"\"\n"}
{"task_id": "remove-colored-pieces-if-both-neighbors-are-the-same-color", "prompt": "def winnerOfGame(colors: str) -> bool:\n \"\"\"\n There are n pieces arranged in a line, and each piece is colored either by 'A' or by 'B'. You are given a string colors of length n where colors[i] is the color of the ith piece.\n Alice and Bob are playing a game where they take alternating turns removing pieces from the line. In this game, Alice moves first.\n \n Alice is only allowed to remove a piece colored 'A' if both its neighbors are also colored 'A'. She is not allowed to remove pieces that are colored 'B'.\n Bob is only allowed to remove a piece colored 'B' if both its neighbors are also colored 'B'. He is not allowed to remove pieces that are colored 'A'.\n Alice and Bob cannot remove pieces from the edge of the line.\n If a player cannot make a move on their turn, that player loses and the other player wins.\n \n Assuming Alice and Bob play optimally, return true if Alice wins, or return false if Bob wins.\n \n Example 1:\n \n >>> winnerOfGame(colors = \"AAABABB\")\n >>> true\n Explanation:\n AAABABB -> AABABB\n Alice moves first.\n She removes the second 'A' from the left since that is the only 'A' whose neighbors are both 'A'.\n \n Now it's Bob's turn.\n Bob cannot make a move on his turn since there are no 'B's whose neighbors are both 'B'.\n Thus, Alice wins, so return true.\n \n Example 2:\n \n >>> winnerOfGame(colors = \"AA\")\n >>> false\n Explanation:\n Alice has her turn first.\n There are only two 'A's and both are on the edge of the line, so she cannot move on her turn.\n Thus, Bob wins, so return false.\n \n Example 3:\n \n >>> winnerOfGame(colors = \"ABBBBBBBAAA\")\n >>> false\n Explanation:\n ABBBBBBBAAA -> ABBBBBBBAA\n Alice moves first.\n Her only option is to remove the second to last 'A' from the right.\n \n ABBBBBBBAA -> ABBBBBBAA\n Next is Bob's turn.\n He has many options for which 'B' piece to remove. He can pick any.\n \n On Alice's second turn, she has no more pieces that she can remove.\n Thus, Bob wins, so return false.\n \"\"\"\n"}
{"task_id": "the-time-when-the-network-becomes-idle", "prompt": "def networkBecomesIdle(edges: List[List[int]], patience: List[int]) -> int:\n \"\"\"\n There is a network of n servers, labeled from 0 to n - 1. You are given a 2D integer array edges, where edges[i] = [ui, vi] indicates there is a message channel between servers ui and vi, and they can pass any number of messages to each other directly in one second. You are also given a 0-indexed integer array patience of length n.\n All servers are connected, i.e., a message can be passed from one server to any other server(s) directly or indirectly through the message channels.\n The server labeled 0 is the master server. The rest are data servers. Each data server needs to send its message to the master server for processing and wait for a reply. Messages move between servers optimally, so every message takes the least amount of time to arrive at the master server. The master server will process all newly arrived messages instantly and send a reply to the originating server via the reversed path the message had gone through.\n At the beginning of second 0, each data server sends its message to be processed. Starting from second 1, at the beginning of every second, each data server will check if it has received a reply to the message it sent (including any newly arrived replies) from the master server:\n \n If it has not, it will resend the message periodically. The data server i will resend the message every patience[i] second(s), i.e., the data server i will resend the message if patience[i] second(s) have elapsed since the last time the message was sent from this server.\n Otherwise, no more resending will occur from this server.\n \n The network becomes idle when there are no messages passing between servers or arriving at servers.\n Return the earliest second starting from which the network becomes idle.\n \n Example 1:\n \n \n >>> networkBecomesIdle(edges = [[0,1],[1,2]], patience = [0,2,1])\n >>> 8\n Explanation:\n At (the beginning of) second 0,\n - Data server 1 sends its message (denoted 1A) to the master server.\n - Data server 2 sends its message (denoted 2A) to the master server.\n \n At second 1,\n - Message 1A arrives at the master server. Master server processes message 1A instantly and sends a reply 1A back.\n - Server 1 has not received any reply. 1 second (1 < patience[1] = 2) elapsed since this server has sent the message, therefore it does not resend the message.\n - Server 2 has not received any reply. 1 second (1 == patience[2] = 1) elapsed since this server has sent the message, therefore it resends the message (denoted 2B).\n \n At second 2,\n - The reply 1A arrives at server 1. No more resending will occur from server 1.\n - Message 2A arrives at the master server. Master server processes message 2A instantly and sends a reply 2A back.\n - Server 2 resends the message (denoted 2C).\n ...\n At second 4,\n - The reply 2A arrives at server 2. No more resending will occur from server 2.\n ...\n At second 7, reply 2D arrives at server 2.\n \n Starting from the beginning of the second 8, there are no messages passing between servers or arriving at servers.\n This is the time when the network becomes idle.\n \n Example 2:\n \n \n >>> networkBecomesIdle(edges = [[0,1],[0,2],[1,2]], patience = [0,10,10])\n >>> 3\n Explanation: Data servers 1 and 2 receive a reply back at the beginning of second 2.\n From the beginning of the second 3, the network becomes idle.\n \"\"\"\n"}
{"task_id": "kth-smallest-product-of-two-sorted-arrays", "prompt": "def kthSmallestProduct(nums1: List[int], nums2: List[int], k: int) -> int:\n \"\"\"\n Given two sorted 0-indexed integer arrays nums1 and nums2 as well as an integer k, return the kth (1-based) smallest product of nums1[i] * nums2[j] where 0 <= i < nums1.length and 0 <= j < nums2.length.\n \n Example 1:\n \n >>> kthSmallestProduct(nums1 = [2,5], nums2 = [3,4], k = 2)\n >>> 8\n Explanation: The 2 smallest products are:\n - nums1[0] * nums2[0] = 2 * 3 = 6\n - nums1[0] * nums2[1] = 2 * 4 = 8\n The 2nd smallest product is 8.\n \n Example 2:\n \n >>> kthSmallestProduct(nums1 = [-4,-2,0,3], nums2 = [2,4], k = 6)\n >>> 0\n Explanation: The 6 smallest products are:\n - nums1[0] * nums2[1] = (-4) * 4 = -16\n - nums1[0] * nums2[0] = (-4) * 2 = -8\n - nums1[1] * nums2[1] = (-2) * 4 = -8\n - nums1[1] * nums2[0] = (-2) * 2 = -4\n - nums1[2] * nums2[0] = 0 * 2 = 0\n - nums1[2] * nums2[1] = 0 * 4 = 0\n The 6th smallest product is 0.\n \n Example 3:\n \n >>> kthSmallestProduct(nums1 = [-2,-1,0,1,2], nums2 = [-3,-1,2,4,5], k = 3)\n >>> -6\n Explanation: The 3 smallest products are:\n - nums1[0] * nums2[4] = (-2) * 5 = -10\n - nums1[0] * nums2[3] = (-2) * 4 = -8\n - nums1[4] * nums2[0] = 2 * (-3) = -6\n The 3rd smallest product is -6.\n \"\"\"\n"}
{"task_id": "check-if-numbers-are-ascending-in-a-sentence", "prompt": "def areNumbersAscending(s: str) -> bool:\n \"\"\"\n A sentence is a list of tokens separated by a single space with no leading or trailing spaces. Every token is either a positive number consisting of digits 0-9 with no leading zeros, or a word consisting of lowercase English letters.\n \n For example, \"a puppy has 2 eyes 4 legs\" is a sentence with seven tokens: \"2\" and \"4\" are numbers and the other tokens such as \"puppy\" are words.\n \n Given a string s representing a sentence, you need to check if all the numbers in s are strictly increasing from left to right (i.e., other than the last number, each number is strictly smaller than the number on its right in s).\n Return true if so, or false otherwise.\n \n Example 1:\n \n \n >>> areNumbersAscending(s = \"1 box has 3 blue 4 red 6 green and 12 yellow marbles\")\n >>> true\n Explanation: The numbers in s are: 1, 3, 4, 6, 12.\n They are strictly increasing from left to right: 1 < 3 < 4 < 6 < 12.\n \n Example 2:\n \n >>> areNumbersAscending(s = \"hello world 5 x 5\")\n >>> false\n Explanation: The numbers in s are: 5, 5. They are not strictly increasing.\n \n Example 3:\n \n \n >>> areNumbersAscending(s = \"sunset is at 7 51 pm overnight lows will be in the low 50 and 60 s\")\n >>> false\n Explanation: The numbers in s are: 7, 51, 50, 60. They are not strictly increasing.\n \"\"\"\n"}
{"task_id": "count-number-of-maximum-bitwise-or-subsets", "prompt": "def countMaxOrSubsets(nums: List[int]) -> int:\n \"\"\"\n Given an integer array nums, find the maximum possible bitwise OR of a subset of nums and return the number of different non-empty subsets with the maximum bitwise OR.\n An array a is a subset of an array b if a can be obtained from b by deleting some (possibly zero) elements of b. Two subsets are considered different if the indices of the elements chosen are different.\n The bitwise OR of an array a is equal to a[0] OR a[1] OR ... OR a[a.length - 1] (0-indexed).\n \n Example 1:\n \n >>> countMaxOrSubsets(nums = [3,1])\n >>> 2\n Explanation: The maximum possible bitwise OR of a subset is 3. There are 2 subsets with a bitwise OR of 3:\n - [3]\n - [3,1]\n \n Example 2:\n \n >>> countMaxOrSubsets(nums = [2,2,2])\n >>> 7\n Explanation: All non-empty subsets of [2,2,2] have a bitwise OR of 2. There are 23 - 1 = 7 total subsets.\n \n Example 3:\n \n >>> countMaxOrSubsets(nums = [3,2,1,5])\n >>> 6\n Explanation: The maximum possible bitwise OR of a subset is 7. There are 6 subsets with a bitwise OR of 7:\n - [3,5]\n - [3,1,5]\n - [3,2,5]\n - [3,2,1,5]\n - [2,5]\n - [2,1,5]\n \"\"\"\n"}
{"task_id": "second-minimum-time-to-reach-destination", "prompt": "def secondMinimum(n: int, edges: List[List[int]], time: int, change: int) -> int:\n \"\"\"\n A city is represented as a bi-directional connected graph with n vertices where each vertex is labeled from 1 to n (inclusive). The edges in the graph are represented as a 2D integer array edges, where each edges[i] = [ui, vi] denotes a bi-directional edge between vertex ui and vertex vi. Every vertex pair is connected by at most one edge, and no vertex has an edge to itself. The time taken to traverse any edge is time minutes.\n Each vertex has a traffic signal which changes its color from green to red and vice versa every\u00a0change minutes. All signals change at the same time. You can enter a vertex at any time, but can leave a vertex only when the signal is green. You cannot wait at a vertex if the signal is green.\n The second minimum value is defined as the smallest value strictly larger than the minimum value.\n \n For example the second minimum value of [2, 3, 4] is 3, and the second minimum value of [2, 2, 4] is 4.\n \n Given n, edges, time, and change, return the second minimum time it will take to go from vertex 1 to vertex n.\n Notes:\n \n You can go through any vertex any number of times, including 1 and n.\n You can assume that when the journey starts, all signals have just turned green.\n \n \n Example 1:\n \n \n >>> secondMinimum(n = 5, edges = [[1,2],[1,3],[1,4],[3,4],[4,5]], time = 3, change = 5)\n >>> 13\n Explanation:\n The figure on the left shows the given graph.\n The blue path in the figure on the right is the minimum time path.\n The time taken is:\n - Start at 1, time elapsed=0\n - 1 -> 4: 3 minutes, time elapsed=3\n - 4 -> 5: 3 minutes, time elapsed=6\n Hence the minimum time needed is 6 minutes.\n \n The red path shows the path to get the second minimum time.\n - Start at 1, time elapsed=0\n - 1 -> 3: 3 minutes, time elapsed=3\n - 3 -> 4: 3 minutes, time elapsed=6\n - Wait at 4 for 4 minutes, time elapsed=10\n - 4 -> 5: 3 minutes, time elapsed=13\n Hence the second minimum time is 13 minutes.\n \n Example 2:\n \n \n >>> secondMinimum(n = 2, edges = [[1,2]], time = 3, change = 2)\n >>> 11\n Explanation:\n The minimum time path is 1 -> 2 with time = 3 minutes.\n The second minimum time path is 1 -> 2 -> 1 -> 2 with time = 11 minutes.\n \"\"\"\n"}
{"task_id": "sort-linked-list-already-sorted-using-absolute-values", "prompt": "# class ListNode:\n# def __init__(val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution:\n def sortLinkedList(head: Optional[ListNode]) -> Optional[ListNode]:\n \"\"\"\n Given the head of a singly linked list that is sorted in non-decreasing order using the absolute values of its nodes, return the list sorted in non-decreasing order using the actual values of its nodes.\n \n Example 1:\n \n \n >>> __init__(head = [0,2,-5,5,10,-10])\n >>> [-10,-5,0,2,5,10]\n Explanation:\n The list sorted in non-descending order using the absolute values of the nodes is [0,2,-5,5,10,-10].\n The list sorted in non-descending order using the actual values is [-10,-5,0,2,5,10].\n \n Example 2:\n \n \n >>> __init__(head = [0,1,2])\n >>> [0,1,2]\n Explanation:\n The linked list is already sorted in non-decreasing order.\n \n Example 3:\n \n >>> __init__(head = [1])\n >>> [1]\n Explanation:\n The linked list is already sorted in non-decreasing order.\n \"\"\"\n"}
{"task_id": "number-of-valid-words-in-a-sentence", "prompt": "def countValidWords(sentence: str) -> int:\n \"\"\"\n A sentence consists of lowercase letters ('a' to 'z'), digits ('0' to '9'), hyphens ('-'), punctuation marks ('!', '.', and ','), and spaces (' ') only. Each sentence can be broken down into one or more tokens separated by one or more spaces ' '.\n A token is a valid word if all three of the following are true:\n \n It only contains lowercase letters, hyphens, and/or punctuation (no digits).\n There is at most one hyphen '-'. If present, it must be surrounded by lowercase characters (\"a-b\" is valid, but \"-ab\" and \"ab-\" are not valid).\n There is at most one punctuation mark. If present, it must be at the end of the token (\"ab,\", \"cd!\", and \".\" are valid, but \"a!b\" and \"c.,\" are not valid).\n \n Examples of valid words include \"a-b.\", \"afad\", \"ba-c\", \"a!\", and \"!\".\n Given a string sentence, return the number of valid words in sentence.\n \n Example 1:\n \n >>> countValidWords(sentence = \"cat and dog\")\n >>> 3\n Explanation: The valid words in the sentence are \"cat\", \"and\", and \"dog\".\n \n Example 2:\n \n >>> countValidWords(sentence = \"!this 1-s b8d!\")\n >>> 0\n Explanation: There are no valid words in the sentence.\n \"!this\" is invalid because it starts with a punctuation mark.\n \"1-s\" and \"b8d\" are invalid because they contain digits.\n \n Example 3:\n \n >>> countValidWords(sentence = \"alice and bob are playing stone-game10\")\n >>> 5\n Explanation: The valid words in the sentence are \"alice\", \"and\", \"bob\", \"are\", and \"playing\".\n \"stone-game10\" is invalid because it contains digits.\n \"\"\"\n"}
{"task_id": "next-greater-numerically-balanced-number", "prompt": "def nextBeautifulNumber(n: int) -> int:\n \"\"\"\n An integer x is numerically balanced if for every digit d in the number x, there are exactly d occurrences of that digit in x.\n Given an integer n, return the smallest numerically balanced number strictly greater than n.\n \n Example 1:\n \n >>> nextBeautifulNumber(n = 1)\n >>> 22\n Explanation:\n 22 is numerically balanced since:\n - The digit 2 occurs 2 times.\n It is also the smallest numerically balanced number strictly greater than 1.\n \n Example 2:\n \n >>> nextBeautifulNumber(n = 1000)\n >>> 1333\n Explanation:\n 1333 is numerically balanced since:\n - The digit 1 occurs 1 time.\n - The digit 3 occurs 3 times.\n It is also the smallest numerically balanced number strictly greater than 1000.\n Note that 1022 cannot be the answer because 0 appeared more than 0 times.\n \n Example 3:\n \n >>> nextBeautifulNumber(n = 3000)\n >>> 3133\n Explanation:\n 3133 is numerically balanced since:\n - The digit 1 occurs 1 time.\n - The digit 3 occurs 3 times.\n It is also the smallest numerically balanced number strictly greater than 3000.\n \"\"\"\n"}
{"task_id": "count-nodes-with-the-highest-score", "prompt": "def countHighestScoreNodes(parents: List[int]) -> int:\n \"\"\"\n There is a binary tree rooted at 0 consisting of n nodes. The nodes are labeled from 0 to n - 1. You are given a 0-indexed integer array parents representing the tree, where parents[i] is the parent of node i. Since node 0 is the root, parents[0] == -1.\n Each node has a score. To find the score of a node, consider if the node and the edges connected to it were removed. The tree would become one or more non-empty subtrees. The size of a subtree is the number of the nodes in it. The score of the node is the product of the sizes of all those subtrees.\n Return the number of nodes that have the highest score.\n \n Example 1:\n \n \n >>> countHighestScoreNodes(parents = [-1,2,0,2,0])\n >>> 3\n Explanation:\n - The score of node 0 is: 3 * 1 = 3\n - The score of node 1 is: 4 = 4\n - The score of node 2 is: 1 * 1 * 2 = 2\n - The score of node 3 is: 4 = 4\n - The score of node 4 is: 4 = 4\n The highest score is 4, and three nodes (node 1, node 3, and node 4) have the highest score.\n \n Example 2:\n \n \n >>> countHighestScoreNodes(parents = [-1,2,0])\n >>> 2\n Explanation:\n - The score of node 0 is: 2 = 2\n - The score of node 1 is: 2 = 2\n - The score of node 2 is: 1 * 1 = 1\n The highest score is 2, and two nodes (node 0 and node 1) have the highest score.\n \"\"\"\n"}
{"task_id": "parallel-courses-iii", "prompt": "def minimumTime(n: int, relations: List[List[int]], time: List[int]) -> int:\n \"\"\"\n You are given an integer n, which indicates that there are n courses labeled from 1 to n. You are also given a 2D integer array relations where relations[j] = [prevCoursej, nextCoursej] denotes that course prevCoursej has to be completed before course nextCoursej (prerequisite relationship). Furthermore, you are given a 0-indexed integer array time where time[i] denotes how many months it takes to complete the (i+1)th course.\n You must find the minimum number of months needed to complete all the courses following these rules:\n \n You may start taking a course at any time if the prerequisites are met.\n Any number of courses can be taken at the same time.\n \n Return the minimum number of months needed to complete all the courses.\n Note: The test cases are generated such that it is possible to complete every course (i.e., the graph is a directed acyclic graph).\n \n Example 1:\n \n \n >>> minimumTime(n = 3, relations = [[1,3],[2,3]], time = [3,2,5])\n >>> 8\n Explanation: The figure above represents the given graph and the time required to complete each course.\n We start course 1 and course 2 simultaneously at month 0.\n Course 1 takes 3 months and course 2 takes 2 months to complete respectively.\n Thus, the earliest time we can start course 3 is at month 3, and the total time required is 3 + 5 = 8 months.\n \n Example 2:\n \n \n >>> minimumTime(n = 5, relations = [[1,5],[2,5],[3,5],[3,4],[4,5]], time = [1,2,3,4,5])\n >>> 12\n Explanation: The figure above represents the given graph and the time required to complete each course.\n You can start courses 1, 2, and 3 at month 0.\n You can complete them after 1, 2, and 3 months respectively.\n Course 4 can be taken only after course 3 is completed, i.e., after 3 months. It is completed after 3 + 4 = 7 months.\n Course 5 can be taken only after courses 1, 2, 3, and 4 have been completed, i.e., after max(1,2,3,7) = 7 months.\n Thus, the minimum time needed to complete all the courses is 7 + 5 = 12 months.\n \"\"\"\n"}
{"task_id": "minimum-cost-to-separate-sentence-into-rows", "prompt": "def minimumCost(sentence: str, k: int) -> int:\n \"\"\"\n You are given a string sentence containing words separated by spaces, and an integer k. Your task is to separate sentence into rows where the number of characters in each row is at most k. You may assume that sentence does not begin or end with a space, and the words in sentence are separated by a single space.\n You can split sentence into rows by inserting line breaks between words in sentence. A word cannot be split between two rows. Each word must be used exactly once, and the word order cannot be rearranged. Adjacent words in a row should be separated by a single space, and rows should not begin or end with spaces.\n The cost of a row with length n is (k - n)2, and the total cost is the sum of the costs for all rows except the last one.\n \n For example if sentence = \"i love leetcode\" and k = 12:\n \n \n Separating sentence into \"i\", \"love\", and \"leetcode\" has a cost of (12 - 1)2 + (12 - 4)2 = 185.\n Separating sentence into \"i love\", and \"leetcode\" has a cost of (12 - 6)2 = 36.\n Separating sentence into \"i\", and \"love leetcode\" is not possible because the length of \"love leetcode\" is greater than k.\n \n \n \n Return the minimum possible total cost of separating sentence into rows.\n \n Example 1:\n \n >>> minimumCost(sentence = \"i love leetcode\", k = 12)\n >>> 36\n Explanation:\n Separating sentence into \"i\", \"love\", and \"leetcode\" has a cost of (12 - 1)2 + (12 - 4)2 = 185.\n Separating sentence into \"i love\", and \"leetcode\" has a cost of (12 - 6)2 = 36.\n Separating sentence into \"i\", \"love leetcode\" is not possible because \"love leetcode\" has length 13.\n 36 is the minimum possible total cost so return it.\n \n Example 2:\n \n >>> minimumCost(sentence = \"apples and bananas taste great\", k = 7)\n >>> 21\n Explanation\n Separating sentence into \"apples\", \"and\", \"bananas\", \"taste\", and \"great\" has a cost of (7 - 6)2 + (7 - 3)2 + (7 - 7)2 + (7 - 5)2 = 21.\n 21 is the minimum possible total cost so return it.\n \n Example 3:\n \n >>> minimumCost(sentence = \"a\", k = 5)\n >>> 0\n Explanation:\n The cost of the last row is not included in the total cost, and since there is only one row, return 0.\n \"\"\"\n"}
{"task_id": "kth-distinct-string-in-an-array", "prompt": "def kthDistinct(arr: List[str], k: int) -> str:\n \"\"\"\n A distinct string is a string that is present only once in an array.\n Given an array of strings arr, and an integer k, return the kth distinct string present in arr. If there are fewer than k distinct strings, return an empty string \"\".\n Note that the strings are considered in the order in which they appear in the array.\n \n Example 1:\n \n >>> kthDistinct(arr = [\"d\",\"b\",\"c\",\"b\",\"c\",\"a\"], k = 2)\n >>> \"a\"\n Explanation:\n The only distinct strings in arr are \"d\" and \"a\".\n \"d\" appears 1st, so it is the 1st distinct string.\n \"a\" appears 2nd, so it is the 2nd distinct string.\n Since k == 2, \"a\" is returned.\n \n Example 2:\n \n >>> kthDistinct(arr = [\"aaa\",\"aa\",\"a\"], k = 1)\n >>> \"aaa\"\n Explanation:\n All strings in arr are distinct, so the 1st string \"aaa\" is returned.\n \n Example 3:\n \n >>> kthDistinct(arr = [\"a\",\"b\",\"a\"], k = 3)\n >>> \"\"\n Explanation:\n The only distinct string is \"b\". Since there are fewer than 3 distinct strings, we return an empty string \"\".\n \"\"\"\n"}
{"task_id": "two-best-non-overlapping-events", "prompt": "def maxTwoEvents(events: List[List[int]]) -> int:\n \"\"\"\n You are given a 0-indexed 2D integer array of events where events[i] = [startTimei, endTimei, valuei]. The ith event starts at startTimei and ends at endTimei, and if you attend this event, you will receive a value of valuei. You can choose at most two non-overlapping events to attend such that the sum of their values is maximized.\n Return this maximum sum.\n Note that the start time and end time is inclusive: that is, you cannot attend two events where one of them starts and the other ends at the same time. More specifically, if you attend an event with end time t, the next event must start at or after t + 1.\n \n Example 1:\n \n \n >>> maxTwoEvents(events = [[1,3,2],[4,5,2],[2,4,3]])\n >>> 4\n Explanation: Choose the green events, 0 and 1 for a sum of 2 + 2 = 4.\n \n Example 2:\n \n \n >>> maxTwoEvents(events = [[1,3,2],[4,5,2],[1,5,5]])\n >>> 5\n Explanation: Choose event 2 for a sum of 5.\n \n Example 3:\n \n \n >>> maxTwoEvents(events = [[1,5,3],[1,5,1],[6,6,5]])\n >>> 8\n Explanation: Choose events 0 and 2 for a sum of 3 + 5 = 8.\n \"\"\"\n"}
{"task_id": "plates-between-candles", "prompt": "def platesBetweenCandles(s: str, queries: List[List[int]]) -> List[int]:\n \"\"\"\n There is a long table with a line of plates and candles arranged on top of it. You are given a 0-indexed string s consisting of characters '*' and '|' only, where a '*' represents a plate and a '|' represents a candle.\n You are also given a 0-indexed 2D integer array queries where queries[i] = [lefti, righti] denotes the substring s[lefti...righti] (inclusive). For each query, you need to find the number of plates between candles that are in the substring. A plate is considered between candles if there is at least one candle to its left and at least one candle to its right in the substring.\n \n For example, s = \"||**||**|*\", and a query [3, 8] denotes the substring \"*||**|\". The number of plates between candles in this substring is 2, as each of the two plates has at least one candle in the substring to its left and right.\n \n Return an integer array answer where answer[i] is the answer to the ith query.\n \n Example 1:\n \n \n >>> platesBetweenCandles(s = \"**|**|***|\", queries = [[2,5],[5,9]])\n >>> [2,3]\n Explanation:\n - queries[0] has two plates between candles.\n - queries[1] has three plates between candles.\n \n Example 2:\n \n \n >>> platesBetweenCandles(s = \"***|**|*****|**||**|*\", queries = [[1,17],[4,5],[14,17],[5,11],[15,16]])\n >>> [9,0,0,0,0]\n Explanation:\n - queries[0] has nine plates between candles.\n - The other queries have zero plates between candles.\n \"\"\"\n"}
{"task_id": "number-of-valid-move-combinations-on-chessboard", "prompt": "def countCombinations(pieces: List[str], positions: List[List[int]]) -> int:\n \"\"\"\n There is an 8 x 8 chessboard containing n pieces (rooks, queens, or bishops). You are given a string array pieces of length n, where pieces[i] describes the type (rook, queen, or bishop) of the ith piece. In addition, you are given a 2D integer array positions also of length n, where positions[i] = [ri, ci] indicates that the ith piece is currently at the 1-based coordinate (ri, ci) on the chessboard.\n When making a move for a piece, you choose a destination square that the piece will travel toward and stop on.\n \n A rook can only travel horizontally or vertically from (r, c) to the direction of (r+1, c), (r-1, c), (r, c+1), or (r, c-1).\n A queen can only travel horizontally, vertically, or diagonally from (r, c) to the direction of (r+1, c), (r-1, c), (r, c+1), (r, c-1), (r+1, c+1), (r+1, c-1), (r-1, c+1), (r-1, c-1).\n A bishop can only travel diagonally from (r, c) to the direction of (r+1, c+1), (r+1, c-1), (r-1, c+1), (r-1, c-1).\n \n You must make a move for every piece on the board simultaneously. A move combination consists of all the moves performed on all the given pieces. Every second, each piece will instantaneously travel one square towards their destination if they are not already at it. All pieces start traveling at the 0th second. A move combination is invalid if, at a given time, two or more pieces occupy the same square.\n Return the number of valid move combinations\u200b\u200b\u200b\u200b\u200b.\n Notes:\n \n No two pieces will start in the same square.\n You may choose the square a piece is already on as its destination.\n If two pieces are directly adjacent to each other, it is valid for them to move past each other and swap positions in one second.\n \n \n Example 1:\n \n \n >>> countCombinations(pieces = [\"rook\"], positions = [[1,1]])\n >>> 15\n Explanation: The image above shows the possible squares the piece can move to.\n \n Example 2:\n \n \n >>> countCombinations(pieces = [\"queen\"], positions = [[1,1]])\n >>> 22\n Explanation: The image above shows the possible squares the piece can move to.\n \n Example 3:\n \n \n >>> countCombinations(pieces = [\"bishop\"], positions = [[4,3]])\n >>> 12\n Explanation: The image above shows the possible squares the piece can move to.\n \"\"\"\n"}
{"task_id": "smallest-index-with-equal-value", "prompt": "def smallestEqual(nums: List[int]) -> int:\n \"\"\"\n Given a 0-indexed integer array nums, return the smallest index i of nums such that i mod 10 == nums[i], or -1 if such index does not exist.\n x mod y denotes the remainder when x is divided by y.\n \n Example 1:\n \n >>> smallestEqual(nums = [0,1,2])\n >>> 0\n Explanation:\n i=0: 0 mod 10 = 0 == nums[0].\n i=1: 1 mod 10 = 1 == nums[1].\n i=2: 2 mod 10 = 2 == nums[2].\n All indices have i mod 10 == nums[i], so we return the smallest index 0.\n \n Example 2:\n \n >>> smallestEqual(nums = [4,3,2,1])\n >>> 2\n Explanation:\n i=0: 0 mod 10 = 0 != nums[0].\n i=1: 1 mod 10 = 1 != nums[1].\n i=2: 2 mod 10 = 2 == nums[2].\n i=3: 3 mod 10 = 3 != nums[3].\n 2 is the only index which has i mod 10 == nums[i].\n \n Example 3:\n \n >>> smallestEqual(nums = [1,2,3,4,5,6,7,8,9,0])\n >>> -1\n Explanation: No index satisfies i mod 10 == nums[i].\n \"\"\"\n"}
{"task_id": "find-the-minimum-and-maximum-number-of-nodes-between-critical-points", "prompt": "# class ListNode:\n# def __init__(val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution:\n def nodesBetweenCriticalPoints(head: Optional[ListNode]) -> List[int]:\n \"\"\"\n A critical point in a linked list is defined as either a local maxima or a local minima.\n A node is a local maxima if the current node has a value strictly greater than the previous node and the next node.\n A node is a local minima if the current node has a value strictly smaller than the previous node and the next node.\n Note that a node can only be a local maxima/minima if there exists both a previous node and a next node.\n Given a linked list head, return an array of length 2 containing [minDistance, maxDistance] where minDistance is the minimum distance between any\u00a0two distinct critical points and maxDistance is the maximum distance between any\u00a0two distinct critical points. If there are fewer than two critical points, return [-1, -1].\n \n Example 1:\n \n \n >>> __init__(head = [3,1])\n >>> [-1,-1]\n Explanation: There are no critical points in [3,1].\n \n Example 2:\n \n \n >>> __init__(head = [5,3,1,2,5,1,2])\n >>> [1,3]\n Explanation: There are three critical points:\n - [5,3,1,2,5,1,2]: The third node is a local minima because 1 is less than 3 and 2.\n - [5,3,1,2,5,1,2]: The fifth node is a local maxima because 5 is greater than 2 and 1.\n - [5,3,1,2,5,1,2]: The sixth node is a local minima because 1 is less than 5 and 2.\n The minimum distance is between the fifth and the sixth node. minDistance = 6 - 5 = 1.\n The maximum distance is between the third and the sixth node. maxDistance = 6 - 3 = 3.\n \n Example 3:\n \n \n >>> __init__(head = [1,3,2,2,3,2,2,2,7])\n >>> [3,3]\n Explanation: There are two critical points:\n - [1,3,2,2,3,2,2,2,7]: The second node is a local maxima because 3 is greater than 1 and 2.\n - [1,3,2,2,3,2,2,2,7]: The fifth node is a local maxima because 3 is greater than 2 and 2.\n Both the minimum and maximum distances are between the second and the fifth node.\n Thus, minDistance and maxDistance is 5 - 2 = 3.\n Note that the last node is not considered a local maxima because it does not have a next node.\n \"\"\"\n"}
{"task_id": "minimum-operations-to-convert-number", "prompt": "def minimumOperations(nums: List[int], start: int, goal: int) -> int:\n \"\"\"\n You are given a 0-indexed integer array nums containing distinct numbers, an integer start, and an integer goal. There is an integer x that is initially set to start, and you want to perform operations on x such that it is converted to goal. You can perform the following operation repeatedly on the number x:\n If 0 <= x <= 1000, then for any index i in the array (0 <= i < nums.length), you can set x to any of the following:\n \n x + nums[i]\n x - nums[i]\n x ^ nums[i] (bitwise-XOR)\n \n Note that you can use each nums[i] any number of times in any order. Operations that set x to be out of the range 0 <= x <= 1000 are valid, but no more operations can be done afterward.\n Return the minimum number of operations needed to convert x = start into goal, and -1 if it is not possible.\n \n Example 1:\n \n >>> minimumOperations(nums = [2,4,12], start = 2, goal = 12)\n >>> 2\n Explanation: We can go from 2 \u2192 14 \u2192 12 with the following 2 operations.\n - 2 + 12 = 14\n - 14 - 2 = 12\n \n Example 2:\n \n >>> minimumOperations(nums = [3,5,7], start = 0, goal = -4)\n >>> 2\n Explanation: We can go from 0 \u2192 3 \u2192 -4 with the following 2 operations.\n - 0 + 3 = 3\n - 3 - 7 = -4\n Note that the last operation sets x out of the range 0 <= x <= 1000, which is valid.\n \n Example 3:\n \n >>> minimumOperations(nums = [2,8,16], start = 0, goal = 1)\n >>> -1\n Explanation: There is no way to convert 0 into 1.\n \"\"\"\n"}
{"task_id": "check-if-an-original-string-exists-given-two-encoded-strings", "prompt": "def possiblyEquals(s1: str, s2: str) -> bool:\n \"\"\"\n An original string, consisting of lowercase English letters, can be encoded by the following steps:\n \n Arbitrarily split it into a sequence of some number of non-empty substrings.\n Arbitrarily choose some elements (possibly none) of the sequence, and replace each with its length (as a numeric string).\n Concatenate the sequence as the encoded string.\n \n For example, one way to encode an original string \"abcdefghijklmnop\" might be:\n \n Split it as a sequence: [\"ab\", \"cdefghijklmn\", \"o\", \"p\"].\n Choose the second and third elements to be replaced by their lengths, respectively. The sequence becomes [\"ab\", \"12\", \"1\", \"p\"].\n Concatenate the elements of the sequence to get the encoded string: \"ab121p\".\n \n Given two encoded strings s1 and s2, consisting of lowercase English letters and digits 1-9 (inclusive), return true if there exists an original string that could be encoded as both s1 and s2. Otherwise, return false.\n Note: The test cases are generated such that the number of consecutive digits in s1 and s2 does not exceed 3.\n \n Example 1:\n \n >>> possiblyEquals(s1 = \"internationalization\", s2 = \"i18n\")\n >>> true\n Explanation: It is possible that \"internationalization\" was the original string.\n - \"internationalization\"\n -> Split: [\"internationalization\"]\n -> Do not replace any element\n -> Concatenate: \"internationalization\", which is s1.\n - \"internationalization\"\n -> Split: [\"i\", \"nternationalizatio\", \"n\"]\n -> Replace: [\"i\", \"18\", \"n\"]\n -> Concatenate: \"i18n\", which is s2\n \n Example 2:\n \n >>> possiblyEquals(s1 = \"l123e\", s2 = \"44\")\n >>> true\n Explanation: It is possible that \"leetcode\" was the original string.\n - \"leetcode\"\n -> Split: [\"l\", \"e\", \"et\", \"cod\", \"e\"]\n -> Replace: [\"l\", \"1\", \"2\", \"3\", \"e\"]\n -> Concatenate: \"l123e\", which is s1.\n - \"leetcode\"\n -> Split: [\"leet\", \"code\"]\n -> Replace: [\"4\", \"4\"]\n -> Concatenate: \"44\", which is s2.\n \n Example 3:\n \n >>> possiblyEquals(s1 = \"a5b\", s2 = \"c5b\")\n >>> false\n Explanation: It is impossible.\n - The original string encoded as s1 must start with the letter 'a'.\n - The original string encoded as s2 must start with the letter 'c'.\n \"\"\"\n"}
{"task_id": "number-of-spaces-cleaning-robot-cleaned", "prompt": "def numberOfCleanRooms(room: List[List[int]]) -> int:\n \"\"\"\n A room is represented by a 0-indexed 2D binary matrix room where a 0 represents an empty space and a 1 represents a space with an object. The top left corner of the room will be empty in all test cases.\n A cleaning robot starts at the top left corner of the room and is facing right. The robot will continue heading straight until it reaches the edge of the room or it hits an object, after which it will turn 90 degrees clockwise and repeat this process. The starting space and all spaces that the robot visits are cleaned by it.\n Return the number of clean spaces in the room if the robot runs indefinitely.\n \n Example 1:\n \n \n \n >>> numberOfCleanRooms(room = [[0,0,0],[1,1,0],[0,0,0]])\n >>> 7\n Explanation:\n \n \u200b\u200b\u200b\u200b\u200b\u200b\u200bThe robot cleans the spaces at (0, 0), (0, 1), and (0, 2).\n The robot is at the edge of the room, so it turns 90 degrees clockwise and now faces down.\n The robot cleans the spaces at (1, 2), and (2, 2).\n The robot is at the edge of the room, so it turns 90 degrees clockwise and now faces left.\n The robot cleans the spaces at (2, 1), and (2, 0).\n The robot has cleaned all 7 empty spaces, so return 7.\n \n \n Example 2:\n \n \n \n >>> numberOfCleanRooms(room = [[0,1,0],[1,0,0],[0,0,0]])\n >>> 1\n Explanation:\n \n The robot cleans the space at (0, 0).\n The robot hits an object, so it turns 90 degrees clockwise and now faces down.\n The robot hits an object, so it turns 90 degrees clockwise and now faces left.\n The robot is at the edge of the room, so it turns 90 degrees clockwise and now faces up.\n The robot is at the edge of the room, so it turns 90 degrees clockwise and now faces right.\n The robot is back at its starting position.\n The robot has cleaned 1 space, so return 1.\n \n \n Example 3:\n \n >>> numberOfCleanRooms(room = [[0,0,0],[0,0,0],[0,0,0]])\n >>> 8\u200b\u200b\u200b\u200b\u200b\u200b\u200b\n \"\"\"\n"}
{"task_id": "count-vowel-substrings-of-a-string", "prompt": "def countVowelSubstrings(word: str) -> int:\n \"\"\"\n A substring is a contiguous (non-empty) sequence of characters within a string.\n A vowel substring is a substring that only consists of vowels ('a', 'e', 'i', 'o', and 'u') and has all five vowels present in it.\n Given a string word, return the number of vowel substrings in word.\n \n Example 1:\n \n >>> countVowelSubstrings(word = \"aeiouu\")\n >>> 2\n Explanation: The vowel substrings of word are as follows (underlined):\n - \"aeiouu\"\n - \"aeiouu\"\n \n Example 2:\n \n >>> countVowelSubstrings(word = \"unicornarihan\")\n >>> 0\n Explanation: Not all 5 vowels are present, so there are no vowel substrings.\n \n Example 3:\n \n >>> countVowelSubstrings(word = \"cuaieuouac\")\n >>> 7\n Explanation: The vowel substrings of word are as follows (underlined):\n - \"cuaieuouac\"\n - \"cuaieuouac\"\n - \"cuaieuouac\"\n - \"cuaieuouac\"\n - \"cuaieuouac\"\n - \"cuaieuouac\"\n - \"cuaieuouac\"\n \"\"\"\n"}
{"task_id": "vowels-of-all-substrings", "prompt": "def countVowels(word: str) -> int:\n \"\"\"\n Given a string word, return the sum of the number of vowels ('a', 'e', 'i', 'o', and 'u') in every substring of word.\n A substring is a contiguous (non-empty) sequence of characters within a string.\n Note: Due to the large constraints, the answer may not fit in a signed 32-bit integer. Please be careful during the calculations.\n \n Example 1:\n \n >>> countVowels(word = \"aba\")\n >>> 6\n Explanation:\n All possible substrings are: \"a\", \"ab\", \"aba\", \"b\", \"ba\", and \"a\".\n - \"b\" has 0 vowels in it\n - \"a\", \"ab\", \"ba\", and \"a\" have 1 vowel each\n - \"aba\" has 2 vowels in it\n Hence, the total sum of vowels = 0 + 1 + 1 + 1 + 1 + 2 = 6.\n \n Example 2:\n \n >>> countVowels(word = \"abc\")\n >>> 3\n Explanation:\n All possible substrings are: \"a\", \"ab\", \"abc\", \"b\", \"bc\", and \"c\".\n - \"a\", \"ab\", and \"abc\" have 1 vowel each\n - \"b\", \"bc\", and \"c\" have 0 vowels each\n Hence, the total sum of vowels = 1 + 1 + 1 + 0 + 0 + 0 = 3.\n \n Example 3:\n \n >>> countVowels(word = \"ltcd\")\n >>> 0\n Explanation: There are no vowels in any substring of \"ltcd\".\n \"\"\"\n"}
{"task_id": "minimized-maximum-of-products-distributed-to-any-store", "prompt": "def minimizedMaximum(n: int, quantities: List[int]) -> int:\n \"\"\"\n You are given an integer n indicating there are n specialty retail stores. There are m product types of varying amounts, which are given as a 0-indexed integer array quantities, where quantities[i] represents the number of products of the ith product type.\n You need to distribute all products to the retail stores following these rules:\n \n A store can only be given at most one product type but can be given any amount of it.\n After distribution, each store will have been given some number of products (possibly 0). Let x represent the maximum number of products given to any store. You want x to be as small as possible, i.e., you want to minimize the maximum number of products that are given to any store.\n \n Return the minimum possible x.\n \n Example 1:\n \n >>> minimizedMaximum(n = 6, quantities = [11,6])\n >>> 3\n Explanation: One optimal way is:\n - The 11 products of type 0 are distributed to the first four stores in these amounts: 2, 3, 3, 3\n - The 6 products of type 1 are distributed to the other two stores in these amounts: 3, 3\n The maximum number of products given to any store is max(2, 3, 3, 3, 3, 3) = 3.\n \n Example 2:\n \n >>> minimizedMaximum(n = 7, quantities = [15,10,10])\n >>> 5\n Explanation: One optimal way is:\n - The 15 products of type 0 are distributed to the first three stores in these amounts: 5, 5, 5\n - The 10 products of type 1 are distributed to the next two stores in these amounts: 5, 5\n - The 10 products of type 2 are distributed to the last two stores in these amounts: 5, 5\n The maximum number of products given to any store is max(5, 5, 5, 5, 5, 5, 5) = 5.\n \n Example 3:\n \n >>> minimizedMaximum(n = 1, quantities = [100000])\n >>> 100000\n Explanation: The only optimal way is:\n - The 100000 products of type 0 are distributed to the only store.\n The maximum number of products given to any store is max(100000) = 100000.\n \"\"\"\n"}
{"task_id": "maximum-path-quality-of-a-graph", "prompt": "def maximalPathQuality(values: List[int], edges: List[List[int]], maxTime: int) -> int:\n \"\"\"\n There is an undirected graph with n nodes numbered from 0 to n - 1 (inclusive). You are given a 0-indexed integer array values where values[i] is the value of the ith node. You are also given a 0-indexed 2D integer array edges, where each edges[j] = [uj, vj, timej] indicates that there is an undirected edge between the nodes uj and vj, and it takes timej seconds to travel between the two nodes. Finally, you are given an integer maxTime.\n A valid path in the graph is any path that starts at node 0, ends at node 0, and takes at most maxTime seconds to complete. You may visit the same node multiple times. The quality of a valid path is the sum of the values of the unique nodes visited in the path (each node's value is added at most once to the sum).\n Return the maximum quality of a valid path.\n Note: There are at most four edges connected to each node.\n \n Example 1:\n \n \n >>> maximalPathQuality(values = [0,32,10,43], edges = [[0,1,10],[1,2,15],[0,3,10]], maxTime = 49)\n >>> 75\n Explanation:\n One possible path is 0 -> 1 -> 0 -> 3 -> 0. The total time taken is 10 + 10 + 10 + 10 = 40 <= 49.\n The nodes visited are 0, 1, and 3, giving a maximal path quality of 0 + 32 + 43 = 75.\n \n Example 2:\n \n \n >>> maximalPathQuality(values = [5,10,15,20], edges = [[0,1,10],[1,2,10],[0,3,10]], maxTime = 30)\n >>> 25\n Explanation:\n One possible path is 0 -> 3 -> 0. The total time taken is 10 + 10 = 20 <= 30.\n The nodes visited are 0 and 3, giving a maximal path quality of 5 + 20 = 25.\n \n Example 3:\n \n \n >>> maximalPathQuality(values = [1,2,3,4], edges = [[0,1,10],[1,2,11],[2,3,12],[1,3,13]], maxTime = 50)\n >>> 7\n Explanation:\n One possible path is 0 -> 1 -> 3 -> 1 -> 0. The total time taken is 10 + 13 + 13 + 10 = 46 <= 50.\n The nodes visited are 0, 1, and 3, giving a maximal path quality of 1 + 2 + 4 = 7.\n \"\"\"\n"}
{"task_id": "number-of-equal-count-substrings", "prompt": "def equalCountSubstrings(s: str, count: int) -> int:\n \"\"\"\n You are given a 0-indexed string s consisting of only lowercase English letters, and an integer count. A substring of s is said to be an equal count substring if, for each unique letter in the substring, it appears exactly count times in the substring.\n Return the number of equal count substrings in s.\n A substring is a contiguous non-empty sequence of characters within a string.\n \n Example 1:\n \n >>> equalCountSubstrings(s = \"aaabcbbcc\", count = 3)\n >>> 3\n Explanation:\n The substring that starts at index 0 and ends at index 2 is \"aaa\".\n The letter 'a' in the substring appears exactly 3 times.\n The substring that starts at index 3 and ends at index 8 is \"bcbbcc\".\n The letters 'b' and 'c' in the substring appear exactly 3 times.\n The substring that starts at index 0 and ends at index 8 is \"aaabcbbcc\".\n The letters 'a', 'b', and 'c' in the substring appear exactly 3 times.\n \n Example 2:\n \n >>> equalCountSubstrings(s = \"abcd\", count = 2)\n >>> 0\n Explanation:\n The number of times each letter appears in s is less than count.\n Therefore, no substrings in s are equal count substrings, so return 0.\n \n Example 3:\n \n >>> equalCountSubstrings(s = \"a\", count = 5)\n >>> 0\n Explanation:\n The number of times each letter appears in s is less than count.\n Therefore, no substrings in s are equal count substrings, so return 0\n \"\"\"\n"}
{"task_id": "check-whether-two-strings-are-almost-equivalent", "prompt": "def checkAlmostEquivalent(word1: str, word2: str) -> bool:\n \"\"\"\n Two strings word1 and word2 are considered almost equivalent if the differences between the frequencies of each letter from 'a' to 'z' between word1 and word2 is at most 3.\n Given two strings word1 and word2, each of length n, return true if word1 and word2 are almost equivalent, or false otherwise.\n The frequency of a letter x is the number of times it occurs in the string.\n \n Example 1:\n \n >>> checkAlmostEquivalent(word1 = \"aaaa\", word2 = \"bccb\")\n >>> false\n Explanation: There are 4 'a's in \"aaaa\" but 0 'a's in \"bccb\".\n The difference is 4, which is more than the allowed 3.\n \n Example 2:\n \n >>> checkAlmostEquivalent(word1 = \"abcdeef\", word2 = \"abaaacc\")\n >>> true\n Explanation: The differences between the frequencies of each letter in word1 and word2 are at most 3:\n - 'a' appears 1 time in word1 and 4 times in word2. The difference is 3.\n - 'b' appears 1 time in word1 and 1 time in word2. The difference is 0.\n - 'c' appears 1 time in word1 and 2 times in word2. The difference is 1.\n - 'd' appears 1 time in word1 and 0 times in word2. The difference is 1.\n - 'e' appears 2 times in word1 and 0 times in word2. The difference is 2.\n - 'f' appears 1 time in word1 and 0 times in word2. The difference is 1.\n \n Example 3:\n \n >>> checkAlmostEquivalent(word1 = \"cccddabba\", word2 = \"babababab\")\n >>> true\n Explanation: The differences between the frequencies of each letter in word1 and word2 are at most 3:\n - 'a' appears 2 times in word1 and 4 times in word2. The difference is 2.\n - 'b' appears 2 times in word1 and 5 times in word2. The difference is 3.\n - 'c' appears 3 times in word1 and 0 times in word2. The difference is 3.\n - 'd' appears 2 times in word1 and 0 times in word2. The difference is 2.\n \"\"\"\n"}
{"task_id": "most-beautiful-item-for-each-query", "prompt": "def maximumBeauty(items: List[List[int]], queries: List[int]) -> List[int]:\n \"\"\"\n You are given a 2D integer array items where items[i] = [pricei, beautyi] denotes the price and beauty of an item respectively.\n You are also given a 0-indexed integer array queries. For each queries[j], you want to determine the maximum beauty of an item whose price is less than or equal to queries[j]. If no such item exists, then the answer to this query is 0.\n Return an array answer of the same length as queries where answer[j] is the answer to the jth query.\n \n Example 1:\n \n >>> maximumBeauty(items = [[1,2],[3,2],[2,4],[5,6],[3,5]], queries = [1,2,3,4,5,6])\n >>> [2,4,5,5,6,6]\n Explanation:\n - For queries[0]=1, [1,2] is the only item which has price <= 1. Hence, the answer for this query is 2.\n - For queries[1]=2, the items which can be considered are [1,2] and [2,4].\n The maximum beauty among them is 4.\n - For queries[2]=3 and queries[3]=4, the items which can be considered are [1,2], [3,2], [2,4], and [3,5].\n The maximum beauty among them is 5.\n - For queries[4]=5 and queries[5]=6, all items can be considered.\n Hence, the answer for them is the maximum beauty of all items, i.e., 6.\n \n Example 2:\n \n >>> maximumBeauty(items = [[1,2],[1,2],[1,3],[1,4]], queries = [1])\n >>> [4]\n Explanation:\n The price of every item is equal to 1, so we choose the item with the maximum beauty 4.\n Note that multiple items can have the same price and/or beauty.\n \n Example 3:\n \n >>> maximumBeauty(items = [[10,1000]], queries = [5])\n >>> [0]\n Explanation:\n No item has a price less than or equal to 5, so no item can be chosen.\n Hence, the answer to the query is 0.\n \"\"\"\n"}
{"task_id": "maximum-number-of-tasks-you-can-assign", "prompt": "def maxTaskAssign(tasks: List[int], workers: List[int], pills: int, strength: int) -> int:\n \"\"\"\n You have n tasks and m workers. Each task has a strength requirement stored in a 0-indexed integer array tasks, with the ith task requiring tasks[i] strength to complete. The strength of each worker is stored in a 0-indexed integer array workers, with the jth worker having workers[j] strength. Each worker can only be assigned to a single task and must have a strength greater than or equal to the task's strength requirement (i.e., workers[j] >= tasks[i]).\n Additionally, you have pills magical pills that will increase a worker's strength by strength. You can decide which workers receive the magical pills, however, you may only give each worker at most one magical pill.\n Given the 0-indexed integer arrays tasks and workers and the integers pills and strength, return the maximum number of tasks that can be completed.\n \n Example 1:\n \n >>> maxTaskAssign(tasks = [3,2,1], workers = [0,3,3], pills = 1, strength = 1)\n >>> 3\n Explanation:\n We can assign the magical pill and tasks as follows:\n - Give the magical pill to worker 0.\n - Assign worker 0 to task 2 (0 + 1 >= 1)\n - Assign worker 1 to task 1 (3 >= 2)\n - Assign worker 2 to task 0 (3 >= 3)\n \n Example 2:\n \n >>> maxTaskAssign(tasks = [5,4], workers = [0,0,0], pills = 1, strength = 5)\n >>> 1\n Explanation:\n We can assign the magical pill and tasks as follows:\n - Give the magical pill to worker 0.\n - Assign worker 0 to task 0 (0 + 5 >= 5)\n \n Example 3:\n \n >>> maxTaskAssign(tasks = [10,15,30], workers = [0,10,10,10,10], pills = 3, strength = 10)\n >>> 2\n Explanation:\n We can assign the magical pills and tasks as follows:\n - Give the magical pill to worker 0 and worker 1.\n - Assign worker 0 to task 0 (0 + 10 >= 10)\n - Assign worker 1 to task 1 (10 + 10 >= 15)\n The last pill is not given because it will not make any worker strong enough for the last task.\n \"\"\"\n"}
{"task_id": "time-needed-to-buy-tickets", "prompt": "def timeRequiredToBuy(tickets: List[int], k: int) -> int:\n \"\"\"\n There are n people in a line queuing to buy tickets, where the 0th person is at the front of the line and the (n - 1)th person is at the back of the line.\n You are given a 0-indexed integer array tickets of length n where the number of tickets that the ith person would like to buy is tickets[i].\n Each person takes exactly 1 second to buy a ticket. A person can only buy 1 ticket at a time and has to go back to the end of the line (which happens instantaneously) in order to buy more tickets. If a person does not have any tickets left to buy, the person will leave the line.\n Return the time taken for the person initially at position k (0-indexed) to finish buying tickets.\n \n Example 1:\n \n >>> timeRequiredToBuy(tickets = [2,3,2], k = 2)\n >>> 6\n Explanation:\n \n The queue starts as [2,3,2], where the kth person is underlined.\n After the person at the front has bought a ticket, the queue becomes [3,2,1] at 1 second.\n Continuing this process, the queue becomes [2,1,2] at 2 seconds.\n Continuing this process, the queue becomes [1,2,1] at 3 seconds.\n Continuing this process, the queue becomes [2,1] at 4 seconds. Note: the person at the front left the queue.\n Continuing this process, the queue becomes [1,1] at 5 seconds.\n Continuing this process, the queue becomes [1] at 6 seconds. The kth person has bought all their tickets, so return 6.\n \n \n Example 2:\n \n >>> timeRequiredToBuy(tickets = [5,1,1,1], k = 0)\n >>> 8\n Explanation:\n \n The queue starts as [5,1,1,1], where the kth person is underlined.\n After the person at the front has bought a ticket, the queue becomes [1,1,1,4] at 1 second.\n Continuing this process for 3 seconds, the queue becomes [4] at 4 seconds.\n Continuing this process for 4 seconds, the queue becomes [] at 8 seconds. The kth person has bought all their tickets, so return 8.\n \"\"\"\n"}
{"task_id": "reverse-nodes-in-even-length-groups", "prompt": "# class ListNode:\n# def __init__(val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution:\n def reverseEvenLengthGroups(head: Optional[ListNode]) -> Optional[ListNode]:\n \"\"\"\n You are given the head of a linked list.\n The nodes in the linked list are sequentially assigned to non-empty groups whose lengths form the sequence of the natural numbers (1, 2, 3, 4, ...). The length of a group is the number of nodes assigned to it. In other words,\n \n The 1st node is assigned to the first group.\n The 2nd and the 3rd nodes are assigned to the second group.\n The 4th, 5th, and 6th nodes are assigned to the third group, and so on.\n \n Note that the length of the last group may be less than or equal to 1 + the length of the second to last group.\n Reverse the nodes in each group with an even length, and return the head of the modified linked list.\n \n Example 1:\n \n \n >>> __init__(head = [5,2,6,3,9,1,7,3,8,4])\n >>> [5,6,2,3,9,1,4,8,3,7]\n Explanation:\n - The length of the first group is 1, which is odd, hence no reversal occurs.\n - The length of the second group is 2, which is even, hence the nodes are reversed.\n - The length of the third group is 3, which is odd, hence no reversal occurs.\n - The length of the last group is 4, which is even, hence the nodes are reversed.\n \n Example 2:\n \n \n >>> __init__(head = [1,1,0,6])\n >>> [1,0,1,6]\n Explanation:\n - The length of the first group is 1. No reversal occurs.\n - The length of the second group is 2. The nodes are reversed.\n - The length of the last group is 1. No reversal occurs.\n \n Example 3:\n \n \n >>> __init__(head = [1,1,0,6,5])\n >>> [1,0,1,5,6]\n Explanation:\n - The length of the first group is 1. No reversal occurs.\n - The length of the second group is 2. The nodes are reversed.\n - The length of the last group is 2. The nodes are reversed.\n \"\"\"\n"}
{"task_id": "decode-the-slanted-ciphertext", "prompt": "def decodeCiphertext(encodedText: str, rows: int) -> str:\n \"\"\"\n A string originalText is encoded using a slanted transposition cipher to a string encodedText with the help of a matrix having a fixed number of rows rows.\n originalText is placed first in a top-left to bottom-right manner.\n \n The blue cells are filled first, followed by the red cells, then the yellow cells, and so on, until we reach the end of originalText. The arrow indicates the order in which the cells are filled. All empty cells are filled with ' '. The number of columns is chosen such that the rightmost column will not be empty after filling in originalText.\n encodedText is then formed by appending all characters of the matrix in a row-wise fashion.\n \n The characters in the blue cells are appended first to encodedText, then the red cells, and so on, and finally the yellow cells. The arrow indicates the order in which the cells are accessed.\n For example, if originalText = \"cipher\" and rows = 3, then we encode it in the following manner:\n \n The blue arrows depict how originalText is placed in the matrix, and the red arrows denote the order in which encodedText is formed. In the above example, encodedText = \"ch ie pr\".\n Given the encoded string encodedText and number of rows rows, return the original string originalText.\n Note: originalText does not have any trailing spaces ' '. The test cases are generated such that there is only one possible originalText.\n \n Example 1:\n \n >>> decodeCiphertext(encodedText = \"ch ie pr\", rows = 3)\n >>> \"cipher\"\n Explanation: This is the same example described in the problem description.\n \n Example 2:\n \n \n >>> decodeCiphertext(encodedText = \"iveo eed l te olc\", rows = 4)\n >>> \"i love leetcode\"\n Explanation: The figure above denotes the matrix that was used to encode originalText.\n The blue arrows show how we can find originalText from encodedText.\n \n Example 3:\n \n \n >>> decodeCiphertext(encodedText = \"coding\", rows = 1)\n >>> \"coding\"\n Explanation: Since there is only 1 row, both originalText and encodedText are the same.\n \"\"\"\n"}
{"task_id": "process-restricted-friend-requests", "prompt": "def friendRequests(n: int, restrictions: List[List[int]], requests: List[List[int]]) -> List[bool]:\n \"\"\"\n You are given an integer n indicating the number of people in a network. Each person is labeled from 0 to n - 1.\n You are also given a 0-indexed 2D integer array restrictions, where restrictions[i] = [xi, yi] means that person xi and person yi cannot become friends, either directly or indirectly through other people.\n Initially, no one is friends with each other. You are given a list of friend requests as a 0-indexed 2D integer array requests, where requests[j] = [uj, vj] is a friend request between person uj and person vj.\n A friend request is successful if uj and vj can be friends. Each friend request is processed in the given order (i.e., requests[j] occurs before requests[j + 1]), and upon a successful request, uj and vj become direct friends for all future friend requests.\n Return a boolean array result, where each result[j] is true if the jth friend request is successful or false if it is not.\n Note: If uj and vj are already direct friends, the request is still successful.\n \n Example 1:\n \n >>> friendRequests(n = 3, restrictions = [[0,1]], requests = [[0,2],[2,1]])\n >>> [true,false]\n Explanation:\n Request 0: Person 0 and person 2 can be friends, so they become direct friends.\n Request 1: Person 2 and person 1 cannot be friends since person 0 and person 1 would be indirect friends (1--2--0).\n \n Example 2:\n \n >>> friendRequests(n = 3, restrictions = [[0,1]], requests = [[1,2],[0,2]])\n >>> [true,false]\n Explanation:\n Request 0: Person 1 and person 2 can be friends, so they become direct friends.\n Request 1: Person 0 and person 2 cannot be friends since person 0 and person 1 would be indirect friends (0--2--1).\n \n Example 3:\n \n >>> friendRequests(n = 5, restrictions = [[0,1],[1,2],[2,3]], requests = [[0,4],[1,2],[3,1],[3,4]])\n >>> [true,false,true,false]\n Explanation:\n Request 0: Person 0 and person 4 can be friends, so they become direct friends.\n Request 1: Person 1 and person 2 cannot be friends since they are directly restricted.\n Request 2: Person 3 and person 1 can be friends, so they become direct friends.\n Request 3: Person 3 and person 4 cannot be friends since person 0 and person 1 would be indirect friends (0--4--3--1).\n \"\"\"\n"}
{"task_id": "paths-in-maze-that-lead-to-same-room", "prompt": "def numberOfPaths(n: int, corridors: List[List[int]]) -> int:\n \"\"\"\n A maze consists of n rooms numbered from 1 to n, and some rooms are connected by corridors. You are given a 2D integer array corridors where corridors[i] = [room1i, room2i] indicates that there is a corridor connecting room1i and room2i, allowing a person in the maze to go from room1i to room2i and vice versa.\n The designer of the maze wants to know how confusing the maze is. The confusion score of the maze is the number of different cycles of length 3.\n \n For example, 1 \u2192 2 \u2192 3 \u2192 1 is a cycle of length 3, but 1 \u2192 2 \u2192 3 \u2192 4 and 1 \u2192 2 \u2192 3 \u2192 2 \u2192 1 are not.\n \n Two cycles are considered to be different if one or more of the rooms visited in the first cycle is not in the second cycle.\n Return the confusion score of the maze.\n \n Example 1:\n \n \n >>> numberOfPaths(n = 5, corridors = [[1,2],[5,2],[4,1],[2,4],[3,1],[3,4]])\n >>> 2\n Explanation:\n One cycle of length 3 is 4 \u2192 1 \u2192 3 \u2192 4, denoted in red.\n Note that this is the same cycle as 3 \u2192 4 \u2192 1 \u2192 3 or 1 \u2192 3 \u2192 4 \u2192 1 because the rooms are the same.\n Another cycle of length 3 is 1 \u2192 2 \u2192 4 \u2192 1, denoted in blue.\n Thus, there are two different cycles of length 3.\n \n Example 2:\n \n \n >>> numberOfPaths(n = 4, corridors = [[1,2],[3,4]])\n >>> 0\n Explanation:\n There are no cycles of length 3.\n \"\"\"\n"}
{"task_id": "two-furthest-houses-with-different-colors", "prompt": "def maxDistance(colors: List[int]) -> int:\n \"\"\"\n There are n houses evenly lined up on the street, and each house is beautifully painted. You are given a 0-indexed integer array colors of length n, where colors[i] represents the color of the ith house.\n Return the maximum distance between two houses with different colors.\n The distance between the ith and jth houses is abs(i - j), where abs(x) is the absolute value of x.\n \n Example 1:\n \n \n >>> maxDistance(colors = [1,1,1,6,1,1,1])\n >>> 3\n Explanation: In the above image, color 1 is blue, and color 6 is red.\n The furthest two houses with different colors are house 0 and house 3.\n House 0 has color 1, and house 3 has color 6. The distance between them is abs(0 - 3) = 3.\n Note that houses 3 and 6 can also produce the optimal answer.\n \n Example 2:\n \n \n >>> maxDistance(colors = [1,8,3,8,3])\n >>> 4\n Explanation: In the above image, color 1 is blue, color 8 is yellow, and color 3 is green.\n The furthest two houses with different colors are house 0 and house 4.\n House 0 has color 1, and house 4 has color 3. The distance between them is abs(0 - 4) = 4.\n \n Example 3:\n \n >>> maxDistance(colors = [0,1])\n >>> 1\n Explanation: The furthest two houses with different colors are house 0 and house 1.\n House 0 has color 0, and house 1 has color 1. The distance between them is abs(0 - 1) = 1.\n \"\"\"\n"}
{"task_id": "watering-plants", "prompt": "def wateringPlants(plants: List[int], capacity: int) -> int:\n \"\"\"\n You want to water n plants in your garden with a watering can. The plants are arranged in a row and are labeled from 0 to n - 1 from left to right where the ith plant is located at x = i. There is a river at x = -1 that you can refill your watering can at.\n Each plant needs a specific amount of water. You will water the plants in the following way:\n \n Water the plants in order from left to right.\n After watering the current plant, if you do not have enough water to completely water the next plant, return to the river to fully refill the watering can.\n You cannot refill the watering can early.\n \n You are initially at the river (i.e., x = -1). It takes one step to move one unit on the x-axis.\n Given a 0-indexed integer array plants of n integers, where plants[i] is the amount of water the ith plant needs, and an integer capacity representing the watering can capacity, return the number of steps needed to water all the plants.\n \n Example 1:\n \n >>> wateringPlants(plants = [2,2,3,3], capacity = 5)\n >>> 14\n Explanation: Start at the river with a full watering can:\n - Walk to plant 0 (1 step) and water it. Watering can has 3 units of water.\n - Walk to plant 1 (1 step) and water it. Watering can has 1 unit of water.\n - Since you cannot completely water plant 2, walk back to the river to refill (2 steps).\n - Walk to plant 2 (3 steps) and water it. Watering can has 2 units of water.\n - Since you cannot completely water plant 3, walk back to the river to refill (3 steps).\n - Walk to plant 3 (4 steps) and water it.\n Steps needed = 1 + 1 + 2 + 3 + 3 + 4 = 14.\n \n Example 2:\n \n >>> wateringPlants(plants = [1,1,1,4,2,3], capacity = 4)\n >>> 30\n Explanation: Start at the river with a full watering can:\n - Water plants 0, 1, and 2 (3 steps). Return to river (3 steps).\n - Water plant 3 (4 steps). Return to river (4 steps).\n - Water plant 4 (5 steps). Return to river (5 steps).\n - Water plant 5 (6 steps).\n Steps needed = 3 + 3 + 4 + 4 + 5 + 5 + 6 = 30.\n \n Example 3:\n \n >>> wateringPlants(plants = [7,7,7,7,7,7,7], capacity = 8)\n >>> 49\n Explanation: You have to refill before watering each plant.\n Steps needed = 1 + 1 + 2 + 2 + 3 + 3 + 4 + 4 + 5 + 5 + 6 + 6 + 7 = 49.\n \"\"\"\n"}
{"task_id": "sum-of-k-mirror-numbers", "prompt": "def kMirror(k: int, n: int) -> int:\n \"\"\"\n A k-mirror number is a positive integer without leading zeros that reads the same both forward and backward in base-10 as well as in base-k.\n \n For example, 9 is a 2-mirror number. The representation of 9 in base-10 and base-2 are 9 and 1001 respectively, which read the same both forward and backward.\n On the contrary, 4 is not a 2-mirror number. The representation of 4 in base-2 is 100, which does not read the same both forward and backward.\n \n Given the base k and the number n, return the sum of the n smallest k-mirror numbers.\n \n Example 1:\n \n >>> kMirror(k = 2, n = 5)\n >>> 25\n Explanation:\n The 5 smallest 2-mirror numbers and their representations in base-2 are listed as follows:\n base-10 base-2\n 1 1\n 3 11\n 5 101\n 7 111\n 9 1001\n Their sum = 1 + 3 + 5 + 7 + 9 = 25.\n \n Example 2:\n \n >>> kMirror(k = 3, n = 7)\n >>> 499\n Explanation:\n The 7 smallest 3-mirror numbers are and their representations in base-3 are listed as follows:\n base-10 base-3\n 1 1\n 2 2\n 4 11\n 8 22\n 121 11111\n 151 12121\n 212 21212\n Their sum = 1 + 2 + 4 + 8 + 121 + 151 + 212 = 499.\n \n Example 3:\n \n >>> kMirror(k = 7, n = 17)\n >>> 20379000\n Explanation: The 17 smallest 7-mirror numbers are:\n 1, 2, 3, 4, 5, 6, 8, 121, 171, 242, 292, 16561, 65656, 2137312, 4602064, 6597956, 6958596\n \"\"\"\n"}
{"task_id": "substrings-that-begin-and-end-with-the-same-letter", "prompt": "def numberOfSubstrings(s: str) -> int:\n \"\"\"\n You are given a 0-indexed string s consisting of only lowercase English letters. Return the number of substrings in s that begin and end with the same character.\n A substring is a contiguous non-empty sequence of characters within a string.\n \n Example 1:\n \n >>> numberOfSubstrings(s = \"abcba\")\n >>> 7\n Explanation:\n The substrings of length 1 that start and end with the same letter are: \"a\", \"b\", \"c\", \"b\", and \"a\".\n The substring of length 3 that starts and ends with the same letter is: \"bcb\".\n The substring of length 5 that starts and ends with the same letter is: \"abcba\".\n \n Example 2:\n \n >>> numberOfSubstrings(s = \"abacad\")\n >>> 9\n Explanation:\n The substrings of length 1 that start and end with the same letter are: \"a\", \"b\", \"a\", \"c\", \"a\", and \"d\".\n The substrings of length 3 that start and end with the same letter are: \"aba\" and \"aca\".\n The substring of length 5 that starts and ends with the same letter is: \"abaca\".\n \n Example 3:\n \n >>> numberOfSubstrings(s = \"a\")\n >>> 1\n Explanation:\n The substring of length 1 that starts and ends with the same letter is: \"a\".\n \"\"\"\n"}
{"task_id": "count-common-words-with-one-occurrence", "prompt": "def countWords(words1: List[str], words2: List[str]) -> int:\n \"\"\"\n Given two string arrays words1 and words2, return the number of strings that appear exactly once in each\u00a0of the two arrays.\n \n Example 1:\n \n >>> countWords(words1 = [\"leetcode\",\"is\",\"amazing\",\"as\",\"is\"], words2 = [\"amazing\",\"leetcode\",\"is\"])\n >>> 2\n Explanation:\n - \"leetcode\" appears exactly once in each of the two arrays. We count this string.\n - \"amazing\" appears exactly once in each of the two arrays. We count this string.\n - \"is\" appears in each of the two arrays, but there are 2 occurrences of it in words1. We do not count this string.\n - \"as\" appears once in words1, but does not appear in words2. We do not count this string.\n Thus, there are 2 strings that appear exactly once in each of the two arrays.\n \n Example 2:\n \n >>> countWords(words1 = [\"b\",\"bb\",\"bbb\"], words2 = [\"a\",\"aa\",\"aaa\"])\n >>> 0\n Explanation: There are no strings that appear in each of the two arrays.\n \n Example 3:\n \n >>> countWords(words1 = [\"a\",\"ab\"], words2 = [\"a\",\"a\",\"a\",\"ab\"])\n >>> 1\n Explanation: The only string that appears exactly once in each of the two arrays is \"ab\".\n \"\"\"\n"}
{"task_id": "minimum-number-of-food-buckets-to-feed-the-hamsters", "prompt": "def minimumBuckets(hamsters: str) -> int:\n \"\"\"\n You are given a 0-indexed string hamsters where hamsters[i] is either:\n \n 'H' indicating that there is a hamster at index i, or\n '.' indicating that index i is empty.\n \n You will add some number of food buckets at the empty indices in order to feed the hamsters. A hamster can be fed if there is at least one food bucket to its left or to its right. More formally, a hamster at index i can be fed if you place a food bucket at index i - 1 and/or at index i + 1.\n Return the minimum number of food buckets you should place at empty indices to feed all the hamsters or -1 if it is impossible to feed all of them.\n \n Example 1:\n \n \n >>> minimumBuckets(hamsters = \"H..H\")\n >>> 2\n Explanation: We place two food buckets at indices 1 and 2.\n It can be shown that if we place only one food bucket, one of the hamsters will not be fed.\n \n Example 2:\n \n \n >>> minimumBuckets(hamsters = \".H.H.\")\n >>> 1\n Explanation: We place one food bucket at index 2.\n \n Example 3:\n \n \n >>> minimumBuckets(hamsters = \".HHH.\")\n >>> -1\n Explanation: If we place a food bucket at every empty index as shown, the hamster at index 2 will not be able to eat.\n \"\"\"\n"}
{"task_id": "minimum-cost-homecoming-of-a-robot-in-a-grid", "prompt": "def minCost(startPos: List[int], homePos: List[int], rowCosts: List[int], colCosts: List[int]) -> int:\n \"\"\"\n There is an m x n grid, where (0, 0) is the top-left cell and (m - 1, n - 1) is the bottom-right cell. You are given an integer array startPos where startPos = [startrow, startcol] indicates that initially, a robot is at the cell (startrow, startcol). You are also given an integer array homePos where homePos = [homerow, homecol] indicates that its home is at the cell (homerow, homecol).\n The robot needs to go to its home. It can move one cell in four directions: left, right, up, or down, and it can not move outside the boundary. Every move incurs some cost. You are further given two 0-indexed integer arrays: rowCosts of length m and colCosts of length n.\n \n If the robot moves up or down into a cell whose row is r, then this move costs rowCosts[r].\n If the robot moves left or right into a cell whose column is c, then this move costs colCosts[c].\n \n Return the minimum total cost for this robot to return home.\n \n Example 1:\n \n \n >>> minCost(startPos = [1, 0], homePos = [2, 3], rowCosts = [5, 4, 3], colCosts = [8, 2, 6, 7])\n >>> 18\n Explanation: One optimal path is that:\n Starting from (1, 0)\n -> It goes down to (2, 0). This move costs rowCosts[2] = 3.\n -> It goes right to (2, 1). This move costs colCosts[1] = 2.\n -> It goes right to (2, 2). This move costs colCosts[2] = 6.\n -> It goes right to (2, 3). This move costs colCosts[3] = 7.\n The total cost is 3 + 2 + 6 + 7 = 18\n Example 2:\n \n >>> minCost(startPos = [0, 0], homePos = [0, 0], rowCosts = [5], colCosts = [26])\n >>> 0\n Explanation: The robot is already at its home. Since no moves occur, the total cost is 0.\n \"\"\"\n"}
{"task_id": "count-fertile-pyramids-in-a-land", "prompt": "def countPyramids(grid: List[List[int]]) -> int:\n \"\"\"\n A farmer has a rectangular grid of land with m rows and n columns that can be divided into unit cells. Each cell is either fertile (represented by a 1) or barren (represented by a 0). All cells outside the grid are considered barren.\n A pyramidal plot of land can be defined as a set of cells with the following criteria:\n \n The number of cells in the set has to be greater than 1 and all cells must be fertile.\n The apex of a pyramid is the topmost cell of the pyramid. The height of a pyramid is the number of rows it covers. Let (r, c) be the apex of the pyramid, and its height be h. Then, the plot comprises of cells (i, j) where r <= i <= r + h - 1 and c - (i - r) <= j <= c + (i - r).\n \n An inverse pyramidal plot of land can be defined as a set of cells with similar criteria:\n \n The number of cells in the set has to be greater than 1 and all cells must be fertile.\n The apex of an inverse pyramid is the bottommost cell of the inverse pyramid. The height of an inverse pyramid is the number of rows it covers. Let (r, c) be the apex of the pyramid, and its height be h. Then, the plot comprises of cells (i, j) where r - h + 1 <= i <= r and c - (r - i) <= j <= c + (r - i).\n \n Some examples of valid and invalid pyramidal (and inverse pyramidal) plots are shown below. Black cells indicate fertile cells.\n \n Given a 0-indexed m x n binary matrix grid representing the farmland, return the total number of pyramidal and inverse pyramidal plots that can be found in grid.\n \n Example 1:\n \n \n >>> countPyramids(grid = [[0,1,1,0],[1,1,1,1]])\n >>> 2\n Explanation: The 2 possible pyramidal plots are shown in blue and red respectively.\n There are no inverse pyramidal plots in this grid.\n Hence total number of pyramidal and inverse pyramidal plots is 2 + 0 = 2.\n \n Example 2:\n \n \n >>> countPyramids(grid = [[1,1,1],[1,1,1]])\n >>> 2\n Explanation: The pyramidal plot is shown in blue, and the inverse pyramidal plot is shown in red.\n Hence the total number of plots is 1 + 1 = 2.\n \n Example 3:\n \n \n >>> countPyramids(grid = [[1,1,1,1,0],[1,1,1,1,1],[1,1,1,1,1],[0,1,0,0,1]])\n >>> 13\n Explanation: There are 7 pyramidal plots, 3 of which are shown in the 2nd and 3rd figures.\n There are 6 inverse pyramidal plots, 2 of which are shown in the last figure.\n The total number of plots is 7 + 6 = 13.\n \"\"\"\n"}
{"task_id": "find-target-indices-after-sorting-array", "prompt": "def targetIndices(nums: List[int], target: int) -> List[int]:\n \"\"\"\n You are given a 0-indexed integer array nums and a target element target.\n A target index is an index i such that nums[i] == target.\n Return a list of the target indices of nums after sorting nums in non-decreasing order. If there are no target indices, return an empty list. The returned list must be sorted in increasing order.\n \n Example 1:\n \n >>> targetIndices(nums = [1,2,5,2,3], target = 2)\n >>> [1,2]\n Explanation: After sorting, nums is [1,2,2,3,5].\n The indices where nums[i] == 2 are 1 and 2.\n \n Example 2:\n \n >>> targetIndices(nums = [1,2,5,2,3], target = 3)\n >>> [3]\n Explanation: After sorting, nums is [1,2,2,3,5].\n The index where nums[i] == 3 is 3.\n \n Example 3:\n \n >>> targetIndices(nums = [1,2,5,2,3], target = 5)\n >>> [4]\n Explanation: After sorting, nums is [1,2,2,3,5].\n The index where nums[i] == 5 is 4.\n \"\"\"\n"}
{"task_id": "k-radius-subarray-averages", "prompt": "def getAverages(nums: List[int], k: int) -> List[int]:\n \"\"\"\n You are given a 0-indexed array nums of n integers, and an integer k.\n The k-radius average for a subarray of nums centered at some index i with the radius k is the average of all elements in nums between the indices i - k and i + k (inclusive). If there are less than k elements before or after the index i, then the k-radius average is -1.\n Build and return an array avgs of length n where avgs[i] is the k-radius average for the subarray centered at index i.\n The average of x elements is the sum of the x elements divided by x, using integer division. The integer division truncates toward zero, which means losing its fractional part.\n \n For example, the average of four elements 2, 3, 1, and 5 is (2 + 3 + 1 + 5) / 4 = 11 / 4 = 2.75, which truncates to 2.\n \n \n Example 1:\n \n \n >>> getAverages(nums = [7,4,3,9,1,8,5,2,6], k = 3)\n >>> [-1,-1,-1,5,4,4,-1,-1,-1]\n Explanation:\n - avg[0], avg[1], and avg[2] are -1 because there are less than k elements before each index.\n - The sum of the subarray centered at index 3 with radius 3 is: 7 + 4 + 3 + 9 + 1 + 8 + 5 = 37.\n Using integer division, avg[3] = 37 / 7 = 5.\n - For the subarray centered at index 4, avg[4] = (4 + 3 + 9 + 1 + 8 + 5 + 2) / 7 = 4.\n - For the subarray centered at index 5, avg[5] = (3 + 9 + 1 + 8 + 5 + 2 + 6) / 7 = 4.\n - avg[6], avg[7], and avg[8] are -1 because there are less than k elements after each index.\n \n Example 2:\n \n >>> getAverages(nums = [100000], k = 0)\n >>> [100000]\n Explanation:\n - The sum of the subarray centered at index 0 with radius 0 is: 100000.\n avg[0] = 100000 / 1 = 100000.\n \n Example 3:\n \n >>> getAverages(nums = [8], k = 100000)\n >>> [-1]\n Explanation:\n - avg[0] is -1 because there are less than k elements before and after index 0.\n \"\"\"\n"}
{"task_id": "removing-minimum-and-maximum-from-array", "prompt": "def minimumDeletions(nums: List[int]) -> int:\n \"\"\"\n You are given a 0-indexed array of distinct integers nums.\n There is an element in nums that has the lowest value and an element that has the highest value. We call them the minimum and maximum respectively. Your goal is to remove both these elements from the array.\n A deletion is defined as either removing an element from the front of the array or removing an element from the back of the array.\n Return the minimum number of deletions it would take to remove both the minimum and maximum element from the array.\n \n Example 1:\n \n >>> minimumDeletions(nums = [2,10,7,5,4,1,8,6])\n >>> 5\n Explanation:\n The minimum element in the array is nums[5], which is 1.\n The maximum element in the array is nums[1], which is 10.\n We can remove both the minimum and maximum by removing 2 elements from the front and 3 elements from the back.\n This results in 2 + 3 = 5 deletions, which is the minimum number possible.\n \n Example 2:\n \n >>> minimumDeletions(nums = [0,-4,19,1,8,-2,-3,5])\n >>> 3\n Explanation:\n The minimum element in the array is nums[1], which is -4.\n The maximum element in the array is nums[2], which is 19.\n We can remove both the minimum and maximum by removing 3 elements from the front.\n This results in only 3 deletions, which is the minimum number possible.\n \n Example 3:\n \n >>> minimumDeletions(nums = [101])\n >>> 1\n Explanation:\n There is only one element in the array, which makes it both the minimum and maximum element.\n We can remove it with 1 deletion.\n \"\"\"\n"}
{"task_id": "find-all-people-with-secret", "prompt": "def findAllPeople(n: int, meetings: List[List[int]], firstPerson: int) -> List[int]:\n \"\"\"\n You are given an integer n indicating there are n people numbered from 0 to n - 1. You are also given a 0-indexed 2D integer array meetings where meetings[i] = [xi, yi, timei] indicates that person xi and person yi have a meeting at timei. A person may attend multiple meetings at the same time. Finally, you are given an integer firstPerson.\n Person 0 has a secret and initially shares the secret with a person firstPerson at time 0. This secret is then shared every time a meeting takes place with a person that has the secret. More formally, for every meeting, if a person xi has the secret at timei, then they will share the secret with person yi, and vice versa.\n The secrets are shared instantaneously. That is, a person may receive the secret and share it with people in other meetings within the same time frame.\n Return a list of all the people that have the secret after all the meetings have taken place. You may return the answer in any order.\n \n Example 1:\n \n >>> findAllPeople(n = 6, meetings = [[1,2,5],[2,3,8],[1,5,10]], firstPerson = 1)\n >>> [0,1,2,3,5]\n Explanation:\n At time 0, person 0 shares the secret with person 1.\n At time 5, person 1 shares the secret with person 2.\n At time 8, person 2 shares the secret with person 3.\n At time 10, person 1 shares the secret with person 5.\u200b\u200b\u200b\u200b\n Thus, people 0, 1, 2, 3, and 5 know the secret after all the meetings.\n \n Example 2:\n \n >>> findAllPeople(n = 4, meetings = [[3,1,3],[1,2,2],[0,3,3]], firstPerson = 3)\n >>> [0,1,3]\n Explanation:\n At time 0, person 0 shares the secret with person 3.\n At time 2, neither person 1 nor person 2 know the secret.\n At time 3, person 3 shares the secret with person 0 and person 1.\n Thus, people 0, 1, and 3 know the secret after all the meetings.\n \n Example 3:\n \n >>> findAllPeople(n = 5, meetings = [[3,4,2],[1,2,1],[2,3,1]], firstPerson = 1)\n >>> [0,1,2,3,4]\n Explanation:\n At time 0, person 0 shares the secret with person 1.\n At time 1, person 1 shares the secret with person 2, and person 2 shares the secret with person 3.\n Note that person 2 can share the secret at the same time as receiving it.\n At time 2, person 3 shares the secret with person 4.\n Thus, people 0, 1, 2, 3, and 4 know the secret after all the meetings.\n \"\"\"\n"}
{"task_id": "minimum-cost-to-reach-city-with-discounts", "prompt": "def minimumCost(n: int, highways: List[List[int]], discounts: int) -> int:\n \"\"\"\n A series of highways connect n cities numbered from 0 to n - 1. You are given a 2D integer array highways where highways[i] = [city1i, city2i, tolli] indicates that there is a highway that connects city1i and city2i, allowing a car to go from city1i to city2i and vice versa for a cost of tolli.\n You are also given an integer discounts which represents the number of discounts you have. You can use a discount to travel across the ith highway for a cost of tolli / 2 (integer division). Each discount may only be used once, and you can only use at most one discount per highway.\n Return the minimum total cost to go from city 0 to city n - 1, or -1 if it is not possible to go from city 0 to city n - 1.\n \n Example 1:\n \n \n >>> minimumCost(n = 5, highways = [[0,1,4],[2,1,3],[1,4,11],[3,2,3],[3,4,2]], discounts = 1)\n >>> 9\n Explanation:\n Go from 0 to 1 for a cost of 4.\n Go from 1 to 4 and use a discount for a cost of 11 / 2 = 5.\n The minimum cost to go from 0 to 4 is 4 + 5 = 9.\n \n Example 2:\n \n \n >>> minimumCost(n = 4, highways = [[1,3,17],[1,2,7],[3,2,5],[0,1,6],[3,0,20]], discounts = 20)\n >>> 8\n Explanation:\n Go from 0 to 1 and use a discount for a cost of 6 / 2 = 3.\n Go from 1 to 2 and use a discount for a cost of 7 / 2 = 3.\n Go from 2 to 3 and use a discount for a cost of 5 / 2 = 2.\n The minimum cost to go from 0 to 3 is 3 + 3 + 2 = 8.\n \n Example 3:\n \n \n >>> minimumCost(n = 4, highways = [[0,1,3],[2,3,2]], discounts = 0)\n >>> -1\n Explanation:\n It is impossible to go from 0 to 3 so return -1.\n \"\"\"\n"}
{"task_id": "finding-3-digit-even-numbers", "prompt": "def findEvenNumbers(digits: List[int]) -> List[int]:\n \"\"\"\n You are given an integer array digits, where each element is a digit. The array may contain duplicates.\n You need to find all the unique integers that follow the given requirements:\n \n The integer consists of the concatenation of three elements from digits in any arbitrary order.\n The integer does not have leading zeros.\n The integer is even.\n \n For example, if the given digits were [1, 2, 3], integers 132 and 312 follow the requirements.\n Return a sorted array of the unique integers.\n \n Example 1:\n \n >>> findEvenNumbers(digits = [2,1,3,0])\n >>> [102,120,130,132,210,230,302,310,312,320]\n Explanation: All the possible integers that follow the requirements are in the output array.\n Notice that there are no odd integers or integers with leading zeros.\n \n Example 2:\n \n >>> findEvenNumbers(digits = [2,2,8,8,2])\n >>> [222,228,282,288,822,828,882]\n Explanation: The same digit can be used as many times as it appears in digits.\n In this example, the digit 8 is used twice each time in 288, 828, and 882.\n \n Example 3:\n \n >>> findEvenNumbers(digits = [3,7,5])\n >>> []\n Explanation: No even integers can be formed using the given digits.\n \"\"\"\n"}
{"task_id": "delete-the-middle-node-of-a-linked-list", "prompt": "# class ListNode:\n# def __init__(val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution:\n def deleteMiddle(head: Optional[ListNode]) -> Optional[ListNode]:\n \"\"\"\n You are given the head of a linked list. Delete the middle node, and return the head of the modified linked list.\n The middle node of a linked list of size n is the \u230an / 2\u230bth node from the start using 0-based indexing, where \u230ax\u230b denotes the largest integer less than or equal to x.\n \n For n = 1, 2, 3, 4, and 5, the middle nodes are 0, 1, 1, 2, and 2, respectively.\n \n \n Example 1:\n \n \n >>> __init__(head = [1,3,4,7,1,2,6])\n >>> [1,3,4,1,2,6]\n Explanation:\n The above figure represents the given linked list. The indices of the nodes are written below.\n Since n = 7, node 3 with value 7 is the middle node, which is marked in red.\n We return the new list after removing this node.\n \n Example 2:\n \n \n >>> __init__(head = [1,2,3,4])\n >>> [1,2,4]\n Explanation:\n The above figure represents the given linked list.\n For n = 4, node 2 with value 3 is the middle node, which is marked in red.\n \n Example 3:\n \n \n >>> __init__(head = [2,1])\n >>> [2]\n Explanation:\n The above figure represents the given linked list.\n For n = 2, node 1 with value 1 is the middle node, which is marked in red.\n Node 0 with value 2 is the only node remaining after removing node 1.\n \"\"\"\n"}
{"task_id": "step-by-step-directions-from-a-binary-tree-node-to-another", "prompt": "# class TreeNode:\n# def __init__(val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def getDirections(root: Optional[TreeNode], startValue: int, destValue: int) -> str:\n \"\"\"\n You are given the root of a binary tree with n nodes. Each node is uniquely assigned a value from 1 to n. You are also given an integer startValue representing the value of the start node s, and a different integer destValue representing the value of the destination node t.\n Find the shortest path starting from node s and ending at node t. Generate step-by-step directions of such path as a string consisting of only the uppercase letters 'L', 'R', and 'U'. Each letter indicates a specific direction:\n \n 'L' means to go from a node to its left child node.\n 'R' means to go from a node to its right child node.\n 'U' means to go from a node to its parent node.\n \n Return the step-by-step directions of the shortest path from node s to node t.\n \n Example 1:\n \n \n >>> __init__(root = [5,1,2,3,null,6,4], startValue = 3, destValue = 6)\n >>> \"UURL\"\n Explanation: The shortest path is: 3 \u2192 1 \u2192 5 \u2192 2 \u2192 6.\n \n Example 2:\n \n \n >>> __init__(root = [2,1], startValue = 2, destValue = 1)\n >>> \"L\"\n Explanation: The shortest path is: 2 \u2192 1.\n \"\"\"\n"}
{"task_id": "valid-arrangement-of-pairs", "prompt": "def validArrangement(pairs: List[List[int]]) -> List[List[int]]:\n \"\"\"\n You are given a 0-indexed 2D integer array pairs where pairs[i] = [starti, endi]. An arrangement of pairs is valid if for every index i where 1 <= i < pairs.length, we have endi-1 == starti.\n Return any valid arrangement of pairs.\n Note: The inputs will be generated such that there exists a valid arrangement of pairs.\n \n Example 1:\n \n >>> validArrangement(pairs = [[5,1],[4,5],[11,9],[9,4]])\n >>> [[11,9],[9,4],[4,5],[5,1]]\n Explanation:\n This is a valid arrangement since endi-1 always equals starti.\n end0 = 9 == 9 = start1\n end1 = 4 == 4 = start2\n end2 = 5 == 5 = start3\n \n Example 2:\n \n >>> validArrangement(pairs = [[1,3],[3,2],[2,1]])\n >>> [[1,3],[3,2],[2,1]]\n Explanation:\n This is a valid arrangement since endi-1 always equals starti.\n end0 = 3 == 3 = start1\n end1 = 2 == 2 = start2\n The arrangements [[2,1],[1,3],[3,2]] and [[3,2],[2,1],[1,3]] are also valid.\n \n Example 3:\n \n >>> validArrangement(pairs = [[1,2],[1,3],[2,1]])\n >>> [[1,2],[2,1],[1,3]]\n Explanation:\n This is a valid arrangement since endi-1 always equals starti.\n end0 = 2 == 2 = start1\n end1 = 1 == 1 = start2\n \"\"\"\n"}
{"task_id": "subsequence-of-size-k-with-the-largest-even-sum", "prompt": "def largestEvenSum(nums: List[int], k: int) -> int:\n \"\"\"\n You are given an integer array nums and an integer k. Find the largest even sum of any subsequence of nums that has a length of k.\n Return this sum, or -1 if such a sum does not exist.\n 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.\n \n Example 1:\n \n >>> largestEvenSum(nums = [4,1,5,3,1], k = 3)\n >>> 12\n Explanation:\n The subsequence with the largest possible even sum is [4,5,3]. It has a sum of 4 + 5 + 3 = 12.\n \n Example 2:\n \n >>> largestEvenSum(nums = [4,6,2], k = 3)\n >>> 12\n Explanation:\n The subsequence with the largest possible even sum is [4,6,2]. It has a sum of 4 + 6 + 2 = 12.\n \n Example 3:\n \n >>> largestEvenSum(nums = [1,3,5], k = 1)\n >>> -1\n Explanation:\n No subsequence of nums with length 1 has an even sum.\n \"\"\"\n"}
{"task_id": "find-subsequence-of-length-k-with-the-largest-sum", "prompt": "def maxSubsequence(nums: List[int], k: int) -> List[int]:\n \"\"\"\n You are given an integer array nums and an integer k. You want to find a subsequence of nums of length k that has the largest sum.\n Return any such subsequence as an integer array of length k.\n 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.\n \n Example 1:\n \n >>> maxSubsequence(nums = [2,1,3,3], k = 2)\n >>> [3,3]\n Explanation:\n The subsequence has the largest sum of 3 + 3 = 6.\n Example 2:\n \n >>> maxSubsequence(nums = [-1,-2,3,4], k = 3)\n >>> [-1,3,4]\n Explanation:\n The subsequence has the largest sum of -1 + 3 + 4 = 6.\n \n Example 3:\n \n >>> maxSubsequence(nums = [3,4,3,3], k = 2)\n >>> [3,4]\n Explanation:\n The subsequence has the largest sum of 3 + 4 = 7.\n Another possible subsequence is [4, 3].\n \"\"\"\n"}
{"task_id": "find-good-days-to-rob-the-bank", "prompt": "def goodDaysToRobBank(security: List[int], time: int) -> List[int]:\n \"\"\"\n You and a gang of thieves are planning on robbing a bank. You are given a 0-indexed integer array security, where security[i] is the number of guards on duty on the ith day. The days are numbered starting from 0. You are also given an integer time.\n The ith day is a good day to rob the bank if:\n \n There are at least time days before and after the ith day,\n The number of guards at the bank for the time days before i are non-increasing, and\n The number of guards at the bank for the time days after i are non-decreasing.\n \n More formally, this means day i is a good day to rob the bank if and only if security[i - time] >= security[i - time + 1] >= ... >= security[i] <= ... <= security[i + time - 1] <= security[i + time].\n Return a list of all days (0-indexed) that are good days to rob the bank. The order that the days are returned in does not matter.\n \n Example 1:\n \n >>> goodDaysToRobBank(security = [5,3,3,3,5,6,2], time = 2)\n >>> [2,3]\n Explanation:\n On day 2, we have security[0] >= security[1] >= security[2] <= security[3] <= security[4].\n On day 3, we have security[1] >= security[2] >= security[3] <= security[4] <= security[5].\n No other days satisfy this condition, so days 2 and 3 are the only good days to rob the bank.\n \n Example 2:\n \n >>> goodDaysToRobBank(security = [1,1,1,1,1], time = 0)\n >>> [0,1,2,3,4]\n Explanation:\n Since time equals 0, every day is a good day to rob the bank, so return every day.\n \n Example 3:\n \n >>> goodDaysToRobBank(security = [1,2,3,4,5,6], time = 2)\n >>> []\n Explanation:\n No day has 2 days before it that have a non-increasing number of guards.\n Thus, no day is a good day to rob the bank, so return an empty list.\n \"\"\"\n"}
{"task_id": "detonate-the-maximum-bombs", "prompt": "def maximumDetonation(bombs: List[List[int]]) -> int:\n \"\"\"\n You are given a list of bombs. The range of a bomb is defined as the area where its effect can be felt. This area is in the shape of a circle with the center as the location of the bomb.\n The bombs are represented by a 0-indexed 2D integer array bombs where bombs[i] = [xi, yi, ri]. xi and yi denote the X-coordinate and Y-coordinate of the location of the ith bomb, whereas ri denotes the radius of its range.\n You may choose to detonate a single bomb. When a bomb is detonated, it will detonate all bombs that lie in its range. These bombs will further detonate the bombs that lie in their ranges.\n Given the list of bombs, return the maximum number of bombs that can be detonated if you are allowed to detonate only one bomb.\n \n Example 1:\n \n \n >>> maximumDetonation(bombs = [[2,1,3],[6,1,4]])\n >>> 2\n Explanation:\n The above figure shows the positions and ranges of the 2 bombs.\n If we detonate the left bomb, the right bomb will not be affected.\n But if we detonate the right bomb, both bombs will be detonated.\n So the maximum bombs that can be detonated is max(1, 2) = 2.\n \n Example 2:\n \n \n >>> maximumDetonation(bombs = [[1,1,5],[10,10,5]])\n >>> 1\n Explanation:\n Detonating either bomb will not detonate the other bomb, so the maximum number of bombs that can be detonated is 1.\n \n Example 3:\n \n \n >>> maximumDetonation(bombs = [[1,2,3],[2,3,1],[3,4,2],[4,5,3],[5,6,4]])\n >>> 5\n Explanation:\n The best bomb to detonate is bomb 0 because:\n - Bomb 0 detonates bombs 1 and 2. The red circle denotes the range of bomb 0.\n - Bomb 2 detonates bomb 3. The blue circle denotes the range of bomb 2.\n - Bomb 3 detonates bomb 4. The green circle denotes the range of bomb 3.\n Thus all 5 bombs are detonated.\n \"\"\"\n"}
{"task_id": "rings-and-rods", "prompt": "def countPoints(rings: str) -> int:\n \"\"\"\n There are n rings and each ring is either red, green, or blue. The rings are distributed across ten rods labeled from 0 to 9.\n You are given a string rings of length 2n that describes the n rings that are placed onto the rods. Every two characters in rings forms a color-position pair that is used to describe each ring where:\n \n The first character of the ith pair denotes the ith ring's color ('R', 'G', 'B').\n The second character of the ith pair denotes the rod that the ith ring is placed on ('0' to '9').\n \n For example, \"R3G2B1\" describes n == 3 rings: a red ring placed onto the rod labeled 3, a green ring placed onto the rod labeled 2, and a blue ring placed onto the rod labeled 1.\n Return the number of rods that have all three colors of rings on them.\n \n Example 1:\n \n \n >>> countPoints(rings = \"B0B6G0R6R0R6G9\")\n >>> 1\n Explanation:\n - The rod labeled 0 holds 3 rings with all colors: red, green, and blue.\n - The rod labeled 6 holds 3 rings, but it only has red and blue.\n - The rod labeled 9 holds only a green ring.\n Thus, the number of rods with all three colors is 1.\n \n Example 2:\n \n \n >>> countPoints(rings = \"B0R0G0R9R0B0G0\")\n >>> 1\n Explanation:\n - The rod labeled 0 holds 6 rings with all colors: red, green, and blue.\n - The rod labeled 9 holds only a red ring.\n Thus, the number of rods with all three colors is 1.\n \n Example 3:\n \n >>> countPoints(rings = \"G4\")\n >>> 0\n Explanation:\n Only one ring is given. Thus, no rods have all three colors.\n \"\"\"\n"}
{"task_id": "sum-of-subarray-ranges", "prompt": "def subArrayRanges(nums: List[int]) -> int:\n \"\"\"\n You are given an integer array nums. The range of a subarray of nums is the difference between the largest and smallest element in the subarray.\n Return the sum of all subarray ranges of nums.\n A subarray is a contiguous non-empty sequence of elements within an array.\n \n Example 1:\n \n >>> subArrayRanges(nums = [1,2,3])\n >>> 4\n Explanation: The 6 subarrays of nums are the following:\n [1], range = largest - smallest = 1 - 1 = 0\n [2], range = 2 - 2 = 0\n [3], range = 3 - 3 = 0\n [1,2], range = 2 - 1 = 1\n [2,3], range = 3 - 2 = 1\n [1,2,3], range = 3 - 1 = 2\n So the sum of all ranges is 0 + 0 + 0 + 1 + 1 + 2 = 4.\n Example 2:\n \n >>> subArrayRanges(nums = [1,3,3])\n >>> 4\n Explanation: The 6 subarrays of nums are the following:\n [1], range = largest - smallest = 1 - 1 = 0\n [3], range = 3 - 3 = 0\n [3], range = 3 - 3 = 0\n [1,3], range = 3 - 1 = 2\n [3,3], range = 3 - 3 = 0\n [1,3,3], range = 3 - 1 = 2\n So the sum of all ranges is 0 + 0 + 0 + 2 + 0 + 2 = 4.\n \n Example 3:\n \n >>> subArrayRanges(nums = [4,-2,-3,4,1])\n >>> 59\n Explanation: The sum of all subarray ranges of nums is 59.\n \"\"\"\n"}
{"task_id": "watering-plants-ii", "prompt": "def minimumRefill(plants: List[int], capacityA: int, capacityB: int) -> int:\n \"\"\"\n Alice and Bob want to water n plants in their garden. The plants are arranged in a row and are labeled from 0 to n - 1 from left to right where the ith plant is located at x = i.\n Each plant needs a specific amount of water. Alice and Bob have a watering can each, initially full. They water the plants in the following way:\n \n Alice waters the plants in order from left to right, starting from the 0th plant. Bob waters the plants in order from right to left, starting from the (n - 1)th plant. They begin watering the plants simultaneously.\n It takes the same amount of time to water each plant regardless of how much water it needs.\n Alice/Bob must water the plant if they have enough in their can to fully water it. Otherwise, they first refill their can (instantaneously) then water the plant.\n In case both Alice and Bob reach the same plant, the one with more water currently in his/her watering can should water this plant. If they have the same amount of water, then Alice should water this plant.\n \n Given a 0-indexed integer array plants of n integers, where plants[i] is the amount of water the ith plant needs, and two integers capacityA and capacityB representing the capacities of Alice's and Bob's watering cans respectively, return the number of times they have to refill to water all the plants.\n \n Example 1:\n \n >>> minimumRefill(plants = [2,2,3,3], capacityA = 5, capacityB = 5)\n >>> 1\n Explanation:\n - Initially, Alice and Bob have 5 units of water each in their watering cans.\n - Alice waters plant 0, Bob waters plant 3.\n - Alice and Bob now have 3 units and 2 units of water respectively.\n - Alice has enough water for plant 1, so she waters it. Bob does not have enough water for plant 2, so he refills his can then waters it.\n So, the total number of times they have to refill to water all the plants is 0 + 0 + 1 + 0 = 1.\n \n Example 2:\n \n >>> minimumRefill(plants = [2,2,3,3], capacityA = 3, capacityB = 4)\n >>> 2\n Explanation:\n - Initially, Alice and Bob have 3 units and 4 units of water in their watering cans respectively.\n - Alice waters plant 0, Bob waters plant 3.\n - Alice and Bob now have 1 unit of water each, and need to water plants 1 and 2 respectively.\n - Since neither of them have enough water for their current plants, they refill their cans and then water the plants.\n So, the total number of times they have to refill to water all the plants is 0 + 1 + 1 + 0 = 2.\n \n Example 3:\n \n >>> minimumRefill(plants = [5], capacityA = 10, capacityB = 8)\n >>> 0\n Explanation:\n - There is only one plant.\n - Alice's watering can has 10 units of water, whereas Bob's can has 8 units. Since Alice has more water in her can, she waters this plant.\n So, the total number of times they have to refill is 0.\n \"\"\"\n"}
{"task_id": "maximum-fruits-harvested-after-at-most-k-steps", "prompt": "def maxTotalFruits(fruits: List[List[int]], startPos: int, k: int) -> int:\n \"\"\"\n Fruits are available at some positions on an infinite x-axis. You are given a 2D integer array fruits where fruits[i] = [positioni, amounti] depicts amounti fruits at the position positioni. fruits is already sorted by positioni in ascending order, and each positioni is unique.\n You are also given an integer startPos and an integer k. Initially, you are at the position startPos. From any position, you can either walk to the left or right. It takes one step to move one unit on the x-axis, and you can walk at most k steps in total. For every position you reach, you harvest all the fruits at that position, and the fruits will disappear from that position.\n Return the maximum total number of fruits you can harvest.\n \n Example 1:\n \n \n >>> maxTotalFruits(fruits = [[2,8],[6,3],[8,6]], startPos = 5, k = 4)\n >>> 9\n Explanation:\n The optimal way is to:\n - Move right to position 6 and harvest 3 fruits\n - Move right to position 8 and harvest 6 fruits\n You moved 3 steps and harvested 3 + 6 = 9 fruits in total.\n \n Example 2:\n \n \n >>> maxTotalFruits(fruits = [[0,9],[4,1],[5,7],[6,2],[7,4],[10,9]], startPos = 5, k = 4)\n >>> 14\n Explanation:\n You can move at most k = 4 steps, so you cannot reach position 0 nor 10.\n The optimal way is to:\n - Harvest the 7 fruits at the starting position 5\n - Move left to position 4 and harvest 1 fruit\n - Move right to position 6 and harvest 2 fruits\n - Move right to position 7 and harvest 4 fruits\n You moved 1 + 3 = 4 steps and harvested 7 + 1 + 2 + 4 = 14 fruits in total.\n \n Example 3:\n \n \n >>> maxTotalFruits(fruits = [[0,3],[6,4],[8,5]], startPos = 3, k = 2)\n >>> 0\n Explanation:\n You can move at most k = 2 steps and cannot reach any position with fruits.\n \"\"\"\n"}
{"task_id": "number-of-unique-flavors-after-sharing-k-candies", "prompt": "def shareCandies(candies: List[int], k: int) -> int:\n \"\"\"\n You are given a 0-indexed integer array candies, where candies[i] represents the flavor of the ith candy. Your mom wants you to share these candies with your little sister by giving her k consecutive candies, but you want to keep as many flavors of candies as possible.\n Return the maximum number of unique flavors of candy you can keep after sharing with your sister.\n \n Example 1:\n \n >>> shareCandies(candies = [1,2,2,3,4,3], k = 3)\n >>> 3\n Explanation:\n Give the candies in the range [1, 3] (inclusive) with flavors [2,2,3].\n You can eat candies with flavors [1,4,3].\n There are 3 unique flavors, so return 3.\n \n Example 2:\n \n >>> shareCandies(candies = [2,2,2,2,3,3], k = 2)\n >>> 2\n Explanation:\n Give the candies in the range [3, 4] (inclusive) with flavors [2,3].\n You can eat candies with flavors [2,2,2,3].\n There are 2 unique flavors, so return 2.\n Note that you can also share the candies with flavors [2,2] and eat the candies with flavors [2,2,3,3].\n \n Example 3:\n \n >>> shareCandies(candies = [2,4,5], k = 0)\n >>> 3\n Explanation:\n You do not have to give any candies.\n You can eat the candies with flavors [2,4,5].\n There are 3 unique flavors, so return 3.\n \"\"\"\n"}
{"task_id": "find-first-palindromic-string-in-the-array", "prompt": "def firstPalindrome(words: List[str]) -> str:\n \"\"\"\n Given an array of strings words, return the first palindromic string in the array. If there is no such string, return an empty string \"\".\n A string is palindromic if it reads the same forward and backward.\n \n Example 1:\n \n >>> firstPalindrome(words = [\"abc\",\"car\",\"ada\",\"racecar\",\"cool\"])\n >>> \"ada\"\n Explanation: The first string that is palindromic is \"ada\".\n Note that \"racecar\" is also palindromic, but it is not the first.\n \n Example 2:\n \n >>> firstPalindrome(words = [\"notapalindrome\",\"racecar\"])\n >>> \"racecar\"\n Explanation: The first and only string that is palindromic is \"racecar\".\n \n Example 3:\n \n >>> firstPalindrome(words = [\"def\",\"ghi\"])\n >>> \"\"\n Explanation: There are no palindromic strings, so the empty string is returned.\n \"\"\"\n"}
{"task_id": "adding-spaces-to-a-string", "prompt": "def addSpaces(s: str, spaces: List[int]) -> str:\n \"\"\"\n You are given a 0-indexed string s and a 0-indexed integer array spaces that describes the indices in the original string where spaces will be added. Each space should be inserted before the character at the given index.\n \n For example, given s = \"EnjoyYourCoffee\" and spaces = [5, 9], we place spaces before 'Y' and 'C', which are at indices 5 and 9 respectively. Thus, we obtain \"Enjoy Your Coffee\".\n \n Return the modified string after the spaces have been added.\n \n Example 1:\n \n >>> addSpaces(s = \"LeetcodeHelpsMeLearn\", spaces = [8,13,15])\n >>> \"Leetcode Helps Me Learn\"\n Explanation:\n The indices 8, 13, and 15 correspond to the underlined characters in \"LeetcodeHelpsMeLearn\".\n We then place spaces before those characters.\n \n Example 2:\n \n >>> addSpaces(s = \"icodeinpython\", spaces = [1,5,7,9])\n >>> \"i code in py thon\"\n Explanation:\n The indices 1, 5, 7, and 9 correspond to the underlined characters in \"icodeinpython\".\n We then place spaces before those characters.\n \n Example 3:\n \n >>> addSpaces(s = \"spacing\", spaces = [0,1,2,3,4,5,6])\n >>> \" s p a c i n g\"\n Explanation:\n We are also able to place spaces before the first character of the string.\n \"\"\"\n"}
{"task_id": "number-of-smooth-descent-periods-of-a-stock", "prompt": "def getDescentPeriods(prices: List[int]) -> int:\n \"\"\"\n You are given an integer array prices representing the daily price history of a stock, where prices[i] is the stock price on the ith day.\n A smooth descent period of a stock consists of one or more contiguous days such that the price on each day is lower than the price on the preceding day by exactly 1. The first day of the period is exempted from this rule.\n Return the number of smooth descent periods.\n \n Example 1:\n \n >>> getDescentPeriods(prices = [3,2,1,4])\n >>> 7\n Explanation: There are 7 smooth descent periods:\n [3], [2], [1], [4], [3,2], [2,1], and [3,2,1]\n Note that a period with one day is a smooth descent period by the definition.\n \n Example 2:\n \n >>> getDescentPeriods(prices = [8,6,7,7])\n >>> 4\n Explanation: There are 4 smooth descent periods: [8], [6], [7], and [7]\n Note that [8,6] is not a smooth descent period as 8 - 6 \u2260 1.\n \n Example 3:\n \n >>> getDescentPeriods(prices = [1])\n >>> 1\n Explanation: There is 1 smooth descent period: [1]\n \"\"\"\n"}
{"task_id": "minimum-operations-to-make-the-array-k-increasing", "prompt": "def kIncreasing(arr: List[int], k: int) -> int:\n \"\"\"\n You are given a 0-indexed array arr consisting of n positive integers, and a positive integer k.\n The array arr is called K-increasing if arr[i-k] <= arr[i] holds for every index i, where k <= i <= n-1.\n \n For example, arr = [4, 1, 5, 2, 6, 2] is K-increasing for k = 2 because:\n \n \n arr[0] <= arr[2] (4 <= 5)\n arr[1] <= arr[3] (1 <= 2)\n arr[2] <= arr[4] (5 <= 6)\n arr[3] <= arr[5] (2 <= 2)\n \n \n However, the same arr is not K-increasing for k = 1 (because arr[0] > arr[1]) or k = 3 (because arr[0] > arr[3]).\n \n In one operation, you can choose an index i and change arr[i] into any positive integer.\n Return the minimum number of operations required to make the array K-increasing for the given k.\n \n Example 1:\n \n >>> kIncreasing(arr = [5,4,3,2,1], k = 1)\n >>> 4\n Explanation:\n For k = 1, the resultant array has to be non-decreasing.\n Some of the K-increasing arrays that can be formed are [5,6,7,8,9], [1,1,1,1,1], [2,2,3,4,4]. All of them require 4 operations.\n It is suboptimal to change the array to, for example, [6,7,8,9,10] because it would take 5 operations.\n It can be shown that we cannot make the array K-increasing in less than 4 operations.\n \n Example 2:\n \n >>> kIncreasing(arr = [4,1,5,2,6,2], k = 2)\n >>> 0\n Explanation:\n This is the same example as the one in the problem description.\n Here, for every index i where 2 <= i <= 5, arr[i-2] <= arr[i].\n Since the given array is already K-increasing, we do not need to perform any operations.\n Example 3:\n \n >>> kIncreasing(arr = [4,1,5,2,6,2], k = 3)\n >>> 2\n Explanation:\n Indices 3 and 5 are the only ones not satisfying arr[i-3] <= arr[i] for 3 <= i <= 5.\n One of the ways we can make the array K-increasing is by changing arr[3] to 4 and arr[5] to 5.\n The array will now be [4,1,5,4,6,5].\n Note that there can be other ways to make the array K-increasing, but none of them require less than 2 operations.\n \"\"\"\n"}
{"task_id": "elements-in-array-after-removing-and-replacing-elements", "prompt": "def elementInNums(nums: List[int], queries: List[List[int]]) -> List[int]:\n \"\"\"\n You are given a 0-indexed integer array nums. Initially on minute 0, the array is unchanged. Every minute, the leftmost element in nums is removed until no elements remain. Then, every minute, one element is appended to the end of nums, in the order they were removed in, until the original array is restored. This process repeats indefinitely.\n \n For example, the array [0,1,2] would change as follows: [0,1,2] \u2192 [1,2] \u2192 [2] \u2192 [] \u2192 [0] \u2192 [0,1] \u2192 [0,1,2] \u2192 [1,2] \u2192 [2] \u2192 [] \u2192 [0] \u2192 [0,1] \u2192 [0,1,2] \u2192 ...\n \n You are also given a 2D integer array queries of size n where queries[j] = [timej, indexj]. The answer to the jth query is:\n \n nums[indexj] if indexj < nums.length at minute timej\n -1 if indexj >= nums.length at minute timej\n \n Return an integer array ans of size n where ans[j] is the answer to the jth query.\n \n Example 1:\n \n >>> elementInNums(nums = [0,1,2], queries = [[0,2],[2,0],[3,2],[5,0]])\n >>> [2,2,-1,0]\n Explanation:\n Minute 0: [0,1,2] - All elements are in the nums.\n Minute 1: [1,2] - The leftmost element, 0, is removed.\n Minute 2: [2] - The leftmost element, 1, is removed.\n Minute 3: [] - The leftmost element, 2, is removed.\n Minute 4: [0] - 0 is added to the end of nums.\n Minute 5: [0,1] - 1 is added to the end of nums.\n \n At minute 0, nums[2] is 2.\n At minute 2, nums[0] is 2.\n At minute 3, nums[2] does not exist.\n At minute 5, nums[0] is 0.\n \n Example 2:\n \n >>> elementInNums(nums = [2], queries = [[0,0],[1,0],[2,0],[3,0]])\n >>> [2,-1,2,-1]\n Minute 0: [2] - All elements are in the nums.\n Minute 1: [] - The leftmost element, 2, is removed.\n Minute 2: [2] - 2 is added to the end of nums.\n Minute 3: [] - The leftmost element, 2, is removed.\n \n At minute 0, nums[0] is 2.\n At minute 1, nums[0] does not exist.\n At minute 2, nums[0] is 2.\n At minute 3, nums[0] does not exist.\n \"\"\"\n"}
{"task_id": "maximum-number-of-words-found-in-sentences", "prompt": "def mostWordsFound(sentences: List[str]) -> int:\n \"\"\"\n A sentence is a list of words that are separated by a single space\u00a0with no leading or trailing spaces.\n You are given an array of strings sentences, where each sentences[i] represents a single sentence.\n Return the maximum number of words that appear in a single sentence.\n \n Example 1:\n \n >>> mostWordsFound(sentences = [\"alice and bob love leetcode\", \"i think so too\", \"this is great thanks very much\"])\n >>> 6\n Explanation:\n - The first sentence, \"alice and bob love leetcode\", has 5 words in total.\n - The second sentence, \"i think so too\", has 4 words in total.\n - The third sentence, \"this is great thanks very much\", has 6 words in total.\n Thus, the maximum number of words in a single sentence comes from the third sentence, which has 6 words.\n \n Example 2:\n \n >>> mostWordsFound(sentences = [\"please wait\", \"continue to fight\", \"continue to win\"])\n >>> 3\n Explanation: It is possible that multiple sentences contain the same number of words.\n In this example, the second and third sentences (underlined) have the same number of words.\n \"\"\"\n"}
{"task_id": "find-all-possible-recipes-from-given-supplies", "prompt": "def findAllRecipes(recipes: List[str], ingredients: List[List[str]], supplies: List[str]) -> List[str]:\n \"\"\"\n You have information about n different recipes. You are given a string array recipes and a 2D string array ingredients. The ith recipe has the name recipes[i], and you can create it if you have all the needed ingredients from ingredients[i]. A recipe can also be an ingredient for other recipes, i.e., ingredients[i] may contain a string that is in recipes.\n You are also given a string array supplies containing all the ingredients that you initially have, and you have an infinite supply of all of them.\n Return a list of all the recipes that you can create. You may return the answer in any order.\n Note that two recipes may contain each other in their ingredients.\n \n Example 1:\n \n >>> findAllRecipes(recipes = [\"bread\"], ingredients = [[\"yeast\",\"flour\"]], supplies = [\"yeast\",\"flour\",\"corn\"])\n >>> [\"bread\"]\n Explanation:\n We can create \"bread\" since we have the ingredients \"yeast\" and \"flour\".\n \n Example 2:\n \n >>> findAllRecipes(recipes = [\"bread\",\"sandwich\"], ingredients = [[\"yeast\",\"flour\"],[\"bread\",\"meat\"]], supplies = [\"yeast\",\"flour\",\"meat\"])\n >>> [\"bread\",\"sandwich\"]\n Explanation:\n We can create \"bread\" since we have the ingredients \"yeast\" and \"flour\".\n We can create \"sandwich\" since we have the ingredient \"meat\" and can create the ingredient \"bread\".\n \n Example 3:\n \n >>> findAllRecipes(recipes = [\"bread\",\"sandwich\",\"burger\"], ingredients = [[\"yeast\",\"flour\"],[\"bread\",\"meat\"],[\"sandwich\",\"meat\",\"bread\"]], supplies = [\"yeast\",\"flour\",\"meat\"])\n >>> [\"bread\",\"sandwich\",\"burger\"]\n Explanation:\n We can create \"bread\" since we have the ingredients \"yeast\" and \"flour\".\n We can create \"sandwich\" since we have the ingredient \"meat\" and can create the ingredient \"bread\".\n We can create \"burger\" since we have the ingredient \"meat\" and can create the ingredients \"bread\" and \"sandwich\".\n \"\"\"\n"}
{"task_id": "check-if-a-parentheses-string-can-be-valid", "prompt": "def canBeValid(s: str, locked: str) -> bool:\n \"\"\"\n A parentheses string is a non-empty string consisting only of '(' and ')'. It is valid if any of the following conditions is true:\n \n It is ().\n It can be written as AB (A concatenated with B), where A and B are valid parentheses strings.\n It can be written as (A), where A is a valid parentheses string.\n \n You are given a parentheses string s and a string locked, both of length n. locked is a binary string consisting only of '0's and '1's. For each index i of locked,\n \n If locked[i] is '1', you cannot change s[i].\n But if locked[i] is '0', you can change s[i] to either '(' or ')'.\n \n Return true if you can make s a valid parentheses string. Otherwise, return false.\n \n Example 1:\n \n \n >>> canBeValid(s = \"))()))\", locked = \"010100\")\n >>> true\n Explanation: locked[1] == '1' and locked[3] == '1', so we cannot change s[1] or s[3].\n We change s[0] and s[4] to '(' while leaving s[2] and s[5] unchanged to make s valid.\n Example 2:\n \n >>> canBeValid(s = \"()()\", locked = \"0000\")\n >>> true\n Explanation: We do not need to make any changes because s is already valid.\n \n Example 3:\n \n >>> canBeValid(s = \")\", locked = \"0\")\n >>> false\n Explanation: locked permits us to change s[0].\n Changing s[0] to either '(' or ')' will not make s valid.\n \n Example 4:\n \n >>> canBeValid(s = \"(((())(((())\", locked = \"111111010111\")\n >>> true\n Explanation: locked permits us to change s[6] and s[8].\n We change s[6] and s[8] to ')' to make s valid.\n \"\"\"\n"}
{"task_id": "abbreviating-the-product-of-a-range", "prompt": "def abbreviateProduct(left: int, right: int) -> str:\n \"\"\"\n You are given two positive integers left and right with left <= right. Calculate the product of all integers in the inclusive range [left, right].\n Since the product may be very large, you will abbreviate it following these steps:\n \n Count all trailing zeros in the product and remove them. Let us denote this count as C.\n \n \n For example, there are 3 trailing zeros in 1000, and there are 0 trailing zeros in 546.\n \n \n Denote the remaining number of digits in the product as d. If d > 10, then express the product as ... where denotes the first 5 digits of the product, and denotes the last 5 digits of the product after removing all trailing zeros. If d <= 10, we keep it unchanged.\n \n For example, we express 1234567654321 as 12345...54321, but 1234567 is represented as 1234567.\n \n \n Finally, represent the product as a string \"...eC\".\n \n For example, 12345678987600000 will be represented as \"12345...89876e5\".\n \n \n \n Return a string denoting the abbreviated product of all integers in the inclusive range [left, right].\n \n Example 1:\n \n >>> abbreviateProduct(left = 1, right = 4)\n >>> \"24e0\"\n Explanation: The product is 1 \u00d7 2 \u00d7 3 \u00d7 4 = 24.\n There are no trailing zeros, so 24 remains the same. The abbreviation will end with \"e0\".\n Since the number of digits is 2, which is less than 10, we do not have to abbreviate it further.\n Thus, the final representation is \"24e0\".\n \n Example 2:\n \n >>> abbreviateProduct(left = 2, right = 11)\n >>> \"399168e2\"\n Explanation: The product is 39916800.\n There are 2 trailing zeros, which we remove to get 399168. The abbreviation will end with \"e2\".\n The number of digits after removing the trailing zeros is 6, so we do not abbreviate it further.\n Hence, the abbreviated product is \"399168e2\".\n \n Example 3:\n \n >>> abbreviateProduct(left = 371, right = 375)\n >>> \"7219856259e3\"\n Explanation: The product is 7219856259000.\n \"\"\"\n"}
{"task_id": "a-number-after-a-double-reversal", "prompt": "def isSameAfterReversals(num: int) -> bool:\n \"\"\"\n Reversing an integer means to reverse all its digits.\n \n For example, reversing 2021 gives 1202. Reversing 12300 gives 321 as the leading zeros are not retained.\n \n Given an integer num, reverse num to get reversed1, then reverse reversed1 to get reversed2. Return true if reversed2 equals num. Otherwise return false.\n \n Example 1:\n \n >>> isSameAfterReversals(num = 526)\n >>> true\n Explanation: Reverse num to get 625, then reverse 625 to get 526, which equals num.\n \n Example 2:\n \n >>> isSameAfterReversals(num = 1800)\n >>> false\n Explanation: Reverse num to get 81, then reverse 81 to get 18, which does not equal num.\n \n Example 3:\n \n >>> isSameAfterReversals(num = 0)\n >>> true\n Explanation: Reverse num to get 0, then reverse 0 to get 0, which equals num.\n \"\"\"\n"}
{"task_id": "execution-of-all-suffix-instructions-staying-in-a-grid", "prompt": "def executeInstructions(n: int, startPos: List[int], s: str) -> List[int]:\n \"\"\"\n There is an n x n grid, with the top-left cell at (0, 0) and the bottom-right cell at (n - 1, n - 1). You are given the integer n and an integer array startPos where startPos = [startrow, startcol] indicates that a robot is initially at cell (startrow, startcol).\n You are also given a 0-indexed string s of length m where s[i] is the ith instruction for the robot: 'L' (move left), 'R' (move right), 'U' (move up), and 'D' (move down).\n The robot can begin executing from any ith instruction in s. It executes the instructions one by one towards the end of s but it stops if either of these conditions is met:\n \n The next instruction will move the robot off the grid.\n There are no more instructions left to execute.\n \n Return an array answer of length m where answer[i] is the number of instructions the robot can execute if the robot begins executing from the ith instruction in s.\n \n Example 1:\n \n \n >>> executeInstructions(n = 3, startPos = [0,1], s = \"RRDDLU\")\n >>> [1,5,4,3,1,0]\n Explanation: Starting from startPos and beginning execution from the ith instruction:\n - 0th: \"RRDDLU\". Only one instruction \"R\" can be executed before it moves off the grid.\n - 1st: \"RDDLU\". All five instructions can be executed while it stays in the grid and ends at (1, 1).\n - 2nd: \"DDLU\". All four instructions can be executed while it stays in the grid and ends at (1, 0).\n - 3rd: \"DLU\". All three instructions can be executed while it stays in the grid and ends at (0, 0).\n - 4th: \"LU\". Only one instruction \"L\" can be executed before it moves off the grid.\n - 5th: \"U\". If moving up, it would move off the grid.\n \n Example 2:\n \n \n >>> executeInstructions(n = 2, startPos = [1,1], s = \"LURD\")\n >>> [4,1,0,0]\n Explanation:\n - 0th: \"LURD\".\n - 1st: \"URD\".\n - 2nd: \"RD\".\n - 3rd: \"D\".\n \n Example 3:\n \n \n >>> executeInstructions(n = 1, startPos = [0,0], s = \"LRUD\")\n >>> [0,0,0,0]\n Explanation: No matter which instruction the robot begins execution from, it would move off the grid.\n \"\"\"\n"}
{"task_id": "intervals-between-identical-elements", "prompt": "def getDistances(arr: List[int]) -> List[int]:\n \"\"\"\n You are given a 0-indexed array of n integers arr.\n The interval between two elements in arr is defined as the absolute difference between their indices. More formally, the interval between arr[i] and arr[j] is |i - j|.\n Return an array intervals of length n where intervals[i] is the sum of intervals between arr[i] and each element in arr with the same value as arr[i].\n Note: |x| is the absolute value of x.\n \n Example 1:\n \n >>> getDistances(arr = [2,1,3,1,2,3,3])\n >>> [4,2,7,2,4,4,5]\n Explanation:\n - Index 0: Another 2 is found at index 4. |0 - 4| = 4\n - Index 1: Another 1 is found at index 3. |1 - 3| = 2\n - Index 2: Two more 3s are found at indices 5 and 6. |2 - 5| + |2 - 6| = 7\n - Index 3: Another 1 is found at index 1. |3 - 1| = 2\n - Index 4: Another 2 is found at index 0. |4 - 0| = 4\n - Index 5: Two more 3s are found at indices 2 and 6. |5 - 2| + |5 - 6| = 4\n - Index 6: Two more 3s are found at indices 2 and 5. |6 - 2| + |6 - 5| = 5\n \n Example 2:\n \n >>> getDistances(arr = [10,5,10,10])\n >>> [5,0,3,4]\n Explanation:\n - Index 0: Two more 10s are found at indices 2 and 3. |0 - 2| + |0 - 3| = 5\n - Index 1: There is only one 5 in the array, so its sum of intervals to identical elements is 0.\n - Index 2: Two more 10s are found at indices 0 and 3. |2 - 0| + |2 - 3| = 3\n - Index 3: Two more 10s are found at indices 0 and 2. |3 - 0| + |3 - 2| = 4\n \"\"\"\n"}
{"task_id": "recover-the-original-array", "prompt": "def recoverArray(nums: List[int]) -> List[int]:\n \"\"\"\n Alice had a 0-indexed array arr consisting of n positive integers. She chose an arbitrary positive integer k and created two new 0-indexed integer arrays lower and higher in the following manner:\n \n lower[i] = arr[i] - k, for every index i where 0 <= i < n\n higher[i] = arr[i] + k, for every index i where 0 <= i < n\n \n Unfortunately, Alice lost all three arrays. However, she remembers the integers that were present in the arrays lower and higher, but not the array each integer belonged to. Help Alice and recover the original array.\n Given an array nums consisting of 2n integers, where exactly n of the integers were present in lower and the remaining in higher, return the original array arr. In case the answer is not unique, return any valid array.\n Note: The test cases are generated such that there exists at least one valid array arr.\n \n Example 1:\n \n >>> recoverArray(nums = [2,10,6,4,8,12])\n >>> [3,7,11]\n Explanation:\n If arr = [3,7,11] and k = 1, we get lower = [2,6,10] and higher = [4,8,12].\n Combining lower and higher gives us [2,6,10,4,8,12], which is a permutation of nums.\n Another valid possibility is that arr = [5,7,9] and k = 3. In that case, lower = [2,4,6] and higher = [8,10,12].\n \n Example 2:\n \n >>> recoverArray(nums = [1,1,3,3])\n >>> [2,2]\n Explanation:\n If arr = [2,2] and k = 1, we get lower = [1,1] and higher = [3,3].\n Combining lower and higher gives us [1,1,3,3], which is equal to nums.\n Note that arr cannot be [1,3] because in that case, the only possible way to obtain [1,1,3,3] is with k = 0.\n This is invalid since k must be positive.\n \n Example 3:\n \n >>> recoverArray(nums = [5,435])\n >>> [220]\n Explanation:\n The only possible combination is arr = [220] and k = 215. Using them, we get lower = [5] and higher = [435].\n \"\"\"\n"}
{"task_id": "minimum-operations-to-remove-adjacent-ones-in-matrix", "prompt": "def minimumOperations(grid: List[List[int]]) -> int:\n \"\"\"\n You are given a 0-indexed binary matrix grid. In one operation, you can flip any 1 in grid to be 0.\n A binary matrix is well-isolated if there is no 1 in the matrix that is 4-directionally connected (i.e., horizontal and vertical) to another 1.\n Return the minimum number of operations to make grid well-isolated.\n \n Example 1:\n \n \n >>> minimumOperations(grid = [[1,1,0],[0,1,1],[1,1,1]])\n >>> 3\n Explanation: Use 3 operations to change grid[0][1], grid[1][2], and grid[2][1] to 0.\n After, no more 1's are 4-directionally connected and grid is well-isolated.\n \n Example 2:\n \n \n >>> minimumOperations(grid = [[0,0,0],[0,0,0],[0,0,0]])\n >>> 0\n Explanation: There are no 1's in grid and it is well-isolated.\n No operations were done so return 0.\n \n Example 3:\n \n \n >>> minimumOperations(grid = [[0,1],[1,0]])\n >>> 0\n Explanation: None of the 1's are 4-directionally connected and grid is well-isolated.\n No operations were done so return 0.\n \"\"\"\n"}
{"task_id": "check-if-all-as-appears-before-all-bs", "prompt": "def checkString(s: str) -> bool:\n \"\"\"\n Given a string s consisting of only the characters 'a' and 'b', return true if every 'a' appears before every 'b' in the string. Otherwise, return false.\n \n Example 1:\n \n >>> checkString(s = \"aaabbb\")\n >>> true\n Explanation:\n The 'a's are at indices 0, 1, and 2, while the 'b's are at indices 3, 4, and 5.\n Hence, every 'a' appears before every 'b' and we return true.\n \n Example 2:\n \n >>> checkString(s = \"abab\")\n >>> false\n Explanation:\n There is an 'a' at index 2 and a 'b' at index 1.\n Hence, not every 'a' appears before every 'b' and we return false.\n \n Example 3:\n \n >>> checkString(s = \"bbb\")\n >>> true\n Explanation:\n There are no 'a's, hence, every 'a' appears before every 'b' and we return true.\n \"\"\"\n"}
{"task_id": "number-of-laser-beams-in-a-bank", "prompt": "def numberOfBeams(bank: List[str]) -> int:\n \"\"\"\n Anti-theft security devices are activated inside a bank. You are given a 0-indexed binary string array bank representing the floor plan of the bank, which is an m x n 2D matrix. bank[i] represents the ith row, consisting of '0's and '1's. '0' means the cell is empty, while'1' means the cell has a security device.\n There is one laser beam between any two security devices if both conditions are met:\n \n The two devices are located on two different rows: r1 and r2, where r1 < r2.\n For each row i where r1 < i < r2, there are no security devices in the ith row.\n \n Laser beams are independent, i.e., one beam does not interfere nor join with another.\n Return the total number of laser beams in the bank.\n \n Example 1:\n \n \n >>> numberOfBeams(bank = [\"011001\",\"000000\",\"010100\",\"001000\"])\n >>> 8\n Explanation: Between each of the following device pairs, there is one beam. In total, there are 8 beams:\n * bank[0][1] -- bank[2][1]\n * bank[0][1] -- bank[2][3]\n * bank[0][2] -- bank[2][1]\n * bank[0][2] -- bank[2][3]\n * bank[0][5] -- bank[2][1]\n * bank[0][5] -- bank[2][3]\n * bank[2][1] -- bank[3][2]\n * bank[2][3] -- bank[3][2]\n Note that there is no beam between any device on the 0th row with any on the 3rd row.\n This is because the 2nd row contains security devices, which breaks the second condition.\n \n Example 2:\n \n \n >>> numberOfBeams(bank = [\"000\",\"111\",\"000\"])\n >>> 0\n Explanation: There does not exist two devices located on two different rows.\n \"\"\"\n"}
{"task_id": "destroying-asteroids", "prompt": "def asteroidsDestroyed(mass: int, asteroids: List[int]) -> bool:\n \"\"\"\n You are given an integer mass, which represents the original mass of a planet. You are further given an integer array asteroids, where asteroids[i] is the mass of the ith asteroid.\n You can arrange for the planet to collide with the asteroids in any arbitrary order. If the mass of the planet is greater than or equal to the mass of the asteroid, the asteroid is destroyed and the planet gains the mass of the asteroid. Otherwise, the planet is destroyed.\n Return true if all asteroids can be destroyed. Otherwise, return false.\n \n Example 1:\n \n >>> asteroidsDestroyed(mass = 10, asteroids = [3,9,19,5,21])\n >>> true\n Explanation: One way to order the asteroids is [9,19,5,3,21]:\n - The planet collides with the asteroid with a mass of 9. New planet mass: 10 + 9 = 19\n - The planet collides with the asteroid with a mass of 19. New planet mass: 19 + 19 = 38\n - The planet collides with the asteroid with a mass of 5. New planet mass: 38 + 5 = 43\n - The planet collides with the asteroid with a mass of 3. New planet mass: 43 + 3 = 46\n - The planet collides with the asteroid with a mass of 21. New planet mass: 46 + 21 = 67\n All asteroids are destroyed.\n \n Example 2:\n \n >>> asteroidsDestroyed(mass = 5, asteroids = [4,9,23,4])\n >>> false\n Explanation:\n The planet cannot ever gain enough mass to destroy the asteroid with a mass of 23.\n After the planet destroys the other asteroids, it will have a mass of 5 + 4 + 9 + 4 = 22.\n This is less than 23, so a collision would not destroy the last asteroid.\n \"\"\"\n"}
{"task_id": "maximum-employees-to-be-invited-to-a-meeting", "prompt": "def maximumInvitations(favorite: List[int]) -> int:\n \"\"\"\n A company is organizing a meeting and has a list of n employees, waiting to be invited. They have arranged for a large circular table, capable of seating any number of employees.\n The employees are numbered from 0 to n - 1. Each employee has a favorite person and they will attend the meeting only if they can sit next to their favorite person at the table. The favorite person of an employee is not themself.\n Given a 0-indexed integer array favorite, where favorite[i] denotes the favorite person of the ith employee, return the maximum number of employees that can be invited to the meeting.\n \n Example 1:\n \n \n >>> maximumInvitations(favorite = [2,2,1,2])\n >>> 3\n Explanation:\n The above figure shows how the company can invite employees 0, 1, and 2, and seat them at the round table.\n All employees cannot be invited because employee 2 cannot sit beside employees 0, 1, and 3, simultaneously.\n Note that the company can also invite employees 1, 2, and 3, and give them their desired seats.\n The maximum number of employees that can be invited to the meeting is 3.\n \n Example 2:\n \n >>> maximumInvitations(favorite = [1,2,0])\n >>> 3\n Explanation:\n Each employee is the favorite person of at least one other employee, and the only way the company can invite them is if they invite every employee.\n The seating arrangement will be the same as that in the figure given in example 1:\n - Employee 0 will sit between employees 2 and 1.\n - Employee 1 will sit between employees 0 and 2.\n - Employee 2 will sit between employees 1 and 0.\n The maximum number of employees that can be invited to the meeting is 3.\n \n Example 3:\n \n \n >>> maximumInvitations(favorite = [3,0,1,4,1])\n >>> 4\n Explanation:\n The above figure shows how the company will invite employees 0, 1, 3, and 4, and seat them at the round table.\n Employee 2 cannot be invited because the two spots next to their favorite employee 1 are taken.\n So the company leaves them out of the meeting.\n The maximum number of employees that can be invited to the meeting is 4.\n \"\"\"\n"}
{"task_id": "remove-all-ones-with-row-and-column-flips", "prompt": "def removeOnes(grid: List[List[int]]) -> bool:\n \"\"\"\n You are given an m x n binary matrix grid.\n In one operation, you can choose any row or column and flip each value in that row or column (i.e., changing all 0's to 1's, and all 1's to 0's).\n Return true if it is possible to remove all 1's from grid using any number of operations or false otherwise.\n \n Example 1:\n \n \n >>> removeOnes(grid = [[0,1,0],[1,0,1],[0,1,0]])\n >>> true\n Explanation: One possible way to remove all 1's from grid is to:\n - Flip the middle row\n - Flip the middle column\n \n Example 2:\n \n \n >>> removeOnes(grid = [[1,1,0],[0,0,0],[0,0,0]])\n >>> false\n Explanation: It is impossible to remove all 1's from grid.\n \n Example 3:\n \n \n >>> removeOnes(grid = [[0]])\n >>> true\n Explanation: There are no 1's in grid.\n \"\"\"\n"}
{"task_id": "capitalize-the-title", "prompt": "def capitalizeTitle(title: str) -> str:\n \"\"\"\n You are given a string title consisting of one or more words separated by a single space, where each word consists of English letters. Capitalize the string by changing the capitalization of each word such that:\n \n If the length of the word is 1 or 2 letters, change all letters to lowercase.\n Otherwise, change the first letter to uppercase and the remaining letters to lowercase.\n \n Return the capitalized title.\n \n Example 1:\n \n >>> capitalizeTitle(title = \"capiTalIze tHe titLe\")\n >>> \"Capitalize The Title\"\n Explanation:\n Since all the words have a length of at least 3, the first letter of each word is uppercase, and the remaining letters are lowercase.\n \n Example 2:\n \n >>> capitalizeTitle(title = \"First leTTeR of EACH Word\")\n >>> \"First Letter of Each Word\"\n Explanation:\n The word \"of\" has length 2, so it is all lowercase.\n The remaining words have a length of at least 3, so the first letter of each remaining word is uppercase, and the remaining letters are lowercase.\n \n Example 3:\n \n >>> capitalizeTitle(title = \"i lOve leetcode\")\n >>> \"i Love Leetcode\"\n Explanation:\n The word \"i\" has length 1, so it is lowercase.\n The remaining words have a length of at least 3, so the first letter of each remaining word is uppercase, and the remaining letters are lowercase.\n \"\"\"\n"}
{"task_id": "maximum-twin-sum-of-a-linked-list", "prompt": "# class ListNode:\n# def __init__(val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution:\n def pairSum(head: Optional[ListNode]) -> int:\n \"\"\"\n In a linked list of size n, where n is even, the ith node (0-indexed) of the linked list is known as the twin of the (n-1-i)th node, if 0 <= i <= (n / 2) - 1.\n \n For example, if n = 4, then node 0 is the twin of node 3, and node 1 is the twin of node 2. These are the only nodes with twins for n = 4.\n \n The twin sum is defined as the sum of a node and its twin.\n Given the head of a linked list with even length, return the maximum twin sum of the linked list.\n \n Example 1:\n \n \n >>> __init__(head = [5,4,2,1])\n >>> 6\n Explanation:\n Nodes 0 and 1 are the twins of nodes 3 and 2, respectively. All have twin sum = 6.\n There are no other nodes with twins in the linked list.\n Thus, the maximum twin sum of the linked list is 6.\n \n Example 2:\n \n \n >>> __init__(head = [4,2,2,3])\n >>> 7\n Explanation:\n The nodes with twins present in this linked list are:\n - Node 0 is the twin of node 3 having a twin sum of 4 + 3 = 7.\n - Node 1 is the twin of node 2 having a twin sum of 2 + 2 = 4.\n Thus, the maximum twin sum of the linked list is max(7, 4) = 7.\n \n Example 3:\n \n \n >>> __init__(head = [1,100000])\n >>> 100001\n Explanation:\n There is only one node with a twin in the linked list having twin sum of 1 + 100000 = 100001.\n \"\"\"\n"}
{"task_id": "longest-palindrome-by-concatenating-two-letter-words", "prompt": "def longestPalindrome(words: List[str]) -> int:\n \"\"\"\n You are given an array of strings words. Each element of words consists of two lowercase English letters.\n Create the longest possible palindrome by selecting some elements from words and concatenating them in any order. Each element can be selected at most once.\n Return the length of the longest palindrome that you can create. If it is impossible to create any palindrome, return 0.\n A palindrome is a string that reads the same forward and backward.\n \n Example 1:\n \n >>> longestPalindrome(words = [\"lc\",\"cl\",\"gg\"])\n >>> 6\n Explanation: One longest palindrome is \"lc\" + \"gg\" + \"cl\" = \"lcggcl\", of length 6.\n Note that \"clgglc\" is another longest palindrome that can be created.\n \n Example 2:\n \n >>> longestPalindrome(words = [\"ab\",\"ty\",\"yt\",\"lc\",\"cl\",\"ab\"])\n >>> 8\n Explanation: One longest palindrome is \"ty\" + \"lc\" + \"cl\" + \"yt\" = \"tylcclyt\", of length 8.\n Note that \"lcyttycl\" is another longest palindrome that can be created.\n \n Example 3:\n \n >>> longestPalindrome(words = [\"cc\",\"ll\",\"xx\"])\n >>> 2\n Explanation: One longest palindrome is \"cc\", of length 2.\n Note that \"ll\" is another longest palindrome that can be created, and so is \"xx\".\n \"\"\"\n"}
{"task_id": "stamping-the-grid", "prompt": "def possibleToStamp(grid: List[List[int]], stampHeight: int, stampWidth: int) -> bool:\n \"\"\"\n You are given an m x n binary matrix grid where each cell is either 0 (empty) or 1 (occupied).\n You are then given stamps of size stampHeight x stampWidth. We want to fit the stamps such that they follow the given restrictions and requirements:\n \n Cover all the empty cells.\n Do not cover any of the occupied cells.\n We can put as many stamps as we want.\n Stamps can overlap with each other.\n Stamps are not allowed to be rotated.\n Stamps must stay completely inside the grid.\n \n Return true if it is possible to fit the stamps while following the given restrictions and requirements. Otherwise, return false.\n \n Example 1:\n \n \n >>> possibleToStamp(grid = [[1,0,0,0],[1,0,0,0],[1,0,0,0],[1,0,0,0],[1,0,0,0]], stampHeight = 4, stampWidth = 3)\n >>> true\n Explanation: We have two overlapping stamps (labeled 1 and 2 in the image) that are able to cover all the empty cells.\n \n Example 2:\n \n \n >>> possibleToStamp(grid = [[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]], stampHeight = 2, stampWidth = 2)\n >>> false\n Explanation: There is no way to fit the stamps onto all the empty cells without the stamps going outside the grid.\n \"\"\"\n"}
{"task_id": "check-if-every-row-and-column-contains-all-numbers", "prompt": "def checkValid(matrix: List[List[int]]) -> bool:\n \"\"\"\n An n x n matrix is valid if every row and every column contains all the integers from 1 to n (inclusive).\n Given an n x n integer matrix matrix, return true if the matrix is valid. Otherwise, return false.\n \n Example 1:\n \n \n >>> checkValid(matrix = [[1,2,3],[3,1,2],[2,3,1]])\n >>> true\n Explanation: In this case, n = 3, and every row and column contains the numbers 1, 2, and 3.\n Hence, we return true.\n \n Example 2:\n \n \n >>> checkValid(matrix = [[1,1,1],[1,2,3],[1,2,3]])\n >>> false\n Explanation: In this case, n = 3, but the first row and the first column do not contain the numbers 2 or 3.\n Hence, we return false.\n \"\"\"\n"}
{"task_id": "minimum-swaps-to-group-all-1s-together-ii", "prompt": "def minSwaps(nums: List[int]) -> int:\n \"\"\"\n A swap is defined as taking two distinct positions in an array and swapping the values in them.\n A circular array is defined as an array where we consider the first element and the last element to be adjacent.\n Given a binary circular array nums, return the minimum number of swaps required to group all 1's present in the array together at any location.\n \n Example 1:\n \n >>> minSwaps(nums = [0,1,0,1,1,0,0])\n >>> 1\n Explanation: Here are a few of the ways to group all the 1's together:\n [0,0,1,1,1,0,0] using 1 swap.\n [0,1,1,1,0,0,0] using 1 swap.\n [1,1,0,0,0,0,1] using 2 swaps (using the circular property of the array).\n There is no way to group all 1's together with 0 swaps.\n Thus, the minimum number of swaps required is 1.\n \n Example 2:\n \n >>> minSwaps(nums = [0,1,1,1,0,0,1,1,0])\n >>> 2\n Explanation: Here are a few of the ways to group all the 1's together:\n [1,1,1,0,0,0,0,1,1] using 2 swaps (using the circular property of the array).\n [1,1,1,1,1,0,0,0,0] using 2 swaps.\n There is no way to group all 1's together with 0 or 1 swaps.\n Thus, the minimum number of swaps required is 2.\n \n Example 3:\n \n >>> minSwaps(nums = [1,1,0,0,1])\n >>> 0\n Explanation: All the 1's are already grouped together due to the circular property of the array.\n Thus, the minimum number of swaps required is 0.\n \"\"\"\n"}
{"task_id": "count-words-obtained-after-adding-a-letter", "prompt": "def wordCount(startWords: List[str], targetWords: List[str]) -> int:\n \"\"\"\n You are given two 0-indexed arrays of strings startWords and targetWords. Each string consists of lowercase English letters only.\n For each string in targetWords, check if it is possible to choose a string from startWords and perform a conversion operation on it to be equal to that from targetWords.\n The conversion operation is described in the following two steps:\n \n Append any lowercase letter that is not present in the string to its end.\n \n \n For example, if the string is \"abc\", the letters 'd', 'e', or 'y' can be added to it, but not 'a'. If 'd' is added, the resulting string will be \"abcd\".\n \n \n Rearrange the letters of the new string in any arbitrary order.\n \n For example, \"abcd\" can be rearranged to \"acbd\", \"bacd\", \"cbda\", and so on. Note that it can also be rearranged to \"abcd\" itself.\n \n \n \n Return the number of strings in targetWords that can be obtained by performing the operations on any string of startWords.\n Note that you will only be verifying if the string in targetWords can be obtained from a string in startWords by performing the operations. The strings in startWords do not actually change during this process.\n \n Example 1:\n \n >>> wordCount(startWords = [\"ant\",\"act\",\"tack\"], targetWords = [\"tack\",\"act\",\"acti\"])\n >>> 2\n Explanation:\n - In order to form targetWords[0] = \"tack\", we use startWords[1] = \"act\", append 'k' to it, and rearrange \"actk\" to \"tack\".\n - There is no string in startWords that can be used to obtain targetWords[1] = \"act\".\n Note that \"act\" does exist in startWords, but we must append one letter to the string before rearranging it.\n - In order to form targetWords[2] = \"acti\", we use startWords[1] = \"act\", append 'i' to it, and rearrange \"acti\" to \"acti\" itself.\n \n Example 2:\n \n >>> wordCount(startWords = [\"ab\",\"a\"], targetWords = [\"abc\",\"abcd\"])\n >>> 1\n Explanation:\n - In order to form targetWords[0] = \"abc\", we use startWords[0] = \"ab\", add 'c' to it, and rearrange it to \"abc\".\n - There is no string in startWords that can be used to obtain targetWords[1] = \"abcd\".\n \"\"\"\n"}
{"task_id": "earliest-possible-day-of-full-bloom", "prompt": "def earliestFullBloom(plantTime: List[int], growTime: List[int]) -> int:\n \"\"\"\n You have n flower seeds. Every seed must be planted first before it can begin to grow, then bloom. Planting a seed takes time and so does the growth of a seed. You are given two 0-indexed integer arrays plantTime and growTime, of length n each:\n \n plantTime[i] is the number of full days it takes you to plant the ith seed. Every day, you can work on planting exactly one seed. You do not have to work on planting the same seed on consecutive days, but the planting of a seed is not complete until you have worked plantTime[i] days on planting it in total.\n growTime[i] is the number of full days it takes the ith seed to grow after being completely planted. After the last day of its growth, the flower blooms and stays bloomed forever.\n \n From the beginning of day 0, you can plant the seeds in any order.\n Return the earliest possible day where all seeds are blooming.\n \n Example 1:\n \n \n >>> earliestFullBloom(plantTime = [1,4,3], growTime = [2,3,1])\n >>> 9\n Explanation: The grayed out pots represent planting days, colored pots represent growing days, and the flower represents the day it blooms.\n One optimal way is:\n On day 0, plant the 0th seed. The seed grows for 2 full days and blooms on day 3.\n On days 1, 2, 3, and 4, plant the 1st seed. The seed grows for 3 full days and blooms on day 8.\n On days 5, 6, and 7, plant the 2nd seed. The seed grows for 1 full day and blooms on day 9.\n Thus, on day 9, all the seeds are blooming.\n \n Example 2:\n \n \n >>> earliestFullBloom(plantTime = [1,2,3,2], growTime = [2,1,2,1])\n >>> 9\n Explanation: The grayed out pots represent planting days, colored pots represent growing days, and the flower represents the day it blooms.\n One optimal way is:\n On day 1, plant the 0th seed. The seed grows for 2 full days and blooms on day 4.\n On days 0 and 3, plant the 1st seed. The seed grows for 1 full day and blooms on day 5.\n On days 2, 4, and 5, plant the 2nd seed. The seed grows for 2 full days and blooms on day 8.\n On days 6 and 7, plant the 3rd seed. The seed grows for 1 full day and blooms on day 9.\n Thus, on day 9, all the seeds are blooming.\n \n Example 3:\n \n >>> earliestFullBloom(plantTime = [1], growTime = [1])\n >>> 2\n Explanation: On day 0, plant the 0th seed. The seed grows for 1 full day and blooms on day 2.\n Thus, on day 2, all the seeds are blooming.\n \"\"\"\n"}
{"task_id": "pour-water-between-buckets-to-make-water-levels-equal", "prompt": "def equalizeWater(buckets: List[int], loss: int) -> float:\n \"\"\"\n You have n buckets each containing some gallons of water in it, represented by a 0-indexed integer array buckets, where the ith bucket contains buckets[i] gallons of water. You are also given an integer loss.\n You want to make the amount of water in each bucket equal. You can pour any amount of water from one bucket to another bucket (not necessarily an integer). However, every time you pour k gallons of water, you spill loss percent of k.\n Return the maximum amount of water in each bucket after making the amount of water equal. Answers within 10-5 of the actual answer will be accepted.\n \n Example 1:\n \n >>> equalizeWater(buckets = [1,2,7], loss = 80)\n >>> 2.00000\n Explanation: Pour 5 gallons of water from buckets[2] to buckets[0].\n 5 * 80% = 4 gallons are spilled and buckets[0] only receives 5 - 4 = 1 gallon of water.\n All buckets have 2 gallons of water in them so return 2.\n \n Example 2:\n \n >>> equalizeWater(buckets = [2,4,6], loss = 50)\n >>> 3.50000\n Explanation: Pour 0.5 gallons of water from buckets[1] to buckets[0].\n 0.5 * 50% = 0.25 gallons are spilled and buckets[0] only receives 0.5 - 0.25 = 0.25 gallons of water.\n Now, buckets = [2.25, 3.5, 6].\n Pour 2.5 gallons of water from buckets[2] to buckets[0].\n 2.5 * 50% = 1.25 gallons are spilled and buckets[0] only receives 2.5 - 1.25 = 1.25 gallons of water.\n All buckets have 3.5 gallons of water in them so return 3.5.\n \n Example 3:\n \n >>> equalizeWater(buckets = [3,3,3,3], loss = 40)\n >>> 3.00000\n Explanation: All buckets already have the same amount of water in them.\n \"\"\"\n"}
{"task_id": "divide-a-string-into-groups-of-size-k", "prompt": "def divideString(s: str, k: int, fill: str) -> List[str]:\n \"\"\"\n A string s can be partitioned into groups of size k using the following procedure:\n \n The first group consists of the first k characters of the string, the second group consists of the next k characters of the string, and so on. Each element can be a part of exactly one group.\n For the last group, if the string does not have k characters remaining, a character fill is used to complete the group.\n \n Note that the partition is done so that after removing the fill character from the last group (if it exists) and concatenating all the groups in order, the resultant string should be s.\n Given the string s, the size of each group k and the character fill, return a string array denoting the composition of every group s has been divided into, using the above procedure.\n \n Example 1:\n \n >>> divideString(s = \"abcdefghi\", k = 3, fill = \"x\")\n >>> [\"abc\",\"def\",\"ghi\"]\n Explanation:\n The first 3 characters \"abc\" form the first group.\n The next 3 characters \"def\" form the second group.\n The last 3 characters \"ghi\" form the third group.\n Since all groups can be completely filled by characters from the string, we do not need to use fill.\n Thus, the groups formed are \"abc\", \"def\", and \"ghi\".\n \n Example 2:\n \n >>> divideString(s = \"abcdefghij\", k = 3, fill = \"x\")\n >>> [\"abc\",\"def\",\"ghi\",\"jxx\"]\n Explanation:\n Similar to the previous example, we are forming the first three groups \"abc\", \"def\", and \"ghi\".\n For the last group, we can only use the character 'j' from the string. To complete this group, we add 'x' twice.\n Thus, the 4 groups formed are \"abc\", \"def\", \"ghi\", and \"jxx\".\n \"\"\"\n"}
{"task_id": "minimum-moves-to-reach-target-score", "prompt": "def minMoves(target: int, maxDoubles: int) -> int:\n \"\"\"\n You are playing a game with integers. You start with the integer 1 and you want to reach the integer target.\n In one move, you can either:\n \n Increment the current integer by one (i.e., x = x + 1).\n Double the current integer (i.e., x = 2 * x).\n \n You can use the increment operation any number of times, however, you can only use the double operation at most maxDoubles times.\n Given the two integers target and maxDoubles, return the minimum number of moves needed to reach target starting with 1.\n \n Example 1:\n \n >>> minMoves(target = 5, maxDoubles = 0)\n >>> 4\n Explanation: Keep incrementing by 1 until you reach target.\n \n Example 2:\n \n >>> minMoves(target = 19, maxDoubles = 2)\n >>> 7\n Explanation: Initially, x = 1\n Increment 3 times so x = 4\n Double once so x = 8\n Increment once so x = 9\n Double again so x = 18\n Increment once so x = 19\n \n Example 3:\n \n >>> minMoves(target = 10, maxDoubles = 4)\n >>> 4\n Explanation: Initially, x = 1\n Increment once so x = 2\n Double once so x = 4\n Increment once so x = 5\n Double again so x = 10\n \"\"\"\n"}
{"task_id": "solving-questions-with-brainpower", "prompt": "def mostPoints(questions: List[List[int]]) -> int:\n \"\"\"\n You are given a 0-indexed 2D integer array questions where questions[i] = [pointsi, brainpoweri].\n The array describes the questions of an exam, where you have to process the questions in order (i.e., starting from question 0) and make a decision whether to solve or skip each question. Solving question i will earn you pointsi points but you will be unable to solve each of the next brainpoweri questions. If you skip question i, you get to make the decision on the next question.\n \n For example, given questions = [[3, 2], [4, 3], [4, 4], [2, 5]]:\n \n \n If question 0 is solved, you will earn 3 points but you will be unable to solve questions 1 and 2.\n If instead, question 0 is skipped and question 1 is solved, you will earn 4 points but you will be unable to solve questions 2 and 3.\n \n \n \n Return the maximum points you can earn for the exam.\n \n Example 1:\n \n >>> mostPoints(questions = [[3,2],[4,3],[4,4],[2,5]])\n >>> 5\n Explanation: The maximum points can be earned by solving questions 0 and 3.\n - Solve question 0: Earn 3 points, will be unable to solve the next 2 questions\n - Unable to solve questions 1 and 2\n - Solve question 3: Earn 2 points\n Total points earned: 3 + 2 = 5. There is no other way to earn 5 or more points.\n \n Example 2:\n \n >>> mostPoints(questions = [[1,1],[2,2],[3,3],[4,4],[5,5]])\n >>> 7\n Explanation: The maximum points can be earned by solving questions 1 and 4.\n - Skip question 0\n - Solve question 1: Earn 2 points, will be unable to solve the next 2 questions\n - Unable to solve questions 2 and 3\n - Solve question 4: Earn 5 points\n Total points earned: 2 + 5 = 7. There is no other way to earn 7 or more points.\n \"\"\"\n"}
{"task_id": "maximum-running-time-of-n-computers", "prompt": "def maxRunTime(n: int, batteries: List[int]) -> int:\n \"\"\"\n You have n computers. You are given the integer n and a 0-indexed integer array batteries where the ith battery can run a computer for batteries[i] minutes. You are interested in running all n computers simultaneously using the given batteries.\n Initially, you can insert at most one battery into each computer. After that and at any integer time moment, you can remove a battery from a computer and insert another battery any number of times. The inserted battery can be a totally new battery or a battery from another computer. You may assume that the removing and inserting processes take no time.\n Note that the batteries cannot be recharged.\n Return the maximum number of minutes you can run all the n computers simultaneously.\n \n Example 1:\n \n \n >>> maxRunTime(n = 2, batteries = [3,3,3])\n >>> 4\n Explanation:\n Initially, insert battery 0 into the first computer and battery 1 into the second computer.\n After two minutes, remove battery 1 from the second computer and insert battery 2 instead. Note that battery 1 can still run for one minute.\n At the end of the third minute, battery 0 is drained, and you need to remove it from the first computer and insert battery 1 instead.\n By the end of the fourth minute, battery 1 is also drained, and the first computer is no longer running.\n We can run the two computers simultaneously for at most 4 minutes, so we return 4.\n \n \n Example 2:\n \n \n >>> maxRunTime(n = 2, batteries = [1,1,1,1])\n >>> 2\n Explanation:\n Initially, insert battery 0 into the first computer and battery 2 into the second computer.\n After one minute, battery 0 and battery 2 are drained so you need to remove them and insert battery 1 into the first computer and battery 3 into the second computer.\n After another minute, battery 1 and battery 3 are also drained so the first and second computers are no longer running.\n We can run the two computers simultaneously for at most 2 minutes, so we return 2.\n \"\"\"\n"}
{"task_id": "choose-numbers-from-two-arrays-in-range", "prompt": "def countSubranges(nums1: List[int], nums2: List[int]) -> int:\n \"\"\"\n You are given two 0-indexed integer arrays nums1 and nums2 of length n.\n A range [l, r] (inclusive) where 0 <= l <= r < n is balanced if:\n \n For every i in the range [l, r], you pick either nums1[i] or nums2[i].\n The sum of the numbers you pick from nums1 equals to the sum of the numbers you pick from nums2 (the sum is considered to be 0 if you pick no numbers from an array).\n \n Two balanced ranges from [l1, r1] and [l2, r2] are considered to be different if at least one of the following is true:\n \n l1 != l2\n r1 != r2\n nums1[i] is picked in the first range, and nums2[i] is picked in the second range or vice versa for at least one i.\n \n Return the number of different ranges that are balanced. Since the answer may be very large, return it modulo 109 + 7.\n \n Example 1:\n \n >>> countSubranges(nums1 = [1,2,5], nums2 = [2,6,3])\n >>> 3\n Explanation: The balanced ranges are:\n - [0, 1] where we choose nums2[0], and nums1[1].\n The sum of the numbers chosen from nums1 equals the sum of the numbers chosen from nums2: 2 = 2.\n - [0, 2] where we choose nums1[0], nums2[1], and nums1[2].\n The sum of the numbers chosen from nums1 equals the sum of the numbers chosen from nums2: 1 + 5 = 6.\n - [0, 2] where we choose nums1[0], nums1[1], and nums2[2].\n The sum of the numbers chosen from nums1 equals the sum of the numbers chosen from nums2: 1 + 2 = 3.\n Note that the second and third balanced ranges are different.\n In the second balanced range, we choose nums2[1] and in the third balanced range, we choose nums1[1].\n \n Example 2:\n \n >>> countSubranges(nums1 = [0,1], nums2 = [1,0])\n >>> 4\n Explanation: The balanced ranges are:\n - [0, 0] where we choose nums1[0].\n The sum of the numbers chosen from nums1 equals the sum of the numbers chosen from nums2: 0 = 0.\n - [1, 1] where we choose nums2[1].\n The sum of the numbers chosen from nums1 equals the sum of the numbers chosen from nums2: 0 = 0.\n - [0, 1] where we choose nums1[0] and nums2[1].\n The sum of the numbers chosen from nums1 equals the sum of the numbers chosen from nums2: 0 = 0.\n - [0, 1] where we choose nums2[0] and nums1[1].\n The sum of the numbers chosen from nums1 equals the sum of the numbers chosen from nums2: 1 = 1.\n \"\"\"\n"}
{"task_id": "minimum-cost-of-buying-candies-with-discount", "prompt": "def minimumCost(cost: List[int]) -> int:\n \"\"\"\n A shop is selling candies at a discount. For every two candies sold, the shop gives a third candy for free.\n The customer can choose any candy to take away for free as long as the cost of the chosen candy is less than or equal to the minimum cost of the two candies bought.\n \n For example, if there are 4 candies with costs 1, 2, 3, and 4, and the customer buys candies with costs 2 and 3, they\u00a0can take the candy with cost 1 for free, but not the candy with cost 4.\n \n Given a 0-indexed integer array cost, where cost[i] denotes the cost of the ith candy, return the minimum cost of buying all the candies.\n \n Example 1:\n \n >>> minimumCost(cost = [1,2,3])\n >>> 5\n Explanation: We buy the candies with costs 2 and 3, and take the candy with cost 1 for free.\n The total cost of buying all candies is 2 + 3 = 5. This is the only way we can buy the candies.\n Note that we cannot buy candies with costs 1 and 3, and then take the candy with cost 2 for free.\n The cost of the free candy has to be less than or equal to the minimum cost of the purchased candies.\n \n Example 2:\n \n >>> minimumCost(cost = [6,5,7,9,2,2])\n >>> 23\n Explanation: The way in which we can get the minimum cost is described below:\n - Buy candies with costs 9 and 7\n - Take the candy with cost 6 for free\n - We buy candies with costs 5 and 2\n - Take the last remaining candy with cost 2 for free\n Hence, the minimum cost to buy all candies is 9 + 7 + 5 + 2 = 23.\n \n Example 3:\n \n >>> minimumCost(cost = [5,5])\n >>> 10\n Explanation: Since there are only 2 candies, we buy both of them. There is not a third candy we can take for free.\n Hence, the minimum cost to buy all candies is 5 + 5 = 10.\n \"\"\"\n"}
{"task_id": "count-the-hidden-sequences", "prompt": "def numberOfArrays(differences: List[int], lower: int, upper: int) -> int:\n \"\"\"\n You are given a 0-indexed array of n integers differences, which describes the differences between each pair of consecutive integers of a hidden sequence of length (n + 1). More formally, call the hidden sequence hidden, then we have that differences[i] = hidden[i + 1] - hidden[i].\n You are further given two integers lower and upper that describe the inclusive range of values [lower, upper] that the hidden sequence can contain.\n \n For example, given differences = [1, -3, 4], lower = 1, upper = 6, the hidden sequence is a sequence of length 4 whose elements are in between 1 and 6 (inclusive).\n \n \n [3, 4, 1, 5] and [4, 5, 2, 6] are possible hidden sequences.\n [5, 6, 3, 7] is not possible since it contains an element greater than 6.\n [1, 2, 3, 4] is not possible since the differences are not correct.\n \n \n \n Return the number of possible hidden sequences there are. If there are no possible sequences, return 0.\n \n Example 1:\n \n >>> numberOfArrays(differences = [1,-3,4], lower = 1, upper = 6)\n >>> 2\n Explanation: The possible hidden sequences are:\n - [3, 4, 1, 5]\n - [4, 5, 2, 6]\n Thus, we return 2.\n \n Example 2:\n \n >>> numberOfArrays(differences = [3,-4,5,1,-2], lower = -4, upper = 5)\n >>> 4\n Explanation: The possible hidden sequences are:\n - [-3, 0, -4, 1, 2, 0]\n - [-2, 1, -3, 2, 3, 1]\n - [-1, 2, -2, 3, 4, 2]\n - [0, 3, -1, 4, 5, 3]\n Thus, we return 4.\n \n Example 3:\n \n >>> numberOfArrays(differences = [4,-7,2], lower = 3, upper = 6)\n >>> 0\n Explanation: There are no possible hidden sequences. Thus, we return 0.\n \"\"\"\n"}
{"task_id": "k-highest-ranked-items-within-a-price-range", "prompt": "def highestRankedKItems(grid: List[List[int]], pricing: List[int], start: List[int], k: int) -> List[List[int]]:\n \"\"\"\n You are given a 0-indexed 2D integer array grid of size m x n that represents a map of the items in a shop. The integers in the grid represent the following:\n \n 0 represents a wall that you cannot pass through.\n 1 represents an empty cell that you can freely move to and from.\n All other positive integers represent the price of an item in that cell. You may also freely move to and from these item cells.\n \n It takes 1 step to travel between adjacent grid cells.\n You are also given integer arrays pricing and start where pricing = [low, high] and start = [row, col] indicates that you start at the position (row, col) and are interested only in items with a price in the range of [low, high] (inclusive). You are further given an integer k.\n You are interested in the positions of the k highest-ranked items whose prices are within the given price range. The rank is determined by the first of these criteria that is different:\n \n Distance, defined as the length of the shortest path from the start (shorter distance has a higher rank).\n Price (lower price has a higher rank, but it must be in the price range).\n The row number (smaller row number has a higher rank).\n The column number (smaller column number has a higher rank).\n \n Return the k highest-ranked items within the price range sorted by their rank (highest to lowest). If there are fewer than k reachable items within the price range, return all of them.\n \n Example 1:\n \n \n >>> highestRankedKItems(grid = [[1,2,0,1],[1,3,0,1],[0,2,5,1]], pricing = [2,5], start = [0,0], k = 3)\n >>> [[0,1],[1,1],[2,1]]\n Explanation: You start at (0,0).\n With a price range of [2,5], we can take items from (0,1), (1,1), (2,1) and (2,2).\n The ranks of these items are:\n - (0,1) with distance 1\n - (1,1) with distance 2\n - (2,1) with distance 3\n - (2,2) with distance 4\n Thus, the 3 highest ranked items in the price range are (0,1), (1,1), and (2,1).\n \n Example 2:\n \n \n >>> highestRankedKItems(grid = [[1,2,0,1],[1,3,3,1],[0,2,5,1]], pricing = [2,3], start = [2,3], k = 2)\n >>> [[2,1],[1,2]]\n Explanation: You start at (2,3).\n With a price range of [2,3], we can take items from (0,1), (1,1), (1,2) and (2,1).\n The ranks of these items are:\n - (2,1) with distance 2, price 2\n - (1,2) with distance 2, price 3\n - (1,1) with distance 3\n - (0,1) with distance 4\n Thus, the 2 highest ranked items in the price range are (2,1) and (1,2).\n \n Example 3:\n \n \n >>> highestRankedKItems(grid = [[1,1,1],[0,0,1],[2,3,4]], pricing = [2,3], start = [0,0], k = 3)\n >>> [[2,1],[2,0]]\n Explanation: You start at (0,0).\n With a price range of [2,3], we can take items from (2,0) and (2,1).\n The ranks of these items are:\n - (2,1) with distance 5\n - (2,0) with distance 6\n Thus, the 2 highest ranked items in the price range are (2,1) and (2,0).\n Note that k = 3 but there are only 2 reachable items within the price range.\n \"\"\"\n"}
{"task_id": "number-of-ways-to-divide-a-long-corridor", "prompt": "def numberOfWays(corridor: str) -> int:\n \"\"\"\n Along a long library corridor, there is a line of seats and decorative plants. You are given a 0-indexed string corridor of length n consisting of letters 'S' and 'P' where each 'S' represents a seat and each 'P' represents a plant.\n One room divider has already been installed to the left of index 0, and another to the right of index n - 1. Additional room dividers can be installed. For each position between indices i - 1 and i (1 <= i <= n - 1), at most one divider can be installed.\n Divide the corridor into non-overlapping sections, where each section has exactly two seats with any number of plants. There may be multiple ways to perform the division. Two ways are different if there is a position with a room divider installed in the first way but not in the second way.\n Return the number of ways to divide the corridor. Since the answer may be very large, return it modulo 109 + 7. If there is no way, return 0.\n \n Example 1:\n \n \n >>> numberOfWays(corridor = \"SSPPSPS\")\n >>> 3\n Explanation: There are 3 different ways to divide the corridor.\n The black bars in the above image indicate the two room dividers already installed.\n Note that in each of the ways, each section has exactly two seats.\n \n Example 2:\n \n \n >>> numberOfWays(corridor = \"PPSPSP\")\n >>> 1\n Explanation: There is only 1 way to divide the corridor, by not installing any additional dividers.\n Installing any would create some section that does not have exactly two seats.\n \n Example 3:\n \n \n >>> numberOfWays(corridor = \"S\")\n >>> 0\n Explanation: There is no way to divide the corridor because there will always be a section that does not have exactly two seats.\n \"\"\"\n"}
{"task_id": "count-elements-with-strictly-smaller-and-greater-elements", "prompt": "def countElements(nums: List[int]) -> int:\n \"\"\"\n Given an integer array nums, return the number of elements that have both a strictly smaller and a strictly greater element appear in nums.\n \n Example 1:\n \n >>> countElements(nums = [11,7,2,15])\n >>> 2\n Explanation: The element 7 has the element 2 strictly smaller than it and the element 11 strictly greater than it.\n Element 11 has element 7 strictly smaller than it and element 15 strictly greater than it.\n In total there are 2 elements having both a strictly smaller and a strictly greater element appear in nums.\n \n Example 2:\n \n >>> countElements(nums = [-3,3,3,90])\n >>> 2\n Explanation: The element 3 has the element -3 strictly smaller than it and the element 90 strictly greater than it.\n Since there are two elements with the value 3, in total there are 2 elements having both a strictly smaller and a strictly greater element appear in nums.\n \"\"\"\n"}
{"task_id": "rearrange-array-elements-by-sign", "prompt": "def rearrangeArray(nums: List[int]) -> List[int]:\n \"\"\"\n You are given a 0-indexed integer array nums of even length consisting of an equal number of positive and negative integers.\n You should return the array of nums such that the the array follows the given conditions:\n \n Every consecutive pair of integers have opposite signs.\n For all integers with the same sign, the order in which they were present in nums is preserved.\n The rearranged array begins with a positive integer.\n \n Return the modified array after rearranging the elements to satisfy the aforementioned conditions.\n \n Example 1:\n \n >>> rearrangeArray(nums = [3,1,-2,-5,2,-4])\n >>> [3,-2,1,-5,2,-4]\n Explanation:\n The positive integers in nums are [3,1,2]. The negative integers are [-2,-5,-4].\n The only possible way to rearrange them such that they satisfy all conditions is [3,-2,1,-5,2,-4].\n Other ways such as [1,-2,2,-5,3,-4], [3,1,2,-2,-5,-4], [-2,3,-5,1,-4,2] are incorrect because they do not satisfy one or more conditions.\n \n Example 2:\n \n >>> rearrangeArray(nums = [-1,1])\n >>> [1,-1]\n Explanation:\n 1 is the only positive integer and -1 the only negative integer in nums.\n So nums is rearranged to [1,-1].\n \"\"\"\n"}
{"task_id": "find-all-lonely-numbers-in-the-array", "prompt": "def findLonely(nums: List[int]) -> List[int]:\n \"\"\"\n You are given an integer array nums. A number x is lonely when it appears only once, and no adjacent numbers (i.e. x + 1 and x - 1) appear in the array.\n Return all lonely numbers in nums. You may return the answer in any order.\n \n Example 1:\n \n >>> findLonely(nums = [10,6,5,8])\n >>> [10,8]\n Explanation:\n - 10 is a lonely number since it appears exactly once and 9 and 11 does not appear in nums.\n - 8 is a lonely number since it appears exactly once and 7 and 9 does not appear in nums.\n - 5 is not a lonely number since 6 appears in nums and vice versa.\n Hence, the lonely numbers in nums are [10, 8].\n Note that [8, 10] may also be returned.\n \n Example 2:\n \n >>> findLonely(nums = [1,3,5,3])\n >>> [1,5]\n Explanation:\n - 1 is a lonely number since it appears exactly once and 0 and 2 does not appear in nums.\n - 5 is a lonely number since it appears exactly once and 4 and 6 does not appear in nums.\n - 3 is not a lonely number since it appears twice.\n Hence, the lonely numbers in nums are [1, 5].\n Note that [5, 1] may also be returned.\n \"\"\"\n"}
{"task_id": "maximum-good-people-based-on-statements", "prompt": "def maximumGood(statements: List[List[int]]) -> int:\n \"\"\"\n There are two types of persons:\n \n The good person: The person who always tells the truth.\n The bad person: The person who might tell the truth and might lie.\n \n You are given a 0-indexed 2D integer array statements of size n x n that represents the statements made by n people about each other. More specifically, statements[i][j] could be one of the following:\n \n 0 which represents a statement made by person i that person j is a bad person.\n 1 which represents a statement made by person i that person j is a good person.\n 2 represents that no statement is made by person i about person j.\n \n Additionally, no person ever makes a statement about themselves. Formally, we have that statements[i][i] = 2 for all 0 <= i < n.\n Return the maximum number of people who can be good based on the statements made by the n people.\n \n Example 1:\n \n \n >>> maximumGood(statements = [[2,1,2],[1,2,2],[2,0,2]])\n >>> 2\n Explanation: Each person makes a single statement.\n - Person 0 states that person 1 is good.\n - Person 1 states that person 0 is good.\n - Person 2 states that person 1 is bad.\n Let's take person 2 as the key.\n - Assuming that person 2 is a good person:\n - Based on the statement made by person 2, person 1 is a bad person.\n - Now we know for sure that person 1 is bad and person 2 is good.\n - Based on the statement made by person 1, and since person 1 is bad, they could be:\n - telling the truth. There will be a contradiction in this case and this assumption is invalid.\n - lying. In this case, person 0 is also a bad person and lied in their statement.\n - Following that person 2 is a good person, there will be only one good person in the group.\n - Assuming that person 2 is a bad person:\n - Based on the statement made by person 2, and since person 2 is bad, they could be:\n - telling the truth. Following this scenario, person 0 and 1 are both bad as explained before.\n - Following that person 2 is bad but told the truth, there will be no good persons in the group.\n - lying. In this case person 1 is a good person.\n - Since person 1 is a good person, person 0 is also a good person.\n - Following that person 2 is bad and lied, there will be two good persons in the group.\n We can see that at most 2 persons are good in the best case, so we return 2.\n Note that there is more than one way to arrive at this conclusion.\n \n Example 2:\n \n \n >>> maximumGood(statements = [[2,0],[0,2]])\n >>> 1\n Explanation: Each person makes a single statement.\n - Person 0 states that person 1 is bad.\n - Person 1 states that person 0 is bad.\n Let's take person 0 as the key.\n - Assuming that person 0 is a good person:\n - Based on the statement made by person 0, person 1 is a bad person and was lying.\n - Following that person 0 is a good person, there will be only one good person in the group.\n - Assuming that person 0 is a bad person:\n - Based on the statement made by person 0, and since person 0 is bad, they could be:\n - telling the truth. Following this scenario, person 0 and 1 are both bad.\n - Following that person 0 is bad but told the truth, there will be no good persons in the group.\n - lying. In this case person 1 is a good person.\n - Following that person 0 is bad and lied, there will be only one good person in the group.\n We can see that at most, one person is good in the best case, so we return 1.\n Note that there is more than one way to arrive at this conclusion.\n \"\"\"\n"}
{"task_id": "minimum-number-of-lines-to-cover-points", "prompt": "def minimumLines(points: List[List[int]]) -> int:\n \"\"\"\n You are given an array points where points[i] = [xi, yi] represents a point on an X-Y plane.\n Straight lines are going to be added to the X-Y plane, such that every point is covered by at least one line.\n Return the minimum number of straight lines needed to cover all the points.\n \n Example 1:\n \n \n >>> minimumLines(points = [[0,1],[2,3],[4,5],[4,3]])\n >>> 2\n Explanation: The minimum number of straight lines needed is two. One possible solution is to add:\n - One line connecting the point at (0, 1) to the point at (4, 5).\n - Another line connecting the point at (2, 3) to the point at (4, 3).\n \n Example 2:\n \n \n >>> minimumLines(points = [[0,2],[-2,-2],[1,4]])\n >>> 1\n Explanation: The minimum number of straight lines needed is one. The only solution is to add:\n - One line connecting the point at (-2, -2) to the point at (1, 4).\n \"\"\"\n"}
{"task_id": "keep-multiplying-found-values-by-two", "prompt": "def findFinalValue(nums: List[int], original: int) -> int:\n \"\"\"\n You are given an array of integers nums. You are also given an integer original which is the first number that needs to be searched for in nums.\n You then do the following steps:\n \n If original is found in nums, multiply it by two (i.e., set original = 2 * original).\n Otherwise, stop the process.\n Repeat this process with the new number as long as you keep finding the number.\n \n Return the final value of original.\n \n Example 1:\n \n >>> findFinalValue(nums = [5,3,6,1,12], original = 3)\n >>> 24\n Explanation:\n - 3 is found in nums. 3 is multiplied by 2 to obtain 6.\n - 6 is found in nums. 6 is multiplied by 2 to obtain 12.\n - 12 is found in nums. 12 is multiplied by 2 to obtain 24.\n - 24 is not found in nums. Thus, 24 is returned.\n \n Example 2:\n \n >>> findFinalValue(nums = [2,7,9], original = 4)\n >>> 4\n Explanation:\n - 4 is not found in nums. Thus, 4 is returned.\n \"\"\"\n"}
{"task_id": "all-divisions-with-the-highest-score-of-a-binary-array", "prompt": "def maxScoreIndices(nums: List[int]) -> List[int]:\n \"\"\"\n You are given a 0-indexed binary array nums of length n. nums can be divided at index i (where 0 <= i <= n) into two arrays (possibly empty) numsleft and numsright:\n \n numsleft has all the elements of nums between index 0 and i - 1 (inclusive), while numsright has all the elements of nums between index i and n - 1 (inclusive).\n If i == 0, numsleft is empty, while numsright has all the elements of nums.\n If i == n, numsleft has all the elements of nums, while numsright is empty.\n \n The division score of an index i is the sum of the number of 0's in numsleft and the number of 1's in numsright.\n Return all distinct indices that have the highest possible division score. You may return the answer in any order.\n \n Example 1:\n \n >>> maxScoreIndices(nums = [0,0,1,0])\n >>> [2,4]\n Explanation: Division at index\n - 0: numsleft is []. numsright is [0,0,1,0]. The score is 0 + 1 = 1.\n - 1: numsleft is [0]. numsright is [0,1,0]. The score is 1 + 1 = 2.\n - 2: numsleft is [0,0]. numsright is [1,0]. The score is 2 + 1 = 3.\n - 3: numsleft is [0,0,1]. numsright is [0]. The score is 2 + 0 = 2.\n - 4: numsleft is [0,0,1,0]. numsright is []. The score is 3 + 0 = 3.\n Indices 2 and 4 both have the highest possible division score 3.\n Note the answer [4,2] would also be accepted.\n Example 2:\n \n >>> maxScoreIndices(nums = [0,0,0])\n >>> [3]\n Explanation: Division at index\n - 0: numsleft is []. numsright is [0,0,0]. The score is 0 + 0 = 0.\n - 1: numsleft is [0]. numsright is [0,0]. The score is 1 + 0 = 1.\n - 2: numsleft is [0,0]. numsright is [0]. The score is 2 + 0 = 2.\n - 3: numsleft is [0,0,0]. numsright is []. The score is 3 + 0 = 3.\n Only index 3 has the highest possible division score 3.\n \n Example 3:\n \n >>> maxScoreIndices(nums = [1,1])\n >>> [0]\n Explanation: Division at index\n - 0: numsleft is []. numsright is [1,1]. The score is 0 + 2 = 2.\n - 1: numsleft is [1]. numsright is [1]. The score is 0 + 1 = 1.\n - 2: numsleft is [1,1]. numsright is []. The score is 0 + 0 = 0.\n Only index 0 has the highest possible division score 2.\n \"\"\"\n"}
{"task_id": "find-substring-with-given-hash-value", "prompt": "def subStrHash(s: str, power: int, modulo: int, k: int, hashValue: int) -> str:\n \"\"\"\n The hash of a 0-indexed string s of length k, given integers p and m, is computed using the following function:\n \n hash(s, p, m) = (val(s[0]) * p0 + val(s[1]) * p1 + ... + val(s[k-1]) * pk-1) mod m.\n \n Where val(s[i]) represents the index of s[i] in the alphabet from val('a') = 1 to val('z') = 26.\n You are given a string s and the integers power, modulo, k, and hashValue. Return sub, the first substring of s of length k such that hash(sub, power, modulo) == hashValue.\n The test cases will be generated such that an answer always exists.\n A substring is a contiguous non-empty sequence of characters within a string.\n \n Example 1:\n \n >>> subStrHash(s = \"leetcode\", power = 7, modulo = 20, k = 2, hashValue = 0)\n >>> \"ee\"\n Explanation: The hash of \"ee\" can be computed to be hash(\"ee\", 7, 20) = (5 * 1 + 5 * 7) mod 20 = 40 mod 20 = 0.\n \"ee\" is the first substring of length 2 with hashValue 0. Hence, we return \"ee\".\n \n Example 2:\n \n >>> subStrHash(s = \"fbxzaad\", power = 31, modulo = 100, k = 3, hashValue = 32)\n >>> \"fbx\"\n Explanation: The hash of \"fbx\" can be computed to be hash(\"fbx\", 31, 100) = (6 * 1 + 2 * 31 + 24 * 312) mod 100 = 23132 mod 100 = 32.\n The hash of \"bxz\" can be computed to be hash(\"bxz\", 31, 100) = (2 * 1 + 24 * 31 + 26 * 312) mod 100 = 25732 mod 100 = 32.\n \"fbx\" is the first substring of length 3 with hashValue 32. Hence, we return \"fbx\".\n Note that \"bxz\" also has a hash of 32 but it appears later than \"fbx\".\n \"\"\"\n"}
{"task_id": "groups-of-strings", "prompt": "def groupStrings(words: List[str]) -> List[int]:\n \"\"\"\n You are given a 0-indexed array of strings words. Each string consists of lowercase English letters only. No letter occurs more than once in any string of words.\n Two strings s1 and s2 are said to be connected if the set of letters of s2 can be obtained from the set of letters of s1 by any one of the following operations:\n \n Adding exactly one letter to the set of the letters of s1.\n Deleting exactly one letter from the set of the letters of s1.\n Replacing exactly one letter from the set of the letters of s1 with any letter, including itself.\n \n The array words can be divided into one or more non-intersecting groups. A string belongs to a group if any one of the following is true:\n \n It is connected to at least one other string of the group.\n It is the only string present in the group.\n \n Note that the strings in words should be grouped in such a manner that a string belonging to a group cannot be connected to a string present in any other group. It can be proved that such an arrangement is always unique.\n Return an array ans of size 2 where:\n \n ans[0] is the maximum number of groups words can be divided into, and\n ans[1] is the size of the largest group.\n \n \n Example 1:\n \n >>> groupStrings(words = [\"a\",\"b\",\"ab\",\"cde\"])\n >>> [2,3]\n Explanation:\n - words[0] can be used to obtain words[1] (by replacing 'a' with 'b'), and words[2] (by adding 'b'). So words[0] is connected to words[1] and words[2].\n - words[1] can be used to obtain words[0] (by replacing 'b' with 'a'), and words[2] (by adding 'a'). So words[1] is connected to words[0] and words[2].\n - words[2] can be used to obtain words[0] (by deleting 'b'), and words[1] (by deleting 'a'). So words[2] is connected to words[0] and words[1].\n - words[3] is not connected to any string in words.\n Thus, words can be divided into 2 groups [\"a\",\"b\",\"ab\"] and [\"cde\"]. The size of the largest group is 3.\n \n Example 2:\n \n >>> groupStrings(words = [\"a\",\"ab\",\"abc\"])\n >>> [1,3]\n Explanation:\n - words[0] is connected to words[1].\n - words[1] is connected to words[0] and words[2].\n - words[2] is connected to words[1].\n Since all strings are connected to each other, they should be grouped together.\n Thus, the size of the largest group is 3.\n \"\"\"\n"}
{"task_id": "amount-of-new-area-painted-each-day", "prompt": "def amountPainted(paint: List[List[int]]) -> List[int]:\n \"\"\"\n There is a long and thin painting that can be represented by a number line. You are given a 0-indexed 2D integer array paint of length n, where paint[i] = [starti, endi]. This means that on the ith day you need to paint the area between starti and endi.\n Painting the same area multiple times will create an uneven painting so you only want to paint each area of the painting at most once.\n Return an integer array worklog of length n, where worklog[i] is the amount of new area that you painted on the ith day.\n \n Example 1:\n \n \n >>> amountPainted(paint = [[1,4],[4,7],[5,8]])\n >>> [3,3,1]\n Explanation:\n On day 0, paint everything between 1 and 4.\n The amount of new area painted on day 0 is 4 - 1 = 3.\n On day 1, paint everything between 4 and 7.\n The amount of new area painted on day 1 is 7 - 4 = 3.\n On day 2, paint everything between 7 and 8.\n Everything between 5 and 7 was already painted on day 1.\n The amount of new area painted on day 2 is 8 - 7 = 1.\n \n Example 2:\n \n \n >>> amountPainted(paint = [[1,4],[5,8],[4,7]])\n >>> [3,3,1]\n Explanation:\n On day 0, paint everything between 1 and 4.\n The amount of new area painted on day 0 is 4 - 1 = 3.\n On day 1, paint everything between 5 and 8.\n The amount of new area painted on day 1 is 8 - 5 = 3.\n On day 2, paint everything between 4 and 5.\n Everything between 5 and 7 was already painted on day 1.\n The amount of new area painted on day 2 is 5 - 4 = 1.\n \n Example 3:\n \n \n >>> amountPainted(paint = [[1,5],[2,4]])\n >>> [4,0]\n Explanation:\n On day 0, paint everything between 1 and 5.\n The amount of new area painted on day 0 is 5 - 1 = 4.\n On day 1, paint nothing because everything between 2 and 4 was already painted on day 0.\n The amount of new area painted on day 1 is 0.\n \"\"\"\n"}
{"task_id": "minimum-sum-of-four-digit-number-after-splitting-digits", "prompt": "def minimumSum(num: int) -> int:\n \"\"\"\n You are given a positive integer num consisting of exactly four digits. Split num into two new integers new1 and new2 by using the digits found in num. Leading zeros are allowed in new1 and new2, and all the digits found in num must be used.\n \n For example, given num = 2932, you have the following digits: two 2's, one 9 and one 3. Some of the possible pairs [new1, new2] are [22, 93], [23, 92], [223, 9] and [2, 329].\n \n Return the minimum possible sum of new1 and new2.\n \n Example 1:\n \n >>> minimumSum(num = 2932)\n >>> 52\n Explanation: Some possible pairs [new1, new2] are [29, 23], [223, 9], etc.\n The minimum sum can be obtained by the pair [29, 23]: 29 + 23 = 52.\n \n Example 2:\n \n >>> minimumSum(num = 4009)\n >>> 13\n Explanation: Some possible pairs [new1, new2] are [0, 49], [490, 0], etc.\n The minimum sum can be obtained by the pair [4, 9]: 4 + 9 = 13.\n \"\"\"\n"}
{"task_id": "partition-array-according-to-given-pivot", "prompt": "def pivotArray(nums: List[int], pivot: int) -> List[int]:\n \"\"\"\n You are given a 0-indexed integer array nums and an integer pivot. Rearrange nums such that the following conditions are satisfied:\n \n Every element less than pivot appears before every element greater than pivot.\n Every element equal to pivot appears in between the elements less than and greater than pivot.\n The relative order of the elements less than pivot and the elements greater than pivot is maintained.\n \n More formally, consider every pi, pj where pi is the new position of the ith element and pj is the new position of the jth element. If i < j and both elements are smaller (or larger) than pivot, then pi < pj.\n \n \n \n Return nums after the rearrangement.\n \n Example 1:\n \n >>> pivotArray(nums = [9,12,5,10,14,3,10], pivot = 10)\n >>> [9,5,3,10,10,12,14]\n Explanation:\n The elements 9, 5, and 3 are less than the pivot so they are on the left side of the array.\n The elements 12 and 14 are greater than the pivot so they are on the right side of the array.\n The relative ordering of the elements less than and greater than pivot is also maintained. [9, 5, 3] and [12, 14] are the respective orderings.\n \n Example 2:\n \n >>> pivotArray(nums = [-3,4,3,2], pivot = 2)\n >>> [-3,2,4,3]\n Explanation:\n The element -3 is less than the pivot so it is on the left side of the array.\n The elements 4 and 3 are greater than the pivot so they are on the right side of the array.\n The relative ordering of the elements less than and greater than pivot is also maintained. [-3] and [4, 3] are the respective orderings.\n \"\"\"\n"}
{"task_id": "minimum-cost-to-set-cooking-time", "prompt": "def minCostSetTime(startAt: int, moveCost: int, pushCost: int, targetSeconds: int) -> int:\n \"\"\"\n A generic microwave supports cooking times for:\n \n at least 1 second.\n at most 99 minutes and 99 seconds.\n \n To set the cooking time, you push at most four digits. The microwave normalizes what you push as four digits by prepending zeroes. It interprets the first two digits as the minutes and the last two digits as the seconds. It then adds them up as the cooking time. For example,\n \n You push 9 5 4 (three digits). It is normalized as 0954 and interpreted as 9 minutes and 54 seconds.\n You push 0 0 0 8 (four digits). It is interpreted as 0 minutes and 8 seconds.\n You push 8 0 9 0. It is interpreted as 80 minutes and 90 seconds.\n You push 8 1 3 0. It is interpreted as 81 minutes and 30 seconds.\n \n You are given integers startAt, moveCost, pushCost, and targetSeconds. Initially, your finger is on the digit startAt. Moving the finger above any specific digit costs moveCost units of fatigue. Pushing the digit below the finger once costs pushCost units of fatigue.\n There can be multiple ways to set the microwave to cook for targetSeconds seconds but you are interested in the way with the minimum cost.\n Return the minimum cost to set targetSeconds seconds of cooking time.\n Remember that one minute consists of 60 seconds.\n \n Example 1:\n \n \n >>> minCostSetTime(startAt = 1, moveCost = 2, pushCost = 1, targetSeconds = 600)\n >>> 6\n Explanation: The following are the possible ways to set the cooking time.\n - 1 0 0 0, interpreted as 10 minutes and 0 seconds.\n \u00a0 The finger is already on digit 1, pushes 1 (with cost 1), moves to 0 (with cost 2), pushes 0 (with cost 1), pushes 0 (with cost 1), and pushes 0 (with cost 1).\n \u00a0 The cost is: 1 + 2 + 1 + 1 + 1 = 6. This is the minimum cost.\n - 0 9 6 0, interpreted as 9 minutes and 60 seconds. That is also 600 seconds.\n \u00a0 The finger moves to 0 (with cost 2), pushes 0 (with cost 1), moves to 9 (with cost 2), pushes 9 (with cost 1), moves to 6 (with cost 2), pushes 6 (with cost 1), moves to 0 (with cost 2), and pushes 0 (with cost 1).\n \u00a0 The cost is: 2 + 1 + 2 + 1 + 2 + 1 + 2 + 1 = 12.\n - 9 6 0, normalized as 0960 and interpreted as 9 minutes and 60 seconds.\n \u00a0 The finger moves to 9 (with cost 2), pushes 9 (with cost 1), moves to 6 (with cost 2), pushes 6 (with cost 1), moves to 0 (with cost 2), and pushes 0 (with cost 1).\n \u00a0 The cost is: 2 + 1 + 2 + 1 + 2 + 1 = 9.\n \n Example 2:\n \n \n >>> minCostSetTime(startAt = 0, moveCost = 1, pushCost = 2, targetSeconds = 76)\n >>> 6\n Explanation: The optimal way is to push two digits: 7 6, interpreted as 76 seconds.\n The finger moves to 7 (with cost 1), pushes 7 (with cost 2), moves to 6 (with cost 1), and pushes 6 (with cost 2). The total cost is: 1 + 2 + 1 + 2 = 6\n Note other possible ways are 0076, 076, 0116, and 116, but none of them produces the minimum cost.\n \"\"\"\n"}
{"task_id": "minimum-difference-in-sums-after-removal-of-elements", "prompt": "def minimumDifference(nums: List[int]) -> int:\n \"\"\"\n You are given a 0-indexed integer array nums consisting of 3 * n elements.\n You are allowed to remove any subsequence of elements of size exactly n from nums. The remaining 2 * n elements will be divided into two equal parts:\n \n The first n elements belonging to the first part and their sum is sumfirst.\n The next n elements belonging to the second part and their sum is sumsecond.\n \n The difference in sums of the two parts is denoted as sumfirst - sumsecond.\n \n For example, if sumfirst = 3 and sumsecond = 2, their difference is 1.\n Similarly, if sumfirst = 2 and sumsecond = 3, their difference is -1.\n \n Return the minimum difference possible between the sums of the two parts after the removal of n elements.\n \n Example 1:\n \n >>> minimumDifference(nums = [3,1,2])\n >>> -1\n Explanation: Here, nums has 3 elements, so n = 1.\n Thus we have to remove 1 element from nums and divide the array into two equal parts.\n - If we remove nums[0] = 3, the array will be [1,2]. The difference in sums of the two parts will be 1 - 2 = -1.\n - If we remove nums[1] = 1, the array will be [3,2]. The difference in sums of the two parts will be 3 - 2 = 1.\n - If we remove nums[2] = 2, the array will be [3,1]. The difference in sums of the two parts will be 3 - 1 = 2.\n The minimum difference between sums of the two parts is min(-1,1,2) = -1.\n \n Example 2:\n \n >>> minimumDifference(nums = [7,9,5,8,1,3])\n >>> 1\n Explanation: Here n = 2. So we must remove 2 elements and divide the remaining array into two parts containing two elements each.\n If we remove nums[2] = 5 and nums[3] = 8, the resultant array will be [7,9,1,3]. The difference in sums will be (7+9) - (1+3) = 12.\n To obtain the minimum difference, we should remove nums[1] = 9 and nums[4] = 1. The resultant array becomes [7,5,8,3]. The difference in sums of the two parts is (7+5) - (8+3) = 1.\n It can be shown that it is not possible to obtain a difference smaller than 1.\n \"\"\"\n"}
{"task_id": "sort-even-and-odd-indices-independently", "prompt": "def sortEvenOdd(nums: List[int]) -> List[int]:\n \"\"\"\n You are given a 0-indexed integer array nums. Rearrange the values of nums according to the following rules:\n \n Sort the values at odd indices of nums in non-increasing order.\n \n \n For example, if nums = [4,1,2,3] before this step, it becomes [4,3,2,1] after. The values at odd indices 1 and 3 are sorted in non-increasing order.\n \n \n Sort the values at even indices of nums in non-decreasing order.\n \n For example, if nums = [4,1,2,3] before this step, it becomes [2,1,4,3] after. The values at even indices 0 and 2 are sorted in non-decreasing order.\n \n \n \n Return the array formed after rearranging the values of nums.\n \n Example 1:\n \n >>> sortEvenOdd(nums = [4,1,2,3])\n >>> [2,3,4,1]\n Explanation:\n First, we sort the values present at odd indices (1 and 3) in non-increasing order.\n So, nums changes from [4,1,2,3] to [4,3,2,1].\n Next, we sort the values present at even indices (0 and 2) in non-decreasing order.\n So, nums changes from [4,1,2,3] to [2,3,4,1].\n Thus, the array formed after rearranging the values is [2,3,4,1].\n \n Example 2:\n \n >>> sortEvenOdd(nums = [2,1])\n >>> [2,1]\n Explanation:\n Since there is exactly one odd index and one even index, no rearrangement of values takes place.\n The resultant array formed is [2,1], which is the same as the initial array.\n \"\"\"\n"}
{"task_id": "smallest-value-of-the-rearranged-number", "prompt": "def smallestNumber(num: int) -> int:\n \"\"\"\n You are given an integer num. Rearrange the digits of num such that its value is minimized and it does not contain any leading zeros.\n Return the rearranged number with minimal value.\n Note that the sign of the number does not change after rearranging the digits.\n \n Example 1:\n \n >>> smallestNumber(num = 310)\n >>> 103\n Explanation: The possible arrangements for the digits of 310 are 013, 031, 103, 130, 301, 310.\n The arrangement with the smallest value that does not contain any leading zeros is 103.\n \n Example 2:\n \n >>> smallestNumber(num = -7605)\n >>> -7650\n Explanation: Some possible arrangements for the digits of -7605 are -7650, -6705, -5076, -0567.\n The arrangement with the smallest value that does not contain any leading zeros is -7650.\n \"\"\"\n"}
{"task_id": "minimum-time-to-remove-all-cars-containing-illegal-goods", "prompt": "def minimumTime(s: str) -> int:\n \"\"\"\n You are given a 0-indexed binary string s which represents a sequence of train cars. s[i] = '0' denotes that the ith car does not contain illegal goods and s[i] = '1' denotes that the ith car does contain illegal goods.\n As the train conductor, you would like to get rid of all the cars containing illegal goods. You can do any of the following three operations any number of times:\n \n Remove a train car from the left end (i.e., remove s[0]) which takes 1 unit of time.\n Remove a train car from the right end (i.e., remove s[s.length - 1]) which takes 1 unit of time.\n Remove a train car from anywhere in the sequence which takes 2 units of time.\n \n Return the minimum time to remove all the cars containing illegal goods.\n Note that an empty sequence of cars is considered to have no cars containing illegal goods.\n \n Example 1:\n \n >>> minimumTime(s = \"1100101\")\n >>> 5\n Explanation:\n One way to remove all the cars containing illegal goods from the sequence is to\n - remove a car from the left end 2 times. Time taken is 2 * 1 = 2.\n - remove a car from the right end. Time taken is 1.\n - remove the car containing illegal goods found in the middle. Time taken is 2.\n This obtains a total time of 2 + 1 + 2 = 5.\n \n An alternative way is to\n - remove a car from the left end 2 times. Time taken is 2 * 1 = 2.\n - remove a car from the right end 3 times. Time taken is 3 * 1 = 3.\n This also obtains a total time of 2 + 3 = 5.\n \n 5 is the minimum time taken to remove all the cars containing illegal goods.\n There are no other ways to remove them with less time.\n \n Example 2:\n \n >>> minimumTime(s = \"0010\")\n >>> 2\n Explanation:\n One way to remove all the cars containing illegal goods from the sequence is to\n - remove a car from the left end 3 times. Time taken is 3 * 1 = 3.\n This obtains a total time of 3.\n \n Another way to remove all the cars containing illegal goods from the sequence is to\n - remove the car containing illegal goods found in the middle. Time taken is 2.\n This obtains a total time of 2.\n \n Another way to remove all the cars containing illegal goods from the sequence is to\n - remove a car from the right end 2 times. Time taken is 2 * 1 = 2.\n This obtains a total time of 2.\n \n 2 is the minimum time taken to remove all the cars containing illegal goods.\n There are no other ways to remove them with less time.\n \"\"\"\n"}
{"task_id": "unique-substrings-with-equal-digit-frequency", "prompt": "def equalDigitFrequency(s: str) -> int:\n \"\"\"\n Given a digit string s, return the number of unique substrings of s where every digit appears the same number of times.\n \n Example 1:\n \n >>> equalDigitFrequency(s = \"1212\")\n >>> 5\n Explanation: The substrings that meet the requirements are \"1\", \"2\", \"12\", \"21\", \"1212\".\n Note that although the substring \"12\" appears twice, it is only counted once.\n \n Example 2:\n \n >>> equalDigitFrequency(s = \"12321\")\n >>> 9\n Explanation: The substrings that meet the requirements are \"1\", \"2\", \"3\", \"12\", \"23\", \"32\", \"21\", \"123\", \"321\".\n \"\"\"\n"}
{"task_id": "count-operations-to-obtain-zero", "prompt": "def countOperations(num1: int, num2: int) -> int:\n \"\"\"\n You are given two non-negative integers num1 and num2.\n In one operation, if num1 >= num2, you must subtract num2 from num1, otherwise subtract num1 from num2.\n \n For example, if num1 = 5 and num2 = 4, subtract num2 from num1, thus obtaining num1 = 1 and num2 = 4. However, if num1 = 4 and num2 = 5, after one operation, num1 = 4 and num2 = 1.\n \n Return the number of operations required to make either num1 = 0 or num2 = 0.\n \n Example 1:\n \n >>> countOperations(num1 = 2, num2 = 3)\n >>> 3\n Explanation:\n - Operation 1: num1 = 2, num2 = 3. Since num1 < num2, we subtract num1 from num2 and get num1 = 2, num2 = 3 - 2 = 1.\n - Operation 2: num1 = 2, num2 = 1. Since num1 > num2, we subtract num2 from num1.\n - Operation 3: num1 = 1, num2 = 1. Since num1 == num2, we subtract num2 from num1.\n Now num1 = 0 and num2 = 1. Since num1 == 0, we do not need to perform any further operations.\n So the total number of operations required is 3.\n \n Example 2:\n \n >>> countOperations(num1 = 10, num2 = 10)\n >>> 1\n Explanation:\n - Operation 1: num1 = 10, num2 = 10. Since num1 == num2, we subtract num2 from num1 and get num1 = 10 - 10 = 0.\n Now num1 = 0 and num2 = 10. Since num1 == 0, we are done.\n So the total number of operations required is 1.\n \"\"\"\n"}
{"task_id": "minimum-operations-to-make-the-array-alternating", "prompt": "def minimumOperations(nums: List[int]) -> int:\n \"\"\"\n You are given a 0-indexed array nums consisting of n positive integers.\n The array nums is called alternating if:\n \n nums[i - 2] == nums[i], where 2 <= i <= n - 1.\n nums[i - 1] != nums[i], where 1 <= i <= n - 1.\n \n In one operation, you can choose an index i and change nums[i] into any positive integer.\n Return the minimum number of operations required to make the array alternating.\n \n Example 1:\n \n >>> minimumOperations(nums = [3,1,3,2,4,3])\n >>> 3\n Explanation:\n One way to make the array alternating is by converting it to [3,1,3,1,3,1].\n The number of operations required in this case is 3.\n It can be proven that it is not possible to make the array alternating in less than 3 operations.\n \n Example 2:\n \n >>> minimumOperations(nums = [1,2,2,2,2])\n >>> 2\n Explanation:\n One way to make the array alternating is by converting it to [1,2,1,2,1].\n The number of operations required in this case is 2.\n Note that the array cannot be converted to [2,2,2,2,2] because in this case nums[0] == nums[1] which violates the conditions of an alternating array.\n \"\"\"\n"}
{"task_id": "removing-minimum-number-of-magic-beans", "prompt": "def minimumRemoval(beans: List[int]) -> int:\n \"\"\"\n You are given an array of positive integers beans, where each integer represents the number of magic beans found in a particular magic bag.\n Remove any number of beans (possibly none) from each bag such that the number of beans in each remaining non-empty bag (still containing at least one bean) is equal. Once a bean has been removed from a bag, you are not allowed to return it to any of the bags.\n Return the minimum number of magic beans that you have to remove.\n \n Example 1:\n \n >>> minimumRemoval(beans = [4,1,6,5])\n >>> 4\n Explanation:\n - We remove 1 bean from the bag with only 1 bean.\n This results in the remaining bags: [4,0,6,5]\n - Then we remove 2 beans from the bag with 6 beans.\n This results in the remaining bags: [4,0,4,5]\n - Then we remove 1 bean from the bag with 5 beans.\n This results in the remaining bags: [4,0,4,4]\n We removed a total of 1 + 2 + 1 = 4 beans to make the remaining non-empty bags have an equal number of beans.\n There are no other solutions that remove 4 beans or fewer.\n \n Example 2:\n \n >>> minimumRemoval(beans = [2,10,3,2])\n >>> 7\n Explanation:\n - We remove 2 beans from one of the bags with 2 beans.\n This results in the remaining bags: [0,10,3,2]\n - Then we remove 2 beans from the other bag with 2 beans.\n This results in the remaining bags: [0,10,3,0]\n - Then we remove 3 beans from the bag with 3 beans.\n This results in the remaining bags: [0,10,0,0]\n We removed a total of 2 + 2 + 3 = 7 beans to make the remaining non-empty bags have an equal number of beans.\n There are no other solutions that removes 7 beans or fewer.\n \"\"\"\n"}
{"task_id": "maximum-and-sum-of-array", "prompt": "def maximumANDSum(nums: List[int], numSlots: int) -> int:\n \"\"\"\n You are given an integer array nums of length n and an integer numSlots such that 2 * numSlots >= n. There are numSlots slots numbered from 1 to numSlots.\n You have to place all n integers into the slots such that each slot contains at most two numbers. The AND sum of a given placement is the sum of the bitwise AND of every number with its respective slot number.\n \n For example, the AND sum of placing the numbers [1, 3] into slot 1 and [4, 6] into slot 2 is equal to (1 AND 1) + (3 AND 1) + (4 AND 2) + (6 AND 2) = 1 + 1 + 0 + 2 = 4.\n \n Return the maximum possible AND sum of nums given numSlots slots.\n \n Example 1:\n \n >>> maximumANDSum(nums = [1,2,3,4,5,6], numSlots = 3)\n >>> 9\n Explanation: One possible placement is [1, 4] into slot 1, [2, 6] into slot 2, and [3, 5] into slot 3.\n This gives the maximum AND sum of (1 AND 1) + (4 AND 1) + (2 AND 2) + (6 AND 2) + (3 AND 3) + (5 AND 3) = 1 + 0 + 2 + 2 + 3 + 1 = 9.\n \n Example 2:\n \n >>> maximumANDSum(nums = [1,3,10,4,7,1], numSlots = 9)\n >>> 24\n Explanation: One possible placement is [1, 1] into slot 1, [3] into slot 3, [4] into slot 4, [7] into slot 7, and [10] into slot 9.\n This gives the maximum AND sum of (1 AND 1) + (1 AND 1) + (3 AND 3) + (4 AND 4) + (7 AND 7) + (10 AND 9) = 1 + 1 + 3 + 4 + 7 + 8 = 24.\n Note that slots 2, 5, 6, and 8 are empty which is permitted.\n \"\"\"\n"}
{"task_id": "remove-all-ones-with-row-and-column-flips-ii", "prompt": "def removeOnes(grid: List[List[int]]) -> int:\n \"\"\"\n You are given a 0-indexed m x n binary matrix grid.\n In one operation, you can choose any i and j that meet the following conditions:\n \n 0 <= i < m\n 0 <= j < n\n grid[i][j] == 1\n \n and change the values of all cells in row i and column j to zero.\n Return the minimum number of operations needed to remove all 1's from grid.\n \n Example 1:\n \n \n >>> removeOnes(grid = [[1,1,1],[1,1,1],[0,1,0]])\n >>> 2\n Explanation:\n In the first operation, change all cell values of row 1 and column 1 to zero.\n In the second operation, change all cell values of row 0 and column 0 to zero.\n \n Example 2:\n \n \n >>> removeOnes(grid = [[0,1,0],[1,0,1],[0,1,0]])\n >>> 2\n Explanation:\n In the first operation, change all cell values of row 1 and column 0 to zero.\n In the second operation, change all cell values of row 2 and column 1 to zero.\n Note that we cannot perform an operation using row 1 and column 1 because grid[1][1] != 1.\n \n Example 3:\n \n \n >>> removeOnes(grid = [[0,0],[0,0]])\n >>> 0\n Explanation:\n There are no 1's to remove so return 0.\n \"\"\"\n"}
{"task_id": "count-equal-and-divisible-pairs-in-an-array", "prompt": "def countPairs(nums: List[int], k: int) -> int:\n \"\"\"\n Given a 0-indexed integer array nums of length n and an integer k, return the number of pairs (i, j) where 0 <= i < j < n, such that nums[i] == nums[j] and (i * j) is divisible by k.\n \n Example 1:\n \n >>> countPairs(nums = [3,1,2,2,2,1,3], k = 2)\n >>> 4\n Explanation:\n There are 4 pairs that meet all the requirements:\n - nums[0] == nums[6], and 0 * 6 == 0, which is divisible by 2.\n - nums[2] == nums[3], and 2 * 3 == 6, which is divisible by 2.\n - nums[2] == nums[4], and 2 * 4 == 8, which is divisible by 2.\n - nums[3] == nums[4], and 3 * 4 == 12, which is divisible by 2.\n \n Example 2:\n \n >>> countPairs(nums = [1,2,3,4], k = 1)\n >>> 0\n Explanation: Since no value in nums is repeated, there are no pairs (i,j) that meet all the requirements.\n \"\"\"\n"}
{"task_id": "find-three-consecutive-integers-that-sum-to-a-given-number", "prompt": "def sumOfThree(num: int) -> List[int]:\n \"\"\"\n Given an integer num, return three consecutive integers (as a sorted array) that sum to num. If num cannot be expressed as the sum of three consecutive integers, return an empty array.\n \n Example 1:\n \n >>> sumOfThree(num = 33)\n >>> [10,11,12]\n Explanation: 33 can be expressed as 10 + 11 + 12 = 33.\n 10, 11, 12 are 3 consecutive integers, so we return [10, 11, 12].\n \n Example 2:\n \n >>> sumOfThree(num = 4)\n >>> []\n Explanation: There is no way to express 4 as the sum of 3 consecutive integers.\n \"\"\"\n"}
{"task_id": "maximum-split-of-positive-even-integers", "prompt": "def maximumEvenSplit(finalSum: int) -> List[int]:\n \"\"\"\n You are given an integer finalSum. Split it into a sum of a maximum number of unique positive even integers.\n \n For example, given finalSum = 12, the following splits are valid (unique positive even integers summing up to finalSum): (12), (2 + 10), (2 + 4 + 6), and (4 + 8). Among them, (2 + 4 + 6) contains the maximum number of integers. Note that finalSum cannot be split into (2 + 2 + 4 + 4) as all the numbers should be unique.\n \n Return a list of integers that represent a valid split containing a maximum number of integers. If no valid split exists for finalSum, return an empty list. You may return the integers in any order.\n \n Example 1:\n \n >>> maximumEvenSplit(finalSum = 12)\n >>> [2,4,6]\n Explanation: The following are valid splits: (12), (2 + 10), (2 + 4 + 6), and (4 + 8).\n (2 + 4 + 6) has the maximum number of integers, which is 3. Thus, we return [2,4,6].\n Note that [2,6,4], [6,2,4], etc. are also accepted.\n \n Example 2:\n \n >>> maximumEvenSplit(finalSum = 7)\n >>> []\n Explanation: There are no valid splits for the given finalSum.\n Thus, we return an empty array.\n \n Example 3:\n \n >>> maximumEvenSplit(finalSum = 28)\n >>> [6,8,2,12]\n Explanation: The following are valid splits: (2 + 26), (6 + 8 + 2 + 12), and (4 + 24).\n (6 + 8 + 2 + 12) has the maximum number of integers, which is 4. Thus, we return [6,8,2,12].\n Note that [10,2,4,12], [6,2,4,16], etc. are also accepted.\n \"\"\"\n"}
{"task_id": "count-good-triplets-in-an-array", "prompt": "def goodTriplets(nums1: List[int], nums2: List[int]) -> int:\n \"\"\"\n You are given two 0-indexed arrays nums1 and nums2 of length n, both of which are permutations of [0, 1, ..., n - 1].\n A good triplet is a set of 3 distinct values which are present in increasing order by position both in nums1 and nums2. In other words, if we consider pos1v as the index of the value v in nums1 and pos2v as the index of the value v in nums2, then a good triplet will be a set (x, y, z) where 0 <= x, y, z <= n - 1, such that pos1x < pos1y < pos1z and pos2x < pos2y < pos2z.\n Return the total number of good triplets.\n \n Example 1:\n \n >>> goodTriplets(nums1 = [2,0,1,3], nums2 = [0,1,2,3])\n >>> 1\n Explanation:\n There are 4 triplets (x,y,z) such that pos1x < pos1y < pos1z. They are (2,0,1), (2,0,3), (2,1,3), and (0,1,3).\n Out of those triplets, only the triplet (0,1,3) satisfies pos2x < pos2y < pos2z. Hence, there is only 1 good triplet.\n \n Example 2:\n \n >>> goodTriplets(nums1 = [4,0,1,3,2], nums2 = [4,1,0,2,3])\n >>> 4\n Explanation: The 4 good triplets are (4,0,3), (4,0,2), (4,1,3), and (4,1,2).\n \"\"\"\n"}
{"task_id": "count-integers-with-even-digit-sum", "prompt": "def countEven(num: int) -> int:\n \"\"\"\n Given a positive integer num, return the number of positive integers less than or equal to num whose digit sums are even.\n The digit sum of a positive integer is the sum of all its digits.\n \n Example 1:\n \n >>> countEven(num = 4)\n >>> 2\n Explanation:\n The only integers less than or equal to 4 whose digit sums are even are 2 and 4.\n \n Example 2:\n \n >>> countEven(num = 30)\n >>> 14\n Explanation:\n The 14 integers less than or equal to 30 whose digit sums are even are\n 2, 4, 6, 8, 11, 13, 15, 17, 19, 20, 22, 24, 26, and 28.\n \"\"\"\n"}
{"task_id": "merge-nodes-in-between-zeros", "prompt": "# class ListNode:\n# def __init__(val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution:\n def mergeNodes(head: Optional[ListNode]) -> Optional[ListNode]:\n \"\"\"\n You are given the head of a linked list, which contains a series of integers separated by 0's. The beginning and end of the linked list will have Node.val == 0.\n For every two consecutive 0's, merge all the nodes lying in between them into a single node whose value is the sum of all the merged nodes. The modified list should not contain any 0's.\n Return the head of the modified linked list.\n \n Example 1:\n \n \n >>> __init__(head = [0,3,1,0,4,5,2,0])\n >>> [4,11]\n Explanation:\n The above figure represents the given linked list. The modified list contains\n - The sum of the nodes marked in green: 3 + 1 = 4.\n - The sum of the nodes marked in red: 4 + 5 + 2 = 11.\n \n Example 2:\n \n \n >>> __init__(head = [0,1,0,3,0,2,2,0])\n >>> [1,3,4]\n Explanation:\n The above figure represents the given linked list. The modified list contains\n - The sum of the nodes marked in green: 1 = 1.\n - The sum of the nodes marked in red: 3 = 3.\n - The sum of the nodes marked in yellow: 2 + 2 = 4.\n \"\"\"\n"}
{"task_id": "construct-string-with-repeat-limit", "prompt": "def repeatLimitedString(s: str, repeatLimit: int) -> str:\n \"\"\"\n You are given a string s and an integer repeatLimit. Construct a new string repeatLimitedString using the characters of s such that no letter appears more than repeatLimit times in a row. You do not have to use all characters from s.\n Return the lexicographically largest repeatLimitedString possible.\n A string a is lexicographically larger than a string b if in the first position where a and b differ, string a has a letter that appears later in the alphabet than the corresponding letter in b. If the first min(a.length, b.length) characters do not differ, then the longer string is the lexicographically larger one.\n \n Example 1:\n \n >>> repeatLimitedString(s = \"cczazcc\", repeatLimit = 3)\n >>> \"zzcccac\"\n Explanation: We use all of the characters from s to construct the repeatLimitedString \"zzcccac\".\n The letter 'a' appears at most 1 time in a row.\n The letter 'c' appears at most 3 times in a row.\n The letter 'z' appears at most 2 times in a row.\n Hence, no letter appears more than repeatLimit times in a row and the string is a valid repeatLimitedString.\n The string is the lexicographically largest repeatLimitedString possible so we return \"zzcccac\".\n Note that the string \"zzcccca\" is lexicographically larger but the letter 'c' appears more than 3 times in a row, so it is not a valid repeatLimitedString.\n \n Example 2:\n \n >>> repeatLimitedString(s = \"aababab\", repeatLimit = 2)\n >>> \"bbabaa\"\n Explanation: We use only some of the characters from s to construct the repeatLimitedString \"bbabaa\".\n The letter 'a' appears at most 2 times in a row.\n The letter 'b' appears at most 2 times in a row.\n Hence, no letter appears more than repeatLimit times in a row and the string is a valid repeatLimitedString.\n The string is the lexicographically largest repeatLimitedString possible so we return \"bbabaa\".\n Note that the string \"bbabaaa\" is lexicographically larger but the letter 'a' appears more than 2 times in a row, so it is not a valid repeatLimitedString.\n \"\"\"\n"}
{"task_id": "count-array-pairs-divisible-by-k", "prompt": "def countPairs(nums: List[int], k: int) -> int:\n \"\"\"\n Given a 0-indexed integer array nums of length n and an integer k, return the number of pairs (i, j) such that:\n \n 0 <= i < j <= n - 1 and\n nums[i] * nums[j] is divisible by k.\n \n \n Example 1:\n \n >>> countPairs(nums = [1,2,3,4,5], k = 2)\n >>> 7\n Explanation:\n The 7 pairs of indices whose corresponding products are divisible by 2 are\n (0, 1), (0, 3), (1, 2), (1, 3), (1, 4), (2, 3), and (3, 4).\n Their products are 2, 4, 6, 8, 10, 12, and 20 respectively.\n Other pairs such as (0, 2) and (2, 4) have products 3 and 15 respectively, which are not divisible by 2.\n \n Example 2:\n \n >>> countPairs(nums = [1,2,3,4], k = 5)\n >>> 0\n Explanation: There does not exist any pair of indices whose corresponding product is divisible by 5.\n \"\"\"\n"}
{"task_id": "number-of-ways-to-build-sturdy-brick-wall", "prompt": "def buildWall(height: int, width: int, bricks: List[int]) -> int:\n \"\"\"\n You are given integers height and width which specify the dimensions of a brick wall you are building. You are also given a 0-indexed array of unique integers bricks, where the ith brick has a height of 1 and a width of bricks[i]. You have an infinite supply of each type of brick and bricks may not be rotated.\n Each row in the wall must be exactly width units long. For the wall to be sturdy, adjacent rows in the wall should not join bricks at the same location, except at the ends of the wall.\n Return the number of ways to build a sturdy wall. Since the answer may be very large, return it modulo 109 + 7.\n \n Example 1:\n \n \n >>> buildWall(height = 2, width = 3, bricks = [1,2])\n >>> 2\n Explanation:\n The first two walls in the diagram show the only two ways to build a sturdy brick wall.\n Note that the third wall in the diagram is not sturdy because adjacent rows join bricks 2 units from the left.\n \n Example 2:\n \n >>> buildWall(height = 1, width = 1, bricks = [5])\n >>> 0\n Explanation:\n There are no ways to build a sturdy wall because the only type of brick we have is longer than the width of the wall.\n \"\"\"\n"}
{"task_id": "counting-words-with-a-given-prefix", "prompt": "def prefixCount(words: List[str], pref: str) -> int:\n \"\"\"\n You are given an array of strings words and a string pref.\n Return the number of strings in words that contain pref as a prefix.\n A prefix of a string s is any leading contiguous substring of s.\n \n Example 1:\n \n >>> prefixCount(words = [\"pay\",\"attention\",\"practice\",\"attend\"], pref = \"at\")\n >>> 2\n Explanation: The 2 strings that contain \"at\" as a prefix are: \"attention\" and \"attend\".\n \n Example 2:\n \n >>> prefixCount(words = [\"leetcode\",\"win\",\"loops\",\"success\"], pref = \"code\")\n >>> 0\n Explanation: There are no strings that contain \"code\" as a prefix.\n \"\"\"\n"}
{"task_id": "minimum-number-of-steps-to-make-two-strings-anagram-ii", "prompt": "def minSteps(s: str, t: str) -> int:\n \"\"\"\n You are given two strings s and t. In one step, you can append any character to either s or t.\n Return the minimum number of steps to make s and t anagrams of each other.\n An anagram of a string is a string that contains the same characters with a different (or the same) ordering.\n \n Example 1:\n \n >>> minSteps(s = \"leetcode\", t = \"coats\")\n >>> 7\n Explanation:\n - In 2 steps, we can append the letters in \"as\" onto s = \"leetcode\", forming s = \"leetcodeas\".\n - In 5 steps, we can append the letters in \"leede\" onto t = \"coats\", forming t = \"coatsleede\".\n \"leetcodeas\" and \"coatsleede\" are now anagrams of each other.\n We used a total of 2 + 5 = 7 steps.\n It can be shown that there is no way to make them anagrams of each other with less than 7 steps.\n \n Example 2:\n \n >>> minSteps(s = \"night\", t = \"thing\")\n >>> 0\n Explanation: The given strings are already anagrams of each other. Thus, we do not need any further steps.\n \"\"\"\n"}
{"task_id": "minimum-time-to-complete-trips", "prompt": "def minimumTime(time: List[int], totalTrips: int) -> int:\n \"\"\"\n You are given an array time where time[i] denotes the time taken by the ith bus to complete one trip.\n Each bus can make multiple trips successively; that is, the next trip can start immediately after completing the current trip. Also, each bus operates independently; that is, the trips of one bus do not influence the trips of any other bus.\n You are also given an integer totalTrips, which denotes the number of trips all buses should make in total. Return the minimum time required for all buses to complete at least totalTrips trips.\n \n Example 1:\n \n >>> minimumTime(time = [1,2,3], totalTrips = 5)\n >>> 3\n Explanation:\n - At time t = 1, the number of trips completed by each bus are [1,0,0].\n The total number of trips completed is 1 + 0 + 0 = 1.\n - At time t = 2, the number of trips completed by each bus are [2,1,0].\n The total number of trips completed is 2 + 1 + 0 = 3.\n - At time t = 3, the number of trips completed by each bus are [3,1,1].\n The total number of trips completed is 3 + 1 + 1 = 5.\n So the minimum time needed for all buses to complete at least 5 trips is 3.\n \n Example 2:\n \n >>> minimumTime(time = [2], totalTrips = 1)\n >>> 2\n Explanation:\n There is only one bus, and it will complete its first trip at t = 2.\n So the minimum time needed to complete 1 trip is 2.\n \"\"\"\n"}
{"task_id": "minimum-time-to-finish-the-race", "prompt": "def minimumFinishTime(tires: List[List[int]], changeTime: int, numLaps: int) -> int:\n \"\"\"\n You are given a 0-indexed 2D integer array tires where tires[i] = [fi, ri] indicates that the ith tire can finish its xth successive lap in fi * ri(x-1) seconds.\n \n For example, if fi = 3 and ri = 2, then the tire would finish its 1st lap in 3 seconds, its 2nd lap in 3 * 2 = 6 seconds, its 3rd lap in 3 * 22 = 12 seconds, etc.\n \n You are also given an integer changeTime and an integer numLaps.\n The race consists of numLaps laps and you may start the race with any tire. You have an unlimited supply of each tire and after every lap, you may change to any given tire (including the current tire type) if you wait changeTime seconds.\n Return the minimum time to finish the race.\n \n Example 1:\n \n >>> minimumFinishTime(tires = [[2,3],[3,4]], changeTime = 5, numLaps = 4)\n >>> 21\n Explanation:\n Lap 1: Start with tire 0 and finish the lap in 2 seconds.\n Lap 2: Continue with tire 0 and finish the lap in 2 * 3 = 6 seconds.\n Lap 3: Change tires to a new tire 0 for 5 seconds and then finish the lap in another 2 seconds.\n Lap 4: Continue with tire 0 and finish the lap in 2 * 3 = 6 seconds.\n Total time = 2 + 6 + 5 + 2 + 6 = 21 seconds.\n The minimum time to complete the race is 21 seconds.\n \n Example 2:\n \n >>> minimumFinishTime(tires = [[1,10],[2,2],[3,4]], changeTime = 6, numLaps = 5)\n >>> 25\n Explanation:\n Lap 1: Start with tire 1 and finish the lap in 2 seconds.\n Lap 2: Continue with tire 1 and finish the lap in 2 * 2 = 4 seconds.\n Lap 3: Change tires to a new tire 1 for 6 seconds and then finish the lap in another 2 seconds.\n Lap 4: Continue with tire 1 and finish the lap in 2 * 2 = 4 seconds.\n Lap 5: Change tires to tire 0 for 6 seconds then finish the lap in another 1 second.\n Total time = 2 + 4 + 6 + 2 + 4 + 6 + 1 = 25 seconds.\n The minimum time to complete the race is 25 seconds.\n \"\"\"\n"}
{"task_id": "number-of-ways-to-build-house-of-cards", "prompt": "def houseOfCards(n: int) -> int:\n \"\"\"\n You are given an integer n representing the number of playing cards you have. A house of cards meets the following conditions:\n \n A house of cards consists of one or more rows of triangles and horizontal cards.\n Triangles are created by leaning two cards against each other.\n One card must be placed horizontally between all adjacent triangles in a row.\n Any triangle on a row higher than the first must be placed on a horizontal card from the previous row.\n Each triangle is placed in the leftmost available spot in the row.\n \n Return the number of distinct house of cards you can build using all n cards. Two houses of cards are considered distinct if there exists a row where the two houses contain a different number of cards.\n \n Example 1:\n \n \n >>> houseOfCards(n = 16)\n >>> 2\n Explanation: The two valid houses of cards are shown.\n The third house of cards in the diagram is not valid because the rightmost triangle on the top row is not placed on top of a horizontal card.\n \n Example 2:\n \n \n >>> houseOfCards(n = 2)\n >>> 1\n Explanation: The one valid house of cards is shown.\n \n Example 3:\n \n \n >>> houseOfCards(n = 4)\n >>> 0\n Explanation: The three houses of cards in the diagram are not valid.\n The first house of cards needs a horizontal card placed between the two triangles.\n The second house of cards uses 5 cards.\n The third house of cards uses 2 cards.\n \"\"\"\n"}
{"task_id": "most-frequent-number-following-key-in-an-array", "prompt": "def mostFrequent(nums: List[int], key: int) -> int:\n \"\"\"\n You are given a 0-indexed integer array nums. You are also given an integer key, which is present in nums.\n For every unique integer target in nums, count the number of times target immediately follows an occurrence of key in nums. In other words, count the number of indices i such that:\n \n 0 <= i <= nums.length - 2,\n nums[i] == key and,\n nums[i + 1] == target.\n \n Return the target with the maximum count. The test cases will be generated such that the target with maximum count is unique.\n \n Example 1:\n \n >>> mostFrequent(nums = [1,100,200,1,100], key = 1)\n >>> 100\n Explanation: For target = 100, there are 2 occurrences at indices 1 and 4 which follow an occurrence of key.\n No other integers follow an occurrence of key, so we return 100.\n \n Example 2:\n \n >>> mostFrequent(nums = [2,2,2,2,3], key = 2)\n >>> 2\n Explanation: For target = 2, there are 3 occurrences at indices 1, 2, and 3 which follow an occurrence of key.\n For target = 3, there is only one occurrence at index 4 which follows an occurrence of key.\n target = 2 has the maximum number of occurrences following an occurrence of key, so we return 2.\n \"\"\"\n"}
{"task_id": "sort-the-jumbled-numbers", "prompt": "def sortJumbled(mapping: List[int], nums: List[int]) -> List[int]:\n \"\"\"\n You are given a 0-indexed integer array mapping which represents the mapping rule of a shuffled decimal system. mapping[i] = j means digit i should be mapped to digit j in this system.\n The mapped value of an integer is the new integer obtained by replacing each occurrence of digit i in the integer with mapping[i] for all 0 <= i <= 9.\n You are also given another integer array nums. Return the array nums sorted in non-decreasing order based on the mapped values of its elements.\n Notes:\n \n Elements with the same mapped values should appear in the same relative order as in the input.\n The elements of nums should only be sorted based on their mapped values and not be replaced by them.\n \n \n Example 1:\n \n >>> sortJumbled(mapping = [8,9,4,0,2,1,3,5,7,6], nums = [991,338,38])\n >>> [338,38,991]\n Explanation:\n Map the number 991 as follows:\n 1. mapping[9] = 6, so all occurrences of the digit 9 will become 6.\n 2. mapping[1] = 9, so all occurrences of the digit 1 will become 9.\n Therefore, the mapped value of 991 is 669.\n 338 maps to 007, or 7 after removing the leading zeros.\n 38 maps to 07, which is also 7 after removing leading zeros.\n Since 338 and 38 share the same mapped value, they should remain in the same relative order, so 338 comes before 38.\n Thus, the sorted array is [338,38,991].\n \n Example 2:\n \n >>> sortJumbled(mapping = [0,1,2,3,4,5,6,7,8,9], nums = [789,456,123])\n >>> [123,456,789]\n Explanation: 789 maps to 789, 456 maps to 456, and 123 maps to 123. Thus, the sorted array is [123,456,789].\n \"\"\"\n"}
{"task_id": "all-ancestors-of-a-node-in-a-directed-acyclic-graph", "prompt": "def getAncestors(n: int, edges: List[List[int]]) -> List[List[int]]:\n \"\"\"\n You are given a positive integer n representing the number of nodes of a Directed Acyclic Graph (DAG). The nodes are numbered from 0 to n - 1 (inclusive).\n You are also given a 2D integer array edges, where edges[i] = [fromi, toi] denotes that there is a unidirectional edge from fromi to toi in the graph.\n Return a list answer, where answer[i] is the list of ancestors of the ith node, sorted in ascending order.\n A node u is an ancestor of another node v if u can reach v via a set of edges.\n \n Example 1:\n \n \n >>> getAncestors(n = 8, edgeList = [[0,3],[0,4],[1,3],[2,4],[2,7],[3,5],[3,6],[3,7],[4,6]])\n >>> [[],[],[],[0,1],[0,2],[0,1,3],[0,1,2,3,4],[0,1,2,3]]\n Explanation:\n The above diagram represents the input graph.\n - Nodes 0, 1, and 2 do not have any ancestors.\n - Node 3 has two ancestors 0 and 1.\n - Node 4 has two ancestors 0 and 2.\n - Node 5 has three ancestors 0, 1, and 3.\n - Node 6 has five ancestors 0, 1, 2, 3, and 4.\n - Node 7 has four ancestors 0, 1, 2, and 3.\n \n Example 2:\n \n \n >>> getAncestors(n = 5, edgeList = [[0,1],[0,2],[0,3],[0,4],[1,2],[1,3],[1,4],[2,3],[2,4],[3,4]])\n >>> [[],[0],[0,1],[0,1,2],[0,1,2,3]]\n Explanation:\n The above diagram represents the input graph.\n - Node 0 does not have any ancestor.\n - Node 1 has one ancestor 0.\n - Node 2 has two ancestors 0 and 1.\n - Node 3 has three ancestors 0, 1, and 2.\n - Node 4 has four ancestors 0, 1, 2, and 3.\n \"\"\"\n"}
{"task_id": "minimum-number-of-moves-to-make-palindrome", "prompt": "def minMovesToMakePalindrome(s: str) -> int:\n \"\"\"\n You are given a string s consisting only of lowercase English letters.\n In one move, you can select any two adjacent characters of s and swap them.\n Return the minimum number of moves needed to make s a palindrome.\n Note that the input will be generated such that s can always be converted to a palindrome.\n \n Example 1:\n \n >>> minMovesToMakePalindrome(s = \"aabb\")\n >>> 2\n Explanation:\n We can obtain two palindromes from s, \"abba\" and \"baab\".\n - We can obtain \"abba\" from s in 2 moves: \"aabb\" -> \"abab\" -> \"abba\".\n - We can obtain \"baab\" from s in 2 moves: \"aabb\" -> \"abab\" -> \"baab\".\n Thus, the minimum number of moves needed to make s a palindrome is 2.\n \n Example 2:\n \n >>> minMovesToMakePalindrome(s = \"letelt\")\n >>> 2\n Explanation:\n One of the palindromes we can obtain from s in 2 moves is \"lettel\".\n One of the ways we can obtain it is \"letelt\" -> \"letetl\" -> \"lettel\".\n Other palindromes such as \"tleelt\" can also be obtained in 2 moves.\n It can be shown that it is not possible to obtain a palindrome in less than 2 moves.\n \"\"\"\n"}
{"task_id": "cells-in-a-range-on-an-excel-sheet", "prompt": "def cellsInRange(s: str) -> List[str]:\n \"\"\"\n A cell (r, c) of an excel sheet is represented as a string \"\" where:\n \n denotes the column number c of the cell. It is represented by alphabetical letters.\n \n \n For example, the 1st column is denoted by 'A', the 2nd by 'B', the 3rd by 'C', and so on.\n \n \n is the row number r of the cell. The rth row is represented by the integer r.\n \n You are given a string s\u00a0in\u00a0the format \":\", where represents the column c1, represents the row r1, represents the column c2, and represents the row r2, such that r1 <= r2 and c1 <= c2.\n Return the list of cells (x, y) such that r1 <= x <= r2 and c1 <= y <= c2. The cells should be represented as\u00a0strings in the format mentioned above and be sorted in non-decreasing order first by columns and then by rows.\n \n Example 1:\n \n \n >>> cellsInRange(s = \"K1:L2\")\n >>> [\"K1\",\"K2\",\"L1\",\"L2\"]\n Explanation:\n The above diagram shows the cells which should be present in the list.\n The red arrows denote the order in which the cells should be presented.\n \n Example 2:\n \n \n >>> cellsInRange(s = \"A1:F1\")\n >>> [\"A1\",\"B1\",\"C1\",\"D1\",\"E1\",\"F1\"]\n Explanation:\n The above diagram shows the cells which should be present in the list.\n The red arrow denotes the order in which the cells should be presented.\n \"\"\"\n"}
{"task_id": "append-k-integers-with-minimal-sum", "prompt": "def minimalKSum(nums: List[int], k: int) -> int:\n \"\"\"\n You are given an integer array nums and an integer k. Append k unique positive integers that do not appear in nums to nums such that the resulting total sum is minimum.\n Return the sum of the k integers appended to nums.\n \n Example 1:\n \n >>> minimalKSum(nums = [1,4,25,10,25], k = 2)\n >>> 5\n Explanation: The two unique positive integers that do not appear in nums which we append are 2 and 3.\n The resulting sum of nums is 1 + 4 + 25 + 10 + 25 + 2 + 3 = 70, which is the minimum.\n The sum of the two integers appended is 2 + 3 = 5, so we return 5.\n Example 2:\n \n >>> minimalKSum(nums = [5,6], k = 6)\n >>> 25\n Explanation: The six unique positive integers that do not appear in nums which we append are 1, 2, 3, 4, 7, and 8.\n The resulting sum of nums is 5 + 6 + 1 + 2 + 3 + 4 + 7 + 8 = 36, which is the minimum.\n The sum of the six integers appended is 1 + 2 + 3 + 4 + 7 + 8 = 25, so we return 25.\n \"\"\"\n"}
{"task_id": "create-binary-tree-from-descriptions", "prompt": "# class TreeNode:\n# def __init__(val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def createBinaryTree(descriptions: List[List[int]]) -> Optional[TreeNode]:\n \"\"\"\n You are given a 2D integer array descriptions where descriptions[i] = [parenti, childi, isLefti] indicates that parenti is the parent of childi in a binary tree of unique values. Furthermore,\n \n If isLefti == 1, then childi is the left child of parenti.\n If isLefti == 0, then childi is the right child of parenti.\n \n Construct the binary tree described by descriptions and return its root.\n The test cases will be generated such that the binary tree is valid.\n \n Example 1:\n \n \n >>> __init__(descriptions = [[20,15,1],[20,17,0],[50,20,1],[50,80,0],[80,19,1]])\n >>> [50,20,80,15,17,19]\n Explanation: The root node is the node with value 50 since it has no parent.\n The resulting binary tree is shown in the diagram.\n \n Example 2:\n \n \n >>> __init__(descriptions = [[1,2,1],[2,3,0],[3,4,1]])\n >>> [1,2,null,null,3,4]\n Explanation: The root node is the node with value 1 since it has no parent.\n The resulting binary tree is shown in the diagram.\n \"\"\"\n"}
{"task_id": "replace-non-coprime-numbers-in-array", "prompt": "def replaceNonCoprimes(nums: List[int]) -> List[int]:\n \"\"\"\n You are given an array of integers nums. Perform the following steps:\n \n Find any two adjacent numbers in nums that are non-coprime.\n If no such numbers are found, stop the process.\n Otherwise, delete the two numbers and replace them with their LCM (Least Common Multiple).\n Repeat this process as long as you keep finding two adjacent non-coprime numbers.\n \n Return the final modified array. It can be shown that replacing adjacent non-coprime numbers in any arbitrary order will lead to the same result.\n The test cases are generated such that the values in the final array are less than or equal to 108.\n Two values x and y are non-coprime if GCD(x, y) > 1 where GCD(x, y) is the Greatest Common Divisor of x and y.\n \n Example 1:\n \n >>> replaceNonCoprimes(nums = [6,4,3,2,7,6,2])\n >>> [12,7,6]\n Explanation:\n - (6, 4) are non-coprime with LCM(6, 4) = 12. Now, nums = [12,3,2,7,6,2].\n - (12, 3) are non-coprime with LCM(12, 3) = 12. Now, nums = [12,2,7,6,2].\n - (12, 2) are non-coprime with LCM(12, 2) = 12. Now, nums = [12,7,6,2].\n - (6, 2) are non-coprime with LCM(6, 2) = 6. Now, nums = [12,7,6].\n There are no more adjacent non-coprime numbers in nums.\n Thus, the final modified array is [12,7,6].\n Note that there are other ways to obtain the same resultant array.\n \n Example 2:\n \n >>> replaceNonCoprimes(nums = [2,2,1,1,3,3,3])\n >>> [2,1,1,3]\n Explanation:\n - (3, 3) are non-coprime with LCM(3, 3) = 3. Now, nums = [2,2,1,1,3,3].\n - (3, 3) are non-coprime with LCM(3, 3) = 3. Now, nums = [2,2,1,1,3].\n - (2, 2) are non-coprime with LCM(2, 2) = 2. Now, nums = [2,1,1,3].\n There are no more adjacent non-coprime numbers in nums.\n Thus, the final modified array is [2,1,1,3].\n Note that there are other ways to obtain the same resultant array.\n \"\"\"\n"}
{"task_id": "number-of-single-divisor-triplets", "prompt": "def singleDivisorTriplet(nums: List[int]) -> int:\n \"\"\"\n You are given a 0-indexed array of positive integers nums. A triplet of three distinct indices (i, j, k) is called a single divisor triplet of nums if nums[i] + nums[j] + nums[k] is divisible by exactly one of nums[i], nums[j], or nums[k].\n Return the number of single divisor triplets of nums.\n \n Example 1:\n \n >>> singleDivisorTriplet(nums = [4,6,7,3,2])\n >>> 12\n Explanation:\n The triplets (0, 3, 4), (0, 4, 3), (3, 0, 4), (3, 4, 0), (4, 0, 3), and (4, 3, 0) have the values of [4, 3, 2] (or a permutation of [4, 3, 2]).\n 4 + 3 + 2 = 9 which is only divisible by 3, so all such triplets are single divisor triplets.\n The triplets (0, 2, 3), (0, 3, 2), (2, 0, 3), (2, 3, 0), (3, 0, 2), and (3, 2, 0) have the values of [4, 7, 3] (or a permutation of [4, 7, 3]).\n 4 + 7 + 3 = 14 which is only divisible by 7, so all such triplets are single divisor triplets.\n There are 12 single divisor triplets in total.\n \n Example 2:\n \n >>> singleDivisorTriplet(nums = [1,2,2])\n >>> 6\n Explanation:\n The triplets (0, 1, 2), (0, 2, 1), (1, 0, 2), (1, 2, 0), (2, 0, 1), and (2, 1, 0) have the values of [1, 2, 2] (or a permutation of [1, 2, 2]).\n 1 + 2 + 2 = 5 which is only divisible by 1, so all such triplets are single divisor triplets.\n There are 6 single divisor triplets in total.\n \n Example 3:\n \n >>> singleDivisorTriplet(nums = [1,1,1])\n >>> 0\n Explanation:\n There are no single divisor triplets.\n Note that (0, 1, 2) is not a single divisor triplet because nums[0] + nums[1] + nums[2] = 3 and 3 is divisible by nums[0], nums[1], and nums[2].\n \"\"\"\n"}
{"task_id": "find-all-k-distant-indices-in-an-array", "prompt": "def findKDistantIndices(nums: List[int], key: int, k: int) -> List[int]:\n \"\"\"\n You are given a 0-indexed integer array nums and two integers key and k. A k-distant index is an index i of nums for which there exists at least one index j such that |i - j| <= k and nums[j] == key.\n Return a list of all k-distant indices sorted in increasing order.\n \n Example 1:\n \n >>> findKDistantIndices(nums = [3,4,9,1,3,9,5], key = 9, k = 1)\n >>> [1,2,3,4,5,6]\n Explanation: Here, nums[2] == key and nums[5] == key.\n - For index 0, |0 - 2| > k and |0 - 5| > k, so there is no j where |0 - j| <= k and nums[j] == key. Thus, 0 is not a k-distant index.\n - For index 1, |1 - 2| <= k and nums[2] == key, so 1 is a k-distant index.\n - For index 2, |2 - 2| <= k and nums[2] == key, so 2 is a k-distant index.\n - For index 3, |3 - 2| <= k and nums[2] == key, so 3 is a k-distant index.\n - For index 4, |4 - 5| <= k and nums[5] == key, so 4 is a k-distant index.\n - For index 5, |5 - 5| <= k and nums[5] == key, so 5 is a k-distant index.\n - For index 6, |6 - 5| <= k and nums[5] == key, so 6 is a k-distant index.\n Thus, we return [1,2,3,4,5,6] which is sorted in increasing order.\n \n Example 2:\n \n >>> findKDistantIndices(nums = [2,2,2,2,2], key = 2, k = 2)\n >>> [0,1,2,3,4]\n Explanation: For all indices i in nums, there exists some index j such that |i - j| <= k and nums[j] == key, so every index is a k-distant index.\n Hence, we return [0,1,2,3,4].\n \"\"\"\n"}
{"task_id": "count-artifacts-that-can-be-extracted", "prompt": "def digArtifacts(n: int, artifacts: List[List[int]], dig: List[List[int]]) -> int:\n \"\"\"\n There is an n x n 0-indexed grid with some artifacts buried in it. You are given the integer n and a 0-indexed 2D integer array artifacts describing the positions of the rectangular artifacts where artifacts[i] = [r1i, c1i, r2i, c2i] denotes that the ith artifact is buried in the subgrid where:\n \n (r1i, c1i) is the coordinate of the top-left cell of the ith artifact and\n (r2i, c2i) is the coordinate of the bottom-right cell of the ith artifact.\n \n You will excavate some cells of the grid and remove all the mud from them. If the cell has a part of an artifact buried underneath, it will be uncovered. If all the parts of an artifact are uncovered, you can extract it.\n Given a 0-indexed 2D integer array dig where dig[i] = [ri, ci] indicates that you will excavate the cell (ri, ci), return the number of artifacts that you can extract.\n The test cases are generated such that:\n \n No two artifacts overlap.\n Each artifact only covers at most 4 cells.\n The entries of dig are unique.\n \n \n Example 1:\n \n \n >>> digArtifacts(n = 2, artifacts = [[0,0,0,0],[0,1,1,1]], dig = [[0,0],[0,1]])\n >>> 1\n Explanation:\n The different colors represent different artifacts. Excavated cells are labeled with a 'D' in the grid.\n There is 1 artifact that can be extracted, namely the red artifact.\n The blue artifact has one part in cell (1,1) which remains uncovered, so we cannot extract it.\n Thus, we return 1.\n \n Example 2:\n \n \n >>> digArtifacts(n = 2, artifacts = [[0,0,0,0],[0,1,1,1]], dig = [[0,0],[0,1],[1,1]])\n >>> 2\n Explanation: Both the red and blue artifacts have all parts uncovered (labeled with a 'D') and can be extracted, so we return 2.\n \"\"\"\n"}
{"task_id": "maximize-the-topmost-element-after-k-moves", "prompt": "def maximumTop(nums: List[int], k: int) -> int:\n \"\"\"\n You are given a 0-indexed integer array nums representing the contents of a pile, where nums[0] is the topmost element of the pile.\n In one move, you can perform either of the following:\n \n If the pile is not empty, remove the topmost element of the pile.\n If there are one or more removed elements, add any one of them back onto the pile. This element becomes the new topmost element.\n \n You are also given an integer k, which denotes the total number of moves to be made.\n Return the maximum value of the topmost element of the pile possible after exactly k moves. In case it is not possible to obtain a non-empty pile after k moves, return -1.\n \n Example 1:\n \n >>> maximumTop(nums = [5,2,2,4,0,6], k = 4)\n >>> 5\n Explanation:\n One of the ways we can end with 5 at the top of the pile after 4 moves is as follows:\n - Step 1: Remove the topmost element = 5. The pile becomes [2,2,4,0,6].\n - Step 2: Remove the topmost element = 2. The pile becomes [2,4,0,6].\n - Step 3: Remove the topmost element = 2. The pile becomes [4,0,6].\n - Step 4: Add 5 back onto the pile. The pile becomes [5,4,0,6].\n Note that this is not the only way to end with 5 at the top of the pile. It can be shown that 5 is the largest answer possible after 4 moves.\n \n Example 2:\n \n >>> maximumTop(nums = [2], k = 1)\n >>> -1\n Explanation:\n In the first move, our only option is to pop the topmost element of the pile.\n Since it is not possible to obtain a non-empty pile after one move, we return -1.\n \"\"\"\n"}
{"task_id": "minimum-weighted-subgraph-with-the-required-paths", "prompt": "def minimumWeight(n: int, edges: List[List[int]], src1: int, src2: int, dest: int) -> int:\n \"\"\"\n You are given an integer n denoting the number of nodes of a weighted directed graph. The nodes are numbered from 0 to n - 1.\n You are also given a 2D integer array edges where edges[i] = [fromi, toi, weighti] denotes that there exists a directed edge from fromi to toi with weight weighti.\n Lastly, you are given three distinct integers src1, src2, and dest denoting three distinct nodes of the graph.\n Return the minimum weight of a subgraph of the graph such that it is possible to reach dest from both src1 and src2 via a set of edges of this subgraph. In case such a subgraph does not exist, return -1.\n A subgraph is a graph whose vertices and edges are subsets of the original graph. The weight of a subgraph is the sum of weights of its constituent edges.\n \n Example 1:\n \n \n >>> minimumWeight(n = 6, edges = [[0,2,2],[0,5,6],[1,0,3],[1,4,5],[2,1,1],[2,3,3],[2,3,4],[3,4,2],[4,5,1]], src1 = 0, src2 = 1, dest = 5)\n >>> 9\n Explanation:\n The above figure represents the input graph.\n The blue edges represent one of the subgraphs that yield the optimal answer.\n Note that the subgraph [[1,0,3],[0,5,6]] also yields the optimal answer. It is not possible to get a subgraph with less weight satisfying all the constraints.\n \n Example 2:\n \n \n >>> minimumWeight(n = 3, edges = [[0,1,1],[2,1,1]], src1 = 0, src2 = 1, dest = 2)\n >>> -1\n Explanation:\n The above figure represents the input graph.\n It can be seen that there does not exist any path from node 1 to node 2, hence there are no subgraphs satisfying all the constraints.\n \"\"\"\n"}
{"task_id": "distance-to-a-cycle-in-undirected-graph", "prompt": "def distanceToCycle(n: int, edges: List[List[int]]) -> List[int]:\n \"\"\"\n You are given a positive integer n representing the number of nodes in a connected undirected graph containing exactly one cycle. The nodes are numbered from 0 to n - 1 (inclusive).\n You are also given a 2D integer array edges, where edges[i] = [node1i, node2i] denotes that there is a bidirectional edge connecting node1i and node2i in the graph.\n The distance between two nodes a and b is defined to be the minimum number of edges that are needed to go from a to b.\n Return an integer array answer of size n, where answer[i] is the minimum distance between the ith node and any node in the cycle.\n \n Example 1:\n \n \n >>> distanceToCycle(n = 7, edges = [[1,2],[2,4],[4,3],[3,1],[0,1],[5,2],[6,5]])\n >>> [1,0,0,0,0,1,2]\n Explanation:\n The nodes 1, 2, 3, and 4 form the cycle.\n The distance from 0 to 1 is 1.\n The distance from 1 to 1 is 0.\n The distance from 2 to 2 is 0.\n The distance from 3 to 3 is 0.\n The distance from 4 to 4 is 0.\n The distance from 5 to 2 is 1.\n The distance from 6 to 2 is 2.\n \n Example 2:\n \n \n >>> distanceToCycle(n = 9, edges = [[0,1],[1,2],[0,2],[2,6],[6,7],[6,8],[0,3],[3,4],[3,5]])\n >>> [0,0,0,1,2,2,1,2,2]\n Explanation:\n The nodes 0, 1, and 2 form the cycle.\n The distance from 0 to 0 is 0.\n The distance from 1 to 1 is 0.\n The distance from 2 to 2 is 0.\n The distance from 3 to 1 is 1.\n The distance from 4 to 1 is 2.\n The distance from 5 to 1 is 2.\n The distance from 6 to 2 is 1.\n The distance from 7 to 2 is 2.\n The distance from 8 to 2 is 2.\n \"\"\"\n"}
{"task_id": "divide-array-into-equal-pairs", "prompt": "def divideArray(nums: List[int]) -> bool:\n \"\"\"\n You are given an integer array nums consisting of 2 * n integers.\n You need to divide nums into n pairs such that:\n \n Each element belongs to exactly one pair.\n The elements present in a pair are equal.\n \n Return true if nums can be divided into n pairs, otherwise return false.\n \n Example 1:\n \n >>> divideArray(nums = [3,2,3,2,2,2])\n >>> true\n Explanation:\n There are 6 elements in nums, so they should be divided into 6 / 2 = 3 pairs.\n If nums is divided into the pairs (2, 2), (3, 3), and (2, 2), it will satisfy all the conditions.\n \n Example 2:\n \n >>> divideArray(nums = [1,2,3,4])\n >>> false\n Explanation:\n There is no way to divide nums into 4 / 2 = 2 pairs such that the pairs satisfy every condition.\n \"\"\"\n"}
{"task_id": "maximize-number-of-subsequences-in-a-string", "prompt": "def maximumSubsequenceCount(text: str, pattern: str) -> int:\n \"\"\"\n You are given a 0-indexed string text and another 0-indexed string pattern of length 2, both of which consist of only lowercase English letters.\n You can add either pattern[0] or pattern[1] anywhere in text exactly once. Note that the character can be added even at the beginning or at the end of text.\n Return the maximum number of times pattern can occur as a subsequence of the modified text.\n A subsequence is a string that can be derived from another string by deleting some or no characters without changing the order of the remaining characters.\n \n Example 1:\n \n >>> maximumSubsequenceCount(text = \"abdcdbc\", pattern = \"ac\")\n >>> 4\n Explanation:\n If we add pattern[0] = 'a' in between text[1] and text[2], we get \"abadcdbc\". Now, the number of times \"ac\" occurs as a subsequence is 4.\n Some other strings which have 4 subsequences \"ac\" after adding a character to text are \"aabdcdbc\" and \"abdacdbc\".\n However, strings such as \"abdcadbc\", \"abdccdbc\", and \"abdcdbcc\", although obtainable, have only 3 subsequences \"ac\" and are thus suboptimal.\n It can be shown that it is not possible to get more than 4 subsequences \"ac\" by adding only one character.\n \n Example 2:\n \n >>> maximumSubsequenceCount(text = \"aabb\", pattern = \"ab\")\n >>> 6\n Explanation:\n Some of the strings which can be obtained from text and have 6 subsequences \"ab\" are \"aaabb\", \"aaabb\", and \"aabbb\".\n \"\"\"\n"}
{"task_id": "minimum-operations-to-halve-array-sum", "prompt": "def halveArray(nums: List[int]) -> int:\n \"\"\"\n You are given an array nums of positive integers. In one operation, you can choose any number from nums and reduce it to exactly half the number. (Note that you may choose this reduced number in future operations.)\n Return the minimum number of operations to reduce the sum of nums by at least half.\n \n Example 1:\n \n >>> halveArray(nums = [5,19,8,1])\n >>> 3\n Explanation: The initial sum of nums is equal to 5 + 19 + 8 + 1 = 33.\n The following is one of the ways to reduce the sum by at least half:\n Pick the number 19 and reduce it to 9.5.\n Pick the number 9.5 and reduce it to 4.75.\n Pick the number 8 and reduce it to 4.\n The final array is [5, 4.75, 4, 1] with a total sum of 5 + 4.75 + 4 + 1 = 14.75.\n The sum of nums has been reduced by 33 - 14.75 = 18.25, which is at least half of the initial sum, 18.25 >= 33/2 = 16.5.\n Overall, 3 operations were used so we return 3.\n It can be shown that we cannot reduce the sum by at least half in less than 3 operations.\n \n Example 2:\n \n >>> halveArray(nums = [3,8,20])\n >>> 3\n Explanation: The initial sum of nums is equal to 3 + 8 + 20 = 31.\n The following is one of the ways to reduce the sum by at least half:\n Pick the number 20 and reduce it to 10.\n Pick the number 10 and reduce it to 5.\n Pick the number 3 and reduce it to 1.5.\n The final array is [1.5, 8, 5] with a total sum of 1.5 + 8 + 5 = 14.5.\n The sum of nums has been reduced by 31 - 14.5 = 16.5, which is at least half of the initial sum, 16.5 >= 31/2 = 15.5.\n Overall, 3 operations were used so we return 3.\n It can be shown that we cannot reduce the sum by at least half in less than 3 operations.\n \"\"\"\n"}
{"task_id": "minimum-white-tiles-after-covering-with-carpets", "prompt": "def minimumWhiteTiles(floor: str, numCarpets: int, carpetLen: int) -> int:\n \"\"\"\n You are given a 0-indexed binary string floor, which represents the colors of tiles on a floor:\n \n floor[i] = '0' denotes that the ith tile of the floor is colored black.\n On the other hand, floor[i] = '1' denotes that the ith tile of the floor is colored white.\n \n You are also given numCarpets and carpetLen. You have numCarpets black carpets, each of length carpetLen tiles. Cover the tiles with the given carpets such that the number of white tiles still visible is minimum. Carpets may overlap one another.\n Return the minimum number of white tiles still visible.\n \n Example 1:\n \n \n >>> minimumWhiteTiles(floor = \"10110101\", numCarpets = 2, carpetLen = 2)\n >>> 2\n Explanation:\n The figure above shows one way of covering the tiles with the carpets such that only 2 white tiles are visible.\n No other way of covering the tiles with the carpets can leave less than 2 white tiles visible.\n \n Example 2:\n \n \n >>> minimumWhiteTiles(floor = \"11111\", numCarpets = 2, carpetLen = 3)\n >>> 0\n Explanation:\n The figure above shows one way of covering the tiles with the carpets such that no white tiles are visible.\n Note that the carpets are able to overlap one another.\n \"\"\"\n"}
{"task_id": "count-hills-and-valleys-in-an-array", "prompt": "def countHillValley(nums: List[int]) -> int:\n \"\"\"\n You are given a 0-indexed integer array nums. An index i is part of a hill in nums if the closest non-equal neighbors of i are smaller than nums[i]. Similarly, an index i is part of a valley in nums if the closest non-equal neighbors of i are larger than nums[i]. Adjacent indices i and j are part of the same hill or valley if nums[i] == nums[j].\n Note that for an index to be part of a hill or valley, it must have a non-equal neighbor on both the left and right of the index.\n Return the number of hills and valleys in nums.\n \n Example 1:\n \n >>> countHillValley(nums = [2,4,1,1,6,5])\n >>> 3\n Explanation:\n At index 0: There is no non-equal neighbor of 2 on the left, so index 0 is neither a hill nor a valley.\n At index 1: The closest non-equal neighbors of 4 are 2 and 1. Since 4 > 2 and 4 > 1, index 1 is a hill.\n At index 2: The closest non-equal neighbors of 1 are 4 and 6. Since 1 < 4 and 1 < 6, index 2 is a valley.\n At index 3: The closest non-equal neighbors of 1 are 4 and 6. Since 1 < 4 and 1 < 6, index 3 is a valley, but note that it is part of the same valley as index 2.\n At index 4: The closest non-equal neighbors of 6 are 1 and 5. Since 6 > 1 and 6 > 5, index 4 is a hill.\n At index 5: There is no non-equal neighbor of 5 on the right, so index 5 is neither a hill nor a valley.\n There are 3 hills and valleys so we return 3.\n \n Example 2:\n \n >>> countHillValley(nums = [6,6,5,5,4,1])\n >>> 0\n Explanation:\n At index 0: There is no non-equal neighbor of 6 on the left, so index 0 is neither a hill nor a valley.\n At index 1: There is no non-equal neighbor of 6 on the left, so index 1 is neither a hill nor a valley.\n At index 2: The closest non-equal neighbors of 5 are 6 and 4. Since 5 < 6 and 5 > 4, index 2 is neither a hill nor a valley.\n At index 3: The closest non-equal neighbors of 5 are 6 and 4. Since 5 < 6 and 5 > 4, index 3 is neither a hill nor a valley.\n At index 4: The closest non-equal neighbors of 4 are 5 and 1. Since 4 < 5 and 4 > 1, index 4 is neither a hill nor a valley.\n At index 5: There is no non-equal neighbor of 1 on the right, so index 5 is neither a hill nor a valley.\n There are 0 hills and valleys so we return 0.\n \"\"\"\n"}
{"task_id": "count-collisions-on-a-road", "prompt": "def countCollisions(directions: str) -> int:\n \"\"\"\n There are n cars on an infinitely long road. The cars are numbered from 0 to n - 1 from left to right and each car is present at a unique point.\n You are given a 0-indexed string directions of length n. directions[i] can be either 'L', 'R', or 'S' denoting whether the ith car is moving towards the left, towards the right, or staying at its current point respectively. Each moving car has the same speed.\n The number of collisions can be calculated as follows:\n \n When two cars moving in opposite directions collide with each other, the number of collisions increases by 2.\n When a moving car collides with a stationary car, the number of collisions increases by 1.\n \n After a collision, the cars involved can no longer move and will stay at the point where they collided. Other than that, cars cannot change their state or direction of motion.\n Return the total number of collisions that will happen on the road.\n \n Example 1:\n \n >>> countCollisions(directions = \"RLRSLL\")\n >>> 5\n Explanation:\n The collisions that will happen on the road are:\n - Cars 0 and 1 will collide with each other. Since they are moving in opposite directions, the number of collisions becomes 0 + 2 = 2.\n - Cars 2 and 3 will collide with each other. Since car 3 is stationary, the number of collisions becomes 2 + 1 = 3.\n - Cars 3 and 4 will collide with each other. Since car 3 is stationary, the number of collisions becomes 3 + 1 = 4.\n - Cars 4 and 5 will collide with each other. After car 4 collides with car 3, it will stay at the point of collision and get hit by car 5. The number of collisions becomes 4 + 1 = 5.\n Thus, the total number of collisions that will happen on the road is 5.\n \n Example 2:\n \n >>> countCollisions(directions = \"LLRR\")\n >>> 0\n Explanation:\n No cars will collide with each other. Thus, the total number of collisions that will happen on the road is 0.\n \"\"\"\n"}
{"task_id": "maximum-points-in-an-archery-competition", "prompt": "def maximumBobPoints(numArrows: int, aliceArrows: List[int]) -> List[int]:\n \"\"\"\n Alice and Bob are opponents in an archery competition. The competition has set the following rules:\n \n Alice first shoots numArrows arrows and then Bob shoots numArrows arrows.\n The points are then calculated as follows:\n \n The target has integer scoring sections ranging from 0 to 11 inclusive.\n For each section of the target with score k (in between 0 to 11), say Alice and Bob have shot ak and bk arrows on that section respectively. If ak >= bk, then Alice takes k points. If ak < bk, then Bob takes k points.\n However, if ak == bk == 0, then nobody takes k points.\n \n \n \n \n \n For example, if Alice and Bob both shot 2 arrows on the section with score 11, then Alice takes 11 points. On the other hand, if Alice shot 0 arrows on the section with score 11 and Bob shot 2 arrows on that same section, then Bob takes 11 points.\n \n \n You are given the integer numArrows and an integer array aliceArrows of size 12, which represents the number of arrows Alice shot on each scoring section from 0 to 11. Now, Bob wants to maximize the total number of points he can obtain.\n Return the array bobArrows which represents the number of arrows Bob shot on each scoring section from 0 to 11. The sum of the values in bobArrows should equal numArrows.\n If there are multiple ways for Bob to earn the maximum total points, return any one of them.\n \n Example 1:\n \n \n >>> maximumBobPoints(numArrows = 9, aliceArrows = [1,1,0,1,0,0,2,1,0,1,2,0])\n >>> [0,0,0,0,1,1,0,0,1,2,3,1]\n Explanation: The table above shows how the competition is scored.\n Bob earns a total point of 4 + 5 + 8 + 9 + 10 + 11 = 47.\n It can be shown that Bob cannot obtain a score higher than 47 points.\n \n Example 2:\n \n \n >>> maximumBobPoints(numArrows = 3, aliceArrows = [0,0,1,0,0,0,0,0,0,0,0,2])\n >>> [0,0,0,0,0,0,0,0,1,1,1,0]\n Explanation: The table above shows how the competition is scored.\n Bob earns a total point of 8 + 9 + 10 = 27.\n It can be shown that Bob cannot obtain a score higher than 27 points.\n \"\"\"\n"}
{"task_id": "longest-substring-of-one-repeating-character", "prompt": "def longestRepeating(s: str, queryCharacters: str, queryIndices: List[int]) -> List[int]:\n \"\"\"\n You are given a 0-indexed string s. You are also given a 0-indexed string queryCharacters of length k and a 0-indexed array of integer indices queryIndices of length k, both of which are used to describe k queries.\n The ith query updates the character in s at index queryIndices[i] to the character queryCharacters[i].\n Return an array lengths of length k where lengths[i] is the length of the longest substring of s consisting of only one repeating character after the ith query is performed.\n \n Example 1:\n \n >>> longestRepeating(s = \"babacc\", queryCharacters = \"bcb\", queryIndices = [1,3,3])\n >>> [3,3,4]\n Explanation:\n - 1st query updates s = \"bbbacc\". The longest substring consisting of one repeating character is \"bbb\" with length 3.\n - 2nd query updates s = \"bbbccc\".\n The longest substring consisting of one repeating character can be \"bbb\" or \"ccc\" with length 3.\n - 3rd query updates s = \"bbbbcc\". The longest substring consisting of one repeating character is \"bbbb\" with length 4.\n Thus, we return [3,3,4].\n \n Example 2:\n \n >>> longestRepeating(s = \"abyzz\", queryCharacters = \"aa\", queryIndices = [2,1])\n >>> [2,3]\n Explanation:\n - 1st query updates s = \"abazz\". The longest substring consisting of one repeating character is \"zz\" with length 2.\n - 2nd query updates s = \"aaazz\". The longest substring consisting of one repeating character is \"aaa\" with length 3.\n Thus, we return [2,3].\n \"\"\"\n"}
{"task_id": "minimum-health-to-beat-game", "prompt": "def minimumHealth(damage: List[int], armor: int) -> int:\n \"\"\"\n You are playing a game that has n levels numbered from 0 to n - 1. You are given a 0-indexed integer array damage where damage[i] is the amount of health you will lose to complete the ith level.\n You are also given an integer armor. You may use your armor ability at most once during the game on any level which will protect you from at most armor damage.\n You must complete the levels in order and your health must be greater than 0 at all times to beat the game.\n Return the minimum health you need to start with to beat the game.\n \n Example 1:\n \n >>> minimumHealth(damage = [2,7,4,3], armor = 4)\n >>> 13\n Explanation: One optimal way to beat the game starting at 13 health is:\n On round 1, take 2 damage. You have 13 - 2 = 11 health.\n On round 2, take 7 damage. You have 11 - 7 = 4 health.\n On round 3, use your armor to protect you from 4 damage. You have 4 - 0 = 4 health.\n On round 4, take 3 damage. You have 4 - 3 = 1 health.\n Note that 13 is the minimum health you need to start with to beat the game.\n \n Example 2:\n \n >>> minimumHealth(damage = [2,5,3,4], armor = 7)\n >>> 10\n Explanation: One optimal way to beat the game starting at 10 health is:\n On round 1, take 2 damage. You have 10 - 2 = 8 health.\n On round 2, use your armor to protect you from 5 damage. You have 8 - 0 = 8 health.\n On round 3, take 3 damage. You have 8 - 3 = 5 health.\n On round 4, take 4 damage. You have 5 - 4 = 1 health.\n Note that 10 is the minimum health you need to start with to beat the game.\n \n Example 3:\n \n >>> minimumHealth(damage = [3,3,3], armor = 0)\n >>> 10\n Explanation: One optimal way to beat the game starting at 10 health is:\n On round 1, take 3 damage. You have 10 - 3 = 7 health.\n On round 2, take 3 damage. You have 7 - 3 = 4 health.\n On round 3, take 3 damage. You have 4 - 3 = 1 health.\n Note that you did not use your armor ability.\n \"\"\"\n"}
{"task_id": "find-the-difference-of-two-arrays", "prompt": "def findDifference(nums1: List[int], nums2: List[int]) -> List[List[int]]:\n \"\"\"\n Given two 0-indexed integer arrays nums1 and nums2, return a list answer of size 2 where:\n \n answer[0] is a list of all distinct integers in nums1 which are not present in nums2.\n answer[1] is a list of all distinct integers in nums2 which are not present in nums1.\n \n Note that the integers in the lists may be returned in any order.\n \n Example 1:\n \n >>> findDifference(nums1 = [1,2,3], nums2 = [2,4,6])\n >>> [[1,3],[4,6]]\n Explanation:\n For nums1, nums1[1] = 2 is present at index 0 of nums2, whereas nums1[0] = 1 and nums1[2] = 3 are not present in nums2. Therefore, answer[0] = [1,3].\n For nums2, nums2[0] = 2 is present at index 1 of nums1, whereas nums2[1] = 4 and nums2[2] = 6 are not present in nums2. Therefore, answer[1] = [4,6].\n Example 2:\n \n >>> findDifference(nums1 = [1,2,3,3], nums2 = [1,1,2,2])\n >>> [[3],[]]\n Explanation:\n For nums1, nums1[2] and nums1[3] are not present in nums2. Since nums1[2] == nums1[3], their value is only included once and answer[0] = [3].\n Every integer in nums2 is present in nums1. Therefore, answer[1] = [].\n \"\"\"\n"}
{"task_id": "minimum-deletions-to-make-array-beautiful", "prompt": "def minDeletion(nums: List[int]) -> int:\n \"\"\"\n You are given a 0-indexed integer array nums. The array nums is beautiful if:\n \n nums.length is even.\n nums[i] != nums[i + 1] for all i % 2 == 0.\n \n Note that an empty array is considered beautiful.\n You can delete any number of elements from nums. When you delete an element, all the elements to the right of the deleted element will be shifted one unit to the left to fill the gap created and all the elements to the left of the deleted element will remain unchanged.\n Return the minimum number of elements to delete from nums to make it beautiful.\n \n Example 1:\n \n >>> minDeletion(nums = [1,1,2,3,5])\n >>> 1\n Explanation: You can delete either nums[0] or nums[1] to make nums = [1,2,3,5] which is beautiful. It can be proven you need at least 1 deletion to make nums beautiful.\n \n Example 2:\n \n >>> minDeletion(nums = [1,1,2,2,3,3])\n >>> 2\n Explanation: You can delete nums[0] and nums[5] to make nums = [1,2,2,3] which is beautiful. It can be proven you need at least 2 deletions to make nums beautiful.\n \"\"\"\n"}
{"task_id": "find-palindrome-with-fixed-length", "prompt": "def kthPalindrome(queries: List[int], intLength: int) -> List[int]:\n \"\"\"\n Given an integer array queries and a positive integer intLength, return an array answer where answer[i] is either the queries[i]th smallest positive palindrome of length intLength or -1 if no such palindrome exists.\n A palindrome is a number that reads the same backwards and forwards. Palindromes cannot have leading zeros.\n \n Example 1:\n \n >>> kthPalindrome(queries = [1,2,3,4,5,90], intLength = 3)\n >>> [101,111,121,131,141,999]\n Explanation:\n The first few palindromes of length 3 are:\n 101, 111, 121, 131, 141, 151, 161, 171, 181, 191, 202, ...\n The 90th palindrome of length 3 is 999.\n \n Example 2:\n \n >>> kthPalindrome(queries = [2,4,6], intLength = 4)\n >>> [1111,1331,1551]\n Explanation:\n The first six palindromes of length 4 are:\n 1001, 1111, 1221, 1331, 1441, and 1551.\n \"\"\"\n"}
{"task_id": "maximum-value-of-k-coins-from-piles", "prompt": "def maxValueOfCoins(piles: List[List[int]], k: int) -> int:\n \"\"\"\n There are n piles of coins on a table. Each pile consists of a positive number of coins of assorted denominations.\n In one move, you can choose any coin on top of any pile, remove it, and add it to your wallet.\n Given a list piles, where piles[i] is a list of integers denoting the composition of the ith pile from top to bottom, and a positive integer k, return the maximum total value of coins you can have in your wallet if you choose exactly k coins optimally.\n \n Example 1:\n \n \n >>> maxValueOfCoins(piles = [[1,100,3],[7,8,9]], k = 2)\n >>> 101\n Explanation:\n The above diagram shows the different ways we can choose k coins.\n The maximum total we can obtain is 101.\n \n Example 2:\n \n >>> maxValueOfCoins(piles = [[100],[100],[100],[100],[100],[100],[1,1,1,1,1,1,700]], k = 7)\n >>> 706\n Explanation:\n The maximum total can be obtained if we choose all coins from the last pile.\n \"\"\"\n"}
{"task_id": "maximum-sum-score-of-array", "prompt": "def maximumSumScore(nums: List[int]) -> int:\n \"\"\"\n You are given a 0-indexed integer array nums of length n.\n The sum score of nums at an index i where 0 <= i < n is the maximum of:\n \n The sum of the first i + 1 elements of nums.\n The sum of the last n - i elements of nums.\n \n Return the maximum sum score of nums at any index.\n \n Example 1:\n \n >>> maximumSumScore(nums = [4,3,-2,5])\n >>> 10\n Explanation:\n The sum score at index 0 is max(4, 4 + 3 + -2 + 5) = max(4, 10) = 10.\n The sum score at index 1 is max(4 + 3, 3 + -2 + 5) = max(7, 6) = 7.\n The sum score at index 2 is max(4 + 3 + -2, -2 + 5) = max(5, 3) = 5.\n The sum score at index 3 is max(4 + 3 + -2 + 5, 5) = max(10, 5) = 10.\n The maximum sum score of nums is 10.\n \n Example 2:\n \n >>> maximumSumScore(nums = [-3,-5])\n >>> -3\n Explanation:\n The sum score at index 0 is max(-3, -3 + -5) = max(-3, -8) = -3.\n The sum score at index 1 is max(-3 + -5, -5) = max(-8, -5) = -5.\n The maximum sum score of nums is -3.\n \"\"\"\n"}
{"task_id": "minimum-bit-flips-to-convert-number", "prompt": "def minBitFlips(start: int, goal: int) -> int:\n \"\"\"\n A bit flip of a number x is choosing a bit in the binary representation of x and flipping it from either 0 to 1 or 1 to 0.\n \n For example, for x = 7, the binary representation is 111 and we may choose any bit (including any leading zeros not shown) and flip it. We can flip the first bit from the right to get 110, flip the second bit from the right to get 101, flip the fifth bit from the right (a leading zero) to get 10111, etc.\n \n Given two integers start and goal, return the minimum number of bit flips to convert start to goal.\n \n Example 1:\n \n >>> minBitFlips(start = 10, goal = 7)\n >>> 3\n Explanation: The binary representation of 10 and 7 are 1010 and 0111 respectively. We can convert 10 to 7 in 3 steps:\n - Flip the first bit from the right: 1010 -> 1011.\n - Flip the third bit from the right: 1011 -> 1111.\n - Flip the fourth bit from the right: 1111 -> 0111.\n It can be shown we cannot convert 10 to 7 in less than 3 steps. Hence, we return 3.\n Example 2:\n \n >>> minBitFlips(start = 3, goal = 4)\n >>> 3\n Explanation: The binary representation of 3 and 4 are 011 and 100 respectively. We can convert 3 to 4 in 3 steps:\n - Flip the first bit from the right: 011 -> 010.\n - Flip the second bit from the right: 010 -> 000.\n - Flip the third bit from the right: 000 -> 100.\n It can be shown we cannot convert 3 to 4 in less than 3 steps. Hence, we return 3.\n \"\"\"\n"}
{"task_id": "find-triangular-sum-of-an-array", "prompt": "def triangularSum(nums: List[int]) -> int:\n \"\"\"\n You are given a 0-indexed integer array nums, where nums[i] is a digit between 0 and 9 (inclusive).\n The triangular sum of nums is the value of the only element present in nums after the following process terminates:\n \n Let nums comprise of n elements. If n == 1, end the process. Otherwise, create a new 0-indexed integer array newNums of length n - 1.\n For each index i, where 0 <= i <\u00a0n - 1, assign the value of newNums[i] as (nums[i] + nums[i+1]) % 10, where % denotes modulo operator.\n Replace the array nums with newNums.\n Repeat the entire process starting from step 1.\n \n Return the triangular sum of nums.\n \n Example 1:\n \n \n >>> triangularSum(nums = [1,2,3,4,5])\n >>> 8\n Explanation:\n The above diagram depicts the process from which we obtain the triangular sum of the array.\n Example 2:\n \n >>> triangularSum(nums = [5])\n >>> 5\n Explanation:\n Since there is only one element in nums, the triangular sum is the value of that element itself.\n \"\"\"\n"}
{"task_id": "number-of-ways-to-select-buildings", "prompt": "def numberOfWays(s: str) -> int:\n \"\"\"\n You are given a 0-indexed binary string s which represents the types of buildings along a street where:\n \n s[i] = '0' denotes that the ith building is an office and\n s[i] = '1' denotes that the ith building is a restaurant.\n \n As a city official, you would like to select 3 buildings for random inspection. However, to ensure variety, no two consecutive buildings out of the selected buildings can be of the same type.\n \n For example, given s = \"001101\", we cannot select the 1st, 3rd, and 5th buildings as that would form \"011\" which is not allowed due to having two consecutive buildings of the same type.\n \n Return the number of valid ways to select 3 buildings.\n \n Example 1:\n \n >>> numberOfWays(s = \"001101\")\n >>> 6\n Explanation:\n The following sets of indices selected are valid:\n - [0,2,4] from \"001101\" forms \"010\"\n - [0,3,4] from \"001101\" forms \"010\"\n - [1,2,4] from \"001101\" forms \"010\"\n - [1,3,4] from \"001101\" forms \"010\"\n - [2,4,5] from \"001101\" forms \"101\"\n - [3,4,5] from \"001101\" forms \"101\"\n No other selection is valid. Thus, there are 6 total ways.\n \n Example 2:\n \n >>> numberOfWays(s = \"11100\")\n >>> 0\n Explanation: It can be shown that there are no valid selections.\n \"\"\"\n"}
{"task_id": "sum-of-scores-of-built-strings", "prompt": "def sumScores(s: str) -> int:\n \"\"\"\n You are building a string s of length n one character at a time, prepending each new character to the front of the string. The strings are labeled from 1 to n, where the string with length i is labeled si.\n \n For example, for s = \"abaca\", s1 == \"a\", s2 == \"ca\", s3 == \"aca\", etc.\n \n The score of si is the length of the longest common prefix between si and sn (Note that s == sn).\n Given the final string s, return the sum of the score of every si.\n \n Example 1:\n \n >>> sumScores(s = \"babab\")\n >>> 9\n Explanation:\n For s1 == \"b\", the longest common prefix is \"b\" which has a score of 1.\n For s2 == \"ab\", there is no common prefix so the score is 0.\n For s3 == \"bab\", the longest common prefix is \"bab\" which has a score of 3.\n For s4 == \"abab\", there is no common prefix so the score is 0.\n For s5 == \"babab\", the longest common prefix is \"babab\" which has a score of 5.\n The sum of the scores is 1 + 0 + 3 + 0 + 5 = 9, so we return 9.\n Example 2:\n \n >>> sumScores(s = \"azbazbzaz\")\n >>> 14\n Explanation:\n For s2 == \"az\", the longest common prefix is \"az\" which has a score of 2.\n For s6 == \"azbzaz\", the longest common prefix is \"azb\" which has a score of 3.\n For s9 == \"azbazbzaz\", the longest common prefix is \"azbazbzaz\" which has a score of 9.\n For all other si, the score is 0.\n The sum of the scores is 2 + 3 + 9 = 14, so we return 14.\n \"\"\"\n"}
{"task_id": "minimum-number-of-operations-to-convert-time", "prompt": "def convertTime(current: str, correct: str) -> int:\n \"\"\"\n You are given two strings current and correct representing two 24-hour times.\n 24-hour times are formatted as \"HH:MM\", where HH is between 00 and 23, and MM is between 00 and 59. The earliest 24-hour time is 00:00, and the latest is 23:59.\n In one operation you can increase the time current by 1, 5, 15, or 60 minutes. You can perform this operation any number of times.\n Return the minimum number of operations needed to convert current to correct.\n \n Example 1:\n \n >>> convertTime(current = \"02:30\", correct = \"04:35\")\n >>> 3\n Explanation:\n We can convert current to correct in 3 operations as follows:\n - Add 60 minutes to current. current becomes \"03:30\".\n - Add 60 minutes to current. current becomes \"04:30\".\n - Add 5 minutes to current. current becomes \"04:35\".\n It can be proven that it is not possible to convert current to correct in fewer than 3 operations.\n Example 2:\n \n >>> convertTime(current = \"11:00\", correct = \"11:01\")\n >>> 1\n Explanation: We only have to add one minute to current, so the minimum number of operations needed is 1.\n \"\"\"\n"}
{"task_id": "find-players-with-zero-or-one-losses", "prompt": "def findWinners(matches: List[List[int]]) -> List[List[int]]:\n \"\"\"\n You are given an integer array matches where matches[i] = [winneri, loseri] indicates that the player winneri defeated player loseri in a match.\n Return a list answer of size 2 where:\n \n answer[0] is a list of all players that have not lost any matches.\n answer[1] is a list of all players that have lost exactly one match.\n \n The values in the two lists should be returned in increasing order.\n Note:\n \n You should only consider the players that have played at least one match.\n The testcases will be generated such that no two matches will have the same outcome.\n \n \n Example 1:\n \n >>> findWinners(matches = [[1,3],[2,3],[3,6],[5,6],[5,7],[4,5],[4,8],[4,9],[10,4],[10,9]])\n >>> [[1,2,10],[4,5,7,8]]\n Explanation:\n Players 1, 2, and 10 have not lost any matches.\n Players 4, 5, 7, and 8 each have lost one match.\n Players 3, 6, and 9 each have lost two matches.\n Thus, answer[0] = [1,2,10] and answer[1] = [4,5,7,8].\n \n Example 2:\n \n >>> findWinners(matches = [[2,3],[1,3],[5,4],[6,4]])\n >>> [[1,2,5,6],[]]\n Explanation:\n Players 1, 2, 5, and 6 have not lost any matches.\n Players 3 and 4 each have lost two matches.\n Thus, answer[0] = [1,2,5,6] and answer[1] = [].\n \"\"\"\n"}
{"task_id": "maximum-candies-allocated-to-k-children", "prompt": "def maximumCandies(candies: List[int], k: int) -> int:\n \"\"\"\n You are given a 0-indexed integer array candies. Each element in the array denotes a pile of candies of size candies[i]. You can divide each pile into any number of sub piles, but you cannot merge two piles together.\n You are also given an integer k. You should allocate piles of candies to k children such that each child gets the same number of candies. Each child can be allocated candies from only one pile of candies and some piles of candies may go unused.\n Return the maximum number of candies each child can get.\n \n Example 1:\n \n >>> maximumCandies(candies = [5,8,6], k = 3)\n >>> 5\n Explanation: We can divide candies[1] into 2 piles of size 5 and 3, and candies[2] into 2 piles of size 5 and 1. We now have five piles of candies of sizes 5, 5, 3, 5, and 1. We can allocate the 3 piles of size 5 to 3 children. It can be proven that each child cannot receive more than 5 candies.\n \n Example 2:\n \n >>> maximumCandies(candies = [2,5], k = 11)\n >>> 0\n Explanation: There are 11 children but only 7 candies in total, so it is impossible to ensure each child receives at least one candy. Thus, each child gets no candy and the answer is 0.\n \"\"\"\n"}
{"task_id": "check-if-an-array-is-consecutive", "prompt": "def isConsecutive(nums: List[int]) -> bool:\n \"\"\"\n Given an integer array nums, return true if nums is consecutive, otherwise return false.\n An array is consecutive if it contains every number in the range [x, x + n - 1] (inclusive), where x is the minimum number in the array and n is the length of the array.\n \n Example 1:\n \n >>> isConsecutive(nums = [1,3,4,2])\n >>> true\n Explanation:\n The minimum value is 1 and the length of nums is 4.\n All of the values in the range [x, x + n - 1] = [1, 1 + 4 - 1] = [1, 4] = (1, 2, 3, 4) occur in nums.\n Therefore, nums is consecutive.\n \n Example 2:\n \n >>> isConsecutive(nums = [1,3])\n >>> false\n Explanation:\n The minimum value is 1 and the length of nums is 2.\n The value 2 in the range [x, x + n - 1] = [1, 1 + 2 - 1], = [1, 2] = (1, 2) does not occur in nums.\n Therefore, nums is not consecutive.\n \n Example 3:\n \n >>> isConsecutive(nums = [3,5,4])\n >>> true\n Explanation:\n The minimum value is 3 and the length of nums is 3.\n All of the values in the range [x, x + n - 1] = [3, 3 + 3 - 1] = [3, 5] = (3, 4, 5) occur in nums.\n Therefore, nums is consecutive.\n \"\"\"\n"}
{"task_id": "largest-number-after-digit-swaps-by-parity", "prompt": "def largestInteger(num: int) -> int:\n \"\"\"\n You are given a positive integer num. You may swap any two digits of num that have the same parity (i.e. both odd digits or both even digits).\n Return the largest possible value of num after any number of swaps.\n \n Example 1:\n \n >>> largestInteger(num = 1234)\n >>> 3412\n Explanation: Swap the digit 3 with the digit 1, this results in the number 3214.\n Swap the digit 2 with the digit 4, this results in the number 3412.\n Note that there may be other sequences of swaps but it can be shown that 3412 is the largest possible number.\n Also note that we may not swap the digit 4 with the digit 1 since they are of different parities.\n \n Example 2:\n \n >>> largestInteger(num = 65875)\n >>> 87655\n Explanation: Swap the digit 8 with the digit 6, this results in the number 85675.\n Swap the first digit 5 with the digit 7, this results in the number 87655.\n Note that there may be other sequences of swaps but it can be shown that 87655 is the largest possible number.\n \"\"\"\n"}
{"task_id": "minimize-result-by-adding-parentheses-to-expression", "prompt": "def minimizeResult(expression: str) -> str:\n \"\"\"\n You are given a 0-indexed string expression of the form \"+\" where and represent positive integers.\n Add a pair of parentheses to expression such that after the addition of parentheses, expression is a valid mathematical expression and evaluates to the smallest possible value. The left parenthesis must be added to the left of '+' and the right parenthesis must be added to the right of '+'.\n Return expression after adding a pair of parentheses such that expression evaluates to the smallest possible value. If there are multiple answers that yield the same result, return any of them.\n The input has been generated such that the original value of expression, and the value of expression after adding any pair of parentheses that meets the requirements fits within a signed 32-bit integer.\n \n Example 1:\n \n >>> minimizeResult(expression = \"247+38\")\n >>> \"2(47+38)\"\n Explanation: The expression evaluates to 2 * (47 + 38) = 2 * 85 = 170.\n Note that \"2(4)7+38\" is invalid because the right parenthesis must be to the right of the '+'.\n It can be shown that 170 is the smallest possible value.\n \n Example 2:\n \n >>> minimizeResult(expression = \"12+34\")\n >>> \"1(2+3)4\"\n Explanation: The expression evaluates to 1 * (2 + 3) * 4 = 1 * 5 * 4 = 20.\n \n Example 3:\n \n >>> minimizeResult(expression = \"999+999\")\n >>> \"(999+999)\"\n Explanation: The expression evaluates to 999 + 999 = 1998.\n \"\"\"\n"}
{"task_id": "maximum-product-after-k-increments", "prompt": "def maximumProduct(nums: List[int], k: int) -> int:\n \"\"\"\n You are given an array of non-negative integers nums and an integer k. In one operation, you may choose any element from nums and increment it by 1.\n Return the maximum product of nums after at most k operations. Since the answer may be very large, return it modulo 109 + 7. Note that you should maximize the product before taking the modulo.\n \n Example 1:\n \n >>> maximumProduct(nums = [0,4], k = 5)\n >>> 20\n Explanation: Increment the first number 5 times.\n Now nums = [5, 4], with a product of 5 * 4 = 20.\n It can be shown that 20 is maximum product possible, so we return 20.\n Note that there may be other ways to increment nums to have the maximum product.\n \n Example 2:\n \n >>> maximumProduct(nums = [6,3,3,2], k = 2)\n >>> 216\n Explanation: Increment the second number 1 time and increment the fourth number 1 time.\n Now nums = [6, 4, 3, 3], with a product of 6 * 4 * 3 * 3 = 216.\n It can be shown that 216 is maximum product possible, so we return 216.\n Note that there may be other ways to increment nums to have the maximum product.\n \"\"\"\n"}
{"task_id": "maximum-total-beauty-of-the-gardens", "prompt": "def maximumBeauty(flowers: List[int], newFlowers: int, target: int, full: int, partial: int) -> int:\n \"\"\"\n Alice is a caretaker of n gardens and she wants to plant flowers to maximize the total beauty of all her gardens.\n You are given a 0-indexed integer array flowers of size n, where flowers[i] is the number of flowers already planted in the ith garden. Flowers that are already planted cannot be removed. You are then given another integer newFlowers, which is the maximum number of flowers that Alice can additionally plant. You are also given the integers target, full, and partial.\n A garden is considered complete if it has at least target flowers. The total beauty of the gardens is then determined as the sum of the following:\n \n The number of complete gardens multiplied by full.\n The minimum number of flowers in any of the incomplete gardens multiplied by partial. If there are no incomplete gardens, then this value will be 0.\n \n Return the maximum total beauty that Alice can obtain after planting at most newFlowers flowers.\n \n Example 1:\n \n >>> maximumBeauty(flowers = [1,3,1,1], newFlowers = 7, target = 6, full = 12, partial = 1)\n >>> 14\n Explanation: Alice can plant\n - 2 flowers in the 0th garden\n - 3 flowers in the 1st garden\n - 1 flower in the 2nd garden\n - 1 flower in the 3rd garden\n The gardens will then be [3,6,2,2]. She planted a total of 2 + 3 + 1 + 1 = 7 flowers.\n There is 1 garden that is complete.\n The minimum number of flowers in the incomplete gardens is 2.\n Thus, the total beauty is 1 * 12 + 2 * 1 = 12 + 2 = 14.\n No other way of planting flowers can obtain a total beauty higher than 14.\n \n Example 2:\n \n >>> maximumBeauty(flowers = [2,4,5,3], newFlowers = 10, target = 5, full = 2, partial = 6)\n >>> 30\n Explanation: Alice can plant\n - 3 flowers in the 0th garden\n - 0 flowers in the 1st garden\n - 0 flowers in the 2nd garden\n - 2 flowers in the 3rd garden\n The gardens will then be [5,4,5,5]. She planted a total of 3 + 0 + 0 + 2 = 5 flowers.\n There are 3 gardens that are complete.\n The minimum number of flowers in the incomplete gardens is 4.\n Thus, the total beauty is 3 * 2 + 4 * 6 = 6 + 24 = 30.\n No other way of planting flowers can obtain a total beauty higher than 30.\n Note that Alice could make all the gardens complete but in this case, she would obtain a lower total beauty.\n \"\"\"\n"}
{"task_id": "add-two-integers", "prompt": "def sum(num1: int, num2: int) -> int:\n \"\"\"\n Given two integers num1 and num2, return the sum of the two integers.\n \n Example 1:\n \n >>> sum(num1 = 12, num2 = 5)\n >>> 17\n Explanation: num1 is 12, num2 is 5, and their sum is 12 + 5 = 17, so 17 is returned.\n \n Example 2:\n \n >>> sum(num1 = -10, num2 = 4)\n >>> -6\n Explanation: num1 + num2 = -6, so -6 is returned.\n \"\"\"\n"}
{"task_id": "root-equals-sum-of-children", "prompt": "# class TreeNode:\n# def __init__(val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def checkTree(root: Optional[TreeNode]) -> bool:\n \"\"\"\n You are given the root of a binary tree that consists of exactly 3 nodes: the root, its left child, and its right child.\n Return true if the value of the root is equal to the sum of the values of its two children, or false otherwise.\n \n Example 1:\n \n \n >>> __init__(root = [10,4,6])\n >>> true\n Explanation: The values of the root, its left child, and its right child are 10, 4, and 6, respectively.\n 10 is equal to 4 + 6, so we return true.\n \n Example 2:\n \n \n >>> __init__(root = [5,3,1])\n >>> false\n Explanation: The values of the root, its left child, and its right child are 5, 3, and 1, respectively.\n 5 is not equal to 3 + 1, so we return false.\n \"\"\"\n"}
{"task_id": "count-positions-on-street-with-required-brightness", "prompt": "def meetRequirement(n: int, lights: List[List[int]], requirement: List[int]) -> int:\n \"\"\"\n You are given an integer n. A perfectly straight street is represented by a number line ranging from 0 to n - 1. You are given a 2D integer array lights representing the street lamp(s) on the street. Each lights[i] = [positioni, rangei] indicates that there is a street lamp at position positioni that lights up the area from [max(0, positioni - rangei), min(n - 1, positioni + rangei)] (inclusive).\n The brightness of a position p is defined as the number of street lamps that light up the position p. You are given a 0-indexed integer array requirement of size n where requirement[i] is the minimum brightness of the ith position on the street.\n Return the number of positions i on the street between 0 and n - 1 that have a brightness of at least requirement[i].\n \n Example 1:\n \n \n >>> meetRequirement(n = 5, lights = [[0,1],[2,1],[3,2]], requirement = [0,2,1,4,1])\n >>> 4\n Explanation:\n - The first street lamp lights up the area from [max(0, 0 - 1), min(n - 1, 0 + 1)] = [0, 1] (inclusive).\n - The second street lamp lights up the area from [max(0, 2 - 1), min(n - 1, 2 + 1)] = [1, 3] (inclusive).\n - The third street lamp lights up the area from [max(0, 3 - 2), min(n - 1, 3 + 2)] = [1, 4] (inclusive).\n \n - Position 0 is covered by the first street lamp. It is covered by 1 street lamp which is greater than requirement[0].\n - Position 1 is covered by the first, second, and third street lamps. It is covered by 3 street lamps which is greater than requirement[1].\n - Position 2 is covered by the second and third street lamps. It is covered by 2 street lamps which is greater than requirement[2].\n - Position 3 is covered by the second and third street lamps. It is covered by 2 street lamps which is less than requirement[3].\n - Position 4 is covered by the third street lamp. It is covered by 1 street lamp which is equal to requirement[4].\n \n Positions 0, 1, 2, and 4 meet the requirement so we return 4.\n \n Example 2:\n \n >>> meetRequirement(n = 1, lights = [[0,1]], requirement = [2])\n >>> 0\n Explanation:\n - The first street lamp lights up the area from [max(0, 0 - 1), min(n - 1, 0 + 1)] = [0, 0] (inclusive).\n - Position 0 is covered by the first street lamp. It is covered by 1 street lamp which is less than requirement[0].\n - We return 0 because no position meets their brightness requirement.\n \"\"\"\n"}
{"task_id": "find-closest-number-to-zero", "prompt": "def findClosestNumber(nums: List[int]) -> int:\n \"\"\"\n Given an integer array nums of size n, return the number with the value closest to 0 in nums. If there are multiple answers, return the number with the largest value.\n \n Example 1:\n \n >>> findClosestNumber(nums = [-4,-2,1,4,8])\n >>> 1\n Explanation:\n The distance from -4 to 0 is |-4| = 4.\n The distance from -2 to 0 is |-2| = 2.\n The distance from 1 to 0 is |1| = 1.\n The distance from 4 to 0 is |4| = 4.\n The distance from 8 to 0 is |8| = 8.\n Thus, the closest number to 0 in the array is 1.\n \n Example 2:\n \n >>> findClosestNumber(nums = [2,-1,1])\n >>> 1\n Explanation: 1 and -1 are both the closest numbers to 0, so 1 being larger is returned.\n \"\"\"\n"}
{"task_id": "number-of-ways-to-buy-pens-and-pencils", "prompt": "def waysToBuyPensPencils(total: int, cost1: int, cost2: int) -> int:\n \"\"\"\n You are given an integer total indicating the amount of money you have. You are also given two integers cost1 and cost2 indicating the price of a pen and pencil respectively. You can spend part or all of your money to buy multiple quantities (or none) of each kind of writing utensil.\n Return the number of distinct ways you can buy some number of pens and pencils.\n \n Example 1:\n \n >>> waysToBuyPensPencils(total = 20, cost1 = 10, cost2 = 5)\n >>> 9\n Explanation: The price of a pen is 10 and the price of a pencil is 5.\n - If you buy 0 pens, you can buy 0, 1, 2, 3, or 4 pencils.\n - If you buy 1 pen, you can buy 0, 1, or 2 pencils.\n - If you buy 2 pens, you cannot buy any pencils.\n The total number of ways to buy pens and pencils is 5 + 3 + 1 = 9.\n \n Example 2:\n \n >>> waysToBuyPensPencils(total = 5, cost1 = 10, cost2 = 10)\n >>> 1\n Explanation: The price of both pens and pencils are 10, which cost more than total, so you cannot buy any writing utensils. Therefore, there is only 1 way: buy 0 pens and 0 pencils.\n \"\"\"\n"}
{"task_id": "maximum-score-of-a-node-sequence", "prompt": "def maximumScore(scores: List[int], edges: List[List[int]]) -> int:\n \"\"\"\n There is an undirected graph with n nodes, numbered from 0 to n - 1.\n You are given a 0-indexed integer array scores of length n where scores[i] denotes the score of node i. You are also given a 2D integer array edges where edges[i] = [ai, bi] denotes that there exists an undirected edge connecting nodes ai and bi.\n A node sequence is valid if it meets the following conditions:\n \n There is an edge connecting every pair of adjacent nodes in the sequence.\n No node appears more than once in the sequence.\n \n The score of a node sequence is defined as the sum of the scores of the nodes in the sequence.\n Return the maximum score of a valid node sequence with a length of 4. If no such sequence exists, return -1.\n \n Example 1:\n \n \n >>> maximumScore(scores = [5,2,9,8,4], edges = [[0,1],[1,2],[2,3],[0,2],[1,3],[2,4]])\n >>> 24\n Explanation: The figure above shows the graph and the chosen node sequence [0,1,2,3].\n The score of the node sequence is 5 + 2 + 9 + 8 = 24.\n It can be shown that no other node sequence has a score of more than 24.\n Note that the sequences [3,1,2,0] and [1,0,2,3] are also valid and have a score of 24.\n The sequence [0,3,2,4] is not valid since no edge connects nodes 0 and 3.\n \n Example 2:\n \n \n >>> maximumScore(scores = [9,20,6,4,11,12], edges = [[0,3],[5,3],[2,4],[1,3]])\n >>> -1\n Explanation: The figure above shows the graph.\n There are no valid node sequences of length 4, so we return -1.\n \"\"\"\n"}
{"task_id": "calculate-digit-sum-of-a-string", "prompt": "def digitSum(s: str, k: int) -> str:\n \"\"\"\n You are given a string s consisting of digits and an integer k.\n A round can be completed if the length of s is greater than k. In one round, do the following:\n \n Divide s into consecutive groups of size k such that the first k characters are in the first group, the next k characters are in the second group, and so on. Note that the size of the last group can be smaller than k.\n Replace each group of s with a string representing the sum of all its digits. For example, \"346\" is replaced with \"13\" because 3 + 4 + 6 = 13.\n Merge consecutive groups together to form a new string. If the length of the string is greater than k, repeat from step 1.\n \n Return s after all rounds have been completed.\n \n Example 1:\n \n >>> digitSum(s = \"11111222223\", k = 3)\n >>> \"135\"\n Explanation:\n - For the first round, we divide s into groups of size 3: \"111\", \"112\", \"222\", and \"23\".\n \u200b\u200b\u200b\u200b\u200bThen we calculate the digit sum of each group: 1 + 1 + 1 = 3, 1 + 1 + 2 = 4, 2 + 2 + 2 = 6, and 2 + 3 = 5.\n \u00a0 So, s becomes \"3\" + \"4\" + \"6\" + \"5\" = \"3465\" after the first round.\n - For the second round, we divide s into \"346\" and \"5\".\n \u00a0 Then we calculate the digit sum of each group: 3 + 4 + 6 = 13, 5 = 5.\n \u00a0 So, s becomes \"13\" + \"5\" = \"135\" after second round.\n Now, s.length <= k, so we return \"135\" as the answer.\n \n Example 2:\n \n >>> digitSum(s = \"00000000\", k = 3)\n >>> \"000\"\n Explanation:\n We divide s into \"000\", \"000\", and \"00\".\n Then we calculate the digit sum of each group: 0 + 0 + 0 = 0, 0 + 0 + 0 = 0, and 0 + 0 = 0.\n s becomes \"0\" + \"0\" + \"0\" = \"000\", whose length is equal to k, so we return \"000\".\n \"\"\"\n"}
{"task_id": "minimum-rounds-to-complete-all-tasks", "prompt": "def minimumRounds(tasks: List[int]) -> int:\n \"\"\"\n You are given a 0-indexed integer array tasks, where tasks[i] represents the difficulty level of a task. In each round, you can complete either 2 or 3 tasks of the same difficulty level.\n Return the minimum rounds required to complete all the tasks, or -1 if it is not possible to complete all the tasks.\n \n Example 1:\n \n >>> minimumRounds(tasks = [2,2,3,3,2,4,4,4,4,4])\n >>> 4\n Explanation: To complete all the tasks, a possible plan is:\n - In the first round, you complete 3 tasks of difficulty level 2.\n - In the second round, you complete 2 tasks of difficulty level 3.\n - In the third round, you complete 3 tasks of difficulty level 4.\n - In the fourth round, you complete 2 tasks of difficulty level 4.\n It can be shown that all the tasks cannot be completed in fewer than 4 rounds, so the answer is 4.\n \n Example 2:\n \n >>> minimumRounds(tasks = [2,3,3])\n >>> -1\n Explanation: There is only 1 task of difficulty level 2, but in each round, you can only complete either 2 or 3 tasks of the same difficulty level. Hence, you cannot complete all the tasks, and the answer is -1.\n \"\"\"\n"}
{"task_id": "maximum-trailing-zeros-in-a-cornered-path", "prompt": "def maxTrailingZeros(grid: List[List[int]]) -> int:\n \"\"\"\n You are given a 2D integer array grid of size m x n, where each cell contains a positive integer.\n A cornered path is defined as a set of adjacent cells with at most one turn. More specifically, the path should exclusively move either horizontally or vertically up to the turn (if there is one), without returning to a previously visited cell. After the turn, the path will then move exclusively in the alternate direction: move vertically if it moved horizontally, and vice versa, also without returning to a previously visited cell.\n The product of a path is defined as the product of all the values in the path.\n Return the maximum number of trailing zeros in the product of a cornered path found in grid.\n Note:\n \n Horizontal movement means moving in either the left or right direction.\n Vertical movement means moving in either the up or down direction.\n \n \n Example 1:\n \n \n >>> maxTrailingZeros(grid = [[23,17,15,3,20],[8,1,20,27,11],[9,4,6,2,21],[40,9,1,10,6],[22,7,4,5,3]])\n >>> 3\n Explanation: The grid on the left shows a valid cornered path.\n It has a product of 15 * 20 * 6 * 1 * 10 = 18000 which has 3 trailing zeros.\n It can be shown that this is the maximum trailing zeros in the product of a cornered path.\n \n The grid in the middle is not a cornered path as it has more than one turn.\n The grid on the right is not a cornered path as it requires a return to a previously visited cell.\n \n Example 2:\n \n \n >>> maxTrailingZeros(grid = [[4,3,2],[7,6,1],[8,8,8]])\n >>> 0\n Explanation: The grid is shown in the figure above.\n There are no cornered paths in the grid that result in a product with a trailing zero.\n \"\"\"\n"}
{"task_id": "longest-path-with-different-adjacent-characters", "prompt": "def longestPath(parent: List[int], s: str) -> int:\n \"\"\"\n You are given a tree (i.e. a connected, undirected graph that has no cycles) rooted at node 0 consisting of n nodes numbered from 0 to n - 1. The tree is represented by a 0-indexed array parent of size n, where parent[i] is the parent of node i. Since node 0 is the root, parent[0] == -1.\n You are also given a string s of length n, where s[i] is the character assigned to node i.\n Return the length of the longest path in the tree such that no pair of adjacent nodes on the path have the same character assigned to them.\n \n Example 1:\n \n \n >>> longestPath(parent = [-1,0,0,1,1,2], s = \"abacbe\")\n >>> 3\n Explanation: The longest path where each two adjacent nodes have different characters in the tree is the path: 0 -> 1 -> 3. The length of this path is 3, so 3 is returned.\n It can be proven that there is no longer path that satisfies the conditions.\n \n Example 2:\n \n \n >>> longestPath(parent = [-1,0,0,0], s = \"aabc\")\n >>> 3\n Explanation: The longest path where each two adjacent nodes have different characters is the path: 2 -> 0 -> 3. The length of this path is 3, so 3 is returned.\n \"\"\"\n"}
{"task_id": "maximum-cost-of-trip-with-k-highways", "prompt": "def maximumCost(n: int, highways: List[List[int]], k: int) -> int:\n \"\"\"\n A series of highways connect n cities numbered from 0 to n - 1. You are given a 2D integer array highways where highways[i] = [city1i, city2i, tolli] indicates that there is a highway that connects city1i and city2i, allowing a car to go from city1i to city2i and vice versa for a cost of tolli.\n You are also given an integer k. You are going on a trip that crosses exactly k highways. You may start at any city, but you may only visit each city at most once during your trip.\n Return the maximum cost of your trip. If there is no trip that meets the requirements, return -1.\n \n Example 1:\n \n \n >>> maximumCost(n = 5, highways = [[0,1,4],[2,1,3],[1,4,11],[3,2,3],[3,4,2]], k = 3)\n >>> 17\n Explanation:\n One possible trip is to go from 0 -> 1 -> 4 -> 3. The cost of this trip is 4 + 11 + 2 = 17.\n Another possible trip is to go from 4 -> 1 -> 2 -> 3. The cost of this trip is 11 + 3 + 3 = 17.\n It can be proven that 17 is the maximum possible cost of any valid trip.\n \n Note that the trip 4 -> 1 -> 0 -> 1 is not allowed because you visit the city 1 twice.\n \n Example 2:\n \n \n >>> maximumCost(n = 4, highways = [[0,1,3],[2,3,2]], k = 2)\n >>> -1\n Explanation: There are no valid trips of length 2, so return -1.\n \"\"\"\n"}
{"task_id": "intersection-of-multiple-arrays", "prompt": "def intersection(nums: List[List[int]]) -> List[int]:\n \"\"\"\n Given a 2D integer array nums where nums[i] is a non-empty array of distinct positive integers, return the list of integers that are present in each array of nums sorted in ascending order.\n \n Example 1:\n \n >>> intersection(nums = [[3,1,2,4,5],[1,2,3,4],[3,4,5,6]])\n >>> [3,4]\n Explanation:\n The only integers present in each of nums[0] = [3,1,2,4,5], nums[1] = [1,2,3,4], and nums[2] = [3,4,5,6] are 3 and 4, so we return [3,4].\n Example 2:\n \n >>> intersection(nums = [[1,2,3],[4,5,6]])\n >>> []\n Explanation:\n There does not exist any integer present both in nums[0] and nums[1], so we return an empty list [].\n \"\"\"\n"}
{"task_id": "count-lattice-points-inside-a-circle", "prompt": "def countLatticePoints(circles: List[List[int]]) -> int:\n \"\"\"\n Given a 2D integer array circles where circles[i] = [xi, yi, ri] represents the center (xi, yi) and radius ri of the ith circle drawn on a grid, return the number of lattice points that are present inside at least one circle.\n Note:\n \n A lattice point is a point with integer coordinates.\n Points that lie on the circumference of a circle are also considered to be inside it.\n \n \n Example 1:\n \n \n >>> countLatticePoints(circles = [[2,2,1]])\n >>> 5\n Explanation:\n The figure above shows the given circle.\n The lattice points present inside the circle are (1, 2), (2, 1), (2, 2), (2, 3), and (3, 2) and are shown in green.\n Other points such as (1, 1) and (1, 3), which are shown in red, are not considered inside the circle.\n Hence, the number of lattice points present inside at least one circle is 5.\n Example 2:\n \n \n >>> countLatticePoints(circles = [[2,2,2],[3,4,1]])\n >>> 16\n Explanation:\n The figure above shows the given circles.\n There are exactly 16 lattice points which are present inside at least one circle.\n Some of them are (0, 2), (2, 0), (2, 4), (3, 2), and (4, 4).\n \"\"\"\n"}
{"task_id": "count-number-of-rectangles-containing-each-point", "prompt": "def countRectangles(rectangles: List[List[int]], points: List[List[int]]) -> List[int]:\n \"\"\"\n You are given a 2D integer array rectangles where rectangles[i] = [li, hi] indicates that ith rectangle has a length of li and a height of hi. You are also given a 2D integer array points where points[j] = [xj, yj] is a point with coordinates (xj, yj).\n The ith rectangle has its bottom-left corner point at the coordinates (0, 0) and its top-right corner point at (li, hi).\n Return an integer array count of length points.length where count[j] is the number of rectangles that contain the jth point.\n The ith rectangle contains the jth point if 0 <= xj <= li and 0 <= yj <= hi. Note that points that lie on the edges of a rectangle are also considered to be contained by that rectangle.\n \n Example 1:\n \n \n >>> countRectangles(rectangles = [[1,2],[2,3],[2,5]], points = [[2,1],[1,4]])\n >>> [2,1]\n Explanation:\n The first rectangle contains no points.\n The second rectangle contains only the point (2, 1).\n The third rectangle contains the points (2, 1) and (1, 4).\n The number of rectangles that contain the point (2, 1) is 2.\n The number of rectangles that contain the point (1, 4) is 1.\n Therefore, we return [2, 1].\n \n Example 2:\n \n \n >>> countRectangles(rectangles = [[1,1],[2,2],[3,3]], points = [[1,3],[1,1]])\n >>> [1,3]\n Explanation:\n The first rectangle contains only the point (1, 1).\n The second rectangle contains only the point (1, 1).\n The third rectangle contains the points (1, 3) and (1, 1).\n The number of rectangles that contain the point (1, 3) is 1.\n The number of rectangles that contain the point (1, 1) is 3.\n Therefore, we return [1, 3].\n \"\"\"\n"}
{"task_id": "number-of-flowers-in-full-bloom", "prompt": "def fullBloomFlowers(flowers: List[List[int]], people: List[int]) -> List[int]:\n \"\"\"\n You are given a 0-indexed 2D integer array flowers, where flowers[i] = [starti, endi] means the ith flower will be in full bloom from starti to endi (inclusive). You are also given a 0-indexed integer array people of size n, where people[i] is the time that the ith person will arrive to see the flowers.\n Return an integer array answer of size n, where answer[i] is the number of flowers that are in full bloom when the ith person arrives.\n \n Example 1:\n \n \n >>> fullBloomFlowers(flowers = [[1,6],[3,7],[9,12],[4,13]], people = [2,3,7,11])\n >>> [1,2,2,2]\n Explanation: The figure above shows the times when the flowers are in full bloom and when the people arrive.\n For each person, we return the number of flowers in full bloom during their arrival.\n \n Example 2:\n \n \n >>> fullBloomFlowers(flowers = [[1,10],[3,3]], people = [3,3,2])\n >>> [2,2,1]\n Explanation: The figure above shows the times when the flowers are in full bloom and when the people arrive.\n For each person, we return the number of flowers in full bloom during their arrival.\n \"\"\"\n"}
{"task_id": "count-prefixes-of-a-given-string", "prompt": "def countPrefixes(words: List[str], s: str) -> int:\n \"\"\"\n You are given a string array words and a string s, where words[i] and s comprise only of lowercase English letters.\n Return the number of strings in words that are a prefix of s.\n A prefix of a string is a substring that occurs at the beginning of the string. A substring is a contiguous sequence of characters within a string.\n \n Example 1:\n \n >>> countPrefixes(words = [\"a\",\"b\",\"c\",\"ab\",\"bc\",\"abc\"], s = \"abc\")\n >>> 3\n Explanation:\n The strings in words which are a prefix of s = \"abc\" are:\n \"a\", \"ab\", and \"abc\".\n Thus the number of strings in words which are a prefix of s is 3.\n Example 2:\n \n >>> countPrefixes(words = [\"a\",\"a\"], s = \"aa\")\n >>> 2\n Explanation:\n Both of the strings are a prefix of s.\n Note that the same string can occur multiple times in words, and it should be counted each time.\n \"\"\"\n"}
{"task_id": "minimum-average-difference", "prompt": "def minimumAverageDifference(nums: List[int]) -> int:\n \"\"\"\n You are given a 0-indexed integer array nums of length n.\n The average difference of the index i is the absolute difference between the average of the first i + 1 elements of nums and the average of the last n - i - 1 elements. Both averages should be rounded down to the nearest integer.\n Return the index with the minimum average difference. If there are multiple such indices, return the smallest one.\n Note:\n \n The absolute difference of two numbers is the absolute value of their difference.\n The average of n elements is the sum of the n elements divided (integer division) by n.\n The average of 0 elements is considered to be 0.\n \n \n Example 1:\n \n >>> minimumAverageDifference(nums = [2,5,3,9,5,3])\n >>> 3\n Explanation:\n - The average difference of index 0 is: |2 / 1 - (5 + 3 + 9 + 5 + 3) / 5| = |2 / 1 - 25 / 5| = |2 - 5| = 3.\n - The average difference of index 1 is: |(2 + 5) / 2 - (3 + 9 + 5 + 3) / 4| = |7 / 2 - 20 / 4| = |3 - 5| = 2.\n - The average difference of index 2 is: |(2 + 5 + 3) / 3 - (9 + 5 + 3) / 3| = |10 / 3 - 17 / 3| = |3 - 5| = 2.\n - The average difference of index 3 is: |(2 + 5 + 3 + 9) / 4 - (5 + 3) / 2| = |19 / 4 - 8 / 2| = |4 - 4| = 0.\n - The average difference of index 4 is: |(2 + 5 + 3 + 9 + 5) / 5 - 3 / 1| = |24 / 5 - 3 / 1| = |4 - 3| = 1.\n - The average difference of index 5 is: |(2 + 5 + 3 + 9 + 5 + 3) / 6 - 0| = |27 / 6 - 0| = |4 - 0| = 4.\n The average difference of index 3 is the minimum average difference so return 3.\n \n Example 2:\n \n >>> minimumAverageDifference(nums = [0])\n >>> 0\n Explanation:\n The only index is 0 so return 0.\n The average difference of index 0 is: |0 / 1 - 0| = |0 - 0| = 0.\n \"\"\"\n"}
{"task_id": "count-unguarded-cells-in-the-grid", "prompt": "def countUnguarded(m: int, n: int, guards: List[List[int]], walls: List[List[int]]) -> int:\n \"\"\"\n You are given two integers m and n representing a 0-indexed m x n grid. You are also given two 2D integer arrays guards and walls where guards[i] = [rowi, coli] and walls[j] = [rowj, colj] represent the positions of the ith guard and jth wall respectively.\n A guard can see every cell in the four cardinal directions (north, east, south, or west) starting from their position unless obstructed by a wall or another guard. A cell is guarded if there is at least one guard that can see it.\n Return the number of unoccupied cells that are not guarded.\n \n Example 1:\n \n \n >>> countUnguarded(m = 4, n = 6, guards = [[0,0],[1,1],[2,3]], walls = [[0,1],[2,2],[1,4]])\n >>> 7\n Explanation: The guarded and unguarded cells are shown in red and green respectively in the above diagram.\n There are a total of 7 unguarded cells, so we return 7.\n \n Example 2:\n \n \n >>> countUnguarded(m = 3, n = 3, guards = [[1,1]], walls = [[0,1],[1,0],[2,1],[1,2]])\n >>> 4\n Explanation: The unguarded cells are shown in green in the above diagram.\n There are a total of 4 unguarded cells, so we return 4.\n \"\"\"\n"}
{"task_id": "escape-the-spreading-fire", "prompt": "def maximumMinutes(grid: List[List[int]]) -> int:\n \"\"\"\n You are given a 0-indexed 2D integer array grid of size m x n which represents a field. Each cell has one of three values:\n \n 0 represents grass,\n 1 represents fire,\n 2 represents a wall that you and fire cannot pass through.\n \n You are situated in the top-left cell, (0, 0), and you want to travel to the safehouse at the bottom-right cell, (m - 1, n - 1). Every minute, you may move to an adjacent grass cell. After your move, every fire cell will spread to all adjacent cells that are not walls.\n Return the maximum number of minutes that you can stay in your initial position before moving while still safely reaching the safehouse. If this is impossible, return -1. If you can always reach the safehouse regardless of the minutes stayed, return 109.\n Note that even if the fire spreads to the safehouse immediately after you have reached it, it will be counted as safely reaching the safehouse.\n A cell is adjacent to another cell if the former is directly north, east, south, or west of the latter (i.e., their sides are touching).\n \n Example 1:\n \n \n >>> maximumMinutes(grid = [[0,2,0,0,0,0,0],[0,0,0,2,2,1,0],[0,2,0,0,1,2,0],[0,0,2,2,2,0,2],[0,0,0,0,0,0,0]])\n >>> 3\n Explanation: The figure above shows the scenario where you stay in the initial position for 3 minutes.\n You will still be able to safely reach the safehouse.\n Staying for more than 3 minutes will not allow you to safely reach the safehouse.\n Example 2:\n \n \n >>> maximumMinutes(grid = [[0,0,0,0],[0,1,2,0],[0,2,0,0]])\n >>> -1\n Explanation: The figure above shows the scenario where you immediately move towards the safehouse.\n Fire will spread to any cell you move towards and it is impossible to safely reach the safehouse.\n Thus, -1 is returned.\n \n Example 3:\n \n \n >>> maximumMinutes(grid = [[0,0,0],[2,2,0],[1,2,0]])\n >>> 1000000000\n Explanation: The figure above shows the initial grid.\n Notice that the fire is contained by walls and you will always be able to safely reach the safehouse.\n Thus, 109 is returned.\n \"\"\"\n"}
{"task_id": "remove-digit-from-number-to-maximize-result", "prompt": "def removeDigit(number: str, digit: str) -> str:\n \"\"\"\n You are given a string number representing a positive integer and a character digit.\n Return the resulting string after removing exactly one occurrence of digit from number such that the value of the resulting string in decimal form is maximized. The test cases are generated such that digit occurs at least once in number.\n \n Example 1:\n \n >>> removeDigit(number = \"123\", digit = \"3\")\n >>> \"12\"\n Explanation: There is only one '3' in \"123\". After removing '3', the result is \"12\".\n \n Example 2:\n \n >>> removeDigit(number = \"1231\", digit = \"1\")\n >>> \"231\"\n Explanation: We can remove the first '1' to get \"231\" or remove the second '1' to get \"123\".\n Since 231 > 123, we return \"231\".\n \n Example 3:\n \n >>> removeDigit(number = \"551\", digit = \"5\")\n >>> \"51\"\n Explanation: We can remove either the first or second '5' from \"551\".\n Both result in the string \"51\".\n \"\"\"\n"}
{"task_id": "minimum-consecutive-cards-to-pick-up", "prompt": "def minimumCardPickup(cards: List[int]) -> int:\n \"\"\"\n You are given an integer array cards where cards[i] represents the value of the ith card. A pair of cards are matching if the cards have the same value.\n Return the minimum number of consecutive cards you have to pick up to have a pair of matching cards among the picked cards. If it is impossible to have matching cards, return -1.\n \n Example 1:\n \n >>> minimumCardPickup(cards = [3,4,2,3,4,7])\n >>> 4\n Explanation: We can pick up the cards [3,4,2,3] which contain a matching pair of cards with value 3. Note that picking up the cards [4,2,3,4] is also optimal.\n \n Example 2:\n \n >>> minimumCardPickup(cards = [1,0,5,3])\n >>> -1\n Explanation: There is no way to pick up a set of consecutive cards that contain a pair of matching cards.\n \"\"\"\n"}
{"task_id": "k-divisible-elements-subarrays", "prompt": "def countDistinct(nums: List[int], k: int, p: int) -> int:\n \"\"\"\n Given an integer array nums and two integers k and p, return the number of distinct subarrays, which have at most k elements that are divisible by p.\n Two arrays nums1 and nums2 are said to be distinct if:\n \n They are of different lengths, or\n There exists at least one index i where nums1[i] != nums2[i].\n \n A subarray is defined as a non-empty contiguous sequence of elements in an array.\n \n Example 1:\n \n >>> countDistinct(nums = [2,3,3,2,2], k = 2, p = 2)\n >>> 11\n Explanation:\n The elements at indices 0, 3, and 4 are divisible by p = 2.\n The 11 distinct subarrays which have at most k = 2 elements divisible by 2 are:\n [2], [2,3], [2,3,3], [2,3,3,2], [3], [3,3], [3,3,2], [3,3,2,2], [3,2], [3,2,2], and [2,2].\n Note that the subarrays [2] and [3] occur more than once in nums, but they should each be counted only once.\n The subarray [2,3,3,2,2] should not be counted because it has 3 elements that are divisible by 2.\n \n Example 2:\n \n >>> countDistinct(nums = [1,2,3,4], k = 4, p = 1)\n >>> 10\n Explanation:\n All element of nums are divisible by p = 1.\n Also, every subarray of nums will have at most 4 elements that are divisible by 1.\n Since all subarrays are distinct, the total number of subarrays satisfying all the constraints is 10.\n \"\"\"\n"}
{"task_id": "total-appeal-of-a-string", "prompt": "def appealSum(s: str) -> int:\n \"\"\"\n The appeal of a string is the number of distinct characters found in the string.\n \n For example, the appeal of \"abbca\" is 3 because it has 3 distinct characters: 'a', 'b', and 'c'.\n \n Given a string s, return the total appeal of all of its substrings.\n A substring is a contiguous sequence of characters within a string.\n \n Example 1:\n \n >>> appealSum(s = \"abbca\")\n >>> 28\n Explanation: The following are the substrings of \"abbca\":\n - Substrings of length 1: \"a\", \"b\", \"b\", \"c\", \"a\" have an appeal of 1, 1, 1, 1, and 1 respectively. The sum is 5.\n - Substrings of length 2: \"ab\", \"bb\", \"bc\", \"ca\" have an appeal of 2, 1, 2, and 2 respectively. The sum is 7.\n - Substrings of length 3: \"abb\", \"bbc\", \"bca\" have an appeal of 2, 2, and 3 respectively. The sum is 7.\n - Substrings of length 4: \"abbc\", \"bbca\" have an appeal of 3 and 3 respectively. The sum is 6.\n - Substrings of length 5: \"abbca\" has an appeal of 3. The sum is 3.\n The total sum is 5 + 7 + 7 + 6 + 3 = 28.\n \n Example 2:\n \n >>> appealSum(s = \"code\")\n >>> 20\n Explanation: The following are the substrings of \"code\":\n - Substrings of length 1: \"c\", \"o\", \"d\", \"e\" have an appeal of 1, 1, 1, and 1 respectively. The sum is 4.\n - Substrings of length 2: \"co\", \"od\", \"de\" have an appeal of 2, 2, and 2 respectively. The sum is 6.\n - Substrings of length 3: \"cod\", \"ode\" have an appeal of 3 and 3 respectively. The sum is 6.\n - Substrings of length 4: \"code\" has an appeal of 4. The sum is 4.\n The total sum is 4 + 6 + 6 + 4 = 20.\n \"\"\"\n"}
{"task_id": "make-array-non-decreasing-or-non-increasing", "prompt": "def convertArray(nums: List[int]) -> int:\n \"\"\"\n You are given a 0-indexed integer array nums. In one operation, you can:\n \n Choose an index i in the range 0 <= i < nums.length\n Set nums[i] to nums[i] + 1 or nums[i] - 1\n \n Return the minimum number of operations to make nums non-decreasing or non-increasing.\n \n Example 1:\n \n >>> convertArray(nums = [3,2,4,5,0])\n >>> 4\n Explanation:\n One possible way to turn nums into non-increasing order is to:\n - Add 1 to nums[1] once so that it becomes 3.\n - Subtract 1 from nums[2] once so it becomes 3.\n - Subtract 1 from nums[3] twice so it becomes 3.\n After doing the 4 operations, nums becomes [3,3,3,3,0] which is in non-increasing order.\n Note that it is also possible to turn nums into [4,4,4,4,0] in 4 operations.\n It can be proven that 4 is the minimum number of operations needed.\n \n Example 2:\n \n >>> convertArray(nums = [2,2,3,4])\n >>> 0\n Explanation: nums is already in non-decreasing order, so no operations are needed and we return 0.\n \n Example 3:\n \n >>> convertArray(nums = [0])\n >>> 0\n Explanation: nums is already in non-decreasing order, so no operations are needed and we return 0.\n \"\"\"\n"}
{"task_id": "largest-3-same-digit-number-in-string", "prompt": "def largestGoodInteger(num: str) -> str:\n \"\"\"\n You are given a string num representing a large integer. An integer is good if it meets the following conditions:\n \n It is a substring of num with length 3.\n It consists of only one unique digit.\n \n Return the maximum good integer as a string or an empty string \"\" if no such integer exists.\n Note:\n \n A substring is a contiguous sequence of characters within a string.\n There may be leading zeroes in num or a good integer.\n \n \n Example 1:\n \n >>> largestGoodInteger(num = \"6777133339\")\n >>> \"777\"\n Explanation: There are two distinct good integers: \"777\" and \"333\".\n \"777\" is the largest, so we return \"777\".\n \n Example 2:\n \n >>> largestGoodInteger(num = \"2300019\")\n >>> \"000\"\n Explanation: \"000\" is the only good integer.\n \n Example 3:\n \n >>> largestGoodInteger(num = \"42352338\")\n >>> \"\"\n Explanation: No substring of length 3 consists of only one unique digit. Therefore, there are no good integers.\n \"\"\"\n"}
{"task_id": "count-nodes-equal-to-average-of-subtree", "prompt": "# class TreeNode:\n# def __init__(val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def averageOfSubtree(root: TreeNode) -> int:\n \"\"\"\n Given the root of a binary tree, return the number of nodes where the value of the node is equal to the average of the values in its subtree.\n Note:\n \n The average of n elements is the sum of the n elements divided by n and rounded down to the nearest integer.\n A subtree of root is a tree consisting of root and all of its descendants.\n \n \n Example 1:\n \n \n >>> __init__(root = [4,8,5,0,1,null,6])\n >>> 5\n Explanation:\n For the node with value 4: The average of its subtree is (4 + 8 + 5 + 0 + 1 + 6) / 6 = 24 / 6 = 4.\n For the node with value 5: The average of its subtree is (5 + 6) / 2 = 11 / 2 = 5.\n For the node with value 0: The average of its subtree is 0 / 1 = 0.\n For the node with value 1: The average of its subtree is 1 / 1 = 1.\n For the node with value 6: The average of its subtree is 6 / 1 = 6.\n \n Example 2:\n \n \n >>> __init__(root = [1])\n >>> 1\n Explanation: For the node with value 1: The average of its subtree is 1 / 1 = 1.\n \"\"\"\n"}
{"task_id": "count-number-of-texts", "prompt": "def countTexts(pressedKeys: str) -> int:\n \"\"\"\n Alice is texting Bob using her phone. The mapping of digits to letters is shown in the figure below.\n \n In order to add a letter, Alice has to press the key of the corresponding digit i times, where i is the position of the letter in the key.\n \n For example, to add the letter 's', Alice has to press '7' four times. Similarly, to add the letter 'k', Alice has to press '5' twice.\n Note that the digits '0' and '1' do not map to any letters, so Alice does not use them.\n \n However, due to an error in transmission, Bob did not receive Alice's text message but received a string of pressed keys instead.\n \n For example, when Alice sent the message \"bob\", Bob received the string \"2266622\".\n \n Given a string pressedKeys representing the string received by Bob, return the total number of possible text messages Alice could have sent.\n Since the answer may be very large, return it modulo 109 + 7.\n \n Example 1:\n \n >>> countTexts(pressedKeys = \"22233\")\n >>> 8\n Explanation:\n The possible text messages Alice could have sent are:\n \"aaadd\", \"abdd\", \"badd\", \"cdd\", \"aaae\", \"abe\", \"bae\", and \"ce\".\n Since there are 8 possible messages, we return 8.\n \n Example 2:\n \n >>> countTexts(pressedKeys = \"222222222222222222222222222222222222\")\n >>> 82876089\n Explanation:\n There are 2082876103 possible text messages Alice could have sent.\n Since we need to return the answer modulo 109 + 7, we return 2082876103 % (109 + 7) = 82876089.\n \"\"\"\n"}
{"task_id": "check-if-there-is-a-valid-parentheses-string-path", "prompt": "def hasValidPath(grid: List[List[str]]) -> bool:\n \"\"\"\n A parentheses string is a non-empty string consisting only of '(' and ')'. It is valid if any of the following conditions is true:\n \n It is ().\n It can be written as AB (A concatenated with B), where A and B are valid parentheses strings.\n It can be written as (A), where A is a valid parentheses string.\n \n You are given an m x n matrix of parentheses grid. A valid parentheses string path in the grid is a path satisfying all of the following conditions:\n \n The path starts from the upper left cell (0, 0).\n The path ends at the bottom-right cell (m - 1, n - 1).\n The path only ever moves down or right.\n The resulting parentheses string formed by the path is valid.\n \n Return true if there exists a valid parentheses string path in the grid. Otherwise, return false.\n \n Example 1:\n \n \n >>> hasValidPath(grid = [[\"(\",\"(\",\"(\"],[\")\",\"(\",\")\"],[\"(\",\"(\",\")\"],[\"(\",\"(\",\")\"]])\n >>> true\n Explanation: The above diagram shows two possible paths that form valid parentheses strings.\n The first path shown results in the valid parentheses string \"()(())\".\n The second path shown results in the valid parentheses string \"((()))\".\n Note that there may be other valid parentheses string paths.\n \n Example 2:\n \n \n >>> hasValidPath(grid = [[\")\",\")\"],[\"(\",\"(\"]])\n >>> false\n Explanation: The two possible paths form the parentheses strings \"))(\" and \")((\". Since neither of them are valid parentheses strings, we return false.\n \"\"\"\n"}
{"task_id": "minimum-number-of-keypresses", "prompt": "def minimumKeypresses(s: str) -> int:\n \"\"\"\n You have a keypad with 9 buttons, numbered from 1 to 9, each mapped to lowercase English letters. You can choose which characters each button is matched to as long as:\n \n All 26 lowercase English letters are mapped to.\n Each character is mapped to by exactly 1 button.\n Each button maps to at most 3 characters.\n \n To type the first character matched to a button, you press the button once. To type the second character, you press the button twice, and so on.\n Given a string s, return the minimum number of keypresses needed to type s using your keypad.\n Note that the characters mapped to by each button, and the order they are mapped in cannot be changed.\n \n Example 1:\n \n \n >>> minimumKeypresses(s = \"apple\")\n >>> 5\n Explanation: One optimal way to setup your keypad is shown above.\n Type 'a' by pressing button 1 once.\n Type 'p' by pressing button 6 once.\n Type 'p' by pressing button 6 once.\n Type 'l' by pressing button 5 once.\n Type 'e' by pressing button 3 once.\n A total of 5 button presses are needed, so return 5.\n \n Example 2:\n \n \n >>> minimumKeypresses(s = \"abcdefghijkl\")\n >>> 15\n Explanation: One optimal way to setup your keypad is shown above.\n The letters 'a' to 'i' can each be typed by pressing a button once.\n Type 'j' by pressing button 1 twice.\n Type 'k' by pressing button 2 twice.\n Type 'l' by pressing button 3 twice.\n A total of 15 button presses are needed, so return 15.\n \"\"\"\n"}
{"task_id": "find-the-k-beauty-of-a-number", "prompt": "def divisorSubstrings(num: int, k: int) -> int:\n \"\"\"\n The k-beauty of an integer num is defined as the number of substrings of num when it is read as a string that meet the following conditions:\n \n It has a length of k.\n It is a divisor of num.\n \n Given integers num and k, return the k-beauty of num.\n Note:\n \n Leading zeros are allowed.\n 0 is not a divisor of any value.\n \n A substring is a contiguous sequence of characters in a string.\n \n Example 1:\n \n >>> divisorSubstrings(num = 240, k = 2)\n >>> 2\n Explanation: The following are the substrings of num of length k:\n - \"24\" from \"240\": 24 is a divisor of 240.\n - \"40\" from \"240\": 40 is a divisor of 240.\n Therefore, the k-beauty is 2.\n \n Example 2:\n \n >>> divisorSubstrings(num = 430043, k = 2)\n >>> 2\n Explanation: The following are the substrings of num of length k:\n - \"43\" from \"430043\": 43 is a divisor of 430043.\n - \"30\" from \"430043\": 30 is not a divisor of 430043.\n - \"00\" from \"430043\": 0 is not a divisor of 430043.\n - \"04\" from \"430043\": 4 is not a divisor of 430043.\n - \"43\" from \"430043\": 43 is a divisor of 430043.\n Therefore, the k-beauty is 2.\n \"\"\"\n"}
{"task_id": "number-of-ways-to-split-array", "prompt": "def waysToSplitArray(nums: List[int]) -> int:\n \"\"\"\n You are given a 0-indexed integer array nums of length n.\n nums contains a valid split at index i if the following are true:\n \n The sum of the first i + 1 elements is greater than or equal to the sum of the last n - i - 1 elements.\n There is at least one element to the right of i. That is, 0 <= i < n - 1.\n \n Return the number of valid splits in nums.\n \n Example 1:\n \n >>> waysToSplitArray(nums = [10,4,-8,7])\n >>> 2\n Explanation:\n There are three ways of splitting nums into two non-empty parts:\n - Split nums at index 0. Then, the first part is [10], and its sum is 10. The second part is [4,-8,7], and its sum is 3. Since 10 >= 3, i = 0 is a valid split.\n - Split nums at index 1. Then, the first part is [10,4], and its sum is 14. The second part is [-8,7], and its sum is -1. Since 14 >= -1, i = 1 is a valid split.\n - Split nums at index 2. Then, the first part is [10,4,-8], and its sum is 6. The second part is [7], and its sum is 7. Since 6 < 7, i = 2 is not a valid split.\n Thus, the number of valid splits in nums is 2.\n \n Example 2:\n \n >>> waysToSplitArray(nums = [2,3,1,0])\n >>> 2\n Explanation:\n There are two valid splits in nums:\n - Split nums at index 1. Then, the first part is [2,3], and its sum is 5. The second part is [1,0], and its sum is 1. Since 5 >= 1, i = 1 is a valid split.\n - Split nums at index 2. Then, the first part is [2,3,1], and its sum is 6. The second part is [0], and its sum is 0. Since 6 >= 0, i = 2 is a valid split.\n \"\"\"\n"}
{"task_id": "maximum-white-tiles-covered-by-a-carpet", "prompt": "def maximumWhiteTiles(tiles: List[List[int]], carpetLen: int) -> int:\n \"\"\"\n You are given a 2D integer array tiles where tiles[i] = [li, ri] represents that every tile j in the range li <= j <= ri is colored white.\n You are also given an integer carpetLen, the length of a single carpet that can be placed anywhere.\n Return the maximum number of white tiles that can be covered by the carpet.\n \n Example 1:\n \n \n >>> maximumWhiteTiles(tiles = [[1,5],[10,11],[12,18],[20,25],[30,32]], carpetLen = 10)\n >>> 9\n Explanation: Place the carpet starting on tile 10.\n It covers 9 white tiles, so we return 9.\n Note that there may be other places where the carpet covers 9 white tiles.\n It can be shown that the carpet cannot cover more than 9 white tiles.\n \n Example 2:\n \n \n >>> maximumWhiteTiles(tiles = [[10,11],[1,1]], carpetLen = 2)\n >>> 2\n Explanation: Place the carpet starting on tile 10.\n It covers 2 white tiles, so we return 2.\n \"\"\"\n"}
{"task_id": "substring-with-largest-variance", "prompt": "def largestVariance(s: str) -> int:\n \"\"\"\n The variance of a string is defined as the largest difference between the number of occurrences of any 2 characters present in the string. Note the two characters may or may not be the same.\n Given a string s consisting of lowercase English letters only, return the largest variance possible among all substrings of s.\n A substring is a contiguous sequence of characters within a string.\n \n Example 1:\n \n >>> largestVariance(s = \"aababbb\")\n >>> 3\n Explanation:\n All possible variances along with their respective substrings are listed below:\n - Variance 0 for substrings \"a\", \"aa\", \"ab\", \"abab\", \"aababb\", \"ba\", \"b\", \"bb\", and \"bbb\".\n - Variance 1 for substrings \"aab\", \"aba\", \"abb\", \"aabab\", \"ababb\", \"aababbb\", and \"bab\".\n - Variance 2 for substrings \"aaba\", \"ababbb\", \"abbb\", and \"babb\".\n - Variance 3 for substring \"babbb\".\n Since the largest possible variance is 3, we return it.\n \n Example 2:\n \n >>> largestVariance(s = \"abcde\")\n >>> 0\n Explanation:\n No letter occurs more than once in s, so the variance of every substring is 0.\n \"\"\"\n"}
{"task_id": "find-resultant-array-after-removing-anagrams", "prompt": "def removeAnagrams(words: List[str]) -> List[str]:\n \"\"\"\n You are given a 0-indexed string array words, where words[i] consists of lowercase English letters.\n In one operation, select any index i such that 0 < i < words.length and words[i - 1] and words[i] are anagrams, and delete words[i] from words. Keep performing this operation as long as you can select an index that satisfies the conditions.\n Return words after performing all operations. It can be shown that selecting the indices for each operation in any arbitrary order will lead to the same result.\n An Anagram is a word or phrase formed by rearranging the letters of a different word or phrase using all the original letters exactly once. For example, \"dacb\" is an anagram of \"abdc\".\n \n Example 1:\n \n >>> removeAnagrams(words = [\"abba\",\"baba\",\"bbaa\",\"cd\",\"cd\"])\n >>> [\"abba\",\"cd\"]\n Explanation:\n One of the ways we can obtain the resultant array is by using the following operations:\n - Since words[2] = \"bbaa\" and words[1] = \"baba\" are anagrams, we choose index 2 and delete words[2].\n Now words = [\"abba\",\"baba\",\"cd\",\"cd\"].\n - Since words[1] = \"baba\" and words[0] = \"abba\" are anagrams, we choose index 1 and delete words[1].\n Now words = [\"abba\",\"cd\",\"cd\"].\n - Since words[2] = \"cd\" and words[1] = \"cd\" are anagrams, we choose index 2 and delete words[2].\n Now words = [\"abba\",\"cd\"].\n We can no longer perform any operations, so [\"abba\",\"cd\"] is the final answer.\n Example 2:\n \n >>> removeAnagrams(words = [\"a\",\"b\",\"c\",\"d\",\"e\"])\n >>> [\"a\",\"b\",\"c\",\"d\",\"e\"]\n Explanation:\n No two adjacent strings in words are anagrams of each other, so no operations are performed.\n \"\"\"\n"}
{"task_id": "maximum-consecutive-floors-without-special-floors", "prompt": "def maxConsecutive(bottom: int, top: int, special: List[int]) -> int:\n \"\"\"\n Alice manages a company and has rented some floors of a building as office space. Alice has decided some of these floors should be special floors, used for relaxation only.\n You are given two integers bottom and top, which denote that Alice has rented all the floors from bottom to top (inclusive). You are also given the integer array special, where special[i] denotes a special floor that Alice has designated for relaxation.\n Return the maximum number of consecutive floors without a special floor.\n \n Example 1:\n \n >>> maxConsecutive(bottom = 2, top = 9, special = [4,6])\n >>> 3\n Explanation: The following are the ranges (inclusive) of consecutive floors without a special floor:\n - (2, 3) with a total amount of 2 floors.\n - (5, 5) with a total amount of 1 floor.\n - (7, 9) with a total amount of 3 floors.\n Therefore, we return the maximum number which is 3 floors.\n \n Example 2:\n \n >>> maxConsecutive(bottom = 6, top = 8, special = [7,6,8])\n >>> 0\n Explanation: Every floor rented is a special floor, so we return 0.\n \"\"\"\n"}
{"task_id": "largest-combination-with-bitwise-and-greater-than-zero", "prompt": "def largestCombination(candidates: List[int]) -> int:\n \"\"\"\n The bitwise AND of an array nums is the bitwise AND of all integers in nums.\n \n For example, for nums = [1, 5, 3], the bitwise AND is equal to 1 & 5 & 3 = 1.\n Also, for nums = [7], the bitwise AND is 7.\n \n You are given an array of positive integers candidates. Compute the bitwise AND for all possible combinations of elements in the candidates array.\n Return the size of the largest combination of candidates with a bitwise AND greater than 0.\n \n Example 1:\n \n >>> largestCombination(candidates = [16,17,71,62,12,24,14])\n >>> 4\n Explanation: The combination [16,17,62,24] has a bitwise AND of 16 & 17 & 62 & 24 = 16 > 0.\n The size of the combination is 4.\n It can be shown that no combination with a size greater than 4 has a bitwise AND greater than 0.\n Note that more than one combination may have the largest size.\n For example, the combination [62,12,24,14] has a bitwise AND of 62 & 12 & 24 & 14 = 8 > 0.\n \n Example 2:\n \n >>> largestCombination(candidates = [8,8])\n >>> 2\n Explanation: The largest combination [8,8] has a bitwise AND of 8 & 8 = 8 > 0.\n The size of the combination is 2, so we return 2.\n \"\"\"\n"}
{"task_id": "closest-node-to-path-in-tree", "prompt": "def closestNode(n: int, edges: List[List[int]], query: List[List[int]]) -> List[int]:\n \"\"\"\n You are given a positive integer n representing the number of nodes in a tree, numbered from 0 to n - 1 (inclusive). You are also given a 2D integer array edges of length n - 1, where edges[i] = [node1i, node2i] denotes that there is a bidirectional edge connecting node1i and node2i in the tree.\n You are given a 0-indexed integer array query of length m where query[i] = [starti, endi, nodei] means that for the ith query, you are tasked with finding the node on the path from starti to endi that is closest to nodei.\n Return an integer array answer of length m, where answer[i] is the answer to the ith query.\n \n Example 1:\n \n \n >>> closestNode(n = 7, edges = [[0,1],[0,2],[0,3],[1,4],[2,5],[2,6]], query = [[5,3,4],[5,3,6]])\n >>> [0,2]\n Explanation:\n The path from node 5 to node 3 consists of the nodes 5, 2, 0, and 3.\n The distance between node 4 and node 0 is 2.\n Node 0 is the node on the path closest to node 4, so the answer to the first query is 0.\n The distance between node 6 and node 2 is 1.\n Node 2 is the node on the path closest to node 6, so the answer to the second query is 2.\n \n Example 2:\n \n \n >>> closestNode(n = 3, edges = [[0,1],[1,2]], query = [[0,1,2]])\n >>> [1]\n Explanation:\n The path from node 0 to node 1 consists of the nodes 0, 1.\n The distance between node 2 and node 1 is 1.\n Node 1 is the node on the path closest to node 2, so the answer to the first query is 1.\n \n Example 3:\n \n \n >>> closestNode(n = 3, edges = [[0,1],[1,2]], query = [[0,0,0]])\n >>> [0]\n Explanation:\n The path from node 0 to node 0 consists of the node 0.\n Since 0 is the only node on the path, the answer to the first query is 0.\n \"\"\"\n"}
{"task_id": "percentage-of-letter-in-string", "prompt": "def percentageLetter(s: str, letter: str) -> int:\n \"\"\"\n Given a string s and a character letter, return the percentage of characters in s that equal letter rounded down to the nearest whole percent.\n \n Example 1:\n \n >>> percentageLetter(s = \"foobar\", letter = \"o\")\n >>> 33\n Explanation:\n The percentage of characters in s that equal the letter 'o' is 2 / 6 * 100% = 33% when rounded down, so we return 33.\n \n Example 2:\n \n >>> percentageLetter(s = \"jjjj\", letter = \"k\")\n >>> 0\n Explanation:\n The percentage of characters in s that equal the letter 'k' is 0%, so we return 0.\n \"\"\"\n"}
{"task_id": "maximum-bags-with-full-capacity-of-rocks", "prompt": "def maximumBags(capacity: List[int], rocks: List[int], additionalRocks: int) -> int:\n \"\"\"\n You have n bags numbered from 0 to n - 1. You are given two 0-indexed integer arrays capacity and rocks. The ith bag can hold a maximum of capacity[i] rocks and currently contains rocks[i] rocks. You are also given an integer additionalRocks, the number of additional rocks you can place in any of the bags.\n Return the maximum number of bags that could have full capacity after placing the additional rocks in some bags.\n \n Example 1:\n \n >>> maximumBags(capacity = [2,3,4,5], rocks = [1,2,4,4], additionalRocks = 2)\n >>> 3\n Explanation:\n Place 1 rock in bag 0 and 1 rock in bag 1.\n The number of rocks in each bag are now [2,3,4,4].\n Bags 0, 1, and 2 have full capacity.\n There are 3 bags at full capacity, so we return 3.\n It can be shown that it is not possible to have more than 3 bags at full capacity.\n Note that there may be other ways of placing the rocks that result in an answer of 3.\n \n Example 2:\n \n >>> maximumBags(capacity = [10,2,2], rocks = [2,2,0], additionalRocks = 100)\n >>> 3\n Explanation:\n Place 8 rocks in bag 0 and 2 rocks in bag 2.\n The number of rocks in each bag are now [10,2,2].\n Bags 0, 1, and 2 have full capacity.\n There are 3 bags at full capacity, so we return 3.\n It can be shown that it is not possible to have more than 3 bags at full capacity.\n Note that we did not use all of the additional rocks.\n \"\"\"\n"}
{"task_id": "minimum-lines-to-represent-a-line-chart", "prompt": "def minimumLines(stockPrices: List[List[int]]) -> int:\n \"\"\"\n You are given a 2D integer array stockPrices where stockPrices[i] = [dayi, pricei] indicates the price of the stock on day dayi is pricei. A line chart is created from the array by plotting the points on an XY plane with the X-axis representing the day and the Y-axis representing the price and connecting adjacent points. One such example is shown below:\n \n Return the minimum number of lines needed to represent the line chart.\n \n Example 1:\n \n \n >>> minimumLines(stockPrices = [[1,7],[2,6],[3,5],[4,4],[5,4],[6,3],[7,2],[8,1]])\n >>> 3\n Explanation:\n The diagram above represents the input, with the X-axis representing the day and Y-axis representing the price.\n The following 3 lines can be drawn to represent the line chart:\n - Line 1 (in red) from (1,7) to (4,4) passing through (1,7), (2,6), (3,5), and (4,4).\n - Line 2 (in blue) from (4,4) to (5,4).\n - Line 3 (in green) from (5,4) to (8,1) passing through (5,4), (6,3), (7,2), and (8,1).\n It can be shown that it is not possible to represent the line chart using less than 3 lines.\n \n Example 2:\n \n \n >>> minimumLines(stockPrices = [[3,4],[1,2],[7,8],[2,3]])\n >>> 1\n Explanation:\n As shown in the diagram above, the line chart can be represented with a single line.\n \"\"\"\n"}
{"task_id": "sum-of-total-strength-of-wizards", "prompt": "def totalStrength(strength: List[int]) -> int:\n \"\"\"\n As the ruler of a kingdom, you have an army of wizards at your command.\n You are given a 0-indexed integer array strength, where strength[i] denotes the strength of the ith wizard. For a contiguous group of wizards (i.e. the wizards' strengths form a subarray of strength), the total strength is defined as the product of the following two values:\n \n The strength of the weakest wizard in the group.\n The total of all the individual strengths of the wizards in the group.\n \n Return the sum of the total strengths of all contiguous groups of wizards. Since the answer may be very large, return it modulo 109 + 7.\n A subarray is a contiguous non-empty sequence of elements within an array.\n \n Example 1:\n \n >>> totalStrength(strength = [1,3,1,2])\n >>> 44\n Explanation: The following are all the contiguous groups of wizards:\n - [1] from [1,3,1,2] has a total strength of min([1]) * sum([1]) = 1 * 1 = 1\n - [3] from [1,3,1,2] has a total strength of min([3]) * sum([3]) = 3 * 3 = 9\n - [1] from [1,3,1,2] has a total strength of min([1]) * sum([1]) = 1 * 1 = 1\n - [2] from [1,3,1,2] has a total strength of min([2]) * sum([2]) = 2 * 2 = 4\n - [1,3] from [1,3,1,2] has a total strength of min([1,3]) * sum([1,3]) = 1 * 4 = 4\n - [3,1] from [1,3,1,2] has a total strength of min([3,1]) * sum([3,1]) = 1 * 4 = 4\n - [1,2] from [1,3,1,2] has a total strength of min([1,2]) * sum([1,2]) = 1 * 3 = 3\n - [1,3,1] from [1,3,1,2] has a total strength of min([1,3,1]) * sum([1,3,1]) = 1 * 5 = 5\n - [3,1,2] from [1,3,1,2] has a total strength of min([3,1,2]) * sum([3,1,2]) = 1 * 6 = 6\n - [1,3,1,2] from [1,3,1,2] has a total strength of min([1,3,1,2]) * sum([1,3,1,2]) = 1 * 7 = 7\n The sum of all the total strengths is 1 + 9 + 1 + 4 + 4 + 4 + 3 + 5 + 6 + 7 = 44.\n \n Example 2:\n \n >>> totalStrength(strength = [5,4,6])\n >>> 213\n Explanation: The following are all the contiguous groups of wizards:\n - [5] from [5,4,6] has a total strength of min([5]) * sum([5]) = 5 * 5 = 25\n - [4] from [5,4,6] has a total strength of min([4]) * sum([4]) = 4 * 4 = 16\n - [6] from [5,4,6] has a total strength of min([6]) * sum([6]) = 6 * 6 = 36\n - [5,4] from [5,4,6] has a total strength of min([5,4]) * sum([5,4]) = 4 * 9 = 36\n - [4,6] from [5,4,6] has a total strength of min([4,6]) * sum([4,6]) = 4 * 10 = 40\n - [5,4,6] from [5,4,6] has a total strength of min([5,4,6]) * sum([5,4,6]) = 4 * 15 = 60\n The sum of all the total strengths is 25 + 16 + 36 + 36 + 40 + 60 = 213.\n \"\"\"\n"}
{"task_id": "number-of-people-that-can-be-seen-in-a-grid", "prompt": "def seePeople(heights: List[List[int]]) -> List[List[int]]:\n \"\"\"\n You are given an m x n 0-indexed 2D array of positive integers heights where heights[i][j] is the height of the person standing at position (i, j).\n A person standing at position (row1, col1) can see a person standing at position (row2, col2) if:\n \n The person at (row2, col2) is to the right or below the person at (row1, col1). More formally, this means that either row1 == row2 and col1 < col2 or row1 < row2 and col1 == col2.\n Everyone in between them is shorter than both of them.\n \n Return an m x n 2D array of integers answer where answer[i][j] is the number of people that the person at position (i, j) can see.\n \n Example 1:\n \n \n >>> seePeople(heights = [[3,1,4,2,5]])\n >>> [[2,1,2,1,0]]\n Explanation:\n - The person at (0, 0) can see the people at (0, 1) and (0, 2).\n Note that he cannot see the person at (0, 4) because the person at (0, 2) is taller than him.\n - The person at (0, 1) can see the person at (0, 2).\n - The person at (0, 2) can see the people at (0, 3) and (0, 4).\n - The person at (0, 3) can see the person at (0, 4).\n - The person at (0, 4) cannot see anybody.\n \n Example 2:\n \n \n >>> seePeople(heights = [[5,1],[3,1],[4,1]])\n >>> [[3,1],[2,1],[1,0]]\n Explanation:\n - The person at (0, 0) can see the people at (0, 1), (1, 0) and (2, 0).\n - The person at (0, 1) can see the person at (1, 1).\n - The person at (1, 0) can see the people at (1, 1) and (2, 0).\n - The person at (1, 1) can see the person at (2, 1).\n - The person at (2, 0) can see the person at (2, 1).\n - The person at (2, 1) cannot see anybody.\n \"\"\"\n"}
{"task_id": "check-if-number-has-equal-digit-count-and-digit-value", "prompt": "def digitCount(num: str) -> bool:\n \"\"\"\n You are given a 0-indexed string num of length n consisting of digits.\n Return true if for every index i in the range 0 <= i < n, the digit i occurs num[i] times in num, otherwise return false.\n \n Example 1:\n \n >>> digitCount(num = \"1210\")\n >>> true\n Explanation:\n num[0] = '1'. The digit 0 occurs once in num.\n num[1] = '2'. The digit 1 occurs twice in num.\n num[2] = '1'. The digit 2 occurs once in num.\n num[3] = '0'. The digit 3 occurs zero times in num.\n The condition holds true for every index in \"1210\", so return true.\n \n Example 2:\n \n >>> digitCount(num = \"030\")\n >>> false\n Explanation:\n num[0] = '0'. The digit 0 should occur zero times, but actually occurs twice in num.\n num[1] = '3'. The digit 1 should occur three times, but actually occurs zero times in num.\n num[2] = '0'. The digit 2 occurs zero times in num.\n The indices 0 and 1 both violate the condition, so return false.\n \"\"\"\n"}
{"task_id": "sender-with-largest-word-count", "prompt": "def largestWordCount(messages: List[str], senders: List[str]) -> str:\n \"\"\"\n You have a chat log of n messages. You are given two string arrays messages and senders where messages[i] is a message sent by senders[i].\n A message is list of words that are separated by a single space with no leading or trailing spaces. The word count of a sender is the total number of words sent by the sender. Note that a sender may send more than one message.\n Return the sender with the largest word count. If there is more than one sender with the largest word count, return the one with the lexicographically largest name.\n Note:\n \n Uppercase letters come before lowercase letters in lexicographical order.\n \"Alice\" and \"alice\" are distinct.\n \n \n Example 1:\n \n >>> largestWordCount(messages = [\"Hello userTwooo\",\"Hi userThree\",\"Wonderful day Alice\",\"Nice day userThree\"], senders = [\"Alice\",\"userTwo\",\"userThree\",\"Alice\"])\n >>> \"Alice\"\n Explanation: Alice sends a total of 2 + 3 = 5 words.\n userTwo sends a total of 2 words.\n userThree sends a total of 3 words.\n Since Alice has the largest word count, we return \"Alice\".\n \n Example 2:\n \n >>> largestWordCount(messages = [\"How is leetcode for everyone\",\"Leetcode is useful for practice\"], senders = [\"Bob\",\"Charlie\"])\n >>> \"Charlie\"\n Explanation: Bob sends a total of 5 words.\n Charlie sends a total of 5 words.\n Since there is a tie for the largest word count, we return the sender with the lexicographically larger name, Charlie.\n \"\"\"\n"}
{"task_id": "maximum-total-importance-of-roads", "prompt": "def maximumImportance(n: int, roads: List[List[int]]) -> int:\n \"\"\"\n You are given an integer n denoting the number of cities in a country. The cities are numbered from 0 to n - 1.\n You are also given a 2D integer array roads where roads[i] = [ai, bi] denotes that there exists a bidirectional road connecting cities ai and bi.\n You need to assign each city with an integer value from 1 to n, where each value can only be used once. The importance of a road is then defined as the sum of the values of the two cities it connects.\n Return the maximum total importance of all roads possible after assigning the values optimally.\n \n Example 1:\n \n \n >>> maximumImportance(n = 5, roads = [[0,1],[1,2],[2,3],[0,2],[1,3],[2,4]])\n >>> 43\n Explanation: The figure above shows the country and the assigned values of [2,4,5,3,1].\n - The road (0,1) has an importance of 2 + 4 = 6.\n - The road (1,2) has an importance of 4 + 5 = 9.\n - The road (2,3) has an importance of 5 + 3 = 8.\n - The road (0,2) has an importance of 2 + 5 = 7.\n - The road (1,3) has an importance of 4 + 3 = 7.\n - The road (2,4) has an importance of 5 + 1 = 6.\n The total importance of all roads is 6 + 9 + 8 + 7 + 7 + 6 = 43.\n It can be shown that we cannot obtain a greater total importance than 43.\n \n Example 2:\n \n \n >>> maximumImportance(n = 5, roads = [[0,3],[2,4],[1,3]])\n >>> 20\n Explanation: The figure above shows the country and the assigned values of [4,3,2,5,1].\n - The road (0,3) has an importance of 4 + 5 = 9.\n - The road (2,4) has an importance of 2 + 1 = 3.\n - The road (1,3) has an importance of 3 + 5 = 8.\n The total importance of all roads is 9 + 3 + 8 = 20.\n It can be shown that we cannot obtain a greater total importance than 20.\n \"\"\"\n"}
{"task_id": "rearrange-characters-to-make-target-string", "prompt": "def rearrangeCharacters(s: str, target: str) -> int:\n \"\"\"\n You are given two 0-indexed strings s and target. You can take some letters from s and rearrange them to form new strings.\n Return the maximum number of copies of target that can be formed by taking letters from s and rearranging them.\n \n Example 1:\n \n >>> rearrangeCharacters(s = \"ilovecodingonleetcode\", target = \"code\")\n >>> 2\n Explanation:\n For the first copy of \"code\", take the letters at indices 4, 5, 6, and 7.\n For the second copy of \"code\", take the letters at indices 17, 18, 19, and 20.\n The strings that are formed are \"ecod\" and \"code\" which can both be rearranged into \"code\".\n We can make at most two copies of \"code\", so we return 2.\n \n Example 2:\n \n >>> rearrangeCharacters(s = \"abcba\", target = \"abc\")\n >>> 1\n Explanation:\n We can make one copy of \"abc\" by taking the letters at indices 0, 1, and 2.\n We can make at most one copy of \"abc\", so we return 1.\n Note that while there is an extra 'a' and 'b' at indices 3 and 4, we cannot reuse the letter 'c' at index 2, so we cannot make a second copy of \"abc\".\n \n Example 3:\n \n >>> rearrangeCharacters(s = \"abbaccaddaeea\", target = \"aaaaa\")\n >>> 1\n Explanation:\n We can make one copy of \"aaaaa\" by taking the letters at indices 0, 3, 6, 9, and 12.\n We can make at most one copy of \"aaaaa\", so we return 1.\n \"\"\"\n"}
{"task_id": "apply-discount-to-prices", "prompt": "def discountPrices(sentence: str, discount: int) -> str:\n \"\"\"\n A sentence is a string of single-space separated words where each word can contain digits, lowercase letters, and the dollar sign '$'. A word represents a price if it is a sequence of digits preceded by a dollar sign.\n \n For example, \"$100\", \"$23\", and \"$6\" represent prices while \"100\", \"$\", and \"$1e5\" do not.\n \n You are given a string sentence representing a sentence and an integer discount. For each word representing a price, apply a discount of discount% on the price and update the word in the sentence. All updated prices should be represented with exactly two decimal places.\n Return a string representing the modified sentence.\n Note that all prices will contain at most 10 digits.\n \n Example 1:\n \n >>> discountPrices(sentence = \"there are $1 $2 and 5$ candies in the shop\", discount = 50)\n >>> \"there are $0.50 $1.00 and 5$ candies in the shop\"\n Explanation:\n The words which represent prices are \"$1\" and \"$2\".\n - A 50% discount on \"$1\" yields \"$0.50\", so \"$1\" is replaced by \"$0.50\".\n - A 50% discount on \"$2\" yields \"$1\". Since we need to have exactly 2 decimal places after a price, we replace \"$2\" with \"$1.00\".\n \n Example 2:\n \n >>> discountPrices(sentence = \"1 2 $3 4 $5 $6 7 8$ $9 $10$\", discount = 100)\n >>> \"1 2 $0.00 4 $0.00 $0.00 7 8$ $0.00 $10$\"\n Explanation:\n Applying a 100% discount on any price will result in 0.\n The words representing prices are \"$3\", \"$5\", \"$6\", and \"$9\".\n Each of them is replaced by \"$0.00\".\n \"\"\"\n"}
{"task_id": "steps-to-make-array-non-decreasing", "prompt": "def totalSteps(nums: List[int]) -> int:\n \"\"\"\n You are given a 0-indexed integer array nums. In one step, remove all elements nums[i] where nums[i - 1] > nums[i] for all 0 < i < nums.length.\n Return the number of steps performed until nums becomes a non-decreasing array.\n \n Example 1:\n \n >>> totalSteps(nums = [5,3,4,4,7,3,6,11,8,5,11])\n >>> 3\n Explanation: The following are the steps performed:\n - Step 1: [5,3,4,4,7,3,6,11,8,5,11] becomes [5,4,4,7,6,11,11]\n - Step 2: [5,4,4,7,6,11,11] becomes [5,4,7,11,11]\n - Step 3: [5,4,7,11,11] becomes [5,7,11,11]\n [5,7,11,11] is a non-decreasing array. Therefore, we return 3.\n \n Example 2:\n \n >>> totalSteps(nums = [4,5,7,7,13])\n >>> 0\n Explanation: nums is already a non-decreasing array. Therefore, we return 0.\n \"\"\"\n"}
{"task_id": "minimum-obstacle-removal-to-reach-corner", "prompt": "def minimumObstacles(grid: List[List[int]]) -> int:\n \"\"\"\n You are given a 0-indexed 2D integer array grid of size m x n. Each cell has one of two values:\n \n 0 represents an empty cell,\n 1 represents an obstacle that may be removed.\n \n You can move up, down, left, or right from and to an empty cell.\n Return the minimum number of obstacles to remove so you can move from the upper left corner (0, 0) to the lower right corner (m - 1, n - 1).\n \n Example 1:\n \n \n >>> minimumObstacles(grid = [[0,1,1],[1,1,0],[1,1,0]])\n >>> 2\n Explanation: We can remove the obstacles at (0, 1) and (0, 2) to create a path from (0, 0) to (2, 2).\n It can be shown that we need to remove at least 2 obstacles, so we return 2.\n Note that there may be other ways to remove 2 obstacles to create a path.\n \n Example 2:\n \n \n >>> minimumObstacles(grid = [[0,1,0,0,0],[0,1,0,1,0],[0,0,0,1,0]])\n >>> 0\n Explanation: We can move from (0, 0) to (2, 4) without removing any obstacles, so we return 0.\n \"\"\"\n"}
{"task_id": "maximum-profit-from-trading-stocks", "prompt": "def maximumProfit(present: List[int], future: List[int], budget: int) -> int:\n \"\"\"\n You are given two 0-indexed integer arrays of the same length present and future where present[i] is the current price of the ith stock and future[i] is the price of the ith stock a year in the future. You may buy each stock at most once. You are also given an integer budget representing the amount of money you currently have.\n Return the maximum amount of profit you can make.\n \n Example 1:\n \n >>> maximumProfit(present = [5,4,6,2,3], future = [8,5,4,3,5], budget = 10)\n >>> 6\n Explanation: One possible way to maximize your profit is to:\n Buy the 0th, 3rd, and 4th stocks for a total of 5 + 2 + 3 = 10.\n Next year, sell all three stocks for a total of 8 + 3 + 5 = 16.\n The profit you made is 16 - 10 = 6.\n It can be shown that the maximum profit you can make is 6.\n \n Example 2:\n \n >>> maximumProfit(present = [2,2,5], future = [3,4,10], budget = 6)\n >>> 5\n Explanation: The only possible way to maximize your profit is to:\n Buy the 2nd stock, and make a profit of 10 - 5 = 5.\n It can be shown that the maximum profit you can make is 5.\n \n Example 3:\n \n >>> maximumProfit(present = [3,3,12], future = [0,3,15], budget = 10)\n >>> 0\n Explanation: One possible way to maximize your profit is to:\n Buy the 1st stock, and make a profit of 3 - 3 = 0.\n It can be shown that the maximum profit you can make is 0.\n \"\"\"\n"}
{"task_id": "min-max-game", "prompt": "def minMaxGame(nums: List[int]) -> int:\n \"\"\"\n You are given a 0-indexed integer array nums whose length is a power of 2.\n Apply the following algorithm on nums:\n \n Let n be the length of nums. If n == 1, end the process. Otherwise, create a new 0-indexed integer array newNums of length n / 2.\n For every even index i where 0 <= i < n / 2, assign the value of newNums[i] as min(nums[2 * i], nums[2 * i + 1]).\n For every odd index i where 0 <= i < n / 2, assign the value of newNums[i] as max(nums[2 * i], nums[2 * i + 1]).\n Replace the array nums with newNums.\n Repeat the entire process starting from step 1.\n \n Return the last number that remains in nums after applying the algorithm.\n \n Example 1:\n \n \n >>> minMaxGame(nums = [1,3,5,2,4,8,2,2])\n >>> 1\n Explanation: The following arrays are the results of applying the algorithm repeatedly.\n First: nums = [1,5,4,2]\n Second: nums = [1,4]\n Third: nums = [1]\n 1 is the last remaining number, so we return 1.\n \n Example 2:\n \n >>> minMaxGame(nums = [3])\n >>> 3\n Explanation: 3 is already the last remaining number, so we return 3.\n \"\"\"\n"}
{"task_id": "partition-array-such-that-maximum-difference-is-k", "prompt": "def partitionArray(nums: List[int], k: int) -> int:\n \"\"\"\n You are given an integer array nums and an integer k. You may partition nums into one or more subsequences such that each element in nums appears in exactly one of the subsequences.\n Return the minimum number of subsequences needed such that the difference between the maximum and minimum values in each subsequence is at most k.\n A subsequence is a sequence that can be derived from another sequence by deleting some or no elements without changing the order of the remaining elements.\n \n Example 1:\n \n >>> partitionArray(nums = [3,6,1,2,5], k = 2)\n >>> 2\n Explanation:\n We can partition nums into the two subsequences [3,1,2] and [6,5].\n The difference between the maximum and minimum value in the first subsequence is 3 - 1 = 2.\n The difference between the maximum and minimum value in the second subsequence is 6 - 5 = 1.\n Since two subsequences were created, we return 2. It can be shown that 2 is the minimum number of subsequences needed.\n \n Example 2:\n \n >>> partitionArray(nums = [1,2,3], k = 1)\n >>> 2\n Explanation:\n We can partition nums into the two subsequences [1,2] and [3].\n The difference between the maximum and minimum value in the first subsequence is 2 - 1 = 1.\n The difference between the maximum and minimum value in the second subsequence is 3 - 3 = 0.\n Since two subsequences were created, we return 2. Note that another optimal solution is to partition nums into the two subsequences [1] and [2,3].\n \n Example 3:\n \n >>> partitionArray(nums = [2,2,4,5], k = 0)\n >>> 3\n Explanation:\n We can partition nums into the three subsequences [2,2], [4], and [5].\n The difference between the maximum and minimum value in the first subsequences is 2 - 2 = 0.\n The difference between the maximum and minimum value in the second subsequences is 4 - 4 = 0.\n The difference between the maximum and minimum value in the third subsequences is 5 - 5 = 0.\n Since three subsequences were created, we return 3. It can be shown that 3 is the minimum number of subsequences needed.\n \"\"\"\n"}
{"task_id": "replace-elements-in-an-array", "prompt": "def arrayChange(nums: List[int], operations: List[List[int]]) -> List[int]:\n \"\"\"\n You are given a 0-indexed array nums that consists of n distinct positive integers. Apply m operations to this array, where in the ith operation you replace the number operations[i][0] with operations[i][1].\n It is guaranteed that in the ith operation:\n \n operations[i][0] exists in nums.\n operations[i][1] does not exist in nums.\n \n Return the array obtained after applying all the operations.\n \n Example 1:\n \n >>> arrayChange(nums = [1,2,4,6], operations = [[1,3],[4,7],[6,1]])\n >>> [3,2,7,1]\n Explanation: We perform the following operations on nums:\n - Replace the number 1 with 3. nums becomes [3,2,4,6].\n - Replace the number 4 with 7. nums becomes [3,2,7,6].\n - Replace the number 6 with 1. nums becomes [3,2,7,1].\n We return the final array [3,2,7,1].\n \n Example 2:\n \n >>> arrayChange(nums = [1,2], operations = [[1,3],[2,1],[3,2]])\n >>> [2,1]\n Explanation: We perform the following operations to nums:\n - Replace the number 1 with 3. nums becomes [3,2].\n - Replace the number 2 with 1. nums becomes [3,1].\n - Replace the number 3 with 2. nums becomes [2,1].\n We return the array [2,1].\n \"\"\"\n"}
{"task_id": "jump-game-viii", "prompt": "def minCost(nums: List[int], costs: List[int]) -> int:\n \"\"\"\n You are given a 0-indexed integer array nums of length n. You are initially standing at index 0. You can jump from index i to index j where i < j if:\n \n nums[i] <= nums[j] and nums[k] < nums[i] for all indexes k in the range i < k < j, or\n nums[i] > nums[j] and nums[k] >= nums[i] for all indexes k in the range i < k < j.\n \n You are also given an integer array costs of length n where costs[i] denotes the cost of jumping to index i.\n Return the minimum cost to jump to the index n - 1.\n \n Example 1:\n \n >>> minCost(nums = [3,2,4,4,1], costs = [3,7,6,4,2])\n >>> 8\n Explanation: You start at index 0.\n - Jump to index 2 with a cost of costs[2] = 6.\n - Jump to index 4 with a cost of costs[4] = 2.\n The total cost is 8. It can be proven that 8 is the minimum cost needed.\n Two other possible paths are from index 0 -> 1 -> 4 and index 0 -> 2 -> 3 -> 4.\n These have a total cost of 9 and 12, respectively.\n \n Example 2:\n \n >>> minCost(nums = [0,1,2], costs = [1,1,1])\n >>> 2\n Explanation: Start at index 0.\n - Jump to index 1 with a cost of costs[1] = 1.\n - Jump to index 2 with a cost of costs[2] = 1.\n The total cost is 2. Note that you cannot jump directly from index 0 to index 2 because nums[0] <= nums[1].\n \"\"\"\n"}
{"task_id": "strong-password-checker-ii", "prompt": "def strongPasswordCheckerII(password: str) -> bool:\n \"\"\"\n A password is said to be strong if it satisfies all the following criteria:\n \n It has at least 8 characters.\n It contains at least one lowercase letter.\n It contains at least one uppercase letter.\n It contains at least one digit.\n It contains at least one special character. The special characters are the characters in the following string: \"!@#$%^&*()-+\".\n It does not contain 2 of the same character in adjacent positions (i.e., \"aab\" violates this condition, but \"aba\" does not).\n \n Given a string password, return true if it is a strong password. Otherwise, return false.\n \n Example 1:\n \n >>> strongPasswordCheckerII(password = \"IloveLe3tcode!\")\n >>> true\n Explanation: The password meets all the requirements. Therefore, we return true.\n \n Example 2:\n \n >>> strongPasswordCheckerII(password = \"Me+You--IsMyDream\")\n >>> false\n Explanation: The password does not contain a digit and also contains 2 of the same character in adjacent positions. Therefore, we return false.\n \n Example 3:\n \n >>> strongPasswordCheckerII(password = \"1aB!\")\n >>> false\n Explanation: The password does not meet the length requirement. Therefore, we return false.\n \"\"\"\n"}
{"task_id": "successful-pairs-of-spells-and-potions", "prompt": "def successfulPairs(spells: List[int], potions: List[int], success: int) -> List[int]:\n \"\"\"\n You are given two positive integer arrays spells and potions, of length n and m respectively, where spells[i] represents the strength of the ith spell and potions[j] represents the strength of the jth potion.\n You are also given an integer success. A spell and potion pair is considered successful if the product of their strengths is at least success.\n Return an integer array pairs of length n where pairs[i] is the number of potions that will form a successful pair with the ith spell.\n \n Example 1:\n \n >>> successfulPairs(spells = [5,1,3], potions = [1,2,3,4,5], success = 7)\n >>> [4,0,3]\n Explanation:\n - 0th spell: 5 * [1,2,3,4,5] = [5,10,15,20,25]. 4 pairs are successful.\n - 1st spell: 1 * [1,2,3,4,5] = [1,2,3,4,5]. 0 pairs are successful.\n - 2nd spell: 3 * [1,2,3,4,5] = [3,6,9,12,15]. 3 pairs are successful.\n Thus, [4,0,3] is returned.\n \n Example 2:\n \n >>> successfulPairs(spells = [3,1,2], potions = [8,5,8], success = 16)\n >>> [2,0,2]\n Explanation:\n - 0th spell: 3 * [8,5,8] = [24,15,24]. 2 pairs are successful.\n - 1st spell: 1 * [8,5,8] = [8,5,8]. 0 pairs are successful.\n - 2nd spell: 2 * [8,5,8] = [16,10,16]. 2 pairs are successful.\n Thus, [2,0,2] is returned.\n \"\"\"\n"}
{"task_id": "match-substring-after-replacement", "prompt": "def matchReplacement(s: str, sub: str, mappings: List[List[str]]) -> bool:\n \"\"\"\n You are given two strings s and sub. You are also given a 2D character array mappings where mappings[i] = [oldi, newi] indicates that you may perform the following operation any number of times:\n \n Replace a character oldi of sub with newi.\n \n Each character in sub cannot be replaced more than once.\n Return true if it is possible to make sub a substring of s by replacing zero or more characters according to mappings. Otherwise, return false.\n A substring is a contiguous non-empty sequence of characters within a string.\n \n Example 1:\n \n >>> matchReplacement(s = \"fool3e7bar\", sub = \"leet\", mappings = [[\"e\",\"3\"],[\"t\",\"7\"],[\"t\",\"8\"]])\n >>> true\n Explanation: Replace the first 'e' in sub with '3' and 't' in sub with '7'.\n Now sub = \"l3e7\" is a substring of s, so we return true.\n Example 2:\n \n >>> matchReplacement(s = \"fooleetbar\", sub = \"f00l\", mappings = [[\"o\",\"0\"]])\n >>> false\n Explanation: The string \"f00l\" is not a substring of s and no replacements can be made.\n Note that we cannot replace '0' with 'o'.\n \n Example 3:\n \n >>> matchReplacement(s = \"Fool33tbaR\", sub = \"leetd\", mappings = [[\"e\",\"3\"],[\"t\",\"7\"],[\"t\",\"8\"],[\"d\",\"b\"],[\"p\",\"b\"]])\n >>> true\n Explanation: Replace the first and second 'e' in sub with '3' and 'd' in sub with 'b'.\n Now sub = \"l33tb\" is a substring of s, so we return true.\n \"\"\"\n"}
{"task_id": "count-subarrays-with-score-less-than-k", "prompt": "def countSubarrays(nums: List[int], k: int) -> int:\n \"\"\"\n The score of an array is defined as the product of its sum and its length.\n \n For example, the score of [1, 2, 3, 4, 5] is (1 + 2 + 3 + 4 + 5) * 5 = 75.\n \n Given a positive integer array nums and an integer k, return the number of non-empty subarrays of nums whose score is strictly less than k.\n A subarray is a contiguous sequence of elements within an array.\n \n Example 1:\n \n >>> countSubarrays(nums = [2,1,4,3,5], k = 10)\n >>> 6\n Explanation:\n The 6 subarrays having scores less than 10 are:\n - [2] with score 2 * 1 = 2.\n - [1] with score 1 * 1 = 1.\n - [4] with score 4 * 1 = 4.\n - [3] with score 3 * 1 = 3.\n - [5] with score 5 * 1 = 5.\n - [2,1] with score (2 + 1) * 2 = 6.\n Note that subarrays such as [1,4] and [4,3,5] are not considered because their scores are 10 and 36 respectively, while we need scores strictly less than 10.\n Example 2:\n \n >>> countSubarrays(nums = [1,1,1], k = 5)\n >>> 5\n Explanation:\n Every subarray except [1,1,1] has a score less than 5.\n [1,1,1] has a score (1 + 1 + 1) * 3 = 9, which is greater than 5.\n Thus, there are 5 subarrays having scores less than 5.\n \"\"\"\n"}
{"task_id": "calculate-amount-paid-in-taxes", "prompt": "def calculateTax(brackets: List[List[int]], income: int) -> float:\n \"\"\"\n You are given a 0-indexed 2D integer array brackets where brackets[i] = [upperi, percenti] means that the ith tax bracket has an upper bound of upperi and is taxed at a rate of percenti. The brackets are sorted by upper bound (i.e. upperi-1 < upperi for 0 < i < brackets.length).\n Tax is calculated as follows:\n \n The first upper0 dollars earned are taxed at a rate of percent0.\n The next upper1 - upper0 dollars earned are taxed at a rate of percent1.\n The next upper2 - upper1 dollars earned are taxed at a rate of percent2.\n And so on.\n \n You are given an integer income representing the amount of money you earned. Return the amount of money that you have to pay in taxes. Answers within 10-5 of the actual answer will be accepted.\n \n Example 1:\n \n >>> calculateTax(brackets = [[3,50],[7,10],[12,25]], income = 10)\n >>> 2.65000\n Explanation:\n Based on your income, you have 3 dollars in the 1st tax bracket, 4 dollars in the 2nd tax bracket, and 3 dollars in the 3rd tax bracket.\n The tax rate for the three tax brackets is 50%, 10%, and 25%, respectively.\n In total, you pay $3 * 50% + $4 * 10% + $3 * 25% = $2.65 in taxes.\n \n Example 2:\n \n >>> calculateTax(brackets = [[1,0],[4,25],[5,50]], income = 2)\n >>> 0.25000\n Explanation:\n Based on your income, you have 1 dollar in the 1st tax bracket and 1 dollar in the 2nd tax bracket.\n The tax rate for the two tax brackets is 0% and 25%, respectively.\n In total, you pay $1 * 0% + $1 * 25% = $0.25 in taxes.\n \n Example 3:\n \n >>> calculateTax(brackets = [[2,50]], income = 0)\n >>> 0.00000\n Explanation:\n You have no income to tax, so you have to pay a total of $0 in taxes.\n \"\"\"\n"}
{"task_id": "minimum-path-cost-in-a-grid", "prompt": "def minPathCost(grid: List[List[int]], moveCost: List[List[int]]) -> int:\n \"\"\"\n You are given a 0-indexed m x n integer matrix grid consisting of distinct integers from 0 to m * n - 1. You can move in this matrix from a cell to any other cell in the next row. That is, if you are in cell (x, y) such that x < m - 1, you can move to any of the cells (x + 1, 0), (x + 1, 1), ..., (x + 1, n - 1). Note that it is not possible to move from cells in the last row.\n Each possible move has a cost given by a 0-indexed 2D array moveCost of size (m * n) x n, where moveCost[i][j] is the cost of moving from a cell with value i to a cell in column j of the next row. The cost of moving from cells in the last row of grid can be ignored.\n The cost of a path in grid is the sum of all values of cells visited plus the sum of costs of all the moves made. Return the minimum cost of a path that starts from any cell in the first row and ends at any cell in the last row.\n \n Example 1:\n \n \n >>> minPathCost(grid = [[5,3],[4,0],[2,1]], moveCost = [[9,8],[1,5],[10,12],[18,6],[2,4],[14,3]])\n >>> 17\n Explanation: The path with the minimum possible cost is the path 5 -> 0 -> 1.\n - The sum of the values of cells visited is 5 + 0 + 1 = 6.\n - The cost of moving from 5 to 0 is 3.\n - The cost of moving from 0 to 1 is 8.\n So the total cost of the path is 6 + 3 + 8 = 17.\n \n Example 2:\n \n >>> minPathCost(grid = [[5,1,2],[4,0,3]], moveCost = [[12,10,15],[20,23,8],[21,7,1],[8,1,13],[9,10,25],[5,3,2]])\n >>> 6\n Explanation: The path with the minimum possible cost is the path 2 -> 3.\n - The sum of the values of cells visited is 2 + 3 = 5.\n - The cost of moving from 2 to 3 is 1.\n So the total cost of this path is 5 + 1 = 6.\n \"\"\"\n"}
{"task_id": "fair-distribution-of-cookies", "prompt": "def distributeCookies(cookies: List[int], k: int) -> int:\n \"\"\"\n You are given an integer array cookies, where cookies[i] denotes the number of cookies in the ith bag. You are also given an integer k that denotes the number of children to distribute all the bags of cookies to. All the cookies in the same bag must go to the same child and cannot be split up.\n The unfairness of a distribution is defined as the maximum total cookies obtained by a single child in the distribution.\n Return the minimum unfairness of all distributions.\n \n Example 1:\n \n >>> distributeCookies(cookies = [8,15,10,20,8], k = 2)\n >>> 31\n Explanation: One optimal distribution is [8,15,8] and [10,20]\n - The 1st child receives [8,15,8] which has a total of 8 + 15 + 8 = 31 cookies.\n - The 2nd child receives [10,20] which has a total of 10 + 20 = 30 cookies.\n The unfairness of the distribution is max(31,30) = 31.\n It can be shown that there is no distribution with an unfairness less than 31.\n \n Example 2:\n \n >>> distributeCookies(cookies = [6,1,3,2,2,4,1,2], k = 3)\n >>> 7\n Explanation: One optimal distribution is [6,1], [3,2,2], and [4,1,2]\n - The 1st child receives [6,1] which has a total of 6 + 1 = 7 cookies.\n - The 2nd child receives [3,2,2] which has a total of 3 + 2 + 2 = 7 cookies.\n - The 3rd child receives [4,1,2] which has a total of 4 + 1 + 2 = 7 cookies.\n The unfairness of the distribution is max(7,7,7) = 7.\n It can be shown that there is no distribution with an unfairness less than 7.\n \"\"\"\n"}
{"task_id": "naming-a-company", "prompt": "def distinctNames(ideas: List[str]) -> int:\n \"\"\"\n You are given an array of strings ideas that represents a list of names to be used in the process of naming a company. The process of naming a company is as follows:\n \n Choose 2 distinct names from ideas, call them ideaA and ideaB.\n Swap the first letters of ideaA and ideaB with each other.\n If both of the new names are not found in the original ideas, then the name ideaA ideaB (the concatenation of ideaA and ideaB, separated by a space) is a valid company name.\n Otherwise, it is not a valid name.\n \n Return the number of distinct valid names for the company.\n \n Example 1:\n \n >>> distinctNames(ideas = [\"coffee\",\"donuts\",\"time\",\"toffee\"])\n >>> 6\n Explanation: The following selections are valid:\n - (\"coffee\", \"donuts\"): The company name created is \"doffee conuts\".\n - (\"donuts\", \"coffee\"): The company name created is \"conuts doffee\".\n - (\"donuts\", \"time\"): The company name created is \"tonuts dime\".\n - (\"donuts\", \"toffee\"): The company name created is \"tonuts doffee\".\n - (\"time\", \"donuts\"): The company name created is \"dime tonuts\".\n - (\"toffee\", \"donuts\"): The company name created is \"doffee tonuts\".\n Therefore, there are a total of 6 distinct company names.\n \n The following are some examples of invalid selections:\n - (\"coffee\", \"time\"): The name \"toffee\" formed after swapping already exists in the original array.\n - (\"time\", \"toffee\"): Both names are still the same after swapping and exist in the original array.\n - (\"coffee\", \"toffee\"): Both names formed after swapping already exist in the original array.\n \n Example 2:\n \n >>> distinctNames(ideas = [\"lack\",\"back\"])\n >>> 0\n Explanation: There are no valid selections. Therefore, 0 is returned.\n \"\"\"\n"}
{"task_id": "check-for-contradictions-in-equations", "prompt": "def checkContradictions(equations: List[List[str]], values: List[float]) -> bool:\n \"\"\"\n You are given a 2D array of strings equations and an array of real numbers values, where equations[i] = [Ai, Bi] and values[i] means that Ai / Bi = values[i].\n Determine if there exists a contradiction in the equations. Return true if there is a contradiction, or false otherwise.\n Note:\n \n When checking if two numbers are equal, check that their absolute difference is less than 10-5.\n The testcases are generated such that there are no cases targeting precision, i.e. using double is enough to solve the problem.\n \n \n Example 1:\n \n >>> checkContradictions(equations = [[\"a\",\"b\"],[\"b\",\"c\"],[\"a\",\"c\"]], values = [3,0.5,1.5])\n >>> false\n Explanation:\n The given equations are: a / b = 3, b / c = 0.5, a / c = 1.5\n There are no contradictions in the equations. One possible assignment to satisfy all equations is:\n a = 3, b = 1 and c = 2.\n \n Example 2:\n \n >>> checkContradictions(equations = [[\"le\",\"et\"],[\"le\",\"code\"],[\"code\",\"et\"]], values = [2,5,0.5])\n >>> true\n Explanation:\n The given equations are: le / et = 2, le / code = 5, code / et = 0.5\n Based on the first two equations, we get code / et = 0.4.\n Since the third equation is code / et = 0.5, we get a contradiction.\n \"\"\"\n"}
{"task_id": "greatest-english-letter-in-upper-and-lower-case", "prompt": "def greatestLetter(s: str) -> str:\n \"\"\"\n Given a string of English letters s, return the greatest English letter which occurs as both a lowercase and uppercase letter in s. The returned letter should be in uppercase. If no such letter exists, return an empty string.\n An English letter b is greater than another letter a if b appears after a in the English alphabet.\n \n Example 1:\n \n >>> greatestLetter(s = \"lEeTcOdE\")\n >>> \"E\"\n Explanation:\n The letter 'E' is the only letter to appear in both lower and upper case.\n \n Example 2:\n \n >>> greatestLetter(s = \"arRAzFif\")\n >>> \"R\"\n Explanation:\n The letter 'R' is the greatest letter to appear in both lower and upper case.\n Note that 'A' and 'F' also appear in both lower and upper case, but 'R' is greater than 'F' or 'A'.\n \n Example 3:\n \n >>> greatestLetter(s = \"AbCdEfGhIjK\")\n >>> \"\"\n Explanation:\n There is no letter that appears in both lower and upper case.\n \"\"\"\n"}
{"task_id": "sum-of-numbers-with-units-digit-k", "prompt": "def minimumNumbers(num: int, k: int) -> int:\n \"\"\"\n Given two integers num and k, consider a set of positive integers with the following properties:\n \n The units digit of each integer is k.\n The sum of the integers is num.\n \n Return the minimum possible size of such a set, or -1 if no such set exists.\n Note:\n \n The set can contain multiple instances of the same integer, and the sum of an empty set is considered 0.\n The units digit of a number is the rightmost digit of the number.\n \n \n Example 1:\n \n >>> minimumNumbers(num = 58, k = 9)\n >>> 2\n Explanation:\n One valid set is [9,49], as the sum is 58 and each integer has a units digit of 9.\n Another valid set is [19,39].\n It can be shown that 2 is the minimum possible size of a valid set.\n \n Example 2:\n \n >>> minimumNumbers(num = 37, k = 2)\n >>> -1\n Explanation: It is not possible to obtain a sum of 37 using only integers that have a units digit of 2.\n \n Example 3:\n \n >>> minimumNumbers(num = 0, k = 7)\n >>> 0\n Explanation: The sum of an empty set is considered 0.\n \"\"\"\n"}
{"task_id": "longest-binary-subsequence-less-than-or-equal-to-k", "prompt": "def longestSubsequence(s: str, k: int) -> int:\n \"\"\"\n You are given a binary string s and a positive integer k.\n Return the length of the longest subsequence of s that makes up a binary number less than or equal to k.\n Note:\n \n The subsequence can contain leading zeroes.\n The empty string is considered to be equal to 0.\n A subsequence is a string that can be derived from another string by deleting some or no characters without changing the order of the remaining characters.\n \n \n Example 1:\n \n >>> longestSubsequence(s = \"1001010\", k = 5)\n >>> 5\n Explanation: The longest subsequence of s that makes up a binary number less than or equal to 5 is \"00010\", as this number is equal to 2 in decimal.\n Note that \"00100\" and \"00101\" are also possible, which are equal to 4 and 5 in decimal, respectively.\n The length of this subsequence is 5, so 5 is returned.\n \n Example 2:\n \n >>> longestSubsequence(s = \"00101001\", k = 1)\n >>> 6\n Explanation: \"000001\" is the longest subsequence of s that makes up a binary number less than or equal to 1, as this number is equal to 1 in decimal.\n The length of this subsequence is 6, so 6 is returned.\n \"\"\"\n"}
{"task_id": "selling-pieces-of-wood", "prompt": "def sellingWood(m: int, n: int, prices: List[List[int]]) -> int:\n \"\"\"\n You are given two integers m and n that represent the height and width of a rectangular piece of wood. You are also given a 2D integer array prices, where prices[i] = [hi, wi, pricei] indicates you can sell a rectangular piece of wood of height hi and width wi for pricei dollars.\n To cut a piece of wood, you must make a vertical or horizontal cut across the entire height or width of the piece to split it into two smaller pieces. After cutting a piece of wood into some number of smaller pieces, you can sell pieces according to prices. You may sell multiple pieces of the same shape, and you do not have to sell all the shapes. The grain of the wood makes a difference, so you cannot rotate a piece to swap its height and width.\n Return the maximum money you can earn after cutting an m x n piece of wood.\n Note that you can cut the piece of wood as many times as you want.\n \n Example 1:\n \n \n >>> sellingWood(m = 3, n = 5, prices = [[1,4,2],[2,2,7],[2,1,3]])\n >>> 19\n Explanation: The diagram above shows a possible scenario. It consists of:\n - 2 pieces of wood shaped 2 x 2, selling for a price of 2 * 7 = 14.\n - 1 piece of wood shaped 2 x 1, selling for a price of 1 * 3 = 3.\n - 1 piece of wood shaped 1 x 4, selling for a price of 1 * 2 = 2.\n This obtains a total of 14 + 3 + 2 = 19 money earned.\n It can be shown that 19 is the maximum amount of money that can be earned.\n \n Example 2:\n \n \n >>> sellingWood(m = 4, n = 6, prices = [[3,2,10],[1,4,2],[4,1,3]])\n >>> 32\n Explanation: The diagram above shows a possible scenario. It consists of:\n - 3 pieces of wood shaped 3 x 2, selling for a price of 3 * 10 = 30.\n - 1 piece of wood shaped 1 x 4, selling for a price of 1 * 2 = 2.\n This obtains a total of 30 + 2 = 32 money earned.\n It can be shown that 32 is the maximum amount of money that can be earned.\n Notice that we cannot rotate the 1 x 4 piece of wood to obtain a 4 x 1 piece of wood.\n \"\"\"\n"}
{"task_id": "count-asterisks", "prompt": "def countAsterisks(s: str) -> int:\n \"\"\"\n You are given a string s, where every two consecutive vertical bars '|' are grouped into a pair. In other words, the 1st and 2nd '|' make a pair, the 3rd and 4th '|' make a pair, and so forth.\n Return the number of '*' in s, excluding the '*' between each pair of '|'.\n Note that each '|' will belong to exactly one pair.\n \n Example 1:\n \n >>> countAsterisks(s = \"l|*e*et|c**o|*de|\")\n >>> 2\n Explanation: The considered characters are underlined: \"l|*e*et|c**o|*de|\".\n The characters between the first and second '|' are excluded from the answer.\n Also, the characters between the third and fourth '|' are excluded from the answer.\n There are 2 asterisks considered. Therefore, we return 2.\n Example 2:\n \n >>> countAsterisks(s = \"iamprogrammer\")\n >>> 0\n Explanation: In this example, there are no asterisks in s. Therefore, we return 0.\n \n Example 3:\n \n >>> countAsterisks(s = \"yo|uar|e**|b|e***au|tifu|l\")\n >>> 5\n Explanation: The considered characters are underlined: \"yo|uar|e**|b|e***au|tifu|l\". There are 5 asterisks considered. Therefore, we return 5.\n \"\"\"\n"}
{"task_id": "count-unreachable-pairs-of-nodes-in-an-undirected-graph", "prompt": "def countPairs(n: int, edges: List[List[int]]) -> int:\n \"\"\"\n You are given an integer n. There is an undirected graph with n nodes, numbered from 0 to n - 1. You are given a 2D integer array edges where edges[i] = [ai, bi] denotes that there exists an undirected edge connecting nodes ai and bi.\n Return the number of pairs of different nodes that are unreachable from each other.\n \n Example 1:\n \n \n >>> countPairs(n = 3, edges = [[0,1],[0,2],[1,2]])\n >>> 0\n Explanation: There are no pairs of nodes that are unreachable from each other. Therefore, we return 0.\n \n Example 2:\n \n \n >>> countPairs(n = 7, edges = [[0,2],[0,5],[2,4],[1,6],[5,4]])\n >>> 14\n Explanation: There are 14 pairs of nodes that are unreachable from each other:\n [[0,1],[0,3],[0,6],[1,2],[1,3],[1,4],[1,5],[2,3],[2,6],[3,4],[3,5],[3,6],[4,6],[5,6]].\n Therefore, we return 14.\n \"\"\"\n"}
{"task_id": "maximum-xor-after-operations", "prompt": "def maximumXOR(nums: List[int]) -> int:\n \"\"\"\n You are given a 0-indexed integer array nums. In one operation, select any non-negative integer x and an index i, then update nums[i] to be equal to nums[i] AND (nums[i] XOR x).\n Note that AND is the bitwise AND operation and XOR is the bitwise XOR operation.\n Return the maximum possible bitwise XOR of all elements of nums after applying the operation any number of times.\n \n Example 1:\n \n >>> maximumXOR(nums = [3,2,4,6])\n >>> 7\n Explanation: Apply the operation with x = 4 and i = 3, num[3] = 6 AND (6 XOR 4) = 6 AND 2 = 2.\n Now, nums = [3, 2, 4, 2] and the bitwise XOR of all the elements = 3 XOR 2 XOR 4 XOR 2 = 7.\n It can be shown that 7 is the maximum possible bitwise XOR.\n Note that other operations may be used to achieve a bitwise XOR of 7.\n Example 2:\n \n >>> maximumXOR(nums = [1,2,3,9,2])\n >>> 11\n Explanation: Apply the operation zero times.\n The bitwise XOR of all the elements = 1 XOR 2 XOR 3 XOR 9 XOR 2 = 11.\n It can be shown that 11 is the maximum possible bitwise XOR.\n \"\"\"\n"}
{"task_id": "number-of-distinct-roll-sequences", "prompt": "def distinctSequences(n: int) -> int:\n \"\"\"\n You are given an integer n. You roll a fair 6-sided dice n times. Determine the total number of distinct sequences of rolls possible such that the following conditions are satisfied:\n \n The greatest common divisor of any adjacent values in the sequence is equal to 1.\n There is at least a gap of 2 rolls between equal valued rolls. More formally, if the value of the ith roll is equal to the value of the jth roll, then abs(i - j) > 2.\n \n Return the total number of distinct sequences possible. Since the answer may be very large, return it modulo 109 + 7.\n Two sequences are considered distinct if at least one element is different.\n \n Example 1:\n \n >>> distinctSequences(n = 4)\n >>> 184\n Explanation: Some of the possible sequences are (1, 2, 3, 4), (6, 1, 2, 3), (1, 2, 3, 1), etc.\n Some invalid sequences are (1, 2, 1, 3), (1, 2, 3, 6).\n (1, 2, 1, 3) is invalid since the first and third roll have an equal value and abs(1 - 3) = 2 (i and j are 1-indexed).\n (1, 2, 3, 6) is invalid since the greatest common divisor of 3 and 6 = 3.\n There are a total of 184 distinct sequences possible, so we return 184.\n Example 2:\n \n >>> distinctSequences(n = 2)\n >>> 22\n Explanation: Some of the possible sequences are (1, 2), (2, 1), (3, 2).\n Some invalid sequences are (3, 6), (2, 4) since the greatest common divisor is not equal to 1.\n There are a total of 22 distinct sequences possible, so we return 22.\n \"\"\"\n"}
{"task_id": "check-if-matrix-is-x-matrix", "prompt": "def checkXMatrix(grid: List[List[int]]) -> bool:\n \"\"\"\n A square matrix is said to be an X-Matrix if both of the following conditions hold:\n \n All the elements in the diagonals of the matrix are non-zero.\n All other elements are 0.\n \n Given a 2D integer array grid of size n x n representing a square matrix, return true if grid is an X-Matrix. Otherwise, return false.\n \n Example 1:\n \n \n >>> checkXMatrix(grid = [[2,0,0,1],[0,3,1,0],[0,5,2,0],[4,0,0,2]])\n >>> true\n Explanation: Refer to the diagram above.\n An X-Matrix should have the green elements (diagonals) be non-zero and the red elements be 0.\n Thus, grid is an X-Matrix.\n \n Example 2:\n \n \n >>> checkXMatrix(grid = [[5,7,0],[0,3,1],[0,5,0]])\n >>> false\n Explanation: Refer to the diagram above.\n An X-Matrix should have the green elements (diagonals) be non-zero and the red elements be 0.\n Thus, grid is not an X-Matrix.\n \"\"\"\n"}
{"task_id": "count-number-of-ways-to-place-houses", "prompt": "def countHousePlacements(n: int) -> int:\n \"\"\"\n There is a street with n * 2 plots, where there are n plots on each side of the street. The plots on each side are numbered from 1 to n. On each plot, a house can be placed.\n Return the number of ways houses can be placed such that no two houses are adjacent to each other on the same side of the street. Since the answer may be very large, return it modulo 109 + 7.\n Note that if a house is placed on the ith plot on one side of the street, a house can also be placed on the ith plot on the other side of the street.\n \n Example 1:\n \n >>> countHousePlacements(n = 1)\n >>> 4\n Explanation:\n Possible arrangements:\n 1. All plots are empty.\n 2. A house is placed on one side of the street.\n 3. A house is placed on the other side of the street.\n 4. Two houses are placed, one on each side of the street.\n \n Example 2:\n \n \n >>> countHousePlacements(n = 2)\n >>> 9\n Explanation: The 9 possible arrangements are shown in the diagram above.\n \"\"\"\n"}
{"task_id": "maximum-score-of-spliced-array", "prompt": "def maximumsSplicedArray(nums1: List[int], nums2: List[int]) -> int:\n \"\"\"\n You are given two 0-indexed integer arrays nums1 and nums2, both of length n.\n You can choose two integers left and right where 0 <= left <= right < n and swap the subarray nums1[left...right] with the subarray nums2[left...right].\n \n For example, if nums1 = [1,2,3,4,5] and nums2 = [11,12,13,14,15] and you choose left = 1 and right = 2, nums1 becomes [1,12,13,4,5] and nums2 becomes [11,2,3,14,15].\n \n You may choose to apply the mentioned operation once or not do anything.\n The score of the arrays is the maximum of sum(nums1) and sum(nums2), where sum(arr) is the sum of all the elements in the array arr.\n Return the maximum possible score.\n A subarray is a contiguous sequence of elements within an array. arr[left...right] denotes the subarray that contains the elements of nums between indices left and right (inclusive).\n \n Example 1:\n \n >>> maximumsSplicedArray(nums1 = [60,60,60], nums2 = [10,90,10])\n >>> 210\n Explanation: Choosing left = 1 and right = 1, we have nums1 = [60,90,60] and nums2 = [10,60,10].\n The score is max(sum(nums1), sum(nums2)) = max(210, 80) = 210.\n Example 2:\n \n >>> maximumsSplicedArray(nums1 = [20,40,20,70,30], nums2 = [50,20,50,40,20])\n >>> 220\n Explanation: Choosing left = 3, right = 4, we have nums1 = [20,40,20,40,20] and nums2 = [50,20,50,70,30].\n The score is max(sum(nums1), sum(nums2)) = max(140, 220) = 220.\n \n Example 3:\n \n >>> maximumsSplicedArray(nums1 = [7,11,13], nums2 = [1,1,1])\n >>> 31\n Explanation: We choose not to swap any subarray.\n The score is max(sum(nums1), sum(nums2)) = max(31, 3) = 31.\n \"\"\"\n"}
{"task_id": "minimum-score-after-removals-on-a-tree", "prompt": "def minimumScore(nums: List[int], edges: List[List[int]]) -> int:\n \"\"\"\n There is an undirected connected tree with n nodes labeled from 0 to n - 1 and n - 1 edges.\n You are given a 0-indexed integer array nums of length n where nums[i] represents the value of the ith node. You are also given a 2D integer array edges of length n - 1 where edges[i] = [ai, bi] indicates that there is an edge between nodes ai and bi in the tree.\n Remove two distinct edges of the tree to form three connected components. For a pair of removed edges, the following steps are defined:\n \n Get the XOR of all the values of the nodes for each of the three components respectively.\n The difference between the largest XOR value and the smallest XOR value is the score of the pair.\n \n \n For example, say the three components have the node values: [4,5,7], [1,9], and [3,3,3]. The three XOR values are 4 ^ 5 ^ 7 = 6, 1 ^ 9 = 8, and 3 ^ 3 ^ 3 = 3. The largest XOR value is 8 and the smallest XOR value is 3. The score is then 8 - 3 = 5.\n \n Return the minimum score of any possible pair of edge removals on the given tree.\n \n Example 1:\n \n \n >>> minimumScore(nums = [1,5,5,4,11], edges = [[0,1],[1,2],[1,3],[3,4]])\n >>> 9\n Explanation: The diagram above shows a way to make a pair of removals.\n - The 1st component has nodes [1,3,4] with values [5,4,11]. Its XOR value is 5 ^ 4 ^ 11 = 10.\n - The 2nd component has node [0] with value [1]. Its XOR value is 1 = 1.\n - The 3rd component has node [2] with value [5]. Its XOR value is 5 = 5.\n The score is the difference between the largest and smallest XOR value which is 10 - 1 = 9.\n It can be shown that no other pair of removals will obtain a smaller score than 9.\n \n Example 2:\n \n \n >>> minimumScore(nums = [5,5,2,4,4,2], edges = [[0,1],[1,2],[5,2],[4,3],[1,3]])\n >>> 0\n Explanation: The diagram above shows a way to make a pair of removals.\n - The 1st component has nodes [3,4] with values [4,4]. Its XOR value is 4 ^ 4 = 0.\n - The 2nd component has nodes [1,0] with values [5,5]. Its XOR value is 5 ^ 5 = 0.\n - The 3rd component has nodes [2,5] with values [2,2]. Its XOR value is 2 ^ 2 = 0.\n The score is the difference between the largest and smallest XOR value which is 0 - 0 = 0.\n We cannot obtain a smaller score than 0.\n \"\"\"\n"}
{"task_id": "find-minimum-time-to-finish-all-jobs-ii", "prompt": "def minimumTime(jobs: List[int], workers: List[int]) -> int:\n \"\"\"\n You are given two 0-indexed integer arrays jobs and workers of equal length, where jobs[i] is the amount of time needed to complete the ith job, and workers[j] is the amount of time the jth worker can work each day.\n Each job should be assigned to exactly one worker, such that each worker completes exactly one job.\n Return the minimum number of days needed to complete all the jobs after assignment.\n \n Example 1:\n \n >>> minimumTime(jobs = [5,2,4], workers = [1,7,5])\n >>> 2\n Explanation:\n - Assign the 2nd worker to the 0th job. It takes them 1 day to finish the job.\n - Assign the 0th worker to the 1st job. It takes them 2 days to finish the job.\n - Assign the 1st worker to the 2nd job. It takes them 1 day to finish the job.\n It takes 2 days for all the jobs to be completed, so return 2.\n It can be proven that 2 days is the minimum number of days needed.\n \n Example 2:\n \n >>> minimumTime(jobs = [3,18,15,9], workers = [6,5,1,3])\n >>> 3\n Explanation:\n - Assign the 2nd worker to the 0th job. It takes them 3 days to finish the job.\n - Assign the 0th worker to the 1st job. It takes them 3 days to finish the job.\n - Assign the 1st worker to the 2nd job. It takes them 3 days to finish the job.\n - Assign the 3rd worker to the 3rd job. It takes them 3 days to finish the job.\n It takes 3 days for all the jobs to be completed, so return 3.\n It can be proven that 3 days is the minimum number of days needed.\n \"\"\"\n"}
{"task_id": "decode-the-message", "prompt": "def decodeMessage(key: str, message: str) -> str:\n \"\"\"\n You are given the strings key and message, which represent a cipher key and a secret message, respectively. The steps to decode message are as follows:\n \n Use the first appearance of all 26 lowercase English letters in key as the order of the substitution table.\n Align the substitution table with the regular English alphabet.\n Each letter in message is then substituted using the table.\n Spaces ' ' are transformed to themselves.\n \n \n For example, given key = \"happy boy\" (actual key would have at least one instance of each letter in the alphabet), we have the partial substitution table of ('h' -> 'a', 'a' -> 'b', 'p' -> 'c', 'y' -> 'd', 'b' -> 'e', 'o' -> 'f').\n \n Return the decoded message.\n \n Example 1:\n \n \n >>> decodeMessage(key = \"the quick brown fox jumps over the lazy dog\", message = \"vkbs bs t suepuv\")\n >>> \"this is a secret\"\n Explanation: The diagram above shows the substitution table.\n It is obtained by taking the first appearance of each letter in \"the quick brown fox jumps over the lazy dog\".\n \n Example 2:\n \n \n >>> decodeMessage(key = \"eljuxhpwnyrdgtqkviszcfmabo\", message = \"zwx hnfx lqantp mnoeius ycgk vcnjrdb\")\n >>> \"the five boxing wizards jump quickly\"\n Explanation: The diagram above shows the substitution table.\n It is obtained by taking the first appearance of each letter in \"eljuxhpwnyrdgtqkviszcfmabo\".\n \"\"\"\n"}
{"task_id": "spiral-matrix-iv", "prompt": "# class ListNode:\n# def __init__(val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution:\n def spiralMatrix(m: int, n: int, head: Optional[ListNode]) -> List[List[int]]:\n \"\"\"\n You are given two integers m and n, which represent the dimensions of a matrix.\n You are also given the head of a linked list of integers.\n Generate an m x n matrix that contains the integers in the linked list presented in spiral order (clockwise), starting from the top-left of the matrix. If there are remaining empty spaces, fill them with -1.\n Return the generated matrix.\n \n Example 1:\n \n \n >>> __init__(m = 3, n = 5, head = [3,0,2,6,8,1,7,9,4,2,5,5,0])\n >>> [[3,0,2,6,8],[5,0,-1,-1,1],[5,2,4,9,7]]\n Explanation: The diagram above shows how the values are printed in the matrix.\n Note that the remaining spaces in the matrix are filled with -1.\n \n Example 2:\n \n \n >>> __init__(m = 1, n = 4, head = [0,1,2])\n >>> [[0,1,2,-1]]\n Explanation: The diagram above shows how the values are printed from left to right in the matrix.\n The last space in the matrix is set to -1.\n \"\"\"\n"}
{"task_id": "number-of-people-aware-of-a-secret", "prompt": "def peopleAwareOfSecret(n: int, delay: int, forget: int) -> int:\n \"\"\"\n On day 1, one person discovers a secret.\n You are given an integer delay, which means that each person will share the secret with a new person every day, starting from delay days after discovering the secret. You are also given an integer forget, which means that each person will forget the secret forget days after discovering it. A person cannot share the secret on the same day they forgot it, or on any day afterwards.\n Given an integer n, return the number of people who know the secret at the end of day n. Since the answer may be very large, return it modulo 109 + 7.\n \n Example 1:\n \n >>> peopleAwareOfSecret(n = 6, delay = 2, forget = 4)\n >>> 5\n Explanation:\n Day 1: Suppose the first person is named A. (1 person)\n Day 2: A is the only person who knows the secret. (1 person)\n Day 3: A shares the secret with a new person, B. (2 people)\n Day 4: A shares the secret with a new person, C. (3 people)\n Day 5: A forgets the secret, and B shares the secret with a new person, D. (3 people)\n Day 6: B shares the secret with E, and C shares the secret with F. (5 people)\n \n Example 2:\n \n >>> peopleAwareOfSecret(n = 4, delay = 1, forget = 3)\n >>> 6\n Explanation:\n Day 1: The first person is named A. (1 person)\n Day 2: A shares the secret with B. (2 people)\n Day 3: A and B share the secret with 2 new people, C and D. (4 people)\n Day 4: A forgets the secret. B, C, and D share the secret with 3 new people. (6 people)\n \"\"\"\n"}
{"task_id": "number-of-increasing-paths-in-a-grid", "prompt": "def countPaths(grid: List[List[int]]) -> int:\n \"\"\"\n You are given an m x n integer matrix grid, where you can move from a cell to any adjacent cell in all 4 directions.\n Return the number of strictly increasing paths in the grid such that you can start from any cell and end at any cell. Since the answer may be very large, return it modulo 109 + 7.\n Two paths are considered different if they do not have exactly the same sequence of visited cells.\n \n Example 1:\n \n \n >>> countPaths(grid = [[1,1],[3,4]])\n >>> 8\n Explanation: The strictly increasing paths are:\n - Paths with length 1: [1], [1], [3], [4].\n - Paths with length 2: [1 -> 3], [1 -> 4], [3 -> 4].\n - Paths with length 3: [1 -> 3 -> 4].\n The total number of paths is 4 + 3 + 1 = 8.\n \n Example 2:\n \n >>> countPaths(grid = [[1],[2]])\n >>> 3\n Explanation: The strictly increasing paths are:\n - Paths with length 1: [1], [2].\n - Paths with length 2: [1 -> 2].\n The total number of paths is 2 + 1 = 3.\n \"\"\"\n"}
{"task_id": "valid-palindrome-iv", "prompt": "def makePalindrome(s: str) -> bool:\n \"\"\"\n You are given a 0-indexed string s consisting of only lowercase English letters. In one operation, you can change any character of s to any other character.\n Return true if you can make s a palindrome after performing exactly one or two operations, or return false otherwise.\n \n Example 1:\n \n >>> makePalindrome(s = \"abcdba\")\n >>> true\n Explanation: One way to make s a palindrome using 1 operation is:\n - Change s[2] to 'd'. Now, s = \"abddba\".\n One operation could be performed to make s a palindrome so return true.\n \n Example 2:\n \n >>> makePalindrome(s = \"aa\")\n >>> true\n Explanation: One way to make s a palindrome using 2 operations is:\n - Change s[0] to 'b'. Now, s = \"ba\".\n - Change s[1] to 'b'. Now, s = \"bb\".\n Two operations could be performed to make s a palindrome so return true.\n \n Example 3:\n \n >>> makePalindrome(s = \"abcdef\")\n >>> false\n Explanation: It is not possible to make s a palindrome using one or two operations so return false.\n \"\"\"\n"}
{"task_id": "evaluate-boolean-binary-tree", "prompt": "# class TreeNode:\n# def __init__(val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def evaluateTree(root: Optional[TreeNode]) -> bool:\n \"\"\"\n You are given the root of a full binary tree with the following properties:\n \n Leaf nodes have either the value 0 or 1, where 0 represents False and 1 represents True.\n Non-leaf nodes have either the value 2 or 3, where 2 represents the boolean OR and 3 represents the boolean AND.\n \n The evaluation of a node is as follows:\n \n If the node is a leaf node, the evaluation is the value of the node, i.e. True or False.\n Otherwise, evaluate the node's two children and apply the boolean operation of its value with the children's evaluations.\n \n Return the boolean result of evaluating the root node.\n A full binary tree is a binary tree where each node has either 0 or 2 children.\n A leaf node is a node that has zero children.\n \n Example 1:\n \n \n >>> __init__(root = [2,1,3,null,null,0,1])\n >>> true\n Explanation: The above diagram illustrates the evaluation process.\n The AND node evaluates to False AND True = False.\n The OR node evaluates to True OR False = True.\n The root node evaluates to True, so we return true.\n Example 2:\n \n >>> __init__(root = [0])\n >>> false\n Explanation: The root node is a leaf node and it evaluates to false, so we return false.\n \"\"\"\n"}
{"task_id": "the-latest-time-to-catch-a-bus", "prompt": "def latestTimeCatchTheBus(buses: List[int], passengers: List[int], capacity: int) -> int:\n \"\"\"\n You are given a 0-indexed integer array buses of length n, where buses[i] represents the departure time of the ith bus. You are also given a 0-indexed integer array passengers of length m, where passengers[j] represents the arrival time of the jth passenger. All bus departure times are unique. All passenger arrival times are unique.\n You are given an integer capacity, which represents the maximum number of passengers that can get on each bus.\n When a passenger arrives, they will wait in line for the next available bus. You can get on a bus that departs at x minutes if you arrive at y minutes where y <= x, and the bus is not full. Passengers with the earliest arrival times get on the bus first.\n More formally when a bus arrives, either:\n \n If capacity or fewer passengers are waiting for a bus, they will all get on the bus, or\n The capacity passengers with the earliest arrival times will get on the bus.\n \n Return the latest time you may arrive at the bus station to catch a bus. You cannot arrive at the same time as another passenger.\n Note: The arrays buses and passengers are not necessarily sorted.\n \n Example 1:\n \n >>> latestTimeCatchTheBus(buses = [10,20], passengers = [2,17,18,19], capacity = 2)\n >>> 16\n Explanation: Suppose you arrive at time 16.\n At time 10, the first bus departs with the 0th passenger.\n At time 20, the second bus departs with you and the 1st passenger.\n Note that you may not arrive at the same time as another passenger, which is why you must arrive before the 1st passenger to catch the bus.\n Example 2:\n \n >>> latestTimeCatchTheBus(buses = [20,30,10], passengers = [19,13,26,4,25,11,21], capacity = 2)\n >>> 20\n Explanation: Suppose you arrive at time 20.\n At time 10, the first bus departs with the 3rd passenger.\n At time 20, the second bus departs with the 5th and 1st passengers.\n At time 30, the third bus departs with the 0th passenger and you.\n Notice if you had arrived any later, then the 6th passenger would have taken your seat on the third bus.\n \"\"\"\n"}
{"task_id": "minimum-sum-of-squared-difference", "prompt": "def minSumSquareDiff(nums1: List[int], nums2: List[int], k1: int, k2: int) -> int:\n \"\"\"\n You are given two positive 0-indexed integer arrays nums1 and nums2, both of length n.\n The sum of squared difference of arrays nums1 and nums2 is defined as the sum of (nums1[i] - nums2[i])2 for each 0 <= i < n.\n You are also given two positive integers k1 and k2. You can modify any of the elements of nums1 by +1 or -1 at most k1 times. Similarly, you can modify any of the elements of nums2 by +1 or -1 at most k2 times.\n Return the minimum sum of squared difference after modifying array nums1 at most k1 times and modifying array nums2 at most k2 times.\n Note: You are allowed to modify the array elements to become negative integers.\n \n Example 1:\n \n >>> minSumSquareDiff(nums1 = [1,2,3,4], nums2 = [2,10,20,19], k1 = 0, k2 = 0)\n >>> 579\n Explanation: The elements in nums1 and nums2 cannot be modified because k1 = 0 and k2 = 0.\n The sum of square difference will be: (1 - 2)2 + (2 - 10)2 + (3 - 20)2 + (4 - 19)2\u00a0= 579.\n \n Example 2:\n \n >>> minSumSquareDiff(nums1 = [1,4,10,12], nums2 = [5,8,6,9], k1 = 1, k2 = 1)\n >>> 43\n Explanation: One way to obtain the minimum sum of square difference is:\n - Increase nums1[0] once.\n - Increase nums2[2] once.\n The minimum of the sum of square difference will be:\n (2 - 5)2 + (4 - 8)2 + (10 - 7)2 + (12 - 9)2\u00a0= 43.\n Note that, there are other ways to obtain the minimum of the sum of square difference, but there is no way to obtain a sum smaller than 43.\n \"\"\"\n"}
{"task_id": "subarray-with-elements-greater-than-varying-threshold", "prompt": "def validSubarraySize(nums: List[int], threshold: int) -> int:\n \"\"\"\n You are given an integer array nums and an integer threshold.\n Find any subarray of nums of length k such that every element in the subarray is greater than threshold / k.\n Return the size of any such subarray. If there is no such subarray, return -1.\n A subarray is a contiguous non-empty sequence of elements within an array.\n \n Example 1:\n \n >>> validSubarraySize(nums = [1,3,4,3,1], threshold = 6)\n >>> 3\n Explanation: The subarray [3,4,3] has a size of 3, and every element is greater than 6 / 3 = 2.\n Note that this is the only valid subarray.\n \n Example 2:\n \n >>> validSubarraySize(nums = [6,5,6,5,8], threshold = 7)\n >>> 1\n Explanation: The subarray [8] has a size of 1, and 8 > 7 / 1 = 7. So 1 is returned.\n Note that the subarray [6,5] has a size of 2, and every element is greater than 7 / 2 = 3.5.\n Similarly, the subarrays [6,5,6], [6,5,6,5], [6,5,6,5,8] also satisfy the given conditions.\n Therefore, 2, 3, 4, or 5 may also be returned.\n \"\"\"\n"}
{"task_id": "minimum-amount-of-time-to-fill-cups", "prompt": "def fillCups(amount: List[int]) -> int:\n \"\"\"\n You have a water dispenser that can dispense cold, warm, and hot water. Every second, you can either fill up 2 cups with different types of water, or 1 cup of any type of water.\n You are given a 0-indexed integer array amount of length 3 where amount[0], amount[1], and amount[2] denote the number of cold, warm, and hot water cups you need to fill respectively. Return the minimum number of seconds needed to fill up all the cups.\n \n Example 1:\n \n >>> fillCups(amount = [1,4,2])\n >>> 4\n Explanation: One way to fill up the cups is:\n Second 1: Fill up a cold cup and a warm cup.\n Second 2: Fill up a warm cup and a hot cup.\n Second 3: Fill up a warm cup and a hot cup.\n Second 4: Fill up a warm cup.\n It can be proven that 4 is the minimum number of seconds needed.\n \n Example 2:\n \n >>> fillCups(amount = [5,4,4])\n >>> 7\n Explanation: One way to fill up the cups is:\n Second 1: Fill up a cold cup, and a hot cup.\n Second 2: Fill up a cold cup, and a warm cup.\n Second 3: Fill up a cold cup, and a warm cup.\n Second 4: Fill up a warm cup, and a hot cup.\n Second 5: Fill up a cold cup, and a hot cup.\n Second 6: Fill up a cold cup, and a warm cup.\n Second 7: Fill up a hot cup.\n \n Example 3:\n \n >>> fillCups(amount = [5,0,0])\n >>> 5\n Explanation: Every second, we fill up a cold cup.\n \"\"\"\n"}
{"task_id": "move-pieces-to-obtain-a-string", "prompt": "def canChange(start: str, target: str) -> bool:\n \"\"\"\n You are given two strings start and target, both of length n. Each string consists only of the characters 'L', 'R', and '_' where:\n \n The characters 'L' and 'R' represent pieces, where a piece 'L' can move to the left only if there is a blank space directly to its left, and a piece 'R' can move to the right only if there is a blank space directly to its right.\n The character '_' represents a blank space that can be occupied by any of the 'L' or 'R' pieces.\n \n Return true if it is possible to obtain the string target by moving the pieces of the string start any number of times. Otherwise, return false.\n \n Example 1:\n \n >>> canChange(start = \"_L__R__R_\", target = \"L______RR\")\n >>> true\n Explanation: We can obtain the string target from start by doing the following moves:\n - Move the first piece one step to the left, start becomes equal to \"L___R__R_\".\n - Move the last piece one step to the right, start becomes equal to \"L___R___R\".\n - Move the second piece three steps to the right, start becomes equal to \"L______RR\".\n Since it is possible to get the string target from start, we return true.\n \n Example 2:\n \n >>> canChange(start = \"R_L_\", target = \"__LR\")\n >>> false\n Explanation: The 'R' piece in the string start can move one step to the right to obtain \"_RL_\".\n After that, no pieces can move anymore, so it is impossible to obtain the string target from start.\n \n Example 3:\n \n >>> canChange(start = \"_R\", target = \"R_\")\n >>> false\n Explanation: The piece in the string start can move only to the right, so it is impossible to obtain the string target from start.\n \"\"\"\n"}
{"task_id": "count-the-number-of-ideal-arrays", "prompt": "def idealArrays(n: int, maxValue: int) -> int:\n \"\"\"\n You are given two integers n and maxValue, which are used to describe an ideal array.\n A 0-indexed integer array arr of length n is considered ideal if the following conditions hold:\n \n Every arr[i] is a value from 1 to maxValue, for 0 <= i < n.\n Every arr[i] is divisible by arr[i - 1], for 0 < i < n.\n \n Return the number of distinct ideal arrays of length n. Since the answer may be very large, return it modulo 109 + 7.\n \n Example 1:\n \n >>> idealArrays(n = 2, maxValue = 5)\n >>> 10\n Explanation: The following are the possible ideal arrays:\n - Arrays starting with the value 1 (5 arrays): [1,1], [1,2], [1,3], [1,4], [1,5]\n - Arrays starting with the value 2 (2 arrays): [2,2], [2,4]\n - Arrays starting with the value 3 (1 array): [3,3]\n - Arrays starting with the value 4 (1 array): [4,4]\n - Arrays starting with the value 5 (1 array): [5,5]\n There are a total of 5 + 2 + 1 + 1 + 1 = 10 distinct ideal arrays.\n \n Example 2:\n \n >>> idealArrays(n = 5, maxValue = 3)\n >>> 11\n Explanation: The following are the possible ideal arrays:\n - Arrays starting with the value 1 (9 arrays):\n - With no other distinct values (1 array): [1,1,1,1,1]\n - With 2nd distinct value 2 (4 arrays): [1,1,1,1,2], [1,1,1,2,2], [1,1,2,2,2], [1,2,2,2,2]\n - With 2nd distinct value 3 (4 arrays): [1,1,1,1,3], [1,1,1,3,3], [1,1,3,3,3], [1,3,3,3,3]\n - Arrays starting with the value 2 (1 array): [2,2,2,2,2]\n - Arrays starting with the value 3 (1 array): [3,3,3,3,3]\n There are a total of 9 + 1 + 1 = 11 distinct ideal arrays.\n \"\"\"\n"}
{"task_id": "minimum-adjacent-swaps-to-make-a-valid-array", "prompt": "def minimumSwaps(nums: List[int]) -> int:\n \"\"\"\n You are given a 0-indexed integer array nums.\n Swaps of adjacent elements are able to be performed on nums.\n A valid array meets the following conditions:\n \n The largest element (any of the largest elements if there are multiple) is at the rightmost position in the array.\n The smallest element (any of the smallest elements if there are multiple) is at the leftmost position in the array.\n \n Return the minimum swaps required to make nums a valid array.\n \n Example 1:\n \n >>> minimumSwaps(nums = [3,4,5,5,3,1])\n >>> 6\n Explanation: Perform the following swaps:\n - Swap 1: Swap the 3rd and 4th elements, nums is then [3,4,5,3,5,1].\n - Swap 2: Swap the 4th and 5th elements, nums is then [3,4,5,3,1,5].\n - Swap 3: Swap the 3rd and 4th elements, nums is then [3,4,5,1,3,5].\n - Swap 4: Swap the 2nd and 3rd elements, nums is then [3,4,1,5,3,5].\n - Swap 5: Swap the 1st and 2nd elements, nums is then [3,1,4,5,3,5].\n - Swap 6: Swap the 0th and 1st elements, nums is then [1,3,4,5,3,5].\n It can be shown that 6 swaps is the minimum swaps required to make a valid array.\n \n Example 2:\n \n >>> minimumSwaps(nums = [9])\n >>> 0\n Explanation: The array is already valid, so we return 0.\n \"\"\"\n"}
{"task_id": "maximum-number-of-pairs-in-array", "prompt": "def numberOfPairs(nums: List[int]) -> List[int]:\n \"\"\"\n You are given a 0-indexed integer array nums. In one operation, you may do the following:\n \n Choose two integers in nums that are equal.\n Remove both integers from nums, forming a pair.\n \n The operation is done on nums as many times as possible.\n Return a 0-indexed integer array answer of size 2 where answer[0] is the number of pairs that are formed and answer[1] is the number of leftover integers in nums after doing the operation as many times as possible.\n \n Example 1:\n \n >>> numberOfPairs(nums = [1,3,2,1,3,2,2])\n >>> [3,1]\n Explanation:\n Form a pair with nums[0] and nums[3] and remove them from nums. Now, nums = [3,2,3,2,2].\n Form a pair with nums[0] and nums[2] and remove them from nums. Now, nums = [2,2,2].\n Form a pair with nums[0] and nums[1] and remove them from nums. Now, nums = [2].\n No more pairs can be formed. A total of 3 pairs have been formed, and there is 1 number leftover in nums.\n \n Example 2:\n \n >>> numberOfPairs(nums = [1,1])\n >>> [1,0]\n Explanation: Form a pair with nums[0] and nums[1] and remove them from nums. Now, nums = [].\n No more pairs can be formed. A total of 1 pair has been formed, and there are 0 numbers leftover in nums.\n \n Example 3:\n \n >>> numberOfPairs(nums = [0])\n >>> [0,1]\n Explanation: No pairs can be formed, and there is 1 number leftover in nums.\n \"\"\"\n"}
{"task_id": "max-sum-of-a-pair-with-equal-sum-of-digits", "prompt": "def maximumSum(nums: List[int]) -> int:\n \"\"\"\n You are given a 0-indexed array nums consisting of positive integers. You can choose two indices i and j, such that i != j, and the sum of digits of the number nums[i] is equal to that of nums[j].\n Return the maximum value of nums[i] + nums[j] that you can obtain over all possible indices i and j that satisfy the conditions. If no such pair of indices exists, return -1.\n \n Example 1:\n \n >>> maximumSum(nums = [18,43,36,13,7])\n >>> 54\n Explanation: The pairs (i, j) that satisfy the conditions are:\n - (0, 2), both numbers have a sum of digits equal to 9, and their sum is 18 + 36 = 54.\n - (1, 4), both numbers have a sum of digits equal to 7, and their sum is 43 + 7 = 50.\n So the maximum sum that we can obtain is 54.\n \n Example 2:\n \n >>> maximumSum(nums = [10,12,19,14])\n >>> -1\n Explanation: There are no two numbers that satisfy the conditions, so we return -1.\n \"\"\"\n"}
{"task_id": "query-kth-smallest-trimmed-number", "prompt": "def smallestTrimmedNumbers(nums: List[str], queries: List[List[int]]) -> List[int]:\n \"\"\"\n You are given a 0-indexed array of strings nums, where each string is of equal length and consists of only digits.\n You are also given a 0-indexed 2D integer array queries where queries[i] = [ki, trimi]. For each queries[i], you need to:\n \n Trim each number in nums to its rightmost trimi digits.\n Determine the index of the kith smallest trimmed number in nums. If two trimmed numbers are equal, the number with the lower index is considered to be smaller.\n Reset each number in nums to its original length.\n \n Return an array answer of the same length as queries, where answer[i] is the answer to the ith query.\n Note:\n \n To trim to the rightmost x digits means to keep removing the leftmost digit, until only x digits remain.\n Strings in nums may contain leading zeros.\n \n \n Example 1:\n \n >>> smallestTrimmedNumbers(nums = [\"102\",\"473\",\"251\",\"814\"], queries = [[1,1],[2,3],[4,2],[1,2]])\n >>> [2,2,1,0]\n Explanation:\n 1. After trimming to the last digit, nums = [\"2\",\"3\",\"1\",\"4\"]. The smallest number is 1 at index 2.\n 2. Trimmed to the last 3 digits, nums is unchanged. The 2nd smallest number is 251 at index 2.\n 3. Trimmed to the last 2 digits, nums = [\"02\",\"73\",\"51\",\"14\"]. The 4th smallest number is 73.\n 4. Trimmed to the last 2 digits, the smallest number is 2 at index 0.\n Note that the trimmed number \"02\" is evaluated as 2.\n \n Example 2:\n \n >>> smallestTrimmedNumbers(nums = [\"24\",\"37\",\"96\",\"04\"], queries = [[2,1],[2,2]])\n >>> [3,0]\n Explanation:\n 1. Trimmed to the last digit, nums = [\"4\",\"7\",\"6\",\"4\"]. The 2nd smallest number is 4 at index 3.\n There are two occurrences of 4, but the one at index 0 is considered smaller than the one at index 3.\n 2. Trimmed to the last 2 digits, nums is unchanged. The 2nd smallest number is 24.\n \"\"\"\n"}
{"task_id": "minimum-deletions-to-make-array-divisible", "prompt": "def minOperations(nums: List[int], numsDivide: List[int]) -> int:\n \"\"\"\n You are given two positive integer arrays nums and numsDivide. You can delete any number of elements from nums.\n Return the minimum number of deletions such that the smallest element in nums divides all the elements of numsDivide. If this is not possible, return -1.\n Note that an integer x divides y if y % x == 0.\n \n Example 1:\n \n >>> minOperations(nums = [2,3,2,4,3], numsDivide = [9,6,9,3,15])\n >>> 2\n Explanation:\n The smallest element in [2,3,2,4,3] is 2, which does not divide all the elements of numsDivide.\n We use 2 deletions to delete the elements in nums that are equal to 2 which makes nums = [3,4,3].\n The smallest element in [3,4,3] is 3, which divides all the elements of numsDivide.\n It can be shown that 2 is the minimum number of deletions needed.\n \n Example 2:\n \n >>> minOperations(nums = [4,3,6], numsDivide = [8,2,6,10])\n >>> -1\n Explanation:\n We want the smallest element in nums to divide all the elements of numsDivide.\n There is no way to delete elements from nums to allow this.\n \"\"\"\n"}
{"task_id": "finding-the-number-of-visible-mountains", "prompt": "def visibleMountains(peaks: List[List[int]]) -> int:\n \"\"\"\n You are given a 0-indexed 2D integer array peaks where peaks[i] = [xi, yi] states that mountain i has a peak at coordinates (xi, yi). A mountain can be described as a right-angled isosceles triangle, with its base along the x-axis and a right angle at its peak. More formally, the gradients of ascending and descending the mountain are 1 and -1 respectively.\n A mountain is considered visible if its peak does not lie within another mountain (including the border of other mountains).\n Return the number of visible mountains.\n \n Example 1:\n \n \n >>> visibleMountains(peaks = [[2,2],[6,3],[5,4]])\n >>> 2\n Explanation: The diagram above shows the mountains.\n - Mountain 0 is visible since its peak does not lie within another mountain or its sides.\n - Mountain 1 is not visible since its peak lies within the side of mountain 2.\n - Mountain 2 is visible since its peak does not lie within another mountain or its sides.\n There are 2 mountains that are visible.\n Example 2:\n \n \n >>> visibleMountains(peaks = [[1,3],[1,3]])\n >>> 0\n Explanation: The diagram above shows the mountains (they completely overlap).\n Both mountains are not visible since their peaks lie within each other.\n \"\"\"\n"}
{"task_id": "best-poker-hand", "prompt": "def bestHand(ranks: List[int], suits: List[str]) -> str:\n \"\"\"\n You are given an integer array ranks and a character array suits. You have 5 cards where the ith card has a rank of ranks[i] and a suit of suits[i].\n The following are the types of poker hands you can make from best to worst:\n \n \"Flush\": Five cards of the same suit.\n \"Three of a Kind\": Three cards of the same rank.\n \"Pair\": Two cards of the same rank.\n \"High Card\": Any single card.\n \n Return a string representing the best type of poker hand you can make with the given cards.\n Note that the return values are case-sensitive.\n \n Example 1:\n \n >>> bestHand(ranks = [13,2,3,1,9], suits = [\"a\",\"a\",\"a\",\"a\",\"a\"])\n >>> \"Flush\"\n Explanation: The hand with all the cards consists of 5 cards with the same suit, so we have a \"Flush\".\n \n Example 2:\n \n >>> bestHand(ranks = [4,4,2,4,4], suits = [\"d\",\"a\",\"a\",\"b\",\"c\"])\n >>> \"Three of a Kind\"\n Explanation: The hand with the first, second, and fourth card consists of 3 cards with the same rank, so we have a \"Three of a Kind\".\n Note that we could also make a \"Pair\" hand but \"Three of a Kind\" is a better hand.\n Also note that other cards could be used to make the \"Three of a Kind\" hand.\n Example 3:\n \n >>> bestHand(ranks = [10,10,2,12,9], suits = [\"a\",\"b\",\"c\",\"a\",\"d\"])\n >>> \"Pair\"\n Explanation: The hand with the first and second card consists of 2 cards with the same rank, so we have a \"Pair\".\n Note that we cannot make a \"Flush\" or a \"Three of a Kind\".\n \"\"\"\n"}
{"task_id": "number-of-zero-filled-subarrays", "prompt": "def zeroFilledSubarray(nums: List[int]) -> int:\n \"\"\"\n Given an integer array nums, return the number of subarrays filled with 0.\n A subarray is a contiguous non-empty sequence of elements within an array.\n \n Example 1:\n \n >>> zeroFilledSubarray(nums = [1,3,0,0,2,0,0,4])\n >>> 6\n Explanation:\n There are 4 occurrences of [0] as a subarray.\n There are 2 occurrences of [0,0] as a subarray.\n There is no occurrence of a subarray with a size more than 2 filled with 0. Therefore, we return 6.\n Example 2:\n \n >>> zeroFilledSubarray(nums = [0,0,0,2,0,0])\n >>> 9\n Explanation:\n There are 5 occurrences of [0] as a subarray.\n There are 3 occurrences of [0,0] as a subarray.\n There is 1 occurrence of [0,0,0] as a subarray.\n There is no occurrence of a subarray with a size more than 3 filled with 0. Therefore, we return 9.\n \n Example 3:\n \n >>> zeroFilledSubarray(nums = [2,10,2019])\n >>> 0\n Explanation: There is no subarray filled with 0. Therefore, we return 0.\n \"\"\"\n"}
{"task_id": "shortest-impossible-sequence-of-rolls", "prompt": "def shortestSequence(rolls: List[int], k: int) -> int:\n \"\"\"\n You are given an integer array rolls of length n and an integer k. You roll a k sided dice numbered from 1 to k, n times, where the result of the ith roll is rolls[i].\n Return the length of the shortest sequence of rolls so that there's no such subsequence in rolls.\n A sequence of rolls of length len is the result of rolling a k sided dice len times.\n \n Example 1:\n \n >>> shortestSequence(rolls = [4,2,1,2,3,3,2,4,1], k = 4)\n >>> 3\n Explanation: Every sequence of rolls of length 1, [1], [2], [3], [4], can be taken from rolls.\n Every sequence of rolls of length 2, [1, 1], [1, 2], ..., [4, 4], can be taken from rolls.\n The sequence [1, 4, 2] cannot be taken from rolls, so we return 3.\n Note that there are other sequences that cannot be taken from rolls.\n Example 2:\n \n >>> shortestSequence(rolls = [1,1,2,2], k = 2)\n >>> 2\n Explanation: Every sequence of rolls of length 1, [1], [2], can be taken from rolls.\n The sequence [2, 1] cannot be taken from rolls, so we return 2.\n Note that there are other sequences that cannot be taken from rolls but [2, 1] is the shortest.\n \n Example 3:\n \n >>> shortestSequence(rolls = [1,1,3,2,2,2,3,3], k = 4)\n >>> 1\n Explanation: The sequence [4] cannot be taken from rolls, so we return 1.\n Note that there are other sequences that cannot be taken from rolls but [4] is the shortest.\n \"\"\"\n"}
{"task_id": "first-letter-to-appear-twice", "prompt": "def repeatedCharacter(s: str) -> str:\n \"\"\"\n Given a string s consisting of lowercase English letters, return the first letter to appear twice.\n Note:\n \n A letter a appears twice before another letter b if the second occurrence of a is before the second occurrence of b.\n s will contain at least one letter that appears twice.\n \n \n Example 1:\n \n >>> repeatedCharacter(s = \"abccbaacz\")\n >>> \"c\"\n Explanation:\n The letter 'a' appears on the indexes 0, 5 and 6.\n The letter 'b' appears on the indexes 1 and 4.\n The letter 'c' appears on the indexes 2, 3 and 7.\n The letter 'z' appears on the index 8.\n The letter 'c' is the first letter to appear twice, because out of all the letters the index of its second occurrence is the smallest.\n \n Example 2:\n \n >>> repeatedCharacter(s = \"abcdd\")\n >>> \"d\"\n Explanation:\n The only letter that appears twice is 'd' so we return 'd'.\n \"\"\"\n"}
{"task_id": "equal-row-and-column-pairs", "prompt": "def equalPairs(grid: List[List[int]]) -> int:\n \"\"\"\n Given a 0-indexed n x n integer matrix grid, return the number of pairs (ri, cj) such that row ri and column cj are equal.\n A row and column pair is considered equal if they contain the same elements in the same order (i.e., an equal array).\n \n Example 1:\n \n \n >>> equalPairs(grid = [[3,2,1],[1,7,6],[2,7,7]])\n >>> 1\n Explanation: There is 1 equal row and column pair:\n - (Row 2, Column 1): [2,7,7]\n \n Example 2:\n \n \n >>> equalPairs(grid = [[3,1,2,2],[1,4,4,5],[2,4,2,2],[2,4,2,2]])\n >>> 3\n Explanation: There are 3 equal row and column pairs:\n - (Row 0, Column 0): [3,1,2,2]\n - (Row 2, Column 2): [2,4,2,2]\n - (Row 3, Column 2): [2,4,2,2]\n \"\"\"\n"}
{"task_id": "number-of-excellent-pairs", "prompt": "def countExcellentPairs(nums: List[int], k: int) -> int:\n \"\"\"\n You are given a 0-indexed positive integer array nums and a positive integer k.\n A pair of numbers (num1, num2) is called excellent if the following conditions are satisfied:\n \n Both the numbers num1 and num2 exist in the array nums.\n The sum of the number of set bits in num1 OR num2 and num1 AND num2 is greater than or equal to k, where OR is the bitwise OR operation and AND is the bitwise AND operation.\n \n Return the number of distinct excellent pairs.\n Two pairs (a, b) and (c, d) are considered distinct if either a != c or b != d. For example, (1, 2) and (2, 1) are distinct.\n Note that a pair (num1, num2) such that num1 == num2 can also be excellent if you have at least one occurrence of num1 in the array.\n \n Example 1:\n \n >>> countExcellentPairs(nums = [1,2,3,1], k = 3)\n >>> 5\n Explanation: The excellent pairs are the following:\n - (3, 3). (3 AND 3) and (3 OR 3) are both equal to (11) in binary. The total number of set bits is 2 + 2 = 4, which is greater than or equal to k = 3.\n - (2, 3) and (3, 2). (2 AND 3) is equal to (10) in binary, and (2 OR 3) is equal to (11) in binary. The total number of set bits is 1 + 2 = 3.\n - (1, 3) and (3, 1). (1 AND 3) is equal to (01) in binary, and (1 OR 3) is equal to (11) in binary. The total number of set bits is 1 + 2 = 3.\n So the number of excellent pairs is 5.\n Example 2:\n \n >>> countExcellentPairs(nums = [5,1,1], k = 10)\n >>> 0\n Explanation: There are no excellent pairs for this array.\n \"\"\"\n"}
{"task_id": "maximum-number-of-books-you-can-take", "prompt": "def maximumBooks(books: List[int]) -> int:\n \"\"\"\n You are given a 0-indexed integer array books of length n where books[i] denotes the number of books on the ith shelf of a bookshelf.\n You are going to take books from a contiguous section of the bookshelf spanning from l to r where 0 <= l <= r < n. For each index i in the range l <= i < r, you must take strictly fewer books from shelf i than shelf i + 1.\n Return the maximum number of books you can take from the bookshelf.\n \n Example 1:\n \n >>> maximumBooks(books = [8,5,2,7,9])\n >>> 19\n Explanation:\n - Take 1 book from shelf 1.\n - Take 2 books from shelf 2.\n - Take 7 books from shelf 3.\n - Take 9 books from shelf 4.\n You have taken 19 books, so return 19.\n It can be proven that 19 is the maximum number of books you can take.\n \n Example 2:\n \n >>> maximumBooks(books = [7,0,3,4,5])\n >>> 12\n Explanation:\n - Take 3 books from shelf 2.\n - Take 4 books from shelf 3.\n - Take 5 books from shelf 4.\n You have taken 12 books so return 12.\n It can be proven that 12 is the maximum number of books you can take.\n \n Example 3:\n \n >>> maximumBooks(books = [8,2,3,7,3,4,0,1,4,3])\n >>> 13\n Explanation:\n - Take 1 book from shelf 0.\n - Take 2 books from shelf 1.\n - Take 3 books from shelf 2.\n - Take 7 books from shelf 3.\n You have taken 13 books so return 13.\n It can be proven that 13 is the maximum number of books you can take.\n \"\"\"\n"}
{"task_id": "make-array-zero-by-subtracting-equal-amounts", "prompt": "def minimumOperations(nums: List[int]) -> int:\n \"\"\"\n You are given a non-negative integer array nums. In one operation, you must:\n \n Choose a positive integer x such that x is less than or equal to the smallest non-zero element in nums.\n Subtract x from every positive element in nums.\n \n Return the minimum number of operations to make every element in nums equal to 0.\n \n Example 1:\n \n >>> minimumOperations(nums = [1,5,0,3,5])\n >>> 3\n Explanation:\n In the first operation, choose x = 1. Now, nums = [0,4,0,2,4].\n In the second operation, choose x = 2. Now, nums = [0,2,0,0,2].\n In the third operation, choose x = 2. Now, nums = [0,0,0,0,0].\n \n Example 2:\n \n >>> minimumOperations(nums = [0])\n >>> 0\n Explanation: Each element in nums is already 0 so no operations are needed.\n \"\"\"\n"}
{"task_id": "maximum-number-of-groups-entering-a-competition", "prompt": "def maximumGroups(grades: List[int]) -> int:\n \"\"\"\n You are given a positive integer array grades which represents the grades of students in a university. You would like to enter all these students into a competition in ordered non-empty groups, such that the ordering meets the following conditions:\n \n The sum of the grades of students in the ith group is less than the sum of the grades of students in the (i + 1)th group, for all groups (except the last).\n The total number of students in the ith group is less than the total number of students in the (i + 1)th group, for all groups (except the last).\n \n Return the maximum number of groups that can be formed.\n \n Example 1:\n \n >>> maximumGroups(grades = [10,6,12,7,3,5])\n >>> 3\n Explanation: The following is a possible way to form 3 groups of students:\n - 1st group has the students with grades = [12]. Sum of grades: 12. Student count: 1\n - 2nd group has the students with grades = [6,7]. Sum of grades: 6 + 7 = 13. Student count: 2\n - 3rd group has the students with grades = [10,3,5]. Sum of grades: 10 + 3 + 5 = 18. Student count: 3\n It can be shown that it is not possible to form more than 3 groups.\n \n Example 2:\n \n >>> maximumGroups(grades = [8,8])\n >>> 1\n Explanation: We can only form 1 group, since forming 2 groups would lead to an equal number of students in both groups.\n \"\"\"\n"}
{"task_id": "find-closest-node-to-given-two-nodes", "prompt": "def closestMeetingNode(edges: List[int], node1: int, node2: int) -> int:\n \"\"\"\n You are given a directed graph of n nodes numbered from 0 to n - 1, where each node has at most one outgoing edge.\n The graph is represented with a given 0-indexed array edges of size n, indicating that there is a directed edge from node i to node edges[i]. If there is no outgoing edge from i, then edges[i] == -1.\n You are also given two integers node1 and node2.\n Return the index of the node that can be reached from both node1 and node2, such that the maximum between the distance from node1 to that node, and from node2 to that node is minimized. If there are multiple answers, return the node with the smallest index, and if no possible answer exists, return -1.\n Note that edges may contain cycles.\n \n Example 1:\n \n \n >>> closestMeetingNode(edges = [2,2,3,-1], node1 = 0, node2 = 1)\n >>> 2\n Explanation: The distance from node 0 to node 2 is 1, and the distance from node 1 to node 2 is 1.\n The maximum of those two distances is 1. It can be proven that we cannot get a node with a smaller maximum distance than 1, so we return node 2.\n \n Example 2:\n \n \n >>> closestMeetingNode(edges = [1,2,-1], node1 = 0, node2 = 2)\n >>> 2\n Explanation: The distance from node 0 to node 2 is 2, and the distance from node 2 to itself is 0.\n The maximum of those two distances is 2. It can be proven that we cannot get a node with a smaller maximum distance than 2, so we return node 2.\n \"\"\"\n"}
{"task_id": "longest-cycle-in-a-graph", "prompt": "def longestCycle(edges: List[int]) -> int:\n \"\"\"\n You are given a directed graph of n nodes numbered from 0 to n - 1, where each node has at most one outgoing edge.\n The graph is represented with a given 0-indexed array edges of size n, indicating that there is a directed edge from node i to node edges[i]. If there is no outgoing edge from node i, then edges[i] == -1.\n Return the length of the longest cycle in the graph. If no cycle exists, return -1.\n A cycle is a path that starts and ends at the same node.\n \n Example 1:\n \n \n >>> longestCycle(edges = [3,3,4,2,3])\n >>> 3\n Explanation: The longest cycle in the graph is the cycle: 2 -> 4 -> 3 -> 2.\n The length of this cycle is 3, so 3 is returned.\n \n Example 2:\n \n \n >>> longestCycle(edges = [2,-1,3,1])\n >>> -1\n Explanation: There are no cycles in this graph.\n \"\"\"\n"}
{"task_id": "minimum-costs-using-the-train-line", "prompt": "def minimumCosts(regular: List[int], express: List[int], expressCost: int) -> List[int]:\n \"\"\"\n A train line going through a city has two routes, the regular route and the express route. Both routes go through the same n + 1 stops labeled from 0 to n. Initially, you start on the regular route at stop 0.\n You are given two 1-indexed integer arrays regular and express, both of length n. regular[i] describes the cost it takes to go from stop i - 1 to stop i using the regular route, and express[i] describes the cost it takes to go from stop i - 1 to stop i using the express route.\n You are also given an integer expressCost which represents the cost to transfer from the regular route to the express route.\n Note that:\n \n There is no cost to transfer from the express route back to the regular route.\n You pay expressCost every time you transfer from the regular route to the express route.\n There is no extra cost to stay on the express route.\n \n Return a 1-indexed array costs of length n, where costs[i] is the minimum cost to reach stop i from stop 0.\n Note that a stop can be counted as reached from either route.\n \n Example 1:\n \n \n >>> minimumCosts(regular = [1,6,9,5], express = [5,2,3,10], expressCost = 8)\n >>> [1,7,14,19]\n Explanation: The diagram above shows how to reach stop 4 from stop 0 with minimum cost.\n - Take the regular route from stop 0 to stop 1, costing 1.\n - Take the express route from stop 1 to stop 2, costing 8 + 2 = 10.\n - Take the express route from stop 2 to stop 3, costing 3.\n - Take the regular route from stop 3 to stop 4, costing 5.\n The total cost is 1 + 10 + 3 + 5 = 19.\n Note that a different route could be taken to reach the other stops with minimum cost.\n \n Example 2:\n \n \n >>> minimumCosts(regular = [11,5,13], express = [7,10,6], expressCost = 3)\n >>> [10,15,24]\n Explanation: The diagram above shows how to reach stop 3 from stop 0 with minimum cost.\n - Take the express route from stop 0 to stop 1, costing 3 + 7 = 10.\n - Take the regular route from stop 1 to stop 2, costing 5.\n - Take the express route from stop 2 to stop 3, costing 3 + 6 = 9.\n The total cost is 10 + 5 + 9 = 24.\n Note that the expressCost is paid again to transfer back to the express route.\n \"\"\"\n"}
{"task_id": "merge-similar-items", "prompt": "def mergeSimilarItems(items1: List[List[int]], items2: List[List[int]]) -> List[List[int]]:\n \"\"\"\n You are given two 2D integer arrays, items1 and items2, representing two sets of items. Each array items has the following properties:\n \n items[i] = [valuei, weighti] where valuei represents the value and weighti represents the weight of the ith item.\n The value of each item in items is unique.\n \n Return a 2D integer array ret where ret[i] = [valuei, weighti], with weighti being the sum of weights of all items with value valuei.\n Note: ret should be returned in ascending order by value.\n \n Example 1:\n \n >>> mergeSimilarItems(items1 = [[1,1],[4,5],[3,8]], items2 = [[3,1],[1,5]])\n >>> [[1,6],[3,9],[4,5]]\n Explanation:\n The item with value = 1 occurs in items1 with weight = 1 and in items2 with weight = 5, total weight = 1 + 5 = 6.\n The item with value = 3 occurs in items1 with weight = 8 and in items2 with weight = 1, total weight = 8 + 1 = 9.\n The item with value = 4 occurs in items1 with weight = 5, total weight = 5.\n Therefore, we return [[1,6],[3,9],[4,5]].\n \n Example 2:\n \n >>> mergeSimilarItems(items1 = [[1,1],[3,2],[2,3]], items2 = [[2,1],[3,2],[1,3]])\n >>> [[1,4],[2,4],[3,4]]\n Explanation:\n The item with value = 1 occurs in items1 with weight = 1 and in items2 with weight = 3, total weight = 1 + 3 = 4.\n The item with value = 2 occurs in items1 with weight = 3 and in items2 with weight = 1, total weight = 3 + 1 = 4.\n The item with value = 3 occurs in items1 with weight = 2 and in items2 with weight = 2, total weight = 2 + 2 = 4.\n Therefore, we return [[1,4],[2,4],[3,4]].\n Example 3:\n \n >>> mergeSimilarItems(items1 = [[1,3],[2,2]], items2 = [[7,1],[2,2],[1,4]])\n >>> [[1,7],[2,4],[7,1]]\n Explanation:\n The item with value = 1 occurs in items1 with weight = 3 and in items2 with weight = 4, total weight = 3 + 4 = 7.\n The item with value = 2 occurs in items1 with weight = 2 and in items2 with weight = 2, total weight = 2 + 2 = 4.\n The item with value = 7 occurs in items2 with weight = 1, total weight = 1.\n Therefore, we return [[1,7],[2,4],[7,1]].\n \"\"\"\n"}
{"task_id": "count-number-of-bad-pairs", "prompt": "def countBadPairs(nums: List[int]) -> int:\n \"\"\"\n You are given a 0-indexed integer array nums. A pair of indices (i, j) is a bad pair if i < j and j - i != nums[j] - nums[i].\n Return the total number of bad pairs in nums.\n \n Example 1:\n \n >>> countBadPairs(nums = [4,1,3,3])\n >>> 5\n Explanation: The pair (0, 1) is a bad pair since 1 - 0 != 1 - 4.\n The pair (0, 2) is a bad pair since 2 - 0 != 3 - 4, 2 != -1.\n The pair (0, 3) is a bad pair since 3 - 0 != 3 - 4, 3 != -1.\n The pair (1, 2) is a bad pair since 2 - 1 != 3 - 1, 1 != 2.\n The pair (2, 3) is a bad pair since 3 - 2 != 3 - 3, 1 != 0.\n There are a total of 5 bad pairs, so we return 5.\n \n Example 2:\n \n >>> countBadPairs(nums = [1,2,3,4,5])\n >>> 0\n Explanation: There are no bad pairs.\n \"\"\"\n"}
{"task_id": "task-scheduler-ii", "prompt": "def taskSchedulerII(tasks: List[int], space: int) -> int:\n \"\"\"\n You are given a 0-indexed array of positive integers tasks, representing tasks that need to be completed in order, where tasks[i] represents the type of the ith task.\n You are also given a positive integer space, which represents the minimum number of days that must pass after the completion of a task before another task of the same type can be performed.\n Each day, until all tasks have been completed, you must either:\n \n Complete the next task from tasks, or\n Take a break.\n \n Return the minimum number of days needed to complete all tasks.\n \n Example 1:\n \n >>> taskSchedulerII(tasks = [1,2,1,2,3,1], space = 3)\n >>> 9\n Explanation:\n One way to complete all tasks in 9 days is as follows:\n Day 1: Complete the 0th task.\n Day 2: Complete the 1st task.\n Day 3: Take a break.\n Day 4: Take a break.\n Day 5: Complete the 2nd task.\n Day 6: Complete the 3rd task.\n Day 7: Take a break.\n Day 8: Complete the 4th task.\n Day 9: Complete the 5th task.\n It can be shown that the tasks cannot be completed in less than 9 days.\n \n Example 2:\n \n >>> taskSchedulerII(tasks = [5,8,8,5], space = 2)\n >>> 6\n Explanation:\n One way to complete all tasks in 6 days is as follows:\n Day 1: Complete the 0th task.\n Day 2: Complete the 1st task.\n Day 3: Take a break.\n Day 4: Take a break.\n Day 5: Complete the 2nd task.\n Day 6: Complete the 3rd task.\n It can be shown that the tasks cannot be completed in less than 6 days.\n \"\"\"\n"}
{"task_id": "minimum-replacements-to-sort-the-array", "prompt": "def minimumReplacement(nums: List[int]) -> int:\n \"\"\"\n You are given a 0-indexed integer array nums. In one operation you can replace any element of the array with any two elements that sum to it.\n \n For example, consider nums = [5,6,7]. In one operation, we can replace nums[1] with 2 and 4 and convert nums to [5,2,4,7].\n \n Return the minimum number of operations to make an array that is sorted in non-decreasing order.\n \n Example 1:\n \n >>> minimumReplacement(nums = [3,9,3])\n >>> 2\n Explanation: Here are the steps to sort the array in non-decreasing order:\n - From [3,9,3], replace the 9 with 3 and 6 so the array becomes [3,3,6,3]\n - From [3,3,6,3], replace the 6 with 3 and 3 so the array becomes [3,3,3,3,3]\n There are 2 steps to sort the array in non-decreasing order. Therefore, we return 2.\n \n \n Example 2:\n \n >>> minimumReplacement(nums = [1,2,3,4,5])\n >>> 0\n Explanation: The array is already in non-decreasing order. Therefore, we return 0.\n \"\"\"\n"}
{"task_id": "number-of-arithmetic-triplets", "prompt": "def arithmeticTriplets(nums: List[int], diff: int) -> int:\n \"\"\"\n You are given a 0-indexed, strictly increasing integer array nums and a positive integer diff. A triplet (i, j, k) is an arithmetic triplet if the following conditions are met:\n \n i < j < k,\n nums[j] - nums[i] == diff, and\n nums[k] - nums[j] == diff.\n \n Return the number of unique arithmetic triplets.\n \n Example 1:\n \n >>> arithmeticTriplets(nums = [0,1,4,6,7,10], diff = 3)\n >>> 2\n Explanation:\n (1, 2, 4) is an arithmetic triplet because both 7 - 4 == 3 and 4 - 1 == 3.\n (2, 4, 5) is an arithmetic triplet because both 10 - 7 == 3 and 7 - 4 == 3.\n \n Example 2:\n \n >>> arithmeticTriplets(nums = [4,5,6,7,8,9], diff = 2)\n >>> 2\n Explanation:\n (0, 2, 4) is an arithmetic triplet because both 8 - 6 == 2 and 6 - 4 == 2.\n (1, 3, 5) is an arithmetic triplet because both 9 - 7 == 2 and 7 - 5 == 2.\n \"\"\"\n"}
{"task_id": "reachable-nodes-with-restrictions", "prompt": "def reachableNodes(n: int, edges: List[List[int]], restricted: List[int]) -> int:\n \"\"\"\n There is an undirected tree with n nodes labeled from 0 to n - 1 and n - 1 edges.\n You are given a 2D integer array edges of length n - 1 where edges[i] = [ai, bi] indicates that there is an edge between nodes ai and bi in the tree. You are also given an integer array restricted which represents restricted nodes.\n Return the maximum number of nodes you can reach from node 0 without visiting a restricted node.\n Note that node 0 will not be a restricted node.\n \n Example 1:\n \n \n >>> reachableNodes(n = 7, edges = [[0,1],[1,2],[3,1],[4,0],[0,5],[5,6]], restricted = [4,5])\n >>> 4\n Explanation: The diagram above shows the tree.\n We have that [0,1,2,3] are the only nodes that can be reached from node 0 without visiting a restricted node.\n \n Example 2:\n \n \n >>> reachableNodes(n = 7, edges = [[0,1],[0,2],[0,5],[0,4],[3,2],[6,5]], restricted = [4,2,1])\n >>> 3\n Explanation: The diagram above shows the tree.\n We have that [0,5,6] are the only nodes that can be reached from node 0 without visiting a restricted node.\n \"\"\"\n"}
{"task_id": "check-if-there-is-a-valid-partition-for-the-array", "prompt": "def validPartition(nums: List[int]) -> bool:\n \"\"\"\n You are given a 0-indexed integer array nums. You have to partition the array into one or more contiguous subarrays.\n We call a partition of the array valid if each of the obtained subarrays satisfies one of the following conditions:\n \n The subarray consists of exactly 2, equal elements. For example, the subarray [2,2] is good.\n The subarray consists of exactly 3, equal elements. For example, the subarray [4,4,4] is good.\n The subarray consists of exactly 3 consecutive increasing elements, that is, the difference between adjacent elements is 1. For example, the subarray [3,4,5] is good, but the subarray [1,3,5] is not.\n \n Return true if the array has at least one valid partition. Otherwise, return false.\n \n Example 1:\n \n >>> validPartition(nums = [4,4,4,5,6])\n >>> true\n Explanation: The array can be partitioned into the subarrays [4,4] and [4,5,6].\n This partition is valid, so we return true.\n \n Example 2:\n \n >>> validPartition(nums = [1,1,1,2])\n >>> false\n Explanation: There is no valid partition for this array.\n \"\"\"\n"}
{"task_id": "longest-ideal-subsequence", "prompt": "def longestIdealString(s: str, k: int) -> int:\n \"\"\"\n You are given a string s consisting of lowercase letters and an integer k. We call a string t ideal if the following conditions are satisfied:\n \n t is a subsequence of the string s.\n The absolute difference in the alphabet order of every two adjacent letters in t is less than or equal to k.\n \n Return the length of the longest ideal string.\n A subsequence is a string that can be derived from another string by deleting some or no characters without changing the order of the remaining characters.\n Note that the alphabet order is not cyclic. For example, the absolute difference in the alphabet order of 'a' and 'z' is 25, not 1.\n \n Example 1:\n \n >>> longestIdealString(s = \"acfgbd\", k = 2)\n >>> 4\n Explanation: The longest ideal string is \"acbd\". The length of this string is 4, so 4 is returned.\n Note that \"acfgbd\" is not ideal because 'c' and 'f' have a difference of 3 in alphabet order.\n Example 2:\n \n >>> longestIdealString(s = \"abcd\", k = 3)\n >>> 4\n Explanation: The longest ideal string is \"abcd\". The length of this string is 4, so 4 is returned.\n \"\"\"\n"}
{"task_id": "minimize-maximum-value-in-a-grid", "prompt": "def minScore(grid: List[List[int]]) -> List[List[int]]:\n \"\"\"\n You are given an m x n integer matrix grid containing distinct positive integers.\n You have to replace each integer in the matrix with a positive integer satisfying the following conditions:\n \n The relative order of every two elements that are in the same row or column should stay the same after the replacements.\n The maximum number in the matrix after the replacements should be as small as possible.\n \n The relative order stays the same if for all pairs of elements in the original matrix such that grid[r1][c1] > grid[r2][c2] where either r1 == r2 or c1 == c2, then it must be true that grid[r1][c1] > grid[r2][c2] after the replacements.\n For example, if grid = [[2, 4, 5], [7, 3, 9]] then a good replacement could be either grid = [[1, 2, 3], [2, 1, 4]] or grid = [[1, 2, 3], [3, 1, 4]].\n Return the resulting matrix. If there are multiple answers, return any of them.\n \n Example 1:\n \n \n >>> minScore(grid = [[3,1],[2,5]])\n >>> [[2,1],[1,2]]\n Explanation: The above diagram shows a valid replacement.\n The maximum number in the matrix is 2. It can be shown that no smaller value can be obtained.\n \n Example 2:\n \n >>> minScore(grid = [[10]])\n >>> [[1]]\n Explanation: We replace the only number in the matrix with 1.\n \"\"\"\n"}
{"task_id": "largest-local-values-in-a-matrix", "prompt": "def largestLocal(grid: List[List[int]]) -> List[List[int]]:\n \"\"\"\n You are given an n x n integer matrix grid.\n Generate an integer matrix maxLocal of size (n - 2) x (n - 2) such that:\n \n maxLocal[i][j] is equal to the largest value of the 3 x 3 matrix in grid centered around row i + 1 and column j + 1.\n \n In other words, we want to find the largest value in every contiguous 3 x 3 matrix in grid.\n Return the generated matrix.\n \n Example 1:\n \n \n >>> largestLocal(grid = [[9,9,8,1],[5,6,2,6],[8,2,6,4],[6,2,2,2]])\n >>> [[9,9],[8,6]]\n Explanation: The diagram above shows the original matrix and the generated matrix.\n Notice that each value in the generated matrix corresponds to the largest value of a contiguous 3 x 3 matrix in grid.\n Example 2:\n \n \n >>> largestLocal(grid = [[1,1,1,1,1],[1,1,1,1,1],[1,1,2,1,1],[1,1,1,1,1],[1,1,1,1,1]])\n >>> [[2,2,2],[2,2,2],[2,2,2]]\n Explanation: Notice that the 2 is contained within every contiguous 3 x 3 matrix in grid.\n \"\"\"\n"}
{"task_id": "node-with-highest-edge-score", "prompt": "def edgeScore(edges: List[int]) -> int:\n \"\"\"\n You are given a directed graph with n nodes labeled from 0 to n - 1, where each node has exactly one outgoing edge.\n The graph is represented by a given 0-indexed integer array edges of length n, where edges[i] indicates that there is a directed edge from node i to node edges[i].\n The edge score of a node i is defined as the sum of the labels of all the nodes that have an edge pointing to i.\n Return the node with the highest edge score. If multiple nodes have the same edge score, return the node with the smallest index.\n \n Example 1:\n \n \n >>> edgeScore(edges = [1,0,0,0,0,7,7,5])\n >>> 7\n Explanation:\n - The nodes 1, 2, 3 and 4 have an edge pointing to node 0. The edge score of node 0 is 1 + 2 + 3 + 4 = 10.\n - The node 0 has an edge pointing to node 1. The edge score of node 1 is 0.\n - The node 7 has an edge pointing to node 5. The edge score of node 5 is 7.\n - The nodes 5 and 6 have an edge pointing to node 7. The edge score of node 7 is 5 + 6 = 11.\n Node 7 has the highest edge score so return 7.\n \n Example 2:\n \n \n >>> edgeScore(edges = [2,0,0,2])\n >>> 0\n Explanation:\n - The nodes 1 and 2 have an edge pointing to node 0. The edge score of node 0 is 1 + 2 = 3.\n - The nodes 0 and 3 have an edge pointing to node 2. The edge score of node 2 is 0 + 3 = 3.\n Nodes 0 and 2 both have an edge score of 3. Since node 0 has a smaller index, we return 0.\n \"\"\"\n"}
{"task_id": "construct-smallest-number-from-di-string", "prompt": "def smallestNumber(pattern: str) -> str:\n \"\"\"\n You are given a 0-indexed string pattern of length n consisting of the characters 'I' meaning increasing and 'D' meaning decreasing.\n A 0-indexed string num of length n + 1 is created using the following conditions:\n \n num consists of the digits '1' to '9', where each digit is used at most once.\n If pattern[i] == 'I', then num[i] < num[i + 1].\n If pattern[i] == 'D', then num[i] > num[i + 1].\n \n Return the lexicographically smallest possible string num that meets the conditions.\n \n Example 1:\n \n >>> smallestNumber(pattern = \"IIIDIDDD\")\n >>> \"123549876\"\n Explanation:\n At indices 0, 1, 2, and 4 we must have that num[i] < num[i+1].\n At indices 3, 5, 6, and 7 we must have that num[i] > num[i+1].\n Some possible values of num are \"245639871\", \"135749862\", and \"123849765\".\n It can be proven that \"123549876\" is the smallest possible num that meets the conditions.\n Note that \"123414321\" is not possible because the digit '1' is used more than once.\n Example 2:\n \n >>> smallestNumber(pattern = \"DDD\")\n >>> \"4321\"\n Explanation:\n Some possible values of num are \"9876\", \"7321\", and \"8742\".\n It can be proven that \"4321\" is the smallest possible num that meets the conditions.\n \"\"\"\n"}
{"task_id": "count-special-integers", "prompt": "def countSpecialNumbers(n: int) -> int:\n \"\"\"\n We call a positive integer special if all of its digits are distinct.\n Given a positive integer n, return the number of special integers that belong to the interval [1, n].\n \n Example 1:\n \n >>> countSpecialNumbers(n = 20)\n >>> 19\n Explanation: All the integers from 1 to 20, except 11, are special. Thus, there are 19 special integers.\n \n Example 2:\n \n >>> countSpecialNumbers(n = 5)\n >>> 5\n Explanation: All the integers from 1 to 5 are special.\n \n Example 3:\n \n >>> countSpecialNumbers(n = 135)\n >>> 110\n Explanation: There are 110 integers from 1 to 135 that are special.\n Some of the integers that are not special are: 22, 114, and 131.\n \"\"\"\n"}
{"task_id": "choose-edges-to-maximize-score-in-a-tree", "prompt": "def maxScore(edges: List[List[int]]) -> int:\n \"\"\"\n You are given a weighted tree consisting of n nodes numbered from 0 to n - 1.\n The tree is rooted at node 0 and represented with a 2D array edges of size n where edges[i] = [pari, weighti] indicates that node pari is the parent of node i, and the edge between them has a weight equal to weighti. Since the root does not have a parent, you have edges[0] = [-1, -1].\n Choose some edges from the tree such that no two chosen edges are adjacent and the sum of the weights of the chosen edges is maximized.\n Return the maximum sum of the chosen edges.\n Note:\n \n You are allowed to not choose any edges in the tree, the sum of weights in this case will be 0.\n Two edges Edge1 and Edge2 in the tree are adjacent if they have a common node.\n \n In other words, they are adjacent if Edge1 connects nodes a and b and Edge2 connects nodes b and c.\n \n \n \n \n Example 1:\n \n \n >>> maxScore(edges = [[-1,-1],[0,5],[0,10],[2,6],[2,4]])\n >>> 11\n Explanation: The above diagram shows the edges that we have to choose colored in red.\n The total score is 5 + 6 = 11.\n It can be shown that no better score can be obtained.\n \n Example 2:\n \n \n >>> maxScore(edges = [[-1,-1],[0,5],[0,-6],[0,7]])\n >>> 7\n Explanation: We choose the edge with weight 7.\n Note that we cannot choose more than one edge because all edges are adjacent to each other.\n \"\"\"\n"}
{"task_id": "minimum-recolors-to-get-k-consecutive-black-blocks", "prompt": "def minimumRecolors(blocks: str, k: int) -> int:\n \"\"\"\n You are given a 0-indexed string blocks of length n, where blocks[i] is either 'W' or 'B', representing the color of the ith block. The characters 'W' and 'B' denote the colors white and black, respectively.\n You are also given an integer k, which is the desired number of consecutive black blocks.\n In one operation, you can recolor a white block such that it becomes a black block.\n Return the minimum number of operations needed such that there is at least one occurrence of k consecutive black blocks.\n \n Example 1:\n \n >>> minimumRecolors(blocks = \"WBBWWBBWBW\", k = 7)\n >>> 3\n Explanation:\n One way to achieve 7 consecutive black blocks is to recolor the 0th, 3rd, and 4th blocks\n so that blocks = \"BBBBBBBWBW\".\n It can be shown that there is no way to achieve 7 consecutive black blocks in less than 3 operations.\n Therefore, we return 3.\n \n Example 2:\n \n >>> minimumRecolors(blocks = \"WBWBBBW\", k = 2)\n >>> 0\n Explanation:\n No changes need to be made, since 2 consecutive black blocks already exist.\n Therefore, we return 0.\n \"\"\"\n"}
{"task_id": "time-needed-to-rearrange-a-binary-string", "prompt": "def secondsToRemoveOccurrences(s: str) -> int:\n \"\"\"\n You are given a binary string s. In one second, all occurrences of \"01\" are simultaneously replaced with \"10\". This process repeats until no occurrences of \"01\" exist.\n Return the number of seconds needed to complete this process.\n \n Example 1:\n \n >>> secondsToRemoveOccurrences(s = \"0110101\")\n >>> 4\n Explanation:\n After one second, s becomes \"1011010\".\n After another second, s becomes \"1101100\".\n After the third second, s becomes \"1110100\".\n After the fourth second, s becomes \"1111000\".\n No occurrence of \"01\" exists any longer, and the process needed 4 seconds to complete,\n so we return 4.\n \n Example 2:\n \n >>> secondsToRemoveOccurrences(s = \"11100\")\n >>> 0\n Explanation:\n No occurrence of \"01\" exists in s, and the processes needed 0 seconds to complete,\n so we return 0.\n \"\"\"\n"}
{"task_id": "shifting-letters-ii", "prompt": "def shiftingLetters(s: str, shifts: List[List[int]]) -> str:\n \"\"\"\n You are given a string s of lowercase English letters and a 2D integer array shifts where shifts[i] = [starti, endi, directioni]. For every i, shift the characters in s from the index starti to the index endi (inclusive) forward if directioni = 1, or shift the characters backward if directioni = 0.\n Shifting a character forward means replacing it with the next letter in the alphabet (wrapping around so that 'z' becomes 'a'). Similarly, shifting a character backward means replacing it with the previous letter in the alphabet (wrapping around so that 'a' becomes 'z').\n Return the final string after all such shifts to s are applied.\n \n Example 1:\n \n >>> shiftingLetters(s = \"abc\", shifts = [[0,1,0],[1,2,1],[0,2,1]])\n >>> \"ace\"\n Explanation: Firstly, shift the characters from index 0 to index 1 backward. Now s = \"zac\".\n Secondly, shift the characters from index 1 to index 2 forward. Now s = \"zbd\".\n Finally, shift the characters from index 0 to index 2 forward. Now s = \"ace\".\n Example 2:\n \n >>> shiftingLetters(s = \"dztz\", shifts = [[0,0,0],[1,1,1]])\n >>> \"catz\"\n Explanation: Firstly, shift the characters from index 0 to index 0 backward. Now s = \"cztz\".\n Finally, shift the characters from index 1 to index 1 forward. Now s = \"catz\".\n \"\"\"\n"}
{"task_id": "maximum-segment-sum-after-removals", "prompt": "def maximumSegmentSum(nums: List[int], removeQueries: List[int]) -> List[int]:\n \"\"\"\n You are given two 0-indexed integer arrays nums and removeQueries, both of length n. For the ith query, the element in nums at the index removeQueries[i] is removed, splitting nums into different segments.\n A segment is a contiguous sequence of positive integers in nums. A segment sum is the sum of every element in a segment.\n Return an integer array answer, of length n, where answer[i] is the maximum segment sum after applying the ith removal.\n Note: The same index will not be removed more than once.\n \n Example 1:\n \n >>> maximumSegmentSum(nums = [1,2,5,6,1], removeQueries = [0,3,2,4,1])\n >>> [14,7,2,2,0]\n Explanation: Using 0 to indicate a removed element, the answer is as follows:\n Query 1: Remove the 0th element, nums becomes [0,2,5,6,1] and the maximum segment sum is 14 for segment [2,5,6,1].\n Query 2: Remove the 3rd element, nums becomes [0,2,5,0,1] and the maximum segment sum is 7 for segment [2,5].\n Query 3: Remove the 2nd element, nums becomes [0,2,0,0,1] and the maximum segment sum is 2 for segment [2].\n Query 4: Remove the 4th element, nums becomes [0,2,0,0,0] and the maximum segment sum is 2 for segment [2].\n Query 5: Remove the 1st element, nums becomes [0,0,0,0,0] and the maximum segment sum is 0, since there are no segments.\n Finally, we return [14,7,2,2,0].\n Example 2:\n \n >>> maximumSegmentSum(nums = [3,2,11,1], removeQueries = [3,2,1,0])\n >>> [16,5,3,0]\n Explanation: Using 0 to indicate a removed element, the answer is as follows:\n Query 1: Remove the 3rd element, nums becomes [3,2,11,0] and the maximum segment sum is 16 for segment [3,2,11].\n Query 2: Remove the 2nd element, nums becomes [3,2,0,0] and the maximum segment sum is 5 for segment [3,2].\n Query 3: Remove the 1st element, nums becomes [3,0,0,0] and the maximum segment sum is 3 for segment [3].\n Query 4: Remove the 0th element, nums becomes [0,0,0,0] and the maximum segment sum is 0, since there are no segments.\n Finally, we return [16,5,3,0].\n \"\"\"\n"}
{"task_id": "minimum-hours-of-training-to-win-a-competition", "prompt": "def minNumberOfHours(initialEnergy: int, initialExperience: int, energy: List[int], experience: List[int]) -> int:\n \"\"\"\n You are entering a competition, and are given two positive integers initialEnergy and initialExperience denoting your initial energy and initial experience respectively.\n You are also given two 0-indexed integer arrays energy and experience, both of length n.\n You will face n opponents in order. The energy and experience of the ith opponent is denoted by energy[i] and experience[i] respectively. When you face an opponent, you need to have both strictly greater experience and energy to defeat them and move to the next opponent if available.\n Defeating the ith opponent increases your experience by experience[i], but decreases your energy by energy[i].\n Before starting the competition, you can train for some number of hours. After each hour of training, you can either choose to increase your initial experience by one, or increase your initial energy by one.\n Return the minimum number of training hours required to defeat all n opponents.\n \n Example 1:\n \n >>> minNumberOfHours(initialEnergy = 5, initialExperience = 3, energy = [1,4,3,2], experience = [2,6,3,1])\n >>> 8\n Explanation: You can increase your energy to 11 after 6 hours of training, and your experience to 5 after 2 hours of training.\n You face the opponents in the following order:\n - You have more energy and experience than the 0th opponent so you win.\n Your energy becomes 11 - 1 = 10, and your experience becomes 5 + 2 = 7.\n - You have more energy and experience than the 1st opponent so you win.\n Your energy becomes 10 - 4 = 6, and your experience becomes 7 + 6 = 13.\n - You have more energy and experience than the 2nd opponent so you win.\n Your energy becomes 6 - 3 = 3, and your experience becomes 13 + 3 = 16.\n - You have more energy and experience than the 3rd opponent so you win.\n Your energy becomes 3 - 2 = 1, and your experience becomes 16 + 1 = 17.\n You did a total of 6 + 2 = 8 hours of training before the competition, so we return 8.\n It can be proven that no smaller answer exists.\n \n Example 2:\n \n >>> minNumberOfHours(initialEnergy = 2, initialExperience = 4, energy = [1], experience = [3])\n >>> 0\n Explanation: You do not need any additional energy or experience to win the competition, so we return 0.\n \"\"\"\n"}
{"task_id": "largest-palindromic-number", "prompt": "def largestPalindromic(num: str) -> str:\n \"\"\"\n You are given a string num consisting of digits only.\n Return the largest palindromic integer (in the form of a string) that can be formed using digits taken from num. It should not contain leading zeroes.\n Notes:\n \n You do not need to use all the digits of num, but you must use at least one digit.\n The digits can be reordered.\n \n \n Example 1:\n \n >>> largestPalindromic(num = \"444947137\")\n >>> \"7449447\"\n Explanation:\n Use the digits \"4449477\" from \"444947137\" to form the palindromic integer \"7449447\".\n It can be shown that \"7449447\" is the largest palindromic integer that can be formed.\n \n Example 2:\n \n >>> largestPalindromic(num = \"00009\")\n >>> \"9\"\n Explanation:\n It can be shown that \"9\" is the largest palindromic integer that can be formed.\n Note that the integer returned should not contain leading zeroes.\n \"\"\"\n"}
{"task_id": "amount-of-time-for-binary-tree-to-be-infected", "prompt": "# class TreeNode:\n# def __init__(val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def amountOfTime(root: Optional[TreeNode], start: int) -> int:\n \"\"\"\n You are given the root of a binary tree with unique values, and an integer start. At minute 0, an infection starts from the node with value start.\n Each minute, a node becomes infected if:\n \n The node is currently uninfected.\n The node is adjacent to an infected node.\n \n Return the number of minutes needed for the entire tree to be infected.\n \n Example 1:\n \n \n >>> __init__(root = [1,5,3,null,4,10,6,9,2], start = 3)\n >>> 4\n Explanation: The following nodes are infected during:\n - Minute 0: Node 3\n - Minute 1: Nodes 1, 10 and 6\n - Minute 2: Node 5\n - Minute 3: Node 4\n - Minute 4: Nodes 9 and 2\n It takes 4 minutes for the whole tree to be infected so we return 4.\n \n Example 2:\n \n \n >>> __init__(root = [1], start = 1)\n >>> 0\n Explanation: At minute 0, the only node in the tree is infected so we return 0.\n \"\"\"\n"}
{"task_id": "find-the-k-sum-of-an-array", "prompt": "def kSum(nums: List[int], k: int) -> int:\n \"\"\"\n You are given an integer array nums and a positive integer k. You can choose any subsequence of the array and sum all of its elements together.\n We define the K-Sum of the array as the kth largest subsequence sum that can be obtained (not necessarily distinct).\n Return the K-Sum of the array.\n 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.\n Note that the empty subsequence is considered to have a sum of 0.\n \n Example 1:\n \n >>> kSum(nums = [2,4,-2], k = 5)\n >>> 2\n Explanation: All the possible subsequence sums that we can obtain are the following sorted in decreasing order:\n - 6, 4, 4, 2, 2, 0, 0, -2.\n The 5-Sum of the array is 2.\n \n Example 2:\n \n >>> kSum(nums = [1,-2,3,4,-10,12], k = 16)\n >>> 10\n Explanation: The 16-Sum of the array is 10.\n \"\"\"\n"}
{"task_id": "median-of-a-row-wise-sorted-matrix", "prompt": "def matrixMedian(grid: List[List[int]]) -> int:\n \"\"\"\n Given an m x n matrix grid containing an odd number of integers where each row is sorted in non-decreasing order, return the median of the matrix.\n You must solve the problem in less than O(m * n) time complexity.\n \n Example 1:\n \n >>> matrixMedian(grid = [[1,1,2],[2,3,3],[1,3,4]])\n >>> 2\n Explanation: The elements of the matrix in sorted order are 1,1,1,2,2,3,3,3,4. The median is 2.\n \n Example 2:\n \n >>> matrixMedian(grid = [[1,1,3,3,4]])\n >>> 3\n Explanation: The elements of the matrix in sorted order are 1,1,3,3,4. The median is 3.\n \"\"\"\n"}
{"task_id": "longest-subsequence-with-limited-sum", "prompt": "def answerQueries(nums: List[int], queries: List[int]) -> List[int]:\n \"\"\"\n You are given an integer array nums of length n, and an integer array queries of length m.\n Return an array answer of length m where answer[i] is the maximum size of a subsequence that you can take from nums such that the sum of its elements is less than or equal to queries[i].\n 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.\n \n Example 1:\n \n >>> answerQueries(nums = [4,5,2,1], queries = [3,10,21])\n >>> [2,3,4]\n Explanation: We answer the queries as follows:\n - The subsequence [2,1] has a sum less than or equal to 3. It can be proven that 2 is the maximum size of such a subsequence, so answer[0] = 2.\n - The subsequence [4,5,1] has a sum less than or equal to 10. It can be proven that 3 is the maximum size of such a subsequence, so answer[1] = 3.\n - The subsequence [4,5,2,1] has a sum less than or equal to 21. It can be proven that 4 is the maximum size of such a subsequence, so answer[2] = 4.\n \n Example 2:\n \n >>> answerQueries(nums = [2,3,4,5], queries = [1])\n >>> [0]\n Explanation: The empty subsequence is the only subsequence that has a sum less than or equal to 1, so answer[0] = 0.\n \"\"\"\n"}
{"task_id": "removing-stars-from-a-string", "prompt": "def removeStars(s: str) -> str:\n \"\"\"\n You are given a string s, which contains stars *.\n In one operation, you can:\n \n Choose a star in s.\n Remove the closest non-star character to its left, as well as remove the star itself.\n \n Return the string after all stars have been removed.\n Note:\n \n The input will be generated such that the operation is always possible.\n It can be shown that the resulting string will always be unique.\n \n \n Example 1:\n \n >>> removeStars(s = \"leet**cod*e\")\n >>> \"lecoe\"\n Explanation: Performing the removals from left to right:\n - The closest character to the 1st star is 't' in \"leet**cod*e\". s becomes \"lee*cod*e\".\n - The closest character to the 2nd star is 'e' in \"lee*cod*e\". s becomes \"lecod*e\".\n - The closest character to the 3rd star is 'd' in \"lecod*e\". s becomes \"lecoe\".\n There are no more stars, so we return \"lecoe\".\n Example 2:\n \n >>> removeStars(s = \"erase*****\")\n >>> \"\"\n Explanation: The entire string is removed, so we return an empty string.\n \"\"\"\n"}
{"task_id": "minimum-amount-of-time-to-collect-garbage", "prompt": "def garbageCollection(garbage: List[str], travel: List[int]) -> int:\n \"\"\"\n You are given a 0-indexed array of strings garbage where garbage[i] represents the assortment of garbage at the ith house. garbage[i] consists only of the characters 'M', 'P' and 'G' representing one unit of metal, paper and glass garbage respectively. Picking up one unit of any type of garbage takes 1 minute.\n You are also given a 0-indexed integer array travel where travel[i] is the number of minutes needed to go from house i to house i + 1.\n There are three garbage trucks in the city, each responsible for picking up one type of garbage. Each garbage truck starts at house 0 and must visit each house in order; however, they do not need to visit every house.\n Only one garbage truck may be used at any given moment. While one truck is driving or picking up garbage, the other two trucks cannot do anything.\n Return the minimum number of minutes needed to pick up all the garbage.\n \n Example 1:\n \n >>> garbageCollection(garbage = [\"G\",\"P\",\"GP\",\"GG\"], travel = [2,4,3])\n >>> 21\n Explanation:\n The paper garbage truck:\n 1. Travels from house 0 to house 1\n 2. Collects the paper garbage at house 1\n 3. Travels from house 1 to house 2\n 4. Collects the paper garbage at house 2\n Altogether, it takes 8 minutes to pick up all the paper garbage.\n The glass garbage truck:\n 1. Collects the glass garbage at house 0\n 2. Travels from house 0 to house 1\n 3. Travels from house 1 to house 2\n 4. Collects the glass garbage at house 2\n 5. Travels from house 2 to house 3\n 6. Collects the glass garbage at house 3\n Altogether, it takes 13 minutes to pick up all the glass garbage.\n Since there is no metal garbage, we do not need to consider the metal garbage truck.\n Therefore, it takes a total of 8 + 13 = 21 minutes to collect all the garbage.\n \n Example 2:\n \n >>> garbageCollection(garbage = [\"MMM\",\"PGM\",\"GP\"], travel = [3,10])\n >>> 37\n Explanation:\n The metal garbage truck takes 7 minutes to pick up all the metal garbage.\n The paper garbage truck takes 15 minutes to pick up all the paper garbage.\n The glass garbage truck takes 15 minutes to pick up all the glass garbage.\n It takes a total of 7 + 15 + 15 = 37 minutes to collect all the garbage.\n \"\"\"\n"}
{"task_id": "build-a-matrix-with-conditions", "prompt": "def buildMatrix(k: int, rowConditions: List[List[int]], colConditions: List[List[int]]) -> List[List[int]]:\n \"\"\"\n You are given a positive integer k. You are also given:\n \n a 2D integer array rowConditions of size n where rowConditions[i] = [abovei, belowi], and\n a 2D integer array colConditions of size m where colConditions[i] = [lefti, righti].\n \n The two arrays contain integers from 1 to k.\n You have to build a k x k matrix that contains each of the numbers from 1 to k exactly once. The remaining cells should have the value 0.\n The matrix should also satisfy the following conditions:\n \n The number abovei should appear in a row that is strictly above the row at which the number belowi appears for all i from 0 to n - 1.\n The number lefti should appear in a column that is strictly left of the column at which the number righti appears for all i from 0 to m - 1.\n \n Return any matrix that satisfies the conditions. If no answer exists, return an empty matrix.\n \n Example 1:\n \n \n >>> buildMatrix(k = 3, rowConditions = [[1,2],[3,2]], colConditions = [[2,1],[3,2]])\n >>> [[3,0,0],[0,0,1],[0,2,0]]\n Explanation: The diagram above shows a valid example of a matrix that satisfies all the conditions.\n The row conditions are the following:\n - Number 1 is in row 1, and number 2 is in row 2, so 1 is above 2 in the matrix.\n - Number 3 is in row 0, and number 2 is in row 2, so 3 is above 2 in the matrix.\n The column conditions are the following:\n - Number 2 is in column 1, and number 1 is in column 2, so 2 is left of 1 in the matrix.\n - Number 3 is in column 0, and number 2 is in column 1, so 3 is left of 2 in the matrix.\n Note that there may be multiple correct answers.\n \n Example 2:\n \n >>> buildMatrix(k = 3, rowConditions = [[1,2],[2,3],[3,1],[2,3]], colConditions = [[2,1]])\n >>> []\n Explanation: From the first two conditions, 3 has to be below 1 but the third conditions needs 3 to be above 1 to be satisfied.\n No matrix can satisfy all the conditions, so we return the empty matrix.\n \"\"\"\n"}
{"task_id": "count-strictly-increasing-subarrays", "prompt": "def countSubarrays(nums: List[int]) -> int:\n \"\"\"\n You are given an array nums consisting of positive integers.\n Return the number of subarrays of nums that are in strictly increasing order.\n A subarray is a contiguous part of an array.\n \n Example 1:\n \n >>> countSubarrays(nums = [1,3,5,4,4,6])\n >>> 10\n Explanation: The strictly increasing subarrays are the following:\n - Subarrays of length 1: [1], [3], [5], [4], [4], [6].\n - Subarrays of length 2: [1,3], [3,5], [4,6].\n - Subarrays of length 3: [1,3,5].\n The total number of subarrays is 6 + 3 + 1 = 10.\n \n Example 2:\n \n >>> countSubarrays(nums = [1,2,3,4,5])\n >>> 15\n Explanation: Every subarray is strictly increasing. There are 15 possible subarrays that we can take.\n \"\"\"\n"}
{"task_id": "find-subarrays-with-equal-sum", "prompt": "def findSubarrays(nums: List[int]) -> bool:\n \"\"\"\n Given a 0-indexed integer array nums, determine whether there exist two subarrays of length 2 with equal sum. Note that the two subarrays must begin at different indices.\n Return true if these subarrays exist, and false otherwise.\n A subarray is a contiguous non-empty sequence of elements within an array.\n \n Example 1:\n \n >>> findSubarrays(nums = [4,2,4])\n >>> true\n Explanation: The subarrays with elements [4,2] and [2,4] have the same sum of 6.\n \n Example 2:\n \n >>> findSubarrays(nums = [1,2,3,4,5])\n >>> false\n Explanation: No two subarrays of size 2 have the same sum.\n \n Example 3:\n \n >>> findSubarrays(nums = [0,0,0])\n >>> true\n Explanation: The subarrays [nums[0],nums[1]] and [nums[1],nums[2]] have the same sum of 0.\n Note that even though the subarrays have the same content, the two subarrays are considered different because they are in different positions in the original array.\n \"\"\"\n"}
{"task_id": "strictly-palindromic-number", "prompt": "def isStrictlyPalindromic(n: int) -> bool:\n \"\"\"\n An integer n is strictly palindromic if, for every base b between 2 and n - 2 (inclusive), the string representation of the integer n in base b is palindromic.\n Given an integer n, return true if n is strictly palindromic and false otherwise.\n A string is palindromic if it reads the same forward and backward.\n \n Example 1:\n \n >>> isStrictlyPalindromic(n = 9)\n >>> false\n Explanation: In base 2: 9 = 1001 (base 2), which is palindromic.\n In base 3: 9 = 100 (base 3), which is not palindromic.\n Therefore, 9 is not strictly palindromic so we return false.\n Note that in bases 4, 5, 6, and 7, n = 9 is also not palindromic.\n \n Example 2:\n \n >>> isStrictlyPalindromic(n = 4)\n >>> false\n Explanation: We only consider base 2: 4 = 100 (base 2), which is not palindromic.\n Therefore, we return false.\n \"\"\"\n"}
{"task_id": "maximum-rows-covered-by-columns", "prompt": "def maximumRows(matrix: List[List[int]], numSelect: int) -> int:\n \"\"\"\n You are given an m x n binary matrix matrix and an integer numSelect.\n Your goal is to select exactly numSelect distinct columns from matrix such that you cover as many rows as possible.\n A row is considered covered if all the 1's in that row are also part of a column that you have selected. If a row does not have any 1s, it is also considered covered.\n More formally, let us consider selected = {c1, c2, ...., cnumSelect} as the set of columns selected by you. A row i is covered by selected if:\n \n For each cell where matrix[i][j] == 1, the column j is in selected.\n Or, no cell in row i has a value of 1.\n \n Return the maximum number of rows that can be covered by a set of numSelect columns.\n \n Example 1:\n \n \n >>> maximumRows(matrix = [[0,0,0],[1,0,1],[0,1,1],[0,0,1]], numSelect = 2)\n >>> 3\n Explanation:\n One possible way to cover 3 rows is shown in the diagram above.\n We choose s = {0, 2}.\n - Row 0 is covered because it has no occurrences of 1.\n - Row 1 is covered because the columns with value 1, i.e. 0 and 2 are present in s.\n - Row 2 is not covered because matrix[2][1] == 1 but 1 is not present in s.\n - Row 3 is covered because matrix[2][2] == 1 and 2 is present in s.\n Thus, we can cover three rows.\n Note that s = {1, 2} will also cover 3 rows, but it can be shown that no more than three rows can be covered.\n \n Example 2:\n \n \n >>> maximumRows(matrix = [[1],[0]], numSelect = 1)\n >>> 2\n Explanation:\n Selecting the only column will result in both rows being covered since the entire matrix is selected.\n \"\"\"\n"}
{"task_id": "maximum-number-of-robots-within-budget", "prompt": "def maximumRobots(chargeTimes: List[int], runningCosts: List[int], budget: int) -> int:\n \"\"\"\n You have n robots. You are given two 0-indexed integer arrays, chargeTimes and runningCosts, both of length n. The ith robot costs chargeTimes[i] units to charge and costs runningCosts[i] units to run. You are also given an integer budget.\n The total cost of running k chosen robots is equal to max(chargeTimes) + k * sum(runningCosts), where max(chargeTimes) is the largest charge cost among the k robots and sum(runningCosts) is the sum of running costs among the k robots.\n Return the maximum number of consecutive robots you can run such that the total cost does not exceed budget.\n \n Example 1:\n \n >>> maximumRobots(chargeTimes = [3,6,1,3,4], runningCosts = [2,1,3,4,5], budget = 25)\n >>> 3\n Explanation:\n It is possible to run all individual and consecutive pairs of robots within budget.\n To obtain answer 3, consider the first 3 robots. The total cost will be max(3,6,1) + 3 * sum(2,1,3) = 6 + 3 * 6 = 24 which is less than 25.\n It can be shown that it is not possible to run more than 3 consecutive robots within budget, so we return 3.\n \n Example 2:\n \n >>> maximumRobots(chargeTimes = [11,12,19], runningCosts = [10,8,7], budget = 19)\n >>> 0\n Explanation: No robot can be run that does not exceed the budget, so we return 0.\n \"\"\"\n"}
{"task_id": "check-distances-between-same-letters", "prompt": "def checkDistances(s: str, distance: List[int]) -> bool:\n \"\"\"\n You are given a 0-indexed string s consisting of only lowercase English letters, where each letter in s appears exactly twice. You are also given a 0-indexed integer array distance of length 26.\n Each letter in the alphabet is numbered from 0 to 25 (i.e. 'a' -> 0, 'b' -> 1, 'c' -> 2, ... , 'z' -> 25).\n In a well-spaced string, the number of letters between the two occurrences of the ith letter is distance[i]. If the ith letter does not appear in s, then distance[i] can be ignored.\n Return true if s is a well-spaced string, otherwise return false.\n \n Example 1:\n \n >>> checkDistances(s = \"abaccb\", distance = [1,3,0,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0])\n >>> true\n Explanation:\n - 'a' appears at indices 0 and 2 so it satisfies distance[0] = 1.\n - 'b' appears at indices 1 and 5 so it satisfies distance[1] = 3.\n - 'c' appears at indices 3 and 4 so it satisfies distance[2] = 0.\n Note that distance[3] = 5, but since 'd' does not appear in s, it can be ignored.\n Return true because s is a well-spaced string.\n \n Example 2:\n \n >>> checkDistances(s = \"aa\", distance = [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0])\n >>> false\n Explanation:\n - 'a' appears at indices 0 and 1 so there are zero letters between them.\n Because distance[0] = 1, s is not a well-spaced string.\n \"\"\"\n"}
{"task_id": "number-of-ways-to-reach-a-position-after-exactly-k-steps", "prompt": "def numberOfWays(startPos: int, endPos: int, k: int) -> int:\n \"\"\"\n You are given two positive integers startPos and endPos. Initially, you are standing at position startPos on an infinite number line. With one step, you can move either one position to the left, or one position to the right.\n Given a positive integer k, return the number of different ways to reach the position endPos starting from startPos, such that you perform exactly k steps. Since the answer may be very large, return it modulo 109 + 7.\n Two ways are considered different if the order of the steps made is not exactly the same.\n Note that the number line includes negative integers.\n \n Example 1:\n \n >>> numberOfWays(startPos = 1, endPos = 2, k = 3)\n >>> 3\n Explanation: We can reach position 2 from 1 in exactly 3 steps in three ways:\n - 1 -> 2 -> 3 -> 2.\n - 1 -> 2 -> 1 -> 2.\n - 1 -> 0 -> 1 -> 2.\n It can be proven that no other way is possible, so we return 3.\n Example 2:\n \n >>> numberOfWays(startPos = 2, endPos = 5, k = 10)\n >>> 0\n Explanation: It is impossible to reach position 5 from position 2 in exactly 10 steps.\n \"\"\"\n"}
{"task_id": "longest-nice-subarray", "prompt": "def longestNiceSubarray(nums: List[int]) -> int:\n \"\"\"\n You are given an array nums consisting of positive integers.\n We call a subarray of nums nice if the bitwise AND of every pair of elements that are in different positions in the subarray is equal to 0.\n Return the length of the longest nice subarray.\n A subarray is a contiguous part of an array.\n Note that subarrays of length 1 are always considered nice.\n \n Example 1:\n \n >>> longestNiceSubarray(nums = [1,3,8,48,10])\n >>> 3\n Explanation: The longest nice subarray is [3,8,48]. This subarray satisfies the conditions:\n - 3 AND 8 = 0.\n - 3 AND 48 = 0.\n - 8 AND 48 = 0.\n It can be proven that no longer nice subarray can be obtained, so we return 3.\n Example 2:\n \n >>> longestNiceSubarray(nums = [3,1,5,11,13])\n >>> 1\n Explanation: The length of the longest nice subarray is 1. Any subarray of length 1 can be chosen.\n \"\"\"\n"}
{"task_id": "meeting-rooms-iii", "prompt": "def mostBooked(n: int, meetings: List[List[int]]) -> int:\n \"\"\"\n You are given an integer n. There are n rooms numbered from 0 to n - 1.\n You are given a 2D integer array meetings where meetings[i] = [starti, endi] means that a meeting will be held during the half-closed time interval [starti, endi). All the values of starti are unique.\n Meetings are allocated to rooms in the following manner:\n \n Each meeting will take place in the unused room with the lowest number.\n If there are no available rooms, the meeting will be delayed until a room becomes free. The delayed meeting should have the same duration as the original meeting.\n When a room becomes unused, meetings that have an earlier original start time should be given the room.\n \n Return the number of the room that held the most meetings. If there are multiple rooms, return the room with the lowest number.\n A half-closed interval [a, b) is the interval between a and b including a and not including b.\n \n Example 1:\n \n >>> mostBooked(n = 2, meetings = [[0,10],[1,5],[2,7],[3,4]])\n >>> 0\n Explanation:\n - At time 0, both rooms are not being used. The first meeting starts in room 0.\n - At time 1, only room 1 is not being used. The second meeting starts in room 1.\n - At time 2, both rooms are being used. The third meeting is delayed.\n - At time 3, both rooms are being used. The fourth meeting is delayed.\n - At time 5, the meeting in room 1 finishes. The third meeting starts in room 1 for the time period [5,10).\n - At time 10, the meetings in both rooms finish. The fourth meeting starts in room 0 for the time period [10,11).\n Both rooms 0 and 1 held 2 meetings, so we return 0.\n \n Example 2:\n \n >>> mostBooked(n = 3, meetings = [[1,20],[2,10],[3,5],[4,9],[6,8]])\n >>> 1\n Explanation:\n - At time 1, all three rooms are not being used. The first meeting starts in room 0.\n - At time 2, rooms 1 and 2 are not being used. The second meeting starts in room 1.\n - At time 3, only room 2 is not being used. The third meeting starts in room 2.\n - At time 4, all three rooms are being used. The fourth meeting is delayed.\n - At time 5, the meeting in room 2 finishes. The fourth meeting starts in room 2 for the time period [5,10).\n - At time 6, all three rooms are being used. The fifth meeting is delayed.\n - At time 10, the meetings in rooms 1 and 2 finish. The fifth meeting starts in room 1 for the time period [10,12).\n Room 0 held 1 meeting while rooms 1 and 2 each held 2 meetings, so we return 1.\n \"\"\"\n"}
{"task_id": "minimum-time-to-kill-all-monsters", "prompt": "def minimumTime(power: List[int]) -> int:\n \"\"\"\n You are given an integer array power where power[i] is the power of the ith monster.\n You start with 0 mana points, and each day you increase your mana points by gain where gain initially is equal to 1.\n Each day, after gaining gain mana, you can defeat a monster if your mana points are greater than or equal to the power of that monster. When you defeat a monster:\n \n your mana points will be reset to 0, and\n the value of gain increases by 1.\n \n Return the minimum number of days needed to defeat all the monsters.\n \n Example 1:\n \n >>> minimumTime(power = [3,1,4])\n >>> 4\n Explanation: The optimal way to beat all the monsters is to:\n - Day 1: Gain 1 mana point to get a total of 1 mana point. Spend all mana points to kill the 2nd monster.\n - Day 2: Gain 2 mana points to get a total of 2 mana points.\n - Day 3: Gain 2 mana points to get a total of 4 mana points. Spend all mana points to kill the 3rd monster.\n - Day 4: Gain 3 mana points to get a total of 3 mana points. Spend all mana points to kill the 1st monster.\n It can be proven that 4 is the minimum number of days needed.\n \n Example 2:\n \n >>> minimumTime(power = [1,1,4])\n >>> 4\n Explanation: The optimal way to beat all the monsters is to:\n - Day 1: Gain 1 mana point to get a total of 1 mana point. Spend all mana points to kill the 1st monster.\n - Day 2: Gain 2 mana points to get a total of 2 mana points. Spend all mana points to kill the 2nd monster.\n - Day 3: Gain 3 mana points to get a total of 3 mana points.\n - Day 4: Gain 3 mana points to get a total of 6 mana points. Spend all mana points to kill the 3rd monster.\n It can be proven that 4 is the minimum number of days needed.\n \n Example 3:\n \n >>> minimumTime(power = [1,2,4,9])\n >>> 6\n Explanation: The optimal way to beat all the monsters is to:\n - Day 1: Gain 1 mana point to get a total of 1 mana point. Spend all mana points to kill the 1st monster.\n - Day 2: Gain 2 mana points to get a total of 2 mana points. Spend all mana points to kill the 2nd monster.\n - Day 3: Gain 3 mana points to get a total of 3 mana points.\n - Day 4: Gain 3 mana points to get a total of 6 mana points.\n - Day 5: Gain 3 mana points to get a total of 9 mana points. Spend all mana points to kill the 4th monster.\n - Day 6: Gain 4 mana points to get a total of 4 mana points. Spend all mana points to kill the 3rd monster.\n It can be proven that 6 is the minimum number of days needed.\n \"\"\"\n"}
{"task_id": "most-frequent-even-element", "prompt": "def mostFrequentEven(nums: List[int]) -> int:\n \"\"\"\n Given an integer array nums, return the most frequent even element.\n If there is a tie, return the smallest one. If there is no such element, return -1.\n \n Example 1:\n \n >>> mostFrequentEven(nums = [0,1,2,2,4,4,1])\n >>> 2\n Explanation:\n The even elements are 0, 2, and 4. Of these, 2 and 4 appear the most.\n We return the smallest one, which is 2.\n Example 2:\n \n >>> mostFrequentEven(nums = [4,4,4,9,2,4])\n >>> 4\n Explanation: 4 is the even element appears the most.\n \n Example 3:\n \n >>> mostFrequentEven(nums = [29,47,21,41,13,37,25,7])\n >>> -1\n Explanation: There is no even element.\n \"\"\"\n"}
{"task_id": "optimal-partition-of-string", "prompt": "def partitionString(s: str) -> int:\n \"\"\"\n Given a string s, partition the string into one or more substrings such that the characters in each substring are unique. That is, no letter appears in a single substring more than once.\n Return the minimum number of substrings in such a partition.\n Note that each character should belong to exactly one substring in a partition.\n \n Example 1:\n \n >>> partitionString(s = \"abacaba\")\n >>> 4\n Explanation:\n Two possible partitions are (\"a\",\"ba\",\"cab\",\"a\") and (\"ab\",\"a\",\"ca\",\"ba\").\n It can be shown that 4 is the minimum number of substrings needed.\n \n Example 2:\n \n >>> partitionString(s = \"ssssss\")\n >>> 6\n Explanation:\n The only valid partition is (\"s\",\"s\",\"s\",\"s\",\"s\",\"s\").\n \"\"\"\n"}
{"task_id": "divide-intervals-into-minimum-number-of-groups", "prompt": "def minGroups(intervals: List[List[int]]) -> int:\n \"\"\"\n You are given a 2D integer array intervals where intervals[i] = [lefti, righti] represents the inclusive interval [lefti, righti].\n You have to divide the intervals into one or more groups such that each interval is in exactly one group, and no two intervals that are in the same group intersect each other.\n Return the minimum number of groups you need to make.\n Two intervals intersect if there is at least one common number between them. For example, the intervals [1, 5] and [5, 8] intersect.\n \n Example 1:\n \n >>> minGroups(intervals = [[5,10],[6,8],[1,5],[2,3],[1,10]])\n >>> 3\n Explanation: We can divide the intervals into the following groups:\n - Group 1: [1, 5], [6, 8].\n - Group 2: [2, 3], [5, 10].\n - Group 3: [1, 10].\n It can be proven that it is not possible to divide the intervals into fewer than 3 groups.\n \n Example 2:\n \n >>> minGroups(intervals = [[1,3],[5,6],[8,10],[11,13]])\n >>> 1\n Explanation: None of the intervals overlap, so we can put all of them in one group.\n \"\"\"\n"}
{"task_id": "longest-increasing-subsequence-ii", "prompt": "def lengthOfLIS(nums: List[int], k: int) -> int:\n \"\"\"\n You are given an integer array nums and an integer k.\n Find the longest subsequence of nums that meets the following requirements:\n \n The subsequence is strictly increasing and\n The difference between adjacent elements in the subsequence is at most k.\n \n Return the length of the longest subsequence that meets the requirements.\n 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.\n \n Example 1:\n \n >>> lengthOfLIS(nums = [4,2,1,4,3,4,5,8,15], k = 3)\n >>> 5\n Explanation:\n The longest subsequence that meets the requirements is [1,3,4,5,8].\n The subsequence has a length of 5, so we return 5.\n Note that the subsequence [1,3,4,5,8,15] does not meet the requirements because 15 - 8 = 7 is larger than 3.\n \n Example 2:\n \n >>> lengthOfLIS(nums = [7,4,5,1,8,12,4,7], k = 5)\n >>> 4\n Explanation:\n The longest subsequence that meets the requirements is [4,5,8,12].\n The subsequence has a length of 4, so we return 4.\n \n Example 3:\n \n >>> lengthOfLIS(nums = [1,5], k = 1)\n >>> 1\n Explanation:\n The longest subsequence that meets the requirements is [1].\n The subsequence has a length of 1, so we return 1.\n \"\"\"\n"}
{"task_id": "count-days-spent-together", "prompt": "def countDaysTogether(arriveAlice: str, leaveAlice: str, arriveBob: str, leaveBob: str) -> int:\n \"\"\"\n Alice and Bob are traveling to Rome for separate business meetings.\n You are given 4 strings arriveAlice, leaveAlice, arriveBob, and leaveBob. Alice will be in the city from the dates arriveAlice to leaveAlice (inclusive), while Bob will be in the city from the dates arriveBob to leaveBob (inclusive). Each will be a 5-character string in the format \"MM-DD\", corresponding to the month and day of the date.\n Return the total number of days that Alice and Bob are in Rome together.\n You can assume that all dates occur in the same calendar year, which is not a leap year. Note that the number of days per month can be represented as: [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31].\n \n Example 1:\n \n >>> countDaysTogether(arriveAlice = \"08-15\", leaveAlice = \"08-18\", arriveBob = \"08-16\", leaveBob = \"08-19\")\n >>> 3\n Explanation: Alice will be in Rome from August 15 to August 18. Bob will be in Rome from August 16 to August 19. They are both in Rome together on August 16th, 17th, and 18th, so the answer is 3.\n \n Example 2:\n \n >>> countDaysTogether(arriveAlice = \"10-01\", leaveAlice = \"10-31\", arriveBob = \"11-01\", leaveBob = \"12-31\")\n >>> 0\n Explanation: There is no day when Alice and Bob are in Rome together, so we return 0.\n \"\"\"\n"}
{"task_id": "maximum-matching-of-players-with-trainers", "prompt": "def matchPlayersAndTrainers(players: List[int], trainers: List[int]) -> int:\n \"\"\"\n You are given a 0-indexed integer array players, where players[i] represents the ability of the ith player. You are also given a 0-indexed integer array trainers, where trainers[j] represents the training capacity of the jth trainer.\n The ith player can match with the jth trainer if the player's ability is less than or equal to the trainer's training capacity. Additionally, the ith player can be matched with at most one trainer, and the jth trainer can be matched with at most one player.\n Return the maximum number of matchings between players and trainers that satisfy these conditions.\n \n Example 1:\n \n >>> matchPlayersAndTrainers(players = [4,7,9], trainers = [8,2,5,8])\n >>> 2\n Explanation:\n One of the ways we can form two matchings is as follows:\n - players[0] can be matched with trainers[0] since 4 <= 8.\n - players[1] can be matched with trainers[3] since 7 <= 8.\n It can be proven that 2 is the maximum number of matchings that can be formed.\n \n Example 2:\n \n >>> matchPlayersAndTrainers(players = [1,1,1], trainers = [10])\n >>> 1\n Explanation:\n The trainer can be matched with any of the 3 players.\n Each player can only be matched with one trainer, so the maximum answer is 1.\n \"\"\"\n"}
{"task_id": "smallest-subarrays-with-maximum-bitwise-or", "prompt": "def smallestSubarrays(nums: List[int]) -> List[int]:\n \"\"\"\n You are given a 0-indexed array nums of length n, consisting of non-negative integers. For each index i from 0 to n - 1, you must determine the size of the minimum sized non-empty subarray of nums starting at i (inclusive) that has the maximum possible bitwise OR.\n \n In other words, let Bij be the bitwise OR of the subarray nums[i...j]. You need to find the smallest subarray starting at i, such that bitwise OR of this subarray is equal to max(Bik) where i <= k <= n - 1.\n \n The bitwise OR of an array is the bitwise OR of all the numbers in it.\n Return an integer array answer of size n where answer[i] is the length of the minimum sized subarray starting at i with maximum bitwise OR.\n A subarray is a contiguous non-empty sequence of elements within an array.\n \n Example 1:\n \n >>> smallestSubarrays(nums = [1,0,2,1,3])\n >>> [3,3,2,2,1]\n Explanation:\n The maximum possible bitwise OR starting at any index is 3.\n - Starting at index 0, the shortest subarray that yields it is [1,0,2].\n - Starting at index 1, the shortest subarray that yields the maximum bitwise OR is [0,2,1].\n - Starting at index 2, the shortest subarray that yields the maximum bitwise OR is [2,1].\n - Starting at index 3, the shortest subarray that yields the maximum bitwise OR is [1,3].\n - Starting at index 4, the shortest subarray that yields the maximum bitwise OR is [3].\n Therefore, we return [3,3,2,2,1].\n \n Example 2:\n \n >>> smallestSubarrays(nums = [1,2])\n >>> [2,1]\n Explanation:\n Starting at index 0, the shortest subarray that yields the maximum bitwise OR is of length 2.\n Starting at index 1, the shortest subarray that yields the maximum bitwise OR is of length 1.\n Therefore, we return [2,1].\n \"\"\"\n"}
{"task_id": "minimum-money-required-before-transactions", "prompt": "def minimumMoney(transactions: List[List[int]]) -> int:\n \"\"\"\n You are given a 0-indexed 2D integer array transactions, where transactions[i] = [costi, cashbacki].\n The array describes transactions, where each transaction must be completed exactly once in some order. At any given moment, you have a certain amount of money. In order to complete transaction i, money >= costi must hold true. After performing a transaction, money becomes money - costi + cashbacki.\n Return the minimum amount of money required before any transaction so that all of the transactions can be completed regardless of the order of the transactions.\n \n Example 1:\n \n >>> minimumMoney(transactions = [[2,1],[5,0],[4,2]])\n >>> 10\n Explanation:\n Starting with money = 10, the transactions can be performed in any order.\n It can be shown that starting with money < 10 will fail to complete all transactions in some order.\n \n Example 2:\n \n >>> minimumMoney(transactions = [[3,0],[0,3]])\n >>> 3\n Explanation:\n - If transactions are in the order [[3,0],[0,3]], the minimum money required to complete the transactions is 3.\n - If transactions are in the order [[0,3],[3,0]], the minimum money required to complete the transactions is 0.\n Thus, starting with money = 3, the transactions can be performed in any order.\n \"\"\"\n"}
{"task_id": "smallest-even-multiple", "prompt": "def smallestEvenMultiple(n: int) -> int:\n \"\"\"\n Given a positive integer n, return the smallest positive integer that is a multiple of both 2 and n.\n \n Example 1:\n \n >>> smallestEvenMultiple(n = 5)\n >>> 10\n Explanation: The smallest multiple of both 5 and 2 is 10.\n \n Example 2:\n \n >>> smallestEvenMultiple(n = 6)\n >>> 6\n Explanation: The smallest multiple of both 6 and 2 is 6. Note that a number is a multiple of itself.\n \"\"\"\n"}
{"task_id": "length-of-the-longest-alphabetical-continuous-substring", "prompt": "def longestContinuousSubstring(s: str) -> int:\n \"\"\"\n An alphabetical continuous string is a string consisting of consecutive letters in the alphabet. In other words, it is any substring of the string \"abcdefghijklmnopqrstuvwxyz\".\n \n For example, \"abc\" is an alphabetical continuous string, while \"acb\" and \"za\" are not.\n \n Given a string s consisting of lowercase letters only, return the length of the longest alphabetical continuous substring.\n \n Example 1:\n \n >>> longestContinuousSubstring(s = \"abacaba\")\n >>> 2\n Explanation: There are 4 distinct continuous substrings: \"a\", \"b\", \"c\" and \"ab\".\n \"ab\" is the longest continuous substring.\n \n Example 2:\n \n >>> longestContinuousSubstring(s = \"abcde\")\n >>> 5\n Explanation: \"abcde\" is the longest continuous substring.\n \"\"\"\n"}
{"task_id": "reverse-odd-levels-of-binary-tree", "prompt": "# class TreeNode:\n# def __init__(val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def reverseOddLevels(root: Optional[TreeNode]) -> Optional[TreeNode]:\n \"\"\"\n Given the root of a perfect binary tree, reverse the node values at each odd level of the tree.\n \n For example, suppose the node values at level 3 are [2,1,3,4,7,11,29,18], then it should become [18,29,11,7,4,3,1,2].\n \n Return the root of the reversed tree.\n A binary tree is perfect if all parent nodes have two children and all leaves are on the same level.\n The level of a node is the number of edges along the path between it and the root node.\n \n Example 1:\n \n \n >>> __init__(root = [2,3,5,8,13,21,34])\n >>> [2,5,3,8,13,21,34]\n Explanation:\n The tree has only one odd level.\n The nodes at level 1 are 3, 5 respectively, which are reversed and become 5, 3.\n \n Example 2:\n \n \n >>> __init__(root = [7,13,11])\n >>> [7,11,13]\n Explanation:\n The nodes at level 1 are 13, 11, which are reversed and become 11, 13.\n \n Example 3:\n \n >>> __init__(root = [0,1,2,0,0,0,0,1,1,1,1,2,2,2,2])\n >>> [0,2,1,0,0,0,0,2,2,2,2,1,1,1,1]\n Explanation:\n The odd levels have non-zero values.\n The nodes at level 1 were 1, 2, and are 2, 1 after the reversal.\n The nodes at level 3 were 1, 1, 1, 1, 2, 2, 2, 2, and are 2, 2, 2, 2, 1, 1, 1, 1 after the reversal.\n \"\"\"\n"}
{"task_id": "sum-of-prefix-scores-of-strings", "prompt": "def sumPrefixScores(words: List[str]) -> List[int]:\n \"\"\"\n You are given an array words of size n consisting of non-empty strings.\n We define the score of a string term as the number of strings words[i] such that term is a prefix of words[i].\n \n For example, if words = [\"a\", \"ab\", \"abc\", \"cab\"], then the score of \"ab\" is 2, since \"ab\" is a prefix of both \"ab\" and \"abc\".\n \n Return an array answer of size n where answer[i] is the sum of scores of every non-empty prefix of words[i].\n Note that a string is considered as a prefix of itself.\n \n Example 1:\n \n >>> sumPrefixScores(words = [\"abc\",\"ab\",\"bc\",\"b\"])\n >>> [5,4,3,2]\n Explanation: The answer for each string is the following:\n - \"abc\" has 3 prefixes: \"a\", \"ab\", and \"abc\".\n - There are 2 strings with the prefix \"a\", 2 strings with the prefix \"ab\", and 1 string with the prefix \"abc\".\n The total is answer[0] = 2 + 2 + 1 = 5.\n - \"ab\" has 2 prefixes: \"a\" and \"ab\".\n - There are 2 strings with the prefix \"a\", and 2 strings with the prefix \"ab\".\n The total is answer[1] = 2 + 2 = 4.\n - \"bc\" has 2 prefixes: \"b\" and \"bc\".\n - There are 2 strings with the prefix \"b\", and 1 string with the prefix \"bc\".\n The total is answer[2] = 2 + 1 = 3.\n - \"b\" has 1 prefix: \"b\".\n - There are 2 strings with the prefix \"b\".\n The total is answer[3] = 2.\n \n Example 2:\n \n >>> sumPrefixScores(words = [\"abcd\"])\n >>> [4]\n Explanation:\n \"abcd\" has 4 prefixes: \"a\", \"ab\", \"abc\", and \"abcd\".\n Each prefix has a score of one, so the total is answer[0] = 1 + 1 + 1 + 1 = 4.\n \"\"\"\n"}
{"task_id": "closest-fair-integer", "prompt": "def closestFair(n: int) -> int:\n \"\"\"\n You are given a positive integer n.\n We call an integer k fair if the number of even digits in k is equal to the number of odd digits in it.\n Return the smallest fair integer that is greater than or equal to n.\n \n Example 1:\n \n >>> closestFair(n = 2)\n >>> 10\n Explanation: The smallest fair integer that is greater than or equal to 2 is 10.\n 10 is fair because it has an equal number of even and odd digits (one odd digit and one even digit).\n Example 2:\n \n >>> closestFair(n = 403)\n >>> 1001\n Explanation: The smallest fair integer that is greater than or equal to 403 is 1001.\n 1001 is fair because it has an equal number of even and odd digits (two odd digits and two even digits).\n \"\"\"\n"}
{"task_id": "sort-the-people", "prompt": "def sortPeople(names: List[str], heights: List[int]) -> List[str]:\n \"\"\"\n You are given an array of strings names, and an array heights that consists of distinct positive integers. Both arrays are of length n.\n For each index i, names[i] and heights[i] denote the name and height of the ith person.\n Return names sorted in descending order by the people's heights.\n \n Example 1:\n \n >>> sortPeople(names = [\"Mary\",\"John\",\"Emma\"], heights = [180,165,170])\n >>> [\"Mary\",\"Emma\",\"John\"]\n Explanation: Mary is the tallest, followed by Emma and John.\n \n Example 2:\n \n >>> sortPeople(names = [\"Alice\",\"Bob\",\"Bob\"], heights = [155,185,150])\n >>> [\"Bob\",\"Alice\",\"Bob\"]\n Explanation: The first Bob is the tallest, followed by Alice and the second Bob.\n \"\"\"\n"}
{"task_id": "longest-subarray-with-maximum-bitwise-and", "prompt": "def longestSubarray(nums: List[int]) -> int:\n \"\"\"\n You are given an integer array nums of size n.\n Consider a non-empty subarray from nums that has the maximum possible bitwise AND.\n \n In other words, let k be the maximum value of the bitwise AND of any subarray of nums. Then, only subarrays with a bitwise AND equal to k should be considered.\n \n Return the length of the longest such subarray.\n The bitwise AND of an array is the bitwise AND of all the numbers in it.\n A subarray is a contiguous sequence of elements within an array.\n \n Example 1:\n \n >>> longestSubarray(nums = [1,2,3,3,2,2])\n >>> 2\n Explanation:\n The maximum possible bitwise AND of a subarray is 3.\n The longest subarray with that value is [3,3], so we return 2.\n \n Example 2:\n \n >>> longestSubarray(nums = [1,2,3,4])\n >>> 1\n Explanation:\n The maximum possible bitwise AND of a subarray is 4.\n The longest subarray with that value is [4], so we return 1.\n \"\"\"\n"}
{"task_id": "find-all-good-indices", "prompt": "def goodIndices(nums: List[int], k: int) -> List[int]:\n \"\"\"\n You are given a 0-indexed integer array nums of size n and a positive integer k.\n We call an index i in the range k <= i < n - k good if the following conditions are satisfied:\n \n The k elements that are just before the index i are in non-increasing order.\n The k elements that are just after the index i are in non-decreasing order.\n \n Return an array of all good indices sorted in increasing order.\n \n Example 1:\n \n >>> goodIndices(nums = [2,1,1,1,3,4,1], k = 2)\n >>> [2,3]\n Explanation: There are two good indices in the array:\n - Index 2. The subarray [2,1] is in non-increasing order, and the subarray [1,3] is in non-decreasing order.\n - Index 3. The subarray [1,1] is in non-increasing order, and the subarray [3,4] is in non-decreasing order.\n Note that the index 4 is not good because [4,1] is not non-decreasing.\n Example 2:\n \n >>> goodIndices(nums = [2,1,1,2], k = 2)\n >>> []\n Explanation: There are no good indices in this array.\n \"\"\"\n"}
{"task_id": "number-of-good-paths", "prompt": "def numberOfGoodPaths(vals: List[int], edges: List[List[int]]) -> int:\n \"\"\"\n There is a tree (i.e. a connected, undirected graph with no cycles) consisting of n nodes numbered from 0 to n - 1 and exactly n - 1 edges.\n You are given a 0-indexed integer array vals of length n where vals[i] denotes the value of the ith node. You are also given a 2D integer array edges where edges[i] = [ai, bi] denotes that there exists an undirected edge connecting nodes ai and bi.\n A good path is a simple path that satisfies the following conditions:\n \n The starting node and the ending node have the same value.\n All nodes between the starting node and the ending node have values less than or equal to the starting node (i.e. the starting node's value should be the maximum value along the path).\n \n Return the number of distinct good paths.\n Note that a path and its reverse are counted as the same path. For example, 0 -> 1 is considered to be the same as 1 -> 0. A single node is also considered as a valid path.\n \n Example 1:\n \n \n >>> numberOfGoodPaths(vals = [1,3,2,1,3], edges = [[0,1],[0,2],[2,3],[2,4]])\n >>> 6\n Explanation: There are 5 good paths consisting of a single node.\n There is 1 additional good path: 1 -> 0 -> 2 -> 4.\n (The reverse path 4 -> 2 -> 0 -> 1 is treated as the same as 1 -> 0 -> 2 -> 4.)\n Note that 0 -> 2 -> 3 is not a good path because vals[2] > vals[0].\n \n Example 2:\n \n \n >>> numberOfGoodPaths(vals = [1,1,2,2,3], edges = [[0,1],[1,2],[2,3],[2,4]])\n >>> 7\n Explanation: There are 5 good paths consisting of a single node.\n There are 2 additional good paths: 0 -> 1 and 2 -> 3.\n \n Example 3:\n \n \n >>> numberOfGoodPaths(vals = [1], edges = [])\n >>> 1\n Explanation: The tree consists of only one node, so there is one good path.\n \"\"\"\n"}
{"task_id": "merge-operations-to-turn-array-into-a-palindrome", "prompt": "def minimumOperations(nums: List[int]) -> int:\n \"\"\"\n You are given an array nums consisting of positive integers.\n You can perform the following operation on the array any number of times:\n \n Choose any two adjacent elements and replace them with their sum.\n \n \n For example, if nums = [1,2,3,1], you can apply one operation to make it [1,5,1].\n \n \n \n Return the minimum number of operations needed to turn the array into a palindrome.\n \n Example 1:\n \n >>> minimumOperations(nums = [4,3,2,1,2,3,1])\n >>> 2\n Explanation: We can turn the array into a palindrome in 2 operations as follows:\n - Apply the operation on the fourth and fifth element of the array, nums becomes equal to [4,3,2,3,3,1].\n - Apply the operation on the fifth and sixth element of the array, nums becomes equal to [4,3,2,3,4].\n The array [4,3,2,3,4] is a palindrome.\n It can be shown that 2 is the minimum number of operations needed.\n \n Example 2:\n \n >>> minimumOperations(nums = [1,2,3,4])\n >>> 3\n Explanation: We do the operation 3 times in any position, we obtain the array [10] at the end which is a palindrome.\n \"\"\"\n"}
{"task_id": "remove-letter-to-equalize-frequency", "prompt": "def equalFrequency(word: str) -> bool:\n \"\"\"\n You are given a 0-indexed string word, consisting of lowercase English letters. You need to select one index and remove the letter at that index from word so that the frequency of every letter present in word is equal.\n Return true if it is possible to remove one letter so that the frequency of all letters in word are equal, and false otherwise.\n Note:\n \n The frequency of a letter x is the number of times it occurs in the string.\n You must remove exactly one letter and cannot choose to do nothing.\n \n \n Example 1:\n \n >>> equalFrequency(word = \"abcc\")\n >>> true\n Explanation: Select index 3 and delete it: word becomes \"abc\" and each character has a frequency of 1.\n \n Example 2:\n \n >>> equalFrequency(word = \"aazz\")\n >>> false\n Explanation: We must delete a character, so either the frequency of \"a\" is 1 and the frequency of \"z\" is 2, or vice versa. It is impossible to make all present letters have equal frequency.\n \"\"\"\n"}
{"task_id": "bitwise-xor-of-all-pairings", "prompt": "def xorAllNums(nums1: List[int], nums2: List[int]) -> int:\n \"\"\"\n You are given two 0-indexed arrays, nums1 and nums2, consisting of non-negative integers. Let there be another array, nums3, which contains the bitwise XOR of all pairings of integers between nums1 and nums2 (every integer in nums1 is paired with every integer in nums2 exactly once).\n Return the bitwise XOR of all integers in nums3.\n \n Example 1:\n \n >>> xorAllNums(nums1 = [2,1,3], nums2 = [10,2,5,0])\n >>> 13\n Explanation:\n A possible nums3 array is [8,0,7,2,11,3,4,1,9,1,6,3].\n The bitwise XOR of all these numbers is 13, so we return 13.\n \n Example 2:\n \n >>> xorAllNums(nums1 = [1,2], nums2 = [3,4])\n >>> 0\n Explanation:\n All possible pairs of bitwise XORs are nums1[0] ^ nums2[0], nums1[0] ^ nums2[1], nums1[1] ^ nums2[0],\n and nums1[1] ^ nums2[1].\n Thus, one possible nums3 array is [2,5,1,6].\n 2 ^ 5 ^ 1 ^ 6 = 0, so we return 0.\n \"\"\"\n"}
{"task_id": "number-of-pairs-satisfying-inequality", "prompt": "def numberOfPairs(nums1: List[int], nums2: List[int], diff: int) -> int:\n \"\"\"\n You are given two 0-indexed integer arrays nums1 and nums2, each of size n, and an integer diff. Find the number of pairs (i, j) such that:\n \n 0 <= i < j <= n - 1 and\n nums1[i] - nums1[j] <= nums2[i] - nums2[j] + diff.\n \n Return the number of pairs that satisfy the conditions.\n \n Example 1:\n \n >>> numberOfPairs(nums1 = [3,2,5], nums2 = [2,2,1], diff = 1)\n >>> 3\n Explanation:\n There are 3 pairs that satisfy the conditions:\n 1. i = 0, j = 1: 3 - 2 <= 2 - 2 + 1. Since i < j and 1 <= 1, this pair satisfies the conditions.\n 2. i = 0, j = 2: 3 - 5 <= 2 - 1 + 1. Since i < j and -2 <= 2, this pair satisfies the conditions.\n 3. i = 1, j = 2: 2 - 5 <= 2 - 1 + 1. Since i < j and -3 <= 2, this pair satisfies the conditions.\n Therefore, we return 3.\n \n Example 2:\n \n >>> numberOfPairs(nums1 = [3,-1], nums2 = [-2,2], diff = -1)\n >>> 0\n Explanation:\n Since there does not exist any pair that satisfies the conditions, we return 0.\n \"\"\"\n"}
{"task_id": "number-of-common-factors", "prompt": "def commonFactors(a: int, b: int) -> int:\n \"\"\"\n Given two positive integers a and b, return the number of common factors of a and b.\n An integer x is a common factor of a and b if x divides both a and b.\n \n Example 1:\n \n >>> commonFactors(a = 12, b = 6)\n >>> 4\n Explanation: The common factors of 12 and 6 are 1, 2, 3, 6.\n \n Example 2:\n \n >>> commonFactors(a = 25, b = 30)\n >>> 2\n Explanation: The common factors of 25 and 30 are 1, 5.\n \"\"\"\n"}
{"task_id": "maximum-sum-of-an-hourglass", "prompt": "def maxSum(grid: List[List[int]]) -> int:\n \"\"\"\n You are given an m x n integer matrix grid.\n We define an hourglass as a part of the matrix with the following form:\n \n Return the maximum sum of the elements of an hourglass.\n Note that an hourglass cannot be rotated and must be entirely contained within the matrix.\n \n Example 1:\n \n \n >>> maxSum(grid = [[6,2,1,3],[4,2,1,5],[9,2,8,7],[4,1,2,9]])\n >>> 30\n Explanation: The cells shown above represent the hourglass with the maximum sum: 6 + 2 + 1 + 2 + 9 + 2 + 8 = 30.\n \n Example 2:\n \n \n >>> maxSum(grid = [[1,2,3],[4,5,6],[7,8,9]])\n >>> 35\n Explanation: There is only one hourglass in the matrix, with the sum: 1 + 2 + 3 + 5 + 7 + 8 + 9 = 35.\n \"\"\"\n"}
{"task_id": "minimize-xor", "prompt": "def minimizeXor(num1: int, num2: int) -> int:\n \"\"\"\n Given two positive integers num1 and num2, find the positive integer x such that:\n \n x has the same number of set bits as num2, and\n The value x XOR num1 is minimal.\n \n Note that XOR is the bitwise XOR operation.\n Return the integer x. The test cases are generated such that x is uniquely determined.\n The number of set bits of an integer is the number of 1's in its binary representation.\n \n Example 1:\n \n >>> minimizeXor(num1 = 3, num2 = 5)\n >>> 3\n Explanation:\n The binary representations of num1 and num2 are 0011 and 0101, respectively.\n The integer 3 has the same number of set bits as num2, and the value 3 XOR 3 = 0 is minimal.\n \n Example 2:\n \n >>> minimizeXor(num1 = 1, num2 = 12)\n >>> 3\n Explanation:\n The binary representations of num1 and num2 are 0001 and 1100, respectively.\n The integer 3 has the same number of set bits as num2, and the value 3 XOR 1 = 2 is minimal.\n \"\"\"\n"}
{"task_id": "maximum-deletions-on-a-string", "prompt": "def deleteString(s: str) -> int:\n \"\"\"\n You are given a string s consisting of only lowercase English letters. In one operation, you can:\n \n Delete the entire string s, or\n Delete the first i letters of s if the first i letters of s are equal to the following i letters in s, for any i in the range 1 <= i <= s.length / 2.\n \n For example, if s = \"ababc\", then in one operation, you could delete the first two letters of s to get \"abc\", since the first two letters of s and the following two letters of s are both equal to \"ab\".\n Return the maximum number of operations needed to delete all of s.\n \n Example 1:\n \n >>> deleteString(s = \"abcabcdabc\")\n >>> 2\n Explanation:\n - Delete the first 3 letters (\"abc\") since the next 3 letters are equal. Now, s = \"abcdabc\".\n - Delete all the letters.\n We used 2 operations so return 2. It can be proven that 2 is the maximum number of operations needed.\n Note that in the second operation we cannot delete \"abc\" again because the next occurrence of \"abc\" does not happen in the next 3 letters.\n \n Example 2:\n \n >>> deleteString(s = \"aaabaab\")\n >>> 4\n Explanation:\n - Delete the first letter (\"a\") since the next letter is equal. Now, s = \"aabaab\".\n - Delete the first 3 letters (\"aab\") since the next 3 letters are equal. Now, s = \"aab\".\n - Delete the first letter (\"a\") since the next letter is equal. Now, s = \"ab\".\n - Delete all the letters.\n We used 4 operations so return 4. It can be proven that 4 is the maximum number of operations needed.\n \n Example 3:\n \n >>> deleteString(s = \"aaaaa\")\n >>> 5\n Explanation: In each operation, we can delete the first letter of s.\n \"\"\"\n"}
{"task_id": "maximize-total-tastiness-of-purchased-fruits", "prompt": "def maxTastiness(price: List[int], tastiness: List[int], maxAmount: int, maxCoupons: int) -> int:\n \"\"\"\n You are given two non-negative integer arrays price and tastiness, both arrays have the same length n. You are also given two non-negative integers maxAmount and maxCoupons.\n For every integer i in range [0, n - 1]:\n \n price[i] describes the price of ith fruit.\n tastiness[i] describes the tastiness of ith fruit.\n \n You want to purchase some fruits such that total tastiness is maximized and the total price does not exceed maxAmount.\n Additionally, you can use a coupon to purchase fruit for half of its price (rounded down to the closest integer). You can use at most maxCoupons of such coupons.\n Return the maximum total tastiness that can be purchased.\n Note that:\n \n You can purchase each fruit at most once.\n You can use coupons on some fruit at most once.\n \n \n Example 1:\n \n >>> maxTastiness(price = [10,20,20], tastiness = [5,8,8], maxAmount = 20, maxCoupons = 1)\n >>> 13\n Explanation: It is possible to make total tastiness 13 in following way:\n - Buy first fruit without coupon, so that total price = 0 + 10 and total tastiness = 0 + 5.\n - Buy second fruit with coupon, so that total price = 10 + 10 and total tastiness = 5 + 8.\n - Do not buy third fruit, so that total price = 20 and total tastiness = 13.\n It can be proven that 13 is the maximum total tastiness that can be obtained.\n \n Example 2:\n \n >>> maxTastiness(price = [10,15,7], tastiness = [5,8,20], maxAmount = 10, maxCoupons = 2)\n >>> 28\n Explanation: It is possible to make total tastiness 20 in following way:\n - Do not buy first fruit, so that total price = 0 and total tastiness = 0.\n - Buy second fruit with coupon, so that total price = 0 + 7 and total tastiness = 0 + 8.\n - Buy third fruit with coupon, so that total price = 7 + 3 and total tastiness = 8 + 20.\n It can be proven that 28 is the maximum total tastiness that can be obtained.\n \"\"\"\n"}
{"task_id": "the-employee-that-worked-on-the-longest-task", "prompt": "def hardestWorker(n: int, logs: List[List[int]]) -> int:\n \"\"\"\n There are n employees, each with a unique id from 0 to n - 1.\n You are given a 2D integer array logs where logs[i] = [idi, leaveTimei] where:\n \n idi is the id of the employee that worked on the ith task, and\n leaveTimei is the time at which the employee finished the ith task. All the values leaveTimei are unique.\n \n Note that the ith task starts the moment right after the (i - 1)th task ends, and the 0th task starts at time 0.\n Return the id of the employee that worked the task with the longest time. If there is a tie between two or more employees, return the smallest id among them.\n \n Example 1:\n \n >>> hardestWorker(n = 10, logs = [[0,3],[2,5],[0,9],[1,15]])\n >>> 1\n Explanation:\n Task 0 started at 0 and ended at 3 with 3 units of times.\n Task 1 started at 3 and ended at 5 with 2 units of times.\n Task 2 started at 5 and ended at 9 with 4 units of times.\n Task 3 started at 9 and ended at 15 with 6 units of times.\n The task with the longest time is task 3 and the employee with id 1 is the one that worked on it, so we return 1.\n \n Example 2:\n \n >>> hardestWorker(n = 26, logs = [[1,1],[3,7],[2,12],[7,17]])\n >>> 3\n Explanation:\n Task 0 started at 0 and ended at 1 with 1 unit of times.\n Task 1 started at 1 and ended at 7 with 6 units of times.\n Task 2 started at 7 and ended at 12 with 5 units of times.\n Task 3 started at 12 and ended at 17 with 5 units of times.\n The tasks with the longest time is task 1. The employee that worked on it is 3, so we return 3.\n \n Example 3:\n \n >>> hardestWorker(n = 2, logs = [[0,10],[1,20]])\n >>> 0\n Explanation:\n Task 0 started at 0 and ended at 10 with 10 units of times.\n Task 1 started at 10 and ended at 20 with 10 units of times.\n The tasks with the longest time are tasks 0 and 1. The employees that worked on them are 0 and 1, so we return the smallest id 0.\n \"\"\"\n"}
{"task_id": "find-the-original-array-of-prefix-xor", "prompt": "def findArray(pref: List[int]) -> List[int]:\n \"\"\"\n You are given an integer array pref of size n. Find and return the array arr of size n that satisfies:\n \n pref[i] = arr[0] ^ arr[1] ^ ... ^ arr[i].\n \n Note that ^ denotes the bitwise-xor operation.\n It can be proven that the answer is unique.\n \n Example 1:\n \n >>> findArray(pref = [5,2,0,3,1])\n >>> [5,7,2,3,2]\n Explanation: From the array [5,7,2,3,2] we have the following:\n - pref[0] = 5.\n - pref[1] = 5 ^ 7 = 2.\n - pref[2] = 5 ^ 7 ^ 2 = 0.\n - pref[3] = 5 ^ 7 ^ 2 ^ 3 = 3.\n - pref[4] = 5 ^ 7 ^ 2 ^ 3 ^ 2 = 1.\n \n Example 2:\n \n >>> findArray(pref = [13])\n >>> [13]\n Explanation: We have pref[0] = arr[0] = 13.\n \"\"\"\n"}
{"task_id": "using-a-robot-to-print-the-lexicographically-smallest-string", "prompt": "def robotWithString(s: str) -> str:\n \"\"\"\n You are given a string s and a robot that currently holds an empty string t. Apply one of the following operations until s and t are both empty:\n \n Remove the first character of a string s and give it to the robot. The robot will append this character to the string t.\n Remove the last character of a string t and give it to the robot. The robot will write this character on paper.\n \n Return the lexicographically smallest string that can be written on the paper.\n \n Example 1:\n \n >>> robotWithString(s = \"zza\")\n >>> \"azz\"\n Explanation: Let p denote the written string.\n Initially p=\"\", s=\"zza\", t=\"\".\n Perform first operation three times p=\"\", s=\"\", t=\"zza\".\n Perform second operation three times p=\"azz\", s=\"\", t=\"\".\n \n Example 2:\n \n >>> robotWithString(s = \"bac\")\n >>> \"abc\"\n Explanation: Let p denote the written string.\n Perform first operation twice p=\"\", s=\"c\", t=\"ba\".\n Perform second operation twice p=\"ab\", s=\"c\", t=\"\".\n Perform first operation p=\"ab\", s=\"\", t=\"c\".\n Perform second operation p=\"abc\", s=\"\", t=\"\".\n \n Example 3:\n \n >>> robotWithString(s = \"bdda\")\n >>> \"addb\"\n Explanation: Let p denote the written string.\n Initially p=\"\", s=\"bdda\", t=\"\".\n Perform first operation four times p=\"\", s=\"\", t=\"bdda\".\n Perform second operation four times p=\"addb\", s=\"\", t=\"\".\n \"\"\"\n"}
{"task_id": "paths-in-matrix-whose-sum-is-divisible-by-k", "prompt": "def numberOfPaths(grid: List[List[int]], k: int) -> int:\n \"\"\"\n You are given a 0-indexed m x n integer matrix grid and an integer k. You are currently at position (0, 0) and you want to reach position (m - 1, n - 1) moving only down or right.\n Return the number of paths where the sum of the elements on the path is divisible by k. Since the answer may be very large, return it modulo 109 + 7.\n \n Example 1:\n \n \n >>> numberOfPaths(grid = [[5,2,4],[3,0,5],[0,7,2]], k = 3)\n >>> 2\n Explanation: There are two paths where the sum of the elements on the path is divisible by k.\n The first path highlighted in red has a sum of 5 + 2 + 4 + 5 + 2 = 18 which is divisible by 3.\n The second path highlighted in blue has a sum of 5 + 3 + 0 + 5 + 2 = 15 which is divisible by 3.\n \n Example 2:\n \n \n >>> numberOfPaths(grid = [[0,0]], k = 5)\n >>> 1\n Explanation: The path highlighted in red has a sum of 0 + 0 = 0 which is divisible by 5.\n \n Example 3:\n \n \n >>> numberOfPaths(grid = [[7,3,4,9],[2,3,6,2],[2,3,7,0]], k = 1)\n >>> 10\n Explanation: Every integer is divisible by 1 so the sum of the elements on every possible path is divisible by k.\n \"\"\"\n"}
{"task_id": "minimum-split-into-subarrays-with-gcd-greater-than-one", "prompt": "def minimumSplits(nums: List[int]) -> int:\n \"\"\"\n You are given an array nums consisting of positive integers.\n Split the array into one or more disjoint subarrays such that:\n \n Each element of the array belongs to exactly one subarray, and\n The GCD of the elements of each subarray is strictly greater than 1.\n \n Return the minimum number of subarrays that can be obtained after the split.\n Note that:\n \n The GCD of a subarray is the largest positive integer that evenly divides all the elements of the subarray.\n A subarray is a contiguous part of the array.\n \n \n Example 1:\n \n >>> minimumSplits(nums = [12,6,3,14,8])\n >>> 2\n Explanation: We can split the array into the subarrays: [12,6,3] and [14,8].\n - The GCD of 12, 6 and 3 is 3, which is strictly greater than 1.\n - The GCD of 14 and 8 is 2, which is strictly greater than 1.\n It can be shown that splitting the array into one subarray will make the GCD = 1.\n \n Example 2:\n \n >>> minimumSplits(nums = [4,12,6,14])\n >>> 1\n Explanation: We can split the array into only one subarray, which is the whole array.\n \"\"\"\n"}
{"task_id": "number-of-valid-clock-times", "prompt": "def countTime(time: str) -> int:\n \"\"\"\n You are given a string of length 5 called time, representing the current time on a digital clock in the format \"hh:mm\". The earliest possible time is \"00:00\" and the latest possible time is \"23:59\".\n In the string time, the digits represented by the ?\u00a0symbol are unknown, and must be replaced with a digit from 0 to 9.\n Return an integer answer, the number of valid clock times that can be created by replacing every ?\u00a0with a digit from 0 to 9.\n \n Example 1:\n \n >>> countTime(time = \"?5:00\")\n >>> 2\n Explanation: We can replace the ? with either a 0 or 1, producing \"05:00\" or \"15:00\". Note that we cannot replace it with a 2, since the time \"25:00\" is invalid. In total, we have two choices.\n \n Example 2:\n \n >>> countTime(time = \"0?:0?\")\n >>> 100\n Explanation: Each ? can be replaced by any digit from 0 to 9, so we have 100 total choices.\n \n Example 3:\n \n >>> countTime(time = \"??:??\")\n >>> 1440\n Explanation: There are 24 possible choices for the hours, and 60 possible choices for the minutes. In total, we have 24 * 60 = 1440 choices.\n \"\"\"\n"}
{"task_id": "range-product-queries-of-powers", "prompt": "def productQueries(n: int, queries: List[List[int]]) -> List[int]:\n \"\"\"\n Given a positive integer n, there exists a 0-indexed array called powers, composed of the minimum number of powers of 2 that sum to n. The array is sorted in non-decreasing order, and there is only one way to form the array.\n You are also given a 0-indexed 2D integer array queries, where queries[i] = [lefti, righti]. Each queries[i] represents a query where you have to find the product of all powers[j] with lefti <= j <= righti.\n Return an array answers, equal in length to queries, where answers[i] is the answer to the ith query. Since the answer to the ith query may be too large, each answers[i] should be returned modulo 109 + 7.\n \n Example 1:\n \n >>> productQueries(n = 15, queries = [[0,1],[2,2],[0,3]])\n >>> [2,4,64]\n Explanation:\n For n = 15, powers = [1,2,4,8]. It can be shown that powers cannot be a smaller size.\n Answer to 1st query: powers[0] * powers[1] = 1 * 2 = 2.\n Answer to 2nd query: powers[2] = 4.\n Answer to 3rd query: powers[0] * powers[1] * powers[2] * powers[3] = 1 * 2 * 4 * 8 = 64.\n Each answer modulo 109 + 7 yields the same answer, so [2,4,64] is returned.\n \n Example 2:\n \n >>> productQueries(n = 2, queries = [[0,0]])\n >>> [2]\n Explanation:\n For n = 2, powers = [2].\n The answer to the only query is powers[0] = 2. The answer modulo 109 + 7 is the same, so [2] is returned.\n \"\"\"\n"}
{"task_id": "minimize-maximum-of-array", "prompt": "def minimizeArrayValue(nums: List[int]) -> int:\n \"\"\"\n You are given a 0-indexed array nums comprising of n non-negative integers.\n In one operation, you must:\n \n Choose an integer i such that 1 <= i < n and nums[i] > 0.\n Decrease nums[i] by 1.\n Increase nums[i - 1] by 1.\n \n Return the minimum possible value of the maximum integer of nums after performing any number of operations.\n \n Example 1:\n \n >>> minimizeArrayValue(nums = [3,7,1,6])\n >>> 5\n Explanation:\n One set of optimal operations is as follows:\n 1. Choose i = 1, and nums becomes [4,6,1,6].\n 2. Choose i = 3, and nums becomes [4,6,2,5].\n 3. Choose i = 1, and nums becomes [5,5,2,5].\n The maximum integer of nums is 5. It can be shown that the maximum number cannot be less than 5.\n Therefore, we return 5.\n \n Example 2:\n \n >>> minimizeArrayValue(nums = [10,1])\n >>> 10\n Explanation:\n It is optimal to leave nums as is, and since 10 is the maximum value, we return 10.\n \"\"\"\n"}
{"task_id": "create-components-with-same-value", "prompt": "def componentValue(nums: List[int], edges: List[List[int]]) -> int:\n \"\"\"\n There is an undirected tree with n nodes labeled from 0 to n - 1.\n You are given a 0-indexed integer array nums of length n where nums[i] represents the value of the ith node. You are also given a 2D integer array edges of length n - 1 where edges[i] = [ai, bi] indicates that there is an edge between nodes ai and bi in the tree.\n You are allowed to delete some edges, splitting the tree into multiple connected components. Let the value of a component be the sum of all nums[i] for which node i is in the component.\n Return the maximum number of edges you can delete, such that every connected component in the tree has the same value.\n \n Example 1:\n \n \n >>> componentValue(nums = [6,2,2,2,6], edges = [[0,1],[1,2],[1,3],[3,4]])\n >>> 2\n Explanation: The above figure shows how we can delete the edges [0,1] and [3,4]. The created components are nodes [0], [1,2,3] and [4]. The sum of the values in each component equals 6. It can be proven that no better deletion exists, so the answer is 2.\n \n Example 2:\n \n >>> componentValue(nums = [2], edges = [])\n >>> 0\n Explanation: There are no edges to be deleted.\n \"\"\"\n"}
{"task_id": "largest-positive-integer-that-exists-with-its-negative", "prompt": "def findMaxK(nums: List[int]) -> int:\n \"\"\"\n Given an integer array nums that does not contain any zeros, find the largest positive integer k such that -k also exists in the array.\n Return the positive integer k. If there is no such integer, return -1.\n \n Example 1:\n \n >>> findMaxK(nums = [-1,2,-3,3])\n >>> 3\n Explanation: 3 is the only valid k we can find in the array.\n \n Example 2:\n \n >>> findMaxK(nums = [-1,10,6,7,-7,1])\n >>> 7\n Explanation: Both 1 and 7 have their corresponding negative values in the array. 7 has a larger value.\n \n Example 3:\n \n >>> findMaxK(nums = [-10,8,6,7,-2,-3])\n >>> -1\n Explanation: There is no a single valid k, we return -1.\n \"\"\"\n"}
{"task_id": "count-number-of-distinct-integers-after-reverse-operations", "prompt": "def countDistinctIntegers(nums: List[int]) -> int:\n \"\"\"\n You are given an array nums consisting of positive integers.\n You have to take each integer in the array, reverse its digits, and add it to the end of the array. You should apply this operation to the original integers in nums.\n Return the number of distinct integers in the final array.\n \n Example 1:\n \n >>> countDistinctIntegers(nums = [1,13,10,12,31])\n >>> 6\n Explanation: After including the reverse of each number, the resulting array is [1,13,10,12,31,1,31,1,21,13].\n The reversed integers that were added to the end of the array are underlined. Note that for the integer 10, after reversing it, it becomes 01 which is just 1.\n The number of distinct integers in this array is 6 (The numbers 1, 10, 12, 13, 21, and 31).\n Example 2:\n \n >>> countDistinctIntegers(nums = [2,2,2])\n >>> 1\n Explanation: After including the reverse of each number, the resulting array is [2,2,2,2,2,2].\n The number of distinct integers in this array is 1 (The number 2).\n \"\"\"\n"}
{"task_id": "sum-of-number-and-its-reverse", "prompt": "def sumOfNumberAndReverse(num: int) -> bool:\n \"\"\"\n Given a non-negative integer num, return true if num can be expressed as the sum of any non-negative integer and its reverse, or false otherwise.\n \n Example 1:\n \n >>> sumOfNumberAndReverse(num = 443)\n >>> true\n Explanation: 172 + 271 = 443 so we return true.\n \n Example 2:\n \n >>> sumOfNumberAndReverse(num = 63)\n >>> false\n Explanation: 63 cannot be expressed as the sum of a non-negative integer and its reverse so we return false.\n \n Example 3:\n \n >>> sumOfNumberAndReverse(num = 181)\n >>> true\n Explanation: 140 + 041 = 181 so we return true. Note that when a number is reversed, there may be leading zeros.\n \"\"\"\n"}
{"task_id": "count-subarrays-with-fixed-bounds", "prompt": "def countSubarrays(nums: List[int], minK: int, maxK: int) -> int:\n \"\"\"\n You are given an integer array nums and two integers minK and maxK.\n A fixed-bound subarray of nums is a subarray that satisfies the following conditions:\n \n The minimum value in the subarray is equal to minK.\n The maximum value in the subarray is equal to maxK.\n \n Return the number of fixed-bound subarrays.\n A subarray is a contiguous part of an array.\n \n Example 1:\n \n >>> countSubarrays(nums = [1,3,5,2,7,5], minK = 1, maxK = 5)\n >>> 2\n Explanation: The fixed-bound subarrays are [1,3,5] and [1,3,5,2].\n \n Example 2:\n \n >>> countSubarrays(nums = [1,1,1,1], minK = 1, maxK = 1)\n >>> 10\n Explanation: Every subarray of nums is a fixed-bound subarray. There are 10 possible subarrays.\n \"\"\"\n"}
{"task_id": "number-of-nodes-with-value-one", "prompt": "def numberOfNodes(n: int, queries: List[int]) -> int:\n \"\"\"\n There is an undirected connected tree with n nodes labeled from 1 to n and n - 1 edges. You are given the integer n. The parent node of a node with a label v is the node with the label floor (v / 2). The root of the tree is the node with the label 1.\n \n For example, if n = 7, then the node with the label 3 has the node with the label floor(3 / 2) = 1 as its parent, and the node with the label 7 has the node with the label floor(7 / 2) = 3 as its parent.\n \n You are also given an integer array queries. Initially, every node has a value 0 on it. For each query queries[i], you should flip all values in the subtree of the node with the label queries[i].\n Return the total number of nodes with the value 1 after processing all the queries.\n Note that:\n \n Flipping the value of a node means that the node with the value 0 becomes 1 and vice versa.\n floor(x) is equivalent to rounding x down to the nearest integer.\n \n \n Example 1:\n \n \n >>> numberOfNodes(n = 5 , queries = [1,2,5])\n >>> 3\n Explanation: The diagram above shows the tree structure and its status after performing the queries. The blue node represents the value 0, and the red node represents the value 1.\n After processing the queries, there are three red nodes (nodes with value 1): 1, 3, and 5.\n \n Example 2:\n \n \n >>> numberOfNodes(n = 3, queries = [2,3,3])\n >>> 1\n Explanation: The diagram above shows the tree structure and its status after performing the queries. The blue node represents the value 0, and the red node represents the value 1.\n After processing the queries, there are one red node (node with value 1): 2.\n \"\"\"\n"}
{"task_id": "determine-if-two-events-have-conflict", "prompt": "def haveConflict(event1: List[str], event2: List[str]) -> bool:\n \"\"\"\n You are given two arrays of strings that represent two inclusive events that happened on the same day, event1 and event2, where:\n \n event1 = [startTime1, endTime1] and\n event2 = [startTime2, endTime2].\n \n Event times are valid 24 hours format in the form of HH:MM.\n A conflict happens when two events have some non-empty intersection (i.e., some moment is common to both events).\n Return true if there is a conflict between two events. Otherwise, return false.\n \n Example 1:\n \n >>> haveConflict(event1 = [\"01:15\",\"02:00\"], event2 = [\"02:00\",\"03:00\"])\n >>> true\n Explanation: The two events intersect at time 2:00.\n \n Example 2:\n \n >>> haveConflict(event1 = [\"01:00\",\"02:00\"], event2 = [\"01:20\",\"03:00\"])\n >>> true\n Explanation: The two events intersect starting from 01:20 to 02:00.\n \n Example 3:\n \n >>> haveConflict(event1 = [\"10:00\",\"11:00\"], event2 = [\"14:00\",\"15:00\"])\n >>> false\n Explanation: The two events do not intersect.\n \"\"\"\n"}
{"task_id": "number-of-subarrays-with-gcd-equal-to-k", "prompt": "def subarrayGCD(nums: List[int], k: int) -> int:\n \"\"\"\n Given an integer array nums and an integer k, return the number of subarrays of nums where the greatest common divisor of the subarray's elements is k.\n A subarray is a contiguous non-empty sequence of elements within an array.\n The greatest common divisor of an array is the largest integer that evenly divides all the array elements.\n \n Example 1:\n \n >>> subarrayGCD(nums = [9,3,1,2,6,3], k = 3)\n >>> 4\n Explanation: The subarrays of nums where 3 is the greatest common divisor of all the subarray's elements are:\n - [9,3,1,2,6,3]\n - [9,3,1,2,6,3]\n - [9,3,1,2,6,3]\n - [9,3,1,2,6,3]\n \n Example 2:\n \n >>> subarrayGCD(nums = [4], k = 7)\n >>> 0\n Explanation: There are no subarrays of nums where 7 is the greatest common divisor of all the subarray's elements.\n \"\"\"\n"}
{"task_id": "minimum-cost-to-make-array-equal", "prompt": "def minCost(nums: List[int], cost: List[int]) -> int:\n \"\"\"\n You are given two 0-indexed arrays nums and cost consisting each of n positive integers.\n You can do the following operation any number of times:\n \n Increase or decrease any element of the array nums by 1.\n \n The cost of doing one operation on the ith element is cost[i].\n Return the minimum total cost such that all the elements of the array nums become equal.\n \n Example 1:\n \n >>> minCost(nums = [1,3,5,2], cost = [2,3,1,14])\n >>> 8\n Explanation: We can make all the elements equal to 2 in the following way:\n - Increase the 0th element one time. The cost is 2.\n - Decrease the 1st element one time. The cost is 3.\n - Decrease the 2nd element three times. The cost is 1 + 1 + 1 = 3.\n The total cost is 2 + 3 + 3 = 8.\n It can be shown that we cannot make the array equal with a smaller cost.\n \n Example 2:\n \n >>> minCost(nums = [2,2,2,2,2], cost = [4,2,8,1,3])\n >>> 0\n Explanation: All the elements are already equal, so no operations are needed.\n \"\"\"\n"}
{"task_id": "minimum-number-of-operations-to-make-arrays-similar", "prompt": "def makeSimilar(nums: List[int], target: List[int]) -> int:\n \"\"\"\n You are given two positive integer arrays nums and target, of the same length.\n In one operation, you can choose any two distinct indices i and j where 0 <= i, j < nums.length and:\n \n set nums[i] = nums[i] + 2 and\n set nums[j] = nums[j] - 2.\n \n Two arrays are considered to be similar if the frequency of each element is the same.\n Return the minimum number of operations required to make nums similar to target. The test cases are generated such that nums can always be similar to target.\n \n Example 1:\n \n >>> makeSimilar(nums = [8,12,6], target = [2,14,10])\n >>> 2\n Explanation: It is possible to make nums similar to target in two operations:\n - Choose i = 0 and j = 2, nums = [10,12,4].\n - Choose i = 1 and j = 2, nums = [10,14,2].\n It can be shown that 2 is the minimum number of operations needed.\n \n Example 2:\n \n >>> makeSimilar(nums = [1,2,5], target = [4,1,3])\n >>> 1\n Explanation: We can make nums similar to target in one operation:\n - Choose i = 1 and j = 2, nums = [1,4,3].\n \n Example 3:\n \n >>> makeSimilar(nums = [1,1,1,1,1], target = [1,1,1,1,1])\n >>> 0\n Explanation: The array nums is already similiar to target.\n \"\"\"\n"}
{"task_id": "number-of-distinct-binary-strings-after-applying-operations", "prompt": "def countDistinctStrings(s: str, k: int) -> int:\n \"\"\"\n You are given a binary string s and a positive integer k.\n You can apply the following operation on the string any number of times:\n \n Choose any substring of size k from s and flip all its characters, that is, turn all 1's into 0's, and all 0's into 1's.\n \n Return the number of distinct strings you can obtain. Since the answer may be too large, return it modulo 109 + 7.\n Note that:\n \n A binary string is a string that consists only of the characters 0 and 1.\n A substring is a contiguous part of a string.\n \n \n Example 1:\n \n >>> countDistinctStrings(s = \"1001\", k = 3)\n >>> 4\n Explanation: We can obtain the following strings:\n - Applying no operation on the string gives s = \"1001\".\n - Applying one operation on the substring starting at index 0 gives s = \"0111\".\n - Applying one operation on the substring starting at index 1 gives s = \"1110\".\n - Applying one operation on both the substrings starting at indices 0 and 1 gives s = \"0000\".\n It can be shown that we cannot obtain any other string, so the answer is 4.\n Example 2:\n \n >>> countDistinctStrings(s = \"10110\", k = 5)\n >>> 2\n Explanation: We can obtain the following strings:\n - Applying no operation on the string gives s = \"10110\".\n - Applying one operation on the whole string gives s = \"01001\".\n It can be shown that we cannot obtain any other string, so the answer is 2.\n \"\"\"\n"}
{"task_id": "odd-string-difference", "prompt": "def oddString(words: List[str]) -> str:\n \"\"\"\n You are given an array of equal-length strings words. Assume that the length of each string is n.\n Each string words[i] can be converted into a difference integer array difference[i] of length n - 1 where difference[i][j] = words[i][j+1] - words[i][j] where 0 <= j <= n - 2. Note that the difference between two letters is the difference between their positions in the alphabet i.e.\u00a0the position of 'a' is 0, 'b' is 1, and 'z' is 25.\n \n For example, for the string \"acb\", the difference integer array is [2 - 0, 1 - 2] = [2, -1].\n \n All the strings in words have the same difference integer array, except one. You should find that string.\n Return the string in words that has different difference integer array.\n \n Example 1:\n \n >>> oddString(words = [\"adc\",\"wzy\",\"abc\"])\n >>> \"abc\"\n Explanation:\n - The difference integer array of \"adc\" is [3 - 0, 2 - 3] = [3, -1].\n - The difference integer array of \"wzy\" is [25 - 22, 24 - 25]= [3, -1].\n - The difference integer array of \"abc\" is [1 - 0, 2 - 1] = [1, 1].\n The odd array out is [1, 1], so we return the corresponding string, \"abc\".\n \n Example 2:\n \n >>> oddString(words = [\"aaa\",\"bob\",\"ccc\",\"ddd\"])\n >>> \"bob\"\n Explanation: All the integer arrays are [0, 0] except for \"bob\", which corresponds to [13, -13].\n \"\"\"\n"}
{"task_id": "words-within-two-edits-of-dictionary", "prompt": "def twoEditWords(queries: List[str], dictionary: List[str]) -> List[str]:\n \"\"\"\n You are given two string arrays, queries and dictionary. All words in each array comprise of lowercase English letters and have the same length.\n In one edit you can take a word from queries, and change any letter in it to any other letter. Find all words from queries that, after a maximum of two edits, equal some word from dictionary.\n Return a list of all words from queries, that match with some word from dictionary after a maximum of two edits. Return the words in the same order they appear in queries.\n \n Example 1:\n \n >>> twoEditWords(queries = [\"word\",\"note\",\"ants\",\"wood\"], dictionary = [\"wood\",\"joke\",\"moat\"])\n >>> [\"word\",\"note\",\"wood\"]\n Explanation:\n - Changing the 'r' in \"word\" to 'o' allows it to equal the dictionary word \"wood\".\n - Changing the 'n' to 'j' and the 't' to 'k' in \"note\" changes it to \"joke\".\n - It would take more than 2 edits for \"ants\" to equal a dictionary word.\n - \"wood\" can remain unchanged (0 edits) and match the corresponding dictionary word.\n Thus, we return [\"word\",\"note\",\"wood\"].\n \n Example 2:\n \n >>> twoEditWords(queries = [\"yes\"], dictionary = [\"not\"])\n >>> []\n Explanation:\n Applying any two edits to \"yes\" cannot make it equal to \"not\". Thus, we return an empty array.\n \"\"\"\n"}
{"task_id": "destroy-sequential-targets", "prompt": "def destroyTargets(nums: List[int], space: int) -> int:\n \"\"\"\n You are given a 0-indexed array nums consisting of positive integers, representing targets on a number line. You are also given an integer space.\n You have a machine which can destroy targets. Seeding the machine with some nums[i] allows it to destroy all targets with values that can be represented as nums[i] + c * space, where c is any non-negative integer. You want to destroy the maximum number of targets in nums.\n Return the minimum value of nums[i] you can seed the machine with to destroy the maximum number of targets.\n \n Example 1:\n \n >>> destroyTargets(nums = [3,7,8,1,1,5], space = 2)\n >>> 1\n Explanation: If we seed the machine with nums[3], then we destroy all targets equal to 1,3,5,7,9,...\n In this case, we would destroy 5 total targets (all except for nums[2]).\n It is impossible to destroy more than 5 targets, so we return nums[3].\n \n Example 2:\n \n >>> destroyTargets(nums = [1,3,5,2,4,6], space = 2)\n >>> 1\n Explanation: Seeding the machine with nums[0], or nums[3] destroys 3 targets.\n It is not possible to destroy more than 3 targets.\n Since nums[0] is the minimal integer that can destroy 3 targets, we return 1.\n \n Example 3:\n \n >>> destroyTargets(nums = [6,2,5], space = 100)\n >>> 2\n Explanation: Whatever initial seed we select, we can only destroy 1 target. The minimal seed is nums[1].\n \"\"\"\n"}
{"task_id": "next-greater-element-iv", "prompt": "def secondGreaterElement(nums: List[int]) -> List[int]:\n \"\"\"\n You are given a 0-indexed array of non-negative integers nums. For each integer in nums, you must find its respective second greater integer.\n The second greater integer of nums[i] is nums[j] such that:\n \n j > i\n nums[j] > nums[i]\n There exists exactly one index k such that nums[k] > nums[i] and i < k < j.\n \n If there is no such nums[j], the second greater integer is considered to be -1.\n \n For example, in the array [1, 2, 4, 3], the second greater integer of 1 is 4, 2 is 3,\u00a0and that of 3 and 4 is -1.\n \n Return an integer array answer, where answer[i] is the second greater integer of nums[i].\n \n Example 1:\n \n >>> secondGreaterElement(nums = [2,4,0,9,6])\n >>> [9,6,6,-1,-1]\n Explanation:\n 0th index: 4 is the first integer greater than 2, and 9 is the second integer greater than 2, to the right of 2.\n 1st index: 9 is the first, and 6 is the second integer greater than 4, to the right of 4.\n 2nd index: 9 is the first, and 6 is the second integer greater than 0, to the right of 0.\n 3rd index: There is no integer greater than 9 to its right, so the second greater integer is considered to be -1.\n 4th index: There is no integer greater than 6 to its right, so the second greater integer is considered to be -1.\n Thus, we return [9,6,6,-1,-1].\n \n Example 2:\n \n >>> secondGreaterElement(nums = [3,3])\n >>> [-1,-1]\n Explanation:\n We return [-1,-1] since neither integer has any integer greater than it.\n \"\"\"\n"}
{"task_id": "average-value-of-even-numbers-that-are-divisible-by-three", "prompt": "def averageValue(nums: List[int]) -> int:\n \"\"\"\n Given an integer array nums of positive integers, return the average value of all even integers that are divisible by 3.\n Note that the average of n elements is the sum of the n elements divided by n and rounded down to the nearest integer.\n \n Example 1:\n \n >>> averageValue(nums = [1,3,6,10,12,15])\n >>> 9\n Explanation: 6 and 12 are even numbers that are divisible by 3. (6 + 12) / 2 = 9.\n \n Example 2:\n \n >>> averageValue(nums = [1,2,4,7,10])\n >>> 0\n Explanation: There is no single number that satisfies the requirement, so return 0.\n \"\"\"\n"}
{"task_id": "most-popular-video-creator", "prompt": "def mostPopularCreator(creators: List[str], ids: List[str], views: List[int]) -> List[List[str]]:\n \"\"\"\n You are given two string arrays creators and ids, and an integer array views, all of length n. The ith video on a platform was created by creators[i], has an id of ids[i], and has views[i] views.\n The popularity of a creator is the sum of the number of views on all of the creator's videos. Find the creator with the highest popularity and the id of their most viewed video.\n \n If multiple creators have the highest popularity, find all of them.\n If multiple videos have the highest view count for a creator, find the lexicographically smallest id.\n \n Note: It is possible for different videos to have the same id, meaning that ids do not uniquely identify a video. For example, two videos with the same ID are considered as distinct videos with their own viewcount.\n Return a 2D array of strings answer where answer[i] = [creatorsi, idi] means that creatorsi has the highest popularity and idi is the id of their most popular video. The answer can be returned in any order.\n \n Example 1:\n \n >>> mostPopularCreator(creators = [\"alice\",\"bob\",\"alice\",\"chris\"], ids = [\"one\",\"two\",\"three\",\"four\"], views = [5,10,5,4])\n >>> [[\"alice\",\"one\"],[\"bob\",\"two\"]]\n Explanation:\n The popularity of alice is 5 + 5 = 10.\n The popularity of bob is 10.\n The popularity of chris is 4.\n alice and bob are the most popular creators.\n For bob, the video with the highest view count is \"two\".\n For alice, the videos with the highest view count are \"one\" and \"three\". Since \"one\" is lexicographically smaller than \"three\", it is included in the answer.\n \n Example 2:\n \n >>> mostPopularCreator(creators = [\"alice\",\"alice\",\"alice\"], ids = [\"a\",\"b\",\"c\"], views = [1,2,2])\n >>> [[\"alice\",\"b\"]]\n Explanation:\n The videos with id \"b\" and \"c\" have the highest view count.\n Since \"b\" is lexicographically smaller than \"c\", it is included in the answer.\n \"\"\"\n"}
{"task_id": "minimum-addition-to-make-integer-beautiful", "prompt": "def makeIntegerBeautiful(n: int, target: int) -> int:\n \"\"\"\n You are given two positive integers n and target.\n An integer is considered beautiful if the sum of its digits is less than or equal to target.\n Return the minimum non-negative integer x such that n + x is beautiful. The input will be generated such that it is always possible to make n beautiful.\n \n Example 1:\n \n >>> makeIntegerBeautiful(n = 16, target = 6)\n >>> 4\n Explanation: Initially n is 16 and its digit sum is 1 + 6 = 7. After adding 4, n becomes 20 and digit sum becomes 2 + 0 = 2. It can be shown that we can not make n beautiful with adding non-negative integer less than 4.\n \n Example 2:\n \n >>> makeIntegerBeautiful(n = 467, target = 6)\n >>> 33\n Explanation: Initially n is 467 and its digit sum is 4 + 6 + 7 = 17. After adding 33, n becomes 500 and digit sum becomes 5 + 0 + 0 = 5. It can be shown that we can not make n beautiful with adding non-negative integer less than 33.\n \n Example 3:\n \n >>> makeIntegerBeautiful(n = 1, target = 1)\n >>> 0\n Explanation: Initially n is 1 and its digit sum is 1, which is already smaller than or equal to target.\n \"\"\"\n"}
{"task_id": "height-of-binary-tree-after-subtree-removal-queries", "prompt": "# class TreeNode:\n# def __init__(val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def treeQueries(root: Optional[TreeNode], queries: List[int]) -> List[int]:\n \"\"\"\n You are given the root of a binary tree with n nodes. Each node is assigned a unique value from 1 to n. You are also given an array queries of size m.\n You have to perform m independent queries on the tree where in the ith query you do the following:\n \n Remove the subtree rooted at the node with the value queries[i] from the tree. It is guaranteed that queries[i] will not be equal to the value of the root.\n \n Return an array answer of size m where answer[i] is the height of the tree after performing the ith query.\n Note:\n \n The queries are independent, so the tree returns to its initial state after each query.\n The height of a tree is the number of edges in the longest simple path from the root to some node in the tree.\n \n \n Example 1:\n \n \n >>> __init__(root = [1,3,4,2,null,6,5,null,null,null,null,null,7], queries = [4])\n >>> [2]\n Explanation: The diagram above shows the tree after removing the subtree rooted at node with value 4.\n The height of the tree is 2 (The path 1 -> 3 -> 2).\n \n Example 2:\n \n \n >>> __init__(root = [5,8,9,2,1,3,7,4,6], queries = [3,2,4,8])\n >>> [3,2,3,2]\n Explanation: We have the following queries:\n - Removing the subtree rooted at node with value 3. The height of the tree becomes 3 (The path 5 -> 8 -> 2 -> 4).\n - Removing the subtree rooted at node with value 2. The height of the tree becomes 2 (The path 5 -> 8 -> 1).\n - Removing the subtree rooted at node with value 4. The height of the tree becomes 3 (The path 5 -> 8 -> 2 -> 6).\n - Removing the subtree rooted at node with value 8. The height of the tree becomes 2 (The path 5 -> 9 -> 3).\n \"\"\"\n"}
{"task_id": "sort-array-by-moving-items-to-empty-space", "prompt": "def sortArray(nums: List[int]) -> int:\n \"\"\"\n You are given an integer array nums of size n containing each element from 0 to n - 1 (inclusive). Each of the elements from 1 to n - 1 represents an item, and the element 0 represents an empty space.\n In one operation, you can move any item to the empty space. nums is considered to be sorted if the numbers of all the items are in ascending order and the empty space is either at the beginning or at the end of the array.\n For example, if n = 4, nums is sorted if:\n \n nums = [0,1,2,3] or\n nums = [1,2,3,0]\n \n ...and considered to be unsorted otherwise.\n Return the minimum number of operations needed to sort nums.\n \n Example 1:\n \n >>> sortArray(nums = [4,2,0,3,1])\n >>> 3\n Explanation:\n - Move item 2 to the empty space. Now, nums = [4,0,2,3,1].\n - Move item 1 to the empty space. Now, nums = [4,1,2,3,0].\n - Move item 4 to the empty space. Now, nums = [0,1,2,3,4].\n It can be proven that 3 is the minimum number of operations needed.\n \n Example 2:\n \n >>> sortArray(nums = [1,2,3,4,0])\n >>> 0\n Explanation: nums is already sorted so return 0.\n \n Example 3:\n \n >>> sortArray(nums = [1,0,2,4,3])\n >>> 2\n Explanation:\n - Move item 2 to the empty space. Now, nums = [1,2,0,4,3].\n - Move item 3 to the empty space. Now, nums = [1,2,3,4,0].\n It can be proven that 2 is the minimum number of operations needed.\n \"\"\"\n"}
{"task_id": "apply-operations-to-an-array", "prompt": "def applyOperations(nums: List[int]) -> List[int]:\n \"\"\"\n You are given a 0-indexed array nums of size n consisting of non-negative integers.\n You need to apply n - 1 operations to this array where, in the ith operation (0-indexed), you will apply the following on the ith element of nums:\n \n If nums[i] == nums[i + 1], then multiply nums[i] by 2 and set nums[i + 1] to 0. Otherwise, you skip this operation.\n \n After performing all the operations, shift all the 0's to the end of the array.\n \n For example, the array [1,0,2,0,0,1] after shifting all its 0's to the end, is [1,2,1,0,0,0].\n \n Return the resulting array.\n Note that the operations are applied sequentially, not all at once.\n \n Example 1:\n \n >>> applyOperations(nums = [1,2,2,1,1,0])\n >>> [1,4,2,0,0,0]\n Explanation: We do the following operations:\n - i = 0: nums[0] and nums[1] are not equal, so we skip this operation.\n - i = 1: nums[1] and nums[2] are equal, we multiply nums[1] by 2 and change nums[2] to 0. The array becomes [1,4,0,1,1,0].\n - i = 2: nums[2] and nums[3] are not equal, so we skip this operation.\n - i = 3: nums[3] and nums[4] are equal, we multiply nums[3] by 2 and change nums[4] to 0. The array becomes [1,4,0,2,0,0].\n - i = 4: nums[4] and nums[5] are equal, we multiply nums[4] by 2 and change nums[5] to 0. The array becomes [1,4,0,2,0,0].\n After that, we shift the 0's to the end, which gives the array [1,4,2,0,0,0].\n \n Example 2:\n \n >>> applyOperations(nums = [0,1])\n >>> [1,0]\n Explanation: No operation can be applied, we just shift the 0 to the end.\n \"\"\"\n"}
{"task_id": "maximum-sum-of-distinct-subarrays-with-length-k", "prompt": "def maximumSubarraySum(nums: List[int], k: int) -> int:\n \"\"\"\n You are given an integer array nums and an integer k. Find the maximum subarray sum of all the subarrays of nums that meet the following conditions:\n \n The length of the subarray is k, and\n All the elements of the subarray are distinct.\n \n Return the maximum subarray sum of all the subarrays that meet the conditions. If no subarray meets the conditions, return 0.\n A subarray is a contiguous non-empty sequence of elements within an array.\n \n Example 1:\n \n >>> maximumSubarraySum(nums = [1,5,4,2,9,9,9], k = 3)\n >>> 15\n Explanation: The subarrays of nums with length 3 are:\n - [1,5,4] which meets the requirements and has a sum of 10.\n - [5,4,2] which meets the requirements and has a sum of 11.\n - [4,2,9] which meets the requirements and has a sum of 15.\n - [2,9,9] which does not meet the requirements because the element 9 is repeated.\n - [9,9,9] which does not meet the requirements because the element 9 is repeated.\n We return 15 because it is the maximum subarray sum of all the subarrays that meet the conditions\n \n Example 2:\n \n >>> maximumSubarraySum(nums = [4,4,4], k = 3)\n >>> 0\n Explanation: The subarrays of nums with length 3 are:\n - [4,4,4] which does not meet the requirements because the element 4 is repeated.\n We return 0 because no subarrays meet the conditions.\n \"\"\"\n"}
{"task_id": "total-cost-to-hire-k-workers", "prompt": "def totalCost(costs: List[int], k: int, candidates: int) -> int:\n \"\"\"\n You are given a 0-indexed integer array costs where costs[i] is the cost of hiring the ith worker.\n You are also given two integers k and candidates. We want to hire exactly k workers according to the following rules:\n \n You will run k sessions and hire exactly one worker in each session.\n In each hiring session, choose the worker with the lowest cost from either the first candidates workers or the last candidates workers. Break the tie by the smallest index.\n \n For example, if costs = [3,2,7,7,1,2] and candidates = 2, then in the first hiring session, we will choose the 4th worker because they have the lowest cost [3,2,7,7,1,2].\n In the second hiring session, we will choose 1st worker because they have the same lowest cost as 4th worker but they have the smallest index [3,2,7,7,2]. Please note that the indexing may be changed in the process.\n \n \n If there are fewer than candidates workers remaining, choose the worker with the lowest cost among them. Break the tie by the smallest index.\n A worker can only be chosen once.\n \n Return the total cost to hire exactly k workers.\n \n Example 1:\n \n >>> totalCost(costs = [17,12,10,2,7,2,11,20,8], k = 3, candidates = 4)\n >>> 11\n Explanation: We hire 3 workers in total. The total cost is initially 0.\n - In the first hiring round we choose the worker from [17,12,10,2,7,2,11,20,8]. The lowest cost is 2, and we break the tie by the smallest index, which is 3. The total cost = 0 + 2 = 2.\n - In the second hiring round we choose the worker from [17,12,10,7,2,11,20,8]. The lowest cost is 2 (index 4). The total cost = 2 + 2 = 4.\n - In the third hiring round we choose the worker from [17,12,10,7,11,20,8]. The lowest cost is 7 (index 3). The total cost = 4 + 7 = 11. Notice that the worker with index 3 was common in the first and last four workers.\n The total hiring cost is 11.\n \n Example 2:\n \n >>> totalCost(costs = [1,2,4,1], k = 3, candidates = 3)\n >>> 4\n Explanation: We hire 3 workers in total. The total cost is initially 0.\n - In the first hiring round we choose the worker from [1,2,4,1]. The lowest cost is 1, and we break the tie by the smallest index, which is 0. The total cost = 0 + 1 = 1. Notice that workers with index 1 and 2 are common in the first and last 3 workers.\n - In the second hiring round we choose the worker from [2,4,1]. The lowest cost is 1 (index 2). The total cost = 1 + 1 = 2.\n - In the third hiring round there are less than three candidates. We choose the worker from the remaining workers [2,4]. The lowest cost is 2 (index 0). The total cost = 2 + 2 = 4.\n The total hiring cost is 4.\n \"\"\"\n"}
{"task_id": "minimum-total-distance-traveled", "prompt": "def minimumTotalDistance(robot: List[int], factory: List[List[int]]) -> int:\n \"\"\"\n There are some robots and factories on the X-axis. You are given an integer array robot where robot[i] is the position of the ith robot. You are also given a 2D integer array factory where factory[j] = [positionj, limitj] indicates that positionj is the position of the jth factory and that the jth factory can repair at most limitj robots.\n The positions of each robot are unique. The positions of each factory are also unique. Note that a robot can be in the same position as a factory initially.\n All the robots are initially broken; they keep moving in one direction. The direction could be the negative or the positive direction of the X-axis. When a robot reaches a factory that did not reach its limit, the factory repairs the robot, and it stops moving.\n At any moment, you can set the initial direction of moving for some robot. Your target is to minimize the total distance traveled by all the robots.\n Return the minimum total distance traveled by all the robots. The test cases are generated such that all the robots can be repaired.\n Note that\n \n All robots move at the same speed.\n If two robots move in the same direction, they will never collide.\n If two robots move in opposite directions and they meet at some point, they do not collide. They cross each other.\n If a robot passes by a factory that reached its limits, it crosses it as if it does not exist.\n If the robot moved from a position x to a position y, the distance it moved is |y - x|.\n \n \n Example 1:\n \n \n >>> minimumTotalDistance(robot = [0,4,6], factory = [[2,2],[6,2]])\n >>> 4\n Explanation: As shown in the figure:\n - The first robot at position 0 moves in the positive direction. It will be repaired at the first factory.\n - The second robot at position 4 moves in the negative direction. It will be repaired at the first factory.\n - The third robot at position 6 will be repaired at the second factory. It does not need to move.\n The limit of the first factory is 2, and it fixed 2 robots.\n The limit of the second factory is 2, and it fixed 1 robot.\n The total distance is |2 - 0| + |2 - 4| + |6 - 6| = 4. It can be shown that we cannot achieve a better total distance than 4.\n \n Example 2:\n \n \n >>> minimumTotalDistance(robot = [1,-1], factory = [[-2,1],[2,1]])\n >>> 2\n Explanation: As shown in the figure:\n - The first robot at position 1 moves in the positive direction. It will be repaired at the second factory.\n - The second robot at position -1 moves in the negative direction. It will be repaired at the first factory.\n The limit of the first factory is 1, and it fixed 1 robot.\n The limit of the second factory is 1, and it fixed 1 robot.\n The total distance is |2 - 1| + |(-2) - (-1)| = 2. It can be shown that we cannot achieve a better total distance than 2.\n \"\"\"\n"}
{"task_id": "minimum-subarrays-in-a-valid-split", "prompt": "def validSubarraySplit(nums: List[int]) -> int:\n \"\"\"\n You are given an integer array nums.\n Splitting of an integer array nums into subarrays is valid if:\n \n the greatest common divisor of the first and last elements of each subarray is greater than 1, and\n each element of nums belongs to exactly one subarray.\n \n Return the minimum number of subarrays in a valid subarray splitting of nums. If a valid subarray splitting is not possible, return -1.\n Note that:\n \n The greatest common divisor of two numbers is the largest positive integer that evenly divides both numbers.\n A subarray is a contiguous non-empty part of an array.\n \n \n Example 1:\n \n >>> validSubarraySplit(nums = [2,6,3,4,3])\n >>> 2\n Explanation: We can create a valid split in the following way: [2,6] | [3,4,3].\n - The starting element of the 1st subarray is 2 and the ending is 6. Their greatest common divisor is 2, which is greater than 1.\n - The starting element of the 2nd subarray is 3 and the ending is 3. Their greatest common divisor is 3, which is greater than 1.\n It can be proved that 2 is the minimum number of subarrays that we can obtain in a valid split.\n \n Example 2:\n \n >>> validSubarraySplit(nums = [3,5])\n >>> 2\n Explanation: We can create a valid split in the following way: [3] | [5].\n - The starting element of the 1st subarray is 3 and the ending is 3. Their greatest common divisor is 3, which is greater than 1.\n - The starting element of the 2nd subarray is 5 and the ending is 5. Their greatest common divisor is 5, which is greater than 1.\n It can be proved that 2 is the minimum number of subarrays that we can obtain in a valid split.\n \n Example 3:\n \n >>> validSubarraySplit(nums = [1,2,1])\n >>> -1\n Explanation: It is impossible to create valid split.\n \"\"\"\n"}
{"task_id": "number-of-distinct-averages", "prompt": "def distinctAverages(nums: List[int]) -> int:\n \"\"\"\n You are given a 0-indexed integer array nums of even length.\n As long as nums is not empty, you must repetitively:\n \n Find the minimum number in nums and remove it.\n Find the maximum number in nums and remove it.\n Calculate the average of the two removed numbers.\n \n The average of two numbers a and b is (a + b) / 2.\n \n For example, the average of 2 and 3 is (2 + 3) / 2 = 2.5.\n \n Return the number of distinct averages calculated using the above process.\n Note that when there is a tie for a minimum or maximum number, any can be removed.\n \n Example 1:\n \n >>> distinctAverages(nums = [4,1,4,0,3,5])\n >>> 2\n Explanation:\n 1. Remove 0 and 5, and the average is (0 + 5) / 2 = 2.5. Now, nums = [4,1,4,3].\n 2. Remove 1 and 4. The average is (1 + 4) / 2 = 2.5, and nums = [4,3].\n 3. Remove 3 and 4, and the average is (3 + 4) / 2 = 3.5.\n Since there are 2 distinct numbers among 2.5, 2.5, and 3.5, we return 2.\n \n Example 2:\n \n >>> distinctAverages(nums = [1,100])\n >>> 1\n Explanation:\n There is only one average to be calculated after removing 1 and 100, so we return 1.\n \"\"\"\n"}
{"task_id": "count-ways-to-build-good-strings", "prompt": "def countGoodStrings(low: int, high: int, zero: int, one: int) -> int:\n \"\"\"\n Given the integers zero, one, low, and high, we can construct a string by starting with an empty string, and then at each step perform either of the following:\n \n Append the character '0' zero times.\n Append the character '1' one times.\n \n This can be performed any number of times.\n A good string is a string constructed by the above process having a length between low and high (inclusive).\n Return the number of different good strings that can be constructed satisfying these properties. Since the answer can be large, return it modulo 109 + 7.\n \n Example 1:\n \n >>> countGoodStrings(low = 3, high = 3, zero = 1, one = 1)\n >>> 8\n Explanation:\n One possible valid good string is \"011\".\n It can be constructed as follows: \"\" -> \"0\" -> \"01\" -> \"011\".\n All binary strings from \"000\" to \"111\" are good strings in this example.\n \n Example 2:\n \n >>> countGoodStrings(low = 2, high = 3, zero = 1, one = 2)\n >>> 5\n Explanation: The good strings are \"00\", \"11\", \"000\", \"110\", and \"011\".\n \"\"\"\n"}
{"task_id": "most-profitable-path-in-a-tree", "prompt": "def mostProfitablePath(edges: List[List[int]], bob: int, amount: List[int]) -> int:\n \"\"\"\n There is an undirected tree with n nodes labeled from 0 to n - 1, rooted at node 0. You are given a 2D integer array edges of length n - 1 where edges[i] = [ai, bi] indicates that there is an edge between nodes ai and bi in the tree.\n At every node i, there is a gate. You are also given an array of even integers amount, where amount[i] represents:\n \n the price needed to open the gate at node i, if amount[i] is negative, or,\n the cash reward obtained on opening the gate at node i, otherwise.\n \n The game goes on as follows:\n \n Initially, Alice is at node 0 and Bob is at node bob.\n At every second, Alice and Bob each move to an adjacent node. Alice moves towards some leaf node, while Bob moves towards node 0.\n For every node along their path, Alice and Bob either spend money to open the gate at that node, or accept the reward. Note that:\n \n If the gate is already open, no price will be required, nor will there be any cash reward.\n If Alice and Bob reach the node simultaneously, they share the price/reward for opening the gate there. In other words, if the price to open the gate is c, then both Alice and Bob pay\u00a0c / 2 each. Similarly, if the reward at the gate is c, both of them receive c / 2 each.\n \n \n If Alice reaches a leaf node, she stops moving. Similarly, if Bob reaches node 0, he stops moving. Note that these events are independent of each other.\n \n Return the maximum net income Alice can have if she travels towards the optimal leaf node.\n \n Example 1:\n \n \n >>> mostProfitablePath(edges = [[0,1],[1,2],[1,3],[3,4]], bob = 3, amount = [-2,4,2,-4,6])\n >>> 6\n Explanation:\n The above diagram represents the given tree. The game goes as follows:\n - Alice is initially on node 0, Bob on node 3. They open the gates of their respective nodes.\n Alice's net income is now -2.\n - Both Alice and Bob move to node 1.\n \u00a0 Since they reach here simultaneously, they open the gate together and share the reward.\n \u00a0 Alice's net income becomes -2 + (4 / 2) = 0.\n - Alice moves on to node 3. Since Bob already opened its gate, Alice's income remains unchanged.\n \u00a0 Bob moves on to node 0, and stops moving.\n - Alice moves on to node 4 and opens the gate there. Her net income becomes 0 + 6 = 6.\n Now, neither Alice nor Bob can make any further moves, and the game ends.\n It is not possible for Alice to get a higher net income.\n \n Example 2:\n \n \n >>> mostProfitablePath(edges = [[0,1]], bob = 1, amount = [-7280,2350])\n >>> -7280\n Explanation:\n Alice follows the path 0->1 whereas Bob follows the path 1->0.\n Thus, Alice opens the gate at node 0 only. Hence, her net income is -7280.\n \"\"\"\n"}
{"task_id": "split-message-based-on-limit", "prompt": "def splitMessage(message: str, limit: int) -> List[str]:\n \"\"\"\n You are given a string, message, and a positive integer, limit.\n You must split message into one or more parts based on limit. Each resulting part should have the suffix \"\", where \"b\" is to be replaced with the total number of parts and \"a\" is to be replaced with the index of the part, starting from 1 and going up to b. Additionally, the length of each resulting part (including its suffix) should be equal to limit, except for the last part whose length can be at most limit.\n The resulting parts should be formed such that when their suffixes are removed and they are all concatenated in order, they should be equal to message. Also, the result should contain as few parts as possible.\n Return the parts message would be split into as an array of strings. If it is impossible to split message as required, return an empty array.\n \n Example 1:\n \n >>> splitMessage(message = \"this is really a very awesome message\", limit = 9)\n >>> [\"thi<1/14>\",\"s i<2/14>\",\"s r<3/14>\",\"eal<4/14>\",\"ly <5/14>\",\"a v<6/14>\",\"ery<7/14>\",\" aw<8/14>\",\"eso<9/14>\",\"me<10/14>\",\" m<11/14>\",\"es<12/14>\",\"sa<13/14>\",\"ge<14/14>\"]\n Explanation:\n The first 9 parts take 3 characters each from the beginning of message.\n The next 5 parts take 2 characters each to finish splitting message.\n In this example, each part, including the last, has length 9.\n It can be shown it is not possible to split message into less than 14 parts.\n \n Example 2:\n \n >>> splitMessage(message = \"short message\", limit = 15)\n >>> [\"short mess<1/2>\",\"age<2/2>\"]\n Explanation:\n Under the given constraints, the string can be split into two parts:\n - The first part comprises of the first 10 characters, and has a length 15.\n - The next part comprises of the last 3 characters, and has a length 8.\n \"\"\"\n"}
{"task_id": "convert-the-temperature", "prompt": "def convertTemperature(celsius: float) -> List[float]:\n \"\"\"\n You are given a non-negative floating point number rounded to two decimal places celsius, that denotes the temperature in Celsius.\n You should convert Celsius into Kelvin and Fahrenheit and return it as an array ans = [kelvin, fahrenheit].\n Return the array ans. Answers within 10-5 of the actual answer will be accepted.\n Note that:\n \n Kelvin = Celsius + 273.15\n Fahrenheit = Celsius * 1.80 + 32.00\n \n \n Example 1:\n \n >>> convertTemperature(celsius = 36.50)\n >>> [309.65000,97.70000]\n Explanation: Temperature at 36.50 Celsius converted in Kelvin is 309.65 and converted in Fahrenheit is 97.70.\n \n Example 2:\n \n >>> convertTemperature(celsius = 122.11)\n >>> [395.26000,251.79800]\n Explanation: Temperature at 122.11 Celsius converted in Kelvin is 395.26 and converted in Fahrenheit is 251.798.\n \"\"\"\n"}
{"task_id": "number-of-subarrays-with-lcm-equal-to-k", "prompt": "def subarrayLCM(nums: List[int], k: int) -> int:\n \"\"\"\n Given an integer array nums and an integer k, return the number of subarrays of nums where the least common multiple of the subarray's elements is k.\n A subarray is a contiguous non-empty sequence of elements within an array.\n The least common multiple of an array is the smallest positive integer that is divisible by all the array elements.\n \n Example 1:\n \n >>> subarrayLCM(nums = [3,6,2,7,1], k = 6)\n >>> 4\n Explanation: The subarrays of nums where 6 is the least common multiple of all the subarray's elements are:\n - [3,6,2,7,1]\n - [3,6,2,7,1]\n - [3,6,2,7,1]\n - [3,6,2,7,1]\n \n Example 2:\n \n >>> subarrayLCM(nums = [3], k = 2)\n >>> 0\n Explanation: There are no subarrays of nums where 2 is the least common multiple of all the subarray's elements.\n \"\"\"\n"}
{"task_id": "minimum-number-of-operations-to-sort-a-binary-tree-by-level", "prompt": "# class TreeNode:\n# def __init__(val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def minimumOperations(root: Optional[TreeNode]) -> int:\n \"\"\"\n You are given the root of a binary tree with unique values.\n In one operation, you can choose any two nodes at the same level and swap their values.\n Return the minimum number of operations needed to make the values at each level sorted in a strictly increasing order.\n The level of a node is the number of edges along the path between it and the root node.\n \n Example 1:\n \n \n >>> __init__(root = [1,4,3,7,6,8,5,null,null,null,null,9,null,10])\n >>> 3\n Explanation:\n - Swap 4 and 3. The 2nd level becomes [3,4].\n - Swap 7 and 5. The 3rd level becomes [5,6,8,7].\n - Swap 8 and 7. The 3rd level becomes [5,6,7,8].\n We used 3 operations so return 3.\n It can be proven that 3 is the minimum number of operations needed.\n \n Example 2:\n \n \n >>> __init__(root = [1,3,2,7,6,5,4])\n >>> 3\n Explanation:\n - Swap 3 and 2. The 2nd level becomes [2,3].\n - Swap 7 and 4. The 3rd level becomes [4,6,5,7].\n - Swap 6 and 5. The 3rd level becomes [4,5,6,7].\n We used 3 operations so return 3.\n It can be proven that 3 is the minimum number of operations needed.\n \n Example 3:\n \n \n >>> __init__(root = [1,2,3,4,5,6])\n >>> 0\n Explanation: Each level is already sorted in increasing order so return 0.\n \"\"\"\n"}
{"task_id": "maximum-number-of-non-overlapping-palindrome-substrings", "prompt": "def maxPalindromes(s: str, k: int) -> int:\n \"\"\"\n You are given a string s and a positive integer k.\n Select a set of non-overlapping substrings from the string s that satisfy the following conditions:\n \n The length of each substring is at least k.\n Each substring is a palindrome.\n \n Return the maximum number of substrings in an optimal selection.\n A substring is a contiguous sequence of characters within a string.\n \n Example 1:\n \n >>> maxPalindromes(s = \"abaccdbbd\", k = 3)\n >>> 2\n Explanation: We can select the substrings underlined in s = \"abaccdbbd\". Both \"aba\" and \"dbbd\" are palindromes and have a length of at least k = 3.\n It can be shown that we cannot find a selection with more than two valid substrings.\n \n Example 2:\n \n >>> maxPalindromes(s = \"adbcda\", k = 2)\n >>> 0\n Explanation: There is no palindrome substring of length at least 2 in the string.\n \"\"\"\n"}
{"task_id": "minimum-cost-to-buy-apples", "prompt": "def minCost(n: int, roads: List[List[int]], appleCost: List[int], k: int) -> List[int]:\n \"\"\"\n You are given a positive integer n representing n cities numbered from 1 to n. You are also given a 2D array roads, where roads[i] = [ai, bi, costi] indicates that there is a bidirectional road between cities ai and bi with a cost of traveling equal to costi.\n You can buy apples in any city you want, but some cities have different costs to buy apples. You are given the 1-based array appleCost where appleCost[i] is the cost of buying one apple from city i.\n You start at some city, traverse through various roads, and eventually buy exactly one apple from any city. After you buy that apple, you have to return back to the city you started at, but now the cost of all the roads will be multiplied by a given factor k.\n Given the integer k, return a 1-based array answer of size n where answer[i] is the minimum total cost to buy an apple if you start at city i.\n \n Example 1:\n \n \n >>> minCost(n = 4, roads = [[1,2,4],[2,3,2],[2,4,5],[3,4,1],[1,3,4]], appleCost = [56,42,102,301], k = 2)\n >>> [54,42,48,51]\n Explanation: The minimum cost for each starting city is the following:\n - Starting at city 1: You take the path 1 -> 2, buy an apple at city 2, and finally take the path 2 -> 1. The total cost is 4 + 42 + 4 * 2 = 54.\n - Starting at city 2: You directly buy an apple at city 2. The total cost is 42.\n - Starting at city 3: You take the path 3 -> 2, buy an apple at city 2, and finally take the path 2 -> 3. The total cost is 2 + 42 + 2 * 2 = 48.\n - Starting at city 4: You take the path 4 -> 3 -> 2 then you buy at city 2, and finally take the path 2 -> 3 -> 4. The total cost is 1 + 2 + 42 + 1 * 2 + 2 * 2 = 51.\n \n Example 2:\n \n \n >>> minCost(n = 3, roads = [[1,2,5],[2,3,1],[3,1,2]], appleCost = [2,3,1], k = 3)\n >>> [2,3,1]\n Explanation: It is always optimal to buy the apple in the starting city.\n \"\"\"\n"}
{"task_id": "number-of-unequal-triplets-in-array", "prompt": "def unequalTriplets(nums: List[int]) -> int:\n \"\"\"\n You are given a 0-indexed array of positive integers nums. Find the number of triplets (i, j, k) that meet the following conditions:\n \n 0 <= i < j < k < nums.length\n nums[i], nums[j], and nums[k] are pairwise distinct.\n \n In other words, nums[i] != nums[j], nums[i] != nums[k], and nums[j] != nums[k].\n \n \n \n Return the number of triplets that meet the conditions.\n \n Example 1:\n \n >>> unequalTriplets(nums = [4,4,2,4,3])\n >>> 3\n Explanation: The following triplets meet the conditions:\n - (0, 2, 4) because 4 != 2 != 3\n - (1, 2, 4) because 4 != 2 != 3\n - (2, 3, 4) because 2 != 4 != 3\n Since there are 3 triplets, we return 3.\n Note that (2, 0, 4) is not a valid triplet because 2 > 0.\n \n Example 2:\n \n >>> unequalTriplets(nums = [1,1,1,1,1])\n >>> 0\n Explanation: No triplets meet the conditions so we return 0.\n \"\"\"\n"}
{"task_id": "closest-nodes-queries-in-a-binary-search-tree", "prompt": "# class TreeNode:\n# def __init__(val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def closestNodes(root: Optional[TreeNode], queries: List[int]) -> List[List[int]]:\n \"\"\"\n You are given the root of a binary search tree and an array queries of size n consisting of positive integers.\n Find a 2D array answer of size n where answer[i] = [mini, maxi]:\n \n mini is the largest value in the tree that is smaller than or equal to queries[i]. If a such value does not exist, add -1 instead.\n maxi is the smallest value in the tree that is greater than or equal to queries[i]. If a such value does not exist, add -1 instead.\n \n Return the array answer.\n \n Example 1:\n \n \n >>> __init__(root = [6,2,13,1,4,9,15,null,null,null,null,null,null,14], queries = [2,5,16])\n >>> [[2,2],[4,6],[15,-1]]\n Explanation: We answer the queries in the following way:\n - The largest number that is smaller or equal than 2 in the tree is 2, and the smallest number that is greater or equal than 2 is still 2. So the answer for the first query is [2,2].\n - The largest number that is smaller or equal than 5 in the tree is 4, and the smallest number that is greater or equal than 5 is 6. So the answer for the second query is [4,6].\n - The largest number that is smaller or equal than 16 in the tree is 15, and the smallest number that is greater or equal than 16 does not exist. So the answer for the third query is [15,-1].\n \n Example 2:\n \n \n >>> __init__(root = [4,null,9], queries = [3])\n >>> [[-1,4]]\n Explanation: The largest number that is smaller or equal to 3 in the tree does not exist, and the smallest number that is greater or equal to 3 is 4. So the answer for the query is [-1,4].\n \"\"\"\n"}
{"task_id": "minimum-fuel-cost-to-report-to-the-capital", "prompt": "def minimumFuelCost(roads: List[List[int]], seats: int) -> int:\n \"\"\"\n There is a tree (i.e., a connected, undirected graph with no cycles) structure country network consisting of n cities numbered from 0 to n - 1 and exactly n - 1 roads. The capital city is city 0. You are given a 2D integer array roads where roads[i] = [ai, bi] denotes that there exists a bidirectional road connecting cities ai and bi.\n There is a meeting for the representatives of each city. The meeting is in the capital city.\n There is a car in each city. You are given an integer seats that indicates the number of seats in each car.\n A representative can use the car in their city to travel or change the car and ride with another representative. The cost of traveling between two cities is one liter of fuel.\n Return the minimum number of liters of fuel to reach the capital city.\n \n Example 1:\n \n \n >>> minimumFuelCost(roads = [[0,1],[0,2],[0,3]], seats = 5)\n >>> 3\n Explanation:\n - Representative1 goes directly to the capital with 1 liter of fuel.\n - Representative2 goes directly to the capital with 1 liter of fuel.\n - Representative3 goes directly to the capital with 1 liter of fuel.\n It costs 3 liters of fuel at minimum.\n It can be proven that 3 is the minimum number of liters of fuel needed.\n \n Example 2:\n \n \n >>> minimumFuelCost(roads = [[3,1],[3,2],[1,0],[0,4],[0,5],[4,6]], seats = 2)\n >>> 7\n Explanation:\n - Representative2 goes directly to city 3 with 1 liter of fuel.\n - Representative2 and representative3 go together to city 1 with 1 liter of fuel.\n - Representative2 and representative3 go together to the capital with 1 liter of fuel.\n - Representative1 goes directly to the capital with 1 liter of fuel.\n - Representative5 goes directly to the capital with 1 liter of fuel.\n - Representative6 goes directly to city 4 with 1 liter of fuel.\n - Representative4 and representative6 go together to the capital with 1 liter of fuel.\n It costs 7 liters of fuel at minimum.\n It can be proven that 7 is the minimum number of liters of fuel needed.\n \n Example 3:\n \n \n >>> minimumFuelCost(roads = [], seats = 1)\n >>> 0\n Explanation: No representatives need to travel to the capital city.\n \"\"\"\n"}
{"task_id": "number-of-beautiful-partitions", "prompt": "def beautifulPartitions(s: str, k: int, minLength: int) -> int:\n \"\"\"\n You are given a string s that consists of the digits '1' to '9' and two integers k and minLength.\n A partition of s is called beautiful if:\n \n s is partitioned into k non-intersecting substrings.\n Each substring has a length of at least minLength.\n Each substring starts with a prime digit and ends with a non-prime digit. Prime digits are '2', '3', '5', and '7', and the rest of the digits are non-prime.\n \n Return the number of beautiful partitions of s. Since the answer may be very large, return it modulo 109 + 7.\n A substring is a contiguous sequence of characters within a string.\n \n Example 1:\n \n >>> beautifulPartitions(s = \"23542185131\", k = 3, minLength = 2)\n >>> 3\n Explanation: There exists three ways to create a beautiful partition:\n \"2354 | 218 | 5131\"\n \"2354 | 21851 | 31\"\n \"2354218 | 51 | 31\"\n \n Example 2:\n \n >>> beautifulPartitions(s = \"23542185131\", k = 3, minLength = 3)\n >>> 1\n Explanation: There exists one way to create a beautiful partition: \"2354 | 218 | 5131\".\n \n Example 3:\n \n >>> beautifulPartitions(s = \"3312958\", k = 3, minLength = 1)\n >>> 1\n Explanation: There exists one way to create a beautiful partition: \"331 | 29 | 58\".\n \"\"\"\n"}
{"task_id": "maximum-xor-of-two-non-overlapping-subtrees", "prompt": "def maxXor(n: int, edges: List[List[int]], values: List[int]) -> int:\n \"\"\"\n There is an undirected tree with n nodes labeled from 0 to n - 1. You are given the integer n and a 2D integer array edges of length n - 1, where edges[i] = [ai, bi] indicates that there is an edge between nodes ai and bi in the tree. The root of the tree is the node labeled 0.\n Each node has an associated value. You are given an array values of length n, where values[i] is the value of the ith node.\n Select any two non-overlapping subtrees. Your score is the bitwise XOR of the sum of the values within those subtrees.\n Return the maximum possible score you can achieve. If it is impossible to find two nonoverlapping subtrees, return 0.\n Note that:\n \n The subtree of a node is the tree consisting of that node and all of its descendants.\n Two subtrees are non-overlapping if they do not share any common node.\n \n \n Example 1:\n \n \n >>> maxXor(n = 6, edges = [[0,1],[0,2],[1,3],[1,4],[2,5]], values = [2,8,3,6,2,5])\n >>> 24\n Explanation: Node 1's subtree has sum of values 16, while node 2's subtree has sum of values 8, so choosing these nodes will yield a score of 16 XOR 8 = 24. It can be proved that is the maximum possible score we can obtain.\n \n Example 2:\n \n \n >>> maxXor(n = 3, edges = [[0,1],[1,2]], values = [4,6,1])\n >>> 0\n Explanation: There is no possible way to select two non-overlapping subtrees, so we just return 0.\n \"\"\"\n"}
{"task_id": "minimum-cuts-to-divide-a-circle", "prompt": "def numberOfCuts(n: int) -> int:\n \"\"\"\n A valid cut in a circle can be:\n \n A cut that is represented by a straight line that touches two points on the edge of the circle and passes through its center, or\n A cut that is represented by a straight line that touches one point on the edge of the circle and its center.\n \n Some valid and invalid cuts are shown in the figures below.\n \n Given the integer n, return the minimum number of cuts needed to divide a circle into n equal slices.\n \n Example 1:\n \n \n >>> numberOfCuts(n = 4)\n >>> 2\n Explanation:\n The above figure shows how cutting the circle twice through the middle divides it into 4 equal slices.\n \n Example 2:\n \n \n >>> numberOfCuts(n = 3)\n >>> 3\n Explanation:\n At least 3 cuts are needed to divide the circle into 3 equal slices.\n It can be shown that less than 3 cuts cannot result in 3 slices of equal size and shape.\n Also note that the first cut will not divide the circle into distinct parts.\n \"\"\"\n"}
{"task_id": "difference-between-ones-and-zeros-in-row-and-column", "prompt": "def onesMinusZeros(grid: List[List[int]]) -> List[List[int]]:\n \"\"\"\n You are given a 0-indexed m x n binary matrix grid.\n A 0-indexed m x n difference matrix diff is created with the following procedure:\n \n Let the number of ones in the ith row be onesRowi.\n Let the number of ones in the jth column be onesColj.\n Let the number of zeros in the ith row be zerosRowi.\n Let the number of zeros in the jth column be zerosColj.\n diff[i][j] = onesRowi + onesColj - zerosRowi - zerosColj\n \n Return the difference matrix diff.\n \n Example 1:\n \n \n >>> onesMinusZeros(grid = [[0,1,1],[1,0,1],[0,0,1]])\n >>> [[0,0,4],[0,0,4],[-2,-2,2]]\n Explanation:\n - diff[0][0] = onesRow0 + onesCol0 - zerosRow0 - zerosCol0 = 2 + 1 - 1 - 2 = 0\n - diff[0][1] = onesRow0 + onesCol1 - zerosRow0 - zerosCol1 = 2 + 1 - 1 - 2 = 0\n - diff[0][2] = onesRow0 + onesCol2 - zerosRow0 - zerosCol2 = 2 + 3 - 1 - 0 = 4\n - diff[1][0] = onesRow1 + onesCol0 - zerosRow1 - zerosCol0 = 2 + 1 - 1 - 2 = 0\n - diff[1][1] = onesRow1 + onesCol1 - zerosRow1 - zerosCol1 = 2 + 1 - 1 - 2 = 0\n - diff[1][2] = onesRow1 + onesCol2 - zerosRow1 - zerosCol2 = 2 + 3 - 1 - 0 = 4\n - diff[2][0] = onesRow2 + onesCol0 - zerosRow2 - zerosCol0 = 1 + 1 - 2 - 2 = -2\n - diff[2][1] = onesRow2 + onesCol1 - zerosRow2 - zerosCol1 = 1 + 1 - 2 - 2 = -2\n - diff[2][2] = onesRow2 + onesCol2 - zerosRow2 - zerosCol2 = 1 + 3 - 2 - 0 = 2\n \n Example 2:\n \n \n >>> onesMinusZeros(grid = [[1,1,1],[1,1,1]])\n >>> [[5,5,5],[5,5,5]]\n Explanation:\n - diff[0][0] = onesRow0 + onesCol0 - zerosRow0 - zerosCol0 = 3 + 2 - 0 - 0 = 5\n - diff[0][1] = onesRow0 + onesCol1 - zerosRow0 - zerosCol1 = 3 + 2 - 0 - 0 = 5\n - diff[0][2] = onesRow0 + onesCol2 - zerosRow0 - zerosCol2 = 3 + 2 - 0 - 0 = 5\n - diff[1][0] = onesRow1 + onesCol0 - zerosRow1 - zerosCol0 = 3 + 2 - 0 - 0 = 5\n - diff[1][1] = onesRow1 + onesCol1 - zerosRow1 - zerosCol1 = 3 + 2 - 0 - 0 = 5\n - diff[1][2] = onesRow1 + onesCol2 - zerosRow1 - zerosCol2 = 3 + 2 - 0 - 0 = 5\n \"\"\"\n"}
{"task_id": "minimum-penalty-for-a-shop", "prompt": "def bestClosingTime(customers: str) -> int:\n \"\"\"\n You are given the customer visit log of a shop represented by a 0-indexed string customers consisting only of characters 'N' and 'Y':\n \n if the ith character is 'Y', it means that customers come at the ith hour\n whereas 'N' indicates that no customers come at the ith hour.\n \n If the shop closes at the jth hour (0 <= j <= n), the penalty is calculated as follows:\n \n For every hour when the shop is open and no customers come, the penalty increases by 1.\n For every hour when the shop is closed and customers come, the penalty increases by 1.\n \n Return the earliest hour at which the shop must be closed to incur a minimum penalty.\n Note that if a shop closes at the jth hour, it means the shop is closed at the hour j.\n \n Example 1:\n \n >>> bestClosingTime(customers = \"YYNY\")\n >>> 2\n Explanation:\n - Closing the shop at the 0th hour incurs in 1+1+0+1 = 3 penalty.\n - Closing the shop at the 1st hour incurs in 0+1+0+1 = 2 penalty.\n - Closing the shop at the 2nd hour incurs in 0+0+0+1 = 1 penalty.\n - Closing the shop at the 3rd hour incurs in 0+0+1+1 = 2 penalty.\n - Closing the shop at the 4th hour incurs in 0+0+1+0 = 1 penalty.\n Closing the shop at 2nd or 4th hour gives a minimum penalty. Since 2 is earlier, the optimal closing time is 2.\n \n Example 2:\n \n >>> bestClosingTime(customers = \"NNNNN\")\n >>> 0\n Explanation: It is best to close the shop at the 0th hour as no customers arrive.\n Example 3:\n \n >>> bestClosingTime(customers = \"YYYY\")\n >>> 4\n Explanation: It is best to close the shop at the 4th hour as customers arrive at each hour.\n \"\"\"\n"}
{"task_id": "count-palindromic-subsequences", "prompt": "def countPalindromes(s: str) -> int:\n \"\"\"\n Given a string of digits s, return the number of palindromic subsequences of s having length 5. Since the answer may be very large, return it modulo 109 + 7.\n Note:\n \n A string is palindromic if it reads the same forward and backward.\n A subsequence is a string that can be derived from another string by deleting some or no characters without changing the order of the remaining characters.\n \n \n Example 1:\n \n >>> countPalindromes(s = \"103301\")\n >>> 2\n Explanation:\n There are 6 possible subsequences of length 5: \"10330\",\"10331\",\"10301\",\"10301\",\"13301\",\"03301\".\n Two of them (both equal to \"10301\") are palindromic.\n \n Example 2:\n \n >>> countPalindromes(s = \"0000000\")\n >>> 21\n Explanation: All 21 subsequences are \"00000\", which is palindromic.\n \n Example 3:\n \n >>> countPalindromes(s = \"9999900000\")\n >>> 2\n Explanation: The only two palindromic subsequences are \"99999\" and \"00000\".\n \"\"\"\n"}
{"task_id": "find-the-pivot-integer", "prompt": "def pivotInteger(n: int) -> int:\n \"\"\"\n Given a positive integer n, find the pivot integer x such that:\n \n The sum of all elements between 1 and x inclusively equals the sum of all elements between x and n inclusively.\n \n Return the pivot integer x. If no such integer exists, return -1. It is guaranteed that there will be at most one pivot index for the given input.\n \n Example 1:\n \n >>> pivotInteger(n = 8)\n >>> 6\n Explanation: 6 is the pivot integer since: 1 + 2 + 3 + 4 + 5 + 6 = 6 + 7 + 8 = 21.\n \n Example 2:\n \n >>> pivotInteger(n = 1)\n >>> 1\n Explanation: 1 is the pivot integer since: 1 = 1.\n \n Example 3:\n \n >>> pivotInteger(n = 4)\n >>> -1\n Explanation: It can be proved that no such integer exist.\n \"\"\"\n"}
{"task_id": "append-characters-to-string-to-make-subsequence", "prompt": "def appendCharacters(s: str, t: str) -> int:\n \"\"\"\n You are given two strings s and t consisting of only lowercase English letters.\n Return the minimum number of characters that need to be appended to the end of s so that t becomes a subsequence of s.\n A subsequence is a string that can be derived from another string by deleting some or no characters without changing the order of the remaining characters.\n \n Example 1:\n \n >>> appendCharacters(s = \"coaching\", t = \"coding\")\n >>> 4\n Explanation: Append the characters \"ding\" to the end of s so that s = \"coachingding\".\n Now, t is a subsequence of s (\"coachingding\").\n It can be shown that appending any 3 characters to the end of s will never make t a subsequence.\n \n Example 2:\n \n >>> appendCharacters(s = \"abcde\", t = \"a\")\n >>> 0\n Explanation: t is already a subsequence of s (\"abcde\").\n \n Example 3:\n \n >>> appendCharacters(s = \"z\", t = \"abcde\")\n >>> 5\n Explanation: Append the characters \"abcde\" to the end of s so that s = \"zabcde\".\n Now, t is a subsequence of s (\"zabcde\").\n It can be shown that appending any 4 characters to the end of s will never make t a subsequence.\n \"\"\"\n"}
{"task_id": "remove-nodes-from-linked-list", "prompt": "# class ListNode:\n# def __init__(val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution:\n def removeNodes(head: Optional[ListNode]) -> Optional[ListNode]:\n \"\"\"\n You are given the head of a linked list.\n Remove every node which has a node with a greater value anywhere to the right side of it.\n Return the head of the modified linked list.\n \n Example 1:\n \n \n >>> __init__(head = [5,2,13,3,8])\n >>> [13,8]\n Explanation: The nodes that should be removed are 5, 2 and 3.\n - Node 13 is to the right of node 5.\n - Node 13 is to the right of node 2.\n - Node 8 is to the right of node 3.\n \n Example 2:\n \n >>> __init__(head = [1,1,1,1])\n >>> [1,1,1,1]\n Explanation: Every node has value 1, so no nodes are removed.\n \"\"\"\n"}
{"task_id": "count-subarrays-with-median-k", "prompt": "def countSubarrays(nums: List[int], k: int) -> int:\n \"\"\"\n You are given an array nums of size n consisting of distinct integers from 1 to n and a positive integer k.\n Return the number of non-empty subarrays in nums that have a median equal to k.\n Note:\n \n The median of an array is the middle element after sorting the array in ascending order. If the array is of even length, the median is the left middle element.\n \n \n For example, the median of [2,3,1,4] is 2, and the median of [8,4,3,5,1] is 4.\n \n \n A subarray is a contiguous part of an array.\n \n \n Example 1:\n \n >>> countSubarrays(nums = [3,2,1,4,5], k = 4)\n >>> 3\n Explanation: The subarrays that have a median equal to 4 are: [4], [4,5] and [1,4,5].\n \n Example 2:\n \n >>> countSubarrays(nums = [2,3,1], k = 3)\n >>> 1\n Explanation: [3] is the only subarray that has a median equal to 3.\n \"\"\"\n"}
{"task_id": "number-of-substrings-with-fixed-ratio", "prompt": "def fixedRatio(s: str, num1: int, num2: int) -> int:\n \"\"\"\n You are given a binary string s, and two integers num1 and num2. num1 and num2 are coprime numbers.\n A ratio substring is a substring of s where the ratio between the number of 0's and the number of 1's in the substring is exactly num1 : num2.\n \n For example, if num1 = 2 and num2 = 3, then \"01011\" and \"1110000111\" are ratio substrings, while \"11000\" is not.\n \n Return the number of non-empty ratio substrings of s.\n Note that:\n \n A substring is a contiguous sequence of characters within a string.\n Two values x and y are coprime if gcd(x, y) == 1 where gcd(x, y) is the greatest common divisor of x and y.\n \n \n Example 1:\n \n >>> fixedRatio(s = \"0110011\", num1 = 1, num2 = 2)\n >>> 4\n Explanation: There exist 4 non-empty ratio substrings.\n - The substring s[0..2]: \"0110011\". It contains one 0 and two 1's. The ratio is 1 : 2.\n - The substring s[1..4]: \"0110011\". It contains one 0 and two 1's. The ratio is 1 : 2.\n - The substring s[4..6]: \"0110011\". It contains one 0 and two 1's. The ratio is 1 : 2.\n - The substring s[1..6]: \"0110011\". It contains two 0's and four 1's. The ratio is 2 : 4 == 1 : 2.\n It can be shown that there are no more ratio substrings.\n \n Example 2:\n \n >>> fixedRatio(s = \"10101\", num1 = 3, num2 = 1)\n >>> 0\n Explanation: There is no ratio substrings of s. We return 0.\n \"\"\"\n"}
{"task_id": "circular-sentence", "prompt": "def isCircularSentence(sentence: str) -> bool:\n \"\"\"\n A sentence is a list of words that are separated by a single space with no leading or trailing spaces.\n \n For example, \"Hello World\", \"HELLO\", \"hello world hello world\" are all sentences.\n \n Words consist of only uppercase and lowercase English letters. Uppercase and lowercase English letters are considered different.\n A sentence is circular if:\n \n The last character of each word in the sentence is equal to the first character of its next word.\n The last character of the last word is equal to the first character of the first word.\n \n For example, \"leetcode exercises sound delightful\", \"eetcode\", \"leetcode eats soul\" are all circular sentences. However, \"Leetcode is cool\", \"happy Leetcode\", \"Leetcode\" and \"I like Leetcode\" are not circular sentences.\n Given a string sentence, return true if it is circular. Otherwise, return false.\n \n Example 1:\n \n >>> isCircularSentence(sentence = \"leetcode exercises sound delightful\")\n >>> true\n Explanation: The words in sentence are [\"leetcode\", \"exercises\", \"sound\", \"delightful\"].\n - leetcode's\u00a0last character is equal to exercises's first character.\n - exercises's\u00a0last character is equal to sound's first character.\n - sound's\u00a0last character is equal to delightful's first character.\n - delightful's\u00a0last character is equal to leetcode's first character.\n The sentence is circular.\n Example 2:\n \n >>> isCircularSentence(sentence = \"eetcode\")\n >>> true\n Explanation: The words in sentence are [\"eetcode\"].\n - eetcode's\u00a0last character is equal to eetcode's first character.\n The sentence is circular.\n Example 3:\n \n >>> isCircularSentence(sentence = \"Leetcode is cool\")\n >>> false\n Explanation: The words in sentence are [\"Leetcode\", \"is\", \"cool\"].\n - Leetcode's\u00a0last character is not equal to is's first character.\n The sentence is not circular.\n \"\"\"\n"}
{"task_id": "divide-players-into-teams-of-equal-skill", "prompt": "def dividePlayers(skill: List[int]) -> int:\n \"\"\"\n You are given a positive integer array skill of even length n where skill[i] denotes the skill of the ith player. Divide the players into n / 2 teams of size 2 such that the total skill of each team is equal.\n The chemistry of a team is equal to the product of the skills of the players on that team.\n Return the sum of the chemistry of all the teams, or return -1 if there is no way to divide the players into teams such that the total skill of each team is equal.\n \n Example 1:\n \n >>> dividePlayers(skill = [3,2,5,1,3,4])\n >>> 22\n Explanation:\n Divide the players into the following teams: (1, 5), (2, 4), (3, 3), where each team has a total skill of 6.\n The sum of the chemistry of all the teams is: 1 * 5 + 2 * 4 + 3 * 3 = 5 + 8 + 9 = 22.\n \n Example 2:\n \n >>> dividePlayers(skill = [3,4])\n >>> 12\n Explanation:\n The two players form a team with a total skill of 7.\n The chemistry of the team is 3 * 4 = 12.\n \n Example 3:\n \n >>> dividePlayers(skill = [1,1,2,3])\n >>> -1\n Explanation:\n There is no way to divide the players into teams such that the total skill of each team is equal.\n \"\"\"\n"}
{"task_id": "minimum-score-of-a-path-between-two-cities", "prompt": "def minScore(n: int, roads: List[List[int]]) -> int:\n \"\"\"\n You are given a positive integer n representing n cities numbered from 1 to n. You are also given a 2D array roads where roads[i] = [ai, bi, distancei] indicates that there is a bidirectional road between cities ai and bi with a distance equal to distancei. The cities graph is not necessarily connected.\n The score of a path between two cities is defined as the minimum distance of a road in this path.\n Return the minimum possible score of a path between cities 1 and n.\n Note:\n \n A path is a sequence of roads between two cities.\n It is allowed for a path to contain the same road multiple times, and you can visit cities 1 and n multiple times along the path.\n The test cases are generated such that there is at least one path between 1 and n.\n \n \n Example 1:\n \n \n >>> minScore(n = 4, roads = [[1,2,9],[2,3,6],[2,4,5],[1,4,7]])\n >>> 5\n Explanation: The path from city 1 to 4 with the minimum score is: 1 -> 2 -> 4. The score of this path is min(9,5) = 5.\n It can be shown that no other path has less score.\n \n Example 2:\n \n \n >>> minScore(n = 4, roads = [[1,2,2],[1,3,4],[3,4,7]])\n >>> 2\n Explanation: The path from city 1 to 4 with the minimum score is: 1 -> 2 -> 1 -> 3 -> 4. The score of this path is min(2,2,4,7) = 2.\n \"\"\"\n"}
{"task_id": "divide-nodes-into-the-maximum-number-of-groups", "prompt": "def magnificentSets(n: int, edges: List[List[int]]) -> int:\n \"\"\"\n You are given a positive integer n representing the number of nodes in an undirected graph. The nodes are labeled from 1 to n.\n You are also given a 2D integer array edges, where edges[i] = [ai, bi] indicates that there is a bidirectional edge between nodes ai and bi. Notice that the given graph may be disconnected.\n Divide the nodes of the graph into m groups (1-indexed) such that:\n \n Each node in the graph belongs to exactly one group.\n For every pair of nodes in the graph that are connected by an edge [ai, bi], if ai belongs to the group with index x, and bi belongs to the group with index y, then |y - x| = 1.\n \n Return the maximum number of groups (i.e., maximum m) into which you can divide the nodes. Return -1 if it is impossible to group the nodes with the given conditions.\n \n Example 1:\n \n \n >>> magnificentSets(n = 6, edges = [[1,2],[1,4],[1,5],[2,6],[2,3],[4,6]])\n >>> 4\n Explanation: As shown in the image we:\n - Add node 5 to the first group.\n - Add node 1 to the second group.\n - Add nodes 2 and 4 to the third group.\n - Add nodes 3 and 6 to the fourth group.\n We can see that every edge is satisfied.\n It can be shown that that if we create a fifth group and move any node from the third or fourth group to it, at least on of the edges will not be satisfied.\n \n Example 2:\n \n >>> magnificentSets(n = 3, edges = [[1,2],[2,3],[3,1]])\n >>> -1\n Explanation: If we add node 1 to the first group, node 2 to the second group, and node 3 to the third group to satisfy the first two edges, we can see that the third edge will not be satisfied.\n It can be shown that no grouping is possible.\n \"\"\"\n"}
{"task_id": "number-of-subarrays-having-even-product", "prompt": "def evenProduct(nums: List[int]) -> int:\n \"\"\"\n Given a 0-indexed integer array nums, return the number of subarrays of nums having an even product.\n \n Example 1:\n \n >>> evenProduct(nums = [9,6,7,13])\n >>> 6\n Explanation: There are 6 subarrays with an even product:\n - nums[0..1] = 9 * 6 = 54.\n - nums[0..2] = 9 * 6 * 7 = 378.\n - nums[0..3] = 9 * 6 * 7 * 13 = 4914.\n - nums[1..1] = 6.\n - nums[1..2] = 6 * 7 = 42.\n - nums[1..3] = 6 * 7 * 13 = 546.\n \n Example 2:\n \n >>> evenProduct(nums = [7,3,5])\n >>> 0\n Explanation: There are no subarrays with an even product.\n \"\"\"\n"}
{"task_id": "maximum-value-of-a-string-in-an-array", "prompt": "def maximumValue(strs: List[str]) -> int:\n \"\"\"\n The value of an alphanumeric string can be defined as:\n \n The numeric representation of the string in base 10, if it comprises of digits only.\n The length of the string, otherwise.\n \n Given an array strs of alphanumeric strings, return the maximum value of any string in strs.\n \n Example 1:\n \n >>> maximumValue(strs = [\"alic3\",\"bob\",\"3\",\"4\",\"00000\"])\n >>> 5\n Explanation:\n - \"alic3\" consists of both letters and digits, so its value is its length, i.e. 5.\n - \"bob\" consists only of letters, so its value is also its length, i.e. 3.\n - \"3\" consists only of digits, so its value is its numeric equivalent, i.e. 3.\n - \"4\" also consists only of digits, so its value is 4.\n - \"00000\" consists only of digits, so its value is 0.\n Hence, the maximum value is 5, of \"alic3\".\n \n Example 2:\n \n >>> maximumValue(strs = [\"1\",\"01\",\"001\",\"0001\"])\n >>> 1\n Explanation:\n Each string in the array has value 1. Hence, we return 1.\n \"\"\"\n"}
{"task_id": "maximum-star-sum-of-a-graph", "prompt": "def maxStarSum(vals: List[int], edges: List[List[int]], k: int) -> int:\n \"\"\"\n There is an undirected graph consisting of n nodes numbered from 0 to n - 1. You are given a 0-indexed integer array vals of length n where vals[i] denotes the value of the ith node.\n You are also given a 2D integer array edges where edges[i] = [ai, bi] denotes that there exists an undirected edge connecting nodes ai and bi.\n A star graph is a subgraph of the given graph having a center node containing 0 or more neighbors. In other words, it is a subset of edges of the given graph such that there exists a common node for all edges.\n The image below shows star graphs with 3 and 4 neighbors respectively, centered at the blue node.\n \n The star sum is the sum of the values of all the nodes present in the star graph.\n Given an integer k, return the maximum star sum of a star graph containing at most k edges.\n \n Example 1:\n \n \n >>> maxStarSum(vals = [1,2,3,4,10,-10,-20], edges = [[0,1],[1,2],[1,3],[3,4],[3,5],[3,6]], k = 2)\n >>> 16\n Explanation: The above diagram represents the input graph.\n The star graph with the maximum star sum is denoted by blue. It is centered at 3 and includes its neighbors 1 and 4.\n It can be shown it is not possible to get a star graph with a sum greater than 16.\n \n Example 2:\n \n >>> maxStarSum(vals = [-5], edges = [], k = 0)\n >>> -5\n Explanation: There is only one possible star graph, which is node 0 itself.\n Hence, we return -5.\n \"\"\"\n"}
{"task_id": "frog-jump-ii", "prompt": "def maxJump(stones: List[int]) -> int:\n \"\"\"\n You are given a 0-indexed integer array stones sorted in strictly increasing order representing the positions of stones in a river.\n A frog, initially on the first stone, wants to travel to the last stone and then return to the first stone. However, it can jump to any stone at most once.\n The length of a jump is the absolute difference between the position of the stone the frog is currently on and the position of the stone to which the frog jumps.\n \n More formally, if the frog is at stones[i] and is jumping to stones[j], the length of the jump is |stones[i] - stones[j]|.\n \n The cost of a path is the maximum length of a jump among all jumps in the path.\n Return the minimum cost of a path for the frog.\n \n Example 1:\n \n \n >>> maxJump(stones = [0,2,5,6,7])\n >>> 5\n Explanation: The above figure represents one of the optimal paths the frog can take.\n The cost of this path is 5, which is the maximum length of a jump.\n Since it is not possible to achieve a cost of less than 5, we return it.\n \n Example 2:\n \n \n >>> maxJump(stones = [0,3,9])\n >>> 9\n Explanation:\n The frog can jump directly to the last stone and come back to the first stone.\n In this case, the length of each jump will be 9. The cost for the path will be max(9, 9) = 9.\n It can be shown that this is the minimum achievable cost.\n \"\"\"\n"}
{"task_id": "minimum-total-cost-to-make-arrays-unequal", "prompt": "def minimumTotalCost(nums1: List[int], nums2: List[int]) -> int:\n \"\"\"\n You are given two 0-indexed integer arrays nums1 and nums2, of equal length n.\n In one operation, you can swap the values of any two indices of nums1. The cost of this operation is the sum of the indices.\n Find the minimum total cost of performing the given operation any number of times such that nums1[i] != nums2[i] for all 0 <= i <= n - 1 after performing all the operations.\n Return the minimum total cost such that nums1 and nums2 satisfy the above condition. In case it is not possible, return -1.\n \n Example 1:\n \n >>> minimumTotalCost(nums1 = [1,2,3,4,5], nums2 = [1,2,3,4,5])\n >>> 10\n Explanation:\n One of the ways we can perform the operations is:\n - Swap values at indices 0 and 3, incurring cost = 0 + 3 = 3. Now, nums1 = [4,2,3,1,5]\n - Swap values at indices 1 and 2, incurring cost = 1 + 2 = 3. Now, nums1 = [4,3,2,1,5].\n - Swap values at indices 0 and 4, incurring cost = 0 + 4 = 4. Now, nums1 =[5,3,2,1,4].\n We can see that for each index i, nums1[i] != nums2[i]. The cost required here is 10.\n Note that there are other ways to swap values, but it can be proven that it is not possible to obtain a cost less than 10.\n \n Example 2:\n \n >>> minimumTotalCost(nums1 = [2,2,2,1,3], nums2 = [1,2,2,3,3])\n >>> 10\n Explanation:\n One of the ways we can perform the operations is:\n - Swap values at indices 2 and 3, incurring cost = 2 + 3 = 5. Now, nums1 = [2,2,1,2,3].\n - Swap values at indices 1 and 4, incurring cost = 1 + 4 = 5. Now, nums1 = [2,3,1,2,2].\n The total cost needed here is 10, which is the minimum possible.\n \n Example 3:\n \n >>> minimumTotalCost(nums1 = [1,2,2], nums2 = [1,2,2])\n >>> -1\n Explanation:\n It can be shown that it is not possible to satisfy the given conditions irrespective of the number of operations we perform.\n Hence, we return -1.\n \"\"\"\n"}
{"task_id": "delete-greatest-value-in-each-row", "prompt": "def deleteGreatestValue(grid: List[List[int]]) -> int:\n \"\"\"\n You are given an m x n matrix grid consisting of positive integers.\n Perform the following operation until grid becomes empty:\n \n Delete the element with the greatest value from each row. If multiple such elements exist, delete any of them.\n Add the maximum of deleted elements to the answer.\n \n Note that the number of columns decreases by one after each operation.\n Return the answer after performing the operations described above.\n \n Example 1:\n \n \n >>> deleteGreatestValue(grid = [[1,2,4],[3,3,1]])\n >>> 8\n Explanation: The diagram above shows the removed values in each step.\n - In the first operation, we remove 4 from the first row and 3 from the second row (notice that, there are two cells with value 3 and we can remove any of them). We add 4 to the answer.\n - In the second operation, we remove 2 from the first row and 3 from the second row. We add 3 to the answer.\n - In the third operation, we remove 1 from the first row and 1 from the second row. We add 1 to the answer.\n The final answer = 4 + 3 + 1 = 8.\n \n Example 2:\n \n \n >>> deleteGreatestValue(grid = [[10]])\n >>> 10\n Explanation: The diagram above shows the removed values in each step.\n - In the first operation, we remove 10 from the first row. We add 10 to the answer.\n The final answer = 10.\n \"\"\"\n"}
{"task_id": "longest-square-streak-in-an-array", "prompt": "def longestSquareStreak(nums: List[int]) -> int:\n \"\"\"\n You are given an integer array nums. A subsequence of nums is called a square streak if:\n \n The length of the subsequence is at least 2, and\n after sorting the subsequence, each element (except the first element) is the square of the previous number.\n \n Return the length of the longest square streak in nums, or return -1 if there is no square streak.\n 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.\n \n Example 1:\n \n >>> longestSquareStreak(nums = [4,3,6,16,8,2])\n >>> 3\n Explanation: Choose the subsequence [4,16,2]. After sorting it, it becomes [2,4,16].\n - 4 = 2 * 2.\n - 16 = 4 * 4.\n Therefore, [4,16,2] is a square streak.\n It can be shown that every subsequence of length 4 is not a square streak.\n \n Example 2:\n \n >>> longestSquareStreak(nums = [2,3,5,6,7])\n >>> -1\n Explanation: There is no square streak in nums so return -1.\n \"\"\"\n"}
{"task_id": "maximum-number-of-points-from-grid-queries", "prompt": "def maxPoints(grid: List[List[int]], queries: List[int]) -> List[int]:\n \"\"\"\n You are given an m x n integer matrix grid and an array queries of size k.\n Find an array answer of size k such that for each integer queries[i] you start in the top left cell of the matrix and repeat the following process:\n \n If queries[i] is strictly greater than the value of the current cell that you are in, then you get one point if it is your first time visiting this cell, and you can move to any adjacent cell in all 4 directions: up, down, left, and right.\n Otherwise, you do not get any points, and you end this process.\n \n After the process, answer[i] is the maximum number of points you can get. Note that for each query you are allowed to visit the same cell multiple times.\n Return the resulting array answer.\n \n Example 1:\n \n \n >>> maxPoints(grid = [[1,2,3],[2,5,7],[3,5,1]], queries = [5,6,2])\n >>> [5,8,1]\n Explanation: The diagrams above show which cells we visit to get points for each query.\n Example 2:\n \n \n >>> maxPoints(grid = [[5,2,1],[1,1,2]], queries = [3])\n >>> [0]\n Explanation: We can not get any points because the value of the top left cell is already greater than or equal to 3.\n \"\"\"\n"}
{"task_id": "bitwise-or-of-all-subsequence-sums", "prompt": "def subsequenceSumOr(nums: List[int]) -> int:\n \"\"\"\n Given an integer array nums, return the value of the bitwise OR of the sum of all possible subsequences in the array.\n A subsequence is a sequence that can be derived from another sequence by removing zero or more elements without changing the order of the remaining elements.\n \n Example 1:\n \n >>> subsequenceSumOr(nums = [2,1,0,3])\n >>> 7\n Explanation: All possible subsequence sums that we can have are: 0, 1, 2, 3, 4, 5, 6.\n And we have 0 OR 1 OR 2 OR 3 OR 4 OR 5 OR 6 = 7, so we return 7.\n \n Example 2:\n \n >>> subsequenceSumOr(nums = [0,0,0])\n >>> 0\n Explanation: 0 is the only possible subsequence sum we can have, so we return 0.\n \"\"\"\n"}
{"task_id": "count-pairs-of-similar-strings", "prompt": "def similarPairs(words: List[str]) -> int:\n \"\"\"\n You are given a 0-indexed string array words.\n Two strings are similar if they consist of the same characters.\n \n For example, \"abca\" and \"cba\" are similar since both consist of characters 'a', 'b', and 'c'.\n However, \"abacba\" and \"bcfd\" are not similar since they do not consist of the same characters.\n \n Return the number of pairs (i, j) such that 0 <= i < j <= word.length - 1 and the two strings words[i] and words[j] are similar.\n \n Example 1:\n \n >>> similarPairs(words = [\"aba\",\"aabb\",\"abcd\",\"bac\",\"aabc\"])\n >>> 2\n Explanation: There are 2 pairs that satisfy the conditions:\n - i = 0 and j = 1 : both words[0] and words[1] only consist of characters 'a' and 'b'.\n - i = 3 and j = 4 : both words[3] and words[4] only consist of characters 'a', 'b', and 'c'.\n \n Example 2:\n \n >>> similarPairs(words = [\"aabb\",\"ab\",\"ba\"])\n >>> 3\n Explanation: There are 3 pairs that satisfy the conditions:\n - i = 0 and j = 1 : both words[0] and words[1] only consist of characters 'a' and 'b'.\n - i = 0 and j = 2 : both words[0] and words[2] only consist of characters 'a' and 'b'.\n - i = 1 and j = 2 : both words[1] and words[2] only consist of characters 'a' and 'b'.\n \n Example 3:\n \n >>> similarPairs(words = [\"nba\",\"cba\",\"dba\"])\n >>> 0\n Explanation: Since there does not exist any pair that satisfies the conditions, we return 0.\n \"\"\"\n"}
{"task_id": "smallest-value-after-replacing-with-sum-of-prime-factors", "prompt": "def smallestValue(n: int) -> int:\n \"\"\"\n You are given a positive integer n.\n Continuously replace n with the sum of its prime factors.\n \n Note that if a prime factor divides n multiple times, it should be included in the sum as many times as it divides n.\n \n Return the smallest value n will take on.\n \n Example 1:\n \n >>> smallestValue(n = 15)\n >>> 5\n Explanation: Initially, n = 15.\n 15 = 3 * 5, so replace n with 3 + 5 = 8.\n 8 = 2 * 2 * 2, so replace n with 2 + 2 + 2 = 6.\n 6 = 2 * 3, so replace n with 2 + 3 = 5.\n 5 is the smallest value n will take on.\n \n Example 2:\n \n >>> smallestValue(n = 3)\n >>> 3\n Explanation: Initially, n = 3.\n 3 is the smallest value n will take on.\n \"\"\"\n"}
{"task_id": "add-edges-to-make-degrees-of-all-nodes-even", "prompt": "def isPossible(n: int, edges: List[List[int]]) -> bool:\n \"\"\"\n There is an undirected graph consisting of n nodes numbered from 1 to n. You are given the integer n and a 2D array edges where edges[i] = [ai, bi] indicates that there is an edge between nodes ai and bi. The graph can be disconnected.\n You can add at most two additional edges (possibly none) to this graph so that there are no repeated edges and no self-loops.\n Return true if it is possible to make the degree of each node in the graph even, otherwise return false.\n The degree of a node is the number of edges connected to it.\n \n Example 1:\n \n \n >>> isPossible(n = 5, edges = [[1,2],[2,3],[3,4],[4,2],[1,4],[2,5]])\n >>> true\n Explanation: The above diagram shows a valid way of adding an edge.\n Every node in the resulting graph is connected to an even number of edges.\n \n Example 2:\n \n \n >>> isPossible(n = 4, edges = [[1,2],[3,4]])\n >>> true\n Explanation: The above diagram shows a valid way of adding two edges.\n Example 3:\n \n \n >>> isPossible(n = 4, edges = [[1,2],[1,3],[1,4]])\n >>> false\n Explanation: It is not possible to obtain a valid graph with adding at most 2 edges.\n \"\"\"\n"}
{"task_id": "cycle-length-queries-in-a-tree", "prompt": "def cycleLengthQueries(n: int, queries: List[List[int]]) -> List[int]:\n \"\"\"\n You are given an integer n. There is a complete binary tree with 2n - 1 nodes. The root of that tree is the node with the value 1, and every node with a value val in the range [1, 2n - 1 - 1] has two children where:\n \n The left node has the value 2 * val, and\n The right node has the value 2 * val + 1.\n \n You are also given a 2D integer array queries of length m, where queries[i] = [ai, bi]. For each query, solve the following problem:\n \n Add an edge between the nodes with values ai and bi.\n Find the length of the cycle in the graph.\n Remove the added edge between nodes with values ai and bi.\n \n Note that:\n \n A cycle is a path that starts and ends at the same node, and each edge in the path is visited only once.\n The length of a cycle is the number of edges visited in the cycle.\n There could be multiple edges between two nodes in the tree after adding the edge of the query.\n \n Return an array answer of length m where answer[i] is the answer to the ith query.\n \n Example 1:\n \n \n >>> cycleLengthQueries(n = 3, queries = [[5,3],[4,7],[2,3]])\n >>> [4,5,3]\n Explanation: The diagrams above show the tree of 23 - 1 nodes. Nodes colored in red describe the nodes in the cycle after adding the edge.\n - After adding the edge between nodes 3 and 5, the graph contains a cycle of nodes [5,2,1,3]. Thus answer to the first query is 4. We delete the added edge and process the next query.\n - After adding the edge between nodes 4 and 7, the graph contains a cycle of nodes [4,2,1,3,7]. Thus answer to the second query is 5. We delete the added edge and process the next query.\n - After adding the edge between nodes 2 and 3, the graph contains a cycle of nodes [2,1,3]. Thus answer to the third query is 3. We delete the added edge.\n \n Example 2:\n \n \n >>> cycleLengthQueries(n = 2, queries = [[1,2]])\n >>> [2]\n Explanation: The diagram above shows the tree of 22 - 1 nodes. Nodes colored in red describe the nodes in the cycle after adding the edge.\n - After adding the edge between nodes 1 and 2, the graph contains a cycle of nodes [2,1]. Thus answer for the first query is 2. We delete the added edge.\n \"\"\"\n"}
{"task_id": "check-if-there-is-a-path-with-equal-number-of-0s-and-1s", "prompt": "def isThereAPath(grid: List[List[int]]) -> bool:\n \"\"\"\n You are given a 0-indexed m x n binary matrix grid. You can move from a cell (row, col) to any of the cells (row + 1, col) or (row, col + 1).\n Return true if there is a path from (0, 0) to (m - 1, n - 1) that visits an equal number of 0's and 1's. Otherwise return false.\n \n Example 1:\n \n \n >>> isThereAPath(grid = [[0,1,0,0],[0,1,0,0],[1,0,1,0]])\n >>> true\n Explanation: The path colored in blue in the above diagram is a valid path because we have 3 cells with a value of 1 and 3 with a value of 0. Since there is a valid path, we return true.\n \n Example 2:\n \n \n >>> isThereAPath(grid = [[1,1,0],[0,0,1],[1,0,0]])\n >>> false\n Explanation: There is no path in this grid with an equal number of 0's and 1's.\n \"\"\"\n"}
{"task_id": "maximum-enemy-forts-that-can-be-captured", "prompt": "def captureForts(forts: List[int]) -> int:\n \"\"\"\n You are given a 0-indexed integer array forts of length n representing the positions of several forts. forts[i] can be -1, 0, or 1 where:\n \n -1 represents there is no fort at the ith position.\n 0 indicates there is an enemy fort at the ith position.\n 1 indicates the fort at the ith the position is under your command.\n \n Now you have decided to move your army from one of your forts at position i to an empty position j such that:\n \n 0 <= i, j <= n - 1\n The army travels over enemy forts only. Formally, for all k where min(i,j) < k < max(i,j), forts[k] == 0.\n \n While moving the army, all the enemy forts that come in the way are captured.\n Return the maximum number of enemy forts that can be captured. In case it is impossible to move your army, or you do not have any fort under your command, return 0.\n \n Example 1:\n \n >>> captureForts(forts = [1,0,0,-1,0,0,0,0,1])\n >>> 4\n Explanation:\n - Moving the army from position 0 to position 3 captures 2 enemy forts, at 1 and 2.\n - Moving the army from position 8 to position 3 captures 4 enemy forts.\n Since 4 is the maximum number of enemy forts that can be captured, we return 4.\n \n Example 2:\n \n >>> captureForts(forts = [0,0,1,-1])\n >>> 0\n Explanation: Since no enemy fort can be captured, 0 is returned.\n \"\"\"\n"}
{"task_id": "reward-top-k-students", "prompt": "def topStudents(positive_feedback: List[str], negative_feedback: List[str], report: List[str], student_id: List[int], k: int) -> List[int]:\n \"\"\"\n You are given two string arrays positive_feedback and negative_feedback, containing the words denoting positive and negative feedback, respectively. Note that no word is both positive and negative.\n Initially every student has 0 points. Each positive word in a feedback report increases the points of a student by 3, whereas each negative word decreases the points by 1.\n You are given n feedback reports, represented by a 0-indexed string array report\u00a0and a 0-indexed integer array student_id, where student_id[i] represents the ID of the student who has received the feedback report report[i]. The ID of each student is unique.\n Given an integer k, return the top k students after ranking them in non-increasing order by their points. In case more than one student has the same points, the one with the lower ID ranks higher.\n \n Example 1:\n \n >>> topStudents(positive_feedback = [\"smart\",\"brilliant\",\"studious\"], negative_feedback = [\"not\"], report = [\"this student is studious\",\"the student is smart\"], student_id = [1,2], k = 2)\n >>> [1,2]\n Explanation:\n Both the students have 1 positive feedback and 3 points but since student 1 has a lower ID he ranks higher.\n \n Example 2:\n \n >>> topStudents(positive_feedback = [\"smart\",\"brilliant\",\"studious\"], negative_feedback = [\"not\"], report = [\"this student is not studious\",\"the student is smart\"], student_id = [1,2], k = 2)\n >>> [2,1]\n Explanation:\n - The student with ID 1 has 1 positive feedback and 1 negative feedback, so he has 3-1=2 points.\n - The student with ID 2 has 1 positive feedback, so he has 3 points.\n Since student 2 has more points, [2,1] is returned.\n \"\"\"\n"}
{"task_id": "minimize-the-maximum-of-two-arrays", "prompt": "def minimizeSet(divisor1: int, divisor2: int, uniqueCnt1: int, uniqueCnt2: int) -> int:\n \"\"\"\n We have two arrays arr1 and arr2 which are initially empty. You need to add positive integers to them such that they satisfy all the following conditions:\n \n arr1 contains uniqueCnt1 distinct positive integers, each of which is not divisible by divisor1.\n arr2 contains uniqueCnt2 distinct positive integers, each of which is not divisible by divisor2.\n No integer is present in both arr1 and arr2.\n \n Given divisor1, divisor2, uniqueCnt1, and uniqueCnt2, return the minimum possible maximum integer that can be present in either array.\n \n Example 1:\n \n >>> minimizeSet(divisor1 = 2, divisor2 = 7, uniqueCnt1 = 1, uniqueCnt2 = 3)\n >>> 4\n Explanation:\n We can distribute the first 4 natural numbers into arr1 and arr2.\n arr1 = [1] and arr2 = [2,3,4].\n We can see that both arrays satisfy all the conditions.\n Since the maximum value is 4, we return it.\n \n Example 2:\n \n >>> minimizeSet(divisor1 = 3, divisor2 = 5, uniqueCnt1 = 2, uniqueCnt2 = 1)\n >>> 3\n Explanation:\n Here arr1 = [1,2], and arr2 = [3] satisfy all conditions.\n Since the maximum value is 3, we return it.\n Example 3:\n \n >>> minimizeSet(divisor1 = 2, divisor2 = 4, uniqueCnt1 = 8, uniqueCnt2 = 2)\n >>> 15\n Explanation:\n Here, the final possible arrays can be arr1 = [1,3,5,7,9,11,13,15], and arr2 = [2,6].\n It can be shown that it is not possible to obtain a lower maximum satisfying all conditions.\n \"\"\"\n"}
{"task_id": "shortest-distance-to-target-string-in-a-circular-array", "prompt": "def closestTarget(words: List[str], target: str, startIndex: int) -> int:\n \"\"\"\n You are given a 0-indexed circular string array words and a string target. A circular array means that the array's end connects to the array's beginning.\n \n Formally, the next element of words[i] is words[(i + 1) % n] and the previous element of words[i] is words[(i - 1 + n) % n], where n is the length of words.\n \n Starting from startIndex, you can move to either the next word or the previous word with 1 step at a time.\n Return the shortest distance needed to reach the string target. If the string target does not exist in words, return -1.\n \n Example 1:\n \n >>> closestTarget(words = [\"hello\",\"i\",\"am\",\"leetcode\",\"hello\"], target = \"hello\", startIndex = 1)\n >>> 1\n Explanation: We start from index 1 and can reach \"hello\" by\n - moving 3 units to the right to reach index 4.\n - moving 2 units to the left to reach index 4.\n - moving 4 units to the right to reach index 0.\n - moving 1 unit to the left to reach index 0.\n The shortest distance to reach \"hello\" is 1.\n \n Example 2:\n \n >>> closestTarget(words = [\"a\",\"b\",\"leetcode\"], target = \"leetcode\", startIndex = 0)\n >>> 1\n Explanation: We start from index 0 and can reach \"leetcode\" by\n - moving 2 units to the right to reach index 3.\n - moving 1 unit to the left to reach index 3.\n The shortest distance to reach \"leetcode\" is 1.\n Example 3:\n \n >>> closestTarget(words = [\"i\",\"eat\",\"leetcode\"], target = \"ate\", startIndex = 0)\n >>> -1\n Explanation: Since \"ate\" does not exist in words, we return -1.\n \"\"\"\n"}
{"task_id": "take-k-of-each-character-from-left-and-right", "prompt": "def takeCharacters(s: str, k: int) -> int:\n \"\"\"\n You are given a string s consisting of the characters 'a', 'b', and 'c' and a non-negative integer k. Each minute, you may take either the leftmost character of s, or the rightmost character of s.\n Return the minimum number of minutes needed for you to take at least k of each character, or return -1 if it is not possible to take k of each character.\n \n Example 1:\n \n >>> takeCharacters(s = \"aabaaaacaabc\", k = 2)\n >>> 8\n Explanation:\n Take three characters from the left of s. You now have two 'a' characters, and one 'b' character.\n Take five characters from the right of s. You now have four 'a' characters, two 'b' characters, and two 'c' characters.\n A total of 3 + 5 = 8 minutes is needed.\n It can be proven that 8 is the minimum number of minutes needed.\n \n Example 2:\n \n >>> takeCharacters(s = \"a\", k = 1)\n >>> -1\n Explanation: It is not possible to take one 'b' or 'c' so return -1.\n \"\"\"\n"}
{"task_id": "maximum-tastiness-of-candy-basket", "prompt": "def maximumTastiness(price: List[int], k: int) -> int:\n \"\"\"\n You are given an array of positive integers price where price[i] denotes the price of the ith candy and a positive integer k.\n The store sells baskets of k distinct candies. The tastiness of a candy basket is the smallest absolute difference of the prices of any two candies in the basket.\n Return the maximum tastiness of a candy basket.\n \n Example 1:\n \n >>> maximumTastiness(price = [13,5,1,8,21,2], k = 3)\n >>> 8\n Explanation: Choose the candies with the prices [13,5,21].\n The tastiness of the candy basket is: min(|13 - 5|, |13 - 21|, |5 - 21|) = min(8, 8, 16) = 8.\n It can be proven that 8 is the maximum tastiness that can be achieved.\n \n Example 2:\n \n >>> maximumTastiness(price = [1,3,1], k = 2)\n >>> 2\n Explanation: Choose the candies with the prices [1,3].\n The tastiness of the candy basket is: min(|1 - 3|) = min(2) = 2.\n It can be proven that 2 is the maximum tastiness that can be achieved.\n \n Example 3:\n \n >>> maximumTastiness(price = [7,7,7,7], k = 2)\n >>> 0\n Explanation: Choosing any two distinct candies from the candies we have will result in a tastiness of 0.\n \"\"\"\n"}
{"task_id": "number-of-great-partitions", "prompt": "def countPartitions(nums: List[int], k: int) -> int:\n \"\"\"\n You are given an array nums consisting of positive integers and an integer k.\n Partition the array into two ordered groups such that each element is in exactly one group. A partition is called great if the sum of elements of each group is greater than or equal to k.\n Return the number of distinct great partitions. Since the answer may be too large, return it modulo 109 + 7.\n Two partitions are considered distinct if some element nums[i] is in different groups in the two partitions.\n \n Example 1:\n \n >>> countPartitions(nums = [1,2,3,4], k = 4)\n >>> 6\n Explanation: The great partitions are: ([1,2,3], [4]), ([1,3], [2,4]), ([1,4], [2,3]), ([2,3], [1,4]), ([2,4], [1,3]) and ([4], [1,2,3]).\n \n Example 2:\n \n >>> countPartitions(nums = [3,3,3], k = 4)\n >>> 0\n Explanation: There are no great partitions for this array.\n \n Example 3:\n \n >>> countPartitions(nums = [6,6], k = 2)\n >>> 2\n Explanation: We can either put nums[0] in the first partition or in the second partition.\n The great partitions will be ([6], [6]) and ([6], [6]).\n \"\"\"\n"}
{"task_id": "count-the-number-of-k-big-indices", "prompt": "def kBigIndices(nums: List[int], k: int) -> int:\n \"\"\"\n You are given a 0-indexed integer array nums and a positive integer k.\n We call an index i k-big if the following conditions are satisfied:\n \n There exist at least k different indices idx1 such that idx1 < i and nums[idx1] < nums[i].\n There exist at least k different indices idx2 such that idx2 > i and nums[idx2] < nums[i].\n \n Return the number of k-big indices.\n \n Example 1:\n \n >>> kBigIndices(nums = [2,3,6,5,2,3], k = 2)\n >>> 2\n Explanation: There are only two 2-big indices in nums:\n - i = 2 --> There are two valid idx1: 0 and 1. There are three valid idx2: 2, 3, and 4.\n - i = 3 --> There are two valid idx1: 0 and 1. There are two valid idx2: 3 and 4.\n \n Example 2:\n \n >>> kBigIndices(nums = [1,1,1], k = 3)\n >>> 0\n Explanation: There are no 3-big indices in nums.\n \"\"\"\n"}
{"task_id": "count-the-digits-that-divide-a-number", "prompt": "def countDigits(num: int) -> int:\n \"\"\"\n Given an integer num, return the number of digits in num that divide num.\n An integer val divides nums if nums % val == 0.\n \n Example 1:\n \n >>> countDigits(num = 7)\n >>> 1\n Explanation: 7 divides itself, hence the answer is 1.\n \n Example 2:\n \n >>> countDigits(num = 121)\n >>> 2\n Explanation: 121 is divisible by 1, but not 2. Since 1 occurs twice as a digit, we return 2.\n \n Example 3:\n \n >>> countDigits(num = 1248)\n >>> 4\n Explanation: 1248 is divisible by all of its digits, hence the answer is 4.\n \"\"\"\n"}
{"task_id": "distinct-prime-factors-of-product-of-array", "prompt": "def distinctPrimeFactors(nums: List[int]) -> int:\n \"\"\"\n Given an array of positive integers nums, return the number of distinct prime factors in the product of the elements of nums.\n Note that:\n \n A number greater than 1 is called prime if it is divisible by only 1 and itself.\n An integer val1 is a factor of another integer val2 if val2 / val1 is an integer.\n \n \n Example 1:\n \n >>> distinctPrimeFactors(nums = [2,4,3,7,10,6])\n >>> 4\n Explanation:\n The product of all the elements in nums is: 2 * 4 * 3 * 7 * 10 * 6 = 10080 = 25 * 32 * 5 * 7.\n There are 4 distinct prime factors so we return 4.\n \n Example 2:\n \n >>> distinctPrimeFactors(nums = [2,4,8,16])\n >>> 1\n Explanation:\n The product of all the elements in nums is: 2 * 4 * 8 * 16 = 1024 = 210.\n There is 1 distinct prime factor so we return 1.\n \"\"\"\n"}
{"task_id": "partition-string-into-substrings-with-values-at-most-k", "prompt": "def minimumPartition(s: str, k: int) -> int:\n \"\"\"\n You are given a string s consisting of digits from 1 to 9 and an integer k.\n A partition of a string s is called good if:\n \n Each digit of s is part of exactly one substring.\n The value of each substring is less than or equal to k.\n \n Return the minimum number of substrings in a good partition of s. If no good partition of s exists, return -1.\n Note that:\n \n The value of a string is its result when interpreted as an integer. For example, the value of \"123\" is 123 and the value of \"1\" is 1.\n A substring is a contiguous sequence of characters within a string.\n \n \n Example 1:\n \n >>> minimumPartition(s = \"165462\", k = 60)\n >>> 4\n Explanation: We can partition the string into substrings \"16\", \"54\", \"6\", and \"2\". Each substring has a value less than or equal to k = 60.\n It can be shown that we cannot partition the string into less than 4 substrings.\n \n Example 2:\n \n >>> minimumPartition(s = \"238182\", k = 5)\n >>> -1\n Explanation: There is no good partition for this string.\n \"\"\"\n"}
{"task_id": "closest-prime-numbers-in-range", "prompt": "def closestPrimes(left: int, right: int) -> List[int]:\n \"\"\"\n Given two positive integers left and right, find the two integers num1 and num2 such that:\n \n left <= num1 < num2 <= right .\n Both num1 and num2 are prime numbers.\n num2 - num1 is the minimum amongst all other pairs satisfying the above conditions.\n \n Return the positive integer array ans = [num1, num2]. If there are multiple pairs satisfying these conditions, return the one with the smallest num1 value. If no such numbers exist, return [-1, -1].\n \n Example 1:\n \n >>> closestPrimes(left = 10, right = 19)\n >>> [11,13]\n Explanation: The prime numbers between 10 and 19 are 11, 13, 17, and 19.\n The closest gap between any pair is 2, which can be achieved by [11,13] or [17,19].\n Since 11 is smaller than 17, we return the first pair.\n \n Example 2:\n \n >>> closestPrimes(left = 4, right = 6)\n >>> [-1,-1]\n Explanation: There exists only one prime number in the given range, so the conditions cannot be satisfied.\n \"\"\"\n"}
{"task_id": "categorize-box-according-to-criteria", "prompt": "def categorizeBox(length: int, width: int, height: int, mass: int) -> str:\n \"\"\"\n Given four integers length, width, height, and mass, representing the dimensions and mass of a box, respectively, return a string representing the category of the box.\n \n The box is \"Bulky\" if:\n \n \n Any of the dimensions of the box is greater or equal to 104.\n Or, the volume of the box is greater or equal to 109.\n \n \n If the mass of the box is greater or equal to 100, it is \"Heavy\".\n If the box is both \"Bulky\" and \"Heavy\", then its category is \"Both\".\n If the box is neither \"Bulky\" nor \"Heavy\", then its category is \"Neither\".\n If the box is \"Bulky\" but not \"Heavy\", then its category is \"Bulky\".\n If the box is \"Heavy\" but not \"Bulky\", then its category is \"Heavy\".\n \n Note that the volume of the box is the product of its length, width and height.\n \n Example 1:\n \n >>> categorizeBox(length = 1000, width = 35, height = 700, mass = 300)\n >>> \"Heavy\"\n Explanation:\n None of the dimensions of the box is greater or equal to 104.\n Its volume = 24500000 <= 109. So it cannot be categorized as \"Bulky\".\n However mass >= 100, so the box is \"Heavy\".\n Since the box is not \"Bulky\" but \"Heavy\", we return \"Heavy\".\n Example 2:\n \n >>> categorizeBox(length = 200, width = 50, height = 800, mass = 50)\n >>> \"Neither\"\n Explanation:\n None of the dimensions of the box is greater or equal to 104.\n Its volume = 8 * 106 <= 109. So it cannot be categorized as \"Bulky\".\n Its mass is also less than 100, so it cannot be categorized as \"Heavy\" either.\n Since its neither of the two above categories, we return \"Neither\".\n \"\"\"\n"}
{"task_id": "find-xor-beauty-of-array", "prompt": "def xorBeauty(nums: List[int]) -> int:\n \"\"\"\n You are given a 0-indexed integer array nums.\n The effective value of three indices i, j, and k is defined as ((nums[i] | nums[j]) & nums[k]).\n The xor-beauty of the array is the XORing of the effective values of all the possible triplets of indices (i, j, k) where 0 <= i, j, k < n.\n Return the xor-beauty of nums.\n Note that:\n \n val1 | val2 is bitwise OR of val1 and val2.\n val1 & val2 is bitwise AND of val1 and val2.\n \n \n Example 1:\n \n >>> xorBeauty(nums = [1,4])\n >>> 5\n Explanation:\n The triplets and their corresponding effective values are listed below:\n - (0,0,0) with effective value ((1 | 1) & 1) = 1\n - (0,0,1) with effective value ((1 | 1) & 4) = 0\n - (0,1,0) with effective value ((1 | 4) & 1) = 1\n - (0,1,1) with effective value ((1 | 4) & 4) = 4\n - (1,0,0) with effective value ((4 | 1) & 1) = 1\n - (1,0,1) with effective value ((4 | 1) & 4) = 4\n - (1,1,0) with effective value ((4 | 4) & 1) = 0\n - (1,1,1) with effective value ((4 | 4) & 4) = 4\n Xor-beauty of array will be bitwise XOR of all beauties = 1 ^ 0 ^ 1 ^ 4 ^ 1 ^ 4 ^ 0 ^ 4 = 5.\n Example 2:\n \n >>> xorBeauty(nums = [15,45,20,2,34,35,5,44,32,30])\n >>> 34\n Explanation: The xor-beauty of the given array is 34.\n \"\"\"\n"}
{"task_id": "maximize-the-minimum-powered-city", "prompt": "def maxPower(stations: List[int], r: int, k: int) -> int:\n \"\"\"\n You are given a 0-indexed integer array stations of length n, where stations[i] represents the number of power stations in the ith city.\n Each power station can provide power to every city in a fixed range. In other words, if the range is denoted by r, then a power station at city i can provide power to all cities j such that |i - j| <= r and 0 <= i, j <= n - 1.\n \n Note that |x| denotes absolute value. For example, |7 - 5| = 2 and |3 - 10| = 7.\n \n The power of a city is the total number of power stations it is being provided power from.\n The government has sanctioned building k more power stations, each of which can be built in any city, and have the same range as the pre-existing ones.\n Given the two integers r and k, return the maximum possible minimum power of a city, if the additional power stations are built optimally.\n Note that you can build the k power stations in multiple cities.\n \n Example 1:\n \n >>> maxPower(stations = [1,2,4,5,0], r = 1, k = 2)\n >>> 5\n Explanation:\n One of the optimal ways is to install both the power stations at city 1.\n So stations will become [1,4,4,5,0].\n - City 0 is provided by 1 + 4 = 5 power stations.\n - City 1 is provided by 1 + 4 + 4 = 9 power stations.\n - City 2 is provided by 4 + 4 + 5 = 13 power stations.\n - City 3 is provided by 5 + 4 = 9 power stations.\n - City 4 is provided by 5 + 0 = 5 power stations.\n So the minimum power of a city is 5.\n Since it is not possible to obtain a larger power, we return 5.\n \n Example 2:\n \n >>> maxPower(stations = [4,4,4,4], r = 0, k = 3)\n >>> 4\n Explanation:\n It can be proved that we cannot make the minimum power of a city greater than 4.\n \"\"\"\n"}
{"task_id": "maximum-count-of-positive-integer-and-negative-integer", "prompt": "def maximumCount(nums: List[int]) -> int:\n \"\"\"\n Given an array nums sorted in non-decreasing order, return the maximum between the number of positive integers and the number of negative integers.\n \n In other words, if the number of positive integers in nums is pos and the number of negative integers is neg, then return the maximum of pos and neg.\n \n Note that 0 is neither positive nor negative.\n \n Example 1:\n \n >>> maximumCount(nums = [-2,-1,-1,1,2,3])\n >>> 3\n Explanation: There are 3 positive integers and 3 negative integers. The maximum count among them is 3.\n \n Example 2:\n \n >>> maximumCount(nums = [-3,-2,-1,0,0,1,2])\n >>> 3\n Explanation: There are 2 positive integers and 3 negative integers. The maximum count among them is 3.\n \n Example 3:\n \n >>> maximumCount(nums = [5,20,66,1314])\n >>> 4\n Explanation: There are 4 positive integers and 0 negative integers. The maximum count among them is 4.\n \"\"\"\n"}
{"task_id": "maximal-score-after-applying-k-operations", "prompt": "def maxKelements(nums: List[int], k: int) -> int:\n \"\"\"\n You are given a 0-indexed integer array nums and an integer k. You have a starting score of 0.\n In one operation:\n \n choose an index i such that 0 <= i < nums.length,\n increase your score by nums[i], and\n replace nums[i] with ceil(nums[i] / 3).\n \n Return the maximum possible score you can attain after applying exactly k operations.\n The ceiling function ceil(val) is the least integer greater than or equal to val.\n \n Example 1:\n \n >>> maxKelements(nums = [10,10,10,10,10], k = 5)\n >>> 50\n Explanation: Apply the operation to each array element exactly once. The final score is 10 + 10 + 10 + 10 + 10 = 50.\n \n Example 2:\n \n >>> maxKelements(nums = [1,10,3,3,3], k = 3)\n >>> 17\n Explanation: You can do the following operations:\n Operation 1: Select i = 1, so nums becomes [1,4,3,3,3]. Your score increases by 10.\n Operation 2: Select i = 1, so nums becomes [1,2,3,3,3]. Your score increases by 4.\n Operation 3: Select i = 2, so nums becomes [1,2,1,3,3]. Your score increases by 3.\n The final score is 10 + 4 + 3 = 17.\n \"\"\"\n"}
{"task_id": "make-number-of-distinct-characters-equal", "prompt": "def isItPossible(word1: str, word2: str) -> bool:\n \"\"\"\n You are given two 0-indexed strings word1 and word2.\n A move consists of choosing two indices i and j such that 0 <= i < word1.length and 0 <= j < word2.length and swapping word1[i] with word2[j].\n Return true if it is possible to get the number of distinct characters in word1 and word2 to be equal with exactly one move. Return false otherwise.\n \n Example 1:\n \n >>> isItPossible(word1 = \"ac\", word2 = \"b\")\n >>> false\n Explanation: Any pair of swaps would yield two distinct characters in the first string, and one in the second string.\n \n Example 2:\n \n >>> isItPossible(word1 = \"abcc\", word2 = \"aab\")\n >>> true\n Explanation: We swap index 2 of the first string with index 0 of the second string. The resulting strings are word1 = \"abac\" and word2 = \"cab\", which both have 3 distinct characters.\n \n Example 3:\n \n >>> isItPossible(word1 = \"abcde\", word2 = \"fghij\")\n >>> true\n Explanation: Both resulting strings will have 5 distinct characters, regardless of which indices we swap.\n \"\"\"\n"}
{"task_id": "time-to-cross-a-bridge", "prompt": "def findCrossingTime(n: int, k: int, time: List[List[int]]) -> int:\n \"\"\"\n There are k workers who want to move n boxes from the right (old) warehouse to the left (new) warehouse. You are given the two integers n and k, and a 2D integer array time of size k x 4 where time[i] = [righti, picki, lefti, puti].\n The warehouses are separated by a river and connected by a bridge. Initially, all k workers are waiting on the left side of the bridge. To move the boxes, the ith worker can do the following:\n \n Cross the bridge to the right side in righti minutes.\n Pick a box from the right warehouse in picki minutes.\n Cross the bridge to the left side in lefti minutes.\n Put the box into the left warehouse in puti minutes.\n \n The ith worker is less efficient than the jth worker if either condition is met:\n \n lefti + righti > leftj + rightj\n lefti + righti == leftj + rightj and i > j\n \n The following rules regulate the movement of the workers through the bridge:\n \n Only one worker can use the bridge at a time.\n When the bridge is unused prioritize the least efficient worker (who have picked up the box) on the right side to cross. If not,\u00a0prioritize the least efficient worker on the left side to cross.\n If enough workers have already been dispatched from the left side to pick up all the remaining boxes, no more workers will be sent from the left side.\n \n Return the elapsed minutes at which the last box reaches the left side of the bridge.\n \n Example 1:\n \n >>> findCrossingTime(n = 1, k = 3, time = [[1,1,2,1],[1,1,3,1],[1,1,4,1]])\n >>> 6\n Explanation:\n \n From 0 to 1 minutes: worker 2 crosses the bridge to the right.\n From 1 to 2 minutes: worker 2 picks up a box from the right warehouse.\n From 2 to 6 minutes: worker 2 crosses the bridge to the left.\n From 6 to 7 minutes: worker 2 puts a box at the left warehouse.\n The whole process ends after 7 minutes. We return 6 because the problem asks for the instance of time at which the last worker reaches the left side of the bridge.\n \n \n Example 2:\n \n >>> findCrossingTime(n = 3, k = 2, time = [[1,5,1,8],[10,10,10,10]])\n >>> 37\n Explanation:\n \n \n \n The last box reaches the left side at 37 seconds. Notice, how we do not put the last boxes down, as that would take more time, and they are already on the left with the workers.\n \"\"\"\n"}
{"task_id": "number-of-good-binary-strings", "prompt": "def goodBinaryStrings(minLength: int, maxLength: int, oneGroup: int, zeroGroup: int) -> int:\n \"\"\"\n You are given four integers minLength, maxLength, oneGroup and zeroGroup.\n A binary string is good if it satisfies the following conditions:\n \n The length of the string is in the range [minLength, maxLength].\n The size of each block of consecutive 1's is a multiple of oneGroup.\n \n For example in a binary string 00110111100 sizes of each block of consecutive ones are [2,4].\n \n \n The size of each block of consecutive 0's is a multiple of zeroGroup.\n \n For example, in a binary string 00110111100 sizes of each block of consecutive zeros are [2,1,2].\n \n \n \n Return the number of good binary strings. Since the answer may be too large, return it modulo 109 + 7.\n Note that 0 is considered a multiple of all the numbers.\n \n Example 1:\n \n >>> goodBinaryStrings(minLength = 2, maxLength = 3, oneGroup = 1, zeroGroup = 2)\n >>> 5\n Explanation: There are 5 good binary strings in this example: \"00\", \"11\", \"001\", \"100\", and \"111\".\n It can be proven that there are only 5 good strings satisfying all conditions.\n \n Example 2:\n \n >>> goodBinaryStrings(minLength = 4, maxLength = 4, oneGroup = 4, zeroGroup = 3)\n >>> 1\n Explanation: There is only 1 good binary string in this example: \"1111\".\n It can be proven that there is only 1 good string satisfying all conditions.\n \"\"\"\n"}
{"task_id": "time-taken-to-cross-the-door", "prompt": "def timeTaken(arrival: List[int], state: List[int]) -> List[int]:\n \"\"\"\n There are n persons numbered from 0 to n - 1 and a door. Each person can enter or exit through the door once, taking one second.\n You are given a non-decreasing integer array arrival of size n, where arrival[i] is the arrival time of the ith person at the door. You are also given an array state of size n, where state[i] is 0 if person i wants to enter through the door or 1 if they want to exit through the door.\n If two or more persons want to use the door at the same time, they follow the following rules:\n \n If the door was not used in the previous second, then the person who wants to exit goes first.\n If the door was used in the previous second for entering, the person who wants to enter goes first.\n If the door was used in the previous second for exiting, the person who wants to exit goes first.\n If multiple persons want to go in the same direction, the person with the smallest index goes first.\n \n Return an array answer of size n where answer[i] is the second at which the ith person crosses the door.\n Note that:\n \n Only one person can cross the door at each second.\n A person may arrive at the door and wait without entering or exiting to follow the mentioned rules.\n \n \n Example 1:\n \n >>> timeTaken(arrival = [0,1,1,2,4], state = [0,1,0,0,1])\n >>> [0,3,1,2,4]\n Explanation: At each second we have the following:\n - At t = 0: Person 0 is the only one who wants to enter, so they just enter through the door.\n - At t = 1: Person 1 wants to exit, and person 2 wants to enter. Since the door was used the previous second for entering, person 2 enters.\n - At t = 2: Person 1 still wants to exit, and person 3 wants to enter. Since the door was used the previous second for entering, person 3 enters.\n - At t = 3: Person 1 is the only one who wants to exit, so they just exit through the door.\n - At t = 4: Person 4 is the only one who wants to exit, so they just exit through the door.\n \n Example 2:\n \n >>> timeTaken(arrival = [0,0,0], state = [1,0,1])\n >>> [0,2,1]\n Explanation: At each second we have the following:\n - At t = 0: Person 1 wants to enter while persons 0 and 2 want to exit. Since the door was not used in the previous second, the persons who want to exit get to go first. Since person 0 has a smaller index, they exit first.\n - At t = 1: Person 1 wants to enter, and person 2 wants to exit. Since the door was used in the previous second for exiting, person 2 exits.\n - At t = 2: Person 1 is the only one who wants to enter, so they just enter through the door.\n \"\"\"\n"}
{"task_id": "difference-between-element-sum-and-digit-sum-of-an-array", "prompt": "def differenceOfSum(nums: List[int]) -> int:\n \"\"\"\n You are given a positive integer array nums.\n \n The element sum is the sum of all the elements in nums.\n The digit sum is the sum of all the digits (not necessarily distinct) that appear in nums.\n \n Return the absolute difference between the element sum and digit sum of nums.\n Note that the absolute difference between two integers x and y is defined as |x - y|.\n \n Example 1:\n \n >>> differenceOfSum(nums = [1,15,6,3])\n >>> 9\n Explanation:\n The element sum of nums is 1 + 15 + 6 + 3 = 25.\n The digit sum of nums is 1 + 1 + 5 + 6 + 3 = 16.\n The absolute difference between the element sum and digit sum is |25 - 16| = 9.\n \n Example 2:\n \n >>> differenceOfSum(nums = [1,2,3,4])\n >>> 0\n Explanation:\n The element sum of nums is 1 + 2 + 3 + 4 = 10.\n The digit sum of nums is 1 + 2 + 3 + 4 = 10.\n The absolute difference between the element sum and digit sum is |10 - 10| = 0.\n \"\"\"\n"}
{"task_id": "increment-submatrices-by-one", "prompt": "def rangeAddQueries(n: int, queries: List[List[int]]) -> List[List[int]]:\n \"\"\"\n You are given a positive integer n, indicating that we initially have an n x n\u00a00-indexed integer matrix mat filled with zeroes.\n You are also given a 2D integer array query. For each query[i] = [row1i, col1i, row2i, col2i], you should do the following operation:\n \n Add 1 to every element in the submatrix with the top left corner (row1i, col1i) and the bottom right corner (row2i, col2i). That is, add 1 to mat[x][y] for all row1i <= x <= row2i and col1i <= y <= col2i.\n \n Return the matrix mat after performing every query.\n \n Example 1:\n \n \n >>> rangeAddQueries(n = 3, queries = [[1,1,2,2],[0,0,1,1]])\n >>> [[1,1,0],[1,2,1],[0,1,1]]\n Explanation: The diagram above shows the initial matrix, the matrix after the first query, and the matrix after the second query.\n - In the first query, we add 1 to every element in the submatrix with the top left corner (1, 1) and bottom right corner (2, 2).\n - In the second query, we add 1 to every element in the submatrix with the top left corner (0, 0) and bottom right corner (1, 1).\n \n Example 2:\n \n \n >>> rangeAddQueries(n = 2, queries = [[0,0,1,1]])\n >>> [[1,1],[1,1]]\n Explanation: The diagram above shows the initial matrix and the matrix after the first query.\n - In the first query we add 1 to every element in the matrix.\n \"\"\"\n"}
{"task_id": "count-the-number-of-good-subarrays", "prompt": "def countGood(nums: List[int], k: int) -> int:\n \"\"\"\n Given an integer array nums and an integer k, return the number of good subarrays of nums.\n A subarray arr is good if there are at least k pairs of indices (i, j) such that i < j and arr[i] == arr[j].\n A subarray is a contiguous non-empty sequence of elements within an array.\n \n Example 1:\n \n >>> countGood(nums = [1,1,1,1,1], k = 10)\n >>> 1\n Explanation: The only good subarray is the array nums itself.\n \n Example 2:\n \n >>> countGood(nums = [3,1,4,3,2,2,4], k = 2)\n >>> 4\n Explanation: There are 4 different good subarrays:\n - [3,1,4,3,2,2] that has 2 pairs.\n - [3,1,4,3,2,2,4] that has 3 pairs.\n - [1,4,3,2,2,4] that has 2 pairs.\n - [4,3,2,2,4] that has 2 pairs.\n \"\"\"\n"}
{"task_id": "difference-between-maximum-and-minimum-price-sum", "prompt": "def maxOutput(n: int, edges: List[List[int]], price: List[int]) -> int:\n \"\"\"\n There exists an undirected and initially unrooted tree with n nodes indexed from 0 to n - 1. You are given the integer n and a 2D integer array edges of length n - 1, where edges[i] = [ai, bi] indicates that there is an edge between nodes ai and bi in the tree.\n Each node has an associated price. You are given an integer array price, where price[i] is the price of the ith node.\n The price sum of a given path is the sum of the prices of all nodes lying on that path.\n The tree can be rooted at any node root of your choice. The incurred cost after choosing root is the difference between the maximum and minimum price sum amongst all paths starting at root.\n Return the maximum possible cost amongst all possible root choices.\n \n Example 1:\n \n \n >>> maxOutput(n = 6, edges = [[0,1],[1,2],[1,3],[3,4],[3,5]], price = [9,8,7,6,10,5])\n >>> 24\n Explanation: The diagram above denotes the tree after rooting it at node 2. The first part (colored in red) shows the path with the maximum price sum. The second part (colored in blue) shows the path with the minimum price sum.\n - The first path contains nodes [2,1,3,4]: the prices are [7,8,6,10], and the sum of the prices is 31.\n - The second path contains the node [2] with the price [7].\n The difference between the maximum and minimum price sum is 24. It can be proved that 24 is the maximum cost.\n \n Example 2:\n \n \n >>> maxOutput(n = 3, edges = [[0,1],[1,2]], price = [1,1,1])\n >>> 2\n Explanation: The diagram above denotes the tree after rooting it at node 0. The first part (colored in red) shows the path with the maximum price sum. The second part (colored in blue) shows the path with the minimum price sum.\n - The first path contains nodes [0,1,2]: the prices are [1,1,1], and the sum of the prices is 3.\n - The second path contains node [0] with a price [1].\n The difference between the maximum and minimum price sum is 2. It can be proved that 2 is the maximum cost.\n \"\"\"\n"}
{"task_id": "minimum-common-value", "prompt": "def getCommon(nums1: List[int], nums2: List[int]) -> int:\n \"\"\"\n Given two integer arrays nums1 and nums2, sorted in non-decreasing order, return the minimum integer common to both arrays. If there is no common integer amongst nums1 and nums2, return -1.\n Note that an integer is said to be common to nums1 and nums2 if both arrays have at least one occurrence of that integer.\n \n Example 1:\n \n >>> getCommon(nums1 = [1,2,3], nums2 = [2,4])\n >>> 2\n Explanation: The smallest element common to both arrays is 2, so we return 2.\n \n Example 2:\n \n >>> getCommon(nums1 = [1,2,3,6], nums2 = [2,3,4,5])\n >>> 2\n Explanation: There are two common elements in the array 2 and 3 out of which 2 is the smallest, so 2 is returned.\n \"\"\"\n"}
{"task_id": "minimum-operations-to-make-array-equal-ii", "prompt": "def minOperations(nums1: List[int], nums2: List[int], k: int) -> int:\n \"\"\"\n You are given two integer arrays nums1 and nums2 of equal length n and an integer k. You can perform the following operation on nums1:\n \n Choose two indexes i and j and increment nums1[i] by k and decrement nums1[j] by k. In other words, nums1[i] = nums1[i] + k and nums1[j] = nums1[j] - k.\n \n nums1 is said to be equal to nums2 if for all indices i such that 0 <= i < n, nums1[i] == nums2[i].\n Return the minimum number of operations required to make nums1 equal to nums2. If it is impossible to make them equal, return -1.\n \n Example 1:\n \n >>> minOperations(nums1 = [4,3,1,4], nums2 = [1,3,7,1], k = 3)\n >>> 2\n Explanation: In 2 operations, we can transform nums1 to nums2.\n 1st operation: i = 2, j = 0. After applying the operation, nums1 = [1,3,4,4].\n 2nd operation: i = 2, j = 3. After applying the operation, nums1 = [1,3,7,1].\n One can prove that it is impossible to make arrays equal in fewer operations.\n Example 2:\n \n >>> minOperations(nums1 = [3,8,5,2], nums2 = [2,4,1,6], k = 1)\n >>> -1\n Explanation: It can be proved that it is impossible to make the two arrays equal.\n \"\"\"\n"}
{"task_id": "maximum-subsequence-score", "prompt": "def maxScore(nums1: List[int], nums2: List[int], k: int) -> int:\n \"\"\"\n You are given two 0-indexed integer arrays nums1 and nums2 of equal length n and a positive integer k. You must choose a subsequence of indices from nums1 of length k.\n For chosen indices i0, i1, ..., ik - 1, your score is defined as:\n \n The sum of the selected elements from nums1 multiplied with the minimum of the selected elements from nums2.\n It can defined simply as: (nums1[i0] + nums1[i1] +...+ nums1[ik - 1]) * min(nums2[i0] , nums2[i1], ... ,nums2[ik - 1]).\n \n Return the maximum possible score.\n A subsequence of indices of an array is a set that can be derived from the set {0, 1, ..., n-1} by deleting some or no elements.\n \n Example 1:\n \n >>> maxScore(nums1 = [1,3,3,2], nums2 = [2,1,3,4], k = 3)\n >>> 12\n Explanation:\n The four possible subsequence scores are:\n - We choose the indices 0, 1, and 2 with score = (1+3+3) * min(2,1,3) = 7.\n - We choose the indices 0, 1, and 3 with score = (1+3+2) * min(2,1,4) = 6.\n - We choose the indices 0, 2, and 3 with score = (1+3+2) * min(2,3,4) = 12.\n - We choose the indices 1, 2, and 3 with score = (3+3+2) * min(1,3,4) = 8.\n Therefore, we return the max score, which is 12.\n \n Example 2:\n \n >>> maxScore(nums1 = [4,2,3,1,1], nums2 = [7,5,10,9,6], k = 1)\n >>> 30\n Explanation:\n Choosing index 2 is optimal: nums1[2] * nums2[2] = 3 * 10 = 30 is the maximum possible score.\n \"\"\"\n"}
{"task_id": "check-if-point-is-reachable", "prompt": "def isReachable(targetX: int, targetY: int) -> bool:\n \"\"\"\n There exists an infinitely large grid. You are currently at point (1, 1), and you need to reach the point (targetX, targetY) using a finite number of steps.\n In one step, you can move from point (x, y) to any one of the following points:\n \n (x, y - x)\n (x - y, y)\n (2 * x, y)\n (x, 2 * y)\n \n Given two integers targetX and targetY representing the X-coordinate and Y-coordinate of your final position, return true if you can reach the point from (1, 1) using some number of steps, and false otherwise.\n \n Example 1:\n \n >>> isReachable(targetX = 6, targetY = 9)\n >>> false\n Explanation: It is impossible to reach (6,9) from (1,1) using any sequence of moves, so false is returned.\n \n Example 2:\n \n >>> isReachable(targetX = 4, targetY = 7)\n >>> true\n Explanation: You can follow the path (1,1) -> (1,2) -> (1,4) -> (1,8) -> (1,7) -> (2,7) -> (4,7).\n \"\"\"\n"}
{"task_id": "alternating-digit-sum", "prompt": "def alternateDigitSum(n: int) -> int:\n \"\"\"\n You are given a positive integer n. Each digit of n has a sign according to the following rules:\n \n The most significant digit is assigned a positive sign.\n Each other digit has an opposite sign to its adjacent digits.\n \n Return the sum of all digits with their corresponding sign.\n \n Example 1:\n \n >>> alternateDigitSum(n = 521)\n >>> 4\n Explanation: (+5) + (-2) + (+1) = 4.\n \n Example 2:\n \n >>> alternateDigitSum(n = 111)\n >>> 1\n Explanation: (+1) + (-1) + (+1) = 1.\n \n Example 3:\n \n >>> alternateDigitSum(n = 886996)\n >>> 0\n Explanation: (+8) + (-8) + (+6) + (-9) + (+9) + (-6) = 0.\n \"\"\"\n"}
{"task_id": "sort-the-students-by-their-kth-score", "prompt": "def sortTheStudents(score: List[List[int]], k: int) -> List[List[int]]:\n \"\"\"\n There is a class with m students and n exams. You are given a 0-indexed m x n integer matrix score, where each row represents one student and score[i][j] denotes the score the ith student got in the jth exam. The matrix score contains distinct integers only.\n You are also given an integer k. Sort the students (i.e., the rows of the matrix) by their scores in the kth\u00a0(0-indexed) exam from the highest to the lowest.\n Return the matrix after sorting it.\n \n Example 1:\n \n \n >>> sortTheStudents(score = [[10,6,9,1],[7,5,11,2],[4,8,3,15]], k = 2)\n >>> [[7,5,11,2],[10,6,9,1],[4,8,3,15]]\n Explanation: In the above diagram, S denotes the student, while E denotes the exam.\n - The student with index 1 scored 11 in exam 2, which is the highest score, so they got first place.\n - The student with index 0 scored 9 in exam 2, which is the second highest score, so they got second place.\n - The student with index 2 scored 3 in exam 2, which is the lowest score, so they got third place.\n \n Example 2:\n \n \n >>> sortTheStudents(score = [[3,4],[5,6]], k = 0)\n >>> [[5,6],[3,4]]\n Explanation: In the above diagram, S denotes the student, while E denotes the exam.\n - The student with index 1 scored 5 in exam 0, which is the highest score, so they got first place.\n - The student with index 0 scored 3 in exam 0, which is the lowest score, so they got second place.\n \"\"\"\n"}
{"task_id": "apply-bitwise-operations-to-make-strings-equal", "prompt": "def makeStringsEqual(s: str, target: str) -> bool:\n \"\"\"\n You are given two 0-indexed binary strings s and target of the same length n. You can do the following operation on s any number of times:\n \n Choose two different indices i and j where 0 <= i, j < n.\n Simultaneously, replace s[i] with (s[i] OR s[j]) and s[j] with (s[i] XOR s[j]).\n \n For example, if s = \"0110\", you can choose i = 0 and j = 2, then simultaneously replace s[0] with (s[0] OR s[2] = 0 OR 1 = 1), and s[2] with (s[0] XOR s[2] = 0 XOR 1 = 1), so we will have s = \"1110\".\n Return true if you can make the string s equal to target, or false otherwise.\n \n Example 1:\n \n >>> makeStringsEqual(s = \"1010\", target = \"0110\")\n >>> true\n Explanation: We can do the following operations:\n - Choose i = 2 and j = 0. We have now s = \"0010\".\n - Choose i = 2 and j = 1. We have now s = \"0110\".\n Since we can make s equal to target, we return true.\n \n Example 2:\n \n >>> makeStringsEqual(s = \"11\", target = \"00\")\n >>> false\n Explanation: It is not possible to make s equal to target with any number of operations.\n \"\"\"\n"}
{"task_id": "minimum-cost-to-split-an-array", "prompt": "def minCost(nums: List[int], k: int) -> int:\n \"\"\"\n You are given an integer array nums and an integer k.\n Split the array into some number of non-empty subarrays. The cost of a split is the sum of the importance value of each subarray in the split.\n Let trimmed(subarray) be the version of the subarray where all numbers which appear only once are removed.\n \n For example, trimmed([3,1,2,4,3,4]) = [3,4,3,4].\n \n The importance value of a subarray is k + trimmed(subarray).length.\n \n For example, if a subarray is [1,2,3,3,3,4,4], then trimmed([1,2,3,3,3,4,4]) = [3,3,3,4,4].The importance value of this subarray will be k + 5.\n \n Return the minimum possible cost of a split of nums.\n A subarray is a contiguous non-empty sequence of elements within an array.\n \n Example 1:\n \n >>> minCost(nums = [1,2,1,2,1,3,3], k = 2)\n >>> 8\n Explanation: We split nums to have two subarrays: [1,2], [1,2,1,3,3].\n The importance value of [1,2] is 2 + (0) = 2.\n The importance value of [1,2,1,3,3] is 2 + (2 + 2) = 6.\n The cost of the split is 2 + 6 = 8. It can be shown that this is the minimum possible cost among all the possible splits.\n \n Example 2:\n \n >>> minCost(nums = [1,2,1,2,1], k = 2)\n >>> 6\n Explanation: We split nums to have two subarrays: [1,2], [1,2,1].\n The importance value of [1,2] is 2 + (0) = 2.\n The importance value of [1,2,1] is 2 + (2) = 4.\n The cost of the split is 2 + 4 = 6. It can be shown that this is the minimum possible cost among all the possible splits.\n \n Example 3:\n \n >>> minCost(nums = [1,2,1,2,1], k = 5)\n >>> 10\n Explanation: We split nums to have one subarray: [1,2,1,2,1].\n The importance value of [1,2,1,2,1] is 5 + (3 + 2) = 10.\n The cost of the split is 10. It can be shown that this is the minimum possible cost among all the possible splits.\n \"\"\"\n"}
{"task_id": "maximum-price-to-fill-a-bag", "prompt": "def maxPrice(items: List[List[int]], capacity: int) -> float:\n \"\"\"\n You are given a 2D integer array items where items[i] = [pricei, weighti] denotes the price and weight of the ith item, respectively.\n You are also given a positive integer capacity.\n Each item can be divided into two items with ratios part1 and part2, where part1 + part2 == 1.\n \n The weight of the first item is weighti * part1 and the price of the first item is pricei * part1.\n Similarly, the weight of the second item is weighti * part2 and the price of the second item is pricei * part2.\n \n Return the maximum total price to fill a bag of capacity capacity with given items. If it is impossible to fill a bag return -1. Answers within 10-5 of the actual answer will be considered accepted.\n \n Example 1:\n \n >>> maxPrice(items = [[50,1],[10,8]], capacity = 5)\n >>> 55.00000\n Explanation:\n We divide the 2nd item into two parts with part1 = 0.5 and part2 = 0.5.\n The price and weight of the 1st item are 5, 4. And similarly, the price and the weight of the 2nd item are 5, 4.\n The array items after operation becomes [[50,1],[5,4],[5,4]].\n To fill a bag with capacity 5 we take the 1st element with a price of 50 and the 2nd element with a price of 5.\n It can be proved that 55.0 is the maximum total price that we can achieve.\n \n Example 2:\n \n >>> maxPrice(items = [[100,30]], capacity = 50)\n >>> -1.00000\n Explanation: It is impossible to fill a bag with the given item.\n \"\"\"\n"}
{"task_id": "count-distinct-numbers-on-board", "prompt": "def distinctIntegers(n: int) -> int:\n \"\"\"\n You are given a positive integer n, that is initially placed on a board. Every day, for 109 days, you perform the following procedure:\n \n For each number x present on the board, find all numbers 1 <= i <= n such that x % i == 1.\n Then, place those numbers on the board.\n \n Return the number of distinct integers present on the board after 109 days have elapsed.\n Note:\n \n Once a number is placed on the board, it will remain on it until the end.\n %\u00a0stands\u00a0for the modulo operation. For example,\u00a014 % 3 is 2.\n \n \n Example 1:\n \n >>> distinctIntegers(n = 5)\n >>> 4\n Explanation: Initially, 5 is present on the board.\n The next day, 2 and 4 will be added since 5 % 2 == 1 and 5 % 4 == 1.\n After that day, 3 will be added to the board because 4 % 3 == 1.\n At the end of a billion days, the distinct numbers on the board will be 2, 3, 4, and 5.\n \n Example 2:\n \n >>> distinctIntegers(n = 3)\n >>> 2\n Explanation:\n Since 3 % 2 == 1, 2 will be added to the board.\n After a billion days, the only two distinct numbers on the board are 2 and 3.\n \"\"\"\n"}
{"task_id": "put-marbles-in-bags", "prompt": "def putMarbles(weights: List[int], k: int) -> int:\n \"\"\"\n You have k bags. You are given a 0-indexed integer array weights where weights[i] is the weight of the ith marble. You are also given the integer k.\n Divide the marbles into the k bags according to the following rules:\n \n No bag is empty.\n If the ith marble and jth marble are in a bag, then all marbles with an index between the ith and jth indices should also be in that same bag.\n If a bag consists of all the marbles with an index from i to j inclusively, then the cost of the bag is weights[i] + weights[j].\n \n The score after distributing the marbles is the sum of the costs of all the k bags.\n Return the difference between the maximum and minimum scores among marble distributions.\n \n Example 1:\n \n >>> putMarbles(weights = [1,3,5,1], k = 2)\n >>> 4\n Explanation:\n The distribution [1],[3,5,1] results in the minimal score of (1+1) + (3+1) = 6.\n The distribution [1,3],[5,1], results in the maximal score of (1+3) + (5+1) = 10.\n Thus, we return their difference 10 - 6 = 4.\n \n Example 2:\n \n >>> putMarbles(weights = [1, 3], k = 2)\n >>> 0\n Explanation: The only distribution possible is [1],[3].\n Since both the maximal and minimal score are the same, we return 0.\n \"\"\"\n"}
{"task_id": "count-increasing-quadruplets", "prompt": "def countQuadruplets(nums: List[int]) -> int:\n \"\"\"\n Given a 0-indexed integer array nums of size n containing all numbers from 1 to n, return the number of increasing quadruplets.\n A quadruplet (i, j, k, l) is increasing if:\n \n 0 <= i < j < k < l < n, and\n nums[i] < nums[k] < nums[j] < nums[l].\n \n \n Example 1:\n \n >>> countQuadruplets(nums = [1,3,2,4,5])\n >>> 2\n Explanation:\n - When i = 0, j = 1, k = 2, and l = 3, nums[i] < nums[k] < nums[j] < nums[l].\n - When i = 0, j = 1, k = 2, and l = 4, nums[i] < nums[k] < nums[j] < nums[l].\n There are no other quadruplets, so we return 2.\n \n Example 2:\n \n >>> countQuadruplets(nums = [1,2,3,4])\n >>> 0\n Explanation: There exists only one quadruplet with i = 0, j = 1, k = 2, l = 3, but since nums[j] < nums[k], we return 0.\n \"\"\"\n"}
{"task_id": "separate-the-digits-in-an-array", "prompt": "def separateDigits(nums: List[int]) -> List[int]:\n \"\"\"\n Given an array of positive integers nums, return an array answer that consists of the digits of each integer in nums after separating them in the same order they appear in nums.\n To separate the digits of an integer is to get all the digits it has in the same order.\n \n For example, for the integer 10921, the separation of its digits is [1,0,9,2,1].\n \n \n Example 1:\n \n >>> separateDigits(nums = [13,25,83,77])\n >>> [1,3,2,5,8,3,7,7]\n Explanation:\n - The separation of 13 is [1,3].\n - The separation of 25 is [2,5].\n - The separation of 83 is [8,3].\n - The separation of 77 is [7,7].\n answer = [1,3,2,5,8,3,7,7]. Note that answer contains the separations in the same order.\n \n Example 2:\n \n >>> separateDigits(nums = [7,1,3,9])\n >>> [7,1,3,9]\n Explanation: The separation of each integer in nums is itself.\n answer = [7,1,3,9].\n \"\"\"\n"}
{"task_id": "maximum-number-of-integers-to-choose-from-a-range-i", "prompt": "def maxCount(banned: List[int], n: int, maxSum: int) -> int:\n \"\"\"\n You are given an integer array banned and two integers n and maxSum. You are choosing some number of integers following the below rules:\n \n The chosen integers have to be in the range [1, n].\n Each integer can be chosen at most once.\n The chosen integers should not be in the array banned.\n The sum of the chosen integers should not exceed maxSum.\n \n Return the maximum number of integers you can choose following the mentioned rules.\n \n Example 1:\n \n >>> maxCount(banned = [1,6,5], n = 5, maxSum = 6)\n >>> 2\n Explanation: You can choose the integers 2 and 4.\n 2 and 4 are from the range [1, 5], both did not appear in banned, and their sum is 6, which did not exceed maxSum.\n \n Example 2:\n \n >>> maxCount(banned = [1,2,3,4,5,6,7], n = 8, maxSum = 1)\n >>> 0\n Explanation: You cannot choose any integer while following the mentioned conditions.\n \n Example 3:\n \n >>> maxCount(banned = [11], n = 7, maxSum = 50)\n >>> 7\n Explanation: You can choose the integers 1, 2, 3, 4, 5, 6, and 7.\n They are from the range [1, 7], all did not appear in banned, and their sum is 28, which did not exceed maxSum.\n \"\"\"\n"}
{"task_id": "maximize-win-from-two-segments", "prompt": "def maximizeWin(prizePositions: List[int], k: int) -> int:\n \"\"\"\n There are some prizes on the X-axis. You are given an integer array prizePositions that is sorted in non-decreasing order, where prizePositions[i] is the position of the ith prize. There could be different prizes at the same position on the line. You are also given an integer k.\n You are allowed to select two segments with integer endpoints. The length of each segment must be k. You will collect all prizes whose position falls within at least one of the two selected segments (including the endpoints of the segments). The two selected segments may intersect.\n \n For example if k = 2, you can choose segments [1, 3] and [2, 4], and you will win any prize i that satisfies 1 <= prizePositions[i] <= 3 or 2 <= prizePositions[i] <= 4.\n \n Return the maximum number of prizes you can win if you choose the two segments optimally.\n \n Example 1:\n \n >>> maximizeWin(prizePositions = [1,1,2,2,3,3,5], k = 2)\n >>> 7\n Explanation: In this example, you can win all 7 prizes by selecting two segments [1, 3] and [3, 5].\n \n Example 2:\n \n >>> maximizeWin(prizePositions = [1,2,3,4], k = 0)\n >>> 2\n Explanation: For this example, one choice for the segments is [3, 3] and [4, 4], and you will be able to get 2 prizes.\n \"\"\"\n"}
{"task_id": "disconnect-path-in-a-binary-matrix-by-at-most-one-flip", "prompt": "def isPossibleToCutPath(grid: List[List[int]]) -> bool:\n \"\"\"\n You are given a 0-indexed m x n binary matrix grid. You can move from a cell (row, col) to any of the cells (row + 1, col) or (row, col + 1) that has the value 1.\u00a0The matrix is disconnected if there is no path from (0, 0) to (m - 1, n - 1).\n You can flip the value of at most one (possibly none) cell. You cannot flip the cells (0, 0) and (m - 1, n - 1).\n Return true if it is possible to make the matrix disconnect or false otherwise.\n Note that flipping a cell changes its value from 0 to 1 or from 1 to 0.\n \n Example 1:\n \n \n >>> isPossibleToCutPath(grid = [[1,1,1],[1,0,0],[1,1,1]])\n >>> true\n Explanation: We can change the cell shown in the diagram above. There is no path from (0, 0) to (2, 2) in the resulting grid.\n \n Example 2:\n \n \n >>> isPossibleToCutPath(grid = [[1,1,1],[1,0,1],[1,1,1]])\n >>> false\n Explanation: It is not possible to change at most one cell such that there is not path from (0, 0) to (2, 2).\n \"\"\"\n"}
{"task_id": "maximum-number-of-integers-to-choose-from-a-range-ii", "prompt": "def maxCount(banned: List[int], n: int, maxSum: int) -> int:\n \"\"\"\n You are given an integer array banned and two integers n and maxSum. You are choosing some number of integers following the below rules:\n \n The chosen integers have to be in the range [1, n].\n Each integer can be chosen at most once.\n The chosen integers should not be in the array banned.\n The sum of the chosen integers should not exceed maxSum.\n \n Return the maximum number of integers you can choose following the mentioned rules.\n \n Example 1:\n \n >>> maxCount(banned = [1,4,6], n = 6, maxSum = 4)\n >>> 1\n Explanation: You can choose the integer 3.\n 3 is in the range [1, 6], and do not appear in banned. The sum of the chosen integers is 3, which does not exceed maxSum.\n \n Example 2:\n \n >>> maxCount(banned = [4,3,5,6], n = 7, maxSum = 18)\n >>> 3\n Explanation: You can choose the integers 1, 2, and 7.\n All these integers are in the range [1, 7], all do not appear in banned, and their sum is 10, which does not exceed maxSum.\n \"\"\"\n"}
{"task_id": "take-gifts-from-the-richest-pile", "prompt": "def pickGifts(gifts: List[int], k: int) -> int:\n \"\"\"\n You are given an integer array gifts denoting the number of gifts in various piles. Every second, you do the following:\n \n Choose the pile with the maximum number of gifts.\n If there is more than one pile with the maximum number of gifts, choose any.\n Reduce the number of gifts in the pile to the floor of the square root of the original number of gifts in the pile.\n \n Return the number of gifts remaining after k seconds.\n \n Example 1:\n \n >>> pickGifts(gifts = [25,64,9,4,100], k = 4)\n >>> 29\n Explanation:\n The gifts are taken in the following way:\n - In the first second, the last pile is chosen and 10 gifts are left behind.\n - Then the second pile is chosen and 8 gifts are left behind.\n - After that the first pile is chosen and 5 gifts are left behind.\n - Finally, the last pile is chosen again and 3 gifts are left behind.\n The final remaining gifts are [5,8,9,4,3], so the total number of gifts remaining is 29.\n \n Example 2:\n \n >>> pickGifts(gifts = [1,1,1,1], k = 4)\n >>> 4\n Explanation:\n In this case, regardless which pile you choose, you have to leave behind 1 gift in each pile.\n That is, you can't take any pile with you.\n So, the total gifts remaining are 4.\n \"\"\"\n"}
{"task_id": "count-vowel-strings-in-ranges", "prompt": "def vowelStrings(words: List[str], queries: List[List[int]]) -> List[int]:\n \"\"\"\n You are given a 0-indexed array of strings words and a 2D array of integers queries.\n Each query queries[i] = [li, ri] asks us to find the number of strings present at the indices ranging from li to ri (both inclusive) of words that start and end with a vowel.\n Return an array ans of size queries.length, where ans[i] is the answer to the ith query.\n Note that the vowel letters are 'a', 'e', 'i', 'o', and 'u'.\n \n Example 1:\n \n >>> vowelStrings(words = [\"aba\",\"bcb\",\"ece\",\"aa\",\"e\"], queries = [[0,2],[1,4],[1,1]])\n >>> [2,3,0]\n Explanation: The strings starting and ending with a vowel are \"aba\", \"ece\", \"aa\" and \"e\".\n The answer to the query [0,2] is 2 (strings \"aba\" and \"ece\").\n to query [1,4] is 3 (strings \"ece\", \"aa\", \"e\").\n to query [1,1] is 0.\n We return [2,3,0].\n \n Example 2:\n \n >>> vowelStrings(words = [\"a\",\"e\",\"i\"], queries = [[0,2],[0,1],[2,2]])\n >>> [3,2,1]\n Explanation: Every string satisfies the conditions, so we return [3,2,1].\n \"\"\"\n"}
{"task_id": "house-robber-iv", "prompt": "def minCapability(nums: List[int], k: int) -> int:\n \"\"\"\n There are several consecutive houses along a street, each of which has some money inside. There is also a robber, who wants to steal money from the homes, but he refuses to steal from adjacent homes.\n The capability of the robber is the maximum amount of money he steals from one house of all the houses he robbed.\n You are given an integer array nums representing how much money is stashed in each house. More formally, the ith house from the left has nums[i] dollars.\n You are also given an integer k, representing the minimum number of houses the robber will steal from. It is always possible to steal at least k houses.\n Return the minimum capability of the robber out of all the possible ways to steal at least k houses.\n \n Example 1:\n \n >>> minCapability(nums = [2,3,5,9], k = 2)\n >>> 5\n Explanation:\n There are three ways to rob at least 2 houses:\n - Rob the houses at indices 0 and 2. Capability is max(nums[0], nums[2]) = 5.\n - Rob the houses at indices 0 and 3. Capability is max(nums[0], nums[3]) = 9.\n - Rob the houses at indices 1 and 3. Capability is max(nums[1], nums[3]) = 9.\n Therefore, we return min(5, 9, 9) = 5.\n \n Example 2:\n \n >>> minCapability(nums = [2,7,9,3,1], k = 2)\n >>> 2\n Explanation: There are 7 ways to rob the houses. The way which leads to minimum capability is to rob the house at index 0 and 4. Return max(nums[0], nums[4]) = 2.\n \"\"\"\n"}
{"task_id": "rearranging-fruits", "prompt": "def minCost(basket1: List[int], basket2: List[int]) -> int:\n \"\"\"\n You have two fruit baskets containing n fruits each. You are given two 0-indexed integer arrays basket1 and basket2 representing the cost of fruit in each basket. You want to make both baskets equal. To do so, you can use the following operation as many times as you want:\n \n Chose two indices i and j, and swap the ith\u00a0fruit of basket1 with the jth\u00a0fruit of basket2.\n The cost of the swap is min(basket1[i],basket2[j]).\n \n Two baskets are considered equal if sorting them according to the fruit cost makes them exactly the same baskets.\n Return the minimum cost to make both the baskets equal or -1 if impossible.\n \n Example 1:\n \n >>> minCost(basket1 = [4,2,2,2], basket2 = [1,4,1,2])\n >>> 1\n Explanation: Swap index 1 of basket1 with index 0 of basket2, which has cost 1. Now basket1 = [4,1,2,2] and basket2 = [2,4,1,2]. Rearranging both the arrays makes them equal.\n \n Example 2:\n \n >>> minCost(basket1 = [2,3,4,1], basket2 = [3,2,5,1])\n >>> -1\n Explanation: It can be shown that it is impossible to make both the baskets equal.\n \"\"\"\n"}
{"task_id": "find-the-array-concatenation-value", "prompt": "def findTheArrayConcVal(nums: List[int]) -> int:\n \"\"\"\n You are given a 0-indexed integer array nums.\n The concatenation of two numbers is the number formed by concatenating their numerals.\n \n For example, the concatenation of 15, 49 is 1549.\n \n The concatenation value of nums is initially equal to 0. Perform this operation until nums becomes empty:\n \n If nums has a size greater than one, add the value of the concatenation of the first and the last element to the concatenation value of nums, and remove those two elements from nums. For example, if the nums was [1, 2, 4, 5, 6], add 16 to the concatenation value.\n If only one element exists in nums, add its value to the concatenation value of nums, then remove it.\n \n Return the concatenation value of nums.\n \n Example 1:\n \n >>> findTheArrayConcVal(nums = [7,52,2,4])\n >>> 596\n Explanation: Before performing any operation, nums is [7,52,2,4] and concatenation value is 0.\n - In the first operation:\n We pick the first element, 7, and the last element, 4.\n Their concatenation is 74, and we add it to the concatenation value, so it becomes equal to 74.\n Then we delete them from nums, so nums becomes equal to [52,2].\n - In the second operation:\n We pick the first element, 52, and the last element, 2.\n Their concatenation is 522, and we add it to the concatenation value, so it becomes equal to 596.\n Then we delete them from the nums, so nums becomes empty.\n Since the concatenation value is 596 so the answer is 596.\n \n Example 2:\n \n >>> findTheArrayConcVal(nums = [5,14,13,8,12])\n >>> 673\n Explanation: Before performing any operation, nums is [5,14,13,8,12] and concatenation value is 0.\n - In the first operation:\n We pick the first element, 5, and the last element, 12.\n Their concatenation is 512, and we add it to the concatenation value, so it becomes equal to 512.\n Then we delete them from the nums, so nums becomes equal to [14,13,8].\n - In the second operation:\n We pick the first element, 14, and the last element, 8.\n Their concatenation is 148, and we add it to the concatenation value, so it becomes equal to 660.\n Then we delete them from the nums, so nums becomes equal to [13].\n - In the third operation:\n nums has only one element, so we pick 13 and add it to the concatenation value, so it becomes equal to 673.\n Then we delete it from nums, so nums become empty.\n Since the concatenation value is 673 so the answer is 673.\n \"\"\"\n"}
{"task_id": "count-the-number-of-fair-pairs", "prompt": "def countFairPairs(nums: List[int], lower: int, upper: int) -> int:\n \"\"\"\n Given a 0-indexed integer array nums of size n and two integers lower and upper, return the number of fair pairs.\n A pair (i, j) is fair if:\n \n 0 <= i < j < n, and\n lower <= nums[i] + nums[j] <= upper\n \n \n Example 1:\n \n >>> countFairPairs(nums = [0,1,7,4,4,5], lower = 3, upper = 6)\n >>> 6\n Explanation: There are 6 fair pairs: (0,3), (0,4), (0,5), (1,3), (1,4), and (1,5).\n \n Example 2:\n \n >>> countFairPairs(nums = [1,7,9,2,5], lower = 11, upper = 11)\n >>> 1\n Explanation: There is a single fair pair: (2,3).\n \"\"\"\n"}
{"task_id": "substring-xor-queries", "prompt": "def substringXorQueries(s: str, queries: List[List[int]]) -> List[List[int]]:\n \"\"\"\n You are given a binary string s, and a 2D integer array queries where queries[i] = [firsti, secondi].\n For the ith query, find the shortest substring of s whose decimal value, val, yields secondi when bitwise XORed with firsti. In other words, val ^ firsti == secondi.\n The answer to the ith query is the endpoints (0-indexed) of the substring [lefti, righti] or [-1, -1] if no such substring exists. If there are multiple answers, choose the one with the minimum lefti.\n Return an array ans where ans[i] = [lefti, righti] is the answer to the ith query.\n A substring is a contiguous non-empty sequence of characters within a string.\n \n Example 1:\n \n >>> substringXorQueries(s = \"101101\", queries = [[0,5],[1,2]])\n >>> [[0,2],[2,3]]\n Explanation: For the first query the substring in range [0,2] is \"101\" which has a decimal value of 5, and 5 ^ 0 = 5, hence the answer to the first query is [0,2]. In the second query, the substring in range [2,3] is \"11\", and has a decimal value of 3, and 3 ^ 1 = 2.\u00a0So, [2,3] is returned for the second query.\n \n \n Example 2:\n \n >>> substringXorQueries(s = \"0101\", queries = [[12,8]])\n >>> [[-1,-1]]\n Explanation: In this example there is no substring that answers the query, hence [-1,-1] is returned.\n \n Example 3:\n \n >>> substringXorQueries(s = \"1\", queries = [[4,5]])\n >>> [[0,0]]\n Explanation: For this example, the substring in range [0,0] has a decimal value of 1, and 1 ^ 4 = 5. So, the answer is [0,0].\n \"\"\"\n"}
{"task_id": "subsequence-with-the-minimum-score", "prompt": "def minimumScore(s: str, t: str) -> int:\n \"\"\"\n You are given two strings s and t.\n You are allowed to remove any number of characters from the string t.\n The score of the string is 0 if no characters are removed from the string t, otherwise:\n \n Let left be the minimum index among all removed characters.\n Let right be the maximum index among all removed characters.\n \n Then the score of the string is right - left + 1.\n Return the minimum possible score to make t\u00a0a subsequence of s.\n A subsequence of a string is a new string that is formed from the original string by deleting some (can be none) of the characters without disturbing the relative positions of the remaining characters. (i.e., \"ace\" is a subsequence of \"abcde\" while \"aec\" is not).\n \n Example 1:\n \n >>> minimumScore(s = \"abacaba\", t = \"bzaa\")\n >>> 1\n Explanation: In this example, we remove the character \"z\" at index 1 (0-indexed).\n The string t becomes \"baa\" which is a subsequence of the string \"abacaba\" and the score is 1 - 1 + 1 = 1.\n It can be proven that 1 is the minimum score that we can achieve.\n \n Example 2:\n \n >>> minimumScore(s = \"cde\", t = \"xyz\")\n >>> 3\n Explanation: In this example, we remove characters \"x\", \"y\" and \"z\" at indices 0, 1, and 2 (0-indexed).\n The string t becomes \"\" which is a subsequence of the string \"cde\" and the score is 2 - 0 + 1 = 3.\n It can be proven that 3 is the minimum score that we can achieve.\n \"\"\"\n"}
{"task_id": "maximum-difference-by-remapping-a-digit", "prompt": "def minMaxDifference(num: int) -> int:\n \"\"\"\n You are given an integer num. You know that Bob will sneakily remap one of the 10 possible digits (0 to 9) to another digit.\n Return the difference between the maximum and minimum\u00a0values Bob can make by remapping\u00a0exactly one digit in num.\n Notes:\n \n When Bob remaps a digit d1\u00a0to another digit d2, Bob replaces all occurrences of d1\u00a0in num\u00a0with d2.\n Bob can remap a digit to itself, in which case num\u00a0does not change.\n Bob can remap different digits for obtaining minimum and maximum values respectively.\n The resulting number after remapping can contain leading zeroes.\n \n \n Example 1:\n \n >>> minMaxDifference(num = 11891)\n >>> 99009\n Explanation:\n To achieve the maximum value, Bob can remap the digit 1 to the digit 9 to yield 99899.\n To achieve the minimum value, Bob can remap the digit 1 to the digit 0, yielding 890.\n The difference between these two numbers is 99009.\n \n Example 2:\n \n >>> minMaxDifference(num = 90)\n >>> 99\n Explanation:\n The maximum value that can be returned by the function is 99 (if 0 is replaced by 9) and the minimum value that can be returned by the function is 0 (if 9 is replaced by 0).\n Thus, we return 99.\n \"\"\"\n"}
{"task_id": "minimum-score-by-changing-two-elements", "prompt": "def minimizeSum(nums: List[int]) -> int:\n \"\"\"\n You are given an integer array nums.\n \n The low score of nums is the minimum absolute difference between any two integers.\n The high score of nums is the maximum absolute difference between any two integers.\n The score of nums is the sum of the high and low scores.\n \n Return the minimum score after changing two elements of nums.\n \n Example 1:\n \n >>> minimizeSum(nums = [1,4,7,8,5])\n >>> 3\n Explanation:\n \n Change nums[0] and nums[1] to be 6 so that nums becomes [6,6,7,8,5].\n The low score is the minimum absolute difference: |6 - 6| = 0.\n The high score is the maximum absolute difference: |8 - 5| = 3.\n The sum of high and low score is 3.\n \n \n Example 2:\n \n >>> minimizeSum(nums = [1,4,3])\n >>> 0\n Explanation:\n \n Change nums[1] and nums[2] to 1 so that nums becomes [1,1,1].\n The sum of maximum absolute difference and minimum absolute difference is 0.\n \"\"\"\n"}
{"task_id": "minimum-impossible-or", "prompt": "def minImpossibleOR(nums: List[int]) -> int:\n \"\"\"\n You are given a 0-indexed\u00a0integer array nums.\n We say that an integer x is expressible from nums if there exist some integers 0 <= index1 < index2 < ... < indexk < nums.length for which nums[index1] | nums[index2] | ... | nums[indexk] = x. In other words, an integer is expressible if it can be written as the bitwise OR of some subsequence of nums.\n Return the minimum positive non-zero integer\u00a0that is not expressible from nums.\n \n Example 1:\n \n >>> minImpossibleOR(nums = [2,1])\n >>> 4\n Explanation: 1 and 2 are already present in the array. We know that 3 is expressible, since nums[0] | nums[1] = 2 | 1 = 3. Since 4 is not expressible, we return 4.\n \n Example 2:\n \n >>> minImpossibleOR(nums = [5,3,2])\n >>> 1\n Explanation: We can show that 1 is the smallest number that is not expressible.\n \"\"\"\n"}
{"task_id": "handling-sum-queries-after-update", "prompt": "def handleQuery(nums1: List[int], nums2: List[int], queries: List[List[int]]) -> List[int]:\n \"\"\"\n You are given two 0-indexed arrays nums1 and nums2 and a 2D array queries of queries. There are three types of queries:\n \n For a query of type 1, queries[i]\u00a0= [1, l, r]. Flip the values from 0 to 1 and from 1 to 0 in nums1\u00a0from index l to index r. Both l and r are 0-indexed.\n For a query of type 2, queries[i]\u00a0= [2, p, 0]. For every index 0 <= i < n, set\u00a0nums2[i] =\u00a0nums2[i]\u00a0+ nums1[i]\u00a0* p.\n For a query of type 3, queries[i]\u00a0= [3, 0, 0]. Find the sum of the elements in nums2.\n \n Return an array containing all the answers to the third type\u00a0queries.\n \n Example 1:\n \n >>> handleQuery(nums1 = [1,0,1], nums2 = [0,0,0], queries = [[1,1,1],[2,1,0],[3,0,0]])\n >>> [3]\n Explanation: After the first query nums1 becomes [1,1,1]. After the second query, nums2 becomes [1,1,1], so the answer to the third query is 3. Thus, [3] is returned.\n \n Example 2:\n \n >>> handleQuery(nums1 = [1], nums2 = [5], queries = [[2,0,0],[3,0,0]])\n >>> [5]\n Explanation: After the first query, nums2 remains [5], so the answer to the second query is 5. Thus, [5] is returned.\n \"\"\"\n"}
{"task_id": "merge-two-2d-arrays-by-summing-values", "prompt": "def mergeArrays(nums1: List[List[int]], nums2: List[List[int]]) -> List[List[int]]:\n \"\"\"\n You are given two 2D integer arrays nums1 and nums2.\n \n nums1[i] = [idi, vali]\u00a0indicate that the number with the id idi has a value equal to vali.\n nums2[i] = [idi, vali]\u00a0indicate that the number with the id idi has a value equal to vali.\n \n Each array contains unique ids and is sorted in ascending order by id.\n Merge the two arrays into one array that is sorted in ascending order by id, respecting the following conditions:\n \n Only ids that appear in at least one of the two arrays should be included in the resulting array.\n Each id should be included only once and its value should be the sum of the values of this id in the two arrays. If the id does not exist in one of the two arrays, then assume its value in that array to be 0.\n \n Return the resulting array. The returned array must be sorted in ascending order by id.\n \n Example 1:\n \n >>> mergeArrays(nums1 = [[1,2],[2,3],[4,5]], nums2 = [[1,4],[3,2],[4,1]])\n >>> [[1,6],[2,3],[3,2],[4,6]]\n Explanation: The resulting array contains the following:\n - id = 1, the value of this id is 2 + 4 = 6.\n - id = 2, the value of this id is 3.\n - id = 3, the value of this id is 2.\n - id = 4, the value of this id is 5 + 1 = 6.\n \n Example 2:\n \n >>> mergeArrays(nums1 = [[2,4],[3,6],[5,5]], nums2 = [[1,3],[4,3]])\n >>> [[1,3],[2,4],[3,6],[4,3],[5,5]]\n Explanation: There are no common ids, so we just include each id with its value in the resulting list.\n \"\"\"\n"}
{"task_id": "minimum-operations-to-reduce-an-integer-to-0", "prompt": "def minOperations(n: int) -> int:\n \"\"\"\n You are given a positive integer n, you can do the following operation any number of times:\n \n Add or subtract a power of 2 from n.\n \n Return the minimum number of operations to make n equal to 0.\n A number x is power of 2 if x == 2i\u00a0where i >= 0.\n \n Example 1:\n \n >>> minOperations(n = 39)\n >>> 3\n Explanation: We can do the following operations:\n - Add 20 = 1 to n, so now n = 40.\n - Subtract 23 = 8 from n, so now n = 32.\n - Subtract 25 = 32 from n, so now n = 0.\n It can be shown that 3 is the minimum number of operations we need to make n equal to 0.\n \n Example 2:\n \n >>> minOperations(n = 54)\n >>> 3\n Explanation: We can do the following operations:\n - Add 21 = 2 to n, so now n = 56.\n - Add 23 = 8 to n, so now n = 64.\n - Subtract 26 = 64 from n, so now n = 0.\n So the minimum number of operations is 3.\n \"\"\"\n"}
{"task_id": "count-the-number-of-square-free-subsets", "prompt": "def squareFreeSubsets(nums: List[int]) -> int:\n \"\"\"\n You are given a positive integer 0-indexed\u00a0array nums.\n A subset of the array nums is square-free if the product of its elements is a square-free integer.\n A square-free integer is an integer that is divisible by no square number other than 1.\n Return the number of square-free non-empty subsets of the array nums. Since the answer may be too large, return it modulo 109 + 7.\n A non-empty\u00a0subset of nums is an array that can be obtained by deleting some (possibly none but not all) elements from nums. Two subsets are different if and only if the chosen indices to delete are different.\n \n Example 1:\n \n >>> squareFreeSubsets(nums = [3,4,4,5])\n >>> 3\n Explanation: There are 3 square-free subsets in this example:\n - The subset consisting of the 0th element [3]. The product of its elements is 3, which is a square-free integer.\n - The subset consisting of the 3rd element [5]. The product of its elements is 5, which is a square-free integer.\n - The subset consisting of 0th and 3rd elements [3,5]. The product of its elements is 15, which is a square-free integer.\n It can be proven that there are no more than 3 square-free subsets in the given array.\n Example 2:\n \n >>> squareFreeSubsets(nums = [1])\n >>> 1\n Explanation: There is 1 square-free subset in this example:\n - The subset consisting of the 0th element [1]. The product of its elements is 1, which is a square-free integer.\n It can be proven that there is no more than 1 square-free subset in the given array.\n \"\"\"\n"}
{"task_id": "find-the-string-with-lcp", "prompt": "def findTheString(lcp: List[List[int]]) -> str:\n \"\"\"\n We define the lcp matrix of any 0-indexed string word of n lowercase English letters as an n x n grid such that:\n \n lcp[i][j] is equal to the length of the longest common prefix between the substrings word[i,n-1] and word[j,n-1].\n \n Given an\u00a0n x n matrix lcp, return the alphabetically smallest string word that corresponds to lcp. If there is no such string, return an empty string.\n A string a is lexicographically smaller than a string b (of the same length) if in the first position where a and b differ, string a has a letter that appears earlier in the alphabet than the corresponding letter in b. For example, \"aabd\" is lexicographically smaller than \"aaca\" because the first position they differ is at the third letter, and 'b' comes before 'c'.\n \n Example 1:\n \n >>> findTheString(lcp = [[4,0,2,0],[0,3,0,1],[2,0,2,0],[0,1,0,1]])\n >>> \"abab\"\n Explanation: lcp corresponds to any 4 letter string with two alternating letters. The lexicographically smallest of them is \"abab\".\n \n Example 2:\n \n >>> findTheString(lcp = [[4,3,2,1],[3,3,2,1],[2,2,2,1],[1,1,1,1]])\n >>> \"aaaa\"\n Explanation: lcp corresponds to any 4 letter string with a single distinct letter. The lexicographically smallest of them is \"aaaa\".\n \n Example 3:\n \n >>> findTheString(lcp = [[4,3,2,1],[3,3,2,1],[2,2,2,1],[1,1,1,3]])\n >>> \"\"\n Explanation: lcp[3][3] cannot be equal to 3 since word[3,...,3] consists of only a single letter; Thus, no answer exists.\n \"\"\"\n"}
{"task_id": "left-and-right-sum-differences", "prompt": "def leftRightDifference(nums: List[int]) -> List[int]:\n \"\"\"\n You are given a 0-indexed integer array nums of size n.\n Define two arrays leftSum and rightSum where:\n \n leftSum[i] is the sum of elements to the left of the index i in the array nums. If there is no such element, leftSum[i] = 0.\n rightSum[i] is the sum of elements to the right of the index i in the array nums. If there is no such element, rightSum[i] = 0.\n \n Return an integer array answer of size n where answer[i] = |leftSum[i] - rightSum[i]|.\n \n Example 1:\n \n >>> leftRightDifference(nums = [10,4,8,3])\n >>> [15,1,11,22]\n Explanation: The array leftSum is [0,10,14,22] and the array rightSum is [15,11,3,0].\n The array answer is [|0 - 15|,|10 - 11|,|14 - 3|,|22 - 0|] = [15,1,11,22].\n \n Example 2:\n \n >>> leftRightDifference(nums = [1])\n >>> [0]\n Explanation: The array leftSum is [0] and the array rightSum is [0].\n The array answer is [|0 - 0|] = [0].\n \"\"\"\n"}
{"task_id": "find-the-divisibility-array-of-a-string", "prompt": "def divisibilityArray(word: str, m: int) -> List[int]:\n \"\"\"\n You are given a 0-indexed string word of length n\u00a0consisting of digits, and a positive integer\u00a0m.\n The divisibility array div of word is an integer array of length n such that:\n \n div[i] = 1 if the\u00a0numeric value\u00a0of\u00a0word[0,...,i] is divisible by m, or\n div[i] = 0 otherwise.\n \n Return the divisibility array of word.\n \n Example 1:\n \n >>> divisibilityArray(word = \"998244353\", m = 3)\n >>> [1,1,0,0,0,1,1,0,0]\n Explanation: There are only 4 prefixes that are divisible by 3: \"9\", \"99\", \"998244\", and \"9982443\".\n \n Example 2:\n \n >>> divisibilityArray(word = \"1010\", m = 10)\n >>> [0,1,0,1]\n Explanation: There are only 2 prefixes that are divisible by 10: \"10\", and \"1010\".\n \"\"\"\n"}
{"task_id": "find-the-maximum-number-of-marked-indices", "prompt": "def maxNumOfMarkedIndices(nums: List[int]) -> int:\n \"\"\"\n You are given a 0-indexed integer array nums.\n Initially, all of the indices are unmarked. You are allowed to make this operation any number of times:\n \n Pick two different unmarked indices i and j such that 2 * nums[i] <= nums[j], then mark i and j.\n \n Return the maximum possible number of marked indices in nums using the above operation any number of times.\n \n Example 1:\n \n >>> maxNumOfMarkedIndices(nums = [3,5,2,4])\n >>> 2\n Explanation: In the first operation: pick i = 2 and j = 1, the operation is allowed because 2 * nums[2] <= nums[1]. Then mark index 2 and 1.\n It can be shown that there's no other valid operation so the answer is 2.\n \n Example 2:\n \n >>> maxNumOfMarkedIndices(nums = [9,2,5,4])\n >>> 4\n Explanation: In the first operation: pick i = 3 and j = 0, the operation is allowed because 2 * nums[3] <= nums[0]. Then mark index 3 and 0.\n In the second operation: pick i = 1 and j = 2, the operation is allowed because 2 * nums[1] <= nums[2]. Then mark index 1 and 2.\n Since there is no other operation, the answer is 4.\n \n Example 3:\n \n >>> maxNumOfMarkedIndices(nums = [7,6,8])\n >>> 0\n Explanation: There is no valid operation to do, so the answer is 0.\n \"\"\"\n"}
{"task_id": "minimum-time-to-visit-a-cell-in-a-grid", "prompt": "def minimumTime(grid: List[List[int]]) -> int:\n \"\"\"\n You are given a m x n matrix grid consisting of non-negative integers where grid[row][col] represents the minimum time required to be able to visit the cell (row, col), which means you can visit the cell (row, col) only when the time you visit it is greater than or equal to grid[row][col].\n You are standing in the top-left cell of the matrix in the 0th second, and you must move to any adjacent cell in the four directions: up, down, left, and right. Each move you make takes 1 second.\n Return the minimum time required in which you can visit the bottom-right cell of the matrix. If you cannot visit the bottom-right cell, then return -1.\n \n Example 1:\n \n \n >>> minimumTime(grid = [[0,1,3,2],[5,1,2,5],[4,3,8,6]])\n >>> 7\n Explanation: One of the paths that we can take is the following:\n - at t = 0, we are on the cell (0,0).\n - at t = 1, we move to the cell (0,1). It is possible because grid[0][1] <= 1.\n - at t = 2, we move to the cell (1,1). It is possible because grid[1][1] <= 2.\n - at t = 3, we move to the cell (1,2). It is possible because grid[1][2] <= 3.\n - at t = 4, we move to the cell (1,1). It is possible because grid[1][1] <= 4.\n - at t = 5, we move to the cell (1,2). It is possible because grid[1][2] <= 5.\n - at t = 6, we move to the cell (1,3). It is possible because grid[1][3] <= 6.\n - at t = 7, we move to the cell (2,3). It is possible because grid[2][3] <= 7.\n The final time is 7. It can be shown that it is the minimum time possible.\n \n Example 2:\n \n \n >>> minimumTime(grid = [[0,2,4],[3,2,1],[1,0,4]])\n >>> -1\n Explanation: There is no path from the top left to the bottom-right cell.\n \"\"\"\n"}
{"task_id": "split-with-minimum-sum", "prompt": "def splitNum(num: int) -> int:\n \"\"\"\n Given a positive integer num, split it into two non-negative integers num1 and num2 such that:\n \n The concatenation of num1 and num2 is a permutation of num.\n \n \n In other words, the sum of the number of occurrences of each digit in num1 and num2 is equal to the number of occurrences of that digit in num.\n \n \n num1 and num2 can contain leading zeros.\n \n Return the minimum possible sum of num1 and num2.\n Notes:\n \n It is guaranteed that num does not contain any leading zeros.\n The order of occurrence of the digits in num1 and num2 may differ from the order of occurrence of num.\n \n \n Example 1:\n \n >>> splitNum(num = 4325)\n >>> 59\n Explanation: We can split 4325 so that num1 is 24 and num2 is 35, giving a sum of 59. We can prove that 59 is indeed the minimal possible sum.\n \n Example 2:\n \n >>> splitNum(num = 687)\n >>> 75\n Explanation: We can split 687 so that num1 is 68 and num2 is 7, which would give an optimal sum of 75.\n \"\"\"\n"}
{"task_id": "count-total-number-of-colored-cells", "prompt": "def coloredCells(n: int) -> int:\n \"\"\"\n There exists an infinitely large two-dimensional grid of uncolored unit cells. You are given a positive integer n, indicating that you must do the following routine for n minutes:\n \n At the first minute, color any arbitrary unit cell blue.\n Every minute thereafter, color blue every uncolored cell that touches a blue cell.\n \n Below is a pictorial representation of the state of the grid after minutes 1, 2, and 3.\n \n Return the number of colored cells at the end of n minutes.\n \n Example 1:\n \n >>> coloredCells(n = 1)\n >>> 1\n Explanation: After 1 minute, there is only 1 blue cell, so we return 1.\n \n Example 2:\n \n >>> coloredCells(n = 2)\n >>> 5\n Explanation: After 2 minutes, there are 4 colored cells on the boundary and 1 in the center, so we return 5.\n \"\"\"\n"}
{"task_id": "count-number-of-possible-root-nodes", "prompt": "def rootCount(edges: List[List[int]], guesses: List[List[int]], k: int) -> int:\n \"\"\"\n Alice has an undirected tree with n nodes labeled from 0 to n - 1. The tree is represented as a 2D integer array edges of length n - 1 where edges[i] = [ai, bi] indicates that there is an edge between nodes ai and bi in the tree.\n Alice wants Bob to find the root of the tree. She allows Bob to make several guesses about her tree. In one guess, he does the following:\n \n Chooses two distinct integers u and v such that there exists an edge [u, v] in the tree.\n He tells Alice that u is the parent of v in the tree.\n \n Bob's guesses are represented by a 2D integer array guesses where guesses[j] = [uj, vj] indicates Bob guessed uj to be the parent of vj.\n Alice being lazy, does not reply to each of Bob's guesses, but just says that at least k of his guesses are true.\n Given the 2D integer arrays edges, guesses and the integer k, return the number of possible nodes that can be the root of Alice's tree. If there is no such tree, return 0.\n \n Example 1:\n \n \n >>> rootCount(edges = [[0,1],[1,2],[1,3],[4,2]], guesses = [[1,3],[0,1],[1,0],[2,4]], k = 3)\n >>> 3\n Explanation:\n Root = 0, correct guesses = [1,3], [0,1], [2,4]\n Root = 1, correct guesses = [1,3], [1,0], [2,4]\n Root = 2, correct guesses = [1,3], [1,0], [2,4]\n Root = 3, correct guesses = [1,0], [2,4]\n Root = 4, correct guesses = [1,3], [1,0]\n Considering 0, 1, or 2 as root node leads to 3 correct guesses.\n \n \n Example 2:\n \n \n >>> rootCount(edges = [[0,1],[1,2],[2,3],[3,4]], guesses = [[1,0],[3,4],[2,1],[3,2]], k = 1)\n >>> 5\n Explanation:\n Root = 0, correct guesses = [3,4]\n Root = 1, correct guesses = [1,0], [3,4]\n Root = 2, correct guesses = [1,0], [2,1], [3,4]\n Root = 3, correct guesses = [1,0], [2,1], [3,2], [3,4]\n Root = 4, correct guesses = [1,0], [2,1], [3,2]\n Considering any node as root will give at least 1 correct guess.\n \"\"\"\n"}
{"task_id": "pass-the-pillow", "prompt": "def passThePillow(n: int, time: int) -> int:\n \"\"\"\n There are n people standing in a line labeled from 1 to n. The first person in the line is holding a pillow initially. Every second, the person holding the pillow passes it to the next person standing in the line. Once the pillow reaches the end of the line, the direction changes, and people continue passing the pillow in the opposite direction.\n \n For example, once the pillow reaches the nth person they pass it to the n - 1th person, then to the n - 2th person and so on.\n \n Given the two positive integers n and time, return the index of the person holding the pillow after time seconds.\n \n Example 1:\n \n >>> passThePillow(n = 4, time = 5)\n >>> 2\n Explanation: People pass the pillow in the following way: 1 -> 2 -> 3 -> 4 -> 3 -> 2.\n After five seconds, the 2nd person is holding the pillow.\n \n Example 2:\n \n >>> passThePillow(n = 3, time = 2)\n >>> 3\n Explanation: People pass the pillow in the following way: 1 -> 2 -> 3.\n After two seconds, the 3rd person is holding the pillow.\n \"\"\"\n"}
{"task_id": "kth-largest-sum-in-a-binary-tree", "prompt": "# class TreeNode:\n# def __init__(val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def kthLargestLevelSum(root: Optional[TreeNode], k: int) -> int:\n \"\"\"\n You are given the root of a binary tree and a positive integer k.\n The level sum in the tree is the sum of the values of the nodes that are on the same level.\n Return the kth largest level sum in the tree (not necessarily distinct). If there are fewer than k levels in the tree, return -1.\n Note that two nodes are on the same level if they have the same distance from the root.\n \n Example 1:\n \n \n >>> __init__(root = [5,8,9,2,1,3,7,4,6], k = 2)\n >>> 13\n Explanation: The level sums are the following:\n - Level 1: 5.\n - Level 2: 8 + 9 = 17.\n - Level 3: 2 + 1 + 3 + 7 = 13.\n - Level 4: 4 + 6 = 10.\n The 2nd largest level sum is 13.\n \n Example 2:\n \n \n >>> __init__(root = [1,2,null,3], k = 1)\n >>> 3\n Explanation: The largest level sum is 3.\n \"\"\"\n"}
{"task_id": "split-the-array-to-make-coprime-products", "prompt": "def findValidSplit(nums: List[int]) -> int:\n \"\"\"\n You are given a 0-indexed integer array nums of length n.\n A split at an index i where 0 <= i <= n - 2 is called valid if the product of the first i + 1 elements and the product of the remaining elements are coprime.\n \n For example, if nums = [2, 3, 3], then a split at the index i = 0 is valid because 2 and 9 are coprime, while a split at the index i = 1 is not valid because 6 and 3 are not coprime. A split at the index i = 2 is not valid because i == n - 1.\n \n Return the smallest index i at which the array can be split validly or -1 if there is no such split.\n Two values val1 and val2 are coprime if gcd(val1, val2) == 1 where gcd(val1, val2) is the greatest common divisor of val1 and val2.\n \n Example 1:\n \n \n >>> findValidSplit(nums = [4,7,8,15,3,5])\n >>> 2\n Explanation: The table above shows the values of the product of the first i + 1 elements, the remaining elements, and their gcd at each index i.\n The only valid split is at index 2.\n \n Example 2:\n \n \n >>> findValidSplit(nums = [4,7,15,8,3,5])\n >>> -1\n Explanation: The table above shows the values of the product of the first i + 1 elements, the remaining elements, and their gcd at each index i.\n There is no valid split.\n \"\"\"\n"}
{"task_id": "number-of-ways-to-earn-points", "prompt": "def waysToReachTarget(target: int, types: List[List[int]]) -> int:\n \"\"\"\n There is a test that has n types of questions. You are given an integer target and a 0-indexed 2D integer array types where types[i] = [counti, marksi] indicates that there are counti questions of the ith type, and each one of them is worth marksi points.\n \n \n Return the number of ways you can earn exactly target points in the exam. Since the answer may be too large, return it modulo 109 + 7.\n Note that questions of the same type are indistinguishable.\n \n For example, if there are 3 questions of the same type, then solving the 1st and 2nd questions is the same as solving the 1st and 3rd questions, or the 2nd and 3rd questions.\n \n \n Example 1:\n \n >>> waysToReachTarget(target = 6, types = [[6,1],[3,2],[2,3]])\n >>> 7\n Explanation: You can earn 6 points in one of the seven ways:\n - Solve 6 questions of the 0th type: 1 + 1 + 1 + 1 + 1 + 1 = 6\n - Solve 4 questions of the 0th type and 1 question of the 1st type: 1 + 1 + 1 + 1 + 2 = 6\n - Solve 2 questions of the 0th type and 2 questions of the 1st type: 1 + 1 + 2 + 2 = 6\n - Solve 3 questions of the 0th type and 1 question of the 2nd type: 1 + 1 + 1 + 3 = 6\n - Solve 1 question of the 0th type, 1 question of the 1st type and 1 question of the 2nd type: 1 + 2 + 3 = 6\n - Solve 3 questions of the 1st type: 2 + 2 + 2 = 6\n - Solve 2 questions of the 2nd type: 3 + 3 = 6\n \n Example 2:\n \n >>> waysToReachTarget(target = 5, types = [[50,1],[50,2],[50,5]])\n >>> 4\n Explanation: You can earn 5 points in one of the four ways:\n - Solve 5 questions of the 0th type: 1 + 1 + 1 + 1 + 1 = 5\n - Solve 3 questions of the 0th type and 1 question of the 1st type: 1 + 1 + 1 + 2 = 5\n - Solve 1 questions of the 0th type and 2 questions of the 1st type: 1 + 2 + 2 = 5\n - Solve 1 question of the 2nd type: 5\n \n Example 3:\n \n >>> waysToReachTarget(target = 18, types = [[6,1],[3,2],[2,3]])\n >>> 1\n Explanation: You can only earn 18 points by answering all questions.\n \"\"\"\n"}
{"task_id": "count-the-number-of-vowel-strings-in-range", "prompt": "def vowelStrings(words: List[str], left: int, right: int) -> int:\n \"\"\"\n You are given a 0-indexed array of string words and two integers left and right.\n A string is called a vowel string if it starts with a vowel character and ends with a vowel character where vowel characters are 'a', 'e', 'i', 'o', and 'u'.\n Return the number of vowel strings words[i] where i belongs to the inclusive range [left, right].\n \n Example 1:\n \n >>> vowelStrings(words = [\"are\",\"amy\",\"u\"], left = 0, right = 2)\n >>> 2\n Explanation:\n - \"are\" is a vowel string because it starts with 'a' and ends with 'e'.\n - \"amy\" is not a vowel string because it does not end with a vowel.\n - \"u\" is a vowel string because it starts with 'u' and ends with 'u'.\n The number of vowel strings in the mentioned range is 2.\n \n Example 2:\n \n >>> vowelStrings(words = [\"hey\",\"aeo\",\"mu\",\"ooo\",\"artro\"], left = 1, right = 4)\n >>> 3\n Explanation:\n - \"aeo\" is a vowel string because it starts with 'a' and ends with 'o'.\n - \"mu\" is not a vowel string because it does not start with a vowel.\n - \"ooo\" is a vowel string because it starts with 'o' and ends with 'o'.\n - \"artro\" is a vowel string because it starts with 'a' and ends with 'o'.\n The number of vowel strings in the mentioned range is 3.\n \"\"\"\n"}
{"task_id": "rearrange-array-to-maximize-prefix-score", "prompt": "def maxScore(nums: List[int]) -> int:\n \"\"\"\n You are given a 0-indexed integer array nums. You can rearrange the elements of nums to any order (including the given order).\n Let prefix be the array containing the prefix sums of nums after rearranging it. In other words, prefix[i] is the sum of the elements from 0 to i in nums after rearranging it. The score of nums is the number of positive integers in the array prefix.\n Return the maximum score you can achieve.\n \n Example 1:\n \n >>> maxScore(nums = [2,-1,0,1,-3,3,-3])\n >>> 6\n Explanation: We can rearrange the array into nums = [2,3,1,-1,-3,0,-3].\n prefix = [2,5,6,5,2,2,-1], so the score is 6.\n It can be shown that 6 is the maximum score we can obtain.\n \n Example 2:\n \n >>> maxScore(nums = [-2,-3,0])\n >>> 0\n Explanation: Any rearrangement of the array will result in a score of 0.\n \"\"\"\n"}
{"task_id": "count-the-number-of-beautiful-subarrays", "prompt": "def beautifulSubarrays(nums: List[int]) -> int:\n \"\"\"\n You are given a 0-indexed integer array nums. In one operation, you can:\n \n Choose two different indices i and j such that 0 <= i, j < nums.length.\n Choose a non-negative integer k such that the kth bit (0-indexed) in the binary representation of nums[i] and nums[j] is 1.\n Subtract 2k from nums[i] and nums[j].\n \n A subarray is beautiful if it is possible to make all of its elements equal to 0 after applying the above operation any number of times.\n Return the number of beautiful subarrays in the array nums.\n A subarray is a contiguous non-empty sequence of elements within an array.\n \n Example 1:\n \n >>> beautifulSubarrays(nums = [4,3,1,2,4])\n >>> 2\n Explanation: There are 2 beautiful subarrays in nums: [4,3,1,2,4] and [4,3,1,2,4].\n - We can make all elements in the subarray [3,1,2] equal to 0 in the following way:\n - Choose [3, 1, 2] and k = 1. Subtract 21 from both numbers. The subarray becomes [1, 1, 0].\n - Choose [1, 1, 0] and k = 0. Subtract 20 from both numbers. The subarray becomes [0, 0, 0].\n - We can make all elements in the subarray [4,3,1,2,4] equal to 0 in the following way:\n - Choose [4, 3, 1, 2, 4] and k = 2. Subtract 22 from both numbers. The subarray becomes [0, 3, 1, 2, 0].\n - Choose [0, 3, 1, 2, 0] and k = 0. Subtract 20 from both numbers. The subarray becomes [0, 2, 0, 2, 0].\n - Choose [0, 2, 0, 2, 0] and k = 1. Subtract 21 from both numbers. The subarray becomes [0, 0, 0, 0, 0].\n \n Example 2:\n \n >>> beautifulSubarrays(nums = [1,10,4])\n >>> 0\n Explanation: There are no beautiful subarrays in nums.\n \"\"\"\n"}
{"task_id": "minimum-time-to-complete-all-tasks", "prompt": "def findMinimumTime(tasks: List[List[int]]) -> int:\n \"\"\"\n There is a computer that can run an unlimited number of tasks at the same time. You are given a 2D integer array tasks where tasks[i] = [starti, endi, durationi] indicates that the ith task should run for a total of durationi seconds (not necessarily continuous) within the inclusive time range [starti, endi].\n You may turn on the computer only when it needs to run a task. You can also turn it off if it is idle.\n Return the minimum time during which the computer should be turned on to complete all tasks.\n \n Example 1:\n \n >>> findMinimumTime(tasks = [[2,3,1],[4,5,1],[1,5,2]])\n >>> 2\n Explanation:\n - The first task can be run in the inclusive time range [2, 2].\n - The second task can be run in the inclusive time range [5, 5].\n - The third task can be run in the two inclusive time ranges [2, 2] and [5, 5].\n The computer will be on for a total of 2 seconds.\n \n Example 2:\n \n >>> findMinimumTime(tasks = [[1,3,2],[2,5,3],[5,6,2]])\n >>> 4\n Explanation:\n - The first task can be run in the inclusive time range [2, 3].\n - The second task can be run in the inclusive time ranges [2, 3] and [5, 5].\n - The third task can be run in the two inclusive time range [5, 6].\n The computer will be on for a total of 4 seconds.\n \"\"\"\n"}
{"task_id": "distribute-money-to-maximum-children", "prompt": "def distMoney(money: int, children: int) -> int:\n \"\"\"\n You are given an integer money denoting the amount of money (in dollars) that you have and another integer children denoting the number of children that you must distribute the money to.\n You have to distribute the money according to the following rules:\n \n All money must be distributed.\n Everyone must receive at least 1 dollar.\n Nobody receives 4 dollars.\n \n Return the maximum number of children who may receive exactly 8 dollars if you distribute the money according to the aforementioned rules. If there is no way to distribute the money, return -1.\n \n Example 1:\n \n >>> distMoney(money = 20, children = 3)\n >>> 1\n Explanation:\n The maximum number of children with 8 dollars will be 1. One of the ways to distribute the money is:\n - 8 dollars to the first child.\n - 9 dollars to the second child.\n - 3 dollars to the third child.\n It can be proven that no distribution exists such that number of children getting 8 dollars is greater than 1.\n \n Example 2:\n \n >>> distMoney(money = 16, children = 2)\n >>> 2\n Explanation: Each child can be given 8 dollars.\n \"\"\"\n"}
{"task_id": "maximize-greatness-of-an-array", "prompt": "def maximizeGreatness(nums: List[int]) -> int:\n \"\"\"\n You are given a 0-indexed integer array nums. You are allowed to permute nums into a new array perm of your choosing.\n We define the greatness of nums be the number of indices 0 <= i < nums.length for which perm[i] > nums[i].\n Return the maximum possible greatness you can achieve after permuting nums.\n \n Example 1:\n \n >>> maximizeGreatness(nums = [1,3,5,2,1,3,1])\n >>> 4\n Explanation: One of the optimal rearrangements is perm = [2,5,1,3,3,1,1].\n At indices = 0, 1, 3, and 4, perm[i] > nums[i]. Hence, we return 4.\n Example 2:\n \n >>> maximizeGreatness(nums = [1,2,3,4])\n >>> 3\n Explanation: We can prove the optimal perm is [2,3,4,1].\n At indices = 0, 1, and 2, perm[i] > nums[i]. Hence, we return 3.\n \"\"\"\n"}
{"task_id": "find-score-of-an-array-after-marking-all-elements", "prompt": "def findScore(nums: List[int]) -> int:\n \"\"\"\n You are given an array nums consisting of positive integers.\n Starting with score = 0, apply the following algorithm:\n \n Choose the smallest integer of the array that is not marked. If there is a tie, choose the one with the smallest index.\n Add the value of the chosen integer to score.\n Mark the chosen element and its two adjacent elements if they exist.\n Repeat until all the array elements are marked.\n \n Return the score you get after applying the above algorithm.\n \n Example 1:\n \n >>> findScore(nums = [2,1,3,4,5,2])\n >>> 7\n Explanation: We mark the elements as follows:\n - 1 is the smallest unmarked element, so we mark it and its two adjacent elements: [2,1,3,4,5,2].\n - 2 is the smallest unmarked element, so we mark it and its left adjacent element: [2,1,3,4,5,2].\n - 4 is the only remaining unmarked element, so we mark it: [2,1,3,4,5,2].\n Our score is 1 + 2 + 4 = 7.\n \n Example 2:\n \n >>> findScore(nums = [2,3,5,1,3,2])\n >>> 5\n Explanation: We mark the elements as follows:\n - 1 is the smallest unmarked element, so we mark it and its two adjacent elements: [2,3,5,1,3,2].\n - 2 is the smallest unmarked element, since there are two of them, we choose the left-most one, so we mark the one at index 0 and its right adjacent element: [2,3,5,1,3,2].\n - 2 is the only remaining unmarked element, so we mark it: [2,3,5,1,3,2].\n Our score is 1 + 2 + 2 = 5.\n \"\"\"\n"}
{"task_id": "minimum-time-to-repair-cars", "prompt": "def repairCars(ranks: List[int], cars: int) -> int:\n \"\"\"\n You are given an integer array ranks representing the ranks of some mechanics. ranksi is the rank of the ith mechanic. A mechanic with a rank r can repair n cars in r * n2 minutes.\n You are also given an integer cars representing the total number of cars waiting in the garage to be repaired.\n Return the minimum time taken to repair all the cars.\n Note: All the mechanics can repair the cars simultaneously.\n \n Example 1:\n \n >>> repairCars(ranks = [4,2,3,1], cars = 10)\n >>> 16\n Explanation:\n - The first mechanic will repair two cars. The time required is 4 * 2 * 2 = 16 minutes.\n - The second mechanic will repair two cars. The time required is 2 * 2 * 2 = 8 minutes.\n - The third mechanic will repair two cars. The time required is 3 * 2 * 2 = 12 minutes.\n - The fourth mechanic will repair four cars. The time required is 1 * 4 * 4 = 16 minutes.\n It can be proved that the cars cannot be repaired in less than 16 minutes.\u200b\u200b\u200b\u200b\u200b\n \n Example 2:\n \n >>> repairCars(ranks = [5,1,8], cars = 6)\n >>> 16\n Explanation:\n - The first mechanic will repair one car. The time required is 5 * 1 * 1 = 5 minutes.\n - The second mechanic will repair four cars. The time required is 1 * 4 * 4 = 16 minutes.\n - The third mechanic will repair one car. The time required is 8 * 1 * 1 = 8 minutes.\n It can be proved that the cars cannot be repaired in less than 16 minutes.\u200b\u200b\u200b\u200b\u200b\n \"\"\"\n"}
{"task_id": "number-of-even-and-odd-bits", "prompt": "def evenOddBit(n: int) -> List[int]:\n \"\"\"\n You are given a positive integer n.\n Let even denote the number of even indices in the binary representation of n with value 1.\n Let odd denote the number of odd indices in the binary representation of n with value 1.\n Note that bits are indexed from right to left in the binary representation of a number.\n Return the array [even, odd].\n \n Example 1:\n \n >>> evenOddBit(n = 50)\n >>> [1,2]\n Explanation:\n The binary representation of 50 is 110010.\n It contains 1 on indices 1, 4, and 5.\n \n Example 2:\n \n >>> evenOddBit(n = 2)\n >>> [0,1]\n Explanation:\n The binary representation of 2 is 10.\n It contains 1 only on index 1.\n \"\"\"\n"}
{"task_id": "check-knight-tour-configuration", "prompt": "def checkValidGrid(grid: List[List[int]]) -> bool:\n \"\"\"\n There is a knight on an n x n chessboard. In a valid configuration, the knight starts at the top-left cell of the board and visits every cell on the board exactly once.\n You are given an n x n integer matrix grid consisting of distinct integers from the range [0, n * n - 1] where grid[row][col] indicates that the cell (row, col) is the grid[row][col]th cell that the knight visited. The moves are 0-indexed.\n Return true if grid represents a valid configuration of the knight's movements or false otherwise.\n Note that a valid knight move consists of moving two squares vertically and one square horizontally, or two squares horizontally and one square vertically. The figure below illustrates all the possible eight moves of a knight from some cell.\n \n \n Example 1:\n \n \n >>> checkValidGrid(grid = [[0,11,16,5,20],[17,4,19,10,15],[12,1,8,21,6],[3,18,23,14,9],[24,13,2,7,22]])\n >>> true\n Explanation: The above diagram represents the grid. It can be shown that it is a valid configuration.\n \n Example 2:\n \n \n >>> checkValidGrid(grid = [[0,3,6],[5,8,1],[2,7,4]])\n >>> false\n Explanation: The above diagram represents the grid. The 8th move of the knight is not valid considering its position after the 7th move.\n \"\"\"\n"}
{"task_id": "the-number-of-beautiful-subsets", "prompt": "def beautifulSubsets(nums: List[int], k: int) -> int:\n \"\"\"\n You are given an array nums of positive integers and a positive integer k.\n A subset of nums is beautiful if it does not contain two integers with an absolute difference equal to k.\n Return the number of non-empty beautiful subsets of the array nums.\n A subset of nums is an array that can be obtained by deleting some (possibly none) elements from nums. Two subsets are different if and only if the chosen indices to delete are different.\n \n Example 1:\n \n >>> beautifulSubsets(nums = [2,4,6], k = 2)\n >>> 4\n Explanation: The beautiful subsets of the array nums are: [2], [4], [6], [2, 6].\n It can be proved that there are only 4 beautiful subsets in the array [2,4,6].\n \n Example 2:\n \n >>> beautifulSubsets(nums = [1], k = 1)\n >>> 1\n Explanation: The beautiful subset of the array nums is [1].\n It can be proved that there is only 1 beautiful subset in the array [1].\n \"\"\"\n"}
{"task_id": "smallest-missing-non-negative-integer-after-operations", "prompt": "def findSmallestInteger(nums: List[int], value: int) -> int:\n \"\"\"\n You are given a 0-indexed integer array nums and an integer value.\n In one operation, you can add or subtract value from any element of nums.\n \n For example, if nums = [1,2,3] and value = 2, you can choose to subtract value from nums[0] to make nums = [-1,2,3].\n \n The MEX (minimum excluded) of an array is the smallest missing non-negative integer in it.\n \n For example, the MEX of [-1,2,3] is 0 while the MEX of [1,0,3] is 2.\n \n Return the maximum MEX of nums after applying the mentioned operation any number of times.\n \n Example 1:\n \n >>> findSmallestInteger(nums = [1,-10,7,13,6,8], value = 5)\n >>> 4\n Explanation: One can achieve this result by applying the following operations:\n - Add value to nums[1] twice to make nums = [1,0,7,13,6,8]\n - Subtract value from nums[2] once to make nums = [1,0,2,13,6,8]\n - Subtract value from nums[3] twice to make nums = [1,0,2,3,6,8]\n The MEX of nums is 4. It can be shown that 4 is the maximum MEX we can achieve.\n \n Example 2:\n \n >>> findSmallestInteger(nums = [1,-10,7,13,6,8], value = 7)\n >>> 2\n Explanation: One can achieve this result by applying the following operation:\n - subtract value from nums[2] once to make nums = [1,-10,0,13,6,8]\n The MEX of nums is 2. It can be shown that 2 is the maximum MEX we can achieve.\n \"\"\"\n"}
{"task_id": "make-the-prefix-sum-non-negative", "prompt": "def makePrefSumNonNegative(nums: List[int]) -> int:\n \"\"\"\n You are given a 0-indexed integer array nums. You can apply the following operation any number of times:\n \n Pick any element from nums and put it at the end of nums.\n \n The prefix sum array of nums is an array prefix of the same length as nums such that prefix[i] is the sum of all the integers nums[j] where j is in the inclusive range [0, i].\n Return the minimum number of operations such that the prefix sum array does not contain negative integers. The test cases are generated such that it is always possible to make the prefix sum array non-negative.\n \n Example 1:\n \n >>> makePrefSumNonNegative(nums = [2,3,-5,4])\n >>> 0\n Explanation: we do not need to do any operations.\n The array is [2,3,-5,4]. The prefix sum array is [2, 5, 0, 4].\n \n Example 2:\n \n >>> makePrefSumNonNegative(nums = [3,-5,-2,6])\n >>> 1\n Explanation: we can do one operation on index 1.\n The array after the operation is [3,-2,6,-5]. The prefix sum array is [3, 1, 7, 2].\n \"\"\"\n"}
{"task_id": "k-items-with-the-maximum-sum", "prompt": "def kItemsWithMaximumSum(numOnes: int, numZeros: int, numNegOnes: int, k: int) -> int:\n \"\"\"\n There is a bag that consists of items, each item\u00a0has a number 1, 0, or -1 written on it.\n You are given four non-negative integers numOnes, numZeros, numNegOnes, and k.\n The bag initially contains:\n \n numOnes items with 1s written on them.\n numZeroes items with 0s written on them.\n numNegOnes items with -1s written on them.\n \n We want to pick exactly k items among the available items. Return the maximum possible sum of numbers written on the items.\n \n Example 1:\n \n >>> kItemsWithMaximumSum(numOnes = 3, numZeros = 2, numNegOnes = 0, k = 2)\n >>> 2\n Explanation: We have a bag of items with numbers written on them {1, 1, 1, 0, 0}. We take 2 items with 1 written on them and get a sum in a total of 2.\n It can be proven that 2 is the maximum possible sum.\n \n Example 2:\n \n >>> kItemsWithMaximumSum(numOnes = 3, numZeros = 2, numNegOnes = 0, k = 4)\n >>> 3\n Explanation: We have a bag of items with numbers written on them {1, 1, 1, 0, 0}. We take 3 items with 1 written on them, and 1 item with 0 written on it, and get a sum in a total of 3.\n It can be proven that 3 is the maximum possible sum.\n \"\"\"\n"}
{"task_id": "prime-subtraction-operation", "prompt": "def primeSubOperation(nums: List[int]) -> bool:\n \"\"\"\n You are given a 0-indexed integer array nums of length n.\n You can perform the following operation as many times as you want:\n \n Pick an index i that you haven\u2019t picked before, and pick a prime p strictly less than nums[i], then subtract p from nums[i].\n \n Return true if you can make nums a strictly increasing array using the above operation and false otherwise.\n A strictly increasing array is an array whose each element is strictly greater than its preceding element.\n \n Example 1:\n \n >>> primeSubOperation(nums = [4,9,6,10])\n >>> true\n Explanation: In the first operation: Pick i = 0 and p = 3, and then subtract 3 from nums[0], so that nums becomes [1,9,6,10].\n In the second operation: i = 1, p = 7, subtract 7 from nums[1], so nums becomes equal to [1,2,6,10].\n After the second operation, nums is sorted in strictly increasing order, so the answer is true.\n Example 2:\n \n >>> primeSubOperation(nums = [6,8,11,12])\n >>> true\n Explanation: Initially nums is sorted in strictly increasing order, so we don't need to make any operations.\n Example 3:\n \n >>> primeSubOperation(nums = [5,8,3])\n >>> false\n Explanation: It can be proven that there is no way to perform operations to make nums sorted in strictly increasing order, so the answer is false.\n \"\"\"\n"}
{"task_id": "minimum-operations-to-make-all-array-elements-equal", "prompt": "def minOperations(nums: List[int], queries: List[int]) -> List[int]:\n \"\"\"\n You are given an array nums consisting of positive integers.\n You are also given an integer array queries of size m. For the ith query, you want to make all of the elements of nums equal to queries[i]. You can perform the following operation on the array any number of times:\n \n Increase or decrease an element of the array by 1.\n \n Return an array answer of size m where answer[i] is the minimum number of operations to make all elements of nums equal to queries[i].\n Note that after each query the array is reset to its original state.\n \n Example 1:\n \n >>> minOperations(nums = [3,1,6,8], queries = [1,5])\n >>> [14,10]\n Explanation: For the first query we can do the following operations:\n - Decrease nums[0] 2 times, so that nums = [1,1,6,8].\n - Decrease nums[2] 5 times, so that nums = [1,1,1,8].\n - Decrease nums[3] 7 times, so that nums = [1,1,1,1].\n So the total number of operations for the first query is 2 + 5 + 7 = 14.\n For the second query we can do the following operations:\n - Increase nums[0] 2 times, so that nums = [5,1,6,8].\n - Increase nums[1] 4 times, so that nums = [5,5,6,8].\n - Decrease nums[2] 1 time, so that nums = [5,5,5,8].\n - Decrease nums[3] 3 times, so that nums = [5,5,5,5].\n So the total number of operations for the second query is 2 + 4 + 1 + 3 = 10.\n \n Example 2:\n \n >>> minOperations(nums = [2,9,6,3], queries = [10])\n >>> [20]\n Explanation: We can increase each value in the array to 10. The total number of operations will be 8 + 1 + 4 + 7 = 20.\n \"\"\"\n"}
{"task_id": "collect-coins-in-a-tree", "prompt": "def collectTheCoins(coins: List[int], edges: List[List[int]]) -> int:\n \"\"\"\n There exists an undirected and unrooted tree with n nodes indexed from 0 to n - 1. You are given an integer n and a 2D integer array edges of length n - 1, where edges[i] = [ai, bi] indicates that there is an edge between nodes ai and bi in the tree. You are also given\u00a0an array coins of size n where coins[i] can be either 0 or 1, where 1 indicates the presence of a coin in the vertex i.\n Initially, you choose to start at any vertex in\u00a0the tree.\u00a0Then, you can perform\u00a0the following operations any number of times:\n \n Collect all the coins that are at a distance of at most 2 from the current vertex, or\n Move to any adjacent vertex in the tree.\n \n Find the minimum number of edges you need to go through to collect all the coins and go back to the initial vertex.\n Note that if you pass an edge several times, you need to count it into the answer several times.\n \n Example 1:\n \n \n >>> collectTheCoins(coins = [1,0,0,0,0,1], edges = [[0,1],[1,2],[2,3],[3,4],[4,5]])\n >>> 2\n Explanation: Start at vertex 2, collect the coin at vertex 0, move to vertex 3, collect the coin at vertex 5 then move back to vertex 2.\n \n Example 2:\n \n \n >>> collectTheCoins(coins = [0,0,0,1,1,0,0,1], edges = [[0,1],[0,2],[1,3],[1,4],[2,5],[5,6],[5,7]])\n >>> 2\n Explanation: Start at vertex 0, collect the coins at vertices 4 and 3, move to vertex 2, collect the coin at vertex 7, then move back to vertex 0.\n \"\"\"\n"}
{"task_id": "minimum-time-to-eat-all-grains", "prompt": "def minimumTime(hens: List[int], grains: List[int]) -> int:\n \"\"\"\n There are n hens and m grains on a line. You are given the initial positions of the hens and the grains in two integer arrays hens and grains of size n and m respectively.\n Any hen can eat a grain if they are on the same position. The time taken for this is negligible. One hen can also eat multiple grains.\n In 1 second, a hen can move right or left by 1 unit. The hens can move simultaneously and independently of each other.\n Return the minimum time to eat all grains if the hens act optimally.\n \n Example 1:\n \n >>> minimumTime(hens = [3,6,7], grains = [2,4,7,9])\n >>> 2\n Explanation:\n One of the ways hens eat all grains in 2 seconds is described below:\n - The first hen eats the grain at position 2 in 1 second.\n - The second hen eats the grain at position 4 in 2 seconds.\n - The third hen eats the grains at positions 7 and 9 in 2 seconds.\n So, the maximum time needed is 2.\n It can be proven that the hens cannot eat all grains before 2 seconds.\n Example 2:\n \n >>> minimumTime(hens = [4,6,109,111,213,215], grains = [5,110,214])\n >>> 1\n Explanation:\n One of the ways hens eat all grains in 1 second is described below:\n - The first hen eats the grain at position 5 in 1 second.\n - The fourth hen eats the grain at position 110 in 1 second.\n - The sixth hen eats the grain at position 214 in 1 second.\n - The other hens do not move.\n So, the maximum time needed is 1.\n \"\"\"\n"}
{"task_id": "form-smallest-number-from-two-digit-arrays", "prompt": "def minNumber(nums1: List[int], nums2: List[int]) -> int:\n \"\"\"\n Given two arrays of unique digits nums1 and nums2, return the smallest number that contains at least one digit from each array.\n \n Example 1:\n \n >>> minNumber(nums1 = [4,1,3], nums2 = [5,7])\n >>> 15\n Explanation: The number 15 contains the digit 1 from nums1 and the digit 5 from nums2. It can be proven that 15 is the smallest number we can have.\n \n Example 2:\n \n >>> minNumber(nums1 = [3,5,2,6], nums2 = [3,1,7])\n >>> 3\n Explanation: The number 3 contains the digit 3 which exists in both arrays.\n \"\"\"\n"}
{"task_id": "find-the-substring-with-maximum-cost", "prompt": "def maximumCostSubstring(s: str, chars: str, vals: List[int]) -> int:\n \"\"\"\n You are given a string s, a string chars of distinct characters and an integer array vals of the same length as chars.\n The cost of the substring is the sum of the values of each character in the substring. The cost of an empty string is considered 0.\n The value of the character is defined in the following way:\n \n If the character is not in the string chars, then its value is its corresponding position (1-indexed) in the alphabet.\n \n \n For example, the value of 'a' is 1, the value of 'b' is 2, and so on. The value of 'z' is 26.\n \n \n Otherwise, assuming i is the index where the character occurs in the string chars, then its value is vals[i].\n \n Return the maximum cost among all substrings of the string s.\n \n Example 1:\n \n >>> maximumCostSubstring(s = \"adaa\", chars = \"d\", vals = [-1000])\n >>> 2\n Explanation: The value of the characters \"a\" and \"d\" is 1 and -1000 respectively.\n The substring with the maximum cost is \"aa\" and its cost is 1 + 1 = 2.\n It can be proven that 2 is the maximum cost.\n \n Example 2:\n \n >>> maximumCostSubstring(s = \"abc\", chars = \"abc\", vals = [-1,-1,-1])\n >>> 0\n Explanation: The value of the characters \"a\", \"b\" and \"c\" is -1, -1, and -1 respectively.\n The substring with the maximum cost is the empty substring \"\" and its cost is 0.\n It can be proven that 0 is the maximum cost.\n \"\"\"\n"}
{"task_id": "make-k-subarray-sums-equal", "prompt": "def makeSubKSumEqual(arr: List[int], k: int) -> int:\n \"\"\"\n You are given a 0-indexed integer array arr and an integer k. The array arr is circular. In other words, the first element of the array is the next element of the last element, and the last element of the array is the previous element of the first element.\n You can do the following operation any number of times:\n \n Pick any element from arr and increase or decrease it by 1.\n \n Return the minimum number of operations such that the sum of each subarray of length k is equal.\n A subarray is a contiguous part of the array.\n \n Example 1:\n \n >>> makeSubKSumEqual(arr = [1,4,1,3], k = 2)\n >>> 1\n Explanation: we can do one operation on index 1 to make its value equal to 3.\n The array after the operation is [1,3,1,3]\n - Subarray starts at index 0 is [1, 3], and its sum is 4\n - Subarray starts at index 1 is [3, 1], and its sum is 4\n - Subarray starts at index 2 is [1, 3], and its sum is 4\n - Subarray starts at index 3 is [3, 1], and its sum is 4\n \n Example 2:\n \n >>> makeSubKSumEqual(arr = [2,5,5,7], k = 3)\n >>> 5\n Explanation: we can do three operations on index 0 to make its value equal to 5 and two operations on index 3 to make its value equal to 5.\n The array after the operations is [5,5,5,5]\n - Subarray starts at index 0 is [5, 5, 5], and its sum is 15\n - Subarray starts at index 1 is [5, 5, 5], and its sum is 15\n - Subarray starts at index 2 is [5, 5, 5], and its sum is 15\n - Subarray starts at index 3 is [5, 5, 5], and its sum is 15\n \"\"\"\n"}
{"task_id": "shortest-cycle-in-a-graph", "prompt": "def findShortestCycle(n: int, edges: List[List[int]]) -> int:\n \"\"\"\n There is a bi-directional graph with n vertices, where each vertex is labeled from 0 to n - 1. The edges in the graph are represented by a given 2D integer array edges, where edges[i] = [ui, vi] denotes an edge between vertex ui and vertex vi. Every vertex pair is connected by at most one edge, and no vertex has an edge to itself.\n Return the length of the shortest cycle in the graph. If no cycle exists, return -1.\n A cycle is a path that starts and ends at the same node, and each edge in the path is used only once.\n \n Example 1:\n \n \n >>> findShortestCycle(n = 7, edges = [[0,1],[1,2],[2,0],[3,4],[4,5],[5,6],[6,3]])\n >>> 3\n Explanation: The cycle with the smallest length is : 0 -> 1 -> 2 -> 0\n \n Example 2:\n \n \n >>> findShortestCycle(n = 4, edges = [[0,1],[0,2]])\n >>> -1\n Explanation: There are no cycles in this graph.\n \"\"\"\n"}
{"task_id": "find-the-longest-balanced-substring-of-a-binary-string", "prompt": "def findTheLongestBalancedSubstring(s: str) -> int:\n \"\"\"\n You are given a binary string s consisting only of zeroes and ones.\n A substring of s is considered balanced if all zeroes are before ones and the number of zeroes is equal to the number of ones inside the substring. Notice that the empty substring is considered a balanced substring.\n Return the length of the longest balanced substring of s.\n A substring is a contiguous sequence of characters within a string.\n \n Example 1:\n \n >>> findTheLongestBalancedSubstring(s = \"01000111\")\n >>> 6\n Explanation: The longest balanced substring is \"000111\", which has length 6.\n \n Example 2:\n \n >>> findTheLongestBalancedSubstring(s = \"00111\")\n >>> 4\n Explanation: The longest balanced substring is \"0011\", which has length 4.\n \n Example 3:\n \n >>> findTheLongestBalancedSubstring(s = \"111\")\n >>> 0\n Explanation: There is no balanced substring except the empty substring, so the answer is 0.\n \"\"\"\n"}
{"task_id": "convert-an-array-into-a-2d-array-with-conditions", "prompt": "def findMatrix(nums: List[int]) -> List[List[int]]:\n \"\"\"\n You are given an integer array nums. You need to create a 2D array from nums satisfying the following conditions:\n \n The 2D array should contain only the elements of the array nums.\n Each row in the 2D array contains distinct integers.\n The number of rows in the 2D array should be minimal.\n \n Return the resulting array. If there are multiple answers, return any of them.\n Note that the 2D array can have a different number of elements on each row.\n \n Example 1:\n \n >>> findMatrix(nums = [1,3,4,1,2,3,1])\n >>> [[1,3,4,2],[1,3],[1]]\n Explanation: We can create a 2D array that contains the following rows:\n - 1,3,4,2\n - 1,3\n - 1\n All elements of nums were used, and each row of the 2D array contains distinct integers, so it is a valid answer.\n It can be shown that we cannot have less than 3 rows in a valid array.\n Example 2:\n \n >>> findMatrix(nums = [1,2,3,4])\n >>> [[4,3,2,1]]\n Explanation: All elements of the array are distinct, so we can keep all of them in the first row of the 2D array.\n \"\"\"\n"}
{"task_id": "mice-and-cheese", "prompt": "def miceAndCheese(reward1: List[int], reward2: List[int], k: int) -> int:\n \"\"\"\n There are two mice and n different types of cheese, each type of cheese should be eaten by exactly one mouse.\n A point of the cheese with index i (0-indexed) is:\n \n reward1[i] if the first mouse eats it.\n reward2[i] if the second mouse eats it.\n \n You are given a positive integer array reward1, a positive integer array reward2, and a non-negative integer k.\n Return the maximum points the mice can achieve if the first mouse eats exactly k types of cheese.\n \n Example 1:\n \n >>> miceAndCheese(reward1 = [1,1,3,4], reward2 = [4,4,1,1], k = 2)\n >>> 15\n Explanation: In this example, the first mouse eats the 2nd\u00a0(0-indexed) and the 3rd\u00a0types of cheese, and the second mouse eats the 0th\u00a0and the 1st types of cheese.\n The total points are 4 + 4 + 3 + 4 = 15.\n It can be proven that 15 is the maximum total points that the mice can achieve.\n \n Example 2:\n \n >>> miceAndCheese(reward1 = [1,1], reward2 = [1,1], k = 2)\n >>> 2\n Explanation: In this example, the first mouse eats the 0th\u00a0(0-indexed) and 1st\u00a0types of cheese, and the second mouse does not eat any cheese.\n The total points are 1 + 1 = 2.\n It can be proven that 2 is the maximum total points that the mice can achieve.\n \"\"\"\n"}
{"task_id": "beautiful-pairs", "prompt": "def beautifulPair(nums1: List[int], nums2: List[int]) -> List[int]:\n \"\"\"\n You are given two 0-indexed integer arrays nums1 and nums2 of the same length. A pair of indices (i,j) is called beautiful if|nums1[i] - nums1[j]| + |nums2[i] - nums2[j]| is the smallest amongst all possible indices pairs where i < j.\n Return the beautiful pair. In the case that there are multiple beautiful pairs, return the lexicographically smallest pair.\n Note that\n \n |x| denotes the absolute value of x.\n A pair of indices (i1, j1) is lexicographically smaller than (i2, j2) if i1 < i2 or i1 == i2 and j1 < j2.\n \n \n Example 1:\n \n >>> beautifulPair(nums1 = [1,2,3,2,4], nums2 = [2,3,1,2,3])\n >>> [0,3]\n Explanation: Consider index 0 and index 3. The value of |nums1[i]-nums1[j]| + |nums2[i]-nums2[j]| is 1, which is the smallest value we can achieve.\n \n Example 2:\n \n >>> beautifulPair(nums1 = [1,2,4,3,2,5], nums2 = [1,4,2,3,5,1])\n >>> [1,4]\n Explanation: Consider index 1 and index 4. The value of |nums1[i]-nums1[j]| + |nums2[i]-nums2[j]| is 1, which is the smallest value we can achieve.\n \"\"\"\n"}
{"task_id": "prime-in-diagonal", "prompt": "def diagonalPrime(nums: List[List[int]]) -> int:\n \"\"\"\n You are given a 0-indexed two-dimensional integer array nums.\n Return the largest prime number that lies on at least one of the diagonals of nums. In case, no prime is present on any of the diagonals, return 0.\n Note that:\n \n An integer is prime if it is greater than 1 and has no positive integer divisors other than 1 and itself.\n An integer val is on one of the diagonals of nums if there exists an integer i for which nums[i][i] = val or an i for which nums[i][nums.length - i - 1] = val.\n \n \n In the above diagram, one diagonal is [1,5,9] and another diagonal is [3,5,7].\n \n Example 1:\n \n >>> diagonalPrime(nums = [[1,2,3],[5,6,7],[9,10,11]])\n >>> 11\n Explanation: The numbers 1, 3, 6, 9, and 11 are the only numbers present on at least one of the diagonals. Since 11 is the largest prime, we return 11.\n \n Example 2:\n \n >>> diagonalPrime(nums = [[1,2,3],[5,17,7],[9,11,10]])\n >>> 17\n Explanation: The numbers 1, 3, 9, 10, and 17 are all present on at least one of the diagonals. 17 is the largest prime, so we return 17.\n \"\"\"\n"}
{"task_id": "sum-of-distances", "prompt": "def distance(nums: List[int]) -> List[int]:\n \"\"\"\n You are given a 0-indexed integer array nums. There exists an array arr of length nums.length, where arr[i] is the sum of |i - j| over all j such that nums[j] == nums[i] and j != i. If there is no such j, set arr[i] to be 0.\n Return the array arr.\n \n Example 1:\n \n >>> distance(nums = [1,3,1,1,2])\n >>> [5,0,3,4,0]\n Explanation:\n When i = 0, nums[0] == nums[2] and nums[0] == nums[3]. Therefore, arr[0] = |0 - 2| + |0 - 3| = 5.\n When i = 1, arr[1] = 0 because there is no other index with value 3.\n When i = 2, nums[2] == nums[0] and nums[2] == nums[3]. Therefore, arr[2] = |2 - 0| + |2 - 3| = 3.\n When i = 3, nums[3] == nums[0] and nums[3] == nums[2]. Therefore, arr[3] = |3 - 0| + |3 - 2| = 4.\n When i = 4, arr[4] = 0 because there is no other index with value 2.\n \n \n Example 2:\n \n >>> distance(nums = [0,5,3])\n >>> [0,0,0]\n Explanation: Since each element in nums is distinct, arr[i] = 0 for all i.\n \"\"\"\n"}
{"task_id": "minimize-the-maximum-difference-of-pairs", "prompt": "def minimizeMax(nums: List[int], p: int) -> int:\n \"\"\"\n You are given a 0-indexed integer array nums and an integer p. Find p pairs of indices of nums such that the maximum difference amongst all the pairs is minimized. Also, ensure no index appears more than once amongst the p pairs.\n Note that for a pair of elements at the index i and j, the difference of this pair is |nums[i] - nums[j]|, where |x| represents the absolute value of x.\n Return the minimum maximum difference among all p pairs. We define the maximum of an empty set to be zero.\n \n Example 1:\n \n >>> minimizeMax(nums = [10,1,2,7,1,3], p = 2)\n >>> 1\n Explanation: The first pair is formed from the indices 1 and 4, and the second pair is formed from the indices 2 and 5.\n The maximum difference is max(|nums[1] - nums[4]|, |nums[2] - nums[5]|) = max(0, 1) = 1. Therefore, we return 1.\n \n Example 2:\n \n >>> minimizeMax(nums = [4,2,1,2], p = 1)\n >>> 0\n Explanation: Let the indices 1 and 3 form a pair. The difference of that pair is |2 - 2| = 0, which is the minimum we can attain.\n \"\"\"\n"}
{"task_id": "minimum-number-of-visited-cells-in-a-grid", "prompt": "def minimumVisitedCells(grid: List[List[int]]) -> int:\n \"\"\"\n You are given a 0-indexed m x n integer matrix grid. Your initial position is at the top-left cell (0, 0).\n Starting from the cell (i, j), you can move to one of the following cells:\n \n Cells (i, k) with j < k <= grid[i][j] + j (rightward movement), or\n Cells (k, j) with i < k <= grid[i][j] + i (downward movement).\n \n Return the minimum number of cells you need to visit to reach the bottom-right cell (m - 1, n - 1). If there is no valid path, return -1.\n \n Example 1:\n \n \n >>> minimumVisitedCells(grid = [[3,4,2,1],[4,2,3,1],[2,1,0,0],[2,4,0,0]])\n >>> 4\n Explanation: The image above shows one of the paths that visits exactly 4 cells.\n \n Example 2:\n \n \n >>> minimumVisitedCells(grid = [[3,4,2,1],[4,2,1,1],[2,1,1,0],[3,4,1,0]])\n >>> 3\n Explanation: The image above shows one of the paths that visits exactly 3 cells.\n \n Example 3:\n \n \n >>> minimumVisitedCells(grid = [[2,1,0],[1,0,0]])\n >>> -1\n Explanation: It can be proven that no path exists.\n \"\"\"\n"}
{"task_id": "count-the-number-of-k-free-subsets", "prompt": "def countTheNumOfKFreeSubsets(nums: List[int], k: int) -> int:\n \"\"\"\n You are given an integer array nums,\u00a0which contains distinct elements and an integer k.\n A subset is called a k-Free subset if it contains no two elements with an absolute difference equal to k. Notice that the empty set is a k-Free subset.\n Return the number of k-Free subsets of nums.\n A subset of an array is a selection of elements (possibly none) of the array.\n \n Example 1:\n \n >>> countTheNumOfKFreeSubsets(nums = [5,4,6], k = 1)\n >>> 5\n Explanation: There are 5 valid subsets: {}, {5}, {4}, {6} and {4, 6}.\n \n Example 2:\n \n >>> countTheNumOfKFreeSubsets(nums = [2,3,5,8], k = 5)\n >>> 12\n Explanation: There are 12 valid subsets: {}, {2}, {3}, {5}, {8}, {2, 3}, {2, 3, 5}, {2, 5}, {2, 5, 8}, {2, 8}, {3, 5} and {5, 8}.\n \n Example 3:\n \n >>> countTheNumOfKFreeSubsets(nums = [10,5,9,11], k = 20)\n >>> 16\n Explanation: All subsets are valid. Since the total count of subsets is 24 = 16, so the answer is 16.\n \"\"\"\n"}
{"task_id": "find-the-width-of-columns-of-a-grid", "prompt": "def findColumnWidth(grid: List[List[int]]) -> List[int]:\n \"\"\"\n You are given a 0-indexed m x n integer matrix grid. The width of a column is the maximum length of its integers.\n \n For example, if grid = [[-10], [3], [12]], the width of the only column is 3 since -10 is of length 3.\n \n Return an integer array ans of size n where ans[i] is the width of the ith column.\n The length of an integer x with len digits is equal to len if x is non-negative, and len + 1 otherwise.\n \n Example 1:\n \n >>> findColumnWidth(grid = [[1],[22],[333]])\n >>> [3]\n Explanation: In the 0th column, 333 is of length 3.\n \n Example 2:\n \n >>> findColumnWidth(grid = [[-15,1,3],[15,7,12],[5,6,-2]])\n >>> [3,1,2]\n Explanation:\n In the 0th column, only -15 is of length 3.\n In the 1st column, all integers are of length 1.\n In the 2nd column, both 12 and -2 are of length 2.\n \"\"\"\n"}
{"task_id": "find-the-score-of-all-prefixes-of-an-array", "prompt": "def findPrefixScore(nums: List[int]) -> List[int]:\n \"\"\"\n We define the conversion array conver of an array arr as follows:\n \n conver[i] = arr[i] + max(arr[0..i]) where max(arr[0..i]) is the maximum value of arr[j] over 0 <= j <= i.\n \n We also define the score of an array arr as the sum of the values of the conversion array of arr.\n Given a 0-indexed integer array nums of length n, return an array ans of length n where ans[i] is the score of the prefix nums[0..i].\n \n Example 1:\n \n >>> findPrefixScore(nums = [2,3,7,5,10])\n >>> [4,10,24,36,56]\n Explanation:\n For the prefix [2], the conversion array is [4] hence the score is 4\n For the prefix [2, 3], the conversion array is [4, 6] hence the score is 10\n For the prefix [2, 3, 7], the conversion array is [4, 6, 14] hence the score is 24\n For the prefix [2, 3, 7, 5], the conversion array is [4, 6, 14, 12] hence the score is 36\n For the prefix [2, 3, 7, 5, 10], the conversion array is [4, 6, 14, 12, 20] hence the score is 56\n \n Example 2:\n \n >>> findPrefixScore(nums = [1,1,2,4,8,16])\n >>> [2,4,8,16,32,64]\n Explanation:\n For the prefix [1], the conversion array is [2] hence the score is 2\n For the prefix [1, 1], the conversion array is [2, 2] hence the score is 4\n For the prefix [1, 1, 2], the conversion array is [2, 2, 4] hence the score is 8\n For the prefix [1, 1, 2, 4], the conversion array is [2, 2, 4, 8] hence the score is 16\n For the prefix [1, 1, 2, 4, 8], the conversion array is [2, 2, 4, 8, 16] hence the score is 32\n For the prefix [1, 1, 2, 4, 8, 16], the conversion array is [2, 2, 4, 8, 16, 32] hence the score is 64\n \"\"\"\n"}
{"task_id": "cousins-in-binary-tree-ii", "prompt": "# class TreeNode:\n# def __init__(val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def replaceValueInTree(root: Optional[TreeNode]) -> Optional[TreeNode]:\n \"\"\"\n Given the root of a binary tree, replace the value of each node in the tree with the sum of all its cousins' values.\n Two nodes of a binary tree are cousins if they have the same depth with different parents.\n Return the root of the modified tree.\n Note that the depth of a node is the number of edges in the path from the root node to it.\n \n Example 1:\n \n \n >>> __init__(root = [5,4,9,1,10,null,7])\n >>> [0,0,0,7,7,null,11]\n Explanation: The diagram above shows the initial binary tree and the binary tree after changing the value of each node.\n - Node with value 5 does not have any cousins so its sum is 0.\n - Node with value 4 does not have any cousins so its sum is 0.\n - Node with value 9 does not have any cousins so its sum is 0.\n - Node with value 1 has a cousin with value 7 so its sum is 7.\n - Node with value 10 has a cousin with value 7 so its sum is 7.\n - Node with value 7 has cousins with values 1 and 10 so its sum is 11.\n \n Example 2:\n \n \n >>> __init__(root = [3,1,2])\n >>> [0,0,0]\n Explanation: The diagram above shows the initial binary tree and the binary tree after changing the value of each node.\n - Node with value 3 does not have any cousins so its sum is 0.\n - Node with value 1 does not have any cousins so its sum is 0.\n - Node with value 2 does not have any cousins so its sum is 0.\n \"\"\"\n"}
{"task_id": "row-with-maximum-ones", "prompt": "def rowAndMaximumOnes(mat: List[List[int]]) -> List[int]:\n \"\"\"\n Given a m x n binary matrix mat, find the 0-indexed position of the row that contains the maximum count of ones, and the number of ones in that row.\n In case there are multiple rows that have the maximum count of ones, the row with the smallest row number should be selected.\n Return an array containing the index of the row, and the number of ones in it.\n \n Example 1:\n \n >>> rowAndMaximumOnes(mat = [[0,1],[1,0]])\n >>> [0,1]\n Explanation: Both rows have the same number of 1's. So we return the index of the smaller row, 0, and the maximum count of ones (1). So, the answer is [0,1].\n \n Example 2:\n \n >>> rowAndMaximumOnes(mat = [[0,0,0],[0,1,1]])\n >>> [1,2]\n Explanation: The row indexed 1 has the maximum count of ones (2). So we return its index, 1, and the count. So, the answer is [1,2].\n \n Example 3:\n \n >>> rowAndMaximumOnes(mat = [[0,0],[1,1],[0,0]])\n >>> [1,2]\n Explanation: The row indexed 1 has the maximum count of ones (2). So the answer is [1,2].\n \"\"\"\n"}
{"task_id": "find-the-maximum-divisibility-score", "prompt": "def maxDivScore(nums: List[int], divisors: List[int]) -> int:\n \"\"\"\n You are given two integer arrays nums and divisors.\n The divisibility score of divisors[i] is the number of indices j such that nums[j] is divisible by divisors[i].\n Return the integer divisors[i] with the maximum divisibility score. If multiple integers have the maximum score, return the smallest one.\n \n Example 1:\n \n >>> maxDivScore(nums = [2,9,15,50], divisors = [5,3,7,2])\n >>> 2\n Explanation:\n The divisibility score of divisors[0] is 2 since nums[2] and nums[3] are divisible by 5.\n The divisibility score of divisors[1] is 2 since nums[1] and nums[2] are divisible by 3.\n The divisibility score of divisors[2] is 0 since none of the numbers in nums is divisible by 7.\n The divisibility score of divisors[3] is 2 since nums[0] and nums[3] are divisible by 2.\n As divisors[0],\u00a0divisors[1], and divisors[3] have the same divisibility score, we return the smaller one which is divisors[3].\n \n Example 2:\n \n >>> maxDivScore(nums = [4,7,9,3,9], divisors = [5,2,3])\n >>> 3\n Explanation:\n The divisibility score of divisors[0] is 0 since none of numbers in nums is divisible by 5.\n The divisibility score of divisors[1] is 1 since only nums[0] is divisible by 2.\n The divisibility score of divisors[2] is 3 since nums[2], nums[3] and nums[4] are divisible by 3.\n \n Example 3:\n \n >>> maxDivScore(nums = [20,14,21,10], divisors = [10,16,20])\n >>> 10\n Explanation:\n The divisibility score of divisors[0] is 2 since nums[0] and nums[3] are divisible by 10.\n The divisibility score of divisors[1] is 0 since none of the numbers in nums is divisible by 16.\n The divisibility score of divisors[2] is 1 since nums[0] is divisible by 20.\n \"\"\"\n"}
{"task_id": "minimum-additions-to-make-valid-string", "prompt": "def addMinimum(word: str) -> int:\n \"\"\"\n Given a string word to which you can insert letters \"a\", \"b\" or \"c\" anywhere and any number of times, return the minimum number of letters that must be inserted so that word becomes valid.\n A string is called valid if it can be formed by concatenating the string \"abc\" several times.\n \n Example 1:\n \n >>> addMinimum(word = \"b\")\n >>> 2\n Explanation: Insert the letter \"a\" right before \"b\", and the letter \"c\" right next to \"b\" to obtain the valid string \"abc\".\n \n Example 2:\n \n >>> addMinimum(word = \"aaa\")\n >>> 6\n Explanation: Insert letters \"b\" and \"c\" next to each \"a\" to obtain the valid string \"abcabcabc\".\n \n Example 3:\n \n >>> addMinimum(word = \"abc\")\n >>> 0\n Explanation: word is already valid. No modifications are needed.\n \"\"\"\n"}
{"task_id": "minimize-the-total-price-of-the-trips", "prompt": "def minimumTotalPrice(n: int, edges: List[List[int]], price: List[int], trips: List[List[int]]) -> int:\n \"\"\"\n There exists an undirected and unrooted tree with n nodes indexed from 0 to n - 1. You are given the integer n and a 2D integer array edges of length n - 1, where edges[i] = [ai, bi] indicates that there is an edge between nodes ai and bi in the tree.\n Each node has an associated price. You are given an integer array price, where price[i] is the price of the ith node.\n The price sum of a given path is the sum of the prices of all nodes lying on that path.\n Additionally, you are given a 2D integer array trips, where trips[i] = [starti, endi] indicates that you start the ith trip from the node starti and travel to the node endi by any path you like.\n Before performing your first trip, you can choose some non-adjacent nodes and halve the prices.\n Return the minimum total price sum to perform all the given trips.\n \n Example 1:\n \n \n >>> minimumTotalPrice(n = 4, edges = [[0,1],[1,2],[1,3]], price = [2,2,10,6], trips = [[0,3],[2,1],[2,3]])\n >>> 23\n Explanation: The diagram above denotes the tree after rooting it at node 2. The first part shows the initial tree and the second part shows the tree after choosing nodes 0, 2, and 3, and making their price half.\n For the 1st trip, we choose path [0,1,3]. The price sum of that path is 1 + 2 + 3 = 6.\n For the 2nd trip, we choose path [2,1]. The price sum of that path is 2 + 5 = 7.\n For the 3rd trip, we choose path [2,1,3]. The price sum of that path is 5 + 2 + 3 = 10.\n The total price sum of all trips is 6 + 7 + 10 = 23.\n It can be proven, that 23 is the minimum answer that we can achieve.\n \n Example 2:\n \n \n >>> minimumTotalPrice(n = 2, edges = [[0,1]], price = [2,2], trips = [[0,0]])\n >>> 1\n Explanation: The diagram above denotes the tree after rooting it at node 0. The first part shows the initial tree and the second part shows the tree after choosing node 0, and making its price half.\n For the 1st trip, we choose path [0]. The price sum of that path is 1.\n The total price sum of all trips is 1. It can be proven, that 1 is the minimum answer that we can achieve.\n \"\"\"\n"}
{"task_id": "color-the-triangle-red", "prompt": "def colorRed(n: int) -> List[List[int]]:\n \"\"\"\n You are given an integer n. Consider an equilateral triangle of side length n, broken up into n2 unit equilateral triangles. The triangle has n 1-indexed rows where the ith row has 2i - 1 unit equilateral triangles.\n The triangles in the ith row are also 1-indexed with coordinates from (i, 1) to (i, 2i - 1). The following image shows a triangle of side length 4 with the indexing of its triangle.\n \n Two triangles are neighbors if they share a side. For example:\n \n Triangles (1,1) and (2,2) are neighbors\n Triangles (3,2) and (3,3) are neighbors.\n Triangles (2,2) and (3,3) are not neighbors because they do not share any side.\n \n Initially, all the unit triangles are white. You want to choose k triangles and color them red. We will then run the following algorithm:\n \n Choose a white triangle that has at least two red neighbors.\n \n \n If there is no such triangle, stop the algorithm.\n \n \n Color that triangle red.\n Go to step 1.\n \n Choose the minimum k possible and set k triangles red before running this algorithm such that after the algorithm stops, all unit triangles are colored red.\n Return a 2D list of the coordinates of the triangles that you will color red initially. The answer has to be of the smallest size possible. If there are multiple valid solutions, return any.\n \n Example 1:\n \n \n >>> colorRed(n = 3)\n >>> [[1,1],[2,1],[2,3],[3,1],[3,5]]\n Explanation: Initially, we choose the shown 5 triangles to be red. Then, we run the algorithm:\n - Choose (2,2) that has three red neighbors and color it red.\n - Choose (3,2) that has two red neighbors and color it red.\n - Choose (3,4) that has three red neighbors and color it red.\n - Choose (3,3) that has three red neighbors and color it red.\n It can be shown that choosing any 4 triangles and running the algorithm will not make all triangles red.\n \n Example 2:\n \n \n >>> colorRed(n = 2)\n >>> [[1,1],[2,1],[2,3]]\n Explanation: Initially, we choose the shown 3 triangles to be red. Then, we run the algorithm:\n - Choose (2,2) that has three red neighbors and color it red.\n It can be shown that choosing any 2 triangles and running the algorithm will not make all triangles red.\n \"\"\"\n"}
{"task_id": "calculate-delayed-arrival-time", "prompt": "def findDelayedArrivalTime(arrivalTime: int, delayedTime: int) -> int:\n \"\"\"\n You are given a positive integer arrivalTime denoting the arrival time of a train in hours, and another positive integer delayedTime denoting the amount of delay in hours.\n Return the time when the train will arrive at the station.\n Note that the time in this problem is in 24-hours format.\n \n Example 1:\n \n >>> findDelayedArrivalTime(arrivalTime = 15, delayedTime = 5)\n >>> 20\n Explanation: Arrival time of the train was 15:00 hours. It is delayed by 5 hours. Now it will reach at 15+5 = 20 (20:00 hours).\n \n Example 2:\n \n >>> findDelayedArrivalTime(arrivalTime = 13, delayedTime = 11)\n >>> 0\n Explanation: Arrival time of the train was 13:00 hours. It is delayed by 11 hours. Now it will reach at 13+11=24 (Which is denoted by 00:00 in 24 hours format so return 0).\n \"\"\"\n"}
{"task_id": "sum-multiples", "prompt": "def sumOfMultiples(n: int) -> int:\n \"\"\"\n Given a positive integer n, find the sum of all integers in the range [1, n] inclusive that are divisible by 3, 5, or 7.\n Return an integer denoting the sum of all numbers in the given range satisfying\u00a0the constraint.\n \n Example 1:\n \n >>> sumOfMultiples(n = 7)\n >>> 21\n Explanation: Numbers in the range [1, 7] that are divisible by 3, 5, or 7 are 3, 5, 6, 7. The sum of these numbers is 21.\n \n Example 2:\n \n >>> sumOfMultiples(n = 10)\n >>> 40\n Explanation: Numbers in the range [1, 10] that are divisible by 3, 5, or 7 are 3, 5, 6, 7, 9, 10. The sum of these numbers is 40.\n \n Example 3:\n \n >>> sumOfMultiples(n = 9)\n >>> 30\n Explanation: Numbers in the range [1, 9] that are divisible by 3, 5, or 7 are 3, 5, 6, 7, 9. The sum of these numbers is 30.\n \"\"\"\n"}
{"task_id": "sliding-subarray-beauty", "prompt": "def getSubarrayBeauty(nums: List[int], k: int, x: int) -> List[int]:\n \"\"\"\n Given an integer array nums containing n integers, find the beauty of each subarray of size k.\n The beauty of a subarray is the xth smallest integer in the subarray if it is negative, or 0 if there are fewer than x negative integers.\n Return an integer array containing n - k + 1 integers, which denote the beauty of the subarrays in order from the first index in the array.\n \n \n A subarray is a contiguous non-empty sequence of elements within an array.\n \n \n \n Example 1:\n \n >>> getSubarrayBeauty(nums = [1,-1,-3,-2,3], k = 3, x = 2)\n >>> [-1,-2,-2]\n Explanation: There are 3 subarrays with size k = 3.\n The first subarray is [1, -1, -3] and the 2nd smallest negative integer is -1.\n The second subarray is [-1, -3, -2] and the 2nd smallest negative integer is -2.\n The third subarray is [-3, -2, 3]\u00a0and the 2nd smallest negative integer is -2.\n Example 2:\n \n >>> getSubarrayBeauty(nums = [-1,-2,-3,-4,-5], k = 2, x = 2)\n >>> [-1,-2,-3,-4]\n Explanation: There are 4 subarrays with size k = 2.\n For [-1, -2], the 2nd smallest negative integer is -1.\n For [-2, -3], the 2nd smallest negative integer is -2.\n For [-3, -4], the 2nd smallest negative integer is -3.\n For [-4, -5], the 2nd smallest negative integer is -4.\n Example 3:\n \n >>> getSubarrayBeauty(nums = [-3,1,2,-3,0,-3], k = 2, x = 1)\n >>> [-3,0,-3,-3,-3]\n Explanation: There are 5 subarrays with size k = 2.\n For [-3, 1], the 1st smallest negative integer is -3.\n For [1, 2], there is no negative integer so the beauty is 0.\n For [2, -3], the 1st smallest negative integer is -3.\n For [-3, 0], the 1st smallest negative integer is -3.\n For [0, -3], the 1st smallest negative integer is -3.\n \"\"\"\n"}
{"task_id": "minimum-number-of-operations-to-make-all-array-elements-equal-to-1", "prompt": "def minOperations(nums: List[int]) -> int:\n \"\"\"\n You are given a 0-indexed\u00a0array nums consisiting of positive integers. You can do the following operation on the array any number of times:\n \n Select an index i such that 0 <= i < n - 1 and replace either of\u00a0nums[i] or nums[i+1] with their gcd value.\n \n Return the minimum number of operations to make all elements of nums equal to 1. If it is impossible, return -1.\n The gcd of two integers is the greatest common divisor of the two integers.\n \n Example 1:\n \n >>> minOperations(nums = [2,6,3,4])\n >>> 4\n Explanation: We can do the following operations:\n - Choose index i = 2 and replace nums[2] with gcd(3,4) = 1. Now we have nums = [2,6,1,4].\n - Choose index i = 1 and replace nums[1] with gcd(6,1) = 1. Now we have nums = [2,1,1,4].\n - Choose index i = 0 and replace nums[0] with gcd(2,1) = 1. Now we have nums = [1,1,1,4].\n - Choose index i = 2 and replace nums[3] with gcd(1,4) = 1. Now we have nums = [1,1,1,1].\n \n Example 2:\n \n >>> minOperations(nums = [2,10,6,14])\n >>> -1\n Explanation: It can be shown that it is impossible to make all the elements equal to 1.\n \"\"\"\n"}
{"task_id": "find-maximal-uncovered-ranges", "prompt": "def findMaximalUncoveredRanges(n: int, ranges: List[List[int]]) -> List[List[int]]:\n \"\"\"\n You are given\u00a0an integer n\u00a0which is the length of a 0-indexed array nums, and a 0-indexed 2D-array ranges, which is a list of sub-ranges of nums\u00a0(sub-ranges may overlap).\n Each row ranges[i] has exactly 2 cells:\n \n ranges[i][0], which shows the start of the ith range (inclusive)\n ranges[i][1], which shows the end of the ith range (inclusive)\n \n These ranges cover some cells of nums\u00a0and leave\u00a0some cells uncovered. Your task is to find all of the uncovered ranges with maximal length.\n Return a 2D-array answer of the uncovered ranges, sorted by the starting point in ascending order.\n By all of the\u00a0uncovered ranges with maximal length, we mean satisfying two conditions:\n \n Each uncovered cell should belong to exactly one sub-range\n There should not exist\u00a0two ranges (l1, r1) and (l2, r2) such that r1 + 1 = l2\n \n \n Example 1:\n \n >>> findMaximalUncoveredRanges(n = 10, ranges = [[3,5],[7,8]])\n >>> [[0,2],[6,6],[9,9]]\n Explanation: The ranges (3, 5) and (7, 8) are covered, so if we simplify the array nums to a binary array where 0 shows an uncovered cell and 1 shows a covered cell, the array becomes [0,0,0,1,1,1,0,1,1,0] in which we can observe that the ranges (0, 2), (6, 6) and (9, 9) aren't covered.\n \n Example 2:\n \n >>> findMaximalUncoveredRanges(n = 3, ranges = [[0,2]])\n >>> []\n Explanation: In this example, the whole of the array nums is covered and there are no uncovered cells so the output is an empty array.\n \n Example 3:\n \n >>> findMaximalUncoveredRanges(n = 7, ranges = [[2,4],[0,3]])\n >>> [[5,6]]\n Explanation: The ranges (0, 3) and (2, 4) are covered, so if we simplify the array nums to a binary array where 0 shows an uncovered cell and 1 shows a covered cell, the array becomes [1,1,1,1,1,0,0] in which we can observe that the range (5, 6) is uncovered.\n \"\"\"\n"}
{"task_id": "maximum-sum-with-exactly-k-elements", "prompt": "def maximizeSum(nums: List[int], k: int) -> int:\n \"\"\"\n You are given a 0-indexed integer array nums and an integer k. Your task is to perform the following operation exactly k times in order to maximize your score:\n \n Select an element m from nums.\n Remove the selected element m from the array.\n Add a new element with a value of m + 1 to the array.\n Increase your score by m.\n \n Return the maximum score you can achieve after performing the operation exactly k times.\n \n Example 1:\n \n >>> maximizeSum(nums = [1,2,3,4,5], k = 3)\n >>> 18\n Explanation: We need to choose exactly 3 elements from nums to maximize the sum.\n For the first iteration, we choose 5. Then sum is 5 and nums = [1,2,3,4,6]\n For the second iteration, we choose 6. Then sum is 5 + 6 and nums = [1,2,3,4,7]\n For the third iteration, we choose 7. Then sum is 5 + 6 + 7 = 18 and nums = [1,2,3,4,8]\n So, we will return 18.\n It can be proven, that 18 is the maximum answer that we can achieve.\n \n Example 2:\n \n >>> maximizeSum(nums = [5,5,5], k = 2)\n >>> 11\n Explanation: We need to choose exactly 2 elements from nums to maximize the sum.\n For the first iteration, we choose 5. Then sum is 5 and nums = [5,5,6]\n For the second iteration, we choose 6. Then sum is 5 + 6 = 11 and nums = [5,5,7]\n So, we will return 11.\n It can be proven, that 11 is the maximum answer that we can achieve.\n \"\"\"\n"}
{"task_id": "find-the-prefix-common-array-of-two-arrays", "prompt": "def findThePrefixCommonArray(A: List[int], B: List[int]) -> List[int]:\n \"\"\"\n You are given two 0-indexed integer permutations A and B of length n.\n A prefix common array of A and B is an array C such that C[i] is equal to the count of numbers that are present at or before the index i in both A and B.\n Return the prefix common array of A and B.\n A sequence of n integers is called a\u00a0permutation if it contains all integers from 1 to n exactly once.\n \n Example 1:\n \n >>> findThePrefixCommonArray(A = [1,3,2,4], B = [3,1,2,4])\n >>> [0,2,3,4]\n Explanation: At i = 0: no number is common, so C[0] = 0.\n At i = 1: 1 and 3 are common in A and B, so C[1] = 2.\n At i = 2: 1, 2, and 3 are common in A and B, so C[2] = 3.\n At i = 3: 1, 2, 3, and 4 are common in A and B, so C[3] = 4.\n \n Example 2:\n \n >>> findThePrefixCommonArray(A = [2,3,1], B = [3,1,2])\n >>> [0,1,3]\n Explanation: At i = 0: no number is common, so C[0] = 0.\n At i = 1: only 3 is common in A and B, so C[1] = 1.\n At i = 2: 1, 2, and 3 are common in A and B, so C[2] = 3.\n \"\"\"\n"}
{"task_id": "maximum-number-of-fish-in-a-grid", "prompt": "def findMaxFish(grid: List[List[int]]) -> int:\n \"\"\"\n You are given a 0-indexed 2D matrix grid of size m x n, where (r, c) represents:\n \n A land cell if grid[r][c] = 0, or\n A water cell containing grid[r][c] fish, if grid[r][c] > 0.\n \n A fisher can start at any water cell (r, c) and can do the following operations any number of times:\n \n Catch all the fish at cell (r, c), or\n Move to any adjacent water cell.\n \n Return the maximum number of fish the fisher can catch if he chooses his starting cell optimally, or 0 if no water cell exists.\n An adjacent cell of the cell (r, c), is one of the cells (r, c + 1), (r, c - 1), (r + 1, c) or (r - 1, c) if it exists.\n \n Example 1:\n \n \n >>> findMaxFish(grid = [[0,2,1,0],[4,0,0,3],[1,0,0,4],[0,3,2,0]])\n >>> 7\n Explanation: The fisher can start at cell (1,3) and collect 3 fish, then move to cell (2,3)\u00a0and collect 4 fish.\n \n Example 2:\n \n \n >>> findMaxFish(grid = [[1,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,1]])\n >>> 1\n Explanation: The fisher can start at cells (0,0) or (3,3) and collect a single fish.\n \"\"\"\n"}
{"task_id": "make-array-empty", "prompt": "def countOperationsToEmptyArray(nums: List[int]) -> int:\n \"\"\"\n You are given an integer array nums containing distinct numbers, and you can perform the following operations until the array is empty:\n \n If the first element has the smallest value, remove it\n Otherwise, put the first element at the end of the array.\n \n Return an integer denoting the number of operations it takes to make nums empty.\n \n Example 1:\n \n >>> countOperationsToEmptyArray(nums = [3,4,-1])\n >>> 5\n \n \n \n \n Operation\n Array\n \n \n \n \n 1\n [4, -1, 3]\n \n \n 2\n [-1, 3, 4]\n \n \n 3\n [3, 4]\n \n \n 4\n [4]\n \n \n 5\n []\n \n \n \n Example 2:\n \n >>> countOperationsToEmptyArray(nums = [1,2,4,3])\n >>> 5\n \n \n \n \n Operation\n Array\n \n \n \n \n 1\n [2, 4, 3]\n \n \n 2\n [4, 3]\n \n \n 3\n [3, 4]\n \n \n 4\n [4]\n \n \n 5\n []\n \n \n \n Example 3:\n \n >>> countOperationsToEmptyArray(nums = [1,2,3])\n >>> 3\n \n \n \n \n Operation\n Array\n \n \n \n \n 1\n [2, 3]\n \n \n 2\n [3]\n \n \n 3\n []\n \"\"\"\n"}
{"task_id": "determine-the-winner-of-a-bowling-game", "prompt": "def isWinner(player1: List[int], player2: List[int]) -> int:\n \"\"\"\n You are given two 0-indexed integer arrays player1 and player2, representing the number of pins that player 1 and player 2 hit in a bowling game, respectively.\n The bowling game consists of n turns, and the number of pins in each turn is exactly 10.\n Assume a player hits xi pins in the ith turn. The value of the ith turn for the player is:\n \n 2xi if the player hits 10 pins in either (i - 1)th or (i - 2)th turn.\n Otherwise, it is xi.\n \n The score of the player is the sum of the values of their n turns.\n Return\n \n 1 if the score of player 1 is more than the score of player 2,\n 2 if the score of player 2 is more than the score of player 1, and\n 0 in case of a draw.\n \n \n Example 1:\n \n >>> isWinner(player1 = [5,10,3,2], player2 = [6,5,7,3])\n >>> 1\n Explanation:\n The score of player 1 is 5 + 10 + 2*3 + 2*2 = 25.\n The score of player 2 is 6 + 5 + 7 + 3 = 21.\n \n Example 2:\n \n >>> isWinner(player1 = [3,5,7,6], player2 = [8,10,10,2])\n >>> 2\n Explanation:\n The score of player 1 is 3 + 5 + 7 + 6 = 21.\n The score of player 2 is 8 + 10 + 2*10 + 2*2 = 42.\n \n Example 3:\n \n >>> isWinner(player1 = [2,3], player2 = [4,1])\n >>> 0\n Explanation:\n The score of player1 is 2 + 3 = 5.\n The score of player2 is 4 + 1 = 5.\n \n Example 4:\n \n >>> isWinner(player1 = [1,1,1,10,10,10,10], player2 = [10,10,10,10,1,1,1])\n >>> 2\n Explanation:\n The score of player1 is 1 + 1 + 1 + 10 + 2*10 + 2*10 + 2*10 = 73.\n The score of player2 is 10 + 2*10 + 2*10 + 2*10 + 2*1 + 2*1 + 1 = 75.\n \"\"\"\n"}
{"task_id": "first-completely-painted-row-or-column", "prompt": "def firstCompleteIndex(arr: List[int], mat: List[List[int]]) -> int:\n \"\"\"\n You are given a 0-indexed integer array arr, and an m x n integer matrix mat. arr and mat both contain all the integers in the range [1, m * n].\n Go through each index i in arr starting from index 0 and paint the cell in mat containing the integer arr[i].\n Return the smallest index i at which either a row or a column will be completely painted in mat.\n \n Example 1:\n \n \n >>> firstCompleteIndex(arr = [1,3,4,2], mat = [[1,4],[2,3]])\n >>> 2\n Explanation: The moves are shown in order, and both the first row and second column of the matrix become fully painted at arr[2].\n \n Example 2:\n \n \n >>> firstCompleteIndex(arr = [2,8,7,4,1,3,5,6,9], mat = [[3,2,5],[1,4,6],[8,7,9]])\n >>> 3\n Explanation: The second column becomes fully painted at arr[3].\n \"\"\"\n"}
{"task_id": "minimum-cost-of-a-path-with-special-roads", "prompt": "def minimumCost(start: List[int], target: List[int], specialRoads: List[List[int]]) -> int:\n \"\"\"\n You are given an array start where start = [startX, startY] represents your initial position (startX, startY) in a 2D space. You are also given the array target where target = [targetX, targetY] represents your target position (targetX, targetY).\n The cost of going from a position (x1, y1) to any other position in the space (x2, y2) is |x2 - x1| + |y2 - y1|.\n There are also some special roads. You are given a 2D array specialRoads where specialRoads[i] = [x1i, y1i, x2i, y2i, costi] indicates that the ith special road goes in one direction from (x1i, y1i) to (x2i, y2i) with a cost equal to costi. You can use each special road any number of times.\n Return the minimum cost required to go from (startX, startY) to (targetX, targetY).\n \n Example 1:\n \n >>> minimumCost(start = [1,1], target = [4,5], specialRoads = [[1,2,3,3,2],[3,4,4,5,1]])\n >>> 5\n Explanation:\n \n (1,1) to (1,2) with a cost of |1 - 1| + |2 - 1| = 1.\n (1,2) to (3,3). Use specialRoads[0] with the cost 2.\n (3,3) to (3,4) with a cost of |3 - 3| + |4 - 3| = 1.\n (3,4) to (4,5). Use specialRoads[1] with the cost 1.\n \n So the total cost is 1 + 2 + 1 + 1 = 5.\n \n Example 2:\n \n >>> minimumCost(start = [3,2], target = [5,7], specialRoads = [[5,7,3,2,1],[3,2,3,4,4],[3,3,5,5,5],[3,4,5,6,6]])\n >>> 7\n Explanation:\n It is optimal not to use any special edges and go directly from the starting to the ending position with a cost |5 - 3| + |7 - 2| = 7.\n Note that the specialRoads[0] is directed from (5,7) to (3,2).\n \n Example 3:\n \n >>> minimumCost(start = [1,1], target = [10,4], specialRoads = [[4,2,1,1,3],[1,2,7,4,4],[10,3,6,1,2],[6,1,1,2,3]])\n >>> 8\n Explanation:\n \n (1,1) to (1,2) with a cost of |1 - 1| + |2 - 1| = 1.\n (1,2) to (7,4). Use specialRoads[1] with the cost 4.\n (7,4) to (10,4) with a cost of |10 - 7| + |4 - 4| = 3.\n \"\"\"\n"}
{"task_id": "lexicographically-smallest-beautiful-string", "prompt": "def smallestBeautifulString(s: str, k: int) -> str:\n \"\"\"\n A string is beautiful if:\n \n It consists of the first k letters of the English lowercase alphabet.\n It does not contain any substring of length 2 or more which is a palindrome.\n \n You are given a beautiful string s of length n and a positive integer k.\n Return the lexicographically smallest string of length n, which is larger than s and is beautiful. If there is no such string, return an empty string.\n A string a is lexicographically larger than a string b (of the same length) if in the first position where a and b differ, a has a character strictly larger than the corresponding character in b.\n \n For example, \"abcd\" is lexicographically larger than \"abcc\" because the first position they differ is at the fourth character, and d is greater than c.\n \n \n Example 1:\n \n >>> smallestBeautifulString(s = \"abcz\", k = 26)\n >>> \"abda\"\n Explanation: The string \"abda\" is beautiful and lexicographically larger than the string \"abcz\".\n It can be proven that there is no string that is lexicographically larger than the string \"abcz\", beautiful, and lexicographically smaller than the string \"abda\".\n \n Example 2:\n \n >>> smallestBeautifulString(s = \"dc\", k = 4)\n >>> \"\"\n Explanation: It can be proven that there is no string that is lexicographically larger than the string \"dc\" and is beautiful.\n \"\"\"\n"}
{"task_id": "the-knights-tour", "prompt": "def tourOfKnight(m: int, n: int, r: int, c: int) -> List[List[int]]:\n \"\"\"\n Given two positive integers m and n which are the height and width of a 0-indexed 2D-array board, a pair of positive integers (r, c) which is the starting position of the knight on the board.\n Your task is to find an order of movements for the knight, in a manner that every cell of the\u00a0board gets visited exactly once (the starting cell is considered visited and you shouldn't visit it again).\n Return the array board in which the cells' values show the order of visiting the cell starting from 0 (the initial place of the knight).\n Note that a knight can move from cell (r1, c1) to cell (r2, c2) if 0 <= r2 <= m - 1 and 0 <= c2 <= n - 1 and min(abs(r1 - r2), abs(c1 - c2)) = 1 and max(abs(r1 - r2), abs(c1 - c2)) = 2.\n \n Example 1:\n \n >>> tourOfKnight(m = 1, n = 1, r = 0, c = 0)\n >>> [[0]]\n Explanation: There is only 1 cell and the knight is initially on it so there is only a 0 inside the 1x1 grid.\n \n Example 2:\n \n >>> tourOfKnight(m = 3, n = 4, r = 0, c = 0)\n >>> [[0,3,6,9],[11,8,1,4],[2,5,10,7]]\n Explanation: By the following order of movements we can visit the entire board.\n (0,0)->(1,2)->(2,0)->(0,1)->(1,3)->(2,1)->(0,2)->(2,3)->(1,1)->(0,3)->(2,2)->(1,0)\n \"\"\"\n"}
{"task_id": "find-the-distinct-difference-array", "prompt": "def distinctDifferenceArray(nums: List[int]) -> List[int]:\n \"\"\"\n You are given a 0-indexed array nums of length n.\n The distinct difference array of nums is an array diff of length n such that diff[i] is equal to the number of distinct elements in the suffix nums[i + 1, ..., n - 1] subtracted from the number of distinct elements in the prefix nums[0, ..., i].\n Return the distinct difference array of nums.\n Note that nums[i, ..., j] denotes the subarray of nums starting at index i and ending at index j inclusive. Particularly, if i > j then nums[i, ..., j] denotes an empty subarray.\n \n Example 1:\n \n >>> distinctDifferenceArray(nums = [1,2,3,4,5])\n >>> [-3,-1,1,3,5]\n Explanation: For index i = 0, there is 1 element in the prefix and 4 distinct elements in the suffix. Thus, diff[0] = 1 - 4 = -3.\n For index i = 1, there are 2 distinct elements in the prefix and 3 distinct elements in the suffix. Thus, diff[1] = 2 - 3 = -1.\n For index i = 2, there are 3 distinct elements in the prefix and 2 distinct elements in the suffix. Thus, diff[2] = 3 - 2 = 1.\n For index i = 3, there are 4 distinct elements in the prefix and 1 distinct element in the suffix. Thus, diff[3] = 4 - 1 = 3.\n For index i = 4, there are 5 distinct elements in the prefix and no elements in the suffix. Thus, diff[4] = 5 - 0 = 5.\n \n Example 2:\n \n >>> distinctDifferenceArray(nums = [3,2,3,4,2])\n >>> [-2,-1,0,2,3]\n Explanation: For index i = 0, there is 1 element in the prefix and 3 distinct elements in the suffix. Thus, diff[0] = 1 - 3 = -2.\n For index i = 1, there are 2 distinct elements in the prefix and 3 distinct elements in the suffix. Thus, diff[1] = 2 - 3 = -1.\n For index i = 2, there are 2 distinct elements in the prefix and 2 distinct elements in the suffix. Thus, diff[2] = 2 - 2 = 0.\n For index i = 3, there are 3 distinct elements in the prefix and 1 distinct element in the suffix. Thus, diff[3] = 3 - 1 = 2.\n For index i = 4, there are 3 distinct elements in the prefix and no elements in the suffix. Thus, diff[4] = 3 - 0 = 3.\n \"\"\"\n"}
{"task_id": "number-of-adjacent-elements-with-the-same-color", "prompt": "def colorTheArray(n: int, queries: List[List[int]]) -> List[int]:\n \"\"\"\n You are given an integer n representing an array colors of length n where all elements are set to 0's meaning uncolored. You are also given a 2D integer array queries where queries[i] = [indexi, colori]. For the ith query:\n \n Set colors[indexi] to colori.\n Count adjacent pairs in colors set to the same color (regardless of colori).\n \n Return an array answer of the same length as queries where answer[i] is the answer to the ith query.\n \n Example 1:\n \n >>> colorTheArray(n = 4, queries = [[0,2],[1,2],[3,1],[1,1],[2,1]])\n >>> [0,1,1,0,2]\n Explanation:\n \n Initially array colors = [0,0,0,0], where 0 denotes uncolored elements of the array.\n After the 1st query colors = [2,0,0,0]. The count of adjacent pairs with the same color is 0.\n After the 2nd query colors = [2,2,0,0]. The count of adjacent pairs with the same color is 1.\n After the 3rd query colors = [2,2,0,1]. The count of adjacent pairs with the same color is 1.\n After the 4th query colors = [2,1,0,1]. The count of adjacent pairs with the same color is 0.\n After the 5th query colors = [2,1,1,1]. The count of adjacent pairs with the same color is 2.\n \n \n Example 2:\n \n >>> colorTheArray(n = 1, queries = [[0,100000]])\n >>> [0]\n Explanation:\n After the 1st query colors = [100000]. The count of adjacent pairs with the same color is 0.\n \"\"\"\n"}
{"task_id": "make-costs-of-paths-equal-in-a-binary-tree", "prompt": "def minIncrements(n: int, cost: List[int]) -> int:\n \"\"\"\n You are given an integer n representing the number of nodes in a perfect binary tree consisting of nodes numbered from 1 to n. The root of the tree is node 1 and each node i in the tree has two children where the left child is the node 2 * i and the right child is 2 * i + 1.\n Each node in the tree also has a cost represented by a given 0-indexed integer array cost of size n where cost[i] is the cost of node i + 1. You are allowed to increment the cost of any node by 1 any number of times.\n Return the minimum number of increments you need to make the cost of paths from the root to each leaf node equal.\n Note:\n \n A perfect binary tree is a tree where each node, except the leaf nodes, has exactly 2 children.\n The cost of a path is the sum of costs of nodes in the path.\n \n \n Example 1:\n \n \n >>> minIncrements(n = 7, cost = [1,5,2,2,3,3,1])\n >>> 6\n Explanation: We can do the following increments:\n - Increase the cost of node 4 one time.\n - Increase the cost of node 3 three times.\n - Increase the cost of node 7 two times.\n Each path from the root to a leaf will have a total cost of 9.\n The total increments we did is 1 + 3 + 2 = 6.\n It can be shown that this is the minimum answer we can achieve.\n \n Example 2:\n \n \n >>> minIncrements(n = 3, cost = [5,3,3])\n >>> 0\n Explanation: The two paths already have equal total costs, so no increments are needed.\n \"\"\"\n"}
{"task_id": "number-of-senior-citizens", "prompt": "def countSeniors(details: List[str]) -> int:\n \"\"\"\n You are given a 0-indexed array of strings details. Each element of details provides information about a given passenger compressed into a string of length 15. The system is such that:\n \n The first ten characters consist of the phone number of passengers.\n The next character denotes the gender of the person.\n The following two characters are used to indicate the age of the person.\n The last two characters determine the seat allotted to that person.\n \n Return the number of passengers who are strictly more than 60 years old.\n \n Example 1:\n \n >>> countSeniors(details = [\"7868190130M7522\",\"5303914400F9211\",\"9273338290F4010\"])\n >>> 2\n Explanation: The passengers at indices 0, 1, and 2 have ages 75, 92, and 40. Thus, there are 2 people who are over 60 years old.\n \n Example 2:\n \n >>> countSeniors(details = [\"1313579440F2036\",\"2921522980M5644\"])\n >>> 0\n Explanation: None of the passengers are older than 60.\n \"\"\"\n"}
{"task_id": "sum-in-a-matrix", "prompt": "def matrixSum(nums: List[List[int]]) -> int:\n \"\"\"\n You are given a 0-indexed 2D integer array nums. Initially, your score is 0. Perform the following operations until the matrix becomes empty:\n \n From each row in the matrix, select the largest number and remove it. In the case of a tie, it does not matter which number is chosen.\n Identify the highest number amongst all those removed in step 1. Add that number to your score.\n \n Return the final score.\n \n Example 1:\n \n >>> matrixSum(nums = [[7,2,1],[6,4,2],[6,5,3],[3,2,1]])\n >>> 15\n Explanation: In the first operation, we remove 7, 6, 6, and 3. We then add 7 to our score. Next, we remove 2, 4, 5, and 2. We add 5 to our score. Lastly, we remove 1, 2, 3, and 1. We add 3 to our score. Thus, our final score is 7 + 5 + 3 = 15.\n \n Example 2:\n \n >>> matrixSum(nums = [[1]])\n >>> 1\n Explanation: We remove 1 and add it to the answer. We return 1.\n \"\"\"\n"}
{"task_id": "maximum-or", "prompt": "def maximumOr(nums: List[int], k: int) -> int:\n \"\"\"\n You are given a 0-indexed integer array nums of length n and an integer k. In an operation, you can choose an element and multiply it by 2.\n Return the maximum possible value of nums[0] | nums[1] | ... | nums[n - 1] that can be obtained after applying the operation on nums at most k times.\n Note that a | b denotes the bitwise or between two integers a and b.\n \n Example 1:\n \n >>> maximumOr(nums = [12,9], k = 1)\n >>> 30\n Explanation: If we apply the operation to index 1, our new array nums will be equal to [12,18]. Thus, we return the bitwise or of 12 and 18, which is 30.\n \n Example 2:\n \n >>> maximumOr(nums = [8,1,2], k = 2)\n >>> 35\n Explanation: If we apply the operation twice on index 0, we yield a new array of [32,1,2]. Thus, we return 32|1|2 = 35.\n \"\"\"\n"}
{"task_id": "power-of-heroes", "prompt": "def sumOfPower(nums: List[int]) -> int:\n \"\"\"\n You are given a 0-indexed integer array nums representing the strength of some heroes. The power of a group of heroes is defined as follows:\n \n Let i0, i1, ... ,ik be the indices of the heroes in a group. Then, the power of this group is max(nums[i0], nums[i1], ... ,nums[ik])2 * min(nums[i0], nums[i1], ... ,nums[ik]).\n \n Return the sum of the power of all non-empty groups of heroes possible. Since the sum could be very large, return it modulo 109 + 7.\n \n Example 1:\n \n >>> sumOfPower(nums = [2,1,4])\n >>> 141\n Explanation:\n 1st\u00a0group: [2] has power = 22\u00a0* 2 = 8.\n 2nd\u00a0group: [1] has power = 12 * 1 = 1.\n 3rd\u00a0group: [4] has power = 42 * 4 = 64.\n 4th\u00a0group: [2,1] has power = 22 * 1 = 4.\n 5th\u00a0group: [2,4] has power = 42 * 2 = 32.\n 6th\u00a0group: [1,4] has power = 42 * 1 = 16.\n \u200b\u200b\u200b\u200b\u200b\u200b\u200b7th\u00a0group: [2,1,4] has power = 42\u200b\u200b\u200b\u200b\u200b\u200b\u200b * 1 = 16.\n The sum of powers of all groups is 8 + 1 + 64 + 4 + 32 + 16 + 16 = 141.\n \n \n Example 2:\n \n >>> sumOfPower(nums = [1,1,1])\n >>> 7\n Explanation: A total of 7 groups are possible, and the power of each group will be 1. Therefore, the sum of the powers of all groups is 7.\n \"\"\"\n"}
{"task_id": "find-the-losers-of-the-circular-game", "prompt": "def circularGameLosers(n: int, k: int) -> List[int]:\n \"\"\"\n There are n friends that are playing a game. The friends are sitting in a circle and are numbered from 1 to n in clockwise order. More formally, moving clockwise from the ith friend brings you to the (i+1)th friend for 1 <= i < n, and moving clockwise from the nth friend brings you to the 1st friend.\n The rules of the game are as follows:\n 1st friend receives the ball.\n \n After that, 1st friend passes it to the friend who is k steps away from them in the clockwise direction.\n After that, the friend who receives the ball should pass it to the friend who is 2 * k steps away from them in the clockwise direction.\n After that, the friend who receives the ball should pass it to the friend who is 3 * k steps away from them in the clockwise direction, and so on and so forth.\n \n In other words, on the ith turn, the friend holding the ball should pass it to the friend who is i * k steps away from them in the clockwise direction.\n The game is finished when some friend receives the ball for the second time.\n The losers of the game are friends who did not receive the ball in the entire game.\n Given the number of friends, n, and an integer k, return the array answer, which contains the losers of the game in the ascending order.\n \n Example 1:\n \n >>> circularGameLosers(n = 5, k = 2)\n >>> [4,5]\n Explanation: The game goes as follows:\n 1) Start at 1st\u00a0friend and pass the ball to the friend who is 2 steps away from them - 3rd\u00a0friend.\n 2) 3rd\u00a0friend passes the ball to the friend who is 4 steps away from them - 2nd\u00a0friend.\n 3) 2nd\u00a0friend passes the ball to the friend who is 6 steps away from them - 3rd\u00a0friend.\n 4) The game ends as 3rd\u00a0friend receives the ball for the second time.\n \n Example 2:\n \n >>> circularGameLosers(n = 4, k = 4)\n >>> [2,3,4]\n Explanation: The game goes as follows:\n 1) Start at the 1st\u00a0friend and pass the ball to the friend who is 4 steps away from them - 1st\u00a0friend.\n 2) The game ends as 1st\u00a0friend receives the ball for the second time.\n \"\"\"\n"}
{"task_id": "neighboring-bitwise-xor", "prompt": "def doesValidArrayExist(derived: List[int]) -> bool:\n \"\"\"\n A 0-indexed array derived with length n is derived by computing the bitwise XOR\u00a0(\u2295) of adjacent values in a binary array original of length n.\n Specifically, for each index i in the range [0, n - 1]:\n \n If i = n - 1, then derived[i] = original[i] \u2295 original[0].\n Otherwise, derived[i] = original[i] \u2295 original[i + 1].\n \n Given an array derived, your task is to determine whether there exists a valid binary array original that could have formed derived.\n Return true if such an array exists or false otherwise.\n \n A binary array is an array containing only 0's and 1's\n \n \n Example 1:\n \n >>> doesValidArrayExist(derived = [1,1,0])\n >>> true\n Explanation: A valid original array that gives derived is [0,1,0].\n derived[0] = original[0] \u2295 original[1] = 0 \u2295 1 = 1\n derived[1] = original[1] \u2295 original[2] = 1 \u2295 0 = 1\n derived[2] = original[2] \u2295 original[0] = 0 \u2295 0 = 0\n \n Example 2:\n \n >>> doesValidArrayExist(derived = [1,1])\n >>> true\n Explanation: A valid original array that gives derived is [0,1].\n derived[0] = original[0] \u2295 original[1] = 1\n derived[1] = original[1] \u2295 original[0] = 1\n \n Example 3:\n \n >>> doesValidArrayExist(derived = [1,0])\n >>> false\n Explanation: There is no valid original array that gives derived.\n \"\"\"\n"}
{"task_id": "maximum-number-of-moves-in-a-grid", "prompt": "def maxMoves(grid: List[List[int]]) -> int:\n \"\"\"\n You are given a 0-indexed m x n matrix grid consisting of positive integers.\n You can start at any cell in the first column of the matrix, and traverse the grid in the following way:\n \n From a cell (row, col), you can move to any of the cells: (row - 1, col + 1), (row, col + 1) and (row + 1, col + 1) such that the value of the cell you move to, should be strictly bigger than the value of the current cell.\n \n Return the maximum number of moves that you can perform.\n \n Example 1:\n \n \n >>> maxMoves(grid = [[2,4,3,5],[5,4,9,3],[3,4,2,11],[10,9,13,15]])\n >>> 3\n Explanation: We can start at the cell (0, 0) and make the following moves:\n - (0, 0) -> (0, 1).\n - (0, 1) -> (1, 2).\n - (1, 2) -> (2, 3).\n It can be shown that it is the maximum number of moves that can be made.\n Example 2:\n \n \n >>> maxMoves(grid = [[3,2,4],[2,1,9],[1,1,7]])\n >>> 0\n Explanation: Starting from any cell in the first column we cannot perform any moves.\n \"\"\"\n"}
{"task_id": "count-the-number-of-complete-components", "prompt": "def countCompleteComponents(n: int, edges: List[List[int]]) -> int:\n \"\"\"\n You are given an integer n. There is an undirected graph with n vertices, numbered from 0 to n - 1. You are given a 2D integer array edges where edges[i] = [ai, bi] denotes that there exists an undirected edge connecting vertices ai and bi.\n Return the number of complete connected components of the graph.\n A connected component is a subgraph of a graph in which there exists a path between any two vertices, and no vertex of the subgraph shares an edge with a vertex outside of the subgraph.\n A connected component is said to be complete if there exists an edge between every pair of its vertices.\n \n Example 1:\n \n \n >>> countCompleteComponents(n = 6, edges = [[0,1],[0,2],[1,2],[3,4]])\n >>> 3\n Explanation: From the picture above, one can see that all of the components of this graph are complete.\n \n Example 2:\n \n \n >>> countCompleteComponents(n = 6, edges = [[0,1],[0,2],[1,2],[3,4],[3,5]])\n >>> 1\n Explanation: The component containing vertices 0, 1, and 2 is complete since there is an edge between every pair of two vertices. On the other hand, the component containing vertices 3, 4, and 5 is not complete since there is no edge between vertices 4 and 5. Thus, the number of complete components in this graph is 1.\n \"\"\"\n"}
{"task_id": "minimum-string-length-after-removing-substrings", "prompt": "def minLength(s: str) -> int:\n \"\"\"\n You are given a string s consisting only of uppercase English letters.\n You can apply some operations to this string where, in one operation, you can remove any occurrence of one of the substrings \"AB\" or \"CD\" from s.\n Return the minimum possible length of the resulting string that you can obtain.\n Note that the string concatenates after removing the substring and could produce new \"AB\" or \"CD\" substrings.\n \n Example 1:\n \n >>> minLength(s = \"ABFCACDB\")\n >>> 2\n Explanation: We can do the following operations:\n - Remove the substring \"ABFCACDB\", so s = \"FCACDB\".\n - Remove the substring \"FCACDB\", so s = \"FCAB\".\n - Remove the substring \"FCAB\", so s = \"FC\".\n So the resulting length of the string is 2.\n It can be shown that it is the minimum length that we can obtain.\n Example 2:\n \n >>> minLength(s = \"ACBBD\")\n >>> 5\n Explanation: We cannot do any operations on the string so the length remains the same.\n \"\"\"\n"}
{"task_id": "lexicographically-smallest-palindrome", "prompt": "def makeSmallestPalindrome(s: str) -> str:\n \"\"\"\n You are given a string s consisting of lowercase English letters, and you are allowed to perform operations on it. In one operation, you can replace a character in s with another lowercase English letter.\n Your task is to make s a palindrome with the minimum number of operations possible. If there are multiple palindromes that can be made using the minimum number of operations, make the lexicographically smallest one.\n A string a is lexicographically smaller than a string b (of the same length) if in the first position where a and b differ, string a has a letter that appears earlier in the alphabet than the corresponding letter in b.\n Return the resulting palindrome string.\n \n Example 1:\n \n >>> makeSmallestPalindrome(s = \"egcfe\")\n >>> \"efcfe\"\n Explanation: The minimum number of operations to make \"egcfe\" a palindrome is 1, and the lexicographically smallest palindrome string we can get by modifying one character is \"efcfe\", by changing 'g'.\n \n Example 2:\n \n >>> makeSmallestPalindrome(s = \"abcd\")\n >>> \"abba\"\n Explanation: The minimum number of operations to make \"abcd\" a palindrome is 2, and the lexicographically smallest palindrome string we can get by modifying two characters is \"abba\".\n \n Example 3:\n \n >>> makeSmallestPalindrome(s = \"seven\")\n >>> \"neven\"\n Explanation: The minimum number of operations to make \"seven\" a palindrome is 1, and the lexicographically smallest palindrome string we can get by modifying one character is \"neven\".\n \"\"\"\n"}
{"task_id": "find-the-punishment-number-of-an-integer", "prompt": "def punishmentNumber(n: int) -> int:\n \"\"\"\n Given a positive integer n, return the punishment number of n.\n The punishment number of n is defined as the sum of the squares of all integers i such that:\n \n 1 <= i <= n\n The decimal representation of i * i can be partitioned into contiguous substrings such that the sum of the integer values of these substrings equals i.\n \n \n Example 1:\n \n >>> punishmentNumber(n = 10)\n >>> 182\n Explanation: There are exactly 3 integers i in the range [1, 10] that satisfy the conditions in the statement:\n - 1 since 1 * 1 = 1\n - 9 since 9 * 9 = 81 and 81 can be partitioned into 8 and 1 with a sum equal to 8 + 1 == 9.\n - 10 since 10 * 10 = 100 and 100 can be partitioned into 10 and 0 with a sum equal to 10 + 0 == 10.\n Hence, the punishment number of 10 is 1 + 81 + 100 = 182\n \n Example 2:\n \n >>> punishmentNumber(n = 37)\n >>> 1478\n Explanation: There are exactly 4 integers i in the range [1, 37] that satisfy the conditions in the statement:\n - 1 since 1 * 1 = 1.\n - 9 since 9 * 9 = 81 and 81 can be partitioned into 8 + 1.\n - 10 since 10 * 10 = 100 and 100 can be partitioned into 10 + 0.\n - 36 since 36 * 36 = 1296 and 1296 can be partitioned into 1 + 29 + 6.\n Hence, the punishment number of 37 is 1 + 81 + 100 + 1296 = 1478\n \"\"\"\n"}
{"task_id": "modify-graph-edge-weights", "prompt": "def modifiedGraphEdges(n: int, edges: List[List[int]], source: int, destination: int, target: int) -> List[List[int]]:\n \"\"\"\n You are given an undirected weighted connected graph containing n nodes labeled from 0 to n - 1, and an integer array edges where edges[i] = [ai, bi, wi] indicates that there is an edge between nodes ai and bi with weight wi.\n Some edges have a weight of -1 (wi = -1), while others have a positive weight (wi > 0).\n Your task is to modify all edges with a weight of -1 by assigning them positive integer values in the range [1, 2 * 109] so that the shortest distance between the nodes source and destination becomes equal to an integer target. If there are multiple modifications that make the shortest distance between source and destination equal to target, any of them will be considered correct.\n Return an array containing all edges (even unmodified ones) in any order if it is possible to make the shortest distance from source to destination equal to target, or an empty array if it's impossible.\n Note: You are not allowed to modify the weights of edges with initial positive weights.\n \n Example 1:\n \n \n >>> modifiedGraphEdges(n = 5, edges = [[4,1,-1],[2,0,-1],[0,3,-1],[4,3,-1]], source = 0, destination = 1, target = 5)\n >>> [[4,1,1],[2,0,1],[0,3,3],[4,3,1]]\n Explanation: The graph above shows a possible modification to the edges, making the distance from 0 to 1 equal to 5.\n \n Example 2:\n \n \n >>> modifiedGraphEdges(n = 3, edges = [[0,1,-1],[0,2,5]], source = 0, destination = 2, target = 6)\n >>> []\n Explanation: The graph above contains the initial edges. It is not possible to make the distance from 0 to 2 equal to 6 by modifying the edge with weight -1. So, an empty array is returned.\n \n Example 3:\n \n \n >>> modifiedGraphEdges(n = 4, edges = [[1,0,4],[1,2,3],[2,3,5],[0,3,-1]], source = 0, destination = 2, target = 6)\n >>> [[1,0,4],[1,2,3],[2,3,5],[0,3,1]]\n Explanation: The graph above shows a modified graph having the shortest distance from 0 to 2 as 6.\n \"\"\"\n"}
{"task_id": "minimum-operations-to-make-numbers-non-positive", "prompt": "def minOperations(nums: List[int], x: int, y: int) -> int:\n \"\"\"\n You are given a 0-indexed integer array nums and two integers x and y. In one operation, you must choose an index i such that 0 <= i < nums.length and perform the following:\n \n Decrement nums[i] by x.\n Decrement values by y at all indices except the ith one.\n \n Return the minimum number of operations to make all the integers in nums less than or equal to zero.\n \n Example 1:\n \n >>> minOperations(nums = [3,4,1,7,6], x = 4, y = 2)\n >>> 3\n Explanation: You will need three operations. One of the optimal sequence of operations is:\n Operation 1: Choose i = 3. Then, nums = [1,2,-1,3,4].\n Operation 2: Choose i = 3. Then, nums = [-1,0,-3,-1,2].\n Operation 3: Choose i = 4. Then, nums = [-3,-2,-5,-3,-2].\n Now, all the numbers in nums are non-positive. Therefore, we return 3.\n \n Example 2:\n \n >>> minOperations(nums = [1,2,1], x = 2, y = 1)\n >>> 1\n Explanation: We can perform the operation once on i = 1. Then, nums becomes [0,0,0]. All the positive numbers are removed, and therefore, we return 1.\n \"\"\"\n"}
{"task_id": "buy-two-chocolates", "prompt": "def buyChoco(prices: List[int], money: int) -> int:\n \"\"\"\n You are given an integer array prices representing the prices of various chocolates in a store. You are also given a single integer money, which represents your initial amount of money.\n You must buy exactly two chocolates in such a way that you still have some non-negative leftover money. You would like to minimize the sum of the prices of the two chocolates you buy.\n Return the amount of money you will have leftover after buying the two chocolates. If there is no way for you to buy two chocolates without ending up in debt, return money. Note that the leftover must be non-negative.\n \n Example 1:\n \n >>> buyChoco(prices = [1,2,2], money = 3)\n >>> 0\n Explanation: Purchase the chocolates priced at 1 and 2 units respectively. You will have 3 - 3 = 0 units of money afterwards. Thus, we return 0.\n \n Example 2:\n \n >>> buyChoco(prices = [3,2,3], money = 3)\n >>> 3\n Explanation: You cannot buy 2 chocolates without going in debt, so we return 3.\n \"\"\"\n"}
{"task_id": "extra-characters-in-a-string", "prompt": "def minExtraChar(s: str, dictionary: List[str]) -> int:\n \"\"\"\n You are given a 0-indexed string s and a dictionary of words dictionary. You have to break s into one or more non-overlapping substrings such that each substring is present in dictionary. There may be some extra characters in s which are not present in any of the substrings.\n Return the minimum number of extra characters left over if you break up s optimally.\n \n Example 1:\n \n >>> minExtraChar(s = \"leetscode\", dictionary = [\"leet\",\"code\",\"leetcode\"])\n >>> 1\n Explanation: We can break s in two substrings: \"leet\" from index 0 to 3 and \"code\" from index 5 to 8. There is only 1 unused character (at index 4), so we return 1.\n \n \n Example 2:\n \n >>> minExtraChar(s = \"sayhelloworld\", dictionary = [\"hello\",\"world\"])\n >>> 3\n Explanation: We can break s in two substrings: \"hello\" from index 3 to 7 and \"world\" from index 8 to 12. The characters at indices 0, 1, 2 are not used in any substring and thus are considered as extra characters. Hence, we return 3.\n \"\"\"\n"}
{"task_id": "maximum-strength-of-a-group", "prompt": "def maxStrength(nums: List[int]) -> int:\n \"\"\"\n You are given a 0-indexed integer array nums representing the score of students in an exam. The teacher would like to form one non-empty group of students with maximal strength, where the strength of a group of students of indices i0, i1, i2, ... , ik is defined as nums[i0] * nums[i1] * nums[i2] * ... * nums[ik\u200b].\n Return the maximum strength of a group the teacher can create.\n \n Example 1:\n \n >>> maxStrength(nums = [3,-1,-5,2,5,-9])\n >>> 1350\n Explanation: One way to form a group of maximal strength is to group the students at indices [0,2,3,4,5]. Their strength is 3 * (-5) * 2 * 5 * (-9) = 1350, which we can show is optimal.\n \n Example 2:\n \n >>> maxStrength(nums = [-4,-5,-4])\n >>> 20\n Explanation: Group the students at indices [0, 1] . Then, we\u2019ll have a resulting strength of 20. We cannot achieve greater strength.\n \"\"\"\n"}
{"task_id": "greatest-common-divisor-traversal", "prompt": "def canTraverseAllPairs(nums: List[int]) -> bool:\n \"\"\"\n You are given a 0-indexed integer array nums, and you are allowed to traverse between its indices. You can traverse between index i and index j, i != j, if and only if gcd(nums[i], nums[j]) > 1, where gcd is the greatest common divisor.\n Your task is to determine if for every pair of indices i and j in nums, where i < j, there exists a sequence of traversals that can take us from i to j.\n Return true if it is possible to traverse between all such pairs of indices, or false otherwise.\n \n Example 1:\n \n >>> canTraverseAllPairs(nums = [2,3,6])\n >>> true\n Explanation: In this example, there are 3 possible pairs of indices: (0, 1), (0, 2), and (1, 2).\n To go from index 0 to index 1, we can use the sequence of traversals 0 -> 2 -> 1, where we move from index 0 to index 2 because gcd(nums[0], nums[2]) = gcd(2, 6) = 2 > 1, and then move from index 2 to index 1 because gcd(nums[2], nums[1]) = gcd(6, 3) = 3 > 1.\n To go from index 0 to index 2, we can just go directly because gcd(nums[0], nums[2]) = gcd(2, 6) = 2 > 1. Likewise, to go from index 1 to index 2, we can just go directly because gcd(nums[1], nums[2]) = gcd(3, 6) = 3 > 1.\n \n Example 2:\n \n >>> canTraverseAllPairs(nums = [3,9,5])\n >>> false\n Explanation: No sequence of traversals can take us from index 0 to index 2 in this example. So, we return false.\n \n Example 3:\n \n >>> canTraverseAllPairs(nums = [4,3,12,8])\n >>> true\n Explanation: There are 6 possible pairs of indices to traverse between: (0, 1), (0, 2), (0, 3), (1, 2), (1, 3), and (2, 3). A valid sequence of traversals exists for each pair, so we return true.\n \"\"\"\n"}
{"task_id": "remove-trailing-zeros-from-a-string", "prompt": "def removeTrailingZeros(num: str) -> str:\n \"\"\"\n Given a positive integer num represented as a string, return the integer num without trailing zeros as a string.\n \n Example 1:\n \n >>> removeTrailingZeros(num = \"51230100\")\n >>> \"512301\"\n Explanation: Integer \"51230100\" has 2 trailing zeros, we remove them and return integer \"512301\".\n \n Example 2:\n \n >>> removeTrailingZeros(num = \"123\")\n >>> \"123\"\n Explanation: Integer \"123\" has no trailing zeros, we return integer \"123\".\n \"\"\"\n"}
{"task_id": "difference-of-number-of-distinct-values-on-diagonals", "prompt": "def differenceOfDistinctValues(grid: List[List[int]]) -> List[List[int]]:\n \"\"\"\n Given a 2D grid of size m x n, you should find the matrix answer of size m x n.\n The cell answer[r][c] is calculated by looking at the diagonal values of the cell grid[r][c]:\n \n Let leftAbove[r][c] be the number of distinct values on the diagonal to the left and above the cell grid[r][c] not including the cell grid[r][c] itself.\n Let rightBelow[r][c] be the number of distinct values on the diagonal to the right and below the cell grid[r][c], not including the cell grid[r][c] itself.\n Then answer[r][c] = |leftAbove[r][c] - rightBelow[r][c]|.\n \n A matrix diagonal is a diagonal line of cells starting from some cell in either the topmost row or leftmost column and going in the bottom-right direction until the end of the matrix is reached.\n \n For example, in the below diagram the diagonal is highlighted using the cell with indices (2, 3) colored gray:\n \n \n Red-colored cells are left and above the cell.\n Blue-colored cells are right and below the cell.\n \n \n \n \n Return the matrix answer.\n \n Example 1:\n \n >>> differenceOfDistinctValues(grid = [[1,2,3],[3,1,5],[3,2,1]])\n >>> Output: [[1,1,0],[1,0,1],[0,1,1]]\n Explanation:\n To calculate the answer cells:\n \n \n \n answer\n left-above elements\n leftAbove\n right-below elements\n rightBelow\n |leftAbove - rightBelow|\n \n \n \n \n [0][0]\n []\n 0\n [grid[1][1], grid[2][2]]\n |{1, 1}| = 1\n 1\n \n \n [0][1]\n []\n 0\n [grid[1][2]]\n |{5}| = 1\n 1\n \n \n [0][2]\n []\n 0\n []\n 0\n 0\n \n \n [1][0]\n []\n 0\n [grid[2][1]]\n |{2}| = 1\n 1\n \n \n [1][1]\n [grid[0][0]]\n |{1}| = 1\n [grid[2][2]]\n |{1}| = 1\n 0\n \n \n [1][2]\n [grid[0][1]]\n |{2}| = 1\n []\n 0\n 1\n \n \n [2][0]\n []\n 0\n []\n 0\n 0\n \n \n [2][1]\n [grid[1][0]]\n |{3}| = 1\n []\n 0\n 1\n \n \n [2][2]\n [grid[0][0], grid[1][1]]\n |{1, 1}| = 1\n []\n 0\n 1\n \n \n \n \n Example 2:\n \n >>> differenceOfDistinctValues(grid = [[1]])\n >>> Output: [[0]]\n \"\"\"\n"}
{"task_id": "minimum-cost-to-make-all-characters-equal", "prompt": "def minimumCost(s: str) -> int:\n \"\"\"\n You are given a 0-indexed binary string s of length n on which you can apply two types of operations:\n \n Choose an index i and invert all characters from\u00a0index 0 to index i\u00a0(both inclusive), with a cost of i + 1\n Choose an index i and invert all characters\u00a0from\u00a0index i to index n - 1\u00a0(both inclusive), with a cost of n - i\n \n Return the minimum cost to make all characters of the string equal.\n Invert a character means\u00a0if its value is '0' it becomes '1' and vice-versa.\n \n Example 1:\n \n >>> minimumCost(s = \"0011\")\n >>> 2\n Explanation: Apply the second operation with i = 2 to obtain s = \"0000\" for a cost of 2. It can be shown that 2 is the minimum cost to make all characters equal.\n \n Example 2:\n \n >>> minimumCost(s = \"010101\")\n >>> 9\n Explanation: Apply the first operation with i = 2 to obtain s = \"101101\" for a cost of 3.\n Apply the first operation with i = 1 to obtain s = \"011101\" for a cost of 2.\n Apply the first operation with i = 0 to obtain s = \"111101\" for a cost of 1.\n Apply the second operation with i = 4 to obtain s = \"111110\" for a cost of 2.\n Apply the second operation with i = 5 to obtain s = \"111111\" for a cost of 1.\n The total cost to make all characters equal is 9. It can be shown that 9 is the minimum cost to make all characters equal.\n \"\"\"\n"}
{"task_id": "maximum-strictly-increasing-cells-in-a-matrix", "prompt": "def maxIncreasingCells(mat: List[List[int]]) -> int:\n \"\"\"\n Given a 1-indexed\u00a0m x n integer matrix mat, you can select any cell in the matrix as your starting cell.\n From the starting cell, you can move to any other cell in the same row or column, but only if the value of the destination cell is strictly greater than the value of the current cell. You can repeat this process as many times as possible, moving from cell to cell until you can no longer make any moves.\n Your task is to find the maximum number of cells that you can visit in the matrix by starting from some cell.\n Return an integer denoting the maximum number of cells that can be visited.\n \n Example 1:\n \n \n >>> maxIncreasingCells(mat = [[3,1],[3,4]])\n >>> 2\n Explanation: The image shows how we can visit 2 cells starting from row 1, column 2. It can be shown that we cannot visit more than 2 cells no matter where we start from, so the answer is 2.\n \n Example 2:\n \n \n >>> maxIncreasingCells(mat = [[1,1],[1,1]])\n >>> 1\n Explanation: Since the cells must be strictly increasing, we can only visit one cell in this example.\n \n Example 3:\n \n \n >>> maxIncreasingCells(mat = [[3,1,6],[-9,5,7]])\n >>> 4\n Explanation: The image above shows how we can visit 4 cells starting from row 2, column 1. It can be shown that we cannot visit more than 4 cells no matter where we start from, so the answer is 4.\n \"\"\"\n"}
{"task_id": "find-shortest-path-with-k-hops", "prompt": "def shortestPathWithHops(n: int, edges: List[List[int]], s: int, d: int, k: int) -> int:\n \"\"\"\n You are given a positive integer n which is the number of nodes of a 0-indexed undirected weighted connected graph and a 0-indexed 2D array edges where edges[i] = [ui, vi, wi] indicates that there is an edge between nodes ui and vi with weight wi.\n You are also given two\u00a0nodes s and d, and a positive integer k, your task is to find the shortest path from s to d, but you can hop over at most k edges. In other words,\u00a0make the weight of at most k edges 0 and then find the shortest path from s to d.\n Return the length of the shortest path from s to d with the given condition.\n \n Example 1:\n \n >>> shortestPathWithHops(n = 4, edges = [[0,1,4],[0,2,2],[2,3,6]], s = 1, d = 3, k = 2)\n >>> 2\n Explanation: In this example there is only one path from node 1 (the green node) to node 3 (the red node), which is (1->0->2->3) and the length of it is 4 + 2 + 6 = 12. Now we can make weight of two edges 0, we make weight of the blue edges 0, then we have 0 + 2 + 0 = 2. It can be shown that 2 is the minimum length of a path we can achieve with the given condition.\n \n \n Example 2:\n \n >>> shortestPathWithHops(n = 7, edges = [[3,1,9],[3,2,4],[4,0,9],[0,5,6],[3,6,2],[6,0,4],[1,2,4]], s = 4, d = 1, k = 2)\n >>> 6\n Explanation: In this example there are 2 paths from node 4 (the green node) to node 1 (the red node), which are (4->0->6->3->2->1) and (4->0->6->3->1). The first one has the length 9 + 4 + 2 + 4 + 4 = 23, and the second one has the length 9 + 4 + 2 + 9 = 24. Now if we make weight of the blue edges 0, we get the shortest path with the length 0 + 4 + 2 + 0 = 6. It can be shown that 6 is the minimum length of a path we can achieve with the given condition.\n \n \n Example 3:\n \n >>> shortestPathWithHops(n = 5, edges = [[0,4,2],[0,1,3],[0,2,1],[2,1,4],[1,3,4],[3,4,7]], s = 2, d = 3, k = 1)\n >>> 3\n Explanation: In this example there are 4 paths from node 2 (the green node) to node 3 (the red node), which are (2->1->3), (2->0->1->3), (2->1->0->4->3) and (2->0->4->3). The first two have the length 4 + 4 = 1 + 3 + 4 = 8, the third one has the length 4 + 3 + 2 + 7 = 16 and the last one has the length 1 + 2 + 7 = 10. Now if we make weight of the blue edge 0, we get the shortest path with the length 1 + 2 + 0 = 3. It can be shown that 3 is the minimum length of a path we can achieve with the given condition.\n \"\"\"\n"}
{"task_id": "minimize-string-length", "prompt": "def minimizedStringLength(s: str) -> int:\n \"\"\"\n Given a string s, you have two types of operation:\n \n Choose an index i in the string, and let c be the character in position i. Delete the closest occurrence of c to the left of i (if exists).\n Choose an index i in the string, and let c be the character in position i. Delete the closest occurrence of c to the right of i (if exists).\n \n Your task is to minimize the length of s by performing the above operations zero or more times.\n Return an integer denoting the length of the minimized string.\n \n Example 1:\n \n >>> minimizedStringLength(s = \"aaabc\")\n >>> 3\n Explanation:\n \n Operation 2: we choose i = 1 so c is 'a', then we remove s[2] as it is closest 'a' character to the right of s[1].\n s becomes \"aabc\" after this.\n Operation 1: we choose i = 1 so c is 'a', then we remove s[0] as it is closest 'a' character to the left of s[1].\n s becomes \"abc\" after this.\n \n \n Example 2:\n \n >>> minimizedStringLength(s = \"cbbd\")\n >>> 3\n Explanation:\n \n Operation 1: we choose i = 2 so c is 'b', then we remove s[1] as it is closest 'b' character to the left of s[1].\n s becomes \"cbd\" after this.\n \n \n Example 3:\n \n >>> minimizedStringLength(s = \"baadccab\")\n >>> 4\n Explanation:\n \n Operation 1: we choose i = 6 so c is 'a', then we remove s[2] as it is closest 'a' character to the left of s[6].\n s becomes \"badccab\" after this.\n Operation 2: we choose i = 0 so c is 'b', then we remove s[6] as it is closest 'b' character to the right of s[0].\n s becomes \"badcca\" fter this.\n Operation 2: we choose i = 3 so c is 'c', then we remove s[4] as it is closest 'c' character to the right of s[3].\n s becomes \"badca\" after this.\n Operation 1: we choose i = 4 so c is 'a', then we remove s[1] as it is closest 'a' character to the left of s[4].\n s becomes \"bdca\" after this.\n \"\"\"\n"}
{"task_id": "semi-ordered-permutation", "prompt": "def semiOrderedPermutation(nums: List[int]) -> int:\n \"\"\"\n You are given a 0-indexed permutation of n integers nums.\n A permutation is called semi-ordered if the first number equals 1 and the last number equals n. You can perform the below operation as many times as you want until you make nums a semi-ordered permutation:\n \n Pick two adjacent elements in nums, then swap them.\n \n Return the minimum number of operations to make nums a semi-ordered permutation.\n A permutation is a sequence of integers from 1 to n of length n containing each number exactly once.\n \n Example 1:\n \n >>> semiOrderedPermutation(nums = [2,1,4,3])\n >>> 2\n Explanation: We can make the permutation semi-ordered using these sequence of operations:\n 1 - swap i = 0 and j = 1. The permutation becomes [1,2,4,3].\n 2 - swap i = 2 and j = 3. The permutation becomes [1,2,3,4].\n It can be proved that there is no sequence of less than two operations that make nums a semi-ordered permutation.\n \n Example 2:\n \n >>> semiOrderedPermutation(nums = [2,4,1,3])\n >>> 3\n Explanation: We can make the permutation semi-ordered using these sequence of operations:\n 1 - swap i = 1 and j = 2. The permutation becomes [2,1,4,3].\n 2 - swap i = 0 and j = 1. The permutation becomes [1,2,4,3].\n 3 - swap i = 2 and j = 3. The permutation becomes [1,2,3,4].\n It can be proved that there is no sequence of less than three operations that make nums a semi-ordered permutation.\n \n Example 3:\n \n >>> semiOrderedPermutation(nums = [1,3,4,2,5])\n >>> 0\n Explanation: The permutation is already a semi-ordered permutation.\n \"\"\"\n"}
{"task_id": "sum-of-matrix-after-queries", "prompt": "def matrixSumQueries(n: int, queries: List[List[int]]) -> int:\n \"\"\"\n You are given an integer n and a 0-indexed\u00a02D array queries where queries[i] = [typei, indexi, vali].\n Initially, there is a 0-indexed n x n matrix filled with 0's. For each query, you must apply one of the following changes:\n \n if typei == 0, set the values in the row with indexi to vali, overwriting any previous values.\n if typei == 1, set the values in the column with indexi to vali, overwriting any previous values.\n \n Return the sum of integers in the matrix after all queries are applied.\n \n Example 1:\n \n \n >>> matrixSumQueries(n = 3, queries = [[0,0,1],[1,2,2],[0,2,3],[1,0,4]])\n >>> 23\n Explanation: The image above describes the matrix after each query. The sum of the matrix after all queries are applied is 23.\n \n Example 2:\n \n \n >>> matrixSumQueries(n = 3, queries = [[0,0,4],[0,1,2],[1,0,1],[0,2,3],[1,2,1]])\n >>> 17\n Explanation: The image above describes the matrix after each query. The sum of the matrix after all queries are applied is 17.\n \"\"\"\n"}
{"task_id": "count-of-integers", "prompt": "def count(num1: str, num2: str, min_sum: int, max_sum: int) -> int:\n \"\"\"\n You are given two numeric strings num1 and num2 and two integers max_sum and min_sum. We denote an integer x to be good if:\n \n num1 <= x <= num2\n min_sum <= digit_sum(x) <= max_sum.\n \n Return the number of good integers. Since the answer may be large, return it modulo 109 + 7.\n Note that digit_sum(x) denotes the sum of the digits of x.\n \n Example 1:\n \n >>> count(num1 = \"1\", num2 = \"12\", min_sum = 1, max_sum = 8)\n >>> 11\n Explanation: There are 11 integers whose sum of digits lies between 1 and 8 are 1,2,3,4,5,6,7,8,10,11, and 12. Thus, we return 11.\n \n Example 2:\n \n >>> count(num1 = \"1\", num2 = \"5\", min_sum = 1, max_sum = 5)\n >>> 5\n Explanation: The 5 integers whose sum of digits lies between 1 and 5 are 1,2,3,4, and 5. Thus, we return 5.\n \"\"\"\n"}
{"task_id": "check-if-the-number-is-fascinating", "prompt": "def isFascinating(n: int) -> bool:\n \"\"\"\n You are given an integer n that consists of exactly 3 digits.\n We call the number n fascinating if, after the following modification, the resulting number contains all the digits from 1 to 9 exactly once and does not contain any 0's:\n \n Concatenate n with the numbers 2 * n and 3 * n.\n \n Return true if n is fascinating, or false otherwise.\n Concatenating two numbers means joining them together. For example, the concatenation of 121 and 371 is 121371.\n \n Example 1:\n \n >>> isFascinating(n = 192)\n >>> true\n Explanation: We concatenate the numbers n = 192 and 2 * n = 384 and 3 * n = 576. The resulting number is 192384576. This number contains all the digits from 1 to 9 exactly once.\n \n Example 2:\n \n >>> isFascinating(n = 100)\n >>> false\n Explanation: We concatenate the numbers n = 100 and 2 * n = 200 and 3 * n = 300. The resulting number is 100200300. This number does not satisfy any of the conditions.\n \"\"\"\n"}
{"task_id": "find-the-longest-semi-repetitive-substring", "prompt": "def longestSemiRepetitiveSubstring(s: str) -> int:\n \"\"\"\n You are given a digit string s that consists of digits from 0 to 9.\n A string is called semi-repetitive if there is at most one adjacent pair of the same digit. For example, \"0010\", \"002020\", \"0123\", \"2002\", and \"54944\" are semi-repetitive while the following are not: \"00101022\" (adjacent same digit pairs are 00 and 22), and \"1101234883\" (adjacent same digit pairs are 11 and 88).\n Return the length of the longest semi-repetitive substring of s.\n \n Example 1:\n \n >>> longestSemiRepetitiveSubstring(s = \"52233\")\n >>> 4\n Explanation:\n The longest semi-repetitive substring is \"5223\". Picking the whole string \"52233\" has two adjacent same digit pairs 22 and 33, but at most one is allowed.\n \n Example 2:\n \n >>> longestSemiRepetitiveSubstring(s = \"5494\")\n >>> 4\n Explanation:\n s is a semi-repetitive string.\n \n Example 3:\n \n >>> longestSemiRepetitiveSubstring(s = \"1111111\")\n >>> 2\n Explanation:\n The longest semi-repetitive substring is \"11\". Picking the substring \"111\" has two adjacent same digit pairs, but at most one is allowed.\n \"\"\"\n"}
{"task_id": "movement-of-robots", "prompt": "def sumDistance(nums: List[int], s: str, d: int) -> int:\n \"\"\"\n Some robots are standing on an infinite number line with their initial coordinates given by a 0-indexed integer array nums and will start moving once given the command to move. The robots will move a unit distance each second.\n You are given a string s denoting the direction in which robots will move on command. 'L' means the robot will move towards the left side or negative side of the number line, whereas 'R' means the robot will move towards the right side or positive side of the number line.\n If two robots collide, they will start moving in opposite directions.\n Return the sum of distances between all the\u00a0pairs of robots d seconds after\u00a0the command. Since the sum can be very large, return it modulo 109 + 7.\n Note:\n \n For two robots at the index i and j, pair (i,j) and pair (j,i) are considered the same pair.\n When robots collide, they instantly change their directions without wasting any time.\n Collision happens\u00a0when two robots share the same place in a\u00a0moment.\n \n For example, if a robot is positioned in 0 going to the right and another is positioned in 2 going to the left, the next second they'll be both in 1 and they will change direction and the next second the first one will be in 0, heading left, and another will be in 2, heading right.\n For example,\u00a0if a robot is positioned in 0 going to the right and another is positioned in 1\u00a0going to the left, the next second the first one will be in 0, heading left, and another will be in 1, heading right.\n \n \n \n \n Example 1:\n \n >>> sumDistance(nums = [-2,0,2], s = \"RLL\", d = 3)\n >>> 8\n Explanation:\n After 1 second, the positions are [-1,-1,1]. Now, the robot at index 0 will move left, and the robot at index 1 will move right.\n After 2 seconds, the positions are [-2,0,0]. Now, the robot at index 1 will move left, and the robot at index 2 will move right.\n After 3 seconds, the positions are [-3,-1,1].\n The distance between the robot at index 0 and 1 is abs(-3 - (-1)) = 2.\n The distance between the robot at index 0 and 2 is abs(-3 - 1) = 4.\n The distance between the robot at index 1 and 2 is abs(-1 - 1) = 2.\n The sum of the pairs of all distances = 2 + 4 + 2 = 8.\n \n Example 2:\n \n >>> sumDistance(nums = [1,0], s = \"RL\", d = 2)\n >>> 5\n Explanation:\n After 1 second, the positions are [2,-1].\n After 2 seconds, the positions are [3,-2].\n The distance between the two robots is abs(-2 - 3) = 5.\n \"\"\"\n"}
{"task_id": "find-a-good-subset-of-the-matrix", "prompt": "def goodSubsetofBinaryMatrix(grid: List[List[int]]) -> List[int]:\n \"\"\"\n You are given a 0-indexed m x n binary matrix grid.\n Let us call a non-empty subset of rows good if the sum of each column of the subset is at most half of the length of the subset.\n More formally, if the length of the chosen subset of rows is k, then the sum of each column should be at most floor(k / 2).\n Return an integer array that contains row indices of a good subset sorted in ascending order.\n If there are multiple good subsets, you can return any of them. If there are no good subsets, return an empty array.\n A subset of rows of the matrix grid is any matrix that can be obtained by deleting some (possibly none or all) rows from grid.\n \n Example 1:\n \n >>> goodSubsetofBinaryMatrix(grid = [[0,1,1,0],[0,0,0,1],[1,1,1,1]])\n >>> [0,1]\n Explanation: We can choose the 0th and 1st rows to create a good subset of rows.\n The length of the chosen subset is 2.\n - The sum of the 0th\u00a0column is 0 + 0 = 0, which is at most half of the length of the subset.\n - The sum of the 1st\u00a0column is 1 + 0 = 1, which is at most half of the length of the subset.\n - The sum of the 2nd\u00a0column is 1 + 0 = 1, which is at most half of the length of the subset.\n - The sum of the 3rd\u00a0column is 0 + 1 = 1, which is at most half of the length of the subset.\n \n Example 2:\n \n >>> goodSubsetofBinaryMatrix(grid = [[0]])\n >>> [0]\n Explanation: We can choose the 0th row to create a good subset of rows.\n The length of the chosen subset is 1.\n - The sum of the 0th\u00a0column is 0, which is at most half of the length of the subset.\n \n Example 3:\n \n >>> goodSubsetofBinaryMatrix(grid = [[1,1,1],[1,1,1]])\n >>> []\n Explanation: It is impossible to choose any subset of rows to create a good subset.\n \"\"\"\n"}
{"task_id": "neither-minimum-nor-maximum", "prompt": "def findNonMinOrMax(nums: List[int]) -> int:\n \"\"\"\n Given an integer array nums containing distinct positive integers, find and return any number from the array that is neither the minimum nor the maximum value in the array, or -1 if there is no such number.\n Return the selected integer.\n \n Example 1:\n \n >>> findNonMinOrMax(nums = [3,2,1,4])\n >>> 2\n Explanation: In this example, the minimum value is 1 and the maximum value is 4. Therefore, either 2 or 3 can be valid answers.\n \n Example 2:\n \n >>> findNonMinOrMax(nums = [1,2])\n >>> -1\n Explanation: Since there is no number in nums that is neither the maximum nor the minimum, we cannot select a number that satisfies the given condition. Therefore, there is no answer.\n \n Example 3:\n \n >>> findNonMinOrMax(nums = [2,1,3])\n >>> 2\n Explanation: Since 2 is neither the maximum nor the minimum value in nums, it is the only valid answer.\n \"\"\"\n"}
{"task_id": "lexicographically-smallest-string-after-substring-operation", "prompt": "def smallestString(s: str) -> str:\n \"\"\"\n Given a string s consisting of lowercase English letters. Perform the following operation:\n \n Select any non-empty substring then replace every letter of the substring with the preceding letter of the English alphabet. For example, 'b' is converted to 'a', and 'a' is converted to 'z'.\n \n Return the lexicographically smallest string after performing the operation.\n \n Example 1:\n \n >>> smallestString(s = \"cbabc\")\n >>> \"baabc\"\n Explanation:\n Perform the operation on the substring starting at index 0, and ending at index 1 inclusive.\n \n Example 2:\n \n >>> smallestString(s = \"aa\")\n >>> \"az\"\n Explanation:\n Perform the operation on the last letter.\n \n Example 3:\n \n >>> smallestString(s = \"acbbc\")\n >>> \"abaab\"\n Explanation:\n Perform the operation on the substring starting at index 1, and ending at index 4 inclusive.\n \n Example 4:\n \n >>> smallestString(s = \"leetcode\")\n >>> \"kddsbncd\"\n Explanation:\n Perform the operation on the entire string.\n \"\"\"\n"}
{"task_id": "collecting-chocolates", "prompt": "def minCost(nums: List[int], x: int) -> int:\n \"\"\"\n You are given a 0-indexed integer array nums of size n representing the cost of collecting different chocolates. The cost of collecting the chocolate at the index i\u00a0is nums[i]. Each chocolate is of a different type, and initially, the chocolate at the index\u00a0i\u00a0is of ith type.\n In one operation, you can do the following with an incurred cost of x:\n \n Simultaneously change the chocolate of ith type to ((i + 1) mod n)th type for all chocolates.\n \n Return the minimum cost to collect chocolates of all types, given that you can perform as many operations as you would like.\n \n Example 1:\n \n >>> minCost(nums = [20,1,15], x = 5)\n >>> 13\n Explanation: Initially, the chocolate types are [0,1,2]. We will buy the 1st\u00a0type of chocolate at a cost of 1.\n Now, we will perform the operation at a cost of 5, and the types of chocolates will become [1,2,0]. We will buy the 2nd type of chocolate at a cost of 1.\n Now, we will again perform the operation at a cost of 5, and the chocolate types will become [2,0,1]. We will buy the 0th type of chocolate at a cost of 1.\n Thus, the total cost will become (1 + 5 + 1 + 5 + 1) = 13. We can prove that this is optimal.\n \n Example 2:\n \n >>> minCost(nums = [1,2,3], x = 4)\n >>> 6\n Explanation: We will collect all three types of chocolates at their own price without performing any operations. Therefore, the total cost is 1 + 2 + 3 = 6.\n \"\"\"\n"}
{"task_id": "maximum-sum-queries", "prompt": "def maximumSumQueries(nums1: List[int], nums2: List[int], queries: List[List[int]]) -> List[int]:\n \"\"\"\n You are given two 0-indexed integer arrays nums1 and nums2, each of length n, and a 1-indexed 2D array queries where queries[i] = [xi, yi].\n For the ith query, find the maximum value of nums1[j] + nums2[j] among all indices j (0 <= j < n), where nums1[j] >= xi and nums2[j] >= yi, or -1 if there is no j satisfying the constraints.\n Return an array answer where answer[i] is the answer to the ith query.\n \n Example 1:\n \n >>> maximumSumQueries(nums1 = [4,3,1,2], nums2 = [2,4,9,5], queries = [[4,1],[1,3],[2,5]])\n >>> [6,10,7]\n Explanation:\n For the 1st query xi = 4\u00a0and\u00a0yi = 1, we can select index\u00a0j = 0\u00a0since\u00a0nums1[j] >= 4\u00a0and\u00a0nums2[j] >= 1. The sum\u00a0nums1[j] + nums2[j]\u00a0is 6, and we can show that 6 is the maximum we can obtain.\n \n For the 2nd query xi = 1\u00a0and\u00a0yi = 3, we can select index\u00a0j = 2\u00a0since\u00a0nums1[j] >= 1\u00a0and\u00a0nums2[j] >= 3. The sum\u00a0nums1[j] + nums2[j]\u00a0is 10, and we can show that 10 is the maximum we can obtain.\n \n For the 3rd query xi = 2\u00a0and\u00a0yi = 5, we can select index\u00a0j = 3\u00a0since\u00a0nums1[j] >= 2\u00a0and\u00a0nums2[j] >= 5. The sum\u00a0nums1[j] + nums2[j]\u00a0is 7, and we can show that 7 is the maximum we can obtain.\n \n Therefore, we return\u00a0[6,10,7].\n \n Example 2:\n \n >>> maximumSumQueries(nums1 = [3,2,5], nums2 = [2,3,4], queries = [[4,4],[3,2],[1,1]])\n >>> [9,9,9]\n Explanation: For this example, we can use index\u00a0j = 2\u00a0for all the queries since it satisfies the constraints for each query.\n \n Example 3:\n \n >>> maximumSumQueries(nums1 = [2,1], nums2 = [2,3], queries = [[3,3]])\n >>> [-1]\n Explanation: There is one query in this example with xi = 3 and yi = 3. For every index, j, either nums1[j] < xi or nums2[j] < yi. Hence, there is no solution.\n \"\"\"\n"}
{"task_id": "find-the-closest-marked-node", "prompt": "def minimumDistance(n: int, edges: List[List[int]], s: int, marked: List[int]) -> int:\n \"\"\"\n You are given a positive integer n which is the number of nodes of a 0-indexed directed weighted graph and a 0-indexed 2D array edges where edges[i] = [ui, vi, wi] indicates that there is an edge from node ui to node vi with weight wi.\n You are also given a node s and a node array marked; your task is to find the minimum distance from s to any of the nodes in marked.\n Return an integer denoting the minimum distance from s to any node in marked or -1 if there are no paths from s to any of the marked nodes.\n \n Example 1:\n \n >>> minimumDistance(n = 4, edges = [[0,1,1],[1,2,3],[2,3,2],[0,3,4]], s = 0, marked = [2,3])\n >>> 4\n Explanation: There is one path from node 0 (the green node) to node 2 (a red node), which is 0->1->2, and has a distance of 1 + 3 = 4.\n There are two paths from node 0 to node 3 (a red node), which are 0->1->2->3 and 0->3, the first one has a distance of 1 + 3 + 2 = 6 and the second one has a distance of 4.\n The minimum of them is 4.\n \n \n Example 2:\n \n >>> minimumDistance(n = 5, edges = [[0,1,2],[0,2,4],[1,3,1],[2,3,3],[3,4,2]], s = 1, marked = [0,4])\n >>> 3\n Explanation: There are no paths from node 1 (the green node) to node 0 (a red node).\n There is one path from node 1 to node 4 (a red node), which is 1->3->4, and has a distance of 1 + 2 = 3.\n So the answer is 3.\n \n \n Example 3:\n \n >>> minimumDistance(n = 4, edges = [[0,1,1],[1,2,3],[2,3,2]], s = 3, marked = [0,1])\n >>> -1\n Explanation: There are no paths from node 3 (the green node) to any of the marked nodes (the red nodes), so the answer is -1.\n \"\"\"\n"}
{"task_id": "total-distance-traveled", "prompt": "def distanceTraveled(mainTank: int, additionalTank: int) -> int:\n \"\"\"\n A truck has two fuel tanks. You are given two integers, mainTank representing the fuel present in the main tank in liters and additionalTank representing the fuel present in the additional tank in liters.\n The truck has a mileage of 10 km per liter. Whenever 5 liters of fuel get\u00a0used up in the main tank,\u00a0if the additional tank has at least 1 liters of fuel, 1 liters of fuel will be transferred from the additional tank to the main tank.\n Return the maximum distance which can be traveled.\n Note: Injection from the additional tank is not continuous. It happens suddenly and immediately for every 5 liters consumed.\n \n Example 1:\n \n >>> distanceTraveled(mainTank = 5, additionalTank = 10)\n >>> 60\n Explanation:\n After spending 5 litre of fuel, fuel remaining is (5 - 5 + 1) = 1 litre and distance traveled is 50km.\n After spending another 1 litre of fuel, no fuel gets injected in the main tank and the main tank becomes empty.\n Total distance traveled is 60km.\n \n Example 2:\n \n >>> distanceTraveled(mainTank = 1, additionalTank = 2)\n >>> 10\n Explanation:\n After spending 1 litre of fuel, the main tank becomes empty.\n Total distance traveled is 10km.\n \"\"\"\n"}
{"task_id": "find-the-value-of-the-partition", "prompt": "def findValueOfPartition(nums: List[int]) -> int:\n \"\"\"\n You are given a positive integer array nums.\n Partition nums into two arrays,\u00a0nums1 and nums2, such that:\n \n Each element of the array nums belongs to either the array nums1 or the array nums2.\n Both arrays are non-empty.\n The value of the partition is minimized.\n \n The value of the partition is |max(nums1) - min(nums2)|.\n Here, max(nums1) denotes the maximum element of the array nums1, and min(nums2) denotes the minimum element of the array nums2.\n Return the integer denoting the value of such partition.\n \n Example 1:\n \n >>> findValueOfPartition(nums = [1,3,2,4])\n >>> 1\n Explanation: We can partition the array nums into nums1 = [1,2] and nums2 = [3,4].\n - The maximum element of the array nums1 is equal to 2.\n - The minimum element of the array nums2 is equal to 3.\n The value of the partition is |2 - 3| = 1.\n It can be proven that 1 is the minimum value out of all partitions.\n \n Example 2:\n \n >>> findValueOfPartition(nums = [100,1,10])\n >>> 9\n Explanation: We can partition the array nums into nums1 = [10] and nums2 = [100,1].\n - The maximum element of the array nums1 is equal to 10.\n - The minimum element of the array nums2 is equal to 1.\n The value of the partition is |10 - 1| = 9.\n It can be proven that 9 is the minimum value out of all partitions.\n \"\"\"\n"}
{"task_id": "special-permutations", "prompt": "def specialPerm(nums: List[int]) -> int:\n \"\"\"\n You are given a\u00a00-indexed\u00a0integer array\u00a0nums\u00a0containing\u00a0n\u00a0distinct positive integers. A permutation of\u00a0nums\u00a0is called special if:\n \n For all indexes\u00a00 <= i < n - 1, either\u00a0nums[i] % nums[i+1] == 0\u00a0or\u00a0nums[i+1] % nums[i] == 0.\n \n Return\u00a0the total number of special permutations.\u00a0As the answer could be large, return it\u00a0modulo\u00a0109\u00a0+ 7.\n \n Example 1:\n \n >>> specialPerm(nums = [2,3,6])\n >>> 2\n Explanation: [3,6,2] and [2,6,3] are the two special permutations of nums.\n \n Example 2:\n \n >>> specialPerm(nums = [1,4,3])\n >>> 2\n Explanation: [3,1,4] and [4,1,3] are the two special permutations of nums.\n \"\"\"\n"}
{"task_id": "painting-the-walls", "prompt": "def paintWalls(cost: List[int], time: List[int]) -> int:\n \"\"\"\n You are given two 0-indexed integer arrays,\u00a0cost and time, of size n representing the costs and the time taken to paint n different walls respectively. There are two painters available:\n \n A\u00a0paid painter\u00a0that paints the ith wall in time[i] units of time and takes cost[i] units of money.\n A\u00a0free painter that paints\u00a0any wall in 1 unit of time at a cost of 0. But the\u00a0free painter can only be used if the paid painter is already occupied.\n \n Return the minimum amount of money required to paint the n\u00a0walls.\n \n Example 1:\n \n >>> paintWalls(cost = [1,2,3,2], time = [1,2,3,2])\n >>> 3\n Explanation: The walls at index 0 and 1 will be painted by the paid painter, and it will take 3 units of time; meanwhile, the free painter will paint the walls at index 2 and 3, free of cost in 2 units of time. Thus, the total cost is 1 + 2 = 3.\n \n Example 2:\n \n >>> paintWalls(cost = [2,3,4,2], time = [1,1,1,1])\n >>> 4\n Explanation: The walls at index 0 and 3 will be painted by the paid painter, and it will take 2 units of time; meanwhile, the free painter will paint the walls at index 1 and 2, free of cost in 2 units of time. Thus, the total cost is 2 + 2 = 4.\n \"\"\"\n"}
{"task_id": "count-substrings-without-repeating-character", "prompt": "def numberOfSpecialSubstrings(s: str) -> int:\n \"\"\"\n You are given a string s consisting only of lowercase English letters. We call a substring special if it contains no character which has occurred at least twice (in other words, it does not contain a repeating character). Your task is to count the number of special substrings. For example, in the string \"pop\", the substring \"po\" is a special substring, however, \"pop\" is not special (since 'p' has occurred twice).\n Return the number of special substrings.\n A substring is a contiguous sequence of characters within a string. For example, \"abc\" is a substring of \"abcd\", but \"acd\" is not.\n \n Example 1:\n \n >>> numberOfSpecialSubstrings(s = \"abcd\")\n >>> 10\n Explanation: Since each character occurs once, every substring is a special substring. We have 4 substrings of length one, 3 of length two, 2 of length three, and 1 substring of length four. So overall there are 4 + 3 + 2 + 1 = 10 special substrings.\n \n Example 2:\n \n >>> numberOfSpecialSubstrings(s = \"ooo\")\n >>> 3\n Explanation: Any substring with a length of at least two contains a repeating character. So we have to count the number of substrings of length one, which is 3.\n \n Example 3:\n \n >>> numberOfSpecialSubstrings(s = \"abab\")\n >>> 7\n Explanation: Special substrings are as follows (sorted by their start positions):\n Special substrings of length 1: \"a\", \"b\", \"a\", \"b\"\n Special substrings of length 2: \"ab\", \"ba\", \"ab\"\n And it can be shown that there are no special substrings with a length of at least three. So the answer would be 4 + 3 = 7.\n \"\"\"\n"}
{"task_id": "find-maximum-number-of-string-pairs", "prompt": "def maximumNumberOfStringPairs(words: List[str]) -> int:\n \"\"\"\n You are given a 0-indexed array words consisting of distinct strings.\n The string words[i] can be paired with the string words[j] if:\n \n The string words[i] is equal to the reversed string of words[j].\n 0 <= i < j < words.length.\n \n Return the maximum number of pairs that can be formed from the array words.\n Note that\u00a0each string can belong in\u00a0at most one pair.\n \n Example 1:\n \n >>> maximumNumberOfStringPairs(words = [\"cd\",\"ac\",\"dc\",\"ca\",\"zz\"])\n >>> 2\n Explanation: In this example, we can form 2 pair of strings in the following way:\n - We pair the 0th string with the 2nd string, as the reversed string of word[0] is \"dc\" and is equal to words[2].\n - We pair the 1st string with the 3rd string, as the reversed string of word[1] is \"ca\" and is equal to words[3].\n It can be proven that 2 is the maximum number of pairs that can be formed.\n Example 2:\n \n >>> maximumNumberOfStringPairs(words = [\"ab\",\"ba\",\"cc\"])\n >>> 1\n Explanation: In this example, we can form 1 pair of strings in the following way:\n - We pair the 0th string with the 1st string, as the reversed string of words[1] is \"ab\" and is equal to words[0].\n It can be proven that 1 is the maximum number of pairs that can be formed.\n \n Example 3:\n \n >>> maximumNumberOfStringPairs(words = [\"aa\",\"ab\"])\n >>> 0\n Explanation: In this example, we are unable to form any pair of strings.\n \"\"\"\n"}
{"task_id": "construct-the-longest-new-string", "prompt": "def longestString(x: int, y: int, z: int) -> int:\n \"\"\"\n You are given three integers x, y, and z.\n You have x strings equal to \"AA\", y strings equal to \"BB\", and z strings equal to \"AB\". You want to choose some (possibly all or none) of these strings and concatenate them in some order to form a new string. This new string must not contain \"AAA\" or \"BBB\" as a substring.\n Return the maximum possible length of the new string.\n A substring is a contiguous non-empty sequence of characters within a string.\n \n Example 1:\n \n >>> longestString(x = 2, y = 5, z = 1)\n >>> 12\n Explanation: We can concatenate the strings \"BB\", \"AA\", \"BB\", \"AA\", \"BB\", and \"AB\" in that order. Then, our new string is \"BBAABBAABBAB\".\n That string has length 12, and we can show that it is impossible to construct a string of longer length.\n \n Example 2:\n \n >>> longestString(x = 3, y = 2, z = 2)\n >>> 14\n Explanation: We can concatenate the strings \"AB\", \"AB\", \"AA\", \"BB\", \"AA\", \"BB\", and \"AA\" in that order. Then, our new string is \"ABABAABBAABBAA\".\n That string has length 14, and we can show that it is impossible to construct a string of longer length.\n \"\"\"\n"}
{"task_id": "decremental-string-concatenation", "prompt": "def minimizeConcatenatedLength(words: List[str]) -> int:\n \"\"\"\n You are given a 0-indexed array words containing n strings.\n Let's define a join operation join(x, y) between two strings x and y as concatenating them into xy. However, if the last character of x is equal to the first character of y, one of them is deleted.\n For example join(\"ab\", \"ba\") = \"aba\" and join(\"ab\", \"cde\") = \"abcde\".\n You are to perform n - 1 join operations. Let str0 = words[0]. Starting from i = 1 up to i = n - 1, for the ith operation, you can do one of the following:\n \n Make stri = join(stri - 1, words[i])\n Make stri = join(words[i], stri - 1)\n \n Your task is to minimize the length of strn - 1.\n Return an integer denoting the minimum possible length of strn - 1.\n \n Example 1:\n \n >>> minimizeConcatenatedLength(words = [\"aa\",\"ab\",\"bc\"])\n >>> 4\n Explanation: In this example, we can perform join operations in the following order to minimize the length of str2:\n str0 = \"aa\"\n str1 = join(str0, \"ab\") = \"aab\"\n str2 = join(str1, \"bc\") = \"aabc\"\n It can be shown that the minimum possible length of str2 is 4.\n Example 2:\n \n >>> minimizeConcatenatedLength(words = [\"ab\",\"b\"])\n >>> 2\n Explanation: In this example, str0 = \"ab\", there are two ways to get str1:\n join(str0, \"b\") = \"ab\" or join(\"b\", str0) = \"bab\".\n The first string, \"ab\", has the minimum length. Hence, the answer is 2.\n \n Example 3:\n \n >>> minimizeConcatenatedLength(words = [\"aaa\",\"c\",\"aba\"])\n >>> 6\n Explanation: In this example, we can perform join operations in the following order to minimize the length of str2:\n str0 = \"aaa\"\n str1 = join(str0, \"c\") = \"aaac\"\n str2 = join(\"aba\", str1) = \"abaaac\"\n It can be shown that the minimum possible length of str2 is 6.\n \"\"\"\n"}
{"task_id": "count-zero-request-servers", "prompt": "def countServers(n: int, logs: List[List[int]], x: int, queries: List[int]) -> List[int]:\n \"\"\"\n You are given an integer n denoting the total number of servers and a 2D 0-indexed integer array logs, where logs[i] = [server_id, time] denotes that the server with id server_id received a request at time time.\n You are also given an integer x and a 0-indexed integer array queries.\n Return a 0-indexed integer array arr of length queries.length where arr[i] represents the number of servers that did not receive any requests during the time interval [queries[i] - x, queries[i]].\n Note that the time intervals are inclusive.\n \n Example 1:\n \n >>> countServers(n = 3, logs = [[1,3],[2,6],[1,5]], x = 5, queries = [10,11])\n >>> [1,2]\n Explanation:\n For queries[0]: The servers with ids 1 and 2 get requests in the duration of [5, 10]. Hence, only server 3 gets zero requests.\n For queries[1]: Only the server with id 2 gets a request in duration of [6,11]. Hence, the servers with ids 1 and 3 are the only servers that do not receive any requests during that time period.\n \n \n Example 2:\n \n >>> countServers(n = 3, logs = [[2,4],[2,1],[1,2],[3,1]], x = 2, queries = [3,4])\n >>> [0,1]\n Explanation:\n For queries[0]: All servers get at least one request in the duration of [1, 3].\n For queries[1]: Only server with id 3 gets no request in the duration [2,4].\n \"\"\"\n"}
{"task_id": "number-of-beautiful-pairs", "prompt": "def countBeautifulPairs(nums: List[int]) -> int:\n \"\"\"\n You are given a 0-indexed integer array nums. A pair of indices i, j where 0 <=\u00a0i < j < nums.length is called beautiful if the first digit of nums[i] and the last digit of nums[j] are coprime.\n Return the total number of beautiful pairs in nums.\n Two integers x and y are coprime if there is no integer greater than 1 that divides both of them. In other words, x and y are coprime if gcd(x, y) == 1, where gcd(x, y) is the greatest common divisor of x and y.\n \n Example 1:\n \n >>> countBeautifulPairs(nums = [2,5,1,4])\n >>> 5\n Explanation: There are 5 beautiful pairs in nums:\n When i = 0 and j = 1: the first digit of nums[0] is 2, and the last digit of nums[1] is 5. We can confirm that 2 and 5 are coprime, since gcd(2,5) == 1.\n When i = 0 and j = 2: the first digit of nums[0] is 2, and the last digit of nums[2] is 1. Indeed, gcd(2,1) == 1.\n When i = 1 and j = 2: the first digit of nums[1] is 5, and the last digit of nums[2] is 1. Indeed, gcd(5,1) == 1.\n When i = 1 and j = 3: the first digit of nums[1] is 5, and the last digit of nums[3] is 4. Indeed, gcd(5,4) == 1.\n When i = 2 and j = 3: the first digit of nums[2] is 1, and the last digit of nums[3] is 4. Indeed, gcd(1,4) == 1.\n Thus, we return 5.\n \n Example 2:\n \n >>> countBeautifulPairs(nums = [11,21,12])\n >>> 2\n Explanation: There are 2 beautiful pairs:\n When i = 0 and j = 1: the first digit of nums[0] is 1, and the last digit of nums[1] is 1. Indeed, gcd(1,1) == 1.\n When i = 0 and j = 2: the first digit of nums[0] is 1, and the last digit of nums[2] is 2. Indeed, gcd(1,2) == 1.\n Thus, we return 2.\n \"\"\"\n"}
{"task_id": "minimum-operations-to-make-the-integer-zero", "prompt": "def makeTheIntegerZero(num1: int, num2: int) -> int:\n \"\"\"\n You are given two integers num1 and num2.\n In one operation, you can choose integer i in the range [0, 60] and subtract 2i + num2 from num1.\n Return the integer denoting the minimum number of operations needed to make num1 equal to 0.\n If it is impossible to make num1 equal to 0, return -1.\n \n Example 1:\n \n >>> makeTheIntegerZero(num1 = 3, num2 = -2)\n >>> 3\n Explanation: We can make 3 equal to 0 with the following operations:\n - We choose i = 2 and subtract 22 + (-2) from 3, 3 - (4 + (-2)) = 1.\n - We choose i = 2 and subtract 22\u00a0+ (-2) from 1, 1 - (4 + (-2)) = -1.\n - We choose i = 0 and subtract 20\u00a0+ (-2) from -1, (-1) - (1 + (-2)) = 0.\n It can be proven, that 3 is the minimum number of operations that we need to perform.\n \n Example 2:\n \n >>> makeTheIntegerZero(num1 = 5, num2 = 7)\n >>> -1\n Explanation: It can be proven, that it is impossible to make 5 equal to 0 with the given operation.\n \"\"\"\n"}
{"task_id": "ways-to-split-array-into-good-subarrays", "prompt": "def numberOfGoodSubarraySplits(nums: List[int]) -> int:\n \"\"\"\n You are given a binary array nums.\n A subarray of an array is good if it contains exactly one element with the value 1.\n Return an integer denoting the number of ways to split the array nums into good subarrays. As the number may be too large, return it modulo 109 + 7.\n A subarray is a contiguous non-empty sequence of elements within an array.\n \n Example 1:\n \n >>> numberOfGoodSubarraySplits(nums = [0,1,0,0,1])\n >>> 3\n Explanation: There are 3 ways to split nums into good subarrays:\n - [0,1] [0,0,1]\n - [0,1,0] [0,1]\n - [0,1,0,0] [1]\n \n Example 2:\n \n >>> numberOfGoodSubarraySplits(nums = [0,1,0])\n >>> 1\n Explanation: There is 1 way to split nums into good subarrays:\n - [0,1,0]\n \"\"\"\n"}
{"task_id": "robot-collisions", "prompt": "def survivedRobotsHealths(positions: List[int], healths: List[int], directions: str) -> List[int]:\n \"\"\"\n There are n 1-indexed robots, each having a position on a line, health, and movement direction.\n You are given 0-indexed integer arrays positions, healths, and a string directions (directions[i] is either 'L' for left or 'R' for right). All integers in positions are unique.\n All robots start moving on the line simultaneously at the same speed in their given directions. If two robots ever share the same position while moving, they will collide.\n If two robots collide, the robot with lower health is removed from the line, and the health of the other robot decreases by one. The surviving robot continues in the same direction it was going. If both robots have the same health, they are both removed from the line.\n Your task is to determine the health of the robots that survive the collisions, in the same order that the robots were given, i.e. final health of robot 1 (if survived), final health of robot 2 (if survived), and so on. If there are no survivors, return an empty array.\n Return an array containing the health of the remaining robots (in the order they were given in the input), after no further collisions can occur.\n Note: The positions may be unsorted.\n \n \n Example 1:\n \n \n >>> survivedRobotsHealths(positions = [5,4,3,2,1], healths = [2,17,9,15,10], directions = \"RRRRR\")\n >>> [2,17,9,15,10]\n Explanation: No collision occurs in this example, since all robots are moving in the same direction. So, the health of the robots in order from the first robot is returned, [2, 17, 9, 15, 10].\n \n Example 2:\n \n \n >>> survivedRobotsHealths(positions = [3,5,2,6], healths = [10,10,15,12], directions = \"RLRL\")\n >>> [14]\n Explanation: There are 2 collisions in this example. Firstly, robot 1 and robot 2 will collide, and since both have the same health, they will be removed from the line. Next, robot 3 and robot 4 will collide and since robot 4's health is smaller, it gets removed, and robot 3's health becomes 15 - 1 = 14. Only robot 3 remains, so we return [14].\n \n Example 3:\n \n \n >>> survivedRobotsHealths(positions = [1,2,5,6], healths = [10,10,11,11], directions = \"RLRL\")\n >>> []\n Explanation: Robot 1 and robot 2 will collide and since both have the same health, they are both removed. Robot 3 and 4 will collide and since both have the same health, they are both removed. So, we return an empty array, [].\n \"\"\"\n"}
{"task_id": "longest-even-odd-subarray-with-threshold", "prompt": "def longestAlternatingSubarray(nums: List[int], threshold: int) -> int:\n \"\"\"\n You are given a 0-indexed integer array nums and an integer threshold.\n Find the length of the longest subarray of nums starting at index l and ending at index r (0 <= l <= r < nums.length) that satisfies the following conditions:\n \n nums[l] % 2 == 0\n For all indices i in the range [l, r - 1], nums[i] % 2 != nums[i + 1] % 2\n For all indices i in the range [l, r], nums[i] <= threshold\n \n Return an integer denoting the length of the longest such subarray.\n Note: A subarray is a contiguous non-empty sequence of elements within an array.\n \n Example 1:\n \n >>> longestAlternatingSubarray(nums = [3,2,5,4], threshold = 5)\n >>> 3\n Explanation: In this example, we can select the subarray that starts at l = 1 and ends at r = 3 => [2,5,4]. This subarray satisfies the conditions.\n Hence, the answer is the length of the subarray, 3. We can show that 3 is the maximum possible achievable length.\n Example 2:\n \n >>> longestAlternatingSubarray(nums = [1,2], threshold = 2)\n >>> 1\n Explanation: In this example, we can select the subarray that starts at l = 1 and ends at r = 1 => [2].\n It satisfies all the conditions and we can show that 1 is the maximum possible achievable length.\n \n Example 3:\n \n >>> longestAlternatingSubarray(nums = [2,3,4,5], threshold = 4)\n >>> 3\n Explanation: In this example, we can select the subarray that starts at l = 0 and ends at r = 2 => [2,3,4].\n It satisfies all the conditions.\n Hence, the answer is the length of the subarray, 3. We can show that 3 is the maximum possible achievable length.\n \"\"\"\n"}
{"task_id": "prime-pairs-with-target-sum", "prompt": "def findPrimePairs(n: int) -> List[List[int]]:\n \"\"\"\n You are given an integer n. We say that two integers x and y form a prime number pair if:\n \n 1 <= x <= y <= n\n x + y == n\n x and y are prime numbers\n \n Return the 2D sorted list of prime number pairs [xi, yi]. The list should be sorted in increasing order of xi. If there are no prime number pairs at all, return an empty array.\n Note: A prime number is a natural number greater than 1 with only two factors, itself and 1.\n \n Example 1:\n \n >>> findPrimePairs(n = 10)\n >>> [[3,7],[5,5]]\n Explanation: In this example, there are two prime pairs that satisfy the criteria.\n These pairs are [3,7] and [5,5], and we return them in the sorted order as described in the problem statement.\n \n Example 2:\n \n >>> findPrimePairs(n = 2)\n >>> []\n Explanation: We can show that there is no prime number pair that gives a sum of 2, so we return an empty array.\n \"\"\"\n"}
{"task_id": "continuous-subarrays", "prompt": "def continuousSubarrays(nums: List[int]) -> int:\n \"\"\"\n You are given a 0-indexed integer array nums. A subarray of nums is called continuous if:\n \n Let i, i + 1, ..., j be the indices in the subarray. Then, for each pair of indices i <= i1, i2 <= j, 0 <= |nums[i1] - nums[i2]| <= 2.\n \n Return the total number of continuous subarrays.\n A subarray is a contiguous non-empty sequence of elements within an array.\n \n Example 1:\n \n >>> continuousSubarrays(nums = [5,4,2,4])\n >>> 8\n Explanation:\n Continuous subarray of size 1: [5], [4], [2], [4].\n Continuous subarray of size 2: [5,4], [4,2], [2,4].\n Continuous subarray of size 3: [4,2,4].\n There are no subarrys of size 4.\n Total continuous subarrays = 4 + 3 + 1 = 8.\n It can be shown that there are no more continuous subarrays.\n \n \n Example 2:\n \n >>> continuousSubarrays(nums = [1,2,3])\n >>> 6\n Explanation:\n Continuous subarray of size 1: [1], [2], [3].\n Continuous subarray of size 2: [1,2], [2,3].\n Continuous subarray of size 3: [1,2,3].\n Total continuous subarrays = 3 + 2 + 1 = 6.\n \"\"\"\n"}
{"task_id": "sum-of-imbalance-numbers-of-all-subarrays", "prompt": "def sumImbalanceNumbers(nums: List[int]) -> int:\n \"\"\"\n The imbalance number of a 0-indexed integer array arr of length n is defined as the number of indices in sarr = sorted(arr) such that:\n \n 0 <= i < n - 1, and\n sarr[i+1] - sarr[i] > 1\n \n Here, sorted(arr) is the function that returns the sorted version of arr.\n Given a 0-indexed integer array nums, return the sum of imbalance numbers of all its subarrays.\n A subarray is a contiguous non-empty sequence of elements within an array.\n \n Example 1:\n \n >>> sumImbalanceNumbers(nums = [2,3,1,4])\n >>> 3\n Explanation: There are 3 subarrays with non-zero imbalance numbers:\n - Subarray [3, 1] with an imbalance number of 1.\n - Subarray [3, 1, 4] with an imbalance number of 1.\n - Subarray [1, 4] with an imbalance number of 1.\n The imbalance number of all other subarrays is 0. Hence, the sum of imbalance numbers of all the subarrays of nums is 3.\n \n Example 2:\n \n >>> sumImbalanceNumbers(nums = [1,3,3,3,5])\n >>> 8\n Explanation: There are 7 subarrays with non-zero imbalance numbers:\n - Subarray [1, 3] with an imbalance number of 1.\n - Subarray [1, 3, 3] with an imbalance number of 1.\n - Subarray [1, 3, 3, 3] with an imbalance number of 1.\n - Subarray [1, 3, 3, 3, 5] with an imbalance number of 2.\n - Subarray [3, 3, 3, 5] with an imbalance number of 1.\n - Subarray [3, 3, 5] with an imbalance number of 1.\n - Subarray [3, 5] with an imbalance number of 1.\n The imbalance number of all other subarrays is 0. Hence, the sum of imbalance numbers of all the subarrays of nums is 8.\n \"\"\"\n"}
{"task_id": "is-array-a-preorder-of-some-binary-tree", "prompt": "def isPreorder(nodes: List[List[int]]) -> bool:\n \"\"\"\n Given a 0-indexed integer 2D array nodes, your task is to determine if the given array represents the preorder traversal of some binary tree.\n For each index i, nodes[i] = [id, parentId], where id is the id of the node at the index i and parentId is the id of its parent in the tree (if the node has no parent, then parentId == -1).\n Return true if the given array represents the preorder traversal of some tree, and false otherwise.\n Note: the preorder traversal of a tree is a recursive way to traverse a tree in which we first visit the current node, then we do the preorder traversal for the left child, and finally, we do it for the right child.\n \n Example 1:\n \n >>> isPreorder(nodes = [[0,-1],[1,0],[2,0],[3,2],[4,2]])\n >>> true\n Explanation: The given nodes make the tree in the picture below.\n We can show that this is the preorder traversal of the tree, first we visit node 0, then we do the preorder traversal of the right child which is [1], then we do the preorder traversal of the left child which is [2,3,4].\n \n \n Example 2:\n \n >>> isPreorder(nodes = [[0,-1],[1,0],[2,0],[3,1],[4,1]])\n >>> false\n Explanation: The given nodes make the tree in the picture below.\n For the preorder traversal, first we visit node 0, then we do the preorder traversal of the right child which is [1,3,4], but we can see that in the given order, 2 comes between 1 and 3, so, it's not the preorder traversal of the tree.\n \"\"\"\n"}
{"task_id": "longest-alternating-subarray", "prompt": "def alternatingSubarray(nums: List[int]) -> int:\n \"\"\"\n You are given a 0-indexed integer array nums. A subarray s of length m is called alternating if:\n \n m is greater than 1.\n s1 = s0 + 1.\n The 0-indexed subarray s looks like [s0, s1, s0, s1,...,s(m-1) % 2]. In other words, s1 - s0 = 1, s2 - s1 = -1, s3 - s2 = 1, s4 - s3 = -1, and so on up to s[m - 1] - s[m - 2] = (-1)m.\n \n Return the maximum length of all alternating subarrays present in nums or -1 if no such subarray exists.\n A subarray is a contiguous non-empty sequence of elements within an array.\n \n Example 1:\n \n >>> alternatingSubarray(nums = [2,3,4,3,4])\n >>> 4\n Explanation:\n The alternating subarrays are [2, 3], [3,4], [3,4,3], and [3,4,3,4]. The longest of these is [3,4,3,4], which is of length 4.\n \n Example 2:\n \n >>> alternatingSubarray(nums = [4,5,6])\n >>> 2\n Explanation:\n [4,5] and [5,6] are the only two alternating subarrays. They are both of length 2.\n \"\"\"\n"}
{"task_id": "relocate-marbles", "prompt": "def relocateMarbles(nums: List[int], moveFrom: List[int], moveTo: List[int]) -> List[int]:\n \"\"\"\n You are given a 0-indexed integer array nums representing the initial positions of some marbles. You are also given two 0-indexed integer arrays moveFrom and moveTo of equal length.\n Throughout moveFrom.length steps, you will change the positions of the marbles. On the ith step, you will move all marbles at position moveFrom[i] to position moveTo[i].\n After completing all the steps, return the sorted list of occupied positions.\n Notes:\n \n We call a position occupied if there is at least one marble in that position.\n There may be multiple marbles in a single position.\n \n \n Example 1:\n \n >>> relocateMarbles(nums = [1,6,7,8], moveFrom = [1,7,2], moveTo = [2,9,5])\n >>> [5,6,8,9]\n Explanation: Initially, the marbles are at positions 1,6,7,8.\n At the i = 0th step, we move the marbles at position 1 to position 2. Then, positions 2,6,7,8 are occupied.\n At the i = 1st step, we move the marbles at position 7 to position 9. Then, positions 2,6,8,9 are occupied.\n At the i = 2nd step, we move the marbles at position 2 to position 5. Then, positions 5,6,8,9 are occupied.\n At the end, the final positions containing at least one marbles are [5,6,8,9].\n Example 2:\n \n >>> relocateMarbles(nums = [1,1,3,3], moveFrom = [1,3], moveTo = [2,2])\n >>> [2]\n Explanation: Initially, the marbles are at positions [1,1,3,3].\n At the i = 0th step, we move all the marbles at position 1 to position 2. Then, the marbles are at positions [2,2,3,3].\n At the i = 1st step, we move all the marbles at position 3 to position 2. Then, the marbles are at positions [2,2,2,2].\n Since 2 is the only occupied position, we return [2].\n \"\"\"\n"}
{"task_id": "partition-string-into-minimum-beautiful-substrings", "prompt": "def minimumBeautifulSubstrings(s: str) -> int:\n \"\"\"\n Given a binary string s, partition the string into one or more substrings such that each substring is beautiful.\n A string is beautiful if:\n \n It doesn't contain leading zeros.\n It's the binary representation of a number that is a power of 5.\n \n Return the minimum number of substrings in such partition. If it is impossible to partition the string s into beautiful substrings,\u00a0return -1.\n A substring is a contiguous sequence of characters in a string.\n \n Example 1:\n \n >>> minimumBeautifulSubstrings(s = \"1011\")\n >>> 2\n Explanation: We can paritition the given string into [\"101\", \"1\"].\n - The string \"101\" does not contain leading zeros and is the binary representation of integer 51 = 5.\n - The string \"1\" does not contain leading zeros and is the binary representation of integer 50 = 1.\n It can be shown that 2 is the minimum number of beautiful substrings that s can be partitioned into.\n \n Example 2:\n \n >>> minimumBeautifulSubstrings(s = \"111\")\n >>> 3\n Explanation: We can paritition the given string into [\"1\", \"1\", \"1\"].\n - The string \"1\" does not contain leading zeros and is the binary representation of integer 50 = 1.\n It can be shown that 3 is the minimum number of beautiful substrings that s can be partitioned into.\n \n Example 3:\n \n >>> minimumBeautifulSubstrings(s = \"0\")\n >>> -1\n Explanation: We can not partition the given string into beautiful substrings.\n \"\"\"\n"}
{"task_id": "number-of-black-blocks", "prompt": "def countBlackBlocks(m: int, n: int, coordinates: List[List[int]]) -> List[int]:\n \"\"\"\n You are given two integers m and n representing the dimensions of a\u00a00-indexed\u00a0m x n grid.\n You are also given a 0-indexed 2D integer matrix coordinates, where coordinates[i] = [x, y] indicates that the cell with coordinates [x, y] is colored black. All cells in the grid that do not appear in coordinates are white.\n A block is defined as a 2 x 2 submatrix of the grid. More formally, a block with cell [x, y] as its top-left corner where 0 <= x < m - 1 and 0 <= y < n - 1 contains the coordinates [x, y], [x + 1, y], [x, y + 1], and [x + 1, y + 1].\n Return a 0-indexed integer array arr of size 5 such that arr[i] is the number of blocks that contains exactly i black cells.\n \n Example 1:\n \n >>> countBlackBlocks(m = 3, n = 3, coordinates = [[0,0]])\n >>> [3,1,0,0,0]\n Explanation: The grid looks like this:\n \n There is only 1 block with one black cell, and it is the block starting with cell [0,0].\n The other 3 blocks start with cells [0,1], [1,0] and [1,1]. They all have zero black cells.\n Thus, we return [3,1,0,0,0].\n \n Example 2:\n \n >>> countBlackBlocks(m = 3, n = 3, coordinates = [[0,0],[1,1],[0,2]])\n >>> [0,2,2,0,0]\n Explanation: The grid looks like this:\n \n There are 2 blocks with two black cells (the ones starting with cell coordinates [0,0] and [0,1]).\n The other 2 blocks have starting cell coordinates of [1,0] and [1,1]. They both have 1 black cell.\n Therefore, we return [0,2,2,0,0].\n \"\"\"\n"}
{"task_id": "find-the-maximum-achievable-number", "prompt": "def theMaximumAchievableX(num: int, t: int) -> int:\n \"\"\"\n Given two integers, num and t. A number x is achievable if it can become equal to num after applying the following operation at most t times:\n \n Increase or decrease x by 1, and simultaneously increase or decrease num by 1.\n \n Return the maximum possible value of x.\n \n Example 1:\n \n >>> theMaximumAchievableX(num = 4, t = 1)\n >>> 6\n Explanation:\n Apply the following operation once to make the maximum achievable number equal to num:\n \n Decrease the maximum achievable number by 1, and increase num by 1.\n \n \n Example 2:\n \n >>> theMaximumAchievableX(num = 3, t = 2)\n >>> 7\n Explanation:\n Apply the following operation twice to make the maximum achievable number equal to num:\n \n Decrease the maximum achievable number by 1, and increase num by 1.\n \"\"\"\n"}
{"task_id": "maximum-number-of-jumps-to-reach-the-last-index", "prompt": "def maximumJumps(nums: List[int], target: int) -> int:\n \"\"\"\n You are given a 0-indexed array nums of n integers and an integer target.\n You are initially positioned at index 0. In one step, you can jump from index i to any index j such that:\n \n 0 <= i < j < n\n -target <= nums[j] - nums[i] <= target\n \n Return the maximum number of jumps you can make to reach index n - 1.\n If there is no way to reach index n - 1, return -1.\n \n Example 1:\n \n >>> maximumJumps(nums = [1,3,6,4,1,2], target = 2)\n >>> 3\n Explanation: To go from index 0 to index n - 1 with the maximum number of jumps, you can perform the following jumping sequence:\n - Jump from index 0 to index 1.\n - Jump from index 1 to index 3.\n - Jump from index 3 to index 5.\n It can be proven that there is no other jumping sequence that goes from 0 to n - 1 with more than 3 jumps. Hence, the answer is 3.\n Example 2:\n \n >>> maximumJumps(nums = [1,3,6,4,1,2], target = 3)\n >>> 5\n Explanation: To go from index 0 to index n - 1 with the maximum number of jumps, you can perform the following jumping sequence:\n - Jump from index 0 to index 1.\n - Jump from index 1 to index 2.\n - Jump from index 2 to index 3.\n - Jump from index 3 to index 4.\n - Jump from index 4 to index 5.\n It can be proven that there is no other jumping sequence that goes from 0 to n - 1 with more than 5 jumps. Hence, the answer is 5.\n Example 3:\n \n >>> maximumJumps(nums = [1,3,6,4,1,2], target = 0)\n >>> -1\n Explanation: It can be proven that there is no jumping sequence that goes from 0 to n - 1. Hence, the answer is -1.\n \"\"\"\n"}
{"task_id": "longest-non-decreasing-subarray-from-two-arrays", "prompt": "def maxNonDecreasingLength(nums1: List[int], nums2: List[int]) -> int:\n \"\"\"\n You are given two 0-indexed integer arrays nums1 and nums2 of length n.\n Let's define another 0-indexed integer array, nums3, of length n. For each index i in the range [0, n - 1], you can assign either nums1[i] or nums2[i] to nums3[i].\n Your task is to maximize the length of the longest non-decreasing subarray in nums3 by choosing its values optimally.\n Return an integer representing the length of the longest non-decreasing subarray in nums3.\n Note: A subarray is a contiguous non-empty sequence of elements within an array.\n \n Example 1:\n \n >>> maxNonDecreasingLength(nums1 = [2,3,1], nums2 = [1,2,1])\n >>> 2\n Explanation: One way to construct nums3 is:\n nums3 = [nums1[0], nums2[1], nums2[2]] => [2,2,1].\n The subarray starting from index 0 and ending at index 1, [2,2], forms a non-decreasing subarray of length 2.\n We can show that 2 is the maximum achievable length.\n Example 2:\n \n >>> maxNonDecreasingLength(nums1 = [1,3,2,1], nums2 = [2,2,3,4])\n >>> 4\n Explanation: One way to construct nums3 is:\n nums3 = [nums1[0], nums2[1], nums2[2], nums2[3]] => [1,2,3,4].\n The entire array forms a non-decreasing subarray of length 4, making it the maximum achievable length.\n \n Example 3:\n \n >>> maxNonDecreasingLength(nums1 = [1,1], nums2 = [2,2])\n >>> 2\n Explanation: One way to construct nums3 is:\n nums3 = [nums1[0], nums1[1]] => [1,1].\n The entire array forms a non-decreasing subarray of length 2, making it the maximum achievable length.\n \"\"\"\n"}
{"task_id": "apply-operations-to-make-all-array-elements-equal-to-zero", "prompt": "def checkArray(nums: List[int], k: int) -> bool:\n \"\"\"\n You are given a 0-indexed integer array nums and a positive integer k.\n You can apply the following operation on the array any number of times:\n \n Choose any subarray of size k from the array and decrease all its elements by 1.\n \n Return true if you can make all the array elements equal to 0, or false otherwise.\n A subarray is a contiguous non-empty part of an array.\n \n Example 1:\n \n >>> checkArray(nums = [2,2,3,1,1,0], k = 3)\n >>> true\n Explanation: We can do the following operations:\n - Choose the subarray [2,2,3]. The resulting array will be nums = [1,1,2,1,1,0].\n - Choose the subarray [2,1,1]. The resulting array will be nums = [1,1,1,0,0,0].\n - Choose the subarray [1,1,1]. The resulting array will be nums = [0,0,0,0,0,0].\n \n Example 2:\n \n >>> checkArray(nums = [1,3,1,1], k = 2)\n >>> false\n Explanation: It is not possible to make all the array elements equal to 0.\n \"\"\"\n"}
{"task_id": "height-of-special-binary-tree", "prompt": "# class TreeNode:\n# def __init__(val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def heightOfTree(root: Optional[TreeNode]) -> int:\n \"\"\"\n You are given a root, which is the root of a special binary tree with n nodes. The nodes of the special binary tree are numbered from 1 to n. Suppose the tree has k leaves in the following order: b1 < b2 < ... < bk.\n The leaves of this tree have a special property! That is, for every leaf bi, the following conditions hold:\n \n The right child of bi is bi + 1 if i < k, and b1 otherwise.\n The left child of bi is bi - 1 if i > 1, and bk otherwise.\n \n Return the height of the given tree.\n Note: The height of a binary tree is the length of the longest path from the root to any other node.\n \n Example 1:\n \n >>> __init__(root = [1,2,3,null,null,4,5])\n >>> 2\n Explanation: The given tree is shown in the following picture. Each leaf's left child is the leaf to its left (shown with the blue edges). Each leaf's right child is the leaf to its right (shown with the red edges). We can see that the graph has a height of 2.\n \n \n Example 2:\n \n >>> __init__(root = [1,2])\n >>> 1\n Explanation: The given tree is shown in the following picture. There is only one leaf, so it doesn't have any left or right child. We can see that the graph has a height of 1.\n \n \n Example 3:\n \n >>> __init__(root = [1,2,3,null,null,4,null,5,6])\n >>> 3\n Explanation: The given tree is shown in the following picture. Each leaf's left child is the leaf to its left (shown with the blue edges). Each leaf's right child is the leaf to its right (shown with the red edges). We can see that the graph has a height of 3.\n \"\"\"\n"}
{"task_id": "sum-of-squares-of-special-elements", "prompt": "def sumOfSquares(nums: List[int]) -> int:\n \"\"\"\n You are given a 1-indexed integer array nums of length n.\n An element nums[i] of nums is called special if i divides n, i.e. n % i == 0.\n Return the sum of the squares of all special elements of nums.\n \n Example 1:\n \n >>> sumOfSquares(nums = [1,2,3,4])\n >>> 21\n Explanation: There are exactly 3 special elements in nums: nums[1] since 1 divides 4, nums[2] since 2 divides 4, and nums[4] since 4 divides 4.\n Hence, the sum of the squares of all special elements of nums is nums[1] * nums[1] + nums[2] * nums[2] + nums[4] * nums[4] = 1 * 1 + 2 * 2 + 4 * 4 = 21.\n \n Example 2:\n \n >>> sumOfSquares(nums = [2,7,1,19,18,3])\n >>> 63\n Explanation: There are exactly 4 special elements in nums: nums[1] since 1 divides 6, nums[2] since 2 divides 6, nums[3] since 3 divides 6, and nums[6] since 6 divides 6.\n Hence, the sum of the squares of all special elements of nums is nums[1] * nums[1] + nums[2] * nums[2] + nums[3] * nums[3] + nums[6] * nums[6] = 2 * 2 + 7 * 7 + 1 * 1 + 3 * 3 = 63.\n \"\"\"\n"}
{"task_id": "maximum-beauty-of-an-array-after-applying-operation", "prompt": "def maximumBeauty(nums: List[int], k: int) -> int:\n \"\"\"\n You are given a 0-indexed array nums and a non-negative integer k.\n In one operation, you can do the following:\n \n Choose an index i that hasn't been chosen before from the range [0, nums.length - 1].\n Replace nums[i] with any integer from the range [nums[i] - k, nums[i] + k].\n \n The beauty of the array is the length of the longest subsequence consisting of equal elements.\n Return the maximum possible beauty of the array nums after applying the operation any number of times.\n Note that you can apply the operation to each index only once.\n A\u00a0subsequence of an array is a new array generated from the original array by deleting some elements (possibly none) without changing the order of the remaining elements.\n \n Example 1:\n \n >>> maximumBeauty(nums = [4,6,1,2], k = 2)\n >>> 3\n Explanation: In this example, we apply the following operations:\n - Choose index 1, replace it with 4 (from range [4,8]), nums = [4,4,1,2].\n - Choose index 3, replace it with 4 (from range [0,4]), nums = [4,4,1,4].\n After the applied operations, the beauty of the array nums is 3 (subsequence consisting of indices 0, 1, and 3).\n It can be proven that 3 is the maximum possible length we can achieve.\n \n Example 2:\n \n >>> maximumBeauty(nums = [1,1,1,1], k = 10)\n >>> 4\n Explanation: In this example we don't have to apply any operations.\n The beauty of the array nums is 4 (whole array).\n \"\"\"\n"}
{"task_id": "minimum-index-of-a-valid-split", "prompt": "def minimumIndex(nums: List[int]) -> int:\n \"\"\"\n An element x of an integer array arr of length m is dominant if more than half the elements of arr have a value of x.\n You are given a 0-indexed integer array nums of length n with one dominant element.\n You can split nums at an index i into two arrays nums[0, ..., i] and nums[i + 1, ..., n - 1], but the split is only valid if:\n \n 0 <= i < n - 1\n nums[0, ..., i], and nums[i + 1, ..., n - 1] have the same dominant element.\n \n Here, nums[i, ..., j] denotes the subarray of nums starting at index i and ending at index j, both ends being inclusive. Particularly, if j < i then nums[i, ..., j] denotes an empty subarray.\n Return the minimum index of a valid split. If no valid split exists, return -1.\n \n Example 1:\n \n >>> minimumIndex(nums = [1,2,2,2])\n >>> 2\n Explanation: We can split the array at index 2 to obtain arrays [1,2,2] and [2].\n In array [1,2,2], element 2 is dominant since it occurs twice in the array and 2 * 2 > 3.\n In array [2], element 2 is dominant since it occurs once in the array and 1 * 2 > 1.\n Both [1,2,2] and [2] have the same dominant element as nums, so this is a valid split.\n It can be shown that index 2 is the minimum index of a valid split.\n Example 2:\n \n >>> minimumIndex(nums = [2,1,3,1,1,1,7,1,2,1])\n >>> 4\n Explanation: We can split the array at index 4 to obtain arrays [2,1,3,1,1] and [1,7,1,2,1].\n In array [2,1,3,1,1], element 1 is dominant since it occurs thrice in the array and 3 * 2 > 5.\n In array [1,7,1,2,1], element 1 is dominant since it occurs thrice in the array and 3 * 2 > 5.\n Both [2,1,3,1,1] and [1,7,1,2,1] have the same dominant element as nums, so this is a valid split.\n It can be shown that index 4 is the minimum index of a valid split.\n Example 3:\n \n >>> minimumIndex(nums = [3,3,3,3,7,2,2])\n >>> -1\n Explanation: It can be shown that there is no valid split.\n \"\"\"\n"}
{"task_id": "length-of-the-longest-valid-substring", "prompt": "def longestValidSubstring(word: str, forbidden: List[str]) -> int:\n \"\"\"\n You are given a string word and an array of strings forbidden.\n A string is called valid if none of its substrings are present in forbidden.\n Return the length of the longest valid substring of the string word.\n A substring is a contiguous sequence of characters in a string, possibly empty.\n \n Example 1:\n \n >>> longestValidSubstring(word = \"cbaaaabc\", forbidden = [\"aaa\",\"cb\"])\n >>> 4\n Explanation: There are 11 valid substrings in word: \"c\", \"b\", \"a\", \"ba\", \"aa\", \"bc\", \"baa\", \"aab\", \"ab\", \"abc\" and \"aabc\". The length of the longest valid substring is 4.\n It can be shown that all other substrings contain either \"aaa\" or \"cb\" as a substring.\n Example 2:\n \n >>> longestValidSubstring(word = \"leetcode\", forbidden = [\"de\",\"le\",\"e\"])\n >>> 4\n Explanation: There are 11 valid substrings in word: \"l\", \"t\", \"c\", \"o\", \"d\", \"tc\", \"co\", \"od\", \"tco\", \"cod\", and \"tcod\". The length of the longest valid substring is 4.\n It can be shown that all other substrings contain either \"de\", \"le\", or \"e\" as a substring.\n \"\"\"\n"}
{"task_id": "number-of-unique-categories", "prompt": "# class CategoryHandler:\n# def haveSameCategory(a: int, b: int) -> bool:\n# pass\nclass Solution:\n def numberOfCategories(n: int, categoryHandler: Optional['CategoryHandler']) -> int:\n \"\"\"\n You are given an integer n and an object categoryHandler of class CategoryHandler.\n There are n\u00a0elements, numbered from 0 to n - 1. Each element has a category, and your task is to find the number of unique categories.\n The class CategoryHandler contains the following function, which may help you:\n \n boolean haveSameCategory(integer a, integer b): Returns true if a and b are in the same category and false otherwise. Also, if either a or b is not a valid number (i.e. it's greater than or equal to nor less than 0), it returns false.\n \n Return the number of unique categories.\n \n Example 1:\n \n >>> haveSameCategory(n = 6, categoryHandler = [1,1,2,2,3,3])\n >>> 3\n Explanation: There are 6 elements in this example. The first two elements belong to category 1, the second two belong to category 2, and the last two elements belong to category 3. So there are 3 unique categories.\n \n Example 2:\n \n >>> haveSameCategory(n = 5, categoryHandler = [1,2,3,4,5])\n >>> 5\n Explanation: There are 5 elements in this example. Each element belongs to a unique category. So there are 5 unique categories.\n \n Example 3:\n \n >>> haveSameCategory(n = 3, categoryHandler = [1,1,1])\n >>> 1\n Explanation: There are 3 elements in this example. All of them belong to one category. So there is only 1 unique category.\n \"\"\"\n"}
{"task_id": "check-if-array-is-good", "prompt": "def isGood(nums: List[int]) -> bool:\n \"\"\"\n You are given an integer array nums. We consider an array good if it is a permutation of an array base[n].\n base[n] = [1, 2, ..., n - 1, n, n] (in other words, it is an array of length n + 1 which contains 1 to n - 1 exactly once, plus two occurrences of n). For example, base[1] = [1, 1] and base[3] = [1, 2, 3, 3].\n Return true if the given array is good, otherwise return false.\n Note: A permutation of integers represents an arrangement of these numbers.\n \n Example 1:\n \n >>> isGood(nums = [2, 1, 3])\n >>> false\n Explanation: Since the maximum element of the array is 3, the only candidate n for which this array could be a permutation of base[n], is n = 3. However, base[3] has four elements but array nums has three. Therefore, it can not be a permutation of base[3] = [1, 2, 3, 3]. So the answer is false.\n \n Example 2:\n \n >>> isGood(nums = [1, 3, 3, 2])\n >>> true\n Explanation: Since the maximum element of the array is 3, the only candidate n for which this array could be a permutation of base[n], is n = 3. It can be seen that nums is a permutation of base[3] = [1, 2, 3, 3] (by swapping the second and fourth elements in nums, we reach base[3]). Therefore, the answer is true.\n Example 3:\n \n >>> isGood(nums = [1, 1])\n >>> true\n Explanation: Since the maximum element of the array is 1, the only candidate n for which this array could be a permutation of base[n], is n = 1. It can be seen that nums is a permutation of base[1] = [1, 1]. Therefore, the answer is true.\n Example 4:\n \n >>> isGood(nums = [3, 4, 4, 1, 2, 1])\n >>> false\n Explanation: Since the maximum element of the array is 4, the only candidate n for which this array could be a permutation of base[n], is n = 4. However, base[4] has five elements but array nums has six. Therefore, it can not be a permutation of base[4] = [1, 2, 3, 4, 4]. So the answer is false.\n \"\"\"\n"}
{"task_id": "sort-vowels-in-a-string", "prompt": "def sortVowels(s: str) -> str:\n \"\"\"\n Given a 0-indexed string s, permute s to get a new string t such that:\n \n All consonants remain in their original places. More formally, if there is an index i with 0 <= i < s.length such that s[i] is a consonant, then t[i] = s[i].\n The vowels must be sorted in the nondecreasing order of their ASCII values. More formally, for pairs of indices i, j with 0 <= i < j < s.length such that s[i] and s[j] are vowels, then t[i] must not have a higher ASCII value than t[j].\n \n Return the resulting string.\n The vowels are 'a', 'e', 'i', 'o', and 'u', and they can appear in lowercase or uppercase. Consonants comprise all letters that are not vowels.\n \n Example 1:\n \n >>> sortVowels(s = \"lEetcOde\")\n >>> \"lEOtcede\"\n Explanation: 'E', 'O', and 'e' are the vowels in s; 'l', 't', 'c', and 'd' are all consonants. The vowels are sorted according to their ASCII values, and the consonants remain in the same places.\n \n Example 2:\n \n >>> sortVowels(s = \"lYmpH\")\n >>> \"lYmpH\"\n Explanation: There are no vowels in s (all characters in s are consonants), so we return \"lYmpH\".\n \"\"\"\n"}
{"task_id": "visit-array-positions-to-maximize-score", "prompt": "def maxScore(nums: List[int], x: int) -> int:\n \"\"\"\n You are given a 0-indexed integer array nums and a positive integer x.\n You are initially at position 0 in the array and you can visit other positions according to the following rules:\n \n If you are currently in position i, then you can move to any position j such that i < j.\n For each position i that you visit, you get a score of nums[i].\n If you move from a position i to a position j and the parities of nums[i] and nums[j] differ, then you lose a score of x.\n \n Return the maximum total score you can get.\n Note that initially you have nums[0] points.\n \n Example 1:\n \n >>> maxScore(nums = [2,3,6,1,9,2], x = 5)\n >>> 13\n Explanation: We can visit the following positions in the array: 0 -> 2 -> 3 -> 4.\n The corresponding values are 2, 6, 1 and 9. Since the integers 6 and 1 have different parities, the move 2 -> 3 will make you lose a score of x = 5.\n The total score will be: 2 + 6 + 1 + 9 - 5 = 13.\n \n Example 2:\n \n >>> maxScore(nums = [2,4,6,8], x = 3)\n >>> 20\n Explanation: All the integers in the array have the same parities, so we can visit all of them without losing any score.\n The total score is: 2 + 4 + 6 + 8 = 20.\n \"\"\"\n"}
{"task_id": "ways-to-express-an-integer-as-sum-of-powers", "prompt": "def numberOfWays(n: int, x: int) -> int:\n \"\"\"\n Given two positive integers n and x.\n Return the number of ways n can be expressed as the sum of the xth power of unique positive integers, in other words, the number of sets of unique integers [n1, n2, ..., nk] where n = n1x + n2x + ... + nkx.\n Since the result can be very large, return it modulo 109 + 7.\n For example, if n = 160 and x = 3, one way to express n is n = 23 + 33 + 53.\n \n Example 1:\n \n >>> numberOfWays(n = 10, x = 2)\n >>> 1\n Explanation: We can express n as the following: n = 32 + 12 = 10.\n It can be shown that it is the only way to express 10 as the sum of the 2nd power of unique integers.\n \n Example 2:\n \n >>> numberOfWays(n = 4, x = 1)\n >>> 2\n Explanation: We can express n in the following ways:\n - n = 41 = 4.\n - n = 31 + 11 = 4.\n \"\"\"\n"}
{"task_id": "split-strings-by-separator", "prompt": "def splitWordsBySeparator(words: List[str], separator: str) -> List[str]:\n \"\"\"\n Given an array of strings words and a character separator, split each string in words by separator.\n Return an array of strings containing the new strings formed after the splits, excluding empty strings.\n Notes\n \n separator is used to determine where the split should occur, but it is not included as part of the resulting strings.\n A split may result in more than two strings.\n The resulting strings must maintain the same order as they were initially given.\n \n \n Example 1:\n \n >>> splitWordsBySeparator(words = [\"one.two.three\",\"four.five\",\"six\"], separator = \".\")\n >>> [\"one\",\"two\",\"three\",\"four\",\"five\",\"six\"]\n Explanation: In this example we split as follows:\n \n \"one.two.three\" splits into \"one\", \"two\", \"three\"\n \"four.five\" splits into \"four\", \"five\"\n \"six\" splits into \"six\"\n \n Hence, the resulting array is [\"one\",\"two\",\"three\",\"four\",\"five\",\"six\"].\n Example 2:\n \n >>> splitWordsBySeparator(words = [\"$easy$\",\"$problem$\"], separator = \"$\")\n >>> [\"easy\",\"problem\"]\n Explanation: In this example we split as follows:\n \n \"$easy$\" splits into \"easy\" (excluding empty strings)\n \"$problem$\" splits into \"problem\" (excluding empty strings)\n \n Hence, the resulting array is [\"easy\",\"problem\"].\n \n Example 3:\n \n >>> splitWordsBySeparator(words = [\"|||\"], separator = \"|\")\n >>> []\n Explanation: In this example the resulting split of \"|||\" will contain only empty strings, so we return an empty array [].\n \"\"\"\n"}
{"task_id": "largest-element-in-an-array-after-merge-operations", "prompt": "def maxArrayValue(nums: List[int]) -> int:\n \"\"\"\n You are given a 0-indexed array nums consisting of positive integers.\n You can do the following operation on the array any number of times:\n \n Choose an integer i such that 0 <= i < nums.length - 1 and nums[i] <= nums[i + 1]. Replace the element nums[i + 1] with nums[i] + nums[i + 1] and delete the element nums[i] from the array.\n \n Return the value of the largest element that you can possibly obtain in the final array.\n \n Example 1:\n \n >>> maxArrayValue(nums = [2,3,7,9,3])\n >>> 21\n Explanation: We can apply the following operations on the array:\n - Choose i = 0. The resulting array will be nums = [5,7,9,3].\n - Choose i = 1. The resulting array will be nums = [5,16,3].\n - Choose i = 0. The resulting array will be nums = [21,3].\n The largest element in the final array is 21. It can be shown that we cannot obtain a larger element.\n \n Example 2:\n \n >>> maxArrayValue(nums = [5,3,3])\n >>> 11\n Explanation: We can do the following operations on the array:\n - Choose i = 1. The resulting array will be nums = [5,6].\n - Choose i = 0. The resulting array will be nums = [11].\n There is only one element in the final array, which is 11.\n \"\"\"\n"}
{"task_id": "maximum-number-of-groups-with-increasing-length", "prompt": "def maxIncreasingGroups(usageLimits: List[int]) -> int:\n \"\"\"\n You are given a 0-indexed array usageLimits of length n.\n Your task is to create groups using numbers from 0 to n - 1, ensuring that each number, i, is used no more than usageLimits[i] times in total across all groups. You must also satisfy the following conditions:\n \n Each group must consist of distinct numbers, meaning that no duplicate numbers are allowed within a single group.\n Each group (except the first one) must have a length strictly greater than the previous group.\n \n Return an integer denoting the maximum number of groups you can create while satisfying these conditions.\n \n Example 1:\n \n >>> maxIncreasingGroups(usageLimits = [1,2,5])\n >>> 3\n Explanation: In this example, we can use 0 at most once, 1 at most twice, and 2 at most five times.\n One way of creating the maximum number of groups while satisfying the conditions is:\n Group 1 contains the number [2].\n Group 2 contains the numbers [1,2].\n Group 3 contains the numbers [0,1,2].\n It can be shown that the maximum number of groups is 3.\n So, the output is 3.\n Example 2:\n \n >>> maxIncreasingGroups(usageLimits = [2,1,2])\n >>> 2\n Explanation: In this example, we can use 0 at most twice, 1 at most once, and 2 at most twice.\n One way of creating the maximum number of groups while satisfying the conditions is:\n Group 1 contains the number [0].\n Group 2 contains the numbers [1,2].\n It can be shown that the maximum number of groups is 2.\n So, the output is 2.\n \n Example 3:\n \n >>> maxIncreasingGroups(usageLimits = [1,1])\n >>> 1\n Explanation: In this example, we can use both 0 and 1 at most once.\n One way of creating the maximum number of groups while satisfying the conditions is:\n Group 1 contains the number [0].\n It can be shown that the maximum number of groups is 1.\n So, the output is 1.\n \"\"\"\n"}
{"task_id": "count-paths-that-can-form-a-palindrome-in-a-tree", "prompt": "def countPalindromePaths(parent: List[int], s: str) -> int:\n \"\"\"\n You are given a tree (i.e. a connected, undirected graph that has no cycles) rooted at node 0 consisting of n nodes numbered from 0 to n - 1. The tree is represented by a 0-indexed array parent of size n, where parent[i] is the parent of node i. Since node 0 is the root, parent[0] == -1.\n You are also given a string s of length n, where s[i] is the character assigned to the edge between i and parent[i]. s[0] can be ignored.\n Return the number of pairs of nodes (u, v) such that u < v and the characters assigned to edges on the path from u to v can be rearranged to form a palindrome.\n A string is a palindrome when it reads the same backwards as forwards.\n \n Example 1:\n \n \n >>> countPalindromePaths(parent = [-1,0,0,1,1,2], s = \"acaabc\")\n >>> 8\n Explanation: The valid pairs are:\n - All the pairs (0,1), (0,2), (1,3), (1,4) and (2,5) result in one character which is always a palindrome.\n - The pair (2,3) result in the string \"aca\" which is a palindrome.\n - The pair (1,5) result in the string \"cac\" which is a palindrome.\n - The pair (3,5) result in the string \"acac\" which can be rearranged into the palindrome \"acca\".\n \n Example 2:\n \n >>> countPalindromePaths(parent = [-1,0,0,0,0], s = \"aaaaa\")\n >>> 10\n Explanation: Any pair of nodes (u,v) where u < v is valid.\n \"\"\"\n"}
{"task_id": "count-nodes-that-are-great-enough", "prompt": "# class TreeNode:\n# def __init__(val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def countGreatEnoughNodes(root: Optional[TreeNode], k: int) -> int:\n \"\"\"\n You are given a root to a binary tree and an integer k. A node of this tree is called great enough if the followings hold:\n \n Its subtree has at least k nodes.\n Its value is greater than the value of at least k nodes in its subtree.\n \n Return the number of nodes in this tree that are great enough.\n The node u is in the subtree of the node\u00a0v, if u == v\u00a0or\u00a0v\u00a0is an\u00a0ancestor of u.\n \n Example 1:\n \n >>> __init__(root = [7,6,5,4,3,2,1], k = 2)\n >>> 3\n Explanation: Number the nodes from 1 to 7.\n The values in the subtree of node 1: {1,2,3,4,5,6,7}. Since node.val == 7, there are 6 nodes having a smaller value than its value. So it's great enough.\n The values in the subtree of node 2: {3,4,6}. Since node.val == 6, there are 2 nodes having a smaller value than its value. So it's great enough.\n The values in the subtree of node 3: {1,2,5}. Since node.val == 5, there are 2 nodes having a smaller value than its value. So it's great enough.\n It can be shown that other nodes are not great enough.\n See the picture below for a better understanding.\n \n Example 2:\n \n >>> __init__(root = [1,2,3], k = 1)\n >>> 0\n Explanation: Number the nodes from 1 to 3.\n The values in the subtree of node 1: {1,2,3}. Since node.val == 1, there are no nodes having a smaller value than its value. So it's not great enough.\n The values in the subtree of node 2: {2}. Since node.val == 2, there are no nodes having a smaller value than its value. So it's not great enough.\n The values in the subtree of node 3: {3}. Since node.val == 3, there are no nodes having a smaller value than its value. So it's not great enough.\n See the picture below for a better understanding.\n \n Example 3:\n \n >>> __init__(root = [3,2,2], k = 2)\n >>> 1\n Explanation: Number the nodes from 1 to 3.\n The values in the subtree of node 1: {2,2,3}. Since node.val == 3, there are 2 nodes having a smaller value than its value. So it's great enough.\n The values in the subtree of node 2: {2}. Since node.val == 2, there are no nodes having a smaller value than its value. So it's not great enough.\n The values in the subtree of node 3: {2}. Since node.val == 2, there are no nodes having a smaller value than its value. So it's not great enough.\n See the picture below for a better understanding.\n \"\"\"\n"}
{"task_id": "number-of-employees-who-met-the-target", "prompt": "def numberOfEmployeesWhoMetTarget(hours: List[int], target: int) -> int:\n \"\"\"\n There are n employees in a company, numbered from 0 to n - 1. Each employee i has worked for hours[i] hours in the company.\n The company requires each employee to work for at least target hours.\n You are given a 0-indexed array of non-negative integers hours of length n and a non-negative integer target.\n Return the integer denoting the number of employees who worked at least target hours.\n \n Example 1:\n \n >>> numberOfEmployeesWhoMetTarget(hours = [0,1,2,3,4], target = 2)\n >>> 3\n Explanation: The company wants each employee to work for at least 2 hours.\n - Employee 0 worked for 0 hours and didn't meet the target.\n - Employee 1 worked for 1 hours and didn't meet the target.\n - Employee 2 worked for 2 hours and met the target.\n - Employee 3 worked for 3 hours and met the target.\n - Employee 4 worked for 4 hours and met the target.\n There are 3 employees who met the target.\n \n Example 2:\n \n >>> numberOfEmployeesWhoMetTarget(hours = [5,1,4,2,2], target = 6)\n >>> 0\n Explanation: The company wants each employee to work for at least 6 hours.\n There are 0 employees who met the target.\n \"\"\"\n"}
{"task_id": "count-complete-subarrays-in-an-array", "prompt": "def countCompleteSubarrays(nums: List[int]) -> int:\n \"\"\"\n You are given an array nums consisting of positive integers.\n We call a subarray of an array complete if the following condition is satisfied:\n \n The number of distinct elements in the subarray is equal to the number of distinct elements in the whole array.\n \n Return the number of complete subarrays.\n A subarray is a contiguous non-empty part of an array.\n \n Example 1:\n \n >>> countCompleteSubarrays(nums = [1,3,1,2,2])\n >>> 4\n Explanation: The complete subarrays are the following: [1,3,1,2], [1,3,1,2,2], [3,1,2] and [3,1,2,2].\n \n Example 2:\n \n >>> countCompleteSubarrays(nums = [5,5,5,5])\n >>> 10\n Explanation: The array consists only of the integer 5, so any subarray is complete. The number of subarrays that we can choose is 10.\n \"\"\"\n"}
{"task_id": "shortest-string-that-contains-three-strings", "prompt": "def minimumString(a: str, b: str, c: str) -> str:\n \"\"\"\n Given three strings a, b, and c, your task is to find a string that has the minimum length and contains all three strings as substrings.\n If there are multiple such strings, return the lexicographically smallest one.\n Return a string denoting the answer to the problem.\n Notes\n \n A string a is lexicographically smaller than a string b (of the same length) if in the first position where a and b differ, string a has a letter that appears earlier in the alphabet than the corresponding letter in b.\n A substring is a contiguous sequence of characters within a string.\n \n \n Example 1:\n \n >>> minimumString(a = \"abc\", b = \"bca\", c = \"aaa\")\n >>> \"aaabca\"\n Explanation: We show that \"aaabca\" contains all the given strings: a = ans[2...4], b = ans[3..5], c = ans[0..2]. It can be shown that the length of the resulting string would be at least 6 and \"aaabca\" is the lexicographically smallest one.\n Example 2:\n \n >>> minimumString(a = \"ab\", b = \"ba\", c = \"aba\")\n >>> \"aba\"\n Explanation: We show that the string \"aba\" contains all the given strings: a = ans[0..1], b = ans[1..2], c = ans[0..2]. Since the length of c is 3, the length of the resulting string would be at least 3. It can be shown that \"aba\" is the lexicographically smallest one.\n \"\"\"\n"}
{"task_id": "count-stepping-numbers-in-range", "prompt": "def countSteppingNumbers(low: str, high: str) -> int:\n \"\"\"\n Given two positive integers low and high represented as strings, find the count of stepping numbers in the inclusive range [low, high].\n A stepping number is an integer such that all of its adjacent digits have an absolute difference of exactly 1.\n Return an integer denoting the count of stepping numbers in the inclusive range [low, high].\n Since the answer may be very large, return it modulo 109 + 7.\n Note: A stepping number should not have a leading zero.\n \n Example 1:\n \n >>> countSteppingNumbers(low = \"1\", high = \"11\")\n >>> 10\n Explanation: The stepping numbers in the range [1,11] are 1, 2, 3, 4, 5, 6, 7, 8, 9 and 10. There are a total of 10 stepping numbers in the range. Hence, the output is 10.\n Example 2:\n \n >>> countSteppingNumbers(low = \"90\", high = \"101\")\n >>> 2\n Explanation: The stepping numbers in the range [90,101] are 98 and 101. There are a total of 2 stepping numbers in the range. Hence, the output is 2.\n \"\"\"\n"}
{"task_id": "find-the-k-th-lucky-number", "prompt": "def kthLuckyNumber(k: int) -> str:\n \"\"\"\n We know that 4 and 7 are lucky digits. Also, a number is called lucky\u00a0if it contains only lucky digits.\n You are given an integer k, return the kth\u00a0lucky number represented as a string.\n \n Example 1:\n \n >>> kthLuckyNumber(k = 4)\n >>> \"47\"\n Explanation: The first lucky number is 4, the second one is 7, the third one is 44 and the fourth one is 47.\n \n Example 2:\n \n >>> kthLuckyNumber(k = 10)\n >>> \"477\"\n Explanation: Here are lucky numbers sorted in increasing order:\n 4, 7, 44, 47, 74, 77, 444, 447, 474, 477. So the 10th lucky number is 477.\n Example 3:\n \n >>> kthLuckyNumber(k = 1000)\n >>> \"777747447\"\n Explanation: It can be shown that the 1000th lucky number is 777747447.\n \"\"\"\n"}
{"task_id": "account-balance-after-rounded-purchase", "prompt": "def accountBalanceAfterPurchase(purchaseAmount: int) -> int:\n \"\"\"\n Initially, you have a bank account balance of 100 dollars.\n You are given an integer purchaseAmount representing the amount you will spend on a purchase in dollars, in other words, its price.\n When making the purchase, first the purchaseAmount is rounded to the nearest multiple of 10. Let us call this value roundedAmount. Then, roundedAmount dollars are removed from your bank account.\n Return an integer denoting your final bank account balance after this purchase.\n Notes:\n \n 0 is considered to be a multiple of 10 in this problem.\n When rounding, 5 is rounded upward (5 is rounded to 10, 15 is rounded to 20, 25 to 30, and so on).\n \n \n Example 1:\n \n >>> accountBalanceAfterPurchase(purchaseAmount = 9)\n >>> 90\n Explanation:\n The nearest multiple of 10 to 9 is 10. So your account balance becomes 100 - 10 = 90.\n \n Example 2:\n \n >>> accountBalanceAfterPurchase(purchaseAmount = 15)\n >>> 80\n Explanation:\n The nearest multiple of 10 to 15 is 20. So your account balance becomes 100 - 20 = 80.\n \n Example 3:\n \n >>> accountBalanceAfterPurchase(purchaseAmount = 10)\n >>> 90\n Explanation:\n 10 is a multiple of 10 itself. So your account balance becomes 100 - 10 = 90.\n \"\"\"\n"}
{"task_id": "insert-greatest-common-divisors-in-linked-list", "prompt": "# class ListNode:\n# def __init__(val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution:\n def insertGreatestCommonDivisors(head: Optional[ListNode]) -> Optional[ListNode]:\n \"\"\"\n Given the head of a linked list head, in which each node contains an integer value.\n Between every pair of adjacent nodes, insert a new node with a value equal to the greatest common divisor of them.\n Return the linked list after insertion.\n The greatest common divisor of two numbers is the largest positive integer that evenly divides both numbers.\n \n Example 1:\n \n \n >>> __init__(head = [18,6,10,3])\n >>> [18,6,6,2,10,1,3]\n Explanation: The 1st diagram denotes the initial linked list and the 2nd diagram denotes the linked list after inserting the new nodes (nodes in blue are the inserted nodes).\n - We insert the greatest common divisor of 18 and 6 = 6 between the 1st and the 2nd nodes.\n - We insert the greatest common divisor of 6 and 10 = 2 between the 2nd and the 3rd nodes.\n - We insert the greatest common divisor of 10 and 3 = 1 between the 3rd and the 4th nodes.\n There are no more adjacent nodes, so we return the linked list.\n \n Example 2:\n \n \n >>> __init__(head = [7])\n >>> [7]\n Explanation: The 1st diagram denotes the initial linked list and the 2nd diagram denotes the linked list after inserting the new nodes.\n There are no pairs of adjacent nodes, so we return the initial linked list.\n \"\"\"\n"}
{"task_id": "minimum-seconds-to-equalize-a-circular-array", "prompt": "def minimumSeconds(nums: List[int]) -> int:\n \"\"\"\n You are given a 0-indexed array nums containing n integers.\n At each second, you perform the following operation on the array:\n \n For every index i in the range [0, n - 1], replace nums[i] with either nums[i], nums[(i - 1 + n) % n], or nums[(i + 1) % n].\n \n Note that all the elements get replaced simultaneously.\n Return the minimum number of seconds needed to make all elements in the array nums equal.\n \n Example 1:\n \n >>> minimumSeconds(nums = [1,2,1,2])\n >>> 1\n Explanation: We can equalize the array in 1 second in the following way:\n - At 1st second, replace values at each index with [nums[3],nums[1],nums[3],nums[3]]. After replacement, nums = [2,2,2,2].\n It can be proven that 1 second is the minimum amount of seconds needed for equalizing the array.\n \n Example 2:\n \n >>> minimumSeconds(nums = [2,1,3,3,2])\n >>> 2\n Explanation: We can equalize the array in 2 seconds in the following way:\n - At 1st second, replace values at each index with [nums[0],nums[2],nums[2],nums[2],nums[3]]. After replacement, nums = [2,3,3,3,3].\n - At 2nd second, replace values at each index with [nums[1],nums[1],nums[2],nums[3],nums[4]]. After replacement, nums = [3,3,3,3,3].\n It can be proven that 2 seconds is the minimum amount of seconds needed for equalizing the array.\n \n Example 3:\n \n >>> minimumSeconds(nums = [5,5,5,5])\n >>> 0\n Explanation: We don't need to perform any operations as all elements in the initial array are the same.\n \"\"\"\n"}
{"task_id": "minimum-time-to-make-array-sum-at-most-x", "prompt": "def minimumTime(nums1: List[int], nums2: List[int], x: int) -> int:\n \"\"\"\n You are given two 0-indexed integer arrays nums1 and nums2 of equal length. Every second, for all indices 0 <= i < nums1.length, value of nums1[i] is incremented by nums2[i]. After this is done, you can do the following operation:\n \n Choose an index 0 <= i < nums1.length and make nums1[i] = 0.\n \n You are also given an integer x.\n Return the minimum time in which you can make the sum of all elements of nums1 to be less than or equal to x, or -1 if this is not possible.\n \n Example 1:\n \n >>> minimumTime(nums1 = [1,2,3], nums2 = [1,2,3], x = 4)\n >>> 3\n Explanation:\n For the 1st second, we apply the operation on i = 0. Therefore nums1 = [0,2+2,3+3] = [0,4,6].\n For the 2nd second, we apply the operation on i = 1. Therefore nums1 = [0+1,0,6+3] = [1,0,9].\n For the 3rd second, we apply the operation on i = 2. Therefore nums1 = [1+1,0+2,0] = [2,2,0].\n Now sum of nums1 = 4. It can be shown that these operations are optimal, so we return 3.\n \n \n Example 2:\n \n >>> minimumTime(nums1 = [1,2,3], nums2 = [3,3,3], x = 4)\n >>> -1\n Explanation: It can be shown that the sum of nums1 will always be greater than x, no matter which operations are performed.\n \"\"\"\n"}
{"task_id": "faulty-keyboard", "prompt": "def finalString(s: str) -> str:\n \"\"\"\n Your laptop keyboard is faulty, and whenever you type a character 'i' on it, it reverses the string that you have written. Typing other characters works as expected.\n You are given a 0-indexed string s, and you type each character of s using your faulty keyboard.\n Return the final string that will be present on your laptop screen.\n \n Example 1:\n \n >>> finalString(s = \"string\")\n >>> \"rtsng\"\n Explanation:\n After typing first character, the text on the screen is \"s\".\n After the second character, the text is \"st\".\n After the third character, the text is \"str\".\n Since the fourth character is an 'i', the text gets reversed and becomes \"rts\".\n After the fifth character, the text is \"rtsn\".\n After the sixth character, the text is \"rtsng\".\n Therefore, we return \"rtsng\".\n \n Example 2:\n \n >>> finalString(s = \"poiinter\")\n >>> \"ponter\"\n Explanation:\n After the first character, the text on the screen is \"p\".\n After the second character, the text is \"po\".\n Since the third character you type is an 'i', the text gets reversed and becomes \"op\".\n Since the fourth character you type is an 'i', the text gets reversed and becomes \"po\".\n After the fifth character, the text is \"pon\".\n After the sixth character, the text is \"pont\".\n After the seventh character, the text is \"ponte\".\n After the eighth character, the text is \"ponter\".\n Therefore, we return \"ponter\".\n \"\"\"\n"}
{"task_id": "check-if-it-is-possible-to-split-array", "prompt": "def canSplitArray(nums: List[int], m: int) -> bool:\n \"\"\"\n You are given an array nums of length n and an integer m. You need to determine if it is possible to split the array into n arrays of size 1 by performing a series of steps.\n An array is called good if:\n \n The length of the array is one, or\n The sum of the elements of the array is greater than or equal to m.\n \n In each step, you can select an existing array (which may be the result of previous steps) with a length of at least two and split it into two arrays, if both resulting arrays are good.\n Return true if you can split the given array into n arrays, otherwise return false.\n \n Example 1:\n \n >>> canSplitArray(nums = [2, 2, 1], m = 4)\n >>> true\n Explanation:\n \n Split [2, 2, 1] to [2, 2] and [1]. The array [1] has a length of one, and the array [2, 2] has the sum of its elements equal to 4 >= m, so both are good arrays.\n Split [2, 2] to [2] and [2]. both arrays have the length of one, so both are good arrays.\n \n \n Example 2:\n \n >>> canSplitArray(nums = [2, 1, 3], m = 5)\n >>> false\n Explanation:\n The first move has to be either of the following:\n \n Split [2, 1, 3] to [2, 1] and [3]. The array [2, 1] has neither length of one nor sum of elements greater than or equal to m.\n Split [2, 1, 3] to [2] and [1, 3]. The array [1, 3] has neither length of one nor sum of elements greater than or equal to m.\n \n So as both moves are invalid (they do not divide the array into two good arrays), we are unable to split nums into n arrays of size 1.\n \n Example 3:\n \n >>> canSplitArray(nums = [2, 3, 3, 2, 3], m = 6)\n >>> true\n Explanation:\n \n Split [2, 3, 3, 2, 3] to [2] and [3, 3, 2, 3].\n Split [3, 3, 2, 3] to [3, 3, 2] and [3].\n Split [3, 3, 2] to [3, 3] and [2].\n Split [3, 3] to [3] and [3].\n \"\"\"\n"}
{"task_id": "find-the-safest-path-in-a-grid", "prompt": "def maximumSafenessFactor(grid: List[List[int]]) -> int:\n \"\"\"\n You are given a 0-indexed 2D matrix grid of size n x n, where (r, c) represents:\n \n A cell containing a thief if grid[r][c] = 1\n An empty cell if grid[r][c] = 0\n \n You are initially positioned at cell (0, 0). In one move, you can move to any adjacent cell in the grid, including cells containing thieves.\n The safeness factor of a path on the grid is defined as the minimum manhattan distance from any cell in the path to any thief in the grid.\n Return the maximum safeness factor of all paths leading to cell (n - 1, n - 1).\n An adjacent cell of cell (r, c), is one of the cells (r, c + 1), (r, c - 1), (r + 1, c) and (r - 1, c) if it exists.\n The Manhattan distance between two cells (a, b) and (x, y) is equal to |a - x| + |b - y|, where |val| denotes the absolute value of val.\n \n Example 1:\n \n \n >>> maximumSafenessFactor(grid = [[1,0,0],[0,0,0],[0,0,1]])\n >>> 0\n Explanation: All paths from (0, 0) to (n - 1, n - 1) go through the thieves in cells (0, 0) and (n - 1, n - 1).\n \n Example 2:\n \n \n >>> maximumSafenessFactor(grid = [[0,0,1],[0,0,0],[0,0,0]])\n >>> 2\n Explanation: The path depicted in the picture above has a safeness factor of 2 since:\n - The closest cell of the path to the thief at cell (0, 2) is cell (0, 0). The distance between them is | 0 - 0 | + | 0 - 2 | = 2.\n It can be shown that there are no other paths with a higher safeness factor.\n \n Example 3:\n \n \n >>> maximumSafenessFactor(grid = [[0,0,0,1],[0,0,0,0],[0,0,0,0],[1,0,0,0]])\n >>> 2\n Explanation: The path depicted in the picture above has a safeness factor of 2 since:\n - The closest cell of the path to the thief at cell (0, 3) is cell (1, 2). The distance between them is | 0 - 1 | + | 3 - 2 | = 2.\n - The closest cell of the path to the thief at cell (3, 0) is cell (3, 2). The distance between them is | 3 - 3 | + | 0 - 2 | = 2.\n It can be shown that there are no other paths with a higher safeness factor.\n \"\"\"\n"}
{"task_id": "maximum-elegance-of-a-k-length-subsequence", "prompt": "def findMaximumElegance(items: List[List[int]], k: int) -> int:\n \"\"\"\n You are given a 0-indexed 2D integer array items of length n and an integer k.\n items[i] = [profiti, categoryi], where profiti and categoryi denote the profit and category of the ith item respectively.\n Let's define the elegance of a subsequence of items as total_profit + distinct_categories2, where total_profit is the sum of all profits in the subsequence, and distinct_categories is the number of distinct categories from all the categories in the selected subsequence.\n Your task is to find the maximum elegance from all subsequences of size k in items.\n Return an integer denoting the maximum elegance of a subsequence of items with size exactly k.\n Note: A subsequence of an array is a new array generated from the original array by deleting some elements (possibly none) without changing the remaining elements' relative order.\n \n Example 1:\n \n >>> findMaximumElegance(items = [[3,2],[5,1],[10,1]], k = 2)\n >>> 17\n Explanation: In this example, we have to select a subsequence of size 2.\n We can select items[0] = [3,2] and items[2] = [10,1].\n The total profit in this subsequence is 3 + 10 = 13, and the subsequence contains 2 distinct categories [2,1].\n Hence, the elegance is 13 + 22 = 17, and we can show that it is the maximum achievable elegance.\n \n Example 2:\n \n >>> findMaximumElegance(items = [[3,1],[3,1],[2,2],[5,3]], k = 3)\n >>> 19\n Explanation: In this example, we have to select a subsequence of size 3.\n We can select items[0] = [3,1], items[2] = [2,2], and items[3] = [5,3].\n The total profit in this subsequence is 3 + 2 + 5 = 10, and the subsequence contains 3 distinct categories [1,2,3].\n Hence, the elegance is 10 + 32 = 19, and we can show that it is the maximum achievable elegance.\n Example 3:\n \n >>> findMaximumElegance(items = [[1,1],[2,1],[3,1]], k = 3)\n >>> 7\n Explanation: In this example, we have to select a subsequence of size 3.\n We should select all the items.\n The total profit will be 1 + 2 + 3 = 6, and the subsequence contains 1 distinct category [1].\n Hence, the maximum elegance is 6 + 12 = 7.\n \"\"\"\n"}
{"task_id": "minimum-time-takes-to-reach-destination-without-drowning", "prompt": "def minimumSeconds(land: List[List[str]]) -> int:\n \"\"\"\n You are given an n * m 0-indexed grid of string land. Right now, you are standing at the cell that contains \"S\", and you want to get to the cell containing \"D\". There are three other types of cells in this land:\n \n \".\": These cells are empty.\n \"X\": These cells are stone.\n \"*\": These cells are flooded.\n \n At each second, you can move to a cell that shares a side with your current cell (if it exists). Also, at each second, every empty cell that shares a side with a flooded cell becomes flooded as well.\n There are two problems ahead of your journey:\n \n You can't step on stone cells.\n You can't step on flooded cells since you will drown (also, you can't step on a cell that will be flooded at the same time as you step on it).\n \n Return the minimum time it takes you to reach the destination in seconds, or -1 if it is impossible.\n Note that the destination will never be flooded.\n \n Example 1:\n \n >>> minimumSeconds(land = [[\"D\",\".\",\"*\"],[\".\",\".\",\".\"],[\".\",\"S\",\".\"]])\n >>> 3\n Explanation: The picture below shows the simulation of the land second by second. The blue cells are flooded, and the gray cells are stone.\n Picture (0) shows the initial state and picture (3) shows the final state when we reach destination. As you see, it takes us 3 second to reach destination and the answer would be 3.\n It can be shown that 3 is the minimum time needed to reach from S to D.\n \n \n Example 2:\n \n >>> minimumSeconds(land = [[\"D\",\"X\",\"*\"],[\".\",\".\",\".\"],[\".\",\".\",\"S\"]])\n >>> -1\n Explanation: The picture below shows the simulation of the land second by second. The blue cells are flooded, and the gray cells are stone.\n Picture (0) shows the initial state. As you see, no matter which paths we choose, we will drown at the 3rd\u00a0second. Also the minimum path takes us 4 seconds to reach from S to D.\n So the answer would be -1.\n \n \n Example 3:\n \n >>> minimumSeconds(land = [[\"D\",\".\",\".\",\".\",\"*\",\".\"],[\".\",\"X\",\".\",\"X\",\".\",\".\"],[\".\",\".\",\".\",\".\",\"S\",\".\"]])\n >>> 6\n Explanation: It can be shown that we can reach destination in 6 seconds. Also it can be shown that 6 is the minimum seconds one need to reach from S to D.\n \"\"\"\n"}
{"task_id": "max-pair-sum-in-an-array", "prompt": "def maxSum(nums: List[int]) -> int:\n \"\"\"\n You are given an integer array nums. You have to find the maximum sum of a pair of numbers from nums such that the largest digit in both numbers is equal.\n For example, 2373 is made up of three distinct digits: 2, 3, and 7, where 7 is the largest among them.\n Return the maximum sum or -1 if no such pair exists.\n \n Example 1:\n \n >>> maxSum(nums = [112,131,411])\n >>> -1\n Explanation:\n Each numbers largest digit in order is [2,3,4].\n \n Example 2:\n \n >>> maxSum(nums = [2536,1613,3366,162])\n >>> 5902\n Explanation:\n All the numbers have 6 as their largest digit, so the answer is 2536 + 3366 = 5902.\n \n Example 3:\n \n >>> maxSum(nums = [51,71,17,24,42])\n >>> 88\n Explanation:\n Each number's largest digit in order is [5,7,7,4,4].\n So we have only two possible pairs, 71 + 17 = 88 and 24 + 42 = 66.\n \"\"\"\n"}
{"task_id": "double-a-number-represented-as-a-linked-list", "prompt": "# class ListNode:\n# def __init__(val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution:\n def doubleIt(head: Optional[ListNode]) -> Optional[ListNode]:\n \"\"\"\n You are given the head of a non-empty linked list representing a non-negative integer without leading zeroes.\n Return the head of the linked list after doubling it.\n \n Example 1:\n \n \n >>> __init__(head = [1,8,9])\n >>> [3,7,8]\n Explanation: The figure above corresponds to the given linked list which represents the number 189. Hence, the returned linked list represents the number 189 * 2 = 378.\n \n Example 2:\n \n \n >>> __init__(head = [9,9,9])\n >>> [1,9,9,8]\n Explanation: The figure above corresponds to the given linked list which represents the number 999. Hence, the returned linked list reprersents the number 999 * 2 = 1998.\n \"\"\"\n"}
{"task_id": "minimum-absolute-difference-between-elements-with-constraint", "prompt": "def minAbsoluteDifference(nums: List[int], x: int) -> int:\n \"\"\"\n You are given a 0-indexed integer array nums and an integer x.\n Find the minimum absolute difference between two elements in the array that are at least x indices apart.\n In other words, find two indices i and j such that abs(i - j) >= x and abs(nums[i] - nums[j]) is minimized.\n Return an integer denoting the minimum absolute difference between two elements that are at least x indices apart.\n \n Example 1:\n \n >>> minAbsoluteDifference(nums = [4,3,2,4], x = 2)\n >>> 0\n Explanation: We can select nums[0] = 4 and nums[3] = 4.\n They are at least 2 indices apart, and their absolute difference is the minimum, 0.\n It can be shown that 0 is the optimal answer.\n \n Example 2:\n \n >>> minAbsoluteDifference(nums = [5,3,2,10,15], x = 1)\n >>> 1\n Explanation: We can select nums[1] = 3 and nums[2] = 2.\n They are at least 1 index apart, and their absolute difference is the minimum, 1.\n It can be shown that 1 is the optimal answer.\n \n Example 3:\n \n >>> minAbsoluteDifference(nums = [1,2,3,4], x = 3)\n >>> 3\n Explanation: We can select nums[0] = 1 and nums[3] = 4.\n They are at least 3 indices apart, and their absolute difference is the minimum, 3.\n It can be shown that 3 is the optimal answer.\n \"\"\"\n"}
{"task_id": "minimum-relative-loss-after-buying-chocolates", "prompt": "def minimumRelativeLosses(prices: List[int], queries: List[List[int]]) -> List[int]:\n \"\"\"\n You are given an integer array prices, which shows the chocolate prices and a 2D integer array queries, where queries[i] = [ki, mi].\n Alice and Bob went to buy some chocolates, and Alice suggested a way to pay for them, and Bob agreed.\n The terms for each query are as follows:\n \n If the price of a chocolate is less than or equal to ki, Bob pays for it.\n Otherwise, Bob pays ki of it, and Alice pays the rest.\n \n Bob wants to select exactly mi chocolates such that his relative loss is minimized, more formally, if, in total, Alice has paid ai and Bob has paid bi, Bob wants to minimize bi - ai.\n Return an integer array ans where ans[i] is Bob's minimum relative loss possible for queries[i].\n \n Example 1:\n \n >>> minimumRelativeLosses(prices = [1,9,22,10,19], queries = [[18,4],[5,2]])\n >>> [34,-21]\n Explanation: For the 1st query Bob selects the chocolates with prices [1,9,10,22]. He pays 1 + 9 + 10 + 18 = 38 and Alice pays 0 + 0 + 0 + 4 = 4. So Bob's relative loss is 38 - 4 = 34.\n For the 2nd query Bob selects the chocolates with prices [19,22]. He pays 5 + 5 = 10 and Alice pays 14 + 17 = 31. So Bob's relative loss is 10 - 31 = -21.\n It can be shown that these are the minimum possible relative losses.\n Example 2:\n \n >>> minimumRelativeLosses(prices = [1,5,4,3,7,11,9], queries = [[5,4],[5,7],[7,3],[4,5]])\n >>> [4,16,7,1]\n Explanation: For the 1st query Bob selects the chocolates with prices [1,3,9,11]. He pays 1 + 3 + 5 + 5 = 14 and Alice pays 0 + 0 + 4 + 6 = 10. So Bob's relative loss is 14 - 10 = 4.\n For the 2nd query Bob has to select all the chocolates. He pays 1 + 5 + 4 + 3 + 5 + 5 + 5 = 28 and Alice pays 0 + 0 + 0 + 0 + 2 + 6 + 4 = 12. So Bob's relative loss is 28 - 12 = 16.\n For the 3rd query Bob selects the chocolates with prices [1,3,11] and he pays 1 + 3 + 7 = 11 and Alice pays 0 + 0 + 4 = 4. So Bob's relative loss is 11 - 4 = 7.\n For the 4th query Bob selects the chocolates with prices [1,3,7,9,11] and he pays 1 + 3 + 4 + 4 + 4 = 16 and Alice pays 0 + 0 + 3 + 5 + 7 = 15. So Bob's relative loss is 16 - 15 = 1.\n It can be shown that these are the minimum possible relative losses.\n \n Example 3:\n \n >>> minimumRelativeLosses(prices = [5,6,7], queries = [[10,1],[5,3],[3,3]])\n >>> [5,12,0]\n Explanation: For the 1st query Bob selects the chocolate with price 5 and he pays 5 and Alice pays 0. So Bob's relative loss is 5 - 0 = 5.\n For the 2nd query Bob has to select all the chocolates. He pays 5 + 5 + 5 = 15 and Alice pays 0 + 1 + 2 = 3. So Bob's relative loss is 15 - 3 = 12.\n For the 3rd query Bob has to select all the chocolates. He pays 3 + 3 + 3 = 9 and Alice pays 2 + 3 + 4 = 9. So Bob's relative loss is 9 - 9 = 0.\n It can be shown that these are the minimum possible relative losses.\n \"\"\"\n"}
{"task_id": "count-pairs-whose-sum-is-less-than-target", "prompt": "def countPairs(nums: List[int], target: int) -> int:\n \"\"\"\n Given a 0-indexed integer array nums of length n and an integer target, return the number of pairs (i, j) where 0 <= i < j < n and nums[i] + nums[j] < target.\n \n Example 1:\n \n >>> countPairs(nums = [-1,1,2,3,1], target = 2)\n >>> 3\n Explanation: There are 3 pairs of indices that satisfy the conditions in the statement:\n - (0, 1) since 0 < 1 and nums[0] + nums[1] = 0 < target\n - (0, 2) since 0 < 2 and nums[0] + nums[2] = 1 < target\n - (0, 4) since 0 < 4 and nums[0] + nums[4] = 0 < target\n Note that (0, 3) is not counted since nums[0] + nums[3] is not strictly less than the target.\n \n Example 2:\n \n >>> countPairs(nums = [-6,2,5,-2,-7,-1,3], target = -2)\n >>> 10\n Explanation: There are 10 pairs of indices that satisfy the conditions in the statement:\n - (0, 1) since 0 < 1 and nums[0] + nums[1] = -4 < target\n - (0, 3) since 0 < 3 and nums[0] + nums[3] = -8 < target\n - (0, 4) since 0 < 4 and nums[0] + nums[4] = -13 < target\n - (0, 5) since 0 < 5 and nums[0] + nums[5] = -7 < target\n - (0, 6) since 0 < 6 and nums[0] + nums[6] = -3 < target\n - (1, 4) since 1 < 4 and nums[1] + nums[4] = -5 < target\n - (3, 4) since 3 < 4 and nums[3] + nums[4] = -9 < target\n - (3, 5) since 3 < 5 and nums[3] + nums[5] = -3 < target\n - (4, 5) since 4 < 5 and nums[4] + nums[5] = -8 < target\n - (4, 6) since 4 < 6 and nums[4] + nums[6] = -4 < target\n \"\"\"\n"}
{"task_id": "make-string-a-subsequence-using-cyclic-increments", "prompt": "def canMakeSubsequence(str1: str, str2: str) -> bool:\n \"\"\"\n You are given two 0-indexed strings str1 and str2.\n In an operation, you select a set of indices in str1, and for each index i in the set, increment str1[i] to the next character cyclically. That is 'a' becomes 'b', 'b' becomes 'c', and so on, and 'z' becomes 'a'.\n Return true if it is possible to make str2 a subsequence of str1 by performing the operation at most once, and false otherwise.\n Note: A subsequence of a string is a new string that is formed from the original string by deleting some (possibly none) of the characters without disturbing the relative positions of the remaining characters.\n \n Example 1:\n \n >>> canMakeSubsequence(str1 = \"abc\", str2 = \"ad\")\n >>> true\n Explanation: Select index 2 in str1.\n Increment str1[2] to become 'd'.\n Hence, str1 becomes \"abd\" and str2 is now a subsequence. Therefore, true is returned.\n Example 2:\n \n >>> canMakeSubsequence(str1 = \"zc\", str2 = \"ad\")\n >>> true\n Explanation: Select indices 0 and 1 in str1.\n Increment str1[0] to become 'a'.\n Increment str1[1] to become 'd'.\n Hence, str1 becomes \"ad\" and str2 is now a subsequence. Therefore, true is returned.\n Example 3:\n \n >>> canMakeSubsequence(str1 = \"ab\", str2 = \"d\")\n >>> false\n Explanation: In this example, it can be shown that it is impossible to make str2 a subsequence of str1 using the operation at most once.\n Therefore, false is returned.\n \"\"\"\n"}
{"task_id": "sorting-three-groups", "prompt": "def minimumOperations(nums: List[int]) -> int:\n \"\"\"\n You are given an integer array nums. Each element in nums is 1, 2 or 3. In each operation, you can remove an element from\u00a0nums. Return the minimum number of operations to make nums non-decreasing.\n \n Example 1:\n \n >>> minimumOperations(nums = [2,1,3,2,1])\n >>> 3\n Explanation:\n One of the optimal solutions is to remove nums[0], nums[2] and nums[3].\n \n Example 2:\n \n >>> minimumOperations(nums = [1,3,2,1,3,3])\n >>> 2\n Explanation:\n One of the optimal solutions is to remove nums[1] and nums[2].\n \n Example 3:\n \n >>> minimumOperations(nums = [2,2,2,2,3,3])\n >>> 0\n Explanation:\n nums is already non-decreasing.\n \"\"\"\n"}
{"task_id": "number-of-beautiful-integers-in-the-range", "prompt": "def numberOfBeautifulIntegers(low: int, high: int, k: int) -> int:\n \"\"\"\n You are given positive integers low, high, and k.\n A number is beautiful if it meets both of the following conditions:\n \n The count of even digits in the number is equal to the count of odd digits.\n The number is divisible by k.\n \n Return the number of beautiful integers in the range [low, high].\n \n Example 1:\n \n >>> numberOfBeautifulIntegers(low = 10, high = 20, k = 3)\n >>> 2\n Explanation: There are 2 beautiful integers in the given range: [12,18].\n - 12 is beautiful because it contains 1 odd digit and 1 even digit, and is divisible by k = 3.\n - 18 is beautiful because it contains 1 odd digit and 1 even digit, and is divisible by k = 3.\n Additionally we can see that:\n - 16 is not beautiful because it is not divisible by k = 3.\n - 15 is not beautiful because it does not contain equal counts even and odd digits.\n It can be shown that there are only 2 beautiful integers in the given range.\n \n Example 2:\n \n >>> numberOfBeautifulIntegers(low = 1, high = 10, k = 1)\n >>> 1\n Explanation: There is 1 beautiful integer in the given range: [10].\n - 10 is beautiful because it contains 1 odd digit and 1 even digit, and is divisible by k = 1.\n It can be shown that there is only 1 beautiful integer in the given range.\n \n Example 3:\n \n >>> numberOfBeautifulIntegers(low = 5, high = 5, k = 2)\n >>> 0\n Explanation: There are 0 beautiful integers in the given range.\n - 5 is not beautiful because it is not divisible by k = 2 and it does not contain equal even and odd digits.\n \"\"\"\n"}
{"task_id": "check-if-a-string-is-an-acronym-of-words", "prompt": "def isAcronym(words: List[str], s: str) -> bool:\n \"\"\"\n Given an array of strings words and a string s, determine if s is an acronym of words.\n The string s is considered an acronym of words if it can be formed by concatenating the first character of each string in words in order. For example, \"ab\" can be formed from [\"apple\", \"banana\"], but it can't be formed from [\"bear\", \"aardvark\"].\n Return true if s is an acronym of words, and false otherwise.\n \n Example 1:\n \n >>> isAcronym(words = [\"alice\",\"bob\",\"charlie\"], s = \"abc\")\n >>> true\n Explanation: The first character in the words \"alice\", \"bob\", and \"charlie\" are 'a', 'b', and 'c', respectively. Hence, s = \"abc\" is the acronym.\n \n Example 2:\n \n >>> isAcronym(words = [\"an\",\"apple\"], s = \"a\")\n >>> false\n Explanation: The first character in the words \"an\" and \"apple\" are 'a' and 'a', respectively.\n The acronym formed by concatenating these characters is \"aa\".\n Hence, s = \"a\" is not the acronym.\n \n Example 3:\n \n >>> isAcronym(words = [\"never\",\"gonna\",\"give\",\"up\",\"on\",\"you\"], s = \"ngguoy\")\n >>> true\n Explanation: By concatenating the first character of the words in the array, we get the string \"ngguoy\".\n Hence, s = \"ngguoy\" is the acronym.\n \"\"\"\n"}
{"task_id": "determine-the-minimum-sum-of-a-k-avoiding-array", "prompt": "def minimumSum(n: int, k: int) -> int:\n \"\"\"\n You are given two integers,\u00a0n and k.\n An array of distinct positive integers is called a k-avoiding array if there does not exist any pair of distinct elements that sum to k.\n Return the minimum possible sum of a k-avoiding array of length n.\n \n Example 1:\n \n >>> minimumSum(n = 5, k = 4)\n >>> 18\n Explanation: Consider the k-avoiding array [1,2,4,5,6], which has a sum of 18.\n It can be proven that there is no k-avoiding array with a sum less than 18.\n \n Example 2:\n \n >>> minimumSum(n = 2, k = 6)\n >>> 3\n Explanation: We can construct the array [1,2], which has a sum of 3.\n It can be proven that there is no k-avoiding array with a sum less than 3.\n \"\"\"\n"}
{"task_id": "maximize-the-profit-as-the-salesman", "prompt": "def maximizeTheProfit(n: int, offers: List[List[int]]) -> int:\n \"\"\"\n You are given an integer n representing the number of houses on a number line, numbered from 0 to n - 1.\n Additionally, you are given a 2D integer array offers where offers[i] = [starti, endi, goldi], indicating that ith buyer wants to buy all the houses from starti to endi for goldi amount of gold.\n As a salesman, your goal is to maximize your earnings by strategically selecting and selling houses to buyers.\n Return the maximum amount of gold you can earn.\n Note that different buyers can't buy the same house, and some houses may remain unsold.\n \n Example 1:\n \n >>> maximizeTheProfit(n = 5, offers = [[0,0,1],[0,2,2],[1,3,2]])\n >>> 3\n Explanation: There are 5 houses numbered from 0 to 4 and there are 3 purchase offers.\n We sell houses in the range [0,0] to 1st buyer for 1 gold and houses in the range [1,3] to 3rd buyer for 2 golds.\n It can be proven that 3 is the maximum amount of gold we can achieve.\n \n Example 2:\n \n >>> maximizeTheProfit(n = 5, offers = [[0,0,1],[0,2,10],[1,3,2]])\n >>> 10\n Explanation: There are 5 houses numbered from 0 to 4 and there are 3 purchase offers.\n We sell houses in the range [0,2] to 2nd buyer for 10 golds.\n It can be proven that 10 is the maximum amount of gold we can achieve.\n \"\"\"\n"}
{"task_id": "find-the-longest-equal-subarray", "prompt": "def longestEqualSubarray(nums: List[int], k: int) -> int:\n \"\"\"\n You are given a 0-indexed integer array nums and an integer k.\n A subarray is called equal if all of its elements are equal. Note that the empty subarray is an equal subarray.\n Return the length of the longest possible equal subarray after deleting at most k elements from nums.\n A subarray is a contiguous, possibly empty sequence of elements within an array.\n \n Example 1:\n \n >>> longestEqualSubarray(nums = [1,3,2,3,1,3], k = 3)\n >>> 3\n Explanation: It's optimal to delete the elements at index 2 and index 4.\n After deleting them, nums becomes equal to [1, 3, 3, 3].\n The longest equal subarray starts at i = 1 and ends at j = 3 with length equal to 3.\n It can be proven that no longer equal subarrays can be created.\n \n Example 2:\n \n >>> longestEqualSubarray(nums = [1,1,2,2,1,1], k = 2)\n >>> 4\n Explanation: It's optimal to delete the elements at index 2 and index 3.\n After deleting them, nums becomes equal to [1, 1, 1, 1].\n The array itself is an equal subarray, so the answer is 4.\n It can be proven that no longer equal subarrays can be created.\n \"\"\"\n"}
{"task_id": "maximal-range-that-each-element-is-maximum-in-it", "prompt": "def maximumLengthOfRanges(nums: List[int]) -> List[int]:\n \"\"\"\n You are given a 0-indexed array nums of distinct integers.\n Let us define a 0-indexed array ans of the same length as nums in the following way:\n \n ans[i] is the maximum length of a subarray nums[l..r], such that the maximum element in that subarray is equal to nums[i].\n \n Return the array ans.\n Note that a subarray is a contiguous part of the array.\n \n Example 1:\n \n >>> maximumLengthOfRanges(nums = [1,5,4,3,6])\n >>> [1,4,2,1,5]\n Explanation: For nums[0] the longest subarray in which 1 is the maximum is nums[0..0] so ans[0] = 1.\n For nums[1] the longest subarray in which 5 is the maximum is nums[0..3] so ans[1] = 4.\n For nums[2] the longest subarray in which 4 is the maximum is nums[2..3] so ans[2] = 2.\n For nums[3] the longest subarray in which 3 is the maximum is nums[3..3] so ans[3] = 1.\n For nums[4] the longest subarray in which 6 is the maximum is nums[0..4] so ans[4] = 5.\n \n Example 2:\n \n >>> maximumLengthOfRanges(nums = [1,2,3,4,5])\n >>> [1,2,3,4,5]\n Explanation: For nums[i] the longest subarray in which it's the maximum is nums[0..i] so ans[i] = i + 1.\n \"\"\"\n"}
{"task_id": "furthest-point-from-origin", "prompt": "def furthestDistanceFromOrigin(moves: str) -> int:\n \"\"\"\n You are given a string moves of length n consisting only of characters 'L', 'R', and '_'. The string represents your movement on a number line starting from the origin 0.\n In the ith move, you can choose one of the following directions:\n \n move to the left if moves[i] = 'L' or moves[i] = '_'\n move to the right if moves[i] = 'R' or moves[i] = '_'\n \n Return the distance from the origin of the furthest point you can get to after n moves.\n \n Example 1:\n \n >>> furthestDistanceFromOrigin(moves = \"L_RL__R\")\n >>> 3\n Explanation: The furthest point we can reach from the origin 0 is point -3 through the following sequence of moves \"LLRLLLR\".\n \n Example 2:\n \n >>> furthestDistanceFromOrigin(moves = \"_R__LL_\")\n >>> 5\n Explanation: The furthest point we can reach from the origin 0 is point -5 through the following sequence of moves \"LRLLLLL\".\n \n Example 3:\n \n >>> furthestDistanceFromOrigin(moves = \"_______\")\n >>> 7\n Explanation: The furthest point we can reach from the origin 0 is point 7 through the following sequence of moves \"RRRRRRR\".\n \"\"\"\n"}
{"task_id": "find-the-minimum-possible-sum-of-a-beautiful-array", "prompt": "def minimumPossibleSum(n: int, target: int) -> int:\n \"\"\"\n You are given positive integers n and target.\n An array nums is beautiful if it meets the following conditions:\n \n nums.length == n.\n nums consists of pairwise distinct positive integers.\n There doesn't exist two distinct indices, i and j, in the range [0, n - 1], such that nums[i] + nums[j] == target.\n \n Return the minimum possible sum that a beautiful array could have modulo 109 + 7.\n \n Example 1:\n \n >>> minimumPossibleSum(n = 2, target = 3)\n >>> 4\n Explanation: We can see that nums = [1,3] is beautiful.\n - The array nums has length n = 2.\n - The array nums consists of pairwise distinct positive integers.\n - There doesn't exist two distinct indices, i and j, with nums[i] + nums[j] == 3.\n It can be proven that 4 is the minimum possible sum that a beautiful array could have.\n \n Example 2:\n \n >>> minimumPossibleSum(n = 3, target = 3)\n >>> 8\n Explanation: We can see that nums = [1,3,4] is beautiful.\n - The array nums has length n = 3.\n - The array nums consists of pairwise distinct positive integers.\n - There doesn't exist two distinct indices, i and j, with nums[i] + nums[j] == 3.\n It can be proven that 8 is the minimum possible sum that a beautiful array could have.\n \n Example 3:\n \n >>> minimumPossibleSum(n = 1, target = 1)\n >>> 1\n Explanation: We can see, that nums = [1] is beautiful.\n \"\"\"\n"}
{"task_id": "minimum-operations-to-form-subsequence-with-target-sum", "prompt": "def minOperations(nums: List[int], target: int) -> int:\n \"\"\"\n You are given a 0-indexed array nums consisting of non-negative powers of 2, and an integer target.\n In one operation, you must apply the following changes to the array:\n \n Choose any element of the array nums[i] such that nums[i] > 1.\n Remove nums[i] from the array.\n Add two occurrences of nums[i] / 2 to the end of nums.\n \n Return the minimum number of operations you need to perform so that nums contains a subsequence whose elements sum to target. If it is impossible to obtain such a subsequence, return -1.\n 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.\n \n Example 1:\n \n >>> minOperations(nums = [1,2,8], target = 7)\n >>> 1\n Explanation: In the first operation, we choose element nums[2]. The array becomes equal to nums = [1,2,4,4].\n At this stage, nums contains the subsequence [1,2,4] which sums up to 7.\n It can be shown that there is no shorter sequence of operations that results in a subsequnce that sums up to 7.\n \n Example 2:\n \n >>> minOperations(nums = [1,32,1,2], target = 12)\n >>> 2\n Explanation: In the first operation, we choose element nums[1]. The array becomes equal to nums = [1,1,2,16,16].\n In the second operation, we choose element nums[3]. The array becomes equal to nums = [1,1,2,16,8,8]\n At this stage, nums contains the subsequence [1,1,2,8] which sums up to 12.\n It can be shown that there is no shorter sequence of operations that results in a subsequence that sums up to 12.\n Example 3:\n \n >>> minOperations(nums = [1,32,1], target = 35)\n >>> -1\n Explanation: It can be shown that no sequence of operations results in a subsequence that sums up to 35.\n \"\"\"\n"}
{"task_id": "maximize-value-of-function-in-a-ball-passing-game", "prompt": "def getMaxFunctionValue(receiver: List[int], k: int) -> int:\n \"\"\"\n You are given an integer array receiver of length n and an integer k. n players are playing a ball-passing game.\n You choose the starting player, i. The game proceeds as follows: player i passes the ball to player receiver[i], who then passes it to receiver[receiver[i]], and so on, for k passes in total. The game's score is the sum of the indices of the players who touched the ball, including repetitions, i.e. i + receiver[i] + receiver[receiver[i]] + ... + receiver(k)[i].\n Return\u00a0the maximum\u00a0possible score.\n Notes:\n \n receiver may contain duplicates.\n receiver[i] may be equal to i.\n \n \n Example 1:\n \n >>> getMaxFunctionValue(receiver = [2,0,1], k = 4)\n >>> 6\n Explanation:\n Starting with player i = 2 the initial score is 2:\n \n \n \n Pass\n Sender Index\n Receiver Index\n Score\n \n \n 1\n 2\n 1\n 3\n \n \n 2\n 1\n 0\n 3\n \n \n 3\n 0\n 2\n 5\n \n \n 4\n 2\n 1\n 6\n \n \n \n \n Example 2:\n \n >>> getMaxFunctionValue(receiver = [1,1,1,2,3], k = 3)\n >>> 10\n Explanation:\n Starting with player i = 4 the initial score is 4:\n \n \n \n Pass\n Sender Index\n Receiver Index\n Score\n \n \n 1\n 4\n 3\n 7\n \n \n 2\n 3\n 2\n 9\n \n \n 3\n 2\n 1\n 10\n \"\"\"\n"}
{"task_id": "maximum-coins-heroes-can-collect", "prompt": "def maximumCoins(heroes: List[int], monsters: List[int], coins: List[int]) -> List[int]:\n \"\"\"\n There is a battle and n heroes are trying to defeat m monsters. You are given two 1-indexed arrays of positive integers heroes and monsters of length n and m, respectively. heroes[i] is the power of ith hero, and monsters[i] is the power of ith monster.\n The ith hero can defeat the jth monster if monsters[j] <= heroes[i].\n You are also given a 1-indexed array coins of length m consisting of positive integers. coins[i] is the number of coins that each hero earns after defeating the ith monster.\n Return an array ans of length n where ans[i] is the maximum number of coins that the ith hero can collect from this battle.\n Notes\n \n The health of a hero doesn't get reduced after defeating a monster.\n Multiple heroes can defeat a monster, but each monster can be defeated by a given hero only once.\n \n \n Example 1:\n \n >>> maximumCoins(heroes = [1,4,2], monsters = [1,1,5,2,3], coins = [2,3,4,5,6])\n >>> [5,16,10]\n Explanation: For each hero, we list the index of all the monsters he can defeat:\n 1st hero: [1,2] since the power of this hero is 1 and monsters[1], monsters[2] <= 1. So this hero collects coins[1] + coins[2] = 5 coins.\n 2nd hero: [1,2,4,5] since the power of this hero is 4 and monsters[1], monsters[2], monsters[4], monsters[5] <= 4. So this hero collects coins[1] + coins[2] + coins[4] + coins[5] = 16 coins.\n 3rd hero: [1,2,4] since the power of this hero is 2 and monsters[1], monsters[2], monsters[4] <= 2. So this hero collects coins[1] + coins[2] + coins[4] = 10 coins.\n So the answer would be [5,16,10].\n Example 2:\n \n >>> maximumCoins(heroes = [5], monsters = [2,3,1,2], coins = [10,6,5,2])\n >>> [23]\n Explanation: This hero can defeat all the monsters since monsters[i] <= 5. So he collects all of the coins: coins[1] + coins[2] + coins[3] + coins[4] = 23, and the answer would be [23].\n \n Example 3:\n \n >>> maximumCoins(heroes = [4,4], monsters = [5,7,8], coins = [1,1,1])\n >>> [0,0]\n Explanation: In this example, no hero can defeat a monster. So the answer would be [0,0],\n \"\"\"\n"}
{"task_id": "check-if-strings-can-be-made-equal-with-operations-i", "prompt": "def canBeEqual(s1: str, s2: str) -> bool:\n \"\"\"\n You are given two strings s1 and s2, both of length 4, consisting of lowercase English letters.\n You can apply the following operation on any of the two strings any number of times:\n \n Choose any two indices i and j such that j - i = 2, then swap the two characters at those indices in the string.\n \n Return true if you can make the strings s1 and s2 equal, and false otherwise.\n \n Example 1:\n \n >>> canBeEqual(s1 = \"abcd\", s2 = \"cdab\")\n >>> true\n Explanation: We can do the following operations on s1:\n - Choose the indices i = 0, j = 2. The resulting string is s1 = \"cbad\".\n - Choose the indices i = 1, j = 3. The resulting string is s1 = \"cdab\" = s2.\n \n Example 2:\n \n >>> canBeEqual(s1 = \"abcd\", s2 = \"dacb\")\n >>> false\n Explanation: It is not possible to make the two strings equal.\n \"\"\"\n"}
{"task_id": "check-if-strings-can-be-made-equal-with-operations-ii", "prompt": "def checkStrings(s1: str, s2: str) -> bool:\n \"\"\"\n You are given two strings s1 and s2, both of length n, consisting of lowercase English letters.\n You can apply the following operation on any of the two strings any number of times:\n \n Choose any two indices i and j such that i < j and the difference j - i is even, then swap the two characters at those indices in the string.\n \n Return true if you can make the strings s1 and s2 equal, and\u00a0false otherwise.\n \n Example 1:\n \n >>> checkStrings(s1 = \"abcdba\", s2 = \"cabdab\")\n >>> true\n Explanation: We can apply the following operations on s1:\n - Choose the indices i = 0, j = 2. The resulting string is s1 = \"cbadba\".\n - Choose the indices i = 2, j = 4. The resulting string is s1 = \"cbbdaa\".\n - Choose the indices i = 1, j = 5. The resulting string is s1 = \"cabdab\" = s2.\n \n Example 2:\n \n >>> checkStrings(s1 = \"abe\", s2 = \"bea\")\n >>> false\n Explanation: It is not possible to make the two strings equal.\n \"\"\"\n"}
{"task_id": "maximum-sum-of-almost-unique-subarray", "prompt": "def maxSum(nums: List[int], m: int, k: int) -> int:\n \"\"\"\n You are given an integer array nums and two positive integers m and k.\n Return the maximum sum out of all almost unique subarrays of length k of nums. If no such subarray exists, return 0.\n A subarray of nums is almost unique if it contains at least m distinct elements.\n A subarray is a contiguous non-empty sequence of elements within an array.\n \n Example 1:\n \n >>> maxSum(nums = [2,6,7,3,1,7], m = 3, k = 4)\n >>> 18\n Explanation: There are 3 almost unique subarrays of size k = 4. These subarrays are [2, 6, 7, 3], [6, 7, 3, 1], and [7, 3, 1, 7]. Among these subarrays, the one with the maximum sum is [2, 6, 7, 3] which has a sum of 18.\n \n Example 2:\n \n >>> maxSum(nums = [5,9,9,2,4,5,4], m = 1, k = 3)\n >>> 23\n Explanation: There are 5 almost unique subarrays of size k. These subarrays are [5, 9, 9], [9, 9, 2], [9, 2, 4], [2, 4, 5], and [4, 5, 4]. Among these subarrays, the one with the maximum sum is [5, 9, 9] which has a sum of 23.\n \n Example 3:\n \n >>> maxSum(nums = [1,2,1,2,1,2,1], m = 3, k = 3)\n >>> 0\n Explanation: There are no subarrays of size k = 3 that contain at least m = 3 distinct elements in the given array [1,2,1,2,1,2,1]. Therefore, no almost unique subarrays exist, and the maximum sum is 0.\n \"\"\"\n"}
{"task_id": "count-k-subsequences-of-a-string-with-maximum-beauty", "prompt": "def countKSubsequencesWithMaxBeauty(s: str, k: int) -> int:\n \"\"\"\n You are given a string s and an integer k.\n A k-subsequence is a subsequence of s, having length k, and all its characters are unique, i.e., every character occurs once.\n Let f(c) denote the number of times the character c occurs in s.\n The beauty of a k-subsequence is the sum of f(c) for every character c in the k-subsequence.\n For example, consider s = \"abbbdd\" and k = 2:\n \n f('a') = 1, f('b') = 3, f('d') = 2\n Some k-subsequences of s are:\n \n \"abbbdd\" -> \"ab\" having a beauty of f('a') + f('b') = 4\n \"abbbdd\" -> \"ad\" having a beauty of f('a') + f('d') = 3\n \"abbbdd\" -> \"bd\" having a beauty of f('b') + f('d') = 5\n \n \n \n Return an integer denoting the number of k-subsequences whose beauty is the maximum among all k-subsequences. Since the answer may be too large, return it modulo 109 + 7.\n A subsequence of a string is a new string formed from the original string by deleting some (possibly none) of the characters without disturbing the relative positions of the remaining characters.\n Notes\n \n f(c) is the number of times a character c occurs in s, not a k-subsequence.\n Two k-subsequences are considered different if one is formed by an index that is not present in the other. So, two k-subsequences may form the same string.\n \n \n Example 1:\n \n >>> countKSubsequencesWithMaxBeauty(s = \"bcca\", k = 2)\n >>> 4\n Explanation: From s we have f('a') = 1, f('b') = 1, and f('c') = 2.\n The k-subsequences of s are:\n bcca having a beauty of f('b') + f('c') = 3\n bcca having a beauty of f('b') + f('c') = 3\n bcca having a beauty of f('b') + f('a') = 2\n bcca having a beauty of f('c') + f('a') = 3\n bcca having a beauty of f('c') + f('a') = 3\n There are 4 k-subsequences that have the maximum beauty, 3.\n Hence, the answer is 4.\n \n Example 2:\n \n >>> countKSubsequencesWithMaxBeauty(s = \"abbcd\", k = 4)\n >>> 2\n Explanation: From s we have f('a') = 1, f('b') = 2, f('c') = 1, and f('d') = 1.\n The k-subsequences of s are:\n abbcd having a beauty of f('a') + f('b') + f('c') + f('d') = 5\n abbcd having a beauty of f('a') + f('b') + f('c') + f('d') = 5\n There are 2 k-subsequences that have the maximum beauty, 5.\n Hence, the answer is 2.\n \"\"\"\n"}
{"task_id": "count-symmetric-integers", "prompt": "def countSymmetricIntegers(low: int, high: int) -> int:\n \"\"\"\n You are given two positive integers low and high.\n An integer x consisting of 2 * n digits is symmetric if the sum of the first n digits of x is equal to the sum of the last n digits of x. Numbers with an odd number of digits are never symmetric.\n Return the number of symmetric integers in the range [low, high].\n \n Example 1:\n \n >>> countSymmetricIntegers(low = 1, high = 100)\n >>> 9\n Explanation: There are 9 symmetric integers between 1 and 100: 11, 22, 33, 44, 55, 66, 77, 88, and 99.\n \n Example 2:\n \n >>> countSymmetricIntegers(low = 1200, high = 1230)\n >>> 4\n Explanation: There are 4 symmetric integers between 1200 and 1230: 1203, 1212, 1221, and 1230.\n \"\"\"\n"}
{"task_id": "minimum-operations-to-make-a-special-number", "prompt": "def minimumOperations(num: str) -> int:\n \"\"\"\n You are given a 0-indexed string num representing a non-negative integer.\n In one operation, you can pick any digit of num and delete it. Note that if you delete all the digits of num, num becomes 0.\n Return the minimum number of operations required to make num special.\n An integer x is considered special if it is divisible by 25.\n \n Example 1:\n \n >>> minimumOperations(num = \"2245047\")\n >>> 2\n Explanation: Delete digits num[5] and num[6]. The resulting number is \"22450\" which is special since it is divisible by 25.\n It can be shown that 2 is the minimum number of operations required to get a special number.\n Example 2:\n \n >>> minimumOperations(num = \"2908305\")\n >>> 3\n Explanation: Delete digits num[3], num[4], and num[6]. The resulting number is \"2900\" which is special since it is divisible by 25.\n It can be shown that 3 is the minimum number of operations required to get a special number.\n Example 3:\n \n >>> minimumOperations(num = \"10\")\n >>> 1\n Explanation: Delete digit num[0]. The resulting number is \"0\" which is special since it is divisible by 25.\n It can be shown that 1 is the minimum number of operations required to get a special number.\n \"\"\"\n"}
{"task_id": "count-of-interesting-subarrays", "prompt": "def countInterestingSubarrays(nums: List[int], modulo: int, k: int) -> int:\n \"\"\"\n You are given a 0-indexed integer array nums, an integer modulo, and an integer k.\n Your task is to find the count of subarrays that are interesting.\n A subarray nums[l..r] is interesting if the following condition holds:\n \n Let cnt be the number of indices i in the range [l, r] such that nums[i] % modulo == k. Then, cnt % modulo == k.\n \n Return an integer denoting the count of interesting subarrays.\n Note: A subarray is a contiguous non-empty sequence of elements within an array.\n \n Example 1:\n \n >>> countInterestingSubarrays(nums = [3,2,4], modulo = 2, k = 1)\n >>> 3\n Explanation: In this example the interesting subarrays are:\n The subarray nums[0..0] which is [3].\n - There is only one index, i = 0, in the range [0, 0] that satisfies nums[i] % modulo == k.\n - Hence, cnt = 1 and cnt % modulo == k.\n The subarray nums[0..1] which is [3,2].\n - There is only one index, i = 0, in the range [0, 1] that satisfies nums[i] % modulo == k.\n - Hence, cnt = 1 and cnt % modulo == k.\n The subarray nums[0..2] which is [3,2,4].\n - There is only one index, i = 0, in the range [0, 2] that satisfies nums[i] % modulo == k.\n - Hence, cnt = 1 and cnt % modulo == k.\n It can be shown that there are no other interesting subarrays. So, the answer is 3.\n Example 2:\n \n >>> countInterestingSubarrays(nums = [3,1,9,6], modulo = 3, k = 0)\n >>> 2\n Explanation: In this example the interesting subarrays are:\n The subarray nums[0..3] which is [3,1,9,6].\n - There are three indices, i = 0, 2, 3, in the range [0, 3] that satisfy nums[i] % modulo == k.\n - Hence, cnt = 3 and cnt % modulo == k.\n The subarray nums[1..1] which is [1].\n - There is no index, i, in the range [1, 1] that satisfies nums[i] % modulo == k.\n - Hence, cnt = 0 and cnt % modulo == k.\n It can be shown that there are no other interesting subarrays. So, the answer is 2.\n \"\"\"\n"}
{"task_id": "minimum-edge-weight-equilibrium-queries-in-a-tree", "prompt": "def minOperationsQueries(n: int, edges: List[List[int]], queries: List[List[int]]) -> List[int]:\n \"\"\"\n There is an undirected tree with n nodes labeled from 0 to n - 1. You are given the integer n and a 2D integer array edges of length n - 1, where edges[i] = [ui, vi, wi] indicates that there is an edge between nodes ui and vi with weight wi in the tree.\n You are also given a 2D integer array queries of length m, where queries[i] = [ai, bi]. For each query, find the minimum number of operations required to make the weight of every edge on the path from ai to bi equal. In one operation, you can choose any edge of the tree and change its weight to any value.\n Note that:\n \n Queries are independent of each other, meaning that the tree returns to its initial state on each new query.\n The path from ai to bi is a sequence of distinct nodes starting with node ai and ending with node bi such that every two adjacent nodes in the sequence share an edge in the tree.\n \n Return an array answer of length m where answer[i] is the answer to the ith query.\n \n Example 1:\n \n \n >>> minOperationsQueries(n = 7, edges = [[0,1,1],[1,2,1],[2,3,1],[3,4,2],[4,5,2],[5,6,2]], queries = [[0,3],[3,6],[2,6],[0,6]])\n >>> [0,0,1,3]\n Explanation: In the first query, all the edges in the path from 0 to 3 have a weight of 1. Hence, the answer is 0.\n In the second query, all the edges in the path from 3 to 6 have a weight of 2. Hence, the answer is 0.\n In the third query, we change the weight of edge [2,3] to 2. After this operation, all the edges in the path from 2 to 6 have a weight of 2. Hence, the answer is 1.\n In the fourth query, we change the weights of edges [0,1], [1,2] and [2,3] to 2. After these operations, all the edges in the path from 0 to 6 have a weight of 2. Hence, the answer is 3.\n For each queries[i], it can be shown that answer[i] is the minimum number of operations needed to equalize all the edge weights in the path from ai to bi.\n \n Example 2:\n \n \n >>> minOperationsQueries(n = 8, edges = [[1,2,6],[1,3,4],[2,4,6],[2,5,3],[3,6,6],[3,0,8],[7,0,2]], queries = [[4,6],[0,4],[6,5],[7,4]])\n >>> [1,2,2,3]\n Explanation: In the first query, we change the weight of edge [1,3] to 6. After this operation, all the edges in the path from 4 to 6 have a weight of 6. Hence, the answer is 1.\n In the second query, we change the weight of edges [0,3] and [3,1] to 6. After these operations, all the edges in the path from 0 to 4 have a weight of 6. Hence, the answer is 2.\n In the third query, we change the weight of edges [1,3] and [5,2] to 6. After these operations, all the edges in the path from 6 to 5 have a weight of 6. Hence, the answer is 2.\n In the fourth query, we change the weights of edges [0,7], [0,3] and [1,3] to 6. After these operations, all the edges in the path from 7 to 4 have a weight of 6. Hence, the answer is 3.\n For each queries[i], it can be shown that answer[i] is the minimum number of operations needed to equalize all the edge weights in the path from ai to bi.\n \"\"\"\n"}
{"task_id": "smallest-number-with-given-digit-product", "prompt": "def smallestNumber(n: int) -> str:\n \"\"\"\n Given a positive integer n, return a string representing the smallest positive integer such that the product of its digits is equal to n, or \"-1\" if no such number exists.\n \n Example 1:\n \n >>> smallestNumber(n = 105)\n >>> \"357\"\n Explanation: 3 * 5 * 7 = 105. It can be shown that 357 is the smallest number with a product of digits equal to 105. So the answer would be \"357\".\n \n Example 2:\n \n >>> smallestNumber(n = 7)\n >>> \"7\"\n Explanation: Since 7 has only one digit, its product of digits would be 7. We will show that 7 is the smallest number with a product of digits equal to 7. Since the product of numbers 1 to 6 is 1 to 6 respectively, so \"7\" would be the answer.\n \n Example 3:\n \n >>> smallestNumber(n = 44)\n >>> \"-1\"\n Explanation: It can be shown that there is no number such that its product of digits is equal to 44. So the answer would be \"-1\".\n \"\"\"\n"}
{"task_id": "points-that-intersect-with-cars", "prompt": "def numberOfPoints(nums: List[List[int]]) -> int:\n \"\"\"\n You are given a 0-indexed 2D integer array nums representing the coordinates of the cars parking on a number line. For any index i, nums[i] = [starti, endi] where starti is the starting point of the ith car and endi is the ending point of the ith car.\n Return the number of integer points on the line that are covered with any part of a car.\n \n Example 1:\n \n >>> numberOfPoints(nums = [[3,6],[1,5],[4,7]])\n >>> 7\n Explanation: All the points from 1 to 7 intersect at least one car, therefore the answer would be 7.\n \n Example 2:\n \n >>> numberOfPoints(nums = [[1,3],[5,8]])\n >>> 7\n Explanation: Points intersecting at least one car are 1, 2, 3, 5, 6, 7, 8. There are a total of 7 points, therefore the answer would be 7.\n \"\"\"\n"}
{"task_id": "determine-if-a-cell-is-reachable-at-a-given-time", "prompt": "def isReachableAtTime(sx: int, sy: int, fx: int, fy: int, t: int) -> bool:\n \"\"\"\n You are given four integers sx, sy, fx, fy, and a non-negative integer t.\n In an infinite 2D grid, you start at the cell (sx, sy). Each second, you must move to any of its adjacent cells.\n Return true if you can reach cell (fx, fy) after exactly t seconds, or false otherwise.\n A cell's adjacent cells are the 8 cells around it that share at least one corner with it. You can visit the same cell several times.\n \n Example 1:\n \n \n >>> isReachableAtTime(sx = 2, sy = 4, fx = 7, fy = 7, t = 6)\n >>> true\n Explanation: Starting at cell (2, 4), we can reach cell (7, 7) in exactly 6 seconds by going through the cells depicted in the picture above.\n \n Example 2:\n \n \n >>> isReachableAtTime(sx = 3, sy = 1, fx = 7, fy = 3, t = 3)\n >>> false\n Explanation: Starting at cell (3, 1), it takes at least 4 seconds to reach cell (7, 3) by going through the cells depicted in the picture above. Hence, we cannot reach cell (7, 3) at the third second.\n \"\"\"\n"}
{"task_id": "minimum-moves-to-spread-stones-over-grid", "prompt": "def minimumMoves(grid: List[List[int]]) -> int:\n \"\"\"\n You are given a 0-indexed 2D integer matrix grid of size 3 * 3, representing the number of stones in each cell. The grid contains exactly 9 stones, and there can be multiple stones in a single cell.\n In one move, you can move a single stone from its current cell to any other cell if the two cells share a side.\n Return the minimum number of moves required to place one stone in each cell.\n \n Example 1:\n \n \n >>> minimumMoves(grid = [[1,1,0],[1,1,1],[1,2,1]])\n >>> 3\n Explanation: One possible sequence of moves to place one stone in each cell is:\n 1- Move one stone from cell (2,1) to cell (2,2).\n 2- Move one stone from cell (2,2) to cell (1,2).\n 3- Move one stone from cell (1,2) to cell (0,2).\n In total, it takes 3 moves to place one stone in each cell of the grid.\n It can be shown that 3 is the minimum number of moves required to place one stone in each cell.\n \n Example 2:\n \n \n >>> minimumMoves(grid = [[1,3,0],[1,0,0],[1,0,3]])\n >>> 4\n Explanation: One possible sequence of moves to place one stone in each cell is:\n 1- Move one stone from cell (0,1) to cell (0,2).\n 2- Move one stone from cell (0,1) to cell (1,1).\n 3- Move one stone from cell (2,2) to cell (1,2).\n 4- Move one stone from cell (2,2) to cell (2,1).\n In total, it takes 4 moves to place one stone in each cell of the grid.\n It can be shown that 4 is the minimum number of moves required to place one stone in each cell.\n \"\"\"\n"}
{"task_id": "string-transformation", "prompt": "def numberOfWays(s: str, t: str, k: int) -> int:\n \"\"\"\n You are given two strings s and t of equal length n. You can perform the following operation on the string s:\n \n Remove a suffix of s of length l where 0 < l < n and append it at the start of s.\n \tFor example, let s = 'abcd' then in one operation you can remove the suffix 'cd' and append it in front of s making s = 'cdab'.\n \n You are also given an integer k. Return the number of ways in which s can be transformed into t in exactly k operations.\n Since the answer can be large, return it modulo 109 + 7.\n \n Example 1:\n \n >>> numberOfWays(s = \"abcd\", t = \"cdab\", k = 2)\n >>> 2\n Explanation:\n First way:\n In first operation, choose suffix from index = 3, so resulting s = \"dabc\".\n In second operation, choose suffix from index = 3, so resulting s = \"cdab\".\n \n Second way:\n In first operation, choose suffix from index = 1, so resulting s = \"bcda\".\n In second operation, choose suffix from index = 1, so resulting s = \"cdab\".\n \n Example 2:\n \n >>> numberOfWays(s = \"ababab\", t = \"ababab\", k = 1)\n >>> 2\n Explanation:\n First way:\n Choose suffix from index = 2, so resulting s = \"ababab\".\n \n Second way:\n Choose suffix from index = 4, so resulting s = \"ababab\".\n \"\"\"\n"}
{"task_id": "sum-of-remoteness-of-all-cells", "prompt": "def sumRemoteness(grid: List[List[int]]) -> int:\n \"\"\"\n You are given a 0-indexed matrix grid of order n * n. Each cell in this matrix has a value grid[i][j], which is either a positive integer or -1 representing a blocked cell.\n You can move from a non-blocked cell to any non-blocked cell that shares an edge.\n For any cell (i, j), we represent its remoteness as R[i][j] which is defined as the following:\n \n If the cell (i, j) is a non-blocked cell, R[i][j] is the sum of the values grid[x][y] such that there is no path from the non-blocked cell (x, y) to the cell (i, j).\n For blocked cells, R[i][j] == 0.\n \n Return the sum of R[i][j] over all cells.\n \n Example 1:\n \n \n >>> sumRemoteness(grid = [[-1,1,-1],[5,-1,4],[-1,3,-1]])\n >>> 39\n Explanation: In the picture above, there are four grids. The top-left grid contains the initial values in the grid. Blocked cells are colored black, and other cells get their values as it is in the input. In the top-right grid, you can see the value of R[i][j] for all cells. So the answer would be the sum of them. That is: 0 + 12 + 0 + 8 + 0 + 9 + 0 + 10 + 0 = 39.\n Let's jump on the bottom-left grid in the above picture and calculate R[0][1] (the target cell is colored green). We should sum up the value of cells that can't be reached by the cell (0, 1). These cells are colored yellow in this grid. So R[0][1] = 5 + 4 + 3 = 12.\n Now let's jump on the bottom-right grid in the above picture and calculate R[1][2] (the target cell is colored green). We should sum up the value of cells that can't be reached by the cell (1, 2). These cells are colored yellow in this grid. So R[1][2] = 1 + 5 + 3 = 9.\n \n \n Example 2:\n \n >>> sumRemoteness(grid = [[-1,3,4],[-1,-1,-1],[3,-1,-1]])\n >>> 13\n Explanation: In the picture above, there are four grids. The top-left grid contains the initial values in the grid. Blocked cells are colored black, and other cells get their values as it is in the input. In the top-right grid, you can see the value of R[i][j] for all cells. So the answer would be the sum of them. That is: 3 + 3 + 0 + 0 + 0 + 0 + 7 + 0 + 0 = 13.\n Let's jump on the bottom-left grid in the above picture and calculate R[0][2] (the target cell is colored green). We should sum up the value of cells that can't be reached by the cell (0, 2). This cell is colored yellow in this grid. So R[0][2] = 3.\n Now let's jump on the bottom-right grid in the above picture and calculate R[2][0] (the target cell is colored green). We should sum up the value of cells that can't be reached by the cell (2, 0). These cells are colored yellow in this grid. So R[2][0] = 3 + 4 = 7.\n \n Example 3:\n \n >>> sumRemoteness(grid = [[1]])\n >>> 0\n Explanation: Since there are no other cells than (0, 0), R[0][0] is equal to 0. So the sum of R[i][j] over all cells would be 0.\n \"\"\"\n"}
{"task_id": "minimum-right-shifts-to-sort-the-array", "prompt": "def minimumRightShifts(nums: List[int]) -> int:\n \"\"\"\n You are given a 0-indexed array nums of length n containing distinct positive integers. Return the minimum number of right shifts required to sort nums and -1 if this is not possible.\n A right shift is defined as shifting the element at index i to index (i + 1) % n, for all indices.\n \n Example 1:\n \n >>> minimumRightShifts(nums = [3,4,5,1,2])\n >>> 2\n Explanation:\n After the first right shift, nums = [2,3,4,5,1].\n After the second right shift, nums = [1,2,3,4,5].\n Now nums is sorted; therefore the answer is 2.\n \n Example 2:\n \n >>> minimumRightShifts(nums = [1,3,5])\n >>> 0\n Explanation: nums is already sorted therefore, the answer is 0.\n Example 3:\n \n >>> minimumRightShifts(nums = [2,1,4])\n >>> -1\n Explanation: It's impossible to sort the array using right shifts.\n \"\"\"\n"}
{"task_id": "minimum-array-length-after-pair-removals", "prompt": "def minLengthAfterRemovals(nums: List[int]) -> int:\n \"\"\"\n Given an integer array num sorted in non-decreasing order.\n You can perform the following operation any number of times:\n \n Choose two indices, i and j, where nums[i] < nums[j].\n Then, remove the elements at indices i and j from nums. The remaining elements retain their original order, and the array is re-indexed.\n \n Return the minimum length of nums after applying the operation zero or more times.\n \n Example 1:\n \n >>> minLengthAfterRemovals(nums = [1,2,3,4])\n >>> 0\n Explanation:\n \n \n Example 2:\n \n >>> minLengthAfterRemovals(nums = [1,1,2,2,3,3])\n >>> 0\n Explanation:\n \n \n Example 3:\n \n >>> minLengthAfterRemovals(nums = [1000000000,1000000000])\n >>> 2\n Explanation:\n Since both numbers are equal, they cannot be removed.\n \n Example 4:\n \n >>> minLengthAfterRemovals(nums = [2,3,4,4,4])\n >>> 1\n Explanation:\n \"\"\"\n"}
{"task_id": "count-pairs-of-points-with-distance-k", "prompt": "def countPairs(coordinates: List[List[int]], k: int) -> int:\n \"\"\"\n You are given a 2D integer array coordinates and an integer k, where coordinates[i] = [xi, yi] are the coordinates of the ith point in a 2D plane.\n We define the distance between two points (x1, y1) and (x2, y2) as (x1 XOR x2) + (y1 XOR y2) where XOR is the bitwise XOR operation.\n Return the number of pairs (i, j) such that i < j and the distance between points i and j is equal to k.\n \n Example 1:\n \n >>> countPairs(coordinates = [[1,2],[4,2],[1,3],[5,2]], k = 5)\n >>> 2\n Explanation: We can choose the following pairs:\n - (0,1): Because we have (1 XOR 4) + (2 XOR 2) = 5.\n - (2,3): Because we have (1 XOR 5) + (3 XOR 2) = 5.\n \n Example 2:\n \n >>> countPairs(coordinates = [[1,3],[1,3],[1,3],[1,3],[1,3]], k = 0)\n >>> 10\n Explanation: Any two chosen pairs will have a distance of 0. There are 10 ways to choose two pairs.\n \"\"\"\n"}
{"task_id": "minimum-edge-reversals-so-every-node-is-reachable", "prompt": "def minEdgeReversals(n: int, edges: List[List[int]]) -> List[int]:\n \"\"\"\n There is a simple directed graph with n nodes labeled from 0 to n - 1. The graph would form a tree if its edges were bi-directional.\n You are given an integer n and a 2D integer array edges, where edges[i] = [ui, vi] represents a directed edge going from node ui to node vi.\n An edge reversal changes the direction of an edge, i.e., a directed edge going from node ui to node vi becomes a directed edge going from node vi to node ui.\n For every node i in the range [0, n - 1], your task is to independently calculate the minimum number of edge reversals required so it is possible to reach any other node starting from node i through a sequence of directed edges.\n Return an integer array answer, where answer[i] is the minimum number of edge reversals required so it is possible to reach any other node starting from node i through a sequence of directed edges.\n \n Example 1:\n \n \n >>> minEdgeReversals(n = 4, edges = [[2,0],[2,1],[1,3]])\n >>> [1,1,0,2]\n Explanation: The image above shows the graph formed by the edges.\n For node 0: after reversing the edge [2,0], it is possible to reach any other node starting from node 0.\n So, answer[0] = 1.\n For node 1: after reversing the edge [2,1], it is possible to reach any other node starting from node 1.\n So, answer[1] = 1.\n For node 2: it is already possible to reach any other node starting from node 2.\n So, answer[2] = 0.\n For node 3: after reversing the edges [1,3] and [2,1], it is possible to reach any other node starting from node 3.\n So, answer[3] = 2.\n \n Example 2:\n \n \n >>> minEdgeReversals(n = 3, edges = [[1,2],[2,0]])\n >>> [2,0,1]\n Explanation: The image above shows the graph formed by the edges.\n For node 0: after reversing the edges [2,0] and [1,2], it is possible to reach any other node starting from node 0.\n So, answer[0] = 2.\n For node 1: it is already possible to reach any other node starting from node 1.\n So, answer[1] = 0.\n For node 2: after reversing the edge [1, 2], it is possible to reach any other node starting from node 2.\n So, answer[2] = 1.\n \"\"\"\n"}
{"task_id": "sum-of-values-at-indices-with-k-set-bits", "prompt": "def sumIndicesWithKSetBits(nums: List[int], k: int) -> int:\n \"\"\"\n You are given a 0-indexed integer array nums and an integer k.\n Return an integer that denotes the sum of elements in nums whose corresponding indices have exactly k set bits in their binary representation.\n The set bits in an integer are the 1's present when it is written in binary.\n \n For example, the binary representation of 21 is 10101, which has 3 set bits.\n \n \n Example 1:\n \n >>> sumIndicesWithKSetBits(nums = [5,10,1,5,2], k = 1)\n >>> 13\n Explanation: The binary representation of the indices are:\n 0 = 0002\n 1 = 0012\n 2 = 0102\n 3 = 0112\n 4 = 1002\n Indices 1, 2, and 4 have k = 1 set bits in their binary representation.\n Hence, the answer is nums[1] + nums[2] + nums[4] = 13.\n Example 2:\n \n >>> sumIndicesWithKSetBits(nums = [4,3,2,1], k = 2)\n >>> 1\n Explanation: The binary representation of the indices are:\n 0 = 002\n 1 = 012\n 2 = 102\n 3 = 112\n Only index 3 has k = 2 set bits in its binary representation.\n Hence, the answer is nums[3] = 1.\n \"\"\"\n"}
{"task_id": "happy-students", "prompt": "def countWays(nums: List[int]) -> int:\n \"\"\"\n You are given a 0-indexed integer array nums of length n where n is the total number of students in the class. The class teacher tries to select a group of students so that all the students remain happy.\n The ith student will become happy if one of these two conditions is met:\n \n The student is selected and the total number of selected students is strictly greater than nums[i].\n The student is not selected and the total number of selected students is strictly less than nums[i].\n \n Return the number of ways to select a group of students so that everyone remains happy.\n \n Example 1:\n \n >>> countWays(nums = [1,1])\n >>> 2\n Explanation:\n The two possible ways are:\n The class teacher selects no student.\n The class teacher selects both students to form the group.\n If the class teacher selects just one student to form a group then the both students will not be happy. Therefore, there are only two possible ways.\n \n Example 2:\n \n >>> countWays(nums = [6,0,3,3,6,7,2,7])\n >>> 3\n Explanation:\n The three possible ways are:\n The class teacher selects the student with index = 1 to form the group.\n The class teacher selects the students with index = 1, 2, 3, 6 to form the group.\n The class teacher selects all the students to form the group.\n \"\"\"\n"}
{"task_id": "maximum-number-of-alloys", "prompt": "def maxNumberOfAlloys(n: int, k: int, budget: int, composition: List[List[int]], stock: List[int], cost: List[int]) -> int:\n \"\"\"\n You are the owner of a company that creates alloys using various types of metals. There are n different types of metals available, and you have access to k machines that can be used to create alloys. Each machine requires a specific amount of each metal type to create an alloy.\n For the ith machine to create an alloy, it needs composition[i][j] units of metal of type j. Initially, you have stock[i] units of metal type i, and purchasing one unit of metal type i costs cost[i] coins.\n Given integers n, k, budget, a 1-indexed 2D array composition, and 1-indexed arrays stock and cost, your goal is to maximize the number of alloys the company can create while staying within the budget of budget coins.\n All alloys must be created with the same machine.\n Return the maximum number of alloys that the company can create.\n \n Example 1:\n \n >>> maxNumberOfAlloys(n = 3, k = 2, budget = 15, composition = [[1,1,1],[1,1,10]], stock = [0,0,0], cost = [1,2,3])\n >>> 2\n Explanation: It is optimal to use the 1st machine to create alloys.\n To create 2 alloys we need to buy the:\n - 2 units of metal of the 1st type.\n - 2 units of metal of the 2nd type.\n - 2 units of metal of the 3rd type.\n In total, we need 2 * 1 + 2 * 2 + 2 * 3 = 12 coins, which is smaller than or equal to budget = 15.\n Notice that we have 0 units of metal of each type and we have to buy all the required units of metal.\n It can be proven that we can create at most 2 alloys.\n \n Example 2:\n \n >>> maxNumberOfAlloys(n = 3, k = 2, budget = 15, composition = [[1,1,1],[1,1,10]], stock = [0,0,100], cost = [1,2,3])\n >>> 5\n Explanation: It is optimal to use the 2nd machine to create alloys.\n To create 5 alloys we need to buy:\n - 5 units of metal of the 1st type.\n - 5 units of metal of the 2nd type.\n - 0 units of metal of the 3rd type.\n In total, we need 5 * 1 + 5 * 2 + 0 * 3 = 15 coins, which is smaller than or equal to budget = 15.\n It can be proven that we can create at most 5 alloys.\n \n Example 3:\n \n >>> maxNumberOfAlloys(n = 2, k = 3, budget = 10, composition = [[2,1],[1,2],[1,1]], stock = [1,1], cost = [5,5])\n >>> 2\n Explanation: It is optimal to use the 3rd machine to create alloys.\n To create 2 alloys we need to buy the:\n - 1 unit of metal of the 1st type.\n - 1 unit of metal of the 2nd type.\n In total, we need 1 * 5 + 1 * 5 = 10 coins, which is smaller than or equal to budget = 10.\n It can be proven that we can create at most 2 alloys.\n \"\"\"\n"}
{"task_id": "maximum-element-sum-of-a-complete-subset-of-indices", "prompt": "def maximumSum(nums: List[int]) -> int:\n \"\"\"\n You are given a 1-indexed array nums. Your task is to select a complete subset from nums where every pair of selected indices multiplied is a perfect square,. i. e. if you select ai and aj, i * j must be a perfect square.\n Return the sum of the complete subset with the maximum sum.\n \n Example 1:\n \n >>> maximumSum(nums = [8,7,3,5,7,2,4,9])\n >>> 16\n Explanation:\n We select elements at indices 2 and 8 and 2 * 8 is a perfect square.\n \n Example 2:\n \n >>> maximumSum(nums = [8,10,3,8,1,13,7,9,4])\n >>> 20\n Explanation:\n We select elements at indices 1, 4, and 9. 1 * 4, 1 * 9, 4 * 9 are perfect squares.\n \"\"\"\n"}
{"task_id": "maximum-length-of-semi-decreasing-subarrays", "prompt": "def maxSubarrayLength(nums: List[int]) -> int:\n \"\"\"\n You are given an integer array nums.\n Return the length of the longest semi-decreasing subarray of nums, and 0 if there are no such subarrays.\n \n A subarray is a contiguous non-empty sequence of elements within an array.\n A non-empty array is semi-decreasing if its first element is strictly greater than its last element.\n \n \n Example 1:\n \n >>> maxSubarrayLength(nums = [7,6,5,4,3,2,1,6,10,11])\n >>> 8\n Explanation: Take the subarray [7,6,5,4,3,2,1,6].\n The first element is 7 and the last one is 6 so the condition is met.\n Hence, the answer would be the length of the subarray or 8.\n It can be shown that there aren't any subarrays with the given condition with a length greater than 8.\n \n Example 2:\n \n >>> maxSubarrayLength(nums = [57,55,50,60,61,58,63,59,64,60,63])\n >>> 6\n Explanation: Take the subarray [61,58,63,59,64,60].\n The first element is 61 and the last one is 60 so the condition is met.\n Hence, the answer would be the length of the subarray or 6.\n It can be shown that there aren't any subarrays with the given condition with a length greater than 6.\n \n Example 3:\n \n >>> maxSubarrayLength(nums = [1,2,3,4])\n >>> 0\n Explanation: Since there are no semi-decreasing subarrays in the given array, the answer is 0.\n \"\"\"\n"}
{"task_id": "maximum-odd-binary-number", "prompt": "def maximumOddBinaryNumber(s: str) -> str:\n \"\"\"\n You are given a binary string s that contains at least one '1'.\n You have to rearrange the bits in such a way that the resulting binary number is the maximum odd binary number that can be created from this combination.\n Return a string representing the maximum odd binary number that can be created from the given combination.\n Note that the resulting string can have leading zeros.\n \n Example 1:\n \n >>> maximumOddBinaryNumber(s = \"010\")\n >>> \"001\"\n Explanation: Because there is just one '1', it must be in the last position. So the answer is \"001\".\n \n Example 2:\n \n >>> maximumOddBinaryNumber(s = \"0101\")\n >>> \"1001\"\n Explanation: One of the '1's must be in the last position. The maximum number that can be made with the remaining digits is \"100\". So the answer is \"1001\".\n \"\"\"\n"}
{"task_id": "beautiful-towers-i", "prompt": "def maximumSumOfHeights(heights: List[int]) -> int:\n \"\"\"\n You are given an array heights of n integers representing the number of bricks in n consecutive towers. Your task is to remove some bricks to form a mountain-shaped tower arrangement. In this arrangement, the tower heights are non-decreasing, reaching a maximum peak value with one or multiple consecutive towers and then non-increasing.\n Return the maximum possible sum of heights of a mountain-shaped tower arrangement.\n \n Example 1:\n \n >>> maximumSumOfHeights(heights = [5,3,4,1,1])\n >>> 13\n Explanation:\n We remove some bricks to make heights =\u00a0[5,3,3,1,1], the peak is at index 0.\n \n Example 2:\n \n >>> maximumSumOfHeights(heights = [6,5,3,9,2,7])\n >>> 22\n Explanation:\n We remove some bricks to make heights =\u00a0[3,3,3,9,2,2], the peak is at index 3.\n \n Example 3:\n \n >>> maximumSumOfHeights(heights = [3,2,5,5,2,3])\n >>> 18\n Explanation:\n We remove some bricks to make heights = [2,2,5,5,2,2], the peak is at index 2 or 3.\n \"\"\"\n"}
{"task_id": "beautiful-towers-ii", "prompt": "def maximumSumOfHeights(maxHeights: List[int]) -> int:\n \"\"\"\n You are given a 0-indexed array maxHeights of n integers.\n You are tasked with building n towers in the coordinate line. The ith tower is built at coordinate i and has a height of heights[i].\n A configuration of towers is beautiful if the following conditions hold:\n \n 1 <= heights[i] <= maxHeights[i]\n heights is a mountain array.\n \n Array heights is a mountain if there exists an index i such that:\n \n For all 0 < j <= i, heights[j - 1] <= heights[j]\n For all i <= k < n - 1, heights[k + 1] <= heights[k]\n \n Return the maximum possible sum of heights of a beautiful configuration of towers.\n \n Example 1:\n \n >>> maximumSumOfHeights(maxHeights = [5,3,4,1,1])\n >>> 13\n Explanation: One beautiful configuration with a maximum sum is heights = [5,3,3,1,1]. This configuration is beautiful since:\n - 1 <= heights[i] <= maxHeights[i]\n - heights is a mountain of peak i = 0.\n It can be shown that there exists no other beautiful configuration with a sum of heights greater than 13.\n Example 2:\n \n >>> maximumSumOfHeights(maxHeights = [6,5,3,9,2,7])\n >>> 22\n Explanation: One beautiful configuration with a maximum sum is heights = [3,3,3,9,2,2]. This configuration is beautiful since:\n - 1 <= heights[i] <= maxHeights[i]\n - heights is a mountain of peak i = 3.\n It can be shown that there exists no other beautiful configuration with a sum of heights greater than 22.\n Example 3:\n \n >>> maximumSumOfHeights(maxHeights = [3,2,5,5,2,3])\n >>> 18\n Explanation: One beautiful configuration with a maximum sum is heights = [2,2,5,5,2,2]. This configuration is beautiful since:\n - 1 <= heights[i] <= maxHeights[i]\n - heights is a mountain of peak i = 2.\n Note that, for this configuration, i = 3 can also be considered a peak.\n It can be shown that there exists no other beautiful configuration with a sum of heights greater than 18.\n \"\"\"\n"}
{"task_id": "count-valid-paths-in-a-tree", "prompt": "def countPaths(n: int, edges: List[List[int]]) -> int:\n \"\"\"\n There is an undirected tree with n nodes labeled from 1 to n. You are given the integer n and a 2D integer array edges of length n - 1, where edges[i] = [ui, vi] indicates that there is an edge between nodes ui and vi in the tree.\n Return the number of valid paths in the tree.\n A path (a, b) is valid if there exists exactly one prime number among the node labels in the path from a to b.\n Note that:\n \n The path (a, b) is a sequence of distinct nodes starting with node a and ending with node b such that every two adjacent nodes in the sequence share an edge in the tree.\n Path (a, b) and path (b, a) are considered the same and counted only once.\n \n \n Example 1:\n \n \n >>> countPaths(n = 5, edges = [[1,2],[1,3],[2,4],[2,5]])\n >>> 4\n Explanation: The pairs with exactly one prime number on the path between them are:\n - (1, 2) since the path from 1 to 2 contains prime number 2.\n - (1, 3) since the path from 1 to 3 contains prime number 3.\n - (1, 4) since the path from 1 to 4 contains prime number 2.\n - (2, 4) since the path from 2 to 4 contains prime number 2.\n It can be shown that there are only 4 valid paths.\n \n Example 2:\n \n \n >>> countPaths(n = 6, edges = [[1,2],[1,3],[2,4],[3,5],[3,6]])\n >>> 6\n Explanation: The pairs with exactly one prime number on the path between them are:\n - (1, 2) since the path from 1 to 2 contains prime number 2.\n - (1, 3) since the path from 1 to 3 contains prime number 3.\n - (1, 4) since the path from 1 to 4 contains prime number 2.\n - (1, 6) since the path from 1 to 6 contains prime number 3.\n - (2, 4) since the path from 2 to 4 contains prime number 2.\n - (3, 6) since the path from 3 to 6 contains prime number 3.\n It can be shown that there are only 6 valid paths.\n \"\"\"\n"}
{"task_id": "the-wording-game", "prompt": "def canAliceWin(a: List[str], b: List[str]) -> bool:\n \"\"\"\n Alice and Bob each have a lexicographically sorted array of strings named a and b respectively.\n They are playing a wording game with the following rules:\n \n On each turn, the current player should play a word from their list such that the new word is closely greater than the last played word; then it's the other player's turn.\n If a player can't play a word on their turn, they lose.\n \n Alice starts the game by playing her lexicographically smallest word.\n Given a and b, return true if Alice can win knowing that both players play their best, and false otherwise.\n A word w is closely greater than a word z if the following conditions are met:\n \n w is lexicographically greater than z.\n If w1 is the first letter of w and z1 is the first letter of z, w1 should either be equal to z1 or be the letter after z1 in the alphabet.\n For example, the word \"care\" is closely greater than \"book\" and \"car\", but is not closely greater than \"ant\" or \"cook\".\n \n A string s is lexicographically greater than a string t if in the first position where s and t differ, string s has a letter that appears later in the alphabet than the corresponding letter in t. If the first min(s.length, t.length) characters do not differ, then the longer string is the lexicographically greater one.\n \n Example 1:\n \n >>> canAliceWin(a = [\"avokado\",\"dabar\"], b = [\"brazil\"])\n >>> false\n Explanation: Alice must start the game by playing the word \"avokado\" since it's her smallest word, then Bob plays his only word, \"brazil\", which he can play because its first letter, 'b', is the letter after Alice's word's first letter, 'a'.\n Alice can't play a word since the first letter of the only word left is not equal to 'b' or the letter after 'b', 'c'.\n So, Alice loses, and the game ends.\n Example 2:\n \n >>> canAliceWin(a = [\"ananas\",\"atlas\",\"banana\"], b = [\"albatros\",\"cikla\",\"nogomet\"])\n >>> true\n Explanation: Alice must start the game by playing the word \"ananas\".\n Bob can't play a word since the only word he has that starts with the letter 'a' or 'b' is \"albatros\", which is smaller than Alice's word.\n So Alice wins, and the game ends.\n Example 3:\n \n >>> canAliceWin(a = [\"hrvatska\",\"zastava\"], b = [\"bijeli\",\"galeb\"])\n >>> true\n Explanation: Alice must start the game by playing the word \"hrvatska\".\n Bob can't play a word since the first letter of both of his words are smaller than the first letter of Alice's word, 'h'.\n So Alice wins, and the game ends.\n \"\"\"\n"}
{"task_id": "minimum-operations-to-collect-elements", "prompt": "def minOperations(nums: List[int], k: int) -> int:\n \"\"\"\n You are given an array nums of positive integers and an integer k.\n In one operation, you can remove the last element of the array and add it to your collection.\n Return the minimum number of operations needed to collect elements 1, 2, ..., k.\n \n Example 1:\n \n >>> minOperations(nums = [3,1,5,4,2], k = 2)\n >>> 4\n Explanation: After 4 operations, we collect elements 2, 4, 5, and 1, in this order. Our collection contains elements 1 and 2. Hence, the answer is 4.\n \n Example 2:\n \n >>> minOperations(nums = [3,1,5,4,2], k = 5)\n >>> 5\n Explanation: After 5 operations, we collect elements 2, 4, 5, 1, and 3, in this order. Our collection contains elements 1 through 5. Hence, the answer is 5.\n \n Example 3:\n \n >>> minOperations(nums = [3,2,5,3,1], k = 3)\n >>> 4\n Explanation: After 4 operations, we collect elements 1, 3, 5, and 2, in this order. Our collection contains elements 1 through 3. Hence, the answer is 4.\n \"\"\"\n"}
{"task_id": "minimum-number-of-operations-to-make-array-empty", "prompt": "def minOperations(nums: List[int]) -> int:\n \"\"\"\n You are given a 0-indexed array nums consisting of positive integers.\n There are two types of operations that you can apply on the array any number of times:\n \n Choose two elements with equal values and delete them from the array.\n Choose three elements with equal values and delete them from the array.\n \n Return the minimum number of operations required to make the array empty, or -1 if it is not possible.\n \n Example 1:\n \n >>> minOperations(nums = [2,3,3,2,2,4,2,3,4])\n >>> 4\n Explanation: We can apply the following operations to make the array empty:\n - Apply the first operation on the elements at indices 0 and 3. The resulting array is nums = [3,3,2,4,2,3,4].\n - Apply the first operation on the elements at indices 2 and 4. The resulting array is nums = [3,3,4,3,4].\n - Apply the second operation on the elements at indices 0, 1, and 3. The resulting array is nums = [4,4].\n - Apply the first operation on the elements at indices 0 and 1. The resulting array is nums = [].\n It can be shown that we cannot make the array empty in less than 4 operations.\n \n Example 2:\n \n >>> minOperations(nums = [2,1,2,2,3,3])\n >>> -1\n Explanation: It is impossible to empty the array.\n \"\"\"\n"}
{"task_id": "split-array-into-maximum-number-of-subarrays", "prompt": "def maxSubarrays(nums: List[int]) -> int:\n \"\"\"\n You are given an array nums consisting of non-negative integers.\n We define the score of subarray nums[l..r] such that l <= r as nums[l] AND nums[l + 1] AND ... AND nums[r] where AND is the bitwise AND operation.\n Consider splitting the array into one or more subarrays such that the following conditions are satisfied:\n \n Each element of the array belongs to exactly one subarray.\n The sum of scores of the subarrays is the minimum possible.\n \n Return the maximum number of subarrays in a split that satisfies the conditions above.\n A subarray is a contiguous part of an array.\n \n Example 1:\n \n >>> maxSubarrays(nums = [1,0,2,0,1,2])\n >>> 3\n Explanation: We can split the array into the following subarrays:\n - [1,0]. The score of this subarray is 1 AND 0 = 0.\n - [2,0]. The score of this subarray is 2 AND 0 = 0.\n - [1,2]. The score of this subarray is 1 AND 2 = 0.\n The sum of scores is 0 + 0 + 0 = 0, which is the minimum possible score that we can obtain.\n It can be shown that we cannot split the array into more than 3 subarrays with a total score of 0. So we return 3.\n \n Example 2:\n \n >>> maxSubarrays(nums = [5,7,1,3])\n >>> 1\n Explanation: We can split the array into one subarray: [5,7,1,3] with a score of 1, which is the minimum possible score that we can obtain.\n It can be shown that we cannot split the array into more than 1 subarray with a total score of 1. So we return 1.\n \"\"\"\n"}
{"task_id": "maximum-number-of-k-divisible-components", "prompt": "def maxKDivisibleComponents(n: int, edges: List[List[int]], values: List[int], k: int) -> int:\n \"\"\"\n There is an undirected tree with n nodes labeled from 0 to n - 1. You are given the integer n and a 2D integer array edges of length n - 1, where edges[i] = [ai, bi] indicates that there is an edge between nodes ai and bi in the tree.\n You are also given a 0-indexed integer array values of length n, where values[i] is the value associated with the ith node, and an integer k.\n A valid split of the tree is obtained by removing any set of edges, possibly empty, from the tree such that the resulting components all have values that are divisible by k, where the value of a connected component is the sum of the values of its nodes.\n Return the maximum number of components in any valid split.\n \n Example 1:\n \n \n >>> maxKDivisibleComponents(n = 5, edges = [[0,2],[1,2],[1,3],[2,4]], values = [1,8,1,4,4], k = 6)\n >>> 2\n Explanation: We remove the edge connecting node 1 with 2. The resulting split is valid because:\n - The value of the component containing nodes 1 and 3 is values[1] + values[3] = 12.\n - The value of the component containing nodes 0, 2, and 4 is values[0] + values[2] + values[4] = 6.\n It can be shown that no other valid split has more than 2 connected components.\n Example 2:\n \n \n >>> maxKDivisibleComponents(n = 7, edges = [[0,1],[0,2],[1,3],[1,4],[2,5],[2,6]], values = [3,0,6,1,5,2,1], k = 3)\n >>> 3\n Explanation: We remove the edge connecting node 0 with 2, and the edge connecting node 0 with 1. The resulting split is valid because:\n - The value of the component containing node 0 is values[0] = 3.\n - The value of the component containing nodes 2, 5, and 6 is values[2] + values[5] + values[6] = 9.\n - The value of the component containing nodes 1, 3, and 4 is values[1] + values[3] + values[4] = 6.\n It can be shown that no other valid split has more than 3 connected components.\n \"\"\"\n"}
{"task_id": "maximum-value-of-an-ordered-triplet-i", "prompt": "def maximumTripletValue(nums: List[int]) -> int:\n \"\"\"\n You are given a 0-indexed integer array nums.\n Return the maximum value over all triplets of indices (i, j, k) such that i < j < k. If all such triplets have a negative value, return 0.\n The value of a triplet of indices (i, j, k) is equal to (nums[i] - nums[j]) * nums[k].\n \n Example 1:\n \n >>> maximumTripletValue(nums = [12,6,1,2,7])\n >>> 77\n Explanation: The value of the triplet (0, 2, 4) is (nums[0] - nums[2]) * nums[4] = 77.\n It can be shown that there are no ordered triplets of indices with a value greater than 77.\n \n Example 2:\n \n >>> maximumTripletValue(nums = [1,10,3,4,19])\n >>> 133\n Explanation: The value of the triplet (1, 2, 4) is (nums[1] - nums[2]) * nums[4] = 133.\n It can be shown that there are no ordered triplets of indices with a value greater than 133.\n \n Example 3:\n \n >>> maximumTripletValue(nums = [1,2,3])\n >>> 0\n Explanation: The only ordered triplet of indices (0, 1, 2) has a negative value of (nums[0] - nums[1]) * nums[2] = -3. Hence, the answer would be 0.\n \"\"\"\n"}
{"task_id": "maximum-value-of-an-ordered-triplet-ii", "prompt": "def maximumTripletValue(nums: List[int]) -> int:\n \"\"\"\n You are given a 0-indexed integer array nums.\n Return the maximum value over all triplets of indices (i, j, k) such that i < j < k. If all such triplets have a negative value, return 0.\n The value of a triplet of indices (i, j, k) is equal to (nums[i] - nums[j]) * nums[k].\n \n Example 1:\n \n >>> maximumTripletValue(nums = [12,6,1,2,7])\n >>> 77\n Explanation: The value of the triplet (0, 2, 4) is (nums[0] - nums[2]) * nums[4] = 77.\n It can be shown that there are no ordered triplets of indices with a value greater than 77.\n \n Example 2:\n \n >>> maximumTripletValue(nums = [1,10,3,4,19])\n >>> 133\n Explanation: The value of the triplet (1, 2, 4) is (nums[1] - nums[2]) * nums[4] = 133.\n It can be shown that there are no ordered triplets of indices with a value greater than 133.\n \n Example 3:\n \n >>> maximumTripletValue(nums = [1,2,3])\n >>> 0\n Explanation: The only ordered triplet of indices (0, 1, 2) has a negative value of (nums[0] - nums[1]) * nums[2] = -3. Hence, the answer would be 0.\n \"\"\"\n"}
{"task_id": "minimum-size-subarray-in-infinite-array", "prompt": "def minSizeSubarray(nums: List[int], target: int) -> int:\n \"\"\"\n You are given a 0-indexed array nums and an integer target.\n A 0-indexed array infinite_nums is generated by infinitely appending the elements of nums to itself.\n Return the length of the shortest subarray of the array infinite_nums with a sum equal to target. If there is no such subarray return -1.\n \n Example 1:\n \n >>> minSizeSubarray(nums = [1,2,3], target = 5)\n >>> 2\n Explanation: In this example infinite_nums = [1,2,3,1,2,3,1,2,...].\n The subarray in the range [1,2], has the sum equal to target = 5 and length = 2.\n It can be proven that 2 is the shortest length of a subarray with sum equal to target = 5.\n \n Example 2:\n \n >>> minSizeSubarray(nums = [1,1,1,2,3], target = 4)\n >>> 2\n Explanation: In this example infinite_nums = [1,1,1,2,3,1,1,1,2,3,1,1,...].\n The subarray in the range [4,5], has the sum equal to target = 4 and length = 2.\n It can be proven that 2 is the shortest length of a subarray with sum equal to target = 4.\n \n Example 3:\n \n >>> minSizeSubarray(nums = [2,4,6,8], target = 3)\n >>> -1\n Explanation: In this example infinite_nums = [2,4,6,8,2,4,6,8,...].\n It can be proven that there is no subarray with sum equal to target = 3.\n \"\"\"\n"}
{"task_id": "count-visited-nodes-in-a-directed-graph", "prompt": "def countVisitedNodes(edges: List[int]) -> List[int]:\n \"\"\"\n There is a directed graph consisting of n nodes numbered from 0 to n - 1 and n directed edges.\n You are given a 0-indexed array edges where edges[i] indicates that there is an edge from node i to node edges[i].\n Consider the following process on the graph:\n \n You start from a node x and keep visiting other nodes through edges until you reach a node that you have already visited before on this same process.\n \n Return an array answer where answer[i] is the number of different nodes that you will visit if you perform the process starting from node i.\n \n Example 1:\n \n \n >>> countVisitedNodes(edges = [1,2,0,0])\n >>> [3,3,3,4]\n Explanation: We perform the process starting from each node in the following way:\n - Starting from node 0, we visit the nodes 0 -> 1 -> 2 -> 0. The number of different nodes we visit is 3.\n - Starting from node 1, we visit the nodes 1 -> 2 -> 0 -> 1. The number of different nodes we visit is 3.\n - Starting from node 2, we visit the nodes 2 -> 0 -> 1 -> 2. The number of different nodes we visit is 3.\n - Starting from node 3, we visit the nodes 3 -> 0 -> 1 -> 2 -> 0. The number of different nodes we visit is 4.\n \n Example 2:\n \n \n >>> countVisitedNodes(edges = [1,2,3,4,0])\n >>> [5,5,5,5,5]\n Explanation: Starting from any node we can visit every node in the graph in the process.\n \"\"\"\n"}
{"task_id": "minimizing-array-after-replacing-pairs-with-their-product", "prompt": "def minArrayLength(nums: List[int], k: int) -> int:\n \"\"\"\n Given an integer array nums and an integer k, you can perform the following operation on the array any number of times:\n \n Select two adjacent elements of the array like x and y, such that x * y <= k, and replace both of them with a single element with value x * y (e.g. in one operation the array [1, 2, 2, 3] with k = 5 can become [1, 4, 3] or [2, 2, 3], but can't become [1, 2, 6]).\n \n Return the minimum possible length of nums after any number of operations.\n \n Example 1:\n \n >>> minArrayLength(nums = [2,3,3,7,3,5], k = 20)\n >>> 3\n Explanation: We perform these operations:\n 1. [2,3,3,7,3,5] -> [6,3,7,3,5]\n 2. [6,3,7,3,5] -> [18,7,3,5]\n 3. [18,7,3,5] -> [18,7,15]\n It can be shown that 3 is the minimum length possible to achieve with the given operation.\n \n Example 2:\n \n >>> minArrayLength(nums = [3,3,3,3], k = 6)\n >>> 4\n Explanation: We can't perform any operations since the product of every two adjacent elements is greater than 6.\n Hence, the answer is 4.\n \"\"\"\n"}
{"task_id": "divisible-and-non-divisible-sums-difference", "prompt": "def differenceOfSums(n: int, m: int) -> int:\n \"\"\"\n You are given positive integers n and m.\n Define two integers as follows:\n \n num1: The sum of all integers in the range [1, n] (both inclusive) that are not divisible by m.\n num2: The sum of all integers in the range [1, n] (both inclusive) that are divisible by m.\n \n Return the integer num1 - num2.\n \n Example 1:\n \n >>> differenceOfSums(n = 10, m = 3)\n >>> 19\n Explanation: In the given example:\n - Integers in the range [1, 10] that are not divisible by 3 are [1,2,4,5,7,8,10], num1 is the sum of those integers = 37.\n - Integers in the range [1, 10] that are divisible by 3 are [3,6,9], num2 is the sum of those integers = 18.\n We return 37 - 18 = 19 as the answer.\n \n Example 2:\n \n >>> differenceOfSums(n = 5, m = 6)\n >>> 15\n Explanation: In the given example:\n - Integers in the range [1, 5] that are not divisible by 6 are [1,2,3,4,5], num1 is the sum of those integers = 15.\n - Integers in the range [1, 5] that are divisible by 6 are [], num2 is the sum of those integers = 0.\n We return 15 - 0 = 15 as the answer.\n \n Example 3:\n \n >>> differenceOfSums(n = 5, m = 1)\n >>> -15\n Explanation: In the given example:\n - Integers in the range [1, 5] that are not divisible by 1 are [], num1 is the sum of those integers = 0.\n - Integers in the range [1, 5] that are divisible by 1 are [1,2,3,4,5], num2 is the sum of those integers = 15.\n We return 0 - 15 = -15 as the answer.\n \"\"\"\n"}
{"task_id": "minimum-processing-time", "prompt": "def minProcessingTime(processorTime: List[int], tasks: List[int]) -> int:\n \"\"\"\n You have a certain number of processors, each having 4 cores. The number of tasks to be executed is four times the number of processors. Each task must be assigned to a unique core, and each core can only be used once.\n You are given an array processorTime representing the time each processor becomes available and an array tasks representing how long each task takes to complete. Return the\u00a0minimum time needed to complete all tasks.\n \n Example 1:\n \n >>> minProcessingTime(processorTime = [8,10], tasks = [2,2,3,1,8,7,4,5])\n >>> 16\n Explanation:\n Assign the tasks at indices 4, 5, 6, 7 to the first processor which becomes available at time = 8, and the tasks at indices 0, 1, 2, 3 to the second processor which becomes available at time = 10.\n The time taken by the first processor to finish the execution of all tasks is\u00a0max(8 + 8, 8 + 7, 8 + 4, 8 + 5) = 16.\n The time taken by the second processor to finish the execution of all tasks is\u00a0max(10 + 2, 10 + 2, 10 + 3, 10 + 1) = 13.\n \n Example 2:\n \n >>> minProcessingTime(processorTime = [10,20], tasks = [2,3,1,2,5,8,4,3])\n >>> 23\n Explanation:\n Assign the tasks at indices 1, 4, 5, 6 to the first processor and the others to the second processor.\n The time taken by the first processor to finish the execution of all tasks is max(10 + 3, 10 + 5, 10 + 8, 10 + 4) = 18.\n The time taken by the second processor to finish the execution of all tasks is max(20 + 2, 20 + 1, 20 + 2, 20 + 3) = 23.\n \"\"\"\n"}
{"task_id": "apply-operations-to-make-two-strings-equal", "prompt": "def minOperations(s1: str, s2: str, x: int) -> int:\n \"\"\"\n You are given two 0-indexed binary strings s1 and s2, both of length n, and a positive integer x.\n You can perform any of the following operations on the string s1 any number of times:\n \n Choose two indices i and j, and flip both s1[i] and s1[j]. The cost of this operation is x.\n Choose an index i such that i < n - 1 and flip both s1[i] and s1[i + 1]. The cost of this operation is 1.\n \n Return the minimum cost needed to make the strings s1 and s2 equal, or return -1 if it is impossible.\n Note that flipping a character means changing it from 0 to 1 or vice-versa.\n \n Example 1:\n \n >>> minOperations(s1 = \"1100011000\", s2 = \"0101001010\", x = 2)\n >>> 4\n Explanation: We can do the following operations:\n - Choose i = 3 and apply the second operation. The resulting string is s1 = \"1101111000\".\n - Choose i = 4 and apply the second operation. The resulting string is s1 = \"1101001000\".\n - Choose i = 0 and j = 8 and apply the first operation. The resulting string is s1 = \"0101001010\" = s2.\n The total cost is 1 + 1 + 2 = 4. It can be shown that it is the minimum cost possible.\n \n Example 2:\n \n >>> minOperations(s1 = \"10110\", s2 = \"00011\", x = 4)\n >>> -1\n Explanation: It is not possible to make the two strings equal.\n \"\"\"\n"}
{"task_id": "apply-operations-on-array-to-maximize-sum-of-squares", "prompt": "def maxSum(nums: List[int], k: int) -> int:\n \"\"\"\n You are given a 0-indexed integer array nums and a positive integer k.\n You can do the following operation on the array any number of times:\n \n Choose any two distinct indices i and j and simultaneously update the values of nums[i] to (nums[i] AND nums[j]) and nums[j] to (nums[i] OR nums[j]). Here, OR denotes the bitwise OR operation, and AND denotes the bitwise AND operation.\n \n You have to choose k elements from the final array and calculate the sum of their squares.\n Return the maximum sum of squares you can achieve.\n Since the answer can be very large, return it modulo 109 + 7.\n \n Example 1:\n \n >>> maxSum(nums = [2,6,5,8], k = 2)\n >>> 261\n Explanation: We can do the following operations on the array:\n - Choose i = 0 and j = 3, then change nums[0] to (2 AND 8) = 0 and nums[3] to (2 OR 8) = 10. The resulting array is nums = [0,6,5,10].\n - Choose i = 2 and j = 3, then change nums[2] to (5 AND 10) = 0 and nums[3] to (5 OR 10) = 15. The resulting array is nums = [0,6,0,15].\n We can choose the elements 15 and 6 from the final array. The sum of squares is 152 + 62 = 261.\n It can be shown that this is the maximum value we can get.\n \n Example 2:\n \n >>> maxSum(nums = [4,5,4,7], k = 3)\n >>> 90\n Explanation: We do not need to apply any operations.\n We can choose the elements 7, 5, and 4 with a sum of squares: 72 + 52 + 42 = 90.\n It can be shown that this is the maximum value we can get.\n \"\"\"\n"}
{"task_id": "maximum-linear-stock-score", "prompt": "def maxScore(prices: List[int]) -> int:\n \"\"\"\n Given a 1-indexed integer array prices, where prices[i] is the price of a particular stock on the ith day, your task is to select some of the elements of prices such that your selection is linear.\n A selection indexes, where indexes is a 1-indexed integer array of length k which is a subsequence of the array [1, 2, ..., n], is linear if:\n \n For every 1 < j <= k, prices[indexes[j]] - prices[indexes[j - 1]] == indexes[j] - indexes[j - 1].\n \n 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.\n The score of a selection indexes, is equal to the sum of the following array: [prices[indexes[1]], prices[indexes[2]], ..., prices[indexes[k]].\n Return the maximum score that a linear selection can have.\n \n Example 1:\n \n >>> maxScore(prices = [1,5,3,7,8])\n >>> 20\n Explanation: We can select the indexes [2,4,5]. We show that our selection is linear:\n For j = 2, we have:\n indexes[2] - indexes[1] = 4 - 2 = 2.\n prices[4] - prices[2] = 7 - 5 = 2.\n For j = 3, we have:\n indexes[3] - indexes[2] = 5 - 4 = 1.\n prices[5] - prices[4] = 8 - 7 = 1.\n The sum of the elements is: prices[2] + prices[4] + prices[5] = 20.\n It can be shown that the maximum sum a linear selection can have is 20.\n \n Example 2:\n \n >>> maxScore(prices = [5,6,7,8,9])\n >>> 35\n Explanation: We can select all of the indexes [1,2,3,4,5]. Since each element has a difference of exactly 1 from its previous element, our selection is linear.\n The sum of all the elements is 35 which is the maximum possible some out of every selection.\n \"\"\"\n"}
{"task_id": "last-visited-integers", "prompt": "def lastVisitedIntegers(nums: List[int]) -> List[int]:\n \"\"\"\n Given an integer array nums where nums[i] is either a positive integer or -1. We need to find for each -1 the respective positive integer, which we call the last visited integer.\n To achieve this goal, let's define two empty arrays: seen and ans.\n Start iterating from the beginning of the array nums.\n \n If a positive integer is encountered, prepend it to the front of seen.\n If -1\u00a0is encountered, let k be the number of consecutive -1s seen so far (including the current -1),\n \n If k is less than or equal to the length of seen, append the k-th element of seen to ans.\n If k is strictly greater than the length of seen, append -1 to ans.\n \n \n \n Return the array ans.\n \n Example 1:\n \n >>> lastVisitedIntegers(nums = [1,2,-1,-1,-1])\n >>> [2,1,-1]\n Explanation:\n Start with seen = [] and ans = [].\n \n Process nums[0]: The first element in nums is 1. We prepend it to the front of seen. Now, seen == [1].\n Process nums[1]: The next element is 2. We prepend it to the front of seen. Now, seen == [2, 1].\n Process nums[2]: The next element is -1. This is the first occurrence of -1, so k == 1. We look for the first element in seen. We append 2 to ans. Now, ans == [2].\n Process nums[3]: Another -1. This is the second consecutive -1, so k == 2. The second element in seen is 1, so we append 1 to ans. Now, ans == [2, 1].\n Process nums[4]: Another -1, the third in a row, making k = 3. However, seen only has two elements ([2, 1]). Since k is greater than the number of elements in seen, we append -1 to ans. Finally, ans == [2, 1, -1].\n \n \n Example 2:\n \n >>> lastVisitedIntegers(nums = [1,-1,2,-1,-1])\n >>> [1,2,1]\n Explanation:\n Start with seen = [] and ans = [].\n \n Process nums[0]: The first element in nums is 1. We prepend it to the front of seen. Now, seen == [1].\n Process nums[1]: The next element is -1. This is the first occurrence of -1, so k == 1. We look for the first element in seen, which is 1. Append 1 to ans. Now, ans == [1].\n Process nums[2]: The next element is 2. Prepend this to the front of seen. Now, seen == [2, 1].\n Process nums[3]: The next element is -1. This -1 is not consecutive to the first -1 since 2 was in between. Thus, k resets to 1. The first element in seen is 2, so append 2 to ans. Now, ans == [1, 2].\n Process nums[4]: Another -1. This is consecutive to the previous -1, so k == 2. The second element in seen is 1, append 1 to ans. Finally, ans == [1, 2, 1].\n \"\"\"\n"}
{"task_id": "longest-unequal-adjacent-groups-subsequence-i", "prompt": "def getLongestSubsequence(words: List[str], groups: List[int]) -> List[str]:\n \"\"\"\n You are given a string array words and a binary array groups both of length n, where words[i] is associated with groups[i].\n Your task is to select the longest alternating subsequence from words. A subsequence of words is alternating if for any two consecutive strings in the sequence, their corresponding elements in the binary array groups differ. Essentially, you are to choose strings such that adjacent elements have non-matching corresponding bits in the groups array.\n Formally, you need to find the longest subsequence of an array of indices [0, 1, ..., n - 1] denoted as [i0, i1, ..., ik-1], such that groups[ij] != groups[ij+1] for each 0 <= j < k - 1 and then find the words corresponding to these indices.\n Return the selected subsequence. If there are multiple answers, return any of them.\n Note: The elements in words are distinct.\n \n Example 1:\n \n >>> getLongestSubsequence(words = [\"e\",\"a\",\"b\"], groups = [0,0,1])\n >>> [\"e\",\"b\"]\n Explanation: A subsequence that can be selected is [\"e\",\"b\"] because groups[0] != groups[2]. Another subsequence that can be selected is [\"a\",\"b\"] because groups[1] != groups[2]. It can be demonstrated that the length of the longest subsequence of indices that satisfies the condition is 2.\n \n Example 2:\n \n >>> getLongestSubsequence(words = [\"a\",\"b\",\"c\",\"d\"], groups = [1,0,1,1])\n >>> [\"a\",\"b\",\"c\"]\n Explanation: A subsequence that can be selected is [\"a\",\"b\",\"c\"] because groups[0] != groups[1] and groups[1] != groups[2]. Another subsequence that can be selected is [\"a\",\"b\",\"d\"] because groups[0] != groups[1] and groups[1] != groups[3]. It can be shown that the length of the longest subsequence of indices that satisfies the condition is 3.\n \"\"\"\n"}
{"task_id": "longest-unequal-adjacent-groups-subsequence-ii", "prompt": "def getWordsInLongestSubsequence(words: List[str], groups: List[int]) -> List[str]:\n \"\"\"\n You are given a string array words, and an array groups, both arrays having length n.\n The hamming distance between two strings of equal length is the number of positions at which the corresponding characters are different.\n You need to select the longest subsequence from an array of indices [0, 1, ..., n - 1], such that for the subsequence denoted as [i0, i1, ..., ik-1] having length k, the following holds:\n \n For adjacent indices in the subsequence, their corresponding groups are unequal, i.e., groups[ij] != groups[ij+1], for each j where 0 < j + 1 < k.\n words[ij] and words[ij+1] are equal in length, and the hamming distance between them is 1, where 0 < j + 1 < k, for all indices in the subsequence.\n \n Return a string array containing the words corresponding to the indices (in order) in the selected subsequence. If there are multiple answers, return any of them.\n Note: strings in words may be unequal in length.\n \n Example 1:\n \n >>> getWordsInLongestSubsequence(words = [\"bab\",\"dab\",\"cab\"], groups = [1,2,2])\n >>> [\"bab\",\"cab\"]\n Explanation: A subsequence that can be selected is [0,2].\n \n groups[0] != groups[2]\n words[0].length == words[2].length, and the hamming distance between them is 1.\n \n So, a valid answer is [words[0],words[2]] = [\"bab\",\"cab\"].\n Another subsequence that can be selected is [0,1].\n \n groups[0] != groups[1]\n words[0].length == words[1].length, and the hamming distance between them is 1.\n \n So, another valid answer is [words[0],words[1]] = [\"bab\",\"dab\"].\n It can be shown that the length of the longest subsequence of indices that satisfies the conditions is 2.\n \n Example 2:\n \n >>> getWordsInLongestSubsequence(words = [\"a\",\"b\",\"c\",\"d\"], groups = [1,2,3,4])\n >>> [\"a\",\"b\",\"c\",\"d\"]\n Explanation: We can select the subsequence [0,1,2,3].\n It satisfies both conditions.\n Hence, the answer is [words[0],words[1],words[2],words[3]] = [\"a\",\"b\",\"c\",\"d\"].\n It has the longest length among all subsequences of indices that satisfy the conditions.\n Hence, it is the only answer.\n \"\"\"\n"}
{"task_id": "count-of-sub-multisets-with-bounded-sum", "prompt": "def countSubMultisets(nums: List[int], l: int, r: int) -> int:\n \"\"\"\n You are given a 0-indexed array nums of non-negative integers, and two integers l and r.\n Return the count of sub-multisets within nums where the sum of elements in each subset falls within the inclusive range of [l, r].\n Since the answer may be large, return it modulo 109 + 7.\n A sub-multiset is an unordered collection of elements of the array in which a given value x can occur 0, 1, ..., occ[x] times, where occ[x] is the number of occurrences of x in the array.\n Note that:\n \n Two sub-multisets are the same if sorting both sub-multisets results in identical multisets.\n The sum of an empty multiset is 0.\n \n \n Example 1:\n \n >>> countSubMultisets(nums = [1,2,2,3], l = 6, r = 6)\n >>> 1\n Explanation: The only subset of nums that has a sum of 6 is {1, 2, 3}.\n \n Example 2:\n \n >>> countSubMultisets(nums = [2,1,4,2,7], l = 1, r = 5)\n >>> 7\n Explanation: The subsets of nums that have a sum within the range [1, 5] are {1}, {2}, {4}, {2, 2}, {1, 2}, {1, 4}, and {1, 2, 2}.\n \n Example 3:\n \n >>> countSubMultisets(nums = [1,2,1,3,5,2], l = 3, r = 5)\n >>> 9\n Explanation: The subsets of nums that have a sum within the range [3, 5] are {3}, {5}, {1, 2}, {1, 3}, {2, 2}, {2, 3}, {1, 1, 2}, {1, 1, 3}, and {1, 2, 2}.\n \"\"\"\n"}
{"task_id": "find-indices-with-index-and-value-difference-i", "prompt": "def findIndices(nums: List[int], indexDifference: int, valueDifference: int) -> List[int]:\n \"\"\"\n You are given a 0-indexed integer array nums having length n, an integer indexDifference, and an integer valueDifference.\n Your task is to find two indices i and j, both in the range [0, n - 1], that satisfy the following conditions:\n \n abs(i - j) >= indexDifference, and\n abs(nums[i] - nums[j]) >= valueDifference\n \n Return an integer array answer, where answer = [i, j] if there are two such indices, and answer = [-1, -1] otherwise. If there are multiple choices for the two indices, return any of them.\n Note: i and j may be equal.\n \n Example 1:\n \n >>> findIndices(nums = [5,1,4,1], indexDifference = 2, valueDifference = 4)\n >>> [0,3]\n Explanation: In this example, i = 0 and j = 3 can be selected.\n abs(0 - 3) >= 2 and abs(nums[0] - nums[3]) >= 4.\n Hence, a valid answer is [0,3].\n [3,0] is also a valid answer.\n \n Example 2:\n \n >>> findIndices(nums = [2,1], indexDifference = 0, valueDifference = 0)\n >>> [0,0]\n Explanation: In this example, i = 0 and j = 0 can be selected.\n abs(0 - 0) >= 0 and abs(nums[0] - nums[0]) >= 0.\n Hence, a valid answer is [0,0].\n Other valid answers are [0,1], [1,0], and [1,1].\n \n Example 3:\n \n >>> findIndices(nums = [1,2,3], indexDifference = 2, valueDifference = 4)\n >>> [-1,-1]\n Explanation: In this example, it can be shown that it is impossible to find two indices that satisfy both conditions.\n Hence, [-1,-1] is returned.\n \"\"\"\n"}
{"task_id": "shortest-and-lexicographically-smallest-beautiful-string", "prompt": "def shortestBeautifulSubstring(s: str, k: int) -> str:\n \"\"\"\n You are given a binary string s and a positive integer k.\n A substring of s is beautiful if the number of 1's in it is exactly k.\n Let len be the length of the shortest beautiful substring.\n Return the lexicographically smallest beautiful substring of string s with length equal to len. If s doesn't contain a beautiful substring, return an empty string.\n A string a is lexicographically larger than a string b (of the same length) if in the first position where a and b differ, a has a character strictly larger than the corresponding character in b.\n \n For example, \"abcd\" is lexicographically larger than \"abcc\" because the first position they differ is at the fourth character, and d is greater than c.\n \n \n Example 1:\n \n >>> shortestBeautifulSubstring(s = \"100011001\", k = 3)\n >>> \"11001\"\n Explanation: There are 7 beautiful substrings in this example:\n 1. The substring \"100011001\".\n 2. The substring \"100011001\".\n 3. The substring \"100011001\".\n 4. The substring \"100011001\".\n 5. The substring \"100011001\".\n 6. The substring \"100011001\".\n 7. The substring \"100011001\".\n The length of the shortest beautiful substring is 5.\n The lexicographically smallest beautiful substring with length 5 is the substring \"11001\".\n \n Example 2:\n \n >>> shortestBeautifulSubstring(s = \"1011\", k = 2)\n >>> \"11\"\n Explanation: There are 3 beautiful substrings in this example:\n 1. The substring \"1011\".\n 2. The substring \"1011\".\n 3. The substring \"1011\".\n The length of the shortest beautiful substring is 2.\n The lexicographically smallest beautiful substring with length 2 is the substring \"11\".\n \n Example 3:\n \n >>> shortestBeautifulSubstring(s = \"000\", k = 1)\n >>> \"\"\n Explanation: There are no beautiful substrings in this example.\n \"\"\"\n"}
{"task_id": "find-indices-with-index-and-value-difference-ii", "prompt": "def findIndices(nums: List[int], indexDifference: int, valueDifference: int) -> List[int]:\n \"\"\"\n You are given a 0-indexed integer array nums having length n, an integer indexDifference, and an integer valueDifference.\n Your task is to find two indices i and j, both in the range [0, n - 1], that satisfy the following conditions:\n \n abs(i - j) >= indexDifference, and\n abs(nums[i] - nums[j]) >= valueDifference\n \n Return an integer array answer, where answer = [i, j] if there are two such indices, and answer = [-1, -1] otherwise. If there are multiple choices for the two indices, return any of them.\n Note: i and j may be equal.\n \n Example 1:\n \n >>> findIndices(nums = [5,1,4,1], indexDifference = 2, valueDifference = 4)\n >>> [0,3]\n Explanation: In this example, i = 0 and j = 3 can be selected.\n abs(0 - 3) >= 2 and abs(nums[0] - nums[3]) >= 4.\n Hence, a valid answer is [0,3].\n [3,0] is also a valid answer.\n \n Example 2:\n \n >>> findIndices(nums = [2,1], indexDifference = 0, valueDifference = 0)\n >>> [0,0]\n Explanation: In this example, i = 0 and j = 0 can be selected.\n abs(0 - 0) >= 0 and abs(nums[0] - nums[0]) >= 0.\n Hence, a valid answer is [0,0].\n Other valid answers are [0,1], [1,0], and [1,1].\n \n Example 3:\n \n >>> findIndices(nums = [1,2,3], indexDifference = 2, valueDifference = 4)\n >>> [-1,-1]\n Explanation: In this example, it can be shown that it is impossible to find two indices that satisfy both conditions.\n Hence, [-1,-1] is returned.\n \"\"\"\n"}
{"task_id": "construct-product-matrix", "prompt": "def constructProductMatrix(grid: List[List[int]]) -> List[List[int]]:\n \"\"\"\n Given a 0-indexed 2D integer matrix grid of size n * m, we define a 0-indexed 2D matrix p of size n * m as the product matrix of grid if the following condition is met:\n \n Each element p[i][j] is calculated as the product of all elements in grid except for the element grid[i][j]. This product is then taken modulo 12345.\n \n Return the product matrix of grid.\n \n Example 1:\n \n >>> constructProductMatrix(grid = [[1,2],[3,4]])\n >>> [[24,12],[8,6]]\n Explanation: p[0][0] = grid[0][1] * grid[1][0] * grid[1][1] = 2 * 3 * 4 = 24\n p[0][1] = grid[0][0] * grid[1][0] * grid[1][1] = 1 * 3 * 4 = 12\n p[1][0] = grid[0][0] * grid[0][1] * grid[1][1] = 1 * 2 * 4 = 8\n p[1][1] = grid[0][0] * grid[0][1] * grid[1][0] = 1 * 2 * 3 = 6\n So the answer is [[24,12],[8,6]].\n Example 2:\n \n >>> constructProductMatrix(grid = [[12345],[2],[1]])\n >>> [[2],[0],[0]]\n Explanation: p[0][0] = grid[0][1] * grid[0][2] = 2 * 1 = 2.\n p[0][1] = grid[0][0] * grid[0][2] = 12345 * 1 = 12345. 12345 % 12345 = 0. So p[0][1] = 0.\n p[0][2] = grid[0][0] * grid[0][1] = 12345 * 2 = 24690. 24690 % 12345 = 0. So p[0][2] = 0.\n So the answer is [[2],[0],[0]].\n \"\"\"\n"}
{"task_id": "maximum-profitable-triplets-with-increasing-prices-i", "prompt": "def maxProfit(prices: List[int], profits: List[int]) -> int:\n \"\"\"\n Given the 0-indexed arrays prices and profits of length n. There are n items in an store where the ith item has a price of prices[i] and a profit of profits[i].\n We have to pick three items with the following condition:\n \n prices[i] < prices[j] < prices[k] where i < j < k.\n \n If we pick items with indices i, j and k satisfying the above condition, the profit would be profits[i] + profits[j] + profits[k].\n Return the maximum profit we can get, and -1 if it's not possible to pick three items with the given condition.\n \n Example 1:\n \n >>> maxProfit(prices = [10,2,3,4], profits = [100,2,7,10])\n >>> 19\n Explanation: We can't pick the item with index i=0 since there are no indices j and k such that the condition holds.\n So the only triplet we can pick, are the items with indices 1, 2 and 3 and it's a valid pick since prices[1] < prices[2] < prices[3].\n The answer would be sum of their profits which is 2 + 7 + 10 = 19.\n Example 2:\n \n >>> maxProfit(prices = [1,2,3,4,5], profits = [1,5,3,4,6])\n >>> 15\n Explanation: We can select any triplet of items since for each triplet of indices i, j and k such that i < j < k, the condition holds.\n Therefore the maximum profit we can get would be the 3 most profitable items which are indices 1, 3 and 4.\n The answer would be sum of their profits which is 5 + 4 + 6 = 15.\n Example 3:\n \n >>> maxProfit(prices = [4,3,2,1], profits = [33,20,19,87])\n >>> -1\n Explanation: We can't select any triplet of indices such that the condition holds, so we return -1.\n \"\"\"\n"}
{"task_id": "minimum-sum-of-mountain-triplets-i", "prompt": "def minimumSum(nums: List[int]) -> int:\n \"\"\"\n You are given a 0-indexed array nums of integers.\n A triplet of indices (i, j, k) is a mountain if:\n \n i < j < k\n nums[i] < nums[j] and nums[k] < nums[j]\n \n Return the minimum possible sum of a mountain triplet of nums. If no such triplet exists, return -1.\n \n Example 1:\n \n >>> minimumSum(nums = [8,6,1,5,3])\n >>> 9\n Explanation: Triplet (2, 3, 4) is a mountain triplet of sum 9 since:\n - 2 < 3 < 4\n - nums[2] < nums[3] and nums[4] < nums[3]\n And the sum of this triplet is nums[2] + nums[3] + nums[4] = 9. It can be shown that there are no mountain triplets with a sum of less than 9.\n \n Example 2:\n \n >>> minimumSum(nums = [5,4,8,7,10,2])\n >>> 13\n Explanation: Triplet (1, 3, 5) is a mountain triplet of sum 13 since:\n - 1 < 3 < 5\n - nums[1] < nums[3] and nums[5] < nums[3]\n And the sum of this triplet is nums[1] + nums[3] + nums[5] = 13. It can be shown that there are no mountain triplets with a sum of less than 13.\n \n Example 3:\n \n >>> minimumSum(nums = [6,5,4,3,4,5])\n >>> -1\n Explanation: It can be shown that there are no mountain triplets in nums.\n \"\"\"\n"}
{"task_id": "minimum-sum-of-mountain-triplets-ii", "prompt": "def minimumSum(nums: List[int]) -> int:\n \"\"\"\n You are given a 0-indexed array nums of integers.\n A triplet of indices (i, j, k) is a mountain if:\n \n i < j < k\n nums[i] < nums[j] and nums[k] < nums[j]\n \n Return the minimum possible sum of a mountain triplet of nums. If no such triplet exists, return -1.\n \n Example 1:\n \n >>> minimumSum(nums = [8,6,1,5,3])\n >>> 9\n Explanation: Triplet (2, 3, 4) is a mountain triplet of sum 9 since:\n - 2 < 3 < 4\n - nums[2] < nums[3] and nums[4] < nums[3]\n And the sum of this triplet is nums[2] + nums[3] + nums[4] = 9. It can be shown that there are no mountain triplets with a sum of less than 9.\n \n Example 2:\n \n >>> minimumSum(nums = [5,4,8,7,10,2])\n >>> 13\n Explanation: Triplet (1, 3, 5) is a mountain triplet of sum 13 since:\n - 1 < 3 < 5\n - nums[1] < nums[3] and nums[5] < nums[3]\n And the sum of this triplet is nums[1] + nums[3] + nums[5] = 13. It can be shown that there are no mountain triplets with a sum of less than 13.\n \n Example 3:\n \n >>> minimumSum(nums = [6,5,4,3,4,5])\n >>> -1\n Explanation: It can be shown that there are no mountain triplets in nums.\n \"\"\"\n"}
{"task_id": "minimum-changes-to-make-k-semi-palindromes", "prompt": "def minimumChanges(s: str, k: int) -> int:\n \"\"\"\n Given a string s and an integer k, partition s into k substrings such that the letter changes needed to make each substring a semi-palindrome\u00a0are minimized.\n Return the minimum number of letter changes required.\n A semi-palindrome is a special type of string that can be divided into palindromes based on a repeating pattern. To check if a string is a semi-palindrome:\u200b\n \n Choose a positive divisor d of the string's length. d can range from 1 up to, but not including, the string's length. For a string of length 1, it does not have a valid divisor as per this definition, since the only divisor is its length, which is not allowed.\n For a given divisor d, divide the string into groups where each group contains characters from the string that follow a repeating pattern of length d. Specifically, the first group consists of characters at positions 1, 1 + d, 1 + 2d, and so on; the second group includes characters at positions 2, 2 + d, 2 + 2d, etc.\n The string is considered a semi-palindrome if each of these groups forms a palindrome.\n \n Consider the string \"abcabc\":\n \n The length of \"abcabc\" is 6. Valid divisors are 1, 2, and 3.\n For d = 1: The entire string \"abcabc\" forms one group. Not a palindrome.\n For d = 2:\n \n Group 1 (positions 1, 3, 5): \"acb\"\n Group 2 (positions 2, 4, 6): \"bac\"\n Neither group forms a palindrome.\n \n \n For d = 3:\n \n Group 1 (positions 1, 4): \"aa\"\n Group 2 (positions 2, 5): \"bb\"\n Group 3 (positions 3, 6): \"cc\"\n All groups form palindromes. Therefore, \"abcabc\" is a semi-palindrome.\n \n \n \n \n Example 1:\n \n >>> minimumChanges(s = \"abcac\", k = 2)\n >>> 1\n Explanation: Divide s into \"ab\" and \"cac\". \"cac\" is already semi-palindrome. Change \"ab\" to \"aa\", it becomes semi-palindrome with d = 1.\n \n Example 2:\n \n >>> minimumChanges(s = \"abcdef\", k = 2)\n >>> 2\n Explanation: Divide s into substrings \"abc\" and \"def\". Each\u00a0needs one change to become semi-palindrome.\n \n Example 3:\n \n >>> minimumChanges(s = \"aabbaa\", k = 3)\n >>> 0\n Explanation: Divide s into substrings \"aa\", \"bb\" and \"aa\".\u00a0All are already semi-palindromes.\n \"\"\"\n"}
{"task_id": "number-of-ways-to-reach-destination-in-the-grid", "prompt": "def numberOfWays(n: int, m: int, k: int, source: List[int], dest: List[int]) -> int:\n \"\"\"\n You are given two integers n and m which represent the size of a 1-indexed grid. You are also given an integer k, a 1-indexed integer array source and a 1-indexed integer array dest, where source and dest are in the form [x, y] representing a cell on the given grid.\n You can move through the grid in the following way:\n \n You can go from cell [x1, y1] to cell [x2, y2] if either x1 == x2 or y1 == y2.\n Note that you can't move to the cell you are already in e.g. x1 == x2 and y1 == y2.\n \n Return the number of ways you can reach dest from source by moving through the grid exactly k times.\n Since the answer may be very large, return it modulo 109 + 7.\n \n Example 1:\n \n >>> numberOfWays(n = 3, m = 2, k = 2, source = [1,1], dest = [2,2])\n >>> 2\n Explanation: There are 2 possible sequences of reaching [2,2] from [1,1]:\n - [1,1] -> [1,2] -> [2,2]\n - [1,1] -> [2,1] -> [2,2]\n \n Example 2:\n \n >>> numberOfWays(n = 3, m = 4, k = 3, source = [1,2], dest = [2,3])\n >>> 9\n Explanation: There are 9 possible sequences of reaching [2,3] from [1,2]:\n - [1,2] -> [1,1] -> [1,3] -> [2,3]\n - [1,2] -> [1,1] -> [2,1] -> [2,3]\n - [1,2] -> [1,3] -> [3,3] -> [2,3]\n - [1,2] -> [1,4] -> [1,3] -> [2,3]\n - [1,2] -> [1,4] -> [2,4] -> [2,3]\n - [1,2] -> [2,2] -> [2,1] -> [2,3]\n - [1,2] -> [2,2] -> [2,4] -> [2,3]\n - [1,2] -> [3,2] -> [2,2] -> [2,3]\n - [1,2] -> [3,2] -> [3,3] -> [2,3]\n \"\"\"\n"}
{"task_id": "subarrays-distinct-element-sum-of-squares-i", "prompt": "def sumCounts(nums: List[int]) -> int:\n \"\"\"\n You are given a 0-indexed integer array nums.\n The distinct count of a subarray of nums is defined as:\n \n Let nums[i..j] be a subarray of nums consisting of all the indices from i to j such that 0 <= i <= j < nums.length. Then the number of distinct values in nums[i..j] is called the distinct count of nums[i..j].\n \n Return the sum of the squares of distinct counts of all subarrays of nums.\n A subarray is a contiguous non-empty sequence of elements within an array.\n \n Example 1:\n \n >>> sumCounts(nums = [1,2,1])\n >>> 15\n Explanation: Six possible subarrays are:\n [1]: 1 distinct value\n [2]: 1 distinct value\n [1]: 1 distinct value\n [1,2]: 2 distinct values\n [2,1]: 2 distinct values\n [1,2,1]: 2 distinct values\n The sum of the squares of the distinct counts in all subarrays is equal to 12 + 12 + 12 + 22 + 22 + 22 = 15.\n \n Example 2:\n \n >>> sumCounts(nums = [1,1])\n >>> 3\n Explanation: Three possible subarrays are:\n [1]: 1 distinct value\n [1]: 1 distinct value\n [1,1]: 1 distinct value\n The sum of the squares of the distinct counts in all subarrays is equal to 12 + 12 + 12 = 3.\n \"\"\"\n"}
{"task_id": "minimum-number-of-changes-to-make-binary-string-beautiful", "prompt": "def minChanges(s: str) -> int:\n \"\"\"\n You are given a 0-indexed binary string s having an even length.\n A string is beautiful if it's possible to partition it into one or more substrings such that:\n \n Each substring has an even length.\n Each substring contains only 1's or only 0's.\n \n You can change any character in s to 0 or 1.\n Return the minimum number of changes required to make the string s beautiful.\n \n Example 1:\n \n >>> minChanges(s = \"1001\")\n >>> 2\n Explanation: We change s[1] to 1 and s[3] to 0 to get string \"1100\".\n It can be seen that the string \"1100\" is beautiful because we can partition it into \"11|00\".\n It can be proven that 2 is the minimum number of changes needed to make the string beautiful.\n \n Example 2:\n \n >>> minChanges(s = \"10\")\n >>> 1\n Explanation: We change s[1] to 1 to get string \"11\".\n It can be seen that the string \"11\" is beautiful because we can partition it into \"11\".\n It can be proven that 1 is the minimum number of changes needed to make the string beautiful.\n \n Example 3:\n \n >>> minChanges(s = \"0000\")\n >>> 0\n Explanation: We don't need to make any changes as the string \"0000\" is beautiful already.\n \"\"\"\n"}
{"task_id": "length-of-the-longest-subsequence-that-sums-to-target", "prompt": "def lengthOfLongestSubsequence(nums: List[int], target: int) -> int:\n \"\"\"\n You are given a 0-indexed array of integers nums, and an integer target.\n Return the length of the longest subsequence of nums that sums up to target. If no such subsequence exists, return -1.\n 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.\n \n Example 1:\n \n >>> lengthOfLongestSubsequence(nums = [1,2,3,4,5], target = 9)\n >>> 3\n Explanation: There are 3 subsequences with a sum equal to 9: [4,5], [1,3,5], and [2,3,4]. The longest subsequences are [1,3,5], and [2,3,4]. Hence, the answer is 3.\n \n Example 2:\n \n >>> lengthOfLongestSubsequence(nums = [4,1,3,2,1,5], target = 7)\n >>> 4\n Explanation: There are 5 subsequences with a sum equal to 7: [4,3], [4,1,2], [4,2,1], [1,1,5], and [1,3,2,1]. The longest subsequence is [1,3,2,1]. Hence, the answer is 4.\n \n Example 3:\n \n >>> lengthOfLongestSubsequence(nums = [1,1,5,4,5], target = 3)\n >>> -1\n Explanation: It can be shown that nums has no subsequence that sums up to 3.\n \"\"\"\n"}
{"task_id": "subarrays-distinct-element-sum-of-squares-ii", "prompt": "def sumCounts(nums: List[int]) -> int:\n \"\"\"\n You are given a 0-indexed integer array nums.\n The distinct count of a subarray of nums is defined as:\n \n Let nums[i..j] be a subarray of nums consisting of all the indices from i to j such that 0 <= i <= j < nums.length. Then the number of distinct values in nums[i..j] is called the distinct count of nums[i..j].\n \n Return the sum of the squares of distinct counts of all subarrays of nums.\n Since the answer may be very large, return it modulo 109 + 7.\n A subarray is a contiguous non-empty sequence of elements within an array.\n \n Example 1:\n \n >>> sumCounts(nums = [1,2,1])\n >>> 15\n Explanation: Six possible subarrays are:\n [1]: 1 distinct value\n [2]: 1 distinct value\n [1]: 1 distinct value\n [1,2]: 2 distinct values\n [2,1]: 2 distinct values\n [1,2,1]: 2 distinct values\n The sum of the squares of the distinct counts in all subarrays is equal to 12 + 12 + 12 + 22 + 22 + 22 = 15.\n \n Example 2:\n \n >>> sumCounts(nums = [2,2])\n >>> 3\n Explanation: Three possible subarrays are:\n [2]: 1 distinct value\n [2]: 1 distinct value\n [2,2]: 1 distinct value\n The sum of the squares of the distinct counts in all subarrays is equal to 12 + 12 + 12 = 3.\n \"\"\"\n"}
{"task_id": "find-the-k-or-of-an-array", "prompt": "def findKOr(nums: List[int], k: int) -> int:\n \"\"\"\n You are given an integer array nums, and an integer k. Let's introduce\u00a0K-or operation by extending the standard bitwise OR. In K-or, a bit position in the result is set to 1\u00a0if at least k numbers in nums have a 1 in that position.\n Return the K-or of nums.\n \n Example 1:\n \n >>> findKOr(nums = [7,12,9,8,9,15], k = 4)\n >>> 9\n Explanation:\n Represent numbers in binary:\n \n \n \n Number\n Bit 3\n Bit 2\n Bit 1\n Bit 0\n \n \n 7\n 0\n 1\n 1\n 1\n \n \n 12\n 1\n 1\n 0\n 0\n \n \n 9\n 1\n 0\n 0\n 1\n \n \n 8\n 1\n 0\n 0\n 0\n \n \n 9\n 1\n 0\n 0\n 1\n \n \n 15\n 1\n 1\n 1\n 1\n \n \n Result = 9\n 1\n 0\n 0\n 1\n \n \n \n Bit 0 is set in 7, 9, 9, and 15. Bit 3 is set in 12, 9, 8, 9, and 15.\n Only bits 0 and 3 qualify. The result is (1001)2 = 9.\n \n Example 2:\n \n >>> findKOr(nums = [2,12,1,11,4,5], k = 6)\n >>> 0\n Explanation:\u00a0No bit appears as 1 in all six array numbers, as required for K-or with k = 6. Thus, the result is 0.\n \n Example 3:\n \n >>> findKOr(nums = [10,8,5,9,11,6,8], k = 1)\n >>> 15\n Explanation: Since k == 1, the 1-or of the array is equal to the bitwise OR of all its elements. Hence, the answer is 10 OR 8 OR 5 OR 9 OR 11 OR 6 OR 8 = 15.\n \"\"\"\n"}
{"task_id": "minimum-equal-sum-of-two-arrays-after-replacing-zeros", "prompt": "def minSum(nums1: List[int], nums2: List[int]) -> int:\n \"\"\"\n You are given two arrays nums1 and nums2 consisting of positive integers.\n You have to replace all the 0's in both arrays with strictly positive integers such that the sum of elements of both arrays becomes equal.\n Return the minimum equal sum you can obtain, or -1 if it is impossible.\n \n Example 1:\n \n >>> minSum(nums1 = [3,2,0,1,0], nums2 = [6,5,0])\n >>> 12\n Explanation: We can replace 0's in the following way:\n - Replace the two 0's in nums1 with the values 2 and 4. The resulting array is nums1 = [3,2,2,1,4].\n - Replace the 0 in nums2 with the value 1. The resulting array is nums2 = [6,5,1].\n Both arrays have an equal sum of 12. It can be shown that it is the minimum sum we can obtain.\n \n Example 2:\n \n >>> minSum(nums1 = [2,0,2,0], nums2 = [1,4])\n >>> -1\n Explanation: It is impossible to make the sum of both arrays equal.\n \"\"\"\n"}
{"task_id": "minimum-increment-operations-to-make-array-beautiful", "prompt": "def minIncrementOperations(nums: List[int], k: int) -> int:\n \"\"\"\n You are given a 0-indexed integer array nums having length n, and an integer k.\n You can perform the following increment operation any number of times (including zero):\n \n Choose an index i in the range [0, n - 1], and increase nums[i] by 1.\n \n An array is considered beautiful if, for any subarray with a size of 3 or more, its maximum element is greater than or equal to k.\n Return an integer denoting the minimum number of increment operations needed to make nums beautiful.\n A subarray is a contiguous non-empty sequence of elements within an array.\n \n Example 1:\n \n >>> minIncrementOperations(nums = [2,3,0,0,2], k = 4)\n >>> 3\n Explanation: We can perform the following increment operations to make nums beautiful:\n Choose index i = 1 and increase nums[1] by 1 -> [2,4,0,0,2].\n Choose index i = 4 and increase nums[4] by 1 -> [2,4,0,0,3].\n Choose index i = 4 and increase nums[4] by 1 -> [2,4,0,0,4].\n The subarrays with a size of 3 or more are: [2,4,0], [4,0,0], [0,0,4], [2,4,0,0], [4,0,0,4], [2,4,0,0,4].\n In all the subarrays, the maximum element is equal to k = 4, so nums is now beautiful.\n It can be shown that nums cannot be made beautiful with fewer than 3 increment operations.\n Hence, the answer is 3.\n \n Example 2:\n \n >>> minIncrementOperations(nums = [0,1,3,3], k = 5)\n >>> 2\n Explanation: We can perform the following increment operations to make nums beautiful:\n Choose index i = 2 and increase nums[2] by 1 -> [0,1,4,3].\n Choose index i = 2 and increase nums[2] by 1 -> [0,1,5,3].\n The subarrays with a size of 3 or more are: [0,1,5], [1,5,3], [0,1,5,3].\n In all the subarrays, the maximum element is equal to k = 5, so nums is now beautiful.\n It can be shown that nums cannot be made beautiful with fewer than 2 increment operations.\n Hence, the answer is 2.\n \n Example 3:\n \n >>> minIncrementOperations(nums = [1,1,2], k = 1)\n >>> 0\n Explanation: The only subarray with a size of 3 or more in this example is [1,1,2].\n The maximum element, 2, is already greater than k = 1, so we don't need any increment operation.\n Hence, the answer is 0.\n \"\"\"\n"}
{"task_id": "maximum-points-after-collecting-coins-from-all-nodes", "prompt": "def maximumPoints(edges: List[List[int]], coins: List[int], k: int) -> int:\n \"\"\"\n There exists an undirected tree rooted at node 0 with n nodes labeled from 0 to n - 1. You are given a 2D integer array edges of length n - 1, where edges[i] = [ai, bi] indicates that there is an edge between nodes ai and bi in the tree. You are also given a 0-indexed array coins of size n where coins[i] indicates the number of coins in the vertex i, and an integer k.\n Starting from the root, you have to collect all the coins such that the coins at a node can only be collected if the coins of its ancestors have been already collected.\n Coins at nodei can be collected in one of the following ways:\n \n Collect all the coins, but you will get coins[i] - k points. If coins[i] - k is negative then you will lose abs(coins[i] - k) points.\n Collect all the coins, but you will get floor(coins[i] / 2) points. If this way is used, then for all the nodej present in the subtree of nodei, coins[j] will get reduced to floor(coins[j] / 2).\n \n Return the maximum points you can get after collecting the coins from all the tree nodes.\n \n Example 1:\n \n \n >>> maximumPoints(edges = [[0,1],[1,2],[2,3]], coins = [10,10,3,3], k = 5)\n >>> 11\n Explanation:\n Collect all the coins from node 0 using the first way. Total points = 10 - 5 = 5.\n Collect all the coins from node 1 using the first way. Total points = 5 + (10 - 5) = 10.\n Collect all the coins from node 2 using the second way so coins left at node 3 will be floor(3 / 2) = 1. Total points = 10 + floor(3 / 2) = 11.\n Collect all the coins from node 3 using the second way. Total points = 11 + floor(1 / 2) = 11.\n It can be shown that the maximum points we can get after collecting coins from all the nodes is 11.\n \n Example 2:\n \n \n >>> maximumPoints(edges = [[0,1],[0,2]], coins = [8,4,4], k = 0)\n >>> 16\n Explanation:\n Coins will be collected from all the nodes using the first way. Therefore, total points = (8 - 0) + (4 - 0) + (4 - 0) = 16.\n \"\"\"\n"}
{"task_id": "maximum-profitable-triplets-with-increasing-prices-ii", "prompt": "def maxProfit(prices: List[int], profits: List[int]) -> int:\n \"\"\"\n Given the 0-indexed arrays prices and profits of length n. There are n items in an store where the ith item has a price of prices[i] and a profit of profits[i].\n We have to pick three items with the following condition:\n \n prices[i] < prices[j] < prices[k] where i < j < k.\n \n If we pick items with indices i, j and k satisfying the above condition, the profit would be profits[i] + profits[j] + profits[k].\n Return the maximum profit we can get, and -1 if it's not possible to pick three items with the given condition.\n \n Example 1:\n \n >>> maxProfit(prices = [10,2,3,4], profits = [100,2,7,10])\n >>> 19\n Explanation: We can't pick the item with index i=0 since there are no indices j and k such that the condition holds.\n So the only triplet we can pick, are the items with indices 1, 2 and 3 and it's a valid pick since prices[1] < prices[2] < prices[3].\n The answer would be sum of their profits which is 2 + 7 + 10 = 19.\n Example 2:\n \n >>> maxProfit(prices = [1,2,3,4,5], profits = [1,5,3,4,6])\n >>> 15\n Explanation: We can select any triplet of items since for each triplet of indices i, j and k such that i < j < k, the condition holds.\n Therefore the maximum profit we can get would be the 3 most profitable items which are indices 1, 3 and 4.\n The answer would be sum of their profits which is 5 + 4 + 6 = 15.\n Example 3:\n \n >>> maxProfit(prices = [4,3,2,1], profits = [33,20,19,87])\n >>> -1\n Explanation: We can't select any triplet of indices such that the condition holds, so we return -1.\n \"\"\"\n"}
{"task_id": "find-champion-i", "prompt": "def findChampion(grid: List[List[int]]) -> int:\n \"\"\"\n There are n teams numbered from 0 to n - 1 in a tournament.\n Given a 0-indexed 2D boolean matrix grid of size n * n. For all i, j that 0 <= i, j <= n - 1 and i != j team i is stronger than team j if grid[i][j] == 1, otherwise, team j is stronger than team i.\n Team a will be the champion of the tournament if there is no team b that is stronger than team a.\n Return the team that will be the champion of the tournament.\n \n Example 1:\n \n >>> findChampion(grid = [[0,1],[0,0]])\n >>> 0\n Explanation: There are two teams in this tournament.\n grid[0][1] == 1 means that team 0 is stronger than team 1. So team 0 will be the champion.\n \n Example 2:\n \n >>> findChampion(grid = [[0,0,1],[1,0,1],[0,0,0]])\n >>> 1\n Explanation: There are three teams in this tournament.\n grid[1][0] == 1 means that team 1 is stronger than team 0.\n grid[1][2] == 1 means that team 1 is stronger than team 2.\n So team 1 will be the champion.\n \"\"\"\n"}
{"task_id": "find-champion-ii", "prompt": "def findChampion(n: int, edges: List[List[int]]) -> int:\n \"\"\"\n There are n teams numbered from 0 to n - 1 in a tournament; each team is also a node in a DAG.\n You are given the integer n and a 0-indexed 2D integer array edges of length m representing the DAG, where edges[i] = [ui, vi] indicates that there is a directed edge from team ui to team vi in the graph.\n A directed edge from a to b in the graph means that team a is stronger than team b and team b is weaker than team a.\n Team a will be the champion of the tournament if there is no team b that is stronger than team a.\n Return the team that will be the champion of the tournament if there is a unique champion, otherwise, return -1.\n Notes\n \n A cycle is a series of nodes a1, a2, ..., an, an+1 such that node a1 is the same node as node an+1, the nodes a1, a2, ..., an are distinct, and there is a directed edge from the node ai to node ai+1 for every i in the range [1, n].\n A DAG is a directed graph that does not have any cycle.\n \n \n Example 1:\n \n \n >>> findChampion(n = 3, edges = [[0,1],[1,2]])\n >>> 0\n Explanation: Team 1 is weaker than team 0. Team 2 is weaker than team 1. So the champion is team 0.\n \n Example 2:\n \n \n >>> findChampion(n = 4, edges = [[0,2],[1,3],[1,2]])\n >>> -1\n Explanation: Team 2 is weaker than team 0 and team 1. Team 3 is weaker than team 1. But team 1 and team 0 are not weaker than any other teams. So the answer is -1.\n \"\"\"\n"}
{"task_id": "maximum-score-after-applying-operations-on-a-tree", "prompt": "def maximumScoreAfterOperations(edges: List[List[int]], values: List[int]) -> int:\n \"\"\"\n There is an undirected tree with n nodes labeled from 0 to n - 1, and rooted at node 0. You are given\u00a0a 2D integer array edges of length n - 1, where edges[i] = [ai, bi] indicates that there is an edge between nodes ai and bi in the tree.\n You are also given a 0-indexed integer array values of length n, where values[i] is the value associated with the ith node.\n You start with a score of 0. In one operation, you can:\n \n Pick any node i.\n Add values[i] to your score.\n Set values[i] to 0.\n \n A tree is healthy if the sum of values on the path from the root to any leaf node is different than zero.\n Return the maximum score you can obtain after performing these operations on the tree any number of times so that it remains healthy.\n \n Example 1:\n \n \n >>> maximumScoreAfterOperations(edges = [[0,1],[0,2],[0,3],[2,4],[4,5]], values = [5,2,5,2,1,1])\n >>> 11\n Explanation: We can choose nodes 1, 2, 3, 4, and 5. The value of the root is non-zero. Hence, the sum of values on the path from the root to any leaf is different than zero. Therefore, the tree is healthy and the score is values[1] + values[2] + values[3] + values[4] + values[5] = 11.\n It can be shown that 11 is the maximum score obtainable after any number of operations on the tree.\n \n Example 2:\n \n \n >>> maximumScoreAfterOperations(edges = [[0,1],[0,2],[1,3],[1,4],[2,5],[2,6]], values = [20,10,9,7,4,3,5])\n >>> 40\n Explanation: We can choose nodes 0, 2, 3, and 4.\n - The sum of values on the path from 0 to 4 is equal to 10.\n - The sum of values on the path from 0 to 3 is equal to 10.\n - The sum of values on the path from 0 to 5 is equal to 3.\n - The sum of values on the path from 0 to 6 is equal to 5.\n Therefore, the tree is healthy and the score is values[0] + values[2] + values[3] + values[4] = 40.\n It can be shown that 40 is the maximum score obtainable after any number of operations on the tree.\n \"\"\"\n"}
{"task_id": "maximum-balanced-subsequence-sum", "prompt": "def maxBalancedSubsequenceSum(nums: List[int]) -> int:\n \"\"\"\n You are given a 0-indexed integer array nums.\n A subsequence of nums having length k and consisting of indices i0\u00a0<\u00a0i1 <\u00a0... < ik-1 is balanced if the following holds:\n \n nums[ij] - nums[ij-1] >= ij - ij-1, for every j in the range [1, k - 1].\n \n A subsequence of nums having length 1 is considered balanced.\n Return an integer denoting the maximum possible sum of elements in a balanced subsequence of nums.\n A subsequence of an array is a new non-empty array that is formed from the original array by deleting some (possibly none) of the elements without disturbing the relative positions of the remaining elements.\n \n Example 1:\n \n >>> maxBalancedSubsequenceSum(nums = [3,3,5,6])\n >>> 14\n Explanation: In this example, the subsequence [3,5,6] consisting of indices 0, 2, and 3 can be selected.\n nums[2] - nums[0] >= 2 - 0.\n nums[3] - nums[2] >= 3 - 2.\n Hence, it is a balanced subsequence, and its sum is the maximum among the balanced subsequences of nums.\n The subsequence consisting of indices 1, 2, and 3 is also valid.\n It can be shown that it is not possible to get a balanced subsequence with a sum greater than 14.\n Example 2:\n \n >>> maxBalancedSubsequenceSum(nums = [5,-1,-3,8])\n >>> 13\n Explanation: In this example, the subsequence [5,8] consisting of indices 0 and 3 can be selected.\n nums[3] - nums[0] >= 3 - 0.\n Hence, it is a balanced subsequence, and its sum is the maximum among the balanced subsequences of nums.\n It can be shown that it is not possible to get a balanced subsequence with a sum greater than 13.\n \n Example 3:\n \n >>> maxBalancedSubsequenceSum(nums = [-2,-1])\n >>> -1\n Explanation: In this example, the subsequence [-1] can be selected.\n It is a balanced subsequence, and its sum is the maximum among the balanced subsequences of nums.\n \"\"\"\n"}
{"task_id": "distribute-candies-among-children-iii", "prompt": "def distributeCandies(n: int, limit: int) -> int:\n \"\"\"\n You are given two positive integers n and limit.\n Return the total number of ways to distribute n candies among 3 children such that no child gets more than limit candies.\n \n Example 1:\n \n >>> distributeCandies(n = 5, limit = 2)\n >>> 3\n Explanation: There are 3 ways to distribute 5 candies such that no child gets more than 2 candies: (1, 2, 2), (2, 1, 2) and (2, 2, 1).\n \n Example 2:\n \n >>> distributeCandies(n = 3, limit = 3)\n >>> 10\n Explanation: There are 10 ways to distribute 3 candies such that no child gets more than 3 candies: (0, 0, 3), (0, 1, 2), (0, 2, 1), (0, 3, 0), (1, 0, 2), (1, 1, 1), (1, 2, 0), (2, 0, 1), (2, 1, 0) and (3, 0, 0).\n \"\"\"\n"}
{"task_id": "distribute-candies-among-children-i", "prompt": "def distributeCandies(n: int, limit: int) -> int:\n \"\"\"\n You are given two positive integers n and limit.\n Return the total number of ways to distribute n candies among 3 children such that no child gets more than limit candies.\n \n Example 1:\n \n >>> distributeCandies(n = 5, limit = 2)\n >>> 3\n Explanation: There are 3 ways to distribute 5 candies such that no child gets more than 2 candies: (1, 2, 2), (2, 1, 2) and (2, 2, 1).\n \n Example 2:\n \n >>> distributeCandies(n = 3, limit = 3)\n >>> 10\n Explanation: There are 10 ways to distribute 3 candies such that no child gets more than 3 candies: (0, 0, 3), (0, 1, 2), (0, 2, 1), (0, 3, 0), (1, 0, 2), (1, 1, 1), (1, 2, 0), (2, 0, 1), (2, 1, 0) and (3, 0, 0).\n \"\"\"\n"}
{"task_id": "distribute-candies-among-children-ii", "prompt": "def distributeCandies(n: int, limit: int) -> int:\n \"\"\"\n You are given two positive integers n and limit.\n Return the total number of ways to distribute n candies among 3 children such that no child gets more than limit candies.\n \n Example 1:\n \n >>> distributeCandies(n = 5, limit = 2)\n >>> 3\n Explanation: There are 3 ways to distribute 5 candies such that no child gets more than 2 candies: (1, 2, 2), (2, 1, 2) and (2, 2, 1).\n \n Example 2:\n \n >>> distributeCandies(n = 3, limit = 3)\n >>> 10\n Explanation: There are 10 ways to distribute 3 candies such that no child gets more than 3 candies: (0, 0, 3), (0, 1, 2), (0, 2, 1), (0, 3, 0), (1, 0, 2), (1, 1, 1), (1, 2, 0), (2, 0, 1), (2, 1, 0) and (3, 0, 0).\n \"\"\"\n"}
{"task_id": "number-of-strings-which-can-be-rearranged-to-contain-substring", "prompt": "def stringCount(n: int) -> int:\n \"\"\"\n You are given an integer n.\n A string s is called good if it contains only lowercase English characters and it is possible to rearrange the characters of s such that the new string contains \"leet\" as a substring.\n For example:\n \n The string \"lteer\" is good because we can rearrange it to form \"leetr\" .\n \"letl\" is not good because we cannot rearrange it to contain \"leet\" as a substring.\n \n Return the total number of good strings of length n.\n Since the answer may be large, return it modulo 109 + 7.\n A substring is a contiguous sequence of characters within a string.\n \n \n Example 1:\n \n >>> stringCount(n = 4)\n >>> 12\n Explanation: The 12 strings which can be rearranged to have \"leet\" as a substring are: \"eelt\", \"eetl\", \"elet\", \"elte\", \"etel\", \"etle\", \"leet\", \"lete\", \"ltee\", \"teel\", \"tele\", and \"tlee\".\n \n Example 2:\n \n >>> stringCount(n = 10)\n >>> 83943898\n Explanation: The number of strings with length 10 which can be rearranged to have \"leet\" as a substring is 526083947580. Hence the answer is 526083947580 % (109 + 7) = 83943898.\n \"\"\"\n"}
{"task_id": "maximum-spending-after-buying-items", "prompt": "def maxSpending(values: List[List[int]]) -> int:\n \"\"\"\n You are given a 0-indexed m * n integer matrix values, representing the values of m * n different items in m different shops. Each shop has n items where the jth item in the ith shop has a value of values[i][j]. Additionally, the items in the ith shop are sorted in non-increasing order of value. That is, values[i][j] >= values[i][j + 1] for all 0 <= j < n - 1.\n On each day, you would like to buy a single item from one of the shops. Specifically, On the dth day you can:\n \n Pick any shop i.\n Buy the rightmost available item j for the price of values[i][j] * d. That is, find the greatest index j such that item j was never bought before, and buy it for the price of values[i][j] * d.\n \n Note that all items are pairwise different. For example, if you have bought item 0 from shop 1, you can still buy item 0 from any other shop.\n Return the maximum amount of money that can be spent on buying all m * n products.\n \n Example 1:\n \n >>> maxSpending(values = [[8,5,2],[6,4,1],[9,7,3]])\n >>> 285\n Explanation: On the first day, we buy product 2 from shop 1 for a price of values[1][2] * 1 = 1.\n On the second day, we buy product 2 from shop 0 for a price of values[0][2] * 2 = 4.\n On the third day, we buy product 2 from shop 2 for a price of values[2][2] * 3 = 9.\n On the fourth day, we buy product 1 from shop 1 for a price of values[1][1] * 4 = 16.\n On the fifth day, we buy product 1 from shop 0 for a price of values[0][1] * 5 = 25.\n On the sixth day, we buy product 0 from shop 1 for a price of values[1][0] * 6 = 36.\n On the seventh day, we buy product 1 from shop 2 for a price of values[2][1] * 7 = 49.\n On the eighth day, we buy product 0 from shop 0 for a price of values[0][0] * 8 = 64.\n On the ninth day, we buy product 0 from shop 2 for a price of values[2][0] * 9 = 81.\n Hence, our total spending is equal to 285.\n It can be shown that 285 is the maximum amount of money that can be spent buying all m * n products.\n \n Example 2:\n \n >>> maxSpending(values = [[10,8,6,4,2],[9,7,5,3,2]])\n >>> 386\n Explanation: On the first day, we buy product 4 from shop 0 for a price of values[0][4] * 1 = 2.\n On the second day, we buy product 4 from shop 1 for a price of values[1][4] * 2 = 4.\n On the third day, we buy product 3 from shop 1 for a price of values[1][3] * 3 = 9.\n On the fourth day, we buy product 3 from shop 0 for a price of values[0][3] * 4 = 16.\n On the fifth day, we buy product 2 from shop 1 for a price of values[1][2] * 5 = 25.\n On the sixth day, we buy product 2 from shop 0 for a price of values[0][2] * 6 = 36.\n On the seventh day, we buy product 1 from shop 1 for a price of values[1][1] * 7 = 49.\n On the eighth day, we buy product 1 from shop 0 for a price of values[0][1] * 8 = 64\n On the ninth day, we buy product 0 from shop 1 for a price of values[1][0] * 9 = 81.\n On the tenth day, we buy product 0 from shop 0 for a price of values[0][0] * 10 = 100.\n Hence, our total spending is equal to 386.\n It can be shown that 386 is the maximum amount of money that can be spent buying all m * n products.\n \"\"\"\n"}
{"task_id": "maximum-strong-pair-xor-i", "prompt": "def maximumStrongPairXor(nums: List[int]) -> int:\n \"\"\"\n You are given a 0-indexed integer array nums. A pair of integers x and y is called a strong pair if it satisfies the condition:\n \n |x - y| <= min(x, y)\n \n You need to select two integers from nums such that they form a strong pair and their bitwise XOR is the maximum among all strong pairs in the array.\n Return the maximum XOR value out of all possible strong pairs in the array nums.\n Note that you can pick the same integer twice to form a pair.\n \n Example 1:\n \n >>> maximumStrongPairXor(nums = [1,2,3,4,5])\n >>> 7\n Explanation: There are 11 strong pairs in the array nums: (1, 1), (1, 2), (2, 2), (2, 3), (2, 4), (3, 3), (3, 4), (3, 5), (4, 4), (4, 5) and (5, 5).\n The maximum XOR possible from these pairs is 3 XOR 4 = 7.\n \n Example 2:\n \n >>> maximumStrongPairXor(nums = [10,100])\n >>> 0\n Explanation: There are 2 strong pairs in the array nums: (10, 10) and (100, 100).\n The maximum XOR possible from these pairs is 10 XOR 10 = 0 since the pair (100, 100) also gives 100 XOR 100 = 0.\n \n Example 3:\n \n >>> maximumStrongPairXor(nums = [5,6,25,30])\n >>> 7\n Explanation: There are 6 strong pairs in the array nums: (5, 5), (5, 6), (6, 6), (25, 25), (25, 30) and (30, 30).\n The maximum XOR possible from these pairs is 25 XOR 30 = 7 since the only other non-zero XOR value is 5 XOR 6 = 3.\n \"\"\"\n"}
{"task_id": "high-access-employees", "prompt": "def findHighAccessEmployees(access_times: List[List[str]]) -> List[str]:\n \"\"\"\n You are given a 2D 0-indexed array of strings, access_times, with size n. For each i where 0 <= i <= n - 1, access_times[i][0] represents the name of an employee, and access_times[i][1] represents the access time of that employee. All entries in access_times are within the same day.\n The access time is represented as four digits using a 24-hour time format, for example, \"0800\" or \"2250\".\n An employee is said to be high-access if he has accessed the system three or more times within a one-hour period.\n Times with exactly one hour of difference are not considered part of the same one-hour period. For example, \"0815\" and \"0915\" are not part of the same one-hour period.\n Access times at the start and end of the day are not counted within the same one-hour period. For example, \"0005\" and \"2350\" are not part of the same one-hour period.\n Return a list that contains the names of high-access employees with any order you want.\n \n Example 1:\n \n >>> findHighAccessEmployees(access_times = [[\"a\",\"0549\"],[\"b\",\"0457\"],[\"a\",\"0532\"],[\"a\",\"0621\"],[\"b\",\"0540\"]])\n >>> [\"a\"]\n Explanation: \"a\" has three access times in the one-hour period of [05:32, 06:31] which are 05:32, 05:49, and 06:21.\n But \"b\" does not have more than two access times at all.\n So the answer is [\"a\"].\n Example 2:\n \n >>> findHighAccessEmployees(access_times = [[\"d\",\"0002\"],[\"c\",\"0808\"],[\"c\",\"0829\"],[\"e\",\"0215\"],[\"d\",\"1508\"],[\"d\",\"1444\"],[\"d\",\"1410\"],[\"c\",\"0809\"]])\n >>> [\"c\",\"d\"]\n Explanation: \"c\" has three access times in the one-hour period of [08:08, 09:07] which are 08:08, 08:09, and 08:29.\n \"d\" has also three access times in the one-hour period of [14:10, 15:09] which are 14:10, 14:44, and 15:08.\n However, \"e\" has just one access time, so it can not be in the answer and the final answer is [\"c\",\"d\"].\n Example 3:\n \n >>> findHighAccessEmployees(access_times = [[\"cd\",\"1025\"],[\"ab\",\"1025\"],[\"cd\",\"1046\"],[\"cd\",\"1055\"],[\"ab\",\"1124\"],[\"ab\",\"1120\"]])\n >>> [\"ab\",\"cd\"]\n Explanation: \"ab\" has three access times in the one-hour period of [10:25, 11:24] which are 10:25, 11:20, and 11:24.\n \"cd\" has also three access times in the one-hour period of [10:25, 11:24] which are 10:25, 10:46, and 10:55.\n So the answer is [\"ab\",\"cd\"].\n \"\"\"\n"}
{"task_id": "minimum-operations-to-maximize-last-elements-in-arrays", "prompt": "def minOperations(nums1: List[int], nums2: List[int]) -> int:\n \"\"\"\n You are given two 0-indexed integer arrays, nums1 and nums2, both having length n.\n You are allowed to perform a series of operations (possibly none).\n In an operation, you select an index i in the range [0, n - 1] and swap the values of nums1[i] and nums2[i].\n Your task is to find the minimum number of operations required to satisfy the following conditions:\n \n nums1[n - 1] is equal to the maximum value among all elements of nums1, i.e., nums1[n - 1] = max(nums1[0], nums1[1], ..., nums1[n - 1]).\n nums2[n - 1] is equal to the maximum value among all elements of nums2, i.e., nums2[n - 1] = max(nums2[0], nums2[1], ..., nums2[n - 1]).\n \n Return an integer denoting the minimum number of operations needed to meet both conditions, or -1 if it is impossible to satisfy both conditions.\n \n Example 1:\n \n >>> minOperations(nums1 = [1,2,7], nums2 = [4,5,3])\n >>> 1\n Explanation: In this example, an operation can be performed using index i = 2.\n When nums1[2] and nums2[2] are swapped, nums1 becomes [1,2,3] and nums2 becomes [4,5,7].\n Both conditions are now satisfied.\n It can be shown that the minimum number of operations needed to be performed is 1.\n So, the answer is 1.\n \n Example 2:\n \n >>> minOperations(nums1 = [2,3,4,5,9], nums2 = [8,8,4,4,4])\n >>> 2\n Explanation: In this example, the following operations can be performed:\n First operation using index i = 4.\n When nums1[4] and nums2[4] are swapped, nums1 becomes [2,3,4,5,4], and nums2 becomes [8,8,4,4,9].\n Another operation using index i = 3.\n When nums1[3] and nums2[3] are swapped, nums1 becomes [2,3,4,4,4], and nums2 becomes [8,8,4,5,9].\n Both conditions are now satisfied.\n It can be shown that the minimum number of operations needed to be performed is 2.\n So, the answer is 2.\n \n Example 3:\n \n >>> minOperations(nums1 = [1,5,4], nums2 = [2,5,3])\n >>> -1\n Explanation: In this example, it is not possible to satisfy both conditions.\n So, the answer is -1.\n \"\"\"\n"}
{"task_id": "maximum-strong-pair-xor-ii", "prompt": "def maximumStrongPairXor(nums: List[int]) -> int:\n \"\"\"\n You are given a 0-indexed integer array nums. A pair of integers x and y is called a strong pair if it satisfies the condition:\n \n |x - y| <= min(x, y)\n \n You need to select two integers from nums such that they form a strong pair and their bitwise XOR is the maximum among all strong pairs in the array.\n Return the maximum XOR value out of all possible strong pairs in the array nums.\n Note that you can pick the same integer twice to form a pair.\n \n Example 1:\n \n >>> maximumStrongPairXor(nums = [1,2,3,4,5])\n >>> 7\n Explanation: There are 11 strong pairs in the array nums: (1, 1), (1, 2), (2, 2), (2, 3), (2, 4), (3, 3), (3, 4), (3, 5), (4, 4), (4, 5) and (5, 5).\n The maximum XOR possible from these pairs is 3 XOR 4 = 7.\n \n Example 2:\n \n >>> maximumStrongPairXor(nums = [10,100])\n >>> 0\n Explanation: There are 2 strong pairs in the array nums: (10, 10) and (100, 100).\n The maximum XOR possible from these pairs is 10 XOR 10 = 0 since the pair (100, 100) also gives 100 XOR 100 = 0.\n \n Example 3:\n \n >>> maximumStrongPairXor(nums = [500,520,2500,3000])\n >>> 1020\n Explanation: There are 6 strong pairs in the array nums: (500, 500), (500, 520), (520, 520), (2500, 2500), (2500, 3000) and (3000, 3000).\n The maximum XOR possible from these pairs is 500 XOR 520 = 1020 since the only other non-zero XOR value is 2500 XOR 3000 = 636.\n \"\"\"\n"}
{"task_id": "make-three-strings-equal", "prompt": "def findMinimumOperations(s1: str, s2: str, s3: str) -> int:\n \"\"\"\n You are given three strings: s1, s2, and s3. In one operation you can choose one of these strings and delete its rightmost character. Note that you cannot completely empty a string.\n Return the minimum number of operations required to make the strings equal. If it is impossible to make them equal, return -1.\n \n Example 1:\n \n >>> findMinimumOperations(s1 = \"abc\", s2 = \"abb\", s3 = \"ab\")\n >>> 2\n Explanation:\u00a0Deleting the rightmost character from both s1 and s2 will result in three equal strings.\n \n Example 2:\n \n >>> findMinimumOperations(s1 = \"dac\", s2 = \"bac\", s3 = \"cac\")\n >>> -1\n Explanation: Since the first letters of s1 and s2 differ, they cannot be made equal.\n \"\"\"\n"}
{"task_id": "separate-black-and-white-balls", "prompt": "def minimumSteps(s: str) -> int:\n \"\"\"\n There are n balls on a table, each ball has a color black or white.\n You are given a 0-indexed binary string s of length n, where 1 and 0 represent black and white balls, respectively.\n In each step, you can choose two adjacent balls and swap them.\n Return the minimum number of steps to group all the black balls to the right and all the white balls to the left.\n \n Example 1:\n \n >>> minimumSteps(s = \"101\")\n >>> 1\n Explanation: We can group all the black balls to the right in the following way:\n - Swap s[0] and s[1], s = \"011\".\n Initially, 1s are not grouped together, requiring at least 1 step to group them to the right.\n Example 2:\n \n >>> minimumSteps(s = \"100\")\n >>> 2\n Explanation: We can group all the black balls to the right in the following way:\n - Swap s[0] and s[1], s = \"010\".\n - Swap s[1] and s[2], s = \"001\".\n It can be proven that the minimum number of steps needed is 2.\n \n Example 3:\n \n >>> minimumSteps(s = \"0111\")\n >>> 0\n Explanation: All the black balls are already grouped to the right.\n \"\"\"\n"}
{"task_id": "maximum-xor-product", "prompt": "def maximumXorProduct(a: int, b: int, n: int) -> int:\n \"\"\"\n Given three integers a, b, and n, return the maximum value of (a XOR x) * (b XOR x) where 0 <= x < 2n.\n Since the answer may be too large, return it modulo 109 + 7.\n Note that XOR is the bitwise XOR operation.\n \n Example 1:\n \n >>> maximumXorProduct(a = 12, b = 5, n = 4)\n >>> 98\n Explanation: For x = 2, (a XOR x) = 14 and (b XOR x) = 7. Hence, (a XOR x) * (b XOR x) = 98.\n It can be shown that 98 is the maximum value of (a XOR x) * (b XOR x) for all 0 <= x < 2n.\n \n Example 2:\n \n >>> maximumXorProduct(a = 6, b = 7 , n = 5)\n >>> 930\n Explanation: For x = 25, (a XOR x) = 31 and (b XOR x) = 30. Hence, (a XOR x) * (b XOR x) = 930.\n It can be shown that 930 is the maximum value of (a XOR x) * (b XOR x) for all 0 <= x < 2n.\n Example 3:\n \n >>> maximumXorProduct(a = 1, b = 6, n = 3)\n >>> 12\n Explanation: For x = 5, (a XOR x) = 4 and (b XOR x) = 3. Hence, (a XOR x) * (b XOR x) = 12.\n It can be shown that 12 is the maximum value of (a XOR x) * (b XOR x) for all 0 <= x < 2n.\n \"\"\"\n"}
{"task_id": "find-building-where-alice-and-bob-can-meet", "prompt": "def leftmostBuildingQueries(heights: List[int], queries: List[List[int]]) -> List[int]:\n \"\"\"\n You are given a 0-indexed array heights of positive integers, where heights[i] represents the height of the ith building.\n If a person is in building i, they can move to any other building j if and only if i < j and heights[i] < heights[j].\n You are also given another array queries where queries[i] = [ai, bi]. On the ith query, Alice is in building ai while Bob is in building bi.\n Return an array ans where ans[i] is the index of the leftmost building where Alice and Bob can meet on the ith query. If Alice and Bob cannot move to a common building on query i, set ans[i] to -1.\n \n Example 1:\n \n >>> leftmostBuildingQueries(heights = [6,4,8,5,2,7], queries = [[0,1],[0,3],[2,4],[3,4],[2,2]])\n >>> [2,5,-1,5,2]\n Explanation: In the first query, Alice and Bob can move to building 2 since heights[0] < heights[2] and heights[1] < heights[2].\n In the second query, Alice and Bob can move to building 5 since heights[0] < heights[5] and heights[3] < heights[5].\n In the third query, Alice cannot meet Bob since Alice cannot move to any other building.\n In the fourth query, Alice and Bob can move to building 5 since heights[3] < heights[5] and heights[4] < heights[5].\n In the fifth query, Alice and Bob are already in the same building.\n For ans[i] != -1, It can be shown that ans[i] is the leftmost building where Alice and Bob can meet.\n For ans[i] == -1, It can be shown that there is no building where Alice and Bob can meet.\n \n Example 2:\n \n >>> leftmostBuildingQueries(heights = [5,3,8,2,6,1,4,6], queries = [[0,7],[3,5],[5,2],[3,0],[1,6]])\n >>> [7,6,-1,4,6]\n Explanation: In the first query, Alice can directly move to Bob's building since heights[0] < heights[7].\n In the second query, Alice and Bob can move to building 6 since heights[3] < heights[6] and heights[5] < heights[6].\n In the third query, Alice cannot meet Bob since Bob cannot move to any other building.\n In the fourth query, Alice and Bob can move to building 4 since heights[3] < heights[4] and heights[0] < heights[4].\n In the fifth query, Alice can directly move to Bob's building since heights[1] < heights[6].\n For ans[i] != -1, It can be shown that ans[i] is the leftmost building where Alice and Bob can meet.\n For ans[i] == -1, It can be shown that there is no building where Alice and Bob can meet.\n \"\"\"\n"}
{"task_id": "maximum-gcd-sum-of-a-subarray", "prompt": "def maxGcdSum(nums: List[int], k: int) -> int:\n \"\"\"\n You are given an array of integers nums and an integer k.\n The gcd-sum of an array a is calculated as follows:\n \n Let s be the sum of all the elements of a.\n Let g be the greatest common divisor of all the elements of a.\n The gcd-sum of a is equal to s * g.\n \n Return the maximum gcd-sum of a subarray of nums with at least k elements.\n \n Example 1:\n \n >>> maxGcdSum(nums = [2,1,4,4,4,2], k = 2)\n >>> 48\n Explanation: We take the subarray [4,4,4], the gcd-sum of this array is 4 * (4 + 4 + 4) = 48.\n It can be shown that we can not select any other subarray with a gcd-sum greater than 48.\n Example 2:\n \n >>> maxGcdSum(nums = [7,3,9,4], k = 1)\n >>> 81\n Explanation: We take the subarray [9], the gcd-sum of this array is 9 * 9 = 81.\n It can be shown that we can not select any other subarray with a gcd-sum greater than 81.\n \"\"\"\n"}
{"task_id": "find-words-containing-character", "prompt": "def findWordsContaining(words: List[str], x: str) -> List[int]:\n \"\"\"\n You are given a 0-indexed array of strings words and a character x.\n Return an array of indices representing the words that contain the character x.\n Note that the returned array may be in any order.\n \n Example 1:\n \n >>> findWordsContaining(words = [\"leet\",\"code\"], x = \"e\")\n >>> [0,1]\n Explanation: \"e\" occurs in both words: \"leet\", and \"code\". Hence, we return indices 0 and 1.\n \n Example 2:\n \n >>> findWordsContaining(words = [\"abc\",\"bcd\",\"aaaa\",\"cbc\"], x = \"a\")\n >>> [0,2]\n Explanation: \"a\" occurs in \"abc\", and \"aaaa\". Hence, we return indices 0 and 2.\n \n Example 3:\n \n >>> findWordsContaining(words = [\"abc\",\"bcd\",\"aaaa\",\"cbc\"], x = \"z\")\n >>> []\n Explanation: \"z\" does not occur in any of the words. Hence, we return an empty array.\n \"\"\"\n"}
{"task_id": "maximize-area-of-square-hole-in-grid", "prompt": "def maximizeSquareHoleArea(n: int, m: int, hBars: List[int], vBars: List[int]) -> int:\n \"\"\"\n You are given the two integers, n and m and two integer arrays, hBars and vBars. The grid has n + 2 horizontal and m + 2 vertical bars, creating 1 x 1 unit cells. The bars are indexed starting from 1.\n You can remove some of the bars in hBars from horizontal bars and some of the bars in vBars from vertical bars. Note that other bars are fixed and cannot be removed.\n Return an integer denoting the maximum area of a square-shaped hole in the grid, after removing some bars (possibly none).\n \n Example 1:\n \n \n >>> maximizeSquareHoleArea(n = 2, m = 1, hBars = [2,3], vBars = [2])\n >>> 4\n Explanation:\n The left image shows the initial grid formed by the bars. The horizontal bars are [1,2,3,4], and the vertical bars are\u00a0[1,2,3].\n One way to get the maximum square-shaped hole is by removing horizontal bar 2 and vertical bar 2.\n \n Example 2:\n \n \n >>> maximizeSquareHoleArea(n = 1, m = 1, hBars = [2], vBars = [2])\n >>> 4\n Explanation:\n To get the maximum square-shaped hole, we remove horizontal bar 2 and vertical bar 2.\n \n Example 3:\n \n \n >>> maximizeSquareHoleArea(n = 2, m = 3, hBars = [2,3], vBars = [2,4])\n >>> 4\n Explanation:\n One way to get the maximum square-shaped hole is by removing horizontal bar 3, and vertical bar 4.\n \"\"\"\n"}
{"task_id": "minimum-number-of-coins-for-fruits", "prompt": "def minimumCoins(prices: List[int]) -> int:\n \"\"\"\n You are given an 0-indexed integer array prices where prices[i] denotes the number of coins needed to purchase the (i + 1)th fruit.\n The fruit market has the following reward for each fruit:\n \n If you purchase the (i + 1)th fruit at prices[i] coins, you can get any number of the next i fruits for free.\n \n Note that even if you can take fruit j for free, you can still purchase it for prices[j - 1] coins to receive its reward.\n Return the minimum number of coins needed to acquire all the fruits.\n \n Example 1:\n \n >>> minimumCoins(prices = [3,1,2])\n >>> 4\n Explanation:\n \n Purchase the 1st fruit with prices[0] = 3 coins, you are allowed to take the 2nd fruit for free.\n Purchase the 2nd fruit with prices[1] = 1 coin, you are allowed to take the 3rd fruit for free.\n Take the 3rd fruit for free.\n \n Note that even though you could take the 2nd fruit for free as a reward of buying 1st fruit, you purchase it to receive its reward, which is more optimal.\n \n Example 2:\n \n >>> minimumCoins(prices = [1,10,1,1])\n >>> 2\n Explanation:\n \n Purchase the 1st fruit with prices[0] = 1 coin, you are allowed to take the 2nd fruit for free.\n Take the 2nd fruit for free.\n Purchase the 3rd fruit for prices[2] = 1 coin, you are allowed to take the 4th fruit for free.\n Take the 4th fruit for free.\n \n \n Example 3:\n \n >>> minimumCoins(prices = [26,18,6,12,49,7,45,45])\n >>> 39\n Explanation:\n \n Purchase the 1st fruit with prices[0] = 26 coin, you are allowed to take the 2nd fruit for free.\n Take the 2nd fruit for free.\n Purchase the 3rd fruit for prices[2] = 6 coin, you are allowed to take the 4th, 5th and 6th (the next three) fruits for free.\n Take the 4th fruit for free.\n Take the 5th fruit for free.\n Purchase the 6th fruit with prices[5] = 7 coin, you are allowed to take the 8th and 9th fruit for free.\n Take the 7th fruit for free.\n Take the 8th fruit for free.\n \n Note that even though you could take the 6th fruit for free as a reward of buying 3rd fruit, you purchase it to receive its reward, which is more optimal.\n \"\"\"\n"}
{"task_id": "find-maximum-non-decreasing-array-length", "prompt": "def findMaximumLength(nums: List[int]) -> int:\n \"\"\"\n You are given a 0-indexed integer array nums.\n You can perform any number of operations, where each operation involves selecting a subarray of the array and replacing it with the sum of its elements. For example, if the given array is [1,3,5,6] and you select subarray [3,5] the array will convert to [1,8,6].\n Return the maximum length of a non-decreasing array that can be made after applying operations.\n A subarray is a contiguous non-empty sequence of elements within an array.\n \n Example 1:\n \n >>> findMaximumLength(nums = [5,2,2])\n >>> 1\n Explanation: This array with length 3 is not non-decreasing.\n We have two ways to make the array length two.\n First, choosing subarray [2,2] converts the array to [5,4].\n Second, choosing subarray [5,2] converts the array to [7,2].\n In these two ways the array is not non-decreasing.\n And if we choose subarray [5,2,2] and replace it with [9] it becomes non-decreasing.\n So the answer is 1.\n \n Example 2:\n \n >>> findMaximumLength(nums = [1,2,3,4])\n >>> 4\n Explanation: The array is non-decreasing. So the answer is 4.\n \n Example 3:\n \n >>> findMaximumLength(nums = [4,3,2,6])\n >>> 3\n Explanation: Replacing [3,2] with [5] converts the given array to [4,5,6] that is non-decreasing.\n Because the given array is not non-decreasing, the maximum possible answer is 3.\n \"\"\"\n"}
{"task_id": "matrix-similarity-after-cyclic-shifts", "prompt": "def areSimilar(mat: List[List[int]], k: int) -> bool:\n \"\"\"\n You are given an m x n integer matrix mat and an integer k. The matrix rows are 0-indexed.\n The following proccess happens k times:\n \n Even-indexed rows (0, 2, 4, ...) are cyclically shifted to the left.\n \n \n \n Odd-indexed rows (1, 3, 5, ...) are cyclically shifted to the right.\n \n \n Return true if the final modified matrix after k steps is identical to the original matrix, and false otherwise.\n \n Example 1:\n \n >>> areSimilar(mat = [[1,2,3],[4,5,6],[7,8,9]], k = 4)\n >>> false\n Explanation:\n In each step left shift is applied to rows 0 and 2 (even indices), and right shift to row 1 (odd index).\n \n \n Example 2:\n \n >>> areSimilar(mat = [[1,2,1,2],[5,5,5,5],[6,3,6,3]], k = 2)\n >>> true\n Explanation:\n \n \n Example 3:\n \n >>> areSimilar(mat = [[2,2],[2,2]], k = 3)\n >>> true\n Explanation:\n As all the values are equal in the matrix, even after performing cyclic shifts the matrix will remain the same.\n \"\"\"\n"}
{"task_id": "count-beautiful-substrings-i", "prompt": "def beautifulSubstrings(s: str, k: int) -> int:\n \"\"\"\n You are given a string s and a positive integer k.\n Let vowels and consonants be the number of vowels and consonants in a string.\n A string is beautiful if:\n \n vowels == consonants.\n (vowels * consonants) % k == 0, in other terms the multiplication of vowels and consonants is divisible by k.\n \n Return the number of non-empty beautiful substrings in the given string s.\n A substring is a contiguous sequence of characters in a string.\n Vowel letters in English are 'a', 'e', 'i', 'o', and 'u'.\n Consonant letters in English are every letter except vowels.\n \n Example 1:\n \n >>> beautifulSubstrings(s = \"baeyh\", k = 2)\n >>> 2\n Explanation: There are 2 beautiful substrings in the given string.\n - Substring \"baeyh\", vowels = 2 ([\"a\",e\"]), consonants = 2 ([\"y\",\"h\"]).\n You can see that string \"aeyh\" is beautiful as vowels == consonants and vowels * consonants % k == 0.\n - Substring \"baeyh\", vowels = 2 ([\"a\",e\"]), consonants = 2 ([\"b\",\"y\"]).\n You can see that string \"baey\" is beautiful as vowels == consonants and vowels * consonants % k == 0.\n It can be shown that there are only 2 beautiful substrings in the given string.\n \n Example 2:\n \n >>> beautifulSubstrings(s = \"abba\", k = 1)\n >>> 3\n Explanation: There are 3 beautiful substrings in the given string.\n - Substring \"abba\", vowels = 1 ([\"a\"]), consonants = 1 ([\"b\"]).\n - Substring \"abba\", vowels = 1 ([\"a\"]), consonants = 1 ([\"b\"]).\n - Substring \"abba\", vowels = 2 ([\"a\",\"a\"]), consonants = 2 ([\"b\",\"b\"]).\n It can be shown that there are only 3 beautiful substrings in the given string.\n \n Example 3:\n \n >>> beautifulSubstrings(s = \"bcdf\", k = 1)\n >>> 0\n Explanation: There are no beautiful substrings in the given string.\n \"\"\"\n"}
{"task_id": "make-lexicographically-smallest-array-by-swapping-elements", "prompt": "def lexicographicallySmallestArray(nums: List[int], limit: int) -> List[int]:\n \"\"\"\n You are given a 0-indexed array of positive integers nums and a positive integer limit.\n In one operation, you can choose any two indices i and j and swap nums[i] and nums[j] if |nums[i] - nums[j]| <= limit.\n Return the lexicographically smallest array that can be obtained by performing the operation any number of times.\n An array a is lexicographically smaller than an array b if in the first position where a and b differ, array a has an element that is less than the corresponding element in b. For example, the array [2,10,3] is lexicographically smaller than the array [10,2,3] because they differ at index 0 and 2 < 10.\n \n Example 1:\n \n >>> lexicographicallySmallestArray(nums = [1,5,3,9,8], limit = 2)\n >>> [1,3,5,8,9]\n Explanation: Apply the operation 2 times:\n - Swap nums[1] with nums[2]. The array becomes [1,3,5,9,8]\n - Swap nums[3] with nums[4]. The array becomes [1,3,5,8,9]\n We cannot obtain a lexicographically smaller array by applying any more operations.\n Note that it may be possible to get the same result by doing different operations.\n \n Example 2:\n \n >>> lexicographicallySmallestArray(nums = [1,7,6,18,2,1], limit = 3)\n >>> [1,6,7,18,1,2]\n Explanation: Apply the operation 3 times:\n - Swap nums[1] with nums[2]. The array becomes [1,6,7,18,2,1]\n - Swap nums[0] with nums[4]. The array becomes [2,6,7,18,1,1]\n - Swap nums[0] with nums[5]. The array becomes [1,6,7,18,1,2]\n We cannot obtain a lexicographically smaller array by applying any more operations.\n \n Example 3:\n \n >>> lexicographicallySmallestArray(nums = [1,7,28,19,10], limit = 3)\n >>> [1,7,28,19,10]\n Explanation: [1,7,28,19,10] is the lexicographically smallest array we can obtain because we cannot apply the operation on any two indices.\n \"\"\"\n"}
{"task_id": "count-beautiful-substrings-ii", "prompt": "def beautifulSubstrings(s: str, k: int) -> int:\n \"\"\"\n You are given a string s and a positive integer k.\n Let vowels and consonants be the number of vowels and consonants in a string.\n A string is beautiful if:\n \n vowels == consonants.\n (vowels * consonants) % k == 0, in other terms the multiplication of vowels and consonants is divisible by k.\n \n Return the number of non-empty beautiful substrings in the given string s.\n A substring is a contiguous sequence of characters in a string.\n Vowel letters in English are 'a', 'e', 'i', 'o', and 'u'.\n Consonant letters in English are every letter except vowels.\n \n Example 1:\n \n >>> beautifulSubstrings(s = \"baeyh\", k = 2)\n >>> 2\n Explanation: There are 2 beautiful substrings in the given string.\n - Substring \"baeyh\", vowels = 2 ([\"a\",e\"]), consonants = 2 ([\"y\",\"h\"]).\n You can see that string \"aeyh\" is beautiful as vowels == consonants and vowels * consonants % k == 0.\n - Substring \"baeyh\", vowels = 2 ([\"a\",e\"]), consonants = 2 ([\"b\",\"y\"]).\n You can see that string \"baey\" is beautiful as vowels == consonants and vowels * consonants % k == 0.\n It can be shown that there are only 2 beautiful substrings in the given string.\n \n Example 2:\n \n >>> beautifulSubstrings(s = \"abba\", k = 1)\n >>> 3\n Explanation: There are 3 beautiful substrings in the given string.\n - Substring \"abba\", vowels = 1 ([\"a\"]), consonants = 1 ([\"b\"]).\n - Substring \"abba\", vowels = 1 ([\"a\"]), consonants = 1 ([\"b\"]).\n - Substring \"abba\", vowels = 2 ([\"a\",\"a\"]), consonants = 2 ([\"b\",\"b\"]).\n It can be shown that there are only 3 beautiful substrings in the given string.\n \n Example 3:\n \n >>> beautifulSubstrings(s = \"bcdf\", k = 1)\n >>> 0\n Explanation: There are no beautiful substrings in the given string.\n \"\"\"\n"}
{"task_id": "number-of-divisible-substrings", "prompt": "def countDivisibleSubstrings(word: str) -> int:\n \"\"\"\n Each character of the English alphabet has been mapped to a digit as shown below.\n \n A string is divisible if the sum of the mapped values of its characters is divisible by its length.\n Given a string s, return the number of divisible substrings of s.\n A substring is a contiguous non-empty sequence of characters within a string.\n \n Example 1:\n \n \n \n Substring\n Mapped\n Sum\n Length\n Divisible?\n \n \n a\n 1\n 1\n 1\n Yes\n \n \n s\n 7\n 7\n 1\n Yes\n \n \n d\n 2\n 2\n 1\n Yes\n \n \n f\n 3\n 3\n 1\n Yes\n \n \n as\n 1, 7\n 8\n 2\n Yes\n \n \n sd\n 7, 2\n 9\n 2\n No\n \n \n df\n 2, 3\n 5\n 2\n No\n \n \n asd\n 1, 7, 2\n 10\n 3\n No\n \n \n sdf\n 7, 2, 3\n 12\n 3\n Yes\n \n \n asdf\n 1, 7, 2, 3\n 13\n 4\n No\n \n \n \n \n >>> countDivisibleSubstrings(word = \"asdf\")\n >>> 6\n Explanation: The table above contains the details about every substring of word, and we can see that 6 of them are divisible.\n \n Example 2:\n \n >>> countDivisibleSubstrings(word = \"bdh\")\n >>> 4\n Explanation: The 4 divisible substrings are: \"b\", \"d\", \"h\", \"bdh\".\n It can be shown that there are no other substrings of word that are divisible.\n \n Example 3:\n \n >>> countDivisibleSubstrings(word = \"abcd\")\n >>> 6\n Explanation: The 6 divisible substrings are: \"a\", \"b\", \"c\", \"d\", \"ab\", \"cd\".\n It can be shown that there are no other substrings of word that are divisible.\n \"\"\"\n"}
{"task_id": "find-the-peaks", "prompt": "def findPeaks(mountain: List[int]) -> List[int]:\n \"\"\"\n You are given a 0-indexed array mountain. Your task is to find all the peaks in the mountain array.\n Return an array that consists of indices of peaks in the given array in any order.\n Notes:\n \n A peak is defined as an element that is strictly greater than its neighboring elements.\n The first and last elements of the array are not a peak.\n \n \n Example 1:\n \n >>> findPeaks(mountain = [2,4,4])\n >>> []\n Explanation: mountain[0] and mountain[2] can not be a peak because they are first and last elements of the array.\n mountain[1] also can not be a peak because it is not strictly greater than mountain[2].\n So the answer is [].\n \n Example 2:\n \n >>> findPeaks(mountain = [1,4,3,8,5])\n >>> [1,3]\n Explanation: mountain[0] and mountain[4] can not be a peak because they are first and last elements of the array.\n mountain[2] also can not be a peak because it is not strictly greater than mountain[3] and mountain[1].\n But mountain [1] and mountain[3] are strictly greater than their neighboring elements.\n So the answer is [1,3].\n \"\"\"\n"}
{"task_id": "minimum-number-of-coins-to-be-added", "prompt": "def minimumAddedCoins(coins: List[int], target: int) -> int:\n \"\"\"\n You are given a 0-indexed integer array coins, representing the values of the coins available, and an integer target.\n An integer x is obtainable if there exists a subsequence of coins that sums to x.\n Return the minimum number of coins of any value that need to be added to the array so that every integer in the range [1, target] is obtainable.\n A subsequence of an array is a new non-empty array that is formed from the original array by deleting some (possibly none) of the elements without disturbing the relative positions of the remaining elements.\n \n Example 1:\n \n >>> minimumAddedCoins(coins = [1,4,10], target = 19)\n >>> 2\n Explanation: We need to add coins 2 and 8. The resulting array will be [1,2,4,8,10].\n It can be shown that all integers from 1 to 19 are obtainable from the resulting array, and that 2 is the minimum number of coins that need to be added to the array.\n \n Example 2:\n \n >>> minimumAddedCoins(coins = [1,4,10,5,7,19], target = 19)\n >>> 1\n Explanation: We only need to add the coin 2. The resulting array will be [1,2,4,5,7,10,19].\n It can be shown that all integers from 1 to 19 are obtainable from the resulting array, and that 1 is the minimum number of coins that need to be added to the array.\n \n Example 3:\n \n >>> minimumAddedCoins(coins = [1,1,1], target = 20)\n >>> 3\n Explanation: We need to add coins 4, 8, and 16. The resulting array will be [1,1,1,4,8,16].\n It can be shown that all integers from 1 to 20 are obtainable from the resulting array, and that 3 is the minimum number of coins that need to be added to the array.\n \"\"\"\n"}
{"task_id": "count-complete-substrings", "prompt": "def countCompleteSubstrings(word: str, k: int) -> int:\n \"\"\"\n You are given a string word and an integer k.\n A substring s of word is complete if:\n \n Each character in s occurs exactly k times.\n The difference between two adjacent characters is at most 2. That is, for any two adjacent characters c1 and c2 in s, the absolute difference in their positions in the alphabet is at most 2.\n \n Return the number of complete substrings of word.\n A substring is a non-empty contiguous sequence of characters in a string.\n \n Example 1:\n \n >>> countCompleteSubstrings(word = \"igigee\", k = 2)\n >>> 3\n Explanation: The complete substrings where each character appears exactly twice and the difference between adjacent characters is at most 2 are: igigee, igigee, igigee.\n \n Example 2:\n \n >>> countCompleteSubstrings(word = \"aaabbbccc\", k = 3)\n >>> 6\n Explanation: The complete substrings where each character appears exactly three times and the difference between adjacent characters is at most 2 are: aaabbbccc, aaabbbccc, aaabbbccc, aaabbbccc, aaabbbccc, aaabbbccc.\n \"\"\"\n"}
{"task_id": "number-of-same-end-substrings", "prompt": "def sameEndSubstringCount(s: str, queries: List[List[int]]) -> List[int]:\n \"\"\"\n You are given a 0-indexed string s, and a 2D array of integers queries, where queries[i] = [li, ri] indicates a substring of s starting from the index li and ending at the index ri (both inclusive), i.e. s[li..ri].\n Return an array ans where ans[i] is the number of same-end substrings of queries[i].\n A 0-indexed string t of length n is called same-end if it has the same character at both of its ends, i.e., t[0] == t[n - 1].\n A substring is a contiguous non-empty sequence of characters within a string.\n \n Example 1:\n \n >>> sameEndSubstringCount(s = \"abcaab\", queries = [[0,0],[1,4],[2,5],[0,5]])\n >>> [1,5,5,10]\n Explanation: Here is the same-end substrings of each query:\n 1st query: s[0..0] is \"a\" which has 1 same-end substring: \"a\".\n 2nd query: s[1..4] is \"bcaa\" which has 5 same-end substrings: \"bcaa\", \"bcaa\", \"bcaa\", \"bcaa\", \"bcaa\".\n 3rd query: s[2..5] is \"caab\" which has 5 same-end substrings: \"caab\", \"caab\", \"caab\", \"caab\", \"caab\".\n 4th query: s[0..5] is \"abcaab\" which has 10 same-end substrings: \"abcaab\", \"abcaab\", \"abcaab\", \"abcaab\", \"abcaab\", \"abcaab\", \"abcaab\", \"abcaab\", \"abcaab\", \"abcaab\".\n \n Example 2:\n \n >>> sameEndSubstringCount(s = \"abcd\", queries = [[0,3]])\n >>> [4]\n Explanation: The only query is s[0..3] which is \"abcd\". It has 4 same-end substrings: \"abcd\", \"abcd\", \"abcd\", \"abcd\".\n \"\"\"\n"}
{"task_id": "find-common-elements-between-two-arrays", "prompt": "def findIntersectionValues(nums1: List[int], nums2: List[int]) -> List[int]:\n \"\"\"\n You are given two integer arrays nums1 and nums2 of sizes n and m, respectively. Calculate the following values:\n \n answer1 : the number of indices i such that nums1[i] exists in nums2.\n answer2 : the number of indices i such that nums2[i] exists in nums1.\n \n Return [answer1,answer2].\n \n Example 1:\n \n >>> findIntersectionValues(nums1 = [2,3,2], nums2 = [1,2])\n >>> [2,1]\n Explanation:\n \n \n Example 2:\n \n >>> findIntersectionValues(nums1 = [4,3,2,3,1], nums2 = [2,2,5,2,3,6])\n >>> [3,4]\n Explanation:\n The elements at indices 1, 2, and 3 in nums1 exist in nums2 as well. So answer1 is 3.\n The elements at indices 0, 1, 3, and 4 in nums2 exist in nums1. So answer2 is 4.\n \n Example 3:\n \n >>> findIntersectionValues(nums1 = [3,4,2,3], nums2 = [1,5])\n >>> [0,0]\n Explanation:\n No numbers are common between nums1 and nums2, so answer is [0,0].\n \"\"\"\n"}
{"task_id": "remove-adjacent-almost-equal-characters", "prompt": "def removeAlmostEqualCharacters(word: str) -> int:\n \"\"\"\n You are given a 0-indexed string word.\n In one operation, you can pick any index i of word and change word[i] to any lowercase English letter.\n Return the minimum number of operations needed to remove all adjacent almost-equal characters from word.\n Two characters a and b are almost-equal if a == b or a and b are adjacent in the alphabet.\n \n Example 1:\n \n >>> removeAlmostEqualCharacters(word = \"aaaaa\")\n >>> 2\n Explanation: We can change word into \"acaca\" which does not have any adjacent almost-equal characters.\n It can be shown that the minimum number of operations needed to remove all adjacent almost-equal characters from word is 2.\n \n Example 2:\n \n >>> removeAlmostEqualCharacters(word = \"abddez\")\n >>> 2\n Explanation: We can change word into \"ybdoez\" which does not have any adjacent almost-equal characters.\n It can be shown that the minimum number of operations needed to remove all adjacent almost-equal characters from word is 2.\n Example 3:\n \n >>> removeAlmostEqualCharacters(word = \"zyxyxyz\")\n >>> 3\n Explanation: We can change word into \"zaxaxaz\" which does not have any adjacent almost-equal characters.\n It can be shown that the minimum number of operations needed to remove all adjacent almost-equal characters from word is 3.\n \"\"\"\n"}
{"task_id": "length-of-longest-subarray-with-at-most-k-frequency", "prompt": "def maxSubarrayLength(nums: List[int], k: int) -> int:\n \"\"\"\n You are given an integer array nums and an integer k.\n The frequency of an element x is the number of times it occurs in an array.\n An array is called good if the frequency of each element in this array is less than or equal to k.\n Return the length of the longest good subarray of nums.\n A subarray is a contiguous non-empty sequence of elements within an array.\n \n Example 1:\n \n >>> maxSubarrayLength(nums = [1,2,3,1,2,3,1,2], k = 2)\n >>> 6\n Explanation: The longest possible good subarray is [1,2,3,1,2,3] since the values 1, 2, and 3 occur at most twice in this subarray. Note that the subarrays [2,3,1,2,3,1] and [3,1,2,3,1,2] are also good.\n It can be shown that there are no good subarrays with length more than 6.\n \n Example 2:\n \n >>> maxSubarrayLength(nums = [1,2,1,2,1,2,1,2], k = 1)\n >>> 2\n Explanation: The longest possible good subarray is [1,2] since the values 1 and 2 occur at most once in this subarray. Note that the subarray [2,1] is also good.\n It can be shown that there are no good subarrays with length more than 2.\n \n Example 3:\n \n >>> maxSubarrayLength(nums = [5,5,5,5,5,5,5], k = 4)\n >>> 4\n Explanation: The longest possible good subarray is [5,5,5,5] since the value 5 occurs 4 times in this subarray.\n It can be shown that there are no good subarrays with length more than 4.\n \"\"\"\n"}
{"task_id": "number-of-possible-sets-of-closing-branches", "prompt": "def numberOfSets(n: int, maxDistance: int, roads: List[List[int]]) -> int:\n \"\"\"\n There is a company with n branches across the country, some of which are connected by roads. Initially, all branches are reachable from each other by traveling some roads.\n The company has realized that they are spending an excessive amount of time traveling between their branches. As a result, they have decided to close down some of these branches (possibly none). However, they want to ensure that the remaining branches have a distance of at most maxDistance from each other.\n The distance between two branches is the minimum total traveled length needed to reach one branch from another.\n You are given integers n, maxDistance, and a 0-indexed 2D array roads, where roads[i] = [ui, vi, wi] represents the undirected road between branches ui and vi with length wi.\n Return the number of possible sets of closing branches, so that any branch has a distance of at most maxDistance from any other.\n Note that, after closing a branch, the company will no longer have access to any roads connected to it.\n Note that, multiple roads are allowed.\n \n Example 1:\n \n \n >>> numberOfSets(n = 3, maxDistance = 5, roads = [[0,1,2],[1,2,10],[0,2,10]])\n >>> 5\n Explanation: The possible sets of closing branches are:\n - The set [2], after closing, active branches are [0,1] and they are reachable to each other within distance 2.\n - The set [0,1], after closing, the active branch is [2].\n - The set [1,2], after closing, the active branch is [0].\n - The set [0,2], after closing, the active branch is [1].\n - The set [0,1,2], after closing, there are no active branches.\n It can be proven, that there are only 5 possible sets of closing branches.\n \n Example 2:\n \n \n >>> numberOfSets(n = 3, maxDistance = 5, roads = [[0,1,20],[0,1,10],[1,2,2],[0,2,2]])\n >>> 7\n Explanation: The possible sets of closing branches are:\n - The set [], after closing, active branches are [0,1,2] and they are reachable to each other within distance 4.\n - The set [0], after closing, active branches are [1,2] and they are reachable to each other within distance 2.\n - The set [1], after closing, active branches are [0,2] and they are reachable to each other within distance 2.\n - The set [0,1], after closing, the active branch is [2].\n - The set [1,2], after closing, the active branch is [0].\n - The set [0,2], after closing, the active branch is [1].\n - The set [0,1,2], after closing, there are no active branches.\n It can be proven, that there are only 7 possible sets of closing branches.\n \n Example 3:\n \n >>> numberOfSets(n = 1, maxDistance = 10, roads = [])\n >>> 2\n Explanation: The possible sets of closing branches are:\n - The set [], after closing, the active branch is [0].\n - The set [0], after closing, there are no active branches.\n It can be proven, that there are only 2 possible sets of closing branches.\n \"\"\"\n"}
{"task_id": "count-tested-devices-after-test-operations", "prompt": "def countTestedDevices(batteryPercentages: List[int]) -> int:\n \"\"\"\n You are given a 0-indexed integer array batteryPercentages having length n, denoting the battery percentages of n 0-indexed devices.\n Your task is to test each device i in order from 0 to n - 1, by performing the following test operations:\n \n If batteryPercentages[i] is greater than 0:\n \n \n Increment the count of tested devices.\n Decrease the battery percentage of all devices with indices j in the range [i + 1, n - 1] by 1, ensuring their battery percentage never goes below 0, i.e, batteryPercentages[j] = max(0, batteryPercentages[j] - 1).\n Move to the next device.\n \n \n Otherwise, move to the next device without performing any test.\n \n Return an integer denoting the number of devices that will be tested after performing the test operations in order.\n \n Example 1:\n \n >>> countTestedDevices(batteryPercentages = [1,1,2,1,3])\n >>> 3\n Explanation: Performing the test operations in order starting from device 0:\n At device 0, batteryPercentages[0] > 0, so there is now 1 tested device, and batteryPercentages becomes [1,0,1,0,2].\n At device 1, batteryPercentages[1] == 0, so we move to the next device without testing.\n At device 2, batteryPercentages[2] > 0, so there are now 2 tested devices, and batteryPercentages becomes [1,0,1,0,1].\n At device 3, batteryPercentages[3] == 0, so we move to the next device without testing.\n At device 4, batteryPercentages[4] > 0, so there are now 3 tested devices, and batteryPercentages stays the same.\n So, the answer is 3.\n \n Example 2:\n \n >>> countTestedDevices(batteryPercentages = [0,1,2])\n >>> 2\n Explanation: Performing the test operations in order starting from device 0:\n At device 0, batteryPercentages[0] == 0, so we move to the next device without testing.\n At device 1, batteryPercentages[1] > 0, so there is now 1 tested device, and batteryPercentages becomes [0,1,1].\n At device 2, batteryPercentages[2] > 0, so there are now 2 tested devices, and batteryPercentages stays the same.\n So, the answer is 2.\n \"\"\"\n"}
{"task_id": "count-subarrays-where-max-element-appears-at-least-k-times", "prompt": "def countSubarrays(nums: List[int], k: int) -> int:\n \"\"\"\n You are given an integer array nums and a positive integer k.\n Return the number of subarrays where the maximum element of nums appears at least k times in that subarray.\n A subarray is a contiguous sequence of elements within an array.\n \n Example 1:\n \n >>> countSubarrays(nums = [1,3,2,3,3], k = 2)\n >>> 6\n Explanation: The subarrays that contain the element 3 at least 2 times are: [1,3,2,3], [1,3,2,3,3], [3,2,3], [3,2,3,3], [2,3,3] and [3,3].\n \n Example 2:\n \n >>> countSubarrays(nums = [1,4,2,1], k = 3)\n >>> 0\n Explanation: No subarray contains the element 4 at least 3 times.\n \"\"\"\n"}
{"task_id": "number-of-divisible-triplet-sums", "prompt": "def divisibleTripletCount(nums: List[int], d: int) -> int:\n \"\"\"\n Given a 0-indexed integer array nums and an integer d, return the number of triplets (i, j, k) such that i < j < k and (nums[i] + nums[j] + nums[k]) % d == 0.\n \n Example 1:\n \n >>> divisibleTripletCount(nums = [3,3,4,7,8], d = 5)\n >>> 3\n Explanation: The triplets which are divisible by 5 are: (0, 1, 2), (0, 2, 4), (1, 2, 4).\n It can be shown that no other triplet is divisible by 5. Hence, the answer is 3.\n \n Example 2:\n \n >>> divisibleTripletCount(nums = [3,3,3,3], d = 3)\n >>> 4\n Explanation: Any triplet chosen here has a sum of 9, which is divisible by 3. Hence, the answer is the total number of triplets which is 4.\n \n Example 3:\n \n >>> divisibleTripletCount(nums = [3,3,3,3], d = 6)\n >>> 0\n Explanation: Any triplet chosen here has a sum of 9, which is not divisible by 6. Hence, the answer is 0.\n \"\"\"\n"}
{"task_id": "find-missing-and-repeated-values", "prompt": "def findMissingAndRepeatedValues(grid: List[List[int]]) -> List[int]:\n \"\"\"\n You are given a 0-indexed 2D integer matrix grid of size n * n with values in the range [1, n2]. Each integer appears exactly once except a which appears twice and b which is missing. The task is to find the repeating and missing numbers a and b.\n Return a 0-indexed integer array ans of size 2 where ans[0] equals to a and ans[1] equals to b.\n \n Example 1:\n \n >>> findMissingAndRepeatedValues(grid = [[1,3],[2,2]])\n >>> [2,4]\n Explanation: Number 2 is repeated and number 4 is missing so the answer is [2,4].\n \n Example 2:\n \n >>> findMissingAndRepeatedValues(grid = [[9,1,7],[8,9,2],[3,4,6]])\n >>> [9,5]\n Explanation: Number 9 is repeated and number 5 is missing so the answer is [9,5].\n \"\"\"\n"}
{"task_id": "divide-array-into-arrays-with-max-difference", "prompt": "def divideArray(nums: List[int], k: int) -> List[List[int]]:\n \"\"\"\n You are given an integer array nums of size n where n is a multiple of 3 and a positive integer k.\n Divide the array nums into n / 3 arrays of size 3 satisfying the following condition:\n \n The difference between any two elements in one array is less than or equal to k.\n \n Return a 2D array containing the arrays. If it is impossible to satisfy the conditions, return an empty array. And if there are multiple answers, return any of them.\n \n Example 1:\n \n >>> divideArray(nums = [1,3,4,8,7,9,3,5,1], k = 2)\n >>> [[1,1,3],[3,4,5],[7,8,9]]\n Explanation:\n The difference between any two elements in each array is less than or equal to 2.\n \n Example 2:\n \n >>> divideArray(nums = [2,4,2,2,5,2], k = 2)\n >>> []\n Explanation:\n Different ways to divide nums into 2 arrays of size 3 are:\n \n [[2,2,2],[2,4,5]] (and its permutations)\n [[2,2,4],[2,2,5]] (and its permutations)\n \n Because there are four 2s there will be an array with the elements 2 and 5 no matter how we divide it. since 5 - 2 = 3 > k, the condition is not satisfied and so there is no valid division.\n \n Example 3:\n \n >>> divideArray(nums = [4,2,9,8,2,12,7,12,10,5,8,5,5,7,9,2,5,11], k = 14)\n >>> [[2,2,12],[4,8,5],[5,9,7],[7,8,5],[5,9,10],[11,12,2]]\n Explanation:\n The difference between any two elements in each array is less than or equal to 14.\n \"\"\"\n"}
{"task_id": "minimum-cost-to-make-array-equalindromic", "prompt": "def minimumCost(nums: List[int]) -> int:\n \"\"\"\n You are given a 0-indexed integer array nums having length n.\n You are allowed to perform a special move any number of times (including zero) on nums. In one special move you perform the following steps in order:\n \n Choose an index i in the range [0, n - 1], and a positive integer x.\n Add |nums[i] - x| to the total cost.\n Change the value of nums[i] to x.\n \n A palindromic number is a positive integer that remains the same when its digits are reversed. For example, 121, 2552 and 65756 are palindromic numbers whereas 24, 46, 235 are not palindromic numbers.\n An array is considered equalindromic if all the elements in the array are equal to an integer y, where y is a palindromic number less than 109.\n Return an integer denoting the minimum possible total cost to make nums equalindromic by performing any number of special moves.\n \n Example 1:\n \n >>> minimumCost(nums = [1,2,3,4,5])\n >>> 6\n Explanation: We can make the array equalindromic by changing all elements to 3 which is a palindromic number. The cost of changing the array to [3,3,3,3,3] using 4 special moves is given by |1 - 3| + |2 - 3| + |4 - 3| + |5 - 3| = 6.\n It can be shown that changing all elements to any palindromic number other than 3 cannot be achieved at a lower cost.\n \n Example 2:\n \n >>> minimumCost(nums = [10,12,13,14,15])\n >>> 11\n Explanation: We can make the array equalindromic by changing all elements to 11 which is a palindromic number. The cost of changing the array to [11,11,11,11,11] using 5 special moves is given by |10 - 11| + |12 - 11| + |13 - 11| + |14 - 11| + |15 - 11| = 11.\n It can be shown that changing all elements to any palindromic number other than 11 cannot be achieved at a lower cost.\n \n Example 3:\n \n >>> minimumCost(nums = [22,33,22,33,22])\n >>> 22\n Explanation: We can make the array equalindromic by changing all elements to 22 which is a palindromic number. The cost of changing the array to [22,22,22,22,22] using 2 special moves is given by |33 - 22| + |33 - 22| = 22.\n It can be shown that changing all elements to any palindromic number other than 22 cannot be achieved at a lower cost.\n \"\"\"\n"}
{"task_id": "apply-operations-to-maximize-frequency-score", "prompt": "def maxFrequencyScore(nums: List[int], k: int) -> int:\n \"\"\"\n You are given a 0-indexed integer array nums and an integer k.\n You can perform the following operation on the array at most k times:\n \n Choose any index i from the array and increase or decrease nums[i] by 1.\n \n The score of the final array is the frequency of the most frequent element in the array.\n Return the maximum score you can achieve.\n The frequency of an element is the number of occurences of that element in the array.\n \n Example 1:\n \n >>> maxFrequencyScore(nums = [1,2,6,4], k = 3)\n >>> 3\n Explanation: We can do the following operations on the array:\n - Choose i = 0, and increase the value of nums[0] by 1. The resulting array is [2,2,6,4].\n - Choose i = 3, and decrease the value of nums[3] by 1. The resulting array is [2,2,6,3].\n - Choose i = 3, and decrease the value of nums[3] by 1. The resulting array is [2,2,6,2].\n The element 2 is the most frequent in the final array so our score is 3.\n It can be shown that we cannot achieve a better score.\n \n Example 2:\n \n >>> maxFrequencyScore(nums = [1,4,4,2,4], k = 0)\n >>> 3\n Explanation: We cannot apply any operations so our score will be the frequency of the most frequent element in the original array, which is 3.\n \"\"\"\n"}
{"task_id": "minimum-number-of-coins-for-fruits-ii", "prompt": "def minimumCoins(prices: List[int]) -> int:\n \"\"\"\n You are at a fruit market with different types of exotic fruits on display.\n You are given a 1-indexed array prices, where prices[i] denotes the number of coins needed to purchase the ith fruit.\n The fruit market has the following offer:\n \n If you purchase the ith fruit at prices[i] coins, you can get the next i fruits for free.\n \n Note that even if you can take fruit j for free, you can still purchase it for prices[j] coins to receive a new offer.\n Return the minimum number of coins needed to acquire all the fruits.\n \n Example 1:\n \n >>> minimumCoins(prices = [3,1,2])\n >>> 4\n Explanation: You can acquire the fruits as follows:\n - Purchase the 1st fruit with 3 coins, and you are allowed to take the 2nd fruit for free.\n - Purchase the 2nd fruit with 1 coin, and you are allowed to take the 3rd fruit for free.\n - Take the 3rd fruit for free.\n Note that even though you were allowed to take the 2nd fruit for free, you purchased it because it is more optimal.\n It can be proven that 4 is the minimum number of coins needed to acquire all the fruits.\n \n Example 2:\n \n >>> minimumCoins(prices = [1,10,1,1])\n >>> 2\n Explanation: You can acquire the fruits as follows:\n - Purchase the 1st fruit with 1 coin, and you are allowed to take the 2nd fruit for free.\n - Take the 2nd fruit for free.\n - Purchase the 3rd fruit for 1 coin, and you are allowed to take the 4th fruit for free.\n - Take the 4th fruit for free.\n It can be proven that 2 is the minimum number of coins needed to acquire all the fruits.\n \"\"\"\n"}
{"task_id": "count-the-number-of-incremovable-subarrays-i", "prompt": "def incremovableSubarrayCount(nums: List[int]) -> int:\n \"\"\"\n You are given a 0-indexed array of positive integers nums.\n A subarray of nums is called incremovable if nums becomes strictly increasing on removing the subarray. For example, the subarray [3, 4] is an incremovable subarray of [5, 3, 4, 6, 7] because removing this subarray changes the array [5, 3, 4, 6, 7] to [5, 6, 7] which is strictly increasing.\n Return the total number of incremovable subarrays of nums.\n Note that an empty array is considered strictly increasing.\n A subarray is a contiguous non-empty sequence of elements within an array.\n \n Example 1:\n \n >>> incremovableSubarrayCount(nums = [1,2,3,4])\n >>> 10\n Explanation: The 10 incremovable subarrays are: [1], [2], [3], [4], [1,2], [2,3], [3,4], [1,2,3], [2,3,4], and [1,2,3,4], because on removing any one of these subarrays nums becomes strictly increasing. Note that you cannot select an empty subarray.\n \n Example 2:\n \n >>> incremovableSubarrayCount(nums = [6,5,7,8])\n >>> 7\n Explanation: The 7 incremovable subarrays are: [5], [6], [5,7], [6,5], [5,7,8], [6,5,7] and [6,5,7,8].\n It can be shown that there are only 7 incremovable subarrays in nums.\n \n Example 3:\n \n >>> incremovableSubarrayCount(nums = [8,7,6,6])\n >>> 3\n Explanation: The 3 incremovable subarrays are: [8,7,6], [7,6,6], and [8,7,6,6]. Note that [8,7] is not an incremovable subarray because after removing [8,7] nums becomes [6,6], which is sorted in ascending order but not strictly increasing.\n \"\"\"\n"}
{"task_id": "find-polygon-with-the-largest-perimeter", "prompt": "def largestPerimeter(nums: List[int]) -> int:\n \"\"\"\n You are given an array of positive integers nums of length n.\n A polygon is a closed plane figure that has at least 3 sides. The longest side of a polygon is smaller than the sum of its other sides.\n Conversely, if you have k (k >= 3) positive real numbers a1, a2, a3, ..., ak where a1 <= a2 <= a3 <= ... <= ak and a1 + a2 + a3 + ... + ak-1 > ak, then there always exists a polygon with k sides whose lengths are a1, a2, a3, ..., ak.\n The perimeter of a polygon is the sum of lengths of its sides.\n Return the largest possible perimeter of a polygon whose sides can be formed from nums, or -1 if it is not possible to create a polygon.\n \n Example 1:\n \n >>> largestPerimeter(nums = [5,5,5])\n >>> 15\n Explanation: The only possible polygon that can be made from nums has 3 sides: 5, 5, and 5. The perimeter is 5 + 5 + 5 = 15.\n \n Example 2:\n \n >>> largestPerimeter(nums = [1,12,1,2,5,50,3])\n >>> 12\n Explanation: The polygon with the largest perimeter which can be made from nums has 5 sides: 1, 1, 2, 3, and 5. The perimeter is 1 + 1 + 2 + 3 + 5 = 12.\n We cannot have a polygon with either 12 or 50 as the longest side because it is not possible to include 2 or more smaller sides that have a greater sum than either of them.\n It can be shown that the largest possible perimeter is 12.\n \n Example 3:\n \n >>> largestPerimeter(nums = [5,5,50])\n >>> -1\n Explanation: There is no possible way to form a polygon from nums, as a polygon has at least 3 sides and 50 > 5 + 5.\n \"\"\"\n"}
{"task_id": "count-the-number-of-incremovable-subarrays-ii", "prompt": "def incremovableSubarrayCount(nums: List[int]) -> int:\n \"\"\"\n You are given a 0-indexed array of positive integers nums.\n A subarray of nums is called incremovable if nums becomes strictly increasing on removing the subarray. For example, the subarray [3, 4] is an incremovable subarray of [5, 3, 4, 6, 7] because removing this subarray changes the array [5, 3, 4, 6, 7] to [5, 6, 7] which is strictly increasing.\n Return the total number of incremovable subarrays of nums.\n Note that an empty array is considered strictly increasing.\n A subarray is a contiguous non-empty sequence of elements within an array.\n \n Example 1:\n \n >>> incremovableSubarrayCount(nums = [1,2,3,4])\n >>> 10\n Explanation: The 10 incremovable subarrays are: [1], [2], [3], [4], [1,2], [2,3], [3,4], [1,2,3], [2,3,4], and [1,2,3,4], because on removing any one of these subarrays nums becomes strictly increasing. Note that you cannot select an empty subarray.\n \n Example 2:\n \n >>> incremovableSubarrayCount(nums = [6,5,7,8])\n >>> 7\n Explanation: The 7 incremovable subarrays are: [5], [6], [5,7], [6,5], [5,7,8], [6,5,7] and [6,5,7,8].\n It can be shown that there are only 7 incremovable subarrays in nums.\n \n Example 3:\n \n >>> incremovableSubarrayCount(nums = [8,7,6,6])\n >>> 3\n Explanation: The 3 incremovable subarrays are: [8,7,6], [7,6,6], and [8,7,6,6]. Note that [8,7] is not an incremovable subarray because after removing [8,7] nums becomes [6,6], which is sorted in ascending order but not strictly increasing.\n \"\"\"\n"}
{"task_id": "find-number-of-coins-to-place-in-tree-nodes", "prompt": "def placedCoins(edges: List[List[int]], cost: List[int]) -> List[int]:\n \"\"\"\n You are given an undirected tree with n nodes labeled from 0 to n - 1, and rooted at node 0. You are given a 2D integer array edges of length n - 1, where edges[i] = [ai, bi] indicates that there is an edge between nodes ai and bi in the tree.\n You are also given a 0-indexed integer array cost of length n, where cost[i] is the cost assigned to the ith node.\n You need to place some coins on every node of the tree. The number of coins to be placed at node i can be calculated as:\n \n If size of the subtree of node i is less than 3, place 1 coin.\n Otherwise, place an amount of coins equal to the maximum product of cost values assigned to 3 distinct nodes in the subtree of node i. If this product is negative, place 0 coins.\n \n Return an array coin of size n such that coin[i] is the number of coins placed at node i.\n \n Example 1:\n \n \n >>> placedCoins(edges = [[0,1],[0,2],[0,3],[0,4],[0,5]], cost = [1,2,3,4,5,6])\n >>> [120,1,1,1,1,1]\n Explanation: For node 0 place 6 * 5 * 4 = 120 coins. All other nodes are leaves with subtree of size 1, place 1 coin on each of them.\n \n Example 2:\n \n \n >>> placedCoins(edges = [[0,1],[0,2],[1,3],[1,4],[1,5],[2,6],[2,7],[2,8]], cost = [1,4,2,3,5,7,8,-4,2])\n >>> [280,140,32,1,1,1,1,1,1]\n Explanation: The coins placed on each node are:\n - Place 8 * 7 * 5 = 280 coins on node 0.\n - Place 7 * 5 * 4 = 140 coins on node 1.\n - Place 8 * 2 * 2 = 32 coins on node 2.\n - All other nodes are leaves with subtree of size 1, place 1 coin on each of them.\n \n Example 3:\n \n \n >>> placedCoins(edges = [[0,1],[0,2]], cost = [1,2,-2])\n >>> [0,1,1]\n Explanation: Node 1 and 2 are leaves with subtree of size 1, place 1 coin on each of them. For node 0 the only possible product of cost is 2 * 1 * -2 = -4. Hence place 0 coins on node 0.\n \"\"\"\n"}
{"task_id": "minimum-number-game", "prompt": "def numberGame(nums: List[int]) -> List[int]:\n \"\"\"\n You are given a 0-indexed integer array nums of even length and there is also an empty array arr. Alice and Bob decided to play a game where in every round Alice and Bob will do one move. The rules of the game are as follows:\n \n Every round, first Alice will remove the minimum element from nums, and then Bob does the same.\n Now, first Bob will append the removed element in the array arr, and then Alice does the same.\n The game continues until nums becomes empty.\n \n Return the resulting array arr.\n \n Example 1:\n \n >>> numberGame(nums = [5,4,2,3])\n >>> [3,2,5,4]\n Explanation: In round one, first Alice removes 2 and then Bob removes 3. Then in arr firstly Bob appends 3 and then Alice appends 2. So arr = [3,2].\n At the begining of round two, nums = [5,4]. Now, first Alice removes 4 and then Bob removes 5. Then both append in arr which becomes [3,2,5,4].\n \n Example 2:\n \n >>> numberGame(nums = [2,5])\n >>> [5,2]\n Explanation: In round one, first Alice removes 2 and then Bob removes 5. Then in arr firstly Bob appends and then Alice appends. So arr = [5,2].\n \"\"\"\n"}
{"task_id": "maximum-square-area-by-removing-fences-from-a-field", "prompt": "def maximizeSquareArea(m: int, n: int, hFences: List[int], vFences: List[int]) -> int:\n \"\"\"\n There is a large (m - 1) x (n - 1) rectangular field with corners at (1, 1) and (m, n) containing some horizontal and vertical fences given in arrays hFences and vFences respectively.\n Horizontal fences are from the coordinates (hFences[i], 1) to (hFences[i], n) and vertical fences are from the coordinates (1, vFences[i]) to (m, vFences[i]).\n Return the maximum area of a square field that can be formed by removing some fences (possibly none) or -1 if it is impossible to make a square field.\n Since the answer may be large, return it modulo 109 + 7.\n Note: The field is surrounded by two horizontal fences from the coordinates (1, 1) to (1, n) and (m, 1) to (m, n) and two vertical fences from the coordinates (1, 1) to (m, 1) and (1, n) to (m, n). These fences cannot be removed.\n \n Example 1:\n \n \n >>> maximizeSquareArea(m = 4, n = 3, hFences = [2,3], vFences = [2])\n >>> 4\n Explanation: Removing the horizontal fence at 2 and the vertical fence at 2 will give a square field of area 4.\n \n Example 2:\n \n \n >>> maximizeSquareArea(m = 6, n = 7, hFences = [2], vFences = [4])\n >>> -1\n Explanation: It can be proved that there is no way to create a square field by removing fences.\n \"\"\"\n"}
{"task_id": "minimum-cost-to-convert-string-i", "prompt": "def minimumCost(source: str, target: str, original: List[str], changed: List[str], cost: List[int]) -> int:\n \"\"\"\n You are given two 0-indexed strings source and target, both of length n and consisting of lowercase English letters. You are also given two 0-indexed character arrays original and changed, and an integer array cost, where cost[i] represents the cost of changing the character original[i] to the character changed[i].\n You start with the string source. In one operation, you can pick a character x from the string and change it to the character y at a cost of z if there exists any index j such that cost[j] == z, original[j] == x, and changed[j] == y.\n Return the minimum cost to convert the string source to the string target using any number of operations. If it is impossible to convert source to target, return -1.\n Note that there may exist indices i, j such that original[j] == original[i] and changed[j] == changed[i].\n \n Example 1:\n \n >>> minimumCost(source = \"abcd\", target = \"acbe\", original = [\"a\",\"b\",\"c\",\"c\",\"e\",\"d\"], changed = [\"b\",\"c\",\"b\",\"e\",\"b\",\"e\"], cost = [2,5,5,1,2,20])\n >>> 28\n Explanation: To convert the string \"abcd\" to string \"acbe\":\n - Change value at index 1 from 'b' to 'c' at a cost of 5.\n - Change value at index 2 from 'c' to 'e' at a cost of 1.\n - Change value at index 2 from 'e' to 'b' at a cost of 2.\n - Change value at index 3 from 'd' to 'e' at a cost of 20.\n The total cost incurred is 5 + 1 + 2 + 20 = 28.\n It can be shown that this is the minimum possible cost.\n \n Example 2:\n \n >>> minimumCost(source = \"aaaa\", target = \"bbbb\", original = [\"a\",\"c\"], changed = [\"c\",\"b\"], cost = [1,2])\n >>> 12\n Explanation: To change the character 'a' to 'b' change the character 'a' to 'c' at a cost of 1, followed by changing the character 'c' to 'b' at a cost of 2, for a total cost of 1 + 2 = 3. To change all occurrences of 'a' to 'b', a total cost of 3 * 4 = 12 is incurred.\n \n Example 3:\n \n >>> minimumCost(source = \"abcd\", target = \"abce\", original = [\"a\"], changed = [\"e\"], cost = [10000])\n >>> -1\n Explanation: It is impossible to convert source to target because the value at index 3 cannot be changed from 'd' to 'e'.\n \"\"\"\n"}
{"task_id": "minimum-cost-to-convert-string-ii", "prompt": "def minimumCost(source: str, target: str, original: List[str], changed: List[str], cost: List[int]) -> int:\n \"\"\"\n You are given two 0-indexed strings source and target, both of length n and consisting of lowercase English characters. You are also given two 0-indexed string arrays original and changed, and an integer array cost, where cost[i] represents the cost of converting the string original[i] to the string changed[i].\n You start with the string source. In one operation, you can pick a substring x from the string, and change it to y at a cost of z if there exists any index j such that cost[j] == z, original[j] == x, and changed[j] == y. You are allowed to do any number of operations, but any pair of operations must satisfy either of these two conditions:\n \n The substrings picked in the operations are source[a..b] and source[c..d] with either b < c or d < a. In other words, the indices picked in both operations are disjoint.\n The substrings picked in the operations are source[a..b] and source[c..d] with a == c and b == d. In other words, the indices picked in both operations are identical.\n \n Return the minimum cost to convert the string source to the string target using any number of operations. If it is impossible to convert source to target, return -1.\n Note that there may exist indices i, j such that original[j] == original[i] and changed[j] == changed[i].\n \n Example 1:\n \n >>> minimumCost(source = \"abcd\", target = \"acbe\", original = [\"a\",\"b\",\"c\",\"c\",\"e\",\"d\"], changed = [\"b\",\"c\",\"b\",\"e\",\"b\",\"e\"], cost = [2,5,5,1,2,20])\n >>> 28\n Explanation: To convert \"abcd\" to \"acbe\", do the following operations:\n - Change substring source[1..1] from \"b\" to \"c\" at a cost of 5.\n - Change substring source[2..2] from \"c\" to \"e\" at a cost of 1.\n - Change substring source[2..2] from \"e\" to \"b\" at a cost of 2.\n - Change substring source[3..3] from \"d\" to \"e\" at a cost of 20.\n The total cost incurred is 5 + 1 + 2 + 20 = 28.\n It can be shown that this is the minimum possible cost.\n \n Example 2:\n \n >>> minimumCost(source = \"abcdefgh\", target = \"acdeeghh\", original = [\"bcd\",\"fgh\",\"thh\"], changed = [\"cde\",\"thh\",\"ghh\"], cost = [1,3,5])\n >>> 9\n Explanation: To convert \"abcdefgh\" to \"acdeeghh\", do the following operations:\n - Change substring source[1..3] from \"bcd\" to \"cde\" at a cost of 1.\n - Change substring source[5..7] from \"fgh\" to \"thh\" at a cost of 3. We can do this operation because indices [5,7] are disjoint with indices picked in the first operation.\n - Change substring source[5..7] from \"thh\" to \"ghh\" at a cost of 5. We can do this operation because indices [5,7] are disjoint with indices picked in the first operation, and identical with indices picked in the second operation.\n The total cost incurred is 1 + 3 + 5 = 9.\n It can be shown that this is the minimum possible cost.\n \n Example 3:\n \n >>> minimumCost(source = \"abcdefgh\", target = \"addddddd\", original = [\"bcd\",\"defgh\"], changed = [\"ddd\",\"ddddd\"], cost = [100,1578])\n >>> -1\n Explanation: It is impossible to convert \"abcdefgh\" to \"addddddd\".\n If you select substring source[1..3] as the first operation to change \"abcdefgh\" to \"adddefgh\", you cannot select substring source[3..7] as the second operation because it has a common index, 3, with the first operation.\n If you select substring source[3..7] as the first operation to change \"abcdefgh\" to \"abcddddd\", you cannot select substring source[1..3] as the second operation because it has a common index, 3, with the first operation.\n \"\"\"\n"}
{"task_id": "most-expensive-item-that-can-not-be-bought", "prompt": "def mostExpensiveItem(primeOne: int, primeTwo: int) -> int:\n \"\"\"\n You are given two distinct prime numbers primeOne and primeTwo.\n Alice and Bob are visiting a market. The market has an infinite number of items, for any positive integer x there exists an item whose price is x. Alice wants to buy some items from the market to gift to Bob. She has an infinite number of coins in the denomination primeOne and primeTwo. She wants to know the most expensive item she can not buy to gift to Bob.\n Return the price of the most expensive item which Alice can not gift to Bob.\n \n Example 1:\n \n >>> mostExpensiveItem(primeOne = 2, primeTwo = 5)\n >>> 3\n Explanation: The prices of items which cannot be bought are [1,3]. It can be shown that all items with a price greater than 3 can be bought using a combination of coins of denominations 2 and 5.\n \n Example 2:\n \n >>> mostExpensiveItem(primeOne = 5, primeTwo = 7)\n >>> 23\n Explanation: The prices of items which cannot be bought are [1,2,3,4,6,8,9,11,13,16,18,23]. It can be shown that all items with a price greater than 23 can be bought.\n \"\"\"\n"}
{"task_id": "check-if-bitwise-or-has-trailing-zeros", "prompt": "def hasTrailingZeros(nums: List[int]) -> bool:\n \"\"\"\n You are given an array of positive integers nums.\n You have to check if it is possible to select two or more elements in the array such that the bitwise OR of the selected elements has at least one trailing zero in its binary representation.\n For example, the binary representation of 5, which is \"101\", does not have any trailing zeros, whereas the binary representation of 4, which is \"100\", has two trailing zeros.\n Return true if it is possible to select two or more elements whose bitwise OR has trailing zeros, return false otherwise.\n \n Example 1:\n \n >>> hasTrailingZeros(nums = [1,2,3,4,5])\n >>> true\n Explanation: If we select the elements 2 and 4, their bitwise OR is 6, which has the binary representation \"110\" with one trailing zero.\n \n Example 2:\n \n >>> hasTrailingZeros(nums = [2,4,8,16])\n >>> true\n Explanation: If we select the elements 2 and 4, their bitwise OR is 6, which has the binary representation \"110\" with one trailing zero.\n Other possible ways to select elements to have trailing zeroes in the binary representation of their bitwise OR are: (2, 8), (2, 16), (4, 8), (4, 16), (8, 16), (2, 4, 8), (2, 4, 16), (2, 8, 16), (4, 8, 16), and (2, 4, 8, 16).\n \n Example 3:\n \n >>> hasTrailingZeros(nums = [1,3,5,7,9])\n >>> false\n Explanation: There is no possible way to select two or more elements to have trailing zeros in the binary representation of their bitwise OR.\n \"\"\"\n"}
{"task_id": "find-longest-special-substring-that-occurs-thrice-i", "prompt": "def maximumLength(s: str) -> int:\n \"\"\"\n You are given a string s that consists of lowercase English letters.\n A string is called special if it is made up of only a single character. For example, the string \"abc\" is not special, whereas the strings \"ddd\", \"zz\", and \"f\" are special.\n Return the length of the longest special substring of s which occurs at least thrice, or -1 if no special substring occurs at least thrice.\n A substring is a contiguous non-empty sequence of characters within a string.\n \n Example 1:\n \n >>> maximumLength(s = \"aaaa\")\n >>> 2\n Explanation: The longest special substring which occurs thrice is \"aa\": substrings \"aaaa\", \"aaaa\", and \"aaaa\".\n It can be shown that the maximum length achievable is 2.\n \n Example 2:\n \n >>> maximumLength(s = \"abcdef\")\n >>> -1\n Explanation: There exists no special substring which occurs at least thrice. Hence return -1.\n \n Example 3:\n \n >>> maximumLength(s = \"abcaba\")\n >>> 1\n Explanation: The longest special substring which occurs thrice is \"a\": substrings \"abcaba\", \"abcaba\", and \"abcaba\".\n It can be shown that the maximum length achievable is 1.\n \"\"\"\n"}
{"task_id": "find-longest-special-substring-that-occurs-thrice-ii", "prompt": "def maximumLength(s: str) -> int:\n \"\"\"\n You are given a string s that consists of lowercase English letters.\n A string is called special if it is made up of only a single character. For example, the string \"abc\" is not special, whereas the strings \"ddd\", \"zz\", and \"f\" are special.\n Return the length of the longest special substring of s which occurs at least thrice, or -1 if no special substring occurs at least thrice.\n A substring is a contiguous non-empty sequence of characters within a string.\n \n Example 1:\n \n >>> maximumLength(s = \"aaaa\")\n >>> 2\n Explanation: The longest special substring which occurs thrice is \"aa\": substrings \"aaaa\", \"aaaa\", and \"aaaa\".\n It can be shown that the maximum length achievable is 2.\n \n Example 2:\n \n >>> maximumLength(s = \"abcdef\")\n >>> -1\n Explanation: There exists no special substring which occurs at least thrice. Hence return -1.\n \n Example 3:\n \n >>> maximumLength(s = \"abcaba\")\n >>> 1\n Explanation: The longest special substring which occurs thrice is \"a\": substrings \"abcaba\", \"abcaba\", and \"abcaba\".\n It can be shown that the maximum length achievable is 1.\n \"\"\"\n"}
{"task_id": "palindrome-rearrangement-queries", "prompt": "def canMakePalindromeQueries(s: str, queries: List[List[int]]) -> List[bool]:\n \"\"\"\n You are given a 0-indexed string s having an even length n.\n You are also given a 0-indexed 2D integer array, queries, where queries[i] = [ai, bi, ci, di].\n For each query i, you are allowed to perform the following operations:\n \n Rearrange the characters within the substring s[ai:bi], where 0 <= ai <= bi < n / 2.\n Rearrange the characters within the substring s[ci:di], where n / 2 <= ci <= di < n.\n \n For each query, your task is to determine whether it is possible to make s a palindrome by performing the operations.\n Each query is answered independently of the others.\n Return a 0-indexed array answer, where answer[i] == true if it is possible to make s a palindrome by performing operations specified by the ith query, and false otherwise.\n \n A substring is a contiguous sequence of characters within a string.\n s[x:y] represents the substring consisting of characters from the index x to index y in s, both inclusive.\n \n \n Example 1:\n \n >>> canMakePalindromeQueries(s = \"abcabc\", queries = [[1,1,3,5],[0,2,5,5]])\n >>> [true,true]\n Explanation: In this example, there are two queries:\n In the first query:\n - a0 = 1, b0 = 1, c0 = 3, d0 = 5.\n - So, you are allowed to rearrange s[1:1] => abcabc and s[3:5] => abcabc.\n - To make s a palindrome, s[3:5] can be rearranged to become => abccba.\n - Now, s is a palindrome. So, answer[0] = true.\n In the second query:\n - a1 = 0, b1 = 2, c1 = 5, d1 = 5.\n - So, you are allowed to rearrange s[0:2] => abcabc and s[5:5] => abcabc.\n - To make s a palindrome, s[0:2] can be rearranged to become => cbaabc.\n - Now, s is a palindrome. So, answer[1] = true.\n \n Example 2:\n \n >>> canMakePalindromeQueries(s = \"abbcdecbba\", queries = [[0,2,7,9]])\n >>> [false]\n Explanation: In this example, there is only one query.\n a0 = 0, b0 = 2, c0 = 7, d0 = 9.\n So, you are allowed to rearrange s[0:2] => abbcdecbba and s[7:9] => abbcdecbba.\n It is not possible to make s a palindrome by rearranging these substrings because s[3:6] is not a palindrome.\n So, answer[0] = false.\n Example 3:\n \n >>> canMakePalindromeQueries(s = \"acbcab\", queries = [[1,2,4,5]])\n >>> [true]\n Explanation: In this example, there is only one query.\n a0 = 1, b0 = 2, c0 = 4, d0 = 5.\n So, you are allowed to rearrange s[1:2] => acbcab and s[4:5] => acbcab.\n To make s a palindrome s[1:2] can be rearranged to become abccab.\n Then, s[4:5] can be rearranged to become abccba.\n Now, s is a palindrome. So, answer[0] = true.\n \"\"\"\n"}
{"task_id": "number-of-self-divisible-permutations", "prompt": "def selfDivisiblePermutationCount(n: int) -> int:\n \"\"\"\n Given an integer n, return the number of permutations of the 1-indexed array nums = [1, 2, ..., n], such that it's self-divisible.\n A 1-indexed array a of length n is self-divisible if for every 1 <= i <= n, gcd(a[i], i) == 1.\n A permutation of an array is a rearrangement of the elements of that array, for example here are all of the permutations of the array [1, 2, 3]:\n \n [1, 2, 3]\n [1, 3, 2]\n [2, 1, 3]\n [2, 3, 1]\n [3, 1, 2]\n [3, 2, 1]\n \n \n Example 1:\n \n >>> selfDivisiblePermutationCount(n = 1)\n >>> 1\n Explanation: The array [1] has only 1 permutation which is self-divisible.\n \n Example 2:\n \n >>> selfDivisiblePermutationCount(n = 2)\n >>> 1\n Explanation: The array [1,2] has 2 permutations and only one of them is self-divisible:\n nums = [1,2]: This is not self-divisible since gcd(nums[2], 2) != 1.\n nums = [2,1]: This is self-divisible since gcd(nums[1], 1) == 1 and gcd(nums[2], 2) == 1.\n \n Example 3:\n \n >>> selfDivisiblePermutationCount(n = 3)\n >>> 3\n Explanation: The array [1,2,3] has 3 self-divisble permutations: [1,3,2], [3,1,2], [2,3,1].\n It can be shown that the other 3 permutations are not self-divisible. Hence the answer is 3.\n \"\"\"\n"}
{"task_id": "smallest-missing-integer-greater-than-sequential-prefix-sum", "prompt": "def missingInteger(nums: List[int]) -> int:\n \"\"\"\n You are given a 0-indexed array of integers nums.\n A prefix nums[0..i] is sequential if, for all 1 <= j <= i, nums[j] = nums[j - 1] + 1. In particular, the prefix consisting only of nums[0] is sequential.\n Return the smallest integer x missing from nums such that x is greater than or equal to the sum of the longest sequential prefix.\n \n Example 1:\n \n >>> missingInteger(nums = [1,2,3,2,5])\n >>> 6\n Explanation: The longest sequential prefix of nums is [1,2,3] with a sum of 6. 6 is not in the array, therefore 6 is the smallest missing integer greater than or equal to the sum of the longest sequential prefix.\n \n Example 2:\n \n >>> missingInteger(nums = [3,4,5,1,12,14,13])\n >>> 15\n Explanation: The longest sequential prefix of nums is [3,4,5] with a sum of 12. 12, 13, and 14 belong to the array while 15 does not. Therefore 15 is the smallest missing integer greater than or equal to the sum of the longest sequential prefix.\n \"\"\"\n"}
{"task_id": "minimum-number-of-operations-to-make-array-xor-equal-to-k", "prompt": "def minOperations(nums: List[int], k: int) -> int:\n \"\"\"\n You are given a 0-indexed integer array nums and a positive integer k.\n You can apply the following operation on the array any number of times:\n \n Choose any element of the array and flip a bit in its binary representation. Flipping a bit means changing a 0 to 1 or vice versa.\n \n Return the minimum number of operations required to make the bitwise XOR of all elements of the final array equal to k.\n Note that you can flip leading zero bits in the binary representation of elements. For example, for the number (101)2 you can flip the fourth bit and obtain (1101)2.\n \n Example 1:\n \n >>> minOperations(nums = [2,1,3,4], k = 1)\n >>> 2\n Explanation: We can do the following operations:\n - Choose element 2 which is 3 == (011)2, we flip the first bit and we obtain (010)2 == 2. nums becomes [2,1,2,4].\n - Choose element 0 which is 2 == (010)2, we flip the third bit and we obtain (110)2 = 6. nums becomes [6,1,2,4].\n The XOR of elements of the final array is (6 XOR 1 XOR 2 XOR 4) == 1 == k.\n It can be shown that we cannot make the XOR equal to k in less than 2 operations.\n \n Example 2:\n \n >>> minOperations(nums = [2,0,2,0], k = 0)\n >>> 0\n Explanation: The XOR of elements of the array is (2 XOR 0 XOR 2 XOR 0) == 0 == k. So no operation is needed.\n \"\"\"\n"}
{"task_id": "minimum-number-of-operations-to-make-x-and-y-equal", "prompt": "def minimumOperationsToMakeEqual(x: int, y: int) -> int:\n \"\"\"\n You are given two positive integers x and y.\n In one operation, you can do one of the four following operations:\n \n Divide x by 11 if x is a multiple of 11.\n Divide x by 5 if x is a multiple of 5.\n Decrement x by 1.\n Increment x by 1.\n \n Return the minimum number of operations required to make x and y equal.\n \n Example 1:\n \n >>> minimumOperationsToMakeEqual(x = 26, y = 1)\n >>> 3\n Explanation: We can make 26 equal to 1 by applying the following operations:\n 1. Decrement x by 1\n 2. Divide x by 5\n 3. Divide x by 5\n It can be shown that 3 is the minimum number of operations required to make 26 equal to 1.\n \n Example 2:\n \n >>> minimumOperationsToMakeEqual(x = 54, y = 2)\n >>> 4\n Explanation: We can make 54 equal to 2 by applying the following operations:\n 1. Increment x by 1\n 2. Divide x by 11\n 3. Divide x by 5\n 4. Increment x by 1\n It can be shown that 4 is the minimum number of operations required to make 54 equal to 2.\n \n Example 3:\n \n >>> minimumOperationsToMakeEqual(x = 25, y = 30)\n >>> 5\n Explanation: We can make 25 equal to 30 by applying the following operations:\n 1. Increment x by 1\n 2. Increment x by 1\n 3. Increment x by 1\n 4. Increment x by 1\n 5. Increment x by 1\n It can be shown that 5 is the minimum number of operations required to make 25 equal to 30.\n \"\"\"\n"}
{"task_id": "count-the-number-of-powerful-integers", "prompt": "def numberOfPowerfulInt(start: int, finish: int, limit: int, s: str) -> int:\n \"\"\"\n You are given three integers start, finish, and limit. You are also given a 0-indexed string s representing a positive integer.\n A positive integer x is called powerful if it ends with s (in other words, s is a suffix of x) and each digit in x is at most limit.\n Return the total number of powerful integers in the range [start..finish].\n A string x is a suffix of a string y if and only if x is a substring of y that starts from some index (including 0) in y and extends to the index y.length - 1. For example, 25 is a suffix of 5125 whereas 512 is not.\n \n Example 1:\n \n >>> numberOfPowerfulInt(start = 1, finish = 6000, limit = 4, s = \"124\")\n >>> 5\n Explanation: The powerful integers in the range [1..6000] are 124, 1124, 2124, 3124, and, 4124. All these integers have each digit <= 4, and \"124\" as a suffix. Note that 5124 is not a powerful integer because the first digit is 5 which is greater than 4.\n It can be shown that there are only 5 powerful integers in this range.\n \n Example 2:\n \n >>> numberOfPowerfulInt(start = 15, finish = 215, limit = 6, s = \"10\")\n >>> 2\n Explanation: The powerful integers in the range [15..215] are 110 and 210. All these integers have each digit <= 6, and \"10\" as a suffix.\n It can be shown that there are only 2 powerful integers in this range.\n \n Example 3:\n \n >>> numberOfPowerfulInt(start = 1000, finish = 2000, limit = 4, s = \"3000\")\n >>> 0\n Explanation: All integers in the range [1000..2000] are smaller than 3000, hence \"3000\" cannot be a suffix of any integer in this range.\n \"\"\"\n"}
{"task_id": "maximum-area-of-longest-diagonal-rectangle", "prompt": "def areaOfMaxDiagonal(dimensions: List[List[int]]) -> int:\n \"\"\"\n You are given a 2D 0-indexed integer array dimensions.\n For all indices i, 0 <= i < dimensions.length, dimensions[i][0] represents the length and dimensions[i][1] represents the width of the rectangle i.\n Return the area of the rectangle having the longest diagonal. If there are multiple rectangles with the longest diagonal, return the area of the rectangle having the maximum area.\n \n Example 1:\n \n >>> areaOfMaxDiagonal(dimensions = [[9,3],[8,6]])\n >>> 48\n Explanation:\n For index = 0, length = 9 and width = 3. Diagonal length = sqrt(9 * 9 + 3 * 3) = sqrt(90) \u2248 9.487.\n For index = 1, length = 8 and width = 6. Diagonal length = sqrt(8 * 8 + 6 * 6) = sqrt(100) = 10.\n So, the rectangle at index 1 has a greater diagonal length therefore we return area = 8 * 6 = 48.\n \n Example 2:\n \n >>> areaOfMaxDiagonal(dimensions = [[3,4],[4,3]])\n >>> 12\n Explanation: Length of diagonal is the same for both which is 5, so maximum area = 12.\n \"\"\"\n"}
{"task_id": "minimum-moves-to-capture-the-queen", "prompt": "def minMovesToCaptureTheQueen(a: int, b: int, c: int, d: int, e: int, f: int) -> int:\n \"\"\"\n There is a 1-indexed 8 x 8 chessboard containing 3 pieces.\n You are given 6 integers a, b, c, d, e, and f where:\n \n (a, b) denotes the position of the white rook.\n (c, d) denotes the position of the white bishop.\n (e, f) denotes the position of the black queen.\n \n Given that you can only move the white pieces, return the minimum number of moves required to capture the black queen.\n Note that:\n \n Rooks can move any number of squares either vertically or horizontally, but cannot jump over other pieces.\n Bishops can move any number of squares diagonally, but cannot jump over other pieces.\n A rook or a bishop can capture the queen if it is located in a square that they can move to.\n The queen does not move.\n \n \n Example 1:\n \n \n >>> minMovesToCaptureTheQueen(a = 1, b = 1, c = 8, d = 8, e = 2, f = 3)\n >>> 2\n Explanation: We can capture the black queen in two moves by moving the white rook to (1, 3) then to (2, 3).\n It is impossible to capture the black queen in less than two moves since it is not being attacked by any of the pieces at the beginning.\n \n Example 2:\n \n \n >>> minMovesToCaptureTheQueen(a = 5, b = 3, c = 3, d = 4, e = 5, f = 2)\n >>> 1\n Explanation: We can capture the black queen in a single move by doing one of the following:\n - Move the white rook to (5, 2).\n - Move the white bishop to (5, 2).\n \"\"\"\n"}
{"task_id": "maximum-size-of-a-set-after-removals", "prompt": "def maximumSetSize(nums1: List[int], nums2: List[int]) -> int:\n \"\"\"\n You are given two 0-indexed integer arrays nums1 and nums2 of even length n.\n You must remove n / 2 elements from nums1 and n / 2 elements from nums2. After the removals, you insert the remaining elements of nums1 and nums2 into a set s.\n Return the maximum possible size of the set s.\n \n Example 1:\n \n >>> maximumSetSize(nums1 = [1,2,1,2], nums2 = [1,1,1,1])\n >>> 2\n Explanation: We remove two occurences of 1 from nums1 and nums2. After the removals, the arrays become equal to nums1 = [2,2] and nums2 = [1,1]. Therefore, s = {1,2}.\n It can be shown that 2 is the maximum possible size of the set s after the removals.\n \n Example 2:\n \n >>> maximumSetSize(nums1 = [1,2,3,4,5,6], nums2 = [2,3,2,3,2,3])\n >>> 5\n Explanation: We remove 2, 3, and 6 from nums1, as well as 2 and two occurrences of 3 from nums2. After the removals, the arrays become equal to nums1 = [1,4,5] and nums2 = [2,3,2]. Therefore, s = {1,2,3,4,5}.\n It can be shown that 5 is the maximum possible size of the set s after the removals.\n \n Example 3:\n \n >>> maximumSetSize(nums1 = [1,1,2,2,3,3], nums2 = [4,4,5,5,6,6])\n >>> 6\n Explanation: We remove 1, 2, and 3 from nums1, as well as 4, 5, and 6 from nums2. After the removals, the arrays become equal to nums1 = [1,2,3] and nums2 = [4,5,6]. Therefore, s = {1,2,3,4,5,6}.\n It can be shown that 6 is the maximum possible size of the set s after the removals.\n \"\"\"\n"}
{"task_id": "maximize-the-number-of-partitions-after-operations", "prompt": "def maxPartitionsAfterOperations(s: str, k: int) -> int:\n \"\"\"\n You are given a string s and an integer k.\n First, you are allowed to change at most one index in s to another lowercase English letter.\n After that, do the following partitioning operation until s is empty:\n \n Choose the longest prefix of s containing at most k distinct characters.\n Delete the prefix from s and increase the number of partitions by one. The remaining characters (if any) in s maintain their initial order.\n \n Return an integer denoting the maximum number of resulting partitions after the operations by optimally choosing at most one index to change.\n \n Example 1:\n \n >>> maxPartitionsAfterOperations(s = \"accca\", k = 2)\n >>> 3\n Explanation:\n The optimal way is to change s[2] to something other than a and c, for example, b. then it becomes \"acbca\".\n Then we perform the operations:\n \n The longest prefix containing at most 2 distinct characters is \"ac\", we remove it and s becomes \"bca\".\n Now The longest prefix containing at most 2 distinct characters is \"bc\", so we remove it and s becomes \"a\".\n Finally, we remove \"a\" and s becomes empty, so the procedure ends.\n \n Doing the operations, the string is divided into 3 partitions, so the answer is 3.\n \n Example 2:\n \n >>> maxPartitionsAfterOperations(s = \"aabaab\", k = 3)\n >>> 1\n Explanation:\n Initially\u00a0s\u00a0contains 2 distinct characters, so whichever character we change, it will contain at most 3 distinct characters, so the longest prefix with at most 3 distinct characters would always be all of it, therefore the answer is 1.\n \n Example 3:\n \n >>> maxPartitionsAfterOperations(s = \"xxyz\", k = 1)\n >>> 4\n Explanation:\n The optimal way is to change\u00a0s[0]\u00a0or\u00a0s[1]\u00a0to something other than characters in\u00a0s, for example, to change\u00a0s[0]\u00a0to\u00a0w.\n Then\u00a0s\u00a0becomes \"wxyz\", which consists of 4 distinct characters, so as k is 1, it will divide into 4 partitions.\n \"\"\"\n"}
{"task_id": "maximum-subtree-of-the-same-color", "prompt": "def maximumSubtreeSize(edges: List[List[int]], colors: List[int]) -> int:\n \"\"\"\n You are given a 2D integer array edges representing a tree with n nodes, numbered from 0 to n - 1, rooted at node 0, where edges[i] = [ui, vi] means there is an edge between the nodes vi and ui.\n You are also given a 0-indexed integer array colors of size n, where colors[i] is the color assigned to node i.\n We want to find a node v such that every node in the subtree of v has the same color.\n Return the size of such subtree with the maximum number of nodes possible.\n \n \n Example 1:\n \n >>> maximumSubtreeSize(edges = [[0,1],[0,2],[0,3]], colors = [1,1,2,3])\n >>> 1\n Explanation: Each color is represented as: 1 -> Red, 2 -> Green, 3 -> Blue. We can see that the subtree rooted at node 0 has children with different colors. Any other subtree is of the same color and has a size of 1. Hence, we return 1.\n \n Example 2:\n \n >>> maximumSubtreeSize(edges = [[0,1],[0,2],[0,3]], colors = [1,1,1,1])\n >>> 4\n Explanation: The whole tree has the same color, and the subtree rooted at node 0 has the most number of nodes which is 4. Hence, we return 4.\n \n \n Example 3:\n \n >>> maximumSubtreeSize(edges = [[0,1],[0,2],[2,3],[2,4]], colors = [1,2,3,3,3])\n >>> 3\n Explanation: Each color is represented as: 1 -> Red, 2 -> Green, 3 -> Blue. We can see that the subtree rooted at node 0 has children with different colors. Any other subtree is of the same color, but the subtree rooted at node 2 has a size of 3 which is the maximum. Hence, we return 3.\n \"\"\"\n"}
{"task_id": "count-elements-with-maximum-frequency", "prompt": "def maxFrequencyElements(nums: List[int]) -> int:\n \"\"\"\n You are given an array nums consisting of positive integers.\n Return the total frequencies of elements in nums\u00a0such that those elements all have the maximum frequency.\n The frequency of an element is the number of occurrences of that element in the array.\n \n Example 1:\n \n >>> maxFrequencyElements(nums = [1,2,2,3,1,4])\n >>> 4\n Explanation: The elements 1 and 2 have a frequency of 2 which is the maximum frequency in the array.\n So the number of elements in the array with maximum frequency is 4.\n \n Example 2:\n \n >>> maxFrequencyElements(nums = [1,2,3,4,5])\n >>> 5\n Explanation: All elements of the array have a frequency of 1 which is the maximum.\n So the number of elements in the array with maximum frequency is 5.\n \"\"\"\n"}
{"task_id": "find-beautiful-indices-in-the-given-array-i", "prompt": "def beautifulIndices(s: str, a: str, b: str, k: int) -> List[int]:\n \"\"\"\n You are given a 0-indexed string s, a string a, a string b, and an integer k.\n An index i is beautiful if:\n \n 0 <= i <= s.length - a.length\n s[i..(i + a.length - 1)] == a\n There exists an index j such that:\n \n 0 <= j <= s.length - b.length\n s[j..(j + b.length - 1)] == b\n |j - i| <= k\n \n \n \n Return the array that contains beautiful indices in sorted order from smallest to largest.\n \n Example 1:\n \n >>> beautifulIndices(s = \"isawsquirrelnearmysquirrelhouseohmy\", a = \"my\", b = \"squirrel\", k = 15)\n >>> [16,33]\n Explanation: There are 2 beautiful indices: [16,33].\n - The index 16 is beautiful as s[16..17] == \"my\" and there exists an index 4 with s[4..11] == \"squirrel\" and |16 - 4| <= 15.\n - The index 33 is beautiful as s[33..34] == \"my\" and there exists an index 18 with s[18..25] == \"squirrel\" and |33 - 18| <= 15.\n Thus we return [16,33] as the result.\n \n Example 2:\n \n >>> beautifulIndices(s = \"abcd\", a = \"a\", b = \"a\", k = 4)\n >>> [0]\n Explanation: There is 1 beautiful index: [0].\n - The index 0 is beautiful as s[0..0] == \"a\" and there exists an index 0 with s[0..0] == \"a\" and |0 - 0| <= 4.\n Thus we return [0] as the result.\n \"\"\"\n"}
{"task_id": "maximum-number-that-sum-of-the-prices-is-less-than-or-equal-to-k", "prompt": "def findMaximumNumber(k: int, x: int) -> int:\n \"\"\"\n You are given an integer k and an integer x. The price of a number\u00a0num is calculated by the count of set bits at positions x, 2x, 3x, etc., in its binary representation, starting from the least significant bit. The following table contains examples of how price is calculated.\n \n \n \n x\n num\n Binary Representation\n Price\n \n \n 1\n 13\n 000001101\n 3\n \n \n 2\n 13\n 000001101\n 1\n \n \n 2\n 233\n 011101001\n 3\n \n \n 3\n 13\n 000001101\n 1\n \n \n 3\n 362\n 101101010\n 2\n \n \n \n The\u00a0accumulated price\u00a0of\u00a0num\u00a0is the total\u00a0price of\u00a0numbers from 1 to num. num\u00a0is considered\u00a0cheap\u00a0if its accumulated price\u00a0is less than or equal to k.\n Return the greatest\u00a0cheap number.\n \n Example 1:\n \n >>> findMaximumNumber(k = 9, x = 1)\n >>> 6\n Explanation:\n As shown in the table below, 6 is the greatest cheap number.\n \n \n \n x\n num\n Binary Representation\n Price\n Accumulated Price\n \n \n 1\n 1\n 001\n 1\n 1\n \n \n 1\n 2\n 010\n 1\n 2\n \n \n 1\n 3\n 011\n 2\n 4\n \n \n 1\n 4\n 100\n 1\n 5\n \n \n 1\n 5\n 101\n 2\n 7\n \n \n 1\n 6\n 110\n 2\n 9\n \n \n 1\n 7\n 111\n 3\n 12\n \n \n \n \n Example 2:\n \n >>> findMaximumNumber(k = 7, x = 2)\n >>> 9\n Explanation:\n As shown in the table below, 9 is the greatest cheap number.\n \n \n \n x\n num\n Binary Representation\n Price\n Accumulated Price\n \n \n 2\n 1\n 0001\n 0\n 0\n \n \n 2\n 2\n 0010\n 1\n 1\n \n \n 2\n 3\n 0011\n 1\n 2\n \n \n 2\n 4\n 0100\n 0\n 2\n \n \n 2\n 5\n 0101\n 0\n 2\n \n \n 2\n 6\n 0110\n 1\n 3\n \n \n 2\n 7\n 0111\n 1\n 4\n \n \n 2\n 8\n 1000\n 1\n 5\n \n \n 2\n 9\n 1001\n 1\n 6\n \n \n 2\n 10\n 1010\n 2\n 8\n \"\"\"\n"}
{"task_id": "find-beautiful-indices-in-the-given-array-ii", "prompt": "def beautifulIndices(s: str, a: str, b: str, k: int) -> List[int]:\n \"\"\"\n You are given a 0-indexed string s, a string a, a string b, and an integer k.\n An index i is beautiful if:\n \n 0 <= i <= s.length - a.length\n s[i..(i + a.length - 1)] == a\n There exists an index j such that:\n \n 0 <= j <= s.length - b.length\n s[j..(j + b.length - 1)] == b\n |j - i| <= k\n \n \n \n Return the array that contains beautiful indices in sorted order from smallest to largest.\n \n Example 1:\n \n >>> beautifulIndices(s = \"isawsquirrelnearmysquirrelhouseohmy\", a = \"my\", b = \"squirrel\", k = 15)\n >>> [16,33]\n Explanation: There are 2 beautiful indices: [16,33].\n - The index 16 is beautiful as s[16..17] == \"my\" and there exists an index 4 with s[4..11] == \"squirrel\" and |16 - 4| <= 15.\n - The index 33 is beautiful as s[33..34] == \"my\" and there exists an index 18 with s[18..25] == \"squirrel\" and |33 - 18| <= 15.\n Thus we return [16,33] as the result.\n \n Example 2:\n \n >>> beautifulIndices(s = \"abcd\", a = \"a\", b = \"a\", k = 4)\n >>> [0]\n Explanation: There is 1 beautiful index: [0].\n - The index 0 is beautiful as s[0..0] == \"a\" and there exists an index 0 with s[0..0] == \"a\" and |0 - 0| <= 4.\n Thus we return [0] as the result.\n \"\"\"\n"}
{"task_id": "maximum-number-of-intersections-on-the-chart", "prompt": "def maxIntersectionCount(y: List[int]) -> int:\n \"\"\"\n There is a line chart consisting of n points connected by line segments. You are given a 1-indexed integer array y. The kth point has coordinates (k, y[k]). There are no horizontal lines; that is, no two consecutive points have the same y-coordinate.\n We can draw an infinitely long horizontal line. Return the maximum number of points of intersection of the line with the chart.\n \n Example 1:\n \n \n >>> maxIntersectionCount(y = [1,2,1,2,1,3,2])\n >>> 5\n Explanation: As you can see in the image above, the line y = 1.5 has 5 intersections with the chart (in red crosses). You can also see the line y = 2 which intersects the chart in 4 points (in red crosses). It can be shown that there is no horizontal line intersecting the chart at more than 5 points. So the answer would be 5.\n \n Example 2:\n \n \n >>> maxIntersectionCount(y = [2,1,3,4,5])\n >>> 2\n Explanation: As you can see in the image above, the line y = 1.5 has 2 intersections with the chart (in red crosses). You can also see the line y = 2 which intersects the chart in 2 points (in red crosses). It can be shown that there is no horizontal line intersecting the chart at more than 2 points. So the answer would be 2.\n \"\"\"\n"}
{"task_id": "divide-an-array-into-subarrays-with-minimum-cost-i", "prompt": "def minimumCost(nums: List[int]) -> int:\n \"\"\"\n You are given an array of integers nums of length n.\n The cost of an array is the value of its first element. For example, the cost of [1,2,3] is 1 while the cost of [3,4,1] is 3.\n You need to divide nums into 3 disjoint contiguous subarrays.\n Return the minimum possible sum of the cost of these subarrays.\n \n Example 1:\n \n >>> minimumCost(nums = [1,2,3,12])\n >>> 6\n Explanation: The best possible way to form 3 subarrays is: [1], [2], and [3,12] at a total cost of 1 + 2 + 3 = 6.\n The other possible ways to form 3 subarrays are:\n - [1], [2,3], and [12] at a total cost of 1 + 2 + 12 = 15.\n - [1,2], [3], and [12] at a total cost of 1 + 3 + 12 = 16.\n \n Example 2:\n \n >>> minimumCost(nums = [5,4,3])\n >>> 12\n Explanation: The best possible way to form 3 subarrays is: [5], [4], and [3] at a total cost of 5 + 4 + 3 = 12.\n It can be shown that 12 is the minimum cost achievable.\n \n Example 3:\n \n >>> minimumCost(nums = [10,3,1,1])\n >>> 12\n Explanation: The best possible way to form 3 subarrays is: [10,3], [1], and [1] at a total cost of 10 + 1 + 1 = 12.\n It can be shown that 12 is the minimum cost achievable.\n \"\"\"\n"}
{"task_id": "find-if-array-can-be-sorted", "prompt": "def canSortArray(nums: List[int]) -> bool:\n \"\"\"\n You are given a 0-indexed array of positive integers nums.\n In one operation, you can swap any two adjacent elements if they have the same number of set bits. You are allowed to do this operation any number of times (including zero).\n Return true if you can sort the array in ascending order, else return false.\n \n Example 1:\n \n >>> canSortArray(nums = [8,4,2,30,15])\n >>> true\n Explanation: Let's look at the binary representation of every element. The numbers 2, 4, and 8 have one set bit each with binary representation \"10\", \"100\", and \"1000\" respectively. The numbers 15 and 30 have four set bits each with binary representation \"1111\" and \"11110\".\n We can sort the array using 4 operations:\n - Swap nums[0] with nums[1]. This operation is valid because 8 and 4 have one set bit each. The array becomes [4,8,2,30,15].\n - Swap nums[1] with nums[2]. This operation is valid because 8 and 2 have one set bit each. The array becomes [4,2,8,30,15].\n - Swap nums[0] with nums[1]. This operation is valid because 4 and 2 have one set bit each. The array becomes [2,4,8,30,15].\n - Swap nums[3] with nums[4]. This operation is valid because 30 and 15 have four set bits each. The array becomes [2,4,8,15,30].\n The array has become sorted, hence we return true.\n Note that there may be other sequences of operations which also sort the array.\n \n Example 2:\n \n >>> canSortArray(nums = [1,2,3,4,5])\n >>> true\n Explanation: The array is already sorted, hence we return true.\n \n Example 3:\n \n >>> canSortArray(nums = [3,16,8,4,2])\n >>> false\n Explanation: It can be shown that it is not possible to sort the input array using any number of operations.\n \"\"\"\n"}
{"task_id": "minimize-length-of-array-using-operations", "prompt": "def minimumArrayLength(nums: List[int]) -> int:\n \"\"\"\n You are given a 0-indexed integer array nums containing positive integers.\n Your task is to minimize the length of nums by performing the following operations any number of times (including zero):\n \n Select two distinct indices i and j from nums, such that nums[i] > 0 and nums[j] > 0.\n Insert the result of nums[i] % nums[j] at the end of nums.\n Delete the elements at indices i and j from nums.\n \n Return an integer denoting the minimum length of nums after performing the operation any number of times.\n \n Example 1:\n \n >>> minimumArrayLength(nums = [1,4,3,1])\n >>> 1\n Explanation: One way to minimize the length of the array is as follows:\n Operation 1: Select indices 2 and 1, insert nums[2] % nums[1] at the end and it becomes [1,4,3,1,3], then delete elements at indices 2 and 1.\n nums becomes [1,1,3].\n Operation 2: Select indices 1 and 2, insert nums[1] % nums[2] at the end and it becomes [1,1,3,1], then delete elements at indices 1 and 2.\n nums becomes [1,1].\n Operation 3: Select indices 1 and 0, insert nums[1] % nums[0] at the end and it becomes [1,1,0], then delete elements at indices 1 and 0.\n nums becomes [0].\n The length of nums cannot be reduced further. Hence, the answer is 1.\n It can be shown that 1 is the minimum achievable length.\n Example 2:\n \n >>> minimumArrayLength(nums = [5,5,5,10,5])\n >>> 2\n Explanation: One way to minimize the length of the array is as follows:\n Operation 1: Select indices 0 and 3, insert nums[0] % nums[3] at the end and it becomes [5,5,5,10,5,5], then delete elements at indices 0 and 3.\n nums becomes [5,5,5,5].\n Operation 2: Select indices 2 and 3, insert nums[2] % nums[3] at the end and it becomes [5,5,5,5,0], then delete elements at indices 2 and 3.\n nums becomes [5,5,0].\n Operation 3: Select indices 0 and 1, insert nums[0] % nums[1] at the end and it becomes [5,5,0,0], then delete elements at indices 0 and 1.\n nums becomes [0,0].\n The length of nums cannot be reduced further. Hence, the answer is 2.\n It can be shown that 2 is the minimum achievable length.\n Example 3:\n \n >>> minimumArrayLength(nums = [2,3,4])\n >>> 1\n Explanation: One way to minimize the length of the array is as follows:\n Operation 1: Select indices 1 and 2, insert nums[1] % nums[2] at the end and it becomes [2,3,4,3], then delete elements at indices 1 and 2.\n nums becomes [2,3].\n Operation 2: Select indices 1 and 0, insert nums[1] % nums[0] at the end and it becomes [2,3,1], then delete elements at indices 1 and 0.\n nums becomes [1].\n The length of nums cannot be reduced further. Hence, the answer is 1.\n It can be shown that 1 is the minimum achievable length.\n \"\"\"\n"}
{"task_id": "divide-an-array-into-subarrays-with-minimum-cost-ii", "prompt": "def minimumCost(nums: List[int], k: int, dist: int) -> int:\n \"\"\"\n You are given a 0-indexed array of integers nums of length n, and two positive integers k and dist.\n The cost of an array is the value of its first element. For example, the cost of [1,2,3] is 1 while the cost of [3,4,1] is 3.\n You need to divide nums into k disjoint contiguous subarrays, such that the difference between the starting index of the second subarray and the starting index of the kth subarray should be less than or equal to dist. In other words, if you divide nums into the subarrays nums[0..(i1 - 1)], nums[i1..(i2 - 1)], ..., nums[ik-1..(n - 1)], then ik-1 - i1 <= dist.\n Return the minimum possible sum of the cost of these subarrays.\n \n Example 1:\n \n >>> minimumCost(nums = [1,3,2,6,4,2], k = 3, dist = 3)\n >>> 5\n Explanation: The best possible way to divide nums into 3 subarrays is: [1,3], [2,6,4], and [2]. This choice is valid because ik-1 - i1 is 5 - 2 = 3 which is equal to dist. The total cost is nums[0] + nums[2] + nums[5] which is 1 + 2 + 2 = 5.\n It can be shown that there is no possible way to divide nums into 3 subarrays at a cost lower than 5.\n \n Example 2:\n \n >>> minimumCost(nums = [10,1,2,2,2,1], k = 4, dist = 3)\n >>> 15\n Explanation: The best possible way to divide nums into 4 subarrays is: [10], [1], [2], and [2,2,1]. This choice is valid because ik-1 - i1 is 3 - 1 = 2 which is less than dist. The total cost is nums[0] + nums[1] + nums[2] + nums[3] which is 10 + 1 + 2 + 2 = 15.\n The division [10], [1], [2,2,2], and [1] is not valid, because the difference between ik-1 and i1 is 5 - 1 = 4, which is greater than dist.\n It can be shown that there is no possible way to divide nums into 4 subarrays at a cost lower than 15.\n \n Example 3:\n \n >>> minimumCost(nums = [10,8,18,9], k = 3, dist = 1)\n >>> 36\n Explanation: The best possible way to divide nums into 4 subarrays is: [10], [8], and [18,9]. This choice is valid because ik-1 - i1 is 2 - 1 = 1 which is equal to dist.The total cost is nums[0] + nums[1] + nums[2] which is 10 + 8 + 18 = 36.\n The division [10], [8,18], and [9] is not valid, because the difference between ik-1 and i1 is 3 - 1 = 2, which is greater than dist.\n It can be shown that there is no possible way to divide nums into 3 subarrays at a cost lower than 36.\n \"\"\"\n"}
{"task_id": "minimum-number-of-pushes-to-type-word-i", "prompt": "def minimumPushes(word: str) -> int:\n \"\"\"\n You are given a string word containing distinct lowercase English letters.\n Telephone keypads have keys mapped with distinct collections of lowercase English letters, which can be used to form words by pushing them. For example, the key 2 is mapped with [\"a\",\"b\",\"c\"], we need to push the key one time to type \"a\", two times to type \"b\", and three times to type \"c\" .\n It is allowed to remap the keys numbered 2 to 9 to distinct collections of letters. The keys can be remapped to any amount of letters, but each letter must be mapped to exactly one key. You need to find the minimum number of times the keys will be pushed to type the string word.\n Return the minimum number of pushes needed to type word after remapping the keys.\n An example mapping of letters to keys on a telephone keypad is given below. Note that 1, *, #, and 0 do not map to any letters.\n \n \n Example 1:\n \n \n >>> minimumPushes(word = \"abcde\")\n >>> 5\n Explanation: The remapped keypad given in the image provides the minimum cost.\n \"a\" -> one push on key 2\n \"b\" -> one push on key 3\n \"c\" -> one push on key 4\n \"d\" -> one push on key 5\n \"e\" -> one push on key 6\n Total cost is 1 + 1 + 1 + 1 + 1 = 5.\n It can be shown that no other mapping can provide a lower cost.\n \n Example 2:\n \n \n >>> minimumPushes(word = \"xycdefghij\")\n >>> 12\n Explanation: The remapped keypad given in the image provides the minimum cost.\n \"x\" -> one push on key 2\n \"y\" -> two pushes on key 2\n \"c\" -> one push on key 3\n \"d\" -> two pushes on key 3\n \"e\" -> one push on key 4\n \"f\" -> one push on key 5\n \"g\" -> one push on key 6\n \"h\" -> one push on key 7\n \"i\" -> one push on key 8\n \"j\" -> one push on key 9\n Total cost is 1 + 2 + 1 + 2 + 1 + 1 + 1 + 1 + 1 + 1 = 12.\n It can be shown that no other mapping can provide a lower cost.\n \"\"\"\n"}
{"task_id": "count-the-number-of-houses-at-a-certain-distance-i", "prompt": "def countOfPairs(n: int, x: int, y: int) -> List[int]:\n \"\"\"\n You are given three positive integers n, x, and y.\n In a city, there exist houses numbered 1 to n connected by n streets. There is a street connecting the house numbered i with the house numbered i + 1 for all 1 <= i <= n - 1 . An additional street connects the house numbered x with the house numbered y.\n For each k, such that 1 <= k <= n, you need to find the number of pairs of houses (house1, house2) such that the minimum number of streets that need to be traveled to reach house2 from house1 is k.\n Return a 1-indexed array result of length n where result[k] represents the total number of pairs of houses such that the minimum streets required to reach one house from the other is k.\n Note that x and y can be equal.\n \n Example 1:\n \n \n >>> countOfPairs(n = 3, x = 1, y = 3)\n >>> [6,0,0]\n Explanation: Let's look at each pair of houses:\n - For the pair (1, 2), we can go from house 1 to house 2 directly.\n - For the pair (2, 1), we can go from house 2 to house 1 directly.\n - For the pair (1, 3), we can go from house 1 to house 3 directly.\n - For the pair (3, 1), we can go from house 3 to house 1 directly.\n - For the pair (2, 3), we can go from house 2 to house 3 directly.\n - For the pair (3, 2), we can go from house 3 to house 2 directly.\n \n Example 2:\n \n \n >>> countOfPairs(n = 5, x = 2, y = 4)\n >>> [10,8,2,0,0]\n Explanation: For each distance k the pairs are:\n - For k == 1, the pairs are (1, 2), (2, 1), (2, 3), (3, 2), (2, 4), (4, 2), (3, 4), (4, 3), (4, 5), and (5, 4).\n - For k == 2, the pairs are (1, 3), (3, 1), (1, 4), (4, 1), (2, 5), (5, 2), (3, 5), and (5, 3).\n - For k == 3, the pairs are (1, 5), and (5, 1).\n - For k == 4 and k == 5, there are no pairs.\n \n Example 3:\n \n \n >>> countOfPairs(n = 4, x = 1, y = 1)\n >>> [6,4,2,0]\n Explanation: For each distance k the pairs are:\n - For k == 1, the pairs are (1, 2), (2, 1), (2, 3), (3, 2), (3, 4), and (4, 3).\n - For k == 2, the pairs are (1, 3), (3, 1), (2, 4), and (4, 2).\n - For k == 3, the pairs are (1, 4), and (4, 1).\n - For k == 4, there are no pairs.\n \"\"\"\n"}
{"task_id": "minimum-number-of-pushes-to-type-word-ii", "prompt": "def minimumPushes(word: str) -> int:\n \"\"\"\n You are given a string word containing lowercase English letters.\n Telephone keypads have keys mapped with distinct collections of lowercase English letters, which can be used to form words by pushing them. For example, the key 2 is mapped with [\"a\",\"b\",\"c\"], we need to push the key one time to type \"a\", two times to type \"b\", and three times to type \"c\" .\n It is allowed to remap the keys numbered 2 to 9 to distinct collections of letters. The keys can be remapped to any amount of letters, but each letter must be mapped to exactly one key. You need to find the minimum number of times the keys will be pushed to type the string word.\n Return the minimum number of pushes needed to type word after remapping the keys.\n An example mapping of letters to keys on a telephone keypad is given below. Note that 1, *, #, and 0 do not map to any letters.\n \n \n Example 1:\n \n \n >>> minimumPushes(word = \"abcde\")\n >>> 5\n Explanation: The remapped keypad given in the image provides the minimum cost.\n \"a\" -> one push on key 2\n \"b\" -> one push on key 3\n \"c\" -> one push on key 4\n \"d\" -> one push on key 5\n \"e\" -> one push on key 6\n Total cost is 1 + 1 + 1 + 1 + 1 = 5.\n It can be shown that no other mapping can provide a lower cost.\n \n Example 2:\n \n \n >>> minimumPushes(word = \"xyzxyzxyzxyz\")\n >>> 12\n Explanation: The remapped keypad given in the image provides the minimum cost.\n \"x\" -> one push on key 2\n \"y\" -> one push on key 3\n \"z\" -> one push on key 4\n Total cost is 1 * 4 + 1 * 4 + 1 * 4 = 12\n It can be shown that no other mapping can provide a lower cost.\n Note that the key 9 is not mapped to any letter: it is not necessary to map letters to every key, but to map all the letters.\n \n Example 3:\n \n \n >>> minimumPushes(word = \"aabbccddeeffgghhiiiiii\")\n >>> 24\n Explanation: The remapped keypad given in the image provides the minimum cost.\n \"a\" -> one push on key 2\n \"b\" -> one push on key 3\n \"c\" -> one push on key 4\n \"d\" -> one push on key 5\n \"e\" -> one push on key 6\n \"f\" -> one push on key 7\n \"g\" -> one push on key 8\n \"h\" -> two pushes on key 9\n \"i\" -> one push on key 9\n Total cost is 1 * 2 + 1 * 2 + 1 * 2 + 1 * 2 + 1 * 2 + 1 * 2 + 1 * 2 + 2 * 2 + 6 * 1 = 24.\n It can be shown that no other mapping can provide a lower cost.\n \"\"\"\n"}
{"task_id": "count-the-number-of-houses-at-a-certain-distance-ii", "prompt": "def countOfPairs(n: int, x: int, y: int) -> List[int]:\n \"\"\"\n You are given three positive integers n, x, and y.\n In a city, there exist houses numbered 1 to n connected by n streets. There is a street connecting the house numbered i with the house numbered i + 1 for all 1 <= i <= n - 1 . An additional street connects the house numbered x with the house numbered y.\n For each k, such that 1 <= k <= n, you need to find the number of pairs of houses (house1, house2) such that the minimum number of streets that need to be traveled to reach house2 from house1 is k.\n Return a 1-indexed array result of length n where result[k] represents the total number of pairs of houses such that the minimum streets required to reach one house from the other is k.\n Note that x and y can be equal.\n \n Example 1:\n \n \n >>> countOfPairs(n = 3, x = 1, y = 3)\n >>> [6,0,0]\n Explanation: Let's look at each pair of houses:\n - For the pair (1, 2), we can go from house 1 to house 2 directly.\n - For the pair (2, 1), we can go from house 2 to house 1 directly.\n - For the pair (1, 3), we can go from house 1 to house 3 directly.\n - For the pair (3, 1), we can go from house 3 to house 1 directly.\n - For the pair (2, 3), we can go from house 2 to house 3 directly.\n - For the pair (3, 2), we can go from house 3 to house 2 directly.\n \n Example 2:\n \n \n >>> countOfPairs(n = 5, x = 2, y = 4)\n >>> [10,8,2,0,0]\n Explanation: For each distance k the pairs are:\n - For k == 1, the pairs are (1, 2), (2, 1), (2, 3), (3, 2), (2, 4), (4, 2), (3, 4), (4, 3), (4, 5), and (5, 4).\n - For k == 2, the pairs are (1, 3), (3, 1), (1, 4), (4, 1), (2, 5), (5, 2), (3, 5), and (5, 3).\n - For k == 3, the pairs are (1, 5), and (5, 1).\n - For k == 4 and k == 5, there are no pairs.\n \n Example 3:\n \n \n >>> countOfPairs(n = 4, x = 1, y = 1)\n >>> [6,4,2,0]\n Explanation: For each distance k the pairs are:\n - For k == 1, the pairs are (1, 2), (2, 1), (2, 3), (3, 2), (3, 4), and (4, 3).\n - For k == 2, the pairs are (1, 3), (3, 1), (2, 4), and (4, 2).\n - For k == 3, the pairs are (1, 4), and (4, 1).\n - For k == 4, there are no pairs.\n \"\"\"\n"}
{"task_id": "maximum-number-of-removal-queries-that-can-be-processed-i", "prompt": "def maximumProcessableQueries(nums: List[int], queries: List[int]) -> int:\n \"\"\"\n You are given a 0-indexed array nums and a 0-indexed array queries.\n You can do the following operation at the beginning at most once:\n \n Replace nums with a subsequence of nums.\n \n We start processing queries in the given order; for each query, we do the following:\n \n If the first and the last element of nums is less than queries[i], the processing of queries ends.\n Otherwise, we choose either the first or the last element of nums if it is greater than or equal to queries[i], and we remove the chosen element from nums.\n \n Return the maximum number of queries that can be processed by doing the operation optimally.\n \n Example 1:\n \n >>> maximumProcessableQueries(nums = [1,2,3,4,5], queries = [1,2,3,4,6])\n >>> 4\n Explanation: We don't do any operation and process the queries as follows:\n 1- We choose and remove nums[0] since 1 <= 1, then nums becomes [2,3,4,5].\n 2- We choose and remove nums[0] since 2 <= 2, then nums becomes [3,4,5].\n 3- We choose and remove nums[0] since 3 <= 3, then nums becomes [4,5].\n 4- We choose and remove nums[0] since 4 <= 4, then nums becomes [5].\n 5- We can not choose any elements from nums since they are not greater than or equal to 5.\n Hence, the answer is 4.\n It can be shown that we can't process more than 4 queries.\n \n Example 2:\n \n >>> maximumProcessableQueries(nums = [2,3,2], queries = [2,2,3])\n >>> 3\n Explanation: We don't do any operation and process the queries as follows:\n 1- We choose and remove nums[0] since 2 <= 2, then nums becomes [3,2].\n 2- We choose and remove nums[1] since 2 <= 2, then nums becomes [3].\n 3- We choose and remove nums[0] since 3 <= 3, then nums becomes [].\n Hence, the answer is 3.\n It can be shown that we can't process more than 3 queries.\n \n Example 3:\n \n >>> maximumProcessableQueries(nums = [3,4,3], queries = [4,3,2])\n >>> 2\n Explanation: First we replace nums with the subsequence of nums [4,3].\n Then we can process the queries as follows:\n 1- We choose and remove nums[0] since 4 <= 4, then nums becomes [3].\n 2- We choose and remove nums[0] since 3 <= 3, then nums becomes [].\n 3- We can not process any more queries since nums is empty.\n Hence, the answer is 2.\n It can be shown that we can't process more than 2 queries.\n \"\"\"\n"}
{"task_id": "number-of-changing-keys", "prompt": "def countKeyChanges(s: str) -> int:\n \"\"\"\n You are given a 0-indexed string s typed by a user. Changing a key is defined as using a key different from the last used key. For example, s = \"ab\" has a change of a key while s = \"bBBb\" does not have any.\n Return the number of times the user had to change the key.\n Note: Modifiers like shift or caps lock won't be counted in changing the key that is if a user typed the letter 'a' and then the letter 'A' then it will not be considered as a changing of key.\n \n Example 1:\n \n >>> countKeyChanges(s = \"aAbBcC\")\n >>> 2\n Explanation:\n From s[0] = 'a' to s[1] = 'A', there is no change of key as caps lock or shift is not counted.\n From s[1] = 'A' to s[2] = 'b', there is a change of key.\n From s[2] = 'b' to s[3] = 'B', there is no change of key as caps lock or shift is not counted.\n From s[3] = 'B' to s[4] = 'c', there is a change of key.\n From s[4] = 'c' to s[5] = 'C', there is no change of key as caps lock or shift is not counted.\n \n \n Example 2:\n \n >>> countKeyChanges(s = \"AaAaAaaA\")\n >>> 0\n Explanation: There is no change of key since only the letters 'a' and 'A' are pressed which does not require change of key.\n \"\"\"\n"}
{"task_id": "find-the-maximum-number-of-elements-in-subset", "prompt": "def maximumLength(nums: List[int]) -> int:\n \"\"\"\n You are given an array of positive integers nums.\n You need to select a subset of nums which satisfies the following condition:\n \n You can place the selected elements in a 0-indexed array such that it follows the pattern: [x, x2, x4, ..., xk/2, xk, xk/2, ..., x4, x2, x] (Note that k can be be any non-negative power of 2). For example, [2, 4, 16, 4, 2] and [3, 9, 3] follow the pattern while [2, 4, 8, 4, 2] does not.\n \n Return the maximum number of elements in a subset that satisfies these conditions.\n \n Example 1:\n \n >>> maximumLength(nums = [5,4,1,2,2])\n >>> 3\n Explanation: We can select the subset {4,2,2}, which can be placed in the array as [2,4,2] which follows the pattern and 22 == 4. Hence the answer is 3.\n \n Example 2:\n \n >>> maximumLength(nums = [1,3,2,4])\n >>> 1\n Explanation: We can select the subset {1}, which can be placed in the array as [1] which follows the pattern. Hence the answer is 1. Note that we could have also selected the subsets {2}, {3}, or {4}, there may be multiple subsets which provide the same answer.\n \"\"\"\n"}
{"task_id": "alice-and-bob-playing-flower-game", "prompt": "def flowerGame(n: int, m: int) -> int:\n \"\"\"\n Alice and Bob are playing a turn-based game on a circular field surrounded by flowers. The circle represents the field, and there are x flowers in the clockwise direction between Alice and Bob, and y flowers in the anti-clockwise direction between them.\n The game proceeds as follows:\n \n Alice takes the first turn.\n In each turn, a player must choose either the clockwise or anti-clockwise direction and pick one flower from that side.\n At the end of the turn, if there are no flowers left at all, the current player captures their opponent and wins the game.\n \n Given two integers, n and m, the task is to compute the number of possible pairs (x, y) that satisfy the conditions:\n \n Alice must win the game according to the described rules.\n The number of flowers x in the clockwise direction must be in the range [1,n].\n The number of flowers y in the anti-clockwise direction must be in the range [1,m].\n \n Return the number of possible pairs (x, y) that satisfy the conditions mentioned in the statement.\n \n Example 1:\n \n >>> flowerGame(n = 3, m = 2)\n >>> 3\n Explanation: The following pairs satisfy conditions described in the statement: (1,2), (3,2), (2,1).\n \n Example 2:\n \n >>> flowerGame(n = 1, m = 1)\n >>> 0\n Explanation: No pairs satisfy the conditions described in the statement.\n \"\"\"\n"}
{"task_id": "minimize-or-of-remaining-elements-using-operations", "prompt": "def minOrAfterOperations(nums: List[int], k: int) -> int:\n \"\"\"\n You are given a 0-indexed integer array nums and an integer k.\n In one operation, you can pick any index i of nums such that 0 <= i < nums.length - 1 and replace nums[i] and nums[i + 1] with a single occurrence of nums[i] & nums[i + 1], where & represents the bitwise AND operator.\n Return the minimum possible value of the bitwise OR of the remaining elements of nums after applying at most k operations.\n \n Example 1:\n \n >>> minOrAfterOperations(nums = [3,5,3,2,7], k = 2)\n >>> 3\n Explanation: Let's do the following operations:\n 1. Replace nums[0] and nums[1] with (nums[0] & nums[1]) so that nums becomes equal to [1,3,2,7].\n 2. Replace nums[2] and nums[3] with (nums[2] & nums[3]) so that nums becomes equal to [1,3,2].\n The bitwise-or of the final array is 3.\n It can be shown that 3 is the minimum possible value of the bitwise OR of the remaining elements of nums after applying at most k operations.\n Example 2:\n \n >>> minOrAfterOperations(nums = [7,3,15,14,2,8], k = 4)\n >>> 2\n Explanation: Let's do the following operations:\n 1. Replace nums[0] and nums[1] with (nums[0] & nums[1]) so that nums becomes equal to [3,15,14,2,8].\n 2. Replace nums[0] and nums[1] with (nums[0] & nums[1]) so that nums becomes equal to [3,14,2,8].\n 3. Replace nums[0] and nums[1] with (nums[0] & nums[1]) so that nums becomes equal to [2,2,8].\n 4. Replace nums[1] and nums[2] with (nums[1] & nums[2]) so that nums becomes equal to [2,0].\n The bitwise-or of the final array is 2.\n It can be shown that 2 is the minimum possible value of the bitwise OR of the remaining elements of nums after applying at most k operations.\n \n Example 3:\n \n >>> minOrAfterOperations(nums = [10,7,10,3,9,14,9,4], k = 1)\n >>> 15\n Explanation: Without applying any operations, the bitwise-or of nums is 15.\n It can be shown that 15 is the minimum possible value of the bitwise OR of the remaining elements of nums after applying at most k operations.\n \"\"\"\n"}
{"task_id": "type-of-triangle", "prompt": "def triangleType(nums: List[int]) -> str:\n \"\"\"\n You are given a 0-indexed integer array nums of size 3 which can form the sides of a triangle.\n \n A triangle is called equilateral if it has all sides of equal length.\n A triangle is called isosceles if it has exactly two sides of equal length.\n A triangle is called scalene if all its sides are of different lengths.\n \n Return a string representing the type of triangle that can be formed or \"none\" if it cannot form a triangle.\n \n Example 1:\n \n >>> triangleType(nums = [3,3,3])\n >>> \"equilateral\"\n Explanation: Since all the sides are of equal length, therefore, it will form an equilateral triangle.\n \n Example 2:\n \n >>> triangleType(nums = [3,4,5])\n >>> \"scalene\"\n Explanation:\n nums[0] + nums[1] = 3 + 4 = 7, which is greater than nums[2] = 5.\n nums[0] + nums[2] = 3 + 5 = 8, which is greater than nums[1] = 4.\n nums[1] + nums[2] = 4 + 5 = 9, which is greater than nums[0] = 3.\n Since the sum of the two sides is greater than the third side for all three cases, therefore, it can form a triangle.\n As all the sides are of different lengths, it will form a scalene triangle.\n \"\"\"\n"}
{"task_id": "find-the-number-of-ways-to-place-people-i", "prompt": "def numberOfPairs(points: List[List[int]]) -> int:\n \"\"\"\n You are given a 2D array points of size n x 2 representing integer coordinates of some points on a 2D plane, where points[i] = [xi, yi].\n Count the number of pairs of points (A, B), where\n \n A is on the upper left side of B, and\n there are no other points in the rectangle (or line) they make (including the border).\n \n Return the count.\n \n Example 1:\n \n >>> numberOfPairs(points = [[1,1],[2,2],[3,3]])\n >>> 0\n Explanation:\n \n There is no way to choose A and B so A is on the upper left side of B.\n \n Example 2:\n \n >>> numberOfPairs(points = [[6,2],[4,4],[2,6]])\n >>> 2\n Explanation:\n \n \n The left one is the pair (points[1], points[0]), where points[1] is on the upper left side of points[0] and the rectangle is empty.\n The middle one is the pair (points[2], points[1]), same as the left one it is a valid pair.\n The right one is the pair (points[2], points[0]), where points[2] is on the upper left side of points[0], but points[1] is inside the rectangle so it's not a valid pair.\n \n \n Example 3:\n \n >>> numberOfPairs(points = [[3,1],[1,3],[1,1]])\n >>> 2\n Explanation:\n \n \n The left one is the pair (points[2], points[0]), where points[2] is on the upper left side of points[0] and there are no other points on the line they form. Note that it is a valid state when the two points form a line.\n The middle one is the pair (points[1], points[2]), it is a valid pair same as the left one.\n The right one is the pair (points[1], points[0]), it is not a valid pair as points[2] is on the border of the rectangle.\n \"\"\"\n"}
{"task_id": "maximum-good-subarray-sum", "prompt": "def maximumSubarraySum(nums: List[int], k: int) -> int:\n \"\"\"\n You are given an array nums of length n and a positive integer k.\n A subarray of nums is called good if the absolute difference between its first and last element is exactly k, in other words, the subarray nums[i..j] is good if |nums[i] - nums[j]| == k.\n Return the maximum sum of a good subarray of nums. If there are no good subarrays, return 0.\n \n Example 1:\n \n >>> maximumSubarraySum(nums = [1,2,3,4,5,6], k = 1)\n >>> 11\n Explanation: The absolute difference between the first and last element must be 1 for a good subarray. All the good subarrays are: [1,2], [2,3], [3,4], [4,5], and [5,6]. The maximum subarray sum is 11 for the subarray [5,6].\n \n Example 2:\n \n >>> maximumSubarraySum(nums = [-1,3,2,4,5], k = 3)\n >>> 11\n Explanation: The absolute difference between the first and last element must be 3 for a good subarray. All the good subarrays are: [-1,3,2], and [2,4,5]. The maximum subarray sum is 11 for the subarray [2,4,5].\n \n Example 3:\n \n >>> maximumSubarraySum(nums = [-1,-2,-3,-4], k = 2)\n >>> -6\n Explanation: The absolute difference between the first and last element must be 2 for a good subarray. All the good subarrays are: [-1,-2,-3], and [-2,-3,-4]. The maximum subarray sum is -6 for the subarray [-1,-2,-3].\n \"\"\"\n"}
{"task_id": "find-the-number-of-ways-to-place-people-ii", "prompt": "def numberOfPairs(points: List[List[int]]) -> int:\n \"\"\"\n You are given a 2D array points of size n x 2 representing integer coordinates of some points on a 2D-plane, where points[i] = [xi, yi].\n We define the right direction as positive x-axis (increasing x-coordinate) and the left direction as negative x-axis (decreasing x-coordinate). Similarly, we define the up direction as positive y-axis (increasing y-coordinate) and the down direction as negative y-axis (decreasing y-coordinate)\n You have to place n people, including Alice and Bob, at these points such that there is exactly one person at every point. Alice wants to be alone with Bob, so Alice will build a rectangular fence with Alice's position as the upper left corner and Bob's position as the lower right corner of the fence (Note that the fence might not enclose any area, i.e. it can be a line). If any person other than Alice and Bob is either inside the fence or on the fence, Alice will be sad.\n Return the number of pairs of points where you can place Alice and Bob, such that Alice does not become sad on building the fence.\n Note that Alice can only build a fence with Alice's position as the upper left corner, and Bob's position as the lower right corner. For example, Alice cannot build either of the fences in the picture below with four corners (1, 1), (1, 3), (3, 1), and (3, 3), because:\n \n With Alice at (3, 3) and Bob at (1, 1), Alice's position is not the upper left corner and Bob's position is not the lower right corner of the fence.\n With Alice at (1, 3) and Bob at (1, 1), Bob's position is not the lower right corner of the fence.\n \n \n \n Example 1:\n \n \n >>> numberOfPairs(points = [[1,1],[2,2],[3,3]])\n >>> 0\n Explanation: There is no way to place Alice and Bob such that Alice can build a fence with Alice's position as the upper left corner and Bob's position as the lower right corner. Hence we return 0.\n \n Example 2:\n \n \n >>> numberOfPairs(points = [[6,2],[4,4],[2,6]])\n >>> 2\n Explanation: There are two ways to place Alice and Bob such that Alice will not be sad:\n - Place Alice at (4, 4) and Bob at (6, 2).\n - Place Alice at (2, 6) and Bob at (4, 4).\n You cannot place Alice at (2, 6) and Bob at (6, 2) because the person at (4, 4) will be inside the fence.\n \n Example 3:\n \n \n >>> numberOfPairs(points = [[3,1],[1,3],[1,1]])\n >>> 2\n Explanation: There are two ways to place Alice and Bob such that Alice will not be sad:\n - Place Alice at (1, 1) and Bob at (3, 1).\n - Place Alice at (1, 3) and Bob at (1, 1).\n You cannot place Alice at (1, 3) and Bob at (3, 1) because the person at (1, 1) will be on the fence.\n Note that it does not matter if the fence encloses any area, the first and second fences in the image are valid.\n \"\"\"\n"}
{"task_id": "ant-on-the-boundary", "prompt": "def returnToBoundaryCount(nums: List[int]) -> int:\n \"\"\"\n An ant is on a boundary. It sometimes goes left and sometimes right.\n You are given an array of non-zero integers nums. The ant starts reading nums from the first element of it to its end. At each step, it moves according to the value of the current element:\n \n If nums[i] < 0, it moves left by -nums[i] units.\n If nums[i] > 0, it moves right by nums[i] units.\n \n Return the number of times the ant returns to the boundary.\n Notes:\n \n There is an infinite space on both sides of the boundary.\n We check whether the ant is on the boundary only after it has moved |nums[i]| units. In other words, if the ant crosses the boundary during its movement, it does not count.\n \n \n Example 1:\n \n >>> returnToBoundaryCount(nums = [2,3,-5])\n >>> 1\n Explanation: After the first step, the ant is 2 steps to the right of the boundary.\n After the second step, the ant is 5 steps to the right of the boundary.\n After the third step, the ant is on the boundary.\n So the answer is 1.\n \n Example 2:\n \n >>> returnToBoundaryCount(nums = [3,2,-3,-4])\n >>> 0\n Explanation: After the first step, the ant is 3 steps to the right of the boundary.\n After the second step, the ant is 5 steps to the right of the boundary.\n After the third step, the ant is 2 steps to the right of the boundary.\n After the fourth step, the ant is 2 steps to the left of the boundary.\n The ant never returned to the boundary, so the answer is 0.\n \"\"\"\n"}
{"task_id": "minimum-time-to-revert-word-to-initial-state-i", "prompt": "def minimumTimeToInitialState(word: str, k: int) -> int:\n \"\"\"\n You are given a 0-indexed string word and an integer k.\n At every second, you must perform the following operations:\n \n Remove the first k characters of word.\n Add any k characters to the end of word.\n \n Note that you do not necessarily need to add the same characters that you removed. However, you must perform both operations at every second.\n Return the minimum time greater than zero required for word to revert to its initial state.\n \n Example 1:\n \n >>> minimumTimeToInitialState(word = \"abacaba\", k = 3)\n >>> 2\n Explanation: At the 1st second, we remove characters \"aba\" from the prefix of word, and add characters \"bac\" to the end of word. Thus, word becomes equal to \"cababac\".\n At the 2nd second, we remove characters \"cab\" from the prefix of word, and add \"aba\" to the end of word. Thus, word becomes equal to \"abacaba\" and reverts to its initial state.\n It can be shown that 2 seconds is the minimum time greater than zero required for word to revert to its initial state.\n \n Example 2:\n \n >>> minimumTimeToInitialState(word = \"abacaba\", k = 4)\n >>> 1\n Explanation: At the 1st second, we remove characters \"abac\" from the prefix of word, and add characters \"caba\" to the end of word. Thus, word becomes equal to \"abacaba\" and reverts to its initial state.\n It can be shown that 1 second is the minimum time greater than zero required for word to revert to its initial state.\n \n Example 3:\n \n >>> minimumTimeToInitialState(word = \"abcbabcd\", k = 2)\n >>> 4\n Explanation: At every second, we will remove the first 2 characters of word, and add the same characters to the end of word.\n After 4 seconds, word becomes equal to \"abcbabcd\" and reverts to its initial state.\n It can be shown that 4 seconds is the minimum time greater than zero required for word to revert to its initial state.\n \"\"\"\n"}
{"task_id": "find-the-grid-of-region-average", "prompt": "def resultGrid(image: List[List[int]], threshold: int) -> List[List[int]]:\n \"\"\"\n You are given m x n grid image which represents a grayscale image, where image[i][j] represents a pixel with intensity in the range [0..255]. You are also given a non-negative integer threshold.\n Two pixels are adjacent if they share an edge.\n A region is a 3 x 3 subgrid where the absolute difference in intensity between any two adjacent pixels is less than or equal to threshold.\n All pixels in a region belong to that region, note that a pixel can belong to multiple regions.\n You need to calculate a m x n grid result, where result[i][j] is the average intensity of the regions to which image[i][j] belongs, rounded down to the nearest integer. If image[i][j] belongs to multiple regions, result[i][j] is the average of the rounded-down average intensities of these regions, rounded down to the nearest integer. If image[i][j] does not belong to any region, result[i][j] is equal to image[i][j].\n Return the grid result.\n \n Example 1:\n \n >>> resultGrid(image = [[5,6,7,10],[8,9,10,10],[11,12,13,10]], threshold = 3)\n >>> [[9,9,9,9],[9,9,9,9],[9,9,9,9]]\n Explanation:\n \n There are two regions as illustrated above. The average intensity of the first region is 9, while the average intensity of the second region is 9.67 which is rounded down to 9. The average intensity of both of the regions is (9 + 9) / 2 = 9. As all the pixels belong to either region 1, region 2, or both of them, the intensity of every pixel in the result is 9.\n Please note that the rounded-down values are used when calculating the average of multiple regions, hence the calculation is done using 9 as the average intensity of region 2, not 9.67.\n \n Example 2:\n \n >>> resultGrid(image = [[10,20,30],[15,25,35],[20,30,40],[25,35,45]], threshold = 12)\n >>> [[25,25,25],[27,27,27],[27,27,27],[30,30,30]]\n Explanation:\n \n There are two regions as illustrated above. The average intensity of the first region is 25, while the average intensity of the second region is 30. The average intensity of both of the regions is (25 + 30) / 2 = 27.5 which is rounded down to 27.\n All the pixels in row 0 of the image belong to region 1, hence all the pixels in row 0 in the result are 25. Similarly, all the pixels in row 3 in the result are 30. The pixels in rows 1 and 2 of the image belong to region 1 and region 2, hence their assigned value is 27 in the result.\n \n Example 3:\n \n >>> resultGrid(image = [[5,6,7],[8,9,10],[11,12,13]], threshold = 1)\n >>> [[5,6,7],[8,9,10],[11,12,13]]\n Explanation:\n There is only one 3 x 3 subgrid, while it does not have the condition on difference of adjacent pixels, for example, the difference between image[0][0] and image[1][0] is |5 - 8| = 3 > threshold = 1. None of them belong to any valid regions, so the result should be the same as image.\n \"\"\"\n"}
{"task_id": "minimum-time-to-revert-word-to-initial-state-ii", "prompt": "def minimumTimeToInitialState(word: str, k: int) -> int:\n \"\"\"\n You are given a 0-indexed string word and an integer k.\n At every second, you must perform the following operations:\n \n Remove the first k characters of word.\n Add any k characters to the end of word.\n \n Note that you do not necessarily need to add the same characters that you removed. However, you must perform both operations at every second.\n Return the minimum time greater than zero required for word to revert to its initial state.\n \n Example 1:\n \n >>> minimumTimeToInitialState(word = \"abacaba\", k = 3)\n >>> 2\n Explanation: At the 1st second, we remove characters \"aba\" from the prefix of word, and add characters \"bac\" to the end of word. Thus, word becomes equal to \"cababac\".\n At the 2nd second, we remove characters \"cab\" from the prefix of word, and add \"aba\" to the end of word. Thus, word becomes equal to \"abacaba\" and reverts to its initial state.\n It can be shown that 2 seconds is the minimum time greater than zero required for word to revert to its initial state.\n \n Example 2:\n \n >>> minimumTimeToInitialState(word = \"abacaba\", k = 4)\n >>> 1\n Explanation: At the 1st second, we remove characters \"abac\" from the prefix of word, and add characters \"caba\" to the end of word. Thus, word becomes equal to \"abacaba\" and reverts to its initial state.\n It can be shown that 1 second is the minimum time greater than zero required for word to revert to its initial state.\n \n Example 3:\n \n >>> minimumTimeToInitialState(word = \"abcbabcd\", k = 2)\n >>> 4\n Explanation: At every second, we will remove the first 2 characters of word, and add the same characters to the end of word.\n After 4 seconds, word becomes equal to \"abcbabcd\" and reverts to its initial state.\n It can be shown that 4 seconds is the minimum time greater than zero required for word to revert to its initial state.\n \"\"\"\n"}
{"task_id": "count-numbers-with-unique-digits-ii", "prompt": "def numberCount(a: int, b: int) -> int:\n \"\"\"\n Given two positive integers a and b, return the count of numbers having\u00a0unique digits in the range [a, b] (inclusive).\n \n Example 1:\n \n >>> numberCount(a = 1, b = 20)\n >>> 19\n Explanation: All the numbers in the range [1, 20] have unique digits except 11. Hence, the answer is 19.\n \n Example 2:\n \n >>> numberCount(a = 9, b = 19)\n >>> 10\n Explanation: All the numbers in the range [9, 19] have unique digits except 11. Hence, the answer is 10.\n \n Example 3:\n \n >>> numberCount(a = 80, b = 120)\n >>> 27\n Explanation: There are 41 numbers in the range [80, 120], 27 of which have unique digits.\n \"\"\"\n"}
{"task_id": "modify-the-matrix", "prompt": "def modifiedMatrix(matrix: List[List[int]]) -> List[List[int]]:\n \"\"\"\n Given a 0-indexed m x n integer matrix matrix, create a new 0-indexed matrix called answer. Make answer equal to matrix, then replace each element with the value -1 with the maximum element in its respective column.\n Return the matrix answer.\n \n Example 1:\n \n \n >>> modifiedMatrix(matrix = [[1,2,-1],[4,-1,6],[7,8,9]])\n >>> [[1,2,9],[4,8,6],[7,8,9]]\n Explanation: The diagram above shows the elements that are changed (in blue).\n - We replace the value in the cell [1][1] with the maximum value in the column 1, that is 8.\n - We replace the value in the cell [0][2] with the maximum value in the column 2, that is 9.\n \n Example 2:\n \n \n >>> modifiedMatrix(matrix = [[3,-1],[5,2]])\n >>> [[3,2],[5,2]]\n Explanation: The diagram above shows the elements that are changed (in blue).\n \"\"\"\n"}
{"task_id": "number-of-subarrays-that-match-a-pattern-i", "prompt": "def countMatchingSubarrays(nums: List[int], pattern: List[int]) -> int:\n \"\"\"\n You are given a 0-indexed integer array nums of size n, and a 0-indexed integer array pattern of size m consisting of integers -1, 0, and 1.\n A subarray nums[i..j] of size m + 1 is said to match the pattern if the following conditions hold for each element pattern[k]:\n \n nums[i + k + 1] > nums[i + k] if pattern[k] == 1.\n nums[i + k + 1] == nums[i + k] if pattern[k] == 0.\n nums[i + k + 1] < nums[i + k] if pattern[k] == -1.\n \n Return the count of subarrays in nums that match the pattern.\n \n Example 1:\n \n >>> countMatchingSubarrays(nums = [1,2,3,4,5,6], pattern = [1,1])\n >>> 4\n Explanation: The pattern [1,1] indicates that we are looking for strictly increasing subarrays of size 3. In the array nums, the subarrays [1,2,3], [2,3,4], [3,4,5], and [4,5,6] match this pattern.\n Hence, there are 4 subarrays in nums that match the pattern.\n \n Example 2:\n \n >>> countMatchingSubarrays(nums = [1,4,4,1,3,5,5,3], pattern = [1,0,-1])\n >>> 2\n Explanation: Here, the pattern [1,0,-1] indicates that we are looking for a sequence where the first number is smaller than the second, the second is equal to the third, and the third is greater than the fourth. In the array nums, the subarrays [1,4,4,1], and [3,5,5,3] match this pattern.\n Hence, there are 2 subarrays in nums that match the pattern.\n \"\"\"\n"}
{"task_id": "maximum-palindromes-after-operations", "prompt": "def maxPalindromesAfterOperations(words: List[str]) -> int:\n \"\"\"\n You are given a 0-indexed string array words having length n and containing 0-indexed strings.\n You are allowed to perform the following operation any number of times (including zero):\n \n Choose integers i, j, x, and y such that 0 <= i, j < n, 0 <= x < words[i].length, 0 <= y < words[j].length, and swap the characters words[i][x] and words[j][y].\n \n Return an integer denoting the maximum number of palindromes words can contain, after performing some operations.\n Note: i and j may be equal during an operation.\n \n Example 1:\n \n >>> maxPalindromesAfterOperations(words = [\"abbb\",\"ba\",\"aa\"])\n >>> 3\n Explanation: In this example, one way to get the maximum number of palindromes is:\n Choose i = 0, j = 1, x = 0, y = 0, so we swap words[0][0] and words[1][0]. words becomes [\"bbbb\",\"aa\",\"aa\"].\n All strings in words are now palindromes.\n Hence, the maximum number of palindromes achievable is 3.\n Example 2:\n \n >>> maxPalindromesAfterOperations(words = [\"abc\",\"ab\"])\n >>> 2\n Explanation: In this example, one way to get the maximum number of palindromes is:\n Choose i = 0, j = 1, x = 1, y = 0, so we swap words[0][1] and words[1][0]. words becomes [\"aac\",\"bb\"].\n Choose i = 0, j = 0, x = 1, y = 2, so we swap words[0][1] and words[0][2]. words becomes [\"aca\",\"bb\"].\n Both strings are now palindromes.\n Hence, the maximum number of palindromes achievable is 2.\n \n Example 3:\n \n >>> maxPalindromesAfterOperations(words = [\"cd\",\"ef\",\"a\"])\n >>> 1\n Explanation: In this example, there is no need to perform any operation.\n There is one palindrome in words \"a\".\n It can be shown that it is not possible to get more than one palindrome after any number of operations.\n Hence, the answer is 1.\n \"\"\"\n"}
{"task_id": "number-of-subarrays-that-match-a-pattern-ii", "prompt": "def countMatchingSubarrays(nums: List[int], pattern: List[int]) -> int:\n \"\"\"\n You are given a 0-indexed integer array nums of size n, and a 0-indexed integer array pattern of size m consisting of integers -1, 0, and 1.\n A subarray nums[i..j] of size m + 1 is said to match the pattern if the following conditions hold for each element pattern[k]:\n \n nums[i + k + 1] > nums[i + k] if pattern[k] == 1.\n nums[i + k + 1] == nums[i + k] if pattern[k] == 0.\n nums[i + k + 1] < nums[i + k] if pattern[k] == -1.\n \n Return the count of subarrays in nums that match the pattern.\n \n Example 1:\n \n >>> countMatchingSubarrays(nums = [1,2,3,4,5,6], pattern = [1,1])\n >>> 4\n Explanation: The pattern [1,1] indicates that we are looking for strictly increasing subarrays of size 3. In the array nums, the subarrays [1,2,3], [2,3,4], [3,4,5], and [4,5,6] match this pattern.\n Hence, there are 4 subarrays in nums that match the pattern.\n \n Example 2:\n \n >>> countMatchingSubarrays(nums = [1,4,4,1,3,5,5,3], pattern = [1,0,-1])\n >>> 2\n Explanation: Here, the pattern [1,0,-1] indicates that we are looking for a sequence where the first number is smaller than the second, the second is equal to the third, and the third is greater than the fourth. In the array nums, the subarrays [1,4,4,1], and [3,5,5,3] match this pattern.\n Hence, there are 2 subarrays in nums that match the pattern.\n \"\"\"\n"}
{"task_id": "maximum-number-of-operations-with-the-same-score-i", "prompt": "def maxOperations(nums: List[int]) -> int:\n \"\"\"\n You are given an array of integers nums. Consider the following operation:\n \n Delete the first two elements nums and define the score of the operation as the sum of these two elements.\n \n You can perform this operation until nums contains fewer than two elements. Additionally, the same score must be achieved in all operations.\n Return the maximum number of operations you can perform.\n \n Example 1:\n \n >>> maxOperations(nums = [3,2,1,4,5])\n >>> 2\n Explanation:\n \n We can perform the first operation with the score 3 + 2 = 5. After this operation, nums = [1,4,5].\n We can perform the second operation as its score is 4 + 1 = 5, the same as the previous operation. After this operation, nums = [5].\n As there are fewer than two elements, we can't perform more operations.\n \n \n Example 2:\n \n >>> maxOperations(nums = [1,5,3,3,4,1,3,2,2,3])\n >>> 2\n Explanation:\n \n We can perform the first operation with the score 1 + 5 = 6. After this operation, nums = [3,3,4,1,3,2,2,3].\n We can perform the second operation as its score is 3 + 3 = 6, the same as the previous operation. After this operation, nums = [4,1,3,2,2,3].\n We cannot perform the next operation as its score is 4 + 1 = 5, which is different from the previous scores.\n \n \n Example 3:\n \n >>> maxOperations(nums = [5,3])\n >>> 1\n \"\"\"\n"}
{"task_id": "apply-operations-to-make-string-empty", "prompt": "def lastNonEmptyString(s: str) -> str:\n \"\"\"\n You are given a string s.\n Consider performing the following operation until s becomes empty:\n \n For every alphabet character from 'a' to 'z', remove the first occurrence of that character in s (if it exists).\n \n For example, let initially s = \"aabcbbca\". We do the following operations:\n \n Remove the underlined characters s = \"aabcbbca\". The resulting string is s = \"abbca\".\n Remove the underlined characters s = \"abbca\". The resulting string is s = \"ba\".\n Remove the underlined characters s = \"ba\". The resulting string is s = \"\".\n \n Return the value of the string s right before applying the last operation. In the example above, answer is \"ba\".\n \n Example 1:\n \n >>> lastNonEmptyString(s = \"aabcbbca\")\n >>> \"ba\"\n Explanation: Explained in the statement.\n \n Example 2:\n \n >>> lastNonEmptyString(s = \"abcd\")\n >>> \"abcd\"\n Explanation: We do the following operation:\n - Remove the underlined characters s = \"abcd\". The resulting string is s = \"\".\n The string just before the last operation is \"abcd\".\n \"\"\"\n"}
{"task_id": "maximum-number-of-operations-with-the-same-score-ii", "prompt": "def maxOperations(nums: List[int]) -> int:\n \"\"\"\n Given an array of integers called nums, you can perform any of the following operation while nums contains at least 2 elements:\n \n Choose the first two elements of nums and delete them.\n Choose the last two elements of nums and delete them.\n Choose the first and the last elements of nums and delete them.\n \n The score of the operation is the sum of the deleted elements.\n Your task is to find the maximum number of operations that can be performed, such that all operations have the same score.\n Return the maximum number of operations possible that satisfy the condition mentioned above.\n \n Example 1:\n \n >>> maxOperations(nums = [3,2,1,2,3,4])\n >>> 3\n Explanation: We perform the following operations:\n - Delete the first two elements, with score 3 + 2 = 5, nums = [1,2,3,4].\n - Delete the first and the last elements, with score 1 + 4 = 5, nums = [2,3].\n - Delete the first and the last elements, with score 2 + 3 = 5, nums = [].\n We are unable to perform any more operations as nums is empty.\n \n Example 2:\n \n >>> maxOperations(nums = [3,2,6,1,4])\n >>> 2\n Explanation: We perform the following operations:\n - Delete the first two elements, with score 3 + 2 = 5, nums = [6,1,4].\n - Delete the last two elements, with score 1 + 4 = 5, nums = [6].\n It can be proven that we can perform at most 2 operations.\n \"\"\"\n"}
{"task_id": "maximize-consecutive-elements-in-an-array-after-modification", "prompt": "def maxSelectedElements(nums: List[int]) -> int:\n \"\"\"\n You are given a 0-indexed array nums consisting of positive integers.\n Initially, you can increase the value of any element in the array by at most 1.\n After that, you need to select one or more elements from the final array such that those elements are consecutive when sorted in increasing order. For example, the elements [3, 4, 5] are consecutive while [3, 4, 6] and [1, 1, 2, 3] are not.\n Return the maximum number of elements that you can select.\n \n Example 1:\n \n >>> maxSelectedElements(nums = [2,1,5,1,1])\n >>> 3\n Explanation: We can increase the elements at indices 0 and 3. The resulting array is nums = [3,1,5,2,1].\n We select the elements [3,1,5,2,1] and we sort them to obtain [1,2,3], which are consecutive.\n It can be shown that we cannot select more than 3 consecutive elements.\n Example 2:\n \n >>> maxSelectedElements(nums = [1,4,7,10])\n >>> 1\n Explanation: The maximum consecutive elements that we can select is 1.\n \"\"\"\n"}
{"task_id": "count-prefix-and-suffix-pairs-i", "prompt": "def countPrefixSuffixPairs(words: List[str]) -> int:\n \"\"\"\n You are given a 0-indexed string array words.\n Let's define a boolean function isPrefixAndSuffix that takes two strings, str1 and str2:\n \n isPrefixAndSuffix(str1, str2) returns true if str1 is both a prefix and a suffix of str2, and false otherwise.\n \n For example, isPrefixAndSuffix(\"aba\", \"ababa\") is true because \"aba\" is a prefix of \"ababa\" and also a suffix, but isPrefixAndSuffix(\"abc\", \"abcd\") is false.\n Return an integer denoting the number of index pairs (i, j) such that i < j, and isPrefixAndSuffix(words[i], words[j]) is true.\n \n Example 1:\n \n >>> countPrefixSuffixPairs(words = [\"a\",\"aba\",\"ababa\",\"aa\"])\n >>> 4\n Explanation: In this example, the counted index pairs are:\n i = 0 and j = 1 because isPrefixAndSuffix(\"a\", \"aba\") is true.\n i = 0 and j = 2 because isPrefixAndSuffix(\"a\", \"ababa\") is true.\n i = 0 and j = 3 because isPrefixAndSuffix(\"a\", \"aa\") is true.\n i = 1 and j = 2 because isPrefixAndSuffix(\"aba\", \"ababa\") is true.\n Therefore, the answer is 4.\n Example 2:\n \n >>> countPrefixSuffixPairs(words = [\"pa\",\"papa\",\"ma\",\"mama\"])\n >>> 2\n Explanation: In this example, the counted index pairs are:\n i = 0 and j = 1 because isPrefixAndSuffix(\"pa\", \"papa\") is true.\n i = 2 and j = 3 because isPrefixAndSuffix(\"ma\", \"mama\") is true.\n Therefore, the answer is 2.\n Example 3:\n \n >>> countPrefixSuffixPairs(words = [\"abab\",\"ab\"])\n >>> 0\n Explanation: In this example, the only valid index pair is i = 0 and j = 1, and isPrefixAndSuffix(\"abab\", \"ab\") is false.\n Therefore, the answer is 0.\n \"\"\"\n"}
{"task_id": "find-the-length-of-the-longest-common-prefix", "prompt": "def longestCommonPrefix(arr1: List[int], arr2: List[int]) -> int:\n \"\"\"\n You are given two arrays with positive integers arr1 and arr2.\n A prefix of a positive integer is an integer formed by one or more of its digits, starting from its leftmost digit. For example, 123 is a prefix of the integer 12345, while 234 is not.\n A common prefix of two integers a and b is an integer c, such that c is a prefix of both a and b. For example, 5655359 and 56554 have common prefixes 565 and 5655 while 1223 and 43456 do not have a common prefix.\n You need to find the length of the longest common prefix between all pairs of integers (x, y) such that x belongs to arr1 and y belongs to arr2.\n Return the length of the longest common prefix among all pairs. If no common prefix exists among them, return 0.\n \n Example 1:\n \n >>> longestCommonPrefix(arr1 = [1,10,100], arr2 = [1000])\n >>> 3\n Explanation: There are 3 pairs (arr1[i], arr2[j]):\n - The longest common prefix of (1, 1000) is 1.\n - The longest common prefix of (10, 1000) is 10.\n - The longest common prefix of (100, 1000) is 100.\n The longest common prefix is 100 with a length of 3.\n \n Example 2:\n \n >>> longestCommonPrefix(arr1 = [1,2,3], arr2 = [4,4,4])\n >>> 0\n Explanation: There exists no common prefix for any pair (arr1[i], arr2[j]), hence we return 0.\n Note that common prefixes between elements of the same array do not count.\n \"\"\"\n"}
{"task_id": "most-frequent-prime", "prompt": "def mostFrequentPrime(mat: List[List[int]]) -> int:\n \"\"\"\n You are given a m x n 0-indexed 2D matrix mat. From every cell, you can create numbers in the following way:\n \n There could be at most 8 paths from the cells namely: east, south-east, south, south-west, west, north-west, north, and north-east.\n Select a path from them and append digits in this path to the number being formed by traveling in this direction.\n Note that numbers are generated at every step, for example, if the digits along the path are 1, 9, 1, then there will be three numbers generated along the way: 1, 19, 191.\n \n Return the most frequent prime number greater than 10 out of all the numbers created by traversing the matrix or -1 if no such prime number exists. If there are multiple prime numbers with the highest frequency, then return the largest among them.\n Note: It is invalid to change the direction during the move.\n \n Example 1:\n \n \n \n >>> mostFrequentPrime(mat = [[1,1],[9,9],[1,1]])\n >>> 19\n Explanation:\n From cell (0,0) there are 3 possible directions and the numbers greater than 10 which can be created in those directions are:\n East: [11], South-East: [19], South: [19,191].\n Numbers greater than 10 created from the cell (0,1) in all possible directions are: [19,191,19,11].\n Numbers greater than 10 created from the cell (1,0) in all possible directions are: [99,91,91,91,91].\n Numbers greater than 10 created from the cell (1,1) in all possible directions are: [91,91,99,91,91].\n Numbers greater than 10 created from the cell (2,0) in all possible directions are: [11,19,191,19].\n Numbers greater than 10 created from the cell (2,1) in all possible directions are: [11,19,19,191].\n The most frequent prime number among all the created numbers is 19.\n Example 2:\n \n >>> mostFrequentPrime(mat = [[7]])\n >>> -1\n Explanation: The only number which can be formed is 7. It is a prime number however it is not greater than 10, so return -1.\n Example 3:\n \n >>> mostFrequentPrime(mat = [[9,7,8],[4,6,5],[2,8,6]])\n >>> 97\n Explanation:\n Numbers greater than 10 created from the cell (0,0) in all possible directions are: [97,978,96,966,94,942].\n Numbers greater than 10 created from the cell (0,1) in all possible directions are: [78,75,76,768,74,79].\n Numbers greater than 10 created from the cell (0,2) in all possible directions are: [85,856,86,862,87,879].\n Numbers greater than 10 created from the cell (1,0) in all possible directions are: [46,465,48,42,49,47].\n Numbers greater than 10 created from the cell (1,1) in all possible directions are: [65,66,68,62,64,69,67,68].\n Numbers greater than 10 created from the cell (1,2) in all possible directions are: [56,58,56,564,57,58].\n Numbers greater than 10 created from the cell (2,0) in all possible directions are: [28,286,24,249,26,268].\n Numbers greater than 10 created from the cell (2,1) in all possible directions are: [86,82,84,86,867,85].\n Numbers greater than 10 created from the cell (2,2) in all possible directions are: [68,682,66,669,65,658].\n The most frequent prime number among all the created numbers is 97.\n \"\"\"\n"}
{"task_id": "count-prefix-and-suffix-pairs-ii", "prompt": "def countPrefixSuffixPairs(words: List[str]) -> int:\n \"\"\"\n You are given a 0-indexed string array words.\n Let's define a boolean function isPrefixAndSuffix that takes two strings, str1 and str2:\n \n isPrefixAndSuffix(str1, str2) returns true if str1 is both a prefix and a suffix of str2, and false otherwise.\n \n For example, isPrefixAndSuffix(\"aba\", \"ababa\") is true because \"aba\" is a prefix of \"ababa\" and also a suffix, but isPrefixAndSuffix(\"abc\", \"abcd\") is false.\n Return an integer denoting the number of index pairs (i, j) such that i < j, and isPrefixAndSuffix(words[i], words[j]) is true.\n \n Example 1:\n \n >>> countPrefixSuffixPairs(words = [\"a\",\"aba\",\"ababa\",\"aa\"])\n >>> 4\n Explanation: In this example, the counted index pairs are:\n i = 0 and j = 1 because isPrefixAndSuffix(\"a\", \"aba\") is true.\n i = 0 and j = 2 because isPrefixAndSuffix(\"a\", \"ababa\") is true.\n i = 0 and j = 3 because isPrefixAndSuffix(\"a\", \"aa\") is true.\n i = 1 and j = 2 because isPrefixAndSuffix(\"aba\", \"ababa\") is true.\n Therefore, the answer is 4.\n Example 2:\n \n >>> countPrefixSuffixPairs(words = [\"pa\",\"papa\",\"ma\",\"mama\"])\n >>> 2\n Explanation: In this example, the counted index pairs are:\n i = 0 and j = 1 because isPrefixAndSuffix(\"pa\", \"papa\") is true.\n i = 2 and j = 3 because isPrefixAndSuffix(\"ma\", \"mama\") is true.\n Therefore, the answer is 2.\n Example 3:\n \n >>> countPrefixSuffixPairs(words = [\"abab\",\"ab\"])\n >>> 0\n Explanation: In this example, the only valid index pair is i = 0 and j = 1, and isPrefixAndSuffix(\"abab\", \"ab\") is false.\n Therefore, the answer is 0.\n \"\"\"\n"}
{"task_id": "split-the-array", "prompt": "def isPossibleToSplit(nums: List[int]) -> bool:\n \"\"\"\n You are given an integer array nums of even length. You have to split the array into two parts nums1 and nums2 such that:\n \n nums1.length == nums2.length == nums.length / 2.\n nums1 should contain distinct elements.\n nums2 should also contain distinct elements.\n \n Return true if it is possible to split the array, and false otherwise.\n \n Example 1:\n \n >>> isPossibleToSplit(nums = [1,1,2,2,3,4])\n >>> true\n Explanation: One of the possible ways to split nums is nums1 = [1,2,3] and nums2 = [1,2,4].\n \n Example 2:\n \n >>> isPossibleToSplit(nums = [1,1,1,1])\n >>> false\n Explanation: The only possible way to split nums is nums1 = [1,1] and nums2 = [1,1]. Both nums1 and nums2 do not contain distinct elements. Therefore, we return false.\n \"\"\"\n"}
{"task_id": "find-the-largest-area-of-square-inside-two-rectangles", "prompt": "def largestSquareArea(bottomLeft: List[List[int]], topRight: List[List[int]]) -> int:\n \"\"\"\n There exist n rectangles in a 2D plane with edges parallel to the x and y axis. You are given two 2D integer arrays\u00a0bottomLeft and topRight\u00a0where bottomLeft[i] = [a_i, b_i] and topRight[i] = [c_i, d_i] represent\u00a0the bottom-left and top-right coordinates of the ith rectangle, respectively.\n You need to find the maximum area of a square that can fit inside the intersecting region of at least two rectangles. Return 0 if such a square does not exist.\n \n Example 1:\n \n >>> largestSquareArea(bottomLeft = [[1,1],[2,2],[3,1]], topRight = [[3,3],[4,4],[6,6]])\n >>> 1\n Explanation:\n A square with side length 1 can fit inside either the intersecting region of rectangles 0 and 1 or the intersecting region of rectangles 1 and 2. Hence the maximum area is 1. It can be shown that a square with a greater side length can not fit inside any intersecting region of two rectangles.\n Example 2:\n \n >>> largestSquareArea(bottomLeft = [[1,1],[1,3],[1,5]], topRight = [[5,5],[5,7],[5,9]])\n >>> 4\n Explanation:\n A square with side length 2 can fit inside either the intersecting region of rectangles 0 and 1 or the intersecting region of rectangles 1 and 2. Hence the maximum area is 2 * 2 = 4. It can be shown that a square with a greater side length can not fit inside any intersecting region of two rectangles.\n Example 3:\n \n >>> largestSquareArea(bottomLeft = [[1,1],[2,2],[1,2]], topRight = [[3,3],[4,4],[3,4]])\n >>> 1\n Explanation:\n A square with side length 1 can fit inside the intersecting region of any two rectangles. Also, no larger square can, so the maximum area is 1. Note that the region can be formed by the intersection of more than 2 rectangles.\n Example 4:\n \n >>> largestSquareArea(bottomLeft = [[1,1],[3,3],[3,1]], topRight = [[2,2],[4,4],[4,2]])\n >>> 0\n Explanation:\n No pair of rectangles intersect, hence, the answer is 0.\n \"\"\"\n"}
{"task_id": "earliest-second-to-mark-indices-i", "prompt": "def earliestSecondToMarkIndices(nums: List[int], changeIndices: List[int]) -> int:\n \"\"\"\n You are given two 1-indexed integer arrays, nums and, changeIndices, having lengths n and m, respectively.\n Initially, all indices in nums are unmarked. Your task is to mark all indices in nums.\n In each second, s, in order from 1 to m (inclusive), you can perform one of the following operations:\n \n Choose an index i in the range [1, n] and decrement nums[i] by 1.\n If nums[changeIndices[s]] is equal to 0, mark the index changeIndices[s].\n Do nothing.\n \n Return an integer denoting the earliest second in the range [1, m] when all indices in nums can be marked by choosing operations optimally, or -1 if it is impossible.\n \n Example 1:\n \n >>> earliestSecondToMarkIndices(nums = [2,2,0], changeIndices = [2,2,2,2,3,2,2,1])\n >>> 8\n Explanation: In this example, we have 8 seconds. The following operations can be performed to mark all indices:\n Second 1: Choose index 1 and decrement nums[1] by one. nums becomes [1,2,0].\n Second 2: Choose index 1 and decrement nums[1] by one. nums becomes [0,2,0].\n Second 3: Choose index 2 and decrement nums[2] by one. nums becomes [0,1,0].\n Second 4: Choose index 2 and decrement nums[2] by one. nums becomes [0,0,0].\n Second 5: Mark the index changeIndices[5], which is marking index 3, since nums[3] is equal to 0.\n Second 6: Mark the index changeIndices[6], which is marking index 2, since nums[2] is equal to 0.\n Second 7: Do nothing.\n Second 8: Mark the index changeIndices[8], which is marking index 1, since nums[1] is equal to 0.\n Now all indices have been marked.\n It can be shown that it is not possible to mark all indices earlier than the 8th second.\n Hence, the answer is 8.\n \n Example 2:\n \n >>> earliestSecondToMarkIndices(nums = [1,3], changeIndices = [1,1,1,2,1,1,1])\n >>> 6\n Explanation: In this example, we have 7 seconds. The following operations can be performed to mark all indices:\n Second 1: Choose index 2 and decrement nums[2] by one. nums becomes [1,2].\n Second 2: Choose index 2 and decrement nums[2] by one. nums becomes [1,1].\n Second 3: Choose index 2 and decrement nums[2] by one. nums becomes [1,0].\n Second 4: Mark the index changeIndices[4], which is marking index 2, since nums[2] is equal to 0.\n Second 5: Choose index 1 and decrement nums[1] by one. nums becomes [0,0].\n Second 6: Mark the index changeIndices[6], which is marking index 1, since nums[1] is equal to 0.\n Now all indices have been marked.\n It can be shown that it is not possible to mark all indices earlier than the 6th second.\n Hence, the answer is 6.\n \n Example 3:\n \n >>> earliestSecondToMarkIndices(nums = [0,1], changeIndices = [2,2,2])\n >>> -1\n Explanation: In this example, it is impossible to mark all indices because index 1 isn't in changeIndices.\n Hence, the answer is -1.\n \"\"\"\n"}
{"task_id": "winner-of-the-linked-list-game", "prompt": "# class ListNode:\n# def __init__(val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution:\n def gameResult(head: Optional[ListNode]) -> str:\n \"\"\"\n You are given the head of a linked list of even length containing integers.\n Each odd-indexed node contains an odd integer and each even-indexed node contains an even integer.\n We call each even-indexed node and its next node a pair, e.g., the nodes with indices 0 and 1 are a pair, the nodes with indices 2 and 3 are a pair, and so on.\n For every pair, we compare the values of the nodes in the pair:\n \n If the odd-indexed node is higher, the \"Odd\" team gets a point.\n If the even-indexed node is higher, the \"Even\" team gets a point.\n \n Return the name of the team with the higher points, if the points are equal, return \"Tie\".\n \n Example 1:\n \n >>> __init__(head = [2,1])\n >>> \"Even\"\n Explanation: There is only one pair in this linked list and that is (2,1). Since 2 > 1, the Even team gets the point.\n Hence, the answer would be \"Even\".\n \n Example 2:\n \n >>> __init__(head = [2,5,4,7,20,5])\n >>> \"Odd\"\n Explanation: There are 3 pairs in this linked list. Let's investigate each pair individually:\n (2,5) -> Since 2 < 5, The Odd team gets the point.\n (4,7) -> Since 4 < 7, The Odd team gets the point.\n (20,5) -> Since 20 > 5, The Even team gets the point.\n The Odd team earned 2 points while the Even team got 1 point and the Odd team has the higher points.\n Hence, the answer would be \"Odd\".\n \n Example 3:\n \n >>> __init__(head = [4,5,2,1])\n >>> \"Tie\"\n Explanation: There are 2 pairs in this linked list. Let's investigate each pair individually:\n (4,5) -> Since 4 < 5, the Odd team gets the point.\n (2,1) -> Since 2 > 1, the Even team gets the point.\n Both teams earned 1 point.\n Hence, the answer would be \"Tie\".\n \"\"\"\n"}
{"task_id": "linked-list-frequency", "prompt": "# class ListNode:\n# def __init__(val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution:\n def frequenciesOfElements(head: Optional[ListNode]) -> Optional[ListNode]:\n \"\"\"\n Given the head of a linked list containing k distinct elements, return the head to a linked list of length k containing the frequency of each distinct element in the given linked list in any order.\n \n Example 1:\n \n >>> __init__(head = [1,1,2,1,2,3])\n >>> [3,2,1]\n Explanation: There are 3 distinct elements in the list. The frequency of 1 is 3, the frequency of 2 is 2 and the frequency of 3 is 1. Hence, we return 3 -> 2 -> 1.\n Note that 1 -> 2 -> 3, 1 -> 3 -> 2, 2 -> 1 -> 3, 2 -> 3 -> 1, and 3 -> 1 -> 2 are also valid answers.\n \n Example 2:\n \n >>> __init__(head = [1,1,2,2,2])\n >>> [2,3]\n Explanation: There are 2 distinct elements in the list. The frequency of 1 is 2 and the frequency of 2 is 3. Hence, we return 2 -> 3.\n \n Example 3:\n \n >>> __init__(head = [6,5,4,3,2,1])\n >>> [1,1,1,1,1,1]\n Explanation: There are 6 distinct elements in the list. The frequency of each of them is 1. Hence, we return 1 -> 1 -> 1 -> 1 -> 1 -> 1.\n \"\"\"\n"}
{"task_id": "minimum-operations-to-exceed-threshold-value-i", "prompt": "def minOperations(nums: List[int], k: int) -> int:\n \"\"\"\n You are given a 0-indexed integer array nums, and an integer k.\n In one operation, you can remove one occurrence of the smallest element of nums.\n Return the minimum number of operations needed so that all elements of the array are greater than or equal to k.\n \n Example 1:\n \n >>> minOperations(nums = [2,11,10,1,3], k = 10)\n >>> 3\n Explanation: After one operation, nums becomes equal to [2, 11, 10, 3].\n After two operations, nums becomes equal to [11, 10, 3].\n After three operations, nums becomes equal to [11, 10].\n At this stage, all the elements of nums are greater than or equal to 10 so we can stop.\n It can be shown that 3 is the minimum number of operations needed so that all elements of the array are greater than or equal to 10.\n \n Example 2:\n \n >>> minOperations(nums = [1,1,2,4,9], k = 1)\n >>> 0\n Explanation: All elements of the array are greater than or equal to 1 so we do not need to apply any operations on nums.\n Example 3:\n \n >>> minOperations(nums = [1,1,2,4,9], k = 9)\n >>> 4\n Explanation: only a single element of nums is greater than or equal to 9 so we need to apply the operations 4 times on nums.\n \"\"\"\n"}
{"task_id": "minimum-operations-to-exceed-threshold-value-ii", "prompt": "def minOperations(nums: List[int], k: int) -> int:\n \"\"\"\n You are given a 0-indexed integer array nums, and an integer k.\n You are allowed to perform some operations on nums, where in a single operation, you can:\n \n Select the two smallest integers x and y from nums.\n Remove x and y from nums.\n Insert (min(x, y) * 2 + max(x, y)) at any position in the array.\n \n Note that you can only apply the described operation if nums contains at least two elements.\n Return the minimum number of operations needed so that all elements of the array are greater than or equal to k.\n \n Example 1:\n \n >>> minOperations(nums = [2,11,10,1,3], k = 10)\n >>> 2\n Explanation:\n \n In the first operation, we remove elements 1 and 2, then add 1 * 2 + 2 to nums. nums becomes equal to [4, 11, 10, 3].\n In the second operation, we remove elements 3 and 4, then add 3 * 2 + 4 to nums. nums becomes equal to [10, 11, 10].\n \n At this stage, all the elements of nums are greater than or equal to 10 so we can stop.\n It can be shown that 2 is the minimum number of operations needed so that all elements of the array are greater than or equal to 10.\n \n Example 2:\n \n >>> minOperations(nums = [1,1,2,4,9], k = 20)\n >>> 4\n Explanation:\n \n After one operation, nums becomes equal to [2, 4, 9, 3].\n After two operations, nums becomes equal to [7, 4, 9].\n After three operations, nums becomes equal to [15, 9].\n After four operations, nums becomes equal to [33].\n \n At this stage, all the elements of nums are greater than 20 so we can stop.\n It can be shown that 4 is the minimum number of operations needed so that all elements of the array are greater than or equal to 20.\n \"\"\"\n"}
{"task_id": "count-pairs-of-connectable-servers-in-a-weighted-tree-network", "prompt": "def countPairsOfConnectableServers(edges: List[List[int]], signalSpeed: int) -> List[int]:\n \"\"\"\n You are given an unrooted weighted tree with n vertices representing servers numbered from 0 to n - 1, an array edges where edges[i] = [ai, bi, weighti] represents a bidirectional edge between vertices ai and bi of weight weighti. You are also given an integer signalSpeed.\n Two servers a and b are connectable through a server c if:\n \n a < b, a != c and b != c.\n The distance from c to a is divisible by signalSpeed.\n The distance from c to b is divisible by signalSpeed.\n The path from c to b and the path from c to a do not share any edges.\n \n Return an integer array count of length n where count[i] is the number of server pairs that are connectable through the server i.\n \n Example 1:\n \n \n >>> countPairsOfConnectableServers(edges = [[0,1,1],[1,2,5],[2,3,13],[3,4,9],[4,5,2]], signalSpeed = 1)\n >>> [0,4,6,6,4,0]\n Explanation: Since signalSpeed is 1, count[c] is equal to the number of pairs of paths that start at c and do not share any edges.\n In the case of the given path graph, count[c] is equal to the number of servers to the left of c multiplied by the servers to the right of c.\n \n Example 2:\n \n \n >>> countPairsOfConnectableServers(edges = [[0,6,3],[6,5,3],[0,3,1],[3,2,7],[3,1,6],[3,4,2]], signalSpeed = 3)\n >>> [2,0,0,0,0,0,2]\n Explanation: Through server 0, there are 2 pairs of connectable servers: (4, 5) and (4, 6).\n Through server 6, there are 2 pairs of connectable servers: (4, 5) and (0, 5).\n It can be shown that no two servers are connectable through servers other than 0 and 6.\n \"\"\"\n"}
{"task_id": "find-the-maximum-sum-of-node-values", "prompt": "def maximumValueSum(nums: List[int], k: int, edges: List[List[int]]) -> int:\n \"\"\"\n There exists an undirected tree with n nodes numbered 0 to n - 1. You are given a 0-indexed 2D integer array edges of length n - 1, where edges[i] = [ui, vi] indicates that there is an edge between nodes ui and vi in the tree. You are also given a positive integer k, and a 0-indexed array of non-negative integers nums of length n, where nums[i] represents the value of the node numbered i.\n Alice wants the sum of values of tree nodes to be maximum, for which Alice can perform the following operation any number of times (including zero) on the tree:\n \n Choose any edge [u, v] connecting the nodes u and v, and update their values as follows:\n \n \n nums[u] = nums[u] XOR k\n nums[v] = nums[v] XOR k\n \n \n \n Return the maximum possible sum of the values Alice can achieve by performing the operation any number of times.\n \n Example 1:\n \n \n >>> maximumValueSum(nums = [1,2,1], k = 3, edges = [[0,1],[0,2]])\n >>> 6\n Explanation: Alice can achieve the maximum sum of 6 using a single operation:\n - Choose the edge [0,2]. nums[0] and nums[2] become: 1 XOR 3 = 2, and the array nums becomes: [1,2,1] -> [2,2,2].\n The total sum of values is 2 + 2 + 2 = 6.\n It can be shown that 6 is the maximum achievable sum of values.\n \n Example 2:\n \n \n >>> maximumValueSum(nums = [2,3], k = 7, edges = [[0,1]])\n >>> 9\n Explanation: Alice can achieve the maximum sum of 9 using a single operation:\n - Choose the edge [0,1]. nums[0] becomes: 2 XOR 7 = 5 and nums[1] become: 3 XOR 7 = 4, and the array nums becomes: [2,3] -> [5,4].\n The total sum of values is 5 + 4 = 9.\n It can be shown that 9 is the maximum achievable sum of values.\n \n Example 3:\n \n \n >>> maximumValueSum(nums = [7,7,7,7,7,7], k = 3, edges = [[0,1],[0,2],[0,3],[0,4],[0,5]])\n >>> 42\n Explanation: The maximum achievable sum is 42 which can be achieved by Alice performing no operations.\n \"\"\"\n"}
{"task_id": "distribute-elements-into-two-arrays-i", "prompt": "def resultArray(nums: List[int]) -> List[int]:\n \"\"\"\n You are given a 1-indexed array of distinct integers nums of length n.\n You need to distribute all the elements of nums between two arrays arr1 and arr2 using n operations. In the first operation, append nums[1] to arr1. In the second operation, append nums[2] to arr2. Afterwards, in the ith operation:\n \n If the last element of arr1 is greater than the last element of arr2, append nums[i] to arr1. Otherwise, append nums[i] to arr2.\n \n The array result is formed by concatenating the arrays arr1 and arr2. For example, if arr1 == [1,2,3] and arr2 == [4,5,6], then result = [1,2,3,4,5,6].\n Return the array result.\n \n Example 1:\n \n >>> resultArray(nums = [2,1,3])\n >>> [2,3,1]\n Explanation: After the first 2 operations, arr1 = [2] and arr2 = [1].\n In the 3rd operation, as the last element of arr1 is greater than the last element of arr2 (2 > 1), append nums[3] to arr1.\n After 3 operations, arr1 = [2,3] and arr2 = [1].\n Hence, the array result formed by concatenation is [2,3,1].\n \n Example 2:\n \n >>> resultArray(nums = [5,4,3,8])\n >>> [5,3,4,8]\n Explanation: After the first 2 operations, arr1 = [5] and arr2 = [4].\n In the 3rd operation, as the last element of arr1 is greater than the last element of arr2 (5 > 4), append nums[3] to arr1, hence arr1 becomes [5,3].\n In the 4th operation, as the last element of arr2 is greater than the last element of arr1 (4 > 3), append nums[4] to arr2, hence arr2 becomes [4,8].\n After 4 operations, arr1 = [5,3] and arr2 = [4,8].\n Hence, the array result formed by concatenation is [5,3,4,8].\n \"\"\"\n"}
{"task_id": "count-submatrices-with-top-left-element-and-sum-less-than-k", "prompt": "def countSubmatrices(grid: List[List[int]], k: int) -> int:\n \"\"\"\n You are given a 0-indexed integer matrix grid and an integer k.\n Return the number of submatrices that contain the top-left element of the grid, and have a sum less than or equal to k.\n \n Example 1:\n \n \n >>> countSubmatrices(grid = [[7,6,3],[6,6,1]], k = 18)\n >>> 4\n Explanation: There are only 4 submatrices, shown in the image above, that contain the top-left element of grid, and have a sum less than or equal to 18.\n Example 2:\n \n \n >>> countSubmatrices(grid = [[7,2,9],[1,5,0],[2,6,6]], k = 20)\n >>> 6\n Explanation: There are only 6 submatrices, shown in the image above, that contain the top-left element of grid, and have a sum less than or equal to 20.\n \"\"\"\n"}
{"task_id": "minimum-operations-to-write-the-letter-y-on-a-grid", "prompt": "def minimumOperationsToWriteY(grid: List[List[int]]) -> int:\n \"\"\"\n You are given a 0-indexed n x n grid where n is odd, and grid[r][c] is 0, 1, or 2.\n We say that a cell belongs to the Letter Y if it belongs to one of the following:\n \n The diagonal starting at the top-left cell and ending at the center cell of the grid.\n The diagonal starting at the top-right cell and ending at the center cell of the grid.\n The vertical line starting at the center cell and ending at the bottom border of the grid.\n \n The Letter Y is written on the grid if and only if:\n \n All values at cells belonging to the Y are equal.\n All values at cells not belonging to the Y are equal.\n The values at cells belonging to the Y are different from the values at cells not belonging to the Y.\n \n Return the minimum number of operations needed to write the letter Y on the grid given that in one operation you can change the value at any cell to 0, 1, or 2.\n \n Example 1:\n \n \n >>> minimumOperationsToWriteY(grid = [[1,2,2],[1,1,0],[0,1,0]])\n >>> 3\n Explanation: We can write Y on the grid by applying the changes highlighted in blue in the image above. After the operations, all cells that belong to Y, denoted in bold, have the same value of 1 while those that do not belong to Y are equal to 0.\n It can be shown that 3 is the minimum number of operations needed to write Y on the grid.\n \n Example 2:\n \n \n >>> minimumOperationsToWriteY(grid = [[0,1,0,1,0],[2,1,0,1,2],[2,2,2,0,1],[2,2,2,2,2],[2,1,2,2,2]])\n >>> 12\n Explanation: We can write Y on the grid by applying the changes highlighted in blue in the image above. After the operations, all cells that belong to Y, denoted in bold, have the same value of 0 while those that do not belong to Y are equal to 2.\n It can be shown that 12 is the minimum number of operations needed to write Y on the grid.\n \"\"\"\n"}
{"task_id": "distribute-elements-into-two-arrays-ii", "prompt": "def resultArray(nums: List[int]) -> List[int]:\n \"\"\"\n You are given a 1-indexed array of integers nums of length n.\n We define a function greaterCount such that greaterCount(arr, val) returns the number of elements in arr that are strictly greater than val.\n You need to distribute all the elements of nums between two arrays arr1 and arr2 using n operations. In the first operation, append nums[1] to arr1. In the second operation, append nums[2] to arr2. Afterwards, in the ith operation:\n \n If greaterCount(arr1, nums[i]) > greaterCount(arr2, nums[i]), append nums[i] to arr1.\n If greaterCount(arr1, nums[i]) < greaterCount(arr2, nums[i]), append nums[i] to arr2.\n If greaterCount(arr1, nums[i]) == greaterCount(arr2, nums[i]), append nums[i] to the array with a lesser number of elements.\n If there is still a tie, append nums[i] to arr1.\n \n The array result is formed by concatenating the arrays arr1 and arr2. For example, if arr1 == [1,2,3] and arr2 == [4,5,6], then result = [1,2,3,4,5,6].\n Return the integer array result.\n \n Example 1:\n \n >>> resultArray(nums = [2,1,3,3])\n >>> [2,3,1,3]\n Explanation: After the first 2 operations, arr1 = [2] and arr2 = [1].\n In the 3rd operation, the number of elements greater than 3 is zero in both arrays. Also, the lengths are equal, hence, append nums[3] to arr1.\n In the 4th operation, the number of elements greater than 3 is zero in both arrays. As the length of arr2 is lesser, hence, append nums[4] to arr2.\n After 4 operations, arr1 = [2,3] and arr2 = [1,3].\n Hence, the array result formed by concatenation is [2,3,1,3].\n \n Example 2:\n \n >>> resultArray(nums = [5,14,3,1,2])\n >>> [5,3,1,2,14]\n Explanation: After the first 2 operations, arr1 = [5] and arr2 = [14].\n In the 3rd operation, the number of elements greater than 3 is one in both arrays. Also, the lengths are equal, hence, append nums[3] to arr1.\n In the 4th operation, the number of elements greater than 1 is greater in arr1 than arr2 (2 > 1). Hence, append nums[4] to arr1.\n In the 5th operation, the number of elements greater than 2 is greater in arr1 than arr2 (2 > 1). Hence, append nums[5] to arr1.\n After 5 operations, arr1 = [5,3,1,2] and arr2 = [14].\n Hence, the array result formed by concatenation is [5,3,1,2,14].\n \n Example 3:\n \n >>> resultArray(nums = [3,3,3,3])\n >>> [3,3,3,3]\n Explanation: At the end of 4 operations, arr1 = [3,3] and arr2 = [3,3].\n Hence, the array result formed by concatenation is [3,3,3,3].\n \"\"\"\n"}
{"task_id": "maximum-increasing-triplet-value", "prompt": "def maximumTripletValue(nums: List[int]) -> int:\n \"\"\"\n Given an array nums, return the maximum value of a triplet (i, j, k) such that i < j < k and nums[i] < nums[j] < nums[k].\n The value of a triplet (i, j, k) is nums[i] - nums[j] + nums[k].\n \n \n \n \n Example 1:\n \n >>> maximumTripletValue(nums = [5,6,9])\n >>> 8\n Explanation: We only have one choice for an increasing triplet and that is choosing all three elements. The value of this triplet would be 5 - 6 + 9 = 8.\n \n Example 2:\n \n >>> maximumTripletValue(nums = [1,5,3,6])\n >>> 4\n Explanation: There are only two increasing triplets:\n (0, 1, 3): The value of this triplet is nums[0] - nums[1] + nums[3] = 1 - 5 + 6 = 2.\n (0, 2, 3): The value of this triplet is nums[0] - nums[2] + nums[3] = 1 - 3 + 6 = 4.\n Thus the answer would be 4.\n \"\"\"\n"}
{"task_id": "apple-redistribution-into-boxes", "prompt": "def minimumBoxes(apple: List[int], capacity: List[int]) -> int:\n \"\"\"\n You are given an array apple of size n and an array capacity of size m.\n There are n packs where the ith pack contains apple[i] apples. There are m boxes as well, and the ith box has a capacity of capacity[i] apples.\n Return the minimum number of boxes you need to select to redistribute these n packs of apples into boxes.\n Note that, apples from the same pack can be distributed into different boxes.\n \n Example 1:\n \n >>> minimumBoxes(apple = [1,3,2], capacity = [4,3,1,5,2])\n >>> 2\n Explanation: We will use boxes with capacities 4 and 5.\n It is possible to distribute the apples as the total capacity is greater than or equal to the total number of apples.\n \n Example 2:\n \n >>> minimumBoxes(apple = [5,5,5], capacity = [2,4,2,7])\n >>> 4\n Explanation: We will need to use all the boxes.\n \"\"\"\n"}
{"task_id": "maximize-happiness-of-selected-children", "prompt": "def maximumHappinessSum(happiness: List[int], k: int) -> int:\n \"\"\"\n You are given an array happiness of length n, and a positive integer k.\n There are n children standing in a queue, where the ith child has happiness value happiness[i]. You want to select k children from these n children in k turns.\n In each turn, when you select a child, the happiness value of all the children that have not been selected till now decreases by 1. Note that the happiness value cannot become negative and gets decremented only if it is positive.\n Return the maximum sum of the happiness values of the selected children you can achieve by selecting k children.\n \n Example 1:\n \n >>> maximumHappinessSum(happiness = [1,2,3], k = 2)\n >>> 4\n Explanation: We can pick 2 children in the following way:\n - Pick the child with the happiness value == 3. The happiness value of the remaining children becomes [0,1].\n - Pick the child with the happiness value == 1. The happiness value of the remaining child becomes [0]. Note that the happiness value cannot become less than 0.\n The sum of the happiness values of the selected children is 3 + 1 = 4.\n \n Example 2:\n \n >>> maximumHappinessSum(happiness = [1,1,1,1], k = 2)\n >>> 1\n Explanation: We can pick 2 children in the following way:\n - Pick any child with the happiness value == 1. The happiness value of the remaining children becomes [0,0,0].\n - Pick the child with the happiness value == 0. The happiness value of the remaining child becomes [0,0].\n The sum of the happiness values of the selected children is 1 + 0 = 1.\n \n Example 3:\n \n >>> maximumHappinessSum(happiness = [2,3,4,5], k = 1)\n >>> 5\n Explanation: We can pick 1 child in the following way:\n - Pick the child with the happiness value == 5. The happiness value of the remaining children becomes [1,2,3].\n The sum of the happiness values of the selected children is 5.\n \"\"\"\n"}
{"task_id": "shortest-uncommon-substring-in-an-array", "prompt": "def shortestSubstrings(arr: List[str]) -> List[str]:\n \"\"\"\n You are given an array arr of size n consisting of non-empty strings.\n Find a string array answer of size n such that:\n \n answer[i] is the shortest substring of arr[i] that does not occur as a substring in any other string in arr. If multiple such substrings exist, answer[i] should be the lexicographically smallest. And if no such substring exists, answer[i] should be an empty string.\n \n Return the array answer.\n \n Example 1:\n \n >>> shortestSubstrings(arr = [\"cab\",\"ad\",\"bad\",\"c\"])\n >>> [\"ab\",\"\",\"ba\",\"\"]\n Explanation: We have the following:\n - For the string \"cab\", the shortest substring that does not occur in any other string is either \"ca\" or \"ab\", we choose the lexicographically smaller substring, which is \"ab\".\n - For the string \"ad\", there is no substring that does not occur in any other string.\n - For the string \"bad\", the shortest substring that does not occur in any other string is \"ba\".\n - For the string \"c\", there is no substring that does not occur in any other string.\n \n Example 2:\n \n >>> shortestSubstrings(arr = [\"abc\",\"bcd\",\"abcd\"])\n >>> [\"\",\"\",\"abcd\"]\n Explanation: We have the following:\n - For the string \"abc\", there is no substring that does not occur in any other string.\n - For the string \"bcd\", there is no substring that does not occur in any other string.\n - For the string \"abcd\", the shortest substring that does not occur in any other string is \"abcd\".\n \"\"\"\n"}
{"task_id": "maximum-strength-of-k-disjoint-subarrays", "prompt": "def maximumStrength(nums: List[int], k: int) -> int:\n \"\"\"\n You are given an array of integers nums with length n, and a positive odd integer k.\n Select exactly k disjoint subarrays sub1, sub2, ..., subk from nums such that the last element of subi appears before the first element of sub{i+1} for all 1 <= i <= k-1. The goal is to maximize their combined strength.\n The strength of the selected subarrays is defined as:\n strength = k * sum(sub1)- (k - 1) * sum(sub2) + (k - 2) * sum(sub3) - ... - 2 * sum(sub{k-1}) + sum(subk)\n where sum(subi) is the sum of the elements in the i-th subarray.\n Return the maximum possible strength that can be obtained from selecting exactly k disjoint subarrays from nums.\n Note that the chosen subarrays don't need to cover the entire array.\n \n Example 1:\n >>> maximumStrength(nums = [1,2,3,-1,2], k = 3)\n >>> 22\n Explanation:\n The best possible way to select 3 subarrays is: nums[0..2], nums[3..3], and nums[4..4]. The strength is calculated as follows:\n strength = 3 * (1 + 2 + 3) - 2 * (-1) + 2 = 22\n \n Example 2:\n >>> maximumStrength(nums = [12,-2,-2,-2,-2], k = 5)\n >>> 64\n Explanation:\n The only possible way to select 5 disjoint subarrays is: nums[0..0], nums[1..1], nums[2..2], nums[3..3], and nums[4..4]. The strength is calculated as follows:\n strength = 5 * 12 - 4 * (-2) + 3 * (-2) - 2 * (-2) + (-2) = 64\n Example 3:\n >>> maximumStrength(nums = [-1,-2,-3], k = 1)\n >>> -1\n Explanation:\n The best possible way to select 1 subarray is: nums[0..0]. The strength is -1.\n \"\"\"\n"}
{"task_id": "match-alphanumerical-pattern-in-matrix-i", "prompt": "def findPattern(board: List[List[int]], pattern: List[str]) -> List[int]:\n \"\"\"\n You are given a 2D integer matrix board and a 2D character matrix pattern. Where 0 <= board[r][c] <= 9 and each element of pattern is either a digit or a lowercase English letter.\n Your task is to find a submatrix of board that matches pattern.\n An integer matrix part matches pattern if we can replace cells containing letters in pattern with some digits (each distinct letter with a unique digit) in such a way that the resulting matrix becomes identical to the integer matrix part. In other words,\n \n The matrices have identical dimensions.\n If pattern[r][c] is a digit, then part[r][c] must be the same digit.\n If pattern[r][c] is a letter x:\n \n For every pattern[i][j] == x, part[i][j] must be the same as part[r][c].\n For every pattern[i][j] != x, part[i][j] must be different than part[r][c].\n \n \n \n Return an array of length 2 containing the row number and column number of the upper-left corner of a submatrix of board which matches pattern. If there is more than one such submatrix, return the coordinates of the submatrix with the lowest row index, and in case there is still a tie, return the coordinates of the submatrix with the lowest column index. If there are no suitable answers, return [-1, -1].\n \n Example 1:\n \n \n \n \n 1\n 2\n 2\n \n \n 2\n 2\n 3\n \n \n 2\n 3\n 3\n \n \n \n \n \n \n a\n b\n \n \n b\n b\n \n \n \n \n \n >>> findPattern(board = [[1,2,2],[2,2,3],[2,3,3]], pattern = [\"ab\",\"bb\"])\n >>> [0,0]\n Explanation: If we consider this mapping: \"a\" -> 1 and \"b\" -> 2; the submatrix with the upper-left corner (0,0) is a match as outlined in the matrix above.\n Note that the submatrix with the upper-left corner (1,1) is also a match but since it comes after the other one, we return [0,0].\n \n Example 2:\n \n \n \n \n 1\n 1\n 2\n \n \n 3\n 3\n 4\n \n \n 6\n 6\n 6\n \n \n \n \n \n \n a\n b\n \n \n 6\n 6\n \n \n \n \n \n >>> findPattern(board = [[1,1,2],[3,3,4],[6,6,6]], pattern = [\"ab\",\"66\"])\n >>> [1,1]\n Explanation: If we consider this mapping: \"a\" -> 3 and \"b\" -> 4; the submatrix with the upper-left corner (1,1) is a match as outlined in the matrix above.\n Note that since the corresponding values of \"a\" and \"b\" must differ, the submatrix with the upper-left corner (1,0) is not a match. Hence, we return [1,1].\n \n Example 3:\n \n \n \n \n 1\n 2\n \n \n 2\n 1\n \n \n \n \n \n \n x\n x\n \n \n \n \n \n >>> findPattern(board = [[1,2],[2,1]], pattern = [\"xx\"])\n >>> [-1,-1]\n Explanation: Since the values of the matched submatrix must be the same, there is no match. Hence, we return [-1,-1].\n \"\"\"\n"}
{"task_id": "find-the-sum-of-encrypted-integers", "prompt": "def sumOfEncryptedInt(nums: List[int]) -> int:\n \"\"\"\n You are given an integer array nums containing positive integers. We define a function encrypt such that encrypt(x) replaces every digit in x with the largest digit in x. For example, encrypt(523) = 555 and encrypt(213) = 333.\n Return the sum of encrypted elements.\n \n Example 1:\n \n >>> sumOfEncryptedInt(nums = [1,2,3])\n >>> 6\n Explanation: The encrypted elements are\u00a0[1,2,3]. The sum of encrypted elements is 1 + 2 + 3 == 6.\n \n Example 2:\n \n >>> sumOfEncryptedInt(nums = [10,21,31])\n >>> 66\n Explanation: The encrypted elements are [11,22,33]. The sum of encrypted elements is 11 + 22 + 33 == 66.\n \"\"\"\n"}
{"task_id": "mark-elements-on-array-by-performing-queries", "prompt": "def unmarkedSumArray(nums: List[int], queries: List[List[int]]) -> List[int]:\n \"\"\"\n You are given a 0-indexed array nums of size n consisting of positive integers.\n You are also given a 2D array queries of size m where queries[i] = [indexi, ki].\n Initially all elements of the array are unmarked.\n You need to apply m queries on the array in order, where on the ith query you do the following:\n \n Mark the element at index indexi if it is not already marked.\n Then mark ki unmarked elements in the array with the smallest values. If multiple such elements exist, mark the ones with the smallest indices. And if less than ki unmarked elements exist, then mark all of them.\n \n Return an array answer of size m where answer[i] is the sum of unmarked elements in the array after the ith query.\n \n Example 1:\n \n >>> unmarkedSumArray(nums = [1,2,2,1,2,3,1], queries = [[1,2],[3,3],[4,2]])\n >>> [8,3,0]\n Explanation:\n We do the following queries on the array:\n \n Mark the element at index 1, and 2 of the smallest unmarked elements with the smallest indices if they exist, the marked elements now are nums = [1,2,2,1,2,3,1]. The sum of unmarked elements is 2 + 2 + 3 + 1 = 8.\n Mark the element at index 3, since it is already marked we skip it. Then we mark 3 of the smallest unmarked elements with the smallest indices, the marked elements now are nums = [1,2,2,1,2,3,1]. The sum of unmarked elements is 3.\n Mark the element at index 4, since it is already marked we skip it. Then we mark 2 of the smallest unmarked elements with the smallest indices if they exist, the marked elements now are nums = [1,2,2,1,2,3,1]. The sum of unmarked elements is 0.\n \n \n Example 2:\n \n >>> unmarkedSumArray(nums = [1,4,2,3], queries = [[0,1]])\n >>> [7]\n Explanation: We do one query which is mark the element at index 0 and mark the smallest element among unmarked elements. The marked elements will be nums = [1,4,2,3], and the sum of unmarked elements is 4 + 3 = 7.\n \"\"\"\n"}
{"task_id": "replace-question-marks-in-string-to-minimize-its-value", "prompt": "def minimizeStringValue(s: str) -> str:\n \"\"\"\n You are given a string s. s[i] is either a lowercase English letter or '?'.\n For a string t having length m containing only lowercase English letters, we define the function cost(i) for an index i\u00a0as the number of characters equal to t[i]\u00a0that appeared before it, i.e. in the range [0, i - 1].\n The value of t is the sum of cost(i) for all indices i.\n For example, for the string t = \"aab\":\n \n cost(0) = 0\n cost(1) = 1\n cost(2) = 0\n Hence, the value of \"aab\" is 0 + 1 + 0 = 1.\n \n Your task is to replace all occurrences of '?' in s with any lowercase English letter so that the value of s is minimized.\n Return a string denoting the modified string with replaced occurrences of '?'. If there are multiple strings resulting in the minimum value, return the lexicographically smallest one.\n \n Example 1:\n \n >>> minimizeStringValue(s = \"???\")\n >>> \"abc\"\n Explanation: In this example, we can replace the occurrences of '?' to make s equal to \"abc\".\n For \"abc\", cost(0) = 0, cost(1) = 0, and cost(2) = 0.\n The value of \"abc\" is 0.\n Some other modifications of s that have a value of 0 are \"cba\", \"abz\", and, \"hey\".\n Among all of them, we choose the lexicographically smallest.\n \n Example 2:\n \n >>> minimizeStringValue(s = \"a?a?\")\n >>> \"abac\"\n Explanation: In this example, the occurrences of '?' can be replaced to make s equal to \"abac\".\n For \"abac\", cost(0) = 0, cost(1) = 0, cost(2) = 1, and cost(3) = 0.\n The value of \"abac\" is\u00a01.\n \"\"\"\n"}
{"task_id": "find-the-sum-of-the-power-of-all-subsequences", "prompt": "def sumOfPower(nums: List[int], k: int) -> int:\n \"\"\"\n You are given an integer array nums of length n and a positive integer k.\n The power of an array of integers is defined as the number of subsequences with their sum equal to k.\n Return the sum of power of all subsequences of nums.\n Since the answer may be very large, return it modulo 109 + 7.\n \n Example 1:\n \n >>> sumOfPower(nums = [1,2,3], k = 3)\n >>> 6\n Explanation:\n There are 5 subsequences of nums with non-zero power:\n \n The subsequence [1,2,3] has 2 subsequences with sum == 3: [1,2,3] and [1,2,3].\n The subsequence [1,2,3] has 1 subsequence with sum == 3: [1,2,3].\n The subsequence [1,2,3] has 1 subsequence with sum == 3: [1,2,3].\n The subsequence [1,2,3] has 1 subsequence with sum == 3: [1,2,3].\n The subsequence [1,2,3] has 1 subsequence with sum == 3: [1,2,3].\n \n Hence the answer is 2 + 1 + 1 + 1 + 1 = 6.\n \n Example 2:\n \n >>> sumOfPower(nums = [2,3,3], k = 5)\n >>> 4\n Explanation:\n There are 3 subsequences of nums with non-zero power:\n \n The subsequence [2,3,3] has 2 subsequences with sum == 5: [2,3,3] and [2,3,3].\n The subsequence [2,3,3] has 1 subsequence with sum == 5: [2,3,3].\n The subsequence [2,3,3] has 1 subsequence with sum == 5: [2,3,3].\n \n Hence the answer is 2 + 1 + 1 = 4.\n \n Example 3:\n \n >>> sumOfPower(nums = [1,2,3], k = 7)\n >>> 0\n Explanation:\u00a0There exists no subsequence with sum 7. Hence all subsequences of nums have power = 0.\n \"\"\"\n"}
{"task_id": "existence-of-a-substring-in-a-string-and-its-reverse", "prompt": "def isSubstringPresent(s: str) -> bool:\n \"\"\"\n Given a string s, find any substring of length 2 which is also present in the reverse of s.\n Return true if such a substring exists, and false otherwise.\n \n Example 1:\n \n >>> isSubstringPresent(s = \"leetcode\")\n >>> true\n Explanation: Substring \"ee\" is of length 2 which is also present in reverse(s) == \"edocteel\".\n \n Example 2:\n \n >>> isSubstringPresent(s = \"abcba\")\n >>> true\n Explanation: All of the substrings of length 2 \"ab\", \"bc\", \"cb\", \"ba\" are also present in reverse(s) == \"abcba\".\n \n Example 3:\n \n >>> isSubstringPresent(s = \"abcd\")\n >>> false\n Explanation: There is no substring of length 2 in s, which is also present in the reverse of s.\n \"\"\"\n"}
{"task_id": "count-substrings-starting-and-ending-with-given-character", "prompt": "def countSubstrings(s: str, c: str) -> int:\n \"\"\"\n You are given a string s and a character c. Return the total number of substrings of s that start and end with c.\n \n Example 1:\n \n >>> countSubstrings(s = \"abada\", c = \"a\")\n >>> 6\n Explanation: Substrings starting and ending with \"a\" are: \"abada\", \"abada\", \"abada\", \"abada\", \"abada\", \"abada\".\n \n Example 2:\n \n >>> countSubstrings(s = \"zzz\", c = \"z\")\n >>> 6\n Explanation: There are a total of 6 substrings in s and all start and end with \"z\".\n \"\"\"\n"}
{"task_id": "minimum-deletions-to-make-string-k-special", "prompt": "def minimumDeletions(word: str, k: int) -> int:\n \"\"\"\n You are given a string word and an integer k.\n We consider word to be k-special if |freq(word[i]) - freq(word[j])| <= k for all indices i and j in the string.\n Here, freq(x) denotes the frequency of the character x in word, and |y| denotes the absolute value of y.\n Return the minimum number of characters you need to delete to make word k-special.\n \n Example 1:\n \n >>> minimumDeletions(word = \"aabcaba\", k = 0)\n >>> 3\n Explanation: We can make word 0-special by deleting 2 occurrences of \"a\" and 1 occurrence of \"c\". Therefore, word becomes equal to \"baba\" where freq('a') == freq('b') == 2.\n \n Example 2:\n \n >>> minimumDeletions(word = \"dabdcbdcdcd\", k = 2)\n >>> 2\n Explanation: We can make word 2-special by deleting 1 occurrence of \"a\" and 1 occurrence of \"d\". Therefore, word becomes equal to \"bdcbdcdcd\" where freq('b') == 2, freq('c') == 3, and freq('d') == 4.\n \n Example 3:\n \n >>> minimumDeletions(word = \"aaabaaa\", k = 2)\n >>> 1\n Explanation: We can make word 2-special by deleting 1 occurrence of \"b\". Therefore, word becomes equal to \"aaaaaa\" where each letter's frequency is now uniformly 6.\n \"\"\"\n"}
{"task_id": "minimum-moves-to-pick-k-ones", "prompt": "def minimumMoves(nums: List[int], k: int, maxChanges: int) -> int:\n \"\"\"\n You are given a binary array nums of length n, a positive integer k and a non-negative integer maxChanges.\n Alice plays a game, where the goal is for Alice to pick up k ones from nums using the minimum number of moves. When the game starts, Alice picks up any index aliceIndex in the range [0, n - 1] and stands there. If nums[aliceIndex] == 1 , Alice picks up the one and nums[aliceIndex] becomes 0(this does not count as a move). After this, Alice can make any number of moves (including zero) where in each move Alice must perform exactly one of the following actions:\n \n Select any index j != aliceIndex such that nums[j] == 0 and set nums[j] = 1. This action can be performed at most maxChanges times.\n Select any two adjacent indices x and y (|x - y| == 1) such that nums[x] == 1, nums[y] == 0, then swap their values (set nums[y] = 1 and nums[x] = 0). If y == aliceIndex, Alice picks up the one after this move and nums[y] becomes 0.\n \n Return the minimum number of moves required by Alice to pick exactly k ones.\n \n Example 1:\n \n >>> minimumMoves(nums = [1,1,0,0,0,1,1,0,0,1], k = 3, maxChanges = 1)\n >>> 3\n Explanation: Alice can pick up 3 ones in 3 moves, if Alice performs the following actions in each move when standing at aliceIndex == 1:\n \n At the start of the game Alice picks up the one and nums[1] becomes 0. nums becomes [1,0,0,0,0,1,1,0,0,1].\n Select j == 2 and perform an action of the first type. nums becomes [1,0,1,0,0,1,1,0,0,1]\n Select x == 2 and y == 1, and perform an action of the second type. nums becomes [1,1,0,0,0,1,1,0,0,1]. As y == aliceIndex, Alice picks up the one and nums becomes [1,0,0,0,0,1,1,0,0,1].\n Select x == 0 and y == 1, and perform an action of the second type. nums becomes [0,1,0,0,0,1,1,0,0,1]. As y == aliceIndex, Alice picks up the one and nums becomes [0,0,0,0,0,1,1,0,0,1].\n \n Note that it may be possible for Alice to pick up 3 ones using some other sequence of 3 moves.\n \n Example 2:\n \n >>> minimumMoves(nums = [0,0,0,0], k = 2, maxChanges = 3)\n >>> 4\n Explanation: Alice can pick up 2 ones in 4 moves, if Alice performs the following actions in each move when standing at aliceIndex == 0:\n \n Select j == 1 and perform an action of the first type. nums becomes [0,1,0,0].\n Select x == 1 and y == 0, and perform an action of the second type. nums becomes [1,0,0,0]. As y == aliceIndex, Alice picks up the one and nums becomes [0,0,0,0].\n Select j == 1 again and perform an action of the first type. nums becomes [0,1,0,0].\n Select x == 1 and y == 0 again, and perform an action of the second type. nums becomes [1,0,0,0]. As y == aliceIndex, Alice picks up the one and nums becomes [0,0,0,0].\n \"\"\"\n"}
{"task_id": "make-string-anti-palindrome", "prompt": "def makeAntiPalindrome(s: str) -> str:\n \"\"\"\n We call a string s of even length n an anti-palindrome if for each index 0 <= i < n, s[i] != s[n - i - 1].\n Given a string s, your task is to make s an anti-palindrome by doing any number of operations (including zero).\n In one operation, you can select two characters from s and swap them.\n Return the resulting string. If multiple strings meet the conditions, return the lexicographically smallest one. If it can't be made into an anti-palindrome, return \"-1\".\n \n Example 1:\n \n >>> makeAntiPalindrome(s = \"abca\")\n >>> \"aabc\"\n Explanation:\n \"aabc\" is an anti-palindrome string since s[0] != s[3] and s[1] != s[2]. Also, it is a rearrangement of \"abca\".\n \n Example 2:\n \n >>> makeAntiPalindrome(s = \"abba\")\n >>> \"aabb\"\n Explanation:\n \"aabb\" is an anti-palindrome string since s[0] != s[3] and s[1] != s[2]. Also, it is a rearrangement of \"abba\".\n \n Example 3:\n \n >>> makeAntiPalindrome(s = \"cccd\")\n >>> \"-1\"\n Explanation:\n You can see that no matter how you rearrange the characters of \"cccd\", either s[0] == s[3] or s[1] == s[2]. So it can not form an anti-palindrome string.\n \"\"\"\n"}
{"task_id": "maximum-length-substring-with-two-occurrences", "prompt": "def maximumLengthSubstring(s: str) -> int:\n \"\"\"\n Given a string s, return the maximum length of a substring\u00a0such that it contains at most two occurrences of each character.\n \n Example 1:\n \n >>> maximumLengthSubstring(s = \"bcbbbcba\")\n >>> 4\n Explanation:\n The following substring has a length of 4 and contains at most two occurrences of each character: \"bcbbbcba\".\n Example 2:\n \n >>> maximumLengthSubstring(s = \"aaaa\")\n >>> 2\n Explanation:\n The following substring has a length of 2 and contains at most two occurrences of each character: \"aaaa\".\n \"\"\"\n"}
{"task_id": "apply-operations-to-make-sum-of-array-greater-than-or-equal-to-k", "prompt": "def minOperations(k: int) -> int:\n \"\"\"\n You are given a positive integer k. Initially, you have an array nums = [1].\n You can perform any of the following operations on the array any number of times (possibly zero):\n \n Choose any element in the array and increase its value by 1.\n Duplicate any element in the array and add it to the end of the array.\n \n Return the minimum number of operations required to make the sum of elements of the final array greater than or equal to k.\n \n Example 1:\n \n >>> minOperations(k = 11)\n >>> 5\n Explanation:\n We can do the following operations on the array nums = [1]:\n \n Increase the element by 1 three times. The resulting array is nums = [4].\n Duplicate the element two times. The resulting array is nums = [4,4,4].\n \n The sum of the final array is 4 + 4 + 4 = 12 which is greater than or equal to k = 11.\n The total number of operations performed is 3 + 2 = 5.\n \n Example 2:\n \n >>> minOperations(k = 1)\n >>> 0\n Explanation:\n The sum of the original array is already greater than or equal to 1, so no operations are needed.\n \"\"\"\n"}
{"task_id": "most-frequent-ids", "prompt": "def mostFrequentIDs(nums: List[int], freq: List[int]) -> List[int]:\n \"\"\"\n The problem involves tracking the frequency of IDs in a collection that changes over time. You have two integer arrays, nums and freq, of equal length n. Each element in nums represents an ID, and the corresponding element in freq indicates how many times that ID should be added to or removed from the collection at each step.\n \n Addition of IDs: If freq[i] is positive, it means freq[i] IDs with the value nums[i] are added to the collection at step i.\n Removal of IDs: If freq[i] is negative, it means -freq[i] IDs with the value nums[i] are removed from the collection at step i.\n \n Return an array ans of length n, where ans[i] represents the count of the most frequent ID in the collection after the ith\u00a0step. If the collection is empty at any step, ans[i] should be 0 for that step.\n \n Example 1:\n \n >>> mostFrequentIDs(nums = [2,3,2,1], freq = [3,2,-3,1])\n >>> [3,3,2,2]\n Explanation:\n After step 0, we have 3 IDs with the value of 2. So ans[0] = 3.\n After step 1, we have 3 IDs with the value of 2 and 2 IDs with the value of 3. So ans[1] = 3.\n After step 2, we have 2 IDs with the value of 3. So ans[2] = 2.\n After step 3, we have 2 IDs with the value of 3 and 1 ID with the value of 1. So ans[3] = 2.\n \n Example 2:\n \n >>> mostFrequentIDs(nums = [5,5,3], freq = [2,-2,1])\n >>> [2,0,1]\n Explanation:\n After step 0, we have 2 IDs with the value of 5. So ans[0] = 2.\n After step 1, there are no IDs. So ans[1] = 0.\n After step 2, we have 1 ID with the value of 3. So ans[2] = 1.\n \"\"\"\n"}
{"task_id": "longest-common-suffix-queries", "prompt": "def stringIndices(wordsContainer: List[str], wordsQuery: List[str]) -> List[int]:\n \"\"\"\n You are given two arrays of strings wordsContainer and wordsQuery.\n For each wordsQuery[i], you need to find a string from wordsContainer that has the longest common suffix with wordsQuery[i]. If there are two or more strings in wordsContainer that share the longest common suffix, find the string that is the smallest in length. If there are two or more such strings that have the same smallest length, find the one that occurred earlier in wordsContainer.\n Return an array of integers ans, where ans[i] is the index of the string in wordsContainer that has the longest common suffix with wordsQuery[i].\n \n Example 1:\n \n >>> stringIndices(wordsContainer = [\"abcd\",\"bcd\",\"xbcd\"], wordsQuery = [\"cd\",\"bcd\",\"xyz\"])\n >>> [1,1,1]\n Explanation:\n Let's look at each wordsQuery[i] separately:\n \n For wordsQuery[0] = \"cd\", strings from wordsContainer that share the longest common suffix \"cd\" are at indices 0, 1, and 2. Among these, the answer is the string at index 1 because it has the shortest length of 3.\n For wordsQuery[1] = \"bcd\", strings from wordsContainer that share the longest common suffix \"bcd\" are at indices 0, 1, and 2. Among these, the answer is the string at index 1 because it has the shortest length of 3.\n For wordsQuery[2] = \"xyz\", there is no string from wordsContainer that shares a common suffix. Hence the longest common suffix is \"\", that is shared with strings at index 0, 1, and 2. Among these, the answer is the string at index 1 because it has the shortest length of 3.\n \n \n Example 2:\n \n >>> stringIndices(wordsContainer = [\"abcdefgh\",\"poiuygh\",\"ghghgh\"], wordsQuery = [\"gh\",\"acbfgh\",\"acbfegh\"])\n >>> [2,0,2]\n Explanation:\n Let's look at each wordsQuery[i] separately:\n \n For wordsQuery[0] = \"gh\", strings from wordsContainer that share the longest common suffix \"gh\" are at indices 0, 1, and 2. Among these, the answer is the string at index 2 because it has the shortest length of 6.\n For wordsQuery[1] = \"acbfgh\", only the string at index 0 shares the longest common suffix \"fgh\". Hence it is the answer, even though the string at index 2 is shorter.\n For wordsQuery[2] = \"acbfegh\", strings from wordsContainer that share the longest common suffix \"gh\" are at indices 0, 1, and 2. Among these, the answer is the string at index 2 because it has the shortest length of 6.\n \"\"\"\n"}
{"task_id": "shortest-subarray-with-or-at-least-k-i", "prompt": "def minimumSubarrayLength(nums: List[int], k: int) -> int:\n \"\"\"\n You are given an array nums of non-negative integers and an integer k.\n An array is called special if the bitwise OR of all of its elements is at least k.\n Return the length of the shortest special non-empty subarray of nums, or return -1 if no special subarray exists.\n \n Example 1:\n \n >>> minimumSubarrayLength(nums = [1,2,3], k = 2)\n >>> 1\n Explanation:\n The subarray [3] has OR value of 3. Hence, we return 1.\n Note that [2] is also a special subarray.\n \n Example 2:\n \n >>> minimumSubarrayLength(nums = [2,1,8], k = 10)\n >>> 3\n Explanation:\n The subarray [2,1,8] has OR value of 11. Hence, we return 3.\n \n Example 3:\n \n >>> minimumSubarrayLength(nums = [1,2], k = 0)\n >>> 1\n Explanation:\n The subarray [1] has OR value of 1. Hence, we return 1.\n \"\"\"\n"}
{"task_id": "minimum-levels-to-gain-more-points", "prompt": "def minimumLevels(possible: List[int]) -> int:\n \"\"\"\n You are given a binary array possible of length n.\n Alice and Bob are playing a game that consists of n levels. Some of the levels in the game are impossible to clear while others can always be cleared. In particular, if possible[i] == 0, then the ith level is impossible to clear for both the players. A player gains 1 point on clearing a level and loses 1 point if the player fails to clear it.\n At the start of the game, Alice will play some levels in the given order starting from the 0th level, after which Bob will play for the rest of the levels.\n Alice wants to know the minimum number of levels she should play to gain more points than Bob, if both players play optimally to maximize their points.\n Return the minimum number of levels Alice should play to gain more points. If this is not possible, return -1.\n Note that each player must play at least 1 level.\n \n Example 1:\n \n >>> minimumLevels(possible = [1,0,1,0])\n >>> 1\n Explanation:\n Let's look at all the levels that Alice can play up to:\n \n If Alice plays only level 0 and Bob plays the rest of the levels, Alice has 1 point, while Bob has -1 + 1 - 1 = -1 point.\n If Alice plays till level 1 and Bob plays the rest of the levels, Alice has 1 - 1 = 0 points, while Bob has 1 - 1 = 0 points.\n If Alice plays till level 2 and Bob plays the rest of the levels, Alice has 1 - 1 + 1 = 1 point, while Bob has -1 point.\n \n Alice must play a minimum of 1 level to gain more points.\n \n Example 2:\n \n >>> minimumLevels(possible = [1,1,1,1,1])\n >>> 3\n Explanation:\n Let's look at all the levels that Alice can play up to:\n \n If Alice plays only level 0 and Bob plays the rest of the levels, Alice has 1 point, while Bob has 4 points.\n If Alice plays till level 1 and Bob plays the rest of the levels, Alice has 2 points, while Bob has 3 points.\n If Alice plays till level 2 and Bob plays the rest of the levels, Alice has 3 points, while Bob has 2 points.\n If Alice plays till level 3 and Bob plays the rest of the levels, Alice has 4 points, while Bob has 1 point.\n \n Alice must play a minimum of 3 levels to gain more points.\n \n Example 3:\n \n >>> minimumLevels(possible = [0,0])\n >>> -1\n Explanation:\n The only possible way is for both players to play 1 level each. Alice plays level 0 and loses 1 point. Bob plays level 1 and loses 1 point. As both players have equal points, Alice can't gain more points than Bob.\n \"\"\"\n"}
{"task_id": "shortest-subarray-with-or-at-least-k-ii", "prompt": "def minimumSubarrayLength(nums: List[int], k: int) -> int:\n \"\"\"\n You are given an array nums of non-negative integers and an integer k.\n An array is called special if the bitwise OR of all of its elements is at least k.\n Return the length of the shortest special non-empty subarray of nums, or return -1 if no special subarray exists.\n \n Example 1:\n \n >>> minimumSubarrayLength(nums = [1,2,3], k = 2)\n >>> 1\n Explanation:\n The subarray [3] has OR value of 3. Hence, we return 1.\n \n Example 2:\n \n >>> minimumSubarrayLength(nums = [2,1,8], k = 10)\n >>> 3\n Explanation:\n The subarray [2,1,8] has OR value of 11. Hence, we return 3.\n \n Example 3:\n \n >>> minimumSubarrayLength(nums = [1,2], k = 0)\n >>> 1\n Explanation:\n The subarray [1] has OR value of 1. Hence, we return 1.\n \"\"\"\n"}
{"task_id": "find-the-sum-of-subsequence-powers", "prompt": "def sumOfPowers(nums: List[int], k: int) -> int:\n \"\"\"\n You are given an integer array nums of length n, and a positive integer k.\n The power of a subsequence is defined as the minimum absolute difference between any two elements in the subsequence.\n Return the sum of powers of all subsequences of nums which have length equal to k.\n Since the answer may be large, return it modulo 109 + 7.\n \n Example 1:\n \n >>> sumOfPowers(nums = [1,2,3,4], k = 3)\n >>> 4\n Explanation:\n There are 4 subsequences in nums which have length 3: [1,2,3], [1,3,4], [1,2,4], and [2,3,4]. The sum of powers is |2 - 3| + |3 - 4| + |2 - 1| + |3 - 4| = 4.\n \n Example 2:\n \n >>> sumOfPowers(nums = [2,2], k = 2)\n >>> 0\n Explanation:\n The only subsequence in nums which has length 2 is\u00a0[2,2]. The sum of powers is |2 - 2| = 0.\n \n Example 3:\n \n >>> sumOfPowers(nums = [4,3,-1], k = 2)\n >>> 10\n Explanation:\n There are 3 subsequences in nums which have length 2: [4,3], [4,-1], and [3,-1]. The sum of powers is |4 - 3| + |4 - (-1)| + |3 - (-1)| = 10.\n \"\"\"\n"}
{"task_id": "harshad-number", "prompt": "def sumOfTheDigitsOfHarshadNumber(x: int) -> int:\n \"\"\"\n An integer divisible by the sum of its digits is said to be a Harshad number. You are given an integer x. Return the sum of the digits of x if x is a Harshad number, otherwise, return -1.\n \n Example 1:\n \n >>> sumOfTheDigitsOfHarshadNumber(x = 18)\n >>> 9\n Explanation:\n The sum of digits of x is 9. 18 is divisible by 9. So 18 is a Harshad number and the answer is 9.\n \n Example 2:\n \n >>> sumOfTheDigitsOfHarshadNumber(x = 23)\n >>> -1\n Explanation:\n The sum of digits of x is 5. 23 is not divisible by 5. So 23 is not a Harshad number and the answer is -1.\n \"\"\"\n"}
{"task_id": "water-bottles-ii", "prompt": "def maxBottlesDrunk(numBottles: int, numExchange: int) -> int:\n \"\"\"\n You are given two integers numBottles and numExchange.\n numBottles represents the number of full water bottles that you initially have. In one operation, you can perform one of the following operations:\n \n Drink any number of full water bottles turning them into empty bottles.\n Exchange numExchange empty bottles with one full water bottle. Then, increase numExchange by one.\n \n Note that you cannot exchange multiple batches of empty bottles for the same value of numExchange. For example, if numBottles == 3 and numExchange == 1, you cannot exchange 3 empty water bottles for 3 full bottles.\n Return the maximum number of water bottles you can drink.\n \n Example 1:\n \n \n >>> maxBottlesDrunk(numBottles = 13, numExchange = 6)\n >>> 15\n Explanation: The table above shows the number of full water bottles, empty water bottles, the value of numExchange, and the number of bottles drunk.\n \n Example 2:\n \n \n >>> maxBottlesDrunk(numBottles = 10, numExchange = 3)\n >>> 13\n Explanation: The table above shows the number of full water bottles, empty water bottles, the value of numExchange, and the number of bottles drunk.\n \"\"\"\n"}
{"task_id": "count-alternating-subarrays", "prompt": "def countAlternatingSubarrays(nums: List[int]) -> int:\n \"\"\"\n You are given a binary array nums.\n We call a subarray alternating if no two adjacent elements in the subarray have the same value.\n Return the number of alternating subarrays in nums.\n \n Example 1:\n \n >>> countAlternatingSubarrays(nums = [0,1,1,1])\n >>> 5\n Explanation:\n The following subarrays are alternating: [0], [1], [1], [1], and [0,1].\n \n Example 2:\n \n >>> countAlternatingSubarrays(nums = [1,0,1,0])\n >>> 10\n Explanation:\n Every subarray of the array is alternating. There are 10 possible subarrays that we can choose.\n \"\"\"\n"}
{"task_id": "minimize-manhattan-distances", "prompt": "def minimumDistance(points: List[List[int]]) -> int:\n \"\"\"\n You are given an array points representing integer coordinates of some points on a 2D plane, where points[i] = [xi, yi].\n The distance between two points is defined as their Manhattan distance.\n Return the minimum possible value for maximum distance between any two points by removing exactly one point.\n \n Example 1:\n \n >>> minimumDistance(points = [[3,10],[5,15],[10,2],[4,4]])\n >>> 12\n Explanation:\n The maximum distance after removing each point is the following:\n \n After removing the 0th point the maximum distance is between points (5, 15) and (10, 2), which is |5 - 10| + |15 - 2| = 18.\n After removing the 1st point the maximum distance is between points (3, 10) and (10, 2), which is |3 - 10| + |10 - 2| = 15.\n After removing the 2nd point the maximum distance is between points (5, 15) and (4, 4), which is |5 - 4| + |15 - 4| = 12.\n After removing the 3rd point the maximum distance is between points (5, 15) and (10, 2), which is |5 - 10| + |15 - 2| = 18.\n \n 12 is the minimum possible maximum distance between any two points after removing exactly one point.\n \n Example 2:\n \n >>> minimumDistance(points = [[1,1],[1,1],[1,1]])\n >>> 0\n Explanation:\n Removing any of the points results in the maximum distance between any two points of 0.\n \"\"\"\n"}
{"task_id": "find-longest-self-contained-substring", "prompt": "def maxSubstringLength(s: str) -> int:\n \"\"\"\n Given a string s, your task is to find the length of the longest self-contained substring of s.\n A substring t of a string s is called self-contained if t != s and for every character in t, it doesn't exist in the rest of s.\n Return the length of the longest self-contained substring of s if it exists, otherwise, return -1.\n \n Example 1:\n \n >>> maxSubstringLength(s = \"abba\")\n >>> 2\n Explanation:\n Let's check the substring \"bb\". You can see that no other \"b\" is outside of this substring. Hence the answer is 2.\n \n Example 2:\n \n >>> maxSubstringLength(s = \"abab\")\n >>> -1\n Explanation:\n Every substring we choose does not satisfy the described property (there is some character which is inside and outside of that substring). So the answer would be -1.\n \n Example 3:\n \n >>> maxSubstringLength(s = \"abacd\")\n >>> 4\n Explanation:\n Let's check the substring \"abac\". There is only one character outside of this substring and that is \"d\". There is no \"d\" inside the chosen substring, so it satisfies the condition and the answer is 4.\n \"\"\"\n"}
{"task_id": "longest-strictly-increasing-or-strictly-decreasing-subarray", "prompt": "def longestMonotonicSubarray(nums: List[int]) -> int:\n \"\"\"\n You are given an array of integers nums. Return the length of the longest subarray of nums which is either strictly increasing or strictly decreasing.\n \n Example 1:\n \n >>> longestMonotonicSubarray(nums = [1,4,3,3,2])\n >>> 2\n Explanation:\n The strictly increasing subarrays of nums are [1], [2], [3], [3], [4], and [1,4].\n The strictly decreasing subarrays of nums are [1], [2], [3], [3], [4], [3,2], and [4,3].\n Hence, we return 2.\n \n Example 2:\n \n >>> longestMonotonicSubarray(nums = [3,3,3,3])\n >>> 1\n Explanation:\n The strictly increasing subarrays of nums are [3], [3], [3], and [3].\n The strictly decreasing subarrays of nums are [3], [3], [3], and [3].\n Hence, we return 1.\n \n Example 3:\n \n >>> longestMonotonicSubarray(nums = [3,2,1])\n >>> 3\n Explanation:\n The strictly increasing subarrays of nums are [3], [2], and [1].\n The strictly decreasing subarrays of nums are [3], [2], [1], [3,2], [2,1], and [3,2,1].\n Hence, we return 3.\n \"\"\"\n"}
{"task_id": "lexicographically-smallest-string-after-operations-with-constraint", "prompt": "def getSmallestString(s: str, k: int) -> str:\n \"\"\"\n You are given a string s and an integer k.\n Define a function distance(s1, s2) between two strings s1 and s2 of the same length n as:\n \n The sum of the minimum distance between s1[i] and s2[i] when the characters from 'a' to 'z' are placed in a cyclic order, for all i in the range [0, n - 1].\n \n For example, distance(\"ab\", \"cd\") == 4, and distance(\"a\", \"z\") == 1.\n You can change any letter of s to any other lowercase English letter, any number of times.\n Return a string denoting the lexicographically smallest string t you can get after some changes, such that distance(s, t) <= k.\n \n Example 1:\n \n >>> getSmallestString(s = \"zbbz\", k = 3)\n >>> \"aaaz\"\n Explanation:\n Change s to \"aaaz\". The distance between \"zbbz\" and \"aaaz\" is equal to k = 3.\n \n Example 2:\n \n >>> getSmallestString(s = \"xaxcd\", k = 4)\n >>> \"aawcd\"\n Explanation:\n The distance between \"xaxcd\" and \"aawcd\" is equal to k = 4.\n \n Example 3:\n \n >>> getSmallestString(s = \"lol\", k = 0)\n >>> \"lol\"\n Explanation:\n It's impossible to change any character as k = 0.\n \"\"\"\n"}
{"task_id": "minimum-operations-to-make-median-of-array-equal-to-k", "prompt": "def minOperationsToMakeMedianK(nums: List[int], k: int) -> int:\n \"\"\"\n You are given an integer array nums and a non-negative integer k. In one operation, you can increase or decrease any element by 1.\n Return the minimum number of operations needed to make the median of nums equal to k.\n The median of an array is defined as the middle element of the array when it is sorted in non-decreasing order. If there are two choices for a median, the larger of the two values is taken.\n \n Example 1:\n \n >>> minOperationsToMakeMedianK(nums = [2,5,6,8,5], k = 4)\n >>> 2\n Explanation:\n We can subtract one from nums[1] and nums[4] to obtain [2, 4, 6, 8, 4]. The median of the resulting array is equal to k.\n \n Example 2:\n \n >>> minOperationsToMakeMedianK(nums = [2,5,6,8,5], k = 7)\n >>> 3\n Explanation:\n We can add one to nums[1] twice and add one to nums[2] once to obtain [2, 7, 7, 8, 5].\n \n Example 3:\n \n >>> minOperationsToMakeMedianK(nums = [1,2,3,4,5,6], k = 4)\n >>> 0\n Explanation:\n The median of the array is already equal to k.\n \"\"\"\n"}
{"task_id": "minimum-cost-walk-in-weighted-graph", "prompt": "def minimumCost(n: int, edges: List[List[int]], query: List[List[int]]) -> List[int]:\n \"\"\"\n There is an undirected weighted graph with n vertices labeled from 0 to n - 1.\n You are given the integer n and an array edges, where edges[i] = [ui, vi, wi] indicates that there is an edge between vertices ui and vi with a weight of wi.\n A walk on a graph is a sequence of vertices and edges. The walk starts and ends with a vertex, and each edge connects the vertex that comes before it and the vertex that comes after it. It's important to note that a walk may visit the same edge or vertex more than once.\n The cost of a walk starting at node u and ending at node v is defined as the bitwise AND of the weights of the edges traversed during the walk. In other words, if the sequence of edge weights encountered during the walk is w0, w1, w2, ..., wk, then the cost is calculated as w0 & w1 & w2 & ... & wk, where & denotes the bitwise AND operator.\n You are also given a 2D array query, where query[i] = [si, ti]. For each query, you need to find the minimum cost of the walk starting at vertex si and ending at vertex ti. If there exists no such walk, the answer is -1.\n Return the array answer, where answer[i] denotes the minimum cost of a walk for query i.\n \n Example 1:\n \n >>> minimumCost(n = 5, edges = [[0,1,7],[1,3,7],[1,2,1]], query = [[0,3],[3,4]])\n >>> [1,-1]\n Explanation:\n \n To achieve the cost of 1 in the first query, we need to move on the following edges: 0->1 (weight 7), 1->2 (weight 1), 2->1 (weight 1), 1->3 (weight 7).\n In the second query, there is no walk between nodes 3 and 4, so the answer is -1.\n Example 2:\n \n \n >>> minimumCost(n = 3, edges = [[0,2,7],[0,1,15],[1,2,6],[1,2,1]], query = [[1,2]])\n >>> [0]\n Explanation:\n \n To achieve the cost of 0 in the first query, we need to move on the following edges: 1->2 (weight 1), 2->1 (weight 6), 1->2 (weight 1).\n \"\"\"\n"}
{"task_id": "find-the-index-of-permutation", "prompt": "def getPermutationIndex(perm: List[int]) -> int:\n \"\"\"\n Given an array perm of length n which is a permutation of [1, 2, ..., n], return the index of perm in the lexicographically sorted array of all of the permutations of [1, 2, ..., n].\n Since the answer may be very large, return it modulo 109\u00a0+ 7.\n \n Example 1:\n \n >>> getPermutationIndex(perm = [1,2])\n >>> 0\n Explanation:\n There are only two permutations in the following order:\n [1,2], [2,1]\n \n And [1,2] is at index 0.\n \n Example 2:\n \n >>> getPermutationIndex(perm = [3,1,2])\n >>> 4\n Explanation:\n There are only six permutations in the following order:\n [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], [3,2,1]\n \n And [3,1,2] is at index 4.\n \"\"\"\n"}
{"task_id": "score-of-a-string", "prompt": "def scoreOfString(s: str) -> int:\n \"\"\"\n You are given a string s. The score of a string is defined as the sum of the absolute difference between the ASCII values of adjacent characters.\n Return the score of s.\n \n Example 1:\n \n >>> scoreOfString(s = \"hello\")\n >>> 13\n Explanation:\n The ASCII values of the characters in s are: 'h' = 104, 'e' = 101, 'l' = 108, 'o' = 111. So, the score of s would be |104 - 101| + |101 - 108| + |108 - 108| + |108 - 111| = 3 + 7 + 0 + 3 = 13.\n \n Example 2:\n \n >>> scoreOfString(s = \"zaz\")\n >>> 50\n Explanation:\n The ASCII values of the characters in s are: 'z' = 122, 'a' = 97. So, the score of s would be |122 - 97| + |97 - 122| = 25 + 25 = 50.\n \"\"\"\n"}
{"task_id": "minimum-rectangles-to-cover-points", "prompt": "def minRectanglesToCoverPoints(points: List[List[int]], w: int) -> int:\n \"\"\"\n You are given a 2D integer array points, where points[i] = [xi, yi]. You are also given an integer w. Your task is to cover all the given points with rectangles.\n Each rectangle has its lower end at some point (x1, 0) and its upper end at some point (x2, y2), where x1 <= x2, y2 >= 0, and the condition x2 - x1 <= w must be satisfied for each rectangle.\n A point is considered covered by a rectangle if it lies within or on the boundary of the rectangle.\n Return an integer denoting the minimum number of rectangles needed so that each point is covered by at least one rectangle.\n Note: A point may be covered by more than one rectangle.\n \n Example 1:\n \n \n >>> minRectanglesToCoverPoints(points = [[2,1],[1,0],[1,4],[1,8],[3,5],[4,6]], w = 1)\n >>> 2\n Explanation:\n The image above shows one possible placement of rectangles to cover the points:\n \n A rectangle with a lower end at (1, 0) and its upper end at (2, 8)\n A rectangle with a lower end at (3, 0) and its upper end at (4, 8)\n \n \n Example 2:\n \n \n >>> minRectanglesToCoverPoints(points = [[0,0],[1,1],[2,2],[3,3],[4,4],[5,5],[6,6]], w = 2)\n >>> 3\n Explanation:\n The image above shows one possible placement of rectangles to cover the points:\n \n A rectangle with a lower end at (0, 0) and its upper end at (2, 2)\n A rectangle with a lower end at (3, 0) and its upper end at (5, 5)\n A rectangle with a lower end at (6, 0) and its upper end at (6, 6)\n \n \n Example 3:\n \n \n >>> minRectanglesToCoverPoints(points = [[2,3],[1,2]], w = 0)\n >>> 2\n Explanation:\n The image above shows one possible placement of rectangles to cover the points:\n \n A rectangle with a lower end at (1, 0) and its upper end at (1, 2)\n A rectangle with a lower end at (2, 0) and its upper end at (2, 3)\n \"\"\"\n"}
{"task_id": "minimum-time-to-visit-disappearing-nodes", "prompt": "def minimumTime(n: int, edges: List[List[int]], disappear: List[int]) -> List[int]:\n \"\"\"\n There is an undirected graph of n nodes. You are given a 2D array edges, where edges[i] = [ui, vi, lengthi] describes an edge between node ui and node vi with a traversal time of lengthi units.\n Additionally, you are given an array disappear, where disappear[i] denotes the time when the node i disappears from the graph and you won't be able to visit it.\n Note\u00a0that the graph might be disconnected and might contain multiple edges.\n Return the array answer, with answer[i] denoting the minimum units of time required to reach node i from node 0. If node i is unreachable from node 0 then answer[i] is -1.\n \n Example 1:\n \n >>> minimumTime(n = 3, edges = [[0,1,2],[1,2,1],[0,2,4]], disappear = [1,1,5])\n >>> [0,-1,4]\n Explanation:\n \n We are starting our journey from node 0, and our goal is to find the minimum time required to reach each node before it disappears.\n \n For node 0, we don't need any time as it is our starting point.\n For node 1, we need at least 2 units of time to traverse edges[0]. Unfortunately, it disappears at that moment, so we won't be able to visit it.\n For node 2, we need at least 4 units of time to traverse edges[2].\n \n \n Example 2:\n \n >>> minimumTime(n = 3, edges = [[0,1,2],[1,2,1],[0,2,4]], disappear = [1,3,5])\n >>> [0,2,3]\n Explanation:\n \n We are starting our journey from node 0, and our goal is to find the minimum time required to reach each node before it disappears.\n \n For node 0, we don't need any time as it is the starting point.\n For node 1, we need at least 2 units of time to traverse edges[0].\n For node 2, we need at least 3 units of time to traverse edges[0] and edges[1].\n \n \n Example 3:\n \n >>> minimumTime(n = 2, edges = [[0,1,1]], disappear = [1,1])\n >>> [0,-1]\n Explanation:\n Exactly when we reach node 1, it disappears.\n \"\"\"\n"}
{"task_id": "find-the-number-of-subarrays-where-boundary-elements-are-maximum", "prompt": "def numberOfSubarrays(nums: List[int]) -> int:\n \"\"\"\n You are given an array of positive integers nums.\n Return the number of subarrays of nums, where the first and the last elements of the subarray are equal to the largest element in the subarray.\n \n Example 1:\n \n >>> numberOfSubarrays(nums = [1,4,3,3,2])\n >>> 6\n Explanation:\n There are 6 subarrays which have the first and the last elements equal to the largest element of the subarray:\n \n subarray [1,4,3,3,2], with its largest element 1. The first element is 1 and the last element is also 1.\n subarray [1,4,3,3,2], with its largest element 4. The first element is 4 and the last element is also 4.\n subarray [1,4,3,3,2], with its largest element 3. The first element is 3 and the last element is also 3.\n subarray [1,4,3,3,2], with its largest element 3. The first element is 3 and the last element is also 3.\n subarray [1,4,3,3,2], with its largest element 2. The first element is 2 and the last element is also 2.\n subarray [1,4,3,3,2], with its largest element 3. The first element is 3 and the last element is also 3.\n \n Hence, we return 6.\n \n Example 2:\n \n >>> numberOfSubarrays(nums = [3,3,3])\n >>> 6\n Explanation:\n There are 6 subarrays which have the first and the last elements equal to the largest element of the subarray:\n \n subarray [3,3,3], with its largest element 3. The first element is 3 and the last element is also 3.\n subarray [3,3,3], with its largest element 3. The first element is 3 and the last element is also 3.\n subarray [3,3,3], with its largest element 3. The first element is 3 and the last element is also 3.\n subarray [3,3,3], with its largest element 3. The first element is 3 and the last element is also 3.\n subarray [3,3,3], with its largest element 3. The first element is 3 and the last element is also 3.\n subarray [3,3,3], with its largest element 3. The first element is 3 and the last element is also 3.\n \n Hence, we return 6.\n \n Example 3:\n \n >>> numberOfSubarrays(nums = [1])\n >>> 1\n Explanation:\n There is a single subarray of nums which is [1], with its largest element 1. The first element is 1 and the last element is also 1.\n Hence, we return 1.\n \"\"\"\n"}
{"task_id": "latest-time-you-can-obtain-after-replacing-characters", "prompt": "def findLatestTime(s: str) -> str:\n \"\"\"\n You are given a string s representing a 12-hour format time where some of the digits (possibly none) are replaced with a \"?\".\n 12-hour times are formatted as \"HH:MM\", where HH is between 00 and 11, and MM is between 00 and 59. The earliest 12-hour time is 00:00, and the latest is 11:59.\n You have to replace all the \"?\" characters in s with digits such that the time we obtain by the resulting string is a valid 12-hour format time and is the latest possible.\n Return the resulting string.\n \n Example 1:\n \n >>> findLatestTime(s = \"1?:?4\")\n >>> \"11:54\"\n Explanation: The latest 12-hour format time we can achieve by replacing \"?\" characters is \"11:54\".\n \n Example 2:\n \n >>> findLatestTime(s = \"0?:5?\")\n >>> \"09:59\"\n Explanation: The latest 12-hour format time we can achieve by replacing \"?\" characters is \"09:59\".\n \"\"\"\n"}
{"task_id": "maximum-prime-difference", "prompt": "def maximumPrimeDifference(nums: List[int]) -> int:\n \"\"\"\n You are given an integer array nums.\n Return an integer that is the maximum distance between the indices of two (not necessarily different) prime numbers in nums.\n \n Example 1:\n \n >>> maximumPrimeDifference(nums = [4,2,9,5,3])\n >>> 3\n Explanation: nums[1], nums[3], and nums[4] are prime. So the answer is |4 - 1| = 3.\n \n Example 2:\n \n >>> maximumPrimeDifference(nums = [4,8,2,8])\n >>> 0\n Explanation: nums[2] is prime. Because there is just one prime number, the answer is |2 - 2| = 0.\n \"\"\"\n"}
{"task_id": "kth-smallest-amount-with-single-denomination-combination", "prompt": "def findKthSmallest(coins: List[int], k: int) -> int:\n \"\"\"\n You are given an integer array coins representing coins of different denominations and an integer k.\n You have an infinite number of coins of each denomination. However, you are not allowed to combine coins of different denominations.\n Return the kth smallest amount that can be made using these coins.\n \n Example 1:\n \n >>> findKthSmallest(coins = [3,6,9], k = 3)\n >>> 9\n Explanation: The given coins can make the following amounts:\n Coin 3 produces multiples of 3: 3, 6, 9, 12, 15, etc.\n Coin 6 produces multiples of 6: 6, 12, 18, 24, etc.\n Coin 9 produces multiples of 9: 9, 18, 27, 36, etc.\n All of the coins combined produce: 3, 6, 9, 12, 15, etc.\n \n Example 2:\n \n >>> findKthSmallest(coins = [5,2], k = 7)\n >>> 12\n Explanation: The given coins can make the following amounts:\n Coin 5 produces multiples of 5: 5, 10, 15, 20, etc.\n Coin 2 produces multiples of 2: 2, 4, 6, 8, 10, 12, etc.\n All of the coins combined produce: 2, 4, 5, 6, 8, 10, 12, 14, 15, etc.\n \"\"\"\n"}
{"task_id": "minimum-sum-of-values-by-dividing-array", "prompt": "def minimumValueSum(nums: List[int], andValues: List[int]) -> int:\n \"\"\"\n You are given two arrays nums and andValues of length n and m respectively.\n The value of an array is equal to the last element of that array.\n You have to divide nums into m disjoint contiguous subarrays such that for the ith subarray [li, ri], the bitwise AND of the subarray elements is equal to andValues[i], in other words, nums[li] & nums[li + 1] & ... & nums[ri] == andValues[i] for all 1 <= i <= m, where & represents the bitwise AND operator.\n Return the minimum possible sum of the values of the m subarrays nums is divided into. If it is not possible to divide nums into m subarrays satisfying these conditions, return -1.\n \n Example 1:\n \n >>> minimumValueSum(nums = [1,4,3,3,2], andValues = [0,3,3,2])\n >>> 12\n Explanation:\n The only possible way to divide nums is:\n \n [1,4] as 1 & 4 == 0.\n [3] as the bitwise AND of a single element subarray is that element itself.\n [3] as the bitwise AND of a single element subarray is that element itself.\n [2] as the bitwise AND of a single element subarray is that element itself.\n \n The sum of the values for these subarrays is 4 + 3 + 3 + 2 = 12.\n \n Example 2:\n \n >>> minimumValueSum(nums = [2,3,5,7,7,7,5], andValues = [0,7,5])\n >>> 17\n Explanation:\n There are three ways to divide nums:\n \n [[2,3,5],[7,7,7],[5]] with the sum of the values 5 + 7 + 5 == 17.\n [[2,3,5,7],[7,7],[5]] with the sum of the values 7 + 7 + 5 == 19.\n [[2,3,5,7,7],[7],[5]] with the sum of the values 7 + 7 + 5 == 19.\n \n The minimum possible sum of the values is 17.\n \n Example 3:\n \n >>> minimumValueSum(nums = [1,2,3,4], andValues = [2])\n >>> -1\n Explanation:\n The bitwise AND of the entire array nums is 0. As there is no possible way to divide nums into a single subarray to have the bitwise AND of elements 2, return -1.\n \"\"\"\n"}
{"task_id": "maximum-number-of-potholes-that-can-be-fixed", "prompt": "def maxPotholes(road: str, budget: int) -> int:\n \"\"\"\n You are given a string road, consisting only of characters \"x\" and \".\", where each \"x\" denotes a pothole and each \".\" denotes a smooth road, and an integer budget.\n In one repair operation, you can repair n consecutive potholes for a price of n + 1.\n Return the maximum number of potholes that can be fixed such that the sum of the prices of all of the fixes doesn't go over the given budget.\n \n Example 1:\n \n >>> maxPotholes(road = \"..\", budget = 5)\n >>> 0\n Explanation:\n There are no potholes to be fixed.\n \n Example 2:\n \n >>> maxPotholes(road = \"..xxxxx\", budget = 4)\n >>> 3\n Explanation:\n We fix the first three potholes (they are consecutive). The budget needed for this task is 3 + 1 = 4.\n \n Example 3:\n \n >>> maxPotholes(road = \"x.x.xxx...x\", budget = 14)\n >>> 6\n Explanation:\n We can fix all the potholes. The total cost would be (1 + 1) + (1 + 1) + (3 + 1) + (1 + 1) = 10 which is within our budget of 14.\n \"\"\"\n"}
{"task_id": "count-the-number-of-special-characters-i", "prompt": "def numberOfSpecialChars(word: str) -> int:\n \"\"\"\n You are given a string word. A letter is called special if it appears both in lowercase and uppercase in word.\n Return the number of special letters in word.\n \n Example 1:\n \n >>> numberOfSpecialChars(word = \"aaAbcBC\")\n >>> 3\n Explanation:\n The special characters in word are 'a', 'b', and 'c'.\n \n Example 2:\n \n >>> numberOfSpecialChars(word = \"abc\")\n >>> 0\n Explanation:\n No character in word appears in uppercase.\n \n Example 3:\n \n >>> numberOfSpecialChars(word = \"abBCab\")\n >>> 1\n Explanation:\n The only special character in word is 'b'.\n \"\"\"\n"}
{"task_id": "count-the-number-of-special-characters-ii", "prompt": "def numberOfSpecialChars(word: str) -> int:\n \"\"\"\n You are given a string word. A letter\u00a0c is called special if it appears both in lowercase and uppercase in word, and every lowercase occurrence of c appears before the first uppercase occurrence of c.\n Return the number of special letters in word.\n \n Example 1:\n \n >>> numberOfSpecialChars(word = \"aaAbcBC\")\n >>> 3\n Explanation:\n The special characters are 'a', 'b', and 'c'.\n \n Example 2:\n \n >>> numberOfSpecialChars(word = \"abc\")\n >>> 0\n Explanation:\n There are no special characters in word.\n \n Example 3:\n \n >>> numberOfSpecialChars(word = \"AbBCab\")\n >>> 0\n Explanation:\n There are no special characters in word.\n \"\"\"\n"}
{"task_id": "minimum-number-of-operations-to-satisfy-conditions", "prompt": "def minimumOperations(grid: List[List[int]]) -> int:\n \"\"\"\n You are given a 2D matrix grid of size m x n. In one operation, you can change the value of any cell to any non-negative number. You need to perform some operations such that each cell grid[i][j] is:\n \n Equal to the cell below it, i.e. grid[i][j] == grid[i + 1][j] (if it exists).\n Different from the cell to its right, i.e. grid[i][j] != grid[i][j + 1] (if it exists).\n \n Return the minimum number of operations needed.\n \n Example 1:\n \n >>> minimumOperations(grid = [[1,0,2],[1,0,2]])\n >>> 0\n Explanation:\n \n All the cells in the matrix already satisfy the properties.\n \n Example 2:\n \n >>> minimumOperations(grid = [[1,1,1],[0,0,0]])\n >>> 3\n Explanation:\n \n The matrix becomes [[1,0,1],[1,0,1]] which satisfies the properties, by doing these 3 operations:\n \n Change grid[1][0] to 1.\n Change grid[0][1] to 0.\n Change grid[1][2] to 1.\n \n \n Example 3:\n \n >>> minimumOperations(grid = [[1],[2],[3]])\n >>> 2\n Explanation:\n \n There is a single column. We can change the value to 1 in each cell using 2 operations.\n \"\"\"\n"}
{"task_id": "find-edges-in-shortest-paths", "prompt": "def findAnswer(n: int, edges: List[List[int]]) -> List[bool]:\n \"\"\"\n You are given an undirected weighted graph of n nodes numbered from 0 to n - 1. The graph consists of m edges represented by a 2D array edges, where edges[i] = [ai, bi, wi] indicates that there is an edge between nodes ai and bi with weight wi.\n Consider all the shortest paths from node 0 to node n - 1 in the graph. You need to find a boolean array answer where answer[i] is true if the edge edges[i] is part of at least one shortest path. Otherwise, answer[i] is false.\n Return the array answer.\n Note that the graph may not be connected.\n \n Example 1:\n \n \n >>> findAnswer(n = 6, edges = [[0,1,4],[0,2,1],[1,3,2],[1,4,3],[1,5,1],[2,3,1],[3,5,3],[4,5,2]])\n >>> [true,true,true,false,true,true,true,false]\n Explanation:\n The following are all the shortest paths between nodes 0 and 5:\n \n The path 0 -> 1 -> 5: The sum of weights is 4 + 1 = 5.\n The path 0 -> 2 -> 3 -> 5: The sum of weights is 1 + 1 + 3 = 5.\n The path 0 -> 2 -> 3 -> 1 -> 5: The sum of weights is 1 + 1 + 2 + 1 = 5.\n \n \n Example 2:\n \n \n >>> findAnswer(n = 4, edges = [[2,0,1],[0,1,1],[0,3,4],[3,2,2]])\n >>> [true,false,false,true]\n Explanation:\n There is one shortest path between nodes 0 and 3, which is the path 0 -> 2 -> 3 with the sum of weights 1 + 2 = 3.\n \"\"\"\n"}
{"task_id": "maximum-number-that-makes-result-of-bitwise-and-zero", "prompt": "def maxNumber(n: int) -> int:\n \"\"\"\n Given an integer n, return the maximum integer x such that x <= n, and the bitwise AND of all the numbers in the range [x, n] is 0.\n \n Example 1:\n \n >>> maxNumber(n = 7)\n >>> 3\n Explanation:\n The bitwise AND of [6, 7] is 6.\n The bitwise AND of [5, 6, 7] is 4.\n The bitwise AND of [4, 5, 6, 7] is 4.\n The bitwise AND of [3, 4, 5, 6, 7] is 0.\n \n Example 2:\n \n >>> maxNumber(n = 9)\n >>> 7\n Explanation:\n The bitwise AND of [7, 8, 9] is 0.\n \n Example 3:\n \n >>> maxNumber(n = 17)\n >>> 15\n Explanation:\n The bitwise AND of [15, 16, 17] is 0.\n \"\"\"\n"}
{"task_id": "make-a-square-with-the-same-color", "prompt": "def canMakeSquare(grid: List[List[str]]) -> bool:\n \"\"\"\n You are given a 2D matrix grid of size 3 x 3 consisting only of characters 'B' and 'W'. Character 'W' represents the white color, and character 'B' represents the black color.\n Your task is to change the color of at most one cell so that the matrix has a 2 x 2 square where all cells are of the same color.\n Return true if it is possible to create a 2 x 2 square of the same color, otherwise, return false.\n \n \n \n Example 1:\n \n \n \n \n \n \n \n \n \n \n \n \n >>> canMakeSquare(grid = [[\"B\",\"W\",\"B\"],[\"B\",\"W\",\"W\"],[\"B\",\"W\",\"B\"]])\n >>> true\n Explanation:\n It can be done by changing the color of the grid[0][2].\n \n Example 2:\n \n \n \n \n \n \n \n \n \n \n \n \n >>> canMakeSquare(grid = [[\"B\",\"W\",\"B\"],[\"W\",\"B\",\"W\"],[\"B\",\"W\",\"B\"]])\n >>> false\n Explanation:\n It cannot be done by changing at most one cell.\n \n Example 3:\n \n \n \n \n \n \n \n \n \n \n \n \n >>> canMakeSquare(grid = [[\"B\",\"W\",\"B\"],[\"B\",\"W\",\"W\"],[\"B\",\"W\",\"W\"]])\n >>> true\n Explanation:\n The grid already contains a 2 x 2 square of the same color.\n \"\"\"\n"}
{"task_id": "right-triangles", "prompt": "def numberOfRightTriangles(grid: List[List[int]]) -> int:\n \"\"\"\n You are given a 2D boolean matrix grid.\n A collection of 3 elements of grid is a right triangle if one of its elements is in the same row with another element and in the same column with the third element. The 3 elements may not be next to each other.\n Return an integer that is the number of right triangles that can be made with 3 elements of grid such that all of them have a value of 1.\n \n Example 1:\n \n \n \n \n 0\n 1\n 0\n \n \n 0\n 1\n 1\n \n \n 0\n 1\n 0\n \n \n \n \n \n \n 0\n 1\n 0\n \n \n 0\n 1\n 1\n \n \n 0\n 1\n 0\n \n \n \n \n \n \n 0\n 1\n 0\n \n \n 0\n 1\n 1\n \n \n 0\n 1\n 0\n \n \n \n \n \n >>> numberOfRightTriangles(grid = [[0,1,0],[0,1,1],[0,1,0]])\n >>> 2\n Explanation:\n There are two right triangles with elements of the value 1. Notice that the blue ones do not\u00a0form a right triangle because the 3 elements are in the same column.\n \n Example 2:\n \n \n \n \n 1\n 0\n 0\n 0\n \n \n 0\n 1\n 0\n 1\n \n \n 1\n 0\n 0\n 0\n \n \n \n \n \n >>> numberOfRightTriangles(grid = [[1,0,0,0],[0,1,0,1],[1,0,0,0]])\n >>> 0\n Explanation:\n There are no right triangles with elements of the value 1. \u00a0Notice that the blue ones do not form a right triangle.\n \n Example 3:\n \n \n \n \n 1\n 0\n 1\n \n \n 1\n 0\n 0\n \n \n 1\n 0\n 0\n \n \n \n \n \n \n 1\n 0\n 1\n \n \n 1\n 0\n 0\n \n \n 1\n 0\n 0\n \n \n \n \n \n >>> numberOfRightTriangles(grid = [[1,0,1],[1,0,0],[1,0,0]])\n >>> 2\n Explanation:\n There are two right triangles with elements of the value 1.\n \"\"\"\n"}
{"task_id": "find-all-possible-stable-binary-arrays-i", "prompt": "def numberOfStableArrays(zero: int, one: int, limit: int) -> int:\n \"\"\"\n You are given 3 positive integers zero, one, and limit.\n A binary array arr is called stable if:\n \n The number of occurrences of 0 in arr is exactly zero.\n The number of occurrences of 1 in arr is exactly one.\n Each subarray of arr with a size greater than limit must contain both 0 and 1.\n \n Return the total number of stable binary arrays.\n Since the answer may be very large, return it modulo 109 + 7.\n \n Example 1:\n \n >>> numberOfStableArrays(zero = 1, one = 1, limit = 2)\n >>> 2\n Explanation:\n The two possible stable binary arrays are [1,0] and [0,1], as both arrays have a single 0 and a single 1, and no subarray has a length greater than 2.\n \n Example 2:\n \n >>> numberOfStableArrays(zero = 1, one = 2, limit = 1)\n >>> 1\n Explanation:\n The only possible stable binary array is [1,0,1].\n Note that the binary arrays [1,1,0] and [0,1,1] have subarrays of length 2 with identical elements, hence, they are not stable.\n \n Example 3:\n \n >>> numberOfStableArrays(zero = 3, one = 3, limit = 2)\n >>> 14\n Explanation:\n All the possible stable binary arrays are [0,0,1,0,1,1], [0,0,1,1,0,1], [0,1,0,0,1,1], [0,1,0,1,0,1], [0,1,0,1,1,0], [0,1,1,0,0,1], [0,1,1,0,1,0], [1,0,0,1,0,1], [1,0,0,1,1,0], [1,0,1,0,0,1], [1,0,1,0,1,0], [1,0,1,1,0,0], [1,1,0,0,1,0], and [1,1,0,1,0,0].\n \"\"\"\n"}
{"task_id": "find-all-possible-stable-binary-arrays-ii", "prompt": "def numberOfStableArrays(zero: int, one: int, limit: int) -> int:\n \"\"\"\n You are given 3 positive integers zero, one, and limit.\n A binary array arr is called stable if:\n \n The number of occurrences of 0 in arr is exactly zero.\n The number of occurrences of 1 in arr is exactly one.\n Each subarray of arr with a size greater than limit must contain both 0 and 1.\n \n Return the total number of stable binary arrays.\n Since the answer may be very large, return it modulo 109 + 7.\n \n Example 1:\n \n >>> numberOfStableArrays(zero = 1, one = 1, limit = 2)\n >>> 2\n Explanation:\n The two possible stable binary arrays are [1,0] and [0,1].\n \n Example 2:\n \n >>> numberOfStableArrays(zero = 1, one = 2, limit = 1)\n >>> 1\n Explanation:\n The only possible stable binary array is [1,0,1].\n \n Example 3:\n \n >>> numberOfStableArrays(zero = 3, one = 3, limit = 2)\n >>> 14\n Explanation:\n All the possible stable binary arrays are [0,0,1,0,1,1], [0,0,1,1,0,1], [0,1,0,0,1,1], [0,1,0,1,0,1], [0,1,0,1,1,0], [0,1,1,0,0,1], [0,1,1,0,1,0], [1,0,0,1,0,1], [1,0,0,1,1,0], [1,0,1,0,0,1], [1,0,1,0,1,0], [1,0,1,1,0,0], [1,1,0,0,1,0], and [1,1,0,1,0,0].\n \"\"\"\n"}
{"task_id": "find-the-integer-added-to-array-i", "prompt": "def addedInteger(nums1: List[int], nums2: List[int]) -> int:\n \"\"\"\n You are given two arrays of equal length, nums1 and nums2.\n Each element in nums1 has been increased (or decreased in the case of negative) by an integer, represented by the variable x.\n As a result, nums1 becomes equal to nums2. Two arrays are considered equal when they contain the same integers with the same frequencies.\n Return the integer x.\n \n Example 1:\n \n >>> addedInteger(nums1 = [2,6,4], nums2 = [9,7,5])\n >>> 3\n Explanation:\n The integer added to each element of nums1 is 3.\n \n Example 2:\n \n >>> addedInteger(nums1 = [10], nums2 = [5])\n >>> -5\n Explanation:\n The integer added to each element of nums1 is -5.\n \n Example 3:\n \n >>> addedInteger(nums1 = [1,1,1,1], nums2 = [1,1,1,1])\n >>> 0\n Explanation:\n The integer added to each element of nums1 is 0.\n \"\"\"\n"}
{"task_id": "find-the-integer-added-to-array-ii", "prompt": "def minimumAddedInteger(nums1: List[int], nums2: List[int]) -> int:\n \"\"\"\n You are given two integer arrays nums1 and nums2.\n From nums1 two elements have been removed, and all other elements have been increased (or decreased in the case of negative) by an integer, represented by the variable x.\n As a result, nums1 becomes equal to nums2. Two arrays are considered equal when they contain the same integers with the same frequencies.\n Return the minimum possible integer x that achieves this equivalence.\n \n Example 1:\n \n >>> minimumAddedInteger(nums1 = [4,20,16,12,8], nums2 = [14,18,10])\n >>> -2\n Explanation:\n After removing elements at indices [0,4] and adding -2, nums1 becomes [18,14,10].\n \n Example 2:\n \n >>> minimumAddedInteger(nums1 = [3,5,5,3], nums2 = [7,7])\n >>> 2\n Explanation:\n After removing elements at indices [0,3] and adding 2, nums1 becomes [7,7].\n \"\"\"\n"}
{"task_id": "minimum-array-end", "prompt": "def minEnd(n: int, x: int) -> int:\n \"\"\"\n You are given two integers n and x. You have to construct an array of positive integers nums of size n where for every 0 <= i < n - 1, nums[i + 1] is greater than nums[i], and the result of the bitwise AND operation between all elements of nums is x.\n Return the minimum possible value of nums[n - 1].\n \n Example 1:\n \n >>> minEnd(n = 3, x = 4)\n >>> 6\n Explanation:\n nums can be [4,5,6] and its last element is 6.\n \n Example 2:\n \n >>> minEnd(n = 2, x = 7)\n >>> 15\n Explanation:\n nums can be [7,15] and its last element is 15.\n \"\"\"\n"}
{"task_id": "find-the-median-of-the-uniqueness-array", "prompt": "def medianOfUniquenessArray(nums: List[int]) -> int:\n \"\"\"\n You are given an integer array nums. The uniqueness array of nums is the sorted array that contains the number of distinct elements of all the subarrays of nums. In other words, it is a sorted array consisting of distinct(nums[i..j]), for all 0 <= i <= j < nums.length.\n Here, distinct(nums[i..j]) denotes the number of distinct elements in the subarray that starts at index i and ends at index j.\n Return the median of the uniqueness array of nums.\n Note that the median of an array is defined as the middle element of the array when it is sorted in non-decreasing order. If there are two choices for a median, the smaller of the two values is taken.\n \n Example 1:\n \n >>> medianOfUniquenessArray(nums = [1,2,3])\n >>> 1\n Explanation:\n The uniqueness array of nums is [distinct(nums[0..0]), distinct(nums[1..1]), distinct(nums[2..2]), distinct(nums[0..1]), distinct(nums[1..2]), distinct(nums[0..2])] which is equal to [1, 1, 1, 2, 2, 3]. The uniqueness array has a median of 1. Therefore, the answer is 1.\n \n Example 2:\n \n >>> medianOfUniquenessArray(nums = [3,4,3,4,5])\n >>> 2\n Explanation:\n The uniqueness array of nums is [1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3]. The uniqueness array has a median of 2. Therefore, the answer is 2.\n \n Example 3:\n \n >>> medianOfUniquenessArray(nums = [4,3,5,4])\n >>> 2\n Explanation:\n The uniqueness array of nums is [1, 1, 1, 1, 2, 2, 2, 3, 3, 3]. The uniqueness array has a median of 2. Therefore, the answer is 2.\n \"\"\"\n"}
{"task_id": "equalize-strings-by-adding-or-removing-characters-at-ends", "prompt": "def minOperations(initial: str, target: str) -> int:\n \"\"\"\n Given two strings initial and target, your task is to modify initial by performing a series of operations to make it equal to target.\n In one operation, you can add or remove one character only at the beginning or the end of the string initial.\n Return the minimum number of operations required to transform initial into target.\n \n Example 1:\n \n >>> minOperations(initial = \"abcde\", target = \"cdef\")\n >>> 3\n Explanation:\n Remove 'a' and 'b' from the beginning of initial, then add 'f' to the end.\n \n Example 2:\n \n >>> minOperations(initial = \"axxy\", target = \"yabx\")\n >>> 6\n Explanation:\n \n \n \n Operation\n Resulting String\n \n \n Add 'y' to the beginning\n \"yaxxy\"\n \n \n Remove from end\n \"yaxx\"\n \n \n Remove from end\n \"yax\"\n \n \n Remove from end\n \"ya\"\n \n \n Add 'b' to the end\n \"yab\"\n \n \n Add 'x' to the end\n \"yabx\"\n \n \n \n \n Example 3:\n \n >>> minOperations(initial = \"xyz\", target = \"xyz\")\n >>> 0\n Explanation:\n No operations are needed as the strings are already equal.\n \"\"\"\n"}
{"task_id": "valid-word", "prompt": "def isValid(word: str) -> bool:\n \"\"\"\n A word is considered valid if:\n \n It contains a minimum of 3 characters.\n It contains only digits (0-9), and English letters (uppercase and lowercase).\n It includes at least one vowel.\n It includes at least one consonant.\n \n You are given a string word.\n Return true if word is valid, otherwise, return false.\n Notes:\n \n 'a', 'e', 'i', 'o', 'u', and their uppercases are vowels.\n A consonant is an English letter that is not a vowel.\n \n \n Example 1:\n \n >>> isValid(word = \"234Adas\")\n >>> true\n Explanation:\n This word satisfies the conditions.\n \n Example 2:\n \n >>> isValid(word = \"b3\")\n >>> false\n Explanation:\n The length of this word is fewer than 3, and does not have a vowel.\n \n Example 3:\n \n >>> isValid(word = \"a3$e\")\n >>> false\n Explanation:\n This word contains a '$' character and does not have a consonant.\n \"\"\"\n"}
{"task_id": "minimum-number-of-operations-to-make-word-k-periodic", "prompt": "def minimumOperationsToMakeKPeriodic(word: str, k: int) -> int:\n \"\"\"\n You are given a string word of size n, and an integer k such that k divides n.\n In one operation, you can pick any two indices i and j, that are divisible by k, then replace the substring of length k starting at i with the substring of length k starting at j. That is, replace the substring word[i..i + k - 1] with the substring word[j..j + k - 1].\n Return the minimum number of operations required to make word k-periodic.\n We say that word is k-periodic if there is some string s of length k such that word can be obtained by concatenating s an arbitrary number of times. For example, if word == \u201cababab\u201d, then word is 2-periodic for s = \"ab\".\n \n Example 1:\n \n >>> minimumOperationsToMakeKPeriodic(word = \"leetcodeleet\", k = 4)\n >>> 1\n Explanation:\n We can obtain a 4-periodic string by picking i = 4 and j = 0. After this operation, word becomes equal to \"leetleetleet\".\n \n Example 2:\n \n >>> minimumOperationsToMakeKPeriodic(word = \"leetcoleet\", k = 2)\n >>> 3\n Explanation:\n We can obtain a 2-periodic string by applying the operations in the table below.\n \n \n \n i\n j\n word\n \n \n 0\n 2\n etetcoleet\n \n \n 4\n 0\n etetetleet\n \n \n 6\n 0\n etetetetet\n \"\"\"\n"}
{"task_id": "minimum-length-of-anagram-concatenation", "prompt": "def minAnagramLength(s: str) -> int:\n \"\"\"\n You are given a string s, which is known to be a concatenation of anagrams of some string t.\n Return the minimum possible length of the string t.\n An anagram is formed by rearranging the letters of a string. For example, \"aab\", \"aba\", and, \"baa\" are anagrams of \"aab\".\n \n Example 1:\n \n >>> minAnagramLength(s = \"abba\")\n >>> 2\n Explanation:\n One possible string t could be \"ba\".\n \n Example 2:\n \n >>> minAnagramLength(s = \"cdef\")\n >>> 4\n Explanation:\n One possible string t could be \"cdef\", notice that t can be equal to s.\n \n Example 2:\n \n >>> minAnagramLength(s = \"abcbcacabbaccba\")\n >>> 3\n \"\"\"\n"}
{"task_id": "minimum-cost-to-equalize-array", "prompt": "def minCostToEqualizeArray(nums: List[int], cost1: int, cost2: int) -> int:\n \"\"\"\n You are given an integer array nums and two integers cost1 and cost2. You are allowed to perform either of the following operations any number of times:\n \n Choose an index i from nums and increase nums[i] by 1 for a cost of cost1.\n Choose two different indices i, j, from nums and increase nums[i] and nums[j] by 1 for a cost of cost2.\n \n Return the minimum cost required to make all elements in the array equal.\n Since the answer may be very large, return it modulo 109 + 7.\n \n Example 1:\n \n >>> minCostToEqualizeArray(nums = [4,1], cost1 = 5, cost2 = 2)\n >>> 15\n Explanation:\n The following operations can be performed to make the values equal:\n \n Increase nums[1] by 1 for a cost of 5. nums becomes [4,2].\n Increase nums[1] by 1 for a cost of 5. nums becomes [4,3].\n Increase nums[1] by 1 for a cost of 5. nums becomes [4,4].\n \n The total cost is 15.\n \n Example 2:\n \n >>> minCostToEqualizeArray(nums = [2,3,3,3,5], cost1 = 2, cost2 = 1)\n >>> 6\n Explanation:\n The following operations can be performed to make the values equal:\n \n Increase nums[0] and nums[1] by 1 for a cost of 1. nums becomes [3,4,3,3,5].\n Increase nums[0] and nums[2] by 1 for a cost of 1. nums becomes [4,4,4,3,5].\n Increase nums[0] and nums[3] by 1 for a cost of 1. nums becomes [5,4,4,4,5].\n Increase nums[1] and nums[2] by 1 for a cost of 1. nums becomes [5,5,5,4,5].\n Increase nums[3] by 1 for a cost of 2. nums becomes [5,5,5,5,5].\n \n The total cost is 6.\n \n Example 3:\n \n >>> minCostToEqualizeArray(nums = [3,5,3], cost1 = 1, cost2 = 3)\n >>> 4\n Explanation:\n The following operations can be performed to make the values equal:\n \n Increase nums[0] by 1 for a cost of 1. nums becomes [4,5,3].\n Increase nums[0] by 1 for a cost of 1. nums becomes [5,5,3].\n Increase nums[2] by 1 for a cost of 1. nums becomes [5,5,4].\n Increase nums[2] by 1 for a cost of 1. nums becomes [5,5,5].\n \n The total cost is 4.\n \"\"\"\n"}
{"task_id": "maximum-hamming-distances", "prompt": "def maxHammingDistances(nums: List[int], m: int) -> List[int]:\n \"\"\"\n Given an array nums and an integer m, with each element nums[i] satisfying 0 <= nums[i] < 2m, return an array answer. The answer array should be of the same length as nums, where each element answer[i] represents the maximum Hamming distance between nums[i] and any other element nums[j] in the array.\n The Hamming distance between two binary integers is defined as the number of positions at which the corresponding bits differ (add leading zeroes if needed).\n \n Example 1:\n \n >>> maxHammingDistances(nums = [9,12,9,11], m = 4)\n >>> [2,3,2,3]\n Explanation:\n The binary representation of nums = [1001,1100,1001,1011].\n The maximum hamming distances for each index are:\n \n nums[0]: 1001 and 1100 have a distance of 2.\n nums[1]: 1100 and 1011 have a distance of 3.\n nums[2]: 1001 and 1100 have a distance of 2.\n nums[3]: 1011 and 1100 have a distance of 3.\n \n \n Example 2:\n \n >>> maxHammingDistances(nums = [3,4,6,10], m = 4)\n >>> [3,3,2,3]\n Explanation:\n The binary representation of nums = [0011,0100,0110,1010].\n The maximum hamming distances for each index are:\n \n nums[0]: 0011 and 0100 have a distance of 3.\n nums[1]: 0100 and 0011 have a distance of 3.\n nums[2]: 0110 and 1010 have a distance of 2.\n nums[3]: 1010 and 0100 have a distance of 3.\n \"\"\"\n"}
{"task_id": "check-if-grid-satisfies-conditions", "prompt": "def satisfiesConditions(grid: List[List[int]]) -> bool:\n \"\"\"\n You are given a 2D matrix grid of size m x n. You need to check if each cell grid[i][j] is:\n \n Equal to the cell below it, i.e. grid[i][j] == grid[i + 1][j] (if it exists).\n Different from the cell to its right, i.e. grid[i][j] != grid[i][j + 1] (if it exists).\n \n Return true if all the cells satisfy these conditions, otherwise, return false.\n \n Example 1:\n \n >>> satisfiesConditions(grid = [[1,0,2],[1,0,2]])\n >>> true\n Explanation:\n \n All the cells in the grid satisfy the conditions.\n \n Example 2:\n \n >>> satisfiesConditions(grid = [[1,1,1],[0,0,0]])\n >>> false\n Explanation:\n \n All cells in the first row are equal.\n \n Example 3:\n \n >>> satisfiesConditions(grid = [[1],[2],[3]])\n >>> false\n Explanation:\n \n Cells in the first column have different values.\n \"\"\"\n"}
{"task_id": "maximum-points-inside-the-square", "prompt": "def maxPointsInsideSquare(points: List[List[int]], s: str) -> int:\n \"\"\"\n You are given a 2D array points and a string s where, points[i] represents the coordinates of point i, and s[i] represents the tag of point i.\n A valid square is a square centered at the origin (0, 0), has edges parallel to the axes, and does not contain two points with the same tag.\n Return the maximum number of points contained in a valid square.\n Note:\n \n A point is considered to be inside the square if it lies on or within the square's boundaries.\n The side length of the square can be zero.\n \n \n Example 1:\n \n \n >>> maxPointsInsideSquare(points = [[2,2],[-1,-2],[-4,4],[-3,1],[3,-3]], s = \"abdca\")\n >>> 2\n Explanation:\n The square of side length 4 covers two points points[0] and points[1].\n \n Example 2:\n \n \n >>> maxPointsInsideSquare(points = [[1,1],[-2,-2],[-2,2]], s = \"abb\")\n >>> 1\n Explanation:\n The square of side length 2 covers one point, which is points[0].\n \n Example 3:\n \n >>> maxPointsInsideSquare(points = [[1,1],[-1,-1],[2,-2]], s = \"ccd\")\n >>> 0\n Explanation:\n It's impossible to make any valid squares centered at the origin such that it covers only one point among points[0] and points[1].\n \"\"\"\n"}
{"task_id": "minimum-substring-partition-of-equal-character-frequency", "prompt": "def minimumSubstringsInPartition(s: str) -> int:\n \"\"\"\n Given a string s, you need to partition it into one or more balanced substrings. For example, if s == \"ababcc\" then (\"abab\", \"c\", \"c\"), (\"ab\", \"abc\", \"c\"), and (\"ababcc\") are all valid partitions, but (\"a\", \"bab\", \"cc\"), (\"aba\", \"bc\", \"c\"), and (\"ab\", \"abcc\") are not. The unbalanced substrings are bolded.\n Return the minimum number of substrings that you can partition s into.\n Note: A balanced string is a string where each character in the string occurs the same number of times.\n \n Example 1:\n \n >>> minimumSubstringsInPartition(s = \"fabccddg\")\n >>> 3\n Explanation:\n We can partition the string s into 3 substrings in one of the following ways: (\"fab, \"ccdd\", \"g\"), or (\"fabc\", \"cd\", \"dg\").\n \n Example 2:\n \n >>> minimumSubstringsInPartition(s = \"abababaccddb\")\n >>> 2\n Explanation:\n We can partition the string s into 2 substrings like so: (\"abab\", \"abaccddb\").\n \"\"\"\n"}
{"task_id": "permutation-difference-between-two-strings", "prompt": "def findPermutationDifference(s: str, t: str) -> int:\n \"\"\"\n You are given two strings s and t such that every character occurs at most once in s and t is a permutation of s.\n The permutation difference between s and t is defined as the sum of the absolute difference between the index of the occurrence of each character in s and the index of the occurrence of the same character in t.\n Return the permutation difference between s and t.\n \n Example 1:\n \n >>> findPermutationDifference(s = \"abc\", t = \"bac\")\n >>> 2\n Explanation:\n For s = \"abc\" and t = \"bac\", the permutation difference of s and t is equal to the sum of:\n \n The absolute difference between the index of the occurrence of \"a\" in s and the index of the occurrence of \"a\" in t.\n The absolute difference between the index of the occurrence of \"b\" in s and the index of the occurrence of \"b\" in t.\n The absolute difference between the index of the occurrence of \"c\" in s and the index of the occurrence of \"c\" in t.\n \n That is, the permutation difference between s and t is equal to |0 - 1| + |1 - 0| + |2 - 2| = 2.\n \n Example 2:\n \n >>> findPermutationDifference(s = \"abcde\", t = \"edbac\")\n >>> 12\n Explanation: The permutation difference between s and t is equal to |0 - 3| + |1 - 2| + |2 - 4| + |3 - 1| + |4 - 0| = 12.\n \"\"\"\n"}
{"task_id": "taking-maximum-energy-from-the-mystic-dungeon", "prompt": "def maximumEnergy(energy: List[int], k: int) -> int:\n \"\"\"\n In a mystic dungeon, n magicians are standing in a line. Each magician has an attribute that gives you energy. Some magicians can give you negative energy, which means taking energy from you.\n You have been cursed in such a way that after absorbing energy from magician i, you will be instantly transported to magician (i + k). This process will be repeated until you reach the magician where (i + k) does not exist.\n In other words, you will choose a starting point and then teleport with k jumps until you reach the end of the magicians' sequence, absorbing all the energy during the journey.\n You are given an array energy and an integer k. Return the maximum possible energy you can gain.\n Note that when you are reach a magician, you must take energy from them, whether it is negative or positive energy.\n \n Example 1:\n \n >>> maximumEnergy(energy = [5,2,-10,-5,1], k = 3)\n >>> 3\n Explanation: We can gain a total energy of 3 by starting from magician 1 absorbing 2 + 1 = 3.\n \n Example 2:\n \n >>> maximumEnergy(energy = [-2,-3,-1], k = 2)\n >>> -1\n Explanation: We can gain a total energy of -1 by starting from magician 2.\n \"\"\"\n"}
{"task_id": "maximum-difference-score-in-a-grid", "prompt": "def maxScore(grid: List[List[int]]) -> int:\n \"\"\"\n You are given an m x n matrix grid consisting of positive integers. You can move from a cell in the matrix to any other cell that is either to the bottom or to the right (not necessarily adjacent). The score of a move from a cell with the value c1 to a cell with the value c2 is c2 - c1.\n You can start at any cell, and you have to make at least one move.\n Return the maximum total score you can achieve.\n \n Example 1:\n \n \n >>> maxScore(grid = [[9,5,7,3],[8,9,6,1],[6,7,14,3],[2,5,3,1]])\n >>> 9\n Explanation: We start at the cell (0, 1), and we perform the following moves:\n - Move from the cell (0, 1) to (2, 1) with a score of 7 - 5 = 2.\n - Move from the cell (2, 1) to (2, 2) with a score of 14 - 7 = 7.\n The total score is 2 + 7 = 9.\n \n Example 2:\n \n \n >>> maxScore(grid = [[4,3,2],[3,2,1]])\n >>> -1\n Explanation: We start at the cell (0, 0), and we perform one move: (0, 0) to (0, 1). The score is 3 - 4 = -1.\n \"\"\"\n"}
{"task_id": "find-the-minimum-cost-array-permutation", "prompt": "def findPermutation(nums: List[int]) -> List[int]:\n \"\"\"\n You are given an array nums which is a permutation of [0, 1, 2, ..., n - 1]. The score of any permutation of [0, 1, 2, ..., n - 1] named perm is defined as:\n score(perm) = |perm[0] - nums[perm[1]]| + |perm[1] - nums[perm[2]]| + ... + |perm[n - 1] - nums[perm[0]]|\n Return the permutation perm which has the minimum possible score. If multiple permutations exist with this score, return the one that is lexicographically smallest among them.\n \n Example 1:\n \n >>> findPermutation(nums = [1,0,2])\n >>> [0,1,2]\n Explanation:\n \n The lexicographically smallest permutation with minimum cost is [0,1,2]. The cost of this permutation is |0 - 0| + |1 - 2| + |2 - 1| = 2.\n \n Example 2:\n \n >>> findPermutation(nums = [0,2,1])\n >>> [0,2,1]\n Explanation:\n \n The lexicographically smallest permutation with minimum cost is [0,2,1]. The cost of this permutation is |0 - 1| + |2 - 2| + |1 - 0| = 2.\n \"\"\"\n"}
{"task_id": "special-array-i", "prompt": "def isArraySpecial(nums: List[int]) -> bool:\n \"\"\"\n An array is considered special if the parity of every pair of adjacent elements is different. In other words, one element in each pair must be even, and the other must be odd.\n You are given an array of integers nums. Return true if nums is a special array, otherwise, return false.\n \n Example 1:\n \n >>> isArraySpecial(nums = [1])\n >>> true\n Explanation:\n There is only one element. So the answer is true.\n \n Example 2:\n \n >>> isArraySpecial(nums = [2,1,4])\n >>> true\n Explanation:\n There is only two pairs: (2,1) and (1,4), and both of them contain numbers with different parity. So the answer is true.\n \n Example 3:\n \n >>> isArraySpecial(nums = [4,3,1,6])\n >>> false\n Explanation:\n nums[1] and nums[2] are both odd. So the answer is false.\n \"\"\"\n"}
{"task_id": "special-array-ii", "prompt": "def isArraySpecial(nums: List[int], queries: List[List[int]]) -> List[bool]:\n \"\"\"\n An array is considered special if every pair of its adjacent elements contains two numbers with different parity.\n You are given an array of integer nums and a 2D integer matrix queries, where for queries[i] = [fromi, toi] your task is to check that subarray nums[fromi..toi] is special or not.\n Return an array of booleans answer such that answer[i] is true if nums[fromi..toi] is special.\n \n Example 1:\n \n >>> isArraySpecial(nums = [3,4,1,2,6], queries = [[0,4]])\n >>> [false]\n Explanation:\n The subarray is [3,4,1,2,6]. 2 and 6 are both even.\n \n Example 2:\n \n >>> isArraySpecial(nums = [4,3,1,6], queries = [[0,2],[2,3]])\n >>> [false,true]\n Explanation:\n \n The subarray is [4,3,1]. 3 and 1 are both odd. So the answer to this query is false.\n The subarray is [1,6]. There is only one pair: (1,6) and it contains numbers with different parity. So the answer to this query is true.\n \"\"\"\n"}
{"task_id": "sum-of-digit-differences-of-all-pairs", "prompt": "def sumDigitDifferences(nums: List[int]) -> int:\n \"\"\"\n You are given an array nums consisting of positive integers where all integers have the same number of digits.\n The digit difference between two integers is the count of different digits that are in the same position in the two integers.\n Return the sum of the digit differences between all pairs of integers in nums.\n \n Example 1:\n \n >>> sumDigitDifferences(nums = [13,23,12])\n >>> 4\n Explanation:\n We have the following:\n - The digit difference between 13 and 23 is 1.\n - The digit difference between 13 and 12 is 1.\n - The digit difference between 23 and 12 is 2.\n So the total sum of digit differences between all pairs of integers is 1 + 1 + 2 = 4.\n \n Example 2:\n \n >>> sumDigitDifferences(nums = [10,10,10,10])\n >>> 0\n Explanation:\n All the integers in the array are the same. So the total sum of digit differences between all pairs of integers will be 0.\n \"\"\"\n"}
{"task_id": "find-number-of-ways-to-reach-the-k-th-stair", "prompt": "def waysToReachStair(k: int) -> int:\n \"\"\"\n You are given a non-negative integer k. There exists a staircase with an infinite number of stairs, with the lowest stair numbered 0.\n Alice has an integer jump, with an initial value of 0. She starts on stair 1 and wants to reach stair k using any number of operations. If she is on stair i, in one operation she can:\n \n Go down to stair i - 1. This operation cannot be used consecutively or on stair 0.\n Go up to stair i + 2jump. And then, jump becomes jump + 1.\n \n Return the total number of ways Alice can reach stair k.\n Note that it is possible that Alice reaches the stair k, and performs some operations to reach the stair k again.\n \n Example 1:\n \n >>> waysToReachStair(k = 0)\n >>> 2\n Explanation:\n The 2 possible ways of reaching stair 0 are:\n \n Alice starts at stair 1.\n \n Using an operation of the first type, she goes down 1 stair to reach stair 0.\n \n \n Alice starts at stair 1.\n \n Using an operation of the first type, she goes down 1 stair to reach stair 0.\n Using an operation of the second type, she goes up 20 stairs to reach stair 1.\n Using an operation of the first type, she goes down 1 stair to reach stair 0.\n \n \n \n \n Example 2:\n \n >>> waysToReachStair(k = 1)\n >>> 4\n Explanation:\n The 4 possible ways of reaching stair 1 are:\n \n Alice starts at stair 1. Alice is at stair 1.\n Alice starts at stair 1.\n \n Using an operation of the first type, she goes down 1 stair to reach stair 0.\n Using an operation of the second type, she goes up 20 stairs to reach stair 1.\n \n \n Alice starts at stair 1.\n \n Using an operation of the second type, she goes up 20 stairs to reach stair 2.\n Using an operation of the first type, she goes down 1 stair to reach stair 1.\n \n \n Alice starts at stair 1.\n \n Using an operation of the first type, she goes down 1 stair to reach stair 0.\n Using an operation of the second type, she goes up 20 stairs to reach stair 1.\n Using an operation of the first type, she goes down 1 stair to reach stair 0.\n Using an operation of the second type, she goes up 21 stairs to reach stair 2.\n Using an operation of the first type, she goes down 1 stair to reach stair 1.\n \"\"\"\n"}
{"task_id": "maximum-number-of-upgradable-servers", "prompt": "def maxUpgrades(count: List[int], upgrade: List[int], sell: List[int], money: List[int]) -> List[int]:\n \"\"\"\n You have n data centers and need to upgrade their servers.\n You are given four arrays count, upgrade, sell, and money of length n, which show:\n \n The number of servers\n The cost of upgrading a single server\n The money you get by selling a server\n The money you initially have\n \n for each data center respectively.\n Return an array answer, where for each data center, the corresponding element in answer represents the maximum number of servers that can be upgraded.\n Note that the money from one data center cannot be used for another data center.\n \n Example 1:\n \n >>> maxUpgrades(count = [4,3], upgrade = [3,5], sell = [4,2], money = [8,9])\n >>> [3,2]\n Explanation:\n For the first data center, if we sell one server, we'll have 8 + 4 = 12 units of money and we can upgrade the remaining 3 servers.\n For the second data center, if we sell one server, we'll have 9 + 2 = 11 units of money and we can upgrade the remaining 2 servers.\n \n Example 2:\n \n >>> maxUpgrades(count = [1], upgrade = [2], sell = [1], money = [1])\n >>> [0]\n \"\"\"\n"}
{"task_id": "find-the-level-of-tree-with-minimum-sum", "prompt": "# class TreeNode:\n# def __init__(val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def minimumLevel(root: Optional[TreeNode]) -> int:\n \"\"\"\n Given the root of a binary tree root where each node has a value, return the level of the tree that has the minimum sum of values among all the levels (in case of a tie, return the lowest level).\n Note that the root of the tree is at level 1 and the level of any other node is its distance from the root + 1.\n \n Example 1:\n \n >>> __init__(root = [50,6,2,30,80,7])\n >>> 2\n Explanation:\n \n \n Example 2:\n \n >>> __init__(root = [36,17,10,null,null,24])\n >>> 3\n Explanation:\n \n \n Example 3:\n \n >>> __init__(root = [5,null,5,null,5])\n >>> 1\n Explanation:\n \"\"\"\n"}
{"task_id": "find-the-xor-of-numbers-which-appear-twice", "prompt": "def duplicateNumbersXOR(nums: List[int]) -> int:\n \"\"\"\n You are given an array nums, where each number in the array appears either once or twice.\n Return the bitwise XOR of all the numbers that appear twice in the array, or 0 if no number appears twice.\n \n Example 1:\n \n >>> duplicateNumbersXOR(nums = [1,2,1,3])\n >>> 1\n Explanation:\n The only number that appears twice in\u00a0nums\u00a0is 1.\n \n Example 2:\n \n >>> duplicateNumbersXOR(nums = [1,2,3])\n >>> 0\n Explanation:\n No number appears twice in\u00a0nums.\n \n Example 3:\n \n >>> duplicateNumbersXOR(nums = [1,2,2,1])\n >>> 3\n Explanation:\n Numbers 1 and 2 appeared twice. 1 XOR 2 == 3.\n \"\"\"\n"}
{"task_id": "find-occurrences-of-an-element-in-an-array", "prompt": "def occurrencesOfElement(nums: List[int], queries: List[int], x: int) -> List[int]:\n \"\"\"\n You are given an integer array nums, an integer array queries, and an integer x.\n For each queries[i], you need to find the index of the queries[i]th occurrence of x in the nums array. If there are fewer than queries[i] occurrences of x, the answer should be -1 for that query.\n Return an integer array answer containing the answers to all queries.\n \n Example 1:\n \n >>> occurrencesOfElement(nums = [1,3,1,7], queries = [1,3,2,4], x = 1)\n >>> [0,-1,2,-1]\n Explanation:\n \n For the 1st query, the first occurrence of 1 is at index 0.\n For the 2nd query, there are only two occurrences of 1 in nums, so the answer is -1.\n For the 3rd query, the second occurrence of 1 is at index 2.\n For the 4th query, there are only two occurrences of 1 in nums, so the answer is -1.\n \n \n Example 2:\n \n >>> occurrencesOfElement(nums = [1,2,3], queries = [10], x = 5)\n >>> [-1]\n Explanation:\n \n For the 1st query, 5 doesn't exist in nums, so the answer is -1.\n \"\"\"\n"}
{"task_id": "find-the-number-of-distinct-colors-among-the-balls", "prompt": "def queryResults(limit: int, queries: List[List[int]]) -> List[int]:\n \"\"\"\n You are given an integer limit and a 2D array queries of size n x 2.\n There are limit + 1 balls with distinct labels in the range [0, limit]. Initially, all balls are uncolored. For every query in queries that is of the form [x, y], you mark ball x with the color y. After each query, you need to find the number of colors among the balls.\n Return an array result of length n, where result[i] denotes the number of colors after ith query.\n Note that when answering a query, lack of a color will not be considered as a color.\n \n Example 1:\n \n >>> queryResults(limit = 4, queries = [[1,4],[2,5],[1,3],[3,4]])\n >>> [1,2,2,3]\n Explanation:\n \n \n After query 0, ball 1 has color 4.\n After query 1, ball 1 has color 4, and ball 2 has color 5.\n After query 2, ball 1 has color 3, and ball 2 has color 5.\n After query 3, ball 1 has color 3, ball 2 has color 5, and ball 3 has color 4.\n \n \n Example 2:\n \n >>> queryResults(limit = 4, queries = [[0,1],[1,2],[2,2],[3,4],[4,5]])\n >>> [1,2,2,3,4]\n Explanation:\n \n \n After query 0, ball 0 has color 1.\n After query 1, ball 0 has color 1, and ball 1 has color 2.\n After query 2, ball 0 has color 1, and balls 1 and 2 have color 2.\n After query 3, ball 0 has color 1, balls 1 and 2 have color 2, and ball 3 has color 4.\n After query 4, ball 0 has color 1, balls 1 and 2 have color 2, ball 3 has color 4, and ball 4 has color 5.\n \"\"\"\n"}
{"task_id": "block-placement-queries", "prompt": "def getResults(queries: List[List[int]]) -> List[bool]:\n \"\"\"\n There exists an infinite number line, with its origin at 0 and extending towards the positive x-axis.\n You are given a 2D array queries, which contains two types of queries:\n \n For a query of type 1, queries[i] = [1, x]. Build an obstacle at distance x from the origin. It is guaranteed that there is no obstacle at distance x when the query is asked.\n For a query of type 2, queries[i] = [2, x, sz]. Check if it is possible to place a block of size sz anywhere in the range [0, x] on the line, such that the block entirely lies in the range [0, x]. A block cannot be placed if it intersects with any obstacle, but it may touch it. Note that you do not actually place the block. Queries are separate.\n \n Return a boolean array results, where results[i] is true if you can place the block specified in the ith query of type 2, and false otherwise.\n \n Example 1:\n \n >>> getResults(queries = [[1,2],[2,3,3],[2,3,1],[2,2,2]])\n >>> [false,true,true]\n Explanation:\n \n For query 0, place an obstacle at x = 2. A block of size at most 2 can be placed before x = 3.\n \n Example 2:\n \n >>> getResults(queries = [[1,7],[2,7,6],[1,2],[2,7,5],[2,7,6]])\n >>> [true,true,false]\n Explanation:\n \n \n Place an obstacle at x = 7 for query 0. A block of size at most 7 can be placed before x = 7.\n Place an obstacle at x = 2 for query 2. Now, a block of size at most 5 can be placed before x = 7, and a block of size at most 2 before x = 2.\n \"\"\"\n"}
{"task_id": "find-the-number-of-good-pairs-i", "prompt": "def numberOfPairs(nums1: List[int], nums2: List[int], k: int) -> int:\n \"\"\"\n You are given 2 integer arrays nums1 and nums2 of lengths n and m respectively. You are also given a positive integer k.\n A pair (i, j) is called good if nums1[i] is divisible by nums2[j] * k (0 <= i <= n - 1, 0 <= j <= m - 1).\n Return the total number of good pairs.\n \n Example 1:\n \n >>> numberOfPairs(nums1 = [1,3,4], nums2 = [1,3,4], k = 1)\n >>> 5\n Explanation:\n The 5 good pairs are (0, 0), (1, 0), (1, 1), (2, 0), and (2, 2).\n Example 2:\n \n >>> numberOfPairs(nums1 = [1,2,4,12], nums2 = [2,4], k = 3)\n >>> 2\n Explanation:\n The 2 good pairs are (3, 0) and (3, 1).\n \"\"\"\n"}
{"task_id": "string-compression-iii", "prompt": "def compressedString(word: str) -> str:\n \"\"\"\n Given a string word, compress it using the following algorithm:\n \n Begin with an empty string comp. While word is not empty, use the following operation:\n \n \n Remove a maximum length prefix of word made of a single character c repeating at most 9 times.\n Append the length of the prefix followed by c to comp.\n \n \n \n Return the string comp.\n \n Example 1:\n \n >>> compressedString(word = \"abcde\")\n >>> \"1a1b1c1d1e\"\n Explanation:\n Initially, comp = \"\". Apply the operation 5 times, choosing \"a\", \"b\", \"c\", \"d\", and \"e\" as the prefix in each operation.\n For each prefix, append \"1\" followed by the character to comp.\n \n Example 2:\n \n >>> compressedString(word = \"aaaaaaaaaaaaaabb\")\n >>> \"9a5a2b\"\n Explanation:\n Initially, comp = \"\". Apply the operation 3 times, choosing \"aaaaaaaaa\", \"aaaaa\", and \"bb\" as the prefix in each operation.\n \n For prefix \"aaaaaaaaa\", append \"9\" followed by \"a\" to comp.\n For prefix \"aaaaa\", append \"5\" followed by \"a\" to comp.\n For prefix \"bb\", append \"2\" followed by \"b\" to comp.\n \"\"\"\n"}
{"task_id": "find-the-number-of-good-pairs-ii", "prompt": "def numberOfPairs(nums1: List[int], nums2: List[int], k: int) -> int:\n \"\"\"\n You are given 2 integer arrays nums1 and nums2 of lengths n and m respectively. You are also given a positive integer k.\n A pair (i, j) is called good if nums1[i] is divisible by nums2[j] * k (0 <= i <= n - 1, 0 <= j <= m - 1).\n Return the total number of good pairs.\n \n Example 1:\n \n >>> numberOfPairs(nums1 = [1,3,4], nums2 = [1,3,4], k = 1)\n >>> 5\n Explanation:\n The 5 good pairs are (0, 0), (1, 0), (1, 1), (2, 0), and (2, 2).\n Example 2:\n \n >>> numberOfPairs(nums1 = [1,2,4,12], nums2 = [2,4], k = 3)\n >>> 2\n Explanation:\n The 2 good pairs are (3, 0) and (3, 1).\n \"\"\"\n"}
{"task_id": "maximum-sum-of-subsequence-with-non-adjacent-elements", "prompt": "def maximumSumSubsequence(nums: List[int], queries: List[List[int]]) -> int:\n \"\"\"\n You are given an array nums consisting of integers. You are also given a 2D array queries, where queries[i] = [posi, xi].\n For query i, we first set nums[posi] equal to xi, then we calculate the answer to query i which is the maximum sum of a subsequence of nums where no two adjacent elements are selected.\n Return the sum of the answers to all queries.\n Since the final answer may be very large, return it modulo 109 + 7.\n 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.\n \n Example 1:\n \n >>> maximumSumSubsequence(nums = [3,5,9], queries = [[1,-2],[0,-3]])\n >>> 21\n Explanation:\n After the 1st query, nums = [3,-2,9] and the maximum sum of a subsequence with non-adjacent elements is 3 + 9 = 12.\n After the 2nd query, nums = [-3,-2,9] and the maximum sum of a subsequence with non-adjacent elements is 9.\n \n Example 2:\n \n >>> maximumSumSubsequence(nums = [0,-1], queries = [[0,-5]])\n >>> 0\n Explanation:\n After the 1st query, nums = [-5,-1] and the maximum sum of a subsequence with non-adjacent elements is 0 (choosing an empty subsequence).\n \"\"\"\n"}
{"task_id": "better-compression-of-string", "prompt": "def betterCompression(compressed: str) -> str:\n \"\"\"\n You are given a string compressed representing a compressed version of a string. The format is a character followed by its frequency. For example, \"a3b1a1c2\" is a compressed version of the string \"aaabacc\".\n We seek a better compression with the following conditions:\n \n Each character should appear only once in the compressed version.\n The characters should be in alphabetical order.\n \n Return the better compression of compressed.\n Note: In the better version of compression, the order of letters may change, which is acceptable.\n \n Example 1:\n \n >>> betterCompression(compressed = \"a3c9b2c1\")\n >>> \"a3b2c10\"\n Explanation:\n Characters \"a\" and \"b\" appear only once in the input, but \"c\" appears twice, once with a size of 9 and once with a size of 1.\n Hence, in the resulting string, it should have a size of 10.\n \n Example 2:\n \n >>> betterCompression(compressed = \"c2b3a1\")\n >>> \"a1b3c2\"\n \n Example 3:\n \n >>> betterCompression(compressed = \"a2b4c1\")\n >>> \"a2b4c1\"\n \"\"\"\n"}
{"task_id": "minimum-number-of-chairs-in-a-waiting-room", "prompt": "def minimumChairs(s: str) -> int:\n \"\"\"\n You are given a string s. Simulate events at each second i:\n \n If s[i] == 'E', a person enters the waiting room and takes one of the chairs in it.\n If s[i] == 'L', a person leaves the waiting room, freeing up a chair.\n \n Return the minimum number of chairs needed so that a chair is available for every person who enters the waiting room given that it is initially empty.\n \n Example 1:\n \n >>> minimumChairs(s = \"EEEEEEE\")\n >>> 7\n Explanation:\n After each second, a person enters the waiting room and no person leaves it. Therefore, a minimum of 7 chairs is needed.\n \n Example 2:\n \n >>> minimumChairs(s = \"ELELEEL\")\n >>> 2\n Explanation:\n Let's consider that there are 2 chairs in the waiting room. The table below shows the state of the waiting room at each second.\n \n \n \n \n Second\n Event\n People in the Waiting Room\n Available Chairs\n \n \n 0\n Enter\n 1\n 1\n \n \n 1\n Leave\n 0\n 2\n \n \n 2\n Enter\n 1\n 1\n \n \n 3\n Leave\n 0\n 2\n \n \n 4\n Enter\n 1\n 1\n \n \n 5\n Enter\n 2\n 0\n \n \n 6\n Leave\n 1\n 1\n \n \n \n Example 3:\n \n >>> minimumChairs(s = \"ELEELEELLL\")\n >>> 3\n Explanation:\n Let's consider that there are 3 chairs in the waiting room. The table below shows the state of the waiting room at each second.\n \n \n \n \n Second\n Event\n People in the Waiting Room\n Available Chairs\n \n \n 0\n Enter\n 1\n 2\n \n \n 1\n Leave\n 0\n 3\n \n \n 2\n Enter\n 1\n 2\n \n \n 3\n Enter\n 2\n 1\n \n \n 4\n Leave\n 1\n 2\n \n \n 5\n Enter\n 2\n 1\n \n \n 6\n Enter\n 3\n 0\n \n \n 7\n Leave\n 2\n 1\n \n \n 8\n Leave\n 1\n 2\n \n \n 9\n Leave\n 0\n 3\n \"\"\"\n"}
{"task_id": "count-days-without-meetings", "prompt": "def countDays(days: int, meetings: List[List[int]]) -> int:\n \"\"\"\n You are given a positive integer days representing the total number of days an employee is available for work (starting from day 1). You are also given a 2D array meetings of size n where, meetings[i] = [start_i, end_i] represents the starting and ending days of meeting i (inclusive).\n Return the count of days when the employee is available for work but no meetings are scheduled.\n Note: The meetings may overlap.\n \n Example 1:\n \n >>> countDays(days = 10, meetings = [[5,7],[1,3],[9,10]])\n >>> 2\n Explanation:\n There is no meeting scheduled on the 4th and 8th days.\n \n Example 2:\n \n >>> countDays(days = 5, meetings = [[2,4],[1,3]])\n >>> 1\n Explanation:\n There is no meeting scheduled on the 5th day.\n \n Example 3:\n \n >>> countDays(days = 6, meetings = [[1,6]])\n >>> 0\n Explanation:\n Meetings are scheduled for all working days.\n \"\"\"\n"}
{"task_id": "lexicographically-minimum-string-after-removing-stars", "prompt": "def clearStars(s: str) -> str:\n \"\"\"\n You are given a string s. It may contain any number of '*' characters. Your task is to remove all '*' characters.\n While there is a '*', do the following operation:\n \n Delete the leftmost '*' and the smallest non-'*' character to its left. If there are several smallest characters, you can delete any of them.\n \n Return the lexicographically smallest resulting string after removing all '*' characters.\n \n Example 1:\n \n >>> clearStars(s = \"aaba*\")\n >>> \"aab\"\n Explanation:\n We should delete one of the 'a' characters with '*'. If we choose s[3], s becomes the lexicographically smallest.\n \n Example 2:\n \n >>> clearStars(s = \"abc\")\n >>> \"abc\"\n Explanation:\n There is no '*' in the string.\n \"\"\"\n"}
{"task_id": "find-subarray-with-bitwise-or-closest-to-k", "prompt": "def minimumDifference(nums: List[int], k: int) -> int:\n \"\"\"\n You are given an array nums and an integer k. You need to find a subarray of nums such that the absolute difference between k and the bitwise OR of the subarray elements is as small as possible. In other words, select a subarray nums[l..r] such that |k - (nums[l] OR nums[l + 1] ... OR nums[r])| is minimum.\n Return the minimum possible value of the absolute difference.\n A subarray is a contiguous non-empty sequence of elements within an array.\n \n Example 1:\n \n >>> minimumDifference(nums = [1,2,4,5], k = 3)\n >>> 0\n Explanation:\n The subarray nums[0..1] has OR value 3, which gives the minimum absolute difference |3 - 3| = 0.\n \n Example 2:\n \n >>> minimumDifference(nums = [1,3,1,3], k = 2)\n >>> 1\n Explanation:\n The subarray nums[1..1] has OR value 3, which gives the minimum absolute difference |3 - 2| = 1.\n \n Example 3:\n \n >>> minimumDifference(nums = [1], k = 10)\n >>> 9\n Explanation:\n There is a single subarray with OR value 1, which gives the minimum absolute difference |10 - 1| = 9.\n \"\"\"\n"}
{"task_id": "bitwise-or-of-adjacent-elements", "prompt": "def orArray(nums: List[int]) -> List[int]:\n \"\"\"\n Given an array nums of length n, return an array answer of length n - 1 such that answer[i] = nums[i] | nums[i + 1] where | is the bitwise OR operation.\n \n Example 1:\n \n >>> orArray(nums = [1,3,7,15])\n >>> [3,7,15]\n \n Example 2:\n \n >>> orArray(nums = [8,4,2])\n >>> [12,6]\n \n Example 3:\n \n >>> orArray(nums = [5,4,9,11])\n >>> [5,13,11]\n \"\"\"\n"}
{"task_id": "clear-digits", "prompt": "def clearDigits(s: str) -> str:\n \"\"\"\n You are given a string s.\n Your task is to remove all digits by doing this operation repeatedly:\n \n Delete the first digit and the closest non-digit character to its left.\n \n Return the resulting string after removing all digits.\n Note that the operation cannot be performed on a digit that does not have any non-digit character to its left.\n \n Example 1:\n \n >>> clearDigits(s = \"abc\")\n >>> \"abc\"\n Explanation:\n There is no digit in the string.\n \n Example 2:\n \n >>> clearDigits(s = \"cb34\")\n >>> \"\"\n Explanation:\n First, we apply the operation on s[2], and s becomes \"c4\".\n Then we apply the operation on s[1], and s becomes \"\".\n \"\"\"\n"}
{"task_id": "find-the-first-player-to-win-k-games-in-a-row", "prompt": "def findWinningPlayer(skills: List[int], k: int) -> int:\n \"\"\"\n A competition consists of n players numbered from 0 to n - 1.\n You are given an integer array skills of size n and a positive integer k, where skills[i] is the skill level of player i. All integers in skills are unique.\n All players are standing in a queue in order from player 0 to player n - 1.\n The competition process is as follows:\n \n The first two players in the queue play a game, and the player with the higher skill level wins.\n After the game, the winner stays at the beginning of the queue, and the loser goes to the end of it.\n \n The winner of the competition is the first player who wins k games in a row.\n Return the initial index of the winning player.\n \n Example 1:\n \n >>> findWinningPlayer(skills = [4,2,6,3,9], k = 2)\n >>> 2\n Explanation:\n Initially, the queue of players is [0,1,2,3,4]. The following process happens:\n \n Players 0 and 1 play a game, since the skill of player 0 is higher than that of player 1, player 0 wins. The resulting queue is [0,2,3,4,1].\n Players 0 and 2 play a game, since the skill of player 2 is higher than that of player 0, player 2 wins. The resulting queue is [2,3,4,1,0].\n Players 2 and 3 play a game, since the skill of player 2 is higher than that of player 3, player 2 wins. The resulting queue is [2,4,1,0,3].\n \n Player 2 won k = 2 games in a row, so the winner is player 2.\n \n Example 2:\n \n >>> findWinningPlayer(skills = [2,5,4], k = 3)\n >>> 1\n Explanation:\n Initially, the queue of players is [0,1,2]. The following process happens:\n \n Players 0 and 1 play a game, since the skill of player 1 is higher than that of player 0, player 1 wins. The resulting queue is [1,2,0].\n Players 1 and 2 play a game, since the skill of player 1 is higher than that of player 2, player 1 wins. The resulting queue is [1,0,2].\n Players 1 and 0 play a game, since the skill of player 1 is higher than that of player 0, player 1 wins. The resulting queue is [1,2,0].\n \n Player 1 won k = 3 games in a row, so the winner is player 1.\n \"\"\"\n"}
{"task_id": "find-the-maximum-length-of-a-good-subsequence-i", "prompt": "def maximumLength(nums: List[int], k: int) -> int:\n \"\"\"\n You are given an integer array nums and a non-negative integer k. A sequence of integers seq is called good if there are at most k indices i in the range [0, seq.length - 2] such that seq[i] != seq[i + 1].\n Return the maximum possible length of a good subsequence of nums.\n \n Example 1:\n \n >>> maximumLength(nums = [1,2,1,1,3], k = 2)\n >>> 4\n Explanation:\n The maximum length subsequence is [1,2,1,1,3].\n \n Example 2:\n \n >>> maximumLength(nums = [1,2,3,4,5,1], k = 0)\n >>> 2\n Explanation:\n The maximum length subsequence is [1,2,3,4,5,1].\n \"\"\"\n"}
{"task_id": "find-the-maximum-length-of-a-good-subsequence-ii", "prompt": "def maximumLength(nums: List[int], k: int) -> int:\n \"\"\"\n You are given an integer array nums and a non-negative integer k. A sequence of integers seq is called good if there are at most k indices i in the range [0, seq.length - 2] such that seq[i] != seq[i + 1].\n Return the maximum possible length of a good subsequence of nums.\n \n Example 1:\n \n >>> maximumLength(nums = [1,2,1,1,3], k = 2)\n >>> 4\n Explanation:\n The maximum length subsequence is [1,2,1,1,3].\n \n Example 2:\n \n >>> maximumLength(nums = [1,2,3,4,5,1], k = 0)\n >>> 2\n Explanation:\n The maximum length subsequence is [1,2,3,4,5,1].\n \"\"\"\n"}
{"task_id": "find-the-child-who-has-the-ball-after-k-seconds", "prompt": "def numberOfChild(n: int, k: int) -> int:\n \"\"\"\n You are given two positive integers n and k. There are n children numbered from 0 to n - 1 standing in a queue in order from left to right.\n Initially, child 0 holds a ball and the direction of passing the ball is towards the right direction. After each second, the child holding the ball passes it to the child next to them. Once the ball reaches either end of the line, i.e. child 0 or child n - 1, the direction of passing is reversed.\n Return the number of the child who receives the ball after k seconds.\n \n Example 1:\n \n >>> numberOfChild(n = 3, k = 5)\n >>> 1\n Explanation:\n \n \n \n Time elapsed\n Children\n \n \n 0\n [0, 1, 2]\n \n \n 1\n [0, 1, 2]\n \n \n 2\n [0, 1, 2]\n \n \n 3\n [0, 1, 2]\n \n \n 4\n [0, 1, 2]\n \n \n 5\n [0, 1, 2]\n \n \n \n \n Example 2:\n \n >>> numberOfChild(n = 5, k = 6)\n >>> 2\n Explanation:\n \n \n \n Time elapsed\n Children\n \n \n 0\n [0, 1, 2, 3, 4]\n \n \n 1\n [0, 1, 2, 3, 4]\n \n \n 2\n [0, 1, 2, 3, 4]\n \n \n 3\n [0, 1, 2, 3, 4]\n \n \n 4\n [0, 1, 2, 3, 4]\n \n \n 5\n [0, 1, 2, 3, 4]\n \n \n 6\n [0, 1, 2, 3, 4]\n \n \n \n \n Example 3:\n \n >>> numberOfChild(n = 4, k = 2)\n >>> 2\n Explanation:\n \n \n \n Time elapsed\n Children\n \n \n 0\n [0, 1, 2, 3]\n \n \n 1\n [0, 1, 2, 3]\n \n \n 2\n [0, 1, 2, 3]\n \"\"\"\n"}
{"task_id": "find-the-n-th-value-after-k-seconds", "prompt": "def valueAfterKSeconds(n: int, k: int) -> int:\n \"\"\"\n You are given two integers n and k.\n Initially, you start with an array a of n integers where a[i] = 1 for all 0 <= i <= n - 1. After each second, you simultaneously update each element to be the sum of all its preceding elements plus the element itself. For example, after one second, a[0] remains the same, a[1] becomes a[0] + a[1], a[2] becomes a[0] + a[1] + a[2], and so on.\n Return the value of a[n - 1] after k seconds.\n Since the answer may be very large, return it modulo 109 + 7.\n \n Example 1:\n \n >>> valueAfterKSeconds(n = 4, k = 5)\n >>> 56\n Explanation:\n \n \n \n Second\n State After\n \n \n 0\n [1,1,1,1]\n \n \n 1\n [1,2,3,4]\n \n \n 2\n [1,3,6,10]\n \n \n 3\n [1,4,10,20]\n \n \n 4\n [1,5,15,35]\n \n \n 5\n [1,6,21,56]\n \n \n \n \n Example 2:\n \n >>> valueAfterKSeconds(n = 5, k = 3)\n >>> 35\n Explanation:\n \n \n \n Second\n State After\n \n \n 0\n [1,1,1,1,1]\n \n \n 1\n [1,2,3,4,5]\n \n \n 2\n [1,3,6,10,15]\n \n \n 3\n [1,4,10,20,35]\n \"\"\"\n"}
{"task_id": "maximum-total-reward-using-operations-i", "prompt": "def maxTotalReward(rewardValues: List[int]) -> int:\n \"\"\"\n You are given an integer array rewardValues of length n, representing the values of rewards.\n Initially, your total reward x is 0, and all indices are unmarked. You are allowed to perform the following operation any number of times:\n \n Choose an unmarked index i from the range [0, n - 1].\n If rewardValues[i] is greater than your current total reward x, then add rewardValues[i] to x (i.e., x = x + rewardValues[i]), and mark the index i.\n \n Return an integer denoting the maximum total reward you can collect by performing the operations optimally.\n \n Example 1:\n \n >>> maxTotalReward(rewardValues = [1,1,3,3])\n >>> 4\n Explanation:\n During the operations, we can choose to mark the indices 0 and 2 in order, and the total reward will be 4, which is the maximum.\n \n Example 2:\n \n >>> maxTotalReward(rewardValues = [1,6,4,3,2])\n >>> 11\n Explanation:\n Mark the indices 0, 2, and 1 in order. The total reward will then be 11, which is the maximum.\n \"\"\"\n"}
{"task_id": "maximum-total-reward-using-operations-ii", "prompt": "def maxTotalReward(rewardValues: List[int]) -> int:\n \"\"\"\n You are given an integer array rewardValues of length n, representing the values of rewards.\n Initially, your total reward x is 0, and all indices are unmarked. You are allowed to perform the following operation any number of times:\n \n Choose an unmarked index i from the range [0, n - 1].\n If rewardValues[i] is greater than your current total reward x, then add rewardValues[i] to x (i.e., x = x + rewardValues[i]), and mark the index i.\n \n Return an integer denoting the maximum total reward you can collect by performing the operations optimally.\n \n Example 1:\n \n >>> maxTotalReward(rewardValues = [1,1,3,3])\n >>> 4\n Explanation:\n During the operations, we can choose to mark the indices 0 and 2 in order, and the total reward will be 4, which is the maximum.\n \n Example 2:\n \n >>> maxTotalReward(rewardValues = [1,6,4,3,2])\n >>> 11\n Explanation:\n Mark the indices 0, 2, and 1 in order. The total reward will then be 11, which is the maximum.\n \"\"\"\n"}
{"task_id": "the-number-of-ways-to-make-the-sum", "prompt": "def numberOfWays(n: int) -> int:\n \"\"\"\n You have an infinite number of coins with values 1, 2, and 6, and only 2 coins with value 4.\n Given an integer n, return the number of ways to make the sum of n with the coins you have.\n Since the answer may be very large, return it modulo 109 + 7.\n Note that the order of the coins doesn't matter and [2, 2, 3] is the same as [2, 3, 2].\n \n Example 1:\n \n >>> numberOfWays(n = 4)\n >>> 4\n Explanation:\n Here are the four combinations: [1, 1, 1, 1], [1, 1, 2], [2, 2], [4].\n \n Example 2:\n \n >>> numberOfWays(n = 12)\n >>> 22\n Explanation:\n Note that [4, 4, 4] is not a valid combination since we cannot use 4 three times.\n \n Example 3:\n \n >>> numberOfWays(n = 5)\n >>> 4\n Explanation:\n Here are the four combinations: [1, 1, 1, 1, 1], [1, 1, 1, 2], [1, 2, 2], [1, 4].\n \"\"\"\n"}
{"task_id": "count-pairs-that-form-a-complete-day-i", "prompt": "def countCompleteDayPairs(hours: List[int]) -> int:\n \"\"\"\n Given an integer array hours representing times in hours, return an integer denoting the number of pairs i, j where i < j and hours[i] + hours[j] forms a complete day.\n A complete day is defined as a time duration that is an exact multiple of 24 hours.\n For example, 1 day is 24 hours, 2 days is 48 hours, 3 days is 72 hours, and so on.\n \n Example 1:\n \n >>> countCompleteDayPairs(hours = [12,12,30,24,24])\n >>> 2\n Explanation:\n The pairs of indices that form a complete day are (0, 1) and (3, 4).\n \n Example 2:\n \n >>> countCompleteDayPairs(hours = [72,48,24,3])\n >>> 3\n Explanation:\n The pairs of indices that form a complete day are (0, 1), (0, 2), and (1, 2).\n \"\"\"\n"}
{"task_id": "count-pairs-that-form-a-complete-day-ii", "prompt": "def countCompleteDayPairs(hours: List[int]) -> int:\n \"\"\"\n Given an integer array hours representing times in hours, return an integer denoting the number of pairs i, j where i < j and hours[i] + hours[j] forms a complete day.\n A complete day is defined as a time duration that is an exact multiple of 24 hours.\n For example, 1 day is 24 hours, 2 days is 48 hours, 3 days is 72 hours, and so on.\n \n Example 1:\n \n >>> countCompleteDayPairs(hours = [12,12,30,24,24])\n >>> 2\n Explanation: The pairs of indices that form a complete day are (0, 1) and (3, 4).\n \n Example 2:\n \n >>> countCompleteDayPairs(hours = [72,48,24,3])\n >>> 3\n Explanation: The pairs of indices that form a complete day are (0, 1), (0, 2), and (1, 2).\n \"\"\"\n"}
{"task_id": "maximum-total-damage-with-spell-casting", "prompt": "def maximumTotalDamage(power: List[int]) -> int:\n \"\"\"\n A magician has various spells.\n You are given an array power, where each element represents the damage of a spell. Multiple spells can have the same damage value.\n It is a known fact that if a magician decides to cast a spell with a damage of power[i], they cannot cast any spell with a damage of power[i] - 2, power[i] - 1, power[i] + 1, or power[i] + 2.\n Each spell can be cast only once.\n Return the maximum possible total damage that a magician can cast.\n \n Example 1:\n \n >>> maximumTotalDamage(power = [1,1,3,4])\n >>> 6\n Explanation:\n The maximum possible damage of 6 is produced by casting spells 0, 1, 3 with damage 1, 1, 4.\n \n Example 2:\n \n >>> maximumTotalDamage(power = [7,1,6,6])\n >>> 13\n Explanation:\n The maximum possible damage of 13 is produced by casting spells 1, 2, 3 with damage 1, 6, 6.\n \"\"\"\n"}
{"task_id": "peaks-in-array", "prompt": "def countOfPeaks(nums: List[int], queries: List[List[int]]) -> List[int]:\n \"\"\"\n A peak in an array arr is an element that is greater than its previous and next element in arr.\n You are given an integer array nums and a 2D integer array queries.\n You have to process queries of two types:\n \n queries[i] = [1, li, ri], determine the count of peak elements in the subarray nums[li..ri].\n queries[i] = [2, indexi, vali], change nums[indexi] to vali.\n \n Return an array answer containing the results of the queries of the first type in order.\n Notes:\n \n The first and the last element of an array or a subarray cannot be a peak.\n \n \n Example 1:\n \n >>> countOfPeaks(nums = [3,1,4,2,5], queries = [[2,3,4],[1,0,4]])\n >>> [0]\n Explanation:\n First query: We change nums[3] to 4 and nums becomes [3,1,4,4,5].\n Second query: The number of peaks in the [3,1,4,4,5] is 0.\n \n Example 2:\n \n >>> countOfPeaks(nums = [4,1,4,2,1,5], queries = [[2,2,4],[1,0,2],[1,0,4]])\n >>> [0,1]\n Explanation:\n First query: nums[2] should become 4, but it is already set to 4.\n Second query: The number of peaks in the [4,1,4] is 0.\n Third query: The second 4 is a peak in the [4,1,4,2,1].\n \"\"\"\n"}
{"task_id": "minimum-moves-to-get-a-peaceful-board", "prompt": "def minMoves(rooks: List[List[int]]) -> int:\n \"\"\"\n Given a 2D array rooks of length n, where rooks[i] = [xi, yi] indicates the position of a rook on an n x n chess board. Your task is to move the rooks 1 cell at a time vertically or horizontally (to an adjacent cell) such that the board becomes peaceful.\n A board is peaceful if there is exactly one rook in each row and each column.\n Return the minimum number of moves required to get a peaceful board.\n Note that at no point can there be two rooks in the same cell.\n \n Example 1:\n \n >>> minMoves(rooks = [[0,0],[1,0],[1,1]])\n >>> 3\n Explanation:\n \n Example 2:\n \n >>> minMoves(rooks = [[0,0],[0,1],[0,2],[0,3]])\n >>> 6\n Explanation:\n \"\"\"\n"}
{"task_id": "find-minimum-operations-to-make-all-elements-divisible-by-three", "prompt": "def minimumOperations(nums: List[int]) -> int:\n \"\"\"\n You are given an integer array nums. In one operation, you can add or subtract 1 from any element of nums.\n Return the minimum number of operations to make all elements of nums divisible by 3.\n \n Example 1:\n \n >>> minimumOperations(nums = [1,2,3,4])\n >>> 3\n Explanation:\n All array elements can be made divisible by 3 using 3 operations:\n \n Subtract 1 from 1.\n Add 1 to 2.\n Subtract 1 from 4.\n \n \n Example 2:\n \n >>> minimumOperations(nums = [3,6,9])\n >>> 0\n \"\"\"\n"}
{"task_id": "minimum-operations-to-make-binary-array-elements-equal-to-one-i", "prompt": "def minOperations(nums: List[int]) -> int:\n \"\"\"\n You are given a binary array nums.\n You can do the following operation on the array any number of times (possibly zero):\n \n Choose any 3 consecutive elements from the array and flip all of them.\n \n Flipping an element means changing its value from 0 to 1, and from 1 to 0.\n Return the minimum number of operations required to make all elements in nums equal to 1. If it is impossible, return -1.\n \n Example 1:\n \n >>> minOperations(nums = [0,1,1,1,0,0])\n >>> 3\n Explanation:\n We can do the following operations:\n \n Choose the elements at indices 0, 1 and 2. The resulting array is nums = [1,0,0,1,0,0].\n Choose the elements at indices 1, 2 and 3. The resulting array is nums = [1,1,1,0,0,0].\n Choose the elements at indices 3, 4 and 5. The resulting array is nums = [1,1,1,1,1,1].\n \n \n Example 2:\n \n >>> minOperations(nums = [0,1,1,1])\n >>> -1\n Explanation:\n It is impossible to make all elements equal to 1.\n \"\"\"\n"}
{"task_id": "minimum-operations-to-make-binary-array-elements-equal-to-one-ii", "prompt": "def minOperations(nums: List[int]) -> int:\n \"\"\"\n You are given a binary array nums.\n You can do the following operation on the array any number of times (possibly zero):\n \n Choose any index i from the array and flip all the elements from index i to the end of the array.\n \n Flipping an element means changing its value from 0 to 1, and from 1 to 0.\n Return the minimum number of operations required to make all elements in nums equal to 1.\n \n Example 1:\n \n >>> minOperations(nums = [0,1,1,0,1])\n >>> 4\n Explanation:\n We can do the following operations:\n \n Choose the index i = 1. The resulting array will be nums = [0,0,0,1,0].\n Choose the index i = 0. The resulting array will be nums = [1,1,1,0,1].\n Choose the index i = 4. The resulting array will be nums = [1,1,1,0,0].\n Choose the index i = 3. The resulting array will be nums = [1,1,1,1,1].\n \n \n Example 2:\n \n >>> minOperations(nums = [1,0,0,0])\n >>> 1\n Explanation:\n We can do the following operation:\n \n Choose the index i = 1. The resulting array will be nums = [1,1,1,1].\n \"\"\"\n"}
{"task_id": "count-the-number-of-inversions", "prompt": "def numberOfPermutations(n: int, requirements: List[List[int]]) -> int:\n \"\"\"\n You are given an integer n and a 2D array requirements, where requirements[i] = [endi, cnti] represents the end index and the inversion count of each requirement.\n A pair of indices (i, j) from an integer array nums is called an inversion if:\n \n i < j and nums[i] > nums[j]\n \n Return the number of permutations perm of [0, 1, 2, ..., n - 1] such that for all requirements[i], perm[0..endi] has exactly cnti inversions.\n Since the answer may be very large, return it modulo 109 + 7.\n \n Example 1:\n \n >>> numberOfPermutations(n = 3, requirements = [[2,2],[0,0]])\n >>> 2\n Explanation:\n The two permutations are:\n \n [2, 0, 1]\n \n Prefix [2, 0, 1] has inversions (0, 1) and (0, 2).\n Prefix [2] has 0 inversions.\n \n \n [1, 2, 0]\n \n Prefix [1, 2, 0] has inversions (0, 2) and (1, 2).\n Prefix [1] has 0 inversions.\n \n \n \n \n Example 2:\n \n >>> numberOfPermutations(n = 3, requirements = [[2,2],[1,1],[0,0]])\n >>> 1\n Explanation:\n The only satisfying permutation is [2, 0, 1]:\n \n Prefix [2, 0, 1] has inversions (0, 1) and (0, 2).\n Prefix [2, 0] has an inversion (0, 1).\n Prefix [2] has 0 inversions.\n \n \n Example 3:\n \n >>> numberOfPermutations(n = 2, requirements = [[0,0],[1,0]])\n >>> 1\n Explanation:\n The only satisfying permutation is [0, 1]:\n \n Prefix [0] has 0 inversions.\n Prefix [0, 1] has an inversion (0, 1).\n \"\"\"\n"}
{"task_id": "minimum-average-of-smallest-and-largest-elements", "prompt": "def minimumAverage(nums: List[int]) -> float:\n \"\"\"\n You have an array of floating point numbers averages which is initially empty. You are given an array nums of n integers where n is even.\n You repeat the following procedure n / 2 times:\n \n Remove the smallest element, minElement, and the largest element maxElement,\u00a0from nums.\n Add (minElement + maxElement) / 2 to averages.\n \n Return the minimum element in averages.\n \n Example 1:\n \n >>> minimumAverage(nums = [7,8,3,4,15,13,4,1])\n >>> 5.5\n Explanation:\n \n \n \n step\n nums\n averages\n \n \n 0\n [7,8,3,4,15,13,4,1]\n []\n \n \n 1\n [7,8,3,4,13,4]\n [8]\n \n \n 2\n [7,8,4,4]\n [8,8]\n \n \n 3\n [7,4]\n [8,8,6]\n \n \n 4\n []\n [8,8,6,5.5]\n \n \n \n The smallest element of averages, 5.5, is returned.\n Example 2:\n \n >>> minimumAverage(nums = [1,9,8,3,10,5])\n >>> 5.5\n Explanation:\n \n \n \n step\n nums\n averages\n \n \n 0\n [1,9,8,3,10,5]\n []\n \n \n 1\n [9,8,3,5]\n [5.5]\n \n \n 2\n [8,5]\n [5.5,6]\n \n \n 3\n []\n [5.5,6,6.5]\n \n \n \n \n Example 3:\n \n >>> minimumAverage(nums = [1,2,3,7,8,9])\n >>> 5.0\n Explanation:\n \n \n \n step\n nums\n averages\n \n \n 0\n [1,2,3,7,8,9]\n []\n \n \n 1\n [2,3,7,8]\n [5]\n \n \n 2\n [3,7]\n [5,5]\n \n \n 3\n []\n [5,5,5]\n \"\"\"\n"}
{"task_id": "find-the-minimum-area-to-cover-all-ones-i", "prompt": "def minimumArea(grid: List[List[int]]) -> int:\n \"\"\"\n You are given a 2D binary array grid. Find a rectangle with horizontal and vertical sides with the smallest area, such that all the 1's in grid lie inside this rectangle.\n Return the minimum possible area of the rectangle.\n \n Example 1:\n \n >>> minimumArea(grid = [[0,1,0],[1,0,1]])\n >>> 6\n Explanation:\n \n The smallest rectangle has a height of 2 and a width of 3, so it has an area of 2 * 3 = 6.\n \n Example 2:\n \n >>> minimumArea(grid = [[1,0],[0,0]])\n >>> 1\n Explanation:\n \n The smallest rectangle has both height and width 1, so its area is 1 * 1 = 1.\n \"\"\"\n"}
{"task_id": "maximize-total-cost-of-alternating-subarrays", "prompt": "def maximumTotalCost(nums: List[int]) -> int:\n \"\"\"\n You are given an integer array nums with length n.\n The cost of a subarray nums[l..r], where 0 <= l <= r < n, is defined as:\n cost(l, r) = nums[l] - nums[l + 1] + ... + nums[r] * (\u22121)r \u2212 l\n Your task is to split nums into subarrays such that the total cost of the subarrays is maximized, ensuring each element belongs to exactly one subarray.\n Formally, if nums is split into k subarrays, where k > 1, at indices i1, i2, ..., ik \u2212 1, where 0 <= i1 < i2 < ... < ik - 1 < n - 1, then the total cost will be:\n cost(0, i1) + cost(i1 + 1, i2) + ... + cost(ik \u2212 1 + 1, n \u2212 1)\n Return an integer denoting the maximum total cost of the subarrays after splitting the array optimally.\n Note: If nums is not split into subarrays, i.e. k = 1, the total cost is simply cost(0, n - 1).\n \n Example 1:\n \n >>> maximumTotalCost(nums = [1,-2,3,4])\n >>> 10\n Explanation:\n One way to maximize the total cost is by splitting [1, -2, 3, 4] into subarrays [1, -2, 3] and [4]. The total cost will be (1 + 2 + 3) + 4 = 10.\n \n Example 2:\n \n >>> maximumTotalCost(nums = [1,-1,1,-1])\n >>> 4\n Explanation:\n One way to maximize the total cost is by splitting [1, -1, 1, -1] into subarrays [1, -1] and [1, -1]. The total cost will be (1 + 1) + (1 + 1) = 4.\n \n Example 3:\n \n >>> maximumTotalCost(nums = [0])\n >>> 0\n Explanation:\n We cannot split the array further, so the answer is 0.\n \n Example 4:\n \n >>> maximumTotalCost(nums = [1,-1])\n >>> 2\n Explanation:\n Selecting the whole array gives a total cost of 1 + 1 = 2, which is the maximum.\n \"\"\"\n"}
{"task_id": "find-the-minimum-area-to-cover-all-ones-ii", "prompt": "def minimumSum(grid: List[List[int]]) -> int:\n \"\"\"\n You are given a 2D binary array grid. You need to find 3 non-overlapping rectangles having non-zero areas with horizontal and vertical sides such that all the 1's in grid lie inside these rectangles.\n Return the minimum possible sum of the area of these rectangles.\n Note that the rectangles are allowed to touch.\n \n Example 1:\n \n >>> minimumSum(grid = [[1,0,1],[1,1,1]])\n >>> 5\n Explanation:\n \n \n The 1's at (0, 0) and (1, 0) are covered by a rectangle of area 2.\n The 1's at (0, 2) and (1, 2) are covered by a rectangle of area 2.\n The 1 at (1, 1) is covered by a rectangle of area 1.\n \n \n Example 2:\n \n >>> minimumSum(grid = [[1,0,1,0],[0,1,0,1]])\n >>> 5\n Explanation:\n \n \n The 1's at (0, 0) and (0, 2) are covered by a rectangle of area 3.\n The 1 at (1, 1) is covered by a rectangle of area 1.\n The 1 at (1, 3) is covered by a rectangle of area 1.\n \"\"\"\n"}
{"task_id": "count-triplets-with-even-xor-set-bits-i", "prompt": "def tripletCount(a: List[int], b: List[int], c: List[int]) -> int:\n \"\"\"\n Given three integer arrays a, b, and c, return the number of triplets (a[i], b[j], c[k]), such that the bitwise XOR of the elements of each triplet has an even number of set bits.\n \n Example 1:\n \n >>> tripletCount(a = [1], b = [2], c = [3])\n >>> 1\n Explanation:\n The only triplet is (a[0], b[0], c[0]) and their XOR is: 1 XOR 2 XOR 3 = 002.\n \n Example 2:\n \n >>> tripletCount(a = [1,1], b = [2,3], c = [1,5])\n >>> 4\n Explanation:\n Consider these four triplets:\n \n (a[0], b[1], c[0]): 1 XOR 3 XOR 1 = 0112\n (a[1], b[1], c[0]): 1 XOR 3 XOR 1 = 0112\n (a[0], b[0], c[1]): 1 XOR 2 XOR 5 = 1102\n (a[1], b[0], c[1]): 1 XOR 2 XOR 5 = 1102\n \"\"\"\n"}
{"task_id": "maximum-height-of-a-triangle", "prompt": "def maxHeightOfTriangle(red: int, blue: int) -> int:\n \"\"\"\n You are given two integers red and blue representing the count of red and blue colored balls. You have to arrange these balls to form a triangle such that the 1st row will have 1 ball, the 2nd row will have 2 balls, the 3rd row will have 3 balls, and so on.\n All the balls in a particular row should be the same color, and adjacent rows should have different colors.\n Return the maximum height of the triangle that can be achieved.\n \n Example 1:\n \n >>> maxHeightOfTriangle(red = 2, blue = 4)\n >>> 3\n Explanation:\n \n The only possible arrangement is shown above.\n \n Example 2:\n \n >>> maxHeightOfTriangle(red = 2, blue = 1)\n >>> 2\n Explanation:\n \n The only possible arrangement is shown above.\n \n Example 3:\n \n >>> maxHeightOfTriangle(red = 1, blue = 1)\n >>> 1\n \n Example 4:\n \n >>> maxHeightOfTriangle(red = 10, blue = 1)\n >>> 2\n Explanation:\n \n The only possible arrangement is shown above.\n \"\"\"\n"}
{"task_id": "find-the-maximum-length-of-valid-subsequence-i", "prompt": "def maximumLength(nums: List[int]) -> int:\n \"\"\"\n You are given an integer array nums.\n A subsequence sub of nums with length x is called valid if it satisfies:\n \n (sub[0] + sub[1]) % 2 == (sub[1] + sub[2]) % 2 == ... == (sub[x - 2] + sub[x - 1]) % 2.\n \n Return the length of the longest valid subsequence of nums.\n 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.\n \n Example 1:\n \n >>> maximumLength(nums = [1,2,3,4])\n >>> 4\n Explanation:\n The longest valid subsequence is [1, 2, 3, 4].\n \n Example 2:\n \n >>> maximumLength(nums = [1,2,1,1,2,1,2])\n >>> 6\n Explanation:\n The longest valid subsequence is [1, 2, 1, 2, 1, 2].\n \n Example 3:\n \n >>> maximumLength(nums = [1,3])\n >>> 2\n Explanation:\n The longest valid subsequence is [1, 3].\n \"\"\"\n"}
{"task_id": "find-the-maximum-length-of-valid-subsequence-ii", "prompt": "def maximumLength(nums: List[int], k: int) -> int:\n \"\"\"\n You are given an integer array nums and a positive integer k.\n A subsequence sub of nums with length x is called valid if it satisfies:\n \n (sub[0] + sub[1]) % k == (sub[1] + sub[2]) % k == ... == (sub[x - 2] + sub[x - 1]) % k.\n \n Return the length of the longest valid subsequence of nums.\n \n Example 1:\n \n >>> maximumLength(nums = [1,2,3,4,5], k = 2)\n >>> 5\n Explanation:\n The longest valid subsequence is [1, 2, 3, 4, 5].\n \n Example 2:\n \n >>> maximumLength(nums = [1,4,2,3,1,4], k = 3)\n >>> 4\n Explanation:\n The longest valid subsequence is [1, 4, 1, 4].\n \"\"\"\n"}
{"task_id": "find-minimum-diameter-after-merging-two-trees", "prompt": "def minimumDiameterAfterMerge(edges1: List[List[int]], edges2: List[List[int]]) -> int:\n \"\"\"\n There exist two undirected trees with n and m nodes, numbered from 0 to n - 1 and from 0 to m - 1, respectively. You are given two 2D integer arrays edges1 and edges2 of lengths n - 1 and m - 1, respectively, where edges1[i] = [ai, bi] indicates that there is an edge between nodes ai and bi in the first tree and edges2[i] = [ui, vi] indicates that there is an edge between nodes ui and vi in the second tree.\n You must connect one node from the first tree with another node from the second tree with an edge.\n Return the minimum possible diameter of the resulting tree.\n The diameter of a tree is the length of the longest path between any two nodes in the tree.\n \n Example 1:\n \n >>> minimumDiameterAfterMerge(edges1 = [[0,1],[0,2],[0,3]], edges2 = [[0,1]])\n >>> 3\n Explanation:\n We can obtain a tree of diameter 3 by connecting node 0 from the first tree with any node from the second tree.\n \n Example 2:\n \n \n >>> minimumDiameterAfterMerge(edges1 = [[0,1],[0,2],[0,3],[2,4],[2,5],[3,6],[2,7]], edges2 = [[0,1],[0,2],[0,3],[2,4],[2,5],[3,6],[2,7]])\n >>> 5\n Explanation:\n We can obtain a tree of diameter 5 by connecting node 0 from the first tree with node 0 from the second tree.\n \"\"\"\n"}
{"task_id": "maximum-array-hopping-score-i", "prompt": "def maxScore(nums: List[int]) -> int:\n \"\"\"\n Given an array nums, you have to get the maximum score starting from index 0 and hopping until you reach the last element of the array.\n In each hop, you can jump from index i to an index j > i, and you get a score of (j - i) * nums[j].\n Return the maximum score you can get.\n \n Example 1:\n \n >>> maxScore(nums = [1,5,8])\n >>> 16\n Explanation:\n There are two possible ways to reach the last element:\n \n 0 -> 1 -> 2 with a score of\u00a0(1 - 0) * 5 + (2 - 1) * 8 = 13.\n 0 -> 2 with a score of\u00a0(2 - 0) * 8 =\u00a016.\n \n \n Example 2:\n \n >>> maxScore(nums = [4,5,2,8,9,1,3])\n >>> 42\n Explanation:\n We can do the hopping 0 -> 4 -> 6 with a score of\u00a0(4 - 0) * 9 + (6 - 4) * 3 = 42.\n \"\"\"\n"}
{"task_id": "alternating-groups-i", "prompt": "def numberOfAlternatingGroups(colors: List[int]) -> int:\n \"\"\"\n There is a circle of red and blue tiles. You are given an array of integers colors. The color of tile i is represented by colors[i]:\n \n colors[i] == 0 means that tile i is red.\n colors[i] == 1 means that tile i is blue.\n \n Every 3 contiguous tiles in the circle with alternating colors (the middle tile has a different color from its left and right tiles) is called an alternating group.\n Return the number of alternating groups.\n Note that since colors represents a circle, the first and the last tiles are considered to be next to each other.\n \n Example 1:\n \n >>> numberOfAlternatingGroups(colors = [1,1,1])\n >>> 0\n Explanation:\n \n \n Example 2:\n \n >>> numberOfAlternatingGroups(colors = [0,1,0,0,1])\n >>> 3\n Explanation:\n \n Alternating groups:\n \"\"\"\n"}
{"task_id": "maximum-points-after-enemy-battles", "prompt": "def maximumPoints(enemyEnergies: List[int], currentEnergy: int) -> int:\n \"\"\"\n You are given an integer array enemyEnergies denoting the energy values of various enemies.\n You are also given an integer currentEnergy denoting the amount of energy you have initially.\n You start with 0 points, and all the enemies are unmarked initially.\n You can perform either of the following operations zero or multiple times to gain points:\n \n Choose an unmarked enemy, i, such that currentEnergy >= enemyEnergies[i]. By choosing this option:\n \n \n You gain 1 point.\n Your energy is reduced by the enemy's energy, i.e. currentEnergy = currentEnergy - enemyEnergies[i].\n \n \n If you have at least 1 point, you can choose an unmarked enemy, i. By choosing this option:\n \n Your energy increases by the enemy's energy, i.e. currentEnergy = currentEnergy + enemyEnergies[i].\n The enemy i is marked.\n \n \n \n Return an integer denoting the maximum points you can get in the end by optimally performing operations.\n \n Example 1:\n \n >>> maximumPoints(enemyEnergies = [3,2,2], currentEnergy = 2)\n >>> 3\n Explanation:\n The following operations can be performed to get 3 points, which is the maximum:\n \n First operation on enemy 1: points increases by 1, and currentEnergy decreases by 2. So, points = 1, and currentEnergy = 0.\n Second operation on enemy 0: currentEnergy increases by 3, and enemy 0 is marked. So, points = 1, currentEnergy = 3, and marked enemies = [0].\n First operation on enemy 2: points increases by 1, and currentEnergy decreases by 2. So, points = 2, currentEnergy = 1, and marked enemies = [0].\n Second operation on enemy 2: currentEnergy increases by 2, and enemy 2 is marked. So, points = 2, currentEnergy = 3, and marked enemies = [0, 2].\n First operation on enemy 1: points increases by 1, and currentEnergy decreases by 2. So, points = 3, currentEnergy = 1, and marked enemies = [0, 2].\n \n \n Example 2:\n \n >>> maximumPoints(enemyEnergies = [2], currentEnergy = 10)\n >>> 5\n Explanation:\n Performing the first operation 5 times on enemy 0 results in the maximum number of points.\n \"\"\"\n"}
{"task_id": "alternating-groups-ii", "prompt": "def numberOfAlternatingGroups(colors: List[int], k: int) -> int:\n \"\"\"\n There is a circle of red and blue tiles. You are given an array of integers colors and an integer k. The color of tile i is represented by colors[i]:\n \n colors[i] == 0 means that tile i is red.\n colors[i] == 1 means that tile i is blue.\n \n An alternating group is every k contiguous tiles in the circle with alternating colors (each tile in the group except the first and last one has a different color from its left and right tiles).\n Return the number of alternating groups.\n Note that since colors represents a circle, the first and the last tiles are considered to be next to each other.\n \n Example 1:\n \n >>> numberOfAlternatingGroups(colors = [0,1,0,1,0], k = 3)\n >>> 3\n Explanation:\n \n Alternating groups:\n \n \n Example 2:\n \n >>> numberOfAlternatingGroups(colors = [0,1,0,0,1,0,1], k = 6)\n >>> 2\n Explanation:\n \n Alternating groups:\n \n \n Example 3:\n \n >>> numberOfAlternatingGroups(colors = [1,1,0,1], k = 4)\n >>> 0\n Explanation:\n \"\"\"\n"}
{"task_id": "number-of-subarrays-with-and-value-of-k", "prompt": "def countSubarrays(nums: List[int], k: int) -> int:\n \"\"\"\n Given an array of integers nums and an integer k, return the number of subarrays of nums where the bitwise AND of the elements of the subarray equals k.\n \n Example 1:\n \n >>> countSubarrays(nums = [1,1,1], k = 1)\n >>> 6\n Explanation:\n All subarrays contain only 1's.\n \n Example 2:\n \n >>> countSubarrays(nums = [1,1,2], k = 1)\n >>> 3\n Explanation:\n Subarrays having an AND value of 1 are: [1,1,2], [1,1,2], [1,1,2].\n \n Example 3:\n \n >>> countSubarrays(nums = [1,2,3], k = 2)\n >>> 2\n Explanation:\n Subarrays having an AND value of 2 are: [1,2,3], [1,2,3].\n \"\"\"\n"}
{"task_id": "find-the-encrypted-string", "prompt": "def getEncryptedString(s: str, k: int) -> str:\n \"\"\"\n You are given a string s and an integer k. Encrypt the string using the following algorithm:\n \n For each character c in s, replace c with the kth character after c in the string (in a cyclic manner).\n \n Return the encrypted string.\n \n Example 1:\n \n >>> getEncryptedString(s = \"dart\", k = 3)\n >>> \"tdar\"\n Explanation:\n \n For i = 0, the 3rd character after 'd' is 't'.\n For i = 1, the 3rd character after 'a' is 'd'.\n For i = 2, the 3rd character after 'r' is 'a'.\n For i = 3, the 3rd character after 't' is 'r'.\n \n \n Example 2:\n \n >>> getEncryptedString(s = \"aaa\", k = 1)\n >>> \"aaa\"\n Explanation:\n As all the characters are the same, the encrypted string will also be the same.\n \"\"\"\n"}
{"task_id": "generate-binary-strings-without-adjacent-zeros", "prompt": "def validStrings(n: int) -> List[str]:\n \"\"\"\n You are given a positive integer n.\n A binary string x is valid if all substrings of x of length 2 contain at least one \"1\".\n Return all valid strings with length n, in any order.\n \n Example 1:\n \n >>> validStrings(n = 3)\n >>> [\"010\",\"011\",\"101\",\"110\",\"111\"]\n Explanation:\n The valid strings of length 3 are: \"010\", \"011\", \"101\", \"110\", and \"111\".\n \n Example 2:\n \n >>> validStrings(n = 1)\n >>> [\"0\",\"1\"]\n Explanation:\n The valid strings of length 1 are: \"0\" and \"1\".\n \"\"\"\n"}
{"task_id": "count-submatrices-with-equal-frequency-of-x-and-y", "prompt": "def numberOfSubmatrices(grid: List[List[str]]) -> int:\n \"\"\"\n Given a 2D character matrix grid, where grid[i][j] is either 'X', 'Y', or '.', return the number of submatrices that contain:\n \n grid[0][0]\n an equal frequency of 'X' and 'Y'.\n at least one 'X'.\n \n \n Example 1:\n \n >>> numberOfSubmatrices(grid = [[\"X\",\"Y\",\".\"],[\"Y\",\".\",\".\"]])\n >>> 3\n Explanation:\n \n \n Example 2:\n \n >>> numberOfSubmatrices(grid = [[\"X\",\"X\"],[\"X\",\"Y\"]])\n >>> 0\n Explanation:\n No submatrix has an equal frequency of 'X' and 'Y'.\n \n Example 3:\n \n >>> numberOfSubmatrices(grid = [[\".\",\".\"],[\".\",\".\"]])\n >>> 0\n Explanation:\n No submatrix has at least one 'X'.\n \"\"\"\n"}
{"task_id": "construct-string-with-minimum-cost", "prompt": "def minimumCost(target: str, words: List[str], costs: List[int]) -> int:\n \"\"\"\n You are given a string target, an array of strings words, and an integer array costs, both arrays of the same length.\n Imagine an empty string s.\n You can perform the following operation any number of times (including zero):\n \n Choose an index i in the range [0, words.length - 1].\n Append words[i] to s.\n The cost of operation is costs[i].\n \n Return the minimum cost to make s equal to target. If it's not possible, return -1.\n \n Example 1:\n \n >>> minimumCost(target = \"abcdef\", words = [\"abdef\",\"abc\",\"d\",\"def\",\"ef\"], costs = [100,1,1,10,5])\n >>> 7\n Explanation:\n The minimum cost can be achieved by performing the following operations:\n \n Select index 1 and append \"abc\" to s at a cost of 1, resulting in s = \"abc\".\n Select index 2 and append \"d\" to s at a cost of 1, resulting in s = \"abcd\".\n Select index 4 and append \"ef\" to s at a cost of 5, resulting in s = \"abcdef\".\n \n \n Example 2:\n \n >>> minimumCost(target = \"aaaa\", words = [\"z\",\"zz\",\"zzz\"], costs = [1,10,100])\n >>> -1\n Explanation:\n It is impossible to make s equal to target, so we return -1.\n \"\"\"\n"}
{"task_id": "count-triplets-with-even-xor-set-bits-ii", "prompt": "def tripletCount(a: List[int], b: List[int], c: List[int]) -> int:\n \"\"\"\n Given three integer arrays a, b, and c, return the number of triplets (a[i], b[j], c[k]), such that the bitwise XOR between the elements of each triplet has an even number of set bits.\n \n Example 1:\n \n >>> tripletCount(a = [1], b = [2], c = [3])\n >>> 1\n Explanation:\n The only triplet is (a[0], b[0], c[0]) and their XOR is: 1 XOR 2 XOR 3 = 002.\n \n Example 2:\n \n >>> tripletCount(a = [1,1], b = [2,3], c = [1,5])\n >>> 4\n Explanation:\n Consider these four triplets:\n \n (a[0], b[1], c[0]): 1 XOR 3 XOR 1 = 0112\n (a[1], b[1], c[0]): 1 XOR 3 XOR 1 = 0112\n (a[0], b[0], c[1]): 1 XOR 2 XOR 5 = 1102\n (a[1], b[0], c[1]): 1 XOR 2 XOR 5 = 1102\n \"\"\"\n"}
{"task_id": "lexicographically-smallest-string-after-a-swap", "prompt": "def getSmallestString(s: str) -> str:\n \"\"\"\n Given a string s containing only digits, return the lexicographically smallest string that can be obtained after swapping adjacent digits in s with the same parity at most once.\n Digits have the same parity if both are odd or both are even. For example, 5 and 9, as well as 2 and 4, have the same parity, while 6 and 9 do not.\n \n Example 1:\n \n >>> getSmallestString(s = \"45320\")\n >>> \"43520\"\n Explanation:\n s[1] == '5' and s[2] == '3' both have the same parity, and swapping them results in the lexicographically smallest string.\n \n Example 2:\n \n >>> getSmallestString(s = \"001\")\n >>> \"001\"\n Explanation:\n There is no need to perform a swap because s is already the lexicographically smallest.\n \"\"\"\n"}
{"task_id": "delete-nodes-from-linked-list-present-in-array", "prompt": "# class ListNode:\n# def __init__(val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution:\n def modifiedList(nums: List[int], head: Optional[ListNode]) -> Optional[ListNode]:\n \"\"\"\n You are given an array of integers nums and the head of a linked list. Return the head of the modified linked list after removing all nodes from the linked list that have a value that exists in nums.\n \n Example 1:\n \n >>> __init__(nums = [1,2,3], head = [1,2,3,4,5])\n >>> [4,5]\n Explanation:\n \n Remove the nodes with values 1, 2, and 3.\n \n Example 2:\n \n >>> __init__(nums = [1], head = [1,2,1,2,1,2])\n >>> [2,2,2]\n Explanation:\n \n Remove the nodes with value 1.\n \n Example 3:\n \n >>> __init__(nums = [5], head = [1,2,3,4])\n >>> [1,2,3,4]\n Explanation:\n \n No node has value 5.\n \"\"\"\n"}
{"task_id": "minimum-cost-for-cutting-cake-i", "prompt": "def minimumCost(m: int, n: int, horizontalCut: List[int], verticalCut: List[int]) -> int:\n \"\"\"\n There is an m x n cake that needs to be cut into 1 x 1 pieces.\n You are given integers m, n, and two arrays:\n \n horizontalCut of size m - 1, where horizontalCut[i] represents the cost to cut along the horizontal line i.\n verticalCut of size n - 1, where verticalCut[j] represents the cost to cut along the vertical line j.\n \n In one operation, you can choose any piece of cake that is not yet a 1 x 1 square and perform one of the following cuts:\n \n Cut along a horizontal line i at a cost of horizontalCut[i].\n Cut along a vertical line j at a cost of verticalCut[j].\n \n After the cut, the piece of cake is divided into two distinct pieces.\n The cost of a cut depends only on the initial cost of the line and does not change.\n Return the minimum total cost to cut the entire cake into 1 x 1 pieces.\n \n Example 1:\n \n >>> minimumCost(m = 3, n = 2, horizontalCut = [1,3], verticalCut = [5])\n >>> 13\n Explanation:\n \n \n Perform a cut on the vertical line 0 with cost 5, current total cost is 5.\n Perform a cut on the horizontal line 0 on 3 x 1 subgrid with cost 1.\n Perform a cut on the horizontal line 0 on 3 x 1 subgrid with cost 1.\n Perform a cut on the horizontal line 1 on 2 x 1 subgrid with cost 3.\n Perform a cut on the horizontal line 1 on 2 x 1 subgrid with cost 3.\n \n The total cost is 5 + 1 + 1 + 3 + 3 = 13.\n \n Example 2:\n \n >>> minimumCost(m = 2, n = 2, horizontalCut = [7], verticalCut = [4])\n >>> 15\n Explanation:\n \n Perform a cut on the horizontal line 0 with cost 7.\n Perform a cut on the vertical line 0 on 1 x 2 subgrid with cost 4.\n Perform a cut on the vertical line 0 on 1 x 2 subgrid with cost 4.\n \n The total cost is 7 + 4 + 4 = 15.\n \"\"\"\n"}
{"task_id": "minimum-cost-for-cutting-cake-ii", "prompt": "def minimumCost(m: int, n: int, horizontalCut: List[int], verticalCut: List[int]) -> int:\n \"\"\"\n There is an m x n cake that needs to be cut into 1 x 1 pieces.\n You are given integers m, n, and two arrays:\n \n horizontalCut of size m - 1, where horizontalCut[i] represents the cost to cut along the horizontal line i.\n verticalCut of size n - 1, where verticalCut[j] represents the cost to cut along the vertical line j.\n \n In one operation, you can choose any piece of cake that is not yet a 1 x 1 square and perform one of the following cuts:\n \n Cut along a horizontal line i at a cost of horizontalCut[i].\n Cut along a vertical line j at a cost of verticalCut[j].\n \n After the cut, the piece of cake is divided into two distinct pieces.\n The cost of a cut depends only on the initial cost of the line and does not change.\n Return the minimum total cost to cut the entire cake into 1 x 1 pieces.\n \n Example 1:\n \n >>> minimumCost(m = 3, n = 2, horizontalCut = [1,3], verticalCut = [5])\n >>> 13\n Explanation:\n \n \n Perform a cut on the vertical line 0 with cost 5, current total cost is 5.\n Perform a cut on the horizontal line 0 on 3 x 1 subgrid with cost 1.\n Perform a cut on the horizontal line 0 on 3 x 1 subgrid with cost 1.\n Perform a cut on the horizontal line 1 on 2 x 1 subgrid with cost 3.\n Perform a cut on the horizontal line 1 on 2 x 1 subgrid with cost 3.\n \n The total cost is 5 + 1 + 1 + 3 + 3 = 13.\n \n Example 2:\n \n >>> minimumCost(m = 2, n = 2, horizontalCut = [7], verticalCut = [4])\n >>> 15\n Explanation:\n \n Perform a cut on the horizontal line 0 with cost 7.\n Perform a cut on the vertical line 0 on 1 x 2 subgrid with cost 4.\n Perform a cut on the vertical line 0 on 1 x 2 subgrid with cost 4.\n \n The total cost is 7 + 4 + 4 = 15.\n \"\"\"\n"}
{"task_id": "maximum-array-hopping-score-ii", "prompt": "def maxScore(nums: List[int]) -> int:\n \"\"\"\n Given an array nums, you have to get the maximum score starting from index 0 and hopping until you reach the last element of the array.\n In each hop, you can jump from index i to an index j > i, and you get a score of (j - i) * nums[j].\n Return the maximum score you can get.\n \n Example 1:\n \n >>> maxScore(nums = [1,5,8])\n >>> 16\n Explanation:\n There are two possible ways to reach the last element:\n \n 0 -> 1 -> 2 with a score of (1 - 0) * 5 + (2 - 1) * 8 = 13.\n 0 -> 2 with a score of (2 - 0) * 8 = 16.\n \n \n Example 2:\n \n >>> maxScore(nums = [4,5,2,8,9,1,3])\n >>> 42\n Explanation:\n We can do the hopping 0 -> 4 -> 6 with a score of\u00a0(4 - 0) * 9 + (6 - 4) * 3 = 42.\n \"\"\"\n"}
{"task_id": "find-the-winning-player-in-coin-game", "prompt": "def winningPlayer(x: int, y: int) -> str:\n \"\"\"\n You are given two positive integers x and y, denoting the number of coins with values 75 and 10 respectively.\n Alice and Bob are playing a game. Each turn, starting with Alice, the player must pick up coins with a total value 115. If the player is unable to do so, they lose the game.\n Return the name of the player who wins the game if both players play optimally.\n \n Example 1:\n \n >>> winningPlayer(x = 2, y = 7)\n >>> \"Alice\"\n Explanation:\n The game ends in a single turn:\n \n Alice picks 1 coin with a value of 75 and 4 coins with a value of 10.\n \n \n Example 2:\n \n >>> winningPlayer(x = 4, y = 11)\n >>> \"Bob\"\n Explanation:\n The game ends in 2 turns:\n \n Alice picks 1 coin with a value of 75 and 4 coins with a value of 10.\n Bob picks 1 coin with a value of 75 and 4 coins with a value of 10.\n \"\"\"\n"}
{"task_id": "minimum-length-of-string-after-operations", "prompt": "def minimumLength(s: str) -> int:\n \"\"\"\n You are given a string s.\n You can perform the following process on s any number of times:\n \n Choose an index i in the string such that there is at least one character to the left of index i that is equal to s[i], and at least one character to the right that is also equal to s[i].\n Delete the closest occurrence of s[i] located to the left of i.\n Delete the closest occurrence of s[i] located to the right of i.\n \n Return the minimum length of the final string s that you can achieve.\n \n Example 1:\n \n >>> minimumLength(s = \"abaacbcbb\")\n >>> 5\n Explanation:\n We do the following operations:\n \n Choose index 2, then remove the characters at indices 0 and 3. The resulting string is s = \"bacbcbb\".\n Choose index 3, then remove the characters at indices 0 and 5. The resulting string is s = \"acbcb\".\n \n \n Example 2:\n \n >>> minimumLength(s = \"aa\")\n >>> 2\n Explanation:\n We cannot perform any operations, so we return the length of the original string.\n \"\"\"\n"}
{"task_id": "minimum-array-changes-to-make-differences-equal", "prompt": "def minChanges(nums: List[int], k: int) -> int:\n \"\"\"\n You are given an integer array nums of size n where n is even, and an integer k.\n You can perform some changes on the array, where in one change you can replace any element in the array with any integer in the range from 0 to k.\n You need to perform some changes (possibly none) such that the final array satisfies the following condition:\n \n There exists an integer X such that abs(a[i] - a[n - i - 1]) = X for all (0 <= i < n).\n \n Return the minimum number of changes required to satisfy the above condition.\n \n Example 1:\n \n >>> minChanges(nums = [1,0,1,2,4,3], k = 4)\n >>> 2\n Explanation:\n We can perform the following changes:\n \n Replace nums[1] by 2. The resulting array is nums = [1,2,1,2,4,3].\n Replace nums[3] by 3. The resulting array is nums = [1,2,1,3,4,3].\n \n The integer X will be 2.\n \n Example 2:\n \n >>> minChanges(nums = [0,1,2,3,3,6,5,4], k = 6)\n >>> 2\n Explanation:\n We can perform the following operations:\n \n Replace nums[3] by 0. The resulting array is nums = [0,1,2,0,3,6,5,4].\n Replace nums[4] by 4. The resulting array is nums = [0,1,2,0,4,6,5,4].\n \n The integer X will be 4.\n \"\"\"\n"}
{"task_id": "maximum-score-from-grid-operations", "prompt": "def maximumScore(grid: List[List[int]]) -> int:\n \"\"\"\n You are given a 2D matrix grid of size n x n. Initially, all cells of the grid are colored white. In one operation, you can select any cell of indices (i, j), and color black all the cells of the jth column starting from the top row down to the ith row.\n The grid score is the sum of all grid[i][j] such that cell (i, j) is white and it has a horizontally adjacent black cell.\n Return the maximum score that can be achieved after some number of operations.\n \n Example 1:\n \n >>> maximumScore(grid = [[0,0,0,0,0],[0,0,3,0,0],[0,1,0,0,0],[5,0,0,3,0],[0,0,0,0,2]])\n >>> 11\n Explanation:\n \n In the first operation, we color all cells in column 1 down to row 3, and in the second operation, we color all cells in column 4 down to the last row. The score of the resulting grid is grid[3][0] + grid[1][2] + grid[3][3] which is equal to 11.\n \n Example 2:\n \n >>> maximumScore(grid = [[10,9,0,0,15],[7,1,0,8,0],[5,20,0,11,0],[0,0,0,1,2],[8,12,1,10,3]])\n >>> 94\n Explanation:\n \n We perform operations on 1, 2, and 3 down to rows 1, 4, and 0, respectively. The score of the resulting grid is grid[0][0] + grid[1][0] + grid[2][1] + grid[4][1] + grid[1][3] + grid[2][3] + grid[3][3] + grid[4][3] + grid[0][4] which is equal to 94.\n \"\"\"\n"}
{"task_id": "number-of-bit-changes-to-make-two-integers-equal", "prompt": "def minChanges(n: int, k: int) -> int:\n \"\"\"\n You are given two positive integers n and k.\n You can choose any bit in the binary representation of n that is equal to 1 and change it to 0.\n Return the number of changes needed to make n equal to k. If it is impossible, return -1.\n \n Example 1:\n \n >>> minChanges(n = 13, k = 4)\n >>> 2\n Explanation:\n Initially, the binary representations of n and k are n = (1101)2 and k = (0100)2.\n We can change the first and fourth bits of n. The resulting integer is n = (0100)2 = k.\n \n Example 2:\n \n >>> minChanges(n = 21, k = 21)\n >>> 0\n Explanation:\n n and k are already equal, so no changes are needed.\n \n Example 3:\n \n >>> minChanges(n = 14, k = 13)\n >>> -1\n Explanation:\n It is not possible to make n equal to k.\n \"\"\"\n"}
{"task_id": "vowels-game-in-a-string", "prompt": "def doesAliceWin(s: str) -> bool:\n \"\"\"\n Alice and Bob are playing a game on a string.\n You are given a string s, Alice and Bob will take turns playing the following game where Alice starts first:\n \n On Alice's turn, she has to remove any non-empty substring from s that contains an odd number of vowels.\n On Bob's turn, he has to remove any non-empty substring from s that contains an even number of vowels.\n \n The first player who cannot make a move on their turn loses the game. We assume that both Alice and Bob play optimally.\n Return true if Alice wins the game, and false otherwise.\n The English vowels are: a, e, i, o, and u.\n \n Example 1:\n \n >>> doesAliceWin(s = \"leetcoder\")\n >>> true\n Explanation:\n Alice can win the game as follows:\n \n Alice plays first, she can delete the underlined substring in s = \"leetcoder\" which contains 3 vowels. The resulting string is s = \"der\".\n Bob plays second, he can delete the underlined substring in s = \"der\" which contains 0 vowels. The resulting string is s = \"er\".\n Alice plays third, she can delete the whole string s = \"er\" which contains 1 vowel.\n Bob plays fourth, since the string is empty, there is no valid play for Bob. So Alice wins the game.\n \n \n Example 2:\n \n >>> doesAliceWin(s = \"bbcd\")\n >>> false\n Explanation:\n There is no valid play for Alice in her first turn, so Alice loses the game.\n \"\"\"\n"}
{"task_id": "maximum-number-of-operations-to-move-ones-to-the-end", "prompt": "def maxOperations(s: str) -> int:\n \"\"\"\n You are given a binary string s.\n You can perform the following operation on the string any number of times:\n \n Choose any index i from the string where i + 1 < s.length such that s[i] == '1' and s[i + 1] == '0'.\n Move the character s[i] to the right until it reaches the end of the string or another '1'. For example, for s = \"010010\", if we choose i = 1, the resulting string will be s = \"000110\".\n \n Return the maximum number of operations that you can perform.\n \n Example 1:\n \n >>> maxOperations(s = \"1001101\")\n >>> 4\n Explanation:\n We can perform the following operations:\n \n Choose index i = 0. The resulting string is s = \"0011101\".\n Choose index i = 4. The resulting string is s = \"0011011\".\n Choose index i = 3. The resulting string is s = \"0010111\".\n Choose index i = 2. The resulting string is s = \"0001111\".\n \n \n Example 2:\n \n >>> maxOperations(s = \"00111\")\n >>> 0\n \"\"\"\n"}
{"task_id": "minimum-operations-to-make-array-equal-to-target", "prompt": "def minimumOperations(nums: List[int], target: List[int]) -> int:\n \"\"\"\n You are given two positive integer arrays nums and target, of the same length.\n In a single operation, you can select any subarray of nums and increment each element within that subarray by 1 or decrement each element within that subarray by 1.\n Return the minimum number of operations required to make nums equal to the array target.\n \n Example 1:\n \n >>> minimumOperations(nums = [3,5,1,2], target = [4,6,2,4])\n >>> 2\n Explanation:\n We will perform the following operations to make nums equal to target:\n - Increment\u00a0nums[0..3] by 1, nums = [4,6,2,3].\n - Increment\u00a0nums[3..3] by 1, nums = [4,6,2,4].\n \n Example 2:\n \n >>> minimumOperations(nums = [1,3,2], target = [2,1,4])\n >>> 5\n Explanation:\n We will perform the following operations to make nums equal to target:\n - Increment\u00a0nums[0..0] by 1, nums = [2,3,2].\n - Decrement\u00a0nums[1..1] by 1, nums = [2,2,2].\n - Decrement\u00a0nums[1..1] by 1, nums = [2,1,2].\n - Increment\u00a0nums[2..2] by 1, nums = [2,1,3].\n - Increment\u00a0nums[2..2] by 1, nums = [2,1,4].\n \"\"\"\n"}
{"task_id": "minimum-number-of-increasing-subsequence-to-be-removed", "prompt": "def minOperations(nums: List[int]) -> int:\n \"\"\"\n Given an array of integers nums, you are allowed to perform the following operation any number of times:\n \n Remove a strictly increasing subsequence from the array.\n \n Your task is to find the minimum number of operations required to make the array empty.\n \n Example 1:\n \n >>> minOperations(nums = [5,3,1,4,2])\n >>> 3\n Explanation:\n We remove subsequences [1, 2], [3, 4], [5].\n \n Example 2:\n \n >>> minOperations(nums = [1,2,3,4,5])\n >>> 1\n \n Example 3:\n \n >>> minOperations(nums = [5,4,3,2,1])\n >>> 5\n \"\"\"\n"}
{"task_id": "find-if-digit-game-can-be-won", "prompt": "def canAliceWin(nums: List[int]) -> bool:\n \"\"\"\n You are given an array of positive integers nums.\n Alice and Bob are playing a game. In the game, Alice can choose either all single-digit numbers or all double-digit numbers from nums, and the rest of the numbers are given to Bob. Alice wins if the sum of her numbers is strictly greater than the sum of Bob's numbers.\n Return true if Alice can win this game, otherwise, return false.\n \n Example 1:\n \n >>> canAliceWin(nums = [1,2,3,4,10])\n >>> false\n Explanation:\n Alice cannot win by choosing either single-digit or double-digit numbers.\n \n Example 2:\n \n >>> canAliceWin(nums = [1,2,3,4,5,14])\n >>> true\n Explanation:\n Alice can win by choosing single-digit numbers which have a sum equal to 15.\n \n Example 3:\n \n >>> canAliceWin(nums = [5,5,5,25])\n >>> true\n Explanation:\n Alice can win by choosing double-digit numbers which have a sum equal to 25.\n \"\"\"\n"}
{"task_id": "find-the-count-of-numbers-which-are-not-special", "prompt": "def nonSpecialCount(l: int, r: int) -> int:\n \"\"\"\n You are given 2 positive integers l and r. For any number x, all positive divisors of x except x are called the proper divisors of x.\n A number is called special if it has exactly 2 proper divisors. For example:\n \n The number 4 is special because it has proper divisors 1 and 2.\n The number 6 is not special because it has proper divisors 1, 2, and 3.\n \n Return the count of numbers in the range [l, r] that are not special.\n \n Example 1:\n \n >>> nonSpecialCount(l = 5, r = 7)\n >>> 3\n Explanation:\n There are no special numbers in the range [5, 7].\n \n Example 2:\n \n >>> nonSpecialCount(l = 4, r = 16)\n >>> 11\n Explanation:\n The special numbers in the range [4, 16] are 4 and 9.\n \"\"\"\n"}
{"task_id": "count-the-number-of-substrings-with-dominant-ones", "prompt": "def numberOfSubstrings(s: str) -> int:\n \"\"\"\n You are given a binary string s.\n Return the number of substrings with dominant ones.\n A string has dominant ones if the number of ones in the string is greater than or equal to the square of the number of zeros in the string.\n \n Example 1:\n \n >>> numberOfSubstrings(s = \"00011\")\n >>> 5\n Explanation:\n The substrings with dominant ones are shown in the table below.\n \n \n \n \n i\n j\n s[i..j]\n Number of Zeros\n Number of Ones\n \n \n \n \n 3\n 3\n 1\n 0\n 1\n \n \n 4\n 4\n 1\n 0\n 1\n \n \n 2\n 3\n 01\n 1\n 1\n \n \n 3\n 4\n 11\n 0\n 2\n \n \n 2\n 4\n 011\n 1\n 2\n \n \n \n Example 2:\n \n >>> numberOfSubstrings(s = \"101101\")\n >>> 16\n Explanation:\n The substrings with non-dominant ones are shown in the table below.\n Since there are 21 substrings total and 5 of them have non-dominant ones, it follows that there are 16 substrings with dominant ones.\n \n \n \n \n i\n j\n s[i..j]\n Number of Zeros\n Number of Ones\n \n \n \n \n 1\n 1\n 0\n 1\n 0\n \n \n 4\n 4\n 0\n 1\n 0\n \n \n 1\n 4\n 0110\n 2\n 2\n \n \n 0\n 4\n 10110\n 2\n 3\n \n \n 1\n 5\n 01101\n 2\n 3\n \"\"\"\n"}
{"task_id": "check-if-the-rectangle-corner-is-reachable", "prompt": "def canReachCorner(xCorner: int, yCorner: int, circles: List[List[int]]) -> bool:\n \"\"\"\n You are given two positive integers xCorner and yCorner, and a 2D array circles, where circles[i] = [xi, yi, ri] denotes a circle with center at (xi, yi) and radius ri.\n There is a rectangle in the coordinate plane with its bottom left corner at the origin and top right corner at the coordinate (xCorner, yCorner). You need to check whether there is a path from the bottom left corner to the top right corner such that the entire path lies inside the rectangle, does not touch or lie inside any circle, and touches the rectangle only at the two corners.\n Return true if such a path exists, and false otherwise.\n \n Example 1:\n \n >>> canReachCorner(xCorner = 3, yCorner = 4, circles = [[2,1,1]])\n >>> true\n Explanation:\n \n The black curve shows a possible path between (0, 0) and (3, 4).\n \n Example 2:\n \n >>> canReachCorner(xCorner = 3, yCorner = 3, circles = [[1,1,2]])\n >>> false\n Explanation:\n \n No path exists from (0, 0) to (3, 3).\n \n Example 3:\n \n >>> canReachCorner(xCorner = 3, yCorner = 3, circles = [[2,1,1],[1,2,1]])\n >>> false\n Explanation:\n \n No path exists from (0, 0) to (3, 3).\n \n Example 4:\n \n >>> canReachCorner(xCorner = 4, yCorner = 4, circles = [[5,5,1]])\n >>> true\n Explanation:\n \"\"\"\n"}
{"task_id": "alt-and-tab-simulation", "prompt": "def simulationResult(windows: List[int], queries: List[int]) -> List[int]:\n \"\"\"\n There are n windows open numbered from 1 to n, we want to simulate using alt + tab to navigate between the windows.\n You are given an array windows which contains the initial order of the windows (the first element is at the top and the last one is at the bottom).\n You are also given an array queries where for each query, the window queries[i] is brought to the top.\n Return the final state of the array windows.\n \n Example 1:\n \n >>> simulationResult(windows = [1,2,3], queries = [3,3,2])\n >>> [2,3,1]\n Explanation:\n Here is the window array after each query:\n \n Initial order: [1,2,3]\n After the first query: [3,1,2]\n After the second query: [3,1,2]\n After the last query: [2,3,1]\n \n \n Example 2:\n \n >>> simulationResult(windows = [1,4,2,3], queries = [4,1,3])\n >>> [3,1,4,2]\n Explanation:\n Here is the window array after each query:\n \n Initial order: [1,4,2,3]\n After the first query: [4,1,2,3]\n After the second query: [1,4,2,3]\n After the last query: [3,1,4,2]\n \"\"\"\n"}
{"task_id": "find-the-number-of-winning-players", "prompt": "def winningPlayerCount(n: int, pick: List[List[int]]) -> int:\n \"\"\"\n You are given an integer n representing the number of players in a game and a 2D array pick where pick[i] = [xi, yi] represents that the player xi picked a ball of color yi.\n Player i wins the game if they pick strictly more than i balls of the same color. In other words,\n \n Player 0 wins if they pick any ball.\n Player 1 wins if they pick at least two balls of the same color.\n ...\n Player i wins if they pick at leasti + 1 balls of the same color.\n \n Return the number of players who win the game.\n Note that multiple players can win the game.\n \n Example 1:\n \n >>> winningPlayerCount(n = 4, pick = [[0,0],[1,0],[1,0],[2,1],[2,1],[2,0]])\n >>> 2\n Explanation:\n Player 0 and player 1 win the game, while players 2 and 3 do not win.\n \n Example 2:\n \n >>> winningPlayerCount(n = 5, pick = [[1,1],[1,2],[1,3],[1,4]])\n >>> 0\n Explanation:\n No player wins the game.\n \n Example 3:\n \n >>> winningPlayerCount(n = 5, pick = [[1,1],[2,4],[2,4],[2,4]])\n >>> 1\n Explanation:\n Player 2 wins the game by picking 3 balls with color 4.\n \"\"\"\n"}
{"task_id": "minimum-number-of-flips-to-make-binary-grid-palindromic-i", "prompt": "def minFlips(grid: List[List[int]]) -> int:\n \"\"\"\n You are given an m x n binary matrix grid.\n A row or column is considered palindromic if its values read the same forward and backward.\n You can flip any number of cells in grid from 0 to 1, or from 1 to 0.\n Return the minimum number of cells that need to be flipped to make either all rows palindromic or all columns palindromic.\n \n Example 1:\n \n >>> minFlips(grid = [[1,0,0],[0,0,0],[0,0,1]])\n >>> 2\n Explanation:\n \n Flipping the highlighted cells makes all the rows palindromic.\n \n Example 2:\n \n >>> minFlips(grid = [[0,1],[0,1],[0,0]])\n >>> 1\n Explanation:\n \n Flipping the highlighted cell makes all the columns palindromic.\n \n Example 3:\n \n >>> minFlips(grid = [[1],[0]])\n >>> 0\n Explanation:\n All rows are already palindromic.\n \"\"\"\n"}
{"task_id": "minimum-number-of-flips-to-make-binary-grid-palindromic-ii", "prompt": "def minFlips(grid: List[List[int]]) -> int:\n \"\"\"\n You are given an m x n binary matrix grid.\n A row or column is considered palindromic if its values read the same forward and backward.\n You can flip any number of cells in grid from 0 to 1, or from 1 to 0.\n Return the minimum number of cells that need to be flipped to make all rows and columns palindromic, and the total number of 1's in grid divisible by 4.\n \n Example 1:\n \n >>> minFlips(grid = [[1,0,0],[0,1,0],[0,0,1]])\n >>> 3\n Explanation:\n \n \n Example 2:\n \n >>> minFlips(grid = [[0,1],[0,1],[0,0]])\n >>> 2\n Explanation:\n \n \n Example 3:\n \n >>> minFlips(grid = [[1],[1]])\n >>> 2\n Explanation:\n \"\"\"\n"}
{"task_id": "time-taken-to-mark-all-nodes", "prompt": "def timeTaken(edges: List[List[int]]) -> List[int]:\n \"\"\"\n There exists an undirected tree with n nodes numbered 0 to n - 1. You are given a 2D integer array edges of length n - 1, where edges[i] = [ui, vi] indicates that there is an edge between nodes ui and vi in the tree.\n Initially, all nodes are unmarked. For each node i:\n \n If i is odd, the node will get marked at time x if there is at least one node adjacent to it which was marked at time x - 1.\n If i is even, the node will get marked at time x if there is at least one node adjacent to it which was marked at time x - 2.\n \n Return an array times where times[i] is the time when all nodes get marked in the tree, if you mark node i at time t = 0.\n Note that the answer for each times[i] is independent, i.e. when you mark node i all other nodes are unmarked.\n \n Example 1:\n \n >>> timeTaken(edges = [[0,1],[0,2]])\n >>> [2,4,3]\n Explanation:\n \n \n For i = 0:\n \n \n Node 1 is marked at t = 1, and Node 2 at t = 2.\n \n \n For i = 1:\n \n Node 0 is marked at t = 2, and Node 2 at t = 4.\n \n \n For i = 2:\n \n Node 0 is marked at t = 2, and Node 1 at t = 3.\n \n \n \n \n Example 2:\n \n >>> timeTaken(edges = [[0,1]])\n >>> [1,2]\n Explanation:\n \n \n For i = 0:\n \n \n Node 1 is marked at t = 1.\n \n \n For i = 1:\n \n Node 0 is marked at t = 2.\n \n \n \n \n Example 3:\n \n >>> timeTaken(edges = [[2,4],[0,1],[2,3],[0,2]])\n >>> [4,6,3,5,5]\n Explanation:\n \"\"\"\n"}