Skip to content

Instantly share code, notes, and snippets.

@tou55aint
Created September 26, 2021 04:37
Show Gist options
  • Save tou55aint/e71e81f1710d75c97de721d746bacea5 to your computer and use it in GitHub Desktop.
Save tou55aint/e71e81f1710d75c97de721d746bacea5 to your computer and use it in GitHub Desktop.
LeetCode questions converted to JSON
This file has been truncated, but you can view the full file.
[{
"id": "1",
"title": "Two Sum",
"question": "Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target.\nYou may assume that each input would have exactly one solution, and you may not use the same element twice.\nYou can return the answer in any order.",
"examples": [
"Input: nums = [2,7,11,15], target = 9",
"Output: [0,1]",
"Output: Because nums[0] + nums[1] == 9, we return [0, 1].",
"Input: nums = [3,2,4], target = 6",
"Output: [1,2]",
"Input: nums = [3,3], target = 6",
"Output: [0,1]",
""
],
"constraints": [
"2 <= nums. length <= 104-109 <= nums[i] <= 109-109 <= target <= 109Only one valid answer exists."
]
},
{
"id": "7",
"title": "Reverse Integer",
"question": "Given a signed 32-bit integer x, return x with its digits reversed.\n If reversing x causes the value to go outside the signed 32-bit integer range [-231, 231 - 1], then return 0.\nAssume the environment does not allow you to store 64-bit integers (signed or unsigned).",
"examples": [
"Input: x = 123",
"Output: 321",
"Input: x = -123",
"Output: -321",
"Input: x = 120",
"Output: 21",
"Input: x = 0",
"Output: 0",
""
],
"constraints": [
"-231 <= x <= 231 - 1"
]
},
{
"id": "35",
"title": "Search Insert Position",
"question": "Given a sorted array of distinct integers and a target value, return the index if the target is found.\n If not, return the index where it would be if it were inserted in order.\nYou must write an algorithm with O(log n) runtime complexity.",
"examples": [
"Input: nums = [1,3,5,6], target = 5",
"Output: 2",
"Input: nums = [1,3,5,6], target = 2",
"Output: 1",
"Input: nums = [1,3,5,6], target = 7",
"Output: 4",
"Input: nums = [1,3,5,6], target = 0",
"Output: 0",
"Input: nums = [1], target = 0",
"Output: 0",
""
],
"constraints": [
"1 <= nums. length <= 104-104 <= nums[i] <= 104nums contains distinct values sorted in ascending order.-104 <= target <= 104"
]
},
{
"id": "485",
"title": "Max Consecutive Ones",
"question": "Given a binary array nums, return the maximum number of consecutive 1's in the array.",
"examples": [
"Input: nums = [1,1,0,1,1,1]",
"Output: 3",
"Explanation: The first two digits or the last three digits are consecutive 1s. The maximum number of consecutive 1s is 3.",
"Input: nums = [1,0,1,1,0,1]",
"Output: 2",
""
],
"constraints": [
"1 <= nums. length <= 105nums[i] is either 0 or 1."
]
},
{
"id": "1498",
"title": "Number of Subsequences That Satisfy the Given Sum Condition",
"question": "Given an array of integers nums and an integer target.\nReturn 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.\n Since the answer may be too large, return it modulo 109 + 7.",
"examples": [
"Input: nums = [3,5,6,7], target = 9",
"Output: 4",
"Explanation: There are 4 subsequences that satisfy the condition.",
"[3] -> Min value + max value <= target (3 + 3 <= 9)",
"[3,5] -> (3 + 5 <= 9)",
"[3,5,6] -> (3 + 6 <= 9)",
"[3,6] -> (3 + 6 <= 9)",
"Input: nums = [3,3,6,8], target = 10",
"Output: 6",
"Explanation: There are 6 subsequences that satisfy the condition. (nums can have repeated numbers).",
"[3] , [3] , [3,3], [3,6] , [3,6] , [3,3,6]Input: nums = [2,3,3,4,6,7], target = 12",
"Output: 61",
"Explanation: There are 63 non-empty subsequences, two of them don't satisfy the condition ([6,7], [7]).",
"Number of valid subsequences (63 - 2 = 61).",
"Input: nums = [5,2,4,1,7,6,8], target = 16",
"Output: 127",
"Explanation: All non-empty subset satisfy the condition (2^7 - 1) = 127"
],
"constraints": [
"1 <= nums. length <= 1051 <= nums[i] <= 1061 <= target <= 106"
]
},
{
"id": "1503",
"title": "Last Moment Before All Ants Fall Out of a Plank",
"question": "We have a wooden plank of the length n units.\n Some ants are walking on the plank, each ant moves with speed 1 unit per second.\n Some of the ants move to the left, the other move to the right.\nWhen two ants moving in two different directions meet at some point, they change their directions and continue moving again.\n Assume changing directions doesn't take any additional time.\nWhen an ant reaches one end of the plank at a time t, it falls out of the plank imediately.\nGiven an integer n and two integer arrays left and right, the positions of the ants moving to the left and the right.\n Return the moment when the last ant(s) fall out of the plank.",
"examples": [
"Input: n = 4, left = [4,3], right = [0,1]",
"Output: 4",
"Explanation: In the image above:",
"-The ant at index 0 is named A and going to the right.",
"-The ant at index 1 is named B and going to the right.",
"-The ant at index 3 is named C and going to the left.",
"-The ant at index 4 is named D and going to the left.",
"Note that the last moment when an ant was on the plank is t = 4 second, after that it falls imediately out of the plank. (i. e. We can say that at t = 4. 0000000001, there is no ants on the plank).",
"Input: n = 7, left = [], right = [0,1,2,3,4,5,6,7]",
"Output: 7",
"Explanation: All ants are going to the right, the ant at index 0 needs 7 seconds to fall.",
"Input: n = 7, left = [0,1,2,3,4,5,6,7], right = []",
"Output: 7",
"Explanation: All ants are going to the left, the ant at index 7 needs 7 seconds to fall.",
"Input: n = 9, left = [5], right = [4]",
"Output: 5",
"Explanation: At t = 1 second, both ants will be at the same intial position but with different direction.",
"Input: n = 6, left = [6], right = [0]",
"Output: 6",
""
],
"constraints": [
"1 <= n <= 10^40 <= left. length <= n + 10 <= left[i] <= n0 <= right. length <= n + 10 <= right[i] <= n1 <= left. length + right. length <= n + 1All values of left and right are unique",
" and each value can appear only in one of the two arrays."
]
},
{
"id": "1504",
"title": "Count Submatrices With All Ones",
"question": "Given a rows * columns matrix mat of ones and zeros, return how many submatrices have all ones.",
"examples": [
"Input: mat = [[1,0,1],",
"  [1,1,0],",
"  [1,1,0]]",
"Output: 13",
"Explanation:",
"There are 6 rectangles of side 1x1.",
"There are 2 rectangles of side 1x2.",
"There are 3 rectangles of side 2x1.",
"There is 1 rectangle of side 2x2. ",
"There is 1 rectangle of side 3x1.",
"Total number of rectangles = 6 + 2 + 3 + 1 + 1 = 13.",
"Input: mat = [[0,1,1,0],",
"  [0,1,1,1],",
"  [1,1,1,0]]",
"Output: 24",
"Explanation:",
"There are 8 rectangles of side 1x1.",
"There are 5 rectangles of side 1x2.",
"There are 2 rectangles of side 1x3. ",
"There are 4 rectangles of side 2x1.",
"There are 2 rectangles of side 2x2. ",
"There are 2 rectangles of side 3x1. ",
"There is 1 rectangle of side 3x2. ",
"Total number of rectangles = 8 + 5 + 2 + 4 + 2 + 2 + 1 = 24.",
"Input: mat = [[1,1,1,1,1,1]]",
"Output: 21",
"Input: mat = [[1,0,1],[0,1,0],[1,0,1]]",
"Output: 5",
""
],
"constraints": [
"1 <= rows <= 1501 <= columns <= 1500 <= mat[i][j] <= 1"
]
},
{
"id": "1508",
"title": "Range Sum of Sorted Subarray Sums",
"question": "You are given the array nums consisting of n positive integers.\n 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.\nReturn the sum of the numbers from index left to index right (indexed from 1), inclusive, in the new array.\n Since the answer can be a huge number return it modulo 109 + 7.",
"examples": [
"Input: nums = [1,2,3,4], n = 4, left = 1, right = 5",
"Output: 13 ",
"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. ",
"Input: nums = [1,2,3,4], n = 4, left = 3, right = 4",
"Output: 6",
"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.",
"Input: nums = [1,2,3,4], n = 4, left = 1, right = 10",
"Output: 50",
""
],
"constraints": [
"n == nums. length1 <= nums. length <= 10001 <= nums[i] <= 1001 <= left <= right <= n * (n + 1) / 2"
]
},
{
"id": "1509",
"title": "Minimum Difference Between Largest and Smallest Value in Three Moves",
"question": "Given an array nums, you are allowed to choose one element of nums and change it by any value in one move.\nReturn the minimum difference between the largest and smallest value of nums after perfoming at most 3 moves.",
"examples": [
"Input: nums = [5,3,2,4]",
"Output: 0",
"Explanation: Change the array [5,3,2,4] to [2,2,2,2].",
"The difference between the maximum and minimum is 2-2 = 0. Input: nums = [1,5,0,10,14]",
"Output: 1",
"Explanation: Change the array [1,5,0,10,14] to [1,1,0,1,1]. ",
"The difference between the maximum and minimum is 1-0 = 1.",
"Input: nums = [6,6,0,1,1,4,6]",
"Output: 2",
"Input: nums = [1,5,6,14,15]",
"Output: 1",
""
],
"constraints": [
"1 <= nums. length <= 10^5-10^9 <= nums[i] <= 10^9"
]
},
{
"id": "1513",
"title": "Number of Substrings With Only 1s",
"question": "Given a binary string s (a string consisting only of '0' and '1's).\nReturn the number of substrings with all characters 1's.\nSince the answer may be too large, return it modulo 10^9 + 7.",
"examples": [
"Input: s = \"0110111\"",
"Output: 9",
"Explanation: There are 9 substring in total with only 1's characters.",
"\"1\" -> 5 times.",
"\"11\" -> 3 times.",
"\"111\" -> 1 time. Input: s = \"101\"",
"Output: 2",
"Explanation: Substring \"1\" is shown 2 times in s.",
"Input: s = \"111111\"",
"Output: 21",
"Explanation: Each substring contains only 1's characters.",
"Input: s = \"000\"",
"Output: 0",
""
],
"constraints": [
"s[i] == '0' or s[i] == '1'1 <= s. length <= 10^5"
]
},
{
"id": "1514",
"title": "Path with Maximum Probability",
"question": "You are given an undirected weighted graph of n nodes (0-indexed), represented by an edge list where edges[i] = [a, b] is an undirected edge connecting the nodes a and b with a probability of success of traversing that edge succProb[i].\nGiven two nodes start and end, find the path with the maximum probability of success to go from start to end and return its success probability.\nIf there is no path from start to end, return 0.\n Your answer will be accepted if it differs from the correct answer by at most 1e-5.",
"examples": [
"Input: n = 3, edges = [[0,1],[1,2],[0,2]], succProb = [0. 5,0. 5,0. 2], start = 0, end = 2",
"Output: 0. 25000",
"Explanation: There 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.",
"Input: n = 3, edges = [[0,1],[1,2],[0,2]], succProb = [0. 5,0. 5,0. 3], start = 0, end = 2",
"Output: 0. 30000",
"Input: n = 3, edges = [[0,1]], succProb = [0. 5], start = 0, end = 2",
"Output: 0. 00000",
"Explanation: There is no path between 0 and 2.",
""
],
"constraints": [
"2 <= n <= 10^40 <= start",
" end < nstart != end0 <= a",
" b < na != b0 <= succProb. length == edges. length <= 2*10^40 <= succProb[i] <= 1There is at most one edge between every two nodes."
]
},
{
"id": "1519",
"title": "Number of Nodes in the Sub-Tree With the Same Label",
"question": "Given a tree (i.\ne.\n a connected, undirected graph that has no cycles) consisting of n nodes numbered from 0 to n - 1 and exactly n - 1 edges.\n 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.\ne.\n The node with the number i has the label labels[i]).\nThe 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.\nReturn 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.\nA subtree of a tree T is the tree consisting of a node in T and all of its descendant nodes.",
"examples": [
"Input: n = 7, edges = [[0,1],[0,2],[1,4],[1,5],[2,3],[2,6]], labels = \"abaedcd\"",
"Output: [2,1,1,1,1,1,1]",
"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.",
"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).",
"Input: n = 4, edges = [[0,1],[1,2],[0,3]], labels = \"bbbb\"",
"Output: [4,2,1,1]",
"Explanation: The sub-tree of node 2 contains only node 2, so the answer is 1.",
"The sub-tree of node 3 contains only node 3, so the answer is 1.",
"The sub-tree of node 1 contains nodes 1 and 2, both have label 'b', thus the answer is 2.",
"The sub-tree of node 0 contains nodes 0, 1, 2 and 3, all with label 'b', thus the answer is 4.",
"Input: n = 5, edges = [[0,1],[0,2],[1,3],[0,4]], labels = \"aabab\"",
"Output: [3,2,1,1,1]",
"Input: n = 6, edges = [[0,1],[0,2],[1,3],[3,4],[4,5]], labels = \"cbabaa\"",
"Output: [1,2,1,1,2,1]",
"Input: n = 7, edges = [[0,1],[1,2],[2,3],[3,4],[4,5],[5,6]], labels = \"aaabaaa\"",
"Output: [6,5,4,1,3,2,1]",
""
],
"constraints": [
"1 <= n <= 10^5edges. length == n - 1edges[i]. length == 20 <= ai",
" bi < nai != bilabels. length == nlabels is consisting of only of lower-case English letters."
]
},
{
"id": "1524",
"title": "Number of Sub-arrays With Odd Sum",
"question": "Given an array of integers arr, return the number of subarrays with an odd sum.\nSince the answer can be very large, return it modulo 109 + 7.",
"examples": [
"Input: arr = [1,3,5]",
"Output: 4",
"Explanation: All subarrays are [[1],[1,3],[1,3,5],[3],[3,5],[5]]",
"All sub-arrays sum are [1,4,9,3,8,5].",
"Odd sums are [1,9,3,5] so the answer is 4.",
"Input: arr = [2,4,6]",
"Output: 0",
"Explanation: All subarrays are [[2],[2,4],[2,4,6],[4],[4,6],[6]]",
"All sub-arrays sum are [2,6,12,4,10,6].",
"All sub-arrays have even sum and the answer is 0.",
"Input: arr = [1,2,3,4,5,6,7]",
"Output: 16",
""
],
"constraints": [
"1 <= arr. length <= 1051 <= arr[i] <= 100"
]
},
{
"id": "1525",
"title": "Number of Good Ways to Split a String",
"question": "You are given a string s, a split is called good if you can split s into 2 non-empty strings p and q where its concatenation is equal to s and the number of distinct letters in p and q are the same.\nReturn the number of good splits you can make in s.",
"examples": [
"Input: s = \"aacaba\"",
"Output: 2",
"Explanation: There are 5 ways to split \"aacaba\" and 2 of them are good. ",
"(\"a\", \"acaba\") Left string and right string contains 1 and 3 different letters respectively.",
"(\"aa\", \"caba\") Left string and right string contains 1 and 3 different letters respectively.",
"(\"aac\", \"aba\") Left string and right string contains 2 and 2 different letters respectively (good split).",
"(\"aaca\", \"ba\") Left string and right string contains 2 and 2 different letters respectively (good split).",
"(\"aacab\", \"a\") Left string and right string contains 3 and 1 different letters respectively.",
"Input: s = \"abcd\"",
"Output: 1",
"Explanation: Split the string as follows (\"ab\", \"cd\").",
"Input: s = \"aaaaa\"",
"Output: 4",
"Explanation: All possible splits are good. Input: s = \"acbadbaada\"",
"Output: 2",
""
],
"constraints": [
"s contains only lowercase English letters. 1 <= s. length <= 10^5"
]
},
{
"id": "492",
"title": "Construct the Rectangle",
"question": "A web developer needs to know how to design a web page's size.\n So, given a specific rectangular web page’s area, your job by now is to design a rectangular web page, whose length L and width W satisfy the following requirements:Return an array [L, W] where L and W are the length and width of the web page you designed in sequence.",
"examples": [
"Input: area = 4",
"Output: [2,2]",
"Explanation: The target area is 4, and all the possible ways to construct it are [1,4], [2,2], [4,1]. ",
"But according to requirement 2, [1,4] is illegal; according to requirement 3, [4,1] is not optimal compared to [2,2]. So the length L is 2, and the width W is 2.",
"Input: area = 37",
"Output: [37,1]",
"Input: area = 122122",
"Output: [427,286]",
""
],
"constraints": [
"1 <= area <= 107"
]
},
{
"id": "1529",
"title": "Bulb Switcher IV",
"question": "There is a room with n bulbs, numbered from 0 to n - 1, arranged in a row from left to right.\n Initially, all the bulbs are turned off.\nYour task is to obtain the configuration represented by target where target[i] is '1' if the ith bulb is turned on and is '0' if it is turned off.\nYou have a switch to flip the state of the bulb, a flip operation is defined as follows:When any bulb is flipped it means that if it is '0' it changes to '1' and if it is '1' it changes to '0'.\nReturn the minimum number of flips required to form target.",
"examples": [
"Input: target = \"10111\"",
"Output: 3",
"Explanation: Initial configuration \"00000\".",
"flip from the third bulb: \"00000\" -> \"00111\"",
"flip from the first bulb: \"00111\" -> \"11000\"",
"flip from the second bulb: \"11000\" -> \"10111\"",
"We need at least 3 flip operations to form target. Input: target = \"101\"",
"Output: 3",
"Explanation: \"000\" -> \"111\" -> \"100\" -> \"101\".",
"Input: target = \"00000\"",
"Output: 0",
"Input: target = \"001011101\"",
"Output: 5",
""
],
"constraints": [
"Choose any bulb (index i) of your current configuration. Flip each bulb from index i to index n - 1. 1 <= target. length <= 105target[i] is either '0' or '1'."
]
},
{
"id": "1530",
"title": "Number of Good Leaf Nodes Pairs",
"question": "Given the root of a binary tree and an integer distance.\n 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.\nReturn the number of good leaf node pairs in the tree.",
"examples": [
"Input: root = [1,2,3,null,4], distance = 3",
"Output: 1",
"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.",
"Input: root = [1,2,3,4,5,6,7], distance = 3",
"Output: 2",
"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.",
"Input: root = [7,1,4,6,null,5,3,null,null,null,null,null,2], distance = 3",
"Output: 1",
"Explanation: The only good pair is [2,5].",
"Input: root = [100], distance = 1",
"Output: 0",
"Input: root = [1,1,1], distance = 2",
"Output: 1",
""
],
"constraints": [
"The number of nodes in the tree is in the range [1",
" 2^10]. Each node's value is between [1",
" 100]. 1 <= distance <= 10"
]
},
{
"id": "1535",
"title": "Find the Winner of an Array Game",
"question": "Given an integer array arr of distinct integers and an integer k.\nA game will be played between the first two elements of the array (i.\ne.\n arr[0] and arr[1]).\n 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.\n The game ends when an integer wins k consecutive rounds.\nReturn the integer which will win the game.\nIt is guaranteed that there will be a winner of the game.",
"examples": [
"Input: arr = [2,1,3,5,4,6,7], k = 2",
"Output: 5",
"Explanation: Let's see the rounds of the game:",
"Round | arr | winner | win_count",
" 1 | [2,1,3,5,4,6,7] | 2 | 1",
" 2 | [2,3,5,4,6,7,1] | 3 | 1",
" 3 | [3,5,4,6,7,1,2] | 5 | 1",
" 4 | [5,4,6,7,1,2,3] | 5 | 2",
"So we can see that 4 rounds will be played and 5 is the winner because it wins 2 consecutive games.",
"Input: arr = [3,2,1], k = 10",
"Output: 3",
"Explanation: 3 will win the first 10 rounds consecutively.",
"Input: arr = [1,9,8,2,3,7,6,4,5], k = 7",
"Output: 9",
"Input: arr = [1,11,22,33,44,55,66,77,88,99], k = 1000000000",
"Output: 99",
""
],
"constraints": [
"2 <= arr. length <= 10^51 <= arr[i] <= 10^6arr contains distinct integers. 1 <= k <= 10^9"
]
},
{
"id": "1536",
"title": "Minimum Swaps to Arrange a Binary Grid",
"question": "Given an n x n binary grid, in one step you can choose two adjacent rows of the grid and swap them.\nA grid is said to be valid if all the cells above the main diagonal are zeros.\nReturn the minimum number of steps needed to make the grid valid, or -1 if the grid cannot be valid.\nThe main diagonal of a grid is the diagonal that starts at cell (1, 1) and ends at cell (n, n).",
"examples": [
"Input: grid = [[0,0,1],[1,1,0],[1,0,0]]",
"Output: 3",
"Input: grid = [[0,1,1,0],[0,1,1,0],[0,1,1,0],[0,1,1,0]]",
"Output: -1",
"Explanation: All rows are similar, swaps have no effect on the grid.",
"Input: grid = [[1,0,0],[1,1,0],[1,1,1]]",
"Output: 0",
""
],
"constraints": [
"n == grid. lengthn == grid[i]. length1 <= n <= 200grid[i][j] is 0 or 1"
]
},
{
"id": "1540",
"title": "Can Convert String in K Moves",
"question": "Given two strings s and t, your goal is to convert s into t in k moves or less.\nDuring the ith (1 <= i <= k) move you can:Shifting a character means replacing it by the next letter in the alphabet (wrapping around so that 'z' becomes 'a').\n Shifting a character by i means applying the shift operations i times.\nRemember that any index j can be picked at most once.\nReturn true if it's possible to convert s into t in no more than k moves, otherwise return false.",
"examples": [
"Input: s = \"input\", t = \"ouput\", k = 9",
"Output: true",
"Explanation: In the 6th move, we shift 'i' 6 times to get 'o'. And in the 7th move we shift 'n' to get 'u'.",
"Input: s = \"abc\", t = \"bcd\", k = 10",
"Output: false",
"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.",
"Input: s = \"aab\", t = \"bbb\", k = 27",
"Output: true",
"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'.",
""
],
"constraints": [
"Choose any index j (1-indexed) from s",
" such that 1 <= j <= s. length and j has not been chosen in any previous move",
" and shift the character at that index i times. Do nothing. 1 <= s. length",
" t. length <= 10^50 <= k <= 10^9s",
" t contain only lowercase English letters."
]
},
{
"id": "1541",
"title": "Minimum Insertions to Balance a Parentheses String",
"question": "Given a parentheses string s containing only the characters '(' and ')'.\n A parentheses string is balanced if:In other words, we treat '(' as openning parenthesis and '))' as closing parenthesis.\nFor example, \"())\", \"())(())))\" and \"(())())))\" are balanced, \")()\", \"()))\" and \"(()))\" are not balanced.\nYou can insert the characters '(' and ')' at any position of the string to balance it if needed.\nReturn the minimum number of insertions needed to make s balanced.",
"examples": [
"Input: s = \"(()))\"",
"Output: 1",
"Explanation: The second '(' has two matching '))', but the first '(' has only ')' matching. We need to to add one more ')' at the end of the string to be \"(())))\" which is balanced.",
"Input: s = \"())\"",
"Output: 0",
"Explanation: The string is already balanced.",
"Input: s = \"))())(\"",
"Output: 3",
"Explanation: Add '(' to match the first '))', Add '))' to match the last '('.",
"Input: s = \"((((((\"",
"Output: 12",
"Explanation: Add 12 ')' to balance the string.",
"Input: s = \")))))))\"",
"Output: 5",
"Explanation: Add 4 '(' at the beginning of the string and one ')' at the end. The string becomes \"(((())))))))\".",
""
],
"constraints": [
"Any left parenthesis '(' must have a corresponding two consecutive right parenthesis '))'. Left parenthesis '(' must go before the corresponding two consecutive right parenthesis '))'. 1 <= s. length <= 10^5s consists of '(' and ')' only."
]
},
{
"id": "1545",
"title": "Find Kth Bit in Nth Binary String",
"question": "Given two positive integers n and k, the binary string  Sn is formed as follows: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).\nFor example, the first 4 strings in the above sequence are:Return the kth bit in Sn.\n It is guaranteed that k is valid for the given n.",
"examples": [
"Input: n = 3, k = 1",
"Output: \"0\"",
"Explanation: S3 is \"0111001\". The first bit is \"0\".",
"Input: n = 4, k = 11",
"Output: \"1\"",
"Explanation: S4 is \"011100110110001\". The 11th bit is \"1\".",
"Input: n = 1, k = 1",
"Output: \"0\"",
"Input: n = 2, k = 3",
"Output: \"1\"",
""
],
"constraints": [
"S1 = \"0\"Si = Si-1 + \"1\" + reverse(invert(Si-1)) for i > 1S1 = \"0\"S2 = \"011\"S3 = \"0111001\"S4 = \"011100110110001\"1 <= n <= 201 <= k <= 2n - 1"
]
},
{
"id": "1546",
"title": "Maximum Number of Non-Overlapping Subarrays With Sum Equals Target",
"question": "Given an array nums and an integer target.\nReturn the maximum number of non-empty non-overlapping subarrays such that the sum of values in each subarray is equal to target.",
"examples": [
"Input: nums = [1,1,1,1,1], target = 2",
"Output: 2",
"Explanation: There are 2 non-overlapping subarrays [1,1,1,1,1] with sum equals to target(2).",
"Input: nums = [-1,3,5,1,4,2,-9], target = 6",
"Output: 2",
"Explanation: There are 3 subarrays with sum equal to 6.",
"([5,1], [4,2], [3,5,1,4,2,-9]) but only the first 2 are non-overlapping. Input: nums = [-2,6,6,3,5,4,1,2,8], target = 10",
"Output: 3",
"Input: nums = [0,0,0], target = 0",
"Output: 3",
""
],
"constraints": [
"1 <= nums. length <= 10^5-10^4 <= nums[i] <= 10^40 <= target <= 10^6"
]
},
{
"id": "1551",
"title": "Minimum Operations to Make Array Equal",
"question": "You have an array arr of length n where arr[i] = (2 * i) + 1 for all valid values of i (i.\ne.\n 0 <= i < n).\nIn 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.\ne.\n perform arr[x] -=1 and arr[y] += 1).\n The goal is to make all the elements of the array equal.\n It is guaranteed that all the elements of the array can be made equal using some operations.\nGiven an integer n, the length of the array.\n Return the minimum number of operations needed to make all the elements of arr equal.",
"examples": [
"Input: n = 3",
"Output: 2",
"Explanation: arr = [1, 3, 5]",
"First operation choose x = 2 and y = 0, this leads arr to be [2, 3, 4]",
"In the second operation choose x = 2 and y = 0 again, thus arr = [3, 3, 3].",
"Input: n = 6",
"Output: 9",
""
],
"constraints": [
"1 <= n <= 10^4"
]
},
{
"id": "1552",
"title": "Magnetic Force Between Two Balls",
"question": "In universe Earth C-137, Rick discovered a special form of magnetic force between two balls if they are put in his new invented basket.\n 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.\nRick stated that magnetic force between two different balls at positions x and y is |x - y|.\nGiven the integer array position and the integer m.\n Return the required force.",
"examples": [
"Input: position = [1,2,3,4,7], m = 3",
"Output: 3",
"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.",
"Input: position = [5,4,3,2,1,1000000000], m = 2",
"Output: 999999999",
"Explanation: We can use baskets 1 and 1000000000.",
""
],
"constraints": [
"n == position. length2 <= n <= 10^51 <= position[i] <= 10^9All integers in position are distinct. 2 <= m <= position. length"
]
},
{
"id": "495",
"title": "Teemo Attacking",
"question": "Our hero Teemo is attacking an enemy Ashe with poison attacks! When Teemo attacks Ashe, Ashe gets poisoned for a exactly duration seconds.\n More formally, an attack at second t will mean Ashe is poisoned during the inclusive time interval [t, t + duration - 1].\n If Teemo attacks again before the poison effect ends, the timer for it is reset, and the poison effect will end duration seconds after the new attack.\nYou are given a non-decreasing integer array timeSeries, where timeSeries[i] denotes that Teemo attacks Ashe at second timeSeries[i], and an integer duration.\nReturn the total number of seconds that Ashe is poisoned.",
"examples": [
"Input: timeSeries = [1,4], duration = 2",
"Output: 4",
"Explanation: Teemo's attacks on Ashe go as follows:",
"- At second 1, Teemo attacks, and Ashe is poisoned for seconds 1 and 2.",
"- At second 4, Teemo attacks, and Ashe is poisoned for seconds 4 and 5.",
"Ashe is poisoned for seconds 1, 2, 4, and 5, which is 4 seconds in total.",
"Input: timeSeries = [1,2], duration = 2",
"Output: 3",
"Explanation: Teemo's attacks on Ashe go as follows:",
"- At second 1, Teemo attacks, and Ashe is poisoned for seconds 1 and 2.",
"- At second 2 however, Teemo attacks again and resets the poison timer. Ashe is poisoned for seconds 2 and 3.",
"Ashe is poisoned for seconds 1, 2, and 3, which is 3 seconds in total."
],
"constraints": [
"1 <= timeSeries. length <= 1040 <= timeSeries[i]",
" duration <= 107timeSeries is sorted in non-decreasing order."
]
},
{
"id": "1557",
"title": "Minimum Number of Vertices to Reach All Nodes",
"question": "Given a directed acyclic graph, with n vertices numbered from 0 to n-1, and an array edges where edges[i] = [fromi, toi] represents a directed edge from node fromi to node toi.\nFind the smallest set of vertices from which all nodes in the graph are reachable.\n It's guaranteed that a unique solution exists.\nNotice that you can return the vertices in any order.",
"examples": [
"Input: n = 6, edges = [[0,1],[0,2],[2,5],[3,4],[4,2]]",
"Output: [0,3]",
"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]. Input: n = 5, edges = [[0,1],[2,1],[3,1],[1,4],[2,4]]",
"Output: [0,2,3]",
"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.",
""
],
"constraints": [
"2 <= n <= 10^51 <= edges. length <= min(10^5",
" n * (n - 1) / 2)edges[i]. length == 20 <= fromi",
" toi < nAll pairs (fromi",
" toi) are distinct."
]
},
{
"id": "1558",
"title": "Minimum Numbers of Function Calls to Make Target Array",
"question": "Your task is to form an integer array nums from an initial array of zeros arr that is the same size as nums.\nReturn the minimum number of function calls to make nums from arr.\nThe answer is guaranteed to fit in a 32-bit signed integer.",
"examples": [
"Input: nums = [1,5]",
"Output: 5",
"Explanation: Increment by 1 (second element): [0, 0] to get [0, 1] (1 operation).",
"Double all the elements: [0, 1] -> [0, 2] -> [0, 4] (2 operations).",
"Increment by 1 (both elements) [0, 4] -> [1, 4] -> [1, 5] (2 operations).",
"Total of operations: 1 + 2 + 2 = 5.",
"Input: nums = [2,2]",
"Output: 3",
"Explanation: Increment by 1 (both elements) [0, 0] -> [0, 1] -> [1, 1] (2 operations).",
"Double all the elements: [1, 1] -> [2, 2] (1 operation).",
"Total of operations: 2 + 1 = 3.",
"Input: nums = [4,2,5]",
"Output: 6",
"Explanation: (initial)[0,0,0] -> [1,0,0] -> [1,0,1] -> [2,0,2] -> [2,1,2] -> [4,2,4] -> [4,2,5](nums).",
"Input: nums = [3,2,2,4]",
"Output: 7",
"Input: nums = [2,4,8,16]",
"Output: 8",
""
],
"constraints": [
"1 <= nums. length <= 10^50 <= nums[i] <= 10^9"
]
},
{
"id": "1561",
"title": "Maximum Number of Coins You Can Get",
"question": "There are 3n piles of coins of varying size, you and your friends will take piles of coins as follows:Given an array of integers piles where piles[i] is the number of coins in the ith pile.\nReturn the maximum number of coins which you can have.",
"examples": [
"Input: piles = [2,4,1,2,7,8]",
"Output: 9",
"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.",
"Choose the triplet (1, 2, 4), Alice Pick the pile with 4 coins, you the pile with 2 coins and Bob the last one.",
"The maximum number of coins which you can have are: 7 + 2 = 9.",
"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.",
"Input: piles = [2,4,5]",
"Output: 4",
"Input: piles = [9,8,7,6,5,1,2,3,4]",
"Output: 18",
""
],
"constraints": [
"In each step",
" you will choose any 3 piles of coins (not necessarily consecutive). Of your choice",
" Alice will pick the pile with the maximum number of coins. You will pick the next pile with maximum number of coins. Your friend Bob will pick the last pile. Repeat until there are no more piles of coins. 3 <= piles. length <= 10^5piles. length % 3 == 01 <= piles[i] <= 10^4"
]
},
{
"id": "1562",
"title": "Find Latest Group of Size M",
"question": "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.\nAt 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 given an integer m and you need to find the latest step at which there exists a group of ones of length m.\n A group of ones is a contiguous substring of 1s such that it cannot be extended in either direction.\nReturn the latest step at which there exists a group of ones of length exactly m.\n If no such group exists, return -1.",
"examples": [
"Input: arr = [3,5,1,2,4], m = 1",
"Output: 4",
"Explanation:",
"Step 1: \"00100\", groups: [\"1\"]",
"Step 2: \"00101\", groups: [\"1\", \"1\"]",
"Step 3: \"10101\", groups: [\"1\", \"1\", \"1\"]",
"Step 4: \"11101\", groups: [\"111\", \"1\"]",
"Step 5: \"11111\", groups: [\"11111\"]",
"The latest step at which there exists a group of size 1 is step 4. Input: arr = [3,1,5,4,2], m = 2",
"Output: -1",
"Explanation:",
"Step 1: \"00100\", groups: [\"1\"]",
"Step 2: \"10100\", groups: [\"1\", \"1\"]",
"Step 3: \"10101\", groups: [\"1\", \"1\", \"1\"]",
"Step 4: \"10111\", groups: [\"1\", \"111\"]",
"Step 5: \"11111\", groups: [\"11111\"]",
"No group of size 2 exists during any step.",
"Input: arr = [1], m = 1",
"Output: 1",
"Input: arr = [2,1], m = 2",
"Output: 2",
""
],
"constraints": [
"n == arr. length1 <= n <= 10^51 <= arr[i] <= nAll integers in arr are distinct. 1 <= m <= arr. length"
]
},
{
"id": "1567",
"title": "Maximum Length of Subarray With Positive Product",
"question": "Given an array of integers nums, find the maximum length of a subarray where the product of all its elements is positive.\nA subarray of an array is a consecutive sequence of zero or more values taken out of that array.\nReturn the maximum length of a subarray with positive product.",
"examples": [
"Input: nums = [1,-2,-3,4]",
"Output: 4",
"Explanation: The array nums already has a positive product of 24.",
"Input: nums = [0,1,-2,-3,-4]",
"Output: 3",
"Explanation: The longest subarray with positive product is [1,-2,-3] which has a product of 6.",
"Notice that we cannot include 0 in the subarray since that'll make the product 0 which is not positive. Input: nums = [-1,-2,-3,0,1]",
"Output: 2",
"Explanation: The longest subarray with positive product is [-1,-2] or [-2,-3].",
"Input: nums = [-1,2]",
"Output: 1",
"Input: nums = [1,2,3,5,-6,4,0,10]",
"Output: 4",
""
],
"constraints": [
"1 <= nums. length <= 10^5-10^9 <= nums[i] <= 10^9"
]
},
{
"id": "1573",
"title": "Number of Ways to Split a String",
"question": "Given a binary string s (a string consisting only of '0's and '1's), we can split s into 3 non-empty strings s1, s2, s3 (s1+ s2+ s3 = s).\nReturn the number of ways s can be split such that the number of characters '1' is the same in s1, s2, and s3.\nSince the answer may be too large, return it modulo 10^9 + 7.",
"examples": [
"Input: s = \"10101\"",
"Output: 4",
"Explanation: There are four ways to split s in 3 parts where each part contain the same number of letters '1'.",
"\"1|010|1\"",
"\"1|01|01\"",
"\"10|10|1\"",
"\"10|1|01\"",
"Input: s = \"1001\"",
"Output: 0",
"Input: s = \"0000\"",
"Output: 3",
"Explanation: There are three ways to split s in 3 parts.",
"\"0|0|00\"",
"\"0|00|0\"",
"\"00|0|0\"",
"Input: s = \"100100010100110\"",
"Output: 12",
""
],
"constraints": [
"3 <= s. length <= 10^5s[i] is '0' or '1'."
]
},
{
"id": "1574",
"title": "Shortest Subarray to be Removed to Make Array Sorted",
"question": "Given an integer array arr, remove a subarray (can be empty) from arr such that the remaining elements in arr are non-decreasing.\nA subarray is a contiguous subsequence of the array.\nReturn the length of the shortest subarray to remove.",
"examples": [
"Input: arr = [1,2,3,10,4,2,3,5]",
"Output: 3",
"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.",
"Another correct solution is to remove the subarray [3,10,4]. Input: arr = [5,4,3,2,1]",
"Output: 4",
"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].",
"Input: arr = [1,2,3]",
"Output: 0",
"Explanation: The array is already non-decreasing. We do not need to remove any elements.",
"Input: arr = [1]",
"Output: 0",
""
],
"constraints": [
"1 <= arr. length <= 10^50 <= arr[i] <= 10^9"
]
},
{
"id": "1577",
"title": "Number of Ways Where Square of Number Is Equal to Product of Two Numbers",
"question": "Given two arrays of integers nums1 and nums2, return the number of triplets formed (type 1 and type 2) under the following rules:",
"examples": [
"Input: nums1 = [7,4], nums2 = [5,2,8,9]",
"Output: 1",
"Explanation: Type 1: (1,1,2), nums1[1]^2 = nums2[1] * nums2[2]. (4^2 = 2 * 8). ",
"Input: nums1 = [1,1], nums2 = [1,1,1]",
"Output: 9",
"Explanation: All Triplets are valid, because 1^2 = 1 * 1.",
"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].",
"Type 2: (0,0,1), (1,0,1), (2,0,1). nums2[i]^2 = nums1[j] * nums1[k].",
"Input: nums1 = [7,7,8,3], nums2 = [1,2,9,7]",
"Output: 2",
"Explanation: There are 2 valid triplets.",
"Type 1: (3,0,2). nums1[3]^2 = nums2[0] * nums2[2].",
"Type 2: (3,0,1). nums2[3]^2 = nums1[0] * nums1[1].",
"Input: nums1 = [4,7,9,11,23], nums2 = [3,5,1024,12,18]",
"Output: 0",
"Explanation: There are no valid triplets.",
""
],
"constraints": [
"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. 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. 1 <= nums1. length",
" nums2. length <= 10001 <= nums1[i]",
" nums2[i] <= 10^5"
]
},
{
"id": "1578",
"title": "Minimum Deletion Cost to Avoid Repeating Letters",
"question": "Given a string s and an array of integers cost where cost[i] is the cost of deleting the ith character in s.\nReturn the minimum cost of deletions such that there are no two identical letters next to each other.\nNotice that you will delete the chosen characters at the same time, in other words, after deleting a character, the costs of deleting other characters will not change.",
"examples": [
"Input: s = \"abaac\", cost = [1,2,3,4,5]",
"Output: 3",
"Explanation: Delete the letter \"a\" with cost 3 to get \"abac\" (String without two identical letters next to each other).",
"Input: s = \"abc\", cost = [1,2,3]",
"Output: 0",
"Explanation: You don't need to delete any character because there are no identical letters next to each other.",
"Input: s = \"aabaa\", cost = [1,2,3,4,1]",
"Output: 2",
"Explanation: Delete the first and the last character, getting the string (\"aba\").",
""
],
"constraints": [
"s. length == cost. length1 <= s. length",
" cost. length <= 10^51 <= cost[i] <= 10^4s contains only lowercase English letters."
]
},
{
"id": "1583",
"title": "Count Unhappy Friends",
"question": "You are given a list of preferences for n friends, where n is always even.\nFor each person i, preferences[i] contains a list of friends sorted in the order of preference.\n In other words, a friend earlier in the list is more preferred than a friend later in the list.\n Friends in each list are denoted by integers from 0 to n-1.\nAll the friends are divided into pairs.\n The pairings are given in a list pairs, where pairs[i] = [xi, yi] denotes xi is paired with yi and yi is paired with xi.\nHowever, this pairing may cause some of the friends to be unhappy.\n A friend x is unhappy if x is paired with y and there exists a friend u who is paired with v but:Return the number of unhappy friends.",
"examples": [
"Input: n = 4, preferences = [[1, 2, 3], [3, 2, 0], [3, 1, 0], [1, 2, 0]], pairs = [[0, 1], [2, 3]]",
"Output: 2",
"Explanation:",
"Friend 1 is unhappy because:",
"- 1 is paired with 0 but prefers 3 over 0, and",
"- 3 prefers 1 over 2.",
"Friend 3 is unhappy because:",
"- 3 is paired with 2 but prefers 1 over 2, and",
"- 1 prefers 3 over 0.",
"Friends 0 and 2 are happy.",
"Input: n = 2, preferences = [[1], [0]], pairs = [[1, 0]]",
"Output: 0",
"Explanation: Both friends 0 and 1 are happy.",
"Input: n = 4, preferences = [[1, 3, 2], [2, 3, 0], [1, 3, 0], [0, 2, 1]], pairs = [[1, 3], [0, 2]]",
"Output: 4",
""
],
"constraints": [
"x prefers u over y",
" andu prefers x over v. 2 <= n <= 500n is even. preferences. length == npreferences[i]. length == n - 10 <= preferences[i][j] <= n - 1preferences[i] does not contain i. All values in preferences[i] are unique. pairs. length == n/2pairs[i]. length == 2xi != yi0 <= xi",
" yi <= n - 1Each person is contained in exactly one pair."
]
},
{
"id": "496",
"title": "Next Greater Element I",
"question": "The next greater element of some element x in an array is the first greater element that is to the right of x in the same array.\nYou are given two distinct 0-indexed integer arrays nums1 and nums2, where nums1 is a subset of nums2.\nFor each 0 <= i < nums1.\nlength, find the index j such that nums1[i] == nums2[j] and determine the next greater element of nums2[j] in nums2.\n If there is no next greater element, then the answer for this query is -1.\nReturn an array ans of length nums1.\nlength such that ans[i] is the next greater element as described above.",
"examples": [
"Input: nums1 = [4,1,2], nums2 = [1,3,4,2]",
"Output: [-1,3,-1]",
"Explanation: The next greater element for each value of nums1 is as follows:",
"- 4 is underlined in nums2 = [1,3,4,2]. There is no next greater element, so the answer is -1.",
"- 1 is underlined in nums2 = [1,3,4,2]. The next greater element is 3.",
"- 2 is underlined in nums2 = [1,3,4,2]. There is no next greater element, so the answer is -1.",
"Input: nums1 = [2,4], nums2 = [1,2,3,4]",
"Output: [3,-1]",
"Explanation: The next greater element for each value of nums1 is as follows:",
"- 2 is underlined in nums2 = [1,2,3,4]. The next greater element is 3.",
"- 4 is underlined in nums2 = [1,2,3,4]. There is no next greater element, so the answer is -1.",
""
],
"constraints": [
"1 <= nums1. length <= nums2. length <= 10000 <= nums1[i]",
" nums2[i] <= 104All integers in nums1 and nums2 are unique. All the integers of nums1 also appear in nums2."
]
},
{
"id": "1584",
"title": "Min Cost to Connect All Points",
"question": "You are given an array points representing integer coordinates of some points on a 2D-plane, where points[i] = [xi, yi].\nThe 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.\nReturn the minimum cost to make all points connected.\n All points are connected if there is exactly one simple path between any two points.",
"examples": [
"Input: points = [[0,0],[2,2],[3,10],[5,2],[7,0]]",
"Output: 20",
"Explanation:",
"",
"We can connect the points as shown above to get the minimum cost of 20.",
"Notice that there is a unique path between every pair of points.",
"Input: points = [[3,12],[-2,5],[-4,1]]",
"Output: 18",
"Input: points = [[0,0],[1,1],[1,0],[-1,1]]",
"Output: 4",
"Input: points = [[-1000000,-1000000],[1000000,1000000]]",
"Output: 4000000",
"Input: points = [[0,0]]",
"Output: 0",
""
],
"constraints": [
"1 <= points. length <= 1000-106 <= xi",
" yi <= 106All pairs (xi",
" yi) are distinct."
]
},
{
"id": "1589",
"title": "Maximum Sum Obtained of Any Permutation",
"question": "We have an array of integers, nums, and an array of requests where requests[i] = [starti, endi].\n The ith request asks for the sum of nums[starti] + nums[starti + 1] + .\n.\n.\n + nums[endi - 1] + nums[endi].\n Both starti and endi are 0-indexed.\nReturn the maximum total sum of all requests among all permutations of nums.\nSince the answer may be too large, return it modulo 109 + 7.",
"examples": [
"Input: nums = [1,2,3,4,5], requests = [[1,3],[0,1]]",
"Output: 19",
"Explanation: One permutation of nums is [2,1,3,4,5] with the following result: ",
"requests[0] -> nums[1] + nums[2] + nums[3] = 1 + 3 + 4 = 8",
"requests[1] -> nums[0] + nums[1] = 2 + 1 = 3",
"Total sum: 8 + 3 = 11.",
"A permutation with a higher total sum is [3,5,4,2,1] with the following result:",
"requests[0] -> nums[1] + nums[2] + nums[3] = 5 + 4 + 2 = 11",
"requests[1] -> nums[0] + nums[1] = 3 + 5 = 8",
"Total sum: 11 + 8 = 19, which is the best that you can do.",
"Input: nums = [1,2,3,4,5,6], requests = [[0,1]]",
"Output: 11",
"Explanation: A permutation with the max total sum is [6,5,4,3,2,1] with request sums [11]. Input: nums = [1,2,3,4,5,10], requests = [[0,2],[1,3],[1,1]]",
"Output: 47",
"Explanation: A permutation with the max total sum is [4,10,5,3,2,1] with request sums [19,18,10]."
],
"constraints": [
"n == nums. length1 <= n <= 1050 <= nums[i] <= 1051 <= requests. length <= 105requests[i]. length == 20 <= starti <= endi < n"
]
},
{
"id": "1590",
"title": "Make Sum Divisible by P",
"question": "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.\n It is not allowed to remove the whole array.\nReturn the length of the smallest subarray that you need to remove, or -1 if it's impossible.\nA subarray is defined as a contiguous block of elements in the array.",
"examples": [
"Input: nums = [3,1,4,2], p = 6",
"Output: 1",
"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.",
"Input: nums = [6,3,5,2], p = 9",
"Output: 2",
"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.",
"Input: nums = [1,2,3], p = 3",
"Output: 0",
"Explanation: Here the sum is 6. which is already divisible by 3. Thus we do not need to remove anything.",
"Input: nums = [1,2,3], p = 7",
"Output: -1",
"Explanation: There is no way to remove a subarray in order to get a sum divisible by 7.",
"Input: nums = [1000000000,1000000000,1000000000], p = 3",
"Output: 0",
""
],
"constraints": [
"1 <= nums. length <= 1051 <= nums[i] <= 1091 <= p <= 109"
]
},
{
"id": "1593",
"title": "Split a String Into the Max Number of Unique Substrings",
"question": "Given a string s, return the maximum number of unique substrings that the given string can be split into.\nYou can split string s into any list of non-empty substrings, where the concatenation of the substrings forms the original string.\n However, you must split the substrings such that all of them are unique.\nA substring is a contiguous sequence of characters within a string.",
"examples": [
"Input: s = \"ababccc\"",
"Output: 5",
"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.",
"Input: s = \"aba\"",
"Output: 2",
"Explanation: One way to split maximally is ['a', 'ba'].",
"Input: s = \"aa\"",
"Output: 1",
"Explanation: It is impossible to split the string any further.",
""
],
"constraints": [
"\n1 <= s. length <= 16\n\ns contains only lower case English letters.\n"
]
},
{
"id": "1594",
"title": "Maximum Non Negative Product in a Matrix",
"question": "You are given a rows x cols matrix grid.\n 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.\nAmong all possible paths starting from the top-left corner (0, 0) and ending in the bottom-right corner (rows - 1, cols - 1), find the path with the maximum non-negative product.\n The product of a path is the product of all integers in the grid cells visited along the path.\nReturn the maximum non-negative product modulo 109 + 7.\n If the maximum product is negative return -1.\nNotice that the modulo is performed after getting the maximum product.",
"examples": [
"Input: grid = [[-1,-2,-3],",
"  [-2,-3,-3],",
"  [-3,-3,-2]]",
"Output: -1",
"Explanation: It's not possible to get non-negative product in the path from (0, 0) to (2, 2), so return -1.",
"Input: grid = [[1,-2,1],",
"  [1,-2,1],",
"  [3,-4,1]]",
"Output: 8",
"Explanation: Maximum non-negative product is in bold (1 * 1 * -2 * -4 * 1 = 8).",
"Input: grid = [[1, 3],",
"  [0,-4]]",
"Output: 0",
"Explanation: Maximum non-negative product is in bold (1 * 0 * -4 = 0).",
"Input: grid = [[ 1, 4,4,0],",
"  [-2, 0,0,1],",
"  [ 1,-1,1,1]]",
"Output: 2",
"Explanation: Maximum non-negative product is in bold (1 * -2 * 1 * -1 * 1 * 1 = 2).",
""
],
"constraints": [
"1 <= rows",
" cols <= 15-4 <= grid[i][j] <= 4"
]
},
{
"id": "1599",
"title": "Maximum Profit of Operating a Centennial Wheel",
"question": "You are the operator of a Centennial Wheel that has four gondolas, and each gondola has room for up to four people.\n You have the ability to rotate the gondolas counterclockwise, which costs you runningCost dollars.\nYou 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).\n This means you must rotate the wheel i times before the customers[i] customers arrive.\n You cannot make customers wait if there is room in the gondola.\n 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.\nYou can stop the wheel at any time, including before serving all customers.\n If you decide to stop serving customers, all subsequent rotations are free in order to get all the customers down safely.\n 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.\nReturn the minimum number of rotations you need to perform to maximize your profit.\n If there is no scenario where the profit is positive, return -1.",
"examples": [
"Input: customers = [8,3], boardingCost = 5, runningCost = 6",
"Output: 3",
"Explanation: The numbers written on the gondolas are the number of people currently there.",
"1. 8 customers arrive, 4 board and 4 wait for the next gondola, the wheel rotates. Current profit is 4 * $5 - 1 * $6 = $14.",
"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.",
"3. The final 3 customers board the gondola, the wheel rotates. Current profit is 11 * $5 - 3 * $6 = $37.",
"The highest profit was $37 after rotating the wheel 3 times. Input: customers = [10,9,6], boardingCost = 6, runningCost = 4",
"Output: 7",
"Explanation:",
"1. 10 customers arrive, 4 board and 6 wait for the next gondola, the wheel rotates. Current profit is 4 * $6 - 1 * $4 = $20.",
"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.",
"3. The final 6 customers arrive, 4 board and 13 wait, the wheel rotates. Current profit is 12 * $6 - 3 * $4 = $60.",
"4. 4 board and 9 wait, the wheel rotates. Current profit is 16 * $6 - 4 * $4 = $80.",
"5. 4 board and 5 wait, the wheel rotates. Current profit is 20 * $6 - 5 * $4 = $100.",
"6. 4 board and 1 waits, the wheel rotates. Current profit is 24 * $6 - 6 * $4 = $120.",
"7. 1 boards, the wheel rotates. Current profit is 25 * $6 - 7 * $4 = $122.",
"The highest profit was $122 after rotating the wheel 7 times.",
"",
"Input: customers = [3,4,0,5,1], boardingCost = 1, runningCost = 92",
"Output: -1",
"Explanation:",
"1. 3 customers arrive, 3 board and 0 wait, the wheel rotates. Current profit is 3 * $1 - 1 * $92 = -$89.",
"2. 4 customers arrive, 4 board and 0 wait, the wheel rotates. Current profit is 7 * $1 - 2 * $92 = -$177.",
"3. 0 customers arrive, 0 board and 0 wait, the wheel rotates. Current profit is 7 * $1 - 3 * $92 = -$269.",
"4. 5 customers arrive, 4 board and 1 waits, the wheel rotates. Current profit is 11 * $1 - 4 * $92 = -$357.",
"5. 1 customer arrives, 2 board and 0 wait, the wheel rotates. Current profit is 13 * $1 - 5 * $92 = -$447.",
"The profit was never positive, so return -1.",
"Input: customers = [10,10,6,4,7], boardingCost = 3, runningCost = 8",
"Output: 9",
"Explanation:",
"1. 10 customers arrive, 4 board and 6 wait, the wheel rotates. Current profit is 4 * $3 - 1 * $8 = $4.",
"2. 10 customers arrive, 4 board and 12 wait, the wheel rotates. Current profit is 8 * $3 - 2 * $8 = $8.",
"3. 6 customers arrive, 4 board and 14 wait, the wheel rotates. Current profit is 12 * $3 - 3 * $8 = $12.",
"4. 4 customers arrive, 4 board and 14 wait, the wheel rotates. Current profit is 16 * $3 - 4 * $8 = $16.",
"5. 7 customers arrive, 4 board and 17 wait, the wheel rotates. Current profit is 20 * $3 - 5 * $8 = $20.",
"6. 4 board and 13 wait, the wheel rotates. Current profit is 24 * $3 - 6 * $8 = $24.",
"7. 4 board and 9 wait, the wheel rotates. Current profit is 28 * $3 - 7 * $8 = $28.",
"8. 4 board and 5 wait, the wheel rotates. Current profit is 32 * $3 - 8 * $8 = $32.",
"9. 4 board and 1 waits, the wheel rotates. Current profit is 36 * $3 - 9 * $8 = $36.",
"10. 1 board and 0 wait, the wheel rotates. Current profit is 37 * $3 - 10 * $8 = $31.",
"The highest profit was $36 after rotating the wheel 9 times.",
""
],
"constraints": [
"n == customers. length1 <= n <= 1050 <= customers[i] <= 501 <= boardingCost",
" runningCost <= 100"
]
},
{
"id": "1600",
"title": "Throne Inheritance",
"question": "A kingdom consists of a king, his children, his grandchildren, and so on.\n Every once in a while, someone in the family dies or a child is born.\nThe kingdom has a well-defined order of inheritance that consists of the king as the first member.\n Let's define the recursive function Successor(x, curOrder), which given a person x and the inheritance order so far, returns who should be the next person after x in the order of inheritance.\nFor example, assume we have a kingdom that consists of the king, his children Alice and Bob (Alice is older than Bob), and finally Alice's son Jack.\nUsing the above function, we can always obtain a unique order of inheritance.\nImplement the ThroneInheritance class:",
"examples": [
"Successor(x, curOrder):",
" if x has no children or all of x's children are in curOrder:",
" if x is the king return null",
" else return Successor(x's parent, curOrder)",
" else return x's oldest child who's not in curOrder",
"Input",
"[\"ThroneInheritance\", \"birth\", \"birth\", \"birth\", \"birth\", \"birth\", \"birth\", \"getInheritanceOrder\", \"death\", \"getInheritanceOrder\"]",
"[[\"king\"], [\"king\", \"andy\"], [\"king\", \"bob\"], [\"king\", \"catherine\"], [\"andy\", \"matthew\"], [\"bob\", \"alex\"], [\"bob\", \"asha\"], [null], [\"bob\"], [null]]",
"Output",
"[null, null, null, null, null, null, null, [\"king\", \"andy\", \"matthew\", \"bob\", \"alex\", \"asha\", \"catherine\"], null, [\"king\", \"andy\", \"matthew\", \"alex\", \"asha\", \"catherine\"]]",
"",
"Explanation",
"ThroneInheritance t= new ThroneInheritance(\"king\"); // order: king",
"t. birth(\"king\", \"andy\"); // order: king > andy",
"t. birth(\"king\", \"bob\"); // order: king > andy > bob",
"t. birth(\"king\", \"catherine\"); // order: king > andy > bob > catherine",
"t. birth(\"andy\", \"matthew\"); // order: king > andy > matthew > bob > catherine",
"t. birth(\"bob\", \"alex\"); // order: king > andy > matthew > bob > alex > catherine",
"t. birth(\"bob\", \"asha\"); // order: king > andy > matthew > bob > alex > asha > catherine",
"t. getInheritanceOrder(); // return [\"king\", \"andy\", \"matthew\", \"bob\", \"alex\", \"asha\", \"catherine\"]",
"t. death(\"bob\"); // order: king > andy > matthew > bob > alex > asha > catherine",
"t. getInheritanceOrder(); // return [\"king\", \"andy\", \"matthew\", \"alex\", \"asha\", \"catherine\"]",
""
],
"constraints": [
"ThroneInheritance(string kingName) Initializes an object of the ThroneInheritance class. The name of the king is given as part of the constructor. void birth(string parentName",
" string childName) Indicates that parentName gave birth to childName. void death(string name) Indicates the death of name. The death of the person doesn't affect the Successor function nor the current inheritance order. You can treat it as just marking the person as dead. string[] getInheritanceOrder() Returns a list representing the current order of inheritance excluding dead people. 1 <= kingName. length",
" parentName. length",
" childName. length",
" name. length <= 15kingName",
" parentName",
" childName",
" and name consist of lowercase English letters only. All arguments childName and kingName are distinct. All name arguments of death will be passed to either the constructor or as childName to birth first. For each call to birth(parentName",
" childName)",
" it is guaranteed that parentName is alive. At most 105 calls will be made to birth and death. At most 10 calls will be made to getInheritanceOrder."
]
},
{
"id": "1604",
"title": "Alert Using Same Key-Card Three or More Times in a One Hour Period",
"question": "LeetCode company workers use key-cards to unlock office doors.\n Each time a worker uses their key-card, the security system saves the worker's name and the time when it was used.\n The system emits an alert if any worker uses the key-card three or more times in a one-hour period.\nYou 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.\nAccess times are given in the 24-hour time format \"HH:MM\", such as \"23:51\" and \"09:49\".\nReturn a list of unique worker names who received an alert for frequent keycard use.\n Sort the names in ascending order alphabetically.\nNotice 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.",
"examples": [
"Input: keyName = [\"daniel\",\"daniel\",\"daniel\",\"luis\",\"luis\",\"luis\",\"luis\"], keyTime = [\"10:00\",\"10:40\",\"11:00\",\"09:00\",\"11:00\",\"13:00\",\"15:00\"]",
"Output: [\"daniel\"]",
"Explanation: \"daniel\" used the keycard 3 times in a one-hour period (\"10:00\",\"10:40\", \"11:00\").",
"Input: keyName = [\"alice\",\"alice\",\"alice\",\"bob\",\"bob\",\"bob\",\"bob\"], keyTime = [\"12:01\",\"12:00\",\"18:00\",\"21:00\",\"21:20\",\"21:30\",\"23:00\"]",
"Output: [\"bob\"]",
"Explanation: \"bob\" used the keycard 3 times in a one-hour period (\"21:00\",\"21:20\", \"21:30\").",
"Input: keyName = [\"john\",\"john\",\"john\"], keyTime = [\"23:58\",\"23:59\",\"00:01\"]",
"Output: []",
"Input: keyName = [\"leslie\",\"leslie\",\"leslie\",\"clare\",\"clare\",\"clare\",\"clare\"], keyTime = [\"13:00\",\"13:20\",\"14:00\",\"18:00\",\"18:51\",\"19:30\",\"19:49\"]",
"Output: [\"clare\",\"leslie\"]",
""
],
"constraints": [
"1 <= keyName. length",
" keyTime. length <= 105keyName. length == keyTime. lengthkeyTime[i] is in the format \"HH:MM\".[keyName[i]",
" keyTime[i]] is unique. 1 <= keyName[i]. length <= 10keyName[i] contains only lowercase English letters."
]
},
{
"id": "1605",
"title": "Find Valid Matrix Given Row and Column Sums",
"question": "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.\n In other words, you do not know the elements of the matrix, but you do know the sums of each row and column.\nFind any matrix of non-negative integers of size rowSum.\nlength x colSum.\nlength that satisfies the rowSum and colSum requirements.\nReturn a 2D array representing any matrix that fulfills the requirements.\n It's guaranteed that at least one matrix that fulfills the requirements exists.",
"examples": [
"Input: rowSum = [3,8], colSum = [4,7]",
"Output: [[3,0],",
" [1,7]]",
"Explanation:",
"0th row: 3 + 0 = 3 == rowSum[0]",
"1st row: 1 + 7 = 8 == rowSum[1]",
"0th column: 3 + 1 = 4 == colSum[0]",
"1st column: 0 + 7 = 7 == colSum[1]",
"The row and column sums match, and all matrix elements are non-negative.",
"Another possible matrix is: [[1,2],",
" [3,5]]",
"Input: rowSum = [5,7,10], colSum = [8,6,8]",
"Output: [[0,5,0],",
" [6,1,0],",
" [2,0,8]]",
"Input: rowSum = [14,9], colSum = [6,9,8]",
"Output: [[0,9,5],",
" [6,0,3]]",
"Input: rowSum = [1,0], colSum = [1]",
"Output: [[1],",
" [0]]",
"Input: rowSum = [0], colSum = [0]",
"Output: [[0]]",
""
],
"constraints": [
"1 <= rowSum. length",
" colSum. length <= 5000 <= rowSum[i]",
" colSum[i] <= 108sum(rows) == sum(columns)"
]
},
{
"id": "1609",
"title": "Even Odd Tree",
"question": "A binary tree is named Even-Odd if it meets the following conditions:Given the root of a binary tree, return true if the binary tree is Even-Odd, otherwise return false.",
"examples": [
"Input: root = [1,10,4,3,null,7,9,12,8,6,null,null,2]",
"Output: true",
"Explanation: The node values on each level are:",
"Level 0: [1]",
"Level 1: [10,4]",
"Level 2: [3,7,9]",
"Level 3: [12,8,6,2]",
"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.",
"Input: root = [5,4,2,3,3,7]",
"Output: false",
"Explanation: The node values on each level are:",
"Level 0: [5]",
"Level 1: [4,2]",
"Level 2: [3,3,7]",
"Node values in the level 2 must be in strictly increasing order, so the tree is not Even-Odd.",
"Input: root = [5,9,1,3,5,7]",
"Output: false",
"Explanation: Node values in the level 1 should be even integers.",
"Input: root = [1]",
"Output: true",
"Input: root = [11,8,6,1,3,9,11,30,20,18,16,12,10,4,2,17]",
"Output: true",
""
],
"constraints": [
"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. For every even-indexed level",
" all nodes at the level have odd integer values in strictly increasing order (from left to right). For every odd-indexed level",
" all nodes at the level have even integer values in strictly decreasing order (from left to right). The number of nodes in the tree is in the range [1",
" 105]. 1 <= Node. val <= 106"
]
},
{
"id": "500",
"title": "Keyboard Row",
"question": "Given an array of strings words, return the words that can be typed using letters of the alphabet on only one row of American keyboard like the image below.\nIn the American keyboard:",
"examples": [
"Input: words = [\"Hello\",\"Alaska\",\"Dad\",\"Peace\"]",
"Output: [\"Alaska\",\"Dad\"]",
"Input: words = [\"omk\"]",
"Output: []",
"Input: words = [\"adsdf\",\"sfd\"]",
"Output: [\"adsdf\",\"sfd\"]",
""
],
"constraints": [
"the first row consists of the characters \"qwertyuiop\"",
"the second row consists of the characters \"asdfghjkl\"",
" andthe third row consists of the characters \"zxcvbnm\". 1 <= words. length <= 201 <= words[i]. length <= 100words[i] consists of English letters (both lowercase and uppercase). "
]
},
{
"id": "1615",
"title": "Maximal Network Rank",
"question": "There is an infrastructure of n cities with some number of roads connecting these cities.\n Each roads[i] = [ai, bi] indicates that there is a bidirectional road between cities ai and bi.\nThe network rank of two different cities is defined as the total number of directly connected roads to either city.\n If a road is directly connected to both cities, it is only counted once.\nThe maximal network rank of the infrastructure is the maximum network rank of all pairs of different cities.\nGiven the integer n and the array roads, return the maximal network rank of the entire infrastructure.",
"examples": [
"Input: n = 4, roads = [[0,1],[0,3],[1,2],[1,3]]",
"Output: 4",
"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.",
"Input: n = 5, roads = [[0,1],[0,3],[1,2],[1,3],[2,3],[2,4]]",
"Output: 5",
"Explanation: There are 5 roads that are connected to cities 1 or 2.",
"Input: n = 8, roads = [[0,1],[1,2],[2,3],[2,4],[5,6],[5,7]]",
"Output: 5",
"Explanation: The network rank of 2 and 5 is 5. Notice that all the cities do not have to be connected.",
""
],
"constraints": [
"2 <= n <= 1000 <= roads. length <= n * (n - 1) / 2roads[i]. length == 20 <= ai",
" bi <= n-1ai != biEach pair of cities has at most one road connecting them."
]
},
{
"id": "1616",
"title": "Split Two Strings to Make Palindrome",
"question": "You are given two strings a and b of the same length.\n 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.\n Check if aprefix + bsuffix or bprefix + asuffix forms a palindrome.\nWhen you split a string s into sprefix and ssuffix, either ssuffix or sprefix is allowed to be empty.\n For example, if s = \"abc\", then \"\" + \"abc\", \"a\" + \"bc\", \"ab\" + \"c\" , and \"abc\" + \"\" are valid splits.\nReturn true if it is possible to form a palindrome string, otherwise return false.\nNotice that x + y denotes the concatenation of strings x and y.",
"examples": [
"Input: a = \"x\", b = \"y\"",
"Output: true",
"Explaination: If either a or b are palindromes the answer is true since you can split in the following way:",
"aprefix = \"\", asuffix = \"x\"",
"bprefix = \"\", bsuffix = \"y\"",
"Then, aprefix + bsuffix = \"\" + \"y\" = \"y\", which is a palindrome.",
"Input: a = \"abdef\", b = \"fecab\"",
"Output: true",
"Input: a = \"ulacfd\", b = \"jizalu\"",
"Output: true",
"Explaination: Split them at index 3:",
"aprefix = \"ula\", asuffix = \"cfd\"",
"bprefix = \"jiz\", bsuffix = \"alu\"",
"Then, aprefix + bsuffix = \"ula\" + \"alu\" = \"ulaalu\", which is a palindrome.",
"Input: a = \"xbdef\", b = \"xecab\"",
"Output: false",
""
],
"constraints": [
"1 <= a. length",
" b. length <= 105a. length == b. lengtha and b consist of lowercase English letters"
]
},
{
"id": "1620",
"title": "Coordinate With Maximum Network Quality",
"question": "You are given an array of network towers towers and an integer radius, where towers[i] = [xi, yi, qi] denotes the ith network tower with location (xi, yi) and quality factor qi.\n All the coordinates are integral coordinates on the X-Y plane, and the distance between two coordinates is the Euclidean distance.\nThe integer radius denotes the maximum distance in which the tower is reachable.\n The tower is reachable if the distance is less than or equal to radius.\n Outside that distance, the signal becomes garbled, and the tower is not reachable.\nThe signal quality of the ith tower at a coordinate (x, y) is calculated with the formula ⌊qi / (1 + d)⌋, where d is the distance between the tower and the coordinate.\n The network quality at a coordinate is the sum of the signal qualities from all the reachable towers.\nReturn the integral coordinate where the network quality is maximum.\n If there are multiple coordinates with the same network quality, return the lexicographically minimum coordinate.\nNote:",
"examples": [
"Input: towers = [[1,2,5],[2,1,7],[3,1,9]], radius = 2",
"Output: [2,1]",
"Explanation: ",
"At coordinate (2, 1) the total quality is 13",
"- Quality of 7 from (2, 1) results in ⌊7 / (1 + sqrt(0)⌋ = ⌊7⌋ = 7",
"- Quality of 5 from (1, 2) results in ⌊5 / (1 + sqrt(2)⌋ = ⌊2. 07⌋ = 2",
"- Quality of 9 from (3, 1) results in ⌊9 / (1 + sqrt(1)⌋ = ⌊4. 5⌋ = 4",
"No other coordinate has higher quality. Input: towers = [[23,11,21]], radius = 9",
"Output: [23,11]",
"Input: towers = [[1,2,13],[2,1,7],[0,1,9]], radius = 2",
"Output: [1,2]",
"Input: towers = [[2,1,9],[0,1,9]], radius = 2",
"Output: [0,1]",
"Explanation: Both (0, 1) and (2, 1) are optimal in terms of quality but (0, 1) is lexicograpically minimal.",
""
],
"constraints": [
"A coordinate (x1",
" y1) is lexicographically smaller than (x2",
" y2) if either x1 < x2 or x1 == x2 and y1 < y2.⌊val⌋ is the greatest integer less than or equal to val (the floor function). 1 <= towers. length <= 50towers[i]. length == 30 <= xi",
" yi",
" qi <= 501 <= radius <= 50"
]
},
{
"id": "1621",
"title": "Number of Sets of K Non-Overlapping Line Segments",
"question": "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.\n The endpoints of each segment must have integral coordinates.\n The k line segments do not have to cover all n points, and they are allowed to share endpoints.\nReturn the number of ways we can draw k non-overlapping line segments.\n Since this number can be huge, return it modulo 109 + 7.",
"examples": [
"Input: n = 4, k = 2",
"Output: 5",
"Explanation: ",
"The two line segments are shown in red and blue.",
"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)}. Input: n = 3, k = 1",
"Output: 3",
"Explanation: The 3 ways are {(0,1)}, {(0,2)}, {(1,2)}.",
"Input: n = 30, k = 7",
"Output: 796297179",
"Explanation: The total number of possible ways to draw 7 line segments is 3796297200. Taking this number modulo 109 + 7 gives us 796297179.",
"Input: n = 5, k = 3",
"Output: 7",
"Input: n = 3, k = 2",
"Output: 1"
],
"constraints": [
"2 <= n <= 10001 <= k <= n-1"
]
},
{
"id": "1625",
"title": "Lexicographically Smallest String After Applying Operations",
"question": "You are given a string s of even length consisting of digits from 0 to 9, and two integers a and b.\nYou can apply either of the following two operations any number of times and in any order on s:Return the lexicographically smallest string you can obtain by applying the above operations any number of times on s.\nA 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 For example, \"0158\" is lexicographically smaller than \"0190\" because the first position they differ is at the third letter, and '5' comes before '9'.",
"examples": [
"Input: s = \"5525\", a = 9, b = 2",
"Output: \"2050\"",
"Explanation: We can apply the following operations:",
"Start: \"5525\"",
"Rotate: \"2555\"",
"Add: \"2454\"",
"Add: \"2353\"",
"Rotate: \"5323\"",
"Add: \"5222\"",
"​​​​​​​Add: \"5121\"",
"​​​​​​​Rotate: \"2151\"",
"​​​​​​​Add: \"2050\"​​​​​​​​​​​​",
"There is no way to obtain a string that is lexicographically smaller then \"2050\".",
"Input: s = \"74\", a = 5, b = 1",
"Output: \"24\"",
"Explanation: We can apply the following operations:",
"Start: \"74\"",
"Rotate: \"47\"",
"​​​​​​​Add: \"42\"",
"​​​​​​​Rotate: \"24\"​​​​​​​​​​​​",
"There is no way to obtain a string that is lexicographically smaller then \"24\".",
"Input: s = \"0011\", a = 4, b = 2",
"Output: \"0011\"",
"Explanation: There are no sequence of operations that will give us a lexicographically smaller string than \"0011\".",
"Input: s = \"43987654\", a = 7, b = 3",
"Output: \"00553311\"",
""
],
"constraints": [
"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\". Rotate s to the right by b positions. For example",
" if s = \"3456\" and b = 1",
" s becomes \"6345\". 2 <= s. length <= 100s. length is even. s consists of digits from 0 to 9 only. 1 <= a <= 91 <= b <= s. length - 1"
]
},
{
"id": "1626",
"title": "Best Team With No Conflicts",
"question": "You are the manager of a basketball team.\n For the upcoming tournament, you want to choose the team with the highest overall score.\n The score of the team is the sum of scores of all the players in the team.\nHowever, the basketball team is not allowed to have conflicts.\n A conflict exists if a younger player has a strictly higher score than an older player.\n A conflict does not occur between players of the same age.\nGiven 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.",
"examples": [
"Input: scores = [1,3,5,10,15], ages = [1,2,3,4,5]",
"Output: 34",
"Explanation: You can choose all the players.",
"Input: scores = [4,5,6,5], ages = [2,1,2,1]",
"Output: 16",
"Explanation: It is best to choose the last 3 players. Notice that you are allowed to choose multiple people of the same age.",
"Input: scores = [1,2,3,5], ages = [8,9,10,1]",
"Output: 6",
"Explanation: It is best to choose the first 3 players. ",
""
],
"constraints": [
"1 <= scores. length",
" ages. length <= 1000scores. length == ages. length1 <= scores[i] <= 1061 <= ages[i] <= 1000"
]
},
{
"id": "1630",
"title": "Arithmetic Subarrays",
"question": "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.\n More formally, a sequence s is arithmetic if and only if s[i+1] - s[i] == s[1] - s[0] for all valid i.\nFor example, these are arithmetic sequences:The following sequence is not arithmetic: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]].\n All the arrays are 0-indexed.\nReturn a list of boolean elements answer, where answer[i] is true if the subarray nums[l[i]], nums[l[i]+1], .\n.\n.\n , nums[r[i]] can be rearranged to form an arithmetic sequence, and false otherwise.",
"examples": [
"1, 3, 5, 7, 9",
"7, 7, 7, 7",
"3, -1, -5, -91, 1, 2, 5, 7Input: nums = [4,6,5,9,3,7], l = [0,0,2], r = [2,3,5]",
"Output: [true,false,true]",
"Explanation:",
"In the 0th query, the subarray is [4,6,5]. This can be rearranged as [6,5,4], which is an arithmetic sequence.",
"In the 1st query, the subarray is [4,6,5,9]. This cannot be rearranged as an arithmetic sequence.",
"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. Input: 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]",
"Output: [false,true,false,false,true,true]",
""
],
"constraints": [
"n == nums. lengthm == l. lengthm == r. length2 <= n <= 5001 <= m <= 5000 <= l[i] < r[i] < n-105 <= nums[i] <= 105"
]
},
{
"id": "1631",
"title": "Path With Minimum Effort",
"question": "You are a hiker preparing for an upcoming hike.\n You are given heights, a 2D array of size rows x columns, where heights[row][col] represents the height of cell (row, col).\n 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.\ne.\n, 0-indexed).\n You can move up, down, left, or right, and you wish to find a route that requires the minimum effort.\nA route's effort is the maximum absolute difference in heights between two consecutive cells of the route.\nReturn the minimum effort required to travel from the top-left cell to the bottom-right cell.",
"examples": [
"Input: heights = [[1,2,2],[3,8,2],[5,3,5]]",
"Output: 2",
"Explanation: The route of [1,3,5,3,5] has a maximum absolute difference of 2 in consecutive cells.",
"This is better than the route of [1,2,2,2,5], where the maximum absolute difference is 3.",
"Input: heights = [[1,2,3],[3,8,4],[5,3,5]]",
"Output: 1",
"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].",
"Input: 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]]",
"Output: 0",
"Explanation: This route does not require any effort.",
""
],
"constraints": [
"rows == heights. lengthcolumns == heights[i]. length1 <= rows",
" columns <= 1001 <= heights[i][j] <= 106"
]
},
{
"id": "1637",
"title": "Widest Vertical Area Between Two Points Containing No Points",
"question": "Given n points on a 2D plane where points[i] = [xi, yi], Return the widest vertical area between two points such that no points are inside the area.\nA vertical area is an area of fixed-width extending infinitely along the y-axis (i.\ne.\n, infinite height).\n The widest vertical area is the one with the maximum width.\nNote that points on the edge of a vertical area are not considered included in the area.",
"examples": [
"Input: points = [[8,7],[9,9],[7,4],[9,7]]",
"Output: 1",
"Explanation: Both the red and the blue area are optimal.",
"Input: points = [[3,1],[9,0],[1,0],[1,4],[5,3],[8,8]]",
"Output: 3",
""
],
"constraints": [
"n == points. length2 <= n <= 105points[i]. length == 20 <= xi",
" yi <= 109"
]
},
{
"id": "1638",
"title": "Count Substrings That Differ by One Character",
"question": "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.\n In other words, find the number of substrings in s that differ from some substring in t by exactly one character.\nFor example, the underlined substrings in \"computer\" and \"computation\" only differ by the 'e'/'a', so this is a valid way.\nReturn the number of substrings that satisfy the condition above.\nA substring is a contiguous sequence of characters within a string.",
"examples": [
"Input: s = \"aba\", t = \"baba\"",
"Output: 6",
"Explanation: The following are the pairs of substrings from s and t that differ by exactly 1 character:",
"(\"aba\", \"baba\")",
"(\"aba\", \"baba\")",
"(\"aba\", \"baba\")",
"(\"aba\", \"baba\")",
"(\"aba\", \"baba\")",
"(\"aba\", \"baba\")",
"The underlined portions are the substrings that are chosen from s and t.",
"Input: s = \"ab\", t = \"bb\"",
"Output: 3",
"Explanation: The following are the pairs of substrings from s and t that differ by 1 character:",
"(\"ab\", \"bb\")",
"(\"ab\", \"bb\")",
"(\"ab\", \"bb\")",
"​​​​The underlined portions are the substrings that are chosen from s and t.",
"Input: s = \"a\", t = \"a\"",
"Output: 0",
"Input: s = \"abe\", t = \"bbc\"",
"Output: 10",
""
],
"constraints": [
"1 <= s. length",
" t. length <= 100s and t consist of lowercase English letters only."
]
},
{
"id": "501",
"title": "Find Mode in Binary Search Tree",
"question": "Given the root of a binary search tree (BST) with duplicates, return all the mode(s) (i.\ne.\n, the most frequently occurred element) in it.\nIf the tree has more than one mode, return them in any order.\nAssume a BST is defined as follows:",
"examples": [
"Input: root = [1,null,2,2]",
"Output: [2]",
"Input: root = [0]",
"Output: [0]",
""
],
"constraints": [
"The left subtree of a node contains only nodes with keys less than or equal to the node's key. The right subtree of a node contains only nodes with keys greater than or equal to the node's key. Both the left and right subtrees must also be binary search trees. The number of nodes in the tree is in the range [1",
" 104].-105 <= Node. val <= 105"
]
},
{
"id": "1641",
"title": "Count Sorted Vowel Strings",
"question": "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.\nA 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.",
"examples": [
"Input: n = 1",
"Output: 5",
"Explanation: The 5 sorted strings that consist of vowels only are [\"a\",\"e\",\"i\",\"o\",\"u\"].",
"Input: n = 2",
"Output: 15",
"Explanation: The 15 sorted strings that consist of vowels only are",
"[\"aa\",\"ae\",\"ai\",\"ao\",\"au\",\"ee\",\"ei\",\"eo\",\"eu\",\"ii\",\"io\",\"iu\",\"oo\",\"ou\",\"uu\"].",
"Note that \"ea\" is not a valid string since 'e' comes after 'a' in the alphabet.",
"Input: n = 33",
"Output: 66045",
""
],
"constraints": [
"1 <= n <= 50 "
]
},
{
"id": "1642",
"title": "Furthest Building You Can Reach",
"question": "You are given an integer array heights representing the heights of buildings, some bricks, and some ladders.\nYou start your journey from building 0 and move to the next building by possibly using bricks or ladders.\nWhile moving from building i to building i+1 (0-indexed),Return the furthest building index (0-indexed) you can reach if you use the given ladders and bricks optimally.",
"examples": [
"Input: heights = [4,2,7,6,9,14,12], bricks = 5, ladders = 1",
"Output: 4",
"Explanation: Starting at building 0, you can follow these steps:",
"- Go to building 1 without using ladders nor bricks since 4 >= 2.",
"- Go to building 2 using 5 bricks. You must use either bricks or ladders because 2 < 7.",
"- Go to building 3 without using ladders nor bricks since 7 >= 6.",
"- Go to building 4 using your only ladder. You must use either bricks or ladders because 6 < 9.",
"It is impossible to go beyond building 4 because you do not have any more bricks or ladders.",
"Input: heights = [4,12,2,7,3,18,20,3,19], bricks = 10, ladders = 2",
"Output: 7",
"Input: heights = [14,3,19,3], bricks = 17, ladders = 0",
"Output: 3",
""
],
"constraints": [
"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. 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. 1 <= heights. length <= 1051 <= heights[i] <= 1060 <= bricks <= 1090 <= ladders <= heights. length"
]
},
{
"id": "1647",
"title": "Minimum Deletions to Make Character Frequencies Unique",
"question": "A string s is called good if there are no two different characters in s that have the same frequency.\nGiven a string s, return the minimum number of characters you need to delete to make s good.\nThe frequency of a character in a string is the number of times it appears in the string.\n For example, in the string \"aab\", the frequency of 'a' is 2, while the frequency of 'b' is 1.",
"examples": [
"Input: s = \"aab\"",
"Output: 0",
"Explanation: s is already good.",
"Input: s = \"aaabbbcc\"",
"Output: 2",
"Explanation: You can delete two 'b's resulting in the good string \"aaabcc\".",
"Another way it to delete one 'b' and one 'c' resulting in the good string \"aaabbc\". Input: s = \"ceabaacb\"",
"Output: 2",
"Explanation: You can delete both 'c's resulting in the good string \"eabaab\".",
"Note that we only care about characters that are still in the string at the end (i. e. frequency of 0 is ignored).",
""
],
"constraints": [
"1 <= s. length <= 105s contains only lowercase English letters."
]
},
{
"id": "1648",
"title": "Sell Diminishing-Valued Colored Balls",
"question": "You have an inventory of different colored balls, and there is a customer that wants orders balls of any color.\nThe customer weirdly values the colored balls.\n Each colored ball's value is the number of balls of that color you currently have in your inventory.\n For example, if you own 6 yellow balls, the customer would pay 6 for the first yellow ball.\n After the transaction, there are only 5 yellow balls left, so the next yellow ball is then valued at 5 (i.\ne.\n, the value of the balls decreases as you sell more to the customer).\nYou are given an integer array, inventory, where inventory[i] represents the number of balls of the ith color that you initially own.\n You are also given an integer orders, which represents the total number of balls that the customer wants.\n You can sell the balls in any order.\nReturn the maximum total value that you can attain after selling orders colored balls.\n As the answer may be too large, return it modulo 109 + 7.",
"examples": [
"Input: inventory = [2,5], orders = 4",
"Output: 14",
"Explanation: Sell the 1st color 1 time (2) and the 2nd color 3 times (5 + 4 + 3).",
"The maximum total value is 2 + 5 + 4 + 3 = 14.",
"Input: inventory = [3,5], orders = 6",
"Output: 19",
"Explanation: Sell the 1st color 2 times (3 + 2) and the 2nd color 4 times (5 + 4 + 3 + 2).",
"The maximum total value is 3 + 2 + 5 + 4 + 3 + 2 = 19.",
"Input: inventory = [2,8,4,10,6], orders = 20",
"Output: 110",
"Input: inventory = [1000000000], orders = 1000000000",
"Output: 21",
"Explanation: Sell the 1st color 1000000000 times for a total value of 500000000500000000. 500000000500000000 modulo 109 + 7 = 21.",
""
],
"constraints": [
"1 <= inventory. length <= 1051 <= inventory[i] <= 1091 <= orders <= min(sum(inventory[i])",
" 109)"
]
},
{
"id": "1653",
"title": "Minimum Deletions to Make String Balanced",
"question": "You are given a string s consisting only of characters 'a' and 'b'​​​​.\nYou can delete any number of characters in s to make s balanced.\n s is balanced if there is no pair of indices (i,j) such that i < j and s[i] = 'b' and s[j]= 'a'.\nReturn the minimum number of deletions needed to make s balanced.",
"examples": [
"Input: s = \"aababbab\"",
"Output: 2",
"Explanation: You can either:",
"Delete the characters at 0-indexed positions 2 and 6 (\"aababbab\" -> \"aaabbb\"), or",
"Delete the characters at 0-indexed positions 3 and 6 (\"aababbab\" -> \"aabbbb\").",
"Input: s = \"bbaaaaabb\"",
"Output: 2",
"Explanation: The only solution is to delete the first two characters.",
""
],
"constraints": [
"1 <= s. length <= 105s[i] is 'a' or 'b'​​."
]
},
{
"id": "1654",
"title": "Minimum Jumps to Reach Home",
"question": "A certain bug's home is on the x-axis at position x.\n Help them get there from position 0.\nThe bug jumps according to the following rules:The bug may jump forward beyond its home, but it cannot jump to positions numbered with negative integers.\nGiven 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.\n If there is no possible sequence of jumps that lands the bug on position x, return -1.",
"examples": [
"Input: forbidden = [14,4,18,1,15], a = 3, b = 15, x = 9",
"Output: 3",
"Explanation: 3 jumps forward (0 -> 3 -> 6 -> 9) will get the bug home.",
"Input: forbidden = [8,3,16,6,12,20], a = 15, b = 13, x = 11",
"Output: -1",
"Input: forbidden = [1,6,2,14,5,17,4], a = 16, b = 9, x = 7",
"Output: 2",
"Explanation: One jump forward (0 -> 16) then one jump backward (16 -> 7) will get the bug home.",
""
],
"constraints": [
"It can jump exactly a positions forward (to the right). It can jump exactly b positions backward (to the left). It cannot jump backward twice in a row. It cannot jump to any forbidden positions. 1 <= forbidden. length <= 10001 <= a",
" b",
" forbidden[i] <= 20000 <= x <= 2000All the elements in forbidden are distinct. Position x is not forbidden."
]
},
{
"id": "1657",
"title": "Determine if Two Strings Are Close",
"question": "Two strings are considered close if you can attain one from the other using the following operations:You can use the operations on either string as many times as necessary.\nGiven two strings, word1 and word2, return true if word1 and word2 are close, and false otherwise.",
"examples": [
"Input: word1 = \"abc\", word2 = \"bca\"",
"Output: true",
"Explanation: You can attain word2 from word1 in 2 operations.",
"Apply Operation 1: \"abc\" -> \"acb\"",
"Apply Operation 1: \"acb\" -> \"bca\"",
"Input: word1 = \"a\", word2 = \"aa\"",
"Output: false",
"Explanation: It is impossible to attain word2 from word1, or vice versa, in any number of operations.",
"Input: word1 = \"cabbba\", word2 = \"abbccc\"",
"Output: true",
"Explanation: You can attain word2 from word1 in 3 operations.",
"Apply Operation 1: \"cabbba\" -> \"caabbb\"",
"Apply Operation 2: \"caabbb\" -> \"baaccc\"",
"Apply Operation 2: \"baaccc\" -> \"abbccc\"",
"Input: word1 = \"cabbba\", word2 = \"aabbss\"",
"Output: false",
"Explanation: It is impossible to attain word2 from word1, or vice versa, in any amount of operations.",
""
],
"constraints": [
"Operation 1: Swap any two existing characters.\n\n\t\nFor example",
" abcde -> aecdb\n\nFor example",
" abcde -> aecdbOperation 2: Transform every occurrence of one existing character into another existing character",
" and do the same with the other character.\n\t\nFor example",
" aacabb -> bbcbaa (all a's turn into b's",
" and all b's turn into a's)\n\nFor example",
" aacabb -> bbcbaa (all a's turn into b's",
" and all b's turn into a's)1 <= word1. length",
" word2. length <= 105word1 and word2 contain only lowercase English letters."
]
},
{
"id": "1658",
"title": "Minimum Operations to Reduce X to Zero",
"question": "You are given an integer array nums and an integer x.\n In one operation, you can either remove the leftmost or the rightmost element from the array nums and subtract its value from x.\n Note that this modifies the array for future operations.\nReturn the minimum number of operations to reduce x to exactly 0 if it is possible, otherwise, return -1.",
"examples": [
"Input: nums = [1,1,4,2,3], x = 5",
"Output: 2",
"Explanation: The optimal solution is to remove the last two elements to reduce x to zero.",
"Input: nums = [5,6,7,8,9], x = 4",
"Output: -1",
"Input: nums = [3,2,20,1,1,3], x = 10",
"Output: 5",
"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.",
""
],
"constraints": [
"1 <= nums. length <= 1051 <= nums[i] <= 1041 <= x <= 109"
]
},
{
"id": "1663",
"title": "Smallest String With A Given Numeric Value",
"question": "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.\nThe numeric value of a string consisting of lowercase characters is defined as the sum of its characters' numeric values.\n For example, the numeric value of the string \"abe\" is equal to 1 + 2 + 5 = 8.\nYou are given two integers n and k.\n Return the lexicographically smallest string with length equal to n and numeric value equal to k.\nNote 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.",
"examples": [
"Input: n = 3, k = 27",
"Output: \"aay\"",
"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.",
"Input: n = 5, k = 73",
"Output: \"aaszz\"",
""
],
"constraints": [
"1 <= n <= 105n <= k <= 26 * n"
]
},
{
"id": "1664",
"title": "Ways to Make a Fair Array",
"question": "You are given an integer array nums.\n You can choose exactly one index (0-indexed) and remove the element.\n Notice that the index of the elements may change after the removal.\nFor example, if nums = [6,1,7,4,1]:An array is fair if the sum of the odd-indexed values equals the sum of the even-indexed values.\nReturn the number of indices that you could choose such that after the removal, nums is fair.",
"examples": [
"Input: nums = [2,1,6,4]",
"Output: 1",
"Explanation:",
"Remove index 0: [1,6,4] -> Even sum: 1 + 4 = 5. Odd sum: 6. Not fair.",
"Remove index 1: [2,6,4] -> Even sum: 2 + 4 = 6. Odd sum: 6. Fair.",
"Remove index 2: [2,1,4] -> Even sum: 2 + 4 = 6. Odd sum: 1. Not fair.",
"Remove index 3: [2,1,6] -> Even sum: 2 + 6 = 8. Odd sum: 1. Not fair.",
"There is 1 index that you can remove to make nums fair.",
"Input: nums = [1,1,1]",
"Output: 3",
"Explanation: You can remove any index and the remaining array is fair.",
"Input: nums = [1,2,3]",
"Output: 0",
"Explanation: You cannot make a fair array after removing any index.",
""
],
"constraints": [
"Choosing to remove index 1 results in nums = [6",
"7",
"4",
"1]. Choosing to remove index 2 results in nums = [6",
"1",
"4",
"1]. Choosing to remove index 4 results in nums = [6",
"1",
"7",
"4]. 1 <= nums. length <= 1051 <= nums[i] <= 104"
]
},
{
"id": "504",
"title": "Base 7",
"question": "Given an integer num, return a string of its base 7 representation.",
"examples": [
"Input: num = 100",
"Output: \"202\"",
"Input: num = -7",
"Output: \"-10\"",
""
],
"constraints": [
"-107 <= num <= 107"
]
},
{
"id": "1669",
"title": "Merge In Between Linked Lists",
"question": "You are given two linked lists: list1 and list2 of sizes n and m respectively.\nRemove list1's nodes from the ath node to the bth node, and put list2 in their place.\nThe blue edges and nodes in the following figure incidate the result:Build the result list and return its head.",
"examples": [
"Input: list1 = [0,1,2,3,4,5], a = 3, b = 4, list2 = [1000000,1000001,1000002]",
"Output: [0,1,2,1000000,1000001,1000002,5]",
"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.",
"Input: list1 = [0,1,2,3,4,5,6], a = 2, b = 5, list2 = [1000000,1000001,1000002,1000003,1000004]",
"Output: [0,1,1000000,1000001,1000002,1000003,1000004,6]",
"Explanation: The blue edges and nodes in the above figure indicate the result.",
""
],
"constraints": [
"3 <= list1. length <= 1041 <= a <= b < list1. length - 11 <= list2. length <= 104"
]
},
{
"id": "1670",
"title": "Design Front Middle Back Queue",
"question": "Design a queue that supports push and pop operations in the front, middle, and back.\nImplement the FrontMiddleBack class:Notice that when there are two middle position choices, the operation is performed on the frontmost middle position choice.\n For example:",
"examples": [
"Input:",
"[\"FrontMiddleBackQueue\", \"pushFront\", \"pushBack\", \"pushMiddle\", \"pushMiddle\", \"popFront\", \"popMiddle\", \"popMiddle\", \"popBack\", \"popFront\"]",
"[[], [1], [2], [3], [4], [], [], [], [], []]",
"Output:",
"[null, null, null, null, null, 1, 3, 4, 2, -1]",
"",
"Explanation:",
"FrontMiddleBackQueue q = new FrontMiddleBackQueue();",
"q. pushFront(1); // [1]",
"q. pushBack(2); // [1, 2]",
"q. pushMiddle(3); // [1, 3, 2]",
"q. pushMiddle(4); // [1, 4, 3, 2]",
"q. popFront(); // return 1 -> [4, 3, 2]",
"q. popMiddle(); // return 3 -> [4, 2]",
"q. popMiddle(); // return 4 -> [2]",
"q. popBack(); // return 2 -> []",
"q. popFront(); // return -1 -> [] (The queue is empty)",
""
],
"constraints": [
"FrontMiddleBack() Initializes the queue. void pushFront(int val) Adds val to the front of the queue. void pushMiddle(int val) Adds val to the middle of the queue. void pushBack(int val) Adds val to the back of the queue. int popFront() Removes the front element of the queue and returns it. If the queue is empty",
" return -1. int popMiddle() Removes the middle element of the queue and returns it. If the queue is empty",
" return -1. int popBack() Removes the back element of the queue and returns it. If the queue is empty",
" return -1. Pushing 6 into the middle of [1",
" 2",
" 3",
" 4",
" 5] results in [1",
" 2",
" 6",
" 3",
" 4",
" 5]. Popping the middle from [1",
" 2",
" 3",
" 4",
" 5",
" 6] returns 3 and results in [1",
" 2",
" 4",
" 5",
" 6]. 1 <= val <= 109At most 1000 calls will be made to pushFront",
" pushMiddle",
" pushBack",
" popFront",
" popMiddle",
" and popBack."
]
},
{
"id": "1673",
"title": "Find the Most Competitive Subsequence",
"question": "Given an integer array nums and a positive integer k, return the most competitive subsequence of nums of size k.\nAn array's subsequence is a resulting sequence obtained by erasing some (possibly zero) elements from the array.\nWe 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.\n 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.",
"examples": [
"Input: nums = [3,5,2,6], k = 2",
"Output: [2,6]",
"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.",
"Input: nums = [2,4,3,3,5,4,9,6], k = 4",
"Output: [2,3,3,4]",
""
],
"constraints": [
"1 <= nums. length <= 1050 <= nums[i] <= 1091 <= k <= nums. length"
]
},
{
"id": "1674",
"title": "Minimum Moves to Make Array Complementary",
"question": "You are given an integer array nums of even length n and an integer limit.\n In one move, you can replace any integer from nums with another integer between 1 and limit, inclusive.\nThe array nums is complementary if for all indices i (0-indexed), nums[i] + nums[n - 1 - i] equals the same number.\n For example, the array [1,2,3,4] is complementary because for all indices i, nums[i] + nums[n - 1 - i] = 5.\nReturn the minimum number of moves required to make nums complementary.",
"examples": [
"Input: nums = [1,2,4,3], limit = 4",
"Output: 1",
"Explanation: In 1 move, you can change nums to [1,2,2,3] (underlined elements are changed).",
"nums[0] + nums[3] = 1 + 3 = 4.",
"nums[1] + nums[2] = 2 + 2 = 4.",
"nums[2] + nums[1] = 2 + 2 = 4.",
"nums[3] + nums[0] = 3 + 1 = 4.",
"Therefore, nums[i] + nums[n-1-i] = 4 for every i, so nums is complementary.",
"Input: nums = [1,2,2,1], limit = 2",
"Output: 2",
"Explanation: In 2 moves, you can change nums to [2,2,2,2]. You cannot change any number to 3 since 3 > limit.",
"Input: nums = [1,2,1,2], limit = 2",
"Output: 0",
"Explanation: nums is already complementary.",
""
],
"constraints": [
"n == nums. length2 <= n <= 1051 <= nums[i] <= limit <= 105n is even."
]
},
{
"id": "1679",
"title": "Max Number of K-Sum Pairs",
"question": "You are given an integer array nums and an integer k.\nIn one operation, you can pick two numbers from the array whose sum equals k and remove them from the array.\nReturn the maximum number of operations you can perform on the array.",
"examples": [
"Input: nums = [1,2,3,4], k = 5",
"Output: 2",
"Explanation: Starting with nums = [1,2,3,4]:",
"- Remove numbers 1 and 4, then nums = [2,3]",
"- Remove numbers 2 and 3, then nums = []",
"There are no more pairs that sum up to 5, hence a total of 2 operations. Input: nums = [3,1,3,4,3], k = 6",
"Output: 1",
"Explanation: Starting with nums = [3,1,3,4,3]:",
"- Remove the first two 3's, then nums = [1,4,3]",
"There are no more pairs that sum up to 6, hence a total of 1 operation."
],
"constraints": [
"1 <= nums. length <= 1051 <= nums[i] <= 1091 <= k <= 109"
]
},
{
"id": "1680",
"title": "Concatenation of Consecutive Binary Numbers",
"question": "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.",
"examples": [
"Input: n = 1",
"Output: 1",
"Explanation: \"1\" in binary corresponds to the decimal value 1. ",
"Input: n = 3",
"Output: 27",
"Explanation: In binary, 1, 2, and 3 corresponds to \"1\", \"10\", and \"11\".",
"After concatenating them, we have \"11011\", which corresponds to the decimal value 27.",
"Input: n = 12",
"Output: 505379714",
"Explanation: The concatenation results in \"1101110010111011110001001101010111100\".",
"The decimal value of that is 118505380540.",
"After modulo 109 + 7, the result is 505379714.",
""
],
"constraints": [
"1 <= n <= 105"
]
},
{
"id": "1685",
"title": "Sum of Absolute Differences in a Sorted Array",
"question": "You are given an integer array nums sorted in non-decreasing order.\nBuild 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.\nIn other words, result[i] is equal to sum(|nums[i]-nums[j]|) where 0 <= j < nums.\nlength and j != i (0-indexed).",
"examples": [
"Input: nums = [2,3,5]",
"Output: [4,3,5]",
"Explanation: Assuming the arrays are 0-indexed, then",
"result[0] = |2-2| + |2-3| + |2-5| = 0 + 1 + 3 = 4,",
"result[1] = |3-2| + |3-3| + |3-5| = 1 + 0 + 2 = 3,",
"result[2] = |5-2| + |5-3| + |5-5| = 3 + 2 + 0 = 5.",
"Input: nums = [1,4,6,8,10]",
"Output: [24,15,13,15,21]",
""
],
"constraints": [
"2 <= nums. length <= 1051 <= nums[i] <= nums[i + 1] <= 104"
]
},
{
"id": "1686",
"title": "Stone Game VI",
"question": "Alice and Bob take turns playing a game, with Alice starting first.\nThere are n stones in a pile.\n On each player's turn, they can remove a stone from the pile and receive points based on the stone's value.\n Alice and Bob may value the stones differently.\nYou are given two integer arrays of length n, aliceValues and bobValues.\n Each aliceValues[i] and bobValues[i] represents how Alice and Bob, respectively, value the ith stone.\nThe winner is the person with the most points after all the stones are chosen.\n If both players have the same amount of points, the game results in a draw.\n Both players will play optimally.\n Both players know the other's values.\nDetermine the result of the game, and:",
"examples": [
"Input: aliceValues = [1,3], bobValues = [2,1]",
"Output: 1",
"Explanation:",
"If Alice takes stone 1 (0-indexed) first, Alice will receive 3 points.",
"Bob can only choose stone 0, and will only receive 2 points.",
"Alice wins.",
"Input: aliceValues = [1,2], bobValues = [3,1]",
"Output: 0",
"Explanation:",
"If Alice takes stone 0, and Bob takes stone 1, they will both have 1 point.",
"Draw.",
"Input: aliceValues = [2,4,3], bobValues = [1,6,7]",
"Output: -1",
"Explanation:",
"Regardless of how Alice plays, Bob will be able to have more points than Alice.",
"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.",
"Bob wins.",
""
],
"constraints": [
"If Alice wins",
" return 1. If Bob wins",
" return -1. If the game results in a draw",
" return 0. n == aliceValues. length == bobValues. length1 <= n <= 1051 <= aliceValues[i]",
" bobValues[i] <= 100"
]
},
{
"id": "1689",
"title": "Partitioning Into Minimum Number Of Deci-Binary Numbers",
"question": "A decimal number is called deci-binary if each of its digits is either 0 or 1 without any leading zeros.\n For example, 101 and 1100 are deci-binary, while 112 and 3001 are not.\nGiven 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.",
"examples": [
"Input: n = \"32\"",
"Output: 3",
"Explanation: 10 + 11 + 11 = 32",
"Input: n = \"82734\"",
"Output: 8",
"Input: n = \"27346209830709182346\"",
"Output: 9",
""
],
"constraints": [
"1 <= n. length <= 105n consists of only digits. n does not contain any leading zeros and represents a positive integer."
]
},
{
"id": "1690",
"title": "Stone Game VII",
"question": "Alice and Bob take turns playing a game, with Alice starting first.\nThere are n stones arranged in a row.\n 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.\n The winner is the one with the higher score when there are no stones left to remove.\nBob found that he will always lose this game (poor Bob, he always loses), so he decided to minimize the score's difference.\n Alice's goal is to maximize the difference in the score.\nGiven 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.",
"examples": [
"Input: stones = [5,3,1,4,2]",
"Output: 6",
"Explanation: ",
"- Alice removes 2 and gets 5 + 3 + 1 + 4 = 13 points. Alice = 13, Bob = 0, stones = [5,3,1,4].",
"- Bob removes 5 and gets 3 + 1 + 4 = 8 points. Alice = 13, Bob = 8, stones = [3,1,4].",
"- Alice removes 3 and gets 1 + 4 = 5 points. Alice = 18, Bob = 8, stones = [1,4].",
"- Bob removes 1 and gets 4 points. Alice = 18, Bob = 12, stones = [4].",
"- Alice removes 4 and gets 0 points. Alice = 18, Bob = 12, stones = [].",
"The score difference is 18 - 12 = 6.",
"Input: stones = [7,90,5,1,100,10,10,2]",
"Output: 122"
],
"constraints": [
"n == stones. length2 <= n <= 10001 <= stones[i] <= 1000"
]
},
{
"id": "506",
"title": "Relative Ranks",
"question": "You are given an integer array score of size n, where score[i] is the score of the ith athlete in a competition.\n All the scores are guaranteed to be unique.\nThe athletes are placed based on their scores, where the 1st place athlete has the highest score, the 2nd place athlete has the 2nd highest score, and so on.\n The placement of each athlete determines their rank:Return an array answer of size n where answer[i] is the rank of the ith athlete.",
"examples": [
"Input: score = [5,4,3,2,1]",
"Output: [\"Gold Medal\",\"Silver Medal\",\"Bronze Medal\",\"4\",\"5\"]",
"Explanation: The placements are [1st, 2nd, 3rd, 4th, 5th]. Input: score = [10,3,8,9,4]",
"Output: [\"Gold Medal\",\"5\",\"Bronze Medal\",\"Silver Medal\",\"4\"]",
"Explanation: The placements are [1st, 5th, 3rd, 2nd, 4th].",
"",
""
],
"constraints": [
"The 1st place athlete's rank is \"Gold Medal\". The 2nd place athlete's rank is \"Silver Medal\". The 3rd place athlete's rank is \"Bronze Medal\". For the 4th place to the nth place athlete",
" their rank is their placement number (i. e.",
" the xth place athlete's rank is \"x\"). n == score. length1 <= n <= 1040 <= score[i] <= 106All the values in score are unique."
]
},
{
"id": "1695",
"title": "Maximum Erasure Value",
"question": "You are given an array of positive integers nums and want to erase a subarray containing unique elements.\n The score you get by erasing the subarray is equal to the sum of its elements.\nReturn the maximum score you can get by erasing exactly one subarray.\nAn 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],.\n.\n.\n,a[r] for some (l,r).",
"examples": [
"Input: nums = [4,2,4,5,6]",
"Output: 17",
"Explanation: The optimal subarray here is [2,4,5,6].",
"Input: nums = [5,2,1,2,5,2,1,2,5]",
"Output: 8",
"Explanation: The optimal subarray here is [5,2,1] or [1,2,5].",
""
],
"constraints": [
"1 <= nums. length <= 1051 <= nums[i] <= 104"
]
},
{
"id": "1696",
"title": "Jump Game VI",
"question": "You are given a 0-indexed integer array nums and an integer k.\nYou are initially standing at index 0.\n In one move, you can jump at most k steps forward without going outside the boundaries of the array.\n That is, you can jump from index i to any index in the range [i + 1, min(n - 1, i + k)] inclusive.\nYou want to reach the last index of the array (index n - 1).\n Your score is the sum of all nums[j] for each index j you visited in the array.\nReturn the maximum score you can get.",
"examples": [
"Input: nums = [1,-1,-2,4,-7,3], k = 2",
"Output: 7",
"Explanation: You can choose your jumps forming the subsequence [1,-1,4,3] (underlined above). The sum is 7.",
"Input: nums = [10,-5,-2,4,0,3], k = 3",
"Output: 17",
"Explanation: You can choose your jumps forming the subsequence [10,4,3] (underlined above). The sum is 17.",
"Input: nums = [1,-5,-20,4,-1,3,-6,-3], k = 2",
"Output: 0",
""
],
"constraints": [
"1 <= nums. length",
" k <= 105-104 <= nums[i] <= 104"
]
},
{
"id": "1701",
"title": "Average Waiting Time",
"question": "There is a restaurant with a single chef.\n You are given an array customers, where customers[i] = [arrivali, timei]:When a customer arrives, he gives the chef his order, and the chef starts preparing it once he is idle.\n The customer waits till the chef finishes preparing his order.\n The chef does not prepare food for more than one customer at a time.\n The chef prepares food for customers in the order they were given in the input.\nReturn the average waiting time of all customers.\n Solutions within 10-5 from the actual answer are considered accepted.",
"examples": [
"Input: customers = [[1,2],[2,5],[4,3]]",
"Output: 5. 00000",
"Explanation:",
"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.",
"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.",
"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.",
"So the average waiting time = (2 + 6 + 7) / 3 = 5.",
"Input: customers = [[5,2],[5,4],[10,3],[20,1]]",
"Output: 3. 25000",
"Explanation:",
"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.",
"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.",
"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.",
"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.",
"So the average waiting time = (2 + 6 + 4 + 1) / 4 = 3. 25.",
""
],
"constraints": [
"arrivali is the arrival time of the ith customer. The arrival times are sorted in non-decreasing order. timei is the time needed to prepare the order of the ith customer. 1 <= customers. length <= 1051 <= arrivali",
" timei <= 104arrivali <= arrivali+1"
]
},
{
"id": "1702",
"title": "Maximum Binary String After Change",
"question": "You are given a binary string binary consisting of only 0's or 1's.\n You can apply each of the following operations any number of times:Return the maximum binary string you can obtain after any number of operations.\n Binary string x is greater than binary string y if x's decimal representation is greater than y's decimal representation.",
"examples": [
"Input: binary = \"000110\"",
"Output: \"111011\"",
"Explanation: A valid transformation sequence can be:",
"\"000110\" -> \"000101\" ",
"\"000101\" -> \"100101\" ",
"\"100101\" -> \"110101\" ",
"\"110101\" -> \"110011\" ",
"\"110011\" -> \"111011\"",
"Input: binary = \"01\"",
"Output: \"01\"",
"Explanation: \"01\" cannot be transformed any further.",
""
],
"constraints": [
"Operation 1: If the number contains the substring \"00\"",
" you can replace it with \"10\".\n\n\t\nFor example",
" \"00010\" -> \"10010\"\n\nFor example",
" \"00010\" -> \"10010\"Operation 2: If the number contains the substring \"10\"",
" you can replace it with \"01\".\n\t\nFor example",
" \"00010\" -> \"00001\"\n\nFor example",
" \"00010\" -> \"00001\"1 <= binary. length <= 105binary consist of '0' and '1'."
]
},
{
"id": "1705",
"title": "Maximum Number of Eaten Apples",
"question": "There is a special kind of apple tree that grows apples every day for n days.\n 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.\n On some days, the apple tree does not grow any apples, which are denoted by apples[i] == 0 and days[i] == 0.\nYou decided to eat at most one apple a day (to keep the doctors away).\n Note that you can keep eating after the first n days.\nGiven two integer arrays days and apples of length n, return the maximum number of apples you can eat.",
"examples": [
"Input: apples = [1,2,3,5,2], days = [3,2,1,4,2]",
"Output: 7",
"Explanation: You can eat 7 apples:",
"- On the first day, you eat an apple that grew on the first day.",
"- On the second day, you eat an apple that grew on the second day.",
"- 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.",
"- On the fourth to the seventh days, you eat apples that grew on the fourth day.",
"Input: apples = [3,0,0,0,0,2], days = [3,0,0,0,0,2]",
"Output: 5",
"Explanation: You can eat 5 apples:",
"- On the first to the third day you eat apples that grew on the first day.",
"- Do nothing on the fouth and fifth days.",
"- On the sixth and seventh days you eat apples that grew on the sixth day.",
""
],
"constraints": [
"apples. length == ndays. length == n1 <= n <= 2 * 1040 <= apples[i]",
" days[i] <= 2 * 104days[i] = 0 if and only if apples[i] = 0."
]
},
{
"id": "1706",
"title": "Where Will the Ball Fall",
"question": "You have a 2-D grid of size m x n representing a box, and you have n balls.\n The box is open on the top and bottom sides.\nEach 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.\nWe drop one ball at the top of each column of the box.\n Each ball can get stuck in the box or fall out of the bottom.\n 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.\nReturn 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.",
"examples": [
"Input: 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]]",
"Output: [1,-1,-1,-1,-1]",
"Explanation: This example is shown in the photo.",
"Ball b0 is dropped at column 0 and falls out of the box at column 1.",
"Ball b1 is dropped at column 1 and will get stuck in the box between column 2 and 3 and row 1.",
"Ball b2 is dropped at column 2 and will get stuck on the box between column 2 and 3 and row 0.",
"Ball b3 is dropped at column 3 and will get stuck on the box between column 2 and 3 and row 0.",
"Ball b4 is dropped at column 4 and will get stuck on the box between column 2 and 3 and row 1.",
"Input: grid = [[-1]]",
"Output: [-1]",
"Explanation: The ball gets stuck against the left wall.",
"Input: 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]]",
"Output: [0,1,2,3,4,-1]",
""
],
"constraints": [
"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. 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. m == grid. lengthn == grid[i]. length1 <= m",
" n <= 100grid[i][j] is 1 or -1."
]
},
{
"id": "1711",
"title": "Count Good Meals",
"question": "A good meal is a meal that contains exactly two different food items with a sum of deliciousness equal to a power of two.\nYou can pick any two different foods to make a good meal.\nGiven an array of integers deliciousness where deliciousness[i] is the deliciousness of the i​​​​​​th​​​​​​​​ item of food, return the number of different good meals you can make from this list modulo 109 + 7.\nNote that items with different indices are considered different even if they have the same deliciousness value.",
"examples": [
"Input: deliciousness = [1,3,5,7,9]",
"Output: 4",
"Explanation: The good meals are (1,3), (1,7), (3,5) and, (7,9).",
"Their respective sums are 4, 8, 8, and 16, all of which are powers of 2.",
"Input: deliciousness = [1,1,1,3,3,3,7]",
"Output: 15",
"Explanation: The good meals are (1,1) with 3 ways, (1,3) with 9 ways, and (1,7) with 3 ways."
],
"constraints": [
"1 <= deliciousness. length <= 1050 <= deliciousness[i] <= 220"
]
},
{
"id": "1712",
"title": "Ways to Split Array Into Three Subarrays",
"question": "A split of an integer array is good if:Given nums, an array of non-negative integers, return the number of good ways to split nums.\n As the number may be too large, return it modulo 109 + 7.",
"examples": [
"Input: nums = [1,1,1]",
"Output: 1",
"Explanation: The only good way to split nums is [1] [1] [1]. Input: nums = [1,2,2,2,5,0]",
"Output: 3",
"Explanation: There are three good ways of splitting nums:",
"[1] [2] [2,2,5,0]",
"[1] [2,2] [2,5,0]",
"[1,2] [2,2] [5,0]",
"Input: nums = [3,2,1]",
"Output: 0",
"Explanation: There is no good way to split nums."
],
"constraints": [
"The array is split into three non-empty contiguous subarrays - named left",
" mid",
" right respectively from left to right. 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. 3 <= nums. length <= 1050 <= nums[i] <= 104"
]
},
{
"id": "1717",
"title": "Maximum Score From Removing Substrings",
"question": "You are given a string s and two integers x and y.\n You can perform two types of operations any number of times.\nReturn the maximum points you can gain after applying the above operations on s.",
"examples": [
"Input: s = \"cdbcbbaaabab\", x = 4, y = 5",
"Output: 19",
"Explanation:",
"- Remove the \"ba\" underlined in \"cdbcbbaaabab\". Now, s = \"cdbcbbaaab\" and 5 points are added to the score.",
"- Remove the \"ab\" underlined in \"cdbcbbaaab\". Now, s = \"cdbcbbaa\" and 4 points are added to the score.",
"- Remove the \"ba\" underlined in \"cdbcbbaa\". Now, s = \"cdbcba\" and 5 points are added to the score.",
"- Remove the \"ba\" underlined in \"cdbcba\". Now, s = \"cdbc\" and 5 points are added to the score.",
"Total score = 5 + 4 + 5 + 5 = 19. Input: s = \"aabbaaxybbaabb\", x = 5, y = 4",
"Output: 20",
""
],
"constraints": [
"Remove substring \"ab\" and gain x points.\n\n\t\nFor example",
" when removing \"ab\" from \"cabxbae\" it becomes \"cxbae\".\n\nFor example",
" when removing \"ab\" from \"cabxbae\" it becomes \"cxbae\". Remove substring \"ba\" and gain y points.\n\t\nFor example",
" when removing \"ba\" from \"cabxbae\" it becomes \"cabxe\".\n\nFor example",
" when removing \"ba\" from \"cabxbae\" it becomes \"cabxe\". 1 <= s. length <= 1051 <= x",
" y <= 104s consists of lowercase English letters."
]
},
{
"id": "1718",
"title": "Construct the Lexicographically Largest Valid Sequence",
"question": "Given an integer n, find a sequence that satisfies all of the following:The distance between two numbers on the sequence, a[i] and a[j], is the absolute difference of their indices, |j - i|.\nReturn the lexicographically largest sequence.\n 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.\n 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.",
"examples": [
"Input: n = 3",
"Output: [3,1,2,3,2]",
"Explanation: [2,3,2,1,3] is also a valid sequence, but [3,1,2,3,2] is the lexicographically largest valid sequence.",
"Input: n = 5",
"Output: [5,3,1,4,3,5,2,4,2]",
""
],
"constraints": [
"The integer 1 occurs once in the sequence. Each integer between 2 and n occurs twice in the sequence. For every integer i between 2 and n",
" the distance between the two occurrences of i is exactly i. 1 <= n <= 20"
]
},
{
"id": "507",
"title": "Perfect Number",
"question": "A perfect number is a positive integer that is equal to the sum of its positive divisors, excluding the number itself.\n A divisor of an integer x is an integer that can divide x evenly.\nGiven an integer n, return true if n is a perfect number, otherwise return false.",
"examples": [
"Input: num = 28",
"Output: true",
"Explanation: 28 = 1 + 2 + 4 + 7 + 14",
"1, 2, 4, 7, and 14 are all divisors of 28.",
"Input: num = 6",
"Output: true",
"Input: num = 496",
"Output: true",
"Input: num = 8128",
"Output: true",
"Input: num = 2",
"Output: false",
""
],
"constraints": [
"1 <= num <= 108"
]
},
{
"id": "1721",
"title": "Swapping Nodes in a Linked List",
"question": "You are given the head of a linked list, and an integer k.\nReturn 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).",
"examples": [
"Input: head = [1,2,3,4,5], k = 2",
"Output: [1,4,3,2,5]",
"Input: head = [7,9,6,6,7,8,3,0,9,5], k = 5",
"Output: [7,9,6,6,8,7,3,0,9,5]",
"Input: head = [1], k = 1",
"Output: [1]",
"Input: head = [1,2], k = 1",
"Output: [2,1]",
"Input: head = [1,2,3], k = 2",
"Output: [1,2,3]",
""
],
"constraints": [
"The number of nodes in the list is n. 1 <= k <= n <= 1050 <= Node. val <= 100"
]
},
{
"id": "1722",
"title": "Minimize Hamming Distance After Swap Operations",
"question": "You are given two integer arrays, source and target, both of length n.\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.\n Note that you can swap elements at a specific pair of indices multiple times and in any order.\nThe Hamming distance of two arrays of the same length, source and target, is the number of positions where the elements are different.\n Formally, it is the number of indices i for 0 <= i <= n-1 where source[i] != target[i] (0-indexed).\nReturn the minimum Hamming distance of source and target after performing any amount of swap operations on array source.",
"examples": [
"Input: source = [1,2,3,4], target = [2,1,4,5], allowedSwaps = [[0,1],[2,3]]",
"Output: 1",
"Explanation: source can be transformed the following way:",
"- Swap indices 0 and 1: source = [2,1,3,4]",
"- Swap indices 2 and 3: source = [2,1,4,3]",
"The Hamming distance of source and target is 1 as they differ in 1 position: index 3.",
"Input: source = [1,2,3,4], target = [1,3,2,4], allowedSwaps = []",
"Output: 2",
"Explanation: There are no allowed swaps.",
"The Hamming distance of source and target is 2 as they differ in 2 positions: index 1 and index 2.",
"Input: source = [5,1,2,4,3], target = [1,5,4,2,3], allowedSwaps = [[0,4],[4,2],[1,3],[1,4]]",
"Output: 0",
""
],
"constraints": [
"n == source. length == target. length1 <= n <= 1051 <= source[i]",
" target[i] <= 1050 <= allowedSwaps. length <= 105allowedSwaps[i]. length == 20 <= ai",
" bi <= n - 1ai != bi"
]
},
{
"id": "1726",
"title": "Tuple with Same Product",
"question": "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.",
"examples": [
"Input: nums = [2,3,4,6]",
"Output: 8",
"Explanation: There are 8 valid tuples:",
"(2,6,3,4) , (2,6,4,3) , (6,2,3,4) , (6,2,4,3)",
"(3,4,2,6) , (4,3,2,6) , (3,4,6,2) , (4,3,6,2)",
"Input: nums = [1,2,4,5,10]",
"Output: 16",
"Explanation: There are 16 valids tuples:",
"(1,10,2,5) , (1,10,5,2) , (10,1,2,5) , (10,1,5,2)",
"(2,5,1,10) , (2,5,10,1) , (5,2,1,10) , (5,2,10,1)",
"(2,10,4,5) , (2,10,5,4) , (10,2,4,5) , (10,2,5,4)",
"(4,5,2,10) , (4,5,10,2) , (5,4,2,10) , (5,4,10,2)",
"Input: nums = [2,3,4,6,8,12]",
"Output: 40",
"Input: nums = [2,3,5,7]",
"Output: 0",
""
],
"constraints": [
"1 <= nums. length <= 10001 <= nums[i] <= 104All elements in nums are distinct."
]
},
{
"id": "1727",
"title": "Largest Submatrix With Rearrangements",
"question": "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.\nReturn the area of the largest submatrix within matrix where every element of the submatrix is 1 after reordering the columns optimally.",
"examples": [
"Input: matrix = [[0,0,1],[1,1,1],[1,0,1]]",
"Output: 4",
"Explanation: You can rearrange the columns as shown above.",
"The largest submatrix of 1s, in bold, has an area of 4.",
"Input: matrix = [[1,0,1,0,1]]",
"Output: 3",
"Explanation: You can rearrange the columns as shown above.",
"The largest submatrix of 1s, in bold, has an area of 3.",
"Input: matrix = [[1,1,0],[1,0,1]]",
"Output: 2",
"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. Input: matrix = [[0,0],[0,0]]",
"Output: 0",
"Explanation: As there are no 1s, no submatrix of 1s can be formed and the area is 0."
],
"constraints": [
"m == matrix. lengthn == matrix[i]. length1 <= m * n <= 105matrix[i][j] is 0 or 1."
]
},
{
"id": "1733",
"title": "Minimum Number of People to Teach",
"question": "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.\nYou are given an integer n, an array languages, and an array friendships where:You can choose one language and teach it to some users so that all friends can communicate with each other.\n Return the minimum number of users you need to teach.",
"examples": [
"Input: n = 2, languages = [[1],[2],[1,2]], friendships = [[1,2],[1,3],[2,3]]",
"Output: 1",
"Explanation: You can either teach user 1 the second language or user 2 the first language.",
"Input: n = 3, languages = [[2],[1,3],[1,2],[3]], friendships = [[1,4],[1,2],[3,4],[2,3]]",
"Output: 2",
"Explanation: Teach the third language to users 1 and 3, yielding two users to teach.",
""
],
"constraints": [
"There are n languages numbered 1 through n",
"languages[i] is the set of languages the i​​​​​​th​​​​ user knows",
" andfriendships[i] = [u​​​​​​i​​​",
" v​​​​​​i] denotes a friendship between the users u​​​​​​​​​​​i​​​​​ and vi. 2 <= n <= 500languages. length == m1 <= m <= 5001 <= languages[i]. length <= n1 <= languages[i][j] <= n1 <= u​​​​​​i < v​​​​​​i <= languages. length1 <= friendships. length <= 500All tuples (u​​​​​i",
" v​​​​​​i) are uniquelanguages[i] contains only unique values"
]
},
{
"id": "1734",
"title": "Decode XORed Permutation",
"question": "There is an integer array perm that is a permutation of the first n positive integers, where n is always odd.\nIt was encoded into another integer array encoded of length n - 1, such that encoded[i] = perm[i] XOR perm[i + 1].\n For example, if perm = [1,3,2], then encoded = [2,1].\nGiven the encoded array, return the original array perm.\n It is guaranteed that the answer exists and is unique.",
"examples": [
"Input: encoded = [3,1]",
"Output: [1,2,3]",
"Explanation: If perm = [1,2,3], then encoded = [1 XOR 2,2 XOR 3] = [3,1]",
"Input: encoded = [6,5,4,6]",
"Output: [2,4,1,5,3]",
""
],
"constraints": [
"3 <= n < 105n is odd. encoded. length == n - 1"
]
},
{
"id": "1737",
"title": "Change Minimum Characters to Satisfy One of Three Conditions",
"question": "You are given two strings a and b that consist of lowercase letters.\n In one operation, you can change any character in a or b to any lowercase letter.\nYour goal is to satisfy one of the following three conditions:Return the minimum number of operations needed to achieve your goal.",
"examples": [
"Input: a = \"aba\", b = \"caa\"",
"Output: 2",
"Explanation: Consider the best way to make each condition true:",
"1) Change b to \"ccc\" in 2 operations, then every letter in a is less than every letter in b.",
"2) Change a to \"bbb\" and b to \"aaa\" in 3 operations, then every letter in b is less than every letter in a.",
"3) Change a to \"aaa\" and b to \"aaa\" in 2 operations, then a and b consist of one distinct letter.",
"The best way was done in 2 operations (either condition 1 or condition 3).",
"Input: a = \"dabadd\", b = \"cda\"",
"Output: 3",
"Explanation: The best way is to make condition 1 true by changing b to \"eee\".",
""
],
"constraints": [
"Every letter in a is strictly less than every letter in b in the alphabet. Every letter in b is strictly less than every letter in a in the alphabet. Both a and b consist of only one distinct letter. 1 <= a. length",
" b. length <= 105a and b consist only of lowercase letters."
]
},
{
"id": "1738",
"title": "Find Kth Largest XOR Coordinate Value",
"question": "You are given a 2D matrix of size m x n, consisting of non-negative integers.\n You are also given an integer k.\nThe 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).\nFind the kth largest value (1-indexed) of all the coordinates of matrix.",
"examples": [
"Input: matrix = [[5,2],[1,6]], k = 1",
"Output: 7",
"Explanation: The value of coordinate (0,1) is 5 XOR 2 = 7, which is the largest value. Input: matrix = [[5,2],[1,6]], k = 2",
"Output: 5",
"Explanation: The value of coordinate (0,0) is 5 = 5, which is the 2nd largest value. Input: matrix = [[5,2],[1,6]], k = 3",
"Output: 4",
"Explanation: The value of coordinate (1,0) is 5 XOR 1 = 4, which is the 3rd largest value. Input: matrix = [[5,2],[1,6]], k = 4",
"Output: 0",
"Explanation: The value of coordinate (1,1) is 5 XOR 2 XOR 1 XOR 6 = 0, which is the 4th largest value."
],
"constraints": [
"m == matrix. lengthn == matrix[i]. length1 <= m",
" n <= 10000 <= matrix[i][j] <= 1061 <= k <= m * n"
]
},
{
"id": "1743",
"title": "Restore the Array From Adjacent Pairs",
"question": "There is an integer array nums that consists of n unique elements, but you have forgotten it.\n However, you do remember every pair of adjacent elements in nums.\nYou 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.\nIt 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]].\n The pairs can appear in any order.\nReturn the original array nums.\n If there are multiple solutions, return any of them.",
"examples": [
"Input: adjacentPairs = [[2,1],[3,4],[3,2]]",
"Output: [1,2,3,4]",
"Explanation: This array has all its adjacent pairs in adjacentPairs.",
"Notice that adjacentPairs[i] may not be in left-to-right order.",
"Input: adjacentPairs = [[4,-2],[1,4],[-3,1]]",
"Output: [-2,4,1,-3]",
"Explanation: There can be negative numbers.",
"Another solution is [-3,1,4,-2], which would also be accepted.",
"Input: adjacentPairs = [[100000,-100000]]",
"Output: [100000,-100000]",
""
],
"constraints": [
"nums. length == nadjacentPairs. length == n - 1adjacentPairs[i]. length == 22 <= n <= 105-105 <= nums[i]",
" ui",
" vi <= 105There exists some nums that has adjacentPairs as its pairs."
]
},
{
"id": "1744",
"title": "Can You Eat Your Favorite Candy on Your Favorite Day?",
"question": "You are given a (0-indexed) array of positive integers candiesCount where candiesCount[i] represents the number of candies of the ith type you have.\n You are also given a 2D array queries where queries[i] = [favoriteTypei, favoriteDayi, dailyCapi].\nYou play a game with the following rules:Construct a boolean array answer such that answer.\nlength == queries.\nlength 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.\n Note that you can eat different types of candy on the same day, provided that you follow rule 2.\nReturn the constructed array answer.",
"examples": [
"Input: candiesCount = [7,4,5,3,8], queries = [[0,2,2],[4,2,4],[2,13,1000000000]]",
"Output: [true,false,true]",
"Explanation:",
"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.",
"2- You can eat at most 4 candies each day.",
" 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.",
" 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.",
"3- If you eat 1 candy each day, you will eat a candy of type 2 on day 13.",
"Input: candiesCount = [5,2,6,4,1], queries = [[3,1,2],[4,10,3],[3,10,100],[4,100,30],[1,3,1]]",
"Output: [false,true,true,false,false]",
""
],
"constraints": [
"You start eating candies on day 0. You cannot eat any candy of type i unless you have eaten all candies of type i - 1. You must eat at least one candy per day until you have eaten all the candies. 1 <= candiesCount. length <= 1051 <= candiesCount[i] <= 1051 <= queries. length <= 105queries[i]. length == 30 <= favoriteTypei < candiesCount. length0 <= favoriteDayi <= 1091 <= dailyCapi <= 109"
]
},
{
"id": "509",
"title": "Fibonacci Number",
"question": "The Fibonacci numbers, commonly denoted F(n) form a sequence, called the Fibonacci sequence, such that each number is the sum of the two preceding ones, starting from 0 and 1.\n That is,Given n, calculate F(n).",
"examples": [
"F(0) = 0, F(1) = 1",
"F(n) = F(n - 1) + F(n - 2), for n > 1.",
"Input: n = 2",
"Output: 1",
"Explanation: F(2) = F(1) + F(0) = 1 + 0 = 1.",
"Input: n = 3",
"Output: 2",
"Explanation: F(3) = F(2) + F(1) = 1 + 1 = 2.",
"Input: n = 4",
"Output: 3",
"Explanation: F(4) = F(3) + F(2) = 2 + 1 = 3.",
""
],
"constraints": [
"0 <= n <= 30"
]
},
{
"id": "1749",
"title": "Maximum Absolute Sum of Any Subarray",
"question": "You are given an integer array nums.\n The absolute sum of a subarray [numsl, numsl+1, .\n.\n.\n, numsr-1, numsr] is abs(numsl + numsl+1 + .\n.\n.\n + numsr-1 + numsr).\nReturn the maximum absolute sum of any (possibly empty) subarray of nums.\nNote that abs(x) is defined as follows:",
"examples": [
"Input: nums = [1,-3,2,3,-4]",
"Output: 5",
"Explanation: The subarray [2,3] has absolute sum = abs(2+3) = abs(5) = 5.",
"Input: nums = [2,-5,1,-4,3,-2]",
"Output: 8",
"Explanation: The subarray [-5,1,-4] has absolute sum = abs(-5+1-4) = abs(-8) = 8.",
""
],
"constraints": [
"If x is a negative integer",
" then abs(x) = -x. If x is a non-negative integer",
" then abs(x) = x. 1 <= nums. length <= 105-104 <= nums[i] <= 104"
]
},
{
"id": "1750",
"title": "Minimum Length of String After Deleting Similar Ends",
"question": "Given a string s consisting only of characters 'a', 'b', and 'c'.\n You are asked to apply the following algorithm on the string any number of times:Return the minimum length of s after performing the above operation any number of times (possibly zero times).",
"examples": [
"Input: s = \"ca\"",
"Output: 2",
"Explanation: You can't remove any characters, so the string stays as is.",
"Input: s = \"cabaabac\"",
"Output: 0",
"Explanation: An optimal sequence of operations is:",
"- Take prefix = \"c\" and suffix = \"c\" and remove them, s = \"abaaba\".",
"- Take prefix = \"a\" and suffix = \"a\" and remove them, s = \"baab\".",
"- Take prefix = \"b\" and suffix = \"b\" and remove them, s = \"aa\".",
"- Take prefix = \"a\" and suffix = \"a\" and remove them, s = \"\". Input: s = \"aabccabba\"",
"Output: 3",
"Explanation: An optimal sequence of operations is:",
"- Take prefix = \"aa\" and suffix = \"a\" and remove them, s = \"bccabb\".",
"- Take prefix = \"b\" and suffix = \"bb\" and remove them, s = \"cca\".",
""
],
"constraints": [
"1 <= s. length <= 105s only consists of characters 'a'",
" 'b'",
" and 'c'."
]
},
{
"id": "1753",
"title": "Maximum Score From Removing Stones",
"question": "You are playing a solitaire game with three piles of stones of sizes a​​​​​​, b,​​​​​​ and c​​​​​​ respectively.\n Each turn you choose two different non-empty piles, take one stone from each, and add 1 point to your score.\n The game stops when there are fewer than two non-empty piles (meaning there are no more available moves).\nGiven three integers a​​​​​, b,​​​​​ and c​​​​​, return the maximum score you can get.",
"examples": [
"Input: a = 2, b = 4, c = 6",
"Output: 6",
"Explanation: The starting state is (2, 4, 6). One optimal set of moves is:",
"- Take from 1st and 3rd piles, state is now (1, 4, 5)",
"- Take from 1st and 3rd piles, state is now (0, 4, 4)",
"- Take from 2nd and 3rd piles, state is now (0, 3, 3)",
"- Take from 2nd and 3rd piles, state is now (0, 2, 2)",
"- Take from 2nd and 3rd piles, state is now (0, 1, 1)",
"- Take from 2nd and 3rd piles, state is now (0, 0, 0)",
"There are fewer than two non-empty piles, so the game ends. Total: 6 points.",
"Input: a = 4, b = 4, c = 6",
"Output: 7",
"Explanation: The starting state is (4, 4, 6). One optimal set of moves is:",
"- Take from 1st and 2nd piles, state is now (3, 3, 6)",
"- Take from 1st and 3rd piles, state is now (2, 3, 5)",
"- Take from 1st and 3rd piles, state is now (1, 3, 4)",
"- Take from 1st and 3rd piles, state is now (0, 3, 3)",
"- Take from 2nd and 3rd piles, state is now (0, 2, 2)",
"- Take from 2nd and 3rd piles, state is now (0, 1, 1)",
"- Take from 2nd and 3rd piles, state is now (0, 0, 0)",
"There are fewer than two non-empty piles, so the game ends. Total: 7 points.",
"Input: a = 1, b = 8, c = 8",
"Output: 8",
"Explanation: One optimal set of moves is to take from the 2nd and 3rd piles for 8 turns until they are empty.",
"After that, there are fewer than two non-empty piles, so the game ends.",
""
],
"constraints": [
"1 <= a",
" b",
" c <= 105"
]
},
{
"id": "1754",
"title": "Largest Merge Of Two Strings",
"question": "You are given two strings word1 and word2.\n 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:Return the lexicographically largest merge you can construct.\nA 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 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.",
"examples": [
"Input: word1 = \"cabaa\", word2 = \"bcaaa\"",
"Output: \"cbcabaaaaa\"",
"Explanation: One way to get the lexicographically largest merge is:",
"- Take from word1: merge = \"c\", word1 = \"abaa\", word2 = \"bcaaa\"",
"- Take from word2: merge = \"cb\", word1 = \"abaa\", word2 = \"caaa\"",
"- Take from word2: merge = \"cbc\", word1 = \"abaa\", word2 = \"aaa\"",
"- Take from word1: merge = \"cbca\", word1 = \"baa\", word2 = \"aaa\"",
"- Take from word1: merge = \"cbcab\", word1 = \"aa\", word2 = \"aaa\"",
"- Append the remaining 5 a's from word1 and word2 at the end of merge.",
"Input: word1 = \"abcabc\", word2 = \"abdcaba\"",
"Output: \"abdcabcabcaba\"",
""
],
"constraints": [
"If word1 is non-empty",
" append the first character in word1 to merge and delete it from word1.\n\n\t\nFor example",
" if word1 = \"abc\" and merge = \"dv\"",
" then after choosing this operation",
" word1 = \"bc\" and merge = \"dva\".\n\nFor example",
" if word1 = \"abc\" and merge = \"dv\"",
" then after choosing this operation",
" word1 = \"bc\" and merge = \"dva\". If word2 is non-empty",
" append the first character in word2 to merge and delete it from word2.\n\t\nFor example",
" if word2 = \"abc\" and merge = \"\"",
" then after choosing this operation",
" word2 = \"bc\" and merge = \"a\".\n\nFor example",
" if word2 = \"abc\" and merge = \"\"",
" then after choosing this operation",
" word2 = \"bc\" and merge = \"a\". 1 <= word1. length",
" word2. length <= 3000word1 and word2 consist only of lowercase English letters."
]
},
{
"id": "1759",
"title": "Count Number of Homogenous Substrings",
"question": "Given a string s, return the number of homogenous substrings of s.\n Since the answer may be too large, return it modulo 109 + 7.\nA string is homogenous if all the characters of the string are the same.\nA substring is a contiguous sequence of characters within a string.",
"examples": [
"Input: s = \"abbcccaa\"",
"Output: 13",
"Explanation: The homogenous substrings are listed as below:",
"\"a\" appears 3 times.",
"\"aa\" appears 1 time.",
"\"b\" appears 2 times.",
"\"bb\" appears 1 time.",
"\"c\" appears 3 times.",
"\"cc\" appears 2 times.",
"\"ccc\" appears 1 time.",
"3 + 1 + 2 + 1 + 3 + 2 + 1 = 13. Input: s = \"xy\"",
"Output: 2",
"Explanation: The homogenous substrings are \"x\" and \"y\". Input: s = \"zzzzz\"",
"Output: 15",
""
],
"constraints": [
"1 <= s. length <= 105s consists of lowercase letters."
]
},
{
"id": "1760",
"title": "Minimum Limit of Balls in a Bag",
"question": "You are given an integer array nums where the ith bag contains nums[i] balls.\n You are also given an integer maxOperations.\nYou can perform the following operation at most maxOperations times:Your penalty is the maximum number of balls in a bag.\n You want to minimize your penalty after the operations.\nReturn the minimum possible penalty after performing the operations.",
"examples": [
"Input: nums = [9], maxOperations = 2",
"Output: 3",
"Explanation: ",
"- Divide the bag with 9 balls into two bags of sizes 6 and 3. [9] -> [6,3].",
"- Divide the bag with 6 balls into two bags of sizes 3 and 3. [6,3] -> [3,3,3].",
"The bag with the most number of balls has 3 balls, so your penalty is 3 and you should return 3.",
"Input: nums = [2,4,8,2], maxOperations = 4",
"Output: 2",
"Explanation:",
"- Divide the bag with 8 balls into two bags of sizes 4 and 4. [2,4,8,2] -> [2,4,4,4,2].",
"- 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].",
"- 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].",
"- 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].",
"The bag with the most number of balls has 2 balls, so your penalty is 2 an you should return 2.",
"Input: nums = [7,17], maxOperations = 2",
"Output: 7",
""
],
"constraints": [
"Take any bag of balls and divide it into two new bags with a positive number of balls.\n\n\t\nFor 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\nFor 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. 1 <= nums. length <= 1051 <= maxOperations",
" nums[i] <= 109"
]
},
{
"id": "1764",
"title": "Form Array by Concatenating Subarrays of Another Array",
"question": "You are given a 2D integer array groups of length n.\n You are also given an integer array nums.\nYou 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.\ne.\n the subarrays must be in the same order as groups).\nReturn true if you can do this task, and false otherwise.\nNote that the subarrays are disjoint if and only if there is no index k such that nums[k] belongs to more than one subarray.\n A subarray is a contiguous sequence of elements within an array.",
"examples": [
"Input: groups = [[1,-1,-1],[3,-2,0]], nums = [1,-1,0,1,-1,-1,3,-2,0]",
"Output: true",
"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].",
"These subarrays are disjoint as they share no common nums[k] element.",
"Input: groups = [[10,-2],[1,2,3,4]], nums = [1,2,3,4,10,-2]",
"Output: false",
"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.",
"[10,-2] must come before [1,2,3,4].",
"Input: groups = [[1,2,3],[3,4]], nums = [7,7,1,2,3,4,7,7]",
"Output: false",
"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.",
"They share a common elements nums[4] (0-indexed).",
""
],
"constraints": [
"groups. length == n1 <= n <= 1031 <= groups[i]. length",
" sum(groups[i]. length) <= 1031 <= nums. length <= 103-107 <= groups[i][j]",
" nums[k] <= 107"
]
},
{
"id": "1765",
"title": "Map of Highest Peak",
"question": "You are given an integer matrix isWater of size m x n that represents a map of land and water cells.\nYou must assign each cell a height in a way that follows these rules:Find an assignment of heights such that the maximum height in the matrix is maximized.\nReturn an integer matrix height of size m x n where height[i][j] is cell (i, j)'s height.\n If there are multiple solutions, return any of them.",
"examples": [
"Input: isWater = [[0,1],[0,0]]",
"Output: [[1,0],[2,1]]",
"Explanation: The image shows the assigned heights of each cell.",
"The blue cell is the water cell, and the green cells are the land cells.",
"Input: isWater = [[0,0,1],[1,0,0],[0,0,0]]",
"Output: [[1,1,0],[0,1,1],[1,2,2]]",
"Explanation: A height of 2 is the maximum possible height of any assignment.",
"Any height assignment that has a maximum height of 2 while still meeting the rules will also be accepted.",
""
],
"constraints": [
"If isWater[i][j] == 0",
" cell (i",
" j) is a land cell. If isWater[i][j] == 1",
" cell (i",
" j) is a water cell. The height of each cell must be non-negative. If the cell is a water cell",
" its height must be 0. 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). m == isWater. lengthn == isWater[i]. length1 <= m",
" n <= 1000isWater[i][j] is 0 or 1. There is at least one water cell."
]
},
{
"id": "1769",
"title": "Minimum Number of Operations to Move All Balls to Each Box",
"question": "You have n boxes.\n 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.\nIn one operation, you can move one ball from a box to an adjacent box.\n Box i is adjacent to box j if abs(i - j) == 1.\n Note that after doing so, there may be more than one ball in some boxes.\nReturn 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.\nEach answer[i] is calculated considering the initial state of the boxes.",
"examples": [
"Input: boxes = \"110\"",
"Output: [1,1,3]",
"Explanation: The answer for each box is as follows:",
"1) First box: you will have to move one ball from the second box to the first box in one operation.",
"2) Second box: you will have to move one ball from the first box to the second box in one operation.",
"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.",
"Input: boxes = \"001011\"",
"Output: [11,8,5,4,3,4]"
],
"constraints": [
"n == boxes. length1 <= n <= 2000boxes[i] is either '0' or '1'."
]
},
{
"id": "1770",
"title": "Maximum Score from Performing Multiplication Operations",
"question": "You are given two integer arrays nums and multipliers of size n and m respectively, where n >= m.\n The arrays are 1-indexed.\nYou begin with a score of 0.\n You want to perform exactly m operations.\n On the ith operation (1-indexed), you will:Return the maximum score after performing m operations.",
"examples": [
"Input: nums = [1,2,3], multipliers = [3,2,1]",
"Output: 14",
"Explanation: An optimal solution is as follows:",
"- Choose from the end, [1,2,3], adding 3 * 3 = 9 to the score.",
"- Choose from the end, [1,2], adding 2 * 2 = 4 to the score.",
"- Choose from the end, [1], adding 1 * 1 = 1 to the score.",
"The total score is 9 + 4 + 1 = 14. Input: nums = [-5,-3,-3,-2,7,1], multipliers = [-10,-5,3,4,6]",
"Output: 102",
"Explanation: An optimal solution is as follows:",
"- Choose from the start, [-5,-3,-3,-2,7,1], adding -5 * -10 = 50 to the score.",
"- Choose from the start, [-3,-3,-2,7,1], adding -3 * -5 = 15 to the score.",
"- Choose from the start, [-3,-2,7,1], adding -3 * 3 = -9 to the score.",
"- Choose from the end, [-2,7,1], adding 1 * 4 = 4 to the score.",
"- Choose from the end, [-2,7], adding 7 * 6 = 42 to the score. ",
"The total score is 50 + 15 - 9 + 4 + 42 = 102.",
""
],
"constraints": [
"Choose one integer x from either the start or the end of the array nums. Add multipliers[i] * x to your score. Remove x from the array nums. n == nums. lengthm == multipliers. length1 <= m <= 103m <= n <= 105 -1000 <= nums[i]",
" multipliers[i] <= 1000"
]
},
{
"id": "53",
"title": "Maximum Subarray",
"question": "Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum.\nA subarray is a contiguous part of an array.\n   Follow up: If you have figured out the O(n) solution, try coding another solution using the divide and conquer approach, which is more subtle.",
"examples": [
"Input: nums = [-2,1,-3,4,-1,2,1,-5,4]",
"Output: 6",
"Explanation: [4,-1,2,1] has the largest sum = 6.",
"Input: nums = [1]",
"Output: 1",
"Input: nums = [5,4,-1,7,8]",
"Output: 23",
""
],
"constraints": [
"1 <= nums. length <= 3 * 104-105 <= nums[i] <= 105"
]
},
{
"id": "520",
"title": "Detect Capital",
"question": "We define the usage of capitals in a word to be right when one of the following cases holds:Given a string word, return true if the usage of capitals in it is right.",
"examples": [
"Input: word = \"USA\"",
"Output: true",
"Input: word = \"FlaG\"",
"Output: false",
""
],
"constraints": [
"All letters in this word are capitals",
" like \"USA\". All letters in this word are not capitals",
" like \"leetcode\". Only the first letter in this word is capital",
" like \"Google\". 1 <= word. length <= 100word consists of lowercase and uppercase English letters."
]
},
{
"id": "1774",
"title": "Closest Dessert Cost",
"question": "You would like to make dessert and are preparing to buy the ingredients.\n You have n ice cream base flavors and m types of toppings to choose from.\n You must follow these rules when making your dessert:You are given three inputs:You want to make a dessert with a total cost as close to target as possible.\nReturn the closest possible cost of the dessert to target.\n If there are multiple, return the lower one.",
"examples": [
"Input: baseCosts = [1,7], toppingCosts = [3,4], target = 10",
"Output: 10",
"Explanation: Consider the following combination (all 0-indexed):",
"- Choose base 1: cost 7",
"- Take 1 of topping 0: cost 1 x 3 = 3",
"- Take 0 of topping 1: cost 0 x 4 = 0",
"Total: 7 + 3 + 0 = 10.",
"Input: baseCosts = [2,3], toppingCosts = [4,5,100], target = 18",
"Output: 17",
"Explanation: Consider the following combination (all 0-indexed):",
"- Choose base 1: cost 3",
"- Take 1 of topping 0: cost 1 x 4 = 4",
"- Take 2 of topping 1: cost 2 x 5 = 10",
"- Take 0 of topping 2: cost 0 x 100 = 0",
"Total: 3 + 4 + 10 + 0 = 17. You cannot make a dessert with a total cost of 18.",
"Input: baseCosts = [3,10], toppingCosts = [2,5], target = 9",
"Output: 8",
"Explanation: It is possible to make desserts with cost 8 and 10. Return 8 as it is the lower cost.",
"Input: baseCosts = [10], toppingCosts = [1], target = 1",
"Output: 10",
"Explanation: Notice that you don't have to have any toppings, but you must have exactly one base."
],
"constraints": [
"There must be exactly one ice cream base. You can add one or more types of topping or have no toppings at all. There are at most two of each type of topping. baseCosts",
" an integer array of length n",
" where each baseCosts[i] represents the price of the ith ice cream base flavor. toppingCosts",
" an integer array of length m",
" where each toppingCosts[i] is the price of one of the ith topping. target",
" an integer representing your target price for dessert. n == baseCosts. lengthm == toppingCosts. length1 <= n",
" m <= 101 <= baseCosts[i]",
" toppingCosts[i] <= 1041 <= target <= 104"
]
},
{
"id": "1775",
"title": "Equal Sum Arrays With Minimum Number of Operations",
"question": "You are given two arrays of integers nums1 and nums2, possibly of different lengths.\n The values in the arrays are between 1 and 6, inclusive.\nIn one operation, you can change any integer's value in any of the arrays to any value between 1 and 6, inclusive.\nReturn the minimum number of operations required to make the sum of values in nums1 equal to the sum of values in nums2.\n Return -1​​​​​ if it is not possible to make the sum of the two arrays equal.",
"examples": [
"Input: nums1 = [1,2,3,4,5,6], nums2 = [1,1,2,2,2,2]",
"Output: 3",
"Explanation: You can make the sums of nums1 and nums2 equal with 3 operations. All indices are 0-indexed.",
"- Change nums2[0] to 6. nums1 = [1,2,3,4,5,6], nums2 = [6,1,2,2,2,2].",
"- Change nums1[5] to 1. nums1 = [1,2,3,4,5,1], nums2 = [6,1,2,2,2,2].",
"- Change nums1[2] to 2. nums1 = [1,2,2,4,5,1], nums2 = [6,1,2,2,2,2].",
"Input: nums1 = [1,1,1,1,1,1,1], nums2 = [6]",
"Output: -1",
"Explanation: There is no way to decrease the sum of nums1 or to increase the sum of nums2 to make them equal.",
"Input: nums1 = [6,6], nums2 = [1]",
"Output: 3",
"Explanation: You can make the sums of nums1 and nums2 equal with 3 operations. All indices are 0-indexed. ",
"- Change nums1[0] to 2. nums1 = [2,6], nums2 = [1].",
"- Change nums1[1] to 2. nums1 = [2,2], nums2 = [1].",
"- Change nums2[0] to 4. nums1 = [2,2], nums2 = [4].",
""
],
"constraints": [
"1 <= nums1. length",
" nums2. length <= 1051 <= nums1[i]",
" nums2[i] <= 6"
]
},
{
"id": "1780",
"title": "Check if Number is a Sum of Powers of Three",
"question": "Given an integer n, return true if it is possible to represent n as the sum of distinct powers of three.\n Otherwise, return false.\nAn integer y is a power of three if there exists an integer x such that y == 3x.",
"examples": [
"Input: n = 12",
"Output: true",
"Explanation: 12 = 31 + 32",
"Input: n = 91",
"Output: true",
"Explanation: 91 = 30 + 32 + 34",
"Input: n = 21",
"Output: false",
""
],
"constraints": [
"1 <= n <= 107"
]
},
{
"id": "1781",
"title": "Sum of Beauty of All Substrings",
"question": "The beauty of a string is the difference in frequencies between the most frequent and least frequent characters.\nGiven a string s, return the sum of beauty of all of its substrings.",
"examples": [
"Input: s = \"aabcb\"",
"Output: 5",
"Explanation: The substrings with non-zero beauty are [\"aab\",\"aabc\",\"aabcb\",\"abcb\",\"bcb\"], each with beauty equal to 1. Input: s = \"aabcbaa\"",
"Output: 17",
""
],
"constraints": [
"For example",
" the beauty of \"abaacc\" is 3 - 1 = 2. 1 <= s. length <= 500s consists of only lowercase English letters."
]
},
{
"id": "1785",
"title": "Minimum Elements to Add to Form a Given Sum",
"question": "You are given an integer array nums and two integers limit and goal.\n The array nums has an interesting property that abs(nums[i]) <= limit.\nReturn the minimum number of elements you need to add to make the sum of the array equal to goal.\n The array must maintain its property that abs(nums[i]) <= limit.\nNote that abs(x) equals x if x >= 0, and -x otherwise.",
"examples": [
"Input: nums = [1,-1,1], limit = 3, goal = -4",
"Output: 2",
"Explanation: You can add -2 and -3, then the sum of the array will be 1 - 1 + 1 - 2 - 3 = -4.",
"Input: nums = [1,-10,9,1], limit = 100, goal = 0",
"Output: 1",
""
],
"constraints": [
"1 <= nums. length <= 1051 <= limit <= 106-limit <= nums[i] <= limit-109 <= goal <= 109"
]
},
{
"id": "1786",
"title": "Number of Restricted Paths From First to Last Node",
"question": "There is an undirected weighted connected graph.\n 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.\nA path from node start to node end is a sequence of nodes [z0, z1, z2, .\n.\n.\n, zk] such that z0 = start and zk = end and there is an edge between zi and zi+1 where 0 <= i <= k-1.\nThe distance of a path is the sum of the weights on the edges of the path.\n Let distanceToLastNode(x) denote the shortest distance of a path between node n and node x.\n A restricted path is a path that also satisfies that distanceToLastNode(zi) > distanceToLastNode(zi+1) where 0 <= i <= k-1.\nReturn the number of restricted paths from node 1 to node n.\n Since that number may be too large, return it modulo 109 + 7.",
"examples": [
"Input: n = 5, edges = [[1,2,3],[1,3,3],[2,3,1],[1,4,2],[5,2,2],[3,5,1],[5,4,10]]",
"Output: 3",
"Explanation: Each circle contains the node number in black and its distanceToLastNode value in blue. The three restricted paths are:",
"1) 1 --> 2 --> 5",
"2) 1 --> 2 --> 3 --> 5",
"3) 1 --> 3 --> 5",
"Input: 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]]",
"Output: 1",
"Explanation: Each circle contains the node number in black and its distanceToLastNode value in blue. The only restricted path is 1 --> 3 --> 7.",
""
],
"constraints": [
"1 <= n <= 2 * 104n - 1 <= edges. length <= 4 * 104edges[i]. length == 31 <= ui",
" vi <= nui != vi1 <= weighti <= 105There is at most one edge between any two nodes. There is at least one path between any two nodes."
]
},
{
"id": "1792",
"title": "Maximum Average Pass Ratio",
"question": "There is a school that has classes of students and each class will be having a final exam.\n You are given a 2D integer array classes, where classes[i] = [passi, totali].\n You know beforehand that in the ith class, there are totali total students, but only passi number of students will pass the exam.\nYou are also given an integer extraStudents.\n There are another extraStudents brilliant students that are guaranteed to pass the exam of any class they are assigned to.\n 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.\nThe 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.\n The average pass ratio is the sum of pass ratios of all the classes divided by the number of the classes.\nReturn the maximum possible average pass ratio after assigning the extraStudents students.\n Answers within 10-5 of the actual answer will be accepted.",
"examples": [
"Input: classes = [[1,2],[3,5],[2,2]], extraStudents = 2",
"Output: 0. 78333",
"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.",
"Input: classes = [[2,4],[3,9],[4,5],[2,10]], extraStudents = 4",
"Output: 0. 53485",
""
],
"constraints": [
"1 <= classes. length <= 105classes[i]. length == 21 <= passi <= totali <= 1051 <= extraStudents <= 105"
]
},
{
"id": "1797",
"title": "Design Authentication Manager",
"question": "There is an authentication system that works with authentication tokens.\n For each session, the user will receive a new authentication token that will expire timeToLive seconds after the currentTime.\n If the token is renewed, the expiry time will be extended to expire timeToLive seconds after the (potentially different) currentTime.\nImplement the AuthenticationManager class:Note that if a token expires at time t, and another action happens on time t (renew or countUnexpiredTokens), the expiration takes place before the other actions.",
"examples": [
"Input",
"[\"AuthenticationManager\", \"renew\", \"generate\", \"countUnexpiredTokens\", \"generate\", \"renew\", \"renew\", \"countUnexpiredTokens\"]",
"[[5], [\"aaa\", 1], [\"aaa\", 2], [6], [\"bbb\", 7], [\"aaa\", 8], [\"bbb\", 10], [15]]",
"Output",
"[null, null, null, 1, null, null, null, 0]",
"",
"Explanation",
"AuthenticationManager authenticationManager = new AuthenticationManager(5); // Constructs the AuthenticationManager with timeToLive = 5 seconds.",
"authenticationManager. renew(\"aaa\", 1); // No token exists with tokenId \"aaa\" at time 1, so nothing happens.",
"authenticationManager. generate(\"aaa\", 2); // Generates a new token with tokenId \"aaa\" at time 2.",
"authenticationManager. countUnexpiredTokens(6); // The token with tokenId \"aaa\" is the only unexpired one at time 6, so return 1.",
"authenticationManager. generate(\"bbb\", 7); // Generates a new token with tokenId \"bbb\" at time 7.",
"authenticationManager. renew(\"aaa\", 8); // The token with tokenId \"aaa\" expired at time 7, and 8 >= 7, so at time 8 the renew request is ignored, and nothing happens.",
"authenticationManager. renew(\"bbb\", 10); // The token with tokenId \"bbb\" is unexpired at time 10, so the renew request is fulfilled and now the token will expire at time 15.",
"authenticationManager. countUnexpiredTokens(15); // The token with tokenId \"bbb\" expires at time 15, and the token with tokenId \"aaa\" expired at time 7, so currently no token is unexpired, so return 0.",
""
],
"constraints": [
"AuthenticationManager(int timeToLive) constructs the AuthenticationManager and sets the timeToLive. generate(string tokenId",
" int currentTime) generates a new token with the given tokenId at the given currentTime in seconds. renew(string tokenId",
" int currentTime) renews the unexpired token with the given tokenId at the given currentTime in seconds. If there are no unexpired tokens with the given tokenId",
" the request is ignored",
" and nothing happens. countUnexpiredTokens(int currentTime) returns the number of unexpired tokens at the given currentTime. 1 <= timeToLive <= 1081 <= currentTime <= 1081 <= tokenId. length <= 5tokenId consists only of lowercase letters. All calls to generate will contain unique values of tokenId. The values of currentTime across all the function calls will be strictly increasing. At most 2000 calls will be made to all functions combined."
]
},
{
"id": "1798",
"title": "Maximum Number of Consecutive Values You Can Make",
"question": "You are given an integer array coins of length n which represents the n coins that you own.\n The value of the ith coin is coins[i].\n You can make some value x if you can choose some of your n coins such that their values sum up to x.\nReturn the maximum number of consecutive integer values that you can make with your coins starting from and including 0.\nNote that you may have multiple coins of the same value.",
"examples": [
"Input: coins = [1,3]",
"Output: 2",
"Explanation: You can make the following values:",
"- 0: take []",
"- 1: take [1]",
"You can make 2 consecutive integer values starting from 0. Input: coins = [1,1,1,4]",
"Output: 8",
"Explanation: You can make the following values:",
"- 0: take []",
"- 1: take [1]",
"- 2: take [1,1]",
"- 3: take [1,1,1]",
"- 4: take [4]",
"- 5: take [4,1]",
"- 6: take [4,1,1]",
"- 7: take [4,1,1,1]",
"You can make 8 consecutive integer values starting from 0. Input: nums = [1,4,10,3,1]",
"Output: 20"
],
"constraints": [
"coins. length == n1 <= n <= 4 * 1041 <= coins[i] <= 4 * 104"
]
},
{
"id": "1801",
"title": "Number of Orders in the Backlog",
"question": "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.\n The orderTypei is:Note that orders[i] represents a batch of amounti independent orders with the same price and order type.\n All orders represented by orders[i] will be placed before all orders represented by orders[i+1] for all valid i.\nThere is a backlog that consists of orders that have not been executed.\n The backlog is initially empty.\n When an order is placed, the following happens:Return the total amount of orders in the backlog after placing all the orders from the input.\n Since this number can be large, return it modulo 109 + 7.",
"examples": [
"Input: orders = [[10,5,0],[15,2,1],[25,1,1],[30,4,0]]",
"Output: 6",
"Explanation: Here is what happens with the orders:",
"- 5 orders of type buy with price 10 are placed. There are no sell orders, so the 5 orders are added to the backlog.",
"- 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.",
"- 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.",
"- 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.",
"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.",
"Input: orders = [[7,1000000000,1],[15,3,0],[5,999999995,0],[5,1,1]]",
"Output: 999999984",
"Explanation: Here is what happens with the orders:",
"- 109 orders of type sell with price 7 are placed. There are no buy orders, so the 109 orders are added to the backlog.",
"- 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.",
"- 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.",
"- 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.",
"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).",
""
],
"constraints": [
"0 if it is a batch of buy orders",
" or1 if it is a batch of sell orders. If 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. Vice 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. 1 <= orders. length <= 105orders[i]. length == 31 <= pricei",
" amounti <= 109orderTypei is either 0 or 1."
]
},
{
"id": "521",
"title": "Longest Uncommon Subsequence I",
"question": "Given two strings a and b, return the length of the longest uncommon subsequence between a and b.\n If the longest uncommon subsequence does not exist, return -1.\nAn uncommon subsequence between two strings is a string that is a subsequence of one but not the other.\nA subsequence of a string s is a string that can be obtained after deleting any number of characters from s.",
"examples": [
"Input: a = \"aba\", b = \"cdc\"",
"Output: 3",
"Explanation: One longest uncommon subsequence is \"aba\" because \"aba\" is a subsequence of \"aba\" but not \"cdc\".",
"Note that \"cdc\" is also a longest uncommon subsequence.",
"Input: a = \"aaa\", b = \"bbb\"",
"Output: 3",
"Explanation: The longest uncommon subsequences are \"aaa\" and \"bbb\".",
"Input: a = \"aaa\", b = \"aaa\"",
"Output: -1",
"Explanation: Every subsequence of string a is also a subsequence of string b. Similarly, every subsequence of string b is also a subsequence of string a.",
""
],
"constraints": [
"For example",
" \"abc\" is a subsequence of \"aebdc\" because you can delete the underlined characters in \"aebdc\" to get \"abc\". Other subsequences of \"aebdc\" include \"aebdc\"",
" \"aeb\"",
" and \"\" (empty string). 1 <= a. length",
" b. length <= 100a and b consist of lower-case English letters."
]
},
{
"id": "1802",
"title": "Maximum Value at a Given Index in a Bounded Array",
"question": "You are given three positive integers: n, index, and maxSum.\n You want to construct an array nums (0-indexed) that satisfies the following conditions:Return nums[index] of the constructed array.\nNote that abs(x) equals x if x >= 0, and -x otherwise.",
"examples": [
"Input: n = 4, index = 2, maxSum = 6",
"Output: 2",
"Explanation: nums = [1,2,2,1] is one array that satisfies all the conditions.",
"There are no arrays that satisfy all the conditions and have nums[2] == 3, so 2 is the maximum nums[2].",
"Input: n = 6, index = 1, maxSum = 10",
"Output: 3",
""
],
"constraints": [
"nums. length == nnums[i] is a positive integer where 0 <= i < n. abs(nums[i] - nums[i+1]) <= 1 where 0 <= i < n-1. The sum of all the elements of nums does not exceed maxSum. nums[index] is maximized. 1 <= n <= maxSum <= 1090 <= index < n"
]
},
{
"id": "1806",
"title": "Minimum Number of Operations to Reinitialize a Permutation",
"question": "You are given an even integer n​​​​​​.\n You initially have a permutation perm of size n​​ where perm[i] == i​ (0-indexed)​​​​.\nIn one operation, you will create a new array arr, and for each i:You will then assign arr​​​​ to perm.\nReturn the minimum non-zero number of operations you need to perform on perm to return the permutation to its initial value.",
"examples": [
"Input: n = 2",
"Output: 1",
"Explanation: perm = [0,1] initially.",
"After the 1st operation, perm = [0,1]",
"So it takes only 1 operation.",
"Input: n = 4",
"Output: 2",
"Explanation: perm = [0,1,2,3] initially.",
"After the 1st operation, perm = [0,2,1,3]",
"After the 2nd operation, perm = [0,1,2,3]",
"So it takes only 2 operations.",
"Input: n = 6",
"Output: 4",
""
],
"constraints": [
"If i % 2 == 0",
" then arr[i] = perm[i / 2]. If i % 2 == 1",
" then arr[i] = perm[n / 2 + (i - 1) / 2]. 2 <= n <= 1000n​​​​​​ is even."
]
},
{
"id": "1807",
"title": "Evaluate the Bracket Pairs of a String",
"question": "You are given a string s that contains some bracket pairs, with each pair containing a non-empty key.\nYou know the values of a wide range of keys.\n This is represented by a 2D string array knowledge where each knowledge[i] = [keyi, valuei] indicates that key keyi has a value of valuei.\nYou are tasked to evaluate all of the bracket pairs.\n When you evaluate a bracket pair that contains some key keyi, you will:Each key will appear at most once in your knowledge.\n There will not be any nested brackets in s.\nReturn the resulting string after evaluating all of the bracket pairs.",
"examples": [
"Input: s = \"(name)is(age)yearsold\", knowledge = [[\"name\",\"bob\"],[\"age\",\"two\"]]",
"Output: \"bobistwoyearsold\"",
"Explanation:",
"The key \"name\" has a value of \"bob\", so replace \"(name)\" with \"bob\".",
"The key \"age\" has a value of \"two\", so replace \"(age)\" with \"two\".",
"Input: s = \"hi(name)\", knowledge = [[\"a\",\"b\"]]",
"Output: \"hi?\"",
"Explanation: As you do not know the value of the key \"name\", replace \"(name)\" with \"?\".",
"Input: s = \"(a)(a)(a)aaa\", knowledge = [[\"a\",\"yes\"]]",
"Output: \"yesyesyesaaa\"",
"Explanation: The same key can appear multiple times.",
"The key \"a\" has a value of \"yes\", so replace all occurrences of \"(a)\" with \"yes\".",
"Notice that the \"a\"s not in a bracket pair are not evaluated.",
"Input: s = \"(a)(b)\", knowledge = [[\"a\",\"b\"],[\"b\",\"a\"]]",
"Output: \"ba\""
],
"constraints": [
"For example",
" in the string \"(name)is(age)yearsold\"",
" there are two bracket pairs that contain the keys \"name\" and \"age\". Replace keyi and the bracket pair with the key's corresponding valuei. 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). 1 <= s. length <= 1050 <= knowledge. length <= 105knowledge[i]. length == 21 <= keyi. length",
" valuei. length <= 10s consists of lowercase English letters and round brackets '(' and ')'. Every open bracket '(' in s will have a corresponding close bracket ')'. The key in each bracket pair of s will be non-empty. There will not be any nested bracket pairs in s. keyi and valuei consist of lowercase English letters. Each keyi in knowledge is unique."
]
},
{
"id": "1813",
"title": "Sentence Similarity III",
"question": "A sentence is a list of words that are separated by a single space with no leading or trailing spaces.\n For example, \"Hello World\", \"HELLO\", \"hello world hello world\" are all sentences.\n Words consist of only uppercase and lowercase English letters.\nTwo sentences sentence1 and sentence2 are similar if it is possible to insert an arbitrary sentence (possibly empty) inside one of these sentences such that the two sentences become equal.\n For example, sentence1 = \"Hello my name is Jane\" and sentence2 = \"Hello Jane\" can be made equal by inserting \"my name is\" between \"Hello\" and \"Jane\" in sentence2.\nGiven two sentences sentence1 and sentence2, return true if sentence1 and sentence2 are similar.\n Otherwise, return false.",
"examples": [
"Input: sentence1 = \"My name is Haley\", sentence2 = \"My Haley\"",
"Output: true",
"Explanation: sentence2 can be turned to sentence1 by inserting \"name is\" between \"My\" and \"Haley\".",
"Input: sentence1 = \"of\", sentence2 = \"A lot of words\"",
"Output: false",
"Explanation: No single sentence can be inserted inside one of the sentences to make it equal to the other.",
"Input: sentence1 = \"Eating right now\", sentence2 = \"Eating\"",
"Output: true",
"Explanation: sentence2 can be turned to sentence1 by inserting \"right now\" at the end of the sentence.",
"Input: sentence1 = \"Luky\", sentence2 = \"Lucccky\"",
"Output: false",
""
],
"constraints": [
"1 <= sentence1. length",
" sentence2. length <= 100sentence1 and sentence2 consist of lowercase and uppercase English letters and spaces. The words in sentence1 and sentence2 are separated by a single space."
]
},
{
"id": "1814",
"title": "Count Nice Pairs in an Array",
"question": "You are given an array nums that consists of non-negative integers.\n Let us define rev(x) as the reverse of the non-negative integer x.\n For example, rev(123) = 321, and rev(120) = 21.\n A pair of indices (i, j) is nice if it satisfies all of the following conditions:Return the number of nice pairs of indices.\n Since that number can be too large, return it modulo 109 + 7.",
"examples": [
"Input: nums = [42,11,1,97]",
"Output: 2",
"Explanation: The two pairs are:",
" - (0,3) : 42 + rev(97) = 42 + 79 = 121, 97 + rev(42) = 97 + 24 = 121.",
" - (1,2) : 11 + rev(1) = 11 + 1 = 12, 1 + rev(11) = 1 + 11 = 12.",
"Input: nums = [13,10,35,24,76]",
"Output: 4",
""
],
"constraints": [
"0 <= i < j < nums. lengthnums[i] + rev(nums[j]) == nums[j] + rev(nums[i])1 <= nums. length <= 1050 <= nums[i] <= 109"
]
},
{
"id": "1817",
"title": "Finding the Users Active Minutes",
"question": "You are given the logs for users' actions on LeetCode, and an integer k.\n 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.\nMultiple users can perform actions simultaneously, and a single user can perform multiple actions in the same minute.\nThe 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.\n A minute can only be counted once, even if multiple actions occur during it.\nYou 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.\nReturn the array answer as described above.",
"examples": [
"Input: logs = [[0,5],[1,2],[0,2],[0,5],[1,3]], k = 5",
"Output: [0,2,0,0,0]",
"Explanation:",
"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).",
"The user with ID=1 performed actions at minutes 2 and 3. Hence, they have a UAM of 2.",
"Since both users have a UAM of 2, answer[2] is 2, and the remaining answer[j] values are 0.",
"Input: logs = [[1,1],[2,2],[2,3]], k = 4",
"Output: [1,1,0,0]",
"Explanation:",
"The user with ID=1 performed a single action at minute 1. Hence, they have a UAM of 1.",
"The user with ID=2 performed actions at minutes 2 and 3. Hence, they have a UAM of 2.",
"There is one user with a UAM of 1 and one with a UAM of 2.",
"Hence, answer[1] = 1, answer[2] = 1, and the remaining values are 0.",
""
],
"constraints": [
"1 <= logs. length <= 1040 <= IDi <= 1091 <= timei <= 105k is in the range [The maximum UAM for a user",
" 105]."
]
},
{
"id": "1818",
"title": "Minimum Absolute Sum Difference",
"question": "You are given two positive integer arrays nums1 and nums2, both of length n.\nThe 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).\nYou can replace at most one element of nums1 with any other element in nums1 to minimize the absolute sum difference.\nReturn the minimum absolute sum difference after replacing at most one element in the array nums1.\n Since the answer may be large, return it modulo 109 + 7.\n|x| is defined as:",
"examples": [
"Input: nums1 = [1,7,5], nums2 = [2,3,5]",
"Output: 3",
"Explanation: There are two possible optimal solutions:",
"- Replace the second element with the first: [1,7,5] => [1,1,5], or",
"- Replace the second element with the third: [1,7,5] => [1,5,5].",
"Both will yield an absolute sum difference of |1-2| + (|1-3| or |5-3|) + |5-5| = 3.",
"Input: nums1 = [2,4,6,8,10], nums2 = [2,4,6,8,10]",
"Output: 0",
"Explanation: nums1 is equal to nums2 so no replacement is needed. This will result in an ",
"absolute sum difference of 0.",
"Input: nums1 = [1,10,4,4,2,7], nums2 = [9,3,5,1,7,4]",
"Output: 20",
"Explanation: Replace the first element with the second: [1,10,4,4,2,7] => [10,10,4,4,2,7].",
"This yields an absolute sum difference of |10-9| + |10-3| + |4-5| + |4-1| + |2-7| + |7-4| = 20",
""
],
"constraints": [
"x if x >= 0",
" or-x if x < 0. n == nums1. lengthn == nums2. length1 <= n <= 1051 <= nums1[i]",
" nums2[i] <= 105"
]
},
{
"id": "1823",
"title": "Find the Winner of the Circular Game",
"question": "There are n friends that are playing a game.\n The friends are sitting in a circle and are numbered from 1 to n in clockwise order.\n 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.\nThe rules of the game are as follows:Given the number of friends, n, and an integer k, return the winner of the game.",
"examples": [
"Input: n = 5, k = 2",
"Output: 3",
"Explanation: Here are the steps of the game:",
"1) Start at friend 1.",
"2) Count 2 friends clockwise, which are friends 1 and 2.",
"3) Friend 2 leaves the circle. Next start is friend 3.",
"4) Count 2 friends clockwise, which are friends 3 and 4.",
"5) Friend 4 leaves the circle. Next start is friend 5.",
"6) Count 2 friends clockwise, which are friends 5 and 1.",
"7) Friend 1 leaves the circle. Next start is friend 3.",
"8) Count 2 friends clockwise, which are friends 3 and 5.",
"9) Friend 5 leaves the circle. Only friend 3 is left, so they are the winner. Input: n = 6, k = 5",
"Output: 1",
"Explanation: The friends leave in this order: 5, 4, 6, 2, 3. The winner is friend 1.",
""
],
"constraints": [
"1 <= k <= n <= 500"
]
},
{
"id": "1824",
"title": "Minimum Sideway Jumps",
"question": "There is a 3 lane road of length n that consists of n + 1 points labeled from 0 to n.\n A frog starts at point 0 in the second lane and wants to jump to point n.\n However, there could be obstacles along the way.\nYou 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.\n If obstacles[i] == 0, there are no obstacles at point i.\n There will be at most one obstacle in the 3 lanes at each point.\nThe 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.\n 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.\nReturn the minimum number of side jumps the frog needs to reach any lane at point n starting from lane 2 at point 0.\nNote: There will be no obstacles on points 0 and n.",
"examples": [
"Input: obstacles = [0,1,2,3,0]",
"Output: 2 ",
"Explanation: The optimal solution is shown by the arrows above. There are 2 side jumps (red arrows).",
"Note that the frog can jump over obstacles only when making side jumps (as shown at point 2).",
"Input: obstacles = [0,1,1,3,3,0]",
"Output: 0",
"Explanation: There are no obstacles on lane 2. No side jumps are required.",
"Input: obstacles = [0,2,1,0,3,0]",
"Output: 2",
"Explanation: The optimal solution is shown by the arrows above. There are 2 side jumps.",
""
],
"constraints": [
"For example",
" if obstacles[2] == 1",
" then there is an obstacle on lane 1 at point 2. For example",
" the frog can jump from lane 3 at point 3 to lane 1 at point 3. obstacles. length == n + 11 <= n <= 5 * 1050 <= obstacles[i] <= 3obstacles[0] == obstacles[n] == 0"
]
},
{
"id": "1828",
"title": "Queries on Number of Points Inside a Circle",
"question": "You are given an array points where points[i] = [xi, yi] is the coordinates of the ith point on a 2D plane.\n Multiple points can have the same coordinates.\nYou are also given an array queries where queries[j] = [xj, yj, rj] describes a circle centered at (xj, yj) with a radius of rj.\nFor each query queries[j], compute the number of points inside the jth circle.\n Points on the border of the circle are considered inside.\nReturn an array answer, where answer[j] is the answer to the jth query.\n   Follow up: Could you find the answer for each query in better complexity than O(n)?",
"examples": [
"Input: points = [[1,3],[3,3],[5,3],[2,2]], queries = [[2,3,1],[4,3,1],[1,1,2]]",
"Output: [3,2,2]",
"Explanation: The points and circles are shown above.",
"queries[0] is the green circle, queries[1] is the red circle, and queries[2] is the blue circle.",
"Input: points = [[1,1],[2,2],[3,3],[4,4],[5,5]], queries = [[1,2,2],[2,2,2],[4,3,2],[4,3,3]]",
"Output: [2,3,2,4]",
"Explanation: The points and circles are shown above.",
"queries[0] is green, queries[1] is red, queries[2] is blue, and queries[3] is purple.",
""
],
"constraints": [
"1 <= points. length <= 500points[i]. length == 20 <= x​​​​​​i",
" y​​​​​​i <= 5001 <= queries. length <= 500queries[j]. length == 30 <= xj",
" yj <= 5001 <= rj <= 500All coordinates are integers."
]
},
{
"id": "530",
"title": "Minimum Absolute Difference in BST",
"question": "Given the root of a Binary Search Tree (BST), return the minimum absolute difference between the values of any two different nodes in the tree.\n   Note: This question is the same as 783: https://leetcode.\ncom/problems/minimum-distance-between-bst-nodes/",
"examples": [
"Input: root = [4,2,6,1,3]",
"Output: 1",
"Input: root = [1,0,48,null,null,12,49]",
"Output: 1",
""
],
"constraints": [
"The number of nodes in the tree is in the range [2",
" 104]. 0 <= Node. val <= 105"
]
},
{
"id": "1829",
"title": "Maximum XOR for Each Query",
"question": "You are given a sorted array nums of n non-negative integers and an integer maximumBit.\n You want to perform the following query n times:Return an array answer, where answer[i] is the answer to the ith query.",
"examples": [
"Input: nums = [0,1,1,3], maximumBit = 2",
"Output: [0,3,2,3]",
"Explanation: The queries are answered as follows:",
"1st query: nums = [0,1,1,3], k = 0 since 0 XOR 1 XOR 1 XOR 3 XOR 0 = 3.",
"2nd query: nums = [0,1,1], k = 3 since 0 XOR 1 XOR 1 XOR 3 = 3.",
"3rd query: nums = [0,1], k = 2 since 0 XOR 1 XOR 2 = 3.",
"4th query: nums = [0], k = 3 since 0 XOR 3 = 3.",
"Input: nums = [2,3,4,7], maximumBit = 3",
"Output: [5,2,6,5]",
"Explanation: The queries are answered as follows:",
"1st query: nums = [2,3,4,7], k = 5 since 2 XOR 3 XOR 4 XOR 7 XOR 5 = 7.",
"2nd query: nums = [2,3,4], k = 2 since 2 XOR 3 XOR 4 XOR 2 = 7.",
"3rd query: nums = [2,3], k = 6 since 2 XOR 3 XOR 6 = 7.",
"4th query: nums = [2], k = 5 since 2 XOR 5 = 7.",
"Input: nums = [0,1,2,2,5,7], maximumBit = 3",
"Output: [4,3,6,4,6,7]",
""
],
"constraints": [
"nums. length == n1 <= n <= 1051 <= maximumBit <= 200 <= nums[i] < 2maximumBitnums​​​ is sorted in ascending order."
]
},
{
"id": "1833",
"title": "Maximum Ice Cream Bars",
"question": "It is a sweltering summer day, and a boy wants to buy some ice cream bars.\nAt the store, there are n ice cream bars.\n You are given an array costs of length n, where costs[i] is the price of the ith ice cream bar in coins.\n The boy initially has coins coins to spend, and he wants to buy as many ice cream bars as possible.\n Return the maximum number of ice cream bars the boy can buy with coins coins.\nNote: The boy can buy the ice cream bars in any order.",
"examples": [
"Input: costs = [1,3,2,4,1], coins = 7",
"Output: 4",
"Explanation: The boy can buy ice cream bars at indices 0,1,2,4 for a total price of 1 + 3 + 2 + 1 = 7.",
"Input: costs = [10,6,8,7,7,8], coins = 5",
"Output: 0",
"Explanation: The boy cannot afford any of the ice cream bars.",
"Input: costs = [1,6,3,1,2,5], coins = 20",
"Output: 6",
"Explanation: The boy can buy all the ice cream bars for a total price of 1 + 6 + 3 + 1 + 2 + 5 = 18.",
""
],
"constraints": [
"costs. length == n1 <= n <= 1051 <= costs[i] <= 1051 <= coins <= 108"
]
},
{
"id": "1834",
"title": "Single-Threaded CPU",
"question": "You are given n​​​​​​ tasks labeled from 0 to n - 1 represented by a 2D integer array tasks, where tasks[i] = [enqueueTimei, processingTimei] means that the i​​​​​​th​​​​ task will be available to process at enqueueTimei and will take processingTimei to finish processing.\nYou have a single-threaded CPU that can process at most one task at a time and will act in the following way:Return the order in which the CPU will process the tasks.",
"examples": [
"Input: tasks = [[1,2],[2,4],[3,2],[4,1]]",
"Output: [0,2,3,1]",
"Explanation: The events go as follows: ",
"- At time = 1, task 0 is available to process. Available tasks = {0}.",
"- Also at time = 1, the idle CPU starts processing task 0. Available tasks = {}.",
"- At time = 2, task 1 is available to process. Available tasks = {1}.",
"- At time = 3, task 2 is available to process. Available tasks = {1, 2}.",
"- Also at time = 3, the CPU finishes task 0 and starts processing task 2 as it is the shortest. Available tasks = {1}.",
"- At time = 4, task 3 is available to process. Available tasks = {1, 3}.",
"- At time = 5, the CPU finishes task 2 and starts processing task 3 as it is the shortest. Available tasks = {1}.",
"- At time = 6, the CPU finishes task 3 and starts processing task 1. Available tasks = {}.",
"- At time = 10, the CPU finishes task 1 and becomes idle.",
"Input: tasks = [[7,10],[7,12],[7,5],[7,4],[7,2]]",
"Output: [4,3,2,0,1]",
"Explanation: The events go as follows:",
"- At time = 7, all the tasks become available. Available tasks = {0,1,2,3,4}.",
"- Also at time = 7, the idle CPU starts processing task 4. Available tasks = {0,1,2,3}.",
"- At time = 9, the CPU finishes task 4 and starts processing task 3. Available tasks = {0,1,2}.",
"- At time = 13, the CPU finishes task 3 and starts processing task 2. Available tasks = {0,1}.",
"- At time = 18, the CPU finishes task 2 and starts processing task 0. Available tasks = {1}.",
"- At time = 28, the CPU finishes task 0 and starts processing task 1. Available tasks = {}.",
"- At time = 40, the CPU finishes task 1 and becomes idle.",
""
],
"constraints": [
"If the CPU is idle and there are no available tasks to process",
" the CPU remains idle. 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. Once a task is started",
" the CPU will process the entire task without stopping. The CPU can finish a task then start a new one instantly. tasks. length == n1 <= n <= 1051 <= enqueueTimei",
" processingTimei <= 109"
]
},
{
"id": "1838",
"title": "Frequency of the Most Frequent Element",
"question": "The frequency of an element is the number of times it occurs in an array.\nYou are given an integer array nums and an integer k.\n In one operation, you can choose an index of nums and increment the element at that index by 1.\nReturn the maximum possible frequency of an element after performing at most k operations.",
"examples": [
"Input: nums = [1,2,4], k = 5",
"Output: 3",
"Explanation: Increment the first element three times and the second element two times to make nums = [4,4,4].",
"4 has a frequency of 3. Input: nums = [1,4,8,13], k = 5",
"Output: 2",
"Explanation: There are multiple optimal solutions:",
"- Increment the first element three times to make nums = [4,4,8,13]. 4 has a frequency of 2.",
"- Increment the second element four times to make nums = [1,8,8,13]. 8 has a frequency of 2.",
"- Increment the third element five times to make nums = [1,4,13,13]. 13 has a frequency of 2.",
"Input: nums = [3,9,6], k = 2",
"Output: 1",
""
],
"constraints": [
"1 <= nums. length <= 1051 <= nums[i] <= 1051 <= k <= 105"
]
},
{
"id": "1839",
"title": "Longest Substring Of All Vowels in Order",
"question": "A string is considered beautiful if it satisfies the following conditions:For example, strings \"aeiou\" and \"aaaaaaeiiiioou\" are considered beautiful, but \"uaeio\", \"aeoiu\", and \"aaaeeeooo\" are not beautiful.\nGiven a string word consisting of English vowels, return the length of the longest beautiful substring of word.\n If no such substring exists, return 0.\nA substring is a contiguous sequence of characters in a string.",
"examples": [
"Input: word = \"aeiaaioaaaaeiiiiouuuooaauuaeiu\"",
"Output: 13",
"Explanation: The longest beautiful substring in word is \"aaaaeiiiiouuu\" of length 13. Input: word = \"aeeeiiiioooauuuaeiou\"",
"Output: 5",
"Explanation: The longest beautiful substring in word is \"aeiou\" of length 5.",
"Input: word = \"a\"",
"Output: 0",
"Explanation: There is no beautiful substring, so return 0.",
""
],
"constraints": [
"Each of the 5 English vowels ('a'",
" 'e'",
" 'i'",
" 'o'",
" 'u') must appear at least once in it. The letters must be sorted in alphabetical order (i. e. all 'a's before 'e's",
" all 'e's before 'i's",
" etc.). 1 <= word. length <= 5 * 105word consists of characters 'a'",
" 'e'",
" 'i'",
" 'o'",
" and 'u'."
]
},
{
"id": "1845",
"title": "Seat Reservation Manager",
"question": "Design a system that manages the reservation state of n seats that are numbered from 1 to n.\nImplement the SeatManager class:",
"examples": [
"Input",
"[\"SeatManager\", \"reserve\", \"reserve\", \"unreserve\", \"reserve\", \"reserve\", \"reserve\", \"reserve\", \"unreserve\"]",
"[[5], [], [], [2], [], [], [], [], [5]]",
"Output",
"[null, 1, 2, null, 2, 3, 4, 5, null]",
"",
"Explanation",
"SeatManager seatManager = new SeatManager(5); // Initializes a SeatManager with 5 seats.",
"seatManager. reserve(); // All seats are available, so return the lowest numbered seat, which is 1.",
"seatManager. reserve(); // The available seats are [2,3,4,5], so return the lowest of them, which is 2.",
"seatManager. unreserve(2); // Unreserve seat 2, so now the available seats are [2,3,4,5].",
"seatManager. reserve(); // The available seats are [2,3,4,5], so return the lowest of them, which is 2.",
"seatManager. reserve(); // The available seats are [3,4,5], so return the lowest of them, which is 3.",
"seatManager. reserve(); // The available seats are [4,5], so return the lowest of them, which is 4.",
"seatManager. reserve(); // The only available seat is seat 5, so return 5.",
"seatManager. unreserve(5); // Unreserve seat 5, so now the available seats are [5].",
""
],
"constraints": [
"SeatManager(int n) Initializes a SeatManager object that will manage n seats numbered from 1 to n. All seats are initially available. int reserve() Fetches the smallest-numbered unreserved seat",
" reserves it",
" and returns its number. void unreserve(int seatNumber) Unreserves the seat with the given seatNumber. 1 <= n <= 1051 <= seatNumber <= nFor each call to reserve",
" it is guaranteed that there will be at least one unreserved seat. For each call to unreserve",
" it is guaranteed that seatNumber will be reserved. At most 105 calls in total will be made to reserve and unreserve."
]
},
{
"id": "1846",
"title": "Maximum Element After Decreasing and Rearranging",
"question": "You are given an array of positive integers arr.\n Perform some operations (possibly none) on arr so that it satisfies these conditions:There are 2 types of operations that you can perform any number of times:Return the maximum possible value of an element in arr after performing the operations to satisfy the conditions.",
"examples": [
"Input: arr = [2,2,1,2,1]",
"Output: 2",
"Explanation: ",
"We can satisfy the conditions by rearranging arr so it becomes [1,2,2,2,1].",
"The largest element in arr is 2.",
"Input: arr = [100,1,1000]",
"Output: 3",
"Explanation: ",
"One possible way to satisfy the conditions is by doing the following:",
"1. Rearrange arr so it becomes [1,100,1000].",
"2. Decrease the value of the second element to 2.",
"3. Decrease the value of the third element to 3.",
"Now arr = [1,2,3], which satisfies the conditions.",
"The largest element in arr is 3.",
"Input: arr = [1,2,3,4,5]",
"Output: 5",
"Explanation: The array already satisfies the conditions, and the largest element is 5.",
""
],
"constraints": [
"The value of the first element in arr must be 1. 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. Decrease the value of any element of arr to a smaller positive integer. Rearrange the elements of arr to be in any order. 1 <= arr. length <= 1051 <= arr[i] <= 109"
]
},
{
"id": "1849",
"title": "Splitting a String Into Descending Consecutive Values",
"question": "You are given a string s that consists of only digits.\nCheck 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.\nReturn true if it is possible to split s​​​​​​ as described above, or false otherwise.\nA substring is a contiguous sequence of characters in a string.",
"examples": [
"Input: s = \"1234\"",
"Output: false",
"Explanation: There is no valid way to split s.",
"Input: s = \"050043\"",
"Output: true",
"Explanation: s can be split into [\"05\", \"004\", \"3\"] with numerical values [5,4,3].",
"The values are in descending order with adjacent values differing by 1.",
"Input: s = \"9080701\"",
"Output: false",
"Explanation: There is no valid way to split s.",
"Input: s = \"10009998\"",
"Output: true",
"Explanation: s can be split into [\"100\", \"099\", \"98\"] with numerical values [100,99,98].",
"The values are in descending order with adjacent values differing by 1.",
""
],
"constraints": [
"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. 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. 1 <= s. length <= 20s only consists of digits."
]
},
{
"id": "1850",
"title": "Minimum Adjacent Swaps to Reach the Kth Smallest Number",
"question": "You are given a string num, representing a large integer, and an integer k.\nWe call some integer wonderful if it is a permutation of the digits in num and is greater in value than num.\n There can be many wonderful integers.\n However, we only care about the smallest-valued ones.\nReturn the minimum number of adjacent digit swaps that needs to be applied to num to reach the kth smallest wonderful integer.\nThe tests are generated in such a way that kth smallest wonderful integer exists.",
"examples": [
"Input: num = \"5489355142\", k = 4",
"Output: 2",
"Explanation: The 4th smallest wonderful number is \"5489355421\". To get this number:",
"- Swap index 7 with index 8: \"5489355142\" -> \"5489355412\"",
"- Swap index 8 with index 9: \"5489355412\" -> \"5489355421\"",
"Input: num = \"11112\", k = 4",
"Output: 4",
"Explanation: The 4th smallest wonderful number is \"21111\". To get this number:",
"- Swap index 3 with index 4: \"11112\" -> \"11121\"",
"- Swap index 2 with index 3: \"11121\" -> \"11211\"",
"- Swap index 1 with index 2: \"11211\" -> \"12111\"",
"- Swap index 0 with index 1: \"12111\" -> \"21111\"",
"Input: num = \"00123\", k = 1",
"Output: 1",
"Explanation: The 1st smallest wonderful number is \"00132\". To get this number:",
"- Swap index 3 with index 4: \"00123\" -> \"00132\"",
""
],
"constraints": [
"For example",
" when num = \"5489355142\":\n\n\t\nThe 1st smallest wonderful integer is \"5489355214\".\nThe 2nd smallest wonderful integer is \"5489355241\".\nThe 3rd smallest wonderful integer is \"5489355412\".\nThe 4th smallest wonderful integer is \"5489355421\".\n\nThe 1st smallest wonderful integer is \"5489355214\". The 2nd smallest wonderful integer is \"5489355241\". The 3rd smallest wonderful integer is \"5489355412\". The 4th smallest wonderful integer is \"5489355421\". 2 <= num. length <= 10001 <= k <= 1000num only consists of digits."
]
},
{
"id": "1855",
"title": "Maximum Distance Between a Pair of Values",
"question": "You are given two non-increasing 0-indexed integer arrays nums1​​​​​​ and nums2​​​​​​.\nA pair of indices (i, j), where 0 <= i < nums1.\nlength and 0 <= j < nums2.\nlength, is valid if both i <= j and nums1[i] <= nums2[j].\n The distance of the pair is j - i​​​​.\nReturn the maximum distance of any valid pair (i, j).\n If there are no valid pairs, return 0.\nAn array arr is non-increasing if arr[i-1] >= arr[i] for every 1 <= i < arr.\nlength.",
"examples": [
"Input: nums1 = [55,30,5,4,2], nums2 = [100,20,10,10,5]",
"Output: 2",
"Explanation: The valid pairs are (0,0), (2,2), (2,3), (2,4), (3,3), (3,4), and (4,4).",
"The maximum distance is 2 with pair (2,4).",
"Input: nums1 = [2,2,2], nums2 = [10,10,1]",
"Output: 1",
"Explanation: The valid pairs are (0,0), (0,1), and (1,1).",
"The maximum distance is 1 with pair (0,1).",
"Input: nums1 = [30,29,19,5], nums2 = [25,25,25,25,25]",
"Output: 2",
"Explanation: The valid pairs are (2,2), (2,3), (2,4), (3,3), and (3,4).",
"The maximum distance is 2 with pair (2,4).",
"Input: nums1 = [5,4], nums2 = [3,2]",
"Output: 0",
"Explanation: There are no valid pairs, so return 0.",
""
],
"constraints": [
"1 <= nums1. length <= 1051 <= nums2. length <= 1051 <= nums1[i]",
" nums2[j] <= 105Both nums1 and nums2 are non-increasing."
]
},
{
"id": "541",
"title": "Reverse String II",
"question": "Given a string s and an integer k, reverse the first k characters for every 2k characters counting from the start of the string.\nIf there are fewer than k characters left, reverse all of them.\n If there are less than 2k but greater than or equal to k characters, then reverse the first k characters and left the other as original.",
"examples": [
"Input: s = \"abcdefg\", k = 2",
"Output: \"bacdfeg\"",
"Input: s = \"abcd\", k = 2",
"Output: \"bacd\"",
""
],
"constraints": [
"1 <= s. length <= 104s consists of only lowercase English letters. 1 <= k <= 104"
]
},
{
"id": "1856",
"title": "Maximum Subarray Min-Product",
"question": "The min-product of an array is equal to the minimum value in the array multiplied by the array's sum.\nGiven an array of integers nums, return the maximum min-product of any non-empty subarray of nums.\n Since the answer may be large, return it modulo 109 + 7.\nNote that the min-product should be maximized before performing the modulo operation.\n Testcases are generated such that the maximum min-product without modulo will fit in a 64-bit signed integer.\nA subarray is a contiguous part of an array.",
"examples": [
"Input: nums = [1,2,3,2]",
"Output: 14",
"Explanation: The maximum min-product is achieved with the subarray [2,3,2] (minimum value is 2).",
"2 * (2+3+2) = 2 * 7 = 14.",
"Input: nums = [2,3,3,1,2]",
"Output: 18",
"Explanation: The maximum min-product is achieved with the subarray [3,3] (minimum value is 3).",
"3 * (3+3) = 3 * 6 = 18.",
"Input: nums = [3,1,5,6,4,2]",
"Output: 60",
"Explanation: The maximum min-product is achieved with the subarray [5,6,4] (minimum value is 4).",
"4 * (5+6+4) = 4 * 15 = 60.",
""
],
"constraints": [
"For example",
" the array [3",
"2",
"5] (minimum value is 2) has a min-product of 2 * (3+2+5) = 2 * 10 = 20. 1 <= nums. length <= 1051 <= nums[i] <= 107"
]
},
{
"id": "1860",
"title": "Incremental Memory Leak",
"question": "You are given two integers memory1 and memory2 representing the available memory in bits on two memory sticks.\n There is currently a faulty program running that consumes an increasing amount of memory every second.\nAt 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).\n If neither stick has at least i bits of available memory, the program crashes.\nReturn 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.",
"examples": [
"Input: memory1 = 2, memory2 = 2",
"Output: [3,1,0]",
"Explanation: The memory is allocated as follows:",
"- At the 1st second, 1 bit of memory is allocated to stick 1. The first stick now has 1 bit of available memory.",
"- At the 2nd second, 2 bits of memory are allocated to stick 2. The second stick now has 0 bits of available memory.",
"- At the 3rd second, the program crashes. The sticks have 1 and 0 bits available respectively.",
"Input: memory1 = 8, memory2 = 11",
"Output: [6,0,4]",
"Explanation: The memory is allocated as follows:",
"- At the 1st second, 1 bit of memory is allocated to stick 2. The second stick now has 10 bit of available memory.",
"- At the 2nd second, 2 bits of memory are allocated to stick 2. The second stick now has 8 bits of available memory.",
"- At the 3rd second, 3 bits of memory are allocated to stick 1. The first stick now has 5 bits of available memory.",
"- At the 4th second, 4 bits of memory are allocated to stick 2. The second stick now has 4 bits of available memory.",
"- At the 5th second, 5 bits of memory are allocated to stick 1. The first stick now has 0 bits of available memory.",
"- At the 6th second, the program crashes. The sticks have 0 and 4 bits available respectively.",
""
],
"constraints": [
"0 <= memory1",
" memory2 <= 231 - 1"
]
},
{
"id": "1861",
"title": "Rotating the Box",
"question": "You are given an m x n matrix of characters box representing a side-view of a box.\n Each cell of the box is one of the following:The box is rotated 90 degrees clockwise, causing some of the stones to fall due to gravity.\n Each stone falls down until it lands on an obstacle, another stone, or the bottom of the box.\n Gravity does not affect the obstacles' positions, and the inertia from the box's rotation does not affect the stones' horizontal positions.\nIt is guaranteed that each stone in box rests on an obstacle, another stone, or the bottom of the box.\nReturn an n x m matrix representing the box after the rotation described above.",
"examples": [
"Input: box = [[\"#\",\".\",\"#\"]]",
"Output: [[\".\"],",
"  [\"#\"],",
"  [\"#\"]]",
"Input: box = [[\"#\",\".\",\"*\",\".\"],",
"  [\"#\",\"#\",\"*\",\".\"]]",
"Output: [[\"#\",\".\"],",
"  [\"#\",\"#\"],",
"  [\"*\",\"*\"],",
"  [\".\",\".\"]]",
"Input: box = [[\"#\",\"#\",\"*\",\".\",\"*\",\".\"],",
"  [\"#\",\"#\",\"#\",\"*\",\".\",\".\"],",
"  [\"#\",\"#\",\"#\",\".\",\"#\",\".\"]]",
"Output: [[\".\",\"#\",\"#\"],",
"  [\".\",\"#\",\"#\"],",
"  [\"#\",\"#\",\"*\"],",
"  [\"#\",\"*\",\".\"],",
"  [\"#\",\".\",\"*\"],",
"  [\"#\",\".\",\".\"]]",
""
],
"constraints": [
"A stone '#'A stationary obstacle '*'Empty '.'m == box. lengthn == box[i]. length1 <= m",
" n <= 500box[i][j] is either '#'",
" '*'",
" or '.'."
]
},
{
"id": "1864",
"title": "Minimum Number of Swaps to Make the Binary String Alternating",
"question": "Given a binary string s, return the minimum number of character swaps to make it alternating, or -1 if it is impossible.\nThe string is called alternating if no two adjacent characters are equal.\n For example, the strings \"010\" and \"1010\" are alternating, while the string \"0100\" is not.\nAny two characters may be swapped, even if they are not adjacent.",
"examples": [
"Input: s = \"111000\"",
"Output: 1",
"Explanation: Swap positions 1 and 4: \"111000\" -> \"101010\"",
"The string is now alternating.",
"Input: s = \"010\"",
"Output: 0",
"Explanation: The string is already alternating, no swaps are needed.",
"Input: s = \"1110\"",
"Output: -1",
""
],
"constraints": [
"1 <= s. length <= 1000s[i] is either '0' or '1'."
]
},
{
"id": "1865",
"title": "Finding Pairs With a Certain Sum",
"question": "You are given two integer arrays nums1 and nums2.\n You are tasked to implement a data structure that supports queries of two types:Implement the FindSumPairs class:",
"examples": [
"Input",
"[\"FindSumPairs\", \"count\", \"add\", \"count\", \"count\", \"add\", \"add\", \"count\"]",
"[[[1, 1, 2, 2, 2, 3], [1, 4, 5, 2, 5, 4]], [7], [3, 2], [8], [4], [0, 1], [1, 1], [7]]",
"Output",
"[null, 8, null, 2, 1, null, null, 11]",
"",
"Explanation",
"FindSumPairs findSumPairs = new FindSumPairs([1, 1, 2, 2, 2, 3], [1, 4, 5, 2, 5, 4]);",
"findSumPairs. count(7); // return 8; pairs (2,2), (3,2), (4,2), (2,4), (3,4), (4,4) make 2 + 5 and pairs (5,1), (5,5) make 3 + 4",
"findSumPairs. add(3, 2); // now nums2 = [1,4,5,4,5,4]",
"findSumPairs. count(8); // return 2; pairs (5,2), (5,4) make 3 + 5",
"findSumPairs. count(4); // return 1; pair (5,0) makes 3 + 1",
"findSumPairs. add(0, 1); // now nums2 = [2,4,5,4,5,4]",
"findSumPairs. add(1, 1); // now nums2 = [2,5,5,4,5,4]",
"findSumPairs. count(7); // return 11; pairs (2,1), (2,2), (2,4), (3,1), (3,2), (3,4), (4,1), (4,2), (4,4) make 2 + 5 and pairs (5,3), (5,5) make 3 + 4",
""
],
"constraints": [
"FindSumPairs(int[] nums1",
" int[] nums2) Initializes the FindSumPairs object with two integer arrays nums1 and nums2. void add(int index",
" int val) Adds val to nums2[index]",
" i. e.",
" apply nums2[index] += val. int count(int tot) Returns the number of pairs (i",
" j) such that nums1[i] + nums2[j] == tot. 1 <= nums1. length <= 10001 <= nums2. length <= 1051 <= nums1[i] <= 1091 <= nums2[i] <= 1050 <= index < nums2. length1 <= val <= 1051 <= tot <= 109At most 1000 calls are made to add and count each."
]
},
{
"id": "1870",
"title": "Minimum Speed to Arrive on Time",
"question": "You are given a floating-point number hour, representing the amount of time you have to reach the office.\n To commute to the office, you must take n trains in sequential order.\n You are also given an integer array dist of length n, where dist[i] describes the distance (in kilometers) of the ith train ride.\nEach train can only depart at an integer hour, so you may need to wait in between each train ride.\nReturn 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.\nTests are generated such that the answer will not exceed 107 and hour will have at most two digits after the decimal point.",
"examples": [
"Input: dist = [1,3,2], hour = 6",
"Output: 1",
"Explanation: At speed 1:",
"- The first train ride takes 1/1 = 1 hour.",
"- Since we are already at an integer hour, we depart immediately at the 1 hour mark. The second train takes 3/1 = 3 hours.",
"- Since we are already at an integer hour, we depart immediately at the 4 hour mark. The third train takes 2/1 = 2 hours.",
"- You will arrive at exactly the 6 hour mark.",
"Input: dist = [1,3,2], hour = 2. 7",
"Output: 3",
"Explanation: At speed 3:",
"- The first train ride takes 1/3 = 0. 33333 hours.",
"- Since we are not at an integer hour, we wait until the 1 hour mark to depart. The second train ride takes 3/3 = 1 hour.",
"- Since we are already at an integer hour, we depart immediately at the 2 hour mark. The third train takes 2/3 = 0. 66667 hours.",
"- You will arrive at the 2. 66667 hour mark.",
"Input: dist = [1,3,2], hour = 1. 9",
"Output: -1",
"Explanation: It is impossible because the earliest the third train can depart is at the 2 hour mark.",
""
],
"constraints": [
"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 == dist. length1 <= n <= 1051 <= dist[i] <= 1051 <= hour <= 109There will be at most two digits after the decimal point in hour."
]
},
{
"id": "1871",
"title": "Jump Game VII",
"question": "You are given a 0-indexed binary string s and two integers minJump and maxJump.\n In the beginning, you are standing at index 0, which is equal to '0'.\n You can move from index i to index j if the following conditions are fulfilled:Return true if you can reach index s.\nlength - 1 in s, or false otherwise.",
"examples": [
"Input: s = \"011010\", minJump = 2, maxJump = 3",
"Output: true",
"Explanation:",
"In the first step, move from index 0 to index 3. ",
"In the second step, move from index 3 to index 5.",
"Input: s = \"01101110\", minJump = 2, maxJump = 3",
"Output: false",
""
],
"constraints": [
"i + minJump <= j <= min(i + maxJump",
" s. length - 1)",
" ands[j] == '0'. 2 <= s. length <= 105s[i] is either '0' or '1'. s[0] == '0'1 <= minJump <= maxJump < s. length"
]
},
{
"id": "1877",
"title": "Minimize Maximum Pair Sum in Array",
"question": "The pair sum of a pair (a,b) is equal to a + b.\n The maximum pair sum is the largest pair sum in a list of pairs.\nGiven an array nums of even length n, pair up the elements of nums into n / 2 pairs such that:Return the minimized maximum pair sum after optimally pairing up the elements.",
"examples": [
"Input: nums = [3,5,2,3]",
"Output: 7",
"Explanation: The elements can be paired up into pairs (3,3) and (5,2).",
"The maximum pair sum is max(3+3, 5+2) = max(6, 7) = 7.",
"Input: nums = [3,5,4,2,4,6]",
"Output: 8",
"Explanation: The elements can be paired up into pairs (3,5), (4,4), and (6,2).",
"The maximum pair sum is max(3+5, 4+4, 6+2) = max(8, 8, 8) = 8.",
""
],
"constraints": [
"For example",
" if we have pairs (1",
"5)",
" (2",
"3)",
" and (4",
"4)",
" the maximum pair sum would be max(1+5",
" 2+3",
" 4+4) = max(6",
" 5",
" 8) = 8. Each element of nums is in exactly one pair",
" andThe maximum pair sum is minimized. n == nums. length2 <= n <= 105n is even. 1 <= nums[i] <= 105"
]
},
{
"id": "1878",
"title": "Get Biggest Three Rhombus Sums in a Grid",
"question": "You are given an m x n integer matrix grid​​​.\nA rhombus sum is the sum of the elements that form the border of a regular rhombus shape in grid​​​.\n The rhombus must have the shape of a square rotated 45 degrees with each of the corners centered in a grid cell.\n Below is an image of four valid rhombus shapes with the corresponding colored cells that should be included in each rhombus sum:Note that the rhombus can have an area of 0, which is depicted by the purple rhombus in the bottom right corner.\nReturn the biggest three distinct rhombus sums in the grid in descending order.\n If there are less than three distinct values, return all of them.",
"examples": [
"Input: 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]]",
"Output: [228,216,211]",
"Explanation: The rhombus shapes for the three biggest distinct rhombus sums are depicted above.",
"- Blue: 20 + 3 + 200 + 5 = 228",
"- Red: 200 + 2 + 10 + 4 = 216",
"- Green: 5 + 200 + 4 + 2 = 211",
"Input: grid = [[1,2,3],[4,5,6],[7,8,9]]",
"Output: [20,9,8]",
"Explanation: The rhombus shapes for the three biggest distinct rhombus sums are depicted above.",
"- Blue: 4 + 2 + 6 + 8 = 20",
"- Red: 9 (area 0 rhombus in the bottom right corner)",
"- Green: 8 (area 0 rhombus in the bottom middle)",
"Input: grid = [[7,7,7]]",
"Output: [7]",
"Explanation: All three possible rhombus sums are the same, so return [7].",
""
],
"constraints": [
"m == grid. lengthn == grid[i]. length1 <= m",
" n <= 501 <= grid[i][j] <= 105"
]
},
{
"id": "1881",
"title": "Maximum Value after Insertion",
"question": "You are given a very large integer n, represented as a string,​​​​​​ and an integer digit x.\n The digits in n and the digit x are in the inclusive range [1, 9], and n may represent a negative number.\nYou want to maximize n's numerical value by inserting x anywhere in the decimal representation of n​​​​​​.\n You cannot insert x to the left of the negative sign.\nReturn a string representing the maximum value of n​​​​​​ after the insertion.",
"examples": [
"Input: n = \"99\", x = 9",
"Output: \"999\"",
"Explanation: The result is the same regardless of where you insert 9.",
"Input: n = \"-13\", x = 2",
"Output: \"-123\"",
"Explanation: You can make n one of {-213, -123, -132}, and the largest of those three is -123.",
""
],
"constraints": [
"For example",
" if n = 73 and x = 6",
" it would be best to insert it between 7 and 3",
" making n = 763. If n = -55 and x = 2",
" it would be best to insert it before the first 5",
" making n = -255. 1 <= n. length <= 1051 <= x <= 9The digits in n​​​ are in the range [1",
" 9]. n is a valid representation of an integer. In the case of a negative n",
"​​​​​​ it will begin with '-'."
]
},
{
"id": "543",
"title": "Diameter of Binary Tree",
"question": "Given the root of a binary tree, return the length of the diameter of the tree.\nThe diameter of a binary tree is the length of the longest path between any two nodes in a tree.\n This path may or may not pass through the root.\nThe length of a path between two nodes is represented by the number of edges between them.",
"examples": [
"Input: root = [1,2,3,4,5]",
"Output: 3",
"Explanation: 3 is the length of the path [4,2,1,3] or [5,2,1,3].",
"Input: root = [1,2]",
"Output: 1",
""
],
"constraints": [
"The number of nodes in the tree is in the range [1",
" 104].-100 <= Node. val <= 100"
]
},
{
"id": "1882",
"title": "Process Tasks Using Servers",
"question": "You are given two 0-indexed integer arrays servers and tasks of lengths n​​​​​​ and m​​​​​​ respectively.\n servers[i] is the weight of the i​​​​​​th​​​​ server, and tasks[j] is the time needed to process the j​​​​​​th​​​​ task in seconds.\nTasks are assigned to the servers using a task queue.\n Initially, all servers are free, and the queue is empty.\nAt second j, the jth task is inserted into the queue (starting with the 0th task being inserted at second 0).\n 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.\nIf there are no free servers and the queue is not empty, we wait until a server becomes free and immediately assign the next task.\n 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.\nA server that is assigned task j at second t will be free again at second t + tasks[j].\nBuild an array ans​​​​ of length m, where ans[j] is the index of the server the j​​​​​​th task will be assigned to.\nReturn the array ans​​​​.",
"examples": [
"Input: servers = [3,3,2], tasks = [1,2,3,2,1,2]",
"Output: [2,2,0,2,1,2]",
"Explanation: Events in chronological order go as follows:",
"- At second 0, task 0 is added and processed using server 2 until second 1.",
"- At second 1, server 2 becomes free. Task 1 is added and processed using server 2 until second 3.",
"- At second 2, task 2 is added and processed using server 0 until second 5.",
"- At second 3, server 2 becomes free. Task 3 is added and processed using server 2 until second 5.",
"- At second 4, task 4 is added and processed using server 1 until second 5.",
"- At second 5, all servers become free. Task 5 is added and processed using server 2 until second 7. Input: servers = [5,1,4,3,2], tasks = [2,1,2,4,5,2,1]",
"Output: [1,4,1,4,1,3,2]",
"Explanation: Events in chronological order go as follows: ",
"- At second 0, task 0 is added and processed using server 1 until second 2.",
"- At second 1, task 1 is added and processed using server 4 until second 2.",
"- At second 2, servers 1 and 4 become free. Task 2 is added and processed using server 1 until second 4. ",
"- At second 3, task 3 is added and processed using server 4 until second 7.",
"- At second 4, server 1 becomes free. Task 4 is added and processed using server 1 until second 9. ",
"- At second 5, task 5 is added and processed using server 3 until second 7.",
"- At second 6, task 6 is added and processed using server 2 until second 7.",
""
],
"constraints": [
"servers. length == ntasks. length == m1 <= n",
" m <= 2 * 1051 <= servers[i]",
" tasks[j] <= 2 * 105"
]
},
{
"id": "1884",
"title": "Egg Drop With 2 Eggs and N Floors",
"question": "You are given two identical eggs and you have access to a building with n floors labeled from 1 to n.\nYou 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.\nIn each move, you may take an unbroken egg and drop it from any floor x (where 1 <= x <= n).\n If the egg breaks, you can no longer use it.\n However, if the egg does not break, you may reuse it in future moves.\nReturn the minimum number of moves that you need to determine with certainty what the value of f is.",
"examples": [
"Input: n = 2",
"Output: 2",
"Explanation: We can drop the first egg from floor 1 and the second egg from floor 2.",
"If the first egg breaks, we know that f = 0.",
"If the second egg breaks but the first egg didn't, we know that f = 1.",
"Otherwise, if both eggs survive, we know that f = 2.",
"Input: n = 100",
"Output: 14",
"Explanation: One optimal strategy is:",
"- 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 7 more drops. Total drops is 1 + 7 = 8.",
"- 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.",
"- 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.",
"Regardless of the outcome, it takes at most 14 drops to determine f.",
""
],
"constraints": [
"1 <= n <= 1000"
]
},
{
"id": "1887",
"title": "Reduction Operations to Make the Array Elements Equal",
"question": "Given an integer array nums, your goal is to make all elements in nums equal.\n To complete one operation, follow these steps:Return the number of operations to make all elements in nums equal.",
"examples": [
"Input: nums = [5,1,3]",
"Output: 3",
"Explanation: It takes 3 operations to make all elements in nums equal:",
"1. largest = 5 at index 0. nextLargest = 3. Reduce nums[0] to 3. nums = [3,1,3].",
"2. largest = 3 at index 0. nextLargest = 1. Reduce nums[0] to 1. nums = [1,1,3].",
"3. largest = 3 at index 2. nextLargest = 1. Reduce nums[2] to 1. nums = [1,1,1].",
"Input: nums = [1,1,1]",
"Output: 0",
"Explanation: All elements in nums are already equal.",
"Input: nums = [1,1,2,2,3]",
"Output: 4",
"Explanation: It takes 4 operations to make all elements in nums equal:",
"1. largest = 3 at index 4. nextLargest = 2. Reduce nums[4] to 2. nums = [1,1,2,2,2].",
"2. largest = 2 at index 2. nextLargest = 1. Reduce nums[2] to 1. nums = [1,1,1,2,2].",
"3. largest = 2 at index 3. nextLargest = 1. Reduce nums[3] to 1. nums = [1,1,1,1,2].",
"4. largest = 2 at index 4. nextLargest = 1. Reduce nums[4] to 1. nums = [1,1,1,1,1].",
""
],
"constraints": [
"1 <= nums. length <= 5 * 1041 <= nums[i] <= 5 * 104"
]
},
{
"id": "1888",
"title": "Minimum Number of Flips to Make the Binary String Alternating",
"question": "You are given a binary string s.\n You are allowed to perform two types of operations on the string in any sequence:Return the minimum number of type-2 operations you need to perform such that s becomes alternating.\nThe string is called alternating if no two adjacent characters are equal.",
"examples": [
"Input: s = \"111000\"",
"Output: 2",
"Explanation: Use the first operation two times to make s = \"100011\".",
"Then, use the second operation on the third and sixth elements to make s = \"101010\".",
"Input: s = \"010\"",
"Output: 0",
"Explanation: The string is already alternating.",
"Input: s = \"1110\"",
"Output: 1",
"Explanation: Use the second operation on the second element to make s = \"1010\".",
""
],
"constraints": [
"Type-1: Remove the character at the start of the string s and append it to the end of the string. Type-2: Pick any character in s and flip its value",
" i. e.",
" if its value is '0' it becomes '1' and vice-versa. For example",
" the strings \"010\" and \"1010\" are alternating",
" while the string \"0100\" is not. 1 <= s. length <= 105s[i] is either '0' or '1'."
]
},
{
"id": "1894",
"title": "Find the Student that Will Replace the Chalk",
"question": "There are n students in a class numbered from 0 to n - 1.\n 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.\n After that, the teacher will restart the process, starting with the student number 0 again.\nYou are given a 0-indexed integer array chalk and an integer k.\n There are initially k pieces of chalk.\n When the student number i is given a problem to solve, they will use chalk[i] pieces of chalk to solve that problem.\n 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.\nReturn the index of the student that will replace the chalk.",
"examples": [
"Input: chalk = [5,1,5], k = 22",
"Output: 0",
"Explanation: The students go in turns as follows:",
"- Student number 0 uses 5 chalk, so k = 17.",
"- Student number 1 uses 1 chalk, so k = 16.",
"- Student number 2 uses 5 chalk, so k = 11.",
"- Student number 0 uses 5 chalk, so k = 6.",
"- Student number 1 uses 1 chalk, so k = 5.",
"- Student number 2 uses 5 chalk, so k = 0.",
"Student number 0 does not have enough chalk, so they will have to replace it. Input: chalk = [3,4,1,2], k = 25",
"Output: 1",
"Explanation: The students go in turns as follows:",
"- Student number 0 uses 3 chalk so k = 22.",
"- Student number 1 uses 4 chalk so k = 18.",
"- Student number 2 uses 1 chalk so k = 17.",
"- Student number 3 uses 2 chalk so k = 15.",
"- Student number 0 uses 3 chalk so k = 12.",
"- Student number 1 uses 4 chalk so k = 8.",
"- Student number 2 uses 1 chalk so k = 7.",
"- Student number 3 uses 2 chalk so k = 5.",
"- Student number 0 uses 3 chalk so k = 2.",
"Student number 1 does not have enough chalk, so they will have to replace it.",
""
],
"constraints": [
"chalk. length == n1 <= n <= 1051 <= chalk[i] <= 1051 <= k <= 109"
]
},
{
"id": "1895",
"title": "Largest Magic Square",
"question": "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.\n The integers in the magic square do not have to be distinct.\n Every 1 x 1 grid is trivially a magic square.\nGiven an m x n integer grid, return the size (i.\ne.\n, the side length k) of the largest magic square that can be found within this grid.",
"examples": [
"Input: grid = [[7,1,4,5,6],[2,5,1,6,4],[1,5,4,3,2],[1,2,7,3,4]]",
"Output: 3",
"Explanation: The largest magic square has a size of 3.",
"Every row sum, column sum, and diagonal sum of this magic square is equal to 12.",
"- Row sums: 5+1+6 = 5+4+3 = 2+7+3 = 12",
"- Column sums: 5+5+2 = 1+4+7 = 6+3+3 = 12",
"- Diagonal sums: 5+4+3 = 6+4+2 = 12",
"Input: grid = [[5,1,3,1],[9,3,3,1],[1,3,3,8]]",
"Output: 2",
""
],
"constraints": [
"m == grid. lengthn == grid[i]. length1 <= m",
" n <= 501 <= grid[i][j] <= 106"
]
},
{
"id": "1898",
"title": "Maximum Number of Removable Characters",
"question": "You are given two strings s and p where p is a subsequence of s.\n You are also given a distinct 0-indexed integer array removable containing a subset of indices of s (s is also 0-indexed).\nYou want to choose an integer k (0 <= k <= removable.\nlength) such that, after removing k characters from s using the first k indices in removable, p is still a subsequence of s.\n 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.\nReturn the maximum k you can choose such that p is still a subsequence of s after the removals.\nA 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.",
"examples": [
"Input: s = \"abcacb\", p = \"ab\", removable = [3,1,0]",
"Output: 2",
"Explanation: After removing the characters at indices 3 and 1, \"abcacb\" becomes \"accb\".",
"\"ab\" is a subsequence of \"accb\".",
"If we remove the characters at indices 3, 1, and 0, \"abcacb\" becomes \"ccb\", and \"ab\" is no longer a subsequence.",
"Hence, the maximum k is 2.",
"Input: s = \"abcbddddd\", p = \"abcd\", removable = [3,2,1,4,5,6]",
"Output: 1",
"Explanation: After removing the character at index 3, \"abcbddddd\" becomes \"abcddddd\".",
"\"abcd\" is a subsequence of \"abcddddd\".",
"Input: s = \"abcab\", p = \"abc\", removable = [0,1,2,3,4]",
"Output: 0",
"Explanation: If you remove the first index in the array removable, \"abc\" is no longer a subsequence.",
""
],
"constraints": [
"1 <= p. length <= s. length <= 1050 <= removable. length < s. length0 <= removable[i] < s. lengthp is a subsequence of s. s and p both consist of lowercase English letters. The elements in removable are distinct."
]
},
{
"id": "1899",
"title": "Merge Triplets to Form Target Triplet",
"question": "A triplet is an array of three integers.\n You are given a 2D integer array triplets, where triplets[i] = [ai, bi, ci] describes the ith triplet.\n You are also given an integer array target = [x, y, z] that describes the triplet you want to obtain.\nTo obtain target, you may apply the following operation on triplets any number of times (possibly zero):Return true if it is possible to obtain the target triplet [x, y, z] as an element of triplets, or false otherwise.",
"examples": [
"Input: triplets = [[2,5,3],[1,8,4],[1,7,5]], target = [2,7,5]",
"Output: true",
"Explanation: Perform the following operations:",
"- Choose the first and last triplets [[2,5,3],[1,8,4],[1,7,5]]. Update the last triplet to be [max(2,1), max(5,7), max(3,5)] = [2,7,5]. triplets = [[2,5,3],[1,8,4],[2,7,5]]",
"The target triplet [2,7,5] is now an element of triplets.",
"Input: triplets = [[1,3,4],[2,5,8]], target = [2,5,8]",
"Output: true",
"Explanation: The target triplet [2,5,8] is already an element of triplets.",
"Input: triplets = [[2,5,3],[2,3,4],[1,2,5],[5,2,3]], target = [5,5,5]",
"Output: true",
"Explanation: Perform the following operations:",
"- Choose the first and third triplets [[2,5,3],[2,3,4],[1,2,5],[5,2,3]]. Update the third triplet to be [max(2,1), max(5,2), max(3,5)] = [2,5,5]. triplets = [[2,5,3],[2,3,4],[2,5,5],[5,2,3]].",
"- Choose the third and fourth triplets [[2,5,3],[2,3,4],[2,5,5],[5,2,3]]. Update the fourth triplet to be [max(2,5), max(5,2), max(5,3)] = [5,5,5]. triplets = [[2,5,3],[2,3,4],[2,5,5],[5,5,5]].",
"The target triplet [5,5,5] is now an element of triplets.",
"Input: triplets = [[3,4,5],[4,5,6]], target = [3,2,5]",
"Output: false",
"Explanation: It is impossible to have [3,2,5] as an element because there is no 2 in any of the triplets.",
""
],
"constraints": [
"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\t\nFor 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\nFor 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]. 1 <= triplets. length <= 105triplets[i]. length == target. length == 31 <= ai",
" bi",
" ci",
" x",
" y",
" z <= 1000"
]
},
{
"id": "1901",
"title": "Find a Peak Element II",
"question": "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.\nGiven 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].\nYou may assume that the entire matrix is surrounded by an outer perimeter with the value -1 in each cell.\nYou must write an algorithm that runs in O(m log(n)) or O(n log(m)) time.",
"examples": [
"Input: mat = [[1,4],[3,2]]",
"Output: [0,1]",
"Explanation: Both 3 and 4 are peak elements so [1,0] and [0,1] are both acceptable answers.",
"Input: mat = [[10,20,15],[21,30,14],[7,16,32]]",
"Output: [1,1]",
"Explanation: Both 30 and 32 are peak elements so [1,1] and [2,2] are both acceptable answers.",
""
],
"constraints": [
"m == mat. lengthn == mat[i]. length1 <= m",
" n <= 5001 <= mat[i][j] <= 105No two adjacent cells are equal."
]
},
{
"id": "1904",
"title": "The Number of Full Rounds You Have Played",
"question": "A new online video game has been released, and in this video game, there are 15-minute rounds scheduled every quarter-hour period.\n This means that at HH:00, HH:15, HH:30 and HH:45, a new round starts, where HH represents an integer number from 00 to 23.\n A 24-hour clock is used, so the earliest time in the day is 00:00 and the latest is 23:59.\nGiven two strings startTime and finishTime in the format \"HH:MM\" representing the exact time you started and finished playing the game, respectively, calculate the number of full rounds that you played during your game session.\nIf finishTime is earlier than startTime, this means you have played overnight (from startTime to the midnight and from midnight to finishTime).\nReturn the number of full rounds that you have played if you had started playing at startTime and finished at finishTime.",
"examples": [
"Input: startTime = \"12:01\", finishTime = \"12:44\"",
"Output: 1",
"Explanation: You played one full round from 12:15 to 12:30.",
"You did not play the full round from 12:00 to 12:15 because you started playing at 12:01 after it began.",
"You did not play the full round from 12:30 to 12:45 because you stopped playing at 12:44 before it ended.",
"Input: startTime = \"20:00\", finishTime = \"06:00\"",
"Output: 40",
"Explanation: You played 16 full rounds from 20:00 to 00:00 and 24 full rounds from 00:00 to 06:00.",
"16 + 24 = 40.",
"Input: startTime = \"00:00\", finishTime = \"23:59\"",
"Output: 95",
"Explanation: You played 4 full rounds each hour except for the last hour where you played 3 full rounds.",
""
],
"constraints": [
"For example",
" if startTime = \"05:20\" and finishTime = \"05:59\" this means you played only one full round from 05:30 to 05:45. You did not play the full round from 05:15 to 05:30 because you started after the round began",
" and you did not play the full round from 05:45 to 06:00 because you stopped before the round ended. startTime and finishTime are in the format HH:MM. 00 <= HH <= 2300 <= MM <= 59startTime and finishTime are not equal."
]
},
{
"id": "551",
"title": "Student Attendance Record I",
"question": "You are given a string s representing an attendance record for a student where each character signifies whether the student was absent, late, or present on that day.\n The record only contains the following three characters:The student is eligible for an attendance award if they meet both of the following criteria:Return true if the student is eligible for an attendance award, or false otherwise.",
"examples": [
"Input: s = \"PPALLP\"",
"Output: true",
"Explanation: The student has fewer than 2 absences and was never late 3 or more consecutive days.",
"Input: s = \"PPALLL\"",
"Output: false",
"Explanation: The student was late 3 consecutive days in the last 3 days, so is not eligible for the award.",
""
],
"constraints": [
"'A': Absent.'L': Late.'P': Present. The student was absent ('A') for strictly fewer than 2 days total. The student was never late ('L') for 3 or more consecutive days. 1 <= s. length <= 1000s[i] is either 'A'",
" 'L'",
" or 'P'."
]
},
{
"id": "1905",
"title": "Count Sub Islands",
"question": "You are given two m x n binary matrices grid1 and grid2 containing only 0's (representing water) and 1's (representing land).\n An island is a group of 1's connected 4-directionally (horizontal or vertical).\n Any cells outside of the grid are considered water cells.\nAn 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.\nReturn the number of islands in grid2 that are considered sub-islands.",
"examples": [
"Input: 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]]",
"Output: 3",
"Explanation: In the picture above, the grid on the left is grid1 and the grid on the right is grid2.",
"The 1s colored red in grid2 are those considered to be part of a sub-island. There are three sub-islands.",
"Input: 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]]",
"Output: 2 ",
"Explanation: In the picture above, the grid on the left is grid1 and the grid on the right is grid2.",
"The 1s colored red in grid2 are those considered to be part of a sub-island. There are two sub-islands.",
""
],
"constraints": [
"m == grid1. length == grid2. lengthn == grid1[i]. length == grid2[i]. length1 <= m",
" n <= 500grid1[i][j] and grid2[i][j] are either 0 or 1."
]
},
{
"id": "1906",
"title": "Minimum Absolute Difference Queries",
"question": "The minimum absolute difference of an array a is defined as the minimum value of |a[i] - a[j]|, where 0 <= i < j < a.\nlength and a[i] != a[j].\n If all elements of a are the same, the minimum absolute difference is -1.\nYou are given an integer array nums and the array queries where queries[i] = [li, ri].\n For each query i, compute the minimum absolute difference of the subarray nums[li.\n.\n.\nri] containing the elements of nums between the 0-based indices li and ri (inclusive).\nReturn an array ans where ans[i] is the answer to the ith query.\nA subarray is a contiguous sequence of elements in an array.\nThe value of |x| is defined as:",
"examples": [
"Input: nums = [1,3,4,8], queries = [[0,1],[1,2],[2,3],[0,3]]",
"Output: [2,1,4,1]",
"Explanation: The queries are processed as follows:",
"- queries[0] = [0,1]: The subarray is [1,3] and the minimum absolute difference is |1-3| = 2.",
"- queries[1] = [1,2]: The subarray is [3,4] and the minimum absolute difference is |3-4| = 1.",
"- queries[2] = [2,3]: The subarray is [4,8] and the minimum absolute difference is |4-8| = 4.",
"- queries[3] = [0,3]: The subarray is [1,3,4,8] and the minimum absolute difference is |3-4| = 1.",
"Input: nums = [4,5,2,2,7,10], queries = [[2,3],[0,2],[0,5],[3,5]]",
"Output: [-1,1,1,3]",
"Explanation: The queries are processed as follows:",
"- queries[0] = [2,3]: The subarray is [2,2] and the minimum absolute difference is -1 because all the",
" elements are the same.",
"- queries[1] = [0,2]: The subarray is [4,5,2] and the minimum absolute difference is |4-5| = 1.",
"- queries[2] = [0,5]: The subarray is [4,5,2,2,7,10] and the minimum absolute difference is |4-5| = 1.",
"- queries[3] = [3,5]: The subarray is [2,7,10] and the minimum absolute difference is |7-10| = 3.",
""
],
"constraints": [
"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. x if x >= 0.-x if x < 0. 2 <= nums. length <= 1051 <= nums[i] <= 1001 <= queries. length <= 2 * 1040 <= li < ri < nums. length"
]
},
{
"id": "1910",
"title": "Remove All Occurrences of a Substring",
"question": "Given two strings s and part, perform the following operation on s until all occurrences of the substring part are removed:Return s after removing all occurrences of part.\nA substring is a contiguous sequence of characters in a string.",
"examples": [
"Input: s = \"daabcbaabcbc\", part = \"abc\"",
"Output: \"dab\"",
"Explanation: The following operations are done:",
"- s = \"daabcbaabcbc\", remove \"abc\" starting at index 2, so s = \"dabaabcbc\".",
"- s = \"dabaabcbc\", remove \"abc\" starting at index 4, so s = \"dababc\".",
"- s = \"dababc\", remove \"abc\" starting at index 3, so s = \"dab\".",
"Now s has no occurrences of \"abc\".",
"Input: s = \"axxxxyyyyb\", part = \"xy\"",
"Output: \"ab\"",
"Explanation: The following operations are done:",
"- s = \"axxxxyyyyb\", remove \"xy\" starting at index 4 so s = \"axxxyyyb\".",
"- s = \"axxxyyyb\", remove \"xy\" starting at index 3 so s = \"axxyyb\".",
"- s = \"axxyyb\", remove \"xy\" starting at index 2 so s = \"axyb\".",
"- s = \"axyb\", remove \"xy\" starting at index 1 so s = \"ab\".",
"Now s has no occurrences of \"xy\".",
""
],
"constraints": [
"Find the leftmost occurrence of the substring part and remove it from s. 1 <= s. length <= 10001 <= part. length <= 1000s​​​​​​ and part consists of lowercase English letters."
]
},
{
"id": "1911",
"title": "Maximum Alternating Subsequence Sum",
"question": "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.\nGiven an array nums, return the maximum alternating sum of any subsequence of nums (after reindexing the elements of the subsequence).\nA 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 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.",
"examples": [
"Input: nums = [4,2,5,3]",
"Output: 7",
"Explanation: It is optimal to choose the subsequence [4,2,5] with alternating sum (4 + 5) - 2 = 7.",
"Input: nums = [5,6,7,8]",
"Output: 8",
"Explanation: It is optimal to choose the subsequence [8] with alternating sum 8.",
"Input: nums = [6,2,1,2,4,5]",
"Output: 10",
"Explanation: It is optimal to choose the subsequence [6,1,5] with alternating sum (6 + 5) - 1 = 10.",
""
],
"constraints": [
"For example",
" the alternating sum of [4",
"2",
"5",
"3] is (4 + 5) - (2 + 3) = 4. 1 <= nums. length <= 1051 <= nums[i] <= 105"
]
},
{
"id": "1914",
"title": "Cyclically Rotating a Grid",
"question": "You are given an m x n integer matrix grid​​​, where m and n are both even integers, and an integer k.\nThe matrix is composed of several layers, which is shown in the below image, where each color is its own layer:A cyclic rotation of the matrix is done by cyclically rotating each layer in the matrix.\n To cyclically rotate a layer once, each element in the layer will take the place of the adjacent element in the counter-clockwise direction.\n An example rotation is shown below:Return the matrix after applying k cyclic rotations to it.",
"examples": [
"Input: grid = [[40,10],[30,20]], k = 1",
"Output: [[10,20],[40,30]]",
"Explanation: The figures above represent the grid at every state.",
"Input: grid = [[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]], k = 2",
"Output: [[3,4,8,12],[2,11,10,16],[1,7,6,15],[5,9,13,14]]",
"Explanation: The figures above represent the grid at every state.",
""
],
"constraints": [
"m == grid. lengthn == grid[i]. length2 <= m",
" n <= 50Both m and n are even integers. 1 <= grid[i][j] <= 50001 <= k <= 109"
]
},
{
"id": "1915",
"title": "Number of Wonderful Substrings",
"question": "A wonderful string is a string where at most one letter appears an odd number of times.\nGiven 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.\n If the same substring appears multiple times in word, then count each occurrence separately.\nA substring is a contiguous sequence of characters in a string.",
"examples": [
"Input: word = \"aba\"",
"Output: 4",
"Explanation: The four wonderful substrings are underlined below:",
"- \"aba\" -> \"a\"",
"- \"aba\" -> \"b\"",
"- \"aba\" -> \"a\"",
"- \"aba\" -> \"aba\"",
"Input: word = \"aabb\"",
"Output: 9",
"Explanation: The nine wonderful substrings are underlined below:",
"- \"aabb\" -> \"a\"",
"- \"aabb\" -> \"aa\"",
"- \"aabb\" -> \"aab\"",
"- \"aabb\" -> \"aabb\"",
"- \"aabb\" -> \"a\"",
"- \"aabb\" -> \"abb\"",
"- \"aabb\" -> \"b\"",
"- \"aabb\" -> \"bb\"",
"- \"aabb\" -> \"b\"",
"Input: word = \"he\"",
"Output: 2",
"Explanation: The two wonderful substrings are underlined below:",
"- \"he\" -> \"h\"",
"- \"he\" -> \"e\"",
""
],
"constraints": [
"For example",
" \"ccjjc\" and \"abab\" are wonderful",
" but \"ab\" is not. 1 <= word. length <= 105word consists of lowercase English letters from 'a' to 'j'."
]
},
{
"id": "1921",
"title": "Eliminate Maximum Number of Monsters",
"question": "You are playing a video game where you are defending your city from a group of n monsters.\n 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.\nThe monsters walk toward the city at a constant speed.\n 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.\nYou have a weapon that, once fully charged, can eliminate a single monster.\n However, the weapon takes one minute to charge.\nThe weapon is fully charged at the very start.\nYou lose when any monster reaches your city.\n 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.\nReturn 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.",
"examples": [
"Input: dist = [1,3,4], speed = [1,1,1]",
"Output: 3",
"Explanation:",
"In the beginning, the distances of the monsters are [1,3,4]. You eliminate the first monster.",
"After a minute, the distances of the monsters are [X,2,3]. You eliminate the second monster.",
"After a minute, the distances of the monsters are [X,X,2]. You eliminate the thrid monster.",
"All 3 monsters can be eliminated. Input: dist = [1,1,2,3], speed = [1,1,1,1]",
"Output: 1",
"Explanation:",
"In the beginning, the distances of the monsters are [1,1,2,3]. You eliminate the first monster.",
"After a minute, the distances of the monsters are [X,0,1,2], so you lose.",
"You can only eliminate 1 monster.",
"Input: dist = [3,2,4], speed = [5,3,2]",
"Output: 1",
"Explanation:",
"In the beginning, the distances of the monsters are [3,2,4]. You eliminate the first monster.",
"After a minute, the distances of the monsters are [X,0,2], so you lose.",
"You can only eliminate 1 monster.",
""
],
"constraints": [
"n == dist. length == speed. length1 <= n <= 1051 <= dist[i]",
" speed[i] <= 105"
]
},
{
"id": "1922",
"title": "Count Good Numbers",
"question": "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).\nGiven an integer n, return the total number of good digit strings of length n.\n Since the answer may be large, return it modulo 109 + 7.\nA digit string is a string consisting of digits 0 through 9 that may contain leading zeros.",
"examples": [
"Input: n = 1",
"Output: 5",
"Explanation: The good numbers of length 1 are \"0\", \"2\", \"4\", \"6\", \"8\".",
"Input: n = 4",
"Output: 400",
"Input: n = 50",
"Output: 564908303",
""
],
"constraints": [
"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. 1 <= n <= 1015"
]
},
{
"id": "1926",
"title": "Nearest Exit from Entrance in Maze",
"question": "You are given an m x n matrix maze (0-indexed) with empty cells (represented as '.\n') and walls (represented as '+').\n 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.\nIn one step, you can move one cell up, down, left, or right.\n You cannot step into a cell with a wall, and you cannot step outside the maze.\n Your goal is to find the nearest exit from the entrance.\n An exit is defined as an empty cell that is at the border of the maze.\n The entrance does not count as an exit.\nReturn the number of steps in the shortest path from the entrance to the nearest exit, or -1 if no such path exists.",
"examples": [
"Input: maze = [[\"+\",\"+\",\".\",\"+\"],[\".\",\".\",\".\",\"+\"],[\"+\",\"+\",\"+\",\".\"]], entrance = [1,2]",
"Output: 1",
"Explanation: There are 3 exits in this maze at [1,0], [0,2], and [2,3].",
"Initially, you are at the entrance cell [1,2].",
"- You can reach [1,0] by moving 2 steps left.",
"- You can reach [0,2] by moving 1 step up.",
"It is impossible to reach [2,3] from the entrance.",
"Thus, the nearest exit is [0,2], which is 1 step away.",
"Input: maze = [[\"+\",\"+\",\"+\"],[\".\",\".\",\".\"],[\"+\",\"+\",\"+\"]], entrance = [1,0]",
"Output: 2",
"Explanation: There is 1 exit in this maze at [1,2].",
"[1,0] does not count as an exit since it is the entrance cell.",
"Initially, you are at the entrance cell [1,0].",
"- You can reach [1,2] by moving 2 steps right.",
"Thus, the nearest exit is [1,2], which is 2 steps away.",
"Input: maze = [[\".\",\"+\"]], entrance = [0,0]",
"Output: -1",
"Explanation: There are no exits in this maze.",
""
],
"constraints": [
"maze. length == mmaze[i]. length == n1 <= m",
" n <= 100maze[i][j] is either '.' or '+'. entrance. length == 20 <= entrancerow < m0 <= entrancecol < nentrance will always be an empty cell."
]
},
{
"id": "1927",
"title": "Sum Game",
"question": "Alice and Bob take turns playing a game, with Alice starting first.\nYou are given a string num of even length consisting of digits and '?' characters.\n On each turn, a player will do the following if there is still at least one '?' in num:The game ends when there are no more '?' characters in num.\nFor Bob to 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.\n For Alice to win, the sums must not be equal.\nAssuming Alice and Bob play optimally, return true if Alice will win and false if Bob will win.",
"examples": [
"Input: num = \"5023\"",
"Output: false",
"Explanation: There are no moves to be made.",
"The sum of the first half is equal to the sum of the second half: 5 + 0 = 2 + 3.",
"Input: num = \"25??\"",
"Output: true",
"Explanation: Alice can replace one of the '?'s with '9' and it will be impossible for Bob to make the sums equal.",
"Input: num = \"?3295???\"",
"Output: false",
"Explanation: It can be proven that Bob will always win. One possible outcome is:",
"- Alice replaces the first '?' with '9'. num = \"93295???\".",
"- Bob replaces one of the '?' in the right half with '9'. num = \"932959??\".",
"- Alice replaces one of the '?' in the right half with '2'. num = \"9329592?\".",
"- Bob replaces the last '?' in the right half with '7'. num = \"93295927\".",
"Bob wins because 9 + 3 + 2 + 9 = 5 + 9 + 2 + 7.",
""
],
"constraints": [
"For example",
" if the game ended with num = \"243801\"",
" then Bob wins because 2+4+3 = 8+0+1. If the game ended with num = \"243803\"",
" then Alice wins because 2+4+3 != 8+0+3. 2 <= num. length <= 105num. length is even. num consists of only digits and '?'."
]
},
{
"id": "557",
"title": "Reverse Words in a String III",
"question": "Given a string s, reverse the order of characters in each word within a sentence while still preserving whitespace and initial word order.",
"examples": [
"Input: s = \"Let's take LeetCode contest\"",
"Output: \"s'teL ekat edoCteeL tsetnoc\"",
"Input: s = \"God Ding\"",
"Output: \"doG gniD\"",
""
],
"constraints": [
"1 <= s. length <= 5 * 104s contains printable ASCII characters. s does not contain any leading or trailing spaces. There is at least one word in s. All the words in s are separated by a single space."
]
},
{
"id": "1930",
"title": "Unique Length-3 Palindromic Subsequences",
"question": "Given a string s, return the number of unique palindromes of length three that are a subsequence of s.\nNote that even if there are multiple ways to obtain the same subsequence, it is still only counted once.\nA palindrome is a string that reads the same forwards and backwards.\nA 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.",
"examples": [
"Input: s = \"aabca\"",
"Output: 3",
"Explanation: The 3 palindromic subsequences of length 3 are:",
"- \"aba\" (subsequence of \"aabca\")",
"- \"aaa\" (subsequence of \"aabca\")",
"- \"aca\" (subsequence of \"aabca\")",
"Input: s = \"adc\"",
"Output: 0",
"Explanation: There are no palindromic subsequences of length 3 in \"adc\".",
"Input: s = \"bbcbaba\"",
"Output: 4",
"Explanation: The 4 palindromic subsequences of length 3 are:",
"- \"bbb\" (subsequence of \"bbcbaba\")",
"- \"bcb\" (subsequence of \"bbcbaba\")",
"- \"bab\" (subsequence of \"bbcbaba\")",
"- \"aba\" (subsequence of \"bbcbaba\")",
""
],
"constraints": [
"For example",
" \"ace\" is a subsequence of \"abcde\". 3 <= s. length <= 105s consists of only lowercase English letters."
]
},
{
"id": "1936",
"title": "Add Minimum Number of Rungs",
"question": "You are given a strictly increasing integer array rungs that represents the height of rungs on a ladder.\n You are currently on the floor at height 0, and you want to reach the last rung.\nYou are also given an integer dist.\n 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.\n You are able to insert rungs at any positive integer height if a rung is not already there.\nReturn the minimum number of rungs that must be added to the ladder in order for you to climb to the last rung.",
"examples": [
"Input: rungs = [1,3,5,10], dist = 2",
"Output: 2",
"Explanation:",
"You currently cannot reach the last rung.",
"Add rungs at heights 7 and 8 to climb this ladder. ",
"The ladder will now have rungs at [1,3,5,7,8,10].",
"Input: rungs = [3,6,8,10], dist = 3",
"Output: 0",
"Explanation:",
"This ladder can be climbed without adding additional rungs.",
"Input: rungs = [3,4,6,7], dist = 2",
"Output: 1",
"Explanation:",
"You currently cannot reach the first rung from the ground.",
"Add a rung at height 1 to climb this ladder.",
"The ladder will now have rungs at [1,3,4,6,7].",
"Input: rungs = [5], dist = 10",
"Output: 0",
"Explanation:",
"This ladder can be climbed without adding additional rungs.",
""
],
"constraints": [
"1 <= rungs. length <= 1051 <= rungs[i] <= 1091 <= dist <= 109rungs is strictly increasing."
]
},
{
"id": "1937",
"title": "Maximum Number of Points with Cost",
"question": "You are given an m x n integer matrix points (0-indexed).\n Starting with 0 points, you want to maximize the number of points you can get from the matrix.\nTo gain points, you must pick one cell in each row.\n Picking the cell at coordinates (r, c) will add points[r][c] to your score.\nHowever, you will lose points if you pick a cell too far from the cell that you picked in the previous row.\n 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.\nReturn the maximum number of points you can achieve.\nabs(x) is defined as:",
"examples": [
"Input: points = [[1,2,3],[1,5,1],[3,1,1]]",
"Output: 9",
"Explanation:",
"The blue cells denote the optimal cells to pick, which have coordinates (0, 2), (1, 1), and (2, 0).",
"You add 3 + 5 + 3 = 11 to your score.",
"However, you must subtract abs(2 - 1) + abs(1 - 0) = 2 from your score.",
"Your final score is 11 - 2 = 9.",
"Input: points = [[1,5],[2,3],[4,2]]",
"Output: 11",
"Explanation:",
"The blue cells denote the optimal cells to pick, which have coordinates (0, 1), (1, 1), and (2, 0).",
"You add 5 + 3 + 4 = 12 to your score.",
"However, you must subtract abs(1 - 1) + abs(1 - 0) = 1 from your score.",
"Your final score is 12 - 1 = 11.",
""
],
"constraints": [
"x for x >= 0.-x for x < 0. m == points. lengthn == points[r]. length1 <= m",
" n <= 1051 <= m * n <= 1050 <= points[r][c] <= 105"
]
},
{
"id": "1942",
"title": "The Number of the Smallest Unoccupied Chair",
"question": "There is a party where n friends numbered from 0 to n - 1 are attending.\n There is an infinite number of chairs in this party that are numbered from 0 to infinity.\n When a friend arrives at the party, they sit on the unoccupied chair with the smallest number.\nWhen a friend leaves the party, their chair becomes unoccupied at the moment they leave.\n If another friend arrives at that same moment, they can sit in that chair.\nYou 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.\n All arrival times are distinct.\nReturn the chair number that the friend numbered targetFriend will sit on.",
"examples": [
"Input: times = [[1,4],[2,3],[4,6]], targetFriend = 1",
"Output: 1",
"Explanation: ",
"- Friend 0 arrives at time 1 and sits on chair 0.",
"- Friend 1 arrives at time 2 and sits on chair 1.",
"- Friend 1 leaves at time 3 and chair 1 becomes empty.",
"- Friend 0 leaves at time 4 and chair 0 becomes empty.",
"- Friend 2 arrives at time 4 and sits on chair 0.",
"Since friend 1 sat on chair 1, we return 1.",
"Input: times = [[3,10],[1,5],[2,6]], targetFriend = 0",
"Output: 2",
"Explanation: ",
"- Friend 1 arrives at time 1 and sits on chair 0.",
"- Friend 2 arrives at time 2 and sits on chair 1.",
"- Friend 0 arrives at time 3 and sits on chair 2.",
"- Friend 1 leaves at time 5 and chair 0 becomes empty.",
"- Friend 2 leaves at time 6 and chair 1 becomes empty.",
"- Friend 0 leaves at time 10 and chair 2 becomes empty.",
"Since friend 0 sat on chair 2, we return 2.",
""
],
"constraints": [
"For example",
" if chairs 0",
" 1",
" and 5 are occupied when a friend comes",
" they will sit on chair number 2. n == times. length2 <= n <= 104times[i]. length == 21 <= arrivali < leavingi <= 1050 <= targetFriend <= n - 1Each arrivali time is distinct."
]
},
{
"id": "1943",
"title": "Describe the Painting",
"question": "There is a long and thin painting that can be represented by a number line.\n The painting was painted with multiple overlapping segments where each segment was painted with a unique color.\n 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.\nThe colors in the overlapping segments of the painting were mixed when it was painted.\n When two or more colors mix, they form a new color that can be represented as a set of mixed colors.\nFor the sake of simplicity, you should only output the sum of the elements in the set rather than the full set.\nYou want to describe the painting with the minimum number of non-overlapping half-closed segments of these mixed colors.\n 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.\nReturn the 2D array painting describing the finished painting (excluding any parts that are not painted).\n You may return the segments in any order.\nA 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.",
"examples": [
"Input: segments = [[1,4,5],[4,7,7],[1,7,9]]",
"Output: [[1,4,14],[4,7,16]]",
"Explanation: The painting can be described as follows:",
"- [1,4) is colored {5,9} (with a sum of 14) from the first and third segments.",
"- [4,7) is colored {7,9} (with a sum of 16) from the second and third segments.",
"Input: segments = [[1,7,9],[6,8,15],[8,10,7]]",
"Output: [[1,6,9],[6,7,24],[7,8,15],[8,10,7]]",
"Explanation: The painting can be described as follows:",
"- [1,6) is colored 9 from the first segment.",
"- [6,7) is colored {9,15} (with a sum of 24) from the first and second segments.",
"- [7,8) is colored 15 from the second segment.",
"- [8,10) is colored 7 from the third segment.",
"Input: segments = [[1,4,5],[1,4,7],[4,7,1],[4,7,11]]",
"Output: [[1,4,12],[4,7,12]]",
"Explanation: The painting can be described as follows:",
"- [1,4) is colored {5,7} (with a sum of 12) from the first and second segments.",
"- [4,7) is colored {1,11} (with a sum of 12) from the third and fourth segments.",
"Note that returning a single segment [1,7) is incorrect because the mixed color sets are different.",
""
],
"constraints": [
"For example",
" if colors 2",
" 4",
" and 6 are mixed",
" then the resulting mixed color is {2",
"4",
"6}. 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\t\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[1",
"4) is colored {5",
"7} (with a sum of 12) from both the first and second segments.[4",
"7) is colored {7} from only the second segment. 1 <= segments. length <= 2 * 104segments[i]. length == 31 <= starti < endi <= 1051 <= colori <= 109Each colori is distinct."
]
},
{
"id": "1946",
"title": "Largest Number After Mutating Substring",
"question": "You are given a string num, which represents a large integer.\n You are also given a 0-indexed integer array change of length 10 that maps each digit 0-9 to another digit.\n More formally, digit d maps to digit change[d].\nYou may choose to mutate a single substring of num.\n To mutate a substring, replace each digit num[i] with the digit it maps to in change (i.\ne.\n replace num[i] with change[num[i]]).\nReturn a string representing the largest possible integer after mutating (or choosing not to) a single substring of num.\nA substring is a contiguous sequence of characters within the string.",
"examples": [
"Input: num = \"132\", change = [9,8,5,0,3,6,4,2,6,8]",
"Output: \"832\"",
"Explanation: Replace the substring \"1\":",
"- 1 maps to change[1] = 8.",
"Thus, \"132\" becomes \"832\".",
"\"832\" is the largest number that can be created, so return it.",
"Input: num = \"021\", change = [9,4,3,5,7,2,1,9,0,6]",
"Output: \"934\"",
"Explanation: Replace the substring \"021\":",
"- 0 maps to change[0] = 9.",
"- 2 maps to change[2] = 3.",
"- 1 maps to change[1] = 4.",
"Thus, \"021\" becomes \"934\".",
"\"934\" is the largest number that can be created, so return it.",
"Input: num = \"5\", change = [1,4,7,5,3,2,5,6,9,4]",
"Output: \"5\"",
"Explanation: \"5\" is already the largest number that can be created, so return it.",
""
],
"constraints": [
"1 <= num. length <= 105num consists of only digits 0-9. change. length == 100 <= change[d] <= 9"
]
},
{
"id": "1947",
"title": "Maximum Compatibility Score Sum",
"question": "There is a survey that consists of n questions where each question's answer is either 0 (no) or 1 (yes).\nThe survey was given to m students numbered from 0 to m - 1 and m mentors numbered from 0 to m - 1.\n 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).\n 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).\nEach student will be assigned to one mentor, and each mentor will have one student assigned to them.\n The compatibility score of a student-mentor pair is the number of answers that are the same for both the student and the mentor.\nYou are tasked with finding the optimal student-mentor pairings to maximize the sum of the compatibility scores.\nGiven students and mentors, return the maximum compatibility score sum that can be achieved.",
"examples": [
"Input: students = [[1,1,0],[1,0,1],[0,0,1]], mentors = [[1,0,0],[0,0,1],[1,1,0]]",
"Output: 8",
"Explanation: We assign students to mentors in the following way:",
"- student 0 to mentor 2 with a compatibility score of 3.",
"- student 1 to mentor 0 with a compatibility score of 2.",
"- student 2 to mentor 1 with a compatibility score of 3.",
"The compatibility score sum is 3 + 2 + 3 = 8.",
"Input: students = [[0,0],[0,0],[0,0]], mentors = [[1,1],[1,1],[1,1]]",
"Output: 0",
"Explanation: The compatibility score of any student-mentor pair is 0.",
""
],
"constraints": [
"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. m == students. length == mentors. lengthn == students[i]. length == mentors[j]. length1 <= m",
" n <= 8students[i][k] is either 0 or 1. mentors[j][k] is either 0 or 1."
]
},
{
"id": "1953",
"title": "Maximum Number of Weeks for Which You Can Work",
"question": "There are n projects numbered from 0 to n - 1.\n You are given an integer array milestones where each milestones[i] denotes the number of milestones the ith project has.\nYou can work on the projects following these two rules: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.\n Note that you may not be able to finish every project's milestones due to these constraints.\nReturn the maximum number of weeks you would be able to work on the projects without violating the rules mentioned above.",
"examples": [
"Input: milestones = [1,2,3]",
"Output: 6",
"Explanation: One possible scenario is:",
"​​​​- During the 1st week, you will work on a milestone of project 0.",
"- During the 2nd week, you will work on a milestone of project 2.",
"- During the 3rd week, you will work on a milestone of project 1.",
"- During the 4th week, you will work on a milestone of project 2.",
"- During the 5th week, you will work on a milestone of project 1.",
"- During the 6th week, you will work on a milestone of project 2.",
"The total number of weeks is 6.",
"Input: milestones = [5,2,1]",
"Output: 7",
"Explanation: One possible scenario is:",
"- During the 1st week, you will work on a milestone of project 0.",
"- During the 2nd week, you will work on a milestone of project 1.",
"- During the 3rd week, you will work on a milestone of project 0.",
"- During the 4th week, you will work on a milestone of project 1.",
"- During the 5th week, you will work on a milestone of project 0.",
"- During the 6th week, you will work on a milestone of project 2.",
"- During the 7th week, you will work on a milestone of project 0.",
"The total number of weeks is 7.",
"Note that you cannot work on the last milestone of project 0 on 8th week because it would violate the rules.",
"Thus, one milestone in project 0 will remain unfinished.",
""
],
"constraints": [
"Every week",
" you will finish exactly one milestone of one project. You must work every week. You cannot work on two milestones from the same project for two consecutive weeks. n == milestones. length1 <= n <= 1051 <= milestones[i] <= 109"
]
},
{
"id": "1954",
"title": "Minimum Garden Perimeter to Collect Enough Apples",
"question": "In a garden represented as an infinite 2D grid, there is an apple tree planted at every integer coordinate.\n The apple tree planted at an integer coordinate (i, j) has |i| + |j| apples growing on it.\nYou will buy an axis-aligned square plot of land that is centered at (0, 0).\nGiven 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.\nThe value of |x| is defined as:",
"examples": [
"Input: neededApples = 1",
"Output: 8",
"Explanation: A square plot of side length 1 does not contain any apples.",
"However, a square plot of side length 2 has 12 apples inside (as depicted in the image above).",
"The perimeter is 2 * 4 = 8.",
"Input: neededApples = 13",
"Output: 16",
"Input: neededApples = 1000000000",
"Output: 5040",
""
],
"constraints": [
"x if x >= 0-x if x < 01 <= neededApples <= 1015"
]
},
{
"id": "1958",
"title": "Check if Move is Legal",
"question": "You are given a 0-indexed 8 x 8 grid board, where board[r][c] represents the cell (r, c) on a game board.\n On the board, free cells are represented by '.\n', white cells are represented by 'W', and black cells are represented by 'B'.\nEach move in this game consists of choosing a free cell and changing it to the color you are playing as (either white or black).\n However, a move is only legal if, after changing it, the cell becomes the endpoint of a good line (horizontal, vertical, or diagonal).\nA 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).\n You can find examples for good lines in the figure below: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.",
"examples": [
"Input: board = [[\".\",\".\",\".\",\"B\",\".\",\".\",\".\",\".\"],[\".\",\".\",\".\",\"W\",\".\",\".\",\".\",\".\"],[\".\",\".\",\".\",\"W\",\".\",\".\",\".\",\".\"],[\".\",\".\",\".\",\"W\",\".\",\".\",\".\",\".\"],[\"W\",\"B\",\"B\",\".\",\"W\",\"W\",\"W\",\"B\"],[\".\",\".\",\".\",\"B\",\".\",\".\",\".\",\".\"],[\".\",\".\",\".\",\"B\",\".\",\".\",\".\",\".\"],[\".\",\".\",\".\",\"W\",\".\",\".\",\".\",\".\"]], rMove = 4, cMove = 3, color = \"B\"",
"Output: true",
"Explanation: '.', 'W', and 'B' are represented by the colors blue, white, and black respectively, and cell (rMove, cMove) is marked with an 'X'.",
"The two good lines with the chosen cell as an endpoint are annotated above with the red rectangles.",
"Input: board = [[\".\",\".\",\".\",\".\",\".\",\".\",\".\",\".\"],[\".\",\"B\",\".\",\".\",\"W\",\".\",\".\",\".\"],[\".\",\".\",\"W\",\".\",\".\",\".\",\".\",\".\"],[\".\",\".\",\".\",\"W\",\"B\",\".\",\".\",\".\"],[\".\",\".\",\".\",\".\",\".\",\".\",\".\",\".\"],[\".\",\".\",\".\",\".\",\"B\",\"W\",\".\",\".\"],[\".\",\".\",\".\",\".\",\".\",\".\",\"W\",\".\"],[\".\",\".\",\".\",\".\",\".\",\".\",\".\",\"B\"]], rMove = 4, cMove = 4, color = \"W\"",
"Output: false",
"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.",
""
],
"constraints": [
"board. length == board[r]. length == 80 <= rMove",
" cMove < 8board[rMove][cMove] == '.'color is either 'B' or 'W'."
]
},
{
"id": "559",
"title": "Maximum Depth of N-ary Tree",
"question": "Given a n-ary tree, find its maximum depth.\nThe maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.\nNary-Tree input serialization is represented in their level order traversal, each group of children is separated by the null value (See examples).",
"examples": [
"Input: root = [1,null,3,2,4,null,5,6]",
"Output: 3",
"Input: root = [1,null,2,3,4,5,null,null,6,7,null,8,null,9,10,null,null,11,null,12,null,13,null,null,14]",
"Output: 5",
""
],
"constraints": [
"The total number of nodes is in the range [0",
" 104]. The depth of the n-ary tree is less than or equal to 1000."
]
},
{
"id": "1959",
"title": "Minimum Total Space Wasted With K Resizing Operations",
"question": "You are currently designing a dynamic array.\n 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.\n In addition, you are given an integer k, the maximum number of times you can resize the array (to any size).\nThe 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.\n The space wasted at time 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.\nlength.\nReturn the minimum total space wasted if you can resize the array at most k times.\nNote: The array can have any size at the start and does not count towards the number of resizing operations.",
"examples": [
"Input: nums = [10,20], k = 0",
"Output: 10",
"Explanation: size = [20,20].",
"We can set the initial size to be 20.",
"The total wasted space is (20 - 10) + (20 - 20) = 10.",
"Input: nums = [10,20,30], k = 1",
"Output: 10",
"Explanation: size = [20,20,30].",
"We can set the initial size to be 20 and resize to 30 at time 2. ",
"The total wasted space is (20 - 10) + (20 - 20) + (30 - 30) = 10.",
"Input: nums = [10,20,15,30,20], k = 2",
"Output: 15",
"Explanation: size = [10,20,20,30,30].",
"We can set the initial size to 10, resize to 20 at time 1, and resize to 30 at time 3.",
"The total wasted space is (10 - 10) + (20 - 20) + (20 - 15) + (30 - 30) + (30 - 20) = 15.",
""
],
"constraints": [
"1 <= nums. length <= 2001 <= nums[i] <= 1060 <= k <= nums. length - 1"
]
},
{
"id": "1962",
"title": "Remove Stones to Minimize the Total",
"question": "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.\n You should apply the following operation exactly k times:Notice that you can apply the operation on the same pile more than once.\nReturn the minimum possible total number of stones remaining after applying the k operations.\nfloor(x) is the greatest integer that is smaller than or equal to x (i.\ne.\n, rounds x down).",
"examples": [
"Input: piles = [5,4,9], k = 2",
"Output: 12",
"Explanation: Steps of a possible scenario are:",
"- Apply the operation on pile 2. The resulting piles are [5,4,5].",
"- Apply the operation on pile 0. The resulting piles are [3,4,5].",
"The total number of stones in [3,4,5] is 12.",
"Input: piles = [4,3,6,7], k = 3",
"Output: 12",
"Explanation: Steps of a possible scenario are:",
"- Apply the operation on pile 2. The resulting piles are [4,3,3,7].",
"- Apply the operation on pile 3. The resulting piles are [4,3,3,4].",
"- Apply the operation on pile 0. The resulting piles are [2,3,3,4].",
"The total number of stones in [2,3,3,4] is 12.",
""
],
"constraints": [
"Choose any piles[i] and remove floor(piles[i] / 2) stones from it. 1 <= piles. length <= 1051 <= piles[i] <= 1041 <= k <= 105"
]
},
{
"id": "1963",
"title": "Minimum Number of Swaps to Make the String Balanced",
"question": "You are given a 0-indexed string s of even length n.\n The string consists of exactly n / 2 opening brackets '[' and n / 2 closing brackets ']'.\nA string is called balanced if and only if:You may swap the brackets at any two indices any number of times.\nReturn the minimum number of swaps to make s balanced.",
"examples": [
"Input: s = \"][][\"",
"Output: 1",
"Explanation: You can make the string balanced by swapping index 0 with index 3.",
"The resulting string is \"[[]]\".",
"Input: s = \"]]][[[\"",
"Output: 2",
"Explanation: You can do the following to make the string balanced:",
"- Swap index 0 with index 4. s = \"[]][][\".",
"- Swap index 1 with index 5. s = \"[[][]]\".",
"The resulting string is \"[[][]]\".",
"Input: s = \"[]\"",
"Output: 0",
"Explanation: The string is already balanced.",
""
],
"constraints": [
"It is the empty string",
" orIt can be written as AB",
" where both A and B are balanced strings",
" orIt can be written as [C]",
" where C is a balanced string. n == s. length2 <= n <= 106n is even. s[i] is either '[' or ']'. The number of opening brackets '[' equals n / 2",
" and the number of closing brackets ']' equals n / 2."
]
},
{
"id": "1968",
"title": "Array With Elements Not Equal to Average of Neighbors",
"question": "You are given a 0-indexed array nums of distinct integers.\n 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.\nMore formally, the rearranged array should have the property such that for every i in the range 1 <= i < nums.\nlength - 1, (nums[i-1] + nums[i+1]) / 2 is not equal to nums[i].\nReturn any rearrangement of nums that meets the requirements.",
"examples": [
"Input: nums = [1,2,3,4,5]",
"Output: [1,2,4,5,3]",
"Explanation:",
"When i=1, nums[i] = 2, and the average of its neighbors is (1+4) / 2 = 2. 5.",
"When i=2, nums[i] = 4, and the average of its neighbors is (2+5) / 2 = 3. 5.",
"When i=3, nums[i] = 5, and the average of its neighbors is (4+3) / 2 = 3. 5.",
"Input: nums = [6,2,0,9,7]",
"Output: [9,7,6,2,0]",
"Explanation:",
"When i=1, nums[i] = 7, and the average of its neighbors is (9+6) / 2 = 7. 5.",
"When i=2, nums[i] = 6, and the average of its neighbors is (7+2) / 2 = 4. 5.",
"When i=3, nums[i] = 2, and the average of its neighbors is (6+0) / 2 = 3.",
""
],
"constraints": [
"3 <= nums. length <= 1050 <= nums[i] <= 105"
]
},
{
"id": "1969",
"title": "Minimum Non-Zero Product of the Array Elements",
"question": "You are given a positive integer p.\n Consider an array nums (1-indexed) that consists of the integers in the inclusive range [1, 2p - 1] in their binary representations.\n You are allowed to do the following operation any number of times:For example, if x = 1101 and y = 0011, after swapping the 2nd bit from the right, we have x = 1111 and y = 0001.\nFind the minimum non-zero product of nums after performing the above operation any number of times.\n Return this product modulo 109 + 7.\nNote: The answer should be the minimum product before the modulo operation is done.",
"examples": [
"Input: p = 1",
"Output: 1",
"Explanation: nums = [1].",
"There is only one element, so the product equals that element.",
"Input: p = 2",
"Output: 6",
"Explanation: nums = [01, 10, 11].",
"Any swap would either make the product 0 or stay the same.",
"Thus, the array product of 1 * 2 * 3 = 6 is already minimized.",
"Input: p = 3",
"Output: 1512",
"Explanation: nums = [001, 010, 011, 100, 101, 110, 111]",
"- In the first operation we can swap the leftmost bit of the second and fifth elements.",
" - The resulting array is [001, 110, 011, 100, 001, 110, 111].",
"- In the second operation we can swap the middle bit of the third and fourth elements.",
" - The resulting array is [001, 110, 001, 110, 001, 110, 111].",
"The array product is 1 * 6 * 1 * 6 * 1 * 6 * 7 = 1512, which is the minimum possible product.",
""
],
"constraints": [
"Choose two elements x and y from nums. Choose a bit in x and swap it with its corresponding bit in y. Corresponding bit refers to the bit that is in the same position in the other integer. 1 <= p <= 60"
]
},
{
"id": "1975",
"title": "Maximum Matrix Sum",
"question": "You are given an n x n integer matrix.\n You can do the following operation any number of times:Two elements are considered adjacent if and only if they share a border.\nYour goal is to maximize the summation of the matrix's elements.\n Return the maximum sum of the matrix's elements using the operation mentioned above.",
"examples": [
"Input: matrix = [[1,-1],[-1,1]]",
"Output: 4",
"Explanation: We can follow the following steps to reach sum equals 4:",
"- Multiply the 2 elements in the first row by -1.",
"- Multiply the 2 elements in the first column by -1.",
"Input: matrix = [[1,2,3],[-1,-2,-3],[1,2,3]]",
"Output: 16",
"Explanation: We can follow the following step to reach sum equals 16:",
"- Multiply the 2 last elements in the second row by -1.",
""
],
"constraints": [
"Choose any two adjacent elements of matrix and multiply each of them by -1. n == matrix. length == matrix[i]. length2 <= n <= 250-105 <= matrix[i][j] <= 105"
]
},
{
"id": "1976",
"title": "Number of Ways to Arrive at Destination",
"question": "You are in a city that consists of n intersections numbered from 0 to n - 1 with bi-directional roads between some intersections.\n 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.\nYou 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.\n You want to know in how many ways you can travel from intersection 0 to intersection n - 1 in the shortest amount of time.\nReturn the number of ways you can arrive at your destination in the shortest amount of time.\n Since the answer may be large, return it modulo 109 + 7.",
"examples": [
"Input: 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]]",
"Output: 4",
"Explanation: The shortest amount of time it takes to go from intersection 0 to intersection 6 is 7 minutes.",
"The four ways to get there in 7 minutes are:",
"- 0 ➝ 6",
"- 0 ➝ 4 ➝ 6",
"- 0 ➝ 1 ➝ 2 ➝ 5 ➝ 6",
"- 0 ➝ 1 ➝ 3 ➝ 5 ➝ 6",
"Input: n = 2, roads = [[1,0,10]]",
"Output: 1",
"Explanation: There is only one way to go from intersection 0 to intersection 1, and it takes 10 minutes.",
""
],
"constraints": [
"1 <= n <= 200n - 1 <= roads. length <= n * (n - 1) / 2roads[i]. length == 30 <= ui",
" vi <= n - 11 <= timei <= 109ui != viThere is at most one road connecting any two intersections. You can reach any intersection from any other intersection."
]
},
{
"id": "1980",
"title": "Find Unique Binary String",
"question": "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.\n If there are multiple answers, you may return any of them.",
"examples": [
"Input: nums = [\"01\",\"10\"]",
"Output: \"11\"",
"Explanation: \"11\" does not appear in nums. \"00\" would also be correct.",
"Input: nums = [\"00\",\"01\"]",
"Output: \"11\"",
"Explanation: \"11\" does not appear in nums. \"10\" would also be correct.",
"Input: nums = [\"111\",\"011\",\"001\"]",
"Output: \"101\"",
"Explanation: \"101\" does not appear in nums. \"000\", \"010\", \"100\", and \"110\" would also be correct.",
""
],
"constraints": [
"n == nums. length1 <= n <= 16nums[i]. length == nnums[i] is either '0' or '1'. All the strings of nums are unique."
]
},
{
"id": "1981",
"title": "Minimize the Difference Between Target and Chosen Elements",
"question": "You are given an m x n integer matrix mat and an integer target.\nChoose one integer from each row in the matrix such that the absolute difference between target and the sum of the chosen elements is minimized.\nReturn the minimum absolute difference.\nThe absolute difference between two numbers a and b is the absolute value of a - b.",
"examples": [
"Input: mat = [[1,2,3],[4,5,6],[7,8,9]], target = 13",
"Output: 0",
"Explanation: One possible choice is to:",
"- Choose 1 from the first row.",
"- Choose 5 from the second row.",
"- Choose 7 from the third row.",
"The sum of the chosen elements is 13, which equals the target, so the absolute difference is 0.",
"Input: mat = [[1],[2],[3]], target = 100",
"Output: 94",
"Explanation: The best possible choice is to:",
"- Choose 1 from the first row.",
"- Choose 2 from the second row.",
"- Choose 3 from the third row.",
"The sum of the chosen elements is 6, and the absolute difference is 94.",
"Input: mat = [[1,2,9,8,7]], target = 6",
"Output: 1",
"Explanation: The best choice is to choose 7 from the first row.",
"The absolute difference is 1.",
""
],
"constraints": [
"m == mat. lengthn == mat[i]. length1 <= m",
" n <= 701 <= mat[i][j] <= 701 <= target <= 800"
]
},
{
"id": "1985",
"title": "Find the Kth Largest Integer in the Array",
"question": "You are given an array of strings nums and an integer k.\n Each string in nums represents an integer without leading zeros.\nReturn the string that represents the kth largest integer in nums.\nNote: Duplicate numbers should be counted distinctly.\n 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.",
"examples": [
"Input: nums = [\"3\",\"6\",\"7\",\"10\"], k = 4",
"Output: \"3\"",
"Explanation:",
"The numbers in nums sorted in non-decreasing order are [\"3\",\"6\",\"7\",\"10\"].",
"The 4th largest integer in nums is \"3\".",
"Input: nums = [\"2\",\"21\",\"12\",\"1\"], k = 3",
"Output: \"2\"",
"Explanation:",
"The numbers in nums sorted in non-decreasing order are [\"1\",\"2\",\"12\",\"21\"].",
"The 3rd largest integer in nums is \"2\".",
"Input: nums = [\"0\",\"0\"], k = 2",
"Output: \"0\"",
"Explanation:",
"The numbers in nums sorted in non-decreasing order are [\"0\",\"0\"].",
"The 2nd largest integer in nums is \"0\".",
""
],
"constraints": [
"1 <= k <= nums. length <= 1041 <= nums[i]. length <= 100nums[i] consists of only digits. nums[i] will not have any leading zeros."
]
},
{
"id": "561",
"title": "Array Partition I",
"question": "Given an integer array nums of 2n integers, group these integers into n pairs (a1, b1), (a2, b2), .\n.\n.\n, (an, bn) such that the sum of min(ai, bi) for all i is maximized.\n Return the maximized sum.",
"examples": [
"Input: nums = [1,4,3,2]",
"Output: 4",
"Explanation: All possible pairings (ignoring the ordering of elements) are:",
"1. (1, 4), (2, 3) -> min(1, 4) + min(2, 3) = 1 + 2 = 3",
"2. (1, 3), (2, 4) -> min(1, 3) + min(2, 4) = 1 + 2 = 3",
"3. (1, 2), (3, 4) -> min(1, 2) + min(3, 4) = 1 + 3 = 4",
"So the maximum possible sum is 4. Input: nums = [6,2,6,5,1,2]",
"Output: 9",
"Explanation: The optimal pairing is (2, 1), (2, 5), (6, 6). min(2, 1) + min(2, 5) + min(6, 6) = 1 + 2 + 6 = 9.",
""
],
"constraints": [
"1 <= n <= 104nums. length == 2 * n-104 <= nums[i] <= 104"
]
},
{
"id": "1986",
"title": "Minimum Number of Work Sessions to Finish the Tasks",
"question": "There are n tasks assigned to you.\n The task times are represented as an integer array tasks of length n, where the ith task takes tasks[i] hours to finish.\n A work session is when you work for at most sessionTime consecutive hours and then take a break.\nYou should finish the given tasks in a way that satisfies the following conditions:Given tasks and sessionTime, return the minimum number of work sessions needed to finish all the tasks following the conditions above.\nThe tests are generated such that sessionTime is greater than or equal to the maximum element in tasks[i].",
"examples": [
"Input: tasks = [1,2,3], sessionTime = 3",
"Output: 2",
"Explanation: You can finish the tasks in two work sessions.",
"- First work session: finish the first and the second tasks in 1 + 2 = 3 hours.",
"- Second work session: finish the third task in 3 hours.",
"Input: tasks = [3,1,3,1,1], sessionTime = 8",
"Output: 2",
"Explanation: You can finish the tasks in two work sessions.",
"- First work session: finish all the tasks except the last one in 3 + 1 + 3 + 1 = 8 hours.",
"- Second work session: finish the last task in 1 hour.",
"Input: tasks = [1,2,3,4,5], sessionTime = 15",
"Output: 1",
"Explanation: You can finish all the tasks in one work session.",
""
],
"constraints": [
"If you start a task in a work session",
" you must complete it in the same work session. You can start a new task immediately after finishing the previous one. You may complete the tasks in any order. n == tasks. length1 <= n <= 141 <= tasks[i] <= 10max(tasks[i]) <= sessionTime <= 15"
]
},
{
"id": "4",
"title": "Median of Two Sorted Arrays",
"question": "Given two sorted arrays nums1 and nums2 of size m and n respectively, return the median of the two sorted arrays.\nThe overall run time complexity should be O(log (m+n)).",
"examples": [
"Input: nums1 = [1,3], nums2 = [2]",
"Output: 2. 00000",
"Explanation: merged array = [1,2,3] and median is 2.",
"Input: nums1 = [1,2], nums2 = [3,4]",
"Output: 2. 50000",
"Explanation: merged array = [1,2,3,4] and median is (2 + 3) / 2 = 2. 5.",
"Input: nums1 = [0,0], nums2 = [0,0]",
"Output: 0. 00000",
"Input: nums1 = [], nums2 = [1]",
"Output: 1. 00000",
"Input: nums1 = [2], nums2 = []",
"Output: 2. 00000",
""
],
"constraints": [
"nums1. length == mnums2. length == n0 <= m <= 10000 <= n <= 10001 <= m + n <= 2000-106 <= nums1[i]",
" nums2[i] <= 106"
]
},
{
"id": "10",
"title": "Regular Expression Matching",
"question": "Given an input string s and a pattern p, implement regular expression matching with support for '.\n' and '*' where:The matching should cover the entire input string (not partial).",
"examples": [
"Input: s = \"aa\", p = \"a\"",
"Output: false",
"Explanation: \"a\" does not match the entire string \"aa\".",
"Input: s = \"aa\", p = \"a*\"",
"Output: true",
"Explanation: '*' means zero or more of the preceding element, 'a'. Therefore, by repeating 'a' once, it becomes \"aa\".",
"Input: s = \"ab\", p = \".*\"",
"Output: true",
"Explanation: \".*\" means \"zero or more (*) of any character (.)\".",
"Input: s = \"aab\", p = \"c*a*b\"",
"Output: true",
"Explanation: c can be repeated 0 times, a can be repeated 1 time. Therefore, it matches \"aab\".",
"Input: s = \"mississippi\", p = \"mis*is*p*.\"",
"Output: false",
""
],
"constraints": [
"'.' Matches any single character.​​​​'*' Matches zero or more of the preceding element. 1 <= s. length <= 201 <= p. length <= 30s contains only lowercase English letters. p contains only lowercase English letters",
" '.'",
" and '*'. It is guaranteed for each appearance of the character '*'",
" there will be a previous valid character to match."
]
},
{
"id": "23",
"title": "Merge k Sorted Lists",
"question": "You are given an array of k linked-lists lists, each linked-list is sorted in ascending order.\nMerge all the linked-lists into one sorted linked-list and return it.",
"examples": [
"Input: lists = [[1,4,5],[1,3,4],[2,6]]",
"Output: [1,1,2,3,4,4,5,6]",
"Explanation: The linked-lists are:",
"[",
" 1->4->5,",
" 1->3->4,",
" 2->6",
"]",
"merging them into one sorted list:",
"1->1->2->3->4->4->5->6",
"Input: lists = []",
"Output: []",
"Input: lists = [[]]",
"Output: []",
""
],
"constraints": [
"k == lists. length0 <= k <= 10^40 <= lists[i]. length <= 500-10^4 <= lists[i][j] <= 10^4lists[i] is sorted in ascending order. The sum of lists[i]. length won't exceed 10^4."
]
},
{
"id": "25",
"title": "Reverse Nodes in k-Group",
"question": "Given a linked list, reverse the nodes of a linked list k at a time and return its modified list.\nk is a positive integer and is less than or equal to the length of the linked list.\n If the number of nodes is not a multiple of k then left-out nodes, in the end, should remain as it is.\nYou may not alter the values in the list's nodes, only nodes themselves may be changed.",
"examples": [
"Input: head = [1,2,3,4,5], k = 2",
"Output: [2,1,4,3,5]",
"Input: head = [1,2,3,4,5], k = 3",
"Output: [3,2,1,4,5]",
"Input: head = [1,2,3,4,5], k = 1",
"Output: [1,2,3,4,5]",
"Input: head = [1], k = 1",
"Output: [1]",
""
],
"constraints": [
"The number of nodes in the list is in the range sz. 1 <= sz <= 50000 <= Node. val <= 10001 <= k <= sz"
]
},
{
"id": "30",
"title": "Substring with Concatenation of All Words",
"question": "You are given a string s and an array of strings words of the same length.\n Return all starting indices of substring(s) in s that is a concatenation of each word in words exactly once, in any order, and without any intervening characters.\nYou can return the answer in any order.",
"examples": [
"Input: s = \"barfoothefoobarman\", words = [\"foo\",\"bar\"]",
"Output: [0,9]",
"Explanation: Substrings starting at index 0 and 9 are \"barfoo\" and \"foobar\" respectively.",
"The output order does not matter, returning [9,0] is fine too.",
"Input: s = \"wordgoodgoodgoodbestword\", words = [\"word\",\"good\",\"best\",\"word\"]",
"Output: []",
"Input: s = \"barfoofoobarthefoobarman\", words = [\"bar\",\"foo\",\"the\"]",
"Output: [6,9,12]",
""
],
"constraints": [
"1 <= s. length <= 104s consists of lower-case English letters. 1 <= words. length <= 50001 <= words[i]. length <= 30words[i] consists of lower-case English letters."
]
},
{
"id": "32",
"title": "Longest Valid Parentheses",
"question": "Given a string containing just the characters '(' and ')', find the length of the longest valid (well-formed) parentheses substring.",
"examples": [
"Input: s = \"(()\"",
"Output: 2",
"Explanation: The longest valid parentheses substring is \"()\".",
"Input: s = \")()())\"",
"Output: 4",
"Explanation: The longest valid parentheses substring is \"()()\".",
"Input: s = \"\"",
"Output: 0",
""
],
"constraints": [
"0 <= s. length <= 3 * 104s[i] is '('",
" or ')'."
]
},
{
"id": "37",
"title": "Sudoku Solver",
"question": "Write a program to solve a Sudoku puzzle by filling the empty cells.\nA sudoku solution must satisfy all of the following rules:The '.\n' character indicates empty cells.",
"examples": [
"Input: board = [[\"5\",\"3\",\".\",\".\",\"7\",\".\",\".\",\".\",\".\"],[\"6\",\".\",\".\",\"1\",\"9\",\"5\",\".\",\".\",\".\"],[\".\",\"9\",\"8\",\".\",\".\",\".\",\".\",\"6\",\".\"],[\"8\",\".\",\".\",\".\",\"6\",\".\",\".\",\".\",\"3\"],[\"4\",\".\",\".\",\"8\",\".\",\"3\",\".\",\".\",\"1\"],[\"7\",\".\",\".\",\".\",\"2\",\".\",\".\",\".\",\"6\"],[\".\",\"6\",\".\",\".\",\".\",\".\",\"2\",\"8\",\".\"],[\".\",\".\",\".\",\"4\",\"1\",\"9\",\".\",\".\",\"5\"],[\".\",\".\",\".\",\".\",\"8\",\".\",\".\",\"7\",\"9\"]]",
"Output: [[\"5\",\"3\",\"4\",\"6\",\"7\",\"8\",\"9\",\"1\",\"2\"],[\"6\",\"7\",\"2\",\"1\",\"9\",\"5\",\"3\",\"4\",\"8\"],[\"1\",\"9\",\"8\",\"3\",\"4\",\"2\",\"5\",\"6\",\"7\"],[\"8\",\"5\",\"9\",\"7\",\"6\",\"1\",\"4\",\"2\",\"3\"],[\"4\",\"2\",\"6\",\"8\",\"5\",\"3\",\"7\",\"9\",\"1\"],[\"7\",\"1\",\"3\",\"9\",\"2\",\"4\",\"8\",\"5\",\"6\"],[\"9\",\"6\",\"1\",\"5\",\"3\",\"7\",\"2\",\"8\",\"4\"],[\"2\",\"8\",\"7\",\"4\",\"1\",\"9\",\"6\",\"3\",\"5\"],[\"3\",\"4\",\"5\",\"2\",\"8\",\"6\",\"1\",\"7\",\"9\"]]",
"Explanation: The input board is shown above and the only valid solution is shown below:",
"",
"",
""
],
"constraints": [
"board. length == 9board[i]. length == 9board[i][j] is a digit or '.'. It is guaranteed that the input board has only one solution."
]
},
{
"id": "41",
"title": "First Missing Positive",
"question": "Given an unsorted integer array nums, return the smallest missing positive integer.\nYou must implement an algorithm that runs in O(n) time and uses constant extra space.",
"examples": [
"Input: nums = [1,2,0]",
"Output: 3",
"Input: nums = [3,4,-1,1]",
"Output: 2",
"Input: nums = [7,8,9,11,12]",
"Output: 1",
""
],
"constraints": [
"1 <= nums. length <= 5 * 105-231 <= nums[i] <= 231 - 1"
]
},
{
"id": "42",
"title": "Trapping Rain Water",
"question": "Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it can trap after raining.",
"examples": [
"Input: height = [0,1,0,2,1,0,1,3,2,1,2,1]",
"Output: 6",
"Explanation: The above elevation map (black section) is represented by array [0,1,0,2,1,0,1,3,2,1,2,1]. In this case, 6 units of rain water (blue section) are being trapped.",
"Input: height = [4,2,0,3,2,5]",
"Output: 9",
""
],
"constraints": [
"n == height. length1 <= n <= 2 * 1040 <= height[i] <= 105"
]
},
{
"id": "563",
"title": "Binary Tree Tilt",
"question": "Given the root of a binary tree, return the sum of every tree node's tilt.\nThe tilt of a tree node is the absolute difference between the sum of all left subtree node values and all right subtree node values.\n If a node does not have a left child, then the sum of the left subtree node values is treated as 0.\n The rule is similar if there the node does not have a right child.",
"examples": [
"Input: root = [1,2,3]",
"Output: 1",
"Explanation: ",
"Tilt of node 2 : |0-0| = 0 (no children)",
"Tilt of node 3 : |0-0| = 0 (no children)",
"Tilt of node 1 : |2-3| = 1 (left subtree is just left child, so sum is 2; right subtree is just right child, so sum is 3)",
"Sum of every tilt : 0 + 0 + 1 = 1",
"Input: root = [4,2,9,3,5,null,7]",
"Output: 15",
"Explanation: ",
"Tilt of node 3 : |0-0| = 0 (no children)",
"Tilt of node 5 : |0-0| = 0 (no children)",
"Tilt of node 7 : |0-0| = 0 (no children)",
"Tilt of node 2 : |3-5| = 2 (left subtree is just left child, so sum is 3; right subtree is just right child, so sum is 5)",
"Tilt of node 9 : |0-7| = 7 (no left child, so sum is 0; right subtree is just right child, so sum is 7)",
"Tilt of node 4 : |(3+5+2)-(9+7)| = |10-16| = 6 (left subtree values are 3, 5, and 2, which sums to 10; right subtree values are 9 and 7, which sums to 16)",
"Sum of every tilt : 0 + 0 + 0 + 2 + 7 + 6 = 15",
"Input: root = [21,7,14,1,1,2,2,3,3]",
"Output: 9",
""
],
"constraints": [
"The number of nodes in the tree is in the range [0",
" 104].-1000 <= Node. val <= 1000"
]
},
{
"id": "44",
"title": "Wildcard Matching",
"question": "Given an input string (s) and a pattern (p), implement wildcard pattern matching with support for '?' and '*' where:The matching should cover the entire input string (not partial).",
"examples": [
"Input: s = \"aa\", p = \"a\"",
"Output: false",
"Explanation: \"a\" does not match the entire string \"aa\".",
"Input: s = \"aa\", p = \"*\"",
"Output: true",
"Explanation: '*' matches any sequence.",
"Input: s = \"cb\", p = \"?a\"",
"Output: false",
"Explanation: '?' matches 'c', but the second letter is 'a', which does not match 'b'.",
"Input: s = \"adceb\", p = \"*a*b\"",
"Output: true",
"Explanation: The first '*' matches the empty sequence, while the second '*' matches the substring \"dce\".",
"Input: s = \"acdcb\", p = \"a*c?b\"",
"Output: false",
""
],
"constraints": [
"'?' Matches any single character.'*' Matches any sequence of characters (including the empty sequence). 0 <= s. length",
" p. length <= 2000s contains only lowercase English letters. p contains only lowercase English letters",
" '?' or '*'."
]
},
{
"id": "51",
"title": "N-Queens",
"question": "The n-queens puzzle is the problem of placing n queens on an n x n chessboard such that no two queens attack each other.\nGiven an integer n, return all distinct solutions to the n-queens puzzle.\n You may return the answer in any order.\nEach solution contains a distinct board configuration of the n-queens' placement, where 'Q' and '.\n' both indicate a queen and an empty space, respectively.",
"examples": [
"Input: n = 4",
"Output: [[\". Q..\",\"... Q\",\"Q...\",\".. Q.\"],[\".. Q.\",\"Q...\",\"... Q\",\". Q..\"]]",
"Explanation: There exist two distinct solutions to the 4-queens puzzle as shown above",
"Input: n = 1",
"Output: [[\"Q\"]]",
""
],
"constraints": [
"1 <= n <= 9"
]
},
{
"id": "52",
"title": "N-Queens II",
"question": "The n-queens puzzle is the problem of placing n queens on an n x n chessboard such that no two queens attack each other.\nGiven an integer n, return the number of distinct solutions to the n-queens puzzle.",
"examples": [
"Input: n = 4",
"Output: 2",
"Explanation: There are two distinct solutions to the 4-queens puzzle as shown.",
"Input: n = 1",
"Output: 1",
""
],
"constraints": [
"1 <= n <= 9"
]
},
{
"id": "60",
"title": "Permutation Sequence",
"question": "The set [1, 2, 3, .\n.\n.\n, n] contains a total of n! unique permutations.\nBy listing and labeling all of the permutations in order, we get the following sequence for n = 3:Given n and k, return the kth permutation sequence.",
"examples": [
"Input: n = 3, k = 3",
"Output: \"213\"",
"Input: n = 4, k = 9",
"Output: \"2314\"",
"Input: n = 3, k = 1",
"Output: \"123\"",
""
],
"constraints": [
"1 <= n <= 91 <= k <= n!"
]
},
{
"id": "65",
"title": "Valid Number",
"question": "A valid number can be split up into these components (in order):A decimal number can be split up into these components (in order):An integer can be split up into these components (in order):For example, all the following are valid numbers: [\"2\", \"0089\", \"-0.\n1\", \"+3.\n14\", \"4.\n\", \"-.\n9\", \"2e10\", \"-90E3\", \"3e+7\", \"+6e-1\", \"53.\n5e93\", \"-123.\n456e789\"], while the following are not valid numbers: [\"abc\", \"1a\", \"1e\", \"e3\", \"99e2.\n5\", \"--6\", \"-+3\", \"95a54e53\"].\nGiven a string s, return true if s is a valid number.",
"examples": [
"Input: s = \"0\"",
"Output: true",
"Input: s = \"e\"",
"Output: false",
"Input: s = \".\"",
"Output: false",
"Input: s = \". 1\"",
"Output: true",
""
],
"constraints": [
"1 <= s. length <= 20s consists of only English letters (both uppercase and lowercase)",
" digits (0-9)",
" plus '+'",
" minus '-'",
" or dot '.'."
]
},
{
"id": "68",
"title": "Text Justification",
"question": "Given an array of strings words and a width maxWidth, format the text such that each line has exactly maxWidth characters and is fully (left and right) justified.\nYou should pack your words in a greedy approach; that is, pack as many words as you can in each line.\n Pad extra spaces ' ' when necessary so that each line has exactly maxWidth characters.\nExtra spaces between words should be distributed as evenly as possible.\n If the number of spaces on a line does not divide evenly between words, the empty slots on the left will be assigned more spaces than the slots on the right.\nFor the last line of text, it should be left-justified and no extra space is inserted between words.\nNote:",
"examples": [
"Input: words = [\"This\", \"is\", \"an\", \"example\", \"of\", \"text\", \"justification.\"], maxWidth = 16",
"Output:",
"[",
"   \"This    is    an\",",
"   \"example  of text\",",
"   \"justification.  \"",
"]Input: words = [\"What\",\"must\",\"be\",\"acknowledgment\",\"shall\",\"be\"], maxWidth = 16",
"Output:",
"[",
"  \"What   must   be\",",
"  \"acknowledgment  \",",
"  \"shall be        \"",
"]",
"Explanation: Note that the last line is \"shall be \" instead of \"shall be\", because the last line must be left-justified instead of fully-justified.",
"Note that the second line is also left-justified becase it contains only one word. Input: words = [\"Science\",\"is\",\"what\",\"we\",\"understand\",\"well\",\"enough\",\"to\",\"explain\",\"to\",\"a\",\"computer.\",\"Art\",\"is\",\"everything\",\"else\",\"we\",\"do\"], maxWidth = 20",
"Output:",
"[",
"  \"Science  is  what we\",",
" \"understand      well\",",
"  \"enough to explain to\",",
"  \"a  computer.  Art is\",",
"  \"everything  else  we\",",
"  \"do                  \"",
"]"
],
"constraints": [
"A word is defined as a character sequence consisting of non-space characters only. Each word's length is guaranteed to be greater than 0 and not exceed maxWidth. The input array words contains at least one word. 1 <= words. length <= 3001 <= words[i]. length <= 20words[i] consists of only English letters and symbols. 1 <= maxWidth <= 100words[i]. length <= maxWidth"
]
},
{
"id": "72",
"title": "Edit Distance",
"question": "Given two strings word1 and word2, return the minimum number of operations required to convert word1 to word2.\nYou have the following three operations permitted on a word:",
"examples": [
"Input: word1 = \"horse\", word2 = \"ros\"",
"Output: 3",
"Explanation: ",
"horse -> rorse (replace 'h' with 'r')",
"rorse -> rose (remove 'r')",
"rose -> ros (remove 'e')",
"Input: word1 = \"intention\", word2 = \"execution\"",
"Output: 5",
"Explanation: ",
"intention -> inention (remove 't')",
"inention -> enention (replace 'i' with 'e')",
"enention -> exention (replace 'n' with 'x')",
"exention -> exection (replace 'n' with 'c')",
"exection -> execution (insert 'u')",
""
],
"constraints": [
"Insert a characterDelete a characterReplace a character0 <= word1. length",
" word2. length <= 500word1 and word2 consist of lowercase English letters."
]
},
{
"id": "76",
"title": "Minimum Window Substring",
"question": "Given two strings s and t of lengths m and n respectively, return the minimum window substring of s such that every character in t (including duplicates) is included in the window.\n If there is no such substring, return the empty string \"\".\nThe testcases will be generated such that the answer is unique.\nA substring is a contiguous sequence of characters within the string.",
"examples": [
"Input: s = \"ADOBECODEBANC\", t = \"ABC\"",
"Output: \"BANC\"",
"Explanation: The minimum window substring \"BANC\" includes 'A', 'B', and 'C' from string t.",
"Input: s = \"a\", t = \"a\"",
"Output: \"a\"",
"Explanation: The entire string s is the minimum window.",
"Input: s = \"a\", t = \"aa\"",
"Output: \"\"",
"Explanation: Both 'a's from t must be included in the window.",
"Since the largest window of s only has one 'a', return empty string.",
""
],
"constraints": [
"m == s. lengthn == t. length1 <= m",
" n <= 105s and t consist of uppercase and lowercase English letters."
]
},
{
"id": "84",
"title": "Largest Rectangle in Histogram",
"question": "Given an array of integers heights representing the histogram's bar height where the width of each bar is 1, return the area of the largest rectangle in the histogram.",
"examples": [
"Input: heights = [2,1,5,6,2,3]",
"Output: 10",
"Explanation: The above is a histogram where width of each bar is 1.",
"The largest rectangle is shown in the red area, which has an area = 10 units.",
"Input: heights = [2,4]",
"Output: 4",
""
],
"constraints": [
"1 <= heights. length <= 1050 <= heights[i] <= 104"
]
},
{
"id": "85",
"title": "Maximal Rectangle",
"question": "Given a rows x cols binary matrix filled with 0's and 1's, find the largest rectangle containing only 1's and return its area.",
"examples": [
"Input: matrix = [[\"1\",\"0\",\"1\",\"0\",\"0\"],[\"1\",\"0\",\"1\",\"1\",\"1\"],[\"1\",\"1\",\"1\",\"1\",\"1\"],[\"1\",\"0\",\"0\",\"1\",\"0\"]]",
"Output: 6",
"Explanation: The maximal rectangle is shown in the above picture.",
"Input: matrix = []",
"Output: 0",
"Input: matrix = [[\"0\"]]",
"Output: 0",
"Input: matrix = [[\"1\"]]",
"Output: 1",
"Input: matrix = [[\"0\",\"0\"]]",
"Output: 0",
""
],
"constraints": [
"rows == matrix. lengthcols == matrix[i]. length0 <= row",
" cols <= 200matrix[i][j] is '0' or '1'."
]
},
{
"id": "58",
"title": "Length of Last Word",
"question": "Given a string s consisting of some words separated by some number of spaces, return the length of the last word in the string.\nA word is a maximal substring consisting of non-space characters only.",
"examples": [
"Input: s = \"Hello World\"",
"Output: 5",
"Explanation: The last word is \"World\" with length 5.",
"Input: s = \" fly me to the moon \"",
"Output: 4",
"Explanation: The last word is \"moon\" with length 4.",
"Input: s = \"luffy is still joyboy\"",
"Output: 6",
"Explanation: The last word is \"joyboy\" with length 6.",
""
],
"constraints": [
"1 <= s. length <= 104s consists of only English letters and spaces ' '. There will be at least one word in s."
]
},
{
"id": "566",
"title": "Reshape the Matrix",
"question": "In MATLAB, there is a handy function called reshape which can reshape an m x n matrix into a new one with a different size r x c keeping its original data.\nYou are given an m x n matrix mat and two integers r and c representing the number of rows and the number of columns of the wanted reshaped matrix.\nThe reshaped matrix should be filled with all the elements of the original matrix in the same row-traversing order as they were.\nIf the reshape operation with given parameters is possible and legal, output the new reshaped matrix; Otherwise, output the original matrix.",
"examples": [
"Input: mat = [[1,2],[3,4]], r = 1, c = 4",
"Output: [[1,2,3,4]]",
"Input: mat = [[1,2],[3,4]], r = 2, c = 4",
"Output: [[1,2],[3,4]]",
""
],
"constraints": [
"m == mat. lengthn == mat[i]. length1 <= m",
" n <= 100-1000 <= mat[i][j] <= 10001 <= r",
" c <= 300"
]
},
{
"id": "87",
"title": "Scramble String",
"question": "We can scramble a string s to get a string t using the following algorithm:Given two strings s1 and s2 of the same length, return true if s2 is a scrambled string of s1, otherwise, return false.",
"examples": [
"Input: s1 = \"great\", s2 = \"rgeat\"",
"Output: true",
"Explanation: One possible scenario applied on s1 is:",
"\"great\" --> \"gr/eat\" // divide at random index.",
"\"gr/eat\" --> \"gr/eat\" // random decision is not to swap the two substrings and keep them in order.",
"\"gr/eat\" --> \"g/r / e/at\" // apply the same algorithm recursively on both substrings. divide at ranom index each of them.",
"\"g/r / e/at\" --> \"r/g / e/at\" // random decision was to swap the first substring and to keep the second substring in the same order.",
"\"r/g / e/at\" --> \"r/g / e/ a/t\" // again apply the algorithm recursively, divide \"at\" to \"a/t\".",
"\"r/g / e/ a/t\" --> \"r/g / e/ a/t\" // random decision is to keep both substrings in the same order.",
"The algorithm stops now and the result string is \"rgeat\" which is s2.",
"As there is one possible scenario that led s1 to be scrambled to s2, we return true.",
"Input: s1 = \"abcde\", s2 = \"caebd\"",
"Output: false",
"Input: s1 = \"a\", s2 = \"a\"",
"Output: true",
""
],
"constraints": [
"Split the string into two non-empty substrings at a random index",
" i. e.",
" if the string is s",
" divide it to x and y where s = x + y. Randomly decide to swap the two substrings or to keep them in the same order. i. e.",
" after this step",
" s may become s = x + y or s = y + x. Apply step 1 recursively on each of the two substrings x and y. s1. length == s2. length1 <= s1. length <= 30s1 and s2 consist of lower-case English letters."
]
},
{
"id": "115",
"title": "Distinct Subsequences",
"question": "Given two strings s and t, return the number of distinct subsequences of s which equals t.\nA string's subsequence is a new string formed from the original string by deleting some (can be none) of the characters without disturbing the remaining characters' relative positions.\n (i.\ne.\n, \"ACE\" is a subsequence of \"ABCDE\" while \"AEC\" is not).\nIt is guaranteed the answer fits on a 32-bit signed integer.",
"examples": [
"Input: s = \"rabbbit\", t = \"rabbit\"",
"Output: 3",
"Explanation:",
"As shown below, there are 3 ways you can generate \"rabbit\" from S.",
"rabbbit",
"rabbbit",
"rabbbit",
"Input: s = \"babgbag\", t = \"bag\"",
"Output: 5",
"Explanation:",
"As shown below, there are 5 ways you can generate \"bag\" from S.",
"babgbag",
"babgbag",
"babgbag",
"babgbag",
"babgbag"
],
"constraints": [
"1 <= s. length",
" t. length <= 1000s and t consist of English letters."
]
},
{
"id": "123",
"title": "Best Time to Buy and Sell Stock III",
"question": "You are given an array prices where prices[i] is the price of a given stock on the ith day.\nFind the maximum profit you can achieve.\n You may complete at most two transactions.\nNote: You may not engage in multiple transactions simultaneously (i.\ne.\n, you must sell the stock before you buy again).",
"examples": [
"Input: prices = [3,3,5,0,0,3,1,4]",
"Output: 6",
"Explanation: Buy on day 4 (price = 0) and sell on day 6 (price = 3), profit = 3-0 = 3.",
"Then buy on day 7 (price = 1) and sell on day 8 (price = 4), profit = 4-1 = 3. Input: prices = [1,2,3,4,5]",
"Output: 4",
"Explanation: Buy on day 1 (price = 1) and sell on day 5 (price = 5), profit = 5-1 = 4.",
"Note that you cannot buy on day 1, buy on day 2 and sell them later, as you are engaging multiple transactions at the same time. You must sell before buying again.",
"Input: prices = [7,6,4,3,1]",
"Output: 0",
"Explanation: In this case, no transaction is done, i. e. max profit = 0.",
"Input: prices = [1]",
"Output: 0",
""
],
"constraints": [
"1 <= prices. length <= 1050 <= prices[i] <= 105"
]
},
{
"id": "124",
"title": "Binary Tree Maximum Path Sum",
"question": "A path in a binary tree is a sequence of nodes where each pair of adjacent nodes in the sequence has an edge connecting them.\n A node can only appear in the sequence at most once.\n Note that the path does not need to pass through the root.\nThe path sum of a path is the sum of the node's values in the path.\nGiven the root of a binary tree, return the maximum path sum of any path.",
"examples": [
"Input: root = [1,2,3]",
"Output: 6",
"Explanation: The optimal path is 2 -> 1 -> 3 with a path sum of 2 + 1 + 3 = 6.",
"Input: root = [-10,9,20,null,null,15,7]",
"Output: 42",
"Explanation: The optimal path is 15 -> 20 -> 7 with a path sum of 15 + 20 + 7 = 42.",
""
],
"constraints": [
"The number of nodes in the tree is in the range [1",
" 3 * 104].-1000 <= Node. val <= 1000"
]
},
{
"id": "126",
"title": "Word Ladder II",
"question": "A transformation sequence from word beginWord to word endWord using a dictionary wordList is a sequence of words beginWord -> s1 -> s2 -> .\n.\n.\n -> sk such that:Given two words, beginWord and endWord, and a dictionary wordList, return all the shortest transformation sequences from beginWord to endWord, or an empty list if no such sequence exists.\n Each sequence should be returned as a list of the words [beginWord, s1, s2, .\n.\n.\n, sk].",
"examples": [
"Input: beginWord = \"hit\", endWord = \"cog\", wordList = [\"hot\",\"dot\",\"dog\",\"lot\",\"log\",\"cog\"]",
"Output: [[\"hit\",\"hot\",\"dot\",\"dog\",\"cog\"],[\"hit\",\"hot\",\"lot\",\"log\",\"cog\"]]",
"Explanation: There are 2 shortest transformation sequences:",
"\"hit\" -> \"hot\" -> \"dot\" -> \"dog\" -> \"cog\"",
"\"hit\" -> \"hot\" -> \"lot\" -> \"log\" -> \"cog\"",
"Input: beginWord = \"hit\", endWord = \"cog\", wordList = [\"hot\",\"dot\",\"dog\",\"lot\",\"log\"]",
"Output: []",
"Explanation: The endWord \"cog\" is not in wordList, therefore there is no valid transformation sequence.",
""
],
"constraints": [
"Every adjacent pair of words differs by a single letter. Every si for 1 <= i <= k is in wordList. Note that beginWord does not need to be in wordList. sk == endWord1 <= beginWord. length <= 5endWord. length == beginWord. length1 <= wordList. length <= 1000wordList[i]. length == beginWord. lengthbeginWord",
" endWord",
" and wordList[i] consist of lowercase English letters. beginWord != endWordAll the words in wordList are unique."
]
},
{
"id": "127",
"title": "Word Ladder",
"question": "A transformation sequence from word beginWord to word endWord using a dictionary wordList is a sequence of words beginWord -> s1 -> s2 -> .\n.\n.\n -> sk such that:Given two words, beginWord and endWord, and a dictionary wordList, return the number of words in the shortest transformation sequence from beginWord to endWord, or 0 if no such sequence exists.",
"examples": [
"Input: beginWord = \"hit\", endWord = \"cog\", wordList = [\"hot\",\"dot\",\"dog\",\"lot\",\"log\",\"cog\"]",
"Output: 5",
"Explanation: One shortest transformation sequence is \"hit\" -> \"hot\" -> \"dot\" -> \"dog\" -> cog\", which is 5 words long.",
"Input: beginWord = \"hit\", endWord = \"cog\", wordList = [\"hot\",\"dot\",\"dog\",\"lot\",\"log\"]",
"Output: 0",
"Explanation: The endWord \"cog\" is not in wordList, therefore there is no valid transformation sequence.",
""
],
"constraints": [
"Every adjacent pair of words differs by a single letter. Every si for 1 <= i <= k is in wordList. Note that beginWord does not need to be in wordList. sk == endWord1 <= beginWord. length <= 10endWord. length == beginWord. length1 <= wordList. length <= 5000wordList[i]. length == beginWord. lengthbeginWord",
" endWord",
" and wordList[i] consist of lowercase English letters. beginWord != endWordAll the words in wordList are unique."
]
},
{
"id": "132",
"title": "Palindrome Partitioning II",
"question": "Given a string s, partition s such that every substring of the partition is a palindrome.\nReturn the minimum cuts needed for a palindrome partitioning of s.",
"examples": [
"Input: s = \"aab\"",
"Output: 1",
"Explanation: The palindrome partitioning [\"aa\",\"b\"] could be produced using 1 cut.",
"Input: s = \"a\"",
"Output: 0",
"Input: s = \"ab\"",
"Output: 1",
""
],
"constraints": [
"1 <= s. length <= 2000s consists of lower-case English letters only."
]
},
{
"id": "135",
"title": "Candy",
"question": "There are n children standing in a line.\n Each child is assigned a rating value given in the integer array ratings.\nYou are giving candies to these children subjected to the following requirements:Return the minimum number of candies you need to have to distribute the candies to the children.",
"examples": [
"Input: ratings = [1,0,2]",
"Output: 5",
"Explanation: You can allocate to the first, second and third child with 2, 1, 2 candies respectively.",
"Input: ratings = [1,2,2]",
"Output: 4",
"Explanation: You can allocate to the first, second and third child with 1, 2, 1 candies respectively.",
"The third child gets 1 candy because it satisfies the above two conditions.",
""
],
"constraints": [
"Each child must have at least one candy. Children with a higher rating get more candies than their neighbors. n == ratings. length1 <= n <= 2 * 1040 <= ratings[i] <= 2 * 104"
]
},
{
"id": "140",
"title": "Word Break II",
"question": "Given a string s and a dictionary of strings wordDict, add spaces in s to construct a sentence where each word is a valid dictionary word.\n Return all such possible sentences in any order.\nNote that the same word in the dictionary may be reused multiple times in the segmentation.",
"examples": [
"Input: s = \"catsanddog\", wordDict = [\"cat\",\"cats\",\"and\",\"sand\",\"dog\"]",
"Output: [\"cats and dog\",\"cat sand dog\"]",
"Input: s = \"pineapplepenapple\", wordDict = [\"apple\",\"pen\",\"applepen\",\"pine\",\"pineapple\"]",
"Output: [\"pine apple pen apple\",\"pineapple pen apple\",\"pine applepen apple\"]",
"Explanation: Note that you are allowed to reuse a dictionary word.",
"Input: s = \"catsandog\", wordDict = [\"cats\",\"dog\",\"sand\",\"and\",\"cat\"]",
"Output: []",
""
],
"constraints": [
"1 <= s. length <= 201 <= wordDict. length <= 10001 <= wordDict[i]. length <= 10s and wordDict[i] consist of only lowercase English letters. All the strings of wordDict are unique."
]
},
{
"id": "149",
"title": "Max Points on a Line",
"question": "Given an array of points where points[i] = [xi, yi] represents a point on the X-Y plane, return the maximum number of points that lie on the same straight line.",
"examples": [
"Input: points = [[1,1],[2,2],[3,3]]",
"Output: 3",
"Input: points = [[1,1],[3,2],[5,3],[4,1],[2,3],[1,4]]",
"Output: 4",
""
],
"constraints": [
"1 <= points. length <= 300points[i]. length == 2-104 <= xi",
" yi <= 104All the points are unique."
]
},
{
"id": "572",
"title": "Subtree of Another Tree",
"question": "Given the roots of two binary trees root and subRoot, return true if there is a subtree of root with the same structure and node values of subRoot and false otherwise.\nA subtree of a binary tree tree is a tree that consists of a node in tree and all of this node's descendants.\n The tree tree could also be considered as a subtree of itself.",
"examples": [
"Input: root = [3,4,5,1,2], subRoot = [4,1,2]",
"Output: true",
"Input: root = [3,4,5,1,2,null,null,null,null,0], subRoot = [4,1,2]",
"Output: false",
""
],
"constraints": [
"The number of nodes in the root tree is in the range [1",
" 2000]. The number of nodes in the subRoot tree is in the range [1",
" 1000].-104 <= root. val <= 104-104 <= subRoot. val <= 104"
]
},
{
"id": "154",
"title": "Find Minimum in Rotated Sorted Array II",
"question": "Suppose an array of length n sorted in ascending order is rotated between 1 and n times.\n For example, the array nums = [0,1,4,4,5,6,7] might become:Notice that rotating an array [a[0], a[1], a[2], .\n.\n.\n, a[n-1]] 1 time results in the array [a[n-1], a[0], a[1], a[2], .\n.\n.\n, a[n-2]].\nGiven the sorted rotated array nums that may contain duplicates, return the minimum element of this array.\nYou must decrease the overall operation steps as much as possible.\n   Follow up: This problem is similar to Find Minimum in Rotated Sorted Array, but nums may contain duplicates.\n Would this affect the runtime complexity? How and why?",
"examples": [
"Input: nums = [1,3,5]",
"Output: 1",
"Input: nums = [2,2,2,0,1]",
"Output: 0",
""
],
"constraints": [
"[4",
"5",
"6",
"7",
"0",
"1",
"4] if it was rotated 4 times.[0",
"1",
"4",
"4",
"5",
"6",
"7] if it was rotated 7 times. n == nums. length1 <= n <= 5000-5000 <= nums[i] <= 5000nums is sorted and rotated between 1 and n times."
]
},
{
"id": "164",
"title": "Maximum Gap",
"question": "Given an integer array nums, return the maximum difference between two successive elements in its sorted form.\n If the array contains less than two elements, return 0.\nYou must write an algorithm that runs in linear time and uses linear extra space.",
"examples": [
"Input: nums = [3,6,9,1]",
"Output: 3",
"Explanation: The sorted form of the array is [1,3,6,9], either (3,6) or (6,9) has the maximum difference 3.",
"Input: nums = [10]",
"Output: 0",
"Explanation: The array contains less than 2 elements, therefore return 0.",
""
],
"constraints": [
"1 <= nums. length <= 1050 <= nums[i] <= 109"
]
},
{
"id": "174",
"title": "Dungeon Game",
"question": "The demons had captured the princess and imprisoned her in the bottom-right corner of a dungeon.\n The dungeon consists of m x n rooms laid out in a 2D grid.\n Our valiant knight was initially positioned in the top-left room and must fight his way through dungeon to rescue the princess.\nThe knight has an initial health point represented by a positive integer.\n If at any point his health point drops to 0 or below, he dies immediately.\nSome of the rooms are guarded by demons (represented by negative integers), so the knight loses health upon entering these rooms; other rooms are either empty (represented as 0) or contain magic orbs that increase the knight's health (represented by positive integers).\nTo reach the princess as quickly as possible, the knight decides to move only rightward or downward in each step.\nReturn the knight's minimum initial health so that he can rescue the princess.\nNote that any room can contain threats or power-ups, even the first room the knight enters and the bottom-right room where the princess is imprisoned.",
"examples": [
"Input: dungeon = [[-2,-3,3],[-5,-10,1],[10,30,-5]]",
"Output: 7",
"Explanation: The initial health of the knight must be at least 7 if he follows the optimal path: RIGHT-> RIGHT -> DOWN -> DOWN.",
"Input: dungeon = [[0]]",
"Output: 1",
""
],
"constraints": [
"m == dungeon. lengthn == dungeon[i]. length1 <= m",
" n <= 200-1000 <= dungeon[i][j] <= 1000"
]
},
{
"id": "188",
"title": "Best Time to Buy and Sell Stock IV",
"question": "You are given an integer array prices where prices[i] is the price of a given stock on the ith day, and an integer k.\nFind the maximum profit you can achieve.\n You may complete at most k transactions.\nNote: You may not engage in multiple transactions simultaneously (i.\ne.\n, you must sell the stock before you buy again).",
"examples": [
"Input: k = 2, prices = [2,4,1]",
"Output: 2",
"Explanation: Buy on day 1 (price = 2) and sell on day 2 (price = 4), profit = 4-2 = 2.",
"Input: k = 2, prices = [3,2,6,5,0,3]",
"Output: 7",
"Explanation: Buy on day 2 (price = 2) and sell on day 3 (price = 6), profit = 6-2 = 4. Then buy on day 5 (price = 0) and sell on day 6 (price = 3), profit = 3-0 = 3.",
""
],
"constraints": [
"0 <= k <= 1000 <= prices. length <= 10000 <= prices[i] <= 1000"
]
},
{
"id": "212",
"title": "Word Search II",
"question": "Given an m x n board of characters and a list of strings words, return all words on the board.\nEach word must be constructed from letters of sequentially adjacent cells, where adjacent cells are horizontally or vertically neighboring.\n The same letter cell may not be used more than once in a word.",
"examples": [
"Input: board = [[\"o\",\"a\",\"a\",\"n\"],[\"e\",\"t\",\"a\",\"e\"],[\"i\",\"h\",\"k\",\"r\"],[\"i\",\"f\",\"l\",\"v\"]], words = [\"oath\",\"pea\",\"eat\",\"rain\"]",
"Output: [\"eat\",\"oath\"]",
"Input: board = [[\"a\",\"b\"],[\"c\",\"d\"]], words = [\"abcb\"]",
"Output: []",
""
],
"constraints": [
"m == board. lengthn == board[i]. length1 <= m",
" n <= 12board[i][j] is a lowercase English letter. 1 <= words. length <= 3 * 1041 <= words[i]. length <= 10words[i] consists of lowercase English letters. All the strings of words are unique."
]
},
{
"id": "214",
"title": "Shortest Palindrome",
"question": "You are given a string s.\n You can convert s to a palindrome by adding characters in front of it.\nReturn the shortest palindrome you can find by performing this transformation.",
"examples": [
"Input: s = \"aacecaaa\"",
"Output: \"aaacecaaa\"",
"Input: s = \"abcd\"",
"Output: \"dcbabcd\"",
""
],
"constraints": [
"0 <= s. length <= 5 * 104s consists of lowercase English letters only."
]
},
{
"id": "218",
"title": "The Skyline Problem",
"question": "A city's skyline is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance.\n Given the locations and heights of all the buildings, return the skyline formed by these buildings collectively.\nThe geometric information of each building is given in the array buildings where buildings[i] = [lefti, righti, heighti]:You may assume all buildings are perfect rectangles grounded on an absolutely flat surface at height 0.\nThe skyline should be represented as a list of \"key points\" sorted by their x-coordinate in the form [[x1,y1],[x2,y2],.\n.\n.\n].\n Each key point is the left endpoint of some horizontal segment in the skyline except the last point in the list, which always has a y-coordinate 0 and is used to mark the skyline's termination where the rightmost building ends.\n Any ground between the leftmost and rightmost buildings should be part of the skyline's contour.\nNote: There must be no consecutive horizontal lines of equal height in the output skyline.\n For instance, [.\n.\n.\n,[2 3],[4 5],[7 5],[11 5],[12 7],.\n.\n.\n] is not acceptable; the three lines of height 5 should be merged into one in the final output as such: [.\n.\n.\n,[2 3],[4 5],[12 7],.\n.\n.\n]",
"examples": [
"Input: buildings = [[2,9,10],[3,7,15],[5,12,12],[15,20,10],[19,24,8]]",
"Output: [[2,10],[3,15],[7,12],[12,0],[15,10],[20,8],[24,0]]",
"Explanation:",
"Figure A shows the buildings of the input.",
"Figure B shows the skyline formed by those buildings. The red points in figure B represent the key points in the output list.",
"Input: buildings = [[0,2,3],[2,5,3]]",
"Output: [[0,3],[5,0]]",
""
],
"constraints": [
"lefti is the x coordinate of the left edge of the ith building. righti is the x coordinate of the right edge of the ith building. heighti is the height of the ith building. 1 <= buildings. length <= 1040 <= lefti < righti <= 231 - 11 <= heighti <= 231 - 1buildings is sorted by lefti in non-decreasing order."
]
},
{
"id": "224",
"title": "Basic Calculator",
"question": "Given a string s representing a valid expression, implement a basic calculator to evaluate it, and return the result of the evaluation.\nNote: You are not allowed to use any built-in function which evaluates strings as mathematical expressions, such as eval().",
"examples": [
"Input: s = \"1 + 1\"",
"Output: 2",
"Input: s = \" 2-1 + 2 \"",
"Output: 3",
"Input: s = \"(1+(4+5+2)-3)+(6+8)\"",
"Output: 23",
""
],
"constraints": [
"1 <= s. length <= 3 * 105s consists of digits",
" '+'",
" '-'",
" '('",
" ')'",
" and ' '. s represents a valid expression.'+' is not used as a unary operation.'-' could be used as a unary operation but it has to be inside parentheses. There will be no two consecutive operators in the input. Every number and running calculation will fit in a signed 32-bit integer."
]
},
{
"id": "233",
"title": "Number of Digit One",
"question": "Given an integer n, count the total number of digit 1 appearing in all non-negative integers less than or equal to n.",
"examples": [
"Input: n = 13",
"Output: 6",
"Input: n = 0",
"Output: 0",
""
],
"constraints": [
"0 <= n <= 109"
]
},
{
"id": "239",
"title": "Sliding Window Maximum",
"question": "You are given an array of integers nums, there is a sliding window of size k which is moving from the very left of the array to the very right.\n You can only see the k numbers in the window.\n Each time the sliding window moves right by one position.\nReturn the max sliding window.",
"examples": [
"Input: nums = [1,3,-1,-3,5,3,6,7], k = 3",
"Output: [3,3,5,5,6,7]",
"Explanation: ",
"Window position Max",
"--------------- -----",
"[1 3 -1] -3 5 3 6 7 3",
" 1 [3 -1 -3] 5 3 6 7 3",
" 1 3 [-1 -3 5] 3 6 7 5",
" 1 3 -1 [-3 5 3] 6 7 5",
" 1 3 -1 -3 [5 3 6] 7 6",
" 1 3 -1 -3 5 [3 6 7] 7",
"Input: nums = [1], k = 1",
"Output: [1]",
"Input: nums = [1,-1], k = 1",
"Output: [1,-1]",
"Input: nums = [9,11], k = 2",
"Output: [11]",
"Input: nums = [4,-2], k = 2",
"Output: [4]",
""
],
"constraints": [
"1 <= nums. length <= 105-104 <= nums[i] <= 1041 <= k <= nums. length"
]
},
{
"id": "575",
"title": "Distribute Candies",
"question": "Alice has n candies, where the ith candy is of type candyType[i].\n Alice noticed that she started to gain weight, so she visited a doctor.\nThe doctor advised Alice to only eat n / 2 of the candies she has (n is always even).\n Alice likes her candies very much, and she wants to eat the maximum number of different types of candies while still following the doctor's advice.\nGiven the integer array candyType of length n, return the maximum number of different types of candies she can eat if she only eats n / 2 of them.",
"examples": [
"Input: candyType = [1,1,2,2,3,3]",
"Output: 3",
"Explanation: Alice can only eat 6 / 2 = 3 candies. Since there are only 3 types, she can eat one of each type.",
"Input: candyType = [1,1,2,3]",
"Output: 2",
"Explanation: Alice can only eat 4 / 2 = 2 candies. Whether she eats types [1,2], [1,3], or [2,3], she still can only eat 2 different types.",
"Input: candyType = [6,6,6,6]",
"Output: 1",
"Explanation: Alice can only eat 4 / 2 = 2 candies. Even though she can eat 2 candies, she only has 1 type.",
""
],
"constraints": [
"n == candyType. length2 <= n <= 104n is even.-105 <= candyType[i] <= 105"
]
},
{
"id": "273",
"title": "Integer to English Words",
"question": "Convert a non-negative integer num to its English words representation.",
"examples": [
"Input: num = 123",
"Output: \"One Hundred Twenty Three\"",
"Input: num = 12345",
"Output: \"Twelve Thousand Three Hundred Forty Five\"",
"Input: num = 1234567",
"Output: \"One Million Two Hundred Thirty Four Thousand Five Hundred Sixty Seven\"",
"Input: num = 1234567891",
"Output: \"One Billion Two Hundred Thirty Four Million Five Hundred Sixty Seven Thousand Eight Hundred Ninety One\"",
""
],
"constraints": [
"0 <= num <= 231 - 1"
]
},
{
"id": "282",
"title": "Expression Add Operators",
"question": "Given a string num that contains only digits and an integer target, return all possibilities to add the binary operators '+', '-', or '*' between the digits of num so that the resultant expression evaluates to the target value.",
"examples": [
"Input: num = \"123\", target = 6",
"Output: [\"1*2*3\",\"1+2+3\"]",
"Input: num = \"232\", target = 8",
"Output: [\"2*3+2\",\"2+3*2\"]",
"Input: num = \"105\", target = 5",
"Output: [\"1*0+5\",\"10-5\"]",
"Input: num = \"00\", target = 0",
"Output: [\"0*0\",\"0+0\",\"0-0\"]",
"Input: num = \"3456237490\", target = 9191",
"Output: []",
""
],
"constraints": [
"1 <= num. length <= 10num consists of only digits.-231 <= target <= 231 - 1"
]
},
{
"id": "295",
"title": "Find Median from Data Stream",
"question": "The median is the middle value in an ordered integer list.\n If the size of the list is even, there is no middle value and the median is the mean of the two middle values.\nImplement the MedianFinder class:   Follow up:",
"examples": [
"Input",
"[\"MedianFinder\", \"addNum\", \"addNum\", \"findMedian\", \"addNum\", \"findMedian\"]",
"[[], [1], [2], [], [3], []]",
"Output",
"[null, null, null, 1. 5, null, 2. 0]",
"",
"Explanation",
"MedianFinder medianFinder = new MedianFinder();",
"medianFinder. addNum(1); // arr = [1]",
"medianFinder. addNum(2); // arr = [1, 2]",
"medianFinder. findMedian(); // return 1. 5 (i. e., (1 + 2) / 2)",
"medianFinder. addNum(3); // arr[1, 2, 3]",
"medianFinder. findMedian(); // return 2. 0",
""
],
"constraints": [
"For example",
" for arr = [2",
"3",
"4]",
" the median is 3. For example",
" for arr = [2",
"3]",
" the median is (2 + 3) / 2 = 2. 5. MedianFinder() initializes the MedianFinder object. void addNum(int num) adds the integer num from the data stream to the data structure. double findMedian() returns the median of all elements so far. Answers within 10-5 of the actual answer will be accepted.-105 <= num <= 105There will be at least one element in the data structure before calling findMedian. At most 5 * 104 calls will be made to addNum and findMedian. If all integer numbers from the stream are in the range [0",
" 100]",
" how would you optimize your solution?If 99% of all integer numbers from the stream are in the range [0",
" 100]",
" how would you optimize your solution?"
]
},
{
"id": "297",
"title": "Serialize and Deserialize Binary Tree",
"question": "Serialization is the process of converting a data structure or object into a sequence of bits so that it can be stored in a file or memory buffer, or transmitted across a network connection link to be reconstructed later in the same or another computer environment.\nDesign an algorithm to serialize and deserialize a binary tree.\n There is no restriction on how your serialization/deserialization algorithm should work.\n You just need to ensure that a binary tree can be serialized to a string and this string can be deserialized to the original tree structure.\nClarification: The input/output format is the same as how LeetCode serializes a binary tree.\n You do not necessarily need to follow this format, so please be creative and come up with different approaches yourself.",
"examples": [
"Input: root = [1,2,3,null,null,4,5]",
"Output: [1,2,3,null,null,4,5]",
"Input: root = []",
"Output: []",
"Input: root = [1]",
"Output: [1]",
"Input: root = [1,2]",
"Output: [1,2]",
""
],
"constraints": [
"The number of nodes in the tree is in the range [0",
" 104].-1000 <= Node. val <= 1000"
]
},
{
"id": "301",
"title": "Remove Invalid Parentheses",
"question": "Given a string s that contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid.\nReturn all the possible results.\n You may return the answer in any order.",
"examples": [
"Input: s = \"()())()\"",
"Output: [\"(())()\",\"()()()\"]",
"Input: s = \"(a)())()\"",
"Output: [\"(a())()\",\"(a)()()\"]",
"Input: s = \")(\"",
"Output: [\"\"]",
""
],
"constraints": [
"1 <= s. length <= 25s consists of lowercase English letters and parentheses '(' and ')'. There will be at most 20 parentheses in s."
]
},
{
"id": "312",
"title": "Burst Balloons",
"question": "You are given n balloons, indexed from 0 to n - 1.\n Each balloon is painted with a number on it represented by an array nums.\n You are asked to burst all the balloons.\nIf you burst the ith balloon, you will get nums[i - 1] * nums[i] * nums[i + 1] coins.\n If i - 1 or i + 1 goes out of bounds of the array, then treat it as if there is a balloon with a 1 painted on it.\nReturn the maximum coins you can collect by bursting the balloons wisely.",
"examples": [
"Input: nums = [3,1,5,8]",
"Output: 167",
"Explanation:",
"nums = [3,1,5,8] --> [3,5,8] --> [3,8] --> [8] --> []",
"coins = 3*1*5 + 3*5*8 + 1*3*8 + 1*8*1 = 167Input: nums = [1,5]",
"Output: 10",
""
],
"constraints": [
"n == nums. length1 <= n <= 5000 <= nums[i] <= 100"
]
},
{
"id": "315",
"title": "Count of Smaller Numbers After Self",
"question": "You are given an integer array nums and you have to return a new counts array.\n The counts array has the property where counts[i] is the number of smaller elements to the right of nums[i].",
"examples": [
"Input: nums = [5,2,6,1]",
"Output: [2,1,1,0]",
"Explanation:",
"To the right of 5 there are 2 smaller elements (2 and 1).",
"To the right of 2 there is only 1 smaller element (1).",
"To the right of 6 there is 1 smaller element (1).",
"To the right of 1 there is 0 smaller element.",
"Input: nums = [-1]",
"Output: [0]",
"Input: nums = [-1,-1]",
"Output: [0,0]",
""
],
"constraints": [
"1 <= nums. length <= 105-104 <= nums[i] <= 104"
]
},
{
"id": "321",
"title": "Create Maximum Number",
"question": "You are given two integer arrays nums1 and nums2 of lengths m and n respectively.\n nums1 and nums2 represent the digits of two numbers.\n You are also given an integer k.\nCreate the maximum number of length k <= m + n from digits of the two numbers.\n The relative order of the digits from the same array must be preserved.\nReturn an array of the k digits representing the answer.",
"examples": [
"Input: nums1 = [3,4,6,5], nums2 = [9,1,2,5,8,3], k = 5",
"Output: [9,8,6,5,3]",
"Input: nums1 = [6,7], nums2 = [6,0,4], k = 5",
"Output: [6,7,6,0,4]",
"Input: nums1 = [3,9], nums2 = [8,9], k = 3",
"Output: [9,8,9]",
""
],
"constraints": [
"m == nums1. lengthn == nums2. length1 <= m",
" n <= 5000 <= nums1[i]",
" nums2[i] <= 91 <= k <= m + n"
]
},
{
"id": "327",
"title": "Count of Range Sum",
"question": "Given an integer array nums and two integers lower and upper, return the number of range sums that lie in [lower, upper] inclusive.\nRange sum S(i, j) is defined as the sum of the elements in nums between indices i and j inclusive, where i <= j.",
"examples": [
"Input: nums = [-2,5,-1], lower = -2, upper = 2",
"Output: 3",
"Explanation: The three ranges are: [0,0], [2,2], and [0,2] and their respective sums are: -2, -1, 2.",
"Input: nums = [0], lower = 0, upper = 0",
"Output: 1",
""
],
"constraints": [
"1 <= nums. length <= 105-231 <= nums[i] <= 231 - 1-105 <= lower <= upper <= 105The answer is guaranteed to fit in a 32-bit integer."
]
},
{
"id": "329",
"title": "Longest Increasing Path in a Matrix",
"question": "Given an m x n integers matrix, return the length of the longest increasing path in matrix.\nFrom each cell, you can either move in four directions: left, right, up, or down.\n You may not move diagonally or move outside the boundary (i.\ne.\n, wrap-around is not allowed).",
"examples": [
"Input: matrix = [[9,9,4],[6,6,8],[2,1,1]]",
"Output: 4",
"Explanation: The longest increasing path is [1, 2, 6, 9].",
"Input: matrix = [[3,4,5],[3,2,6],[2,2,1]]",
"Output: 4",
"Explanation: The longest increasing path is [3, 4, 5, 6]. Moving diagonally is not allowed.",
"Input: matrix = [[1]]",
"Output: 1",
""
],
"constraints": [
"m == matrix. lengthn == matrix[i]. length1 <= m",
" n <= 2000 <= matrix[i][j] <= 231 - 1"
]
},
{
"id": "589",
"title": "N-ary Tree Preorder Traversal",
"question": "Given the root of an n-ary tree, return the preorder traversal of its nodes' values.\nNary-Tree input serialization is represented in their level order traversal.\n Each group of children is separated by the null value (See examples)   Follow up: Recursive solution is trivial, could you do it iteratively?",
"examples": [
"Input: root = [1,null,3,2,4,null,5,6]",
"Output: [1,3,5,6,2,4]",
"Input: root = [1,null,2,3,4,5,null,null,6,7,null,8,null,9,10,null,null,11,null,12,null,13,null,null,14]",
"Output: [1,2,3,6,7,11,14,4,8,12,5,9,13,10]",
""
],
"constraints": [
"The number of nodes in the tree is in the range [0",
" 104]. 0 <= Node. val <= 104The height of the n-ary tree is less than or equal to 1000."
]
},
{
"id": "330",
"title": "Patching Array",
"question": "Given a sorted integer array nums and an integer n, add/patch elements to the array such that any number in the range [1, n] inclusive can be formed by the sum of some elements in the array.\nReturn the minimum number of patches required.",
"examples": [
"Input: nums = [1,3], n = 6",
"Output: 1",
"Explanation:",
"Combinations of nums are [1], [3], [1,3], which form possible sums of: 1, 3, 4.",
"Now if we add/patch 2 to nums, the combinations are: [1], [2], [3], [1,3], [2,3], [1,2,3].",
"Possible sums are 1, 2, 3, 4, 5, 6, which now covers the range [1, 6].",
"So we only need 1 patch.",
"Input: nums = [1,5,10], n = 20",
"Output: 2",
"Explanation: The two patches can be [2, 4].",
"Input: nums = [1,2,2], n = 5",
"Output: 0",
""
],
"constraints": [
"1 <= nums. length <= 10001 <= nums[i] <= 104nums is sorted in ascending order. 1 <= n <= 231 - 1"
]
},
{
"id": "335",
"title": "Self Crossing",
"question": "You are given an array of integers distance.\nYou start at point (0,0) on an X-Y plane and you move distance[0] meters to the north, then distance[1] meters to the west, distance[2] meters to the south, distance[3] meters to the east, and so on.\n In other words, after each move, your direction changes counter-clockwise.\nReturn true if your path crosses itself, and false if it does not.",
"examples": [
"Input: distance = [2,1,1,2]",
"Output: true",
"Input: distance = [1,2,3,4]",
"Output: false",
"Input: distance = [1,1,1,1]",
"Output: true",
""
],
"constraints": [
"1 <= distance. length <= 1051 <= distance[i] <= 105"
]
},
{
"id": "336",
"title": "Palindrome Pairs",
"question": "Given a list of unique words, return all the pairs of the distinct indices (i, j) in the given list, so that the concatenation of the two words words[i] + words[j] is a palindrome.",
"examples": [
"Input: words = [\"abcd\",\"dcba\",\"lls\",\"s\",\"sssll\"]",
"Output: [[0,1],[1,0],[3,2],[2,4]]",
"Explanation: The palindromes are [\"dcbaabcd\",\"abcddcba\",\"slls\",\"llssssll\"]",
"Input: words = [\"bat\",\"tab\",\"cat\"]",
"Output: [[0,1],[1,0]]",
"Explanation: The palindromes are [\"battab\",\"tabbat\"]",
"Input: words = [\"a\",\"\"]",
"Output: [[0,1],[1,0]]",
""
],
"constraints": [
"1 <= words. length <= 50000 <= words[i]. length <= 300words[i] consists of lower-case English letters."
]
},
{
"id": "352",
"title": "Data Stream as Disjoint Intervals",
"question": "Given a data stream input of non-negative integers a1, a2, .\n.\n.\n, an, summarize the numbers seen so far as a list of disjoint intervals.\nImplement the SummaryRanges class:   Follow up: What if there are lots of merges and the number of disjoint intervals is small compared to the size of the data stream?",
"examples": [
"Input",
"[\"SummaryRanges\", \"addNum\", \"getIntervals\", \"addNum\", \"getIntervals\", \"addNum\", \"getIntervals\", \"addNum\", \"getIntervals\", \"addNum\", \"getIntervals\"]",
"[[], [1], [], [3], [], [7], [], [2], [], [6], []]",
"Output",
"[null, null, [[1, 1]], null, [[1, 1], [3, 3]], null, [[1, 1], [3, 3], [7, 7]], null, [[1, 3], [7, 7]], null, [[1, 3], [6, 7]]]",
"",
"Explanation",
"SummaryRanges summaryRanges = new SummaryRanges();",
"summaryRanges. addNum(1); // arr = [1]",
"summaryRanges. getIntervals(); // return [[1, 1]]",
"summaryRanges. addNum(3); // arr = [1, 3]",
"summaryRanges. getIntervals(); // return [[1, 1], [3, 3]]",
"summaryRanges. addNum(7); // arr = [1, 3, 7]",
"summaryRanges. getIntervals(); // return [[1, 1], [3, 3], [7, 7]]",
"summaryRanges. addNum(2); // arr = [1, 2, 3, 7]",
"summaryRanges. getIntervals(); // return [[1, 3], [7, 7]]",
"summaryRanges. addNum(6); // arr = [1, 2, 3, 6, 7]",
"summaryRanges. getIntervals(); // return [[1, 3], [6, 7]]",
""
],
"constraints": [
"SummaryRanges() Initializes the object with an empty stream. void addNum(int val) Adds the integer val to the stream. int[][] getIntervals() Returns a summary of the integers in the stream currently as a list of disjoint intervals [starti",
" endi]. 0 <= val <= 104At most 3 * 104 calls will be made to addNum and getIntervals."
]
},
{
"id": "354",
"title": "Russian Doll Envelopes",
"question": "You are given a 2D array of integers envelopes where envelopes[i] = [wi, hi] represents the width and the height of an envelope.\nOne envelope can fit into another if and only if both the width and height of one envelope are greater than the other envelope's width and height.\nReturn the maximum number of envelopes you can Russian doll (i.\ne.\n, put one inside the other).\nNote: You cannot rotate an envelope.",
"examples": [
"Input: envelopes = [[5,4],[6,4],[6,7],[2,3]]",
"Output: 3",
"Explanation: The maximum number of envelopes you can Russian doll is 3 ([2,3] => [5,4] => [6,7]).",
"Input: envelopes = [[1,1],[1,1],[1,1]]",
"Output: 1",
""
],
"constraints": [
"1 <= envelopes. length <= 5000envelopes[i]. length == 21 <= wi",
" hi <= 104"
]
},
{
"id": "363",
"title": "Max Sum of Rectangle No Larger Than K",
"question": "Given an m x n matrix matrix and an integer k, return the max sum of a rectangle in the matrix such that its sum is no larger than k.\nIt is guaranteed that there will be a rectangle with a sum no larger than k.\n   Follow up: What if the number of rows is much larger than the number of columns?",
"examples": [
"Input: matrix = [[1,0,1],[0,-2,3]], k = 2",
"Output: 2",
"Explanation: Because the sum of the blue rectangle [[0, 1], [-2, 3]] is 2, and 2 is the max number no larger than k (k = 2).",
"Input: matrix = [[2,2,-1]], k = 3",
"Output: 3",
""
],
"constraints": [
"m == matrix. lengthn == matrix[i]. length1 <= m",
" n <= 100-100 <= matrix[i][j] <= 100-105 <= k <= 105"
]
},
{
"id": "381",
"title": "Insert Delete GetRandom O(1) - Duplicates allowed",
"question": "Implement the RandomizedCollection class:You must implement the functions of the class such that each function works in average O(1) time complexity.",
"examples": [
"Input",
"[\"RandomizedCollection\", \"insert\", \"insert\", \"insert\", \"getRandom\", \"remove\", \"getRandom\"]",
"[[], [1], [1], [2], [], [1], []]",
"Output",
"[null, true, false, true, 2, true, 1]",
"",
"Explanation",
"RandomizedCollection randomizedCollection = new RandomizedCollection();",
"randomizedCollection. insert(1); // return True. Inserts 1 to the collection. Returns true as the collection did not contain 1.",
"randomizedCollection. insert(1); // return False. Inserts another 1 to the collection. Returns false as the collection contained 1. Collection now contains [1,1].",
"randomizedCollection. insert(2); // return True. Inserts 2 to the collection, returns true. Collection now contains [1,1,2].",
"randomizedCollection. getRandom(); // getRandom should return 1 with the probability 2/3, and returns 2 with the probability 1/3.",
"randomizedCollection. remove(1); // return True. Removes 1 from the collection, returns true. Collection now contains [1,2].",
"randomizedCollection. getRandom(); // getRandom should return 1 and 2 both equally likely.",
""
],
"constraints": [
"RandomizedCollection() Initializes the RandomizedCollection object. bool insert(int val) Inserts an item val into the multiset if not present. Returns true if the item was not present",
" false otherwise. bool remove(int val) Removes an item val from the multiset if present. Returns true if the item was present",
" false otherwise. Note that if val has multiple occurrences in the multiset",
" we only remove one of them. int getRandom() Returns a random element from the current multiset of elements (it's guaranteed that at least one element exists when this method is called). The probability of each element being returned is linearly related to the number of same values the multiset contains.-231 <= val <= 231 - 1At most 2 * 105  calls will be made to insert",
" remove",
" and getRandom. There will be at least one element in the data structure when getRandom is called."
]
},
{
"id": "391",
"title": "Perfect Rectangle",
"question": "Given an array rectangles where rectangles[i] = [xi, yi, ai, bi] represents an axis-aligned rectangle.\n The bottom-left point of the rectangle is (xi, yi) and the top-right point of it is (ai, bi).\nReturn true if all the rectangles together form an exact cover of a rectangular region.",
"examples": [
"Input: rectangles = [[1,1,3,3],[3,1,4,2],[3,2,4,4],[1,3,2,4],[2,3,3,4]]",
"Output: true",
"Explanation: All 5 rectangles together form an exact cover of a rectangular region.",
"Input: rectangles = [[1,1,2,3],[1,3,2,4],[3,1,4,2],[3,2,4,4]]",
"Output: false",
"Explanation: Because there is a gap between the two rectangular regions.",
"Input: rectangles = [[1,1,3,3],[3,1,4,2],[1,3,2,4],[3,2,4,4]]",
"Output: false",
"Explanation: Because there is a gap in the top center.",
"Input: rectangles = [[1,1,3,3],[3,1,4,2],[1,3,2,4],[2,2,4,4]]",
"Output: false",
"Explanation: Because two of the rectangles overlap with each other.",
""
],
"constraints": [
"1 <= rectangles. length <= 2 * 104rectangles[i]. length == 4-105 <= xi",
" yi",
" ai",
" bi <= 105"
]
},
{
"id": "403",
"title": "Frog Jump",
"question": "A frog is crossing a river.\n The river is divided into some number of units, and at each unit, there may or may not exist a stone.\n The frog can jump on a stone, but it must not jump into the water.\nGiven a list of stones' positions (in units) in sorted ascending order, determine if the frog can cross the river by landing on the last stone.\n Initially, the frog is on the first stone and assumes the first jump must be 1 unit.\nIf the frog's last jump was k units, its next jump must be either k - 1, k, or k + 1 units.\n The frog can only jump in the forward direction.",
"examples": [
"Input: stones = [0,1,3,5,6,8,12,17]",
"Output: true",
"Explanation: The frog can jump to the last stone by jumping 1 unit to the 2nd stone, then 2 units to the 3rd stone, then 2 units to the 4th stone, then 3 units to the 6th stone, 4 units to the 7th stone, and 5 units to the 8th stone.",
"Input: stones = [0,1,2,3,4,8,9,11]",
"Output: false",
"Explanation: There is no way to jump to the last stone as the gap between the 5th and 6th stone is too large.",
""
],
"constraints": [
"2 <= stones. length <= 20000 <= stones[i] <= 231 - 1stones[0] == 0stones is sorted in a strictly increasing order."
]
},
{
"id": "407",
"title": "Trapping Rain Water II",
"question": "Given an m x n integer matrix heightMap representing the height of each unit cell in a 2D elevation map, return the volume of water it can trap after raining.",
"examples": [
"Input: heightMap = [[1,4,3,1,3,2],[3,2,1,3,2,4],[2,3,3,2,3,1]]",
"Output: 4",
"Explanation: After the rain, water is trapped between the blocks.",
"We have two small pounds 1 and 3 units trapped.",
"The total volume of water trapped is 4.",
"Input: heightMap = [[3,3,3,3,3],[3,2,2,2,3],[3,2,1,2,3],[3,2,2,2,3],[3,3,3,3,3]]",
"Output: 10",
""
],
"constraints": [
"m == heightMap. lengthn == heightMap[i]. length1 <= m",
" n <= 2000 <= heightMap[i][j] <= 2 * 104"
]
},
{
"id": "590",
"title": "N-ary Tree Postorder Traversal",
"question": "Given the root of an n-ary tree, return the postorder traversal of its nodes' values.\nNary-Tree input serialization is represented in their level order traversal.\n Each group of children is separated by the null value (See examples)   Follow up: Recursive solution is trivial, could you do it iteratively?",
"examples": [
"Input: root = [1,null,3,2,4,null,5,6]",
"Output: [5,6,3,2,4,1]",
"Input: root = [1,null,2,3,4,5,null,null,6,7,null,8,null,9,10,null,null,11,null,12,null,13,null,null,14]",
"Output: [2,6,14,11,7,3,12,8,4,13,9,10,5,1]",
""
],
"constraints": [
"The number of nodes in the tree is in the range [0",
" 104]. 0 <= Node. val <= 104The height of the n-ary tree is less than or equal to 1000."
]
},
{
"id": "410",
"title": "Split Array Largest Sum",
"question": "Given an array nums which consists of non-negative integers and an integer m, you can split the array into m non-empty continuous subarrays.\nWrite an algorithm to minimize the largest sum among these m subarrays.",
"examples": [
"Input: nums = [7,2,5,10,8], m = 2",
"Output: 18",
"Explanation:",
"There are four ways to split nums into two subarrays.",
"The best way is to split it into [7,2,5] and [10,8],",
"where the largest sum among the two subarrays is only 18.",
"Input: nums = [1,2,3,4,5], m = 2",
"Output: 9",
"Input: nums = [1,4,4], m = 3",
"Output: 4",
""
],
"constraints": [
"1 <= nums. length <= 10000 <= nums[i] <= 1061 <= m <= min(50",
" nums. length)"
]
},
{
"id": "420",
"title": "Strong Password Checker",
"question": "A password is considered strong if the below conditions are all met:Given a string password, return the minimum number of steps required to make password strong.\n if password is already strong, return 0.\nIn one step, you can:",
"examples": [
"Input: password = \"a\"",
"Output: 5",
"Input: password = \"aA1\"",
"Output: 3",
"Input: password = \"1337C0d3\"",
"Output: 0",
""
],
"constraints": [
"It has at least 6 characters and at most 20 characters. It contains at least one lowercase letter",
" at least one uppercase letter",
" and at least one digit. It does not contain three repeating characters in a row (i. e.",
" \"... aaa...\" is weak",
" but \"... aa... a...\" is strong",
" assuming other conditions are met). Insert one character to password",
"Delete one character from password",
" orReplace one character of password with another character. 1 <= password. length <= 50password consists of letters",
" digits",
" dot '.' or exclamation mark '!'."
]
},
{
"id": "432",
"title": "All O`one Data Structure",
"question": "Design a data structure to store the strings' count with the ability to return the strings with minimum and maximum counts.\nImplement the AllOne class:",
"examples": [
"Input",
"[\"AllOne\", \"inc\", \"inc\", \"getMaxKey\", \"getMinKey\", \"inc\", \"getMaxKey\", \"getMinKey\"]",
"[[], [\"hello\"], [\"hello\"], [], [], [\"leet\"], [], []]",
"Output",
"[null, null, null, \"hello\", \"hello\", null, \"hello\", \"leet\"]",
"",
"Explanation",
"AllOne allOne = new AllOne();",
"allOne. inc(\"hello\");",
"allOne. inc(\"hello\");",
"allOne. getMaxKey(); // return \"hello\"",
"allOne. getMinKey(); // return \"hello\"",
"allOne. inc(\"leet\");",
"allOne. getMaxKey(); // return \"hello\"",
"allOne. getMinKey(); // return \"leet\"",
""
],
"constraints": [
"AllOne() Initializes the object of the data structure. inc(String key) Increments the count of the string key by 1. If key does not exist in the data structure",
" insert it with count 1. dec(String key) Decrements the count of the string key by 1. If the count of key is 0 after the decrement",
" remove it from the data structure. It is guaranteed that key exists in the data structure before the decrement. getMaxKey() Returns one of the keys with the maximal count. If no element exists",
" return an empty string \"\". getMinKey() Returns one of the keys with the minimum count. If no element exists",
" return an empty string \"\". 1 <= key. length <= 10key consists of lowercase English letters. It is guaranteed that for each call to dec",
" key is existing in the data structure. At most 5 * 104 calls will be made to inc",
" dec",
" getMaxKey",
" and getMinKey."
]
},
{
"id": "440",
"title": "K-th Smallest in Lexicographical Order",
"question": "Given two integers n and k, return the kth lexicographically smallest integer in the range [1, n].",
"examples": [
"Input: n = 13, k = 2",
"Output: 10",
"Explanation: The lexicographical order is [1, 10, 11, 12, 13, 2, 3, 4, 5, 6, 7, 8, 9], so the second smallest number is 10.",
"Input: n = 1, k = 1",
"Output: 1",
""
],
"constraints": [
"1 <= k <= n <= 109"
]
},
{
"id": "446",
"title": "Arithmetic Slices II - Subsequence",
"question": "Given an integer array nums, return the number of all the arithmetic subsequences of nums.\nA sequence of numbers is called arithmetic if it consists of at least three elements and if the difference between any two consecutive elements is the same.\nA subsequence of an array is a sequence that can be formed by removing some elements (possibly none) of the array.\nThe test cases are generated so that the answer fits in 32-bit integer.",
"examples": [
"Input: nums = [2,4,6,8,10]",
"Output: 7",
"Explanation: All arithmetic subsequence slices are:",
"[2,4,6]",
"[4,6,8]",
"[6,8,10]",
"[2,4,6,8]",
"[4,6,8,10]",
"[2,4,6,8,10]",
"[2,6,10]",
"Input: nums = [7,7,7,7,7]",
"Output: 16",
"Explanation: Any subsequence of this array is arithmetic.",
""
],
"constraints": [
"For example",
" [1",
" 3",
" 5",
" 7",
" 9]",
" [7",
" 7",
" 7",
" 7]",
" and [3",
" -1",
" -5",
" -9] are arithmetic sequences. For example",
" [1",
" 1",
" 2",
" 5",
" 7] is not an arithmetic sequence. For example",
" [2",
"5",
"10] is a subsequence of [1",
"2",
"1",
"2",
"4",
"1",
"5",
"10]. 1  <= nums. length <= 1000-231 <= nums[i] <= 231 - 1"
]
},
{
"id": "458",
"title": "Poor Pigs",
"question": "There are buckets buckets of liquid, where exactly one of the buckets is poisonous.\n To figure out which one is poisonous, you feed some number of (poor) pigs the liquid to see whether they will die or not.\n Unfortunately, you only have minutesToTest minutes to determine which bucket is poisonous.\nYou can feed the pigs according to these steps:Given buckets, minutesToDie, and minutesToTest, return the minimum number of pigs needed to figure out which bucket is poisonous within the allotted time.",
"examples": [
"Input: buckets = 1000, minutesToDie = 15, minutesToTest = 60",
"Output: 5",
"Input: buckets = 4, minutesToDie = 15, minutesToTest = 15",
"Output: 2",
"Input: buckets = 4, minutesToDie = 15, minutesToTest = 30",
"Output: 2",
""
],
"constraints": [
"1 <= buckets <= 10001 <= minutesToDie <= minutesToTest <= 100"
]
},
{
"id": "460",
"title": "LFU Cache",
"question": "Design and implement a data structure for a Least Frequently Used (LFU) cache.\nImplement the LFUCache class:To determine the least frequently used key, a use counter is maintained for each key in the cache.\n The key with the smallest use counter is the least frequently used key.\nWhen a key is first inserted into the cache, its use counter is set to 1 (due to the put operation).\n The use counter for a key in the cache is incremented either a get or put operation is called on it.\nThe functions get and put must each run in O(1) average time complexity.",
"examples": [
"Input",
"[\"LFUCache\", \"put\", \"put\", \"get\", \"put\", \"get\", \"get\", \"put\", \"get\", \"get\", \"get\"]",
"[[2], [1, 1], [2, 2], [1], [3, 3], [2], [3], [4, 4], [1], [3], [4]]",
"Output",
"[null, null, null, 1, null, -1, 3, null, -1, 3, 4]",
"",
"Explanation",
"// cnt(x) = the use counter for key x",
"// cache=[] will show the last used order for tiebreakers (leftmost element is most recent)",
"LFUCache lfu = new LFUCache(2);",
"lfu. put(1, 1); // cache=[1,_], cnt(1)=1",
"lfu. put(2, 2); // cache=[2,1], cnt(2)=1, cnt(1)=1",
"lfu. get(1); // return 1",
" // cache=[1,2], cnt(2)=1, cnt(1)=2",
"lfu. put(3, 3); // 2 is the LFU key because cnt(2)=1 is the smallest, invalidate 2.",
"  // cache=[3,1], cnt(3)=1, cnt(1)=2",
"lfu. get(2); // return -1 (not found)",
"lfu. get(3); // return 3",
" // cache=[3,1], cnt(3)=2, cnt(1)=2",
"lfu. put(4, 4); // Both 1 and 3 have the same cnt, but 1 is LRU, invalidate 1.",
" // cache=[4,3], cnt(4)=1, cnt(3)=2",
"lfu. get(1); // return -1 (not found)",
"lfu. get(3); // return 3",
" // cache=[3,4], cnt(4)=1, cnt(3)=3",
"lfu. get(4); // return 4",
" // cache=[3,4], cnt(4)=2, cnt(3)=3",
""
],
"constraints": [
"LFUCache(int capacity) Initializes the object with the capacity of the data structure. int get(int key) Gets the value of the key if the key exists in the cache. Otherwise",
" returns -1. void put(int key",
" int value) Update the value of the key if present",
" or inserts the key if not already present. When the cache reaches its capacity",
" it should invalidate and remove the least frequently used key before inserting a new item. For this problem",
" when there is a tie (i. e.",
" two or more keys with the same frequency)",
" the least recently used key would be invalidated. 0 <= capacity <= 1040 <= key <= 1050 <= value <= 109At most 2 * 105 calls will be made to get and put."
]
},
{
"id": "466",
"title": "Count The Repetitions",
"question": "We define str = [s, n] as the string str which consists of the string s concatenated n times.\nWe define that string s1 can be obtained from string s2 if we can remove some characters from s2 such that it becomes s1.\nYou are given two strings s1 and s2 and two integers n1 and n2.\n You have the two strings str1 = [s1, n1] and str2 = [s2, n2].\nReturn the maximum integer m such that str = [str2, m] can be obtained from str1.",
"examples": [
"Input: s1 = \"acb\", n1 = 4, s2 = \"ab\", n2 = 2",
"Output: 2",
"Input: s1 = \"acb\", n1 = 1, s2 = \"acb\", n2 = 1",
"Output: 1",
""
],
"constraints": [
"For example",
" str == [\"abc\"",
" 3] ==\"abcabcabc\". For example",
" s1 = \"abc\" can be obtained from s2 = \"abdbec\" based on our definition by removing the bolded underlined characters. 1 <= s1. length",
" s2. length <= 100s1 and s2 consist of lowercase English letters. 1 <= n1",
" n2 <= 106"
]
},
{
"id": "472",
"title": "Concatenated Words",
"question": "Given an array of strings words (without duplicates), return all the concatenated words in the given list of words.\nA concatenated word is defined as a string that is comprised entirely of at least two shorter words in the given array.",
"examples": [
"Input: words = [\"cat\",\"cats\",\"catsdogcats\",\"dog\",\"dogcatsdog\",\"hippopotamuses\",\"rat\",\"ratcatdogcat\"]",
"Output: [\"catsdogcats\",\"dogcatsdog\",\"ratcatdogcat\"]",
"Explanation: \"catsdogcats\" can be concatenated by \"cats\", \"dog\" and \"cats\"; ",
"\"dogcatsdog\" can be concatenated by \"dog\", \"cats\" and \"dog\"; ",
"\"ratcatdogcat\" can be concatenated by \"rat\", \"cat\", \"dog\" and \"cat\". Input: words = [\"cat\",\"dog\",\"catdog\"]",
"Output: [\"catdog\"]",
""
],
"constraints": [
"1 <= words. length <= 1040 <= words[i]. length <= 1000words[i] consists of only lowercase English letters. 0 <= sum(words[i]. length) <= 105"
]
},
{
"id": "479",
"title": "Largest Palindrome Product",
"question": "Given an integer n, return the largest palindromic integer that can be represented as the product of two n-digits integers.\n Since the answer can be very large, return it modulo 1337.",
"examples": [
"Input: n = 2",
"Output: 987",
"Explanation: 99 x 91 = 9009, 9009 % 1337 = 987",
"Input: n = 1",
"Output: 9",
""
],
"constraints": [
"1 <= n <= 8"
]
},
{
"id": "594",
"title": "Longest Harmonious Subsequence",
"question": "We define a harmonious array as an array where the difference between its maximum value and its minimum value is exactly 1.\nGiven an integer array nums, return the length of its longest harmonious subsequence among all its possible subsequences.\nA subsequence of 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.",
"examples": [
"Input: nums = [1,3,2,2,5,2,3,7]",
"Output: 5",
"Explanation: The longest harmonious subsequence is [3,2,2,2,3].",
"Input: nums = [1,2,3,4]",
"Output: 2",
"Input: nums = [1,1,1,1]",
"Output: 0",
""
],
"constraints": [
"1 <= nums. length <= 2 * 104-109 <= nums[i] <= 109"
]
},
{
"id": "480",
"title": "Sliding Window Median",
"question": "The median is the middle value in an ordered integer list.\n If the size of the list is even, there is no middle value.\n So the median is the mean of the two middle values.\nYou are given an integer array nums and an integer k.\n There is a sliding window of size k which is moving from the very left of the array to the very right.\n You can only see the k numbers in the window.\n Each time the sliding window moves right by one position.\nReturn the median array for each window in the original array.\n Answers within 10-5 of the actual value will be accepted.",
"examples": [
"Input: nums = [1,3,-1,-3,5,3,6,7], k = 3",
"Output: [1. 00000,-1. 00000,-1. 00000,3. 00000,5. 00000,6. 00000]",
"Explanation: ",
"Window position Median",
"--------------- -----",
"[1 3 -1] -3 5 3 6 7 1",
" 1 [3 -1 -3] 5 3 6 7 -1",
" 1 3 [-1 -3 5] 3 6 7 -1",
" 1 3 -1 [-3 5 3] 6 7 3",
" 1 3 -1 -3 [5 3 6] 7 5",
" 1 3 -1 -3 5 [3 6 7] 6",
"Input: nums = [1,2,3,4,2,3,1,4,2], k = 3",
"Output: [2. 00000,3. 00000,3. 00000,3. 00000,2. 00000,3. 00000,2. 00000]",
""
],
"constraints": [
"For examples",
" if arr = [2",
"3",
"4]",
" the median is 3. For examples",
" if arr = [1",
"2",
"3",
"4]",
" the median is (2 + 3) / 2 = 2. 5. 1 <= k <= nums. length <= 105231 <= nums[i] <= 231 - 1"
]
},
{
"id": "483",
"title": "Smallest Good Base",
"question": "Given an integer n represented as a string, return the smallest good base of n.\nWe call k >= 2 a good base of n, if all digits of n base k are 1's.",
"examples": [
"Input: n = \"13\"",
"Output: \"3\"",
"Explanation: 13 base 3 is 111.",
"Input: n = \"4681\"",
"Output: \"8\"",
"Explanation: 4681 base 8 is 11111.",
"Input: n = \"1000000000000000000\"",
"Output: \"999999999999999999\"",
"Explanation: 1000000000000000000 base 999999999999999999 is 11.",
""
],
"constraints": [
"n is an integer in the range [3",
" 1018]. n does not contain any leading zeros."
]
},
{
"id": "488",
"title": "Zuma Game",
"question": "You are playing a variation of the game Zuma.\nIn this variation of Zuma, there is a single row of colored balls on a board, where each ball can be colored red 'R', yellow 'Y', blue 'B', green 'G', or white 'W'.\n You also have several colored balls in your hand.\nYour goal is to clear all of the balls from the board.\n On each turn:Given a string board, representing the row of balls on the board, and a string hand, representing the balls in your hand, return the minimum number of balls you have to insert to clear all the balls from the board.\n If you cannot clear all the balls from the board using the balls in your hand, return -1.",
"examples": [
"Input: board = \"WRRBBW\", hand = \"RB\"",
"Output: -1",
"Explanation: It is impossible to clear all the balls. The best you can do is:",
"- Insert 'R' so the board becomes WRRRBBW. WRRRBBW -> WBBW.",
"- Insert 'B' so the board becomes WBBBW. WBBBW -> WW.",
"There are still balls remaining on the board, and you are out of balls to insert. Input: board = \"WWRRBBWW\", hand = \"WRBRW\"",
"Output: 2",
"Explanation: To make the board empty:",
"- Insert 'R' so the board becomes WWRRRBBWW. WWRRRBBWW -> WWBBWW.",
"- Insert 'B' so the board becomes WWBBBWW. WWBBBWW -> WWWW -> empty.",
"2 balls from your hand were needed to clear the board.",
"Input: board = \"G\", hand = \"GGGGG\"",
"Output: 2",
"Explanation: To make the board empty:",
"- Insert 'G' so the board becomes GG.",
"- Insert 'G' so the board becomes GGG. GGG -> empty.",
"2 balls from your hand were needed to clear the board.",
"Input: board = \"RBYYBBRRB\", hand = \"YRBGB\"",
"Output: 3",
"Explanation: To make the board empty:",
"- Insert 'Y' so the board becomes RBYYYBBRRB. RBYYYBBRRB -> RBBBRRB -> RRRB -> B.",
"- Insert 'B' so the board becomes BB.",
"- Insert 'B' so the board becomes BBB. BBB -> empty.",
"3 balls from your hand were needed to clear the board.",
""
],
"constraints": [
"Pick any ball from your hand and insert it in between two balls in the row or on either end of the row. If there is a group of three or more consecutive balls of the same color",
" remove the group of balls from the board.\n\t\nIf this removal causes more groups of three or more of the same color to form",
" then continue removing each group until there are none left.\n\nIf this removal causes more groups of three or more of the same color to form",
" then continue removing each group until there are none left. If there are no more balls on the board",
" then you win the game. Repeat this process until you either win or do not have any more balls in your hand. 1 <= board. length <= 161 <= hand. length <= 5board and hand consist of the characters 'R'",
" 'Y'",
" 'B'",
" 'G'",
" and 'W'. The initial row of balls on the board will not have any groups of three or more consecutive balls of the same color."
]
},
{
"id": "493",
"title": "Reverse Pairs",
"question": "Given an integer array nums, return the number of reverse pairs in the array.\nA reverse pair is a pair (i, j) where 0 <= i < j < nums.\nlength and nums[i] > 2 * nums[j].",
"examples": [
"Input: nums = [1,3,2,3,1]",
"Output: 2",
"Input: nums = [2,4,3,5,1]",
"Output: 3",
""
],
"constraints": [
"1 <= nums. length <= 5 * 104-231 <= nums[i] <= 231 - 1"
]
},
{
"id": "502",
"title": "IPO",
"question": "Suppose LeetCode will start its IPO soon.\n In order to sell a good price of its shares to Venture Capital, LeetCode would like to work on some projects to increase its capital before the IPO.\n Since it has limited resources, it can only finish at most k distinct projects before the IPO.\n Help LeetCode design the best way to maximize its total capital after finishing at most k distinct projects.\nYou are given n projects where the ith project has a pure profit profits[i] and a minimum capital of capital[i] is needed to start it.\nInitially, you have w capital.\n When you finish a project, you will obtain its pure profit and the profit will be added to your total capital.\nPick a list of at most k distinct projects from given projects to maximize your final capital, and return the final maximized capital.\nThe answer is guaranteed to fit in a 32-bit signed integer.",
"examples": [
"Input: k = 2, w = 0, profits = [1,2,3], capital = [0,1,1]",
"Output: 4",
"Explanation: Since your initial capital is 0, you can only start the project indexed 0.",
"After finishing it you will obtain profit 1 and your capital becomes 1.",
"With capital 1, you can either start the project indexed 1 or the project indexed 2.",
"Since you can choose at most 2 projects, you need to finish the project indexed 2 to get the maximum capital.",
"Therefore, output the final maximized capital, which is 0 + 1 + 3 = 4.",
"Input: k = 3, w = 0, profits = [1,2,3], capital = [0,1,2]",
"Output: 6",
""
],
"constraints": [
"1 <= k <= 1050 <= w <= 109n == profits. lengthn == capital. length1 <= n <= 1050 <= profits[i] <= 1040 <= capital[i] <= 109"
]
},
{
"id": "514",
"title": "Freedom Trail",
"question": "In the video game Fallout 4, the quest \"Road to Freedom\" requires players to reach a metal dial called the \"Freedom Trail Ring\" and use the dial to spell a specific keyword to open the door.\nGiven a string ring that represents the code engraved on the outer ring and another string key that represents the keyword that needs to be spelled, return the minimum number of steps to spell all the characters in the keyword.\nInitially, the first character of the ring is aligned at the \"12:00\" direction.\n You should spell all the characters in key one by one by rotating ring clockwise or anticlockwise to make each character of the string key aligned at the \"12:00\" direction and then by pressing the center button.\nAt the stage of rotating the ring to spell the key character key[i]:",
"examples": [
"Input: ring = \"godding\", key = \"gd\"",
"Output: 4",
"Explanation:",
"For the first key character 'g', since it is already in place, we just need 1 step to spell this character. ",
"For the second key character 'd', we need to rotate the ring \"godding\" anticlockwise by two steps to make it become \"ddinggo\".",
"Also, we need 1 more step for spelling.",
"So the final output is 4.",
"Input: ring = \"godding\", key = \"godding\"",
"Output: 13",
""
],
"constraints": [
"1 <= ring. length",
" key. length <= 100ring and key consist of only lower case English letters. It is guaranteed that key could always be spelled by rotating ring."
]
},
{
"id": "517",
"title": "Super Washing Machines",
"question": "You have n super washing machines on a line.\n Initially, each washing machine has some dresses or is empty.\nFor each move, you could choose any m (1 <= m <= n) washing machines, and pass one dress of each washing machine to one of its adjacent washing machines at the same time.\nGiven an integer array machines representing the number of dresses in each washing machine from left to right on the line, return the minimum number of moves to make all the washing machines have the same number of dresses.\n If it is not possible to do it, return -1.",
"examples": [
"Input: machines = [1,0,5]",
"Output: 3",
"Explanation:",
"1st move: 1 0 <-- 5 => 1 1 4",
"2nd move: 1 <-- 1 <-- 4 => 2 1 3",
"3rd move: 2 1 <-- 3 => 2 2 2",
"Input: machines = [0,3,0]",
"Output: 2",
"Explanation:",
"1st move: 0 <-- 3 0 => 1 2 0",
"2nd move: 1 2 --> 0 => 1 1 1",
"Input: machines = [0,2,0]",
"Output: -1",
"Explanation:",
"It's impossible to make all three washing machines have the same number of dresses.",
""
],
"constraints": [
"n == machines. length1 <= n <= 1040 <= machines[i] <= 105"
]
},
{
"id": "546",
"title": "Remove Boxes",
"question": "You are given several boxes with different colors represented by different positive numbers.\nYou may experience several rounds to remove boxes until there is no box left.\n Each time you can choose some continuous boxes with the same color (i.\ne.\n, composed of k boxes, k >= 1), remove them and get k * k points.\nReturn the maximum points you can get.",
"examples": [
"Input: boxes = [1,3,2,2,2,3,4,3,1]",
"Output: 23",
"Explanation:",
"[1, 3, 2, 2, 2, 3, 4, 3, 1] ",
"----> [1, 3, 3, 4, 3, 1] (3*3=9 points) ",
"----> [1, 3, 3, 3, 1] (1*1=1 points) ",
"----> [1, 1] (3*3=9 points) ",
"----> [] (2*2=4 points)",
"Input: boxes = [1,1,1]",
"Output: 9",
"Input: boxes = [1]",
"Output: 1",
""
],
"constraints": [
"1 <= boxes. length <= 1001 <= boxes[i] <= 100"
]
},
{
"id": "552",
"title": "Student Attendance Record II",
"question": "An attendance record for a student can be represented as a string where each character signifies whether the student was absent, late, or present on that day.\n The record only contains the following three characters:Any student is eligible for an attendance award if they meet both of the following criteria:Given an integer n, return the number of possible attendance records of length n that make a student eligible for an attendance award.\n The answer may be very large, so return it modulo 109 + 7.",
"examples": [
"Input: n = 2",
"Output: 8",
"Explanation: There are 8 records with length 2 that are eligible for an award:",
"\"PP\", \"AP\", \"PA\", \"LP\", \"PL\", \"AL\", \"LA\", \"LL\"",
"Only \"AA\" is not eligible because there are 2 absences (there need to be fewer than 2).",
"Input: n = 1",
"Output: 3",
"Input: n = 10101",
"Output: 183236316",
""
],
"constraints": [
"'A': Absent.'L': Late.'P': Present. The student was absent ('A') for strictly fewer than 2 days total. The student was never late ('L') for 3 or more consecutive days. 1 <= n <= 105"
]
},
{
"id": "564",
"title": "Find the Closest Palindrome",
"question": "Given a string n representing an integer, return the closest integer (not including itself), which is a palindrome.\n If there is a tie, return the smaller one.\nThe closest is defined as the absolute difference minimized between two integers.",
"examples": [
"Input: n = \"123\"",
"Output: \"121\"",
"Input: n = \"1\"",
"Output: \"0\"",
"Explanation: 0 and 2 are the closest palindromes but we return the smallest which is 0.",
""
],
"constraints": [
"1 <= n. length <= 18n consists of only digits. n does not have leading zeros. n is representing an integer in the range [1",
" 1018 - 1]."
]
},
{
"id": "598",
"title": "Range Addition II",
"question": "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.\nCount and return the number of maximum integers in the matrix after performing all the operations.",
"examples": [
"Input: m = 3, n = 3, ops = [[2,2],[3,3]]",
"Output: 4",
"Explanation: The maximum integer in M is 2, and there are four of it in M. So return 4.",
"Input: 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]]",
"Output: 4",
"Input: m = 3, n = 3, ops = []",
"Output: 9",
""
],
"constraints": [
"1 <= m",
" n <= 4 * 1040 <= ops. length <= 104ops[i]. length == 21 <= ai <= m1 <= bi <= n"
]
},
{
"id": "587",
"title": "Erect the Fence",
"question": "You are given an array trees where trees[i] = [xi, yi] represents the location of a tree in the garden.\nYou are asked to fence the entire garden using the minimum length of rope as it is expensive.\n The garden is well fenced only if all the trees are enclosed.\nReturn the coordinates of trees that are exactly located on the fence perimeter.",
"examples": [
"Input: points = [[1,1],[2,2],[2,0],[2,4],[3,3],[4,2]]",
"Output: [[1,1],[2,0],[3,3],[2,4],[4,2]]",
"Input: points = [[1,2],[2,2],[4,2]]",
"Output: [[4,2],[2,2],[1,2]]",
""
],
"constraints": [
"1 <= points. length <= 3000points[i]. length == 20 <= xi",
" yi <= 100All the given points are unique."
]
},
{
"id": "591",
"title": "Tag Validator",
"question": "Given a string representing a code snippet, implement a tag validator to parse the code and return whether it is valid.\nA code snippet is valid if all the following rules hold:",
"examples": [
"Input: code = \"<DIV>This is the first line <![CDATA[<div>]]></DIV>\"",
"Output: true",
"Explanation: ",
"The code is wrapped in a closed tag : <DIV> and </DIV>. ",
"The TAG_NAME is valid, the TAG_CONTENT consists of some characters and cdata. ",
"Although CDATA_CONTENT has an unmatched start tag with invalid TAG_NAME, it should be considered as plain text, not parsed as a tag.",
"So TAG_CONTENT is valid, and then the code is valid. Thus return true.",
"Input: code = \"<DIV>>> ![cdata[]] <![CDATA[<div>]>]]>]]>>]</DIV>\"",
"Output: true",
"Explanation:",
"We first separate the code into : start_tag|tag_content|end_tag.",
"start_tag -> \"<DIV>\"",
"end_tag -> \"</DIV>\"",
"tag_content could also be separated into : text1|cdata|text2.",
"text1 -> \">> ![cdata[]] \"",
"cdata -> \"<![CDATA[<div>]>]]>\", where the CDATA_CONTENT is \"<div>]>\"",
"text2 -> \"]]>>]\"",
"The reason why start_tag is NOT \"<DIV>>>\" is because of the rule 6.",
"The reason why cdata is NOT \"<![CDATA[<div>]>]]>]]>\" is because of the rule 7.",
"Input: code = \"<A> <B> </A> </B>\"",
"Output: false",
"Explanation: Unbalanced. If \"<A>\" is closed, then \"<B>\" must be unmatched, and vice versa.",
"Input: code = \"<DIV> div tag is not closed <DIV>\"",
"Output: false",
""
],
"constraints": [
"1 <= code. length <= 500code consists of English letters",
" digits",
" '<'",
" '>'",
" '/'",
" '!'",
" '['",
" ']'",
" '.'",
" and ' '."
]
},
{
"id": "600",
"title": "Non-negative Integers without Consecutive Ones",
"question": "Given a positive integer n, return the number of the integers in the range [0, n] whose binary representations do not contain consecutive ones.",
"examples": [
"Input: n = 5",
"Output: 5",
"Explanation:",
"Here are the non-negative integers <= 5 with their corresponding binary representations:",
"0 : 0",
"1 : 1",
"2 : 10",
"3 : 11",
"4 : 100",
"5 : 101",
"Among them, only integer 3 disobeys the rule (two consecutive ones) and the other 5 satisfy the rule. ",
"Input: n = 1",
"Output: 2",
"Input: n = 2",
"Output: 3",
""
],
"constraints": [
"1 <= n <= 109"
]
},
{
"id": "629",
"title": "K Inverse Pairs Array",
"question": "For an integer array nums, an inverse pair is a pair of integers [i, j] where 0 <= i < j < nums.\nlength and nums[i] > nums[j].\nGiven two integers n and k, return the number of different arrays consist of numbers from 1 to n such that there are exactly k inverse pairs.\n Since the answer can be huge, return it modulo 109 + 7.",
"examples": [
"Input: n = 3, k = 0",
"Output: 1",
"Explanation: Only the array [1,2,3] which consists of numbers from 1 to 3 has exactly 0 inverse pairs.",
"Input: n = 3, k = 1",
"Output: 2",
"Explanation: The array [1,3,2] and [2,1,3] have exactly 1 inverse pair.",
""
],
"constraints": [
"1 <= n <= 10000 <= k <= 1000"
]
},
{
"id": "630",
"title": "Course Schedule III",
"question": "There are n different online courses numbered from 1 to n.\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.\nYou will start on the 1st day and you cannot take two or more courses simultaneously.\nReturn the maximum number of courses that you can take.",
"examples": [
"Input: courses = [[100,200],[200,1300],[1000,1250],[2000,3200]]",
"Output: 3",
"Explanation: ",
"There are totally 4 courses, but you can take 3 courses at most:",
"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.",
"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. ",
"Third, take the 2nd course, it costs 200 days so you will finish it on the 1300th day. ",
"The 4th course cannot be taken now, since you will finish it on the 3300th day, which exceeds the closed date.",
"Input: courses = [[1,2]]",
"Output: 1",
"Input: courses = [[3,2],[4,3]]",
"Output: 0",
""
],
"constraints": [
"1 <= courses. length <= 1041 <= durationi",
" lastDayi <= 104"
]
},
{
"id": "632",
"title": "Smallest Range Covering Elements from K Lists",
"question": "You have k lists of sorted integers in non-decreasing order.\n Find the smallest range that includes at least one number from each of the k lists.\nWe define the range [a, b] is smaller than range [c, d] if b - a < d - c or a < c if b - a == d - c.",
"examples": [
"Input: nums = [[4,10,15,24,26],[0,9,12,20],[5,18,22,30]]",
"Output: [20,24]",
"Explanation: ",
"List 1: [4, 10, 15, 24,26], 24 is in range [20,24].",
"List 2: [0, 9, 12, 20], 20 is in range [20,24].",
"List 3: [5, 18, 22, 30], 22 is in range [20,24].",
"Input: nums = [[1,2,3],[1,2,3],[1,2,3]]",
"Output: [1,1]",
"Input: nums = [[10,10],[11,11]]",
"Output: [10,11]",
"Input: nums = [[10],[11]]",
"Output: [10,11]",
"Input: nums = [[1],[2],[3],[4],[5],[6],[7]]",
"Output: [1,7]",
""
],
"constraints": [
"nums. length == k1 <= k <= 35001 <= nums[i]. length <= 50-105 <= nums[i][j] <= 105nums[i] is sorted in non-decreasing order."
]
},
{
"id": "639",
"title": "Decode Ways II",
"question": "A message containing letters from A-Z can be encoded into numbers using the following mapping: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).\n For example, \"11106\" can be mapped into:Note that the grouping (1 11 06) is invalid because \"06\" cannot be mapped into 'F' since \"6\" is different from \"06\".\nIn addition to the mapping above, an encoded message may contain the '*' character, which can represent any digit from '1' to '9' ('0' is excluded).\n For example, the encoded message \"1*\" may represent any of the encoded messages \"11\", \"12\", \"13\", \"14\", \"15\", \"16\", \"17\", \"18\", or \"19\".\n Decoding \"1*\" is equivalent to decoding any of the encoded messages it can represent.\nGiven a string s consisting of digits and '*' characters, return the number of ways to decode it.\nSince the answer may be very large, return it modulo 109 + 7.",
"examples": [
"'A' -> \"1\"",
"'B' -> \"2\"",
"...",
"'Z' -> \"26\"",
"Input: s = \"*\"",
"Output: 9",
"Explanation: The encoded message can represent any of the encoded messages \"1\", \"2\", \"3\", \"4\", \"5\", \"6\", \"7\", \"8\", or \"9\".",
"Each of these can be decoded to the strings \"A\", \"B\", \"C\", \"D\", \"E\", \"F\", \"G\", \"H\", and \"I\" respectively.",
"Hence, there are a total of 9 ways to decode \"*\".",
"Input: s = \"1*\"",
"Output: 18",
"Explanation: The encoded message can represent any of the encoded messages \"11\", \"12\", \"13\", \"14\", \"15\", \"16\", \"17\", \"18\", or \"19\".",
"Each of these encoded messages have 2 ways to be decoded (e. g. \"11\" can be decoded to \"AA\" or \"K\").",
"Hence, there are a total of 9 * 2 = 18 ways to decode \"1*\".",
"Input: s = \"2*\"",
"Output: 15",
"Explanation: The encoded message can represent any of the encoded messages \"21\", \"22\", \"23\", \"24\", \"25\", \"26\", \"27\", \"28\", or \"29\".",
"\"21\", \"22\", \"23\", \"24\", \"25\", and \"26\" have 2 ways of being decoded, but \"27\", \"28\", and \"29\" only have 1 way.",
"Hence, there are a total of (6 * 2) + (3 * 1) = 12 + 3 = 15 ways to decode \"2*\".",
""
],
"constraints": [
"\"AAJF\" with the grouping (1 1 10 6)\"KJF\" with the grouping (11 10 6)1 <= s. length <= 105s[i] is a digit or '*'."
]
},
{
"id": "664",
"title": "Strange Printer",
"question": "There is a strange printer with the following two special properties:Given a string s, return the minimum number of turns the printer needed to print it.",
"examples": [
"Input: s = \"aaabbb\"",
"Output: 2",
"Explanation: Print \"aaa\" first and then print \"bbb\".",
"Input: s = \"aba\"",
"Output: 2",
"Explanation: Print \"aaa\" first and then print \"b\" from the second place of the string, which will cover the existing character 'a'.",
""
],
"constraints": [
"The printer can only print a sequence of the same character each time. At each turn",
" the printer can print new characters starting from and ending at any place and will cover the original existing characters. 1 <= s. length <= 100s consists of lowercase English letters."
]
},
{
"id": "668",
"title": "Kth Smallest Number in Multiplication Table",
"question": "Nearly everyone has used the Multiplication Table.\n The multiplication table of size m x n is an integer matrix mat where mat[i][j] == i * j (1-indexed).\nGiven three integers m, n, and k, return the kth smallest element in the m x n multiplication table.",
"examples": [
"Input: m = 3, n = 3, k = 5",
"Output: 3",
"Explanation: The 5th smallest number is 3.",
"Input: m = 2, n = 3, k = 6",
"Output: 6",
"Explanation: The 6th smallest number is 6.",
""
],
"constraints": [
"1 <= m",
" n <= 3 * 1041 <= k <= m * n"
]
},
{
"id": "675",
"title": "Cut Off Trees for Golf Event",
"question": "You are asked to cut off all the trees in a forest for a golf event.\n The forest is represented as an m x n matrix.\n In this matrix:In one step, you can walk in any of the four directions: north, east, south, and west.\n If you are standing in a cell with a tree, you can choose whether to cut it off.\nYou must cut off the trees in order from shortest to tallest.\n When you cut off a tree, the value at its cell becomes 1 (an empty cell).\nStarting from the point (0, 0), return the minimum steps you need to walk to cut off all the trees.\n If you cannot cut off all the trees, return -1.\nYou are guaranteed that no two trees have the same height, and there is at least one tree needs to be cut off.",
"examples": [
"Input: forest = [[1,2,3],[0,0,4],[7,6,5]]",
"Output: 6",
"Explanation: Following the path above allows you to cut off the trees from shortest to tallest in 6 steps.",
"Input: forest = [[1,2,3],[0,0,0],[7,6,5]]",
"Output: -1",
"Explanation: The trees in the bottom row cannot be accessed as the middle row is blocked.",
"Input: forest = [[2,3,4],[0,0,5],[8,7,6]]",
"Output: 6",
"Explanation: You can follow the same path as Example 1 to cut off all the trees.",
"Note that you can cut off the first tree at (0, 0) before making any steps.",
""
],
"constraints": [
"0 means the cell cannot be walked through. 1 represents an empty cell that can be walked through. A number greater than 1 represents a tree in a cell that can be walked through",
" and this number is the tree's height. m == forest. lengthn == forest[i]. length1 <= m",
" n <= 500 <= forest[i][j] <= 109"
]
},
{
"id": "599",
"title": "Minimum Index Sum of Two Lists",
"question": "Suppose Andy and Doris want to choose a restaurant for dinner, and they both have a list of favorite restaurants represented by strings.\nYou need to help them find out their common interest with the least list index sum.\n If there is a choice tie between answers, output all of them with no order requirement.\n You could assume there always exists an answer.",
"examples": [
"Input: list1 = [\"Shogun\",\"Tapioca Express\",\"Burger King\",\"KFC\"], list2 = [\"Piatti\",\"The Grill at Torrey Pines\",\"Hungry Hunter Steakhouse\",\"Shogun\"]",
"Output: [\"Shogun\"]",
"Explanation: The only restaurant they both like is \"Shogun\".",
"Input: list1 = [\"Shogun\",\"Tapioca Express\",\"Burger King\",\"KFC\"], list2 = [\"KFC\",\"Shogun\",\"Burger King\"]",
"Output: [\"Shogun\"]",
"Explanation: The restaurant they both like and have the least index sum is \"Shogun\" with index sum 1 (0+1).",
"Input: list1 = [\"Shogun\",\"Tapioca Express\",\"Burger King\",\"KFC\"], list2 = [\"KFC\",\"Burger King\",\"Tapioca Express\",\"Shogun\"]",
"Output: [\"KFC\",\"Burger King\",\"Tapioca Express\",\"Shogun\"]",
"Input: list1 = [\"Shogun\",\"Tapioca Express\",\"Burger King\",\"KFC\"], list2 = [\"KNN\",\"KFC\",\"Burger King\",\"Tapioca Express\",\"Shogun\"]",
"Output: [\"KFC\",\"Burger King\",\"Tapioca Express\",\"Shogun\"]",
"Input: list1 = [\"KFC\"], list2 = [\"KFC\"]",
"Output: [\"KFC\"]",
""
],
"constraints": [
"1 <= list1. length",
" list2. length <= 10001 <= list1[i]. length",
" list2[i]. length <= 30list1[i] and list2[i] consist of spaces ' ' and English letters. All the stings of list1 are unique. All the stings of list2 are unique."
]
},
{
"id": "679",
"title": "24 Game",
"question": "You are given an integer array cards of length 4.\n You have four cards, each containing a number in the range [1, 9].\n You should arrange the numbers on these cards in a mathematical expression using the operators ['+', '-', '*', '/'] and the parentheses '(' and ')' to get the value 24.\nYou are restricted with the following rules:Return true if you can get such expression that evaluates to 24, and false otherwise.",
"examples": [
"Input: cards = [4,1,8,7]",
"Output: true",
"Explanation: (8-4) * (7-1) = 24",
"Input: cards = [1,2,1,2]",
"Output: false",
""
],
"constraints": [
"The division operator '/' represents real division",
" not integer division.\n\n\t\nFor example",
" 4 / (1 - 2 / 3) = 4 / (1 / 3) = 12.\n\nFor example",
" 4 / (1 - 2 / 3) = 4 / (1 / 3) = 12. Every operation done is between two numbers. In particular",
" we cannot use '-' as a unary operator.\n\t\nFor example",
" if cards = [1",
" 1",
" 1",
" 1]",
" the expression \"-1 - 1 - 1 - 1\" is not allowed.\n\nFor example",
" if cards = [1",
" 1",
" 1",
" 1]",
" the expression \"-1 - 1 - 1 - 1\" is not allowed. You cannot concatenate numbers together\n\t\nFor example",
" if cards = [1",
" 2",
" 1",
" 2]",
" the expression \"12 + 12\" is not valid.\n\nFor example",
" if cards = [1",
" 2",
" 1",
" 2]",
" the expression \"12 + 12\" is not valid. cards. length == 41 <= cards[i] <= 9"
]
},
{
"id": "685",
"title": "Redundant Connection II",
"question": "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.\nThe 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.\n The added edge has two different vertices chosen from 1 to n, and was not an edge that already existed.\nThe resulting graph is given as a 2D-array of edges.\n 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.\nReturn an edge that can be removed so that the resulting graph is a rooted tree of n nodes.\n If there are multiple answers, return the answer that occurs last in the given 2D-array.",
"examples": [
"Input: edges = [[1,2],[1,3],[2,3]]",
"Output: [2,3]",
"Input: edges = [[1,2],[2,3],[3,4],[4,1],[1,5]]",
"Output: [4,1]",
""
],
"constraints": [
"n == edges. length3 <= n <= 1000edges[i]. length == 21 <= ui",
" vi <= nui != vi"
]
},
{
"id": "689",
"title": "Maximum Sum of 3 Non-Overlapping Subarrays",
"question": "Given an integer array nums and an integer k, find three non-overlapping subarrays of length k with maximum sum and return them.\nReturn the result as a list of indices representing the starting position of each interval (0-indexed).\n If there are multiple answers, return the lexicographically smallest one.",
"examples": [
"Input: nums = [1,2,1,2,6,7,5,1], k = 2",
"Output: [0,3,5]",
"Explanation: Subarrays [1, 2], [2, 6], [7, 5] correspond to the starting indices [0, 3, 5].",
"We could have also taken [2, 1], but an answer of [1, 3, 5] would be lexicographically larger.",
"Input: nums = [1,2,1,2,1,2,1,2,1], k = 2",
"Output: [0,2,4]",
""
],
"constraints": [
"1 <= nums. length <= 2 * 1041 <= nums[i] < 2161 <= k <= floor(nums. length / 3)"
]
},
{
"id": "691",
"title": "Stickers to Spell Word",
"question": "We are given n different types of stickers.\n Each sticker has a lowercase English word on it.\nYou would like to spell out the given string target by cutting individual letters from your collection of stickers and rearranging them.\n You can use each sticker more than once if you want, and you have infinite quantities of each sticker.\nReturn the minimum number of stickers that you need to spell out target.\n If the task is impossible, return -1.\nNote: 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.",
"examples": [
"Input: stickers = [\"with\",\"example\",\"science\"], target = \"thehat\"",
"Output: 3",
"Explanation:",
"We can use 2 \"with\" stickers, and 1 \"example\" sticker.",
"After cutting and rearrange the letters of those stickers, we can form the target \"thehat\".",
"Also, this is the minimum number of stickers necessary to form the target string.",
"Input: stickers = [\"notice\",\"possible\"], target = \"basicbasic\"",
"Output: -1",
"Explanation:",
"We cannot form the target \"basicbasic\" from cutting letters from the given stickers.",
""
],
"constraints": [
"n == stickers. length1 <= n <= 501 <= stickers[i]. length <= 101 <= target <= 15stickers[i] and target consist of lowercase English letters."
]
},
{
"id": "699",
"title": "Falling Squares",
"question": "There are several squares being dropped onto the X-axis of a 2D plane.\nYou 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.\nEach square is dropped one at a time from a height above any landed squares.\n It then falls downward (negative Y direction) until it either lands on the top side of another square or on the X-axis.\n A square brushing the left/right side of another square does not count as landing on it.\n Once it lands, it freezes in place and cannot be moved.\nAfter each square is dropped, you must record the height of the current tallest stack of squares.\nReturn an integer array ans where ans[i] represents the height described above after dropping the ith square.",
"examples": [
"Input: positions = [[1,2],[2,3],[6,1]]",
"Output: [2,5,5]",
"Explanation:",
"After the first drop, the tallest stack is square 1 with a height of 2.",
"After the second drop, the tallest stack is squares 1 and 2 with a height of 5.",
"After the third drop, the tallest stack is still squares 1 and 2 with a height of 5.",
"Thus, we return an answer of [2, 5, 5].",
"Input: positions = [[100,100],[200,100]]",
"Output: [100,100]",
"Explanation:",
"After the first drop, the tallest stack is square 1 with a height of 100.",
"After the second drop, the tallest stack is either square 1 or square 2, both with heights of 100.",
"Thus, we return an answer of [100, 100].",
"Note that square 2 only brushes the right side of square 1, which does not count as landing on it.",
""
],
"constraints": [
"1 <= positions. length <= 10001 <= lefti <= 1081 <= sideLengthi <= 106"
]
},
{
"id": "710",
"title": "Random Pick with Blacklist",
"question": "You are given an integer n and an array of unique integers blacklist.\n Design an algorithm to pick a random integer in the range [0, n - 1] that is not in blacklist.\n Any integer that is in the mentioned range and not in blacklist should be equally likely returned.\nOptimize your algorithm such that it minimizes the call to the built-in random function of your language.\nImplement the Solution class:",
"examples": [
"Input",
"[\"Solution\", \"pick\", \"pick\", \"pick\", \"pick\", \"pick\", \"pick\", \"pick\"]",
"[[7, [2, 3, 5]], [], [], [], [], [], [], []]",
"Output",
"[null, 6, 4, 1, 6, 1, 6, 4]",
"",
"Explanation",
"Solution solution = new Solution(7, [2, 3, 5]);",
"solution. pick(); // return 6, any integer from [1,4,6] should be ok. Note that for every call of pick, 1, 4, and 6 must be equally likely to be returned (i. e., with probability 1/3).",
"solution. pick(); // return 4",
"solution. pick(); // return 1",
"solution. pick(); // return 6",
"solution. pick(); // return 1",
"solution. pick(); // return 6",
"solution. pick(); // return 4",
""
],
"constraints": [
"Solution(int n",
" int[] blacklist) Initializes the object with the integer n and the blacklisted integers blacklist. int pick() Returns a random integer in the range [0",
" n - 1] and not in blacklist. All the possible integers should be equally likely returned. 1 <= n <= 1090 <= blacklist. length <- min(105",
" n - 1)0 <= blacklist[i] < nAll the values of blacklist are unique. At most 2 * 104 calls will be made to pick."
]
},
{
"id": "715",
"title": "Range Module",
"question": "A Range Module is a module that tracks ranges of numbers.\n Design a data structure to track the ranges represented as half-open intervals and query about them.\nA half-open interval [left, right) denotes all the real numbers x where left <= x < right.\nImplement the RangeModule class:",
"examples": [
"Input",
"[\"RangeModule\", \"addRange\", \"removeRange\", \"queryRange\", \"queryRange\", \"queryRange\"]",
"[[], [10, 20], [14, 16], [10, 14], [13, 15], [16, 17]]",
"Output",
"[null, null, null, true, false, true]",
"",
"Explanation",
"RangeModule rangeModule = new RangeModule();",
"rangeModule. addRange(10, 20);",
"rangeModule. removeRange(14, 16);",
"rangeModule. queryRange(10, 14); // return True,(Every number in [10, 14) is being tracked)",
"rangeModule. queryRange(13, 15); // return False,(Numbers like 14, 14. 03, 14. 17 in [13, 15) are not being tracked)",
"rangeModule. queryRange(16, 17); // return True, (The number 16 in [16, 17) is still being tracked, despite the remove operation)",
""
],
"constraints": [
"RangeModule() Initializes the object of the data structure. void addRange(int left",
" int right) Adds the half-open interval [left",
" right)",
" tracking every real number in that interval. Adding an interval that partially overlaps with currently tracked numbers should add any numbers in the interval [left",
" right) that are not already tracked. boolean queryRange(int left",
" int right) Returns true if every real number in the interval [left",
" right) is currently being tracked",
" and false otherwise. void removeRange(int left",
" int right) Stops tracking every real number currently being tracked in the half-open interval [left",
" right). 1 <= left < right <= 109At most 104 calls will be made to addRange",
" queryRange",
" and removeRange."
]
},
{
"id": "719",
"title": "Find K-th Smallest Pair Distance",
"question": "The distance of a pair of integers a and b is defined as the absolute difference between a and b.\nGiven 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.\nlength.",
"examples": [
"Input: nums = [1,3,1], k = 1",
"Output: 0",
"Explanation: Here are all the pairs:",
"(1,3) -> 2",
"(1,1) -> 0",
"(3,1) -> 2",
"Then the 1st smallest distance pair is (1,1), and its distance is 0.",
"Input: nums = [1,1,1], k = 2",
"Output: 0",
"Input: nums = [1,6,1], k = 3",
"Output: 5",
""
],
"constraints": [
"n == nums. length2 <= n <= 1040 <= nums[i] <= 1061 <= k <= n * (n - 1) / 2"
]
},
{
"id": "726",
"title": "Number of Atoms",
"question": "Given a string formula representing a chemical formula, return the count of each atom.\nThe atomic element always starts with an uppercase character, then zero or more lowercase letters, representing the name.\nOne or more digits representing that element's count may follow if the count is greater than 1.\n If the count is 1, no digits will follow.\nTwo formulas are concatenated together to produce another formula.\nA formula placed in parentheses, and a count (optionally added) is also a formula.\nReturn 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.",
"examples": [
"Input: formula = \"H2O\"",
"Output: \"H2O\"",
"Explanation: The count of elements are {'H': 2, 'O': 1}.",
"Input: formula = \"Mg(OH)2\"",
"Output: \"H2MgO2\"",
"Explanation: The count of elements are {'H': 2, 'Mg': 1, 'O': 2}.",
"Input: formula = \"K4(ON(SO3)2)2\"",
"Output: \"K4N2O14S4\"",
"Explanation: The count of elements are {'K': 4, 'N': 2, 'O': 14, 'S': 4}.",
"Input: formula = \"Be32\"",
"Output: \"Be32\"",
""
],
"constraints": [
"For example",
" \"H2O\" and \"H2O2\" are possible",
" but \"H1O2\" is impossible. For example",
" \"H2O2He3Mg4\" is also a formula. For example",
" \"(H2O2)\" and \"(H2O2)3\" are formulas. 1 <= formula. length <= 1000formula consists of English letters",
" digits",
" '('",
" and ')'. formula is always valid. All the values in the output will fit in a 32-bit integer."
]
},
{
"id": "730",
"title": "Count Different Palindromic Subsequences",
"question": "Given a string s, return the number of different non-empty palindromic subsequences in s.\n Since the answer may be very large, return it modulo 109 + 7.\nA subsequence of a string is obtained by deleting zero or more characters from the string.\nA sequence is palindromic if it is equal to the sequence reversed.\nTwo sequences a1, a2, .\n.\n.\n and b1, b2, .\n.\n.\n are different if there is some i for which ai != bi.",
"examples": [
"Input: s = \"bccb\"",
"Output: 6",
"Explanation: The 6 different non-empty palindromic subsequences are 'b', 'c', 'bb', 'cc', 'bcb', 'bccb'.",
"Note that 'bcb' is counted only once, even though it occurs twice.",
"Input: s = \"abcdabcdabcdabcdabcdabcdabcdabcddcbadcbadcbadcbadcbadcbadcbadcba\"",
"Output: 104860361",
"Explanation: There are 3104860382 different non-empty palindromic subsequences, which is 104860361 modulo 109 + 7.",
""
],
"constraints": [
"1 <= s. length <= 1000s[i] is either 'a'",
" 'b'",
" 'c'",
" or 'd'."
]
},
{
"id": "605",
"title": "Can Place Flowers",
"question": "You have a long flowerbed in which some of the plots are planted, and some are not.\n However, flowers cannot be planted in adjacent plots.\nGiven an integer array flowerbed containing 0's and 1's, where 0 means empty and 1 means not empty, and an integer n, return if n new flowers can be planted in the flowerbed without violating the no-adjacent-flowers rule.",
"examples": [
"Input: flowerbed = [1,0,0,0,1], n = 1",
"Output: true",
"Input: flowerbed = [1,0,0,0,1], n = 2",
"Output: false",
""
],
"constraints": [
"1 <= flowerbed. length <= 2 * 104flowerbed[i] is 0 or 1. There are no two adjacent flowers in flowerbed. 0 <= n <= flowerbed. length"
]
},
{
"id": "732",
"title": "My Calendar III",
"question": "A k-booking happens when k events have some non-empty intersection (i.\ne.\n, there is some time that is common to all k events.\n)You are given some events [start, end), after each given event, return an integer k representing the maximum k-booking between all the previous events.\nImplement the MyCalendarThree class:",
"examples": [
"Input",
"[\"MyCalendarThree\", \"book\", \"book\", \"book\", \"book\", \"book\", \"book\"]",
"[[], [10, 20], [50, 60], [10, 40], [5, 15], [5, 10], [25, 55]]",
"Output",
"[null, 1, 1, 2, 3, 3, 3]",
"",
"Explanation",
"MyCalendarThree myCalendarThree = new MyCalendarThree();",
"myCalendarThree. book(10, 20); // return 1, The first event can be booked and is disjoint, so the maximum k-booking is a 1-booking.",
"myCalendarThree. book(50, 60); // return 1, The second event can be booked and is disjoint, so the maximum k-booking is a 1-booking.",
"myCalendarThree. book(10, 40); // return 2, The third event [10, 40) intersects the first event, and the maximum k-booking is a 2-booking.",
"myCalendarThree. book(5, 15); // return 3, The remaining events cause the maximum K-booking to be only a 3-booking.",
"myCalendarThree. book(5, 10); // return 3",
"myCalendarThree. book(25, 55); // return 3",
""
],
"constraints": [
"MyCalendarThree() Initializes the object. int book(int start",
" int end) Returns an integer k representing the largest integer such that there exists a k-booking in the calendar. 0 <= start < end <= 109At most 400 calls will be made to book."
]
},
{
"id": "736",
"title": "Parse Lisp Expression",
"question": "You are given a string expression representing a Lisp-like expression to return the integer value of.\nThe syntax for these expressions is given as follows.",
"examples": [
"Input: expression = \"(let x 2 (mult x (let x 3 y 4 (add x y))))\"",
"Output: 14",
"Explanation: In the expression (add x y), when checking for the value of the variable x,",
"we check from the innermost scope to the outermost in the context of the variable we are trying to evaluate.",
"Since x = 3 is found first, the value of x is 3.",
"Input: expression = \"(let x 3 x 2 x)\"",
"Output: 2",
"Explanation: Assignment in let statements is processed sequentially.",
"Input: expression = \"(let x 1 y 2 x (add x y) (add x y))\"",
"Output: 5",
"Explanation: The first (add x y) evaluates as 3, and is assigned to x.",
"The second (add x y) evaluates as 3+2 = 5.",
"Input: expression = \"(let x 2 (add (let x 3 (let x 4 x)) x))\"",
"Output: 6",
"Explanation: Even though (let x 4 x) has a deeper scope, it is outside the context",
"of the final x in the add-expression. That final x will equal 2.",
"Input: expression = \"(let a1 3 b2 (add a1 1) b2)\"",
"Output: 4",
"Explanation: Variable names can contain digits after the first character.",
""
],
"constraints": [
"An expression is either an integer",
" let expression",
" add expression",
" mult expression",
" or an assigned variable. Expressions always evaluate to a single integer.(An integer could be positive or negative.)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. 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. 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. 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. 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. 1 <= expression. length <= 2000There are no leading or trailing spaces in exprssion. All tokens are separated by a single space in expressoin. The answer and all intermediate calculations of that answer are guaranteed to fit in a 32-bit integer. The expression is guaranteed to be legal and evaluate to an integer."
]
},
{
"id": "741",
"title": "Cherry Pickup",
"question": "You are given an n x n grid representing a field of cherries, each cell is one of three possible integers.\nReturn the maximum number of cherries you can collect by following the rules below:",
"examples": [
"Input: grid = [[0,1,-1],[1,0,-1],[1,1,1]]",
"Output: 5",
"Explanation: The player started at (0, 0) and went down, down, right right to reach (2, 2).",
"4 cherries were picked up during this single trip, and the matrix becomes [[0,1,-1],[0,0,-1],[0,0,0]].",
"Then, the player went left, up, up, left to return home, picking up one more cherry.",
"The total number of cherries picked up is 5, and this is the maximum possible.",
"Input: grid = [[1,1,-1],[1,-1,1],[-1,1,1]]",
"Output: 0",
""
],
"constraints": [
"0 means the cell is empty",
" so you can pass through",
"1 means the cell contains a cherry that you can pick up and pass through",
" or-1 means the cell contains a thorn that blocks your way. 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). After reaching (n - 1",
" n - 1)",
" returning to (0",
" 0) by moving left or up through valid path cells. When passing through a path cell containing a cherry",
" you pick it up",
" and the cell becomes an empty cell 0. If there is no valid path between (0",
" 0) and (n - 1",
" n - 1)",
" then no cherries can be collected. n == grid. lengthn == grid[i]. length1 <= n <= 50grid[i][j] is -1",
" 0",
" or 1. grid[0][0] != -1grid[n - 1][n - 1] != -1"
]
},
{
"id": "745",
"title": "Prefix and Suffix Search",
"question": "Design a special dictionary with some words that searchs the words in it by a prefix and a suffix.\nImplement the WordFilter class:",
"examples": [
"Input",
"[\"WordFilter\", \"f\"]",
"[[[\"apple\"]], [\"a\", \"e\"]]",
"Output",
"[null, 0]",
"",
"Explanation",
"WordFilter wordFilter = new WordFilter([\"apple\"]);",
"wordFilter. f(\"a\", \"e\"); // return 0, because the word at index 0 has prefix = \"a\" and suffix = 'e\".",
""
],
"constraints": [
"WordFilter(string[] words) Initializes the object with the words in the dictionary. f(string prefix",
" string suffix) Returns the index of the word in the dictionary",
" which has the prefix prefix and the suffix suffix. If there is more than one valid index",
" return the largest of them. If there is no such word in the dictionary",
" return -1. 1 <= words. length <= 150001 <= words[i]. length <= 101 <= prefix. length",
" suffix. length <= 10words[i]",
" prefix and suffix consist of lower-case English letters only. At most 15000 calls will be made to the function f."
]
},
{
"id": "749",
"title": "Contain Virus",
"question": "A virus is spreading rapidly, and your task is to quarantine the infected area by installing walls.\nThe 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.\n A wall (and only one wall) can be installed between any two 4-directionally adjacent cells, on the shared boundary.\nEvery night, the virus spreads to all neighboring cells in all four directions unless blocked by a wall.\n Resources are limited.\n Each day, you can install walls around only one region (i.\ne.\n, the affected area (continuous block of infected cells) that threatens the most uninfected cells the following night).\n There will never be a tie.\nReturn the number of walls used to quarantine all the infected regions.\n If the world will become fully infected, return the number of walls used.",
"examples": [
"Input: 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]]",
"Output: 10",
"Explanation: There are 2 contaminated regions.",
"On the first day, add 5 walls to quarantine the viral region on the left. The board after the virus spreads is:",
"",
"On the second day, add 5 walls to quarantine the viral region on the right. The virus is fully contained.",
"",
"Input: isInfected = [[1,1,1],[1,0,1],[1,1,1]]",
"Output: 4",
"Explanation: Even though there is only one cell saved, there are 4 walls built.",
"Notice that walls are only built on the shared boundary of two different cells.",
"Input: 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]]",
"Output: 13",
"Explanation: The region on the left only builds two new walls.",
""
],
"constraints": [
"m == isInfected. lengthn == isInfected[i]. length1 <= m",
" n <= 50isInfected[i][j] is either 0 or 1. There is always a contiguous viral region throughout the described process that will infect strictly more uncontaminated squares in the next round."
]
},
{
"id": "753",
"title": "Cracking the Safe",
"question": "There is a safe protected by a password.\n The password is a sequence of n digits where each digit can be in the range [0, k - 1].\nThe safe has a peculiar way of checking the password.\n When you enter in a sequence, it checks the most recent n digits that were entered each time you type a digit.\nReturn any string of minimum length that will unlock the safe at some point of entering it.",
"examples": [
"Input: n = 1, k = 2",
"Output: \"10\"",
"Explanation: The password is a single digit, so enter each digit. \"01\" would also unlock the safe.",
"Input: n = 2, k = 2",
"Output: \"01100\"",
"Explanation: For each possible password:",
"- \"00\" is typed in starting from the 4th digit.",
"- \"01\" is typed in starting from the 1st digit.",
"- \"10\" is typed in starting from the 3rd digit.",
"- \"11\" is typed in starting from the 2nd digit.",
"Thus \"01100\" will unlock the safe. \"01100\", \"10011\", and \"11001\" would also unlock the safe.",
""
],
"constraints": [
"For example",
" the correct password is \"345\" and you enter in \"012345\":\n\n\t\nAfter typing 0",
" the most recent 3 digits is \"0\"",
" which is incorrect.\nAfter typing 1",
" the most recent 3 digits is \"01\"",
" which is incorrect.\nAfter typing 2",
" the most recent 3 digits is \"012\"",
" which is incorrect.\nAfter typing 3",
" the most recent 3 digits is \"123\"",
" which is incorrect.\nAfter typing 4",
" the most recent 3 digits is \"234\"",
" which is incorrect.\nAfter typing 5",
" the most recent 3 digits is \"345\"",
" which is correct and the safe unlocks.\n\nAfter typing 0",
" the most recent 3 digits is \"0\"",
" which is incorrect. After typing 1",
" the most recent 3 digits is \"01\"",
" which is incorrect. After typing 2",
" the most recent 3 digits is \"012\"",
" which is incorrect. After typing 3",
" the most recent 3 digits is \"123\"",
" which is incorrect. After typing 4",
" the most recent 3 digits is \"234\"",
" which is incorrect. After typing 5",
" the most recent 3 digits is \"345\"",
" which is correct and the safe unlocks. 1 <= n <= 41 <= k <= 101 <= kn <= 4096"
]
},
{
"id": "757",
"title": "Set Intersection Size At Least Two",
"question": "An integer interval [a, b] (for integers a < b) is a set of all consecutive integers from a to b, including a and b.\nFind the minimum size of a set S such that for every integer interval A in intervals, the intersection of S with A has a size of at least two.",
"examples": [
"Input: intervals = [[1,3],[1,4],[2,5],[3,5]]",
"Output: 3",
"Explanation: Consider the set S = {2, 3, 4}. For each interval, there are at least 2 elements from S in the interval.",
"Also, there isn't a smaller size set that fulfills the above condition.",
"Thus, we output the size of this set, which is 3.",
"Input: intervals = [[1,2],[2,3],[2,4],[4,5]]",
"Output: 5",
"Explanation: An example of a minimum sized set is {1, 2, 3, 4, 5}.",
""
],
"constraints": [
"1 <= intervals. length <= 3000intervals[i]. length == 20 <= ai < bi <= 108"
]
},
{
"id": "761",
"title": "Special Binary String",
"question": "Special binary strings are binary strings with the following two properties:You are given a special binary string s.\nA move consists of choosing two consecutive, non-empty, special substrings of s, and swapping them.\n Two strings are consecutive if the last character of the first string is exactly one index before the first character of the second string.\nReturn the lexicographically largest resulting string possible after applying the mentioned operations on the string.",
"examples": [
"Input: s = \"11011000\"",
"Output: \"11100100\"",
"Explanation: The strings \"10\" [occuring at s[1]] and \"1100\" [at s[3]] are swapped.",
"This is the lexicographically largest string possible after some number of swaps.",
"Input: s = \"10\"",
"Output: \"10\"",
""
],
"constraints": [
"The number of 0's is equal to the number of 1's. Every prefix of the binary string has at least as many 1's as 0's. 1 <= s. length <= 50s[i] is either '0' or '1'. s is a special binary string."
]
},
{
"id": "765",
"title": "Couples Holding Hands",
"question": "There are n couples sitting in 2n seats arranged in a row and want to hold hands.\nThe people and seats are represented by an integer array row where row[i] is the ID of the person sitting in the ith seat.\n 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).\nReturn the minimum number of swaps so that every couple is sitting side by side.\n A swap consists of choosing any two people, then they stand up and switch seats.",
"examples": [
"Input: row = [0,2,1,3]",
"Output: 1",
"Explanation: We only need to swap the second (row[1]) and third (row[2]) person.",
"Input: row = [3,2,0,1]",
"Output: 0",
"Explanation: All couples are already seated side by side.",
""
],
"constraints": [
"2n == row. length2 <= n <= 30n is even. 0 <= row[i] < 2nAll the elements of row are unique."
]
},
{
"id": "768",
"title": "Max Chunks To Make Sorted II",
"question": "You are given an integer array arr.\nWe split arr into some number of chunks (i.\ne.\n, partitions), and individually sort each chunk.\n After concatenating them, the result should equal the sorted array.\nReturn the largest number of chunks we can make to sort the array.",
"examples": [
"Input: arr = [5,4,3,2,1]",
"Output: 1",
"Explanation:",
"Splitting into two or more chunks will not return the required result.",
"For example, splitting into [5, 4], [3, 2, 1] will result in [4, 5, 1, 2, 3], which isn't sorted.",
"Input: arr = [2,1,3,4,4]",
"Output: 4",
"Explanation:",
"We can split into two chunks, such as [2, 1], [3, 4, 4].",
"However, splitting into [2, 1], [3], [4], [4] is the highest number of chunks possible.",
""
],
"constraints": [
"1 <= arr. length <= 20000 <= arr[i] <= 108"
]
},
{
"id": "606",
"title": "Construct String from Binary Tree",
"question": "Given the root of a binary tree, construct a string consists of parenthesis and integers from a binary tree with the preorder traversing way, and return it.\nOmit all the empty parenthesis pairs that do not affect the one-to-one mapping relationship between the string and the original binary tree.",
"examples": [
"Input: root = [1,2,3,4]",
"Output: \"1(2(4))(3)\"",
"Explanation: Originallay it needs to be \"1(2(4)())(3()())\", but you need to omit all the unnecessary empty parenthesis pairs. And it will be \"1(2(4))(3)\"",
"Input: root = [1,2,3,null,4]",
"Output: \"1(2()(4))(3)\"",
"Explanation: Almost the same as the first example, except we cannot omit the first parenthesis pair to break the one-to-one mapping relationship between the input and the output.",
""
],
"constraints": [
"The number of nodes in the tree is in the range [1",
" 104].-1000 <= Node. val <= 1000"
]
},
{
"id": "770",
"title": "Basic Calculator IV",
"question": "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\"]Expressions are evaluated in the usual order: brackets first, then multiplication, then addition and subtraction.\nThe format of the output is as follows:",
"examples": [
"Input: expression = \"e + 8 - a + 5\", evalvars = [\"e\"], evalints = [1]",
"Output: [\"-1*a\",\"14\"]",
"Input: expression = \"e - 8 + temperature - pressure\", evalvars = [\"e\", \"temperature\"], evalints = [1, 12]",
"Output: [\"-1*pressure\",\"5\"]",
"Input: expression = \"(e + 8) * (e - 8)\", evalvars = [], evalints = []",
"Output: [\"1*e*e\",\"-64\"]",
"Input: expression = \"a * b * c + b * a * c * 4\", evalvars = [], evalints = []",
"Output: [\"5*a*b*c\"]",
"Input: expression = \"((a - b) * (b - c) + (c - a)) * ((a - b) + (b - c) * (c - a))\", evalvars = [], evalints = []",
"Output: [\"-1*a*a*b*b\",\"2*a*a*b*c\",\"-1*a*a*c*c\",\"1*a*b*b*b\",\"-1*a*b*b*c\",\"-1*a*b*c*c\",\"1*a*c*c*c\",\"-1*b*b*b*c\",\"2*b*b*c*c\",\"-1*b*c*c*c\",\"2*a*a*b\",\"-2*a*a*c\",\"-2*a*b*b\",\"2*a*c*c\",\"1*b*b*b\",\"-1*b*b*c\",\"1*b*c*c\",\"-1*c*c*c\",\"-1*a*a\",\"1*a*b\",\"1*a*c\",\"-1*b*c\"]",
""
],
"constraints": [
"An expression alternates chunks and symbols",
" with a space separating each chunk and symbol. A chunk is either an expression in parentheses",
" a variable",
" or a non-negative integer. 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\". For example",
" expression = \"1 + 2 * 3\" has an answer of [\"7\"]. For each term of free variables with a non-zero coefficient",
" we write the free variables within a term in sorted order lexicographically.\n\t\nFor example",
" we would never write a term like \"b*a*c\"",
" only \"a*b*c\".\n\nFor example",
" we would never write a term like \"b*a*c\"",
" only \"a*b*c\". 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\t\nFor example",
" \"a*a*b*c\" has degree 4.\n\nFor example",
" \"a*a*b*c\" has degree 4. 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. An example of a well-formatted answer is [\"-2*a*a*a\"",
" \"3*a*a*b\"",
" \"3*b*b\"",
" \"4*a\"",
" \"5*c\"",
" \"-6\"]. Terms (including constant terms) with coefficient 0 are not included.\n\t\nFor example",
" an expression of \"0\" has an output of [].\n\nFor example",
" an expression of \"0\" has an output of []. 1 <= expression. length <= 250expression consists of lowercase English letters",
" digits",
" '+'",
" '-'",
" '*'",
" '('",
" ')'",
" ' '. expression does not contain any leading or trailing spaces. All the tokens in expression are separated by a single space. 0 <= evalvars. length <= 1001 <= evalvars[i]. length <= 20evalvars[i] consists of lowercase English letters. evalints. length == evalvars. length-100 <= evalints[i] <= 100"
]
},
{
"id": "773",
"title": "Sliding Puzzle",
"question": "On an 2 x 3 board, there are five tiles labeled from 1 to 5, and an empty square represented by 0.\n A move consists of choosing 0 and a 4-directionally adjacent number and swapping it.\nThe state of the board is solved if and only if the board is [[1,2,3],[4,5,0]].\nGiven the puzzle board board, return the least number of moves required so that the state of the board is solved.\n If it is impossible for the state of the board to be solved, return -1.",
"examples": [
"Input: board = [[1,2,3],[4,0,5]]",
"Output: 1",
"Explanation: Swap the 0 and the 5 in one move.",
"Input: board = [[1,2,3],[5,4,0]]",
"Output: -1",
"Explanation: No number of moves will make the board solved.",
"Input: board = [[4,1,2],[5,0,3]]",
"Output: 5",
"Explanation: 5 is the smallest number of moves that solves the board.",
"An example path:",
"After move 0: [[4,1,2],[5,0,3]]",
"After move 1: [[4,1,2],[0,5,3]]",
"After move 2: [[0,1,2],[4,5,3]]",
"After move 3: [[1,0,2],[4,5,3]]",
"After move 4: [[1,2,0],[4,5,3]]",
"After move 5: [[1,2,3],[4,5,0]]",
"Input: board = [[3,2,4],[1,5,0]]",
"Output: 14",
""
],
"constraints": [
"board. length == 2board[i]. length == 30 <= board[i][j] <= 5Each value board[i][j] is unique."
]
},
{
"id": "778",
"title": "Swim in Rising Water",
"question": "You are given an n x n integer matrix grid where each value grid[i][j] represents the elevation at that point (i, j).\nThe rain starts to fall.\n At time t, the depth of the water everywhere is t.\n 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.\n You can swim infinite distances in zero time.\n Of course, you must stay within the boundaries of the grid during your swim.\nReturn 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).",
"examples": [
"Input: grid = [[0,2],[1,3]]",
"Output: 3",
"Explanation:",
"At time 0, you are in grid location (0, 0).",
"You cannot go anywhere else because 4-directionally adjacent neighbors have a higher elevation than t = 0.",
"You cannot reach point (1, 1) until time 3.",
"When the depth of water is 3, we can swim anywhere inside the grid.",
"Input: 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]]",
"Output: 16",
"Explanation: The final route is shown.",
"We need to wait until time 16 so that (0, 0) and (4, 4) are connected.",
""
],
"constraints": [
"n == grid. lengthn == grid[i]. length1 <= n <= 500 <= grid[i][j] < n2Each value grid[i][j] is unique."
]
},
{
"id": "780",
"title": "Reaching Points",
"question": "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.\nThe allowed operation on some point (x, y) is to convert it to either (x, x + y) or (x + y, y).",
"examples": [
"Input: sx = 1, sy = 1, tx = 3, ty = 5",
"Output: true",
"Explanation:",
"One series of moves that transforms the starting point to the target is:",
"(1, 1) -> (1, 2)",
"(1, 2) -> (3, 2)",
"(3, 2) -> (3, 5)",
"Input: sx = 1, sy = 1, tx = 2, ty = 2",
"Output: false",
"Input: sx = 1, sy = 1, tx = 1, ty = 1",
"Output: true",
""
],
"constraints": [
"1 <= sx",
" sy",
" tx",
" ty <= 109"
]
},
{
"id": "782",
"title": "Transform to Chessboard",
"question": "You are given an n x n binary grid board.\n In each move, you can swap any two rows with each other, or any two columns with each other.\nReturn the minimum number of moves to transform the board into a chessboard board.\n If the task is impossible, return -1.\nA chessboard board is a board where no 0's and no 1's are 4-directionally adjacent.",
"examples": [
"Input: board = [[0,1,1,0],[0,1,1,0],[1,0,0,1],[1,0,0,1]]",
"Output: 2",
"Explanation: One potential sequence of moves is shown.",
"The first move swaps the first and second column.",
"The second move swaps the second and third row.",
"Input: board = [[0,1],[1,0]]",
"Output: 0",
"Explanation: Also note that the board with 0 in the top left corner, is also a valid chessboard.",
"Input: board = [[1,0],[1,0]]",
"Output: -1",
"Explanation: No matter what sequence of moves you make, you cannot end with a valid chessboard.",
""
],
"constraints": [
"n == board. lengthn == board[i]. length2 <= n <= 30board[i][j] is either 0 or 1."
]
},
{
"id": "786",
"title": "K-th Smallest Prime Fraction",
"question": "You are given a sorted integer array arr containing 1 and prime numbers, where all the integers of arr are unique.\n You are also given an integer k.\nFor every i and j where 0 <= i < j < arr.\nlength, we consider the fraction arr[i] / arr[j].\nReturn the kth smallest fraction considered.\n Return your answer as an array of integers of size 2, where answer[0] == arr[i] and answer[1] == arr[j].",
"examples": [
"Input: arr = [1,2,3,5], k = 3",
"Output: [2,5]",
"Explanation: The fractions to be considered in sorted order are:",
"1/5, 1/3, 2/5, 1/2, 3/5, and 2/3.",
"The third fraction is 2/5.",
"Input: arr = [1,7], k = 1",
"Output: [1,7]",
""
],
"constraints": [
"2 <= arr. length <= 10001 <= arr[i] <= 3 * 104arr[0] == 1arr[i] is a prime number for i > 0. All the numbers of arr are unique and sorted in strictly increasing order. 1 <= k <= arr. length * (arr. length - 1) / 2"
]
},
{
"id": "793",
"title": "Preimage Size of Factorial Zeroes Function",
"question": "Let f(x) be the number of zeroes at the end of x!.\n Recall that x! = 1 * 2 * 3 * .\n.\n.\n * x and by convention, 0! = 1.\nGiven an integer k, return the number of non-negative integers x have the property that f(x) = k.",
"examples": [
"Input: k = 0",
"Output: 5",
"Explanation: 0!, 1!, 2!, 3!, and 4! end with k = 0 zeroes.",
"Input: k = 5",
"Output: 0",
"Explanation: There is no x such that x! ends in k = 5 zeroes.",
"Input: k = 3",
"Output: 5",
""
],
"constraints": [
"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. 0 <= k <= 109"
]
},
{
"id": "798",
"title": "Smallest Rotation with Highest Score",
"question": "You are given an array nums.\n You can rotate it by a non-negative integer k so that the array becomes [nums[k], nums[k + 1], .\n.\n.\n nums[nums.\nlength - 1], nums[0], nums[1], .\n.\n.\n, nums[k-1]].\n Afterward, any entries that are less than or equal to their index are worth one point.\nReturn the rotation index k that corresponds to the highest score we can achieve if we rotated nums by it.\n If there are multiple answers, return the smallest such index k.",
"examples": [
"Input: nums = [2,3,1,4,0]",
"Output: 3",
"Explanation: Scores for each k are listed below: ",
"k = 0, nums = [2,3,1,4,0], score 2",
"k = 1, nums = [3,1,4,0,2], score 3",
"k = 2, nums = [1,4,0,2,3], score 3",
"k = 3, nums = [4,0,2,3,1], score 4",
"k = 4, nums = [0,2,3,1,4], score 3",
"So we should choose k = 3, which has the highest score.",
"Input: nums = [1,3,0,2,4]",
"Output: 0",
"Explanation: nums will always have 3 points no matter how it shifts.",
"So we will choose the smallest k, which is 0.",
""
],
"constraints": [
"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]. 1 <= nums. length <= 1050 <= nums[i] < nums. length"
]
},
{
"id": "801",
"title": "Minimum Swaps To Make Sequences Increasing",
"question": "You are given two integer arrays of the same length nums1 and nums2.\n In one operation, you are allowed to swap nums1[i] with nums2[i].\nReturn the minimum number of needed operations to make nums1 and nums2 strictly increasing.\n The test cases are generated so that the given input always makes it possible.\nAn array arr is strictly increasing if and only if arr[0] < arr[1] < arr[2] < .\n.\n.\n < arr[arr.\nlength - 1].",
"examples": [
"Input: nums1 = [1,3,5,4], nums2 = [1,2,3,7]",
"Output: 1",
"Explanation: ",
"Swap nums1[3] and nums2[3]. Then the sequences are:",
"nums1 = [1, 3, 5, 7] and nums2 = [1, 2, 3, 4]",
"which are both strictly increasing.",
"Input: nums1 = [0,3,5,8,9], nums2 = [2,1,4,6,9]",
"Output: 1",
""
],
"constraints": [
"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]. 2 <= nums1. length <= 105nums2. length == nums1. length0 <= nums1[i]",
" nums2[i] <= 2 * 105"
]
},
{
"id": "803",
"title": "Bricks Falling When Hit",
"question": "You are given an m x n binary grid, where each 1 represents a brick and 0 represents an empty space.\n A brick is stable if:You are also given an array hits, which is a sequence of erasures we want to apply.\n Each time we want to erase the brick at the location hits[i] = (rowi, coli).\n The brick on that location (if it exists) will disappear.\n Some other bricks may no longer be stable because of that erasure and will fall.\n Once a brick falls, it is immediately erased from the grid (i.\ne.\n, it does not land on other stable bricks).\nReturn an array result, where each result[i] is the number of bricks that will fall after the ith erasure is applied.\nNote that an erasure may refer to a location with no brick, and if it does, no bricks drop.",
"examples": [
"Input: grid = [[1,0,0,0],[1,1,1,0]], hits = [[1,0]]",
"Output: [2]",
"Explanation: Starting with the grid:",
"[[1,0,0,0],",
" [1,1,1,0]]",
"We erase the underlined brick at (1,0), resulting in the grid:",
"[[1,0,0,0],",
" [0,1,1,0]]",
"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:",
"[[1,0,0,0],",
" [0,0,0,0]]",
"Hence the result is [2].",
"Input: grid = [[1,0,0,0],[1,1,0,0]], hits = [[1,1],[1,0]]",
"Output: [0,0]",
"Explanation: Starting with the grid:",
"[[1,0,0,0],",
" [1,1,0,0]]",
"We erase the underlined brick at (1,1), resulting in the grid:",
"[[1,0,0,0],",
" [1,0,0,0]]",
"All remaining bricks are still stable, so no bricks fall. The grid remains the same:",
"[[1,0,0,0],",
" [1,0,0,0]]",
"Next, we erase the underlined brick at (1,0), resulting in the grid:",
"[[1,0,0,0],",
" [0,0,0,0]]",
"Once again, all remaining bricks are still stable, so no bricks fall.",
"Hence the result is [0,0].",
""
],
"constraints": [
"It is directly connected to the top of the grid",
" orAt least one other brick in its four adjacent cells is stable. m == grid. lengthn == grid[i]. length1 <= m",
" n <= 200grid[i][j] is 0 or 1. 1 <= hits. length <= 4 * 104hits[i]. length == 20 <= xi <= m - 10 <= yi <= n - 1All (xi",
" yi) are unique."
]
},
{
"id": "66",
"title": "Plus One",
"question": "You are given a large integer represented as an integer array digits, where each digits[i] is the ith digit of the integer.\n The digits are ordered from most significant to least significant in left-to-right order.\n The large integer does not contain any leading 0's.\nIncrement the large integer by one and return the resulting array of digits.",
"examples": [
"Input: digits = [1,2,3]",
"Output: [1,2,4]",
"Explanation: The array represents the integer 123.",
"Incrementing by one gives 123 + 1 = 124.",
"Thus, the result should be [1,2,4].",
"Input: digits = [4,3,2,1]",
"Output: [4,3,2,2]",
"Explanation: The array represents the integer 4321.",
"Incrementing by one gives 4321 + 1 = 4322.",
"Thus, the result should be [4,3,2,2].",
"Input: digits = [0]",
"Output: [1]",
"Explanation: The array represents the integer 0.",
"Incrementing by one gives 0 + 1 = 1.",
"Thus, the result should be [1].",
"Input: digits = [9]",
"Output: [1,0]",
"Explanation: The array represents the integer 9.",
"Incrementing by one gives 9 + 1 = 10.",
"Thus, the result should be [1,0].",
""
],
"constraints": [
"1 <= digits. length <= 1000 <= digits[i] <= 9digits does not contain any leading 0's."
]
},
{
"id": "617",
"title": "Merge Two Binary Trees",
"question": "You are given two binary trees root1 and root2.\nImagine that when you put one of them to cover the other, some nodes of the two trees are overlapped while the others are not.\n You need to merge the two trees into a new binary tree.\n The merge rule is that if two nodes overlap, then sum node values up as the new value of the merged node.\n Otherwise, the NOT null node will be used as the node of the new tree.\nReturn the merged tree.\nNote: The merging process must start from the root nodes of both trees.",
"examples": [
"Input: root1 = [1,3,2,5], root2 = [2,1,3,null,4,null,7]",
"Output: [3,4,5,5,4,null,7]",
"Input: root1 = [1], root2 = [1,2]",
"Output: [2,2]",
""
],
"constraints": [
"The number of nodes in both trees is in the range [0",
" 2000].-104 <= Node. val <= 104"
]
},
{
"id": "805",
"title": "Split Array With Same Average",
"question": "You are given an integer array nums.\nYou 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).\nReturn true if it is possible to achieve that and false otherwise.\nNote that for an array arr, average(arr) is the sum of all the elements of arr over the length of arr.",
"examples": [
"Input: nums = [1,2,3,4,5,6,7,8]",
"Output: true",
"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.",
"Input: nums = [3,1]",
"Output: false",
""
],
"constraints": [
"1 <= nums. length <= 300 <= nums[i] <= 104"
]
},
{
"id": "810",
"title": "Chalkboard XOR Game",
"question": "You are given an array of integers nums represents the numbers written on a chalkboard.\nAlice and Bob take turns erasing exactly one number from the chalkboard, with Alice starting first.\n If erasing a number causes the bitwise XOR of all the elements of the chalkboard to become 0, then that player loses.\n The bitwise XOR of one element is that element itself, and the bitwise XOR of no elements is 0.\nAlso, if any player starts their turn with the bitwise XOR of all the elements of the chalkboard equal to 0, then that player wins.\nReturn true if and only if Alice wins the game, assuming both players play optimally.",
"examples": [
"Input: nums = [1,1,2]",
"Output: false",
"Explanation: ",
"Alice has two choices: erase 1 or erase 2. ",
"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. ",
"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.",
"Input: nums = [0,1]",
"Output: true",
"Input: nums = [1,2,3]",
"Output: true",
""
],
"constraints": [
"1 <= nums. length <= 10000 <= nums[i] < 216"
]
},
{
"id": "815",
"title": "Bus Routes",
"question": "You are given an array routes representing bus routes where routes[i] is a bus route that the ith bus repeats forever.\nYou will start at the bus stop source (You are not on any bus initially), and you want to go to the bus stop target.\n You can travel between bus stops by buses only.\nReturn the least number of buses you must take to travel from source to target.\n Return -1 if it is not possible.",
"examples": [
"Input: routes = [[1,2,7],[3,6,7]], source = 1, target = 6",
"Output: 2",
"Explanation: The best strategy is take the first bus to the bus stop 7, then take the second bus to the bus stop 6.",
"Input: routes = [[7,12],[4,5,15],[6],[15,19],[9,12,13]], source = 15, target = 12",
"Output: -1",
""
],
"constraints": [
"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. 1 <= routes. length <= 500. 1 <= routes[i]. length <= 105All the values of routes[i] are unique. sum(routes[i]. length) <= 1050 <= routes[i][j] < 1060 <= source",
" target < 106"
]
},
{
"id": "818",
"title": "Race Car",
"question": "Your car starts at position 0 and speed +1 on an infinite number line.\n Your car can go into negative positions.\n Your car drives automatically according to a sequence of instructions 'A' (accelerate) and 'R' (reverse):For example, after commands \"AAR\", your car goes to positions 0 --> 1 --> 3 --> 3, and your speed goes to 1 --> 2 --> 4 --> -1.\nGiven a target position target, return the length of the shortest sequence of instructions to get there.",
"examples": [
"Input: target = 3",
"Output: 2",
"Explanation: ",
"The shortest instruction sequence is \"AA\".",
"Your position goes from 0 --> 1 --> 3.",
"Input: target = 6",
"Output: 5",
"Explanation: ",
"The shortest instruction sequence is \"AAARA\".",
"Your position goes from 0 --> 1 --> 3 --> 7 --> 7 --> 6.",
""
],
"constraints": [
"When you get an instruction 'A'",
" your car does the following:\n\n\t\nposition += speed\nspeed *= 2\n\nposition += speedspeed *= 2When you get an instruction 'R'",
" your car does the following:\n\t\nIf your speed is positive then speed = -1\notherwise speed = 1\n\n\tYour position stays the same. If your speed is positive then speed = -1otherwise speed = 11 <= target <= 104"
]
},
{
"id": "827",
"title": "Making A Large Island",
"question": "You are given an n x n binary matrix grid.\n You are allowed to change at most one 0 to be 1.\nReturn the size of the largest island in grid after applying this operation.\nAn island is a 4-directionally connected group of 1s.",
"examples": [
"Input: grid = [[1,0],[0,1]]",
"Output: 3",
"Explanation: Change one 0 to 1 and connect two 1s, then we get an island with area = 3.",
"Input: grid = [[1,1],[1,0]]",
"Output: 4",
"Explanation: Change the 0 to 1 and make the island bigger, only one island with area = 4. Input: grid = [[1,1],[1,1]]",
"Output: 4",
"Explanation: Can't change any 0 to 1, only one island with area = 4.",
""
],
"constraints": [
"n == grid. lengthn == grid[i]. length1 <= n <= 500grid[i][j] is either 0 or 1."
]
},
{
"id": "828",
"title": "Count Unique Characters of All Substrings of a Given String",
"question": "Let's define a function countUniqueChars(s) that returns the number of unique characters on s.\nGiven a string s, return the sum of countUniqueChars(t) where t is a substring of s.\nNotice that some substrings can be repeated so in this case you have to count the repeated ones too.",
"examples": [
"Input: s = \"ABC\"",
"Output: 10",
"Explanation: All possible substrings are: \"A\",\"B\",\"C\",\"AB\",\"BC\" and \"ABC\".",
"Evey substring is composed with only unique letters.",
"Sum of lengths of all substring is 1 + 1 + 1 + 2 + 2 + 3 = 10",
"Input: s = \"ABA\"",
"Output: 8",
"Explanation: The same as example 1, except countUniqueChars(\"ABA\") = 1.",
"Input: s = \"LEETCODE\"",
"Output: 92",
""
],
"constraints": [
"For example if s = \"LEETCODE\" then \"L\"",
" \"T\"",
" \"C\"",
" \"O\"",
" \"D\" are the unique characters since they appear only once in s",
" therefore countUniqueChars(s) = 5. 1 <= s. length <= 105s consists of uppercase English letters only."
]
},
{
"id": "829",
"title": "Consecutive Numbers Sum",
"question": "Given an integer n, return the number of ways you can write n as the sum of consecutive positive integers.",
"examples": [
"Input: n = 5",
"Output: 2",
"Explanation: 5 = 2 + 3",
"Input: n = 9",
"Output: 3",
"Explanation: 9 = 4 + 5 = 2 + 3 + 4",
"Input: n = 15",
"Output: 4",
"Explanation: 15 = 8 + 7 = 4 + 5 + 6 = 1 + 2 + 3 + 4 + 5",
""
],
"constraints": [
"1 <= n <= 109"
]
},
{
"id": "834",
"title": "Sum of Distances in Tree",
"question": "There is an undirected connected tree with n nodes labeled from 0 to n - 1 and n - 1 edges.\nYou 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.\nReturn 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.",
"examples": [
"Input: n = 6, edges = [[0,1],[0,2],[2,3],[2,4],[2,5]]",
"Output: [8,12,6,10,10,10]",
"Explanation: The tree is shown above.",
"We can see that dist(0,1) + dist(0,2) + dist(0,3) + dist(0,4) + dist(0,5)",
"equals 1 + 1 + 2 + 2 + 2 = 8.",
"Hence, answer[0] = 8, and so on.",
"Input: n = 1, edges = []",
"Output: [0]",
"Input: n = 2, edges = [[1,0]]",
"Output: [1,1]",
""
],
"constraints": [
"1 <= n <= 3 * 104edges. length == n - 1edges[i]. length == 20 <= ai",
" bi < nai != biThe given input represents a valid tree."
]
},
{
"id": "839",
"title": "Similar String Groups",
"question": "Two strings X and Y are similar if we can swap two letters (in different positions) of X, so that it equals Y.\n Also two strings X and Y are similar if they are equal.\nFor example, \"tars\" and \"rats\" are similar (swapping at positions 0 and 2), and \"rats\" and \"arts\" are similar, but \"star\" is not similar to \"tars\", \"rats\", or \"arts\".\nTogether, these form two connected groups by similarity: {\"tars\", \"rats\", \"arts\"} and {\"star\"}.\n  Notice that \"tars\" and \"arts\" are in the same group even though they are not similar.\n  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.\nWe are given a list strs of strings where every string in strs is an anagram of every other string in strs.\n How many groups are there?",
"examples": [
"Input: strs = [\"tars\",\"rats\",\"arts\",\"star\"]",
"Output: 2",
"Input: strs = [\"omv\",\"ovm\"]",
"Output: 1",
""
],
"constraints": [
"1 <= strs. length <= 3001 <= strs[i]. length <= 300strs[i] consists of lowercase letters only. All words in strs have the same length and are anagrams of each other."
]
},
{
"id": "843",
"title": "Guess the Word",
"question": "This is an interactive problem.\nYou are given an array of unique strings wordlist where wordlist[i] is 6 letters long, and one word in this list is chosen as secret.\nYou may call Master.\nguess(word) to guess a word.\n The guessed word should have type string and must be from the original list with 6 lowercase letters.\nThis function returns an integer type, representing the number of exact matches (value and position) of your guess to the secret word.\n Also, if your guess is not in the given wordlist, it will return -1 instead.\nFor each test case, you have exactly 10 guesses to guess the word.\n At the end of any number of calls, if you have made 10 or fewer calls to Master.\nguess and at least one of these guesses was secret, then you pass the test case.",
"examples": [
"Input: secret = \"acckzz\", wordlist = [\"acckzz\",\"ccbazz\",\"eiowzz\",\"abcczz\"], numguesses = 10",
"Output: You guessed the secret word correctly.",
"Explanation:",
"master. guess(\"aaaaaa\") returns -1, because \"aaaaaa\" is not in wordlist.",
"master. guess(\"acckzz\") returns 6, because \"acckzz\" is secret and has all 6 matches.",
"master. guess(\"ccbazz\") returns 3, because \"ccbazz\" has 3 matches.",
"master. guess(\"eiowzz\") returns 2, because \"eiowzz\" has 2 matches.",
"master. guess(\"abcczz\") returns 4, because \"abcczz\" has 4 matches.",
"We made 5 calls to master. guess and one of them was the secret, so we pass the test case.",
"Input: secret = \"hamada\", wordlist = [\"hamada\",\"khaled\"], numguesses = 10",
"Output: You guessed the secret word correctly.",
""
],
"constraints": [
"1 <= wordlist. length <= 100wordlist[i]. length == 6wordlist[i] consist of lowercase English letters. All the strings of wordlist are unique. secret exists in wordlist. numguesses == 10"
]
},
{
"id": "628",
"title": "Maximum Product of Three Numbers",
"question": "Given an integer array nums, find three numbers whose product is maximum and return the maximum product.",
"examples": [
"Input: nums = [1,2,3]",
"Output: 6",
"Input: nums = [1,2,3,4]",
"Output: 24",
"Input: nums = [-1,-2,-3]",
"Output: -6",
""
],
"constraints": [
"3 <= nums. length <= 104-1000 <= nums[i] <= 1000"
]
},
{
"id": "847",
"title": "Shortest Path Visiting All Nodes",
"question": "You have an undirected, connected graph of n nodes labeled from 0 to n - 1.\n You are given an array graph where graph[i] is a list of all the nodes connected with node i by an edge.\nReturn the length of the shortest path that visits every node.\n You may start and stop at any node, you may revisit nodes multiple times, and you may reuse edges.",
"examples": [
"Input: graph = [[1,2,3],[0],[0],[0]]",
"Output: 4",
"Explanation: One possible path is [1,0,2,0,3]",
"Input: graph = [[1],[0,2,4],[1,3,4],[2],[1,2]]",
"Output: 4",
"Explanation: One possible path is [0,1,4,2,3]",
""
],
"constraints": [
"n == graph. length1 <= n <= 120 <= graph[i]. length < ngraph[i] does not contain i. If graph[a] contains b",
" then graph[b] contains a. The input graph is always connected."
]
},
{
"id": "850",
"title": "Rectangle Area II",
"question": "We are given a list of (axis-aligned) rectangles.\n Each rectangle[i] = [xi1, yi1, xi2, yi2] , where (xi1, yi1) are the coordinates of the bottom-left corner, and (xi2, yi2) are the coordinates of the top-right corner of the ith rectangle.\nFind the total area covered by all rectangles in the plane.\n Since the answer may be too large, return it modulo 109 + 7.",
"examples": [
"Input: rectangles = [[0,0,2,2],[1,0,2,3],[1,0,3,1]]",
"Output: 6",
"Explanation: As illustrated in the picture.",
"Input: rectangles = [[0,0,1000000000,1000000000]]",
"Output: 49",
"Explanation: The answer is 1018 modulo (109 + 7), which is (109)2 = (-7)2 = 49.",
""
],
"constraints": [
"1 <= rectangles. length <= 200rectanges[i]. length = 40 <= rectangles[i][j] <= 109The total area covered by all rectangles will never exceed 263 - 1 and thus will fit in a 64-bit signed integer."
]
},
{
"id": "854",
"title": "K-Similar Strings",
"question": "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.\nGiven two anagrams s1 and s2, return the smallest k for which s1 and s2 are k-similar.",
"examples": [
"Input: s1 = \"ab\", s2 = \"ba\"",
"Output: 1",
"Input: s1 = \"abc\", s2 = \"bca\"",
"Output: 2",
"Input: s1 = \"abac\", s2 = \"baca\"",
"Output: 2",
"Input: s1 = \"aabc\", s2 = \"abca\"",
"Output: 2",
""
],
"constraints": [
"1 <= s1. length <= 20s2. length == s1. lengths1 and s2 contain only lowercase letters from the set {'a'",
" 'b'",
" 'c'",
" 'd'",
" 'e'",
" 'f'}. s2 is an anagram of s1."
]
},
{
"id": "857",
"title": "Minimum Cost to Hire K Workers",
"question": "There are n workers.\n 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.\nWe want to hire exactly k workers to form a paid group.\n To hire a group of k workers, we must pay them according to the following rules:Given the integer k, return the least amount of money needed to form a paid group satisfying the above conditions.\n Answers within 10-5 of the actual answer will be accepted.",
"examples": [
"Input: quality = [10,20,5], wage = [70,50,30], k = 2",
"Output: 105. 00000",
"Explanation: We pay 70 to 0th worker and 35 to 2nd worker.",
"Input: quality = [3,1,10,10,1], wage = [4,8,2,2,7], k = 3",
"Output: 30. 66667",
"Explanation: We pay 4 to 0th worker, 13. 33333 to 2nd and 3rd workers separately.",
""
],
"constraints": [
"n == quality. length == wage. length1 <= k <= n <= 1041 <= quality[i]",
" wage[i] <= 104"
]
},
{
"id": "862",
"title": "Shortest Subarray with Sum at Least K",
"question": "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.\n If there is no such subarray, return -1.\nA subarray is a contiguous part of an array.",
"examples": [
"Input: nums = [1], k = 1",
"Output: 1",
"Input: nums = [1,2], k = 4",
"Output: -1",
"Input: nums = [2,-1,2], k = 3",
"Output: 3",
""
],
"constraints": [
"1 <= nums. length <= 105-105 <= nums[i] <= 1051 <= k <= 109"
]
},
{
"id": "864",
"title": "Shortest Path to Get All Keys",
"question": "You are given an m x n grid grid where:You start at the starting point and one move consists of walking one space in one of the four cardinal directions.\n You cannot walk outside the grid, or walk into a wall.\nIf you walk over a key, you can pick it up and you cannot walk over a lock unless you have its corresponding key.\nFor 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.\n 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.\nReturn the lowest number of moves to acquire all keys.\n If it is impossible, return -1.",
"examples": [
"Input: grid = [\"@. a.#\",\"###.#\",\"b. A. B\"]",
"Output: 8",
"Explanation: Note that the goal is to obtain all the keys not to open all the locks.",
"Input: grid = [\"@.. aA\",\".. B#.\",\".... b\"]",
"Output: 6",
"Input: grid = [\"@Aa\"]",
"Output: -1",
""
],
"constraints": [
"'.' is an empty cell.'#' is a wall.'@' is the starting point. Lowercase letters represent keys. Uppercase letters represent locks. m == grid. lengthn == grid[i]. length1 <= m",
" n <= 30grid[i][j] is either an English letter",
" '.'",
" '#'",
" or '@'. The number of keys in the grid is in the range [1",
" 6]. Each key in the grid is unique. Each key in the grid has a matching lock."
]
},
{
"id": "871",
"title": "Minimum Number of Refueling Stops",
"question": "A car travels from a starting position to a destination which is target miles east of the starting position.\nThere are gas stations along the way.\n 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.\nThe car starts with an infinite tank of gas, which initially has startFuel liters of fuel in it.\n It uses one liter of gas per one mile that it drives.\n When the car reaches a gas station, it may stop and refuel, transferring all the gas from the station into the car.\nReturn the minimum number of refueling stops the car must make in order to reach its destination.\n If it cannot reach the destination, return -1.\nNote that if the car reaches a gas station with 0 fuel left, the car can still refuel there.\n If the car reaches the destination with 0 fuel left, it is still considered to have arrived.",
"examples": [
"Input: target = 1, startFuel = 1, stations = []",
"Output: 0",
"Explanation: We can reach the target without refueling.",
"Input: target = 100, startFuel = 1, stations = [[10,100]]",
"Output: -1",
"Explanation: We can not reach the target (or even the first gas station).",
"Input: target = 100, startFuel = 10, stations = [[10,60],[20,30],[30,30],[60,40]]",
"Output: 2",
"Explanation: We start with 10 liters of fuel.",
"We drive to position 10, expending 10 liters of fuel. We refuel from 0 liters to 60 liters of gas.",
"Then, we drive from position 10 to position 60 (expending 50 liters of fuel),",
"and refuel from 10 liters to 50 liters of gas. We then drive to and reach the target.",
"We made 2 refueling stops along the way, so we return 2.",
""
],
"constraints": [
"1 <= target",
" startFuel <= 1090 <= stations. length <= 5000 <= positioni <= positioni+1 < target1 <= fueli < 109"
]
},
{
"id": "878",
"title": "Nth Magical Number",
"question": "A positive integer is magical if it is divisible by either a or b.\nGiven the three integers n, a, and b, return the nth magical number.\n Since the answer may be very large, return it modulo 109 + 7.",
"examples": [
"Input: n = 1, a = 2, b = 3",
"Output: 2",
"Input: n = 4, a = 2, b = 3",
"Output: 6",
"Input: n = 5, a = 2, b = 4",
"Output: 10",
"Input: n = 3, a = 6, b = 4",
"Output: 8",
""
],
"constraints": [
"1 <= n <= 1092 <= a",
" b <= 4 * 104"
]
},
{
"id": "879",
"title": "Profitable Schemes",
"question": "There is a group of n members, and a list of various crimes they could commit.\n The ith crime generates a profit[i] and requires group[i] members to participate in it.\n If a member participates in one crime, that member can't participate in another crime.\nLet'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.\nReturn the number of schemes that can be chosen.\n Since the answer may be very large, return it modulo 109 + 7.",
"examples": [
"Input: n = 5, minProfit = 3, group = [2,2], profit = [2,3]",
"Output: 2",
"Explanation: To make a profit of at least 3, the group could either commit crimes 0 and 1, or just crime 1.",
"In total, there are 2 schemes. Input: n = 10, minProfit = 5, group = [2,3,5], profit = [6,7,8]",
"Output: 7",
"Explanation: To make a profit of at least 5, the group could commit any crimes, as long as they commit one.",
"There are 7 possible schemes: (0), (1), (2), (0,1), (0,2), (1,2), and (0,1,2)."
],
"constraints": [
"1 <= n <= 1000 <= minProfit <= 1001 <= group. length <= 1001 <= group[i] <= 100profit. length == group. length0 <= profit[i] <= 100"
]
},
{
"id": "882",
"title": "Reachable Nodes In Subdivided Graph",
"question": "You are given an undirected graph (the \"original graph\") with n nodes labeled from 0 to n - 1.\n You decide to subdivide each edge in the graph into a chain of nodes, with the number of new nodes varying between each edge.\nThe 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.\n Note that cnti == 0 means you will not subdivide the edge.\nTo subdivide the edge [ui, vi], replace it with (cnti + 1) new edges and cnti new nodes.\n The new nodes are x1, x2, .\n.\n.\n, xcnti, and the new edges are [ui, x1], [x1, x2], [x2, x3], .\n.\n.\n, [xcnti+1, xcnti], [xcnti, vi].\nIn 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.\nGiven the original graph and maxMoves, return the number of nodes that are reachable from node 0 in the new graph.",
"examples": [
"Input: edges = [[0,1,10],[0,2,1],[1,2,2]], maxMoves = 6, n = 3",
"Output: 13",
"Explanation: The edge subdivisions are shown in the image above.",
"The nodes that are reachable are highlighted in yellow.",
"Input: edges = [[0,1,4],[1,2,6],[0,2,8],[1,3,1]], maxMoves = 10, n = 4",
"Output: 23",
"Input: edges = [[1,2,4],[1,4,5],[1,3,1],[2,3,4],[3,4,5]], maxMoves = 17, n = 5",
"Output: 1",
"Explanation: Node 0 is disconnected from the rest of the graph, so only node 0 is reachable.",
""
],
"constraints": [
"0 <= edges. length <= min(n * (n - 1) / 2",
" 104)edges[i]. length == 30 <= ui < vi < nThere are no multiple edges in the graph. 0 <= cnti <= 1040 <= maxMoves <= 1091 <= n <= 3000"
]
},
{
"id": "637",
"title": "Average of Levels in Binary Tree",
"question": "",
"examples": [
"Input: root = [3,9,20,null,15,7]",
"Output: [3. 00000,14. 50000,11. 00000]",
"Explanation: The average value of nodes on level 0 is 3, on level 1 is 14. 5, and on level 2 is 11.",
"Hence return [3, 14. 5, 11].",
"Input: root = [3,9,20,15,7]",
"Output: [3. 00000,14. 50000,11. 00000]",
""
],
"constraints": [
"The number of nodes in the tree is in the range [1",
" 104].-231 <= Node. val <= 231 - 1"
]
},
{
"id": "887",
"title": "Super Egg Drop",
"question": "You are given k identical eggs and you have access to a building with n floors labeled from 1 to n.\nYou 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.\nEach move, you may take an unbroken egg and drop it from any floor x (where 1 <= x <= n).\n If the egg breaks, you can no longer use it.\n However, if the egg does not break, you may reuse it in future moves.\nReturn the minimum number of moves that you need to determine with certainty what the value of f is.",
"examples": [
"Input: k = 1, n = 2",
"Output: 2",
"Explanation: ",
"Drop the egg from floor 1. If it breaks, we know that f = 0.",
"Otherwise, drop the egg from floor 2. If it breaks, we know that f = 1.",
"If it does not break, then we know f = 2.",
"Hence, we need at minimum 2 moves to determine with certainty what the value of f is.",
"Input: k = 2, n = 6",
"Output: 3",
"Input: k = 3, n = 14",
"Output: 4",
""
],
"constraints": [
"1 <= k <= 1001 <= n <= 104"
]
},
{
"id": "891",
"title": "Sum of Subsequence Widths",
"question": "The width of a sequence is the difference between the maximum and minimum elements in the sequence.\nGiven an array of integers nums, return the sum of the widths of all the non-empty subsequences of nums.\n Since the answer may be very large, return it modulo 109 + 7.\nA 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.\n For example, [3,6,2,7] is a subsequence of the array [0,3,1,6,2,2,7].",
"examples": [
"Input: nums = [2,1,3]",
"Output: 6",
"Explanation: The subsequences are [1], [2], [3], [2,1], [2,3], [1,3], [2,1,3].",
"The corresponding widths are 0, 0, 0, 1, 1, 2, 2.",
"The sum of these widths is 6.",
"Input: nums = [2]",
"Output: 0",
""
],
"constraints": [
"1 <= nums. length <= 1051 <= nums[i] <= 105"
]
},
{
"id": "895",
"title": "Maximum Frequency Stack",
"question": "Design a stack-like data structure to push elements to the stack and pop the most frequent element from the stack.\nImplement the FreqStack class:",
"examples": [
"Input",
"[\"FreqStack\", \"push\", \"push\", \"push\", \"push\", \"push\", \"push\", \"pop\", \"pop\", \"pop\", \"pop\"]",
"[[], [5], [7], [5], [7], [4], [5], [], [], [], []]",
"Output",
"[null, null, null, null, null, null, null, 5, 7, 5, 4]",
"",
"Explanation",
"FreqStack freqStack = new FreqStack();",
"freqStack. push(5); // The stack is [5]",
"freqStack. push(7); // The stack is [5,7]",
"freqStack. push(5); // The stack is [5,7,5]",
"freqStack. push(7); // The stack is [5,7,5,7]",
"freqStack. push(4); // The stack is [5,7,5,7,4]",
"freqStack. push(5); // The stack is [5,7,5,7,4,5]",
"freqStack. pop(); // return 5, as 5 is the most frequent. The stack becomes [5,7,5,7,4].",
"freqStack. pop(); // return 7, as 5 and 7 is the most frequent, but 7 is closest to the top. The stack becomes [5,7,5,4].",
"freqStack. pop(); // return 5, as 5 is the most frequent. The stack becomes [5,7,4].",
"freqStack. pop(); // return 4, as 4, 5 and 7 is the most frequent, but 4 is closest to the top. The stack becomes [5,7].",
""
],
"constraints": [
"FreqStack() constructs an empty frequency stack. void push(int val) pushes an integer val onto the top of the stack. int pop() removes and returns the most frequent element in the stack.\n\t\nIf there is a tie for the most frequent element",
" the element closest to the stack's top is removed and returned.\n\nIf there is a tie for the most frequent element",
" the element closest to the stack's top is removed and returned. 0 <= val <= 109At most 2 * 104 calls will be made to push and pop. It is guaranteed that there will be at least one element in the stack before calling pop."
]
},
{
"id": "899",
"title": "Orderly Queue",
"question": "You are given a string s and an integer k.\n You can choose one of the first k letters of s and append it at the end of the string.\n.\nReturn the lexicographically smallest string you could have after applying the mentioned step any number of moves.",
"examples": [
"Input: s = \"cba\", k = 1",
"Output: \"acb\"",
"Explanation: ",
"In the first move, we move the 1st character 'c' to the end, obtaining the string \"bac\".",
"In the second move, we move the 1st character 'b' to the end, obtaining the final result \"acb\".",
"Input: s = \"baaca\", k = 3",
"Output: \"aaabc\"",
"Explanation: ",
"In the first move, we move the 1st character 'b' to the end, obtaining the string \"aacab\".",
"In the second move, we move the 3rd character 'c' to the end, obtaining the final result \"aaabc\".",
""
],
"constraints": [
"1 <= k <= s. length <= 1000s consist of lowercase English letters."
]
},
{
"id": "902",
"title": "Numbers At Most N Given Digit Set",
"question": "Given an array of digits which is sorted in non-decreasing order.\n You can write numbers using each digits[i] as many times as we want.\n For example, if digits = ['1','3','5'], we may write numbers such as '13', '551', and '1351315'.\nReturn the number of positive integers that can be generated that are less than or equal to a given integer n.",
"examples": [
"Input: digits = [\"1\",\"3\",\"5\",\"7\"], n = 100",
"Output: 20",
"Explanation: ",
"The 20 numbers that can be written are:",
"1, 3, 5, 7, 11, 13, 15, 17, 31, 33, 35, 37, 51, 53, 55, 57, 71, 73, 75, 77.",
"Input: digits = [\"1\",\"4\",\"9\"], n = 1000000000",
"Output: 29523",
"Explanation: ",
"We can write 3 one digit numbers, 9 two digit numbers, 27 three digit numbers,",
"81 four digit numbers, 243 five digit numbers, 729 six digit numbers,",
"2187 seven digit numbers, 6561 eight digit numbers, and 19683 nine digit numbers.",
"In total, this is 29523 integers that can be written using the digits array.",
"Input: digits = [\"7\"], n = 8",
"Output: 1",
""
],
"constraints": [
"1 <= digits. length <= 9digits[i]. length == 1digits[i] is a digit from '1' to '9'. All the values in digits are unique. digits is sorted in non-decreasing order. 1 <= n <= 109"
]
},
{
"id": "903",
"title": "Valid Permutations for DI Sequence",
"question": "You are given a string s of length n where s[i] is either: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:Return the number of valid permutations perm.\n Since the answer may be large, return it modulo 109 + 7.",
"examples": [
"Input: s = \"DID\"",
"Output: 5",
"Explanation: The 5 valid permutations of (0, 1, 2, 3) are:",
"(1, 0, 3, 2)",
"(2, 0, 3, 1)",
"(2, 1, 3, 0)",
"(3, 0, 2, 1)",
"(3, 1, 2, 0)",
"Input: s = \"D\"",
"Output: 1",
""
],
"constraints": [
"'D' means decreasing",
" or'I' means increasing. If s[i] == 'D'",
" then perm[i] > perm[i + 1]",
" andIf s[i] == 'I'",
" then perm[i] < perm[i + 1]. n == s. length1 <= n <= 200s[i] is either 'I' or 'D'."
]
},
{
"id": "906",
"title": "Super Palindromes",
"question": "Let's say a positive integer is a super-palindrome if it is a palindrome, and it is also the square of a palindrome.\nGiven two positive integers left and right represented as strings, return the number of super-palindromes integers in the inclusive range [left, right].",
"examples": [
"Input: left = \"4\", right = \"1000\"",
"Output: 4",
"Explanation: 4, 9, 121, and 484 are superpalindromes.",
"Note that 676 is not a superpalindrome: 26 * 26 = 676, but 26 is not a palindrome.",
"Input: left = \"1\", right = \"2\"",
"Output: 1",
""
],
"constraints": [
"1 <= left. length",
" right. length <= 18left and right consist of only digits. left and right cannot have leading zeros. left and right represent integers in the range [1",
" 1018 - 1]. left is less than or equal to right."
]
},
{
"id": "913",
"title": "Cat and Mouse",
"question": "A game on an undirected graph is played by two players, Mouse and Cat, who alternate turns.\nThe graph is given as follows: graph[a] is a list of all nodes b such that ab is an edge of the graph.\nThe 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.\nDuring each player's turn, they must travel along one edge of the graph that meets where they are.\n  For example, if the Mouse is at node 1, it must travel to any node in graph[1].\nAdditionally, it is not allowed for the Cat to travel to the Hole (node 0.\n)Then, the game can end in three ways:Given a graph, and assuming both players play optimally, return",
"examples": [
"Input: graph = [[2,5],[3],[0,4,5],[1,4,5],[2,3],[0,2,3]]",
"Output: 0",
"Input: graph = [[1,3],[0],[3],[0,2]]",
"Output: 1",
""
],
"constraints": [
"If ever the Cat occupies the same node as the Mouse",
" the Cat wins. If ever the Mouse reaches the Hole",
" the Mouse wins. If ever a position is repeated (i. e.",
" the players are in the same position as a previous turn",
" and it is the same player's turn to move)",
" the game is a draw. 1 if the mouse wins the game",
"2 if the cat wins the game",
" or0 if the game is a draw. 3 <= graph. length <= 501 <= graph[i]. length < graph. length0 <= graph[i][j] < graph. lengthgraph[i][j] != igraph[i] is unique. The mouse and the cat can always move. "
]
},
{
"id": "920",
"title": "Number of Music Playlists",
"question": "Your music player contains n different songs.\n You want to listen to goal songs (not necessarily different) during your trip.\n To avoid boredom, you will create a playlist so that:Given n, goal, and k, return the number of possible playlists that you can create.\n Since the answer can be very large, return it modulo 109 + 7.",
"examples": [
"Input: n = 3, goal = 3, k = 1",
"Output: 6",
"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].",
"Input: n = 2, goal = 3, k = 0",
"Output: 6",
"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].",
"Input: n = 2, goal = 3, k = 1",
"Output: 2",
"Explanation: There are 2 possible playlists: [1, 2, 1] and [2, 1, 2].",
""
],
"constraints": [
"Every song is played at least once. A song can only be played again only if k other songs have been played. 0 <= k < n <= goal <= 100"
]
},
{
"id": "924",
"title": "Minimize Malware Spread",
"question": "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.\nSome nodes initial are initially infected by malware.\n 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.\n This spread of malware will continue until no more nodes can be infected in this manner.\nSuppose 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.\nReturn the node that, if removed, would minimize M(initial).\n If multiple nodes could be removed to minimize M(initial), return such a node with the smallest index.\nNote that if a node was removed from the initial list of infected nodes, it might still be infected later due to the malware spread.",
"examples": [
"Input: graph = [[1,1,0],[1,1,0],[0,0,1]], initial = [0,1]",
"Output: 0",
"Input: graph = [[1,0,0],[0,1,0],[0,0,1]], initial = [0,2]",
"Output: 0",
"Input: graph = [[1,1,1],[1,1,1],[1,1,1]], initial = [1,2]",
"Output: 1",
""
],
"constraints": [
"n == graph. lengthn == graph[i]. length2 <= n <= 300graph[i][j] is 0 or 1. graph[i][j] == graph[j][i]graph[i][i] == 11 <= initial. length <= n0 <= initial[i] <= n - 1All the integers in initial are unique."
]
},
{
"id": "643",
"title": "Maximum Average Subarray I",
"question": "You are given an integer array nums consisting of n elements, and an integer k.\nFind a contiguous subarray whose length is equal to k that has the maximum average value and return this value.\n Any answer with a calculation error less than 10-5 will be accepted.",
"examples": [
"Input: nums = [1,12,-5,-6,50,3], k = 4",
"Output: 12. 75000",
"Explanation: Maximum average is (12 - 5 - 6 + 50) / 4 = 51 / 4 = 12. 75",
"Input: nums = [5], k = 1",
"Output: 5. 00000",
""
],
"constraints": [
"n == nums. length1 <= k <= n <= 105-104 <= nums[i] <= 104"
]
},
{
"id": "927",
"title": "Three Equal Parts",
"question": "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.\nIf it is possible, return any [i, j] with i + 1 < j, such that:If it is not possible, return [-1, -1].\nNote that the entire part is used when considering what binary value it represents.\n For example, [1,1,0] represents 6 in decimal, not 3.\n Also, leading zeros are allowed, so [0,1,1] and [1,1] represent the same value.",
"examples": [
"Input: arr = [1,0,1,0,1]",
"Output: [0,3]",
"Input: arr = [1,1,0,1,1]",
"Output: [-1,-1]",
"Input: arr = [1,1,0,0,1]",
"Output: [0,2]",
""
],
"constraints": [
"arr[0]",
" arr[1]",
" ...",
" arr[i] is the first part",
"arr[i + 1]",
" arr[i + 2]",
" ...",
" arr[j - 1] is the second part",
" andarr[j]",
" arr[j + 1]",
" ...",
" arr[arr. length - 1] is the third part. All three parts have equal binary values. 3 <= arr. length <= 3 * 104arr[i] is 0 or 1"
]
},
{
"id": "928",
"title": "Minimize Malware Spread II",
"question": "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.\nSome nodes initial are initially infected by malware.\n 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.\n This spread of malware will continue until no more nodes can be infected in this manner.\nSuppose M(initial) is the final number of nodes infected with malware in the entire network after the spread of malware stops.\nWe will remove exactly one node from initial, completely removing it and any connections from this node to any other node.\nReturn the node that, if removed, would minimize M(initial).\n If multiple nodes could be removed to minimize M(initial), return such a node with the smallest index.",
"examples": [
"Input: graph = [[1,1,0],[1,1,0],[0,0,1]], initial = [0,1]",
"Output: 0",
"Input: graph = [[1,1,0],[1,1,1],[0,1,1]], initial = [0,1]",
"Output: 1",
"Input: graph = [[1,1,0,0],[1,1,1,0],[0,1,1,1],[0,0,1,1]], initial = [0,1]",
"Output: 1",
""
],
"constraints": [
"n == graph. lengthn == graph[i]. length2 <= n <= 300graph[i][j] is 0 or 1. graph[i][j] == graph[j][i]graph[i][i] == 11 <= initial. length < n0 <= initial[i] <= n - 1All the integers in initial are unique."
]
},
{
"id": "936",
"title": "Stamping The Sequence",
"question": "You are given two strings stamp and target.\n Initially, there is a string s of length target.\nlength with all s[i] == '?'.\nIn one turn, you can place stamp over s and replace every letter in the s with the corresponding letter from stamp.\nWe want to convert s to target using at most 10 * target.\nlength turns.\nReturn an array of the index of the left-most letter being stamped at each turn.\n If we cannot obtain target from s within 10 * target.\nlength turns, return an empty array.",
"examples": [
"Input: stamp = \"abc\", target = \"ababc\"",
"Output: [0,2]",
"Explanation: Initially s = \"?????\".",
"- Place stamp at index 0 to get \"abc??\".",
"- Place stamp at index 2 to get \"ababc\".",
"[1,0,2] would also be accepted as an answer, as well as some other answers.",
"Input: stamp = \"abca\", target = \"aabcaca\"",
"Output: [3,0,1]",
"Explanation: Initially s = \"???????\".",
"- Place stamp at index 3 to get \"???abca\".",
"- Place stamp at index 0 to get \"abcabca\".",
"- Place stamp at index 1 to get \"aabcaca\".",
""
],
"constraints": [
"For example",
" if stamp = \"abc\" and target = \"abcba\"",
" then s is \"?????\" initially. In one turn you can:\n\n\t\nplace stamp at index 0 of s to obtain \"abc??\"",
"\nplace stamp at index 1 of s to obtain \"?abc?\"",
" or\nplace 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). place stamp at index 0 of s to obtain \"abc??\"",
"place stamp at index 1 of s to obtain \"?abc?\"",
" orplace stamp at index 2 of s to obtain \"??abc\". 1 <= stamp. length <= target. length <= 1000stamp and target consist of lowercase English letters."
]
},
{
"id": "940",
"title": "Distinct Subsequences II",
"question": "Given a string s, return the number of distinct non-empty subsequences of s.\n Since the answer may be very large, return it modulo 109 + 7.",
"examples": [
"Input: s = \"abc\"",
"Output: 7",
"Explanation: The 7 distinct subsequences are \"a\", \"b\", \"c\", \"ab\", \"ac\", \"bc\", and \"abc\".",
"Input: s = \"aba\"",
"Output: 6",
"Explanation: The 6 distinct subsequences are \"a\", \"b\", \"ab\", \"aa\", \"ba\", and \"aba\".",
"Input: s = \"aaa\"",
"Output: 3",
"Explanation: The 3 distinct subsequences are \"a\", \"aa\" and \"aaa\".",
""
],
"constraints": [
"1 <= s. length <= 2000s consists of lowercase English letters."
]
},
{
"id": "943",
"title": "Find the Shortest Superstring",
"question": "Given an array of strings words, return the smallest string that contains each string in words as a substring.\n If there are multiple valid strings of the smallest length, return any of them.\nYou may assume that no string in words is a substring of another string in words.",
"examples": [
"Input: words = [\"alex\",\"loves\",\"leetcode\"]",
"Output: \"alexlovesleetcode\"",
"Explanation: All permutations of \"alex\",\"loves\",\"leetcode\" would also be accepted.",
"Input: words = [\"catg\",\"ctaagt\",\"gcta\",\"ttca\",\"atgcatc\"]",
"Output: \"gctaagttcatgcatc\"",
""
],
"constraints": [
"1 <= words. length <= 121 <= words[i]. length <= 20words[i] consists of lowercase English letters. All the strings of words are unique."
]
},
{
"id": "952",
"title": "Largest Component Size by Common Factor",
"question": "You are given an integer array of unique positive integers nums.\n Consider the following graph:Return the size of the largest connected component in the graph.",
"examples": [
"Input: nums = [4,6,15,35]",
"Output: 4",
"Input: nums = [20,50,9,63]",
"Output: 2",
"Input: nums = [2,3,6,7,4,12,21,39]",
"Output: 8",
""
],
"constraints": [
"There are nums. length nodes",
" labeled nums[0] to nums[nums. length - 1]",
"There is an undirected edge between nums[i] and nums[j] if nums[i] and nums[j] share a common factor greater than 1. 1 <= nums. length <= 2 * 1041 <= nums[i] <= 105All the values of nums are unique."
]
},
{
"id": "956",
"title": "Tallest Billboard",
"question": "You are installing a billboard and want it to have the largest height.\n The billboard will have two steel supports, one on each side.\n Each steel support must be an equal height.\nYou are given a collection of rods that can be welded together.\n For example, if you have rods of lengths 1, 2, and 3, you can weld them together to make a support of length 6.\nReturn the largest possible height of your billboard installation.\n If you cannot support the billboard, return 0.",
"examples": [
"Input: rods = [1,2,3,6]",
"Output: 6",
"Explanation: We have two disjoint subsets {1,2,3} and {6}, which have the same sum = 6.",
"Input: rods = [1,2,3,4,5,6]",
"Output: 10",
"Explanation: We have two disjoint subsets {2,3,5} and {4,6}, which have the same sum = 10.",
"Input: rods = [1,2]",
"Output: 0",
"Explanation: The billboard cannot be supported, so we return 0.",
""
],
"constraints": [
"1 <= rods. length <= 201 <= rods[i] <= 1000sum(rods[i]) <= 5000"
]
},
{
"id": "960",
"title": "Delete Columns to Make Sorted III",
"question": "You are given an array of n strings strs, all of the same length.\nWe may choose any deletion indices, and we delete all the characters in those indices for each string.\nFor example, if we have strs = [\"abcdef\",\"uvwxyz\"] and deletion indices {0, 2, 3}, then the final array after deletions is [\"bef\", \"vyz\"].\nSuppose we chose a set of deletion indices answer such that after deletions, the final array has every string (row) in lexicographic order.\n (i.\ne.\n, (strs[0][0] <= strs[0][1] <= .\n.\n.\n <= strs[0][strs[0].\nlength - 1]), and (strs[1][0] <= strs[1][1] <= .\n.\n.\n <= strs[1][strs[1].\nlength - 1]), and so on).\n Return the minimum possible value of answer.\nlength.",
"examples": [
"Input: strs = [\"babca\",\"bbazb\"]",
"Output: 3",
"Explanation: After deleting columns 0, 1, and 4, the final array is strs = [\"bc\", \"az\"].",
"Both these rows are individually in lexicographic order (ie. strs[0][0] <= strs[0][1] and strs[1][0] <= strs[1][1]).",
"Note that strs[0] > strs[1] - the array strs is not necessarily in lexicographic order. Input: strs = [\"edcba\"]",
"Output: 4",
"Explanation: If we delete less than 4 columns, the only row will not be lexicographically sorted.",
"Input: strs = [\"ghi\",\"def\",\"abc\"]",
"Output: 0",
"Explanation: All rows are already lexicographically sorted.",
""
],
"constraints": [
"n == strs. length1 <= n <= 1001 <= strs[i]. length <= 100strs[i] consists of lowercase English letters. "
]
},
{
"id": "964",
"title": "Least Operators to Express Number",
"question": "Given a single positive integer x, we will write an expression of the form x (op1) x (op2) x (op3) x .\n.\n.\n where each operator op1, op2, etc.\n is either addition, subtraction, multiplication, or division (+, -, *, or /).\n For example, with x = 3, we might write 3 * 3 / 3 + 3 - 3 which is a value of 3.\nWhen writing such an expression, we adhere to the following conventions:We would like to write an expression with the least number of operators such that the expression equals the given target.\n Return the least number of operators used.",
"examples": [
"Input: x = 3, target = 19",
"Output: 5",
"Explanation: 3 * 3 + 3 * 3 + 3 / 3.",
"The expression contains 5 operations.",
"Input: x = 5, target = 501",
"Output: 8",
"Explanation: 5 * 5 * 5 * 5 - 5 * 5 * 5 + 5 / 5.",
"The expression contains 8 operations.",
"Input: x = 100, target = 100000000",
"Output: 3",
"Explanation: 100 * 100 * 100 * 100.",
"The expression contains 3 operations.",
""
],
"constraints": [
"The division operator (/) returns rational numbers. There are no parentheses placed anywhere. We use the usual order of operations: multiplication and division happen before addition and subtraction. 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. 2 <= x <= 1001 <= target <= 2 * 108"
]
},
{
"id": "968",
"title": "Binary Tree Cameras",
"question": "You are given the root of a binary tree.\n We install cameras on the tree nodes where each camera at a node can monitor its parent, itself, and its immediate children.\nReturn the minimum number of cameras needed to monitor all nodes of the tree.",
"examples": [
"Input: root = [0,0,null,0,0]",
"Output: 1",
"Explanation: One camera is enough to monitor all nodes if placed as shown.",
"Input: root = [0,0,null,0,null,0,null,null,0]",
"Output: 2",
"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.",
""
],
"constraints": [
"The number of nodes in the tree is in the range [1",
" 1000]. Node. val == 0"
]
},
{
"id": "645",
"title": "Set Mismatch",
"question": "You have a set of integers s, which originally contains all the numbers from 1 to n.\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.\nYou are given an integer array nums representing the data status of this set after the error.\nFind the number that occurs twice and the number that is missing and return them in the form of an array.",
"examples": [
"Input: nums = [1,2,2,4]",
"Output: [2,3]",
"Input: nums = [1,1]",
"Output: [1,2]",
""
],
"constraints": [
"2 <= nums. length <= 1041 <= nums[i] <= 104"
]
},
{
"id": "972",
"title": "Equal Rational Numbers",
"question": "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.\n The strings may use parentheses to denote the repeating part of the rational number.\nA rational number can be represented using up to three parts: <IntegerPart>, <NonRepeatingPart>, and a <RepeatingPart>.\n The number will be represented in one of the following three ways:The repeating portion of a decimal expansion is conventionally denoted within a pair of round brackets.\n For example:",
"examples": [
"Input: s = \"0.(52)\", t = \"0. 5(25)\"",
"Output: true",
"Explanation: Because \"0.(52)\" represents 0. 52525252..., and \"0. 5(25)\" represents 0. 52525252525..... , the strings represent the same number.",
"Input: s = \"0. 1666(6)\", t = \"0. 166(66)\"",
"Output: true",
"Input: s = \"0. 9(9)\", t = \"1.\"",
"Output: true",
"Explanation: \"0. 9(9)\" represents 0. 999999999... repeated forever, which equals 1. [See this link for an explanation.]",
"\"1.\" represents the number 1, which is formed correctly: (IntegerPart) = \"1\" and (NonRepeatingPart) = \"\".",
""
],
"constraints": [
"<IntegerPart>\n\nFor example",
" 12",
" 0",
" and 123.\n\nFor example",
" 12",
" 0",
" and 123.<IntegerPart><.><NonRepeatingPart>\n\nFor example",
" 0. 5",
" 1.",
" 2. 12",
" and 123. 0001.\n\nFor example",
" 0. 5",
" 1.",
" 2. 12",
" and 123. 0001.<IntegerPart><.><NonRepeatingPart><(><RepeatingPart><)>\n\nFor example",
" 0. 1(6)",
" 1.(9)",
" 123. 00(1212).\n\nFor example",
" 0. 1(6)",
" 1.(9)",
" 123. 00(1212). 1/6 = 0. 16666666... = 0. 1(6) = 0. 1666(6) = 0. 166(66). Each part consists only of digits. The <IntegerPart> does not have leading zeros (except for the zero itself). 1 <= <IntegerPart>. length <= 40 <= <NonRepeatingPart>. length <= 41 <= <RepeatingPart>. length <= 4"
]
},
{
"id": "975",
"title": "Odd Even Jump",
"question": "You are given an integer array arr.\n From some starting index, you can make a series of jumps.\n The (1st, 3rd, 5th, .\n.\n.\n) jumps in the series are called odd-numbered jumps, and the (2nd, 4th, 6th, .\n.\n.\n) jumps in the series are called even-numbered jumps.\n Note that the jumps are numbered, not the indices.\nYou may jump forward from index i to index j (with i < j) in the following way:A starting index is good if, starting from that index, you can reach the end of the array (index arr.\nlength - 1) by jumping some number of times (possibly 0 or more than once).\nReturn the number of good starting indices.",
"examples": [
"Input: arr = [10,13,12,14,15]",
"Output: 2",
"Explanation: ",
"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.",
"From starting index i = 1 and i = 2, we can make our 1st jump to i = 3, then we cannot jump any more.",
"From starting index i = 3, we can make our 1st jump to i = 4, so we have reached the end.",
"From starting index i = 4, we have reached the end already.",
"In total, there are 2 different starting indices i = 3 and i = 4, where we can reach the end with some number of",
"jumps.",
"Input: arr = [2,3,1,1,4]",
"Output: 3",
"Explanation: ",
"From starting index i = 0, we make jumps to i = 1, i = 2, i = 3:",
"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].",
"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",
"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].",
"We can't jump from i = 3 to i = 4, so the starting index i = 0 is not good.",
"In a similar manner, we can deduce that:",
"From starting index i = 1, we jump to i = 4, so we reach the end.",
"From starting index i = 2, we jump to i = 3, and then we can't jump anymore.",
"From starting index i = 3, we jump to i = 4, so we reach the end.",
"From starting index i = 4, we are already at the end.",
"In total, there are 3 different starting indices i = 1, i = 3, and i = 4, where we can reach the end with some",
"number of jumps.",
"Input: arr = [5,1,3,4,2]",
"Output: 3",
"Explanation: We can reach the end from starting indices 1, 2, and 4.",
""
],
"constraints": [
"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. 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. It may be the case that for some index i",
" there are no legal jumps. 1 <= arr. length <= 2 * 1040 <= arr[i] < 105"
]
},
{
"id": "980",
"title": "Unique Paths III",
"question": "You are given an m x n integer array grid where grid[i][j] could be:Return the number of 4-directional walks from the starting square to the ending square, that walk over every non-obstacle square exactly once.",
"examples": [
"Input: grid = [[1,0,0,0],[0,0,0,0],[0,0,2,-1]]",
"Output: 2",
"Explanation: We have the following two paths: ",
"1. (0,0),(0,1),(0,2),(0,3),(1,3),(1,2),(1,1),(1,0),(2,0),(2,1),(2,2)",
"2. (0,0),(1,0),(2,0),(2,1),(1,1),(0,1),(0,2),(0,3),(1,3),(1,2),(2,2)",
"Input: grid = [[1,0,0,0],[0,0,0,0],[0,0,0,2]]",
"Output: 4",
"Explanation: We have the following four paths: ",
"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)",
"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)",
"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)",
"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)",
"Input: grid = [[0,1],[2,0]]",
"Output: 0",
"Explanation: There is no path that walks over every empty square exactly once.",
"Note that the starting and ending square can be anywhere in the grid.",
""
],
"constraints": [
"1 representing the starting square. There is exactly one starting square. 2 representing the ending square. There is exactly one ending square. 0 representing empty squares we can walk over.-1 representing obstacles that we cannot walk over. m == grid. lengthn == grid[i]. length1 <= m",
" n <= 201 <= m * n <= 20-1 <= grid[i][j] <= 2There is exactly one starting cell and one ending cell."
]
},
{
"id": "982",
"title": "Triples with Bitwise AND Equal To Zero",
"question": "Given an integer array nums, return the number of AND triples.\nAn AND triple is a triple of indices (i, j, k) such that:",
"examples": [
"Input: nums = [2,1,3]",
"Output: 12",
"Explanation: We could choose the following i, j, k triples:",
"(i=0, j=0, k=1) : 2 & 2 & 1",
"(i=0, j=1, k=0) : 2 & 1 & 2",
"(i=0, j=1, k=1) : 2 & 1 & 1",
"(i=0, j=1, k=2) : 2 & 1 & 3",
"(i=0, j=2, k=1) : 2 & 3 & 1",
"(i=1, j=0, k=0) : 1 & 2 & 2",
"(i=1, j=0, k=1) : 1 & 2 & 1",
"(i=1, j=0, k=2) : 1 & 2 & 3",
"(i=1, j=1, k=0) : 1 & 1 & 2",
"(i=1, j=2, k=0) : 1 & 3 & 2",
"(i=2, j=0, k=1) : 3 & 2 & 1",
"(i=2, j=1, k=0) : 3 & 1 & 2",
"Input: nums = [0,0,0]",
"Output: 27",
""
],
"constraints": [
"0 <= i < nums. length0 <= j < nums. length0 <= k < nums. lengthnums[i] & nums[j] & nums[k] == 0",
" where & represents the bitwise-AND operator. 1 <= nums. length <= 10000 <= nums[i] < 216"
]
},
{
"id": "987",
"title": "Vertical Order Traversal of a Binary Tree",
"question": "Given the root of a binary tree, calculate the vertical order traversal of the binary tree.\nFor 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.\n The root of the tree is at (0, 0).\nThe 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.\n There may be multiple nodes in the same row and same column.\n In such a case, sort these nodes by their values.\nReturn the vertical order traversal of the binary tree.",
"examples": [
"Input: root = [3,9,20,null,null,15,7]",
"Output: [[9],[3,15],[20],[7]]",
"Explanation:",
"Column -1: Only node 9 is in this column.",
"Column 0: Nodes 3 and 15 are in this column in that order from top to bottom.",
"Column 1: Only node 20 is in this column.",
"Column 2: Only node 7 is in this column. Input: root = [1,2,3,4,5,6,7]",
"Output: [[4],[2],[1,5,6],[3],[7]]",
"Explanation:",
"Column -2: Only node 4 is in this column.",
"Column -1: Only node 2 is in this column.",
"Column 0: Nodes 1, 5, and 6 are in this column.",
" 1 is at the top, so it comes first.",
" 5 and 6 are at the same position (2, 0), so we order them by their value, 5 before 6.",
"Column 1: Only node 3 is in this column.",
"Column 2: Only node 7 is in this column.",
"Input: root = [1,2,3,4,6,5,7]",
"Output: [[4],[2],[1,5,6],[3],[7]]",
"Explanation:",
"This case is the exact same as example 2, but with nodes 5 and 6 swapped.",
"Note that the solution remains the same since 5 and 6 are in the same location and should be ordered by their values.",
""
],
"constraints": [
"The number of nodes in the tree is in the range [1",
" 1000]. 0 <= Node. val <= 1000"
]
},
{
"id": "992",
"title": "Subarrays with K Different Integers",
"question": "Given an integer array nums and an integer k, return the number of good subarrays of nums.\nA good array is an array where the number of different integers in that array is exactly k.\nA subarray is a contiguous part of an array.",
"examples": [
"Input: nums = [1,2,1,2,3], k = 2",
"Output: 7",
"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]",
"Input: nums = [1,2,1,3,4], k = 3",
"Output: 3",
"Explanation: Subarrays formed with exactly 3 different integers: [1,2,1,3], [2,1,3], [1,3,4].",
""
],
"constraints": [
"For example",
" [1",
"2",
"3",
"1",
"2] has 3 different integers: 1",
" 2",
" and 3. 1 <= nums. length <= 2 * 1041 <= nums[i]",
" k <= nums. length"
]
},
{
"id": "995",
"title": "Minimum Number of K Consecutive Bit Flips",
"question": "You are given a binary array nums and an integer k.\nA 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.\nReturn the minimum number of k-bit flips required so that there is no 0 in the array.\n If it is not possible, return -1.\nA subarray is a contiguous part of an array.",
"examples": [
"Input: nums = [0,1,0], k = 1",
"Output: 2",
"Explanation: Flip nums[0], then flip nums[2].",
"Input: nums = [1,1,0], k = 2",
"Output: -1",
"Explanation: No matter how we flip subarrays of size 2, we cannot make the array become [1,1,1].",
"Input: nums = [0,0,0,1,0,1,1,0], k = 3",
"Output: 3",
"Explanation: ",
"Flip nums[0],nums[1],nums[2]: nums becomes [1,1,1,1,0,1,1,0]",
"Flip nums[4],nums[5],nums[6]: nums becomes [1,1,1,1,1,0,0,0]",
"Flip nums[5],nums[6],nums[7]: nums becomes [1,1,1,1,1,1,1,1]",
""
],
"constraints": [
"1 <= nums. length <= 3 * 1041 <= k <= nums. length"
]
},
{
"id": "996",
"title": "Number of Squareful Arrays",
"question": "An array is squareful if the sum of every pair of adjacent elements is a perfect square.\nGiven an integer array nums, return the number of permutations of nums that are squareful.\nTwo permutations perm1 and perm2 are different if there is some index i such that perm1[i] != perm2[i].",
"examples": [
"Input: nums = [1,17,8]",
"Output: 2",
"Explanation: [1,8,17] and [17,8,1] are the valid permutations.",
"Input: nums = [2,2,2]",
"Output: 1",
""
],
"constraints": [
"1 <= nums. length <= 120 <= nums[i] <= 109"
]
},
{
"id": "1000",
"title": "Minimum Cost to Merge Stones",
"question": "There are n piles of stones arranged in a row.\n The ith pile has stones[i] stones.\nA 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.\nReturn the minimum cost to merge all piles of stones into one pile.\n If it is impossible, return -1.",
"examples": [
"Input: stones = [3,2,4,1], k = 2",
"Output: 20",
"Explanation: We start with [3, 2, 4, 1].",
"We merge [3, 2] for a cost of 5, and we are left with [5, 4, 1].",
"We merge [4, 1] for a cost of 5, and we are left with [5, 5].",
"We merge [5, 5] for a cost of 10, and we are left with [10].",
"The total cost was 20, and this is the minimum possible.",
"Input: stones = [3,2,4,1], k = 3",
"Output: -1",
"Explanation: After any merge operation, there are 2 piles left, and we can't merge anymore. So the task is impossible.",
"Input: stones = [3,5,1,2,6], k = 3",
"Output: 25",
"Explanation: We start with [3, 5, 1, 2, 6].",
"We merge [5, 1, 2] for a cost of 8, and we are left with [3, 8, 6].",
"We merge [3, 8, 6] for a cost of 17, and we are left with [17].",
"The total cost was 25, and this is the minimum possible.",
""
],
"constraints": [
"n == stones. length1 <= n <= 301 <= stones[i] <= 1002 <= k <= 30"
]
},
{
"id": "1001",
"title": "Grid Illumination",
"question": "There is a 2D grid of size n x n where each cell of this grid has a lamp that is initially turned off.\nYou 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.\n Even if the same lamp is listed more than once, it is turned on.\nWhen a lamp is turned on, it illuminates its cell and all other cells in the same row, column, or diagonal.\nYou are also given another 2D array queries, where queries[j] = [rowj, colj].\n For the jth query, determine whether grid[rowj][colj] is illuminated or not.\n After answering the jth query, turn off the lamp at grid[rowj][colj] and its 8 adjacent lamps if they exist.\n A lamp is adjacent if its cell shares either a side or corner with grid[rowj][colj].\nReturn 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.",
"examples": [
"Input: n = 5, lamps = [[0,0],[4,4]], queries = [[1,1],[1,0]]",
"Output: [1,0]",
"Explanation: We have the initial grid with all lamps turned off. In the above picture we see the grid after turning on the lamp at grid[0][0] then turning on the lamp at grid[4][4].",
"The 0th query asks if the lamp at grid[1][1] is illuminated or not (the blue square). It is illuminated, so set ans[0] = 1. Then, we turn off all lamps in the red square.",
"",
"The 1st query asks if the lamp at grid[1][0] is illuminated or not (the blue square). It is not illuminated, so set ans[1] = 0. Then, we turn off all lamps in the red rectangle.",
"",
"Input: n = 5, lamps = [[0,0],[4,4]], queries = [[1,1],[1,1]]",
"Output: [1,1]",
"Input: n = 5, lamps = [[0,0],[0,4]], queries = [[0,4],[0,1],[1,4]]",
"Output: [1,1,0]",
""
],
"constraints": [
"1 <= n <= 1090 <= lamps. length <= 200000 <= queries. length <= 20000lamps[i]. length == 20 <= rowi",
" coli < nqueries[j]. length == 20 <= rowj",
" colj < n"
]
},
{
"id": "653",
"title": "Two Sum IV - Input is a BST",
"question": "Given the root of a Binary Search Tree and a target number k, return true if there exist two elements in the BST such that their sum is equal to the given target.",
"examples": [
"Input: root = [5,3,6,2,4,null,7], k = 9",
"Output: true",
"Input: root = [5,3,6,2,4,null,7], k = 28",
"Output: false",
"Input: root = [2,1,3], k = 4",
"Output: true",
"Input: root = [2,1,3], k = 1",
"Output: false",
"Input: root = [2,1,3], k = 3",
"Output: true",
""
],
"constraints": [
"The number of nodes in the tree is in the range [1",
" 104].-104 <= Node. val <= 104root is guaranteed to be a valid binary search tree.-105 <= k <= 105"
]
},
{
"id": "1012",
"title": "Numbers With Repeated Digits",
"question": "Given an integer n, return the number of positive integers in the range [1, n] that have at least one repeated digit.",
"examples": [
"Input: n = 20",
"Output: 1",
"Explanation: The only positive number (<= 20) with at least 1 repeated digit is 11.",
"Input: n = 100",
"Output: 10",
"Explanation: The positive numbers (<= 100) with atleast 1 repeated digit are 11, 22, 33, 44, 55, 66, 77, 88, 99, and 100.",
"Input: n = 1000",
"Output: 262",
""
],
"constraints": [
"1 <= n <= 109"
]
},
{
"id": "1028",
"title": "Recover a Tree From Preorder Traversal",
"question": "We run a preorder depth-first search (DFS) on the root of a binary tree.\nAt 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.\n  If the depth of a node is D, the depth of its immediate child is D + 1.\n  The depth of the root node is 0.\nIf a node has only one child, that child is guaranteed to be the left child.\nGiven the output traversal of this traversal, recover the tree and return its root.",
"examples": [
"Input: traversal = \"1-2--3--4-5--6--7\"",
"Output: [1,2,5,3,4,6,7]",
"Input: traversal = \"1-2--3---4-5--6---7\"",
"Output: [1,2,5,3,null,6,null,4,null,7]",
"Input: traversal = \"1-401--349---90--88\"",
"Output: [1,401,null,349,88,90]",
""
],
"constraints": [
"The number of nodes in the original tree is in the range [1",
" 1000]. 1 <= Node. val <= 109"
]
},
{
"id": "1032",
"title": "Stream of Characters",
"question": "Design an algorithm that accepts a stream of characters and checks if a suffix of these characters is a string of a given array of strings words.\nFor example, if words = [\"abc\", \"xyz\"] and the stream added the four characters (one by one) 'a', 'x', 'y', and 'z', your algorithm should detect that the suffix \"xyz\" of the characters \"axyz\" matches \"xyz\" from words.\nImplement the StreamChecker class:",
"examples": [
"Input",
"[\"StreamChecker\", \"query\", \"query\", \"query\", \"query\", \"query\", \"query\", \"query\", \"query\", \"query\", \"query\", \"query\", \"query\"]",
"[[[\"cd\", \"f\", \"kl\"]], [\"a\"], [\"b\"], [\"c\"], [\"d\"], [\"e\"], [\"f\"], [\"g\"], [\"h\"], [\"i\"], [\"j\"], [\"k\"], [\"l\"]]",
"Output",
"[null, false, false, false, true, false, true, false, false, false, false, false, true]",
"",
"Explanation",
"StreamChecker streamChecker = new StreamChecker([\"cd\", \"f\", \"kl\"]);",
"streamChecker. query(\"a\"); // return False",
"streamChecker. query(\"b\"); // return False",
"streamChecker. query(\"c\"); // return False",
"streamChecker. query(\"d\"); // return True, because 'cd' is in the wordlist",
"streamChecker. query(\"e\"); // return False",
"streamChecker. query(\"f\"); // return True, because 'f' is in the wordlist",
"streamChecker. query(\"g\"); // return False",
"streamChecker. query(\"h\"); // return False",
"streamChecker. query(\"i\"); // return False",
"streamChecker. query(\"j\"); // return False",
"streamChecker. query(\"k\"); // return False",
"streamChecker. query(\"l\"); // return True, because 'kl' is in the wordlist",
""
],
"constraints": [
"StreamChecker(String[] words) Initializes the object with the strings array words. boolean query(char letter) Accepts a new character from the stream and returns true if any non-empty suffix from the stream forms a word that is in words. 1 <= words. length <= 20001 <= words[i]. length <= 2000words[i] consists of lowercase English letters. letter is a lowercase English letter. At most 4 * 104 calls will be made to query."
]
},
{
"id": "1036",
"title": "Escape a Large Maze",
"question": "There is a 1 million by 1 million grid on an XY-plane, and the coordinates of each grid square are (x, y).\nWe start at the source = [sx, sy] square and want to reach the target = [tx, ty] square.\n There is also an array of blocked squares, where each blocked[i] = [xi, yi] represents a blocked square with coordinates (xi, yi).\nEach move, we can walk one square north, east, south, or west if the square is not in the array of blocked squares.\n We are also not allowed to walk outside of the grid.\nReturn true if and only if it is possible to reach the target square from the source square through a sequence of valid moves.",
"examples": [
"Input: blocked = [[0,1],[1,0]], source = [0,0], target = [0,2]",
"Output: false",
"Explanation: The target square is inaccessible starting from the source square because we cannot move.",
"We cannot move north or east because those squares are blocked.",
"We cannot move south or west because we cannot go outside of the grid.",
"Input: blocked = [], source = [0,0], target = [999999,999999]",
"Output: true",
"Explanation: Because there are no blocked cells, it is possible to reach the target square.",
""
],
"constraints": [
"0 <= blocked. length <= 200blocked[i]. length == 20 <= xi",
" yi < 106source. length == target. length == 20 <= sx",
" sy",
" tx",
" ty < 106source != targetIt is guaranteed that source and target are not blocked."
]
},
{
"id": "1044",
"title": "Longest Duplicate Substring",
"question": "Given a string s, consider all duplicated substrings: (contiguous) substrings of s that occur 2 or more times.\n The occurrences may overlap.\nReturn any duplicated substring that has the longest possible length.\n If s does not have a duplicated substring, the answer is \"\".",
"examples": [
"Input: s = \"banana\"",
"Output: \"ana\"",
"Input: s = \"abcd\"",
"Output: \"\"",
""
],
"constraints": [
"2 <= s. length <= 3 * 104s consists of lowercase English letters."
]
},
{
"id": "1074",
"title": "Number of Submatrices That Sum to Target",
"question": "Given a matrix and a target, return the number of non-empty submatrices that sum to target.\nA submatrix x1, y1, x2, y2 is the set of all cells matrix[x][y] with x1 <= x <= x2 and y1 <= y <= y2.\nTwo submatrices (x1, y1, x2, y2) and (x1', y1', x2', y2') are different if they have some coordinate that is different: for example, if x1 != x1'.",
"examples": [
"Input: matrix = [[0,1,0],[1,1,1],[0,1,0]], target = 0",
"Output: 4",
"Explanation: The four 1x1 submatrices that only contain 0.",
"Input: matrix = [[1,-1],[-1,1]], target = 0",
"Output: 5",
"Explanation: The two 1x2 submatrices, plus the two 2x1 submatrices, plus the 2x2 submatrix.",
"Input: matrix = [[904]], target = 0",
"Output: 0",
""
],
"constraints": [
"1 <= matrix. length <= 1001 <= matrix[0]. length <= 100-1000 <= matrix[i] <= 1000-10^8 <= target <= 10^8"
]
},
{
"id": "1092",
"title": "Shortest Common Supersequence",
"question": "Given two strings str1 and str2, return the shortest string that has both str1 and str2 as subsequences.\n If there are multiple valid strings, return any of them.\nA string s is a subsequence of string t if deleting some number of characters from t (possibly 0) results in the string s.",
"examples": [
"Input: str1 = \"abac\", str2 = \"cab\"",
"Output: \"cabac\"",
"Explanation: ",
"str1 = \"abac\" is a subsequence of \"cabac\" because we can delete the first \"c\".",
"str2 = \"cab\" is a subsequence of \"cabac\" because we can delete the last \"ac\".",
"The answer provided is the shortest such string that satisfies these properties.",
"Input: str1 = \"aaaaaaaa\", str2 = \"aaaaaaaa\"",
"Output: \"aaaaaaaa\"",
""
],
"constraints": [
"1 <= str1. length",
" str2. length <= 1000str1 and str2 consist of lowercase English letters."
]
},
{
"id": "1095",
"title": "Find in Mountain Array",
"question": "(This problem is an interactive problem.\n)You may recall that an array A is a mountain array if and only if:Given a mountain array mountainArr, return the minimum index such that mountainArr.\nget(index) == target.\n  If such an index doesn't exist, return -1.\nYou can't access the mountain array directly.\n  You may only access the array using a MountainArray interface:Submissions making more than 100 calls to MountainArray.\nget will be judged Wrong Answer.\n  Also, any solutions that attempt to circumvent the judge will result in disqualification.",
"examples": [
"Input: array = [1,2,3,4,5,3,1], target = 3",
"Output: 2",
"Explanation: 3 exists in the array, at index=2 and index=5. Return the minimum index, which is 2. Input: array = [0,1,2,4,2,1], target = 3",
"Output: -1",
"Explanation: 3 does not exist in the array, so we return -1.",
""
],
"constraints": [
"A. length >= 3There exists some i with 0 < i < A. length - 1 such that:\n\t\nA[0] < A[1] < ... A[i-1] < A[i]\nA[i] > A[i+1] > ... > A[A. length - 1]\n\nA[0] < A[1] < ... A[i-1] < A[i]A[i] > A[i+1] > ... > A[A. length - 1]MountainArray. get(k) returns the element of the array at index k (0-indexed). MountainArray. length() returns the length of the array. 3 <= mountain_arr. length() <= 100000 <= target <= 10^90 <= mountain_arr. get(index) <= 10^9"
]
},
{
"id": "1096",
"title": "Brace Expansion II",
"question": "Under the grammar given below, strings can represent a set of lowercase words.\n Let's use R(expr) to denote the set of words the expression represents.\nGrammar can best be understood through simple examples:Formally, the three rules for our grammar:Given an expression representing a set of words under the given grammar, return the sorted list of words that the expression represents.",
"examples": [
"Input: expression = \"{a,b}{c,{d,e}}\"",
"Output: [\"ac\",\"ad\",\"ae\",\"bc\",\"bd\",\"be\"]",
"Input: expression = \"{{a,z},a{b,c},{ab,z}}\"",
"Output: [\"a\",\"ab\",\"ac\",\"z\"]",
"Explanation: Each distinct word is written only once in the final answer.",
""
],
"constraints": [
"Single letters represent a singleton set containing that word.\n\t\nR(\"a\") = {\"a\"}\nR(\"w\") = {\"w\"}\n\nR(\"a\") = {\"a\"}R(\"w\") = {\"w\"}When we take a comma-delimited list of two or more expressions",
" we take the union of possibilities.\n\t\nR(\"{a",
"b",
"c}\") = {\"a\"",
"\"b\"",
"\"c\"}\nR(\"{{a",
"b}",
"{b",
"c}}\") = {\"a\"",
"\"b\"",
"\"c\"} (notice the final set only contains each word at most once)\n\nR(\"{a",
"b",
"c}\") = {\"a\"",
"\"b\"",
"\"c\"}R(\"{{a",
"b}",
"{b",
"c}}\") = {\"a\"",
"\"b\"",
"\"c\"} (notice the final set only contains each word at most once)When we concatenate two expressions",
" we take the set of possible concatenations between two words where the first word comes from the first expression and the second word comes from the second expression.\n\t\nR(\"{a",
"b}{c",
"d}\") = {\"ac\"",
"\"ad\"",
"\"bc\"",
"\"bd\"}\nR(\"a{b",
"c}{d",
"e}f{g",
"h}\") = {\"abdfg\"",
" \"abdfh\"",
" \"abefg\"",
" \"abefh\"",
" \"acdfg\"",
" \"acdfh\"",
" \"acefg\"",
" \"acefh\"}\n\nR(\"{a",
"b}{c",
"d}\") = {\"ac\"",
"\"ad\"",
"\"bc\"",
"\"bd\"}R(\"a{b",
"c}{d",
"e}f{g",
"h}\") = {\"abdfg\"",
" \"abdfh\"",
" \"abefg\"",
" \"abefh\"",
" \"acdfg\"",
" \"acdfh\"",
" \"acefg\"",
" \"acefh\"}For every lowercase letter x",
" we have R(x) = {x}. For expressions e1",
" e2",
" ... ",
" ek with k >= 2",
" we have R({e1",
" e2",
" ...}) = R(e1) ∪ R(e2) ∪ ... For expressions e1 and e2",
" we have R(e1 + e2) = {a + b for (a",
" b) in R(e1) × R(e2)}",
" where + denotes concatenation",
" and × denotes the cartesian product. 1 <= expression. length <= 60expression[i] consists of '{'",
" '}'",
" '",
"'or lowercase English letters. The given expression represents a set of words based on the grammar given in the description."
]
},
{
"id": "1106",
"title": "Parsing A Boolean Expression",
"question": "Return the result of evaluating a given boolean expression, represented as a string.\nAn expression can either be:",
"examples": [
"Input: expression = \"!(f)\"",
"Output: true",
"Input: expression = \"|(f,t)\"",
"Output: true",
"Input: expression = \"&(t,f)\"",
"Output: false",
"Input: expression = \"|(&(t,f,t),!(t))\"",
"Output: false",
""
],
"constraints": [
"\"t\"",
" evaluating to True;\"f\"",
" evaluating to False;\"!(expr)\"",
" evaluating to the logical NOT of the inner expression expr;\"&(expr1",
"expr2",
"...)\"",
" evaluating to the logical AND of 2 or more inner expressions expr1",
" expr2",
" ...;\"|(expr1",
"expr2",
"...)\"",
" evaluating to the logical OR of 2 or more inner expressions expr1",
" expr2",
" ... 1 <= expression. length <= 20000expression[i] consists of characters in {'('",
" ')'",
" '&'",
" '|'",
" '!'",
" 't'",
" 'f'",
" '",
"'}. expression is a valid expression representing a boolean",
" as given in the description."
]
},
{
"id": "657",
"title": "Robot Return to Origin",
"question": "There is a robot starting at the position (0, 0), the origin, on a 2D plane.\n Given a sequence of its moves, judge if this robot ends up at (0, 0) after it completes its moves.\nYou are given a string moves that represents the move sequence of the robot where moves[i] represents its ith move.\n Valid moves are 'R' (right), 'L' (left), 'U' (up), and 'D' (down).\nReturn true if the robot returns to the origin after it finishes all of its moves, or false otherwise.\nNote: The way that the robot is \"facing\" is irrelevant.\n 'R' will always make the robot move to the right once, 'L' will always make it move left, etc.\n Also, assume that the magnitude of the robot's movement is the same for each move.",
"examples": [
"Input: moves = \"UD\"",
"Output: true",
"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.",
"Input: moves = \"LL\"",
"Output: false",
"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.",
"Input: moves = \"RRDD\"",
"Output: false",
"Input: moves = \"LDRRLRUULR\"",
"Output: false",
""
],
"constraints": [
"1 <= moves. length <= 2 * 104moves only contains the characters 'U'",
" 'D'",
" 'L' and 'R'."
]
},
{
"id": "1125",
"title": "Smallest Sufficient Team",
"question": "In a project, you have a list of required skills req_skills, and a list of people.\n The ith person people[i] contains a list of skills that the person has.\nConsider 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.\n We can represent these teams by the index of each person.\nReturn any sufficient team of the smallest possible size, represented by the index of each person.\n You may return the answer in any order.\nIt is guaranteed an answer exists.",
"examples": [
"Input: req_skills = [\"java\",\"nodejs\",\"reactjs\"], people = [[\"java\"],[\"nodejs\"],[\"nodejs\",\"reactjs\"]]",
"Output: [0,2]",
"Input: req_skills = [\"algorithms\",\"math\",\"java\",\"reactjs\",\"csharp\",\"aws\"], people = [[\"algorithms\",\"math\",\"java\"],[\"algorithms\",\"math\",\"reactjs\"],[\"java\",\"csharp\",\"aws\"],[\"reactjs\",\"csharp\"],[\"csharp\",\"math\"],[\"aws\",\"java\"]]",
"Output: [1,2]",
""
],
"constraints": [
"For example",
" team = [0",
" 1",
" 3] represents the people with skills people[0]",
" people[1]",
" and people[3]. 1 <= req_skills. length <= 161 <= req_skills[i]. length <= 16req_skills[i] consists of lowercase English letters. All the strings of req_skills are unique. 1 <= people. length <= 600 <= people[i]. length <= 161 <= people[i][j]. length <= 16people[i][j] consists of lowercase English letters. All the strings of people[i] are unique. Every skill in people[i] is a skill in req_skills. It is guaranteed a sufficient team exists."
]
},
{
"id": "1147",
"title": "Longest Chunked Palindrome Decomposition",
"question": "You are given a string text.\n You should split it to k substrings (subtext1, subtext2, .\n.\n.\n, subtextk) such that:Return the largest possible value of k.",
"examples": [
"Input: text = \"ghiabcdefhelloadamhelloabcdefghi\"",
"Output: 7",
"Explanation: We can split the string on \"(ghi)(abcdef)(hello)(adam)(hello)(abcdef)(ghi)\".",
"Input: text = \"merchant\"",
"Output: 1",
"Explanation: We can split the string on \"(merchant)\".",
"Input: text = \"antaprezatepzapreanta\"",
"Output: 11",
"Explanation: We can split the string on \"(a)(nt)(a)(pre)(za)(tpe)(za)(pre)(a)(nt)(a)\".",
"Input: text = \"aaa\"",
"Output: 3",
"Explanation: We can split the string on \"(a)(a)(a)\".",
""
],
"constraints": [
"subtexti is a non-empty string. The concatenation of all the substrings is equal to text (i. e.",
" subtext1 + subtext2 + ... + subtextk == text). subtexti == subtextk - i + 1 for all valid values of i (i. e.",
" 1 <= i <= k). 1 <= text. length <= 1000text consists only of lowercase English characters."
]
},
{
"id": "1157",
"title": "Online Majority Element In Subarray",
"question": "Design a data structure that efficiently finds the majority element of a given subarray.\nThe majority element of a subarray is an element that occurs threshold times or more in the subarray.\nImplementing the MajorityChecker class:",
"examples": [
"Input",
"[\"MajorityChecker\", \"query\", \"query\", \"query\"]",
"[[[1, 1, 2, 2, 1, 1]], [0, 5, 4], [0, 3, 3], [2, 3, 2]]",
"Output",
"[null, 1, -1, 2]",
"",
"Explanation",
"MajorityChecker majorityChecker = new MajorityChecker([1, 1, 2, 2, 1, 1]);",
"majorityChecker. query(0, 5, 4); // return 1",
"majorityChecker. query(0, 3, 3); // return -1",
"majorityChecker. query(2, 3, 2); // return 2",
""
],
"constraints": [
"MajorityChecker(int[] arr) Initializes the instance of the class with the given array arr. int query(int left",
" int right",
" int threshold) returns the element in the subarray arr[left... right] that occurs at least threshold times",
" or -1 if no such element exists. 1 <= arr. length <= 2 * 1041 <= arr[i] <= 2 * 1040 <= left <= right < arr. lengththreshold <= right - left + 12 * threshold > right - left + 1At most 104 calls will be made to query."
]
},
{
"id": "1163",
"title": "Last Substring in Lexicographical Order",
"question": "Given a string s, return the last substring of s in lexicographical order.",
"examples": [
"Input: s = \"abab\"",
"Output: \"bab\"",
"Explanation: The substrings are [\"a\", \"ab\", \"aba\", \"abab\", \"b\", \"ba\", \"bab\"]. The lexicographically maximum substring is \"bab\".",
"Input: s = \"leetcode\"",
"Output: \"tcode\"",
""
],
"constraints": [
"1 <= s. length <= 4 * 105s contains only lowercase English letters."
]
},
{
"id": "1172",
"title": "Dinner Plate Stacks",
"question": "You have an infinite number of stacks arranged in a row and numbered (left to right) from 0, each of the stacks has the same maximum capacity.\nImplement the DinnerPlates class:",
"examples": [
"Input",
"[\"DinnerPlates\", \"push\", \"push\", \"push\", \"push\", \"push\", \"popAtStack\", \"push\", \"push\", \"popAtStack\", \"popAtStack\", \"pop\", \"pop\", \"pop\", \"pop\", \"pop\"]",
"[[2], [1], [2], [3], [4], [5], [0], [20], [21], [0], [2], [], [], [], [], []]",
"Output",
"[null, null, null, null, null, null, 2, null, null, 20, 21, 5, 4, 3, 1, -1]",
"",
"Explanation: ",
"DinnerPlates D = DinnerPlates(2); // Initialize with capacity = 2",
"D. push(1);",
"D. push(2);",
"D. push(3);",
"D. push(4);",
"D. push(5); // The stacks are now: 2 4",
" 1 3 5",
" ﹈ ﹈ ﹈",
"D. popAtStack(0); // Returns 2. The stacks are now: 4",
" 1 3 5",
" ﹈ ﹈ ﹈",
"D. push(20); // The stacks are now: 20 4",
" 1 3 5",
" ﹈ ﹈ ﹈",
"D. push(21); // The stacks are now: 20 4 21",
" 1 3 5",
" ﹈ ﹈ ﹈",
"D. popAtStack(0); // Returns 20. The stacks are now: 4 21",
" 1 3 5",
" ﹈ ﹈ ﹈",
"D. popAtStack(2); // Returns 21. The stacks are now: 4",
" 1 3 5",
" ﹈ ﹈ ﹈ ",
"D. pop() // Returns 5. The stacks are now: 4",
" 1 3 ",
" ﹈ ﹈ ",
"D. pop() // Returns 4. The stacks are now: 1 3 ",
" ﹈ ﹈ ",
"D. pop() // Returns 3. The stacks are now: 1 ",
" ﹈ ",
"D. pop() // Returns 1. There are no stacks.",
"D. pop() // Returns -1. There are still no stacks.",
""
],
"constraints": [
"DinnerPlates(int capacity) Initializes the object with the maximum capacity of the stacks capacity. void push(int val) Pushes the given integer val into the leftmost stack with a size less than capacity. int pop() Returns the value at the top of the rightmost non-empty stack and removes it from that stack",
" and returns -1 if all the stacks are empty. int popAtStack(int index) Returns the value at the top of the stack with the given index index and removes it from that stack or returns -1 if the stack with that given index is empty. 1 <= capacity <= 2 * 1041 <= val <= 2 * 1040 <= index <= 105At most 2 * 105 calls will be made to push",
" pop",
" and popAtStack."
]
},
{
"id": "1178",
"title": "Number of Valid Words for Each Puzzle",
"question": "",
"examples": [
"Input: words = [\"aaaa\",\"asas\",\"able\",\"ability\",\"actt\",\"actor\",\"access\"], puzzles = [\"aboveyz\",\"abrodyz\",\"abslute\",\"absoryz\",\"actresz\",\"gaswxyz\"]",
"Output: [1,1,3,2,4,0]",
"Explanation: ",
"1 valid word for \"aboveyz\" : \"aaaa\" ",
"1 valid word for \"abrodyz\" : \"aaaa\"",
"3 valid words for \"abslute\" : \"aaaa\", \"asas\", \"able\"",
"2 valid words for \"absoryz\" : \"aaaa\", \"asas\"",
"4 valid words for \"actresz\" : \"aaaa\", \"asas\", \"actt\", \"access\"",
"There are no valid words for \"gaswxyz\" cause none of the words in the list contains letter 'g'.",
"Input: words = [\"apple\",\"pleas\",\"please\"], puzzles = [\"aelwxyz\",\"aelpxyz\",\"aelpsxy\",\"saelpxy\",\"xaelpsy\"]",
"Output: [0,1,3,2,0]",
""
],
"constraints": [
"word contains the first letter of puzzle. For each letter in word",
" that letter is in puzzle.\n\t\nFor example",
" if the puzzle is \"abcdefg\"",
" then valid words are \"faced\"",
" \"cabbage\"",
" and \"baggage\"",
" while\ninvalid words are \"beefed\" (does not include 'a') and \"based\" (includes 's' which is not in the puzzle).\n\nFor example",
" if the puzzle is \"abcdefg\"",
" then valid words are \"faced\"",
" \"cabbage\"",
" and \"baggage\"",
" whileinvalid words are \"beefed\" (does not include 'a') and \"based\" (includes 's' which is not in the puzzle). 1 <= words. length <= 1054 <= words[i]. length <= 501 <= puzzles. length <= 104puzzles[i]. length == 7words[i] and puzzles[i] consist of lowercase English letters. Each puzzles[i] does not contain repeated characters."
]
},
{
"id": "1187",
"title": "Make Array Strictly Increasing",
"question": "Given two integer arrays arr1 and arr2, return the minimum number of operations (possibly zero) needed to make arr1 strictly increasing.\nIn one operation, you can choose two indices 0 <= i < arr1.\nlength and 0 <= j < arr2.\nlength and do the assignment arr1[i] = arr2[j].\nIf there is no way to make arr1 strictly increasing, return -1.",
"examples": [
"Input: arr1 = [1,5,3,6,7], arr2 = [1,3,2,4]",
"Output: 1",
"Explanation: Replace 5 with 2, then arr1 = [1, 2, 3, 6, 7].",
"Input: arr1 = [1,5,3,6,7], arr2 = [4,3,1]",
"Output: 2",
"Explanation: Replace 5 with 3 and then replace 3 with 4. arr1 = [1, 3, 4, 6, 7].",
"Input: arr1 = [1,5,3,6,7], arr2 = [1,6,3,3]",
"Output: -1",
"Explanation: You can't make arr1 strictly increasing."
],
"constraints": [
"1 <= arr1. length",
" arr2. length <= 20000 <= arr1[i]",
" arr2[i] <= 10^9"
]
},
{
"id": "1192",
"title": "Critical Connections in a Network",
"question": "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.\n Any server can reach other servers directly or indirectly through the network.\nA critical connection is a connection that, if removed, will make some servers unable to reach some other server.\nReturn all critical connections in the network in any order.",
"examples": [
"Input: n = 4, connections = [[0,1],[1,2],[2,0],[1,3]]",
"Output: [[1,3]]",
"Explanation: [[3,1]] is also accepted.",
"Input: n = 2, connections = [[0,1]]",
"Output: [[0,1]]",
""
],
"constraints": [
"2 <= n <= 105n - 1 <= connections. length <= 1050 <= ai",
" bi <= n - 1ai != biThere are no repeated connections."
]
},
{
"id": "1203",
"title": "Sort Items by Groups Respecting Dependencies",
"question": "There are n items each belonging to zero or one of m groups where group[i] is the group that the i-th item belongs to and it's equal to -1 if the i-th item belongs to no group.\n The items and the groups are zero indexed.\n A group can have no item belonging to it.\nReturn a sorted list of the items such that:Return any solution if there is more than one solution and return an empty list if there is no solution.",
"examples": [
"Input: n = 8, m = 2, group = [-1,-1,1,0,0,1,0,-1], beforeItems = [[],[6],[5],[6],[3,6],[],[],[]]",
"Output: [6,3,4,1,5,2,0,7]",
"Input: n = 8, m = 2, group = [-1,-1,1,0,0,1,0,-1], beforeItems = [[],[6],[5],[6],[3],[],[4],[]]",
"Output: []",
"Explanation: This is the same as example 1 except that 4 needs to be before 6 in the sorted list.",
""
],
"constraints": [
"The items that belong to the same group are next to each other in the sorted list. There are some relations between these items where beforeItems[i] is a list containing all the items that should come before the i-th item in the sorted array (to the left of the i-th item). 1 <= m <= n <= 3 * 104group. length == beforeItems. length == n-1 <= group[i] <= m - 10 <= beforeItems[i]. length <= n - 10 <= beforeItems[i][j] <= n - 1i != beforeItems[i][j]beforeItems[i] does not contain duplicates elements."
]
},
{
"id": "1206",
"title": "Design Skiplist",
"question": "Design a Skiplist without using any built-in libraries.\nA skiplist is a data structure that takes O(log(n)) time to add, erase and search.\n Comparing with treap and red-black tree which has the same function and performance, the code length of Skiplist can be comparatively short and the idea behind Skiplists is just simple linked lists.\nFor example, we have a Skiplist containing [30,40,50,60,70,90] and we want to add 80 and 45 into it.\n The Skiplist works this way:\nArtyom Kalinin [CC BY-SA 3.\n0], via Wikimedia CommonsYou can see there are many layers in the Skiplist.\n Each layer is a sorted linked list.\n With the help of the top layers, add, erase and search can be faster than O(n).\n It can be proven that the average time complexity for each operation is O(log(n)) and space complexity is O(n).\nSee more about Skiplist: https://en.\nwikipedia.\norg/wiki/Skip_listImplement the Skiplist class:Note that duplicates may exist in the Skiplist, your code needs to handle this situation.",
"examples": [
"Input",
"[\"Skiplist\", \"add\", \"add\", \"add\", \"search\", \"add\", \"search\", \"erase\", \"erase\", \"search\"]",
"[[], [1], [2], [3], [0], [4], [1], [0], [1], [1]]",
"Output",
"[null, null, null, null, false, null, true, false, true, false]",
"",
"Explanation",
"Skiplist skiplist = new Skiplist();",
"skiplist. add(1);",
"skiplist. add(2);",
"skiplist. add(3);",
"skiplist. search(0); // return False",
"skiplist. add(4);",
"skiplist. search(1); // return True",
"skiplist. erase(0); // return False, 0 is not in skiplist.",
"skiplist. erase(1); // return True",
"skiplist. search(1); // return False, 1 has already been erased."
],
"constraints": [
"Skiplist() Initializes the object of the skiplist. bool search(int target) Returns true if the integer target exists in the Skiplist or false otherwise. void add(int num) Inserts the value num into the SkipList. bool erase(int num) Removes the value num from the Skiplist and returns true. If num does not exist in the Skiplist",
" do nothing and return false. If there exist multiple num values",
" removing any one of them is fine. 0 <= num",
" target <= 2 * 104At most 5 * 104 calls will be made to search",
" add",
" and erase."
]
},
{
"id": "661",
"title": "Image Smoother",
"question": "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.\ne.\n, the average of the nine cells in the blue smoother).\n If one or more of the surrounding cells of a cell is not present, we do not consider it in the average (i.\ne.\n, the average of the four cells in the red smoother).\nGiven 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.",
"examples": [
"Input: img = [[1,1,1],[1,0,1],[1,1,1]]",
"Output: [[0,0,0],[0,0,0],[0,0,0]]",
"Explanation:",
"For the points (0,0), (0,2), (2,0), (2,2): floor(3/4) = floor(0. 75) = 0",
"For the points (0,1), (1,0), (1,2), (2,1): floor(5/6) = floor(0. 83333333) = 0",
"For the point (1,1): floor(8/9) = floor(0. 88888889) = 0",
"Input: img = [[100,200,100],[200,50,200],[100,200,100]]",
"Output: [[137,141,137],[141,138,141],[137,141,137]]",
"Explanation:",
"For the points (0,0), (0,2), (2,0), (2,2): floor((100+200+200+50)/4) = floor(137. 5) = 137",
"For the points (0,1), (1,0), (1,2), (2,1): floor((200+200+50+200+100+100)/6) = floor(141. 666667) = 141",
"For the point (1,1): floor((50+200+200+200+200+100+100+100+100)/9) = floor(138. 888889) = 138",
""
],
"constraints": [
"m == img. lengthn == img[i]. length1 <= m",
" n <= 2000 <= img[i][j] <= 255"
]
},
{
"id": "1210",
"title": "Minimum Moves to Reach Target with Rotations",
"question": "In an n*n grid, there is a snake that spans 2 cells and starts moving from the top left corner at (0, 0) and (0, 1).\n The grid has empty cells represented by zeros and blocked cells represented by ones.\n The snake wants to reach the lower right corner at (n-1, n-2) and (n-1, n-1).\nIn one move the snake can:Return the minimum number of moves to reach the target.\nIf there is no way to reach the target, return -1.",
"examples": [
"Input: grid = [[0,0,0,0,0,1],",
" [1,1,0,0,1,0],",
"  [0,0,0,0,1,1],",
"  [0,0,1,0,1,0],",
"  [0,1,1,0,0,0],",
"  [0,1,1,0,0,0]]",
"Output: 11",
"Explanation:",
"One possible solution is [right, right, rotate clockwise, right, down, down, down, down, rotate counterclockwise, right, down].",
"Input: grid = [[0,0,1,1,1,1],",
"  [0,0,0,0,1,1],",
"  [1,1,0,0,0,1],",
"  [1,1,1,0,0,1],",
"  [1,1,1,0,0,1],",
"  [1,1,1,0,0,0]]",
"Output: 9",
""
],
"constraints": [
"Move one cell to the right if there are no blocked cells there. This move keeps the horizontal/vertical position of the snake as it is. Move down one cell if there are no blocked cells there. This move keeps the horizontal/vertical position of the snake as it is. Rotate clockwise if it's in a horizontal position and the two cells under it are both empty. In that case the snake moves from (r",
" c) and (r",
" c+1) to (r",
" c) and (r+1",
" c).\nRotate counterclockwise if it's in a vertical position and the two cells to its right are both empty. In that case the snake moves from (r",
" c) and (r+1",
" c) to (r",
" c) and (r",
" c+1).\n2 <= n <= 1000 <= grid[i][j] <= 1It is guaranteed that the snake starts at empty cells."
]
},
{
"id": "1220",
"title": "Count Vowels Permutation",
"question": "Given an integer n, your task is to count how many strings of length n can be formed under the following rules:Since the answer may be too large, return it modulo 10^9 + 7.",
"examples": [
"Input: n = 1",
"Output: 5",
"Explanation: All possible strings are: \"a\", \"e\", \"i\" , \"o\" and \"u\".",
"Input: n = 2",
"Output: 10",
"Explanation: All possible strings are: \"ae\", \"ea\", \"ei\", \"ia\", \"ie\", \"io\", \"iu\", \"oi\", \"ou\" and \"ua\".",
"Input: n = 5",
"Output: 68"
],
"constraints": [
"Each character is a lower case vowel ('a'",
" 'e'",
" 'i'",
" 'o'",
" 'u')Each vowel 'a' may only be followed by an 'e'. Each vowel 'e' may only be followed by an 'a' or an 'i'. Each vowel 'i' may not be followed by another 'i'. Each vowel 'o' may only be followed by an 'i' or a 'u'. Each vowel 'u' may only be followed by an 'a'. 1 <= n <= 2 * 10^4"
]
},
{
"id": "1223",
"title": "Dice Roll Simulation",
"question": "A die simulator generates a random number from 1 to 6 for each roll.\n 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.\nTwo sequences are considered different if at least one element differs from each other.\n Since the answer may be too large, return it modulo 10^9 + 7.",
"examples": [
"Input: n = 2, rollMax = [1,1,2,2,2,3]",
"Output: 34",
"Explanation: There will be 2 rolls of die, if there are no constraints on the die, there are 6 * 6 = 36 possible combinations. In this case, looking at rollMax array, the numbers 1 and 2 appear at most once consecutively, therefore sequences (1,1) and (2,2) cannot occur, so the final answer is 36-2 = 34.",
"Input: n = 2, rollMax = [1,1,1,1,1,1]",
"Output: 30",
"Input: n = 3, rollMax = [1,1,1,2,2,3]",
"Output: 181",
""
],
"constraints": [
"1 <= n <= 5000rollMax. length == 61 <= rollMax[i] <= 15"
]
},
{
"id": "1224",
"title": "Maximum Equal Frequency",
"question": "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.\nIf after removing one element there are no remaining elements, it's still considered that every appeared number has the same number of ocurrences (0).",
"examples": [
"Input: nums = [2,2,1,1,5,3,3,5]",
"Output: 7",
"Explanation: For the subarray [2,2,1,1,5,3,3] of length 7, if we remove nums[4]=5, we will get [2,2,1,1,3,3], so that each number will appear exactly twice.",
"Input: nums = [1,1,1,2,2,2,3,3,3,4,4,4,5]",
"Output: 13",
"Input: nums = [1,1,1,2,2,2]",
"Output: 5",
"Input: nums = [10,2,8,9,3,8,1,5,2,3,7,6]",
"Output: 8",
""
],
"constraints": [
"2 <= nums. length <= 10^51 <= nums[i] <= 10^5"
]
},
{
"id": "1235",
"title": "Maximum Profit in Job Scheduling",
"question": "We have n jobs, where every job is scheduled to be done from startTime[i] to endTime[i], obtaining a profit of profit[i].\nYou'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.\nIf you choose a job that ends at time X you will be able to start another job that starts at time X.",
"examples": [
"Input: startTime = [1,2,3,3], endTime = [3,4,5,6], profit = [50,10,40,70]",
"Output: 120",
"Explanation: The subset chosen is the first and fourth job. ",
"Time range [1-3]+[3-6] , we get profit of 120 = 50 + 70.",
"Input: startTime = [1,2,3,4,6], endTime = [3,5,10,6,9], profit = [20,20,100,70,60]",
"Output: 150",
"Explanation: The subset chosen is the first, fourth and fifth job. ",
"Profit obtained 150 = 20 + 70 + 60.",
"Input: startTime = [1,1,1], endTime = [2,3,4], profit = [5,6,4]",
"Output: 6",
""
],
"constraints": [
"1 <= startTime. length == endTime. length == profit. length <= 5 * 1041 <= startTime[i] < endTime[i] <= 1091 <= profit[i] <= 104"
]
},
{
"id": "1240",
"title": "Tiling a Rectangle with the Fewest Squares",
"question": "Given a rectangle of size n x m, return the minimum number of integer-sided squares that tile the rectangle.",
"examples": [
"Input: n = 2, m = 3",
"Output: 3",
"Explanation: 3 squares are necessary to cover the rectangle.",
"2 (squares of 1x1)",
"1 (square of 2x2)Input: n = 5, m = 8",
"Output: 5",
"Input: n = 11, m = 13",
"Output: 6",
""
],
"constraints": [
"1 <= n",
" m <= 13"
]
},
{
"id": "1250",
"title": "Check If It Is a Good Array",
"question": "Given an array nums of positive integers.\n Your task is to select some subset of nums, multiply each element by an integer and add all these numbers.\n The array is said to be good if you can obtain a sum of 1 from the array by any possible subset and multiplicand.\nReturn True if the array is good otherwise return False.",
"examples": [
"Input: nums = [12,5,7,23]",
"Output: true",
"Explanation: Pick numbers 5 and 7.",
"5*3 + 7*(-2) = 1",
"Input: nums = [29,6,10]",
"Output: true",
"Explanation: Pick numbers 29, 6 and 10.",
"29*1 + 6*(-3) + 10*(-1) = 1",
"Input: nums = [3,6]",
"Output: false",
""
],
"constraints": [
"1 <= nums. length <= 10^51 <= nums[i] <= 10^9"
]
},
{
"id": "1255",
"title": "Maximum Score Words Formed by Letters",
"question": "Given a list of words, list of  single letters (might be repeating) and score of every character.\nReturn the maximum score of any valid set of words formed by using the given letters (words[i] cannot be used two or more times).\nIt is not necessary to use all characters in letters and each letter can only be used once.\n Score of letters 'a', 'b', 'c', .\n.\n.\n ,'z' is given by score[0], score[1], .\n.\n.\n , score[25] respectively.",
"examples": [
"Input: 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]",
"Output: 23",
"Explanation:",
"Score a=1, c=9, d=5, g=3, o=2",
"Given letters, we can form the words \"dad\" (5+1+5) and \"good\" (3+2+2+5) with a score of 23.",
"Words \"dad\" and \"dog\" only get a score of 21. Input: 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]",
"Output: 27",
"Explanation:",
"Score a=4, b=4, c=4, x=5, z=10",
"Given letters, we can form the words \"ax\" (4+5), \"bx\" (4+5) and \"cx\" (4+5) with a score of 27.",
"Word \"xxxz\" only get a score of 25. Input: 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]",
"Output: 0",
"Explanation:",
"Letter \"e\" can only be used once."
],
"constraints": [
"1 <= words. length <= 141 <= words[i]. length <= 151 <= letters. length <= 100letters[i]. length == 1score. length == 260 <= score[i] <= 10words[i]",
" letters[i] contains only lower case English letters."
]
},
{
"id": "1263",
"title": "Minimum Moves to Move a Box to Their Target Location",
"question": "A storekeeper is a game in which the player pushes boxes around in a warehouse trying to get them to target locations.\nThe game is represented by an m x n grid of characters grid where each element is a wall, floor, or box.\nYour task is to move the box 'B' to the target position 'T' under the following rules:Return the minimum number of pushes to move the box to the target.\n If there is no way to reach the target, return -1.",
"examples": [
"Input: grid = [[\"#\",\"#\",\"#\",\"#\",\"#\",\"#\"],",
" [\"#\",\"T\",\"#\",\"#\",\"#\",\"#\"],",
"  [\"#\",\".\",\".\",\"B\",\".\",\"#\"],",
"  [\"#\",\".\",\"#\",\"#\",\".\",\"#\"],",
"  [\"#\",\".\",\".\",\".\",\"S\",\"#\"],",
"  [\"#\",\"#\",\"#\",\"#\",\"#\",\"#\"]]",
"Output: 3",
"Explanation: We return only the number of times the box is pushed. Input: grid = [[\"#\",\"#\",\"#\",\"#\",\"#\",\"#\"],",
" [\"#\",\"T\",\"#\",\"#\",\"#\",\"#\"],",
"  [\"#\",\".\",\".\",\"B\",\".\",\"#\"],",
"  [\"#\",\"#\",\"#\",\"#\",\".\",\"#\"],",
"  [\"#\",\".\",\".\",\".\",\"S\",\"#\"],",
"  [\"#\",\"#\",\"#\",\"#\",\"#\",\"#\"]]",
"Output: -1",
"Input: grid = [[\"#\",\"#\",\"#\",\"#\",\"#\",\"#\"],",
"  [\"#\",\"T\",\".\",\".\",\"#\",\"#\"],",
"  [\"#\",\".\",\"#\",\"B\",\".\",\"#\"],",
"  [\"#\",\".\",\".\",\".\",\".\",\"#\"],",
"  [\"#\",\".\",\".\",\".\",\"S\",\"#\"],",
"  [\"#\",\"#\",\"#\",\"#\",\"#\",\"#\"]]",
"Output: 5",
"Explanation: push the box down, left, left, up and up.",
"Input: grid = [[\"#\",\"#\",\"#\",\"#\",\"#\",\"#\",\"#\"],",
"  [\"#\",\"S\",\"#\",\".\",\"B\",\"T\",\"#\"],",
"  [\"#\",\"#\",\"#\",\"#\",\"#\",\"#\",\"#\"]]",
"Output: -1",
""
],
"constraints": [
"The character 'S' represents the player. The player can move up",
" down",
" left",
" right in grid if it is a floor (empty cell). The character '.' represents the floor which means a free cell to walk. The character '#' represents the wall which means an obstacle (impossible to walk there). There is only one box 'B' and one target cell 'T' in the grid. The box can be moved to an adjacent free cell by standing next to the box and then moving in the direction of the box. This is a push. The player cannot walk through the box. m == grid. lengthn == grid[i]. length1 <= m",
" n <= 20grid contains only characters '.'",
" '#'",
" 'S'",
" 'T'",
" or 'B'. There is only one character 'S'",
" 'B'",
" and 'T' in the grid."
]
},
{
"id": "1269",
"title": "Number of Ways to Stay in the Same Place After Some Steps",
"question": "You have a pointer at index 0 in an array of size arrLen.\n 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).\nGiven two integers steps and arrLen, return the number of ways such that your pointer still at index 0 after exactly steps steps.\n Since the answer may be too large, return it modulo 109 + 7.",
"examples": [
"Input: steps = 3, arrLen = 2",
"Output: 4",
"Explanation: There are 4 differents ways to stay at index 0 after 3 steps.",
"Right, Left, Stay",
"Stay, Right, Left",
"Right, Stay, Left",
"Stay, Stay, Stay",
"Input: steps = 2, arrLen = 4",
"Output: 2",
"Explanation: There are 2 differents ways to stay at index 0 after 2 steps",
"Right, Left",
"Stay, Stay",
"Input: steps = 4, arrLen = 2",
"Output: 8",
""
],
"constraints": [
"1 <= steps <= 5001 <= arrLen <= 106"
]
},
{
"id": "671",
"title": "Second Minimum Node In a Binary Tree",
"question": "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.\n If the node has two sub-nodes, then this node's value is the smaller value among its two sub-nodes.\n More formally, the property root.\nval = min(root.\nleft.\nval, root.\nright.\nval) always holds.\nGiven 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.\nIf no such second minimum value exists, output -1 instead.",
"examples": [
"Input: root = [2,2,5,null,null,5,7]",
"Output: 5",
"Explanation: The smallest value is 2, the second smallest value is 5.",
"Input: root = [2,2,2]",
"Output: -1",
"Explanation: The smallest value is 2, but there isn't any second smallest value.",
""
],
"constraints": [
"The number of nodes in the tree is in the range [1",
" 25]. 1 <= Node. val <= 231 - 1root. val == min(root. left. val",
" root. right. val) for each internal node of the tree."
]
},
{
"id": "1278",
"title": "Palindrome Partitioning III",
"question": "You are given a string s containing lowercase letters and an integer k.\n You need to :Return the minimal number of characters that you need to change to divide the string.",
"examples": [
"Input: s = \"abc\", k = 2",
"Output: 1",
"Explanation: You can split the string into \"ab\" and \"c\", and change 1 character in \"ab\" to make it palindrome.",
"Input: s = \"aabbc\", k = 3",
"Output: 0",
"Explanation: You can split the string into \"aa\", \"bb\" and \"c\", all of them are palindrome. Input: s = \"leetcode\", k = 8",
"Output: 0",
""
],
"constraints": [
"First",
" change some characters of s to other lowercase English letters. Then divide s into k non-empty disjoint substrings such that each substring is a palindrome. 1 <= k <= s. length <= 100. s only contains lowercase English letters."
]
},
{
"id": "1284",
"title": "Minimum Number of Flips to Convert Binary Matrix to Zero Matrix",
"question": "Given a m x n binary matrix mat.\n 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).\n A pair of cells are called neighbors if they share one edge.\nReturn the minimum number of steps required to convert mat to a zero matrix or -1 if you cannot.\nA binary matrix is a matrix with all cells equal to 0 or 1 only.\nA zero matrix is a matrix with all cells equal to 0.",
"examples": [
"Input: mat = [[0,0],[0,1]]",
"Output: 3",
"Explanation: One possible solution is to flip (1, 0) then (0, 1) and finally (1, 1) as shown.",
"Input: mat = [[0]]",
"Output: 0",
"Explanation: Given matrix is a zero matrix. We don't need to change it.",
"Input: mat = [[1,1,1],[1,0,1],[0,0,0]]",
"Output: 6",
"Input: mat = [[1,0,0],[1,0,0]]",
"Output: -1",
"Explanation: Given matrix can't be a zero matrix",
""
],
"constraints": [
"m == mat. lengthn == mat[i]. length1 <= m",
" n <= 3mat[i][j] is either 0 or 1."
]
},
{
"id": "1289",
"title": "Minimum Falling Path Sum II",
"question": "Given an n x n integer matrix grid, return the minimum sum of a falling path with non-zero shifts.\nA 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.",
"examples": [
"Input: arr = [[1,2,3],[4,5,6],[7,8,9]]",
"Output: 13",
"Explanation: ",
"The possible falling paths are:",
"[1,5,9], [1,5,7], [1,6,7], [1,6,8],",
"[2,4,8], [2,4,9], [2,6,7], [2,6,8],",
"[3,4,8], [3,4,9], [3,5,7], [3,5,9]",
"The falling path with the smallest sum is [1,5,7], so the answer is 13.",
"Input: grid = [[7]]",
"Output: 7",
""
],
"constraints": [
"n == grid. length == grid[i]. length1 <= n <= 200-99 <= grid[i][j] <= 99"
]
},
{
"id": "1293",
"title": "Shortest Path in a Grid with Obstacles Elimination",
"question": "You are given an m x n integer matrix grid where each cell is either 0 (empty) or 1 (obstacle).\n You can move up, down, left, or right from and to an empty cell in one step.\nReturn 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.\n If it is not possible to find such walk return -1.",
"examples": [
"Input: ",
"grid = ",
"[[0,0,0],",
" [1,1,0],",
" [0,0,0],",
" [0,1,1],",
" [0,0,0]], ",
"k = 1",
"Output: 6",
"Explanation: ",
"The shortest path without eliminating any obstacle is 10. ",
"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).",
"Input: ",
"grid = ",
"[[0,1,1],",
" [1,1,1],",
" [1,0,0]], ",
"k = 1",
"Output: -1",
"Explanation: ",
"We need to eliminate at least two obstacles to find such a walk.",
""
],
"constraints": [
"m == grid. lengthn == grid[i]. length1 <= m",
" n <= 401 <= k <= m * ngrid[i][j] == 0 or 1grid[0][0] == grid[m - 1][n - 1] == 0"
]
},
{
"id": "1298",
"title": "Maximum Candies You Can Get from Boxes",
"question": "Given n boxes, each box is given in the format [status, candies, keys, containedBoxes] where:You will start with some boxes given in initialBoxes array.\n 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.\nReturn the maximum number of candies you can get following the rules above.",
"examples": [
"Input: status = [1,0,1,0], candies = [7,5,4,100], keys = [[],[],[1],[]], containedBoxes = [[1,2],[3],[],[]], initialBoxes = [0]",
"Output: 16",
"Explanation: You will be initially given box 0. You will find 7 candies in it and boxes 1 and 2. Box 1 is closed and you don't 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.",
"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.",
"Total number of candies collected = 7 + 4 + 5 = 16 candy.",
"Input: 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]",
"Output: 6",
"Explanation: You have initially box 0. Opening it you can find boxes 1,2,3,4 and 5 and their keys. The total number of candies will be 6.",
"Input: status = [1,1,1], candies = [100,1,100], keys = [[],[0,2],[]], containedBoxes = [[],[],[]], initialBoxes = [1]",
"Output: 1",
"Input: status = [1], candies = [100], keys = [[]], containedBoxes = [[]], initialBoxes = []",
"Output: 0",
"Input: status = [1,1,1], candies = [2,3,2], keys = [[],[],[]], containedBoxes = [[],[],[]], initialBoxes = [2,1,0]",
"Output: 7",
""
],
"constraints": [
"status[i]: an integer which is 1 if box[i] is open and 0 if box[i] is closed. candies[i]: an integer representing the number of candies in box[i]. keys[i]: an array contains the indices of the boxes you can open with the key in box[i]. containedBoxes[i]: an array contains the indices of the boxes found in box[i]. 1 <= status. length <= 1000status. length == candies. length == keys. length == containedBoxes. length == nstatus[i] is 0 or 1. 1 <= candies[i] <= 10000 <= keys[i]. length <= status. length0 <= keys[i][j] < status. lengthAll values in keys[i] are unique. 0 <= containedBoxes[i]. length <= status. length0 <= containedBoxes[i][j] < status. lengthAll values in containedBoxes[i] are unique. Each box is contained in one box at most. 0 <= initialBoxes. length <= status. length0 <= initialBoxes[i] < status. length"
]
},
{
"id": "1301",
"title": "Number of Paths with Max Score",
"question": "You are given a square board of characters.\n You can move on the board starting at the bottom right square marked with the character 'S'.\nYou need to reach the top left square marked with the character 'E'.\n The rest of the squares are labeled either with a numeric character 1, 2, .\n.\n.\n, 9 or with an obstacle 'X'.\n In one move you can go up, left or up-left (diagonally) only if there is no obstacle there.\nReturn 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.\nIn case there is no path, return [0, 0].",
"examples": [
"Input: board = [\"E23\",\"2X2\",\"12S\"]",
"Output: [7,1]",
"Input: board = [\"E12\",\"1X1\",\"21S\"]",
"Output: [4,2]",
"Input: board = [\"E11\",\"XXX\",\"11S\"]",
"Output: [0,0]",
""
],
"constraints": [
"2 <= board. length == board[i]. length <= 100"
]
},
{
"id": "1307",
"title": "Verbal Arithmetic Puzzle",
"question": "Given an equation, represented by words on left side and the result on right side.\nYou need to check if the equation is solvable under the following rules:Return True if the equation is solvable otherwise return False.",
"examples": [
"Input: words = [\"SEND\",\"MORE\"], result = \"MONEY\"",
"Output: true",
"Explanation: Map 'S'-> 9, 'E'->5, 'N'->6, 'D'->7, 'M'->1, 'O'->0, 'R'->8, 'Y'->'2'",
"Such that: \"SEND\" + \"MORE\" = \"MONEY\" , 9567 + 1085 = 10652Input: words = [\"SIX\",\"SEVEN\",\"SEVEN\"], result = \"TWENTY\"",
"Output: true",
"Explanation: Map 'S'-> 6, 'I'->5, 'X'->0, 'E'->8, 'V'->7, 'N'->2, 'T'->1, 'W'->'3', 'Y'->4",
"Such that: \"SIX\" + \"SEVEN\" + \"SEVEN\" = \"TWENTY\" , 650 + 68782 + 68782 = 138214Input: words = [\"THIS\",\"IS\",\"TOO\"], result = \"FUNNY\"",
"Output: true",
"Input: words = [\"LEET\",\"CODE\"], result = \"POINT\"",
"Output: false",
""
],
"constraints": [
"Each character is decoded as one digit (0 - 9). Every pair of different characters they must map to different digits. Each words[i] and result are decoded as one number without leading zeros. Sum of numbers on left side (words) will equal to the number on right side (result). 2 <= words. length <= 51 <= words[i]. length",
" result. length <= 7words[i]",
" result contain only uppercase English letters. The number of different characters used in the expression is at most 10."
]
},
{
"id": "1312",
"title": "Minimum Insertion Steps to Make a String Palindrome",
"question": "Given a string s.\n In one step you can insert any character at any index of the string.\nReturn the minimum number of steps to make s palindrome.\nA Palindrome String is one that reads the same backward as well as forward.",
"examples": [
"Input: s = \"zzazz\"",
"Output: 0",
"Explanation: The string \"zzazz\" is already palindrome we don't need any insertions.",
"Input: s = \"mbadm\"",
"Output: 2",
"Explanation: String can be \"mbdadbm\" or \"mdbabdm\".",
"Input: s = \"leetcode\"",
"Output: 5",
"Explanation: Inserting 5 characters the string becomes \"leetcodocteel\".",
"Input: s = \"g\"",
"Output: 0",
"Input: s = \"no\"",
"Output: 1",
""
],
"constraints": [
"1 <= s. length <= 500All characters of s are lower case English letters."
]
},
{
"id": "1316",
"title": "Distinct Echo Substrings",
"question": "Return the number of distinct non-empty substrings of text that can be written as the concatenation of some string with itself (i.\ne.\n it can be written as a + a where a is some string).",
"examples": [
"Input: text = \"abcabcabc\"",
"Output: 3",
"Explanation: The 3 substrings are \"abcabc\", \"bcabca\" and \"cabcab\".",
"Input: text = \"leetcodeleetcode\"",
"Output: 2",
"Explanation: The 2 substrings are \"ee\" and \"leetcodeleetcode\".",
""
],
"constraints": [
"1 <= text. length <= 2000text has only lowercase English letters."
]
},
{
"id": "1320",
"title": "Minimum Distance to Type a Word Using Two Fingers",
"question": "You have a keyboard layout as shown above in the X-Y plane, where each English uppercase letter is located at some coordinate.\nGiven the string word, return the minimum total distance to type such string using only two fingers.\nThe distance between coordinates (x1, y1) and (x2, y2) is |x1 - x2| + |y1 - y2|.\nNote 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.",
"examples": [
"Input: word = \"CAKE\"",
"Output: 3",
"Explanation: ",
"Using two fingers, one optimal way to type \"CAKE\" is: ",
"Finger 1 on letter 'C' -> cost = 0 ",
"Finger 1 on letter 'A' -> cost = Distance from letter 'C' to letter 'A' = 2 ",
"Finger 2 on letter 'K' -> cost = 0 ",
"Finger 2 on letter 'E' -> cost = Distance from letter 'K' to letter 'E' = 1 ",
"Total distance = 3",
"Input: word = \"HAPPY\"",
"Output: 6",
"Explanation: ",
"Using two fingers, one optimal way to type \"HAPPY\" is:",
"Finger 1 on letter 'H' -> cost = 0",
"Finger 1 on letter 'A' -> cost = Distance from letter 'H' to letter 'A' = 2",
"Finger 2 on letter 'P' -> cost = 0",
"Finger 2 on letter 'P' -> cost = Distance from letter 'P' to letter 'P' = 0",
"Finger 1 on letter 'Y' -> cost = Distance from letter 'A' to letter 'Y' = 4",
"Total distance = 6",
"Input: word = \"NEW\"",
"Output: 3",
"Input: word = \"YEAR\"",
"Output: 7",
""
],
"constraints": [
"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). 2 <= word. length <= 300word consists of uppercase English letters."
]
},
{
"id": "674",
"title": "Longest Continuous Increasing Subsequence",
"question": "Given an unsorted array of integers nums, return the length of the longest continuous increasing subsequence (i.\ne.\n subarray).\n The subsequence must be strictly increasing.\nA continuous increasing subsequence is defined by two indices l and r (l < r) such that it is [nums[l], nums[l + 1], .\n.\n.\n, nums[r - 1], nums[r]] and for each l <= i < r, nums[i] < nums[i + 1].",
"examples": [
"Input: nums = [1,3,5,4,7]",
"Output: 3",
"Explanation: The longest continuous increasing subsequence is [1,3,5] with length 3.",
"Even though [1,3,5,7] is an increasing subsequence, it is not continuous as elements 5 and 7 are separated by element",
"4.",
"Input: nums = [2,2,2,2,2]",
"Output: 1",
"Explanation: The longest continuous increasing subsequence is [2] with length 1. Note that it must be strictly",
"increasing.",
""
],
"constraints": [
"1 <= nums. length <= 104-109 <= nums[i] <= 109"
]
},
{
"id": "1326",
"title": "Minimum Number of Taps to Open to Water a Garden",
"question": "There is a one-dimensional garden on the x-axis.\n The garden starts at the point 0 and ends at the point n.\n (i.\ne The length of the garden is n).\nThere are n + 1 taps located at points [0, 1, .\n.\n.\n, n] in the garden.\nGiven 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.\nReturn the minimum number of taps that should be open to water the whole garden, If the garden cannot be watered return -1.",
"examples": [
"Input: n = 5, ranges = [3,4,1,1,0,0]",
"Output: 1",
"Explanation: The tap at point 0 can cover the interval [-3,3]",
"The tap at point 1 can cover the interval [-3,5]",
"The tap at point 2 can cover the interval [1,3]",
"The tap at point 3 can cover the interval [2,4]",
"The tap at point 4 can cover the interval [4,4]",
"The tap at point 5 can cover the interval [5,5]",
"Opening Only the second tap will water the whole garden [0,5]",
"Input: n = 3, ranges = [0,0,0,0]",
"Output: -1",
"Explanation: Even if you activate all the four taps you cannot water the whole garden.",
"Input: n = 7, ranges = [1,2,1,0,2,1,0,1]",
"Output: 3",
"Input: n = 8, ranges = [4,0,0,0,0,0,0,0,4]",
"Output: 2",
"Input: n = 8, ranges = [4,0,0,0,4,0,0,0,4]",
"Output: 1",
""
],
"constraints": [
"1 <= n <= 10^4ranges. length == n + 10 <= ranges[i] <= 100"
]
},
{
"id": "1330",
"title": "Reverse Subarray To Maximize Array Value",
"question": "You are given an integer array nums.\n The value of this array is defined as the sum of |nums[i]-nums[i+1]| for all 0 <= i < nums.\nlength-1.\nYou are allowed to select any subarray of the given array and reverse it.\n You can perform this operation only once.\nFind maximum possible value of the final array.",
"examples": [
"Input: nums = [2,3,1,5,4]",
"Output: 10",
"Explanation: By reversing the subarray [3,1,5] the array becomes [2,5,1,3,4] whose value is 10.",
"Input: nums = [2,4,9,24,2,1,10]",
"Output: 68",
""
],
"constraints": [
"1 <= nums. length <= 3*10^4-10^5 <= nums[i] <= 10^5"
]
},
{
"id": "1335",
"title": "Minimum Difficulty of a Job Schedule",
"question": "You want to schedule a list of jobs in d days.\n Jobs are dependent (i.\ne To work on the i-th job, you have to finish all the jobs j where 0 <= j < i).\nYou have to finish at least one task every day.\n The difficulty of a job schedule is the sum of difficulties of each day of the d days.\n The difficulty of a day is the maximum difficulty of a job done in that day.\nGiven an array of integers jobDifficulty and an integer d.\n The difficulty of the i-th job is jobDifficulty[i].\nReturn the minimum difficulty of a job schedule.\n If you cannot find a schedule for the jobs return -1.",
"examples": [
"Input: jobDifficulty = [6,5,4,3,2,1], d = 2",
"Output: 7",
"Explanation: First day you can finish the first 5 jobs, total difficulty = 6.",
"Second day you can finish the last job, total difficulty = 1.",
"The difficulty of the schedule = 6 + 1 = 7 ",
"Input: jobDifficulty = [9,9,9], d = 4",
"Output: -1",
"Explanation: If you finish a job per day you will still have a free day. you cannot find a schedule for the given jobs.",
"Input: jobDifficulty = [1,1,1], d = 3",
"Output: 3",
"Explanation: The schedule is one job per day. total difficulty will be 3.",
"Input: jobDifficulty = [7,1,7,1,7,1], d = 3",
"Output: 15",
"Input: jobDifficulty = [11,111,22,222,33,333,44,444], d = 6",
"Output: 843",
""
],
"constraints": [
"1 <= jobDifficulty. length <= 3000 <= jobDifficulty[i] <= 10001 <= d <= 10"
]
},
{
"id": "1340",
"title": "Jump Game V",
"question": "Given an array of integers arr and an integer d.\n In one step you can jump from index i to index:In addition, you can only jump from index i to index j if arr[i] > arr[j] and arr[i] > arr[k] for all indices k between i and j (More formally min(i, j) < k < max(i, j)).\nYou can choose any index of the array and start jumping.\n Return the maximum number of indices you can visit.\nNotice that you can not jump outside of the array at any time.",
"examples": [
"Input: arr = [6,4,14,6,8,13,9,7,10,6,12], d = 2",
"Output: 4",
"Explanation: You can start at index 10. You can jump 10 --> 8 --> 6 --> 7 as shown.",
"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.",
"Similarly You cannot jump from index 3 to index 2 or index 1.",
"Input: arr = [3,3,3,3,3], d = 3",
"Output: 1",
"Explanation: You can start at any index. You always cannot jump to any index.",
"Input: arr = [7,6,5,4,3,2,1], d = 1",
"Output: 7",
"Explanation: Start at index 0. You can visit all the indicies. ",
"Input: arr = [7,1,7,1,7,1], d = 2",
"Output: 2",
"Input: arr = [66], d = 1",
"Output: 1",
""
],
"constraints": [
"i + x where: i + x < arr. length and 0 < x <= d. i - x where: i - x >= 0 and 0 < x <= d. 1 <= arr. length <= 10001 <= arr[i] <= 10^51 <= d <= arr. length"
]
},
{
"id": "1345",
"title": "Jump Game IV",
"question": "Given an array of integers arr, you are initially positioned at the first index of the array.\nIn one step you can jump from index i to index:Return the minimum number of steps to reach the last index of the array.\nNotice that you can not jump outside of the array at any time.",
"examples": [
"Input: arr = [100,-23,-23,404,100,23,23,23,3,404]",
"Output: 3",
"Explanation: You need three jumps from index 0 --> 4 --> 3 --> 9. Note that index 9 is the last index of the array.",
"Input: arr = [7]",
"Output: 0",
"Explanation: Start index is the last index. You don't need to jump.",
"Input: arr = [7,6,9,6,9,6,9,7]",
"Output: 1",
"Explanation: You can jump directly from index 0 to index 7 which is last index of the array.",
"Input: arr = [6,1,9]",
"Output: 2",
"Input: arr = [11,22,7,7,7,7,7,7,7,22,13]",
"Output: 3",
""
],
"constraints": [
"i + 1 where: i + 1 < arr. length. i - 1 where: i - 1 >= 0. j where: arr[i] == arr[j] and i != j. 1 <= arr. length <= 5 * 104-108 <= arr[i] <= 108"
]
},
{
"id": "1349",
"title": "Maximum Students Taking Exam",
"question": "Given a m * n matrix seats  that represent seats distributions in a classroom.\n If a seat is broken, it is denoted by '#' character otherwise it is denoted by a '.\n' character.\nStudents 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 directly in front or behind him.\n Return the maximum number of students that can take the exam together without any cheating being possible.\n.\nStudents must be placed in seats in good condition.",
"examples": [
"Input: seats = [[\"#\",\".\",\"#\",\"#\",\".\",\"#\"],",
"  [\".\",\"#\",\"#\",\"#\",\"#\",\".\"],",
"  [\"#\",\".\",\"#\",\"#\",\".\",\"#\"]]",
"Output: 4",
"Explanation: Teacher can place 4 students in available seats so they don't cheat on the exam. ",
"Input: seats = [[\".\",\"#\"],",
"  [\"#\",\"#\"],",
"  [\"#\",\".\"],",
"  [\"#\",\"#\"],",
"  [\".\",\"#\"]]",
"Output: 3",
"Explanation: Place all students in available seats. ",
"",
"Input: seats = [[\"#\",\".\",\".\",\".\",\"#\"],",
"  [\".\",\"#\",\".\",\"#\",\".\"],",
"  [\".\",\".\",\"#\",\".\",\".\"],",
"  [\".\",\"#\",\".\",\"#\",\".\"],",
"  [\"#\",\".\",\".\",\".\",\"#\"]]",
"Output: 10",
"Explanation: Place students in available seats in column 1, 3 and 5.",
""
],
"constraints": [
"seats contains only characters '.' and'#'. m == seats. lengthn == seats[i]. length1 <= m <= 81 <= n <= 8"
]
},
{
"id": "1354",
"title": "Construct Target Array With Multiple Sums",
"question": "You are given an array target of n integers.\n From a starting array arr consisting of n 1's, you may perform the following procedure :Return true if it is possible to construct the target array from arr, otherwise, return false.",
"examples": [
"Input: target = [9,3,5]",
"Output: true",
"Explanation: Start with arr = [1, 1, 1] ",
"[1, 1, 1], sum = 3 choose index 1",
"[1, 3, 1], sum = 5 choose index 2",
"[1, 3, 5], sum = 9 choose index 0",
"[9, 3, 5] Done",
"Input: target = [1,1,1,2]",
"Output: false",
"Explanation: Impossible to create target array from [1,1,1,1].",
"Input: target = [8,5]",
"Output: true",
""
],
"constraints": [
"let x be the sum of all elements currently in your array. choose index i",
" such that 0 <= i < n and set the value of arr at index i to x. You may repeat this procedure as many times as needed. n == target. length1 <= n <= 5 * 1041 <= target[i] <= 109"
]
},
{
"id": "1359",
"title": "Count All Valid Pickup and Delivery Options",
"question": "Given n orders, each order consist in pickup and delivery services.\n Count all valid pickup/delivery possible sequences such that delivery(i) is always after of pickup(i).\n Since the answer may be too large, return it modulo 10^9 + 7.",
"examples": [
"Input: n = 1",
"Output: 1",
"Explanation: Unique order (P1, D1), Delivery 1 always is after of Pickup 1.",
"Input: n = 2",
"Output: 6",
"Explanation: All possible orders: ",
"(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).",
"This is an invalid order (P1,D2,P2,D1) because Pickup 2 is after of Delivery 2.",
"Input: n = 3",
"Output: 90",
""
],
"constraints": [
"1 <= n <= 500"
]
},
{
"id": "1363",
"title": "Largest Multiple of Three",
"question": "Given an integer array of digits, return the largest multiple of three that can be formed by concatenating some of the given digits in any order.\nSince the answer may not fit in an integer data type, return the answer as a string.\nIf there is no answer return an empty string.",
"examples": [
"Input: digits = [8,1,9]",
"Output: \"981\"",
"Input: digits = [8,6,7,1,0]",
"Output: \"8760\"",
"Input: digits = [1]",
"Output: \"\"",
"Input: digits = [0,0,0,0,0,0]",
"Output: \"0\"",
""
],
"constraints": [
"1 <= digits. length <= 10^40 <= digits[i] <= 9The returning answer must not contain unnecessary leading zeros."
]
},
{
"id": "1368",
"title": "Minimum Cost to Make at Least One Valid Path in a Grid",
"question": "Notice that there could be some invalid signs on the cells of the grid which points outside the grid.\nYou will initially start at the upper left cell (0,0).\n A valid path in the grid is a path which 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.\n The valid path doesn't have to be the shortest.\nYou can modify the sign on a cell with cost = 1.\n You can modify the sign on a cell one time only.\nReturn the minimum cost to make the grid have at least one valid path.",
"examples": [
"Input: grid = [[1,1,1,1],[2,2,2,2],[1,1,1,1],[2,2,2,2]]",
"Output: 3",
"Explanation: You will start at point (0, 0).",
"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)",
"The total cost = 3.",
"Input: grid = [[1,1,3],[3,2,2],[1,1,4]]",
"Output: 0",
"Explanation: You can follow the path from (0, 0) to (2, 2).",
"Input: grid = [[1,2],[4,3]]",
"Output: 1",
"Input: grid = [[2,2,2],[2,2,2]]",
"Output: 3",
"Input: grid = [[4]]",
"Output: 0",
""
],
"constraints": [
"1 which means go to the cell to the right. (i. e go from grid[i][j] to grid[i][j + 1])2 which means go to the cell to the left. (i. e go from grid[i][j] to grid[i][j - 1])3 which means go to the lower cell. (i. e go from grid[i][j] to grid[i + 1][j])4 which means go to the upper cell. (i. e go from grid[i][j] to grid[i - 1][j])m == grid. lengthn == grid[i]. length1 <= m",
" n <= 100"
]
},
{
"id": "67",
"title": "Add Binary",
"question": "Given two binary strings a and b, return their sum as a binary string.",
"examples": [
"Input: a = \"11\", b = \"1\"",
"Output: \"100\"",
"Input: a = \"1010\", b = \"1011\"",
"Output: \"10101\"",
""
],
"constraints": [
"1 <= a. length",
" b. length <= 104a and b consist only of '0' or '1' characters. Each string does not contain leading zeros except for the zero itself."
]
},
{
"id": "680",
"title": "Valid Palindrome II",
"question": "Given a string s, return true if the s can be palindrome after deleting at most one character from it.",
"examples": [
"Input: s = \"aba\"",
"Output: true",
"Input: s = \"abca\"",
"Output: true",
"Explanation: You could delete the character 'c'.",
"Input: s = \"abc\"",
"Output: false",
""
],
"constraints": [
"1 <= s. length <= 105s consists of lowercase English letters."
]
},
{
"id": "1373",
"title": "Maximum Sum BST in Binary Tree",
"question": "Given a binary tree root, return the maximum sum of all keys of any sub-tree which is also a Binary Search Tree (BST).\nAssume a BST is defined as follows:",
"examples": [
"Input: root = [1,4,3,2,4,2,5,null,null,null,null,null,null,4,6]",
"Output: 20",
"Explanation: Maximum sum in a valid Binary search tree is obtained in root node with key equal to 3.",
"Input: root = [4,3,null,1,2]",
"Output: 2",
"Explanation: Maximum sum in a valid Binary search tree is obtained in a single root node with key equal to 2.",
"Input: root = [-4,-2,-5]",
"Output: 0",
"Explanation: All values are negatives. Return an empty BST.",
"Input: root = [2,1,3]",
"Output: 6",
"Input: root = [5,4,8,3,null,6,3]",
"Output: 7",
""
],
"constraints": [
"The left subtree of a node contains only nodes with keys less than the node's key. The right subtree of a node contains only nodes with keys greater than the node's key. Both the left and right subtrees must also be binary search trees. The number of nodes in the tree is in the range [1",
" 4 * 104].-4 * 104 <= Node. val <= 4 * 104"
]
},
{
"id": "1377",
"title": "Frog Position After T Seconds",
"question": "Given an undirected tree consisting of n vertices numbered from 1 to n.\n A frog starts jumping from vertex 1.\n In one second, the frog jumps from its current vertex to another unvisited vertex if they are directly connected.\n The frog can not jump back to a visited vertex.\n In case the frog can jump to several vertices, it jumps randomly to one of them with the same probability.\n Otherwise, when the frog can not jump to any unvisited vertex, it jumps forever on the same vertex.\nThe 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.\nReturn the probability that after t seconds the frog is on the vertex target.",
"examples": [
"Input: n = 7, edges = [[1,2],[1,3],[1,7],[2,4],[2,6],[3,5]], t = 2, target = 4",
"Output: 0. 16666666666666666 ",
"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. ",
"Input: n = 7, edges = [[1,2],[1,3],[1,7],[2,4],[2,6],[3,5]], t = 1, target = 7",
"Output: 0. 3333333333333333",
"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. ",
"Input: n = 7, edges = [[1,2],[1,3],[1,7],[2,4],[2,6],[3,5]], t = 20, target = 6",
"Output: 0. 16666666666666666",
""
],
"constraints": [
"1 <= n <= 100edges. length == n - 1edges[i]. length == 21 <= ai",
" bi <= n1 <= t <= 501 <= target <= nAnswers within 10-5 of the actual value will be accepted as correct."
]
},
{
"id": "1383",
"title": "Maximum Performance of a Team",
"question": "You are given two integers n and k and two integer arrays speed and efficiency both of length n.\n There are n engineers numbered from 1 to n.\n speed[i] and efficiency[i] represent the speed and efficiency of the ith engineer respectively.\nChoose at most k different engineers out of the n engineers to form a team with the maximum performance.\nThe performance of a team is the sum of their engineers' speeds multiplied by the minimum efficiency among their engineers.\nReturn the maximum performance of this team.\n Since the answer can be a huge number, return it modulo 109 + 7.",
"examples": [
"Input: n = 6, speed = [2,10,3,1,5,8], efficiency = [5,4,3,9,7,2], k = 2",
"Output: 60",
"Explanation: ",
"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.",
"Input: n = 6, speed = [2,10,3,1,5,8], efficiency = [5,4,3,9,7,2], k = 3",
"Output: 68",
"Explanation:",
"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.",
"Input: n = 6, speed = [2,10,3,1,5,8], efficiency = [5,4,3,9,7,2], k = 4",
"Output: 72",
""
],
"constraints": [
"1 <= k <= n <= 105speed. length == nefficiency. length == n1 <= speed[i] <= 1051 <= efficiency[i] <= 108"
]
},
{
"id": "1388",
"title": "Pizza With 3n Slices",
"question": "There is a pizza with 3n slices of varying size, you and your friends will take slices of pizza as follows:Sizes of Pizza slices is represented by circular array slices in clockwise direction.\nReturn the maximum possible sum of slice sizes which you can have.",
"examples": [
"Input: slices = [1,2,3,4,5,6]",
"Output: 10",
"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.",
"Input: slices = [8,9,8,6,1,1]",
"Output: 16",
"Output: Pick pizza slice of size 8 in each turn. If you pick slice with size 9 your partners will pick slices of size 8.",
"Input: slices = [4,1,2,5,8,3,1,9,7]",
"Output: 21",
"Input: slices = [3,1,2]",
"Output: 3",
""
],
"constraints": [
"You will pick any pizza slice. Your friend Alice will pick next slice in anti clockwise direction of your pick. Your friend Bob will pick next slice in clockwise direction of your pick. Repeat until there are no more slices of pizzas. 1 <= slices. length <= 500slices. length % 3 == 01 <= slices[i] <= 1000"
]
},
{
"id": "1392",
"title": "Longest Happy Prefix",
"question": "A string is called a happy prefix if is a non-empty prefix which is also a suffix (excluding itself).\nGiven a string s, return the longest happy prefix of s.\n Return an empty string \"\" if no such prefix exists.",
"examples": [
"Input: s = \"level\"",
"Output: \"l\"",
"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\".",
"Input: s = \"ababab\"",
"Output: \"abab\"",
"Explanation: \"abab\" is the largest prefix which is also suffix. They can overlap in the original string.",
"Input: s = \"leetcodeleet\"",
"Output: \"leet\"",
"Input: s = \"a\"",
"Output: \"\"",
""
],
"constraints": [
"1 <= s. length <= 105s contains only lowercase English letters."
]
},
{
"id": "1397",
"title": "Find All Good Strings",
"question": "Given the strings s1 and s2 of size n and the string evil, return the number of good strings.\nA 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.\n Since the answer can be a huge number, return this modulo 109 + 7.",
"examples": [
"Input: n = 2, s1 = \"aa\", s2 = \"da\", evil = \"b\"",
"Output: 51 ",
"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\". ",
"Input: n = 8, s1 = \"leetcode\", s2 = \"leetgoes\", evil = \"leet\"",
"Output: 0 ",
"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.",
"Input: n = 2, s1 = \"gx\", s2 = \"gz\", evil = \"x\"",
"Output: 2",
""
],
"constraints": [
"s1. length == ns2. length == ns1 <= s21 <= n <= 5001 <= evil. length <= 50All strings consist of lowercase English letters."
]
},
{
"id": "1402",
"title": "Reducing Dishes",
"question": "A chef has collected data on the satisfaction level of his n dishes.\n Chef can cook any dish in 1 unit of time.\nLike-time coefficient of a dish is defined as the time taken to cook that dish including previous dishes multiplied by its satisfaction level  i.\ne.\n  time[i]*satisfaction[i]Return the maximum sum of Like-time coefficient that the chef can obtain after dishes preparation.\nDishes can be prepared in any order and the chef can discard some dishes to get this maximum value.",
"examples": [
"Input: satisfaction = [-1,-8,0,5,-9]",
"Output: 14",
"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). Each dish is prepared in one unit of time. Input: satisfaction = [4,3,2]",
"Output: 20",
"Explanation: Dishes can be prepared in any order, (2*1 + 3*2 + 4*3 = 20)",
"Input: satisfaction = [-1,-4,-5]",
"Output: 0",
"Explanation: People don't like the dishes. No dish is prepared.",
"Input: satisfaction = [-2,5,-1,0,3,-3]",
"Output: 35",
""
],
"constraints": [
"n == satisfaction. length1 <= n <= 500-10^3 <= satisfaction[i] <= 10^3"
]
},
{
"id": "1406",
"title": "Stone Game III",
"question": "Alice and Bob continue their games with piles of stones.\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.\nAlice and Bob take turns, with Alice starting first.\n On each player's turn, that player can take 1, 2 or 3 stones from the first remaining stones in the row.\nThe score of each player is the sum of values of the stones taken.\n The score of each player is 0 initially.\nThe 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.\n The game continues until all the stones have been taken.\nAssume Alice and Bob play optimally.\nReturn \"Alice\" if Alice will win, \"Bob\" if Bob will win or \"Tie\" if they end the game with the same score.",
"examples": [
"Input: values = [1,2,3,7]",
"Output: \"Bob\"",
"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.",
"Input: values = [1,2,3,-9]",
"Output: \"Alice\"",
"Explanation: Alice must choose all the three piles at the first move to win and leave Bob with negative score.",
"If Alice chooses one pile her score will be 1 and the next move Bob's score becomes 5. The next move Alice will take the pile with value = -9 and lose.",
"If Alice chooses two piles her score will be 3 and the next move Bob's score becomes 3. The next move Alice will take the pile with value = -9 and also lose.",
"Remember that both play optimally so here Alice will choose the scenario that makes her win.",
"Input: values = [1,2,3,6]",
"Output: \"Tie\"",
"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.",
"Input: values = [1,2,3,-1,-2,-3,7]",
"Output: \"Alice\"",
"Input: values = [-1,-2,-3]",
"Output: \"Tie\"",
""
],
"constraints": [
"1 <= values. length <= 50000-1000 <= values[i] <= 1000"
]
},
{
"id": "1411",
"title": "Number of Ways to Paint N × 3 Grid",
"question": "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.\ne.\n, no two cells that share vertical or horizontal sides have the same color).\nGiven n the number of rows of the grid, return the number of ways you can paint this grid.\n As the answer may grow large, the answer must be computed modulo 109 + 7.",
"examples": [
"Input: n = 1",
"Output: 12",
"Explanation: There are 12 possible way to paint the grid as shown.",
"Input: n = 2",
"Output: 54",
"Input: n = 3",
"Output: 246",
"Input: n = 7",
"Output: 106494",
"Input: n = 5000",
"Output: 30228214",
""
],
"constraints": [
"n == grid. lengthgrid[i]. length == 31 <= n <= 5000"
]
},
{
"id": "1416",
"title": "Restore The Array",
"question": "A program was supposed to print an array of integers.\n 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.\nGiven the string s and the integer k, return the number of the possible arrays that can be printed as s using the mentioned program.\n Since the answer may be very large, return it modulo 109 + 7.",
"examples": [
"Input: s = \"1000\", k = 10000",
"Output: 1",
"Explanation: The only possible array is [1000]",
"Input: s = \"1000\", k = 10",
"Output: 0",
"Explanation: There cannot be an array that was printed this way and has all integer >= 1 and <= 10.",
"Input: s = \"1317\", k = 2000",
"Output: 8",
"Explanation: Possible arrays are [1317],[131,7],[13,17],[1,317],[13,1,7],[1,31,7],[1,3,17],[1,3,1,7]",
"Input: s = \"2020\", k = 30",
"Output: 1",
"Explanation: The only possible array is [20,20]. [2020] is invalid because 2020 > 30. [2,020] is ivalid because 020 contains leading zeros.",
"Input: s = \"1234567890\", k = 90",
"Output: 34",
""
],
"constraints": [
"1 <= s. length <= 105s consists of only digits and does not contain leading zeros. 1 <= k <= 109"
]
},
{
"id": "682",
"title": "Baseball Game",
"question": "You are keeping score for a baseball game with strange rules.\n The game consists of several rounds, where the scores of past rounds may affect future rounds' scores.\nAt the beginning of the game, you start with an empty record.\n You are given a list of strings ops, where ops[i] is the ith operation you must apply to the record and is one of the following:Return the sum of all the scores on the record.",
"examples": [
"Input: ops = [\"5\",\"2\",\"C\",\"D\",\"+\"]",
"Output: 30",
"Explanation:",
"\"5\" - Add 5 to the record, record is now [5].",
"\"2\" - Add 2 to the record, record is now [5, 2].",
"\"C\" - Invalidate and remove the previous score, record is now [5].",
"\"D\" - Add 2 * 5 = 10 to the record, record is now [5, 10].",
"\"+\" - Add 5 + 10 = 15 to the record, record is now [5, 10, 15].",
"The total sum is 5 + 10 + 15 = 30.",
"Input: ops = [\"5\",\"-2\",\"4\",\"C\",\"D\",\"9\",\"+\",\"+\"]",
"Output: 27",
"Explanation:",
"\"5\" - Add 5 to the record, record is now [5].",
"\"-2\" - Add -2 to the record, record is now [5, -2].",
"\"4\" - Add 4 to the record, record is now [5, -2, 4].",
"\"C\" - Invalidate and remove the previous score, record is now [5, -2].",
"\"D\" - Add 2 * -2 = -4 to the record, record is now [5, -2, -4].",
"\"9\" - Add 9 to the record, record is now [5, -2, -4, 9].",
"\"+\" - Add -4 + 9 = 5 to the record, record is now [5, -2, -4, 9, 5].",
"\"+\" - Add 9 + 5 = 14 to the record, record is now [5, -2, -4, 9, 5, 14].",
"The total sum is 5 + -2 + -4 + 9 + 5 + 14 = 27.",
"Input: ops = [\"1\"]",
"Output: 1",
""
],
"constraints": [
"1 <= ops. length <= 1000ops[i] is \"C\"",
" \"D\"",
" \"+\"",
" or a string representing an integer in the range [-3 * 104",
" 3 * 104]. For operation \"+\"",
" there will always be at least two previous scores on the record. For operations \"C\" and \"D\"",
" there will always be at least one previous score on the record."
]
},
{
"id": "1420",
"title": "Build Array Where You Can Find The Maximum Exactly K Comparisons",
"question": "Given three integers n, m and k.\n Consider the following algorithm to find the maximum element of an array of positive integers:You should build the array arr which has the following properties:Return the number of ways to build the array arr under the mentioned conditions.\n As the answer may grow large, the answer must be computed modulo 10^9 + 7.",
"examples": [
"Input: n = 2, m = 3, k = 1",
"Output: 6",
"Explanation: The possible arrays are [1, 1], [2, 1], [2, 2], [3, 1], [3, 2] [3, 3]",
"Input: n = 5, m = 2, k = 3",
"Output: 0",
"Explanation: There are no possible arrays that satisify the mentioned conditions.",
"Input: n = 9, m = 1, k = 1",
"Output: 1",
"Explanation: The only possible array is [1, 1, 1, 1, 1, 1, 1, 1, 1]",
"Input: n = 50, m = 100, k = 25",
"Output: 34549172",
"Explanation: Don't forget to compute the answer modulo 1000000007",
"Input: n = 37, m = 17, k = 7",
"Output: 418930126",
""
],
"constraints": [
"arr has exactly n integers. 1 <= arr[i] <= m where (0 <= i < n). After applying the mentioned algorithm to arr",
" the value search_cost is equal to k. 1 <= n <= 501 <= m <= 1000 <= k <= n"
]
},
{
"id": "1425",
"title": "Constrained Subsequence Sum",
"question": "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.\nA 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.",
"examples": [
"Input: nums = [10,2,-10,5,20], k = 2",
"Output: 37",
"Explanation: The subsequence is [10, 2, 5, 20].",
"Input: nums = [-1,-2,-3], k = 1",
"Output: -1",
"Explanation: The subsequence must be non-empty, so we choose the largest number.",
"Input: nums = [10,-2,-10,-5,20], k = 2",
"Output: 23",
"Explanation: The subsequence is [10, -2, -5, 20].",
""
],
"constraints": [
"1 <= k <= nums. length <= 105-104 <= nums[i] <= 104"
]
},
{
"id": "1434",
"title": "Number of Ways to Wear Different Hats to Each Other",
"question": "There are n people and 40 types of hats labeled from 1 to 40.\nGiven a list of list of integers hats, where hats[i] is a list of all hats preferred by the i-th person.\nReturn the number of ways that the n people wear different hats to each other.\nSince the answer may be too large, return it modulo 10^9 + 7.",
"examples": [
"Input: hats = [[3,4],[4,5],[5]]",
"Output: 1",
"Explanation: There is only one way to choose hats given the conditions. ",
"First person choose hat 3, Second person choose hat 4 and last one hat 5. Input: hats = [[3,5,1],[3,5]]",
"Output: 4",
"Explanation: There are 4 ways to choose hats",
"(3,5), (5,3), (1,3) and (1,5)",
"Input: hats = [[1,2,3,4],[1,2,3,4],[1,2,3,4],[1,2,3,4]]",
"Output: 24",
"Explanation: Each person can choose hats labeled from 1 to 4.",
"Number of Permutations of (1,2,3,4) = 24.",
"Input: hats = [[1,2,3],[2,3,5,6],[1,3,7,9],[1,8,9],[2,5,7]]",
"Output: 111",
""
],
"constraints": [
"n == hats. length1 <= n <= 101 <= hats[i]. length <= 401 <= hats[i][j] <= 40hats[i] contains a list of unique integers."
]
},
{
"id": "1439",
"title": "Find the Kth Smallest Sum of a Matrix With Sorted Rows",
"question": "You are given an m * n matrix, mat, and an integer k, which has its rows sorted in non-decreasing order.\nYou are allowed to choose exactly 1 element from each row to form an array.\n Return the Kth smallest array sum among all possible arrays.",
"examples": [
"Input: mat = [[1,3,11],[2,4,6]], k = 5",
"Output: 7",
"Explanation: Choosing one element from each row, the first k smallest sum are:",
"[1,2], [1,4], [3,2], [3,4], [1,6]. Where the 5th sum is 7. Input: mat = [[1,3,11],[2,4,6]], k = 9",
"Output: 17",
"Input: mat = [[1,10,10],[1,4,5],[2,3,6]], k = 7",
"Output: 9",
"Explanation: Choosing one element from each row, the first k smallest sum are:",
"[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. ",
"Input: mat = [[1,1,10],[2,2,9]], k = 7",
"Output: 12",
""
],
"constraints": [
"m == mat. lengthn == mat. length[i]1 <= m",
" n <= 401 <= k <= min(200",
" n ^ m)1 <= mat[i][j] <= 5000mat[i] is a non decreasing array."
]
},
{
"id": "1444",
"title": "Number of Ways of Cutting a Pizza",
"question": "Given a rectangular pizza represented as a rows x cols matrix containing the following characters: 'A' (an apple) and '.\n' (empty cell) and given the integer k.\n 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.\n If you cut the pizza vertically, give the left part of the pizza to a person.\n If you cut the pizza horizontally, give the upper part of the pizza to a person.\n Give the last piece of pizza to the last person.\nReturn the number of ways of cutting the pizza such that each piece contains at least one apple.\n Since the answer can be a huge number, return this modulo 10^9 + 7.",
"examples": [
"Input: pizza = [\"A..\",\"AAA\",\"...\"], k = 3",
"Output: 3 ",
"Explanation: The figure above shows the three ways to cut the pizza. Note that pieces must contain at least one apple.",
"Input: pizza = [\"A..\",\"AA.\",\"...\"], k = 3",
"Output: 1",
"Input: pizza = [\"A..\",\"A..\",\"...\"], k = 1",
"Output: 1",
""
],
"constraints": [
"1 <= rows",
" cols <= 50rows == pizza. lengthcols == pizza[i]. length1 <= k <= 10pizza consists of characters 'A' and '.' only."
]
},
{
"id": "1449",
"title": "Form Largest Integer With Digits That Add up to Target",
"question": "Given an array of integers cost and an integer target.\n Return the maximum integer you can paint under the following rules:Since the answer may be too large, return it as string.\nIf there is no way to paint any integer given the condition, return \"0\".",
"examples": [
"Input: cost = [4,3,2,5,6,7,2,5,5], target = 9",
"Output: \"7772\"",
"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.",
"Digit cost",
" 1 -> 4",
" 2 -> 3",
" 3 -> 2",
" 4 -> 5",
" 5 -> 6",
" 6 -> 7",
" 7 -> 2",
" 8 -> 5",
" 9 -> 5",
"Input: cost = [7,6,5,5,5,6,8,7,8], target = 12",
"Output: \"85\"",
"Explanation: The cost to paint the digit '8' is 7, and the digit '5' is 5. Then cost(\"85\") = 7 + 5 = 12.",
"Input: cost = [2,4,6,2,4,6,4,4,4], target = 5",
"Output: \"0\"",
"Explanation: It's not possible to paint any integer with total cost equal to target.",
"Input: cost = [6,10,15,40,40,40,40,40,40], target = 47",
"Output: \"32211\"",
""
],
"constraints": [
"The cost of painting a digit (i+1) is given by cost[i] (0 indexed). The total cost used must be equal to target. Integer does not have digits 0. cost. length == 91 <= cost[i] <= 50001 <= target <= 5000"
]
},
{
"id": "1453",
"title": "Maximum Number of Darts Inside of a Circular Dartboard",
"question": "You have a very large square wall and a circular dartboard placed on the wall.\n You have been challenged to throw darts into the board blindfolded.\n Darts thrown at the wall are represented as an array of points on a 2D plane.\n Return the maximum number of points that are within or lie on any circular dartboard of radius r.",
"examples": [
"Input: points = [[-2,0],[2,0],[0,2],[0,-2]], r = 2",
"Output: 4",
"Explanation: Circle dartboard with center in (0,0) and radius = 2 contain all points.",
"Input: points = [[-3,0],[3,0],[2,6],[5,4],[0,9],[7,8]], r = 5",
"Output: 5",
"Explanation: Circle dartboard with center in (0,4) and radius = 5 contain all points except the point (7,8).",
"Input: points = [[-2,0],[2,0],[0,2],[0,-2]], r = 1",
"Output: 1",
"Input: points = [[1,2],[3,5],[1,-1],[2,3],[4,1],[1,3]], r = 2",
"Output: 4",
""
],
"constraints": [
"1 <= points. length <= 100points[i]. length == 2-10^4 <= points[i][0]",
" points[i][1] <= 10^41 <= r <= 5000"
]
},
{
"id": "1458",
"title": "Max Dot Product of Two Subsequences",
"question": "Given two arrays nums1 and nums2.\nReturn the maximum dot product between non-empty subsequences of nums1 and nums2 with the same length.\nA 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.\n (ie, [2,3,5] is a subsequence of [1,2,3,4,5] while [1,5,3] is not).",
"examples": [
"Input: nums1 = [2,1,-2,5], nums2 = [3,0,-6]",
"Output: 18",
"Explanation: Take subsequence [2,-2] from nums1 and subsequence [3,-6] from nums2.",
"Their dot product is (2*3 + (-2)*(-6)) = 18. Input: nums1 = [3,-2], nums2 = [2,-6,7]",
"Output: 21",
"Explanation: Take subsequence [3] from nums1 and subsequence [7] from nums2.",
"Their dot product is (3*7) = 21. Input: nums1 = [-1,-1], nums2 = [1,1]",
"Output: -1",
"Explanation: Take subsequence [-1] from nums1 and subsequence [1] from nums2.",
"Their dot product is -1."
],
"constraints": [
"1 <= nums1. length",
" nums2. length <= 500-1000 <= nums1[i]",
" nums2[i] <= 1000"
]
},
{
"id": "1463",
"title": "Cherry Pickup II",
"question": "Given a rows x cols matrix grid representing a field of cherries.\n Each cell in grid represents the number of cherries that you can collect.\nYou have two robots that can collect cherries for you, Robot #1 is located at the top-left corner (0,0) , and Robot #2 is located at the top-right corner (0, cols-1) of the grid.\nReturn the maximum number of cherries collection using both robots  by following the rules below:",
"examples": [
"Input: grid = [[3,1,1],[2,5,1],[1,5,5],[2,1,1]]",
"Output: 24",
"Explanation: Path of robot #1 and #2 are described in color green and blue respectively.",
"Cherries taken by Robot #1, (3 + 2 + 5 + 2) = 12.",
"Cherries taken by Robot #2, (1 + 5 + 5 + 1) = 12.",
"Total of cherries: 12 + 12 = 24.",
"Input: 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]]",
"Output: 28",
"Explanation: Path of robot #1 and #2 are described in color green and blue respectively.",
"Cherries taken by Robot #1, (1 + 9 + 5 + 2) = 17.",
"Cherries taken by Robot #2, (1 + 3 + 4 + 3) = 11.",
"Total of cherries: 17 + 11 = 28.",
"Input: grid = [[1,0,0,3],[0,0,0,3],[0,0,3,3],[9,0,3,3]]",
"Output: 22",
"Input: grid = [[1,1],[1,1]]",
"Output: 4",
""
],
"constraints": [
"From a cell (i",
"j)",
" robots can move to cell (i+1",
" j-1) ",
" (i+1",
" j) or (i+1",
" j+1). When any robot is passing through a cell",
" It picks it up all cherries",
" and the cell becomes an empty cell (0). When both robots stay on the same cell",
" only one of them takes the cherries. Both robots cannot move outside of the grid at any moment. Both robots should reach the bottom row in the grid. rows == grid. lengthcols == grid[i]. length2 <= rows",
" cols <= 700 <= grid[i][j] <= 100 "
]
},
{
"id": "1467",
"title": "Probability of a Two Boxes Having The Same Number of Distinct Balls",
"question": "Given 2n balls of k distinct colors.\n 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).\nPlease note that the two boxes are considered different.\n 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).\nWe want to calculate the probability that the two boxes have the same number of distinct balls.",
"examples": [
"Input: balls = [1,1]",
"Output: 1. 00000",
"Explanation: Only 2 ways to divide the balls equally:",
"- A ball of color 1 to box 1 and a ball of color 2 to box 2",
"- A ball of color 2 to box 1 and a ball of color 1 to box 2",
"In both ways, the number of distinct colors in each box is equal. The probability is 2/2 = 1",
"Input: balls = [2,1,1]",
"Output: 0. 66667",
"Explanation: We have the set of balls [1, 1, 2, 3]",
"This set of balls will be shuffled randomly and we may have one of the 12 distinct shuffles with equale probability (i. e. 1/12):",
"[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]",
"After that we add the first two balls to the first box and the second two balls to the second box.",
"We can see that 8 of these 12 possible random distributions have the same number of distinct colors of balls in each box.",
"Probability is 8/12 = 0. 66667",
"Input: balls = [1,2,1,2]",
"Output: 0. 60000",
"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.",
"Probability = 108 / 180 = 0. 6",
"Input: balls = [3,2,1]",
"Output: 0. 30000",
"Explanation: The set of balls is [1, 1, 1, 2, 2, 3]. It is hard to display all the 60 possible random shuffles of this set but it is easy to check that 18 of them will have the same number of distinct colors in each box.",
"Probability = 18 / 60 = 0. 3",
"Input: balls = [6,6,6,6,6,6]",
"Output: 0. 90327",
""
],
"constraints": [
"1 <= balls. length <= 81 <= balls[i] <= 6sum(balls) is even. Answers within 10^-5 of the actual value will be accepted as correct."
]
},
{
"id": "690",
"title": "Employee Importance",
"question": "You have a data structure of employee information, which includes the employee's unique id, their importance value, and their direct subordinates' id.\nYou are given an array of employees employees where:Given an integer id that represents the ID of an employee, return the total importance value of this employee and all their subordinates.",
"examples": [
"Input: employees = [[1,5,[2,3]],[2,3,[]],[3,3,[]]], id = 1",
"Output: 11",
"Explanation: Employee 1 has importance value 5, and he has two direct subordinates: employee 2 and employee 3.",
"They both have importance value 3.",
"So the total importance value of employee 1 is 5 + 3 + 3 = 11.",
"Input: employees = [[1,2,[5]],[5,-3,[]]], id = 5",
"Output: -3",
""
],
"constraints": [
"employees[i]. id is the ID of the ith employee. employees[i]. importance is the importance value of the ith employee. employees[i]. subordinates is a list of the IDs of the subordinates of the ith employee. 1 <= employees. length <= 20001 <= employees[i]. id <= 2000All employees[i]. id are unique.-100 <= employees[i]. importance <= 100One employee has at most one direct leader and may have several subordinates. id is guaranteed to be a valid employee id."
]
},
{
"id": "1473",
"title": "Paint House III",
"question": "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.\nA neighborhood is a maximal group of continuous houses that are painted with the same color.\nGiven an array houses, an m x n matrix cost and an integer target where:Return the minimum cost of painting all the remaining houses in such a way that there are exactly target neighborhoods.\n If it is not possible, return -1.",
"examples": [
"Input: houses = [0,0,0,0,0], cost = [[1,10],[10,1],[10,1],[1,10],[5,1]], m = 5, n = 2, target = 3",
"Output: 9",
"Explanation: Paint houses of this way [1,2,2,1,1]",
"This array contains target = 3 neighborhoods, [{1}, {2,2}, {1,1}].",
"Cost of paint all houses (1 + 1 + 1 + 1 + 5) = 9.",
"Input: houses = [0,2,1,2,0], cost = [[1,10],[10,1],[10,1],[1,10],[5,1]], m = 5, n = 2, target = 3",
"Output: 11",
"Explanation: Some houses are already painted, Paint the houses of this way [2,2,1,2,2]",
"This array contains target = 3 neighborhoods, [{2,2}, {1}, {2,2}]. ",
"Cost of paint the first and last house (10 + 1) = 11.",
"Input: houses = [0,0,0,0,0], cost = [[1,10],[10,1],[1,10],[10,1],[1,10]], m = 5, n = 2, target = 5",
"Output: 5",
"Input: houses = [3,1,2,3], cost = [[1,1,1],[1,1,1],[1,1,1],[1,1,1]], m = 4, n = 3, target = 3",
"Output: -1",
"Explanation: Houses are already painted with a total of 4 neighborhoods [{3},{1},{2},{3}] different of target = 3.",
""
],
"constraints": [
"For example: houses = [1",
"2",
"2",
"3",
"3",
"2",
"1",
"1] contains 5 neighborhoods [{1}",
" {2",
"2}",
" {3",
"3}",
" {2}",
" {1",
"1}]. houses[i]: is the color of the house i",
" and 0 if the house is not painted yet. cost[i][j]: is the cost of paint the house i with the color j + 1. m == houses. length == cost. lengthn == cost[i]. length1 <= m <= 1001 <= n <= 201 <= target <= m0 <= houses[i] <= n1 <= cost[i][j] <= 10^4"
]
},
{
"id": "1478",
"title": "Allocate Mailboxes",
"question": "Given the array houses and an integer k.\n where houses[i] is the location of the ith house along a street, your task is to allocate k mailboxes in the street.\nReturn the minimum total distance between each house and its nearest mailbox.\nThe answer is guaranteed to fit in a 32-bit signed integer.",
"examples": [
"Input: houses = [1,4,8,10,20], k = 3",
"Output: 5",
"Explanation: Allocate mailboxes in position 3, 9 and 20.",
"Minimum total distance from each houses to nearest mailboxes is |3-1| + |4-3| + |9-8| + |10-9| + |20-20| = 5 ",
"Input: houses = [2,3,5,12,18], k = 2",
"Output: 9",
"Explanation: Allocate mailboxes in position 3 and 14.",
"Minimum total distance from each houses to nearest mailboxes is |2-3| + |3-3| + |5-3| + |12-14| + |18-14| = 9.",
"Input: houses = [7,4,6,1], k = 1",
"Output: 8",
"Input: houses = [3,6,14,10], k = 4",
"Output: 0",
""
],
"constraints": [
"n == houses. length1 <= n <= 1001 <= houses[i] <= 10^41 <= k <= nArray houses contain unique integers."
]
},
{
"id": "1483",
"title": "Kth Ancestor of a Tree Node",
"question": "You are given a tree with n nodes numbered from 0 to n - 1 in the form of a parent array parent where parent[i] is the parent of ith node.\n The root of the tree is node 0.\n Find the kth ancestor of a given node.\nThe kth ancestor of a tree node is the kth node in the path from that node to the root node.\nImplement the TreeAncestor class:",
"examples": [
"Input",
"[\"TreeAncestor\", \"getKthAncestor\", \"getKthAncestor\", \"getKthAncestor\"]",
"[[7, [-1, 0, 0, 1, 1, 2, 2]], [3, 1], [5, 2], [6, 3]]",
"Output",
"[null, 1, 0, -1]",
"",
"Explanation",
"TreeAncestor treeAncestor = new TreeAncestor(7, [-1, 0, 0, 1, 1, 2, 2]);",
"treeAncestor. getKthAncestor(3, 1); // returns 1 which is the parent of 3",
"treeAncestor. getKthAncestor(5, 2); // returns 0 which is the grandparent of 5",
"treeAncestor. getKthAncestor(6, 3); // returns -1 because there is no such ancestor"
],
"constraints": [
"TreeAncestor(int n",
" int[] parent) Initializes the object with the number of nodes in the tree and the parent array. int getKthAncestor(int node",
" int k) return the kth ancestor of the given node node. If there is no such ancestor",
" return -1. 1 <= k <= n <= 5 * 104parent. length == nparent[0] == -10 <= parent[i] < n for all 0 < i < n0 <= node < nThere will be at most 5 * 104 queries."
]
},
{
"id": "1489",
"title": "Find Critical and Pseudo-Critical Edges in Minimum Spanning Tree",
"question": "Given a weighted undirected connected graph with n vertices numbered from 0 to n - 1, and an array edges where edges[i] = [ai, bi, weighti] represents a bidirectional and weighted edge between nodes ai and bi.\n A minimum spanning tree (MST) is a subset of the graph's edges that connects all vertices without cycles and with the minimum possible total edge weight.\nFind all the critical and pseudo-critical edges in the given graph's minimum spanning tree (MST).\n An MST edge whose deletion from the graph would cause the MST weight to increase is called a critical edge.\n On the other hand, a pseudo-critical edge is that which can appear in some MSTs but not all.\nNote that you can return the indices of the edges in any order.",
"examples": [
"Input: n = 5, edges = [[0,1,1],[1,2,1],[2,3,2],[0,3,2],[0,4,3],[3,4,3],[1,4,6]]",
"Output: [[0,1],[2,3,4,5]]",
"Explanation: The figure above describes the graph.",
"The following figure shows all the possible MSTs:",
"",
"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.",
"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.",
"Input: n = 4, edges = [[0,1,1],[1,2,1],[2,3,1],[0,3,1]]",
"Output: [[],[0,1,2,3]]",
"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.",
""
],
"constraints": [
"2 <= n <= 1001 <= edges. length <= min(200",
" n * (n - 1) / 2)edges[i]. length == 30 <= ai < bi < n1 <= weighti <= 1000All pairs (ai",
" bi) are distinct."
]
},
{
"id": "1494",
"title": "Parallel Courses II",
"question": "You are given an integer n, which indicates that there are n courses labeled from 1 to n.\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 Also, you are given the integer k.\nIn one semester, you can take at most k courses as long as you have taken all the prerequisites in the previous semester for the courses you are taking.\nReturn the minimum number of semesters needed to take all courses.\n The testcases will be generated such that it is possible to take every course.",
"examples": [
"Input: n = 4, dependencies = [[2,1],[3,1],[1,4]], k = 2",
"Output: 3 ",
"Explanation: The figure above represents the given graph.",
"In the first semester, you can take courses 2 and 3.",
"In the second semester, you can take course 1.",
"In the third semester, you can take course 4.",
"Input: n = 5, dependencies = [[2,1],[3,1],[4,1],[1,5]], k = 2",
"Output: 4 ",
"Explanation: The figure above represents the given graph.",
"In the first semester, you can take courses 2 and 3 only since you cannot take more than two per semester.",
"In the second semester, you can take course 4.",
"In the third semester, you can take course 1.",
"In the fourth semester, you can take course 5.",
"Input: n = 11, dependencies = [], k = 2",
"Output: 6",
""
],
"constraints": [
"1 <= n <= 151 <= k <= n0 <= relations. length <= n * (n-1) / 2relations[i]. length == 21 <= prevCoursei",
" nextCoursei <= nprevCoursei != nextCourseiAll the pairs [prevCoursei",
" nextCoursei] are unique. The given graph is a directed acyclic graph."
]
},
{
"id": "1499",
"title": "Max Value of Equation",
"question": "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.\nlength.\n You are also given an integer k.\nReturn the maximum value of the equation yi + yj + |xi - xj| where |xi - xj| <= k and 1 <= i < j <= points.\nlength.\nIt is guaranteed that there exists at least one pair of points that satisfy the constraint |xi - xj| <= k.",
"examples": [
"Input: points = [[1,3],[2,0],[5,10],[6,-10]], k = 1",
"Output: 4",
"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.",
"No other pairs satisfy the condition, so we return the max of 4 and 1.",
"Input: points = [[0,0],[3,0],[9,2]], k = 3",
"Output: 3",
"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.",
""
],
"constraints": [
"2 <= points. length <= 105points[i]. length == 2-108 <= xi",
" yi <= 1080 <= k <= 2 * 108xi < xj for all 1 <= i < j <= points. lengthxi form a strictly increasing sequence."
]
},
{
"id": "1505",
"title": "Minimum Possible Integer After at Most K Adjacent Swaps On Digits",
"question": "Given a string num representing the digits of a very large integer and an integer k.\nYou are allowed to swap any two adjacent digits of the integer at most k times.\nReturn the minimum integer you can obtain also as a string.",
"examples": [
"Input: num = \"4321\", k = 4",
"Output: \"1342\"",
"Explanation: The steps to obtain the minimum integer from 4321 with 4 adjacent swaps are shown.",
"Input: num = \"100\", k = 1",
"Output: \"010\"",
"Explanation: It's ok for the output to have leading zeros, but the input is guaranteed not to have any leading zeros.",
"Input: num = \"36789\", k = 1000",
"Output: \"36789\"",
"Explanation: We can keep the number without any swaps.",
"Input: num = \"22\", k = 22",
"Output: \"22\"",
"Input: num = \"9438957234785635408\", k = 23",
"Output: \"0345989723478563548\"",
""
],
"constraints": [
"1 <= num. length <= 30000num contains digits only and doesn't have leading zeros. 1 <= k <= 10^9"
]
},
{
"id": "1510",
"title": "Stone Game IV",
"question": "Alice and Bob take turns playing a game, with Alice starting first.\nInitially, there are n stones in a pile.\n  On each player's turn, that player makes a move consisting of removing any non-zero square number of stones in the pile.\nAlso, if a player cannot make a move, he/she loses the game.\nGiven a positive integer n.\n Return True if and only if Alice wins the game otherwise return False, assuming both players play optimally.",
"examples": [
"Input: n = 1",
"Output: true",
"Explanation: Alice can remove 1 stone winning the game because Bob doesn't have any moves. Input: n = 2",
"Output: false",
"Explanation: Alice can only remove 1 stone, after that Bob removes the last one winning the game (2 -> 1 -> 0). Input: n = 4",
"Output: true",
"Explanation: n is already a perfect square, Alice can win with one move, removing 4 stones (4 -> 0).",
"Input: n = 7",
"Output: false",
"Explanation: Alice can't win the game if Bob plays optimally.",
"If Alice starts removing 4 stones, Bob will remove 1 stone then Alice should remove only 1 stone and finally Bob removes the last one (7 -> 3 -> 2 -> 1 -> 0). ",
"If Alice starts removing 1 stone, Bob will remove 4 stones then Alice only can remove 1 stone and finally Bob removes the last one (7 -> 6 -> 2 -> 1 -> 0). Input: n = 17",
"Output: false",
"Explanation: Alice can't win the game if Bob plays optimally.",
""
],
"constraints": [
"1 <= n <= 10^5"
]
},
{
"id": "1515",
"title": "Best Position for a Service Centre",
"question": "A delivery company wants to build a new service centre in a new city.\n The company knows the positions of all the customers in this city on a 2D-Map and wants to build the new centre in a position such that the sum of the euclidean distances to all customers is minimum.\nGiven 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.\nIn other words, you need to choose the position of the service centre [xcentre, ycentre] such that the following formula is minimized:Answers within 10^-5 of the actual value will be accepted.",
"examples": [
"Input: positions = [[0,1],[1,0],[1,2],[2,1]]",
"Output: 4. 00000",
"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.",
"Input: positions = [[1,1],[3,3]]",
"Output: 2. 82843",
"Explanation: The minimum possible sum of distances = sqrt(2) + sqrt(2) = 2. 82843",
"Input: positions = [[1,1]]",
"Output: 0. 00000",
"Input: positions = [[1,1],[0,0],[2,0]]",
"Output: 2. 73205",
"Explanation: At the first glance, you may think that locating the centre at [1, 0] will achieve the minimum sum, but locating it at [1, 0] will make the sum of distances = 3.",
"Try to locate the centre at [1. 0, 0. 5773502711] you will see that the sum of distances is 2. 73205.",
"Be careful with the precision!",
"Input: positions = [[0,1],[3,2],[4,5],[7,6],[8,9],[11,1],[2,12]]",
"Output: 32. 94036",
"Explanation: You can use [4. 3460852395, 4. 9813795505] as the position of the centre.",
""
],
"constraints": [
"1 <= positions. length <= 50positions[i]. length == 20 <= positions[i][0]",
" positions[i][1] <= 100"
]
},
{
"id": "1520",
"title": "Maximum Number of Non-Overlapping Substrings",
"question": "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:Find the maximum number of substrings that meet the above conditions.\n If there are multiple solutions with the same number of substrings, return the one with minimum total length.\n It can be shown that there exists a unique solution of minimum total length.\nNotice that you can return the substrings in any order.",
"examples": [
"Input: s = \"adefaddaccc\"",
"Output: [\"e\",\"f\",\"ccc\"]",
"Explanation: The following are all the possible substrings that meet the conditions:",
"[",
"  \"adefaddaccc\"",
"  \"adefadda\",",
"  \"ef\",",
"  \"e\",",
" \"f\",",
"  \"ccc\",",
"]",
"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.",
"Input: s = \"abbaccd\"",
"Output: [\"d\",\"bb\",\"cc\"]",
"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.",
""
],
"constraints": [
"1 <= s. length <= 10^5s contains only lowercase English letters."
]
},
{
"id": "693",
"title": "Binary Number with Alternating Bits",
"question": "Given a positive integer, check whether it has alternating bits: namely, if two adjacent bits will always have different values.",
"examples": [
"Input: n = 5",
"Output: true",
"Explanation: The binary representation of 5 is: 101",
"Input: n = 7",
"Output: false",
"Explanation: The binary representation of 7 is: 111. Input: n = 11",
"Output: false",
"Explanation: The binary representation of 11 is: 1011. Input: n = 10",
"Output: true",
"Explanation: The binary representation of 10 is: 1010. Input: n = 3",
"Output: false",
""
],
"constraints": [
"1 <= n <= 231 - 1"
]
},
{
"id": "1521",
"title": "Find a Value of a Mysterious Function Closest to Target",
"question": "Winston was given the above mysterious function func.\n 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.\nReturn the minimum possible value of |func(arr, l, r) - target|.\nNotice that func should be called with the values l and r where 0 <= l, r < arr.\nlength.",
"examples": [
"Input: arr = [9,12,3,7,15], target = 5",
"Output: 2",
"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.",
"Input: arr = [1000000,1000000,1000000], target = 1",
"Output: 999999",
"Explanation: Winston called the func with all possible values of [l,r] and he always got 1000000, thus the min difference is 999999.",
"Input: arr = [1,2,4,8,16], target = 0",
"Output: 0",
""
],
"constraints": [
"1 <= arr. length <= 1051 <= arr[i] <= 1060 <= target <= 107"
]
},
{
"id": "1526",
"title": "Minimum Number of Increments on Subarrays to Form a Target Array",
"question": "Given an array of positive integers target and an array initial of same size with all zeros.\nReturn the minimum number of operations to form a target array from initial if you are allowed to do the following operation:",
"examples": [
"Input: target = [1,2,3,2,1]",
"Output: 3",
"Explanation: We need at least 3 operations to form the target array from the initial array.",
"[0,0,0,0,0] increment 1 from index 0 to 4 (inclusive).",
"[1,1,1,1,1] increment 1 from index 1 to 3 (inclusive).",
"[1,2,2,2,1] increment 1 at index 2.",
"[1,2,3,2,1] target array is formed.",
"Input: target = [3,1,1,2]",
"Output: 4",
"Explanation: (initial)[0,0,0,0] -> [1,1,1,1] -> [1,1,1,2] -> [2,1,1,2] -> [3,1,1,2] (target).",
"Input: target = [3,1,5,4,2]",
"Output: 7",
"Explanation: (initial)[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] (target).",
"Input: target = [1,1,1,1]",
"Output: 1",
""
],
"constraints": [
"Choose any subarray from initial and increment each value by one. 1 <= target. length <= 10^51 <= target[i] <= 10^5"
]
},
{
"id": "1531",
"title": "String Compression II",
"question": "Run-length encoding is a string compression method that works by replacing 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).\n For example, to compress the string \"aabccc\" we replace \"aa\" by \"a2\" and replace \"ccc\" by \"c3\".\n Thus the compressed string becomes \"a2bc3\".\nNotice that in this problem, we are not adding '1' after single characters.\nGiven a string s and an integer k.\n You need to delete at most k characters from s such that the run-length encoded version of s has minimum length.\nFind the minimum length of the run-length encoded version of s after deleting at most k characters.",
"examples": [
"Input: s = \"aaabcccd\", k = 2",
"Output: 4",
"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. Input: s = \"aabbaa\", k = 2",
"Output: 2",
"Explanation: If we delete both 'b' characters, the resulting compressed string would be \"a4\" of length 2.",
"Input: s = \"aaaaaaaaaaa\", k = 0",
"Output: 3",
"Explanation: Since k is zero, we cannot delete anything. The compressed string is \"a11\" of length 3.",
""
],
"constraints": [
"1 <= s. length <= 1000 <= k <= s. lengths contains only lowercase English letters."
]
},
{
"id": "1537",
"title": "Get the Maximum Score",
"question": "You are given two sorted arrays of distinct integers nums1 and nums2.\nA valid path is defined as follows:Score is defined as the sum of uniques values in a valid path.\nReturn the maximum score you can obtain of all possible valid paths.\nSince the answer may be too large, return it modulo 10^9 + 7.",
"examples": [
"Input: nums1 = [2,4,5,8,10], nums2 = [4,6,8,9]",
"Output: 30",
"Explanation: Valid paths:",
"[2,4,5,8,10], [2,4,5,8,9], [2,4,6,8,9], [2,4,6,8,10], (starting from nums1)",
"[4,6,8,9], [4,5,8,10], [4,5,8,9], [4,6,8,10] (starting from nums2)",
"The maximum is obtained with the path in green [2,4,6,8,10].",
"Input: nums1 = [1,3,5,7,9], nums2 = [3,5,100]",
"Output: 109",
"Explanation: Maximum sum is obtained with the path [1,3,5,100].",
"Input: nums1 = [1,2,3,4,5], nums2 = [6,7,8,9,10]",
"Output: 40",
"Explanation: There are no common elements between nums1 and nums2.",
"Maximum sum is obtained with the path [6,7,8,9,10].",
"Input: nums1 = [1,4,5,8,9,11,19], nums2 = [2,3,4,11,12]",
"Output: 61",
""
],
"constraints": [
"Choose array nums1 or nums2 to traverse (from index-0). Traverse the current array from left to right. 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). 1 <= nums1. length <= 10^51 <= nums2. length <= 10^51 <= nums1[i]",
" nums2[i] <= 10^7nums1 and nums2 are strictly increasing."
]
},
{
"id": "1542",
"title": "Find Longest Awesome Substring",
"question": "Given a string s.\n An awesome substring is a non-empty substring of s such that we can make any number of swaps in order to make it palindrome.\nReturn the length of the maximum length awesome substring of s.",
"examples": [
"Input: s = \"3242415\"",
"Output: 5",
"Explanation: \"24241\" is the longest awesome substring, we can form the palindrome \"24142\" with some swaps.",
"Input: s = \"12345678\"",
"Output: 1",
"Input: s = \"213123\"",
"Output: 6",
"Explanation: \"213123\" is the longest awesome substring, we can form the palindrome \"231132\" with some swaps.",
"Input: s = \"00\"",
"Output: 2",
""
],
"constraints": [
"1 <= s. length <= 10^5s consists only of digits."
]
},
{
"id": "1547",
"title": "Minimum Cost to Cut a Stick",
"question": "Given a wooden stick of length n units.\n The stick is labelled from 0 to n.\n For example, a stick of length 6 is labelled as follows:Given an integer array cuts where cuts[i] denotes a position you should perform a cut at.\nYou should perform the cuts in order, you can change the order of the cuts as you wish.\nThe cost of one cut is the length of the stick to be cut, the total cost is the sum of costs of all cuts.\n When you cut a stick, it will be split into two smaller sticks (i.\ne.\n the sum of their lengths is the length of the stick before the cut).\n Please refer to the first example for a better explanation.\nReturn the minimum total cost of the cuts.",
"examples": [
"Input: n = 7, cuts = [1,3,4,5]",
"Output: 16",
"Explanation: Using cuts order = [1, 3, 4, 5] as in the input leads to the following scenario:",
"",
"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.",
"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). Input: n = 9, cuts = [5,6,1,4,2]",
"Output: 22",
"Explanation: If you try the given cuts ordering the cost will be 25.",
"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.",
""
],
"constraints": [
"2 <= n <= 10^61 <= cuts. length <= min(n - 1",
" 100)1 <= cuts[i] <= n - 1All the integers in cuts array are distinct."
]
},
{
"id": "1553",
"title": "Minimum Number of Days to Eat N Oranges",
"question": "There are n oranges in the kitchen and you decided to eat some of these oranges every day as follows:You can only choose one of the actions per day.\nReturn the minimum number of days to eat n oranges.",
"examples": [
"Input: n = 10",
"Output: 4",
"Explanation: You have 10 oranges.",
"Day 1: Eat 1 orange, 10 - 1 = 9. ",
"Day 2: Eat 6 oranges, 9 - 2*(9/3) = 9 - 6 = 3. (Since 9 is divisible by 3)",
"Day 3: Eat 2 oranges, 3 - 2*(3/3) = 3 - 2 = 1. ",
"Day 4: Eat the last orange 1 - 1 = 0.",
"You need at least 4 days to eat the 10 oranges.",
"Input: n = 6",
"Output: 3",
"Explanation: You have 6 oranges.",
"Day 1: Eat 3 oranges, 6 - 6/2 = 6 - 3 = 3. (Since 6 is divisible by 2).",
"Day 2: Eat 2 oranges, 3 - 2*(3/3) = 3 - 2 = 1. (Since 3 is divisible by 3)",
"Day 3: Eat the last orange 1 - 1 = 0.",
"You need at least 3 days to eat the 6 oranges.",
"Input: n = 1",
"Output: 1",
"Input: n = 56",
"Output: 6",
""
],
"constraints": [
"Eat one orange. If the number of remaining oranges (n) is divisible by 2 then you can eat  n/2 oranges. If the number of remaining oranges (n) is divisible by 3 then you can eat  2*(n/3) oranges. 1 <= n <= 2*10^9"
]
},
{
"id": "1559",
"title": "Detect Cycles in 2D Grid",
"question": "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.\nA cycle is a path of length 4 or more in the grid that starts and ends at the same cell.\n 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.\nAlso, you cannot move to the cell that you visited in your last move.\n 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.\nReturn true if any cycle of the same value exists in grid, otherwise, return false.",
"examples": [
"Input: grid = [[\"a\",\"a\",\"a\",\"a\"],[\"a\",\"b\",\"b\",\"a\"],[\"a\",\"b\",\"b\",\"a\"],[\"a\",\"a\",\"a\",\"a\"]]",
"Output: true",
"Explanation: There are two valid cycles shown in different colors in the image below:",
"",
"Input: grid = [[\"c\",\"c\",\"c\",\"a\"],[\"c\",\"d\",\"c\",\"c\"],[\"c\",\"c\",\"e\",\"c\"],[\"f\",\"c\",\"c\",\"c\"]]",
"Output: true",
"Explanation: There is only one valid cycle highlighted in the image below:",
"",
"Input: grid = [[\"a\",\"b\",\"b\"],[\"b\",\"z\",\"b\"],[\"b\",\"b\",\"a\"]]",
"Output: false",
""
],
"constraints": [
"m == grid. lengthn == grid[i]. length1 <= m <= 5001 <= n <= 500grid consists only of lowercase English letters."
]
},
{
"id": "1563",
"title": "Stone Game V",
"question": "There are several stones arranged in a row, and each stone has an associated value which is an integer given in the array stoneValue.\nIn each round of the game, Alice divides the row into two non-empty rows (i.\ne.\n 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.\n Bob throws away the row which has the maximum value, and Alice's score increases by the value of the remaining row.\n If the value of the two rows are equal, Bob lets Alice decide which row will be thrown away.\n The next round starts with the remaining row.\nThe game ends when there is only one stone remaining.\n Alice's is initially zero.\nReturn the maximum score that Alice can obtain.",
"examples": [
"Input: stoneValue = [6,2,3,4,5,5]",
"Output: 18",
"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.",
"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).",
"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.",
"Input: stoneValue = [7,7,7,7,7,7,7]",
"Output: 28",
"Input: stoneValue = [4]",
"Output: 0",
""
],
"constraints": [
"1 <= stoneValue. length <= 5001 <= stoneValue[i] <= 10^6"
]
},
{
"id": "1568",
"title": "Minimum Number of Days to Disconnect Island",
"question": "Given a 2D grid consisting of 1s (land) and 0s (water).\n  An island is a maximal 4-directionally (horizontal or vertical) connected group of 1s.\nThe grid is said to be connected if we have exactly one island, otherwise is said disconnected.\nIn one day, we are allowed to change any single land cell (1) into a water cell (0).\nReturn the minimum number of days to disconnect the grid.",
"examples": [
"Input: grid = [[0,1,1,0],[0,1,1,0],[0,0,0,0]]",
"Output: 2",
"Explanation: We need at least 2 days to get a disconnected grid.",
"Change land grid[1][1] and grid[0][2] to water and get 2 disconnected island.",
"Input: grid = [[1,1]]",
"Output: 2",
"Explanation: Grid of full water is also disconnected ([[1,1]] -> [[0,0]]), 0 islands.",
"Input: grid = [[1,0,1,0]]",
"Output: 0",
"Input: grid = [[1,1,0,1,1],",
"  [1,1,1,1,1],",
"  [1,1,0,1,1],",
"  [1,1,0,1,1]]",
"Output: 1",
"Input: grid = [[1,1,0,1,1],",
"  [1,1,1,1,1],",
"  [1,1,0,1,1],",
"  [1,1,1,1,1]]",
"Output: 2",
""
],
"constraints": [
"1 <= grid. length",
" grid[i]. length <= 30grid[i][j] is 0 or 1."
]
},
{
"id": "696",
"title": "Count Binary Substrings",
"question": "Give 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.\nSubstrings that occur multiple times are counted the number of times they occur.",
"examples": [
"Input: s = \"00110011\"",
"Output: 6",
"Explanation: There are 6 substrings that have equal number of consecutive 1's and 0's: \"0011\", \"01\", \"1100\", \"10\", \"0011\", and \"01\".",
"Notice that some of these substrings repeat and are counted the number of times they occur.",
"Also, \"00110011\" is not a valid substring because all the 0's (and 1's) are not grouped together.",
"Input: s = \"10101\"",
"Output: 4",
"Explanation: There are 4 substrings: \"10\", \"01\", \"10\", \"01\" that have equal number of consecutive 1's and 0's.",
""
],
"constraints": [
"1 <= s. length <= 105s[i] is either '0' or '1'."
]
},
{
"id": "1569",
"title": "Number of Ways to Reorder Array to Get Same BST",
"question": "Given an array nums that represents a permutation of integers from 1 to n.\n We are going to construct a binary search tree (BST) by inserting the elements of nums in order into an initially empty BST.\n Find the number of different ways to reorder nums so that the constructed BST is identical to that formed from the original array nums.\nFor example, given nums = [2,1,3], we will have 2 as the root, 1 as a left child, and 3 as a right child.\n The array [2,3,1] also yields the same BST but [3,2,1] yields a different BST.\nReturn the number of ways to reorder nums such that the BST formed is identical to the original BST formed from nums.\nSince the answer may be very large, return it modulo 10^9 + 7.",
"examples": [
"Input: nums = [2,1,3]",
"Output: 1",
"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.",
"Input: nums = [3,4,5,1,2]",
"Output: 5",
"Explanation: The following 5 arrays will yield the same BST: ",
"[3,1,2,4,5]",
"[3,1,4,2,5]",
"[3,1,4,5,2]",
"[3,4,1,2,5]",
"[3,4,1,5,2]",
"Input: nums = [1,2,3]",
"Output: 0",
"Explanation: There are no other orderings of nums that will yield the same BST.",
"Input: nums = [3,1,2,5,4,6]",
"Output: 19",
"Input: nums = [9,4,2,1,3,6,5,7,8,14,11,10,12,13,16,15,17,18]",
"Output: 216212978",
"Explanation: The number of ways to reorder nums to get the same BST is 3216212999. Taking this number modulo 10^9 + 7 gives 216212978.",
""
],
"constraints": [
"1 <= nums. length <= 10001 <= nums[i] <= nums. lengthAll integers in nums are distinct."
]
},
{
"id": "1575",
"title": "Count All Possible Routes",
"question": "You are given an array of distinct positive integers locations where locations[i] represents the position of city i.\n You are also given integers start, finish and fuel representing the starting city, ending city, and the initial amount of fuel you have, respectively.\nAt each step, if you are at city i, you can pick any city j such that j != i and 0 <= j < locations.\nlength and move to city j.\n Moving from city i to city j reduces the amount of fuel you have by |locations[i] - locations[j]|.\n Please notice that |x| denotes the absolute value of x.\nNotice 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).\nReturn the count of all possible routes from start to finish.\nSince the answer may be too large, return it modulo 10^9 + 7.",
"examples": [
"Input: locations = [2,3,6,8,4], start = 1, finish = 3, fuel = 5",
"Output: 4",
"Explanation: The following are all possible routes, each uses 5 units of fuel:",
"1 -> 3",
"1 -> 2 -> 3",
"1 -> 4 -> 3",
"1 -> 4 -> 2 -> 3",
"Input: locations = [4,3,1], start = 1, finish = 0, fuel = 6",
"Output: 5",
"Explanation: The following are all possible routes:",
"1 -> 0, used fuel = 1",
"1 -> 2 -> 0, used fuel = 5",
"1 -> 2 -> 1 -> 0, used fuel = 5",
"1 -> 0 -> 1 -> 0, used fuel = 3",
"1 -> 0 -> 1 -> 0 -> 1 -> 0, used fuel = 5",
"Input: locations = [5,2,1], start = 0, finish = 2, fuel = 3",
"Output: 0",
"Explanation: It's impossible to get from 0 to 2 using only 3 units of fuel since the shortest route needs 4 units of fuel. Input: locations = [2,1,5], start = 0, finish = 0, fuel = 3",
"Output: 2",
"Explanation: There are two possible routes, 0 and 0 -> 1 -> 0. Input: locations = [1,2,3], start = 0, finish = 2, fuel = 40",
"Output: 615088286",
"Explanation: The total number of possible routes is 2615088300. Taking this number modulo 10^9 + 7 gives us 615088286.",
""
],
"constraints": [
"2 <= locations. length <= 1001 <= locations[i] <= 10^9All integers in locations are distinct. 0 <= start",
" finish < locations. length1 <= fuel <= 200"
]
},
{
"id": "1579",
"title": "Remove Max Number of Edges to Keep Graph Fully Traversable",
"question": "Alice and Bob have an undirected graph of n nodes and 3 types of edges: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.\n The graph is fully traversed by Alice and Bob if starting from any node, they can reach all other nodes.\nReturn the maximum number of edges you can remove, or return -1 if it's impossible for the graph to be fully traversed by Alice and Bob.",
"examples": [
"Input: n = 4, edges = [[3,1,2],[3,2,3],[1,1,3],[1,2,4],[1,1,2],[2,3,4]]",
"Output: 2",
"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.",
"Input: n = 4, edges = [[3,1,2],[3,2,3],[1,1,4],[2,1,4]]",
"Output: 0",
"Explanation: Notice that removing any edge will not make the graph fully traversable by Alice and Bob.",
"Input: n = 4, edges = [[3,2,3],[1,1,2],[2,3,4]]",
"Output: -1",
"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."
],
"constraints": [
"Type 1: Can be traversed by Alice only. Type 2: Can be traversed by Bob only. Type 3: Can by traversed by both Alice and Bob. 1 <= n <= 10^51 <= edges. length <= min(10^5",
" 3 * n * (n-1) / 2)edges[i]. length == 31 <= edges[i][0] <= 31 <= edges[i][1] < edges[i][2] <= nAll tuples (typei",
" ui",
" vi) are distinct."
]
},
{
"id": "1585",
"title": "Check If String Is Transformable With Substring Sort Operations",
"question": "Given two strings s and t, you want to transform string s into string t using the following operation any number of times:For example, applying the operation on the underlined substring in \"14234\" results in \"12344\".\nReturn true if it is possible to transform string s into string t.\n Otherwise, return false.\nA substring is a contiguous sequence of characters within a string.",
"examples": [
"Input: s = \"84532\", t = \"34852\"",
"Output: true",
"Explanation: You can transform s into t using the following sort operations:",
"\"84532\" (from index 2 to 3) -> \"84352\"",
"\"84352\" (from index 0 to 2) -> \"34852\"",
"Input: s = \"34521\", t = \"23415\"",
"Output: true",
"Explanation: You can transform s into t using the following sort operations:",
"\"34521\" -> \"23451\"",
"\"23451\" -> \"23415\"",
"Input: s = \"12345\", t = \"12435\"",
"Output: false",
"Input: s = \"1\", t = \"2\"",
"Output: false",
""
],
"constraints": [
"Choose a non-empty substring in s and sort it in-place so the characters are in ascending order. s. length == t. length1 <= s. length <= 105s and t only contain digits from '0' to '9'."
]
},
{
"id": "1591",
"title": "Strange Printer II",
"question": "There is a strange printer with the following two special requirements:You are given a m x n matrix targetGrid, where targetGrid[row][col] is the color in the position (row, col) of the grid.\nReturn true if it is possible to print the matrix targetGrid, otherwise, return false.",
"examples": [
"Input: targetGrid = [[1,1,1,1],[1,2,2,1],[1,2,2,1],[1,1,1,1]]",
"Output: true",
"Input: targetGrid = [[1,1,1,1],[1,1,3,3],[1,1,3,4],[5,5,1,4]]",
"Output: true",
"Input: targetGrid = [[1,2,1],[2,1,2],[1,2,1]]",
"Output: false",
"Explanation: It is impossible to form targetGrid because it is not allowed to print the same color in different turns. Input: targetGrid = [[1,1,1],[3,1,3]]",
"Output: false",
""
],
"constraints": [
"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. Once the printer has used a color for the above operation",
" the same color cannot be used again. m == targetGrid. lengthn == targetGrid[i]. length1 <= m",
" n <= 601 <= targetGrid[row][col] <= 60"
]
},
{
"id": "1595",
"title": "Minimum Cost to Connect Two Groups of Points",
"question": "You are given two groups of points where the first group has size1 points, the second group has size2 points, and size1 >= size2.\nThe 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.\n The groups are connected if each point in both groups is connected to one or more points in the opposite group.\n 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.\nReturn the minimum cost it takes to connect the two groups.",
"examples": [
"Input: cost = [[15, 96], [36, 2]]",
"Output: 17",
"Explanation: The optimal way of connecting the groups is:",
"1--A",
"2--B",
"This results in a total cost of 17.",
"Input: cost = [[1, 3, 5], [4, 1, 1], [1, 5, 3]]",
"Output: 4",
"Explanation: The optimal way of connecting the groups is:",
"1--A",
"2--B",
"2--C",
"3--A",
"This results in a total cost of 4.",
"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.",
"Input: cost = [[2, 5, 1], [3, 4, 7], [8, 1, 2], [6, 2, 4], [3, 8, 8]]",
"Output: 10",
""
],
"constraints": [
"size1 == cost. lengthsize2 == cost[i]. length1 <= size1",
" size2 <= 12size1 >= size20 <= cost[i][j] <= 100"
]
},
{
"id": "1601",
"title": "Maximum Number of Achievable Transfer Requests",
"question": "We have n buildings numbered from 0 to n - 1.\n Each building has a number of employees.\n It's transfer season, and some employees want to change the building they reside in.\nYou are given an array requests where requests[i] = [fromi, toi] represents an employee's request to transfer from building fromi to building toi.\nAll buildings are full, so a list of requests is achievable only if for each building, the net change in employee transfers is zero.\n This means the number of employees leaving is equal to the number of employees moving in.\n 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.\nReturn the maximum number of achievable requests.",
"examples": [
"Input: n = 5, requests = [[0,1],[1,0],[0,1],[1,2],[2,0],[3,4]]",
"Output: 5",
"Explantion: Let's see the requests:",
"From building 0 we have employees x and y and both want to move to building 1.",
"From building 1 we have employees a and b and they want to move to buildings 2 and 0 respectively.",
"From building 2 we have employee z and they want to move to building 0.",
"From building 3 we have employee c and they want to move to building 4.",
"From building 4 we don't have any requests.",
"We can achieve the requests of users x and b by swapping their places.",
"We can achieve the requests of users y, a and z by swapping the places in the 3 buildings.",
"Input: n = 3, requests = [[0,0],[1,2],[2,1]]",
"Output: 3",
"Explantion: Let's see the requests:",
"From building 0 we have employee x and they want to stay in the same building 0.",
"From building 1 we have employee y and they want to move to building 2.",
"From building 2 we have employee z and they want to move to building 1.",
"We can achieve all the requests. Input: n = 4, requests = [[0,3],[3,1],[1,2],[2,0]]",
"Output: 4",
""
],
"constraints": [
"1 <= n <= 201 <= requests. length <= 16requests[i]. length == 20 <= fromi",
" toi < n"
]
},
{
"id": "1606",
"title": "Find Servers That Handled Most Number of Requests",
"question": "You have k servers numbered from 0 to k-1 that are being used to handle multiple requests simultaneously.\n Each server has infinite computational capacity but cannot handle more than one request at a time.\n The requests are assigned to servers according to a specific algorithm: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).\n Your goal is to find the busiest server(s).\n A server is considered busiest if it handled the most number of requests successfully among all the servers.\nReturn a list containing the IDs (0-indexed) of the busiest server(s).\n You may return the IDs in any order.",
"examples": [
"Input: k = 3, arrival = [1,2,3,4,5], load = [5,2,3,3,3] ",
"Output: [1] ",
"Explanation:",
"All of the servers start out available.",
"The first 3 requests are handled by the first 3 servers in order.",
"Request 3 comes in. Server 0 is busy, so it's assigned to the next available server, which is 1.",
"Request 4 comes in. It cannot be handled since all servers are busy, so it is dropped.",
"Servers 0 and 2 handled one request each, while server 1 handled two requests. Hence server 1 is the busiest server.",
"Input: k = 3, arrival = [1,2,3,4], load = [1,2,1,2]",
"Output: [0]",
"Explanation:",
"The first 3 requests are handled by first 3 servers.",
"Request 3 comes in. It is handled by server 0 since the server is available.",
"Server 0 handled two requests, while servers 1 and 2 handled one request each. Hence server 0 is the busiest server.",
"Input: k = 3, arrival = [1,2,3], load = [10,12,11]",
"Output: [0,1,2]",
"Explanation: Each server handles a single request, so they are all considered the busiest.",
"Input: k = 3, arrival = [1,2,3,4,8,9,10], load = [5,2,10,3,1,2,2]",
"Output: [1]",
"Input: k = 1, arrival = [1], load = [1]",
"Output: [0]",
""
],
"constraints": [
"The ith (0-indexed) request arrives. If all servers are busy",
" the request is dropped (not handled at all). If the (i % k)th server is available",
" assign the request to that server. 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. 1 <= k <= 1051 <= arrival. length",
" load. length <= 105arrival. length == load. length1 <= arrival[i]",
" load[i] <= 109arrival is strictly increasing."
]
},
{
"id": "1610",
"title": "Maximum Number of Visible Points",
"question": "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.\nInitially, you are facing directly east from your position.\n You cannot move from your position, but you can rotate.\n In other words, posx and posy cannot be changed.\n Your field of view in degrees is represented by angle, determining how wide you can see from any given view direction.\n Let d be the amount in degrees that you rotate counterclockwise.\n Then, your field of view is the inclusive range of angles [d - angle/2, d + angle/2].\n\nYour browser does not support the video tag or this video format.\n\nYou 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.\nThere can be multiple points at one coordinate.\n There may be points at your location, and you can always see these points regardless of your rotation.\n Points do not obstruct your vision to other points.\nReturn the maximum number of points you can see.",
"examples": [
"Input: points = [[2,1],[2,2],[3,3]], angle = 90, location = [1,1]",
"Output: 3",
"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.",
"Input: points = [[2,1],[2,2],[3,4],[1,1]], angle = 90, location = [1,1]",
"Output: 4",
"Explanation: All points can be made visible in your field of view, including the one at your location.",
"Input: points = [[1,0],[2,1]], angle = 13, location = [1,1]",
"Output: 1",
"Explanation: You can only see one of the two points, as shown above.",
""
],
"constraints": [
"1 <= points. length <= 105points[i]. length == 2location. length == 20 <= angle < 3600 <= posx",
" posy",
" xi",
" yi <= 100"
]
},
{
"id": "1611",
"title": "Minimum One Bit Operations to Make Integers Zero",
"question": "Given an integer n, you must transform it into 0 using the following operations any number of times:Return the minimum number of operations to transform n into 0.",
"examples": [
"Input: n = 0",
"Output: 0",
"Input: n = 3",
"Output: 2",
"Explanation: The binary representation of 3 is \"11\".",
"\"11\" -> \"01\" with the 2nd operation since the 0th bit is 1.",
"\"01\" -> \"00\" with the 1st operation.",
"Input: n = 6",
"Output: 4",
"Explanation: The binary representation of 6 is \"110\".",
"\"110\" -> \"010\" with the 2nd operation since the 1st bit is 1 and 0th through 0th bits are 0.",
"\"010\" -> \"011\" with the 1st operation.",
"\"011\" -> \"001\" with the 2nd operation since the 0th bit is 1.",
"\"001\" -> \"000\" with the 1st operation.",
"Input: n = 9",
"Output: 14",
"Input: n = 333",
"Output: 393",
""
],
"constraints": [
"Change the rightmost (0th) bit in the binary representation of 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. 0 <= n <= 109"
]
},
{
"id": "697",
"title": "Degree of an Array",
"question": "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.\nYour task is to find the smallest possible length of a (contiguous) subarray of nums, that has the same degree as nums.",
"examples": [
"Input: nums = [1,2,2,3,1]",
"Output: 2",
"Explanation: ",
"The input array has a degree of 2 because both elements 1 and 2 appear twice.",
"Of the subarrays that have the same degree:",
"[1, 2, 2, 3, 1], [1, 2, 2, 3], [2, 2, 3, 1], [1, 2, 2], [2, 2, 3], [2, 2]",
"The shortest length is 2. So return 2.",
"Input: nums = [1,2,2,3,1,4,2]",
"Output: 6",
"Explanation: ",
"The degree is 3 because the element 2 is repeated 3 times.",
"So [2,2,3,1,4,2] is the shortest subarray, therefore returning 6.",
""
],
"constraints": [
"nums. length will be between 1 and 50",
"000. nums[i] will be an integer between 0 and 49",
"999."
]
},
{
"id": "1617",
"title": "Count Subtrees With Max Distance Between Cities",
"question": "There are n cities numbered from 1 to n.\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.\n There exists a unique path between each pair of cities.\n In other words, the cities form a tree.\nA 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.\n Two subtrees are different if there is a city in one subtree that is not present in the other.\nFor 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.\nReturn 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.\nNotice that the distance between the two cities is the number of edges in the path between them.",
"examples": [
"Input: n = 4, edges = [[1,2],[2,3],[2,4]]",
"Output: [3,4,0]",
"Explanation:",
"The subtrees with subsets {1,2}, {2,3} and {2,4} have a max distance of 1.",
"The subtrees with subsets {1,2,3}, {1,2,4}, {2,3,4} and {1,2,3,4} have a max distance of 2.",
"No subtree has two nodes where the max distance between them is 3.",
"Input: n = 2, edges = [[1,2]]",
"Output: [1]",
"Input: n = 3, edges = [[1,2],[2,3]]",
"Output: [2,1]",
""
],
"constraints": [
"2 <= n <= 15edges. length == n-1edges[i]. length == 21 <= ui",
" vi <= nAll pairs (ui",
" vi) are distinct."
]
},
{
"id": "1622",
"title": "Fancy Sequence",
"question": "Write an API that generates fancy sequences using the append, addAll, and multAll operations.\nImplement the Fancy class:",
"examples": [
"Input",
"[\"Fancy\", \"append\", \"addAll\", \"append\", \"multAll\", \"getIndex\", \"addAll\", \"append\", \"multAll\", \"getIndex\", \"getIndex\", \"getIndex\"]",
"[[], [2], [3], [7], [2], [0], [3], [10], [2], [0], [1], [2]]",
"Output",
"[null, null, null, null, null, 10, null, null, null, 26, 34, 20]",
"",
"Explanation",
"Fancy fancy = new Fancy();",
"fancy. append(2); // fancy sequence: [2]",
"fancy. addAll(3); // fancy sequence: [2+3] -> [5]",
"fancy. append(7); // fancy sequence: [5, 7]",
"fancy. multAll(2); // fancy sequence: [5*2, 7*2] -> [10, 14]",
"fancy. getIndex(0); // return 10",
"fancy. addAll(3); // fancy sequence: [10+3, 14+3] -> [13, 17]",
"fancy. append(10); // fancy sequence: [13, 17, 10]",
"fancy. multAll(2); // fancy sequence: [13*2, 17*2, 10*2] -> [26, 34, 20]",
"fancy. getIndex(0); // return 26",
"fancy. getIndex(1); // return 34",
"fancy. getIndex(2); // return 20",
""
],
"constraints": [
"Fancy() Initializes the object with an empty sequence. void append(val) Appends an integer val to the end of the sequence. void addAll(inc) Increments all existing values in the sequence by an integer inc. void multAll(m) Multiplies all existing values in the sequence by an integer m. int getIndex(idx) Gets the current value at index idx (0-indexed) of the sequence modulo 109 + 7. If the index is greater or equal than the length of the sequence",
" return -1. 1 <= val",
" inc",
" m <= 1000 <= idx <= 105At most 105 calls total will be made to append",
" addAll",
" multAll",
" and getIndex."
]
},
{
"id": "1627",
"title": "Graph Connectivity With Threshold",
"question": "We have n cities labeled from 1 to n.\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.\n 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: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.\n (i.\ne.\n there is some path between them).\nReturn an array answer, where answer.\nlength == queries.\nlength 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.",
"examples": [
"Input: n = 6, threshold = 2, queries = [[1,4],[2,5],[3,6]]",
"Output: [false,false,true]",
"Explanation: The divisors for each number:",
"1: 1",
"2: 1, 2",
"3: 1, 3",
"4: 1, 2, 4",
"5: 1, 5",
"6: 1, 2, 3, 6",
"Using the underlined divisors above the threshold, only cities 3 and 6 share a common divisor, so they are the",
"only ones directly connected. The result of each query:",
"[1,4] 1 is not connected to 4",
"[2,5] 2 is not connected to 5",
"[3,6] 3 is connected to 6 through path 3--6",
"Input: n = 6, threshold = 0, queries = [[4,5],[3,4],[3,2],[2,6],[1,3]]",
"Output: [true,true,true,true,true]",
"Explanation: The divisors for each number are the same as the previous example. However, since the threshold is 0,",
"all divisors can be used. Since all numbers share 1 as a divisor, all cities are connected.",
"Input: n = 5, threshold = 1, queries = [[4,5],[4,5],[3,2],[2,3],[3,4]]",
"Output: [false,false,false,false,false]",
"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.",
"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].",
""
],
"constraints": [
"x % z == 0",
"y % z == 0",
" andz > threshold. 2 <= n <= 1040 <= threshold <= n1 <= queries. length <= 105queries[i]. length == 21 <= ai",
" bi <= citiesai != bi"
]
},
{
"id": "1632",
"title": "Rank Transform of a Matrix",
"question": "Given an m x n matrix, return a new matrix answer where answer[row][col] is the rank of matrix[row][col].\nThe rank is an integer that represents how large an element is compared to other elements.\n It is calculated using the following rules:It is guaranteed that answer is unique under the given rules.",
"examples": [
"Input: matrix = [[1,2],[3,4]]",
"Output: [[1,2],[2,3]]",
"Explanation:",
"The rank of matrix[0][0] is 1 because it is the smallest integer in its row and column.",
"The rank of matrix[0][1] is 2 because matrix[0][1] > matrix[0][0] and matrix[0][0] is rank 1.",
"The rank of matrix[1][0] is 2 because matrix[1][0] > matrix[0][0] and matrix[0][0] is rank 1.",
"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.",
"Input: matrix = [[7,7],[7,7]]",
"Output: [[1,1],[1,1]]",
"Input: matrix = [[20,-21,14],[-19,4,19],[22,-47,24],[-19,4,19]]",
"Output: [[4,2,3],[1,3,4],[5,1,6],[1,3,4]]",
"Input: matrix = [[7,3,6],[1,4,5],[9,8,2]]",
"Output: [[5,1,4],[1,2,3],[6,3,1]]",
""
],
"constraints": [
"The rank is an integer starting from 1. If two elements p and q are in the same row or column",
" then:\n\t\nIf p < q then rank(p) < rank(q)\nIf p == q then rank(p) == rank(q)\nIf p > q then rank(p) > rank(q)\n\nIf p < q then rank(p) < rank(q)If p == q then rank(p) == rank(q)If p > q then rank(p) > rank(q)The rank should be as small as possible. m == matrix. lengthn == matrix[i]. length1 <= m",
" n <= 500-109 <= matrix[row][col] <= 109"
]
},
{
"id": "1639",
"title": "Number of Ways to Form a Target String Given a Dictionary",
"question": "You are given a list of strings of the same length words and a string target.\nYour task is to form target using the given words under the following rules:Notice that you can use multiple characters from the same string in words provided the conditions above are met.\nReturn the number of ways to form target from words.\n Since the answer may be too large, return it modulo 109 + 7.",
"examples": [
"Input: words = [\"acca\",\"bbbb\",\"caca\"], target = \"aba\"",
"Output: 6",
"Explanation: There are 6 ways to form target.",
"\"aba\" -> index 0 (\"acca\"), index 1 (\"bbbb\"), index 3 (\"caca\")",
"\"aba\" -> index 0 (\"acca\"), index 2 (\"bbbb\"), index 3 (\"caca\")",
"\"aba\" -> index 0 (\"acca\"), index 1 (\"bbbb\"), index 3 (\"acca\")",
"\"aba\" -> index 0 (\"acca\"), index 2 (\"bbbb\"), index 3 (\"acca\")",
"\"aba\" -> index 1 (\"caca\"), index 2 (\"bbbb\"), index 3 (\"acca\")",
"\"aba\" -> index 1 (\"caca\"), index 2 (\"bbbb\"), index 3 (\"caca\")",
"Input: words = [\"abba\",\"baab\"], target = \"bab\"",
"Output: 4",
"Explanation: There are 4 ways to form target.",
"\"bab\" -> index 0 (\"baab\"), index 1 (\"baab\"), index 2 (\"abba\")",
"\"bab\" -> index 0 (\"baab\"), index 1 (\"baab\"), index 3 (\"baab\")",
"\"bab\" -> index 0 (\"baab\"), index 2 (\"baab\"), index 3 (\"baab\")",
"\"bab\" -> index 1 (\"abba\"), index 2 (\"baab\"), index 3 (\"baab\")",
"Input: words = [\"abcd\"], target = \"abcd\"",
"Output: 1",
"Input: words = [\"abab\",\"baba\",\"abba\",\"baab\"], target = \"abba\"",
"Output: 16",
""
],
"constraints": [
"target should be formed from left to right. 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]. 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. Repeat the process until you form the string target. 1 <= words. length <= 10001 <= words[i]. length <= 1000All strings in words have the same length. 1 <= target. length <= 1000words[i] and target contain only lowercase English letters."
]
},
{
"id": "1643",
"title": "Kth Smallest Instructions",
"question": "Bob is standing at cell (0, 0), and he wants to reach destination: (row, column).\n He can only travel right and down.\n You are going to help Bob by providing instructions for him to reach destination.\nThe instructions are represented as a string, where each character is either:Multiple instructions will lead Bob to destination.\n For example, if destination is (2, 3), both \"HHHVV\" and \"HVHVH\" are valid instructions.\nHowever, Bob is very picky.\n Bob has a lucky number k, and he wants the kth lexicographically smallest instructions that will lead him to destination.\n k is 1-indexed.\nGiven an integer array destination and an integer k, return the kth lexicographically smallest instructions that will take Bob to destination.",
"examples": [
"Input: destination = [2,3], k = 1",
"Output: \"HHHVV\"",
"Explanation: All the instructions that reach (2, 3) in lexicographic order are as follows:",
"[\"HHHVV\", \"HHVHV\", \"HHVVH\", \"HVHHV\", \"HVHVH\", \"HVVHH\", \"VHHHV\", \"VHHVH\", \"VHVHH\", \"VVHHH\"].",
"Input: destination = [2,3], k = 2",
"Output: \"HHVHV\"",
"Input: destination = [2,3], k = 3",
"Output: \"HHVVH\"",
""
],
"constraints": [
"'H'",
" meaning move horizontally (go right)",
" or'V'",
" meaning move vertically (go down). destination. length == 21 <= row",
" column <= 151 <= k <= nCr(row + column",
" row)",
" where nCr(a",
" b) denotes a choose b​​​​​."
]
},
{
"id": "1649",
"title": "Create Sorted Array through Instructions",
"question": "Given an integer array instructions, you are asked to create a sorted array from the elements in instructions.\n You start with an empty container nums.\n For each element from left to right in instructions, insert it into nums.\n The cost of each insertion is the minimum of the following: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].\nReturn the total cost to insert all elements from instructions into nums.\n Since the answer may be large, return it modulo 109 + 7",
"examples": [
"Input: instructions = [1,5,6,2]",
"Output: 1",
"Explanation: Begin with nums = [].",
"Insert 1 with cost min(0, 0) = 0, now nums = [1].",
"Insert 5 with cost min(1, 0) = 0, now nums = [1,5].",
"Insert 6 with cost min(2, 0) = 0, now nums = [1,5,6].",
"Insert 2 with cost min(1, 2) = 1, now nums = [1,2,5,6].",
"The total cost is 0 + 0 + 0 + 1 = 1. Input: instructions = [1,2,3,6,5,4]",
"Output: 3",
"Explanation: Begin with nums = [].",
"Insert 1 with cost min(0, 0) = 0, now nums = [1].",
"Insert 2 with cost min(1, 0) = 0, now nums = [1,2].",
"Insert 3 with cost min(2, 0) = 0, now nums = [1,2,3].",
"Insert 6 with cost min(3, 0) = 0, now nums = [1,2,3,6].",
"Insert 5 with cost min(3, 1) = 1, now nums = [1,2,3,5,6].",
"Insert 4 with cost min(3, 2) = 2, now nums = [1,2,3,4,5,6].",
"The total cost is 0 + 0 + 0 + 0 + 1 + 2 = 3.",
"Input: instructions = [1,3,3,3,2,4,2,1,2]",
"Output: 4",
"Explanation: Begin with nums = [].",
"Insert 1 with cost min(0, 0) = 0, now nums = [1].",
"Insert 3 with cost min(1, 0) = 0, now nums = [1,3].",
"Insert 3 with cost min(1, 0) = 0, now nums = [1,3,3].",
"Insert 3 with cost min(1, 0) = 0, now nums = [1,3,3,3].",
"Insert 2 with cost min(1, 3) = 1, now nums = [1,2,3,3,3].",
"Insert 4 with cost min(5, 0) = 0, now nums = [1,2,3,3,3,4].",
"​​​​​​​Insert 2 with cost min(1, 4) = 1, now nums = [1,2,2,3,3,3,4].",
"​​​​​​​Insert 1 with cost min(0, 6) = 0, now nums = [1,1,2,2,3,3,3,4].",
"​​​​​​​Insert 2 with cost min(2, 4) = 2, now nums = [1,1,2,2,2,3,3,3,4].",
"The total cost is 0 + 0 + 0 + 0 + 1 + 0 + 1 + 0 + 2 = 4.",
""
],
"constraints": [
"The number of elements currently in nums that are strictly less than instructions[i]. The number of elements currently in nums that are strictly greater than instructions[i]. 1 <= instructions. length <= 1051 <= instructions[i] <= 105"
]
},
{
"id": "1655",
"title": "Distribute Repeating Integers",
"question": "You are given an array of n integers, nums, where there are at most 50 unique values in the array.\n You are also given an array of m customer order quantities, quantity, where quantity[i] is the amount of integers the ith customer ordered.\n Determine if it is possible to distribute nums such that:Return true if it is possible to distribute nums according to the above conditions.",
"examples": [
"Input: nums = [1,2,3,4], quantity = [2]",
"Output: false",
"Explanation: The 0th customer cannot be given two different integers.",
"Input: nums = [1,2,3,3], quantity = [2]",
"Output: true",
"Explanation: The 0th customer is given [3,3]. The integers [1,2] are not used.",
"Input: nums = [1,1,2,2], quantity = [2,2]",
"Output: true",
"Explanation: The 0th customer is given [1,1], and the 1st customer is given [2,2].",
"Input: nums = [1,1,2,3], quantity = [2,2]",
"Output: false",
"Explanation: Although the 0th customer could be given [1,1], the 1st customer cannot be satisfied. Input: nums = [1,1,1,1,1], quantity = [2,3]",
"Output: true",
"Explanation: The 0th customer is given [1,1], and the 1st customer is given [1,1,1].",
""
],
"constraints": [
"The ith customer gets exactly quantity[i] integers",
"The integers the ith customer gets are all equal",
" andEvery customer is satisfied. n == nums. length1 <= n <= 1051 <= nums[i] <= 1000m == quantity. length1 <= m <= 101 <= quantity[i] <= 105There are at most 50 unique values in nums."
]
},
{
"id": "1659",
"title": "Maximize Grid Happiness",
"question": "You are given four integers, m, n, introvertsCount, and extrovertsCount.\n You have an m x n grid, and there are two types of people: introverts and extroverts.\n There are introvertsCount introverts and extrovertsCount extroverts.\nYou should decide how many people you want to live in the grid and assign each of them one grid cell.\n Note that you do not have to have all the people living in the grid.\nThe happiness of each person is calculated as follows:Neighbors live in the directly adjacent cells north, east, south, and west of a person's cell.\nThe grid happiness is the sum of each person's happiness.\n Return the maximum possible grid happiness.",
"examples": [
"Input: m = 2, n = 3, introvertsCount = 1, extrovertsCount = 2",
"Output: 240",
"Explanation: Assume the grid is 1-indexed with coordinates (row, column).",
"We can put the introvert in cell (1,1) and put the extroverts in cells (1,3) and (2,3).",
"- Introvert at (1,1) happiness: 120 (starting happiness) - (0 * 30) (0 neighbors) = 120",
"- Extrovert at (1,3) happiness: 40 (starting happiness) + (1 * 20) (1 neighbor) = 60",
"- Extrovert at (2,3) happiness: 40 (starting happiness) + (1 * 20) (1 neighbor) = 60",
"The grid happiness is 120 + 60 + 60 = 240.",
"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.",
"Input: m = 3, n = 1, introvertsCount = 2, extrovertsCount = 1",
"Output: 260",
"Explanation: Place the two introverts in (1,1) and (3,1) and the extrovert at (2,1).",
"- Introvert at (1,1) happiness: 120 (starting happiness) - (1 * 30) (1 neighbor) = 90",
"- Extrovert at (2,1) happiness: 40 (starting happiness) + (2 * 20) (2 neighbors) = 80",
"- Introvert at (3,1) happiness: 120 (starting happiness) - (1 * 30) (1 neighbor) = 90",
"The grid happiness is 90 + 80 + 90 = 260.",
"Input: m = 2, n = 2, introvertsCount = 4, extrovertsCount = 0",
"Output: 240",
""
],
"constraints": [
"Introverts start with 120 happiness and lose 30 happiness for each neighbor (introvert or extrovert). Extroverts start with 40 happiness and gain 20 happiness for each neighbor (introvert or extrovert). 1 <= m",
" n <= 50 <= introvertsCount",
" extrovertsCount <= min(m * n",
" 6)"
]
},
{
"id": "1665",
"title": "Minimum Initial Energy to Finish Tasks",
"question": "You are given an array tasks where tasks[i] = [actuali, minimumi]:For example, if the task is [10, 12] and your current energy is 11, you cannot start this task.\n However, if your current energy is 13, you can complete this task, and your energy will be 3 after finishing it.\nYou can finish the tasks in any order you like.\nReturn the minimum initial amount of energy you will need to finish all the tasks.",
"examples": [
"Input: tasks = [[1,2],[2,4],[4,8]]",
"Output: 8",
"Explanation:",
"Starting with 8 energy, we finish the tasks in the following order:",
" - 3rd task. Now energy = 8 - 4 = 4.",
" - 2nd task. Now energy = 4 - 2 = 2.",
" - 1st task. Now energy = 2 - 1 = 1.",
"Notice that even though we have leftover energy, starting with 7 energy does not work because we cannot do the 3rd task. Input: tasks = [[1,3],[2,4],[10,11],[10,12],[8,9]]",
"Output: 32",
"Explanation:",
"Starting with 32 energy, we finish the tasks in the following order:",
" - 1st task. Now energy = 32 - 1 = 31.",
" - 2nd task. Now energy = 31 - 2 = 29.",
" - 3rd task. Now energy = 29 - 10 = 19.",
" - 4th task. Now energy = 19 - 10 = 9.",
" - 5th task. Now energy = 9 - 8 = 1. Input: tasks = [[1,7],[2,8],[3,9],[4,10],[5,11],[6,12]]",
"Output: 27",
"Explanation:",
"Starting with 27 energy, we finish the tasks in the following order:",
" - 5th task. Now energy = 27 - 5 = 22.",
" - 2nd task. Now energy = 22 - 2 = 20.",
" - 3rd task. Now energy = 20 - 3 = 17.",
" - 1st task. Now energy = 17 - 1 = 16.",
" - 4th task. Now energy = 16 - 4 = 12.",
" - 6th task. Now energy = 12 - 6 = 6.",
""
],
"constraints": [
"actuali is the actual amount of energy you spend to finish the ith task. minimumi is the minimum amount of energy you require to begin the ith task. 1 <= tasks. length <= 1051 <= actual​i <= minimumi <= 104"
]
},
{
"id": "700",
"title": "Search in a Binary Search Tree",
"question": "You are given the root of a binary search tree (BST) and an integer val.\nFind the node in the BST that the node's value equals val and return the subtree rooted with that node.\n If such a node does not exist, return null.",
"examples": [
"Input: root = [4,2,7,1,3], val = 2",
"Output: [2,1,3]",
"Input: root = [4,2,7,1,3], val = 5",
"Output: []",
""
],
"constraints": [
"The number of nodes in the tree is in the range [1",
" 5000]. 1 <= Node. val <= 107root is a binary search tree. 1 <= val <= 107"
]
},
{
"id": "1671",
"title": "Minimum Number of Removals to Make Mountain Array",
"question": "You may recall that an array arr is a mountain array if and only if:Given an integer array nums​​​, return the minimum number of elements to remove to make nums​​​ a mountain array.",
"examples": [
"Input: nums = [1,3,1]",
"Output: 0",
"Explanation: The array itself is a mountain array so we do not need to remove any elements.",
"Input: nums = [2,1,1,5,6,2,3,1]",
"Output: 3",
"Explanation: One solution is to remove the elements at indices 0, 1, and 5, making the array nums = [1,5,6,3,1].",
"Input: nums = [4,3,2,1,1,2,3,1]",
"Output: 4",
"Input: nums = [1,2,3,4,4,3,2,1]",
"Output: 1",
""
],
"constraints": [
"arr. length >= 3There exists some index i (0-indexed) with 0 < i < arr. length - 1 such that:\n\t\narr[0] < arr[1] < ... < arr[i - 1] < arr[i]\narr[i] > arr[i + 1] > ... > arr[arr. length - 1]\n\narr[0] < arr[1] < ... < arr[i - 1] < arr[i]arr[i] > arr[i + 1] > ... > arr[arr. length - 1]3 <= nums. length <= 10001 <= nums[i] <= 109It is guaranteed that you can make a mountain array out of nums."
]
},
{
"id": "1675",
"title": "Minimize Deviation in Array",
"question": "You are given an array nums of n positive integers.\nYou can perform two types of operations on any element of the array any number of times:The deviation of the array is the maximum difference between any two elements in the array.\nReturn the minimum deviation the array can have after performing some number of operations.",
"examples": [
"Input: nums = [1,2,3,4]",
"Output: 1",
"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.",
"Input: nums = [4,1,5,20,3]",
"Output: 3",
"Explanation: You can transform the array after two operations to [4,2,5,5,3], then the deviation will be 5 - 2 = 3.",
"Input: nums = [2,10,8]",
"Output: 3",
""
],
"constraints": [
"If the element is even",
" divide it by 2.\n\n\t\nFor 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\nFor 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]. If the element is odd",
" multiply it by 2.\n\t\nFor 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\nFor 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 == nums. length2 <= n <= 1051 <= nums[i] <= 109"
]
},
{
"id": "1681",
"title": "Minimum Incompatibility",
"question": "You are given an integer array nums​​​ and an integer k.\n 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.\nA subset's incompatibility is the difference between the maximum and minimum elements in that array.\nReturn the minimum possible sum of incompatibilities of the k subsets after distributing the array optimally, or return -1 if it is not possible.\nA subset is a group integers that appear in the array with no particular order.",
"examples": [
"Input: nums = [1,2,1,4], k = 2",
"Output: 4",
"Explanation: The optimal distribution of subsets is [1,2] and [1,4].",
"The incompatibility is (2-1) + (4-1) = 4.",
"Note that [1,1] and [2,4] would result in a smaller sum, but the first subset contains 2 equal elements. Input: nums = [6,3,8,1,3,1,2,2], k = 4",
"Output: 6",
"Explanation: The optimal distribution of subsets is [1,2], [2,3], [6,8], and [1,3].",
"The incompatibility is (2-1) + (3-2) + (8-6) + (3-1) = 6.",
"Input: nums = [5,3,3,6,3,3], k = 3",
"Output: -1",
"Explanation: It is impossible to distribute nums into 3 subsets where no two elements are equal in the same subset.",
""
],
"constraints": [
"1 <= k <= nums. length <= 16nums. length is divisible by k1 <= nums[i] <= nums. length"
]
},
{
"id": "1687",
"title": "Delivering Boxes from Storage to Ports",
"question": "You have the task of delivering some boxes from storage to their ports using only one ship.\n However, this ship has a limit on the number of boxes and the total weight that it can carry.\nYou are given an array boxes, where boxes[i] = [ports​​i​, weighti], and three integers portsCount, maxBoxes, and maxWeight.\nThe boxes need to be delivered in the order they are given.\n The ship will follow these steps:The ship must end at storage after all the boxes have been delivered.\nReturn the minimum number of trips the ship needs to make to deliver all boxes to their respective ports.",
"examples": [
"Input: boxes = [[1,1],[2,1],[1,1]], portsCount = 2, maxBoxes = 3, maxWeight = 3",
"Output: 4",
"Explanation: The optimal strategy is as follows: ",
"- 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.",
"So the total number of trips is 4.",
"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).",
"Input: boxes = [[1,2],[3,3],[3,1],[3,1],[2,4]], portsCount = 3, maxBoxes = 3, maxWeight = 6",
"Output: 6",
"Explanation: The optimal strategy is as follows: ",
"- The ship takes the first box, goes to port 1, then returns to storage. 2 trips.",
"- The ship takes the second, third and fourth boxes, goes to port 3, then returns to storage. 2 trips.",
"- The ship takes the fifth box, goes to port 3, then returns to storage. 2 trips.",
"So the total number of trips is 2 + 2 + 2 = 6.",
"Input: boxes = [[1,4],[1,2],[2,1],[2,1],[3,2],[3,4]], portsCount = 3, maxBoxes = 6, maxWeight = 7",
"Output: 6",
"Explanation: The optimal strategy is as follows:",
"- The ship takes the first and second boxes, goes to port 1, then returns to storage. 2 trips.",
"- The ship takes the third and fourth boxes, goes to port 2, then returns to storage. 2 trips.",
"- The ship takes the fifth and sixth boxes, goes to port 3, then returns to storage. 2 trips.",
"So the total number of trips is 2 + 2 + 2 = 6.",
"Input: boxes = [[2,4],[2,5],[3,1],[3,2],[3,7],[3,1],[4,4],[1,3],[5,2]], portsCount = 5, maxBoxes = 5, maxWeight = 7",
"Output: 14",
"Explanation: The optimal strategy is as follows:",
"- The ship takes the first box, goes to port 2, then storage. 2 trips.",
"- The ship takes the second box, goes to port 2, then storage. 2 trips.",
"- The ship takes the third and fourth boxes, goes to port 3, then storage. 2 trips.",
"- The ship takes the fifth box, goes to port 3, then storage. 2 trips.",
"- The ship takes the sixth and seventh boxes, goes to port 3, then port 4, then storage. 3 trips. ",
"- The ship takes the eighth and ninth boxes, goes to port 1, then port 5, then storage. 3 trips.",
"So the total number of trips is 2 + 2 + 2 + 2 + 3 + 3 = 14.",
""
],
"constraints": [
"ports​​i is the port where you need to deliver the ith box and weightsi is the weight of the ith box. portsCount is the number of ports. maxBoxes and maxWeight are the respective box and weight limits of the ship. The ship will take some number of boxes from the boxes queue",
" not violating the maxBoxes and maxWeight constraints. 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. The ship then makes a return trip to storage to take more boxes from the queue. 1 <= boxes. length <= 1051 <= portsCount",
" maxBoxes",
" maxWeight <= 1051 <= ports​​i <= portsCount1 <= weightsi <= maxWeight"
]
},
{
"id": "1691",
"title": "Maximum Height by Stacking Cuboids",
"question": "Given n cuboids where the dimensions of the ith cuboid is cuboids[i] = [widthi, lengthi, heighti] (0-indexed).\n Choose a subset of cuboids and place them on each other.\nYou can place cuboid i on cuboid j if widthi <= widthj and lengthi <= lengthj and heighti <= heightj.\n You can rearrange any cuboid's dimensions by rotating it to put it on another cuboid.\nReturn the maximum height of the stacked cuboids.",
"examples": [
"Input: cuboids = [[50,45,20],[95,37,53],[45,23,12]]",
"Output: 190",
"Explanation:",
"Cuboid 1 is placed on the bottom with the 53x37 side facing down with height 95.",
"Cuboid 0 is placed next with the 45x20 side facing down with height 50.",
"Cuboid 2 is placed next with the 23x12 side facing down with height 45.",
"The total height is 95 + 50 + 45 = 190.",
"Input: cuboids = [[38,25,45],[76,35,3]]",
"Output: 76",
"Explanation:",
"You can't place any of the cuboids on the other.",
"We choose cuboid 1 and rotate it so that the 35x3 side is facing down and its height is 76.",
"Input: cuboids = [[7,11,17],[7,17,11],[11,7,17],[11,17,7],[17,7,11],[17,11,7]]",
"Output: 102",
"Explanation:",
"After rearranging the cuboids, you can see that all cuboids have the same dimension.",
"You can place the 11x7 side down on all cuboids so their heights are 17.",
"The maximum height of stacked cuboids is 6 * 17 = 102.",
""
],
"constraints": [
"n == cuboids. length1 <= n <= 1001 <= widthi",
" lengthi",
" heighti <= 100"
]
},
{
"id": "1697",
"title": "Checking Existence of Edge Length Limited Paths",
"question": "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.\n Note that there may be multiple edges between two nodes.\nGiven 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 .\nReturn a boolean array answer, where answer.\nlength == queries.\nlength and the jth value of answer is true if there is a path for queries[j] is true, and false otherwise.",
"examples": [
"Input: n = 3, edgeList = [[0,1,2],[1,2,4],[2,0,8],[1,0,16]], queries = [[0,1,2],[0,2,5]]",
"Output: [false,true]",
"Explanation: The above figure shows the given graph. Note that there are two overlapping edges between 0 and 1 with distances 2 and 16.",
"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.",
"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.",
"Input: n = 5, edgeList = [[0,1,10],[1,2,5],[2,3,9],[3,4,13]], queries = [[0,4,14],[1,4,13]]",
"Output: [true,false]",
"Exaplanation: The above figure shows the given graph.",
""
],
"constraints": [
"2 <= n <= 1051 <= edgeList. length",
" queries. length <= 105edgeList[i]. length == 3queries[j]. length == 30 <= ui",
" vi",
" pj",
" qj <= n - 1ui != vipj != qj1 <= disi",
" limitj <= 109There may be multiple edges between two nodes."
]
},
{
"id": "1703",
"title": "Minimum Adjacent Swaps for K Consecutive Ones",
"question": "You are given an integer array, nums, and an integer k.\n nums comprises of only 0's and 1's.\n In one move, you can choose two adjacent indices and swap their values.\nReturn the minimum number of moves required so that nums has k consecutive 1's.",
"examples": [
"Input: nums = [1,0,0,1,0,1], k = 2",
"Output: 1",
"Explanation: In 1 move, nums could be [1,0,0,0,1,1] and have 2 consecutive 1's.",
"Input: nums = [1,0,0,0,0,0,1,1], k = 3",
"Output: 5",
"Explanation: In 5 moves, the leftmost 1 can be shifted right until nums = [0,0,0,0,0,1,1,1].",
"Input: nums = [1,1,0,1], k = 2",
"Output: 0",
"Explanation: nums already has 2 consecutive 1's.",
""
],
"constraints": [
"1 <= nums. length <= 105nums[i] is 0 or 1. 1 <= k <= sum(nums)"
]
},
{
"id": "1707",
"title": "Maximum XOR With an Element From Array",
"question": "You are given an array nums consisting of non-negative integers.\n You are also given a queries array, where queries[i] = [xi, mi].\nThe answer to the ith query is the maximum bitwise XOR value of xi and any element of nums that does not exceed mi.\n In other words, the answer is max(nums[j] XOR xi) for all j such that nums[j] <= mi.\n If all elements in nums are larger than mi, then the answer is -1.\nReturn an integer array answer where answer.\nlength == queries.\nlength and answer[i] is the answer to the ith query.",
"examples": [
"Input: nums = [0,1,2,3,4], queries = [[3,1],[1,3],[5,6]]",
"Output: [3,3,7]",
"Explanation:",
"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.",
"2) 1 XOR 2 = 3.",
"3) 5 XOR 2 = 7.",
"Input: nums = [5,2,4,6,6,3], queries = [[12,4],[8,1],[6,3]]",
"Output: [15,-1,5]",
""
],
"constraints": [
"1 <= nums. length",
" queries. length <= 105queries[i]. length == 20 <= nums[j]",
" xi",
" mi <= 109"
]
},
{
"id": "1713",
"title": "Minimum Operations to Make a Subsequence",
"question": "You are given an array target that consists of distinct integers and another integer array arr that can have duplicates.\nIn one operation, you can insert any integer at any position in arr.\n For example, if arr = [1,4,1,2], you can add 3 in the middle and make it [1,4,3,1,2].\n Note that you can insert the integer at the very beginning or end of the array.\nReturn the minimum number of operations needed to make target a subsequence of arr.\nA 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 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.",
"examples": [
"Input: target = [5,1,3], arr = [9,4,2,3,4]",
"Output: 2",
"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.",
"Input: target = [6,4,8,1,3,2], arr = [4,7,6,2,3,8,6,1]",
"Output: 3",
""
],
"constraints": [
"1 <= target. length",
" arr. length <= 1051 <= target[i]",
" arr[i] <= 109target contains no duplicates."
]
},
{
"id": "1719",
"title": "Number Of Ways To Reconstruct A Tree",
"question": "You are given an array pairs, where pairs[i] = [xi, yi], and:Let ways be the number of rooted trees that satisfy the following conditions:Two ways are considered to be different if there is at least one node that has different parents in both ways.\nReturn:A rooted tree is a tree that has a single root node, and all edges are oriented to be outgoing from the root.\nAn ancestor of a node is any node on the path from the root to that node (excluding the node itself).\n The root has no ancestors.",
"examples": [
"Input: pairs = [[1,2],[2,3]]",
"Output: 1",
"Explanation: There is exactly one valid rooted tree, which is shown in the above figure.",
"Input: pairs = [[1,2],[2,3],[1,3]]",
"Output: 2",
"Explanation: There are multiple valid rooted trees. Three of them are shown in the above figures.",
"Input: pairs = [[1,2],[2,3],[2,4],[1,5]]",
"Output: 0",
"Explanation: There are no valid rooted trees."
],
"constraints": [
"There are no duplicates. xi < yiThe tree consists of nodes whose values appeared in pairs. A pair [xi",
" yi] exists in pairs if and only if xi is an ancestor of yi or yi is an ancestor of xi. Note: the tree does not have to be a binary tree. 0 if ways == 01 if ways == 12 if ways > 11 <= pairs. length <= 1051 <= xi < yi <= 500The elements in pairs are unique."
]
},
{
"id": "703",
"title": "Kth Largest Element in a Stream",
"question": "Design a class to find the kth largest element in a stream.\n Note that it is the kth largest element in the sorted order, not the kth distinct element.\nImplement KthLargest class:",
"examples": [
"Input",
"[\"KthLargest\", \"add\", \"add\", \"add\", \"add\", \"add\"]",
"[[3, [4, 5, 8, 2]], [3], [5], [10], [9], [4]]",
"Output",
"[null, 4, 5, 5, 8, 8]",
"",
"Explanation",
"KthLargest kthLargest = new KthLargest(3, [4, 5, 8, 2]);",
"kthLargest. add(3); // return 4",
"kthLargest. add(5); // return 5",
"kthLargest. add(10); // return 5",
"kthLargest. add(9); // return 8",
"kthLargest. add(4); // return 8",
""
],
"constraints": [
"KthLargest(int k",
" int[] nums) Initializes the object with the integer k and the stream of integers nums. int add(int val) Appends the integer val to the stream and returns the element representing the kth largest element in the stream. 1 <= k <= 1040 <= nums. length <= 104-104 <= nums[i] <= 104-104 <= val <= 104At most 104 calls will be made to add. It is guaranteed that there will be at least k elements in the array when you search for the kth element."
]
},
{
"id": "1723",
"title": "Find Minimum Time to Finish All Jobs",
"question": "You are given an integer array jobs, where jobs[i] is the amount of time it takes to complete the ith job.\nThere are k workers that you can assign jobs to.\n Each job should be assigned to exactly one worker.\n The working time of a worker is the sum of the time it takes to complete all jobs assigned to them.\n Your goal is to devise an optimal assignment such that the maximum working time of any worker is minimized.\nReturn the minimum possible maximum working time of any assignment.",
"examples": [
"Input: jobs = [3,2,3], k = 3",
"Output: 3",
"Explanation: By assigning each person one job, the maximum time is 3.",
"Input: jobs = [1,2,4,7,8], k = 2",
"Output: 11",
"Explanation: Assign the jobs the following way:",
"Worker 1: 1, 2, 8 (working time = 1 + 2 + 8 = 11)",
"Worker 2: 4, 7 (working time = 4 + 7 = 11)",
"The maximum working time is 11."
],
"constraints": [
"1 <= k <= jobs. length <= 121 <= jobs[i] <= 107"
]
},
{
"id": "1728",
"title": "Cat and Mouse II",
"question": "A game is played by a cat and a mouse named Cat and Mouse.\nThe environment is represented by a grid of size rows x cols, where each element is a wall, floor, player (Cat, Mouse), or food.\nMouse and Cat play according to the following rules:The game can end in 4 ways: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.",
"examples": [
"Input: grid = [\"####F\",\"#C...\",\"M....\"], catJump = 1, mouseJump = 2",
"Output: true",
"Explanation: Cat cannot catch Mouse on its turn nor can it get the food before Mouse.",
"Input: grid = [\"M. C... F\"], catJump = 1, mouseJump = 4",
"Output: true",
"Input: grid = [\"M. C... F\"], catJump = 1, mouseJump = 3",
"Output: false",
"Input: grid = [\"C...#\",\"...#F\",\"....#\",\"M....\"], catJump = 2, mouseJump = 5",
"Output: false",
"Input: grid = [\". M...\",\"..#..\",\"#..#.\",\"C#.#.\",\"...#F\"], catJump = 3, mouseJump = 1",
"Output: true",
""
],
"constraints": [
"Players are represented by the characters 'C'(Cat)",
"'M'(Mouse). Floors are represented by the character '.' and can be walked on. Walls are represented by the character '#' and cannot be walked on. Food is represented by the character 'F' and can be walked on. There is only one of each character 'C'",
" 'M'",
" and 'F' in grid. Mouse moves first",
" then they take turns to move. 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. 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. Staying in the same position is allowed. Mouse can jump over Cat. If Cat occupies the same position as Mouse",
" Cat wins. If Cat reaches the food first",
" Cat wins. If Mouse reaches the food first",
" Mouse wins. If Mouse cannot get to the food within 1000 turns",
" Cat wins. rows == grid. lengthcols = grid[i]. length1 <= rows",
" cols <= 8grid[i][j] consist only of characters 'C'",
" 'M'",
" 'F'",
" '.'",
" and '#'. There is only one of each character 'C'",
" 'M'",
" and 'F' in grid. 1 <= catJump",
" mouseJump <= 8"
]
},
{
"id": "1735",
"title": "Count Ways to Make Array With Product",
"question": "You are given a 2D integer array, queries.\n For each queries[i], where queries[i] = [ni, ki], find the number of different ways you can place positive integers into an array of size ni such that the product of the integers is ki.\n As the number of ways may be too large, the answer to the ith query is the number of ways modulo 109 + 7.\nReturn an integer array answer where answer.\nlength == queries.\nlength, and answer[i] is the answer to the ith query.",
"examples": [
"Input: queries = [[2,6],[5,1],[73,660]]",
"Output: [4,1,50734910]",
"Explanation: Each query is independent.",
"[2,6]: There are 4 ways to fill an array of size 2 that multiply to 6: [1,6], [2,3], [3,2], [6,1].",
"[5,1]: There is 1 way to fill an array of size 5 that multiply to 1: [1,1,1,1,1].",
"[73,660]: There are 1050734917 ways to fill an array of size 73 that multiply to 660. 1050734917 modulo 109 + 7 = 50734910.",
"Input: queries = [[1,1],[2,2],[3,3],[4,4],[5,5]]",
"Output: [1,2,3,10,5]",
""
],
"constraints": [
"1 <= queries. length <= 104 1 <= ni",
" ki <= 104"
]
},
{
"id": "1739",
"title": "Building Boxes",
"question": "You have a cubic storeroom where the width, length, and height of the room are all equal to n units.\n You are asked to place n boxes in this room where each box is a cube of unit side length.\n There are however some rules to placing the boxes:Given an integer n, return the minimum possible number of boxes touching the floor.",
"examples": [
"Input: n = 3",
"Output: 3",
"Explanation: The figure above is for the placement of the three boxes.",
"These boxes are placed in the corner of the room, where the corner is on the left side.",
"Input: n = 4",
"Output: 3",
"Explanation: The figure above is for the placement of the four boxes.",
"These boxes are placed in the corner of the room, where the corner is on the left side.",
"Input: n = 10",
"Output: 6",
"Explanation: The figure above is for the placement of the ten boxes.",
"These boxes are placed in the corner of the room, where the corner is on the back side."
],
"constraints": [
"You can place the boxes anywhere on the floor. 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. 1 <= n <= 109"
]
},
{
"id": "1745",
"title": "Palindrome Partitioning IV",
"question": "Given a string s, return true if it is possible to split the string s into three non-empty palindromic substrings.\n Otherwise, return false.\n​​​​​A string is said to be palindrome if it the same string when reversed.",
"examples": [
"Input: s = \"abcbdd\"",
"Output: true",
"Explanation: \"abcbdd\" = \"a\" + \"bcb\" + \"dd\", and all three substrings are palindromes.",
"Input: s = \"bcbddxy\"",
"Output: false",
"Explanation: s cannot be split into 3 palindromes.",
""
],
"constraints": [
"3 <= s. length <= 2000s​​​​​​ consists only of lowercase English letters."
]
},
{
"id": "1751",
"title": "Maximum Number of Events That Can Be Attended II",
"question": "You are given an array of events where events[i] = [startDayi, endDayi, valuei].\n The ith event starts at startDayi and ends at endDayi, and if you attend this event, you will receive a value of valuei.\n You are also given an integer k which represents the maximum number of events you can attend.\nYou can only attend one event at a time.\n If you choose to attend an event, you must attend the entire event.\n 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.\nReturn the maximum sum of values that you can receive by attending events.",
"examples": [
"Input: events = [[1,2,4],[3,4,3],[2,3,1]], k = 2",
"Output: 7",
"Explanation: Choose the green events, 0 and 1 (0-indexed) for a total value of 4 + 3 = 7. Input: events = [[1,2,4],[3,4,3],[2,3,10]], k = 2",
"Output: 10",
"Explanation: Choose event 2 for a total value of 10.",
"Notice that you cannot attend any other event as they overlap, and that you do not have to attend k events. Input: events = [[1,1,1],[2,2,2],[3,3,3],[4,4,4]], k = 3",
"Output: 9",
"Explanation: Although the events do not overlap, you can only attend 3 events. Pick the highest valued three."
],
"constraints": [
"1 <= k <= events. length1 <= k * events. length <= 1061 <= startDayi <= endDayi <= 1091 <= valuei <= 106"
]
},
{
"id": "1755",
"title": "Closest Subsequence Sum",
"question": "You are given an integer array nums and an integer goal.\nYou want to choose a subsequence of nums such that the sum of its elements is the closest possible to goal.\n That is, if the sum of the subsequence's elements is sum, then you want to minimize the absolute difference abs(sum - goal).\nReturn the minimum possible value of abs(sum - goal).\nNote that a subsequence of an array is an array formed by removing some elements (possibly all or none) of the original array.",
"examples": [
"Input: nums = [5,-7,3,5], goal = 6",
"Output: 0",
"Explanation: Choose the whole array as a subsequence, with a sum of 6.",
"This is equal to the goal, so the absolute difference is 0.",
"Input: nums = [7,-9,15,-2], goal = -5",
"Output: 1",
"Explanation: Choose the subsequence [7,-9,-2], with a sum of -4.",
"The absolute difference is abs(-4 - (-5)) = abs(1) = 1, which is the minimum.",
"Input: nums = [1,2,3], goal = -7",
"Output: 7",
""
],
"constraints": [
"1 <= nums. length <= 40-107 <= nums[i] <= 107-109 <= goal <= 109"
]
},
{
"id": "1761",
"title": "Minimum Degree of a Connected Trio in a Graph",
"question": "You are given an undirected graph.\n 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.\nA connected trio is a set of three nodes where there is an edge between every pair of them.\nThe degree of a connected trio is the number of edges where one endpoint is in the trio, and the other is not.\nReturn the minimum degree of a connected trio in the graph, or -1 if the graph has no connected trios.",
"examples": [
"Input: n = 6, edges = [[1,2],[1,3],[3,2],[4,1],[5,2],[3,6]]",
"Output: 3",
"Explanation: There is exactly one trio, which is [1,2,3]. The edges that form its degree are bolded in the figure above.",
"Input: n = 7, edges = [[1,3],[4,1],[4,3],[2,5],[5,6],[6,7],[7,5],[2,6]]",
"Output: 0",
"Explanation: There are exactly three trios:",
"1) [1,4,3] with degree 0.",
"2) [2,5,6] with degree 2.",
"3) [5,6,7] with degree 2.",
""
],
"constraints": [
"2 <= n <= 400edges[i]. length == 21 <= edges. length <= n * (n-1) / 21 <= ui",
" vi <= nui != viThere are no repeated edges."
]
},
{
"id": "1766",
"title": "Tree of Coprimes",
"question": "There is a tree (i.\ne.\n, a connected, undirected graph that has no cycles) consisting of n nodes numbered from 0 to n - 1 and exactly n - 1 edges.\n Each node has a value associated with it, and the root of the tree is node 0.\nTo represent this tree, you are given an integer array nums and a 2D array edges.\n 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.\nTwo values x and y are coprime if gcd(x, y) == 1 where gcd(x, y) is the greatest common divisor of x and y.\nAn ancestor of a node i is any other node on the shortest path from node i to the root.\n A node is not considered an ancestor of itself.\nReturn 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.",
"examples": [
"Input: nums = [2,3,3,2], edges = [[0,1],[1,2],[1,3]]",
"Output: [-1,0,0,1]",
"Explanation: In the above figure, each node's value is in parentheses.",
"- Node 0 has no coprime ancestors.",
"- Node 1 has only one ancestor, node 0. Their values are coprime (gcd(2,3) == 1).",
"- Node 2 has two ancestors, nodes 1 and 0. Node 1's value is not coprime (gcd(3,3) == 3), but node 0's",
" value is (gcd(2,3) == 1), so node 0 is the closest valid ancestor.",
"- Node 3 has two ancestors, nodes 1 and 0. It is coprime with node 1 (gcd(3,2) == 1), so node 1 is its",
" closest valid ancestor.",
"Input: nums = [5,6,10,2,3,6,15], edges = [[0,1],[0,2],[1,3],[1,4],[2,5],[2,6]]",
"Output: [-1,0,-1,0,0,0,-1]",
""
],
"constraints": [
"nums. length == n1 <= nums[i] <= 501 <= n <= 105edges. length == n - 1edges[j]. length == 20 <= uj",
" vj < nuj != vj"
]
},
{
"id": "1771",
"title": "Maximize Palindrome Length From Subsequences",
"question": "You are given two strings, word1 and word2.\n You want to construct a string in the following manner:Return the length of the longest palindrome that can be constructed in the described manner.\n If no palindromes can be constructed, return 0.\nA 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.\nA palindrome is a string that reads the same forward as well as backward.",
"examples": [
"Input: word1 = \"cacb\", word2 = \"cbba\"",
"Output: 5",
"Explanation: Choose \"ab\" from word1 and \"cba\" from word2 to make \"abcba\", which is a palindrome. Input: word1 = \"ab\", word2 = \"ab\"",
"Output: 3",
"Explanation: Choose \"ab\" from word1 and \"a\" from word2 to make \"aba\", which is a palindrome. Input: word1 = \"aa\", word2 = \"bb\"",
"Output: 0",
"Explanation: You cannot construct a palindrome from the described method, so return 0."
],
"constraints": [
"Choose some non-empty subsequence subsequence1 from word1. Choose some non-empty subsequence subsequence2 from word2. Concatenate the subsequences: subsequence1 + subsequence2",
" to make the string. 1 <= word1. length",
" word2. length <= 1000word1 and word2 consist of lowercase English letters."
]
},
{
"id": "704",
"title": "Binary Search",
"question": "Given an array of integers nums which is sorted in ascending order, and an integer target, write a function to search target in nums.\n If target exists, then return its index.\n Otherwise, return -1.\nYou must write an algorithm with O(log n) runtime complexity.",
"examples": [
"Input: nums = [-1,0,3,5,9,12], target = 9",
"Output: 4",
"Explanation: 9 exists in nums and its index is 4",
"Input: nums = [-1,0,3,5,9,12], target = 2",
"Output: -1",
"Explanation: 2 does not exist in nums so return -1",
""
],
"constraints": [
"1 <= nums. length <= 104-104 < nums[i]",
" target < 104All the integers in nums are unique. nums is sorted in ascending order."
]
},
{
"id": "1776",
"title": "Car Fleet II",
"question": "There are n cars traveling at different speeds in the same direction along a one-lane road.\n You are given an array cars of length n, where cars[i] = [positioni, speedi] represents:For simplicity, cars can be considered as points moving along the number line.\n Two cars collide when they occupy the same position.\n Once a car collides with another car, they unite and form a single car fleet.\n 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.\nReturn 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.\n Answers within 10-5 of the actual answers are accepted.",
"examples": [
"Input: cars = [[1,2],[2,1],[4,3],[7,2]]",
"Output: [1. 00000,-1. 00000,3. 00000,-1. 00000]",
"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.",
"Input: cars = [[3,4],[5,4],[6,3],[9,1]]",
"Output: [2. 00000,1. 00000,1. 50000,-1. 00000]",
""
],
"constraints": [
"positioni is the distance between the ith car and the beginning of the road in meters. It is guaranteed that positioni < positioni+1. speedi is the initial speed of the ith car in meters per second. 1 <= cars. length <= 1051 <= positioni",
" speedi <= 106positioni < positioni+1"
]
},
{
"id": "1782",
"title": "Count Pairs Of Nodes",
"question": "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.\n You are also given an integer array queries.\nLet incident(a, b) be defined as the number of edges that are connected to either node a or b.\nThe answer to the jth query is the number of pairs of nodes (a, b) that satisfy both of the following conditions:Return an array answers such that answers.\nlength == queries.\nlength and answers[j] is the answer of the jth query.\nNote that there can be multiple edges between the same two nodes.",
"examples": [
"Input: n = 4, edges = [[1,2],[2,4],[1,3],[2,3],[2,1]], queries = [2,3]",
"Output: [6,5]",
"Explanation: The calculations for incident(a, b) are shown in the table above.",
"The answers for each of the queries are as follows:",
"- answers[0] = 6. All the pairs have an incident(a, b) value greater than 2.",
"- answers[1] = 5. All the pairs except (3, 4) have an incident(a, b) value greater than 3.",
"Input: 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]",
"Output: [10,10,9,8,6]",
""
],
"constraints": [
"a < bincident(a",
" b) > queries[j]2 <= n <= 2 * 1041 <= edges. length <= 1051 <= ui",
" vi <= nui != vi1 <= queries. length <= 200 <= queries[j] < edges. length"
]
},
{
"id": "1787",
"title": "Make the XOR of All Segments Equal to Zero",
"question": "You are given an array nums​​​ and an integer k​​​​​.\n 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 .\n.\n.\n XOR nums[right].\nReturn the minimum number of elements to change in the array such that the XOR of all segments of size k​​​​​​ is equal to zero.",
"examples": [
"Input: nums = [1,2,0,3,0], k = 1",
"Output: 3",
"Explanation: Modify the array from [1,2,0,3,0] to from [0,0,0,0,0].",
"Input: nums = [3,4,5,2,1,7,3,4,7], k = 3",
"Output: 3",
"Explanation: Modify the array from [3,4,5,2,1,7,3,4,7] to [3,4,7,3,4,7,3,4,7].",
"Input: nums = [1,2,4,1,2,5,1,2,6], k = 3",
"Output: 3",
"Explanation: Modify the array from [1,2,4,1,2,5,1,2,6] to [1,2,3,1,2,3,1,2,3]."
],
"constraints": [
"1 <= k <= nums. length <= 2000​​​​​​0 <= nums[i] < 210"
]
},
{
"id": "1793",
"title": "Maximum Score of a Good Subarray",
"question": "You are given an array of integers nums (0-indexed) and an integer k.\nThe score of a subarray (i, j) is defined as min(nums[i], nums[i+1], .\n.\n.\n, nums[j]) * (j - i + 1).\n A good subarray is a subarray where i <= k <= j.\nReturn the maximum possible score of a good subarray.",
"examples": [
"Input: nums = [1,4,3,7,4,5], k = 3",
"Output: 15",
"Explanation: The optimal subarray is (1, 5) with a score of min(4,3,7,4,5) * (5-1+1) = 3 * 5 = 15. ",
"Input: nums = [5,5,4,5,4,1,1,1], k = 0",
"Output: 20",
"Explanation: The optimal subarray is (0, 4) with a score of min(5,5,4,5,4) * (4-0+1) = 4 * 5 = 20.",
""
],
"constraints": [
"1 <= nums. length <= 1051 <= nums[i] <= 2 * 1040 <= k < nums. length"
]
},
{
"id": "1799",
"title": "Maximize Score After N Operations",
"question": "You are given nums, an array of positive integers of size 2 * n.\n You must perform n operations on this array.\nIn the ith operation (1-indexed), you will:Return the maximum score you can receive after performing n operations.\nThe function gcd(x, y) is the greatest common divisor of x and y.",
"examples": [
"Input: nums = [1,2]",
"Output: 1",
"Explanation: The optimal choice of operations is:",
"(1 * gcd(1, 2)) = 1",
"Input: nums = [3,4,6,8]",
"Output: 11",
"Explanation: The optimal choice of operations is:",
"(1 * gcd(3, 6)) + (2 * gcd(4, 8)) = 3 + 8 = 11",
"Input: nums = [1,2,3,4,5,6]",
"Output: 14",
"Explanation: The optimal choice of operations is:",
"(1 * gcd(1, 5)) + (2 * gcd(2, 4)) + (3 * gcd(3, 6)) = 1 + 4 + 9 = 14",
""
],
"constraints": [
"Choose two elements",
" x and y. Receive a score of i * gcd(x",
" y). Remove x and y from nums. 1 <= n <= 7nums. length == 2 * n1 <= nums[i] <= 106"
]
},
{
"id": "1803",
"title": "Count Pairs With XOR in a Range",
"question": "Given a (0-indexed) integer array nums and two integers low and high, return the number of nice pairs.\nA nice pair is a pair (i, j) where 0 <= i < j < nums.\nlength and low <= (nums[i] XOR nums[j]) <= high.",
"examples": [
"Input: nums = [1,4,2,7], low = 2, high = 6",
"Output: 6",
"Explanation: All nice pairs (i, j) are as follows:",
" - (0, 1): nums[0] XOR nums[1] = 5 ",
" - (0, 2): nums[0] XOR nums[2] = 3",
" - (0, 3): nums[0] XOR nums[3] = 6",
" - (1, 2): nums[1] XOR nums[2] = 6",
" - (1, 3): nums[1] XOR nums[3] = 3",
" - (2, 3): nums[2] XOR nums[3] = 5",
"Input: nums = [9,8,4,2,1], low = 5, high = 14",
"Output: 8",
"Explanation: All nice pairs (i, j) are as follows:",
"​​​​​ - (0, 2): nums[0] XOR nums[2] = 13",
"  - (0, 3): nums[0] XOR nums[3] = 11",
"  - (0, 4): nums[0] XOR nums[4] = 8",
"  - (1, 2): nums[1] XOR nums[2] = 12",
"  - (1, 3): nums[1] XOR nums[3] = 10",
"  - (1, 4): nums[1] XOR nums[4] = 9",
"  - (2, 3): nums[2] XOR nums[3] = 6",
"  - (2, 4): nums[2] XOR nums[4] = 5"
],
"constraints": [
"1 <= nums. length <= 2 * 1041 <= nums[i] <= 2 * 1041 <= low <= high <= 2 * 104"
]
},
{
"id": "1808",
"title": "Maximize Number of Nice Divisors",
"question": "You are given a positive integer primeFactors.\n You are asked to construct a positive integer n that satisfies the following conditions:Return the number of nice divisors of n.\n Since that number can be too large, return it modulo 109 + 7.\nNote that a prime number is a natural number greater than 1 that is not a product of two smaller natural numbers.\n The prime factors of a number n is a list of prime numbers such that their product equals n.",
"examples": [
"Input: primeFactors = 5",
"Output: 6",
"Explanation: 200 is a valid value of n.",
"It has 5 prime factors: [2,2,2,5,5], and it has 6 nice divisors: [10,20,40,50,100,200].",
"There is not other value of n that has at most 5 prime factors and more nice divisors.",
"Input: primeFactors = 8",
"Output: 18",
""
],
"constraints": [
"The number of prime factors of n (not necessarily distinct) is at most primeFactors. 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. 1 <= primeFactors <= 109"
]
},
{
"id": "1815",
"title": "Maximum Number of Groups Getting Fresh Donuts",
"question": "There is a donuts shop that bakes donuts in batches of batchSize.\n They have a rule where they must serve all of the donuts of a batch before serving any donuts of the next batch.\n 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.\n Each customer will get exactly one donut.\nWhen a group visits the shop, all customers of the group must be served before serving any of the following groups.\n A group will be happy if they all get fresh donuts.\n That is, the first customer of the group does not receive a donut that was left over from the previous group.\nYou can freely rearrange the ordering of the groups.\n Return the maximum possible number of happy groups after rearranging the groups.",
"examples": [
"Input: batchSize = 3, groups = [1,2,3,4,5,6]",
"Output: 4",
"Explanation: You can arrange the groups as [6,2,4,5,1,3]. Then the 1st, 2nd, 4th, and 6th groups will be happy.",
"Input: batchSize = 4, groups = [1,3,2,5,2,2,1,6]",
"Output: 4",
""
],
"constraints": [
"1 <= batchSize <= 91 <= groups. length <= 301 <= groups[i] <= 109"
]
},
{
"id": "1819",
"title": "Number of Different Subsequences GCDs",
"question": "You are given an array nums that consists of positive integers.\nThe GCD of a sequence of numbers is defined as the greatest integer that divides all the numbers in the sequence evenly.\nA subsequence of an array is a sequence that can be formed by removing some elements (possibly none) of the array.\nReturn the number of different GCDs among all non-empty subsequences of nums.",
"examples": [
"Input: nums = [6,10,3]",
"Output: 5",
"Explanation: The figure shows all the non-empty subsequences and their GCDs.",
"The different GCDs are 6, 10, 3, 2, and 1.",
"Input: nums = [5,15,40,5,6]",
"Output: 7",
""
],
"constraints": [
"For example",
" the GCD of the sequence [4",
"6",
"16] is 2. For example",
" [2",
"5",
"10] is a subsequence of [1",
"2",
"1",
"2",
"4",
"1",
"5",
"10]. 1 <= nums. length <= 1051 <= nums[i] <= 2 * 105"
]
},
{
"id": "1825",
"title": "Finding MK Average",
"question": "You are given two integers, m and k, and a stream of integers.\n You are tasked to implement a data structure that calculates the MKAverage for the stream.\nThe MKAverage can be calculated using these steps:Implement the MKAverage class:",
"examples": [
"Input",
"[\"MKAverage\", \"addElement\", \"addElement\", \"calculateMKAverage\", \"addElement\", \"calculateMKAverage\", \"addElement\", \"addElement\", \"addElement\", \"calculateMKAverage\"]",
"[[3, 1], [3], [1], [], [10], [], [5], [5], [5], []]",
"Output",
"[null, null, null, -1, null, 3, null, null, null, 5]",
"",
"Explanation",
"MKAverage obj = new MKAverage(3, 1); ",
"obj. addElement(3); // current elements are [3]",
"obj. addElement(1); // current elements are [3,1]",
"obj. calculateMKAverage(); // return -1, because m = 3 and only 2 elements exist.",
"obj. addElement(10); // current elements are [3,1,10]",
"obj. calculateMKAverage(); // The last 3 elements are [3,1,10].",
" // After removing smallest and largest 1 element the container will be [3].",
" // The average of [3] equals 3/1 = 3, return 3",
"obj. addElement(5); // current elements are [3,1,10,5]",
"obj. addElement(5); // current elements are [3,1,10,5,5]",
"obj. addElement(5); // current elements are [3,1,10,5,5,5]",
"obj. calculateMKAverage(); // The last 3 elements are [5,5,5].",
" // After removing smallest and largest 1 element the container will be [5].",
" // The average of [5] equals 5/1 = 5, return 5",
""
],
"constraints": [
"MKAverage(int m",
" int k) Initializes the MKAverage object with an empty stream and the two integers m and k. void addElement(int num) Inserts a new element num into the stream. int calculateMKAverage() Calculates and returns the MKAverage for the current stream rounded down to the nearest integer. 3 <= m <= 1051 <= k*2 < m1 <= num <= 105At most 105 calls will be made to addElement and calculateMKAverage."
]
},
{
"id": "705",
"title": "Design HashSet",
"question": "Design a HashSet without using any built-in hash table libraries.\nImplement MyHashSet class:",
"examples": [
"Input",
"[\"MyHashSet\", \"add\", \"add\", \"contains\", \"contains\", \"add\", \"contains\", \"remove\", \"contains\"]",
"[[], [1], [2], [1], [3], [2], [2], [2], [2]]",
"Output",
"[null, null, null, true, false, null, true, null, false]",
"",
"Explanation",
"MyHashSet myHashSet = new MyHashSet();",
"myHashSet. add(1); // set = [1]",
"myHashSet. add(2); // set = [1, 2]",
"myHashSet. contains(1); // return True",
"myHashSet. contains(3); // return False, (not found)",
"myHashSet. add(2); // set = [1, 2]",
"myHashSet. contains(2); // return True",
"myHashSet. remove(2); // set = [1]",
"myHashSet. contains(2); // return False, (already removed)"
],
"constraints": [
"void add(key) Inserts the value key into the HashSet. bool contains(key) Returns whether the value key exists in the HashSet or not. void remove(key) Removes the value key in the HashSet. If key does not exist in the HashSet",
" do nothing. 0 <= key <= 106At most 104 calls will be made to add",
" remove",
" and contains."
]
},
{
"id": "1830",
"title": "Minimum Number of Operations to Make String Sorted",
"question": "You are given a string s (0-indexed)​​​​​​.\n You are asked to perform the following operation on s​​​​​​ until you get a sorted string:Return the number of operations needed to make the string sorted.\n Since the answer can be too large, return it modulo 109 + 7.",
"examples": [
"Input: s = \"cba\"",
"Output: 5",
"Explanation: The simulation goes as follows:",
"Operation 1: i=2, j=2. Swap s[1] and s[2] to get s=\"cab\", then reverse the suffix starting at 2. Now, s=\"cab\".",
"Operation 2: i=1, j=2. Swap s[0] and s[2] to get s=\"bac\", then reverse the suffix starting at 1. Now, s=\"bca\".",
"Operation 3: i=2, j=2. Swap s[1] and s[2] to get s=\"bac\", then reverse the suffix starting at 2. Now, s=\"bac\".",
"Operation 4: i=1, j=1. Swap s[0] and s[1] to get s=\"abc\", then reverse the suffix starting at 1. Now, s=\"acb\".",
"Operation 5: i=2, j=2. Swap s[1] and s[2] to get s=\"abc\", then reverse the suffix starting at 2. Now, s=\"abc\".",
"Input: s = \"aabaa\"",
"Output: 2",
"Explanation: The simulation goes as follows:",
"Operation 1: i=3, j=4. Swap s[2] and s[4] to get s=\"aaaab\", then reverse the substring starting at 3. Now, s=\"aaaba\".",
"Operation 2: i=4, j=4. Swap s[3] and s[4] to get s=\"aaaab\", then reverse the substring starting at 4. Now, s=\"aaaab\".",
"Input: s = \"cdbea\"",
"Output: 63Input: s = \"leetcodeleetcodeleetcode\"",
"Output: 982157772",
""
],
"constraints": [
"1 <= s. length <= 3000s​​​​​​ consists only of lowercase English letters."
]
},
{
"id": "1835",
"title": "Find XOR Sum of All Pairs Bitwise AND",
"question": "The XOR sum of a list is the bitwise XOR of all its elements.\n If the list only contains one element, then its XOR sum will be equal to this element.\nYou are given two 0-indexed arrays arr1 and arr2 that consist only of non-negative integers.\nConsider the list containing the result of arr1[i] AND arr2[j] (bitwise AND) for every (i, j) pair where 0 <= i < arr1.\nlength and 0 <= j < arr2.\nlength.\nReturn the XOR sum of the aforementioned list.",
"examples": [
"Input: arr1 = [1,2,3], arr2 = [6,5]",
"Output: 0",
"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].",
"The XOR sum = 0 XOR 1 XOR 2 XOR 0 XOR 2 XOR 1 = 0.",
"Input: arr1 = [12], arr2 = [4]",
"Output: 4",
"Explanation: The list = [12 AND 4] = [4]. The XOR sum = 4.",
""
],
"constraints": [
"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. 1 <= arr1. length",
" arr2. length <= 1050 <= arr1[i]",
" arr2[j] <= 109"
]
},
{
"id": "1840",
"title": "Maximum Building Height",
"question": "You want to build n new buildings in a city.\n The new buildings will be built in a line and are labeled from 1 to n.\nHowever, there are city restrictions on the heights of the new buildings:Additionally, there are city restrictions on the maximum height of specific buildings.\n 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.\nIt is guaranteed that each building will appear at most once in restrictions, and building 1 will not be in restrictions.\nReturn the maximum possible height of the tallest building.",
"examples": [
"Input: n = 5, restrictions = [[2,1],[4,1]]",
"Output: 2",
"Explanation: The green area in the image indicates the maximum allowed height for each building.",
"We can build the buildings with heights [0,1,2,1,2], and the tallest building has a height of 2. Input: n = 6, restrictions = []",
"Output: 5",
"Explanation: The green area in the image indicates the maximum allowed height for each building.",
"We can build the buildings with heights [0,1,2,3,4,5], and the tallest building has a height of 5.",
"Input: n = 10, restrictions = [[5,3],[2,5],[7,4],[10,3]]",
"Output: 5",
"Explanation: The green area in the image indicates the maximum allowed height for each building.",
"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.",
""
],
"constraints": [
"The height of each building must be a non-negative integer. The height of the first building must be 0. The height difference between any two adjacent buildings cannot exceed 1. 2 <= n <= 1090 <= restrictions. length <= min(n - 1",
" 105)2 <= idi <= nidi is unique. 0 <= maxHeighti <= 109"
]
},
{
"id": "1847",
"title": "Closest Room",
"question": "There is a hotel with n rooms.\n 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.\n Each roomIdi is guaranteed to be unique.\nYou are also given k queries in a 2D array queries where queries[j] = [preferredj, minSizej].\n The answer to the jth query is the room number id of a room such that:If there is a tie in the absolute difference, then use the room with the smallest such id.\n If there is no such room, the answer is -1.\nReturn an array answer of length k where answer[j] contains the answer to the jth query.",
"examples": [
"Input: rooms = [[2,2],[1,2],[3,2]], queries = [[3,1],[3,3],[5,2]]",
"Output: [3,-1,3]",
"Explanation: The answers to the queries are as follows:",
"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.",
"Query = [3,3]: There are no rooms with a size of at least 3, so the answer is -1.",
"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. Input: rooms = [[1,4],[2,3],[3,5],[4,1],[5,2]], queries = [[2,3],[2,4],[2,5]]",
"Output: [2,1,3]",
"Explanation: The answers to the queries are as follows:",
"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.",
"Query = [2,4]: Room numbers 1 and 3 both have sizes of at least 4. The answer is 1 since it is smaller.",
"Query = [2,5]: Room number 3 is the only room with a size of at least 5. The answer is 3."
],
"constraints": [
"The room has a size of at least minSizej",
" andabs(id - preferredj) is minimized",
" where abs(x) is the absolute value of x. n == rooms. length1 <= n <= 105k == queries. length1 <= k <= 1041 <= roomIdi",
" preferredj <= 1071 <= sizei",
" minSizej <= 107 "
]
},
{
"id": "1851",
"title": "Minimum Interval to Include Each Query",
"question": "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).\n The size of an interval is defined as the number of integers it contains, or more formally righti - lefti + 1.\nYou are also given an integer array queries.\n The answer to the jth query is the size of the smallest interval i such that lefti <= queries[j] <= righti.\n If no such interval exists, the answer is -1.\nReturn an array containing the answers to the queries.",
"examples": [
"Input: intervals = [[1,4],[2,4],[3,6],[4,4]], queries = [2,3,4,5]",
"Output: [3,3,1,4]",
"Explanation: The queries are processed as follows:",
"- Query = 2: The interval [2,4] is the smallest interval containing 2. The answer is 4 - 2 + 1 = 3.",
"- Query = 3: The interval [2,4] is the smallest interval containing 3. The answer is 4 - 2 + 1 = 3.",
"- Query = 4: The interval [4,4] is the smallest interval containing 4. The answer is 4 - 4 + 1 = 1.",
"- Query = 5: The interval [3,6] is the smallest interval containing 5. The answer is 6 - 3 + 1 = 4.",
"Input: intervals = [[2,3],[2,5],[1,8],[20,25]], queries = [2,19,5,22]",
"Output: [2,-1,4,6]",
"Explanation: The queries are processed as follows:",
"- Query = 2: The interval [2,3] is the smallest interval containing 2. The answer is 3 - 2 + 1 = 2.",
"- Query = 19: None of the intervals contain 19. The answer is -1.",
"- Query = 5: The interval [2,5] is the smallest interval containing 5. The answer is 5 - 2 + 1 = 4.",
"- Query = 22: The interval [20,25] is the smallest interval containing 22. The answer is 25 - 20 + 1 = 6.",
""
],
"constraints": [
"1 <= intervals. length <= 1051 <= queries. length <= 105intervals[i]. length == 21 <= lefti <= righti <= 1071 <= queries[j] <= 107"
]
},
{
"id": "1857",
"title": "Largest Color Value in a Directed Graph",
"question": "There is a directed graph of n colored nodes and m edges.\n The nodes are numbered from 0 to n - 1.\nYou 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).\n 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.\nA valid path in the graph is a sequence of nodes x1 -> x2 -> x3 -> .\n.\n.\n -> xk such that there is a directed edge from xi to xi+1 for every 1 <= i < k.\n The color value of the path is the number of nodes that are colored the most frequently occurring color along that path.\nReturn the largest color value of any valid path in the given graph, or -1 if the graph contains a cycle.",
"examples": [
"Input: colors = \"abaca\", edges = [[0,1],[0,2],[2,3],[3,4]]",
"Output: 3",
"Explanation: The path 0 -> 2 -> 3 -> 4 contains 3 nodes that are colored \"a\" (red in the above image).",
"Input: colors = \"a\", edges = [[0,0]]",
"Output: -1",
"Explanation: There is a cycle from 0 to 0.",
""
],
"constraints": [
"n == colors. lengthm == edges. length1 <= n <= 1050 <= m <= 105colors consists of lowercase English letters. 0 <= aj",
" bj < n"
]
},
{
"id": "1862",
"title": "Sum of Floored Pairs",
"question": "Given an integer array nums, return the sum of floor(nums[i] / nums[j]) for all pairs of indices 0 <= i, j < nums.\nlength in the array.\n Since the answer may be too large, return it modulo 109 + 7.\nThe floor() function returns the integer part of the division.",
"examples": [
"Input: nums = [2,5,9]",
"Output: 10",
"Explanation:",
"floor(2 / 5) = floor(2 / 9) = floor(5 / 9) = 0",
"floor(2 / 2) = floor(5 / 5) = floor(9 / 9) = 1",
"floor(5 / 2) = 2",
"floor(9 / 2) = 4",
"floor(9 / 5) = 1",
"We calculate the floor of the division for every pair of indices in the array then sum them up.",
"Input: nums = [7,7,7,7,7,7,7]",
"Output: 49",
""
],
"constraints": [
"1 <= nums. length <= 1051 <= nums[i] <= 105"
]
},
{
"id": "1866",
"title": "Number of Ways to Rearrange Sticks With K Sticks Visible",
"question": "There are n uniquely-sized sticks whose lengths are integers from 1 to n.\n You want to arrange the sticks such that exactly k sticks are visible from the left.\n A stick is visible from the left if there are no longer sticks to the left of it.\nGiven n and k, return the number of such arrangements.\n Since the answer may be large, return it modulo 109 + 7.",
"examples": [
"Input: n = 3, k = 2",
"Output: 3",
"Explanation: [1,3,2], [2,3,1], and [2,1,3] are the only arrangements such that exactly 2 sticks are visible.",
"The visible sticks are underlined.",
"Input: n = 5, k = 5",
"Output: 1",
"Explanation: [1,2,3,4,5] is the only arrangement such that all 5 sticks are visible.",
"The visible sticks are underlined.",
"Input: n = 20, k = 11",
"Output: 647427950",
"Explanation: There are 647427950 (mod 109 + 7) ways to rearrange the sticks such that exactly 11 sticks are visible.",
""
],
"constraints": [
"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. 1 <= n <= 10001 <= k <= n"
]
},
{
"id": "1872",
"title": "Stone Game VIII",
"question": "Alice and Bob take turns playing a game, with Alice starting first.\nThere are n stones arranged in a row.\n On each player's turn, while the number of stones is more than one, they will do the following:The game stops when only one stone is left in the row.\nThe score difference between Alice and Bob is (Alice's score - Bob's score).\n Alice's goal is to maximize the score difference, and Bob's goal is the minimize the score difference.\nGiven 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.",
"examples": [
"Input: stones = [-1,2,-3,4,-5]",
"Output: 5",
"Explanation:",
"- Alice removes the first 4 stones, adds (-1) + 2 + (-3) + 4 = 2 to her score, and places a stone of",
" value 2 on the left. stones = [2,-5].",
"- Bob removes the first 2 stones, adds 2 + (-5) = -3 to his score, and places a stone of value -3 on",
" the left. stones = [-3].",
"The difference between their scores is 2 - (-3) = 5.",
"Input: stones = [7,-6,5,10,5,-2,-6]",
"Output: 13",
"Explanation:",
"- Alice removes all stones, adds 7 + (-6) + 5 + 10 + 5 + (-2) + (-6) = 13 to her score, and places a",
" stone of value 13 on the left. stones = [13].",
"The difference between their scores is 13 - 0 = 13.",
"Input: stones = [-10,-12]",
"Output: -22",
"Explanation:",
"- Alice can only make one move, which is to remove both stones. She adds (-10) + (-12) = -22 to her",
" score and places a stone of value -22 on the left. stones = [-22].",
"The difference between their scores is (-22) - 0 = -22.",
""
],
"constraints": [
"n == stones. length2 <= n <= 105-104 <= stones[i] <= 104"
]
},
{
"id": "1879",
"title": "Minimum XOR Sum of Two Arrays",
"question": "You are given two integer arrays nums1 and nums2 of length n.\nThe XOR sum of the two integer arrays is (nums1[0] XOR nums2[0]) + (nums1[1] XOR nums2[1]) + .\n.\n.\n + (nums1[n - 1] XOR nums2[n - 1]) (0-indexed).\nRearrange the elements of nums2 such that the resulting XOR sum is minimized.\nReturn the XOR sum after the rearrangement.",
"examples": [
"Input: nums1 = [1,2], nums2 = [2,3]",
"Output: 2",
"Explanation: Rearrange nums2 so that it becomes [3,2].",
"The XOR sum is (1 XOR 3) + (2 XOR 2) = 2 + 0 = 2. Input: nums1 = [1,0,3], nums2 = [5,3,4]",
"Output: 8",
"Explanation: Rearrange nums2 so that it becomes [5,4,3]. ",
"The XOR sum is (1 XOR 5) + (0 XOR 4) + (3 XOR 3) = 4 + 4 + 0 = 8.",
""
],
"constraints": [
"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 == nums1. lengthn == nums2. length1 <= n <= 140 <= nums1[i]",
" nums2[i] <= 107"
]
},
{
"id": "69",
"title": "Sqrt(x)",
"question": "Given a non-negative integer x, compute and return the square root of x.\nSince the return type is an integer, the decimal digits are truncated, and only the integer part of the result is returned.\nNote: You are not allowed to use any built-in exponent function or operator, such as pow(x, 0.\n5) or x ** 0.\n5.",
"examples": [
"Input: x = 4",
"Output: 2",
"Input: x = 8",
"Output: 2",
"Explanation: The square root of 8 is 2. 82842..., and since the decimal part is truncated, 2 is returned."
],
"constraints": [
"0 <= x <= 231 - 1"
]
},
{
"id": "706",
"title": "Design HashMap",
"question": "Design a HashMap without using any built-in hash table libraries.\nImplement the MyHashMap class:",
"examples": [
"Input",
"[\"MyHashMap\", \"put\", \"put\", \"get\", \"get\", \"put\", \"get\", \"remove\", \"get\"]",
"[[], [1, 1], [2, 2], [1], [3], [2, 1], [2], [2], [2]]",
"Output",
"[null, null, null, 1, -1, null, 1, null, -1]",
"",
"Explanation",
"MyHashMap myHashMap = new MyHashMap();",
"myHashMap. put(1, 1); // The map is now [[1,1]]",
"myHashMap. put(2, 2); // The map is now [[1,1], [2,2]]",
"myHashMap. get(1); // return 1, The map is now [[1,1], [2,2]]",
"myHashMap. get(3); // return -1 (i. e., not found), The map is now [[1,1], [2,2]]",
"myHashMap. put(2, 1); // The map is now [[1,1], [2,1]] (i. e., update the existing value)",
"myHashMap. get(2); // return 1, The map is now [[1,1], [2,1]]",
"myHashMap. remove(2); // remove the mapping for 2, The map is now [[1,1]]",
"myHashMap. get(2); // return -1 (i. e., not found), The map is now [[1,1]]",
""
],
"constraints": [
"MyHashMap() initializes the object with an empty map. void put(int key",
" int value) inserts a (key",
" value) pair into the HashMap. If the key already exists in the map",
" update the corresponding value. int get(int key) returns the value to which the specified key is mapped",
" or -1 if this map contains no mapping for the key. void remove(key) removes the key and its corresponding value if the map contains the mapping for the key. 0 <= key",
" value <= 106At most 104 calls will be made to put",
" get",
" and remove."
]
},
{
"id": "1883",
"title": "Minimum Skips to Arrive at Meeting On Time",
"question": "You are given an integer hoursBefore, the number of hours you have to travel to your meeting.\n To arrive at your meeting, you have to travel through n roads.\n 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.\n In addition, you are given an integer speed, which is the speed (in km/h) you will travel at.\nAfter you travel road i, you must rest and wait for the next integer hour before you can begin traveling on the next road.\n Note that you do not have to rest after traveling the last road because you are already at the meeting.\nHowever, 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.\n Note that this means you may finish traveling future roads at different hour marks.\nReturn the minimum number of skips required to arrive at the meeting on time, or -1 if it is impossible.",
"examples": [
"Input: dist = [1,3,2], speed = 4, hoursBefore = 2",
"Output: 1",
"Explanation:",
"Without skipping any rests, you will arrive in (1/4 + 3/4) + (3/4 + 1/4) + (2/4) = 2. 5 hours.",
"You can skip the first rest to arrive in ((1/4 + 0) + (3/4 + 0)) + (2/4) = 1. 5 hours.",
"Note that the second rest is shortened because you finish traveling the second road at an integer hour due to skipping the first rest.",
"Input: dist = [7,3,5,5], speed = 2, hoursBefore = 10",
"Output: 2",
"Explanation:",
"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.",
"You can skip the first and third rest to arrive in ((7/2 + 0) + (3/2 + 0)) + ((5/2 + 0) + (5/2)) = 10 hours.",
"Input: dist = [7,3,5,5], speed = 1, hoursBefore = 10",
"Output: -1",
"Explanation: It is impossible to arrive at the meeting on time even if you skip all the rests.",
""
],
"constraints": [
"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 2 hours",
" you do not need to wait. 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 == dist. length1 <= n <= 10001 <= dist[i] <= 1051 <= speed <= 1061 <= hoursBefore <= 107"
]
},
{
"id": "1889",
"title": "Minimum Space Wasted From Packaging",
"question": "You have n packages that you are trying to place in boxes, one package in each box.\n There are m suppliers that each produce boxes of different sizes (with infinite supply).\n 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.\nThe package sizes are given as an integer array packages, where packages[i] is the size of the ith package.\n The suppliers are given as a 2D integer array boxes, where boxes[j] is an array of box sizes that the jth supplier produces.\nYou want to choose a single supplier and use boxes from them such that the total wasted space is minimized.\n For each package in a box, we define the space wasted to be size of the box - size of the package.\n The total wasted space is the sum of the space wasted in all the boxes.\nReturn the minimum total wasted space by choosing the box supplier optimally, or -1 if it is impossible to fit all the packages inside boxes.\n Since the answer may be large, return it modulo 109 + 7.",
"examples": [
"Input: packages = [2,3,5], boxes = [[4,8],[2,8]]",
"Output: 6",
"Explanation: It is optimal to choose the first supplier, using two size-4 boxes and one size-8 box.",
"The total waste is (4-2) + (4-3) + (8-5) = 6.",
"Input: packages = [2,3,5], boxes = [[1,4],[2,3],[3,4]]",
"Output: -1",
"Explanation: There is no box that the package of size 5 can fit in.",
"Input: packages = [3,5,8,10,11,12], boxes = [[12],[11,9],[10,5,14]]",
"Output: 9",
"Explanation: It is optimal to choose the third supplier, using two size-5 boxes, two size-10 boxes, and two size-14 boxes.",
"The total waste is (5-3) + (5-5) + (10-8) + (10-10) + (14-11) + (14-12) = 9.",
""
],
"constraints": [
"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 == packages. lengthm == boxes. length1 <= n <= 1051 <= m <= 1051 <= packages[i] <= 1051 <= boxes[j]. length <= 1051 <= boxes[j][k] <= 105sum(boxes[j]. length) <= 105The elements in boxes[j] are distinct."
]
},
{
"id": "1896",
"title": "Minimum Cost to Change the Final Value of Expression",
"question": "You are given a valid boolean expression as a string expression consisting of the characters '1','0','&' (bitwise AND operator),'|' (bitwise OR operator),'(', and ')'.\nReturn the minimum cost to change the final value of the expression.\nThe cost of changing the final value of an expression is the number of operations performed on the expression.\n The types of operations are described as follows:Note: '&' does not take precedence over '|' in the order of calculation.\n Evaluate parentheses first, then in left-to-right order.",
"examples": [
"Input: expression = \"1&(0|1)\"",
"Output: 1",
"Explanation: We can turn \"1&(0|1)\" into \"1&(0&1)\" by changing the '|' to a '&' using 1 operation.",
"The new expression evaluates to 0. ",
"Input: expression = \"(0&0)&(0&0&0)\"",
"Output: 3",
"Explanation: We can turn \"(0&0)&(0&0&0)\" into \"(0|1)|(0&0&0)\" using 3 operations.",
"The new expression evaluates to 1.",
"Input: expression = \"(0|(1|0&1))\"",
"Output: 1",
"Explanation: We can turn \"(0|(1|0&1))\" into \"(0|(0|0&1))\" using 1 operation.",
"The new expression evaluates to 0."
],
"constraints": [
"For example",
" \"()1|1\" and \"(1)&()\" are not valid while \"1\"",
" \"(((1))|(0))\"",
" and \"1|(0&(1))\" are valid expressions. 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. Turn a '1' into a '0'. Turn a '0' into a '1'. Turn a '&' into a '|'. Turn a '|' into a '&'. 1 <= expression. length <= 105expression only contains '1'",
"'0'",
"'&'",
"'|'",
"'('",
" and ')'All parentheses are properly matched. There will be no empty parentheses (i. e: \"()\" is not a substring of expression)."
]
},
{
"id": "1900",
"title": "The Earliest and Latest Rounds Where Players Compete",
"question": "There is a tournament where n players are participating.\n 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).\nThe tournament consists of multiple rounds (starting from round number 1).\n 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.\n When the number of players is odd for the current round, the player in the middle automatically advances to the next round.\nAfter each round is over, the winners are lined back up in the row based on the original ordering assigned to them initially (ascending order).\nThe players numbered firstPlayer and secondPlayer are the best in the tournament.\n They can win against any other player before they compete against each other.\n If any two other players compete against each other, either of them might win, and thus you may choose the outcome of this round.\nGiven the integers n, firstPlayer, and secondPlayer, return an integer array containing two values, the earliest possible round number and the latest possible round number in which these two players will compete against each other, respectively.",
"examples": [
"Input: n = 11, firstPlayer = 2, secondPlayer = 4",
"Output: [3,4]",
"Explanation:",
"One possible scenario which leads to the earliest round number:",
"First round: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11",
"Second round: 2, 3, 4, 5, 6, 11",
"Third round: 2, 3, 4",
"One possible scenario which leads to the latest round number:",
"First round: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11",
"Second round: 1, 2, 3, 4, 5, 6",
"Third round: 1, 2, 4",
"Fourth round: 2, 4",
"Input: n = 5, firstPlayer = 1, secondPlayer = 5",
"Output: [1,1]",
"Explanation: The players numbered 1 and 5 compete in the first round.",
"There is no way to make them compete in any other round.",
""
],
"constraints": [
"For example",
" if the row consists of players 1",
" 2",
" 4",
" 6",
" 7\n\nPlayer 1 competes against player 7.\nPlayer 2 competes against player 6.\nPlayer 4 automatically advances to the next round.\n\nPlayer 1 competes against player 7. Player 2 competes against player 6. Player 4 automatically advances to the next round. 2 <= n <= 281 <= firstPlayer < secondPlayer <= n"
]
},
{
"id": "1912",
"title": "Design Movie Rental System",
"question": "You have a movie renting company consisting of n shops.\n You want to implement a renting system that supports searching for, booking, and returning movies.\n The system should also support generating a report of the currently rented movies.\nEach movie is given as a 2D integer array entries where entries[i] = [shopi, moviei, pricei] indicates that there is a copy of movie moviei at shop shopi with a rental price of pricei.\n Each shop carries at most one copy of a movie moviei.\nThe system should support the following functions:Implement the MovieRentingSystem class:Note: The test cases will be generated such that rent will only be called if the shop has an unrented copy of the movie, and drop will only be called if the shop had previously rented out the movie.",
"examples": [
"Input",
"[\"MovieRentingSystem\", \"search\", \"rent\", \"rent\", \"report\", \"drop\", \"search\"]",
"[[3, [[0, 1, 5], [0, 2, 6], [0, 3, 7], [1, 1, 4], [1, 2, 7], [2, 1, 5]]], [1], [0, 1], [1, 2], [], [1, 2], [2]]",
"Output",
"[null, [1, 0, 2], null, null, [[0, 1], [1, 2]], null, [0, 1]]",
"",
"Explanation",
"MovieRentingSystem movieRentingSystem = new MovieRentingSystem(3, [[0, 1, 5], [0, 2, 6], [0, 3, 7], [1, 1, 4], [1, 2, 7], [2, 1, 5]]);",
"movieRentingSystem. search(1); // return [1, 0, 2], Movies of ID 1 are unrented at shops 1, 0, and 2. Shop 1 is cheapest; shop 0 and 2 are the same price, so order by shop number.",
"movieRentingSystem. rent(0, 1); // Rent movie 1 from shop 0. Unrented movies at shop 0 are now [2,3].",
"movieRentingSystem. rent(1, 2); // Rent movie 2 from shop 1. Unrented movies at shop 1 are now [1].",
"movieRentingSystem. report(); // return [[0, 1], [1, 2]]. Movie 1 from shop 0 is cheapest, followed by movie 2 from shop 1.",
"movieRentingSystem. drop(1, 2); // Drop off movie 2 at shop 1. Unrented movies at shop 1 are now [1,2].",
"movieRentingSystem. search(2); // return [0, 1]. Movies of ID 2 are unrented at shops 0 and 1. Shop 0 is cheapest, followed by shop 1.",
""
],
"constraints": [
"Search: Finds the cheapest 5 shops that have an unrented copy of a given movie. The shops should be sorted by price in ascending order",
" and in case of a tie",
" the one with the smaller shopi should appear first. If there are less than 5 matching shops",
" then all of them should be returned. If no shop has an unrented copy",
" then an empty list should be returned. Rent: Rents an unrented copy of a given movie from a given shop. Drop: Drops off a previously rented copy of a given movie at a given shop. Report: Returns the cheapest 5 rented movies (possibly of the same movie ID) as a 2D list res where res[j] = [shopj",
" moviej] describes that the jth cheapest rented movie moviej was rented from the shop shopj. The movies in res should be sorted by price in ascending order",
" and in case of a tie",
" the one with the smaller shopj should appear first",
" and if there is still tie",
" the one with the smaller moviej should appear first. If there are fewer than 5 rented movies",
" then all of them should be returned. If no movies are currently being rented",
" then an empty list should be returned. MovieRentingSystem(int n",
" int[][] entries) Initializes the MovieRentingSystem object with n shops and the movies in entries. List<Integer> search(int movie) Returns a list of shops that have an unrented copy of the given movie as described above. void rent(int shop",
" int movie) Rents the given movie from the given shop. void drop(int shop",
" int movie) Drops off a previously rented movie at the given shop. List<List<Integer>> report() Returns a list of cheapest rented movies as described above. 1 <= n <= 3 * 1051 <= entries. length <= 1050 <= shopi < n1 <= moviei",
" pricei <= 104Each shop carries at most one copy of a movie moviei. At most 105 calls in total will be made to search",
" rent",
" drop and report."
]
},
{
"id": "1916",
"title": "Count Ways to Build Rooms in an Ant Colony",
"question": "You are an ant tasked with adding n new rooms numbered 0 to n-1 to your colony.\n 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.\n Room 0 is already built, so prevRoom[0] = -1.\n The expansion plan is given such that once all the rooms are built, every room will be reachable from room 0.\nYou can only build one room at a time, and you can travel freely between rooms you have already built only if they are connected.\n You can choose to build any room as long as its previous room is already built.\nReturn the number of different orders you can build all the rooms in.\n Since the answer may be large, return it modulo 109 + 7.",
"examples": [
"Input: prevRoom = [-1,0,1]",
"Output: 1",
"Explanation: There is only one way to build the additional rooms: 0 → 1 → 2",
"Input: prevRoom = [-1,0,0,1,2]",
"Output: 6",
"Explanation:",
"The 6 ways are:",
"0 → 1 → 3 → 2 → 4",
"0 → 2 → 4 → 1 → 3",
"0 → 1 → 2 → 3 → 4",
"0 → 1 → 2 → 4 → 3",
"0 → 2 → 1 → 3 → 4",
"0 → 2 → 1 → 4 → 3",
""
],
"constraints": [
"n == prevRoom. length2 <= n <= 105prevRoom[0] == -10 <= prevRoom[i] < n for all 1 <= i < nEvery room is reachable from room 0 once all the rooms are built."
]
},
{
"id": "1923",
"title": "Longest Common Subpath",
"question": "There is a country of n cities numbered from 0 to n - 1.\n In this country, there is a road connecting every pair of cities.\nThere are m friends numbered from 0 to m - 1 who are traveling through the country.\n Each one of them will take a path consisting of some cities.\n Each path is represented by an integer array that contains the visited cities in order.\n The path may contain a city more than once, but the same city will not be listed consecutively.\nGiven 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.\nA subpath of a path is a contiguous sequence of cities within that path.",
"examples": [
"Input: n = 5, paths = [[0,1,2,3,4],",
" [2,3,4],",
" [4,0,1,2,3]]",
"Output: 2",
"Explanation: The longest common subpath is [2,3].",
"Input: n = 3, paths = [[0],[1],[2]]",
"Output: 0",
"Explanation: There is no common subpath shared by the three paths.",
"Input: n = 5, paths = [[0,1,2,3,4],",
" [4,3,2,1,0]]",
"Output: 1",
"Explanation: The possible longest common subpaths are [0], [1], [2], [3], and [4]. All have a length of 1."
],
"constraints": [
"1 <= n <= 105m == paths. length2 <= m <= 105sum(paths[i]. length) <= 1050 <= paths[i][j] < nThe same city is not listed multiple times consecutively in paths[i]."
]
},
{
"id": "1928",
"title": "Minimum Cost to Reach Destination in Time",
"question": "There is a country of n cities numbered from 0 to n - 1 where all the cities are connected by bi-directional roads.\n 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.\n There may be multiple roads of differing travel times connecting the same two cities, but no road connects a city to itself.\nEach time you pass through a city, you must pay a passing fee.\n 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.\nIn the beginning, you are at city 0 and want to reach city n - 1 in maxTime minutes or less.\n 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).\nGiven maxTime, edges, and passingFees, return the minimum cost to complete your journey, or -1 if you cannot complete it within maxTime minutes.",
"examples": [
"Input: 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]",
"Output: 11",
"Explanation: The path to take is 0 -> 1 -> 2 -> 5, which takes 30 minutes and has $11 worth of passing fees.",
"Input: 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]",
"Output: 48",
"Explanation: The path to take is 0 -> 3 -> 4 -> 5, which takes 26 minutes and has $48 worth of passing fees.",
"You cannot take path 0 -> 1 -> 2 -> 5 since it would take too long.",
"Input: 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]",
"Output: -1",
"Explanation: There is no way to reach city 5 from city 0 within 25 minutes.",
""
],
"constraints": [
"1 <= maxTime <= 1000n == passingFees. length2 <= n <= 1000n - 1 <= edges. length <= 10000 <= xi",
" yi <= n - 11 <= timei <= 10001 <= passingFees[j] <= 1000 The graph may contain multiple edges between two nodes. The graph does not contain self loops."
]
},
{
"id": "1931",
"title": "Painting a Grid With Three Different Colors",
"question": "You are given two integers m and n.\n Consider an m x n grid where each cell is initially white.\n You can paint each cell red, green, or blue.\n All cells must be painted.\nReturn the number of ways to color the grid with no two adjacent cells having the same color.\n Since the answer can be very large, return it modulo 109 + 7.",
"examples": [
"Input: m = 1, n = 1",
"Output: 3",
"Explanation: The three possible colorings are shown in the image above.",
"Input: m = 1, n = 2",
"Output: 6",
"Explanation: The six possible colorings are shown in the image above.",
"Input: m = 5, n = 5",
"Output: 580986",
""
],
"constraints": [
"1 <= m <= 51 <= n <= 1000"
]
},
{
"id": "1932",
"title": "Merge BSTs to Create Single BST",
"question": "You are given n BST (binary search tree) root nodes for n separate BSTs stored in an array trees (0-indexed).\n Each BST in trees has at most 3 nodes, and no two roots have the same value.\n In one operation, you can:Return the root of the resulting BST if it is possible to form a valid BST after performing n - 1 operations, or null if it is impossible to create a valid BST.\nA BST (binary search tree) is a binary tree where each node satisfies the following property:A leaf is a node that has no children.",
"examples": [
"Input: trees = [[2,1],[3,2,5],[5,4]]",
"Output: [3,2,5,1,null,4]",
"Explanation:",
"In the first operation, pick i=1 and j=0, and merge trees[0] into trees[1].",
"Delete trees[0], so trees = [[3,2,5,1],[5,4]].",
"",
"In the second operation, pick i=0 and j=1, and merge trees[1] into trees[0].",
"Delete trees[1], so trees = [[3,2,5,1,null,4]].",
"",
"The resulting tree, shown above, is a valid BST, so return its root. Input: trees = [[5,3,8],[3,2,6]]",
"Output: []",
"Explanation:",
"Pick i=0 and j=1 and merge trees[1] into trees[0].",
"Delete trees[1], so trees = [[5,3,8,2,6]].",
"",
"The resulting tree is shown above. This is the only valid operation that can be performed, but the resulting tree is not a valid BST, so return null.",
"Input: trees = [[5,4],[3]]",
"Output: []",
"Explanation: It is impossible to perform any operations.",
"Input: trees = [[2,1,3]]",
"Output: [2,1,3]",
"Explanation: There is only one tree, and it is already a valid BST, so return its root.",
""
],
"constraints": [
"Select two distinct indices i and j such that the value stored at one of the leaves of trees[i] is equal to the root value of trees[j]. Replace the leaf node in trees[i] with trees[j]. Remove trees[j] from trees. Every node in the node's left subtree has a value strictly less than the node's value. Every node in the node's right subtree has a value strictly greater than the node's value. n == trees. length1 <= n <= 5 * 104The number of nodes in each tree is in the range [1",
" 3]. Each node in the input may have children but no grandchildren. No two roots of trees have the same value. All the trees in the input are valid BSTs. 1 <= TreeNode. val <= 5 * 104."
]
},
{
"id": "709",
"title": "To Lower Case",
"question": "Given a string s, return the string after replacing every uppercase letter with the same lowercase letter.",
"examples": [
"Input: s = \"Hello\"",
"Output: \"hello\"",
"Input: s = \"here\"",
"Output: \"here\"",
"Input: s = \"LOVELY\"",
"Output: \"lovely\"",
""
],
"constraints": [
"1 <= s. length <= 100s consists of printable ASCII characters."
]
},
{
"id": "1938",
"title": "Maximum Genetic Difference Query",
"question": "There is a rooted tree consisting of n nodes numbered 0 to n - 1.\n Each node's number denotes its unique genetic value (i.\ne.\n the genetic value of node x is x).\n The genetic difference between two genetic values is defined as the bitwise-XOR of their values.\n You are given the integer array parents, where parents[i] is the parent for node i.\n If node x is the root of the tree, then parents[x] == -1.\nYou are also given the array queries where queries[i] = [nodei, vali].\n 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).\n More formally, you want to maximize vali XOR pi.\nReturn an array ans where ans[i] is the answer to the ith query.",
"examples": [
"Input: parents = [-1,0,1,1], queries = [[0,2],[3,2],[2,5]]",
"Output: [2,3,7]",
"Explanation: The queries are processed as follows:",
"- [0,2]: The node with the maximum genetic difference is 0, with a difference of 2 XOR 0 = 2.",
"- [3,2]: The node with the maximum genetic difference is 1, with a difference of 2 XOR 1 = 3.",
"- [2,5]: The node with the maximum genetic difference is 2, with a difference of 5 XOR 2 = 7.",
"Input: parents = [3,7,-1,2,0,7,0,2], queries = [[4,6],[1,15],[0,5]]",
"Output: [6,14,7]",
"Explanation: The queries are processed as follows:",
"- [4,6]: The node with the maximum genetic difference is 0, with a difference of 6 XOR 0 = 6.",
"- [1,15]: The node with the maximum genetic difference is 1, with a difference of 15 XOR 1 = 14.",
"- [0,5]: The node with the maximum genetic difference is 2, with a difference of 5 XOR 2 = 7.",
""
],
"constraints": [
"2 <= parents. length <= 1050 <= parents[i] <= parents. length - 1 for every node i that is not the root. parents[root] == -11 <= queries. length <= 3 * 1040 <= nodei <= parents. length - 10 <= vali <= 2 * 105"
]
},
{
"id": "1944",
"title": "Number of Visible People in a Queue",
"question": "There are n people standing in a queue, and they numbered from 0 to n - 1 in left to right order.\n You are given an array heights of distinct integers where heights[i] represents the height of the ith person.\nA person can see another person to their right in the queue if everybody in between is shorter than both of them.\n 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], .\n.\n.\n, heights[j-1]).\nReturn 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.",
"examples": [
"Input: heights = [10,6,8,5,11,9]",
"Output: [3,1,2,1,1,0]",
"Explanation:",
"Person 0 can see person 1, 2, and 4.",
"Person 1 can see person 2.",
"Person 2 can see person 3 and 4.",
"Person 3 can see person 4.",
"Person 4 can see person 5.",
"Person 5 can see no one since nobody is to the right of them.",
"Input: heights = [5,1,2,3,10]",
"Output: [4,1,1,1,0]",
""
],
"constraints": [
"n == heights. length1 <= n <= 1051 <= heights[i] <= 105All the values of heights are unique."
]
},
{
"id": "1948",
"title": "Delete Duplicate Folders in System",
"question": "Due to a bug, there are many duplicate folders in a file system.\n 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.\nTwo folders (not necessarily on the same level) are identical if they contain the same non-empty set of identical subfolders and underlying subfolder structure.\n The folders do not need to be at the root level to be identical.\n If two or more folders are identical, then mark the folders as well as all their subfolders.\nOnce all the identical folders and their subfolders have been marked, the file system will delete all of them.\n The file system only runs the deletion once, so any folders that become identical after the initial deletion are not deleted.\nReturn the 2D array ans containing the paths of the remaining folders after deleting all the marked folders.\n The paths may be returned in any order.",
"examples": [
"Input: paths = [[\"a\"],[\"c\"],[\"d\"],[\"a\",\"b\"],[\"c\",\"b\"],[\"d\",\"a\"]]",
"Output: [[\"d\"],[\"d\",\"a\"]]",
"Explanation: The file structure is as shown.",
"Folders \"/a\" and \"/c\" (and their subfolders) are marked for deletion because they both contain an empty",
"folder named \"b\".",
"Input: paths = [[\"a\"],[\"c\"],[\"a\",\"b\"],[\"c\",\"b\"],[\"a\",\"b\",\"x\"],[\"a\",\"b\",\"x\",\"y\"],[\"w\"],[\"w\",\"y\"]]",
"Output: [[\"c\"],[\"c\",\"b\"],[\"a\"],[\"a\",\"b\"]]",
"Explanation: The file structure is as shown. ",
"Folders \"/a/b/x\" and \"/w\" (and their subfolders) are marked for deletion because they both contain an empty folder named \"y\".",
"Note that folders \"/a\" and \"/c\" are identical after the deletion, but they are not deleted because they were not marked beforehand.",
"Input: paths = [[\"a\",\"b\"],[\"c\",\"d\"],[\"c\"],[\"a\"]]",
"Output: [[\"c\"],[\"c\",\"d\"],[\"a\"],[\"a\",\"b\"]]",
"Explanation: All folders are unique in the file system.",
"Note that the returned array can be in a different order as the order does not matter.",
"Input: paths = [[\"a\"],[\"a\",\"x\"],[\"a\",\"x\",\"y\"],[\"a\",\"z\"],[\"b\"],[\"b\",\"x\"],[\"b\",\"x\",\"y\"],[\"b\",\"z\"]]",
"Output: []",
"Explanation: The file structure is as shown.",
"Folders \"/a/x\" and \"/b/x\" (and their subfolders) are marked for deletion because they both contain an",
"empty folder named \"y\".",
"Folders \"/a\" and \"/b\" (and their subfolders) are marked for deletion because they both contain an empty",
"folder \"z\" and the folder \"x\" described above.",
"Input: paths = [[\"a\"],[\"a\",\"x\"],[\"a\",\"x\",\"y\"],[\"a\",\"z\"],[\"b\"],[\"b\",\"x\"],[\"b\",\"x\",\"y\"],[\"b\",\"z\"],[\"b\",\"w\"]]",
"Output: [[\"b\"],[\"b\",\"w\"],[\"b\",\"z\"],[\"a\"],[\"a\",\"z\"]]",
"Explanation: This has the same structure as the previous example, except with the added \"/b/w\".",
"Folders \"/a/x\" and \"/b/x\" are still marked, but \"/a\" and \"/b\" are no longer marked because \"/b\" has the",
"empty folder named \"w\" and \"/a\" does not.",
"Note that \"/a/z\" and \"/b/z\" are not marked because the set of identical subfolders must be non-empty, but these folders are empty.",
""
],
"constraints": [
"For example",
" [\"one\"",
" \"two\"",
" \"three\"] represents the path \"/one/two/three\". 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\t\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/a/a/x/a/x/y/a/z/b/b/x/b/x/y/b/zHowever",
" 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. 1 <= paths. length <= 2 * 1041 <= paths[i]. length <= 5001 <= paths[i][j]. length <= 101 <= sum(paths[i][j]. length) <= 2 * 105path[i][j] consists of lowercase English letters. No two paths lead to the same folder. For any folder not at the root level",
" its parent folder will also be in the input."
]
},
{
"id": "1955",
"title": "Count Number of Special Subsequences",
"question": "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.\nGiven an array nums (consisting of only integers 0, 1, and 2), return the number of different subsequences that are special.\n Since the answer may be very large, return it modulo 109 + 7.\nA 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.\n Two subsequences are different if the set of indices chosen are different.",
"examples": [
"Input: nums = [0,1,2,2]",
"Output: 3",
"Explanation: The special subsequences are bolded [0,1,2,2], [0,1,2,2], and [0,1,2,2].",
"Input: nums = [2,2,0,0]",
"Output: 0",
"Explanation: There are no special subsequences in [2,2,0,0].",
"Input: nums = [0,1,2,0,1,2]",
"Output: 7",
"Explanation: The special subsequences are bolded:",
"- [0,1,2,0,1,2]",
"- [0,1,2,0,1,2]",
"- [0,1,2,0,1,2]",
"- [0,1,2,0,1,2]",
"- [0,1,2,0,1,2]",
"- [0,1,2,0,1,2]",
"- [0,1,2,0,1,2]",
""
],
"constraints": [
"For example",
" [0",
"1",
"2] and [0",
"0",
"1",
"1",
"1",
"2] are special. In contrast",
" [2",
"1",
"0]",
" [1]",
" and [0",
"1",
"2",
"0] are not special. 1 <= nums. length <= 1050 <= nums[i] <= 2"
]
},
{
"id": "1960",
"title": "Maximum Product of the Length of Two Palindromic Substrings",
"question": "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.\nMore formally, you want to choose four integers i, j, k, l such that 0 <= i <= j < k <= l < s.\nlength and both the substrings s[i.\n.\n.\nj] and s[k.\n.\n.\nl] are palindromes and have odd lengths.\n s[i.\n.\n.\nj] denotes a substring from index i to index j inclusive.\nReturn the maximum possible product of the lengths of the two non-intersecting palindromic substrings.\nA palindrome is a string that is the same forward and backward.\n A substring is a contiguous sequence of characters in a string.",
"examples": [
"Input: s = \"ababbb\"",
"Output: 9",
"Explanation: Substrings \"aba\" and \"bbb\" are palindromes with odd length. product = 3 * 3 = 9.",
"Input: s = \"zaaaxbbby\"",
"Output: 9",
"Explanation: Substrings \"aaa\" and \"bbb\" are palindromes with odd length. product = 3 * 3 = 9.",
""
],
"constraints": [
"2 <= s. length <= 105s consists of lowercase English letters."
]
},
{
"id": "1964",
"title": "Find the Longest Valid Obstacle Course at Each Position",
"question": "You want to build some obstacle courses.\n You are given a 0-indexed integer array obstacles of length n, where obstacles[i] describes the height of the ith obstacle.\nFor every index i between 0 and n - 1 (inclusive), find the length of the longest obstacle course in obstacles such that:Return an array ans of length n, where ans[i] is the length of the longest obstacle course for index i as described above.",
"examples": [
"Input: obstacles = [1,2,3,2]",
"Output: [1,2,3,3]",
"Explanation: The longest valid obstacle course at each position is:",
"- i = 0: [1], [1] has length 1.",
"- i = 1: [1,2], [1,2] has length 2.",
"- i = 2: [1,2,3], [1,2,3] has length 3.",
"- i = 3: [1,2,3,2], [1,2,2] has length 3.",
"Input: obstacles = [2,2,1]",
"Output: [1,2,1]",
"Explanation: The longest valid obstacle course at each position is:",
"- i = 0: [2], [2] has length 1.",
"- i = 1: [2,2], [2,2] has length 2.",
"- i = 2: [2,2,1], [1] has length 1.",
"Input: obstacles = [3,1,5,6,4,2]",
"Output: [1,1,2,3,2,2]",
"Explanation: The longest valid obstacle course at each position is:",
"- i = 0: [3], [3] has length 1.",
"- i = 1: [3,1], [1] has length 1.",
"- i = 2: [3,1,5], [3,5] has length 2. [1,5] is also valid.",
"- i = 3: [3,1,5,6], [3,5,6] has length 3. [1,5,6] is also valid.",
"- i = 4: [3,1,5,6,4], [3,4] has length 2. [1,4] is also valid.",
"- i = 5: [3,1,5,6,4,2], [1,2] has length 2.",
""
],
"constraints": [
"You choose any number of obstacles between 0 and i inclusive. You must include the ith obstacle in the course. You must put the chosen obstacles in the same order as they appear in obstacles. Every obstacle (except the first) is taller than or the same height as the obstacle immediately before it. n == obstacles. length1 <= n <= 1051 <= obstacles[i] <= 107"
]
},
{
"id": "1970",
"title": "Last Day Where You Can Still Cross",
"question": "There is a 1-based binary matrix where 0 represents land and 1 represents water.\n You are given integers row and col representing the number of rows and columns in the matrix, respectively.\nInitially on day 0, the entire matrix is land.\n However, each day a new cell becomes flooded with water.\n 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.\ne.\n, changed to 1).\nYou want to find the last day that it is possible to walk from the top to the bottom by only walking on land cells.\n You can start from any cell in the top row and end at any cell in the bottom row.\n You can only travel in the four cardinal directions (left, right, up, and down).\nReturn the last day where it is possible to walk from the top to the bottom by only walking on land cells.",
"examples": [
"Input: row = 2, col = 2, cells = [[1,1],[2,1],[1,2],[2,2]]",
"Output: 2",
"Explanation: The above image depicts how the matrix changes each day starting from day 0.",
"The last day where it is possible to cross from top to bottom is on day 2.",
"Input: row = 2, col = 2, cells = [[1,1],[1,2],[2,1],[2,2]]",
"Output: 1",
"Explanation: The above image depicts how the matrix changes each day starting from day 0.",
"The last day where it is possible to cross from top to bottom is on day 1.",
"Input: row = 3, col = 3, cells = [[1,2],[2,1],[3,3],[2,2],[1,1],[1,3],[2,3],[3,2],[3,1]]",
"Output: 3",
"Explanation: The above image depicts how the matrix changes each day starting from day 0.",
"The last day where it is possible to cross from top to bottom is on day 3.",
""
],
"constraints": [
"2 <= row",
" col <= 2 * 1044 <= row * col <= 2 * 104cells. length == row * col1 <= ri <= row1 <= ci <= colAll the values of cells are unique."
]
},
{
"id": "1977",
"title": "Number of Ways to Separate Numbers",
"question": "You wrote down many positive integers in a string called num.\n However, you realized that you forgot to add commas to seperate the different numbers.\n You remember that the list of integers was non-decreasing and that no integer had leading zeros.\nReturn the number of possible lists of integers that you could have written down to get the string num.\n Since the answer may be large, return it modulo 109 + 7.",
"examples": [
"Input: num = \"327\"",
"Output: 2",
"Explanation: You could have written down the numbers:",
"3, 27",
"327",
"Input: num = \"094\"",
"Output: 0",
"Explanation: No numbers can have leading zeros and all numbers must be positive.",
"Input: num = \"0\"",
"Output: 0",
"Explanation: No numbers can have leading zeros and all numbers must be positive.",
"Input: num = \"9999999999999\"",
"Output: 101",
""
],
"constraints": [
"1 <= num. length <= 3500num consists of digits '0' through '9'."
]
},
{
"id": "1982",
"title": "Find Array Given Subset Sums",
"question": "You are given an integer n representing the length of an unknown array that you are trying to recover.\n You are also given an array sums containing the values of all 2n subset sums of the unknown array (in no particular order).\nReturn the array ans of length n representing the unknown array.\n If multiple answers exist, return any of them.\nAn 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.\n The sum of the elements in sub is one possible subset sum of arr.\n The sum of an empty array is considered to be 0.\nNote: Test cases are generated such that there will always be at least one correct answer.",
"examples": [
"Input: n = 3, sums = [-3,-2,-1,0,0,1,2,3]",
"Output: [1,2,-3]",
"Explanation: [1,2,-3] is able to achieve the given subset sums:",
"- []: sum is 0",
"- [1]: sum is 1",
"- [2]: sum is 2",
"- [1,2]: sum is 3",
"- [-3]: sum is -3",
"- [1,-3]: sum is -2",
"- [2,-3]: sum is -1",
"- [1,2,-3]: sum is 0",
"Note that any permutation of [1,2,-3] and also any permutation of [-1,-2,3] will also be accepted.",
"Input: n = 2, sums = [0,0,0,0]",
"Output: [0,0]",
"Explanation: The only correct answer is [0,0].",
"Input: n = 4, sums = [0,0,5,5,4,-1,4,9,9,-1,4,3,4,8,3,8]",
"Output: [0,-1,4,5]",
"Explanation: [0,-1,4,5] is able to achieve the given subset sums.",
""
],
"constraints": [
"1 <= n <= 15sums. length == 2n-104 <= sums[i] <= 104"
]
},
{
"id": "1987",
"title": "Number of Unique Good Subsequences",
"question": "You are given a binary string binary.\n A subsequence of binary is considered good if it is not empty and has no leading zeros (with the exception of \"0\").\nFind the number of unique good subsequences of binary.\nReturn the number of unique good subsequences of binary.\n Since the answer may be very large, return it modulo 109 + 7.\nA 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.",
"examples": [
"Input: binary = \"001\"",
"Output: 2",
"Explanation: The good subsequences of binary are [\"0\", \"0\", \"1\"].",
"The unique good subsequences are \"0\" and \"1\".",
"Input: binary = \"11\"",
"Output: 2",
"Explanation: The good subsequences of binary are [\"1\", \"1\", \"11\"].",
"The unique good subsequences are \"1\" and \"11\". Input: binary = \"101\"",
"Output: 5",
"Explanation: The good subsequences of binary are [\"1\", \"0\", \"1\", \"10\", \"11\", \"101\"]. ",
"The unique good subsequences are \"0\", \"1\", \"10\", \"11\", and \"101\".",
""
],
"constraints": [
"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. 1 <= binary. length <= 105binary consists of only '0's and '1's."
]
},
{
"id": "717",
"title": "1-bit and 2-bit Characters",
"question": "We have two special characters:Given a binary array bits that ends with 0, return true if the last character must be a one-bit character.",
"examples": [
"Input: bits = [1,0,0]",
"Output: true",
"Explanation: The only way to decode it is two-bit character and one-bit character.",
"So the last character is one-bit character.",
"Input: bits = [1,1,1,0]",
"Output: false",
"Explanation: The only way to decode it is two-bit character and two-bit character.",
"So the last character is not one-bit character.",
""
],
"constraints": [
"The first character can be represented by one bit 0. The second character can be represented by two bits (10 or 11). 1 <= bits. length <= 1000bits[i] is either 0 or 1."
]
},
{
"id": "1960",
"title": "Maximum Product of the Length of Two Palindromic Substrings",
"question": "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.\nMore formally, you want to choose four integers i, j, k, l such that 0 <= i <= j < k <= l < s.\nlength and both the substrings s[i.\n.\n.\nj] and s[k.\n.\n.\nl] are palindromes and have odd lengths.\n s[i.\n.\n.\nj] denotes a substring from index i to index j inclusive.\nReturn the maximum possible product of the lengths of the two non-intersecting palindromic substrings.\nA palindrome is a string that is the same forward and backward.\n A substring is a contiguous sequence of characters in a string.",
"examples": [
"Input: s = \"ababbb\"",
"Output: 9",
"Explanation: Substrings \"aba\" and \"bbb\" are palindromes with odd length. product = 3 * 3 = 9.",
"Input: s = \"zaaaxbbby\"",
"Output: 9",
"Explanation: Substrings \"aaa\" and \"bbb\" are palindromes with odd length. product = 3 * 3 = 9.",
""
],
"constraints": [
"2 <= s. length <= 105s consists of lowercase English letters."
]
},
{
"id": "1964",
"title": "Find the Longest Valid Obstacle Course at Each Position",
"question": "You want to build some obstacle courses.\n You are given a 0-indexed integer array obstacles of length n, where obstacles[i] describes the height of the ith obstacle.\nFor every index i between 0 and n - 1 (inclusive), find the length of the longest obstacle course in obstacles such that:Return an array ans of length n, where ans[i] is the length of the longest obstacle course for index i as described above.",
"examples": [
"Input: obstacles = [1,2,3,2]",
"Output: [1,2,3,3]",
"Explanation: The longest valid obstacle course at each position is:",
"- i = 0: [1], [1] has length 1.",
"- i = 1: [1,2], [1,2] has length 2.",
"- i = 2: [1,2,3], [1,2,3] has length 3.",
"- i = 3: [1,2,3,2], [1,2,2] has length 3.",
"Input: obstacles = [2,2,1]",
"Output: [1,2,1]",
"Explanation: The longest valid obstacle course at each position is:",
"- i = 0: [2], [2] has length 1.",
"- i = 1: [2,2], [2,2] has length 2.",
"- i = 2: [2,2,1], [1] has length 1.",
"Input: obstacles = [3,1,5,6,4,2]",
"Output: [1,1,2,3,2,2]",
"Explanation: The longest valid obstacle course at each position is:",
"- i = 0: [3], [3] has length 1.",
"- i = 1: [3,1], [1] has length 1.",
"- i = 2: [3,1,5], [3,5] has length 2. [1,5] is also valid.",
"- i = 3: [3,1,5,6], [3,5,6] has length 3. [1,5,6] is also valid.",
"- i = 4: [3,1,5,6,4], [3,4] has length 2. [1,4] is also valid.",
"- i = 5: [3,1,5,6,4,2], [1,2] has length 2.",
""
],
"constraints": [
"You choose any number of obstacles between 0 and i inclusive. You must include the ith obstacle in the course. You must put the chosen obstacles in the same order as they appear in obstacles. Every obstacle (except the first) is taller than or the same height as the obstacle immediately before it. n == obstacles. length1 <= n <= 1051 <= obstacles[i] <= 107"
]
},
{
"id": "1970",
"title": "Last Day Where You Can Still Cross",
"question": "There is a 1-based binary matrix where 0 represents land and 1 represents water.\n You are given integers row and col representing the number of rows and columns in the matrix, respectively.\nInitially on day 0, the entire matrix is land.\n However, each day a new cell becomes flooded with water.\n 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.\ne.\n, changed to 1).\nYou want to find the last day that it is possible to walk from the top to the bottom by only walking on land cells.\n You can start from any cell in the top row and end at any cell in the bottom row.\n You can only travel in the four cardinal directions (left, right, up, and down).\nReturn the last d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment